diff options
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/navigation_state.h | 22 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 108 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 18 | ||||
-rw-r--r-- | webkit/glue/webframe.h | 4 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 35 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 4 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 157 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.h | 35 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.cc | 17 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.h | 43 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 16 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.h | 18 | ||||
-rw-r--r-- | webkit/webkit.gyp | 1 |
14 files changed, 226 insertions, 256 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 7fcbe0a..9b11bdc 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2201,8 +2201,8 @@ GURL TabContents::GetAlternateErrorPageURL() const { WebPreferences TabContents::GetWebkitPrefs() { PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); - bool isDomUI = false; - return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI); + bool is_dom_ui = false; + return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui); } void TabContents::OnJSOutOfMemory() { diff --git a/chrome/renderer/navigation_state.h b/chrome/renderer/navigation_state.h index ec45808..ecb79fd 100644 --- a/chrome/renderer/navigation_state.h +++ b/chrome/renderer/navigation_state.h @@ -144,6 +144,23 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { security_info_ = security_info; } + bool postpone_loading_data() const { + return postpone_loading_data_; + } + void set_postpone_loading_data(bool postpone_loading_data) { + postpone_loading_data_ = postpone_loading_data; + } + + void clear_postponed_data() { + postponed_data_.clear(); + } + void append_postponed_data(const char* data, size_t data_len) { + postponed_data_.append(data, data_len); + } + const std::string& postponed_data() const { + return postponed_data_; + } + private: NavigationState(PageTransition::Type transition_type, const base::Time& request_time, @@ -154,7 +171,8 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { load_histograms_recorded_(false), request_committed_(false), is_content_initiated_(is_content_initiated), - pending_page_id_(pending_page_id) { + pending_page_id_(pending_page_id), + postpone_loading_data_(false) { } PageTransition::Type transition_type_; @@ -173,6 +191,8 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { scoped_ptr<webkit_glue::PasswordForm> password_form_data_; scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_; std::string security_info_; + bool postpone_loading_data_; + std::string postponed_data_; DISALLOW_COPY_AND_ASSIGN(NavigationState); }; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 54305ee..c1ace50 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -1283,6 +1283,26 @@ void RenderView::LoadNavigationErrorPage(WebFrame* frame, replace); } +void RenderView::DidReceiveDocumentData(WebFrame* frame, const char* data, + size_t data_len) { + NavigationState* navigation_state = + NavigationState::FromDataSource(frame->GetDataSource()); + if (!navigation_state->postpone_loading_data()) { + frame->CommitDocumentData(data, data_len); + return; + } + + // Continue buffering the response data for the original 404 page. If it + // grows too large, then we'll just let it through. + navigation_state->append_postponed_data(data, data_len); + if (navigation_state->postponed_data().size() >= 512) { + navigation_state->set_postpone_loading_data(false); + frame->CommitDocumentData(navigation_state->postponed_data().data(), + navigation_state->postponed_data().size()); + navigation_state->clear_postponed_data(); + } +} + void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame, bool is_new_navigation) { NavigationState* navigation_state = @@ -1442,31 +1462,81 @@ void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame, } } -void RenderView::WillSendRequest(WebView* webview, - uint32 identifier, +void RenderView::WillSendRequest(WebFrame* frame, uint32 identifier, WebURLRequest* request) { request->setRequestorID(routing_id_); } -void RenderView::BindDOMAutomationController(WebFrame* webframe) { +void RenderView::DidReceiveResponse(WebFrame* frame, uint32 identifier, + const WebURLResponse& response) { + // Consider loading an alternate error page for 404 responses. + if (response.httpStatusCode() != 404) + return; + + // Only do this for responses that correspond to a provisional data source + // of the top-most frame. If we have a provisional data source, then we + // can't have any sub-resources yet, so we know that this response must + // correspond to a frame load. + if (!frame->GetProvisionalDataSource() || frame->GetParent()) + return; + + // If we are in view source mode, then just let the user see the source of + // the server's 404 error page. + if (frame->GetInViewSourceMode()) + return; + + // Can we even load an alternate error page for this URL? + if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) + return; + + NavigationState* navigation_state = + NavigationState::FromDataSource(frame->GetProvisionalDataSource()); + navigation_state->set_postpone_loading_data(true); + navigation_state->clear_postponed_data(); +} + +void RenderView::DidFinishLoading(WebFrame* frame, uint32 identifier) { + NavigationState* navigation_state = + NavigationState::FromDataSource(frame->GetDataSource()); + if (!navigation_state->postpone_loading_data()) + return; + + // The server returned a 404 and the content was < 512 bytes (which we + // suppressed). Go ahead and fetch the alternate page content. + + const GURL& frame_url = frame->GetURL(); + + const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); + DCHECK(error_page_url.is_valid()); + + WebURLError original_error; + original_error.unreachableURL = frame_url; + + navigation_state->set_alt_error_page_fetcher( + new AltErrorPageResourceFetcher( + error_page_url, frame, original_error, + NewCallback(this, &RenderView::AltErrorPageFinished))); +} + +void RenderView::BindDOMAutomationController(WebFrame* frame) { dom_automation_controller_.set_message_sender(this); dom_automation_controller_.set_routing_id(routing_id_); - dom_automation_controller_.BindToJavascript(webframe, + dom_automation_controller_.BindToJavascript(frame, L"domAutomationController"); } -void RenderView::WindowObjectCleared(WebFrame* webframe) { +void RenderView::WindowObjectCleared(WebFrame* frame) { if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) - BindDOMAutomationController(webframe); + BindDOMAutomationController(frame); if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) { dom_ui_bindings_.set_message_sender(this); dom_ui_bindings_.set_routing_id(routing_id_); - dom_ui_bindings_.BindToJavascript(webframe, L"chrome"); + dom_ui_bindings_.BindToJavascript(frame, L"chrome"); } if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { external_host_bindings_.set_message_sender(this); external_host_bindings_.set_routing_id(routing_id_); - external_host_bindings_.BindToJavascript(webframe, L"externalHost"); + external_host_bindings_.BindToJavascript(frame, L"externalHost"); } } @@ -2113,9 +2183,9 @@ void RenderView::OnGetApplicationInfo(int page_id) { Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); } -GURL RenderView::GetAlternateErrorPageURL(const GURL& failedURL, +GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, ErrorPageType error_type) { - if (failedURL.SchemeIsSecure()) { + if (failed_url.SchemeIsSecure()) { // If the URL that failed was secure, then the embedding web page was not // expecting a network attacker to be able to manipulate its contents. As // we fetch alternate error pages over HTTP, we would be allowing a network @@ -2134,7 +2204,7 @@ GURL RenderView::GetAlternateErrorPageURL(const GURL& failedURL, remove_params.ClearPassword(); remove_params.ClearQuery(); remove_params.ClearRef(); - const GURL url_to_send = failedURL.ReplaceComponents(remove_params); + const GURL url_to_send = failed_url.ReplaceComponents(remove_params); // Construct the query params to send to link doctor. std::string params(alternate_error_page_url_.query()); @@ -2862,8 +2932,7 @@ bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, return false; const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, - ec == net::ERR_NAME_NOT_RESOLVED ? WebViewDelegate::DNS_ERROR - : WebViewDelegate::CONNECTION_ERROR); + ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); if (!error_page_url.is_valid()) return false; @@ -2906,7 +2975,18 @@ void RenderView::AltErrorPageFinished(WebFrame* frame, const WebURLError& original_error, const std::string& html) { // Here, we replace the blank page we loaded previously. - LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true); + + // If we failed to download the alternate error page, fall back to the + // original error page if present. Otherwise, LoadNavigationErrorPage + // will simply display a default error page. + const std::string* html_to_load = &html; + if (html.empty()) { + NavigationState* navigation_state = + NavigationState::FromDataSource(frame->GetDataSource()); + html_to_load = &navigation_state->postponed_data(); + } + LoadNavigationErrorPage( + frame, WebURLRequest(), original_error, *html_to_load, true); } void RenderView::OnMoveOrResizeStarted() { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 37c40a0..255c7a5 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -186,6 +186,8 @@ class RenderView : public RenderWidget, const WebKit::WebURLError& error, const std::string& html, bool replace); + virtual void DidReceiveDocumentData(WebFrame* frame, const char* data, + size_t data_len); virtual void DidCommitLoadForFrame(WebView* webview, WebFrame* frame, bool is_new_navigation); virtual void DidReceiveTitle(WebView* webview, @@ -216,9 +218,13 @@ class RenderView : public RenderWidget, virtual void WillCloseFrame(WebView* webview, WebFrame* frame); virtual void WillSubmitForm(WebView* webview, WebFrame* frame, const WebKit::WebForm& form); - virtual void WillSendRequest(WebView* webview, + virtual void WillSendRequest(WebFrame* webframe, uint32 identifier, WebKit::WebURLRequest* request); + virtual void DidReceiveResponse(WebFrame* webframe, + uint32 identifier, + const WebKit::WebURLResponse& response); + virtual void DidFinishLoading(WebFrame* webframe, uint32 identifier); virtual void WindowObjectCleared(WebFrame* webframe); virtual void DocumentElementAvailable(WebFrame* webframe); @@ -260,8 +266,6 @@ class RenderView : public RenderWidget, const GURL& image_url, bool errored, const SkBitmap& image); - virtual GURL GetAlternateErrorPageURL(const GURL& failedURL, - ErrorPageType error_type); virtual void ShowContextMenu(WebView* webview, ContextNodeType node_type, @@ -609,7 +613,15 @@ class RenderView : public RenderWidget, // Locates a sub frame with given xpath WebFrame* GetChildFrame(const std::wstring& frame_xpath) const; + enum ErrorPageType { + DNS_ERROR, + HTTP_404, + CONNECTION_ERROR, + }; + // Alternate error page helpers. + GURL GetAlternateErrorPageURL( + const GURL& failed_url, ErrorPageType error_type); bool MaybeLoadAlternateErrorPage( WebFrame* frame, const WebKit::WebURLError& error, bool replace); std::string GetAltHTMLForTemplate( diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 554bf90..9ee7b23 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -123,6 +123,10 @@ class WebFrame { // ends up triggering WebViewDelegate::WillSendRequest. virtual void DispatchWillSendRequest(WebKit::WebURLRequest* request) = 0; + // Called from within WebViewDelegate::DidReceiveDocumentData to commit data + // for the frame that will be used to construct the frame's document. + virtual void CommitDocumentData(const char* data, size_t data_len) = 0; + // Executes JavaScript in the web frame. virtual void ExecuteScript(const WebKit::WebScriptSource& source) = 0; diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 3564e45..6870280 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -224,8 +224,6 @@ using WebKit::WebURLError; using WebKit::WebURLRequest; using WebKit::WebURLResponse; -using webkit_glue::AltErrorPageResourceFetcher; - // Key for a StatsCounter tracking how many WebFrames are active. static const char* const kWebFrameActiveCount = "WebFrameActiveCount"; @@ -1513,22 +1511,6 @@ void WebFrameImpl::Closing() { frame_ = NULL; } -void WebFrameImpl::DidReceiveData(DocumentLoader* loader, - const char* data, int length) { - // Set the text encoding. This calls begin() for us. It is safe to call - // this multiple times (Mac does: page/mac/WebCoreFrameBridge.mm). - bool user_chosen = true; - String encoding = frame_->loader()->documentLoader()->overrideEncoding(); - if (encoding.isNull()) { - user_chosen = false; - encoding = loader->response().textEncodingName(); - } - frame_->loader()->setEncoding(encoding, user_chosen); - - // NOTE: mac only does this if there is a document - frame_->loader()->addData(data, length); -} - void WebFrameImpl::DidFail(const ResourceError& error, bool was_provisional) { WebViewImpl* web_view = GetWebViewImpl(); WebViewDelegate* delegate = web_view->delegate(); @@ -1550,6 +1532,23 @@ void WebFrameImpl::DispatchWillSendRequest(WebURLRequest* request) { response); } +void WebFrameImpl::CommitDocumentData(const char* data, size_t data_len) { + DocumentLoader* document_loader = frame_->loader()->documentLoader(); + + // Set the text encoding. This calls begin() for us. It is safe to call + // this multiple times (Mac does: page/mac/WebCoreFrameBridge.mm). + bool user_chosen = true; + String encoding = document_loader->overrideEncoding(); + if (encoding.isNull()) { + user_chosen = false; + encoding = document_loader->response().textEncodingName(); + } + frame_->loader()->setEncoding(encoding, user_chosen); + + // NOTE: mac only does this if there is a document + frame_->loader()->addData(data, data_len); +} + void WebFrameImpl::ExecuteScript(const WebScriptSource& source) { frame_->loader()->executeScript( WebCore::ScriptSourceCode( diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 79f2f01..81ba435 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -92,6 +92,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { const WebKit::WebURL& unreachable_url = WebKit::WebURL(), bool replace = false); virtual void DispatchWillSendRequest(WebKit::WebURLRequest* request); + virtual void CommitDocumentData(const char* data, size_t data_len); virtual void ExecuteScript(const WebKit::WebScriptSource& source); virtual void ExecuteScriptInNewContext( const WebKit::WebScriptSource* sources, int num_sources, @@ -168,9 +169,6 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual bool GetInViewSourceMode() const; - virtual void DidReceiveData(WebCore::DocumentLoader* loader, - const char* data, - int length); virtual void DidFail(const WebCore::ResourceError&, bool was_provisional); virtual std::wstring GetName(); diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index d1a6499..0997a43 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -3,40 +3,30 @@ // found in the LICENSE file. #include "config.h" + #include <string> #include <vector> -#include "base/compiler_specific.h" - -MSVC_PUSH_WARNING_LEVEL(0); #include "Chrome.h" #include "CString.h" #include "Document.h" #include "DocumentLoader.h" -#include "HistoryItem.h" #include "HTMLAppletElement.h" -#include "HTMLCollection.h" #include "HTMLFormElement.h" // needed by FormState.h -#include "HTMLFormControlElement.h" -#include "HTMLInputElement.h" #include "HTMLNames.h" #include "FormState.h" #include "FrameLoader.h" #include "FrameLoadRequest.h" -#include "FrameView.h" #include "MIMETypeRegistry.h" #include "MouseEvent.h" #include "Page.h" #include "PlatformString.h" #include "PluginData.h" -#include "RefPtr.h" #include "StringExtras.h" #include "WindowFeatures.h" -MSVC_POP_WARNING(); - #undef LOG + #include "base/basictypes.h" -#include "base/command_line.h" #include "base/logging.h" #include "base/string_util.h" #include "net/base/mime_util.h" @@ -50,12 +40,8 @@ MSVC_POP_WARNING(); #include "webkit/api/public/WebVector.h" #include "webkit/api/src/WrappedResourceRequest.h" #include "webkit/api/src/WrappedResourceResponse.h" -#include "webkit/glue/autofill_form.h" -#include "webkit/glue/alt_error_page_resource_fetcher.h" #include "webkit/glue/glue_util.h" -#include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/plugins/plugin_list.h" -#include "webkit/glue/searchable_form_data.h" #include "webkit/glue/webdatasource_impl.h" #include "webkit/glue/webdevtoolsagent_impl.h" #include "webkit/glue/webframeloaderclient_impl.h" @@ -81,8 +67,6 @@ using WebKit::WebVector; using WebKit::WrappedResourceRequest; using WebKit::WrappedResourceResponse; -using webkit_glue::AltErrorPageResourceFetcher; - // Domain for internal error codes. static const char kInternalErrorDomain[] = "webkit_glue"; @@ -92,12 +76,11 @@ enum { ERR_POLICY_CHANGE = -10000, }; -WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) : - webframe_(frame), - postpone_loading_data_(false), - has_representation_(false), - sent_initial_response_to_plugin_(false), - next_navigation_policy_(WebKit::WebNavigationPolicyIgnore) { +WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) + : webframe_(frame), + has_representation_(false), + sent_initial_response_to_plugin_(false), + next_navigation_policy_(WebKit::WebNavigationPolicyIgnore) { } WebFrameLoaderClient::~WebFrameLoaderClient() { @@ -120,9 +103,8 @@ void WebFrameLoaderClient::windowObjectCleared() { d->WindowObjectCleared(webframe_); WebDevToolsAgentImpl* tools_agent = webview->GetWebDevToolsAgentImpl(); - if (tools_agent) { + if (tools_agent) tools_agent->WindowObjectCleared(webframe_); - } } void WebFrameLoaderClient::documentElementAvailable() { @@ -210,11 +192,10 @@ void WebFrameLoaderClient::detachedFromParent3() { void WebFrameLoaderClient::assignIdentifierToInitialRequest( unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); + WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); if (d) { WrappedResourceRequest webreq(request); - d->AssignIdentifierToRequest(webview, identifier, webreq); + d->AssignIdentifierToRequest(webframe_, identifier, webreq); } } @@ -267,11 +248,10 @@ void WebFrameLoaderClient::dispatchWillSendRequest( request.setFirstPartyForCookies(KURL("about:blank")); // Give the delegate a crack at the request. - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); + WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); if (d) { WrappedResourceRequest webreq(request); - d->WillSendRequest(webview, identifier, &webreq); + d->WillSendRequest(webframe_, identifier, &webreq); } } @@ -303,40 +283,11 @@ void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge( void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response) { - - - /* TODO(evanm): reenable this once we properly sniff XHTML from text/xml documents. - // True if the request was for the page's main frame, or a subframe. - bool is_frame = ResourceType::IsFrame(DetermineTargetTypeFromLoader(loader)); - if (is_frame && - response.httpStatusCode() == 200 && - mime_util::IsViewSourceMimeType( - webkit_glue::CStringToStdString(response.mimeType().latin1()).c_str())) { - loader->frame()->setInViewSourceMode(); - }*/ - - // When the frame request first 404's, chrome may replace it with the alternate - // 404 page's contents. It does this using substitute data in the document - // loader, so the original response and url of the request can be preserved. - // We need to avoid replacing the current page, if it has already been - // replaced (otherwise could loop on setting alt-404 page!) - bool is_substitute_data = loader->substituteData().isValid(); - - // If it's a 404 page, we wait until we get 512 bytes of data before trying - // to load the document. This allows us to put up an alternate 404 page if - // there's short text. - ResourceRequest::TargetType target_type = - DetermineTargetTypeFromLoader(loader); - postpone_loading_data_ = - ResourceRequest::TargetIsMainFrame == target_type && - !is_substitute_data && - response.httpStatusCode() == 404 && - GetAlt404PageUrl(loader).is_valid(); - if (postpone_loading_data_) - postponed_data_.clear(); - - // Cancel any pending loads. - alt_404_page_fetcher_.reset(NULL); + WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); + if (d) { + WrappedResourceResponse webresp(response); + d->DidReceiveResponse(webframe_, identifier, webresp); + } } void WebFrameLoaderClient::dispatchDidReceiveContentLength( @@ -348,59 +299,9 @@ void WebFrameLoaderClient::dispatchDidReceiveContentLength( // Called when a particular resource load completes void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier) { - if (postpone_loading_data_) { - // The server returned a 404 and the content was < 512 bytes (which we - // suppressed). Go ahead and fetch the alternate page content. - const GURL& url = GetAlt404PageUrl(loader); - DCHECK(url.is_valid()) << - "URL changed? It was valid in dispatchDidReceiveResponse."; - WebURLError original_error; - original_error.unreachableURL = webkit_glue::KURLToWebURL(loader->url()); - alt_404_page_fetcher_.reset(new AltErrorPageResourceFetcher( - url, webframe_, original_error, - NewCallback(this, &WebFrameLoaderClient::Alt404PageFinished))); - } - - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); + WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); if (d) - d->DidFinishLoading(webview, identifier); -} - -GURL WebFrameLoaderClient::GetAlt404PageUrl(DocumentLoader* loader) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (!d) - return GURL(); - - const GURL& failedURL = webkit_glue::KURLToGURL(loader->url()); - - // If trying to view source on a 404 page, just show the original page - // content. - if (webframe_->frame()->inViewSourceMode()) - return GURL(); - - // Construct the URL to fetch from the alt error page server. "html404" - // is understood by the link doctor server. - return d->GetAlternateErrorPageURL(failedURL, WebViewDelegate::HTTP_404); -} - -void WebFrameLoaderClient::Alt404PageFinished(WebFrame* frame, - const WebURLError& original_error, - const std::string& html) { - // TODO(darin): Move this processing out to the embedder. - if (!html.empty()) { - // TODO(tc): Handle backoff on so we don't hammer the alt error page - // servers. - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (!d) - return; - d->LoadNavigationErrorPage(webframe_, WebURLRequest(), original_error, html, - true); - } else { - // Fall back on original text - webframe_->LoadHTMLString(postponed_data_, original_error.unreachableURL); - } + d->DidFinishLoading(webframe_, identifier); } void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, @@ -409,7 +310,7 @@ void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, WebViewImpl* webview = webframe_->GetWebViewImpl(); if (webview && webview->delegate()) { webview->delegate()->DidFailLoadingWithError( - webview, identifier, webkit_glue::ResourceErrorToWebURLError(error)); + webframe_, identifier, webkit_glue::ResourceErrorToWebURLError(error)); } } @@ -730,10 +631,6 @@ void WebFrameLoaderClient::dispatchDidStartProvisionalLoad() { d->DidCompleteClientRedirect(webview, webframe_, expected_client_redirect_src_); } - - // Cancel any pending loads. - if (alt_404_page_fetcher_.get()) - alt_404_page_fetcher_->Cancel(); } void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title) { @@ -1072,6 +969,7 @@ void WebFrameLoaderClient::startDownload(const ResourceRequest& request) { void WebFrameLoaderClient::willChangeTitle(DocumentLoader*) { // FIXME } + void WebFrameLoaderClient::didChangeTitle(DocumentLoader*) { // FIXME } @@ -1079,16 +977,9 @@ void WebFrameLoaderClient::didChangeTitle(DocumentLoader*) { // Called whenever data is received. void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length) { if (!plugin_widget_.get()) { - if (postpone_loading_data_) { - postponed_data_.append(data, length); - if (postponed_data_.length() >= 512) { - postpone_loading_data_ = false; - webframe_->DidReceiveData(loader, postponed_data_.c_str(), - static_cast<int>(postponed_data_.length())); - } - return; - } - webframe_->DidReceiveData(loader, data, length); + WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); + if (d) + d->DidReceiveDocumentData(webframe_, data, length); } // The plugin widget could have been created in the webframe_->DidReceiveData diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h index cdae117..0c57399 100644 --- a/webkit/glue/webframeloaderclient_impl.h +++ b/webkit/glue/webframeloaderclient_impl.h @@ -1,32 +1,20 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H__ -#define WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H__ +#ifndef WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H_ +#define WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H_ #include "FrameLoaderClient.h" #include <wtf/RefPtr.h> -#include "base/scoped_ptr.h" #include "googleurl/src/gurl.h" #include "webkit/api/public/WebNavigationPolicy.h" #include "webkit/glue/webview_delegate.h" -namespace WebCore { -class Frame; -class HTMLFormElement; -class Widget; -} - -namespace webkit_glue { -class AltErrorPageResourceFetcher; -} - class WebFrameImpl; class WebPluginContainer; - class WebFrameLoaderClient : public WebCore::FrameLoaderClient { public: WebFrameLoaderClient(WebFrameImpl* webframe); @@ -204,12 +192,6 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { virtual void registerForIconNotification(bool listen = true); private: - // Callback function for download of alternate 404 pages. If the server is - // down or we take too long to download the page, |html| will be empty. - void Alt404PageFinished(WebFrame* frame, - const WebKit::WebURLError& original_error, - const std::string& html); - void makeDocumentView(); // Given a NavigationAction, determine the associated WebNavigationPolicy. @@ -218,9 +200,6 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { const WebCore::NavigationAction& action, WebKit::WebNavigationPolicy* policy); - // Returns a valid GURL if we have an alt 404 server URL. - GURL GetAlt404PageUrl(WebCore::DocumentLoader* loader); - // Returns NavigationGestureAuto if the last load was not user initiated, // otherwise returns NavigationGestureUnknown. NavigationGesture NavigationGestureForLastLoad(); @@ -232,12 +211,6 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { // the web frame object is guaranteed to exist. WebFrameImpl* webframe_; - // Resource fetcher for downloading an alternate 404 page. - scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_404_page_fetcher_; - - bool postpone_loading_data_; - std::string postponed_data_; - // True if makeRepresentation was called. We don't actually have a concept // of a "representation", but we need to know when we're expected to have one. // See finishedLoading(). @@ -263,4 +236,4 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { WebKit::WebNavigationPolicy next_navigation_policy_; }; -#endif // #ifndef WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H__ +#endif // #ifndef WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H_ diff --git a/webkit/glue/webview_delegate.cc b/webkit/glue/webview_delegate.cc deleted file mode 100644 index 58eab61..0000000 --- a/webkit/glue/webview_delegate.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" - -#undef LOG - -#include "webkit/glue/webview_delegate.h" - -#include "base/logging.h" -#include "googleurl/src/gurl.h" - -GURL WebViewDelegate::GetAlternateErrorPageURL(const GURL& failedURL, - ErrorPageType error_type) { - return GURL(); -} diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index e04fd66..0b4b7fe 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -34,6 +34,7 @@ #include "webkit/api/public/WebTextDirection.h" #include "webkit/api/public/WebWidgetClient.h" #include "webkit/glue/context_menu.h" +#include "webkit/glue/webframe.h" namespace webkit_glue { class WebMediaPlayerDelegate; @@ -324,15 +325,14 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { WebFrame* frame) { } - // If the provisional load fails, we try to load a an error page describing - // the user about the load failure. |html| is the UTF8 text to display. If - // |html| is empty, we will fall back on a local error page. - virtual void LoadNavigationErrorPage( - WebFrame* frame, - const WebKit::WebURLRequest& failed_request, - const WebKit::WebURLError& error, - const std::string& html, - bool replace) { + // Notifies the delegate to commit data for the given frame. The delegate + // may optionally convert the data before calling CommitDocumentData or + // suppress a call to CommitDocumentData. For example, if CommitDocumentData + // is never called, then an empty document will be created. + virtual void DidReceiveDocumentData(WebFrame* frame, + const char* data, + size_t data_len) { + frame->CommitDocumentData(data, data_len); } // Notifies the delegate that the load has changed from provisional to @@ -489,7 +489,7 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { // Resource load callbacks will use the identifier throughout the life of the // request. virtual void AssignIdentifierToRequest( - WebView* webview, + WebFrame* webframe, uint32 identifier, const WebKit::WebURLRequest& request) { } @@ -498,17 +498,22 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { // delegate the opportunity to modify the request. Note that request is // writable here, and changes to the URL, for example, will change the request // to be made. - virtual void WillSendRequest(WebView* webview, + virtual void WillSendRequest(WebFrame* webframe, uint32 identifier, WebKit::WebURLRequest* request) { } + virtual void DidReceiveResponse(WebFrame* webframe, + uint32 identifier, + const WebKit::WebURLResponse& response) { + } + // Notifies the delegate that a subresource load has succeeded. - virtual void DidFinishLoading(WebView* webview, uint32 identifier) { + virtual void DidFinishLoading(WebFrame* webframe, uint32 identifier) { } // Notifies the delegate that a subresource load has failed, and why. - virtual void DidFailLoadingWithError(WebView* webview, + virtual void DidFailLoadingWithError(WebFrame* webframe, uint32 identifier, const WebKit::WebURLError& error) { } @@ -755,18 +760,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { const SkBitmap& image) { } - enum ErrorPageType { - DNS_ERROR, - HTTP_404, - CONNECTION_ERROR, - }; - // If providing an alternate error page (like link doctor), returns the URL - // to fetch instead. If an invalid url is returned, just fall back on local - // error pages. |error_name| tells the delegate what type of error page we - // want (e.g., 404 vs dns errors). - virtual GURL GetAlternateErrorPageURL(const GURL& failedURL, - ErrorPageType error_type); - // History Related --------------------------------------------------------- // Tells the embedder to navigate back or forward in session history by the diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 197cc16..003a8396 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -217,7 +217,7 @@ WebNavigationPolicy TestWebViewDelegate::PolicyForNavigationAction( } void TestWebViewDelegate::AssignIdentifierToRequest( - WebView* webview, + WebFrame* webframe, uint32 identifier, const WebURLRequest& request) { if (shell_->ShouldDumpResourceLoadCallbacks()) @@ -229,7 +229,7 @@ std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { return it != resource_identifier_map_.end() ? it->second : "<unknown>"; } -void TestWebViewDelegate::WillSendRequest(WebView* webview, +void TestWebViewDelegate::WillSendRequest(WebFrame* webframe, uint32 identifier, WebURLRequest* request) { GURL url = request->url(); @@ -242,6 +242,14 @@ void TestWebViewDelegate::WillSendRequest(WebView* webview, request_url.c_str()); } + if (block_redirects_) { + printf("Returning null for this redirect\n"); + + // To block the request, we set its URL to an empty one. + request->setURL(WebURL()); + return; + } + if (TestShell::layout_test_mode() && !host.empty() && (url.SchemeIs("http") || url.SchemeIs("https")) && host != "127.0.0.1" && @@ -260,7 +268,7 @@ void TestWebViewDelegate::WillSendRequest(WebView* webview, request->setURL(GURL(TestShell::RewriteLocalUrl(request_url))); } -void TestWebViewDelegate::DidFinishLoading(WebView* webview, +void TestWebViewDelegate::DidFinishLoading(WebFrame* webframe, uint32 identifier) { TRACE_EVENT_END("url.load", identifier, ""); if (shell_->ShouldDumpResourceLoadCallbacks()) { @@ -271,7 +279,7 @@ void TestWebViewDelegate::DidFinishLoading(WebView* webview, resource_identifier_map_.erase(identifier); } -void TestWebViewDelegate::DidFailLoadingWithError(WebView* webview, +void TestWebViewDelegate::DidFailLoadingWithError(WebFrame* webframe, uint32 identifier, const WebURLError& error) { if (shell_->ShouldDumpResourceLoadCallbacks()) { diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 4e9de10..6d88580 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -182,14 +182,14 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, const WebKit::WebURLError& error, WebFrame* for_frame); - virtual void AssignIdentifierToRequest(WebView* webview, + virtual void AssignIdentifierToRequest(WebFrame* webframe, uint32 identifier, const WebKit::WebURLRequest& request); - virtual void WillSendRequest(WebView* webview, + virtual void WillSendRequest(WebFrame* webframe, uint32 identifier, WebKit::WebURLRequest* request); - virtual void DidFinishLoading(WebView* webview, uint32 identifier); - virtual void DidFailLoadingWithError(WebView* webview, + virtual void DidFinishLoading(WebFrame* webframe, uint32 identifier); + virtual void DidFailLoadingWithError(WebFrame* webframe, uint32 identifier, const WebKit::WebURLError& error); @@ -280,6 +280,13 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, void SetCustomPolicyDelegate(bool is_custom, bool is_permissive); void WaitForPolicyDelegate(); + void set_block_redirects(bool block_redirects) { + block_redirects_ = block_redirects; + } + bool block_redirects() const { + return block_redirects_; + } + protected: // Called the title of the page changes. // Can be used to update the title of the window. @@ -349,6 +356,9 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, // true if we want to enable selection of trailing whitespaces bool select_trailing_whitespace_enabled_; + // true if we should block any redirects + bool block_redirects_; + CapturedContextMenuEvents captured_context_menu_events_; WebCursor current_cursor_; diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 17531ce..5b0eefd 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1424,7 +1424,6 @@ 'glue/weburlloader_impl.cc', 'glue/weburlloader_impl.h', 'glue/webview.h', - 'glue/webview_delegate.cc', 'glue/webview_delegate.h', 'glue/webview_impl.cc', 'glue/webview_impl.h', |