⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webframeloaderclient.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1.  Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer. * 2.  Redistributions in binary form must reproduce the above copyright *     notice, this list of conditions and the following disclaimer in the *     documentation and/or other materials provided with the distribution. * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of *     its contributors may be used to endorse or promote products derived *     from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "config.h"#include "WebFrameLoaderClient.h"#include "CFDictionaryPropertyBag.h"#include "COMPropertyBag.h"#include "DOMHTMLClasses.h"#include "EmbeddedWidget.h"#include "MarshallingHelpers.h"#include "NotImplemented.h"#include "WebCachedFramePlatformData.h"#include "WebChromeClient.h"#include "WebDocumentLoader.h"#include "WebError.h"#include "WebFrame.h"#include "WebHistory.h"#include "WebHistoryItem.h"#include "WebMutableURLRequest.h"#include "WebNotificationCenter.h"#include "WebScriptDebugServer.h"#include "WebURLAuthenticationChallenge.h"#include "WebURLResponse.h"#include "WebView.h"#pragma warning(push, 0)#include <WebCore/CachedFrame.h>#include <WebCore/DocumentLoader.h>#include <WebCore/FrameLoader.h>#include <WebCore/FrameTree.h>#include <WebCore/FrameView.h>#include <WebCore/HTMLAppletElement.h>#include <WebCore/HTMLFrameElement.h>#include <WebCore/HTMLFrameOwnerElement.h>#include <WebCore/HTMLNames.h>#include <WebCore/HTMLPlugInElement.h>#include <WebCore/HistoryItem.h>#include <WebCore/Page.h>#include <WebCore/PluginPackage.h>#include <WebCore/PluginView.h>#include <WebCore/RenderPart.h>#include <WebCore/ResourceHandle.h>#pragma warning(pop)using namespace WebCore;using namespace HTMLNames;static WebDataSource* getWebDataSource(DocumentLoader* loader){    return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;}WebFrameLoaderClient::WebFrameLoaderClient(WebFrame* webFrame)    : m_webFrame(webFrame)    , m_manualLoader(0)     , m_hasSentResponseToPlugin(false) {    ASSERT_ARG(webFrame, webFrame);}WebFrameLoaderClient::~WebFrameLoaderClient(){}bool WebFrameLoaderClient::hasWebView() const{    return m_webFrame->webView();}void WebFrameLoaderClient::forceLayout(){    FrameView* view = core(m_webFrame)->view();    if (view)        view->forceLayout(true);}void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    COMPtr<WebMutableURLRequest> webURLRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));    resourceLoadDelegate->identifierForInitialRequest(webView, webURLRequest.get(), getWebDataSource(loader), identifier);}bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader* loader, unsigned long identifier){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return true;    COMPtr<IWebResourceLoadDelegatePrivate2> resourceLoadDelegatePrivate;    if (FAILED(resourceLoadDelegate->QueryInterface(IID_IWebResourceLoadDelegatePrivate2, reinterpret_cast<void**>(&resourceLoadDelegatePrivate))))        return true;    BOOL shouldUse;    if (SUCCEEDED(resourceLoadDelegatePrivate->shouldUseCredentialStorage(webView, identifier, getWebDataSource(loader), &shouldUse)))        return shouldUse;    return true;}void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge){#if USE(CFNETWORK)    ASSERT(challenge.sourceHandle());    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (SUCCEEDED(webView->resourceLoadDelegate(&resourceLoadDelegate))) {        COMPtr<WebURLAuthenticationChallenge> webChallenge(AdoptCOM, WebURLAuthenticationChallenge::createInstance(challenge));        if (SUCCEEDED(resourceLoadDelegate->didReceiveAuthenticationChallenge(webView, identifier, webChallenge.get(), getWebDataSource(loader))))            return;    }    // If the ResourceLoadDelegate doesn't exist or fails to handle the call, we tell the ResourceHandle    // to continue without credential - this is the best approximation of Mac behavior    challenge.sourceHandle()->receivedRequestToContinueWithoutCredential(challenge);#else   notImplemented();#endif}void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    COMPtr<WebURLAuthenticationChallenge> webChallenge(AdoptCOM, WebURLAuthenticationChallenge::createInstance(challenge));    resourceLoadDelegate->didCancelAuthenticationChallenge(webView, identifier, webChallenge.get(), getWebDataSource(loader));}void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    COMPtr<WebMutableURLRequest> webURLRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));    COMPtr<WebURLResponse> webURLRedirectResponse(AdoptCOM, WebURLResponse::createInstance(redirectResponse));    COMPtr<IWebURLRequest> newWebURLRequest;    if (FAILED(resourceLoadDelegate->willSendRequest(webView, identifier, webURLRequest.get(), webURLRedirectResponse.get(), getWebDataSource(loader), &newWebURLRequest)))        return;    if (webURLRequest == newWebURLRequest)        return;    COMPtr<WebMutableURLRequest> newWebURLRequestImpl(Query, newWebURLRequest);    if (!newWebURLRequestImpl)        return;    request = newWebURLRequestImpl->resourceRequest();}void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    COMPtr<WebURLResponse> webURLResponse(AdoptCOM, WebURLResponse::createInstance(response));    resourceLoadDelegate->didReceiveResponse(webView, identifier, webURLResponse.get(), getWebDataSource(loader));}void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long identifier, int length){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    resourceLoadDelegate->didReceiveContentLength(webView, identifier, length, getWebDataSource(loader));}void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    resourceLoadDelegate->didFinishLoadingFromDataSource(webView, identifier, getWebDataSource(loader));}void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, unsigned long identifier, const ResourceError& error){    WebView* webView = m_webFrame->webView();    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))        return;    COMPtr<WebError> webError(AdoptCOM, WebError::createInstance(error));    resourceLoadDelegate->didFailLoadingWithError(webView, identifier, webError.get(), getWebDataSource(loader));}void WebFrameLoaderClient::dispatchDidHandleOnloadEvents(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;    if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) && frameLoadDelegatePriv)        frameLoadDelegatePriv->didHandleOnloadEventsForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didReceiveServerRedirectForProvisionalLoadForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidCancelClientRedirect(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didCancelClientRedirectForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL& url, double delay, double fireDate){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->willPerformClientRedirectToURL(webView, BString(url.string()), delay, MarshallingHelpers::CFAbsoluteTimeToDATE(fireDate), m_webFrame);}void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didChangeLocationWithinPageForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchWillClose(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->willCloseFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidReceiveIcon(){    m_webFrame->webView()->dispatchDidReceiveIconFromWebFrame(m_webFrame);}void WebFrameLoaderClient::dispatchDidStartProvisionalLoad(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didStartProvisionalLoadForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didReceiveTitle(webView, BString(title), m_webFrame);}void WebFrameLoaderClient::dispatchDidCommitLoad(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didCommitLoadForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidFinishDocumentLoad(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;    if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) && frameLoadDelegatePriv)        frameLoadDelegatePriv->didFinishDocumentLoadForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidFinishLoad(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))        frameLoadDelegate->didFinishLoadForFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidFirstLayout(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;    if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) && frameLoadDelegatePriv)        frameLoadDelegatePriv->didFirstLayoutInFrame(webView, m_webFrame);}void WebFrameLoaderClient::dispatchDidFirstVisuallyNonEmptyLayout(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePrivate;    if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePrivate)) && frameLoadDelegatePrivate) {        COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePrivate2(Query, frameLoadDelegatePrivate);        if (frameLoadDelegatePrivate2)            frameLoadDelegatePrivate2->didFirstVisuallyNonEmptyLayoutInFrame(webView, m_webFrame);    }}Frame* WebFrameLoaderClient::dispatchCreatePage(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebUIDelegate> ui;    if (FAILED(webView->uiDelegate(&ui)))        return 0;    COMPtr<IWebView> newWebView;    if (FAILED(ui->createWebViewWithRequest(webView, 0, &newWebView)))        return 0;    COMPtr<IWebFrame> mainFrame;    if (FAILED(newWebView->mainFrame(&mainFrame)))        return 0;    COMPtr<WebFrame> mainFrameImpl(Query, mainFrame);    return core(mainFrameImpl.get());}void WebFrameLoaderClient::dispatchShow(){    WebView* webView = m_webFrame->webView();    COMPtr<IWebUIDelegate> ui;    if (SUCCEEDED(webView->uiDelegate(&ui)))        ui->webViewShow(webView);}void WebFrameLoaderClient::dispatchDidLoadMainResource(DocumentLoader*){}void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error){    if (!m_manualLoader)        return;    m_manualLoader->didFail(error);    m_manualLoader = 0;    m_hasSentResponseToPlugin = false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -