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