ecfede0a07f979020261a50dfcae9ca161ad7020
[WebKit.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     // Restore the page scale factor.
434     double newPageScaleFactor = m_frame->coreFrame()->pageScaleFactor();
435     
436     // Only restore the scale factor for standard frame loads (of the main frame).
437     if (m_frame->isMainFrame() && m_frame->coreFrame()->loader()->loadType() == FrameLoadTypeStandard)
438         newPageScaleFactor = 1.0;
439
440     webPage->scaleWebView(newPageScaleFactor, IntPoint());
441 }
442
443 void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
444 {
445     WebPage* webPage = m_frame->page();
446     if (!webPage)
447         return;
448
449     RefPtr<APIObject> userData;
450
451     // Notify the bundle client.
452     webPage->injectedBundleLoaderClient().didFailProvisionalLoadWithErrorForFrame(webPage, m_frame, error, userData);
453
454     webPage->sandboxExtensionTracker().didFailProvisionalLoad(m_frame);
455
456     // Notify the UIProcess.
457     webPage->send(Messages::WebPageProxy::DidFailProvisionalLoadForFrame(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
458     
459     // If we have a load listener, notify it.
460     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
461         loadListener->didFailLoad(m_frame, error.isCancellation());
462 }
463
464 void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
465 {
466     WebPage* webPage = m_frame->page();
467     if (!webPage)
468         return;
469
470     RefPtr<APIObject> userData;
471
472     // Notify the bundle client.
473     webPage->injectedBundleLoaderClient().didFailLoadWithErrorForFrame(webPage, m_frame, error, userData);
474
475     // Notify the UIProcess.
476     webPage->send(Messages::WebPageProxy::DidFailLoadForFrame(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
477
478     // If we have a load listener, notify it.
479     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
480         loadListener->didFailLoad(m_frame, error.isCancellation());
481 }
482
483 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
484 {
485     WebPage* webPage = m_frame->page();
486     if (!webPage)
487         return;
488
489     RefPtr<APIObject> userData;
490
491     // Notify the bundle client.
492     webPage->injectedBundleLoaderClient().didFinishDocumentLoadForFrame(webPage, m_frame, userData);
493
494     // Notify the UIProcess.
495     webPage->send(Messages::WebPageProxy::DidFinishDocumentLoadForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
496 }
497
498 void WebFrameLoaderClient::dispatchDidFinishLoad()
499 {
500     WebPage* webPage = m_frame->page();
501     if (!webPage)
502         return;
503
504     RefPtr<APIObject> userData;
505
506     // Notify the bundle client.
507     webPage->injectedBundleLoaderClient().didFinishLoadForFrame(webPage, m_frame, userData);
508
509     // Notify the UIProcess.
510     webPage->send(Messages::WebPageProxy::DidFinishLoadForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
511
512     // If we have a load listener, notify it.
513     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
514         loadListener->didFinishLoad(m_frame);
515 }
516
517 void WebFrameLoaderClient::dispatchDidFirstLayout()
518 {
519     WebPage* webPage = m_frame->page();
520     if (!webPage)
521         return;
522
523     RefPtr<APIObject> userData;
524
525     // Notify the bundle client.
526     webPage->injectedBundleLoaderClient().didFirstLayoutForFrame(webPage, m_frame, userData);
527
528     // Notify the UIProcess.
529     webPage->send(Messages::WebPageProxy::DidFirstLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
530 }
531
532 void WebFrameLoaderClient::dispatchDidFirstVisuallyNonEmptyLayout()
533 {
534     WebPage* webPage = m_frame->page();
535     if (!webPage)
536         return;
537
538     RefPtr<APIObject> userData;
539
540     // Notify the bundle client.
541     webPage->injectedBundleLoaderClient().didFirstVisuallyNonEmptyLayoutForFrame(webPage, m_frame, userData);
542
543     // Notify the UIProcess.
544     webPage->send(Messages::WebPageProxy::DidFirstVisuallyNonEmptyLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
545 }
546
547 Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
548 {
549     WebPage* webPage = m_frame->page();
550     if (!webPage)
551         return 0;
552
553     // Just call through to the chrome client.
554     Page* newPage = webPage->corePage()->chrome()->createWindow(m_frame->coreFrame(), FrameLoadRequest(m_frame->coreFrame()->document()->securityOrigin()), WindowFeatures(), navigationAction);
555     if (!newPage)
556         return 0;
557     
558     return newPage->mainFrame();
559 }
560
561 void WebFrameLoaderClient::dispatchShow()
562 {
563     WebPage* webPage = m_frame->page();
564     if (!webPage)
565         return;
566
567     webPage->show();
568 }
569
570 uint32_t modifiersForNavigationAction(const NavigationAction& navigationAction)
571 {
572     uint32_t modifiers = 0;
573     if (const UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(navigationAction.event()))) {
574         if (keyStateEvent->shiftKey())
575             modifiers |= WebEvent::ShiftKey;
576         if (keyStateEvent->ctrlKey())
577             modifiers |= WebEvent::ControlKey;
578         if (keyStateEvent->altKey())
579             modifiers |= WebEvent::AltKey;
580         if (keyStateEvent->metaKey())
581             modifiers |= WebEvent::MetaKey;
582     }
583
584     return modifiers;
585 }
586
587 static const MouseEvent* findMouseEvent(const Event* event)
588 {
589     for (const Event* e = event; e; e = e->underlyingEvent()) {
590         if (e->isMouseEvent())
591             return static_cast<const MouseEvent*>(e);
592     }
593     return 0;
594 }
595
596 int32_t mouseButtonForNavigationAction(const NavigationAction& navigationAction)
597 {
598     const MouseEvent* mouseEvent = findMouseEvent(navigationAction.event());
599     if (!mouseEvent)
600         return -1;
601
602     if (!mouseEvent->buttonDown())
603         return -1;
604
605     return mouseEvent->button();
606 }
607
608 void WebFrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& MIMEType, const ResourceRequest& request)
609 {
610     if (m_frame->coreFrame()->loader()->documentLoader()->url().isEmpty() && request.url() == blankURL()) {
611         // WebKit2 loads initial about:blank documents synchronously, without consulting the policy delegate
612         ASSERT(m_frame->coreFrame()->loader()->stateMachine()->committingFirstRealLoad());
613         (m_frame->coreFrame()->loader()->policyChecker()->*function)(PolicyUse);
614         return;
615     }
616     
617     WebPage* webPage = m_frame->page();
618     if (!webPage)
619         return;
620
621     uint64_t listenerID = m_frame->setUpPolicyListener(function);
622     const String& url = request.url().string(); // FIXME: Pass entire request.
623
624     bool receivedPolicyAction;
625     uint64_t policyAction;
626     uint64_t downloadID;
627     if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForMIMEType(m_frame->frameID(), MIMEType, url, listenerID), Messages::WebPageProxy::DecidePolicyForMIMEType::Reply(receivedPolicyAction, policyAction, downloadID)))
628         return;
629
630     // We call this synchronously because CFNetwork can only convert a loading connection to a download from its didReceiveResponse callback.
631     if (receivedPolicyAction)
632         m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), downloadID);
633 }
634
635 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>, const String& frameName)
636 {
637     WebPage* webPage = m_frame->page();
638     if (!webPage)
639         return;
640
641     uint64_t listenerID = m_frame->setUpPolicyListener(function);
642
643     // FIXME: Pass more than just the navigation action type.
644     // FIXME: Pass the frame name.
645     const String& url = request.url().string(); // FIXME: Pass entire request.
646
647     uint32_t navigationType = static_cast<uint32_t>(navigationAction.type());
648     uint32_t modifiers = modifiersForNavigationAction(navigationAction);
649     int32_t mouseButton = mouseButtonForNavigationAction(navigationAction);
650
651     webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), navigationType, modifiers, mouseButton, url, listenerID));
652 }
653
654 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>)
655 {
656     if (m_frame->coreFrame()->loader()->documentLoader()->url().isEmpty() && request.url() == blankURL()) {
657         // WebKit2 loads initial about:blank documents synchronously, without consulting the policy delegate
658         ASSERT(m_frame->coreFrame()->loader()->stateMachine()->committingFirstRealLoad());
659         (m_frame->coreFrame()->loader()->policyChecker()->*function)(PolicyUse);
660         return;
661     }
662
663     // Always ignore requests with empty URLs.
664     if (request.isEmpty()) {
665         (m_frame->coreFrame()->loader()->policyChecker()->*function)(PolicyIgnore);
666         return;
667     }
668     
669     WebPage* webPage = m_frame->page();
670     if (!webPage)
671         return;
672
673     uint64_t listenerID = m_frame->setUpPolicyListener(function);
674
675     // FIXME: Pass more than just the navigation action type.
676     const String& url = request.url().string(); // FIXME: Pass entire request.
677
678     uint32_t navigationType = static_cast<uint32_t>(navigationAction.type());
679     uint32_t modifiers = modifiersForNavigationAction(navigationAction);
680     int32_t mouseButton = mouseButtonForNavigationAction(navigationAction);
681
682     webPage->send(Messages::WebPageProxy::DecidePolicyForNavigationAction(m_frame->frameID(), navigationType, modifiers, mouseButton, url, listenerID));
683 }
684
685 void WebFrameLoaderClient::cancelPolicyCheck()
686 {
687     m_frame->invalidatePolicyListener();
688 }
689
690 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&)
691 {
692     notImplemented();
693 }
694
695 void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> prpFormState)
696 {
697     WebPage* webPage = m_frame->page();
698     if (!webPage)
699         return;
700
701     // FIXME: Pass more of the form state.
702     RefPtr<FormState> formState = prpFormState;
703     
704     HTMLFormElement* form = formState->form();
705     WebFrame* sourceFrame = static_cast<WebFrameLoaderClient*>(formState->sourceFrame()->loader()->client())->webFrame();    
706     const Vector<std::pair<String, String> >& values = formState->textFieldValues();
707
708     RefPtr<APIObject> userData;
709     webPage->injectedBundleFormClient().willSubmitForm(webPage, form, m_frame, sourceFrame, values, userData);
710
711
712     uint64_t listenerID = m_frame->setUpPolicyListener(function);
713     StringPairVector valuesVector(values);
714
715     webPage->send(Messages::WebPageProxy::WillSubmitForm(m_frame->frameID(), sourceFrame->frameID(), valuesVector, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
716 }
717
718 void WebFrameLoaderClient::dispatchDidLoadMainResource(DocumentLoader*)
719 {
720     notImplemented();
721 }
722
723 void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader*)
724 {
725     notImplemented();
726 }
727
728 void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error)
729 {
730     if (!m_pluginView)
731         return;
732     
733     m_pluginView->manualLoadDidFail(error);
734     m_pluginView = 0;
735     m_hasSentResponseToPluginView = false;
736 }
737
738 void WebFrameLoaderClient::willChangeEstimatedProgress()
739 {
740     notImplemented();
741 }
742
743 void WebFrameLoaderClient::didChangeEstimatedProgress()
744 {
745     notImplemented();
746 }
747
748 void WebFrameLoaderClient::postProgressStartedNotification()
749 {
750     if (WebPage* webPage = m_frame->page())
751         webPage->send(Messages::WebPageProxy::DidStartProgress());
752 }
753
754 void WebFrameLoaderClient::postProgressEstimateChangedNotification()
755 {
756     if (WebPage* webPage = m_frame->page()) {
757         double progress = webPage->corePage()->progress()->estimatedProgress();
758         webPage->send(Messages::WebPageProxy::DidChangeProgress(progress));
759
760     }
761 }
762
763 void WebFrameLoaderClient::postProgressFinishedNotification()
764 {
765     if (WebPage* webPage = m_frame->page())
766         webPage->send(Messages::WebPageProxy::DidFinishProgress());
767 }
768
769 void WebFrameLoaderClient::setMainFrameDocumentReady(bool)
770 {
771     notImplemented();
772 }
773
774 void WebFrameLoaderClient::startDownload(const ResourceRequest& request)
775 {
776     m_frame->startDownload(request);
777 }
778
779 void WebFrameLoaderClient::willChangeTitle(DocumentLoader*)
780 {
781     notImplemented();
782 }
783
784 void WebFrameLoaderClient::didChangeTitle(DocumentLoader*)
785 {
786     notImplemented();
787 }
788
789 void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
790 {
791     // If we're loading a custom representation, we don't want to hand off the data to WebCore.
792     if (m_frameHasCustomRepresentation)
793         return;
794
795     if (!m_pluginView)
796         loader->commitData(data, length);
797
798     // If the document is a stand-alone media document, now is the right time to cancel the WebKit load.
799     // FIXME: This code should be shared across all ports. <http://webkit.org/b/48762>.
800     if (m_frame->coreFrame()->document()->isMediaDocument())
801         loader->cancelMainResourceLoad(pluginWillHandleLoadError(loader->response()));
802
803     // Calling commitData did not create the plug-in view.
804     if (!m_pluginView)
805         return;
806
807     if (!m_hasSentResponseToPluginView) {
808         m_pluginView->manualLoadDidReceiveResponse(loader->response());
809         // manualLoadDidReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
810         // setting up this stream can cause the main document load to be cancelled, setting m_pluginView
811         // to null
812         if (!m_pluginView)
813             return;
814         m_hasSentResponseToPluginView = true;
815     }
816     m_pluginView->manualLoadDidReceiveData(data, length);
817 }
818
819 void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
820 {
821     if (!m_pluginView) {
822         committedLoad(loader, 0, 0);
823
824         if (m_frameHasCustomRepresentation) {
825             WebPage* webPage = m_frame->page();
826             if (!webPage)
827                 return;
828
829             RefPtr<SharedBuffer> mainResourceData = loader->mainResourceData();
830             CoreIPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(mainResourceData ? mainResourceData->data() : 0), mainResourceData ? mainResourceData->size() : 0);
831             
832             webPage->send(Messages::WebPageProxy::DidFinishLoadingDataForCustomRepresentation(dataReference));
833         }
834
835         return;
836     }
837
838     m_pluginView->manualLoadDidFinishLoading();
839     m_pluginView = 0;
840     m_hasSentResponseToPluginView = false;
841 }
842
843 void WebFrameLoaderClient::updateGlobalHistory()
844 {
845     WebPage* webPage = m_frame->page();
846     if (!webPage)
847         return;
848
849     DocumentLoader* loader = m_frame->coreFrame()->loader()->documentLoader();
850
851     WebNavigationDataStore data;
852     data.url = loader->urlForHistory().string();
853     data.title = loader->title();
854
855     WebProcess::shared().connection()->send(Messages::WebContext::DidNavigateWithNavigationData(webPage->pageID(), data, m_frame->frameID()), 0);
856 }
857
858 void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
859 {
860     WebPage* webPage = m_frame->page();
861     if (!webPage)
862         return;
863
864     DocumentLoader* loader = m_frame->coreFrame()->loader()->documentLoader();
865     ASSERT(loader->unreachableURL().isEmpty());
866
867     // Client redirect
868     if (!loader->clientRedirectSourceForHistory().isNull()) {
869         WebProcess::shared().connection()->send(Messages::WebContext::DidPerformClientRedirect(webPage->pageID(),
870             loader->clientRedirectSourceForHistory(), loader->clientRedirectDestinationForHistory(), m_frame->frameID()), 0);
871     }
872
873     // Server redirect
874     if (!loader->serverRedirectSourceForHistory().isNull()) {
875         WebProcess::shared().connection()->send(Messages::WebContext::DidPerformServerRedirect(webPage->pageID(),
876             loader->serverRedirectSourceForHistory(), loader->serverRedirectDestinationForHistory(), m_frame->frameID()), 0);
877     }
878 }
879
880 bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem*) const
881 {
882     notImplemented();
883     return true;
884 }
885
886 void WebFrameLoaderClient::dispatchDidAddBackForwardItem(HistoryItem*) const
887 {
888     notImplemented();
889 }
890
891 void WebFrameLoaderClient::dispatchDidRemoveBackForwardItem(HistoryItem*) const
892 {
893     notImplemented();
894 }
895
896 void WebFrameLoaderClient::dispatchDidChangeBackForwardIndex() const
897 {
898     notImplemented();
899 }
900
901 void WebFrameLoaderClient::didDisplayInsecureContent()
902 {
903     WebPage* webPage = m_frame->page();
904     if (!webPage)
905         return;
906
907     RefPtr<APIObject> userData;
908
909     webPage->injectedBundleLoaderClient().didDisplayInsecureContentForFrame(webPage, m_frame, userData);
910
911     webPage->send(Messages::WebPageProxy::DidDisplayInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
912 }
913
914 void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin*)
915 {
916     WebPage* webPage = m_frame->page();
917     if (!webPage)
918         return;
919
920     RefPtr<APIObject> userData;
921
922     webPage->injectedBundleLoaderClient().didRunInsecureContentForFrame(webPage, m_frame, userData);
923
924     webPage->send(Messages::WebPageProxy::DidRunInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
925 }
926
927 ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request)
928 {
929     return WebKit::cancelledError(request);
930 }
931
932 ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request)
933 {
934     return WebKit::blockedError(request);
935 }
936
937 ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request)
938 {
939     return WebKit::cannotShowURLError(request);
940 }
941
942 ResourceError WebFrameLoaderClient::interruptForPolicyChangeError(const ResourceRequest& request)
943 {
944     return WebKit::interruptForPolicyChangeError(request);
945 }
946
947 ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response)
948 {
949     return WebKit::cannotShowMIMETypeError(response);
950 }
951
952 ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response)
953 {
954     return WebKit::fileDoesNotExistError(response);
955 }
956
957 ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse& response)
958 {
959     return WebKit::pluginWillHandleLoadError(response);
960 }
961
962 bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error)
963 {
964     DEFINE_STATIC_LOCAL(const ResourceError, cancelledError, (this->cancelledError(ResourceRequest())));
965     DEFINE_STATIC_LOCAL(const ResourceError, pluginWillHandleLoadError, (this->pluginWillHandleLoadError(ResourceResponse())));
966
967     if (error.errorCode() == cancelledError.errorCode() && error.domain() == cancelledError.domain())
968         return false;
969
970     if (error.errorCode() == pluginWillHandleLoadError.errorCode() && error.domain() == pluginWillHandleLoadError.domain())
971         return false;
972
973     return true;
974 }
975
976 bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest&) const
977 {
978     notImplemented();
979     return true;
980 }
981
982 bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const
983 {
984     notImplemented();
985     return true;
986 }
987
988 bool WebFrameLoaderClient::canShowMIMETypeAsHTML(const String& MIMEType) const
989 {
990     return true;
991 }
992
993 bool WebFrameLoaderClient::representationExistsForURLScheme(const String& URLScheme) const
994 {
995     notImplemented();
996     return false;
997 }
998
999 String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& URLScheme) const
1000 {
1001     notImplemented();
1002     return String();
1003 }
1004
1005 void WebFrameLoaderClient::frameLoadCompleted()
1006 {
1007     notImplemented();
1008 }
1009
1010 void WebFrameLoaderClient::saveViewStateToItem(HistoryItem*)
1011 {
1012     notImplemented();
1013 }
1014
1015 void WebFrameLoaderClient::restoreViewState()
1016 {
1017     // Inform the UI process of the scale factor.
1018     double scaleFactor = m_frame->coreFrame()->loader()->history()->currentItem()->pageScaleFactor();
1019     m_frame->page()->send(Messages::WebPageProxy::ViewScaleFactorDidChange(scaleFactor));
1020 }
1021
1022 void WebFrameLoaderClient::provisionalLoadStarted()
1023 {
1024     notImplemented();
1025 }
1026
1027 void WebFrameLoaderClient::didFinishLoad()
1028 {
1029     // If we have a load listener, notify it.
1030     if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
1031         loadListener->didFinishLoad(m_frame);
1032 }
1033
1034 void WebFrameLoaderClient::prepareForDataSourceReplacement()
1035 {
1036     notImplemented();
1037 }
1038
1039 PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& data)
1040 {
1041     return DocumentLoader::create(request, data);
1042 }
1043
1044 void WebFrameLoaderClient::setTitle(const String& title, const KURL& url)
1045 {
1046     WebPage* webPage = m_frame->page();
1047     if (!webPage)
1048         return;
1049
1050     WebProcess::shared().connection()->send(Messages::WebContext::DidUpdateHistoryTitle(webPage->pageID(),
1051         title, url.string(), m_frame->frameID()), 0);
1052 }
1053
1054 String WebFrameLoaderClient::userAgent(const KURL&)
1055 {
1056     WebPage* webPage = m_frame->page();
1057     if (!webPage)
1058         return String();
1059
1060     return webPage->userAgent();
1061 }
1062
1063 void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*)
1064 {
1065 }
1066
1067 void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*)
1068 {
1069 }
1070
1071 void WebFrameLoaderClient::transitionToCommittedForNewPage()
1072 {
1073     WebPage* webPage = m_frame->page();
1074     Color backgroundColor = webPage->drawsTransparentBackground() ? Color::transparent : Color::white;
1075
1076     bool isMainFrame = webPage->mainFrame() == m_frame;
1077
1078 #if ENABLE(TILED_BACKING_STORE)
1079     IntSize currentVisibleContentSize = m_frame->coreFrame()->view() ? m_frame->coreFrame()->view()->actualVisibleContentRect().size() : IntSize();
1080     m_frame->coreFrame()->createView(webPage->size(), backgroundColor, false, webPage->resizesToContentsLayoutSize(), isMainFrame && webPage->resizesToContentsEnabled());
1081
1082     if (isMainFrame && webPage->resizesToContentsEnabled()) {
1083         m_frame->coreFrame()->view()->setDelegatesScrolling(true);
1084         m_frame->coreFrame()->view()->setPaintsEntireContents(true);
1085     }
1086
1087     // The HistoryController will update the scroll position later if needed.
1088     m_frame->coreFrame()->view()->setActualVisibleContentRect(IntRect(IntPoint::zero(), currentVisibleContentSize));
1089 #else
1090     const String& mimeType = m_frame->coreFrame()->loader()->documentLoader()->response().mimeType();
1091     m_frameHasCustomRepresentation = isMainFrame && WebProcess::shared().shouldUseCustomRepresentationForMIMEType(mimeType);
1092
1093     m_frame->coreFrame()->createView(webPage->size(), backgroundColor, false, IntSize(), false);
1094 #endif
1095
1096     m_frame->coreFrame()->view()->setTransparent(!webPage->drawsBackground());
1097 }
1098
1099 void WebFrameLoaderClient::didSaveToPageCache()
1100 {
1101     WebPage* webPage = m_frame->page();
1102     if (!webPage)
1103         return;
1104
1105     if (m_frame->isMainFrame())
1106         return;
1107
1108     webPage->send(Messages::WebPageProxy::DidSaveFrameToPageCache(m_frame->frameID()));
1109 }
1110
1111 void WebFrameLoaderClient::didRestoreFromPageCache()
1112 {
1113     WebPage* webPage = m_frame->page();
1114     if (!webPage)
1115         return;
1116
1117     if (m_frame->isMainFrame())
1118         return;
1119
1120     WebFrame* parentFrame = static_cast<WebFrameLoaderClient*>(m_frame->coreFrame()->tree()->parent()->loader()->client())->webFrame();
1121     webPage->send(Messages::WebPageProxy::DidRestoreFrameFromPageCache(m_frame->frameID(), parentFrame->frameID()));
1122 }
1123
1124 void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool value)
1125 {
1126     WebPage* webPage = m_frame->page();
1127     if (!webPage)
1128         return;
1129
1130     webPage->send(Messages::WebPageProxy::FrameDidBecomeFrameSet(m_frame->frameID(), value));
1131 }
1132
1133 bool WebFrameLoaderClient::canCachePage() const
1134 {
1135     // We cannot cache frames that have custom representations because they are
1136     // rendered in the UIProcess. 
1137     return !m_frameHasCustomRepresentation;
1138 }
1139
1140 void WebFrameLoaderClient::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest& initialRequest, const ResourceResponse& response)
1141 {
1142     m_frame->convertHandleToDownload(handle, request, initialRequest, response);
1143 }
1144
1145 PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
1146                                                     const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
1147 {
1148     WebPage* webPage = m_frame->page();
1149
1150     RefPtr<WebFrame> subframe = WebFrame::createSubframe(webPage, name, ownerElement);
1151
1152     Frame* coreSubframe = subframe->coreFrame();
1153
1154      // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
1155     m_frame->coreFrame()->loader()->loadURLIntoChildFrame(url, referrer, coreSubframe);
1156
1157     // The frame's onload handler may have removed it from the document.
1158     if (!coreSubframe->tree()->parent())
1159         return 0;
1160
1161     return coreSubframe;
1162 }
1163
1164 void WebFrameLoaderClient::didTransferChildFrameToNewDocument(Page*)
1165 {
1166     notImplemented();
1167 }
1168
1169 void WebFrameLoaderClient::transferLoadingResourceFromPage(unsigned long, DocumentLoader*, const ResourceRequest&, Page*)
1170 {
1171     notImplemented();
1172 }
1173
1174 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugInElement* pluginElement, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
1175 {
1176     ASSERT(paramNames.size() == paramValues.size());
1177     
1178     WebPage* webPage = m_frame->page();
1179     ASSERT(webPage);
1180     
1181     Plugin::Parameters parameters;
1182     parameters.url = url;
1183     parameters.names = paramNames;
1184     parameters.values = paramValues;
1185     parameters.mimeType = mimeType;
1186     parameters.loadManually = loadManually;
1187
1188     // <rdar://problem/8440903>: AppleConnect has a bug where it does not
1189     // understand the parameter names specified in the <object> element that
1190     // embeds its plug-in. This hack works around the issue by converting the
1191     // parameter names to lowercase before passing them to the plug-in.
1192     // FIXME: This workaround should be dependent on site-specific quirks being
1193     // enabled. This requires adding this setting to WebKit2's WebPreferences
1194     // implementation. See <https://bugs.webkit.org/show_bug.cgi?id=46076>.
1195     if (equalIgnoringCase(mimeType, "application/x-snkp")) {
1196         for (size_t i = 0; i < paramNames.size(); ++i)
1197             parameters.names[i] = paramNames[i].lower();
1198     }
1199
1200     RefPtr<Plugin> plugin = webPage->createPlugin(parameters);
1201     if (!plugin)
1202         return 0;
1203     
1204     return PluginView::create(pluginElement, plugin.release(), parameters);
1205 }
1206
1207 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
1208 {
1209     ASSERT(!m_pluginView);
1210     ASSERT(pluginWidget);
1211     
1212     m_pluginView = static_cast<PluginView*>(pluginWidget);
1213 }
1214
1215 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* appletElement, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues)
1216 {
1217     return createPlugin(pluginSize, appletElement, KURL(), paramNames, paramValues, "application/x-java-applet", false);
1218 }
1219
1220 ObjectContentType WebFrameLoaderClient::objectContentType(const KURL& url, const String& mimeTypeIn)
1221 {
1222     // FIXME: This should be merged with WebCore::FrameLoader::defaultObjectContentType when the plugin code
1223     // is consolidated.
1224
1225     String mimeType = mimeTypeIn;
1226     if (mimeType.isEmpty())
1227         mimeType = MIMETypeRegistry::getMIMETypeForExtension(url.path().substring(url.path().reverseFind('.') + 1));
1228
1229     if (mimeType.isEmpty())
1230         return ObjectContentFrame;
1231
1232     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
1233         return WebCore::ObjectContentImage;
1234
1235     if (WebPage* webPage = m_frame->page()) {
1236         if (PluginData* pluginData = webPage->corePage()->pluginData()) {
1237             if (pluginData->supportsMimeType(mimeType))
1238                 return ObjectContentNetscapePlugin;
1239         }
1240     }
1241
1242     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
1243         return ObjectContentFrame;
1244
1245     return ObjectContentNone;
1246 }
1247
1248 String WebFrameLoaderClient::overrideMediaType() const
1249 {
1250     notImplemented();
1251     return String();
1252 }
1253
1254 void WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
1255 {
1256     WebPage* webPage = m_frame->page();
1257     if (!webPage)
1258         return;
1259
1260     webPage->injectedBundleLoaderClient().didClearWindowObjectForFrame(webPage, m_frame, world);
1261 }
1262
1263 void WebFrameLoaderClient::documentElementAvailable()
1264 {
1265     notImplemented();
1266 }
1267
1268 void WebFrameLoaderClient::didPerformFirstNavigation() const
1269 {
1270     notImplemented();
1271 }
1272
1273 void WebFrameLoaderClient::registerForIconNotification(bool listen)
1274 {
1275     notImplemented();
1276 }
1277
1278 #if PLATFORM(MAC)
1279     
1280 RemoteAXObjectRef WebFrameLoaderClient::accessibilityRemoteObject() 
1281 {
1282     return m_frame->page()->accessibilityRemoteObject();
1283 }
1284     
1285 #if ENABLE(MAC_JAVA_BRIDGE)
1286 jobject WebFrameLoaderClient::javaApplet(NSView*) { return 0; }
1287 #endif
1288 NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse* response) const
1289 {
1290     return response;
1291 }
1292
1293 #endif
1294 #if USE(CFNETWORK)
1295 bool WebFrameLoaderClient::shouldCacheResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&, const unsigned char* data, unsigned long long length)
1296 {
1297     return true;
1298 }
1299
1300 #endif
1301
1302 bool WebFrameLoaderClient::shouldUsePluginDocument(const String& /*mimeType*/) const
1303 {
1304     notImplemented();
1305     return false;
1306 }
1307
1308 PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
1309 {
1310     return WebFrameNetworkingContext::create(m_frame->coreFrame());
1311 }
1312
1313 } // namespace WebKit