2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #include "WebFrameLoaderClient.h"
28 #include "NotImplemented.h"
29 #include "WebCoreTypeArgumentMarshalling.h"
30 #include "WebErrors.h"
32 #include "WebNavigationDataStore.h"
34 #include "WebPageProxyMessageKinds.h"
35 #include "WebProcess.h"
36 #include <JavaScriptCore/APICast.h>
37 #include <JavaScriptCore/JSObject.h>
38 #include <WebCore/Chrome.h>
39 #include <WebCore/DOMWrapperWorld.h>
40 #include <WebCore/DocumentLoader.h>
41 #include <WebCore/FormState.h>
42 #include <WebCore/Frame.h>
43 #include <WebCore/FrameLoadRequest.h>
44 #include <WebCore/FrameView.h>
45 #include <WebCore/HTMLFormElement.h>
46 #include <WebCore/Page.h>
47 #include <WebCore/ProgressTracker.h>
48 #include <WebCore/ResourceError.h>
49 #include <WebCore/Widget.h>
50 #include <WebCore/WindowFeatures.h>
52 using namespace WebCore;
56 void WebFrameLoaderClient::frameLoaderDestroyed()
58 m_frame->invalidate();
60 // Balances explicit ref() in WebFrame::createMainFrame and WebFrame::createSubframe.
64 bool WebFrameLoaderClient::hasHTMLView() const
69 bool WebFrameLoaderClient::hasWebView() const
71 return m_frame->page();
74 void WebFrameLoaderClient::makeRepresentation(DocumentLoader*)
79 void WebFrameLoaderClient::forceLayout()
84 void WebFrameLoaderClient::forceLayoutForNonHTML()
89 void WebFrameLoaderClient::setCopiesOnScroll()
94 void WebFrameLoaderClient::detachedFromParent2()
99 void WebFrameLoaderClient::detachedFromParent3()
104 void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&)
110 void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse)
115 bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier)
121 void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&)
126 void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&)
131 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
132 bool WebFrameLoaderClient::canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long identifier, const ProtectionSpace&)
139 void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&)
144 void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived)
149 void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
154 void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&)
159 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length)
165 void WebFrameLoaderClient::dispatchDidLoadResourceByXMLHttpRequest(unsigned long identifier, const ScriptString&)
170 void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
175 void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
177 WebPage* webPage = m_frame->page();
181 // Notify the bundle client.
182 webPage->injectedBundleClient().didReceiveServerRedirectForProvisionalLoadForFrame(webPage, m_frame);
184 // Notify the UIProcess.
185 WebProcess::shared().connection()->send(WebPageProxyMessage::DidReceiveServerRedirectForProvisionalLoadForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
188 void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
193 void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate)
198 void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
203 void WebFrameLoaderClient::dispatchDidPushStateWithinPage()
208 void WebFrameLoaderClient::dispatchDidReplaceStateWithinPage()
213 void WebFrameLoaderClient::dispatchDidPopStateWithinPage()
218 void WebFrameLoaderClient::dispatchWillClose()
223 void WebFrameLoaderClient::dispatchDidReceiveIcon()
228 void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
230 WebPage* webPage = m_frame->page();
234 DocumentLoader* provisionalLoader = m_frame->coreFrame()->loader()->provisionalDocumentLoader();
235 const String& url = provisionalLoader->url().string();
237 // Notify the bundle client.
238 webPage->injectedBundleClient().didStartProvisionalLoadForFrame(webPage, m_frame);
240 // Notify the UIProcess.
241 WebProcess::shared().connection()->send(WebPageProxyMessage::DidStartProvisionalLoadForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID(), url));
244 void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title)
246 WebPage* webPage = m_frame->page();
250 // Notify the bundle client.
251 webPage->injectedBundleClient().didReceiveTitleForFrame(webPage, title, m_frame);
253 // Notify the UIProcess.
254 WebProcess::shared().connection()->send(WebPageProxyMessage::DidReceiveTitleForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID(), title));
257 void WebFrameLoaderClient::dispatchDidChangeIcons()
262 void WebFrameLoaderClient::dispatchDidCommitLoad()
264 WebPage* webPage = m_frame->page();
268 // Notify the bundle client.
269 webPage->injectedBundleClient().didCommitLoadForFrame(webPage, m_frame);
271 // Notify the UIProcess.
272 WebProcess::shared().connection()->send(WebPageProxyMessage::DidCommitLoadForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
275 void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError&)
277 WebPage* webPage = m_frame->page();
281 // Notify the bundle client.
282 webPage->injectedBundleClient().didFailProvisionalLoadWithErrorForFrame(webPage, m_frame);
284 // Notify the UIProcess.
285 WebProcess::shared().connection()->send(WebPageProxyMessage::DidFailProvisionalLoadForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
288 void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError&)
290 WebPage* webPage = m_frame->page();
294 // Notify the bundle client.
295 webPage->injectedBundleClient().didFailLoadWithErrorForFrame(webPage, m_frame);
297 // Notify the UIProcess.
298 WebProcess::shared().connection()->send(WebPageProxyMessage::DidFailLoadForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
301 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
306 void WebFrameLoaderClient::dispatchDidFinishLoad()
308 WebPage* webPage = m_frame->page();
312 // Notify the bundle client.
313 webPage->injectedBundleClient().didFinishLoadForFrame(webPage, m_frame);
315 // Notify the UIProcess.
316 WebProcess::shared().connection()->send(WebPageProxyMessage::DidFinishLoadForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
319 void WebFrameLoaderClient::dispatchDidFirstLayout()
321 WebPage* webPage = m_frame->page();
325 WebProcess::shared().connection()->send(WebPageProxyMessage::DidFirstLayoutForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
328 void WebFrameLoaderClient::dispatchDidFirstVisuallyNonEmptyLayout()
330 WebPage* webPage = m_frame->page();
334 WebProcess::shared().connection()->send(WebPageProxyMessage::DidFirstVisuallyNonEmptyLayoutForFrame, webPage->pageID(), CoreIPC::In(m_frame->frameID()));
337 Frame* WebFrameLoaderClient::dispatchCreatePage()
339 WebPage* webPage = m_frame->page();
343 // Just call through to the chrome client.
344 Page* newPage = webPage->corePage()->chrome()->createWindow(m_frame->coreFrame(), FrameLoadRequest(), WindowFeatures());
348 return newPage->mainFrame();
351 void WebFrameLoaderClient::dispatchShow()
353 WebPage* webPage = m_frame->page();
360 void WebFrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& MIMEType, const ResourceRequest& request)
362 WebPage* webPage = m_frame->page();
366 uint64_t listenerID = m_frame->setUpPolicyListener(function);
367 const String& url = request.url().string(); // FIXME: Pass entire request.
369 WebProcess::shared().connection()->send(WebPageProxyMessage::DecidePolicyForMIMEType, webPage->pageID(),
370 CoreIPC::In(m_frame->frameID(), MIMEType, url, listenerID));
373 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>, const String& frameName)
375 WebPage* webPage = m_frame->page();
379 uint64_t listenerID = m_frame->setUpPolicyListener(function);
381 // FIXME: Pass more than just the navigation action type.
382 // FIXME: Pass the frame name.
383 const String& url = request.url().string(); // FIXME: Pass entire request.
385 WebProcess::shared().connection()->send(WebPageProxyMessage::DecidePolicyForNewWindowAction, webPage->pageID(),
386 CoreIPC::In(m_frame->frameID(), (uint32_t)navigationAction.type(), url, listenerID));
389 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>)
391 WebPage* webPage = m_frame->page();
395 uint64_t listenerID = m_frame->setUpPolicyListener(function);
397 // FIXME: Pass more than just the navigation action type.
398 const String& url = request.url().string(); // FIXME: Pass entire request.
400 WebProcess::shared().connection()->send(WebPageProxyMessage::DecidePolicyForNavigationAction, webPage->pageID(),
401 CoreIPC::In(m_frame->frameID(), (uint32_t)navigationAction.type(), url, listenerID));
404 void WebFrameLoaderClient::cancelPolicyCheck()
406 m_frame->invalidatePolicyListener();
409 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&)
414 void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState>)
418 Frame* coreFrame = m_frame->coreFrame();
419 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
422 void WebFrameLoaderClient::dispatchDidLoadMainResource(DocumentLoader*)
427 void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader*)
432 void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError&)
437 void WebFrameLoaderClient::willChangeEstimatedProgress()
442 void WebFrameLoaderClient::didChangeEstimatedProgress()
447 void WebFrameLoaderClient::postProgressStartedNotification()
449 if (WebPage* webPage = m_frame->page())
450 WebProcess::shared().connection()->send(WebPageProxyMessage::DidStartProgress, webPage->pageID(), CoreIPC::In());
453 void WebFrameLoaderClient::postProgressEstimateChangedNotification()
455 if (WebPage* webPage = m_frame->page()) {
456 double progress = webPage->corePage()->progress()->estimatedProgress();
457 WebProcess::shared().connection()->send(WebPageProxyMessage::DidChangeProgress, webPage->pageID(), CoreIPC::In(progress));
461 void WebFrameLoaderClient::postProgressFinishedNotification()
463 if (WebPage* webPage = m_frame->page())
464 WebProcess::shared().connection()->send(WebPageProxyMessage::DidFinishProgress, webPage->pageID(), CoreIPC::In());
467 void WebFrameLoaderClient::setMainFrameDocumentReady(bool)
472 void WebFrameLoaderClient::startDownload(const ResourceRequest&)
477 void WebFrameLoaderClient::willChangeTitle(DocumentLoader*)
482 void WebFrameLoaderClient::didChangeTitle(DocumentLoader*)
487 void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
489 const String& textEncoding = loader->response().textEncodingName();
491 receivedData(data, length, textEncoding);
494 void WebFrameLoaderClient::receivedData(const char* data, int length, const String& textEncoding)
496 Frame* coreFrame = m_frame->coreFrame();
500 // Set the encoding. This only needs to be done once, but it's harmless to do it again later.
501 String encoding = coreFrame->loader()->documentLoader()->overrideEncoding();
502 bool userChosen = !encoding.isNull();
503 if (encoding.isNull())
504 encoding = textEncoding;
505 coreFrame->loader()->writer()->setEncoding(encoding, userChosen);
507 coreFrame->loader()->addData(data, length);
510 void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
512 committedLoad(loader, 0, 0);
515 void WebFrameLoaderClient::updateGlobalHistory()
517 WebPage* webPage = m_frame->page();
521 DocumentLoader* loader = m_frame->coreFrame()->loader()->documentLoader();
523 WebNavigationDataStore data;
524 data.url = loader->urlForHistory().string();
525 data.title = loader->title();
527 WebProcess::shared().connection()->send(WebPageProxyMessage::DidNavigateWithNavigationData,
529 CoreIPC::In(data, m_frame->frameID()));
532 void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
534 WebPage* webPage = m_frame->page();
538 DocumentLoader* loader = m_frame->coreFrame()->loader()->documentLoader();
539 ASSERT(loader->unreachableURL().isEmpty());
542 if (!loader->clientRedirectSourceForHistory().isNull()) {
543 WebProcess::shared().connection()->send(WebPageProxyMessage::DidPerformClientRedirect,
545 CoreIPC::In(loader->clientRedirectSourceForHistory(),
546 loader->clientRedirectDestinationForHistory(),
547 m_frame->frameID()));
551 if (!loader->serverRedirectSourceForHistory().isNull()) {
552 WebProcess::shared().connection()->send(WebPageProxyMessage::DidPerformServerRedirect,
554 CoreIPC::In(loader->serverRedirectSourceForHistory(),
555 loader->serverRedirectDestinationForHistory(),
556 m_frame->frameID()));
560 bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem*) const
566 void WebFrameLoaderClient::dispatchDidAddBackForwardItem(HistoryItem*) const
568 if (WebPage* webPage = m_frame->page())
569 webPage->backForwardListDidChange();
572 void WebFrameLoaderClient::dispatchDidRemoveBackForwardItem(HistoryItem*) const
574 if (WebPage* webPage = m_frame->page())
575 webPage->backForwardListDidChange();
578 void WebFrameLoaderClient::dispatchDidChangeBackForwardIndex() const
580 if (WebPage* webPage = m_frame->page())
581 webPage->backForwardListDidChange();
584 void WebFrameLoaderClient::didDisplayInsecureContent()
589 void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin*)
594 ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request)
596 return WebKit::cancelledError(request);
599 ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request)
601 return WebKit::blockedError(request);
604 ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request)
606 return WebKit::cannotShowURLError(request);
609 ResourceError WebFrameLoaderClient::interruptForPolicyChangeError(const ResourceRequest& request)
611 return WebKit::interruptForPolicyChangeError(request);
614 ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response)
616 return WebKit::cannotShowMIMETypeError(response);
619 ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response)
621 return WebKit::fileDoesNotExistError(response);
624 ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse&)
627 return ResourceError();
630 bool WebFrameLoaderClient::shouldFallBack(const ResourceError&)
636 bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest&) const
642 bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const
648 bool WebFrameLoaderClient::representationExistsForURLScheme(const String& URLScheme) const
654 String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& URLScheme) const
660 void WebFrameLoaderClient::frameLoadCompleted()
665 void WebFrameLoaderClient::saveViewStateToItem(HistoryItem*)
670 void WebFrameLoaderClient::restoreViewState()
675 void WebFrameLoaderClient::provisionalLoadStarted()
680 void WebFrameLoaderClient::didFinishLoad()
685 void WebFrameLoaderClient::prepareForDataSourceReplacement()
690 PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& data)
692 return DocumentLoader::create(request, data);
695 void WebFrameLoaderClient::setTitle(const String& title, const KURL& url)
697 WebPage* webPage = m_frame->page();
701 WebProcess::shared().connection()->send(WebPageProxyMessage::DidUpdateHistoryTitle, webPage->pageID(), CoreIPC::In(title, url.string(), m_frame->frameID()));
704 String WebFrameLoaderClient::userAgent(const KURL&)
707 return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/531.4 (KHTML, like Gecko) Version/4.0.3 Safari/531.4";
710 void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*)
715 void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*)
720 void WebFrameLoaderClient::transitionToCommittedForNewPage()
722 m_frame->coreFrame()->createView(m_frame->page()->size(), Color::white, false, IntSize(), false);
725 bool WebFrameLoaderClient::canCachePage() const
731 void WebFrameLoaderClient::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
736 PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
737 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
739 WebPage* webPage = m_frame->page();
741 RefPtr<WebFrame> subframe = WebFrame::createSubframe(webPage, name, ownerElement);
743 // Notify the UI process that subframe has been added.
744 WebProcess::shared().connection()->send(WebPageProxyMessage::DidCreateSubFrame, webPage->pageID(), CoreIPC::In(subframe->frameID()));
746 Frame* coreSubframe = subframe->coreFrame();
748 // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
749 m_frame->coreFrame()->loader()->loadURLIntoChildFrame(url, referrer, coreSubframe);
751 // The frame's onload handler may have removed it from the document.
752 if (!coreSubframe->tree()->parent())
758 void WebFrameLoaderClient::didTransferChildFrameToNewDocument()
763 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually)
769 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
774 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues)
780 ObjectContentType WebFrameLoaderClient::objectContentType(const KURL& url, const String& mimeType)
783 return ObjectContentNone;
786 String WebFrameLoaderClient::overrideMediaType() const
792 void WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
794 WebPage* webPage = m_frame->page();
798 if (world != mainThreadNormalWorld())
801 JSContextRef context = toRef(m_frame->coreFrame()->script()->globalObject(world)->globalExec());
802 JSObjectRef windowObject = toRef(m_frame->coreFrame()->script()->globalObject(world));
804 webPage->injectedBundleClient().didClearWindowObjectForFrame(webPage, m_frame, context, windowObject);
807 void WebFrameLoaderClient::documentElementAvailable()
812 void WebFrameLoaderClient::didPerformFirstNavigation() const
817 void WebFrameLoaderClient::registerForIconNotification(bool listen)
823 #if ENABLE(MAC_JAVA_BRIDGE)
824 jobject WebFrameLoaderClient::javaApplet(NSView*) { return 0; }
826 NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse*) const
834 bool WebFrameLoaderClient::shouldCacheResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&, const unsigned char* data, unsigned long long length)
842 bool WebFrameLoaderClient::shouldUsePluginDocument(const String& /*mimeType*/) const
848 } // namespace WebKit