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