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