df7597847ab3254016eb322ecc3bc5abe8a81784
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebCoreSupport / WebFrameLoaderClient.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "WebFrameLoaderClient.h"
27
28 #define DISABLE_NOT_IMPLEMENTED_WARNINGS 1
29 #include "NotImplemented.h"
30
31 #include "AuthenticationManager.h"
32 #include "DataReference.h"
33 #include "InjectedBundleUserMessageCoders.h"
34 #include "PlatformCertificateInfo.h"
35 #include "PluginView.h"
36 #include "StringPairVector.h"
37 #include "WebContextMessages.h"
38 #include "WebCoreArgumentCoders.h"
39 #include "WebErrors.h"
40 #include "WebEvent.h"
41 #include "WebFrame.h"
42 #include "WebFrameNetworkingContext.h"
43 #include "WebNavigationDataStore.h"
44 #include "WebPage.h"
45 #include "WebPageProxyMessages.h"
46 #include "WebProcess.h"
47 #include "WebProcessProxyMessageKinds.h"
48 #include "WebProcessProxyMessages.h"
49 #include <JavaScriptCore/APICast.h>
50 #include <JavaScriptCore/JSObject.h>
51 #include <WebCore/Chrome.h>
52 #include <WebCore/DOMWrapperWorld.h>
53 #include <WebCore/DocumentLoader.h>
54 #include <WebCore/FormState.h>
55 #include <WebCore/Frame.h>
56 #include <WebCore/FrameLoadRequest.h>
57 #include <WebCore/FrameView.h>
58 #include <WebCore/HTMLAppletElement.h>
59 #include <WebCore/HTMLFormElement.h>
60 #include <WebCore/HistoryItem.h>
61 #include <WebCore/MIMETypeRegistry.h>
62 #include <WebCore/MouseEvent.h>
63 #include <WebCore/Page.h>
64 #include <WebCore/PluginData.h>
65 #include <WebCore/ProgressTracker.h>
66 #include <WebCore/ResourceError.h>
67 #include <WebCore/UIEventWithKeyState.h>
68 #include <WebCore/Widget.h>
69 #include <WebCore/WindowFeatures.h>
70
71 using namespace WebCore;
72
73 namespace WebKit {
74
75 WebFrameLoaderClient::WebFrameLoaderClient(WebFrame* frame)
76     : m_frame(frame)
77     , m_hasSentResponseToPluginView(false)
78     , m_frameHasCustomRepresentation(false)
79 {
80 }
81
82 WebFrameLoaderClient::~WebFrameLoaderClient()
83 {
84 }
85     
86 void WebFrameLoaderClient::frameLoaderDestroyed()
87 {
88     m_frame->invalidate();
89
90     // Balances explicit ref() in WebFrame::createMainFrame and WebFrame::createSubframe.
91     m_frame->deref();
92 }
93
94 bool WebFrameLoaderClient::hasHTMLView() const
95 {
96     return !m_frameHasCustomRepresentation;
97 }
98
99 bool WebFrameLoaderClient::hasWebView() const
100 {
101     return m_frame->page();
102 }
103
104 void WebFrameLoaderClient::makeRepresentation(DocumentLoader*)
105 {
106     notImplemented();
107 }
108
109 void WebFrameLoaderClient::forceLayout()
110 {
111     notImplemented();
112 }
113
114 void WebFrameLoaderClient::forceLayoutForNonHTML()
115 {
116     notImplemented();
117 }
118
119 void WebFrameLoaderClient::setCopiesOnScroll()
120 {
121     notImplemented();
122 }
123
124 void WebFrameLoaderClient::detachedFromParent2()
125 {
126     WebPage* webPage = m_frame->page();
127     if (!webPage)
128         return;
129
130     RefPtr<APIObject> userData;
131
132     // Notify the bundle client.
133     webPage->injectedBundleLoaderClient().didRemoveFrameFromHierarchy(webPage, m_frame, userData);
134
135     // Notify the UIProcess.
136     webPage->send(Messages::WebPageProxy::DidRemoveFrameFromHierarchy(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
137
138 }
139
140 void WebFrameLoaderClient::detachedFromParent3()
141 {
142     notImplemented();
143 }
144
145 void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest& request)
146 {
147     WebPage* webPage = m_frame->page();
148     if (!webPage)
149         return;
150
151     webPage->send(Messages::WebPageProxy::DidInitiateLoadForResource(m_frame->frameID(), identifier, request));
152 }
153
154 void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
155 {
156     WebPage* webPage = m_frame->page();
157     if (!webPage)
158         return;
159
160     if (!webPage->injectedBundleLoaderClient().shouldLoadResourceForFrame(webPage, m_frame, request.url().string())) {
161         request = ResourceRequest();
162         // FIXME: We should probably send a message saying we cancelled the request for the resource.
163         return;
164     }
165
166     webPage->send(Messages::WebPageProxy::DidSendRequestForResource(m_frame->frameID(), identifier, request, redirectResponse));
167 }
168
169 bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier)
170 {
171     return true;
172 }
173
174 void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge& challenge)
175 {
176     // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
177     // Once we do, we might need to make sure authentication fits with our solution.
178
179     WebPage* webPage = m_frame->page();
180     if (!webPage)
181         return;
182
183     AuthenticationManager::shared().didReceiveAuthenticationChallenge(m_frame, challenge);
184 }
185
186 void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&)    
187 {
188     notImplemented();
189 }
190
191 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
192 bool WebFrameLoaderClient::canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long, const ProtectionSpace& protectionSpace)
193 {
194     // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
195     // Once we do, we might need to make sure authentication fits with our solution.
196     
197     WebPage* webPage = m_frame->page();
198     if (!webPage)
199         return false;
200         
201     bool canAuthenticate;
202     if (!webPage->sendSync(Messages::WebPageProxy::CanAuthenticateAgainstProtectionSpaceInFrame(m_frame->frameID(), protectionSpace), Messages::WebPageProxy::CanAuthenticateAgainstProtectionSpaceInFrame::Reply(canAuthenticate)))
203         return false;
204     
205     return canAuthenticate;
206 }
207 #endif
208
209 void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse& response)
210 {
211     WebPage* webPage = m_frame->page();
212     if (!webPage)
213         return;
214
215     webPage->send(Messages::WebPageProxy::DidReceiveResponseForResource(m_frame->frameID(), identifier, response));
216 }
217
218 void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived)
219 {
220     WebPage* webPage = m_frame->page();
221     if (!webPage)
222         return;
223
224     webPage->send(Messages::WebPageProxy::DidReceiveContentLengthForResource(m_frame->frameID(), identifier, lengthReceived));
225 }
226
227 void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
228 {
229     WebPage* webPage = m_frame->page();
230     if (!webPage)
231         return;
232
233     webPage->send(Messages::WebPageProxy::DidFinishLoadForResource(m_frame->frameID(), identifier));
234 }
235
236 void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& error)
237 {
238     WebPage* webPage = m_frame->page();
239     if (!webPage)
240         return;
241
242     webPage->send(Messages::WebPageProxy::DidFailLoadForResource(m_frame->frameID(), identifier, error));
243 }
244
245 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length)
246 {
247     notImplemented();
248     return false;
249 }
250
251 void WebFrameLoaderClient::dispatchDidLoadResourceByXMLHttpRequest(unsigned long identifier, const String&)
252 {
253     notImplemented();
254 }
255
256 void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
257 {
258     WebPage* webPage = m_frame->page();
259     if (!webPage)
260         return;
261
262     // Notify the bundle client.
263     webPage->injectedBundleLoaderClient().didHandleOnloadEventsForFrame(webPage, m_frame);
264 }
265
266 void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
267 {
268     WebPage* webPage = m_frame->page();
269     if (!webPage)
270         return;
271
272     DocumentLoader* provisionalLoader = m_frame->coreFrame()->loader()->provisionalDocumentLoader();
273     const String& url = provisionalLoader->url().string();
274     RefPtr<APIObject> userData;
275
276     // Notify the bundle client.
277     webPage->injectedBundleLoaderClient().didReceiveServerRedirectForProvisionalLoadForFrame(webPage, m_frame, userData);
278
279     // Notify the UIProcess.
280     webPage->send(Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame(m_frame->frameID(), url, InjectedBundleUserMessageEncoder(userData.get())));
281 }
282
283 void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
284 {
285     WebPage* webPage = m_frame->page();
286     if (!webPage)
287         return;
288
289     // Notify the bundle client.
290     webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(webPage, m_frame);
291 }
292
293 void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL& url, double interval, double fireDate)
294 {
295     WebPage* webPage = m_frame->page();
296     if (!webPage)
297         return;
298
299     // Notify the bundle client.
300     webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(webPage, m_frame, url.string(), interval, fireDate);
301 }
302
303 void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
304 {
305     WebPage* webPage = m_frame->page();
306     if (!webPage)
307         return;
308
309     RefPtr<APIObject> userData;
310
311     // Notify the bundle client.
312     webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationAnchorNavigation, userData);
313
314     // Notify the UIProcess.
315     webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationAnchorNavigation, m_frame->coreFrame()->loader()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
316 }
317
318 void WebFrameLoaderClient::dispatchDidPushStateWithinPage()
319 {
320     WebPage* webPage = m_frame->page();
321     if (!webPage)
322         return;
323
324     RefPtr<APIObject> userData;
325
326     // Notify the bundle client.
327     webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStatePush, userData);
328
329     // Notify the UIProcess.
330     webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationSessionStatePush, m_frame->coreFrame()->loader()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
331 }
332
333 void WebFrameLoaderClient::dispatchDidReplaceStateWithinPage()
334 {
335     WebPage* webPage = m_frame->page();
336     if (!webPage)
337         return;
338
339     RefPtr<APIObject> userData;
340
341     // Notify the bundle client.
342     webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStateReplace, userData);
343
344     // Notify the UIProcess.
345     webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationSessionStateReplace, m_frame->coreFrame()->loader()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
346 }
347
348 void WebFrameLoaderClient::dispatchDidPopStateWithinPage()
349 {
350     WebPage* webPage = m_frame->page();
351     if (!webPage)
352         return;
353
354     RefPtr<APIObject> userData;
355
356     // Notify the bundle client.
357     webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStatePop, userData);
358
359     // Notify the UIProcess.
360     webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationSessionStatePop, m_frame->coreFrame()->loader()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
361 }
362
363 void WebFrameLoaderClient::dispatchWillClose()
364 {
365     notImplemented();
366 }
367
368 void WebFrameLoaderClient::dispatchDidReceiveIcon()
369 {
370     notImplemented();
371 }
372
373 void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
374 {
375     WebPage* webPage = m_frame->page();
376     if (!webPage)
377         return;
378     webPage->findController().hideFindUI();
379     
380     DocumentLoader* provisionalLoader = m_frame->coreFrame()->loader()->provisionalDocumentLoader();
381     const String& url = provisionalLoader->url().string();
382     RefPtr<APIObject> userData;
383
384     // Notify the bundle client.
385     webPage->injectedBundleLoaderClient().didStartProvisionalLoadForFrame(webPage, m_frame, userData);
386
387     bool loadingSubstituteDataForUnreachableURL = !provisionalLoader->unreachableURL().isNull();
388
389     webPage->sandboxExtensionTracker().didStartProvisionalLoad(m_frame);
390
391     // Notify the UIProcess.
392     webPage->send(Messages::WebPageProxy::DidStartProvisionalLoadForFrame(m_frame->frameID(), url, loadingSubstituteDataForUnreachableURL, InjectedBundleUserMessageEncoder(userData.get())));
393 }
394
395 void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title)
396 {
397     WebPage* webPage = m_frame->page();
398     if (!webPage)
399         return;
400
401     RefPtr<APIObject> userData;
402
403     // Notify the bundle client.
404     webPage->injectedBundleLoaderClient().didReceiveTitleForFrame(webPage, title, m_frame, userData);
405
406     // Notify the UIProcess.
407     webPage->send(Messages::WebPageProxy::DidReceiveTitleForFrame(m_frame->frameID(), title, InjectedBundleUserMessageEncoder(userData.get())));
408 }
409
410 void WebFrameLoaderClient::dispatchDidChangeIcons()
411 {
412     notImplemented();
413 }
414
415 void WebFrameLoaderClient::dispatchDidCommitLoad()
416 {
417     WebPage* webPage = m_frame->page();
418     if (!webPage)
419         return;
420
421     const ResourceResponse& response = m_frame->coreFrame()->loader()->documentLoader()->response();
422     RefPtr<APIObject> userData;
423
424     // Notify the bundle client.
425     webPage->injectedBundleLoaderClient().didCommitLoadForFrame(webPage, m_frame, userData);
426
427     webPage->sandboxExtensionTracker().didCommitProvisionalLoad(m_frame);
428
429     // Notify the UIProcess.
430
431     webPage->send(Messages::WebPageProxy::DidCommitLoadForFrame(m_frame->frameID(), response.mimeType(), m_frameHasCustomRepresentation, PlatformCertificateInfo(response), InjectedBundleUserMessageEncoder(userData.get())));
432
433     // Only restore the scale factor for standard frame loads (of the main frame).
434     if (m_frame->isMainFrame() && m_frame->coreFrame()->loader()->loadType() == FrameLoadTypeStandard) {
435         if (m_frame->coreFrame()->pageScaleFactor() != 1)
436             webPage->scaleWebView(1, IntPoint());
437     }
438 }
439
440 void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
441 {
442     WebPage* webPage = m_frame->page();
443     if (!webPage)
444         return;
445
446     RefPtr<APIObject> userData;
447
448     // Notify the bundle client.
449     webPage->injectedBundleLoaderClient().didFailProvisionalLoadWithErrorForFrame(webPage, m_frame, error, userData);
450
451     webPage->sandboxExtensionTracker().didFailProvisionalLoad(m_frame);
452
453     // Notify the UIProcess.
454     webPage->send(Messages::WebPageProxy::DidFailProvisionalLoadForFrame(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
455     
456     // If we have a load listener, notify it.
457     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
458         loadListener->didFailLoad(m_frame, error.isCancellation());
459 }
460
461 void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
462 {
463     WebPage* webPage = m_frame->page();
464     if (!webPage)
465         return;
466
467     RefPtr<APIObject> userData;
468
469     // Notify the bundle client.
470     webPage->injectedBundleLoaderClient().didFailLoadWithErrorForFrame(webPage, m_frame, error, userData);
471
472     // Notify the UIProcess.
473     webPage->send(Messages::WebPageProxy::DidFailLoadForFrame(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
474
475     // If we have a load listener, notify it.
476     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
477         loadListener->didFailLoad(m_frame, error.isCancellation());
478 }
479
480 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
481 {
482     WebPage* webPage = m_frame->page();
483     if (!webPage)
484         return;
485
486     RefPtr<APIObject> userData;
487
488     // Notify the bundle client.
489     webPage->injectedBundleLoaderClient().didFinishDocumentLoadForFrame(webPage, m_frame, userData);
490
491     // Notify the UIProcess.
492     webPage->send(Messages::WebPageProxy::DidFinishDocumentLoadForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
493 }
494
495 void WebFrameLoaderClient::dispatchDidFinishLoad()
496 {
497     WebPage* webPage = m_frame->page();
498     if (!webPage)
499         return;
500
501     RefPtr<APIObject> userData;
502
503     // Notify the bundle client.
504     webPage->injectedBundleLoaderClient().didFinishLoadForFrame(webPage, m_frame, userData);
505
506     // Notify the UIProcess.
507     webPage->send(Messages::WebPageProxy::DidFinishLoadForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
508
509     // If we have a load listener, notify it.
510     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
511         loadListener->didFinishLoad(m_frame);
512 }
513
514 void WebFrameLoaderClient::dispatchDidFirstLayout()
515 {
516     WebPage* webPage = m_frame->page();
517     if (!webPage)
518         return;
519
520     RefPtr<APIObject> userData;
521
522     // Notify the bundle client.
523     webPage->injectedBundleLoaderClient().didFirstLayoutForFrame(webPage, m_frame, userData);
524
525     // Notify the UIProcess.
526     webPage->send(Messages::WebPageProxy::DidFirstLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
527 }
528
529 void WebFrameLoaderClient::dispatchDidFirstVisuallyNonEmptyLayout()
530 {
531     WebPage* webPage = m_frame->page();
532     if (!webPage)
533         return;
534
535     RefPtr<APIObject> userData;
536
537     // Notify the bundle client.
538     webPage->injectedBundleLoaderClient().didFirstVisuallyNonEmptyLayoutForFrame(webPage, m_frame, userData);
539
540     // Notify the UIProcess.
541     webPage->send(Messages::WebPageProxy::DidFirstVisuallyNonEmptyLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
542 }
543
544 Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
545 {
546     WebPage* webPage = m_frame->page();
547     if (!webPage)
548         return 0;
549
550     // Just call through to the chrome client.
551     Page* newPage = webPage->corePage()->chrome()->createWindow(m_frame->coreFrame(), FrameLoadRequest(m_frame->coreFrame()->document()->securityOrigin()), WindowFeatures(), navigationAction);
552     if (!newPage)
553         return 0;
554     
555     return newPage->mainFrame();
556 }
557
558 void WebFrameLoaderClient::dispatchShow()
559 {
560     WebPage* webPage = m_frame->page();
561     if (!webPage)
562         return;
563
564     webPage->show();
565 }
566
567 uint32_t modifiersForNavigationAction(const NavigationAction& navigationAction)
568 {
569     uint32_t modifiers = 0;
570     if (const UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(navigationAction.event()))) {
571         if (keyStateEvent->shiftKey())
572             modifiers |= WebEvent::ShiftKey;
573         if (keyStateEvent->ctrlKey())
574             modifiers |= WebEvent::ControlKey;
575         if (keyStateEvent->altKey())
576             modifiers |= WebEvent::AltKey;
577         if (keyStateEvent->metaKey())
578             modifiers |= WebEvent::MetaKey;
579     }
580
581     return modifiers;
582 }
583
584 static const MouseEvent* findMouseEvent(const Event* event)
585 {
586     for (const Event* e = event; e; e = e->underlyingEvent()) {
587         if (e->isMouseEvent())
588             return static_cast<const MouseEvent*>(e);
589     }
590     return 0;
591 }
592
593 int32_t mouseButtonForNavigationAction(const NavigationAction& navigationAction)
594 {
595     const MouseEvent* mouseEvent = findMouseEvent(navigationAction.event());
596     if (!mouseEvent)
597         return -1;
598
599     if (!mouseEvent->buttonDown())
600         return -1;
601
602     return mouseEvent->button();
603 }
604
605 void WebFrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& MIMEType, const ResourceRequest& request)
606 {
607     if (m_frame->coreFrame()->loader()->documentLoader()->url().isEmpty() && request.url() == blankURL()) {
608         // WebKit2 loads initial about:blank documents synchronously, without consulting the policy delegate
609         ASSERT(m_frame->coreFrame()->loader()->stateMachine()->committingFirstRealLoad());
610         (m_frame->coreFrame()->loader()->policyChecker()->*function)(PolicyUse);
611         return;
612     }
613     
614     WebPage* webPage = m_frame->page();
615     if (!webPage)
616         return;
617
618     uint64_t listenerID = m_frame->setUpPolicyListener(function);
619     const String& url = request.url().string(); // FIXME: Pass entire request.
620     if (!url)
621         return;
622
623     bool receivedPolicyAction;
624     uint64_t policyAction;
625     uint64_t downloadID;
626     if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForMIMEType(m_frame->frameID(), MIMEType, url, listenerID), Messages::WebPageProxy::DecidePolicyForMIMEType::Reply(receivedPolicyAction, policyAction, downloadID)))
627         return;
628
629     // We call this synchronously because CFNetwork can only convert a loading connection to a download from its didReceiveResponse callback.
630     if (receivedPolicyAction)
631         m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), downloadID);
632 }
633
634 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>, const String& frameName)
635 {
636     WebPage* webPage = m_frame->page();
637     if (!webPage)
638         return;
639
640     uint64_t listenerID = m_frame->setUpPolicyListener(function);
641
642     // FIXME: Pass more than just the navigation action type.
643     // FIXME: Pass the frame name.
644     const String& url = request.url().string(); // FIXME: Pass entire request.
645
646     uint32_t navigationType = static_cast<uint32_t>(navigationAction.type());
647     uint32_t modifiers = modifiersForNavigationAction(navigationAction);
648     int32_t mouseButton = mouseButtonForNavigationAction(navigationAction);
649
650     webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), navigationType, modifiers, mouseButton, url, listenerID));
651 }
652
653 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>)
654 {
655     if (m_frame->coreFrame()->loader()->documentLoader()->url().isEmpty() && request.url() == blankURL()) {
656         // WebKit2 loads initial about:blank documents synchronously, without consulting the policy delegate
657         ASSERT(m_frame->coreFrame()->loader()->stateMachine()->committingFirstRealLoad());
658         (m_frame->coreFrame()->loader()->policyChecker()->*function)(PolicyUse);
659         return;
660     }
661
662     // Always ignore requests with empty URLs.
663     if (request.isEmpty()) {
664         (m_frame->coreFrame()->loader()->policyChecker()->*function)(PolicyIgnore);
665         return;
666     }
667     
668     WebPage* webPage = m_frame->page();
669     if (!webPage)
670         return;
671
672     uint64_t listenerID = m_frame->setUpPolicyListener(function);
673
674     // FIXME: Pass more than just the navigation action type.
675     const String& url = request.url().string(); // FIXME: Pass entire request.
676
677     uint32_t navigationType = static_cast<uint32_t>(navigationAction.type());
678     uint32_t modifiers = modifiersForNavigationAction(navigationAction);
679     int32_t mouseButton = mouseButtonForNavigationAction(navigationAction);
680
681     webPage->send(Messages::WebPageProxy::DecidePolicyForNavigationAction(m_frame->frameID(), navigationType, modifiers, mouseButton, url, listenerID));
682 }
683
684 void WebFrameLoaderClient::cancelPolicyCheck()
685 {
686     m_frame->invalidatePolicyListener();
687 }
688
689 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&)
690 {
691     notImplemented();
692 }
693
694 void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> prpFormState)
695 {
696     WebPage* webPage = m_frame->page();
697     if (!webPage)
698         return;
699
700     // FIXME: Pass more of the form state.
701     RefPtr<FormState> formState = prpFormState;
702     
703     HTMLFormElement* form = formState->form();
704     WebFrame* sourceFrame = static_cast<WebFrameLoaderClient*>(formState->sourceFrame()->loader()->client())->webFrame();    
705     const Vector<std::pair<String, String> >& values = formState->textFieldValues();
706
707     RefPtr<APIObject> userData;
708     webPage->injectedBundleFormClient().willSubmitForm(webPage, form, m_frame, sourceFrame, values, userData);
709
710
711     uint64_t listenerID = m_frame->setUpPolicyListener(function);
712     StringPairVector valuesVector(values);
713
714     webPage->send(Messages::WebPageProxy::WillSubmitForm(m_frame->frameID(), sourceFrame->frameID(), valuesVector, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
715 }
716
717 void WebFrameLoaderClient::dispatchDidLoadMainResource(DocumentLoader*)
718 {
719     notImplemented();
720 }
721
722 void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader*)
723 {
724     notImplemented();
725 }
726
727 void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error)
728 {
729     if (!m_pluginView)
730         return;
731     
732     m_pluginView->manualLoadDidFail(error);
733     m_pluginView = 0;
734     m_hasSentResponseToPluginView = false;
735 }
736
737 void WebFrameLoaderClient::willChangeEstimatedProgress()
738 {
739     notImplemented();
740 }
741
742 void WebFrameLoaderClient::didChangeEstimatedProgress()
743 {
744     notImplemented();
745 }
746
747 void WebFrameLoaderClient::postProgressStartedNotification()
748 {
749     if (WebPage* webPage = m_frame->page())
750         webPage->send(Messages::WebPageProxy::DidStartProgress());
751 }
752
753 void WebFrameLoaderClient::postProgressEstimateChangedNotification()
754 {
755     if (WebPage* webPage = m_frame->page()) {
756         double progress = webPage->corePage()->progress()->estimatedProgress();
757         webPage->send(Messages::WebPageProxy::DidChangeProgress(progress));
758
759     }
760 }
761
762 void WebFrameLoaderClient::postProgressFinishedNotification()
763 {
764     if (WebPage* webPage = m_frame->page())
765         webPage->send(Messages::WebPageProxy::DidFinishProgress());
766 }
767
768 void WebFrameLoaderClient::setMainFrameDocumentReady(bool)
769 {
770     notImplemented();
771 }
772
773 void WebFrameLoaderClient::startDownload(const ResourceRequest& request)
774 {
775     m_frame->startDownload(request);
776 }
777
778 void WebFrameLoaderClient::willChangeTitle(DocumentLoader*)
779 {
780     notImplemented();
781 }
782
783 void WebFrameLoaderClient::didChangeTitle(DocumentLoader*)
784 {
785     notImplemented();
786 }
787
788 void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
789 {
790     // If we're loading a custom representation, we don't want to hand off the data to WebCore.
791     if (m_frameHasCustomRepresentation)
792         return;
793
794     if (!m_pluginView)
795         loader->commitData(data, length);
796
797     // If the document is a stand-alone media document, now is the right time to cancel the WebKit load.
798     // FIXME: This code should be shared across all ports. <http://webkit.org/b/48762>.
799     if (m_frame->coreFrame()->document()->isMediaDocument())
800         loader->cancelMainResourceLoad(pluginWillHandleLoadError(loader->response()));
801
802     // Calling commitData did not create the plug-in view.
803     if (!m_pluginView)
804         return;
805
806     if (!m_hasSentResponseToPluginView) {
807         m_pluginView->manualLoadDidReceiveResponse(loader->response());
808         // manualLoadDidReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
809         // setting up this stream can cause the main document load to be cancelled, setting m_pluginView
810         // to null
811         if (!m_pluginView)
812             return;
813         m_hasSentResponseToPluginView = true;
814     }
815     m_pluginView->manualLoadDidReceiveData(data, length);
816 }
817
818 void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
819 {
820     if (!m_pluginView) {
821         committedLoad(loader, 0, 0);
822
823         if (m_frameHasCustomRepresentation) {
824             WebPage* webPage = m_frame->page();
825             if (!webPage)
826                 return;
827
828             RefPtr<SharedBuffer> mainResourceData = loader->mainResourceData();
829             CoreIPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(mainResourceData ? mainResourceData->data() : 0), mainResourceData ? mainResourceData->size() : 0);
830             
831             webPage->send(Messages::WebPageProxy::DidFinishLoadingDataForCustomRepresentation(dataReference));
832         }
833
834         return;
835     }
836
837     m_pluginView->manualLoadDidFinishLoading();
838     m_pluginView = 0;
839     m_hasSentResponseToPluginView = false;
840 }
841
842 void WebFrameLoaderClient::updateGlobalHistory()
843 {
844     WebPage* webPage = m_frame->page();
845     if (!webPage)
846         return;
847
848     DocumentLoader* loader = m_frame->coreFrame()->loader()->documentLoader();
849
850     WebNavigationDataStore data;
851     data.url = loader->urlForHistory().string();
852     data.title = loader->title();
853
854     WebProcess::shared().connection()->send(Messages::WebContext::DidNavigateWithNavigationData(webPage->pageID(), data, m_frame->frameID()), 0);
855 }
856
857 void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
858 {
859     WebPage* webPage = m_frame->page();
860     if (!webPage)
861         return;
862
863     DocumentLoader* loader = m_frame->coreFrame()->loader()->documentLoader();
864     ASSERT(loader->unreachableURL().isEmpty());
865
866     // Client redirect
867     if (!loader->clientRedirectSourceForHistory().isNull()) {
868         WebProcess::shared().connection()->send(Messages::WebContext::DidPerformClientRedirect(webPage->pageID(),
869             loader->clientRedirectSourceForHistory(), loader->clientRedirectDestinationForHistory(), m_frame->frameID()), 0);
870     }
871
872     // Server redirect
873     if (!loader->serverRedirectSourceForHistory().isNull()) {
874         WebProcess::shared().connection()->send(Messages::WebContext::DidPerformServerRedirect(webPage->pageID(),
875             loader->serverRedirectSourceForHistory(), loader->serverRedirectDestinationForHistory(), m_frame->frameID()), 0);
876     }
877 }
878
879 bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem*) const
880 {
881     notImplemented();
882     return true;
883 }
884
885 void WebFrameLoaderClient::dispatchDidAddBackForwardItem(HistoryItem*) const
886 {
887     notImplemented();
888 }
889
890 void WebFrameLoaderClient::dispatchDidRemoveBackForwardItem(HistoryItem*) const
891 {
892     notImplemented();
893 }
894
895 void WebFrameLoaderClient::dispatchDidChangeBackForwardIndex() const
896 {
897     notImplemented();
898 }
899
900 void WebFrameLoaderClient::didDisplayInsecureContent()
901 {
902     WebPage* webPage = m_frame->page();
903     if (!webPage)
904         return;
905
906     RefPtr<APIObject> userData;
907
908     webPage->injectedBundleLoaderClient().didDisplayInsecureContentForFrame(webPage, m_frame, userData);
909
910     webPage->send(Messages::WebPageProxy::DidDisplayInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
911 }
912
913 void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin*)
914 {
915     WebPage* webPage = m_frame->page();
916     if (!webPage)
917         return;
918
919     RefPtr<APIObject> userData;
920
921     webPage->injectedBundleLoaderClient().didRunInsecureContentForFrame(webPage, m_frame, userData);
922
923     webPage->send(Messages::WebPageProxy::DidRunInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
924 }
925
926 ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request)
927 {
928     return WebKit::cancelledError(request);
929 }
930
931 ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request)
932 {
933     return WebKit::blockedError(request);
934 }
935
936 ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request)
937 {
938     return WebKit::cannotShowURLError(request);
939 }
940
941 ResourceError WebFrameLoaderClient::interruptForPolicyChangeError(const ResourceRequest& request)
942 {
943     return WebKit::interruptForPolicyChangeError(request);
944 }
945
946 ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response)
947 {
948     return WebKit::cannotShowMIMETypeError(response);
949 }
950
951 ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response)
952 {
953     return WebKit::fileDoesNotExistError(response);
954 }
955
956 ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse& response)
957 {
958     return WebKit::pluginWillHandleLoadError(response);
959 }
960
961 bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error)
962 {
963     DEFINE_STATIC_LOCAL(const ResourceError, cancelledError, (this->cancelledError(ResourceRequest())));
964     DEFINE_STATIC_LOCAL(const ResourceError, pluginWillHandleLoadError, (this->pluginWillHandleLoadError(ResourceResponse())));
965
966     if (error.errorCode() == cancelledError.errorCode() && error.domain() == cancelledError.domain())
967         return false;
968
969     if (error.errorCode() == pluginWillHandleLoadError.errorCode() && error.domain() == pluginWillHandleLoadError.domain())
970         return false;
971
972     return true;
973 }
974
975 bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest&) const
976 {
977     notImplemented();
978     return true;
979 }
980
981 bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const
982 {
983     notImplemented();
984     return true;
985 }
986
987 bool WebFrameLoaderClient::canShowMIMETypeAsHTML(const String& MIMEType) const
988 {
989     return true;
990 }
991
992 bool WebFrameLoaderClient::representationExistsForURLScheme(const String& URLScheme) const
993 {
994     notImplemented();
995     return false;
996 }
997
998 String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& URLScheme) const
999 {
1000     notImplemented();
1001     return String();
1002 }
1003
1004 void WebFrameLoaderClient::frameLoadCompleted()
1005 {
1006     notImplemented();
1007 }
1008
1009 void WebFrameLoaderClient::saveViewStateToItem(HistoryItem*)
1010 {
1011     notImplemented();
1012 }
1013
1014 void WebFrameLoaderClient::restoreViewState()
1015 {
1016     // Inform the UI process of the scale factor.
1017     double scaleFactor = m_frame->coreFrame()->loader()->history()->currentItem()->pageScaleFactor();
1018     m_frame->page()->send(Messages::WebPageProxy::ViewScaleFactorDidChange(scaleFactor));
1019 }
1020
1021 void WebFrameLoaderClient::provisionalLoadStarted()
1022 {
1023     notImplemented();
1024 }
1025
1026 void WebFrameLoaderClient::didFinishLoad()
1027 {
1028     // If we have a load listener, notify it.
1029     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
1030         loadListener->didFinishLoad(m_frame);
1031 }
1032
1033 void WebFrameLoaderClient::prepareForDataSourceReplacement()
1034 {
1035     notImplemented();
1036 }
1037
1038 PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& data)
1039 {
1040     return DocumentLoader::create(request, data);
1041 }
1042
1043 void WebFrameLoaderClient::setTitle(const String& title, const KURL& url)
1044 {
1045     WebPage* webPage = m_frame->page();
1046     if (!webPage)
1047         return;
1048
1049     WebProcess::shared().connection()->send(Messages::WebContext::DidUpdateHistoryTitle(webPage->pageID(),
1050         title, url.string(), m_frame->frameID()), 0);
1051 }
1052
1053 String WebFrameLoaderClient::userAgent(const KURL&)
1054 {
1055     WebPage* webPage = m_frame->page();
1056     if (!webPage)
1057         return String();
1058
1059     return webPage->userAgent();
1060 }
1061
1062 void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*)
1063 {
1064 }
1065
1066 void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*)
1067 {
1068 }
1069
1070 void WebFrameLoaderClient::transitionToCommittedForNewPage()
1071 {
1072     WebPage* webPage = m_frame->page();
1073     Color backgroundColor = webPage->drawsTransparentBackground() ? Color::transparent : Color::white;
1074
1075     bool isMainFrame = webPage->mainFrame() == m_frame;
1076
1077 #if ENABLE(TILED_BACKING_STORE)
1078     IntSize currentVisibleContentSize = m_frame->coreFrame()->view() ? m_frame->coreFrame()->view()->actualVisibleContentRect().size() : IntSize();
1079     m_frame->coreFrame()->createView(webPage->size(), backgroundColor, false, webPage->resizesToContentsLayoutSize(), isMainFrame && webPage->resizesToContentsEnabled());
1080
1081     if (isMainFrame && webPage->resizesToContentsEnabled()) {
1082         m_frame->coreFrame()->view()->setDelegatesScrolling(true);
1083         m_frame->coreFrame()->view()->setPaintsEntireContents(true);
1084     }
1085
1086     // The HistoryController will update the scroll position later if needed.
1087     m_frame->coreFrame()->view()->setActualVisibleContentRect(IntRect(IntPoint::zero(), currentVisibleContentSize));
1088 #else
1089     const String& mimeType = m_frame->coreFrame()->loader()->documentLoader()->response().mimeType();
1090     m_frameHasCustomRepresentation = isMainFrame && WebProcess::shared().shouldUseCustomRepresentationForMIMEType(mimeType);
1091
1092     m_frame->coreFrame()->createView(webPage->size(), backgroundColor, false, IntSize(), false);
1093 #endif
1094
1095     m_frame->coreFrame()->view()->setTransparent(!webPage->drawsBackground());
1096 }
1097
1098 void WebFrameLoaderClient::didSaveToPageCache()
1099 {
1100     WebPage* webPage = m_frame->page();
1101     if (!webPage)
1102         return;
1103
1104     if (m_frame->isMainFrame())
1105         return;
1106
1107     webPage->send(Messages::WebPageProxy::DidSaveFrameToPageCache(m_frame->frameID()));
1108 }
1109
1110 void WebFrameLoaderClient::didRestoreFromPageCache()
1111 {
1112     WebPage* webPage = m_frame->page();
1113     if (!webPage)
1114         return;
1115
1116     if (m_frame->isMainFrame())
1117         return;
1118
1119     WebFrame* parentFrame = static_cast<WebFrameLoaderClient*>(m_frame->coreFrame()->tree()->parent()->loader()->client())->webFrame();
1120     webPage->send(Messages::WebPageProxy::DidRestoreFrameFromPageCache(m_frame->frameID(), parentFrame->frameID()));
1121 }
1122
1123 void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool value)
1124 {
1125     WebPage* webPage = m_frame->page();
1126     if (!webPage)
1127         return;
1128
1129     webPage->send(Messages::WebPageProxy::FrameDidBecomeFrameSet(m_frame->frameID(), value));
1130 }
1131
1132 bool WebFrameLoaderClient::canCachePage() const
1133 {
1134     // We cannot cache frames that have custom representations because they are
1135     // rendered in the UIProcess. 
1136     return !m_frameHasCustomRepresentation;
1137 }
1138
1139 void WebFrameLoaderClient::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest& initialRequest, const ResourceResponse& response)
1140 {
1141     m_frame->convertHandleToDownload(handle, request, initialRequest, response);
1142 }
1143
1144 PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
1145                                                     const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
1146 {
1147     WebPage* webPage = m_frame->page();
1148
1149     RefPtr<WebFrame> subframe = WebFrame::createSubframe(webPage, name, ownerElement);
1150
1151     Frame* coreSubframe = subframe->coreFrame();
1152
1153      // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
1154     m_frame->coreFrame()->loader()->loadURLIntoChildFrame(url, referrer, coreSubframe);
1155
1156     // The frame's onload handler may have removed it from the document.
1157     if (!coreSubframe->tree()->parent())
1158         return 0;
1159
1160     return coreSubframe;
1161 }
1162
1163 void WebFrameLoaderClient::didTransferChildFrameToNewDocument(Page*)
1164 {
1165     notImplemented();
1166 }
1167
1168 void WebFrameLoaderClient::transferLoadingResourceFromPage(unsigned long, DocumentLoader*, const ResourceRequest&, Page*)
1169 {
1170     notImplemented();
1171 }
1172
1173 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugInElement* pluginElement, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
1174 {
1175     ASSERT(paramNames.size() == paramValues.size());
1176     
1177     WebPage* webPage = m_frame->page();
1178     ASSERT(webPage);
1179     
1180     Plugin::Parameters parameters;
1181     parameters.url = url;
1182     parameters.names = paramNames;
1183     parameters.values = paramValues;
1184     parameters.mimeType = mimeType;
1185     parameters.loadManually = loadManually;
1186
1187     // <rdar://problem/8440903>: AppleConnect has a bug where it does not
1188     // understand the parameter names specified in the <object> element that
1189     // embeds its plug-in. This hack works around the issue by converting the
1190     // parameter names to lowercase before passing them to the plug-in.
1191     // FIXME: This workaround should be dependent on site-specific quirks being
1192     // enabled. This requires adding this setting to WebKit2's WebPreferences
1193     // implementation. See <https://bugs.webkit.org/show_bug.cgi?id=46076>.
1194     if (equalIgnoringCase(mimeType, "application/x-snkp")) {
1195         for (size_t i = 0; i < paramNames.size(); ++i)
1196             parameters.names[i] = paramNames[i].lower();
1197     }
1198
1199     RefPtr<Plugin> plugin = webPage->createPlugin(parameters);
1200     if (!plugin)
1201         return 0;
1202     
1203     return PluginView::create(pluginElement, plugin.release(), parameters);
1204 }
1205
1206 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
1207 {
1208     ASSERT(!m_pluginView);
1209     ASSERT(pluginWidget);
1210     
1211     m_pluginView = static_cast<PluginView*>(pluginWidget);
1212 }
1213
1214 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* appletElement, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues)
1215 {
1216     return createPlugin(pluginSize, appletElement, KURL(), paramNames, paramValues, "application/x-java-applet", false);
1217 }
1218
1219 ObjectContentType WebFrameLoaderClient::objectContentType(const KURL& url, const String& mimeTypeIn)
1220 {
1221     // FIXME: This should be merged with WebCore::FrameLoader::defaultObjectContentType when the plugin code
1222     // is consolidated.
1223
1224     String mimeType = mimeTypeIn;
1225     if (mimeType.isEmpty())
1226         mimeType = MIMETypeRegistry::getMIMETypeForExtension(url.path().substring(url.path().reverseFind('.') + 1));
1227
1228     if (mimeType.isEmpty())
1229         return ObjectContentFrame;
1230
1231     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
1232         return WebCore::ObjectContentImage;
1233
1234     if (WebPage* webPage = m_frame->page()) {
1235         if (PluginData* pluginData = webPage->corePage()->pluginData()) {
1236             if (pluginData->supportsMimeType(mimeType))
1237                 return ObjectContentNetscapePlugin;
1238         }
1239     }
1240
1241     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
1242         return ObjectContentFrame;
1243
1244     return ObjectContentNone;
1245 }
1246
1247 String WebFrameLoaderClient::overrideMediaType() const
1248 {
1249     notImplemented();
1250     return String();
1251 }
1252
1253 void WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
1254 {
1255     WebPage* webPage = m_frame->page();
1256     if (!webPage)
1257         return;
1258
1259     webPage->injectedBundleLoaderClient().didClearWindowObjectForFrame(webPage, m_frame, world);
1260 }
1261
1262 void WebFrameLoaderClient::documentElementAvailable()
1263 {
1264     notImplemented();
1265 }
1266
1267 void WebFrameLoaderClient::didPerformFirstNavigation() const
1268 {
1269     notImplemented();
1270 }
1271
1272 void WebFrameLoaderClient::registerForIconNotification(bool listen)
1273 {
1274     notImplemented();
1275 }
1276
1277 #if PLATFORM(MAC)
1278     
1279 RemoteAXObjectRef WebFrameLoaderClient::accessibilityRemoteObject() 
1280 {
1281     return m_frame->page()->accessibilityRemoteObject();
1282 }
1283     
1284 #if ENABLE(MAC_JAVA_BRIDGE)
1285 jobject WebFrameLoaderClient::javaApplet(NSView*) { return 0; }
1286 #endif
1287 NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse* response) const
1288 {
1289     return response;
1290 }
1291
1292 #endif
1293 #if USE(CFNETWORK)
1294 bool WebFrameLoaderClient::shouldCacheResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&, const unsigned char* data, unsigned long long length)
1295 {
1296     return true;
1297 }
1298
1299 #endif
1300
1301 bool WebFrameLoaderClient::shouldUsePluginDocument(const String& /*mimeType*/) const
1302 {
1303     notImplemented();
1304     return false;
1305 }
1306
1307 PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
1308 {
1309     return WebFrameNetworkingContext::create(m_frame->coreFrame());
1310 }
1311
1312 } // namespace WebKit