diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 17:12:55 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 17:12:55 +0000 |
commit | e6f546c3ab626d39d375376890b7f4bfef92f48e (patch) | |
tree | cbf7b1218db462116ea45f8536ee0900cb1f9ea6 /webkit | |
parent | 0e2dc851dc1ba72d849d22eba47ea053b2721916 (diff) | |
download | chromium_src-e6f546c3ab626d39d375376890b7f4bfef92f48e.zip chromium_src-e6f546c3ab626d39d375376890b7f4bfef92f48e.tar.gz chromium_src-e6f546c3ab626d39d375376890b7f4bfef92f48e.tar.bz2 |
Add Reload and LoadData methods to WebFrame. LoadData replaces
LoadAlternateHTMLString, changing types to WebKit API types and
allowing for more flexibility (supports loading non-HTML data).
LoadHTMLString is modified to support some optional parameters.
Note: Since WebFrame is going to soon be part of the WebKit API,
it is OK style-wise for it to use optional parameters.
This patch also includes a change to remove the securityInfo
property from WebURLRequest. I did this so that I could eliminate
the need to pass a WebURLRequest to LoadData / LoadHTMLString.
This also fixes a TODO of mine to eliminate this field on
WebCore::ResourceRequest since securityInfo (SSL cert info) is
really more of a response property. It was only part of the
request as a hack to support certain error pages. I work around
that by leveraging NavigationState in chrome/renderer.
I added some templatized, implicit constructors to WebData for
convenience. I plan to make similar changes to WebCString and
WebString in a future CL.
This CL is a incremental step toward moving ResourceFetcher out
of WebFrame.
BUG=15648
TEST=none
R=dglazkov
Review URL: http://codereview.chromium.org/150146
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/api/public/WebData.h | 25 | ||||
-rw-r--r-- | webkit/api/public/WebFrame.h | 17 | ||||
-rw-r--r-- | webkit/api/public/WebURLRequest.h | 6 | ||||
-rw-r--r-- | webkit/api/src/WebURLRequest.cpp | 10 | ||||
-rw-r--r-- | webkit/glue/bookmarklet_unittest.cc | 11 | ||||
-rw-r--r-- | webkit/glue/cpp_bound_class_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/dom_serializer_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/glue_util.cc | 10 | ||||
-rw-r--r-- | webkit/glue/glue_util.h | 8 | ||||
-rw-r--r-- | webkit/glue/webframe.h | 51 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 192 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 45 | ||||
-rw-r--r-- | webkit/glue/webframe_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 10 | ||||
-rw-r--r-- | webkit/tools/test_shell/plugin_tests.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 18 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 13 |
18 files changed, 227 insertions, 200 deletions
diff --git a/webkit/api/public/WebData.h b/webkit/api/public/WebData.h index 2666789..ad14fa1 100644 --- a/webkit/api/public/WebData.h +++ b/webkit/api/public/WebData.h @@ -1,10 +1,10 @@ /* * Copyright (C) 2009 Google 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: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -57,6 +57,12 @@ namespace WebKit { assign(data, size); } + template <int N> + WebData(const char (&data)[N]) : m_private(0) + { + assign(data, N - 1); + } + WebData(const WebData& d) : m_private(0) { assign(d); } WebData& operator=(const WebData& d) @@ -79,6 +85,19 @@ namespace WebKit { WebData(const WTF::PassRefPtr<WebCore::SharedBuffer>&); WebData& operator=(const WTF::PassRefPtr<WebCore::SharedBuffer>&); operator WTF::PassRefPtr<WebCore::SharedBuffer>() const; +#else + template <class C> + WebData(const C& c) : m_private(0) + { + assign(c.data(), c.size()); + } + + template <class C> + WebData& operator=(const C& c) + { + assign(c.data(), c.size()); + return *this; + } #endif private: diff --git a/webkit/api/public/WebFrame.h b/webkit/api/public/WebFrame.h index be58d6c..fa7e5f5 100644 --- a/webkit/api/public/WebFrame.h +++ b/webkit/api/public/WebFrame.h @@ -158,18 +158,23 @@ namespace WebKit { // Navigation ---------------------------------------------------------- - virtual void loadURL(const WebURLRequest&) = 0; + virtual void reload() = 0; + + virtual void loadRequest(const WebURLRequest&) = 0; + + virtual void loadHistoryItem(const WebHistoryItem&) = 0; virtual void loadData(const WebData& data, const WebString& mimeType, const WebString& textEncoding, const WebURL& baseURL, - const WebURL& unreachableURL, - bool replace) = 0; + const WebURL& unreachableURL = WebURL(), + bool replace = false) = 0; - virtual void loadHistorical(const WebHistoryItem&) = 0; - - virtual void reload() = 0; + virtual void loadHTMLString(const WebData& html, + const WebURL& baseURL, + const WebURL& unreachableURL = WebURL(), + bool replace = false) = 0; virtual bool isLoading() = 0; diff --git a/webkit/api/public/WebURLRequest.h b/webkit/api/public/WebURLRequest.h index dcd580a..6499b85 100644 --- a/webkit/api/public/WebURLRequest.h +++ b/webkit/api/public/WebURLRequest.h @@ -125,12 +125,6 @@ namespace WebKit { WEBKIT_API int appCacheContextID() const; WEBKIT_API void setAppCacheContextID(int id); - // A consumer controlled value intended to be used to record opaque - // security info related to this request. - // FIXME: This really doesn't belong here! - WEBKIT_API WebCString securityInfo() const; - WEBKIT_API void setSecurityInfo(const WebCString&); - #if defined(WEBKIT_IMPLEMENTATION) WebCore::ResourceRequest& toMutableResourceRequest(); const WebCore::ResourceRequest& toResourceRequest() const; diff --git a/webkit/api/src/WebURLRequest.cpp b/webkit/api/src/WebURLRequest.cpp index 542dc23..4611872 100644 --- a/webkit/api/src/WebURLRequest.cpp +++ b/webkit/api/src/WebURLRequest.cpp @@ -209,16 +209,6 @@ void WebURLRequest::setAppCacheContextID(int appCacheContextID) m_private->m_resourceRequest->setAppCacheContextID(appCacheContextID); } -WebCString WebURLRequest::securityInfo() const -{ - return m_private->m_resourceRequest->securityInfo(); -} - -void WebURLRequest::setSecurityInfo(const WebCString& securityInfo) -{ - m_private->m_resourceRequest->setSecurityInfo(securityInfo); -} - ResourceRequest& WebURLRequest::toMutableResourceRequest() { ASSERT(m_private); diff --git a/webkit/glue/bookmarklet_unittest.cc b/webkit/glue/bookmarklet_unittest.cc index 7aed7f0..da06bd1 100644 --- a/webkit/glue/bookmarklet_unittest.cc +++ b/webkit/glue/bookmarklet_unittest.cc @@ -31,6 +31,17 @@ TEST_F(BookmarkletTest, Redirect) { EXPECT_EQ(L"SUCCESS", text); } +TEST_F(BookmarkletTest, RedirectVoided) { + // This test should be redundant with the Redirect test above. The point + // here is to emphasize that in either case the assignment to location during + // the evaluation of the script should suppress loading the script result. + // Here, because of the void() wrapping there is no script result. + test_shell_->LoadURL(L"javascript:void(location.href='data:text/plain,SUCCESS')"); + test_shell_->WaitTestFinished(); + std::wstring text = test_shell_->GetDocumentText(); + EXPECT_EQ(L"SUCCESS", text); +} + TEST_F(BookmarkletTest, NonEmptyResult) { std::wstring text; diff --git a/webkit/glue/cpp_bound_class_unittest.cc b/webkit/glue/cpp_bound_class_unittest.cc index 2579d0f..38aefa3 100644 --- a/webkit/glue/cpp_bound_class_unittest.cc +++ b/webkit/glue/cpp_bound_class_unittest.cc @@ -9,6 +9,8 @@ #include <vector> #include "base/message_loop.h" +#include "webkit/api/public/WebData.h" +#include "webkit/api/public/WebURL.h" #include "webkit/glue/cpp_binding_example.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webframe.h" diff --git a/webkit/glue/devtools/dom_agent_unittest.cc b/webkit/glue/devtools/dom_agent_unittest.cc index e9d9850..3c693b2 100644 --- a/webkit/glue/devtools/dom_agent_unittest.cc +++ b/webkit/glue/devtools/dom_agent_unittest.cc @@ -19,6 +19,8 @@ #include "base/values.h" #include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/api/public/WebData.h" +#include "webkit/api/public/WebURL.h" #include "webkit/glue/devtools/devtools_mock_rpc.h" #include "webkit/glue/devtools/devtools_rpc.h" #include "webkit/glue/devtools/dom_agent_impl.h" diff --git a/webkit/glue/dom_serializer_unittest.cc b/webkit/glue/dom_serializer_unittest.cc index 66200f8..d3f7e8e 100644 --- a/webkit/glue/dom_serializer_unittest.cc +++ b/webkit/glue/dom_serializer_unittest.cc @@ -29,6 +29,8 @@ MSVC_POP_WARNING(); #include "base/string_util.h" #include "net/base/net_util.h" #include "net/url_request/url_request_context.h" +#include "webkit/api/public/WebData.h" +#include "webkit/api/public/WebURL.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/dom_operations_private.h" #include "webkit/glue/dom_serializer.h" diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc index f80604b..c695d87 100644 --- a/webkit/glue/glue_util.cc +++ b/webkit/glue/glue_util.cc @@ -126,6 +126,16 @@ std::string WebStringToStdString(const WebKit::WebString& str) { return ret; } +WebKit::WebData SharedBufferToWebData( + const WTF::PassRefPtr<WebCore::SharedBuffer>& buf) { + return buf; +} + +WTF::PassRefPtr<WebCore::SharedBuffer> WebDataToSharedBuffer( + const WebKit::WebData& data) { + return data; +} + FilePath::StringType StringToFilePathString(const WebCore::String& str) { #if defined(OS_WIN) return StringToStdWString(str); diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h index b22a610..bb98461 100644 --- a/webkit/glue/glue_util.h +++ b/webkit/glue/glue_util.h @@ -21,12 +21,14 @@ class IntSize; class KURL; class ResourceError; class ResourceResponse; +class SharedBuffer; class String; struct ResourceRequest; } namespace WebKit { class WebCString; +class WebData; class WebDragData; class WebForm; class WebHistoryItem; @@ -82,6 +84,12 @@ WebCore::CString WebCStringToCString(const WebKit::WebCString& str); WebKit::WebString StdStringToWebString(const std::string& str); std::string WebStringToStdString(const WebKit::WebString& str); +// WebCore::SharedBuffer <-> WebData. No charset conversion. +WebKit::WebData SharedBufferToWebData( + const WTF::PassRefPtr<WebCore::SharedBuffer>& buf); +WTF::PassRefPtr<WebCore::SharedBuffer> WebDataToSharedBuffer( + const WebKit::WebData& data); + FilePath::StringType StringToFilePathString(const WebCore::String& str); WebCore::String FilePathStringToString(const FilePath::StringType& str); diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index c7927ea..8745362 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -12,6 +12,7 @@ #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/platform_canvas.h" #include "webkit/api/public/WebCanvas.h" +#include "webkit/api/public/WebURL.h" class GURL; class WebView; @@ -19,9 +20,11 @@ class WebTextInput; struct NPObject; namespace WebKit { +class WebData; class WebDataSource; class WebForm; class WebHistoryItem; +class WebString; class WebURLRequest; struct WebConsoleMessage; struct WebFindOptions; @@ -83,6 +86,9 @@ class WebFrame { virtual v8::Local<v8::Context> GetScriptContext() = 0; #endif + // Reload the current document. + virtual void Reload() = 0; + // Loads the given WebURLRequest. virtual void LoadRequest(const WebKit::WebURLRequest& request) = 0; @@ -90,30 +96,27 @@ class WebFrame { // navigation. virtual void LoadHistoryItem(const WebKit::WebHistoryItem& item) = 0; - // This method is short-hand for calling LoadAlternateHTMLString with a dummy - // request for the given base_url. - virtual void LoadHTMLString(const std::string& html_text, - const GURL& base_url) = 0; - - // Loads alternative HTML text in place of a particular URL. This method is - // designed with error pages in mind, in which case it would typically be - // called in response to WebViewDelegate's didFailProvisionalLoadWithError - // method. - // - // |html_text| is a utf8 string to load in the frame. |display_url| is the - // URL that the content will appear to have been loaded from. The |replace| - // parameter controls how this affects session history. If |replace| is - // true, then the current session history entry is replaced with the given - // HTML text. Otherwise, a new navigation is produced. - // - // In either case, when the corresponding session history entry is revisited, - // it is the given request /w the |display_url| substituted for the request's - // URL, which is repeated. The |html_text| is not stored in session history. - // - virtual void LoadAlternateHTMLString(const WebKit::WebURLRequest& request, - const std::string& html_text, - const GURL& display_url, - bool replace) = 0; + // Loads the given data with specific mime type and optional text encoding. + // For HTML data, base_url indicates the security origin of the document and + // is used to resolve links. If specified, unreachable_url is reported via + // WebDataSource::unreachableURL. If replace is false, then this data will + // be loaded as a normal navigation. Otherwise, the current history item + // will be replaced. + virtual void LoadData( + const WebKit::WebData& data, + const WebKit::WebString& mime_type, + const WebKit::WebString& text_encoding, + const WebKit::WebURL& base_url, + const WebKit::WebURL& unreachable_url = WebKit::WebURL(), + bool replace = false) = 0; + + // This method is short-hand for calling LoadData, where mime_type is + // "text/html" and text_encoding is "UTF-8". + virtual void LoadHTMLString( + const WebKit::WebData& html, + const WebKit::WebURL& base_url, + const WebKit::WebURL& unreachable_url = WebKit::WebURL(), + bool replace = false) = 0; // Asks the WebFrame to try and download the alternate error page. We notify // the WebViewDelegate of the results so it can decide whether or not to show diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index b5f2742..3f26032 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -196,6 +196,8 @@ using WebCore::ResourceError; using WebCore::ResourceHandle; using WebCore::ResourceRequest; using WebCore::VisibleSelection; +using WebCore::ScriptValue; +using WebCore::SecurityOrigin; using WebCore::SharedBuffer; using WebCore::String; using WebCore::SubstituteData; @@ -205,6 +207,7 @@ using WebCore::XPathResult; using WebKit::WebCanvas; using WebKit::WebConsoleMessage; +using WebKit::WebData; using WebKit::WebDataSource; using WebKit::WebFindOptions; using WebKit::WebHistoryItem; @@ -212,6 +215,7 @@ using WebKit::WebForm; using WebKit::WebRect; using WebKit::WebScriptSource; using WebKit::WebSize; +using WebKit::WebString; using WebKit::WebURL; using WebKit::WebURLError; using WebKit::WebURLRequest; @@ -412,8 +416,25 @@ void WebFrameImpl::InitMainFrame(WebViewImpl* webview_impl) { frame_->init(); } +void WebFrameImpl::Reload() { + frame_->loader()->saveDocumentAndScrollState(); + + StopLoading(); // Make sure existing activity stops. + frame_->loader()->reload(); +} + void WebFrameImpl::LoadRequest(const WebURLRequest& request) { - InternalLoadRequest(request, SubstituteData(), false); + const ResourceRequest* resource_request = + webkit_glue::WebURLRequestToResourceRequest(&request); + DCHECK(resource_request); + + if (resource_request->url().protocolIs("javascript")) { + LoadJavaScriptURL(resource_request->url()); + return; + } + + StopLoading(); // Make sure existing activity stops. + frame_->loader()->load(*resource_request, false); } void WebFrameImpl::LoadHistoryItem(const WebHistoryItem& item) { @@ -421,7 +442,7 @@ void WebFrameImpl::LoadHistoryItem(const WebHistoryItem& item) { webkit_glue::WebHistoryItemToHistoryItem(item); DCHECK(history_item.get()); - StopLoading(); // make sure existing activity stops + StopLoading(); // Make sure existing activity stops. // If there is no current_item, which happens when we are navigating in // session history after a crash, we need to manufacture one otherwise WebKit @@ -438,78 +459,39 @@ void WebFrameImpl::LoadHistoryItem(const WebHistoryItem& item) { WebCore::FrameLoadTypeIndexedBackForward); } -void WebFrameImpl::InternalLoadRequest(const WebURLRequest& request, - const SubstituteData& data, - bool replace) { - const ResourceRequest* resource_request = - webkit_glue::WebURLRequestToResourceRequest(&request); - DCHECK(resource_request); - - // Special-case javascript URLs. Do not interrupt the existing load when - // asked to load a javascript URL unless the script generates a result. We - // can't just use FrameLoader::executeIfJavaScriptURL because it doesn't - // handle redirects properly. - const KURL& kurl = resource_request->url(); - if (!data.isValid() && kurl.protocol() == "javascript") { - // Don't attempt to reload javascript URLs. - if (resource_request->cachePolicy() == ReloadIgnoringCacheData) - return; - - // We can't load a javascript: URL if there is no Document! - if (!frame_->document()) - return; +void WebFrameImpl::LoadData(const WebData& data, + const WebString& mime_type, + const WebString& text_encoding, + const WebURL& base_url, + const WebURL& unreachable_url, + bool replace) { + SubstituteData subst_data( + webkit_glue::WebDataToSharedBuffer(data), + webkit_glue::WebStringToString(mime_type), + webkit_glue::WebStringToString(text_encoding), + webkit_glue::WebURLToKURL(unreachable_url)); + DCHECK(subst_data.isValid()); - // TODO(darin): Is this the best API to use here? It works and seems - // good, but will it change out from under us? - String script = decodeURLEscapeSequences( - kurl.string().substring(sizeof("javascript:")-1)); - WebCore::ScriptValue result = frame_->loader()->executeScript(script, true); - String scriptResult; - if (result.getString(scriptResult) && - !frame_->loader()->isScheduledLocationChangePending()) { - // TODO(darin): We need to figure out how to represent this in session - // history. Hint: don't re-eval script when the user or script - // navigates back-n-forth (instead store the script result somewhere). - LoadDocumentData(kurl, scriptResult, String("text/html"), String()); - } - return; + StopLoading(); // Make sure existing activity stops. + frame_->loader()->load(ResourceRequest(webkit_glue::WebURLToKURL(base_url)), + subst_data, false); + if (replace) { + // Do this to force WebKit to treat the load as replacing the currently + // loaded page. + frame_->loader()->setReplacing(); } - - StopLoading(); // make sure existing activity stops - - if (data.isValid()) { - DCHECK(resource_request); - frame_->loader()->load(*resource_request, data, false); - if (replace) { - // Do this to force WebKit to treat the load as replacing the currently - // loaded page. - frame_->loader()->setReplacing(); - } - } else if (resource_request->cachePolicy() == ReloadIgnoringCacheData) { - frame_->loader()->reload(); - } else { - frame_->loader()->load(*resource_request, false); - } -} - -void WebFrameImpl::LoadHTMLString(const std::string& html_text, - const GURL& base_url) { - LoadAlternateHTMLString(WebURLRequest(base_url), html_text, GURL(), false); } -void WebFrameImpl::LoadAlternateHTMLString(const WebURLRequest& request, - const std::string& html_text, - const GURL& display_url, - bool replace) { - int len = static_cast<int>(html_text.size()); - RefPtr<SharedBuffer> buf = SharedBuffer::create(html_text.data(), len); - - SubstituteData subst_data( - buf, String("text/html"), String("UTF-8"), - webkit_glue::GURLToKURL(display_url)); - DCHECK(subst_data.isValid()); - - InternalLoadRequest(request, subst_data, replace); +void WebFrameImpl::LoadHTMLString(const WebData& data, + const WebURL& base_url, + const WebURL& unreachable_url, + bool replace) { + LoadData(data, + WebString::fromUTF8("text/html"), + WebString::fromUTF8("UTF-8"), + base_url, + unreachable_url, + replace); } GURL WebFrameImpl::GetURL() const { @@ -579,32 +561,6 @@ WebHistoryItem WebFrameImpl::GetCurrentHistoryItem() const { frame_->page()->backForwardList()->currentItem()); } -void WebFrameImpl::LoadDocumentData(const KURL& base_url, - const String& data, - const String& mime_type, - const String& charset) { - // TODO(darin): This is wrong. We need to re-cast this in terms of a call to - // one of the FrameLoader::load(...) methods. Else, WebCore will be angry!! - - // Requiring a base_url here seems like a good idea for security reasons. - ASSERT(!base_url.isEmpty()); - ASSERT(!mime_type.isEmpty()); - - StopLoading(); - - // Reset any pre-existing scroll offset - frameview()->setScrollPosition(WebCore::IntPoint()); - - // Make sure the correct document type is constructed. - frame_->loader()->setResponseMIMEType(mime_type); - - // TODO(darin): Inform the FrameLoader of the charset somehow. - - frame_->loader()->begin(base_url); - frame_->loader()->write(data); - frame_->loader()->end(); -} - static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) { return loader ? WebDataSourceImpl::FromLoader(loader) : NULL; } @@ -1600,15 +1556,14 @@ void WebFrameImpl::LoadAlternateHTMLErrorPage(const WebURLRequest& request, const GURL& error_page_url, bool replace, const GURL& fake_url) { - // Load alternate HTML in place of the previous request. We create a copy of - // the original request so we can replace its URL with a dummy URL. That - // prevents other web content from the same origin as the failed URL to - // script the error page. - WebURLRequest failed_request(request); - failed_request.setURL(fake_url); + // Load alternate HTML in place of the previous request. We use a fake_url + // for the Base URL. That prevents other web content from the same origin + // as the failed URL to script the error page. - LoadAlternateHTMLString(failed_request, std::string(), - error.unreachableURL, replace); + LoadHTMLString("", // Empty document + fake_url, + error.unreachableURL, + replace); alt_error_page_fetcher_.reset(new AltErrorPageResourceFetcher( GetWebViewImpl(), error, this, error_page_url)); @@ -1843,3 +1798,32 @@ void WebFrameImpl::ClearPasswordListeners() { } password_listeners_.clear(); } + +void WebFrameImpl::LoadJavaScriptURL(const KURL& url) { + // This is copied from FrameLoader::executeIfJavaScriptURL. Unfortunately, + // we cannot just use that method since it is private, and it also doesn't + // quite behave as we require it to for bookmarklets. The key difference is + // that we need to suppress loading the string result from evaluating the JS + // URL if executing the JS URL resulted in a location change. We also allow + // a JS URL to be loaded even if scripts on the page are otherwise disabled. + + if (!frame_->document() || !frame_->page()) + return; + + String script = + decodeURLEscapeSequences(url.string().substring(strlen("javascript:"))); + ScriptValue result = frame_->loader()->executeScript(script, true); + + String script_result; + if (!result.getString(script_result)) + return; + + SecurityOrigin* security_origin = frame_->document()->securityOrigin(); + + if (!frame_->loader()->isScheduledLocationChangePending()) { + frame_->loader()->stopAllLoaders(); + frame_->loader()->begin(frame_->loader()->url(), true, security_origin); + frame_->loader()->write(script_result); + frame_->loader()->end(); + } +} diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 8baab14..4919a0b 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -52,6 +52,7 @@ namespace WebCore { class Frame; class FrameView; class HistoryItem; +class KURL; class Node; class Range; class SubstituteData; @@ -76,19 +77,27 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { void InitMainFrame(WebViewImpl* webview_impl); // WebFrame + virtual void Reload(); virtual void LoadRequest(const WebKit::WebURLRequest& request); virtual void LoadHistoryItem(const WebKit::WebHistoryItem& item); - virtual void LoadHTMLString(const std::string& html_text, - const GURL& base_url); - virtual void LoadAlternateHTMLString(const WebKit::WebURLRequest& request, - const std::string& html_text, - const GURL& display_url, - bool replace); - virtual void LoadAlternateHTMLErrorPage(const WebKit::WebURLRequest& request, - const WebKit::WebURLError& error, - const GURL& error_page_url, - bool replace, - const GURL& fake_url); + virtual void LoadData( + const WebKit::WebData& data, + const WebKit::WebString& mime_type, + const WebKit::WebString& text_encoding, + const WebKit::WebURL& base_url, + const WebKit::WebURL& unreachable_url = WebKit::WebURL(), + bool replace = false); + virtual void LoadHTMLString( + const WebKit::WebData& data, + const WebKit::WebURL& base_url, + const WebKit::WebURL& unreachable_url = WebKit::WebURL(), + bool replace = false); + virtual void LoadAlternateHTMLErrorPage( + const WebKit::WebURLRequest& request, + const WebKit::WebURLError& error, + const GURL& error_page_url, + bool replace, + const GURL& fake_url); virtual void ExecuteScript(const WebKit::WebScriptSource& source); virtual void ExecuteScriptInNewContext( const WebKit::WebScriptSource* sources, int num_sources); @@ -264,14 +273,6 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { // WebFrameLoaderClient void Closing(); - // A helper function for loading some document, given all of its data, into - // this frame. The charset may be empty if unknown, but a mime type must be - // specified. TODO(darin): Add option for storing this in session history. - void LoadDocumentData(const WebCore::KURL& base_url, - const WebCore::String& data, - const WebCore::String& mime_type, - const WebCore::String& charset); - // See WebFrame.h for details. virtual void IncreaseMatchCount(int count, int request_id); virtual void ReportFindInPageSelection(const WebKit::WebRect& selection_rect, @@ -386,13 +387,11 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { // Determines whether to invalidate the content area and scrollbar. void InvalidateIfNecessary(); - void InternalLoadRequest(const WebKit::WebURLRequest& request, - const WebCore::SubstituteData& data, - bool replace); - // Clears the map of password listeners. void ClearPasswordListeners(); + void LoadJavaScriptURL(const WebCore::KURL& url); + // Valid between calls to BeginPrint() and EndPrint(). Containts the print // information. Is used by PrintPage(). scoped_ptr<ChromePrintContext> print_context_; diff --git a/webkit/glue/webframe_unittest.cc b/webkit/glue/webframe_unittest.cc index bc964b2..833d03b1 100644 --- a/webkit/glue/webframe_unittest.cc +++ b/webkit/glue/webframe_unittest.cc @@ -4,6 +4,8 @@ #include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/api/public/WebData.h" +#include "webkit/api/public/WebURL.h" #include "webkit/glue/webframe.h" #include "webkit/glue/webview.h" #include "webkit/tools/test_shell/test_shell_test.h" diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index c886b80..e99813e 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -67,9 +67,13 @@ MSVC_POP_WARNING(); #include "webkit/glue/webview_impl.h" using namespace WebCore; + using base::Time; using base::TimeDelta; + +using WebKit::WebData; using WebKit::WebNavigationType; +using WebKit::WebString; using WebKit::WebURL; using WebKit::WebVector; using WebKit::WrappedResourceRequest; @@ -360,14 +364,14 @@ GURL WebFrameLoaderClient::GetAlt404PageUrl(DocumentLoader* loader) { void WebFrameLoaderClient::Alt404PageFinished(DocumentLoader* loader, const std::string& html) { + const WebURL& base_url = webkit_glue::KURLToWebURL(loader->url()); if (html.length() > 0) { // TODO(tc): Handle backoff on so we don't hammer the alt error page // servers. - webframe_->LoadHTMLString(html, webkit_glue::KURLToGURL(loader->url())); + webframe_->LoadHTMLString(html, base_url); } else { // Fall back on original text - webframe_->LoadHTMLString(postponed_data_, - webkit_glue::KURLToGURL(loader->url())); + webframe_->LoadHTMLString(postponed_data_, base_url); } } diff --git a/webkit/tools/test_shell/plugin_tests.cc b/webkit/tools/test_shell/plugin_tests.cc index f739aec..a0951c9 100644 --- a/webkit/tools/test_shell/plugin_tests.cc +++ b/webkit/tools/test_shell/plugin_tests.cc @@ -10,8 +10,9 @@ #include "base/string_util.h" #include "net/base/escape.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/api/public/WebScriptSource.h" +#include "webkit/api/public/WebData.h" #include "webkit/api/public/WebInputEvent.h" +#include "webkit/api/public/WebScriptSource.h" #include "webkit/glue/webframe.h" #include "webkit/glue/webview.h" #include "webkit/tools/test_shell/test_shell.h" diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 568f401..b2249a6 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -526,23 +526,15 @@ bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { // If we are reloading, then WebKit will use the state of the current page. // Otherwise, we give it the state to navigate to. - if (!reload && !entry.GetContentState().empty()) { + if (reload) { + frame->Reload(); + } else if (!entry.GetContentState().empty()) { DCHECK(entry.GetPageID() != -1); frame->LoadHistoryItem( webkit_glue::HistoryItemFromString(entry.GetContentState())); } else { - WebURLRequest::CachePolicy cache_policy; - if (reload) { - cache_policy = WebURLRequest::ReloadIgnoringCacheData; - } else { - DCHECK(entry.GetPageID() == -1); - cache_policy = WebURLRequest::UseProtocolCachePolicy; - } - - WebURLRequest request(entry.GetURL()); - request.setCachePolicy(cache_policy); - - frame->LoadRequest(request); + DCHECK(entry.GetPageID() == -1); + frame->LoadRequest(WebURLRequest(entry.GetURL())); } // In case LoadRequest failed before DidCreateDataSource was called. diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 912b937..b97c923 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -18,6 +18,7 @@ #include "base/string_util.h" #include "base/trace_event.h" #include "net/base/net_errors.h" +#include "webkit/api/public/WebData.h" #include "webkit/api/public/WebDataSource.h" #include "webkit/api/public/WebDragData.h" #include "webkit/api/public/WebHistoryItem.h" @@ -50,6 +51,7 @@ #include "webkit/tools/test_shell/drop_delegate.h" #endif +using WebKit::WebData; using WebKit::WebDataSource; using WebKit::WebDragData; using WebKit::WebHistoryItem; @@ -342,18 +344,15 @@ void TestWebViewDelegate::DidFailProvisionalLoadWithError( static_cast<TestShellExtraData*>(failed_ds->extraData()); bool replace = extra_data && extra_data->pending_page_id != -1; - WebURLRequest request = failed_ds->request(); - - std::string error_text = + const std::string& error_text = StringPrintf("Error %d when loading url %s", error.reason, - request.url().spec().data()); - request.setURL(GURL("testshell-error:")); + failed_ds->request().url().spec().data()); // Make sure we never show errors in view source mode. frame->SetInViewSourceMode(false); - frame->LoadAlternateHTMLString( - request, error_text, error.unreachableURL, replace); + frame->LoadHTMLString( + error_text, GURL("testshell-error:"), error.unreachableURL, replace); } void TestWebViewDelegate::DidCommitLoadForFrame(WebView* webview, |