1/*
2 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
3 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "FrameLoaderClientWinCE.h"
28
29#include "DocumentLoader.h"
30#include "FrameLoader.h"
31#include "FrameNetworkingContextWinCE.h"
32#include "FrameView.h"
33#include "HTMLFormElement.h"
34#include "MIMETypeRegistry.h"
35#include "NotImplemented.h"
36#include "Page.h"
37#include "PluginDatabase.h"
38#include "RenderPart.h"
39#include "SystemInfo.h"
40#include "WebKitVersion.h"
41#include "WebView.h"
42#include <wtf/text/StringConcatenate.h>
43
44using namespace WebCore;
45
46namespace WebKit {
47
48FrameLoaderClientWinCE::FrameLoaderClientWinCE(WebView* view)
49    : m_webView(view)
50    , m_pluginView(0)
51{
52    ASSERT(m_webView);
53}
54
55FrameLoaderClientWinCE::~FrameLoaderClientWinCE()
56{
57}
58
59String FrameLoaderClientWinCE::userAgent(const KURL&)
60{
61    DEFINE_STATIC_LOCAL(String, userAgentString, ());
62
63    if (userAgentString.isNull()) {
64        String webKitVersion = String::format("%d.%d", WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION);
65        userAgentString = makeString("Mozilla/5.0 (", windowsVersionForUAString(), ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) Mobile Safari/", webKitVersion);
66    }
67
68    return userAgentString;
69}
70
71PassRefPtr<DocumentLoader> FrameLoaderClientWinCE::createDocumentLoader(const WebCore::ResourceRequest& request, const SubstituteData& substituteData)
72{
73    return DocumentLoader::create(request, substituteData);
74}
75
76void FrameLoaderClientWinCE::committedLoad(DocumentLoader* loader, const char* data, int length)
77{
78    if (m_pluginView) {
79        if (!m_hasSentResponseToPlugin) {
80            m_pluginView->didReceiveResponse(loader->response());
81            m_hasSentResponseToPlugin = true;
82        }
83        m_pluginView->didReceiveData(data, length);
84    } else
85        loader->commitData(data, length);
86}
87
88bool FrameLoaderClientWinCE::shouldUseCredentialStorage(DocumentLoader*, unsigned long)
89{
90    notImplemented();
91    return false;
92}
93
94void FrameLoaderClientWinCE::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
95{
96    notImplemented();
97}
98
99void FrameLoaderClientWinCE::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
100{
101    notImplemented();
102}
103
104void FrameLoaderClientWinCE::dispatchWillSendRequest(DocumentLoader*, unsigned long, WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
105{
106    notImplemented();
107}
108
109void FrameLoaderClientWinCE::assignIdentifierToInitialRequest(unsigned long, DocumentLoader*, const WebCore::ResourceRequest&)
110{
111    notImplemented();
112}
113
114void FrameLoaderClientWinCE::postProgressStartedNotification()
115{
116    notImplemented();
117}
118
119void FrameLoaderClientWinCE::postProgressEstimateChangedNotification()
120{
121    notImplemented();
122}
123
124void FrameLoaderClientWinCE::postProgressFinishedNotification()
125{
126    notImplemented();
127}
128
129void FrameLoaderClientWinCE::frameLoaderDestroyed()
130{
131    m_webView = 0;
132    m_frame = 0;
133    delete this;
134}
135
136void FrameLoaderClientWinCE::dispatchDidReceiveResponse(DocumentLoader*, unsigned long, const ResourceResponse& response)
137{
138    m_response = response;
139}
140
141void FrameLoaderClientWinCE::dispatchDecidePolicyForResponse(FramePolicyFunction policyFunction, const WebCore::ResourceResponse& response, const WebCore::ResourceRequest&)
142{
143    if (canShowMIMEType(response.mimeType()))
144        (m_frame->loader()->policyChecker()->*policyFunction)(PolicyUse);
145    else
146        (m_frame->loader()->policyChecker()->*policyFunction)(PolicyDownload);
147}
148
149void FrameLoaderClientWinCE::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction policyFunction, const NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<FormState>, const String&)
150{
151    (m_frame->loader()->policyChecker()->*policyFunction)(PolicyUse);
152}
153
154void FrameLoaderClientWinCE::dispatchDecidePolicyForNavigationAction(FramePolicyFunction policyFunction, const NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<FormState>)
155{
156    (m_frame->loader()->policyChecker()->*policyFunction)(PolicyUse);
157}
158
159void FrameLoaderClientWinCE::dispatchWillSubmitForm(FramePolicyFunction policyFunction, PassRefPtr<FormState>)
160{
161    (m_frame->loader()->policyChecker()->*policyFunction)(PolicyUse);
162}
163
164PassRefPtr<Widget> FrameLoaderClientWinCE::createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool)
165{
166    return 0;
167}
168
169PassRefPtr<Frame> FrameLoaderClientWinCE::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
170                                                 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
171{
172    return m_webView->createFrame(url, name, ownerElement, referrer, allowsScrolling, marginWidth, marginHeight);
173}
174
175void FrameLoaderClientWinCE::didTransferChildFrameToNewDocument(Page*)
176{
177}
178
179void FrameLoaderClientWinCE::transferLoadingResourceFromPage(unsigned long, DocumentLoader*, const WebCore::ResourceRequest&, Page*)
180{
181}
182
183void FrameLoaderClientWinCE::redirectDataToPlugin(Widget* pluginWidget)
184{
185    ASSERT(!m_pluginView);
186    m_pluginView = static_cast<PluginView*>(pluginWidget);
187    m_hasSentResponseToPlugin = false;
188}
189
190PassRefPtr<Widget> FrameLoaderClientWinCE::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL&, const Vector<String>&, const Vector<String>&)
191{
192    notImplemented();
193    return 0;
194}
195
196ObjectContentType FrameLoaderClientWinCE::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
197{
198    return FrameLoader::defaultObjectContentType(url, mimeType, shouldPreferPlugInsForImages);
199}
200
201String FrameLoaderClientWinCE::overrideMediaType() const
202{
203    notImplemented();
204    return String();
205}
206
207void FrameLoaderClientWinCE::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*)
208{
209    notImplemented();
210}
211
212void FrameLoaderClientWinCE::documentElementAvailable()
213{
214    notImplemented();
215}
216
217void FrameLoaderClientWinCE::didPerformFirstNavigation() const
218{
219    notImplemented();
220}
221
222void FrameLoaderClientWinCE::registerForIconNotification(bool)
223{
224    notImplemented();
225}
226
227void FrameLoaderClientWinCE::setMainFrameDocumentReady(bool)
228{
229    notImplemented();
230}
231
232bool FrameLoaderClientWinCE::hasWebView() const
233{
234    return true;
235}
236
237void FrameLoaderClientWinCE::dispatchDidFinishLoad()
238{
239    notImplemented();
240}
241
242void FrameLoaderClientWinCE::frameLoadCompleted()
243{
244    notImplemented();
245}
246
247void FrameLoaderClientWinCE::saveViewStateToItem(HistoryItem*)
248{
249    notImplemented();
250}
251
252void FrameLoaderClientWinCE::restoreViewState()
253{
254    notImplemented();
255}
256
257bool FrameLoaderClientWinCE::shouldGoToHistoryItem(HistoryItem* item) const
258{
259    return item;
260}
261
262bool FrameLoaderClientWinCE::shouldStopLoadingForHistoryItem(HistoryItem* item) const
263{
264    return true;
265}
266
267void FrameLoaderClientWinCE::dispatchDidAddBackForwardItem(HistoryItem*) const
268{
269}
270
271void FrameLoaderClientWinCE::dispatchDidRemoveBackForwardItem(HistoryItem*) const
272{
273}
274
275void FrameLoaderClientWinCE::dispatchDidChangeBackForwardIndex() const
276{
277}
278
279void FrameLoaderClientWinCE::didDisplayInsecureContent()
280{
281    notImplemented();
282}
283
284void FrameLoaderClientWinCE::didRunInsecureContent(SecurityOrigin*, const KURL&)
285{
286    notImplemented();
287}
288
289void FrameLoaderClientWinCE::makeRepresentation(DocumentLoader*)
290{
291    notImplemented();
292}
293
294void FrameLoaderClientWinCE::forceLayout()
295{
296    notImplemented();
297}
298
299void FrameLoaderClientWinCE::forceLayoutForNonHTML()
300{
301    notImplemented();
302}
303
304void FrameLoaderClientWinCE::setCopiesOnScroll()
305{
306    notImplemented();
307}
308
309void FrameLoaderClientWinCE::detachedFromParent2()
310{
311    notImplemented();
312}
313
314void FrameLoaderClientWinCE::detachedFromParent3()
315{
316    notImplemented();
317}
318
319void FrameLoaderClientWinCE::dispatchDidHandleOnloadEvents()
320{
321    notImplemented();
322}
323
324void FrameLoaderClientWinCE::dispatchDidReceiveServerRedirectForProvisionalLoad()
325{
326    notImplemented();
327}
328
329void FrameLoaderClientWinCE::dispatchDidCancelClientRedirect()
330{
331    notImplemented();
332}
333
334void FrameLoaderClientWinCE::dispatchWillPerformClientRedirect(const KURL&, double, double)
335{
336    notImplemented();
337}
338
339void FrameLoaderClientWinCE::dispatchDidChangeLocationWithinPage()
340{
341    notImplemented();
342}
343
344void FrameLoaderClientWinCE::dispatchDidPushStateWithinPage()
345{
346    notImplemented();
347}
348
349void FrameLoaderClientWinCE::dispatchDidReplaceStateWithinPage()
350{
351    notImplemented();
352}
353
354void FrameLoaderClientWinCE::dispatchDidPopStateWithinPage()
355{
356    notImplemented();
357}
358
359void FrameLoaderClientWinCE::dispatchWillClose()
360{
361    notImplemented();
362}
363
364void FrameLoaderClientWinCE::dispatchDidReceiveIcon()
365{
366    notImplemented();
367}
368
369void FrameLoaderClientWinCE::dispatchDidStartProvisionalLoad()
370{
371    notImplemented();
372}
373
374void FrameLoaderClientWinCE::dispatchDidReceiveTitle(const StringWithDirection&)
375{
376    notImplemented();
377}
378
379void FrameLoaderClientWinCE::dispatchDidChangeIcons()
380{
381    notImplemented();
382}
383
384void FrameLoaderClientWinCE::dispatchDidCommitLoad()
385{
386    notImplemented();
387}
388
389void FrameLoaderClientWinCE::dispatchDidFinishDocumentLoad()
390{
391    notImplemented();
392}
393
394void FrameLoaderClientWinCE::dispatchDidFirstLayout()
395{
396    notImplemented();
397}
398
399void FrameLoaderClientWinCE::dispatchDidFirstVisuallyNonEmptyLayout()
400{
401    notImplemented();
402}
403
404void FrameLoaderClientWinCE::dispatchShow()
405{
406    notImplemented();
407}
408
409void FrameLoaderClientWinCE::cancelPolicyCheck()
410{
411    notImplemented();
412}
413
414void FrameLoaderClientWinCE::dispatchDidLoadMainResource(DocumentLoader*)
415{
416    notImplemented();
417}
418
419void FrameLoaderClientWinCE::revertToProvisionalState(DocumentLoader*)
420{
421    notImplemented();
422}
423
424void FrameLoaderClientWinCE::willChangeTitle(DocumentLoader*)
425{
426    notImplemented();
427}
428
429void FrameLoaderClientWinCE::didChangeTitle(DocumentLoader* documentLoader)
430{
431    setTitle(documentLoader->title(), documentLoader->url());
432}
433
434bool FrameLoaderClientWinCE::canHandleRequest(const WebCore::ResourceRequest&) const
435{
436    notImplemented();
437    return true;
438}
439
440bool FrameLoaderClientWinCE::canShowMIMEType(const String& type) const
441{
442    return (MIMETypeRegistry::isSupportedImageMIMEType(type)
443            || MIMETypeRegistry::isSupportedNonImageMIMEType(type)
444            || MIMETypeRegistry::isSupportedMediaMIMEType(type)
445            || PluginDatabase::installedPlugins()->isMIMETypeRegistered(type));
446}
447
448bool FrameLoaderClientWinCE::canShowMIMETypeAsHTML(const String&) const
449{
450    notImplemented();
451    return false;
452}
453
454bool FrameLoaderClientWinCE::representationExistsForURLScheme(const String&) const
455{
456    notImplemented();
457    return false;
458}
459
460String FrameLoaderClientWinCE::generatedMIMETypeForURLScheme(const String&) const
461{
462    notImplemented();
463    return String();
464}
465
466void FrameLoaderClientWinCE::finishedLoading(DocumentLoader* documentLoader)
467{
468    if (!m_pluginView) {
469        documentLoader->writer()->setEncoding(m_response.textEncodingName(), false);
470        return;
471    }
472
473    m_pluginView->didFinishLoading();
474    m_pluginView = 0;
475    m_hasSentResponseToPlugin = false;
476}
477
478void FrameLoaderClientWinCE::provisionalLoadStarted()
479{
480    notImplemented();
481}
482
483void FrameLoaderClientWinCE::didFinishLoad()
484{
485    notImplemented();
486}
487
488void FrameLoaderClientWinCE::prepareForDataSourceReplacement()
489{
490    notImplemented();
491}
492
493void FrameLoaderClientWinCE::setTitle(const StringWithDirection&, const KURL&)
494{
495    notImplemented();
496}
497
498void FrameLoaderClientWinCE::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long, int)
499{
500    notImplemented();
501}
502
503void FrameLoaderClientWinCE::dispatchDidFinishLoading(DocumentLoader*, unsigned long)
504{
505    notImplemented();
506}
507
508void FrameLoaderClientWinCE::dispatchDidFailLoading(DocumentLoader*, unsigned long, const ResourceError&)
509{
510    notImplemented();
511}
512
513bool FrameLoaderClientWinCE::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int)
514{
515    notImplemented();
516    return false;
517}
518
519void FrameLoaderClientWinCE::dispatchDidFailProvisionalLoad(const ResourceError& error)
520{
521    dispatchDidFailLoad(error);
522}
523
524void FrameLoaderClientWinCE::dispatchDidFailLoad(const ResourceError&)
525{
526    notImplemented();
527}
528
529void FrameLoaderClientWinCE::download(ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
530{
531    notImplemented();
532}
533
534ResourceError FrameLoaderClientWinCE::cancelledError(const WebCore::ResourceRequest&)
535{
536    return ResourceError();
537}
538
539ResourceError FrameLoaderClientWinCE::blockedError(const WebCore::ResourceRequest&)
540{
541    return ResourceError();
542}
543
544ResourceError FrameLoaderClientWinCE::cannotShowURLError(const WebCore::ResourceRequest&)
545{
546    return ResourceError();
547}
548
549ResourceError FrameLoaderClientWinCE::interruptForPolicyChangeError(const WebCore::ResourceRequest&)
550{
551    return ResourceError();
552}
553
554ResourceError FrameLoaderClientWinCE::cannotShowMIMETypeError(const WebCore::ResourceResponse&)
555{
556    return ResourceError();
557}
558
559ResourceError FrameLoaderClientWinCE::fileDoesNotExistError(const WebCore::ResourceResponse&)
560{
561    return ResourceError();
562}
563
564ResourceError FrameLoaderClientWinCE::pluginWillHandleLoadError(const WebCore::ResourceResponse&)
565{
566    return ResourceError();
567}
568
569bool FrameLoaderClientWinCE::shouldFallBack(const ResourceError& error)
570{
571    return !(error.isCancellation());
572}
573
574bool FrameLoaderClientWinCE::canCachePage() const
575{
576    return true;
577}
578
579Frame* FrameLoaderClientWinCE::dispatchCreatePage(const NavigationAction&)
580{
581    notImplemented();
582    return 0;
583}
584
585void FrameLoaderClientWinCE::dispatchUnableToImplementPolicy(const ResourceError&)
586{
587    notImplemented();
588}
589
590void FrameLoaderClientWinCE::setMainDocumentError(DocumentLoader*, const ResourceError& error)
591{
592    if (!m_pluginView)
593        return;
594
595    m_pluginView->didFail(error);
596    m_pluginView = 0;
597    m_hasSentResponseToPlugin = false;
598}
599
600void FrameLoaderClientWinCE::startDownload(const WebCore::ResourceRequest&)
601{
602    notImplemented();
603}
604
605void FrameLoaderClientWinCE::updateGlobalHistory()
606{
607    notImplemented();
608}
609
610void FrameLoaderClientWinCE::updateGlobalHistoryRedirectLinks()
611{
612    notImplemented();
613}
614
615void FrameLoaderClientWinCE::savePlatformDataToCachedFrame(CachedFrame*)
616{
617    notImplemented();
618}
619
620void FrameLoaderClientWinCE::transitionToCommittedFromCachedFrame(CachedFrame*)
621{
622    notImplemented();
623}
624
625void FrameLoaderClientWinCE::transitionToCommittedForNewPage()
626{
627    Page* page = m_frame->page();
628    ASSERT(page);
629
630    bool isMainFrame = m_frame == page->mainFrame();
631
632    m_frame->setView(0);
633
634    RefPtr<FrameView> frameView;
635    if (isMainFrame) {
636        RECT rect;
637        m_webView->frameRect(&rect);
638        frameView = FrameView::create(m_frame, IntRect(rect).size());
639    } else
640        frameView = FrameView::create(m_frame);
641
642    m_frame->setView(frameView);
643
644    if (m_frame->ownerRenderer())
645        m_frame->ownerRenderer()->setWidget(frameView);
646}
647
648void FrameLoaderClientWinCE::didSaveToPageCache()
649{
650}
651
652void FrameLoaderClientWinCE::didRestoreFromPageCache()
653{
654}
655
656void FrameLoaderClientWinCE::dispatchDidBecomeFrameset(bool)
657{
658}
659
660PassRefPtr<WebCore::FrameNetworkingContext> FrameLoaderClientWinCE::createNetworkingContext()
661{
662    return FrameNetworkingContextWinCE::create(m_frame, userAgent(KURL()));
663}
664
665} // namespace WebKit
666