diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 04:29:17 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 04:29:17 +0000 |
commit | 3d96893747d18a3c1bf06084d4605a4b34af732f (patch) | |
tree | 9347442c4dd581ab825ed22cddc082e6119000e4 /webkit | |
parent | 47b0ee174aa53dd1fd473bafae35166538f57a68 (diff) | |
download | chromium_src-3d96893747d18a3c1bf06084d4605a4b34af732f.zip chromium_src-3d96893747d18a3c1bf06084d4605a4b34af732f.tar.gz chromium_src-3d96893747d18a3c1bf06084d4605a4b34af732f.tar.bz2 |
Hook up WebFrameClient, replacing many WebViewDelegate methods.
Moved NavigationGesture out of webview_delegate.h into its own
header in chrome/common since it is only needed by Chrome.
Adds WebFrame::isProcessingUserGesture to facilitate the removal
of NavigationGesture.
Cleaned up some TestShell methods related to URL loading. The
method to load an URL now takes a GURL instead of a wchar_t*.
R=dglazkov
BUG=21332
TEST=none
Review URL: http://codereview.chromium.org/200054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
45 files changed, 828 insertions, 1167 deletions
diff --git a/webkit/api/public/WebFrame.h b/webkit/api/public/WebFrame.h index 69e809e..6cde878 100644 --- a/webkit/api/public/WebFrame.h +++ b/webkit/api/public/WebFrame.h @@ -296,6 +296,9 @@ namespace WebKit { // Returns the number of registered unload listeners. virtual unsigned unloadListenerCount() const = 0; + // Returns true if a user gesture is currently being processed. + virtual bool isProcessingUserGesture() const = 0; + // Editing ------------------------------------------------------------- diff --git a/webkit/api/public/WebFrameClient.h b/webkit/api/public/WebFrameClient.h index bdb38fa..cc97ada 100644 --- a/webkit/api/public/WebFrameClient.h +++ b/webkit/api/public/WebFrameClient.h @@ -31,20 +31,26 @@ #ifndef WebFrameClient_h #define WebFrameClient_h -#error "This header file is still a work in progress; do not include!" - #include "WebCommon.h" -#include "WebNavigationGesture.h" +#include "WebNavigationPolicy.h" +#include "WebNavigationType.h" namespace WebKit { + class WebDataSource; class WebForm; class WebFrame; class WebMediaPlayer; class WebMediaPlayerClient; + class WebPlugin; class WebString; class WebURL; + class WebURLRequest; + class WebURLResponse; class WebWorker; class WebWorkerClient; + struct WebPluginParams; + struct WebSize; + struct WebURLError; class WebFrameClient { public: @@ -90,7 +96,8 @@ namespace WebKit { // A client-side redirect will occur. This may correspond to a <META // refresh> or some script activity. virtual void willPerformClientRedirect( - WebFrame*, const WebURL&, double interval, double fireTime) = 0; + WebFrame*, const WebURL& from, const WebURL& to, + double interval, double fireTime) = 0; // A client-side redirect was cancelled. virtual void didCancelClientRedirect(WebFrame*) = 0; @@ -103,7 +110,7 @@ namespace WebKit { virtual void didCreateDataSource(WebFrame*, WebDataSource*) = 0; // A new provisional load has been started. - virtual void didStartProvisionalLoad(WebFrame*, WebNavigationGesture) = 0; + virtual void didStartProvisionalLoad(WebFrame*) = 0; // The provisional load was redirected via a HTTP 3xx response. virtual void didReceiveServerRedirectForProvisionalLoad(WebFrame*) = 0; @@ -111,6 +118,16 @@ namespace WebKit { // The provisional load failed. virtual void didFailProvisionalLoad(WebFrame*, const WebURLError&) = 0; + // Notifies the client to commit data for the given frame. The client + // may optionally prevent default processing by setting preventDefault + // to true before returning. If default processing is prevented, then + // it is up to the client to manually call commitDocumentData on the + // WebFrame. It is only valid to call commitDocumentData within a call + // to didReceiveDocumentData. If commitDocumentData is not called, + // then an empty document will be loaded. + virtual void didReceiveDocumentData( + WebFrame*, const char* data, size_t length, bool& preventDefault) = 0; + // The provisional datasource is now committed. The first part of the // response body has been received, and the encoding of the response // body is known. @@ -146,7 +163,8 @@ namespace WebKit { // Called upon update to scroll position, document state, and other // non-navigational events related to the data held by WebHistoryItem. // WARNING: This method may be called very frequently. - virtual void didUpdateCurrentHistoryItem(WebFrame*) = 0; + // FIXME: Enable this method. + //virtual void didUpdateCurrentHistoryItem(WebFrame*) = 0; // Low-level resource notifications ------------------------------------ @@ -156,16 +174,25 @@ namespace WebKit { virtual void assignIdentifierToRequest( WebFrame*, unsigned identifier, const WebURLRequest&) = 0; - // The request may be modified before it is sent. + // A request is about to be sent out, and the client may modify it. Request + // is writable, and changes to the URL, for example, will change the request + // made. If this request is the result of a redirect, then redirectResponse + // will be non-null and contain the response that triggered the redirect. virtual void willSendRequest( - WebFrame*, unsigned identifier, WebURLRequest&) = 0; + WebFrame*, unsigned identifier, WebURLRequest&, + const WebURLResponse& redirectResponse) = 0; + + // Response headers have been received for the resource request given + // by identifier. + virtual void didReceiveResponse( + WebFrame*, unsigned identifier, const WebURLResponse&) = 0; // The resource request given by identifier succeeded. - virtual void didFinishLoading( + virtual void didFinishResourceLoad( WebFrame*, unsigned identifier) = 0; // The resource request given by identifier failed. - virtual void didFailLoading( + virtual void didFailResourceLoad( WebFrame*, unsigned identifier, const WebURLError&) = 0; // The specified request was satified from WebCore's memory cache. @@ -182,7 +209,7 @@ namespace WebKit { // Geometry notifications ---------------------------------------------- // The size of the content area changed. - virtual void didChangeContentsSize(WebFrame*) = 0; + virtual void didChangeContentsSize(WebFrame*, const WebSize&) = 0; // FIXME need to add: diff --git a/webkit/glue/bookmarklet_unittest.cc b/webkit/glue/bookmarklet_unittest.cc index 4412d61..e6718c7 100644 --- a/webkit/glue/bookmarklet_unittest.cc +++ b/webkit/glue/bookmarklet_unittest.cc @@ -21,13 +21,14 @@ class BookmarkletTest : public TestShellTest { virtual void SetUp() { TestShellTest::SetUp(); - test_shell_->LoadURL(L"data:text/html,start page"); + test_shell_->LoadURL(GURL("data:text/html,start page")); test_shell_->WaitTestFinished(); } }; TEST_F(BookmarkletTest, Redirect) { - test_shell_->LoadURL(L"javascript:location.href='data:text/plain,SUCCESS'"); + test_shell_->LoadURL( + GURL("javascript:location.href='data:text/plain,SUCCESS'")); test_shell_->WaitTestFinished(); std::wstring text = test_shell_->GetDocumentText(); EXPECT_EQ(L"SUCCESS", text); @@ -38,7 +39,8 @@ TEST_F(BookmarkletTest, RedirectVoided) { // 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_->LoadURL( + GURL("javascript:void(location.href='data:text/plain,SUCCESS')")); test_shell_->WaitTestFinished(); std::wstring text = test_shell_->GetDocumentText(); EXPECT_EQ(L"SUCCESS", text); @@ -59,17 +61,17 @@ TEST_F(BookmarkletTest, NonEmptyResult) { EXPECT_EQ(L"false", text); #endif - test_shell_->LoadURL(L"javascript:'hello world'"); + test_shell_->LoadURL(GURL("javascript:'hello world'")); MessageLoop::current()->RunAllPending(); text = test_shell_->GetDocumentText(); EXPECT_EQ(L"hello world", text); } TEST_F(BookmarkletTest, DocumentWrite) { - test_shell_->LoadURL( - L"javascript:document.open();" - L"document.write('hello world');" - L"document.close()"); + test_shell_->LoadURL(GURL( + "javascript:document.open();" + "document.write('hello world');" + "document.close()")); MessageLoop::current()->RunAllPending(); std::wstring text = test_shell_->GetDocumentText(); EXPECT_EQ(L"hello world", text); diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc index 1f6b331..1eb1af5 100644 --- a/webkit/glue/chrome_client_impl.cc +++ b/webkit/glue/chrome_client_impl.cc @@ -30,6 +30,7 @@ #include "googleurl/src/gurl.h" #include "webkit/api/public/WebCursorInfo.h" +#include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebInputEvent.h" #include "webkit/api/public/WebKit.h" #include "webkit/api/public/WebPopupMenuInfo.h" @@ -487,10 +488,10 @@ PlatformWidget ChromeClientImpl::platformWindow() const { void ChromeClientImpl::contentsSizeChanged(WebCore::Frame* frame, const WebCore::IntSize& size) const { - WebViewDelegate* delegate = webview_->delegate(); - - if (delegate) { - delegate->DidContentsSizeChange(webview_, size.width(), size.height()); + WebFrameImpl* webframe = WebFrameImpl::FromFrame(frame); + if (webframe->client()) { + webframe->client()->didChangeContentsSize( + webframe, webkit_glue::IntSizeToWebSize(size)); } } diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc index 9d35344..94b7dd7 100644 --- a/webkit/glue/chromium_bridge_impl.cc +++ b/webkit/glue/chromium_bridge_impl.cc @@ -32,6 +32,7 @@ #include "googleurl/src/url_util.h" #include "skia/ext/skia_utils_win.h" #include "webkit/api/public/WebCursorInfo.h" +#include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebScreenInfo.h" #include "webkit/glue/chrome_client_impl.h" #include "webkit/glue/glue_util.h" @@ -94,11 +95,10 @@ void ChromiumBridge::notifyJSOutOfMemory(Frame* frame) { if (!frame) return; - // Dispatch to the delegate of the view that owns the frame. - WebViewImpl* webview = WebFrameImpl::FromFrame(frame)->GetWebViewImpl(); - if (!webview || !webview->delegate()) + WebFrameImpl* webframe = WebFrameImpl::FromFrame(frame); + if (!webframe->client()) return; - webview->delegate()->JSOutOfMemory(); + webframe->client()->didExhaustMemoryAvailableForScript(webframe); } // Plugin --------------------------------------------------------------------- diff --git a/webkit/glue/context_menu_unittest.cc b/webkit/glue/context_menu_unittest.cc index 8fc009f..61cc229 100644 --- a/webkit/glue/context_menu_unittest.cc +++ b/webkit/glue/context_menu_unittest.cc @@ -35,13 +35,12 @@ class ContextMenuCapturing : public TestShellTest { TEST_F(ContextMenuCapturing, ContextMenuCapturing) { // Make sure we have no stored mouse event state - WebViewDelegate* raw_delegate = test_shell_->webView()->GetDelegate(); - TestWebViewDelegate* test_delegate = static_cast<TestWebViewDelegate*>(raw_delegate); + TestWebViewDelegate* test_delegate = test_shell_->delegate(); test_delegate->clear_captured_context_menu_events(); EXPECT_EQ(0U, test_delegate->captured_context_menu_events().size()); - std::wstring test_url = GetTestURL(iframes_data_dir_, "testiframe.html"); - test_shell_->LoadURL(test_url.c_str()); + GURL test_url = GetTestURL(iframes_data_dir_, "testiframe.html"); + test_shell_->LoadURL(test_url); test_shell_->WaitTestFinished(); // Create a right click in the center of the iframe. (I'm hoping this will diff --git a/webkit/glue/cpp_bound_class_unittest.cc b/webkit/glue/cpp_bound_class_unittest.cc index 7bfd8a5..bdddd11 100644 --- a/webkit/glue/cpp_bound_class_unittest.cc +++ b/webkit/glue/cpp_bound_class_unittest.cc @@ -70,8 +70,8 @@ class ExampleTestShell : public TestShell { // This is a public interface to TestShell's protected method, so it // can be called by our CreateEmptyWindow. - bool PublicInitialize(const std::wstring& startingURL) { - return Initialize(startingURL); + bool PublicInitialize(const std::string& starting_url) { + return Initialize(GURL(starting_url)); } CppBindingExampleWithOptionalFallback example_bound_class_; @@ -84,7 +84,7 @@ class CppBoundClassTest : public TestShellTest { virtual void CreateEmptyWindow() { ExampleTestShell* host = new ExampleTestShell(useFallback()); ASSERT_TRUE(host != NULL); - bool rv = host->PublicInitialize(L"about:blank"); + bool rv = host->PublicInitialize("about:blank"); if (rv) { test_shell_ = host; TestShell::windowList()->push_back(host->mainWnd()); diff --git a/webkit/glue/dom_operations_unittest.cc b/webkit/glue/dom_operations_unittest.cc index 4d6fb86..b5487b2 100644 --- a/webkit/glue/dom_operations_unittest.cc +++ b/webkit/glue/dom_operations_unittest.cc @@ -41,8 +41,7 @@ void DomOperationsTests::GetSavableResourceLinksForPage( GURL file_url = net::FilePathToFileURL(page_file_path); // Load the test file. test_shell_->ResetTestController(); - std::wstring file_wurl = ASCIIToWide(file_url.spec()); - test_shell_->LoadURL(file_wurl.c_str()); + test_shell_->LoadURL(file_url); test_shell_->WaitTestFinished(); // Get all savable resource links for the page. std::vector<GURL> resources_list; @@ -52,9 +51,8 @@ void DomOperationsTests::GetSavableResourceLinksForPage( &referrers_list, &frames_list); - GURL main_page_gurl(WideToUTF8(file_wurl)); ASSERT_TRUE(webkit_glue::GetAllSavableResourceLinksForCurrentPage( - test_shell_->webView(), main_page_gurl, &result)); + test_shell_->webView(), file_url, &result)); // Check all links of sub-resource for (std::vector<GURL>::const_iterator cit = resources_list.begin(); cit != resources_list.end(); ++cit) { diff --git a/webkit/glue/dom_serializer_unittest.cc b/webkit/glue/dom_serializer_unittest.cc index de8d7e1..b6eb8f7 100644 --- a/webkit/glue/dom_serializer_unittest.cc +++ b/webkit/glue/dom_serializer_unittest.cc @@ -96,7 +96,7 @@ class DomSerializerTests : public TestShellTest, void LoadPageFromURL(const GURL& page_url) { // Load the test file. test_shell_->ResetTestController(); - test_shell_->LoadURL(UTF8ToWide(page_url.spec()).c_str()); + test_shell_->LoadURL(page_url); test_shell_->WaitTestFinished(); } diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index 925152b..4106ff6 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -665,6 +665,9 @@ void EditorClientImpl::textFieldDidEndEditing(WebCore::Element* element) { // Hide any showing popup. web_view_->HideAutoCompletePopup(); + if (!editing_client_) + return; // The page is getting closed, don't fill the password. + // Notify any password-listener of the focus change. WebCore::HTMLInputElement* input_element = webkit_glue::ElementToHTMLInputElement(element); @@ -673,9 +676,6 @@ void EditorClientImpl::textFieldDidEndEditing(WebCore::Element* element) { WebFrameImpl* webframe = WebFrameImpl::FromFrame(input_element->document()->frame()); - if (webframe->GetWebViewImpl() && !webframe->GetWebViewImpl()->GetDelegate()) - return; // The page is getting closed, don't fill the password. - webkit_glue::PasswordAutocompleteListener* listener = webframe->GetPasswordListener(input_element); if (!listener) diff --git a/webkit/glue/empty_webframeclient.h b/webkit/glue/empty_webframeclient.h new file mode 100644 index 0000000..86f2561 --- /dev/null +++ b/webkit/glue/empty_webframeclient.h @@ -0,0 +1,89 @@ +// 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. + +#ifndef WEBKIT_GLUE_EMPTY_WEBFRAMECLIENT_H_ +#define WEBKIT_GLUE_EMPTY_WEBFRAMECLIENT_H_ + +#include "webkit/api/public/WebFrameClient.h" + +namespace webkit_glue { + +// Extend from this if you only need to override a few WebFrameClient methods. +class EmptyWebFrameClient : public WebKit::WebFrameClient { + public: + virtual WebKit::WebPlugin* createPlugin( + WebKit::WebFrame* frame, const WebKit::WebPluginParams& params) { + return NULL; } + virtual WebKit::WebWorker* createWorker( + WebKit::WebFrame* frame, WebKit::WebWorkerClient* client) { + return NULL; } + virtual WebKit::WebMediaPlayer* createMediaPlayer( + WebKit::WebFrame* frame, WebKit::WebMediaPlayerClient* client) { + return NULL; } + virtual void willClose(WebKit::WebFrame* frame) {} + virtual void loadURLExternally( + WebKit::WebFrame* frame, const WebKit::WebURLRequest& request, + WebKit::WebNavigationPolicy policy) {} + virtual WebKit::WebNavigationPolicy decidePolicyForNavigation( + WebKit::WebFrame* frame, const WebKit::WebURLRequest& request, + WebKit::WebNavigationType type, + WebKit::WebNavigationPolicy default_policy, bool is_redirect) { + return default_policy; } + virtual void willSubmitForm(WebKit::WebFrame* frame, + const WebKit::WebForm& form) {} + virtual void willPerformClientRedirect( + WebKit::WebFrame* frame, const WebKit::WebURL& from, + const WebKit::WebURL& to, double interval, double fire_time) {} + virtual void didCancelClientRedirect(WebKit::WebFrame* frame) {} + virtual void didCompleteClientRedirect( + WebKit::WebFrame* frame, const WebKit::WebURL& from) {} + virtual void didCreateDataSource( + WebKit::WebFrame* frame, WebKit::WebDataSource* datasource) {} + virtual void didStartProvisionalLoad(WebKit::WebFrame* frame) {} + virtual void didReceiveServerRedirectForProvisionalLoad( + WebKit::WebFrame* frame) {} + virtual void didFailProvisionalLoad( + WebKit::WebFrame* frame, const WebKit::WebURLError& error) {} + virtual void didReceiveDocumentData( + WebKit::WebFrame* frame, const char* data, size_t length, + bool& prevent_default) {} + virtual void didCommitProvisionalLoad( + WebKit::WebFrame* frame, bool is_new_navigation) {} + virtual void didClearWindowObject(WebKit::WebFrame* frame) {} + virtual void didCreateDocumentElement(WebKit::WebFrame* frame) {} + virtual void didReceiveTitle( + WebKit::WebFrame* frame, const WebKit::WebString& title) {} + virtual void didFinishDocumentLoad(WebKit::WebFrame* frame) {} + virtual void didHandleOnloadEvents(WebKit::WebFrame* frame) {} + virtual void didFailLoad( + WebKit::WebFrame* frame, const WebKit::WebURLError& error) {} + virtual void didFinishLoad(WebKit::WebFrame* frame) {} + virtual void didChangeLocationWithinPage( + WebKit::WebFrame* frame, bool is_new_navigation) {} + virtual void assignIdentifierToRequest( + WebKit::WebFrame* frame, unsigned identifier, + const WebKit::WebURLRequest& request) {} + virtual void willSendRequest( + WebKit::WebFrame* frame, unsigned identifier, + WebKit::WebURLRequest& request, + const WebKit::WebURLResponse& redirect_response) {} + virtual void didReceiveResponse( + WebKit::WebFrame* frame, unsigned identifier, + const WebKit::WebURLResponse& response) {} + virtual void didFinishResourceLoad( + WebKit::WebFrame* frame, unsigned identifier) {} + virtual void didFailResourceLoad( + WebKit::WebFrame* frame, unsigned identifier, + const WebKit::WebURLError& error) {} + virtual void didLoadResourceFromMemoryCache( + WebKit::WebFrame* frame, const WebKit::WebURLRequest& request, + const WebKit::WebURLResponse&) {} + virtual void didExhaustMemoryAvailableForScript(WebKit::WebFrame* frame) {} + virtual void didChangeContentsSize( + WebKit::WebFrame* frame, const WebKit::WebSize& size) {} +}; + +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_EMPTY_WEBFRAMECLIENT_H_ diff --git a/webkit/glue/iframe_redirect_unittest.cc b/webkit/glue/iframe_redirect_unittest.cc index 2778c09..3529b77 100644 --- a/webkit/glue/iframe_redirect_unittest.cc +++ b/webkit/glue/iframe_redirect_unittest.cc @@ -35,9 +35,9 @@ TEST_F(IFrameRedirectTest, Test) { iframes_data_dir_ = iframes_data_dir_.AppendASCII("iframe_redirect"); ASSERT_TRUE(file_util::PathExists(iframes_data_dir_)); - std::wstring test_url = GetTestURL(iframes_data_dir_, "main.html"); + GURL test_url = GetTestURL(iframes_data_dir_, "main.html"); - test_shell_->LoadURL(test_url.c_str()); + test_shell_->LoadURL(test_url); test_shell_->WaitTestFinished(); WebFrame* iframe = diff --git a/webkit/glue/inspector_client_impl.cc b/webkit/glue/inspector_client_impl.cc index cf639b2..694bf30 100644 --- a/webkit/glue/inspector_client_impl.cc +++ b/webkit/glue/inspector_client_impl.cc @@ -96,8 +96,8 @@ static void invalidateNodeBoundingRect(WebViewImpl* web_view) { // In order to do so, we'd have to take scrolling into account. const WebSize& size = web_view->size(); WebRect damaged_rect(0, 0, size.width, size.height); - if (web_view->GetDelegate()) - web_view->GetDelegate()->didInvalidateRect(damaged_rect); + if (web_view->delegate()) + web_view->delegate()->didInvalidateRect(damaged_rect); } void InspectorClientImpl::highlight(Node* node) { diff --git a/webkit/glue/mimetype_unittest.cc b/webkit/glue/mimetype_unittest.cc index 7dd52f4..04d5880 100644 --- a/webkit/glue/mimetype_unittest.cc +++ b/webkit/glue/mimetype_unittest.cc @@ -22,7 +22,7 @@ namespace { class MimeTypeTests : public TestShellTest { public: void LoadURL(const GURL& url) { - test_shell_->LoadURL(UTF8ToWide(url.spec()).c_str()); + test_shell_->LoadURL(url); test_shell_->WaitTestFinished(); } diff --git a/webkit/glue/temporary_glue.cc b/webkit/glue/temporary_glue.cc index 6c167aa..774efd5 100644 --- a/webkit/glue/temporary_glue.cc +++ b/webkit/glue/temporary_glue.cc @@ -5,11 +5,13 @@ #include "config.h" #include "webkit/api/src/TemporaryGlue.h" +#include "Page.h" #include <wtf/Assertions.h> #undef LOG +#include "webkit/api/public/WebFrameClient.h" #include "webkit/glue/chrome_client_impl.h" -#include "webkit/glue/webview_impl.h" +#include "webkit/glue/webframe_impl.h" using WebCore::Frame; using WebCore::Page; @@ -19,11 +21,11 @@ namespace WebKit { // static WebMediaPlayer* TemporaryGlue::createWebMediaPlayer( WebMediaPlayerClient* client, Frame* frame) { - WebViewImpl* webview = WebFrameImpl::FromFrame(frame)->GetWebViewImpl(); - if (!webview || !webview->delegate()) + WebFrameImpl* webframe = WebFrameImpl::FromFrame(frame); + if (!webframe->client()) return NULL; - return webview->delegate()->CreateWebMediaPlayer(client); + return webframe->client()->createMediaPlayer(webframe, client); } // static diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index e52075c..d9a7ced 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -147,6 +147,7 @@ MSVC_POP_WARNING(); #include "webkit/api/public/WebConsoleMessage.h" #include "webkit/api/public/WebFindOptions.h" #include "webkit/api/public/WebForm.h" +#include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebHistoryItem.h" #include "webkit/api/public/WebRange.h" #include "webkit/api/public/WebRect.h" @@ -217,6 +218,7 @@ using WebKit::WebDataSource; using WebKit::WebDataSourceImpl; using WebKit::WebFindOptions; using WebKit::WebFrame; +using WebKit::WebFrameClient; using WebKit::WebHistoryItem; using WebKit::WebForm; using WebKit::WebRange; @@ -898,6 +900,10 @@ unsigned WebFrameImpl::unloadListenerCount() const { return frame()->domWindow()->pendingUnloadEventListeners(); } +bool WebFrameImpl::isProcessingUserGesture() const { + return frame()->loader()->isProcessingUserGesture(); +} + void WebFrameImpl::replaceSelection(const WebString& wtext) { String text = webkit_glue::WebStringToString(wtext); RefPtr<DocumentFragment> fragment = createFragmentFromText( @@ -1406,7 +1412,7 @@ void WebFrameImpl::increaseMatchCount(int count, int request_id) { total_matchcount_ += count; // Update the UI with the latest findings. - WebViewDelegate* webview_delegate = GetWebViewImpl()->GetDelegate(); + WebViewDelegate* webview_delegate = GetWebViewImpl()->delegate(); DCHECK(webview_delegate); if (webview_delegate) webview_delegate->ReportFindInPageMatchCount(total_matchcount_, request_id, @@ -1417,7 +1423,7 @@ void WebFrameImpl::reportFindInPageSelection(const WebRect& selection_rect, int active_match_ordinal, int request_id) { // Update the UI with the latest selection rect. - WebViewDelegate* webview_delegate = GetWebViewImpl()->GetDelegate(); + WebViewDelegate* webview_delegate = GetWebViewImpl()->delegate(); DCHECK(webview_delegate); if (webview_delegate) { webview_delegate->ReportFindInPageSelection( @@ -1458,9 +1464,10 @@ WebString WebFrameImpl::contentAsMarkup() const { int WebFrameImpl::live_object_count_ = 0; -WebFrameImpl::WebFrameImpl() +WebFrameImpl::WebFrameImpl(WebFrameClient* client) : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(scope_matches_factory_(this)), + client_(client), active_match_frame_(NULL), active_match_index_(-1), locating_active_rect_(false), @@ -1500,7 +1507,7 @@ PassRefPtr<Frame> WebFrameImpl::CreateChildFrame( const FrameLoadRequest& request, HTMLFrameOwnerElement* owner_element) { // TODO(darin): share code with initWithName() - scoped_refptr<WebFrameImpl> webframe = new WebFrameImpl(); + scoped_refptr<WebFrameImpl> webframe = new WebFrameImpl(client()); // Add an extra ref on behalf of the Frame/FrameLoader, which references the // WebFrame via the FrameLoaderClient interface. See the comment at the top @@ -1690,16 +1697,14 @@ void WebFrameImpl::SetFindEndstateFocusAndSelection() { } void WebFrameImpl::DidFail(const ResourceError& error, bool was_provisional) { - WebViewImpl* web_view = GetWebViewImpl(); - WebViewDelegate* delegate = web_view->delegate(); - if (delegate) { - const WebURLError& web_error = - webkit_glue::ResourceErrorToWebURLError(error); - if (was_provisional) { - delegate->DidFailProvisionalLoadWithError(web_view, web_error, this); - } else { - delegate->DidFailLoadWithError(web_view, web_error, this); - } + if (!client_) + return; + const WebURLError& web_error = + webkit_glue::ResourceErrorToWebURLError(error); + if (was_provisional) { + client_->didFailProvisionalLoad(this, web_error); + } else { + client_->didFailLoad(this, web_error); } } diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index b1c1240..0633214 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -60,6 +60,7 @@ struct WindowFeatures; namespace WebKit { class WebDataSourceImpl; +class WebFrameClient; } // Implementation of WebFrame, note that this is a reference counted object. @@ -130,6 +131,7 @@ class WebFrameImpl : public WebKit::WebFrame, virtual void dispatchWillSendRequest(WebKit::WebURLRequest& request); virtual void commitDocumentData(const char* data, size_t length); virtual unsigned unloadListenerCount() const; + virtual bool isProcessingUserGesture() const; virtual void replaceSelection(const WebKit::WebString& text); virtual void insertText(const WebKit::WebString& text); virtual void setMarkedText( @@ -169,7 +171,7 @@ class WebFrameImpl : public WebKit::WebFrame, virtual WebKit::WebString contentAsText(size_t max_chars) const; virtual WebKit::WebString contentAsMarkup() const; - WebFrameImpl(); + WebFrameImpl(WebKit::WebFrameClient* client); ~WebFrameImpl(); static int live_object_count() { @@ -242,6 +244,9 @@ class WebFrameImpl : public WebKit::WebFrame, webkit_glue::PasswordAutocompleteListener* GetPasswordListener( WebCore::HTMLInputElement* user_name_input_element); + WebKit::WebFrameClient* client() const { return client_; } + void drop_client() { client_ = NULL; } + protected: friend class WebFrameLoaderClient; @@ -258,6 +263,8 @@ class WebFrameImpl : public WebKit::WebFrame, // asynchronously in order to scope string matches during a find operation. ScopedRunnableMethodFactory<WebFrameImpl> scope_matches_factory_; + WebKit::WebFrameClient* client_; + // This is a weak pointer to our corresponding WebCore frame. A reference to // ourselves is held while frame_ is valid. See our Closing method. WebCore::Frame* frame_; diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index 0abcce9..d864839 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -32,6 +32,7 @@ #include "net/base/mime_util.h" #include "net/base/net_errors.h" #include "webkit/api/public/WebForm.h" +#include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebPlugin.h" #include "webkit/api/public/WebPluginParams.h" #include "webkit/api/public/WebURL.h" @@ -110,21 +111,20 @@ void WebFrameLoaderClient::frameLoaderDestroyed() { } void WebFrameLoaderClient::windowObjectCleared() { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) - d->WindowObjectCleared(webframe_); + if (webframe_->client()) + webframe_->client()->didClearWindowObject(webframe_); - WebDevToolsAgentImpl* tools_agent = webview->GetWebDevToolsAgentImpl(); - if (tools_agent) - tools_agent->WindowObjectCleared(webframe_); + WebViewImpl* webview = webframe_->GetWebViewImpl(); + if (webview) { + WebDevToolsAgentImpl* tools_agent = webview->GetWebDevToolsAgentImpl(); + if (tools_agent) + tools_agent->WindowObjectCleared(webframe_); + } } void WebFrameLoaderClient::documentElementAvailable() { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) - d->DocumentElementAvailable(webframe_); + if (webframe_->client()) + webframe_->client()->didCreateDocumentElement(webframe_); } void WebFrameLoaderClient::didCreateScriptContextForFrame() { @@ -196,6 +196,9 @@ void WebFrameLoaderClient::detachedFromParent3() { // go to a page and then navigate to a new page without getting any asserts // or crashes. webframe_->frame()->script()->proxy()->clearForClose(); + + // Drop any reference to the client since it may shortly become invalid. + webframe_->drop_client(); } // This function is responsible for associating the |identifier| with a given @@ -205,10 +208,10 @@ void WebFrameLoaderClient::detachedFromParent3() { void WebFrameLoaderClient::assignIdentifierToInitialRequest( unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request) { - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (d) { + if (webframe_->client()) { WrappedResourceRequest webreq(request); - d->AssignIdentifierToRequest(webframe_, identifier, webreq); + webframe_->client()->assignIdentifierToRequest( + webframe_, identifier, webreq); } } @@ -250,12 +253,12 @@ void WebFrameLoaderClient::dispatchWillSendRequest( if (request.firstPartyForCookies().isEmpty()) request.setFirstPartyForCookies(KURL(ParsedURLString, "about:blank")); - // Give the delegate a crack at the request. - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (d) { + // Give the WebFrameClient a crack at the request. + if (webframe_->client()) { WrappedResourceRequest webreq(request); WrappedResourceResponse webresp(redirect_response); - d->WillSendRequest(webframe_, identifier, &webreq, webresp); + webframe_->client()->willSendRequest( + webframe_, identifier, webreq, webresp); } } @@ -287,10 +290,9 @@ void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge( void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response) { - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (d) { + if (webframe_->client()) { WrappedResourceResponse webresp(response); - d->DidReceiveResponse(webframe_, identifier, webresp); + webframe_->client()->didReceiveResponse(webframe_, identifier, webresp); } } @@ -303,34 +305,26 @@ void WebFrameLoaderClient::dispatchDidReceiveContentLength( // Called when a particular resource load completes void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier) { - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (d) - d->DidFinishLoading(webframe_, identifier); + if (webframe_->client()) + webframe_->client()->didFinishResourceLoad(webframe_, identifier); } void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, unsigned long identifier, const ResourceError& error) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - if (webview && webview->delegate()) { - webview->delegate()->DidFailLoadingWithError( + if (webframe_->client()) { + webframe_->client()->didFailResourceLoad( webframe_, identifier, webkit_glue::ResourceErrorToWebURLError(error)); } } void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - DocumentLoader* documentLoader = - webframe_->frame()->loader()->activeDocumentLoader(); - WebDataSourceImpl* data_source = - WebDataSourceImpl::fromDocumentLoader(documentLoader); - // A frame may be reused. This call ensures we don't hold on to our password // listeners and their associated HTMLInputElements. webframe_->ClearPasswordListeners(); - if (webview && webview->delegate()) - webview->delegate()->DidFinishDocumentLoadForFrame(webview, webframe_); + if (webframe_->client()) + webframe_->client()->didFinishDocumentLoad(webframe_); } bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache( @@ -338,17 +332,13 @@ bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache( const ResourceRequest& request, const ResourceResponse& response, int length) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - - bool result = false; - if (d) { + if (webframe_->client()) { WrappedResourceRequest webreq(request); WrappedResourceResponse webresp(response); - result = d->DidLoadResourceFromMemoryCache(webview, webreq, webresp, - webframe_); + webframe_->client()->didLoadResourceFromMemoryCache( + webframe_, webreq, webresp); } - return result; + return false; // Do not suppress remaining notifications } void WebFrameLoaderClient::dispatchDidLoadResourceByXMLHttpRequest( @@ -357,15 +347,8 @@ void WebFrameLoaderClient::dispatchDidLoadResourceByXMLHttpRequest( } void WebFrameLoaderClient::dispatchDidHandleOnloadEvents() { - // During the onload event of a subframe, the subframe can be removed. In - // that case, it has no page. This is covered by - // LayoutTests/fast/dom/replaceChild.html - if (!webframe_->frame()->page()) - return; - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) - d->DidHandleOnloadEventsForFrame(webview, webframe_); + if (webframe_->client()) + webframe_->client()->didHandleOnloadEvents(webframe_); } // Redirect Tracking @@ -469,37 +452,30 @@ void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad() // what happened). ds->appendRedirect(ds->request().url()); - // Dispatch callback - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) - d->DidReceiveProvisionalLoadServerRedirect(webview, webframe_); + if (webframe_->client()) + webframe_->client()->didReceiveServerRedirectForProvisionalLoad(webframe_); } // Called on both success and failure of a client redirect. void WebFrameLoaderClient::dispatchDidCancelClientRedirect() { // No longer expecting a client redirect. - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview ? webview->delegate() : NULL; - if (d) { + if (webframe_->client()) { expected_client_redirect_src_ = GURL(); expected_client_redirect_dest_ = GURL(); - - d->DidCancelClientRedirect(webview, webframe_); + webframe_->client()->didCancelClientRedirect(webframe_); } // No need to clear the redirect chain, since that data source has already // been deleted by the time this function is called. } -void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL& url, - double interval, - double fire_date) { +void WebFrameLoaderClient::dispatchWillPerformClientRedirect( + const KURL& url, + double interval, + double fire_date) { // Tells dispatchDidStartProvisionalLoad that if it sees this item it is a // redirect and the source item should be added as the start of the chain. - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview ? webview->delegate() : NULL; - if (d) { + if (webframe_->client()) { expected_client_redirect_src_ = webframe_->url(); expected_client_redirect_dest_ = webkit_glue::KURLToGURL(url); @@ -515,12 +491,12 @@ void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL& url, return; } - d->WillPerformClientRedirect(webview, - webframe_, - expected_client_redirect_src_, - expected_client_redirect_dest_, - static_cast<unsigned int>(interval), - static_cast<unsigned int>(fire_date)); + webframe_->client()->willPerformClientRedirect( + webframe_, + expected_client_redirect_src_, + expected_client_redirect_dest_, + static_cast<unsigned int>(interval), + static_cast<unsigned int>(fire_date)); } } @@ -548,13 +524,13 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() { // properly flag these transitions. Once a proper fix for this bug is // identified and applied the following block may no longer be required. bool was_client_redirect = - ((url == expected_client_redirect_dest_) && - (chain_end == expected_client_redirect_src_)) || - (NavigationGestureForLastLoad() == NavigationGestureAuto); + (url == expected_client_redirect_dest_ && + chain_end == expected_client_redirect_src_) || + !webframe_->isProcessingUserGesture(); if (was_client_redirect) { - if (d) - d->DidCompleteClientRedirect(webview, webframe_, chain_end); + if (webframe_->client()) + webframe_->client()->didCompleteClientRedirect(webframe_, chain_end); ds->appendRedirect(chain_end); // Make sure we clear the expected redirect since we just effectively // completed it. @@ -569,9 +545,9 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() { bool is_new_navigation; webview->DidCommitLoad(&is_new_navigation); - if (d) { - d->DidChangeLocationWithinPageForFrame(webview, webframe_, - is_new_navigation); + if (webframe_->client()) { + webframe_->client()->didChangeLocationWithinPage( + webframe_, is_new_navigation); } if (d) @@ -579,10 +555,8 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() { } void WebFrameLoaderClient::dispatchWillClose() { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) - d->WillCloseFrame(webview, webframe_); + if (webframe_->client()) + webframe_->client()->willClose(webframe_); } void WebFrameLoaderClient::dispatchDidReceiveIcon() { @@ -609,8 +583,6 @@ void WebFrameLoaderClient::dispatchDidStartProvisionalLoad() { // any redirects yet. DCHECK(!ds->hasRedirectChain()); - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); // If this load is what we expected from a client redirect, treat it as a // redirect from that original page. The expected redirect urls will be // cleared by DidCancelClientRedirect. @@ -626,26 +598,23 @@ void WebFrameLoaderClient::dispatchDidStartProvisionalLoad() { } ds->appendRedirect(url); - if (d) { + if (webframe_->client()) { // As the comment for DidCompleteClientRedirect in webview_delegate.h // points out, whatever information its invocation contains should only // be considered relevant until the next provisional load has started. // So we first tell the delegate that the load started, and then tell it // about the client redirect the load is responsible for completing. - d->DidStartProvisionalLoadForFrame(webview, webframe_, - NavigationGestureForLastLoad()); + webframe_->client()->didStartProvisionalLoad(webframe_); if (completing_client_redirect) - d->DidCompleteClientRedirect(webview, webframe_, - expected_client_redirect_src_); + webframe_->client()->didCompleteClientRedirect( + webframe_, expected_client_redirect_src_); } } void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) { - d->DidReceiveTitle(webview, webkit_glue::StringToStdWString(title), - webframe_); + if (webframe_->client()) { + webframe_->client()->didReceiveTitle( + webframe_, webkit_glue::StringToWebString(title)); } } @@ -653,9 +622,11 @@ void WebFrameLoaderClient::dispatchDidCommitLoad() { WebViewImpl* webview = webframe_->GetWebViewImpl(); bool is_new_navigation; webview->DidCommitLoad(&is_new_navigation); - WebViewDelegate* d = webview->delegate(); - if (d) - d->DidCommitLoadForFrame(webview, webframe_, is_new_navigation); + + if (webframe_->client()) { + webframe_->client()->didCommitProvisionalLoad( + webframe_, is_new_navigation); + } WebDevToolsAgentImpl* tools_agent = webview->GetWebDevToolsAgentImpl(); if (tools_agent) { @@ -695,10 +666,9 @@ void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) { void WebFrameLoaderClient::dispatchDidFinishLoad() { OwnPtr<WebPluginLoadObserver> plugin_load_observer = GetPluginLoadObserver(); - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) - d->DidFinishLoadForFrame(webview, webframe_); + if (webframe_->client()) + webframe_->client()->didFinishLoad(webframe_); + if (plugin_load_observer) plugin_load_observer->didFinishLoading(); @@ -835,13 +805,11 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction( PassRefPtr<WebCore::FormState> form_state) { PolicyAction policy_action = PolicyIgnore; - WebViewImpl* wv = webframe_->GetWebViewImpl(); - WebViewDelegate* d = wv->delegate(); // It is valid for this function to be invoked in code paths where the // the webview is closed. // The NULL check here is to fix a crash that seems strange // (see - https://bugs.webkit.org/show_bug.cgi?id=23554). - if (d && !request.url().isNull()) { + if (webframe_->client() && !request.url().isNull()) { WebNavigationPolicy navigation_policy = WebKit::WebNavigationPolicyCurrentTab; ActionSpecifiesNavigationPolicy(action, &navigation_policy); @@ -859,8 +827,8 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction( WebNavigationType webnav_type = WebDataSourceImpl::toWebNavigationType(action.type()); - navigation_policy = d->PolicyForNavigationAction( - wv, webframe_, ds->request(), webnav_type, navigation_policy, + navigation_policy = webframe_->client()->decidePolicyForNavigation( + webframe_, ds->request(), webnav_type, navigation_policy, is_redirect); } } @@ -871,13 +839,9 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction( policy_action = PolicyDownload; } else { if (navigation_policy != WebKit::WebNavigationPolicyIgnore) { - GURL referrer = webkit_glue::StringToGURL( - request.httpHeaderField("Referer")); - - d->OpenURL(webframe_->GetWebViewImpl(), - webkit_glue::KURLToGURL(request.url()), - referrer, - navigation_policy); + WrappedResourceRequest webreq(request); + webframe_->client()->loadURLExternally( + webframe_, webreq, navigation_policy); } policy_action = PolicyIgnore; } @@ -896,11 +860,9 @@ void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&) void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> form_ref) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (d) { - d->WillSubmitForm(webview, webframe_, - webkit_glue::HTMLFormElementToWebForm(form_ref->form())); + if (webframe_->client()) { + webframe_->client()->willSubmitForm( + webframe_, webkit_glue::HTMLFormElementToWebForm(form_ref->form())); } (webframe_->frame()->loader()->*function)(PolicyUse); } @@ -974,9 +936,12 @@ void WebFrameLoaderClient::didChangeTitle(DocumentLoader*) { // Called whenever data is received. void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length) { if (!plugin_widget_.get()) { - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (d) - d->DidReceiveDocumentData(webframe_, data, length); + if (webframe_->client()) { + bool preventDefault = false; + webframe_->client()->didReceiveDocumentData(webframe_, data, length, preventDefault); + if (!preventDefault) + webframe_->commitDocumentData(data, length); + } } // If we are sending data to WebCore::MediaDocument, we should stop here @@ -1158,9 +1123,8 @@ PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader( const ResourceRequest& request, const SubstituteData& data) { RefPtr<WebDataSourceImpl> ds = WebDataSourceImpl::create(request, data); - WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); - if (d) - d->DidCreateDataSource(webframe_, ds.get()); + if (webframe_->client()) + webframe_->client()->didCreateDataSource(webframe_, ds.get()); return ds.release(); } @@ -1246,8 +1210,7 @@ PassRefPtr<Widget> WebFrameLoaderClient::createPlugin( return NULL; #endif - WebViewImpl* webview = webframe_->GetWebViewImpl(); - if (!webview->delegate()) + if (!webframe_->client()) return NULL; WebPluginParams params; @@ -1257,7 +1220,7 @@ PassRefPtr<Widget> WebFrameLoaderClient::createPlugin( CopyStringVector(param_values, ¶ms.attributeValues); params.loadManually = load_manually; - WebPlugin* webplugin = webview->delegate()->CreatePlugin(webframe_, params); + WebPlugin* webplugin = webframe_->client()->createPlugin(webframe_, params); if (!webplugin) return NULL; @@ -1361,16 +1324,6 @@ bool WebFrameLoaderClient::ActionSpecifiesNavigationPolicy( return true; } -NavigationGesture WebFrameLoaderClient::NavigationGestureForLastLoad() { - // TODO(timsteele): isProcessingUserGesture() returns too many false positives - // (see bug 1051891) to trust it and assign NavigationGestureUser, so - // for now we assign Unknown in those cases and Auto otherwise. - // (Issue 874811 known false negative as well). - return webframe_->frame()->loader()->isProcessingUserGesture() ? - NavigationGestureUnknown : - NavigationGestureAuto; -} - void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) { DCHECK(url.SchemeIs(webkit_glue::kBackForwardNavigationScheme)); diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h index fd9d3d7..becfab8 100644 --- a/webkit/glue/webframeloaderclient_impl.h +++ b/webkit/glue/webframeloaderclient_impl.h @@ -208,10 +208,6 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { const WebCore::NavigationAction& action, WebKit::WebNavigationPolicy* policy); - // Returns NavigationGestureAuto if the last load was not user initiated, - // otherwise returns NavigationGestureUnknown. - NavigationGesture NavigationGestureForLastLoad(); - // Called when a dummy back-forward navigation is intercepted. void HandleBackForwardNavigation(const GURL&); diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index db4e6fb..6e58180 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -15,6 +15,7 @@ namespace WebKit { class WebDragData; class WebEditingClient; +class WebFrameClient; class WebFrame; class WebSettings; struct WebPoint; @@ -57,9 +58,10 @@ class WebView : public WebKit::WebWidget { static WebView* Create( WebViewDelegate* delegate, WebKit::WebEditingClient* editing_client); - // After creating a WebView, you should immediately call this function. - // You can optionally modify the settings (via GetSettings()) in between. - virtual void InitializeMainFrame() = 0; + // After creating a WebView, you should immediately call this function. You + // can optionally modify the settings (via GetSettings()) in between. The + // frame_client will receive events for the main frame and any child frames. + virtual void InitializeMainFrame(WebKit::WebFrameClient* frame_client) = 0; // Tells all Page instances of this view to update the visited link state for // the specified hash. diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index 3bbdf02..c5c6b6a 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -30,64 +30,28 @@ #include "webkit/api/public/WebDragOperation.h" #include "webkit/api/public/WebFrame.h" -#include "webkit/api/public/WebNavigationPolicy.h" -#include "webkit/api/public/WebNavigationType.h" #include "webkit/api/public/WebTextDirection.h" #include "webkit/api/public/WebWidgetClient.h" #include "webkit/glue/context_menu.h" -namespace webkit_glue { -class WebMediaPlayerDelegate; -struct WebPluginGeometry; -} - namespace WebCore { class AccessibilityObject; } namespace WebKit { -class WebDataSource; class WebDragData; -class WebForm; -class WebWorker; -class WebWorkerClient; -class WebMediaPlayer; -class WebMediaPlayerClient; -class WebNode; class WebNotificationPresenter; -class WebPlugin; -class WebURLRequest; -class WebURLResponse; class WebWidget; -struct WebPluginParams; -struct WebPoint; struct WebPopupMenuInfo; +struct WebPoint; struct WebRect; -struct WebURLError; } class FilePath; class SkBitmap; class WebDevToolsAgentDelegate; -class WebMediaPlayerDelegate; class WebView; struct ContextMenuMediaParams; -struct WebPreferences; - -enum NavigationGesture { - NavigationGestureUser, // User initiated navigation/load. This is not - // currently used due to the untrustworthy nature - // of userGestureHint (wasRunByUserGesture). See - // bug 1051891. - NavigationGestureAuto, // Non-user initiated navigation / load. For example - // onload or setTimeout triggered document.location - // changes, and form.submits. See bug 1046841 for - // some cases that should be treated this way but - // aren't yet. - NavigationGestureUnknown, // What we assign when userGestureHint returns true - // because we can't trust it. -}; - // Interface passed in to the WebViewDelegate to receive notification of the // result of an open file dialog. @@ -137,29 +101,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { return NULL; } - virtual WebKit::WebPlugin* CreatePlugin( - WebKit::WebFrame* parent_frame, - const WebKit::WebPluginParams& params) { - return NULL; - } - - // This method is called when the renderer creates a worker object. - virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client) { - return NULL; - } - - // Called when a WebMediaPlayer is needed. - virtual WebKit::WebMediaPlayer* CreateWebMediaPlayer( - WebKit::WebMediaPlayerClient* client) { - return NULL; - } - - // This method is called to open a URL in the specified manner. - virtual void OpenURL(WebView* webview, const GURL& url, - const GURL& referrer, - WebKit::WebNavigationPolicy policy) { - } - // Notifies how many matches have been found so far, for a given request_id. // |final_update| specifies whether this is the last update (all frames have // completed scoping). @@ -206,21 +147,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { virtual void DidStopLoading(WebView* webview) { } - // The original version of this is WindowScriptObjectAvailable, below. This - // is a Chrome-specific version that serves the same purpose, but has been - // renamed since we haven't implemented WebScriptObject. Our embedding - // implementation binds native objects to the window via the webframe instead. - // TODO(pamg): If we do implement WebScriptObject, we may wish to switch to - // using the original version of this function. - virtual void WindowObjectCleared(WebKit::WebFrame* webframe) { - } - - // Notifies that the documentElement for the document in a webframe has been - // created. This is called before anything else is parsed or executed for the - // document. - virtual void DocumentElementAvailable(WebKit::WebFrame* webframe) { - } - // Notifies that a new script context has been created for this frame. // This is similar to WindowObjectCleared but only called once per frame // context. @@ -235,271 +161,10 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { virtual void DidCreateIsolatedScriptContext(WebKit::WebFrame* webframe) { } - // PolicyDelegate ---------------------------------------------------------- - - // This method is called to notify the delegate, and let it modify a - // proposed navigation. It will be called before loading starts, and - // on every redirect. - // - // default_policy specifies what should normally happen for this - // navigation (open in current tab, start a new tab, start a new - // window, etc). This method can return an altered policy, and - // take any additional separate action it wants to. - // - // is_redirect is true if this is a redirect rather than user action. - virtual WebKit::WebNavigationPolicy PolicyForNavigationAction( - WebView* webview, - WebKit::WebFrame* frame, - const WebKit::WebURLRequest& request, - WebKit::WebNavigationType type, - WebKit::WebNavigationPolicy default_policy, - bool is_redirect) { - return default_policy; - } - - // FrameLoadDelegate ------------------------------------------------------- - - // A datasource has been created for a new navigation. The given datasource - // will become the provisional datasource for the frame. - virtual void DidCreateDataSource(WebKit::WebFrame* frame, - WebKit::WebDataSource* ds) { - } - - // Notifies the delegate that the provisional load of a specified frame in a - // given WebView has started. By the time the provisional load for a frame has - // started, we know whether or not the current load is due to a client - // redirect or not, so we pass this information through to allow us to set - // the referrer properly in those cases. The consumed_client_redirect_src is - // an empty invalid GURL in other cases. - virtual void DidStartProvisionalLoadForFrame( - WebView* webview, - WebKit::WebFrame* frame, - NavigationGesture gesture) { - } - - // Called when a provisional load is redirected (see GetProvisionalDataSource - // for more info on provisional loads). This happens when the server sends - // back any type of redirect HTTP response. - // - // The redirect information can be retrieved from the provisional data - // source's redirect chain, which will be updated prior to this callback. - // The last element in that vector will be the new URL (which will be the - // same as the provisional data source's current URL), and the next-to-last - // element will be the referring URL. - virtual void DidReceiveProvisionalLoadServerRedirect(WebView* webview, - WebKit::WebFrame* frame) { - } - - // @method webView:didFailProvisionalLoadWithError:forFrame: - // @abstract Notifies the delegate that the provisional load has failed - // @param webView The WebView sending the message - // @param error The error that occurred - // @param frame The frame for which the error occurred - // @discussion This method is called after the provisional data source has - // failed to load. The frame will continue to display the contents of the - // committed data source if there is one. - // This notification is only received for errors like network errors. - virtual void DidFailProvisionalLoadWithError(WebView* webview, - const WebKit::WebURLError& error, - WebKit::WebFrame* frame) { - } - - // 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(WebKit::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 - // committed. This method is called after the provisional data source has - // become the committed data source. - // - // In some cases, a single load may be committed more than once. This - // happens in the case of multipart/x-mixed-replace, also known as "server - // push". In this case, a single location change leads to multiple documents - // that are loaded in sequence. When this happens, a new commit will be sent - // for each document. - // - // The "is_new_navigation" flag will be true when a new session history entry - // was created for the load. The frame's GetHistoryState method can be used - // to get the corresponding session history state. - virtual void DidCommitLoadForFrame(WebView* webview, WebKit::WebFrame* frame, - bool is_new_navigation) { - } - - // - // @method webView:didReceiveTitle:forFrame: - // @abstract Notifies the delegate that the page title for a frame has been received - // @param webView The WebView sending the message - // @param title The new page title - // @param frame The frame for which the title has been received - // @discussion The title may update during loading; clients should be prepared for this. - // - (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame; - virtual void DidReceiveTitle(WebView* webview, - const std::wstring& title, - WebKit::WebFrame* frame) { - } - - // - // @method webView:didFinishLoadForFrame: - // @abstract Notifies the delegate that the committed load of a frame has completed - // @param webView The WebView sending the message - // @param frame The frame that finished loading - // @discussion This method is called after the committed data source of a frame has successfully loaded - // and will only be called when all subresources such as images and stylesheets are done loading. - // Plug-In content and JavaScript-requested loads may occur after this method is called. - // - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame; - virtual void DidFinishLoadForFrame(WebView* webview, - WebKit::WebFrame* frame) { - } - - // - // @method webView:didFailLoadWithError:forFrame: - // @abstract Notifies the delegate that the committed load of a frame has failed - // @param webView The WebView sending the message - // @param error The error that occurred - // @param frame The frame that failed to load - // @discussion This method is called after a data source has committed but failed to completely load. - // - (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame; - virtual void DidFailLoadWithError(WebView* webview, - const WebKit::WebURLError& error, - WebKit::WebFrame* forFrame) { - } - - // Notifies the delegate of a DOMContentLoaded event. - // This is called when the html resource has been loaded, but - // not necessarily all subresources (images, stylesheets). So, this is called - // before DidFinishLoadForFrame. - virtual void DidFinishDocumentLoadForFrame(WebView* webview, WebKit::WebFrame* frame) { - } - - // This method is called when we load a resource from an in-memory cache. - // A return value of |false| indicates the load should proceed, but WebCore - // appears to largely ignore the return value. - virtual bool DidLoadResourceFromMemoryCache( - WebView* webview, - const WebKit::WebURLRequest& request, - const WebKit::WebURLResponse& response, - WebKit::WebFrame* frame) { - return false; - } - - // This is called after javascript onload handlers have been fired. - virtual void DidHandleOnloadEventsForFrame(WebView* webview, WebKit::WebFrame* frame) { - } - - // This method is called when anchors within a page have been clicked. - // It is very similar to DidCommitLoadForFrame. - virtual void DidChangeLocationWithinPageForFrame(WebView* webview, - WebKit::WebFrame* frame, - bool is_new_navigation) { - } - // This is called when the favicon for a frame has been received. virtual void DidReceiveIconForFrame(WebView* webview, WebKit::WebFrame* frame) { } - // Notifies the delegate that a frame will start a client-side redirect. When - // this function is called, the redirect has not yet been started (it may - // not even be scheduled to happen until some point in the future). When the - // redirect has been cancelled or has succeeded, DidStopClientRedirect will - // be called. - // - // WebKit considers meta refreshes, and setting document.location (regardless - // of when called) as client redirects (possibly among others). - // - // This function is intended to continue progress feedback while a - // client-side redirect is pending. Watch out: WebKit seems to call us twice - // for client redirects, resulting in two calls of this function. - virtual void WillPerformClientRedirect(WebView* webview, - WebKit::WebFrame* frame, - const GURL& src_url, - const GURL& dest_url, - unsigned int delay_seconds, - unsigned int fire_date) { - } - - // Notifies the delegate that a pending client-side redirect has been - // cancelled (for example, if the frame changes before the timeout) or has - // completed successfully. A client-side redirect is the result of setting - // document.location, for example, as opposed to a server side redirect - // which is the result of HTTP headers (see DidReceiveServerRedirect). - // - // On success, this will be called when the provisional load that the client - // side redirect initiated is committed. - // - // See the implementation of FrameLoader::clientRedirectCancelledOrFinished. - virtual void DidCancelClientRedirect(WebView* webview, - WebKit::WebFrame* frame) { - } - - // Notifies the delegate that the load about to be committed for the specified - // webview and frame was due to a client redirect originating from source URL. - // The information/notification obtained from this method is relevant until - // the next provisional load is started, at which point it becomes obsolete. - virtual void DidCompleteClientRedirect(WebView* webview, - WebKit::WebFrame* frame, - const GURL& source) { - } - - // Notifies the delegate that a form is about to be submitted. - virtual void WillSubmitForm(WebView* webview, WebKit::WebFrame* frame, - const WebKit::WebForm& form) { - } - - // - // @method webView:willCloseFrame: - // @abstract Notifies the delegate that a frame will be closed - // @param webView The WebView sending the message - // @param frame The frame that will be closed - // @discussion This method is called right before WebKit is done with the frame - // and the objects that it contains. - // - (void)webView:(WebView *)sender willCloseFrame:(WebFrame *)frame; - virtual void WillCloseFrame(WebView* webview, WebKit::WebFrame* frame) { - } - - // ResourceLoadDelegate ---------------------------------------------------- - - // Associates the given identifier with the initial resource request. - // Resource load callbacks will use the identifier throughout the life of the - // request. - virtual void AssignIdentifierToRequest( - WebKit::WebFrame* webframe, - uint32 identifier, - const WebKit::WebURLRequest& request) { - } - - // Notifies the delegate that a request is about to be sent out, giving the - // delegate the opportunity to modify the request. Note that request is - // writable here, and changes to the URL, for example, will change the request - // made. If this request is the result of a redirect, then redirect_response - // will be non-null and contain the response that triggered the redirect. - virtual void WillSendRequest( - WebKit::WebFrame* webframe, - uint32 identifier, - WebKit::WebURLRequest* request, - const WebKit::WebURLResponse& redirect_response) { - } - - virtual void DidReceiveResponse(WebKit::WebFrame* webframe, - uint32 identifier, - const WebKit::WebURLResponse& response) { - } - - // Notifies the delegate that a subresource load has succeeded. - virtual void DidFinishLoading(WebKit::WebFrame* webframe, uint32 identifier) { - } - - // Notifies the delegate that a subresource load has failed, and why. - virtual void DidFailLoadingWithError(WebKit::WebFrame* webframe, - uint32 identifier, - const WebKit::WebURLError& error) { - } - // ChromeClient ------------------------------------------------------------ // Appends a line to the application's error console. The message contains @@ -525,10 +190,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { const std::wstring& value) { } - virtual void DidContentsSizeChange(WebKit::WebWidget* webwidget, - int new_width, int new_height) { - } - // Called to retrieve the provider of desktop notifications. Pointer // is owned by the implementation of WebViewDelegate. virtual WebKit::WebNotificationPresenter* GetNotificationPresenter() { @@ -656,10 +317,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { virtual void TakeFocus(WebView* webview, bool reverse) { } - // Displays JS out-of-memory warning in the infobar - virtual void JSOutOfMemory() { - } - // Notification that a user metric has occurred. virtual void UserMetricsRecordAction(const std::wstring& action) { } @@ -758,8 +415,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { // Called when an item was added to the history virtual void DidAddHistoryItem() { } - WebViewDelegate() { } - protected: ~WebViewDelegate() { } }; diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index effb17d..f82c6c7 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -103,6 +103,7 @@ using WebKit::WebDragOperationNone; using WebKit::WebDragOperationsMask; using WebKit::WebEditingClient; using WebKit::WebFrame; +using WebKit::WebFrameClient; using WebKit::WebInputEvent; using WebKit::WebKeyboardEvent; using WebKit::WebMouseEvent; @@ -340,17 +341,19 @@ WebView* WebView::Create(WebViewDelegate* delegate, return instance; } -void WebViewImpl::InitializeMainFrame() { +void WebViewImpl::InitializeMainFrame(WebFrameClient* frame_client) { // NOTE: The WebFrameImpl takes a reference to itself within InitMainFrame // and releases that reference once the corresponding Frame is destroyed. - scoped_refptr<WebFrameImpl> main_frame = new WebFrameImpl(); + scoped_refptr<WebFrameImpl> main_frame = new WebFrameImpl(frame_client); main_frame->InitMainFrame(this); - WebDevToolsAgentDelegate* tools_delegate = - delegate_->GetWebDevToolsAgentDelegate(); - if (tools_delegate) - devtools_agent_.reset(new WebDevToolsAgentImpl(this, tools_delegate)); + if (delegate_) { + WebDevToolsAgentDelegate* tools_delegate = + delegate_->GetWebDevToolsAgentDelegate(); + if (tools_delegate) + devtools_agent_.reset(new WebDevToolsAgentImpl(this, tools_delegate)); + } // Restrict the access to the local file system // (see WebView.mm WebView::_commonInitializationWithFrameName). diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 7bc66e9..611f914 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -82,7 +82,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual void setTextDirection(WebKit::WebTextDirection direction); // WebView methods: - virtual void InitializeMainFrame(); + virtual void InitializeMainFrame(WebKit::WebFrameClient* frame_client); virtual bool ShouldClose(); virtual void ClosePage(); virtual WebViewDelegate* GetDelegate(); diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index 60fe5d0..b5a7861 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -21,6 +21,7 @@ #undef LOG #include "base/logging.h" +#include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebMessagePortChannel.h" #include "webkit/api/public/WebScreenInfo.h" #include "webkit/api/public/WebString.h" @@ -28,6 +29,7 @@ #include "webkit/api/public/WebWorkerClient.h" #include "webkit/api/src/PlatformMessagePortChannel.h" #include "webkit/api/src/WebDataSourceImpl.h" +#include "webkit/glue/empty_webframeclient.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webpreferences.h" @@ -36,7 +38,10 @@ #include "webkit/glue/webworker_impl.h" using WebKit::WebCursorInfo; +using WebKit::WebDataSource; +using WebKit::WebDataSourceImpl; using WebKit::WebFrame; +using WebKit::WebFrameClient; using WebKit::WebMessagePortChannel; using WebKit::WebMessagePortChannelArray; using WebKit::WebNavigationPolicy; @@ -51,39 +56,22 @@ using WebKit::WebWorkerClient; // Dummy WebViewDelegate - we only need it in Worker process to load a // 'shadow page' which will initialize WebCore loader. -class WorkerWebViewDelegate : public WebViewDelegate { +class WorkerWebFrameClient : public webkit_glue::EmptyWebFrameClient { public: - WorkerWebViewDelegate() {} - - virtual void didInvalidateRect(const WebRect&) {} - virtual void didScrollRect(int dx, int dy, const WebRect& clipRect) {} - virtual void didFocus() {} - virtual void didBlur() {} - virtual void didChangeCursor(const WebCursorInfo&) {} - virtual void closeWidgetSoon() {} - virtual void show(WebNavigationPolicy) {} - virtual void runModal() {} - virtual WebRect windowRect() { return WebRect(); } - virtual void setWindowRect(const WebRect&) {} - virtual WebRect windowResizerRect() { return WebRect(); } - virtual WebRect rootWindowRect() { return WebRect(); } - virtual WebScreenInfo screenInfo() { return WebScreenInfo(); } - // Tell the loader to load the data into the 'shadow page' synchronously, // so we can grab the resulting Document right after load. - virtual void DidCreateDataSource(WebFrame* frame, WebKit::WebDataSource* ds) { - static_cast<WebKit::WebDataSourceImpl*>(ds)-> - setDeferMainResourceDataLoad(false); + virtual void didCreateDataSource(WebFrame* frame, WebDataSource* ds) { + static_cast<WebDataSourceImpl*>(ds)->setDeferMainResourceDataLoad(false); } // Lazy allocate and leak this instance. - static WorkerWebViewDelegate* worker_delegate() { - static WorkerWebViewDelegate* worker_delegate = new WorkerWebViewDelegate(); - return worker_delegate; + static WorkerWebFrameClient* GetSharedInstance() { + static WorkerWebFrameClient client; + return &client; } private: - DISALLOW_COPY_AND_ASSIGN(WorkerWebViewDelegate); + WorkerWebFrameClient() {} }; namespace WebKit { @@ -149,9 +137,9 @@ void WebWorkerImpl::startWorkerContext(const WebURL& script_url, // loading requests from the worker context to the rest of WebKit and Chromium // infrastructure. DCHECK(!web_view_); - web_view_ = WebView::Create(WorkerWebViewDelegate::worker_delegate(), NULL); + web_view_ = WebView::Create(NULL, NULL); WebPreferences().Apply(web_view_); - web_view_->InitializeMainFrame(); + web_view_->InitializeMainFrame(WorkerWebFrameClient::GetSharedInstance()); WebFrameImpl* web_frame = static_cast<WebFrameImpl*>(web_view_->GetMainFrame()); diff --git a/webkit/glue/webworkerclient_impl.cc b/webkit/glue/webworkerclient_impl.cc index 6147dca..f6bcfb3 100644 --- a/webkit/glue/webworkerclient_impl.cc +++ b/webkit/glue/webworkerclient_impl.cc @@ -26,6 +26,7 @@ #include "webkit/glue/webworkerclient_impl.h" #include "base/command_line.h" +#include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebKit.h" #include "webkit/api/public/WebKitClient.h" #include "webkit/api/public/WebMessagePortChannel.h" @@ -40,6 +41,7 @@ #include "webkit/glue/webview_impl.h" #include "webkit/glue/webworker_impl.h" +using WebKit::WebFrameClient; using WebKit::WebMessagePortChannel; using WebKit::WebMessagePortChannelArray; using WebKit::WebString; @@ -69,16 +71,10 @@ WebCore::WorkerContextProxy* WebCore::WorkerContextProxy::create( WebWorkerClientImpl* proxy = new WebWorkerClientImpl(worker); if (worker->scriptExecutionContext()->isDocument()) { - // Get to the RenderView, so that we can tell the browser to create a - // worker process if necessary. WebCore::Document* document = static_cast<WebCore::Document*>( worker->scriptExecutionContext()); - WebFrameLoaderClient* frame_loader_client = - static_cast<WebFrameLoaderClient*>( - document->frame()->loader()->client()); - WebViewDelegate* webview_delegate = - frame_loader_client->webframe()->GetWebViewImpl()->delegate(); - webworker = webview_delegate->CreateWebWorker(proxy); + WebFrameImpl* webframe = WebFrameImpl::FromFrame(document->frame()); + webworker = webframe->client()->createWorker(webframe, proxy); } else { WebCore::WorkerContextExecutionProxy* current_context = WebCore::WorkerContextExecutionProxy::retrieve(); diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index 6244cd1..8fa349c 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -374,8 +374,7 @@ class WorkItemLoad : public LayoutTestController::WorkItem { WorkItemLoad(const GURL& url, const string& target) : url_(url), target_(target) {} bool Run(TestShell* shell) { - shell->LoadURLForFrame(UTF8ToWide(url_.spec()).c_str(), - UTF8ToWide(target_).c_str()); + shell->LoadURLForFrame(url_, UTF8ToWide(target_).c_str()); return true; // TODO(darin): Did it really start a navigation? } private: diff --git a/webkit/tools/test_shell/listener_leak_test.cc b/webkit/tools/test_shell/listener_leak_test.cc index 3c5785a..abee399 100644 --- a/webkit/tools/test_shell/listener_leak_test.cc +++ b/webkit/tools/test_shell/listener_leak_test.cc @@ -57,7 +57,7 @@ TEST_F(ListenerLeakTest, ReferenceCycle) { .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("listener")) .Append(FILE_PATH_LITERAL("listener_leak1.html")); - test_shell_->LoadURL(listener_file.ToWStringHack().c_str()); + test_shell_->LoadFile(listener_file); test_shell_->WaitTestFinished(); ASSERT_EQ(0, GetNumObjects(log_skip, "EventListenerLeakTestObject1")); } @@ -72,7 +72,7 @@ TEST_F(ListenerLeakTest, HiddenReferences) { .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("listener")) .Append(FILE_PATH_LITERAL("listener_leak2.html")); - test_shell_->LoadURL(listener_file.ToWStringHack().c_str()); + test_shell_->LoadFile(listener_file); test_shell_->WaitTestFinished(); ASSERT_EQ(1, GetNumObjects(log_skip, "EventListenerLeakTestObject2")); } diff --git a/webkit/tools/test_shell/mac/test_shell_webview.mm b/webkit/tools/test_shell/mac/test_shell_webview.mm index 4767e63..31d5c0a 100644 --- a/webkit/tools/test_shell/mac/test_shell_webview.mm +++ b/webkit/tools/test_shell/mac/test_shell_webview.mm @@ -87,7 +87,7 @@ NSURL* tempUrl = [NSURL URLWithString:url]; if (tempUrl && ![tempUrl scheme]) url = [@"http://" stringByAppendingString:url]; - shell_->LoadURL(UTF8ToWide([url UTF8String]).c_str()); + shell_->LoadURL(GURL(std::string([url UTF8String]))); } - (void)mouseDown:(NSEvent *)theEvent { diff --git a/webkit/tools/test_shell/mac/webview_host.mm b/webkit/tools/test_shell/mac/webview_host.mm index c8ffa08..846fdfe 100644 --- a/webkit/tools/test_shell/mac/webview_host.mm +++ b/webkit/tools/test_shell/mac/webview_host.mm @@ -37,7 +37,7 @@ WebViewHost* WebViewHost::Create(NSView* parent_view, host->webwidget_ = WebView::Create(delegate, delegate); prefs.Apply(host->webview()); - host->webview()->InitializeMainFrame(); + host->webview()->InitializeMainFrame(delegate); host->webwidget_->resize(WebSize(content_rect.size.width, content_rect.size.height)); diff --git a/webkit/tools/test_shell/media_leak_test.cc b/webkit/tools/test_shell/media_leak_test.cc index a356ffa..26312f9 100644 --- a/webkit/tools/test_shell/media_leak_test.cc +++ b/webkit/tools/test_shell/media_leak_test.cc @@ -24,7 +24,7 @@ TEST_F(MediaLeakTest, VideoBear) { .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("media")) .Append(FILE_PATH_LITERAL("bear.html")); - test_shell_->LoadURL(media_file.ToWStringHack().c_str()); + test_shell_->LoadFile(media_file); test_shell_->WaitTestFinished(); } @@ -37,7 +37,7 @@ TEST_F(MediaLeakTest, DISABLED_ManyVideoBear) { .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("media")) .Append(FILE_PATH_LITERAL("manybear.html")); - test_shell_->LoadURL(media_file.ToWStringHack().c_str()); + test_shell_->LoadFile(media_file); test_shell_->WaitTestFinished(); } diff --git a/webkit/tools/test_shell/node_leak_test.cc b/webkit/tools/test_shell/node_leak_test.cc index 7739efd..bfd5688 100644 --- a/webkit/tools/test_shell/node_leak_test.cc +++ b/webkit/tools/test_shell/node_leak_test.cc @@ -65,7 +65,7 @@ class NodeLeakTest : public TestShellTest { } void NavigateToURL(const std::wstring& test_url) { - test_shell_->LoadURL(test_url.c_str()); + test_shell_->LoadURL(GURL(WideToUTF8(test_url))); test_shell_->WaitTestFinished(); // Depends on TestShellTests::TearDown to load blank page and diff --git a/webkit/tools/test_shell/plugin_tests.cc b/webkit/tools/test_shell/plugin_tests.cc index fedc908..3c07a07 100644 --- a/webkit/tools/test_shell/plugin_tests.cc +++ b/webkit/tools/test_shell/plugin_tests.cc @@ -155,7 +155,7 @@ TEST_F(PluginTest, DeleteFrameDuringEvent) { FilePath test_html = data_dir_; test_html = test_html.AppendASCII("plugins"); test_html = test_html.AppendASCII("delete_frame.html"); - test_shell_->LoadURL(test_html.ToWStringHack().c_str()); + test_shell_->LoadFile(test_html); test_shell_->WaitTestFinished(); WebKit::WebMouseEvent input; @@ -185,7 +185,7 @@ TEST_F(PluginTest, PluginVisibilty) { FilePath test_html = data_dir_; test_html = test_html.AppendASCII("plugins"); test_html = test_html.AppendASCII("plugin_visibility.html"); - test_shell_->LoadURL(test_html.ToWStringHack().c_str()); + test_shell_->LoadFile(test_html); test_shell_->WaitTestFinished(); WebFrame* main_frame = test_shell_->webView()->GetMainFrame(); diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 3ebb1bc..cbffa96 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -26,6 +26,7 @@ #include "googleurl/src/url_util.h" #include "grit/webkit_strings.h" #include "net/base/mime_util.h" +#include "net/base/net_util.h" #include "net/url_request/url_request_file_job.h" #include "net/url_request/url_request_filter.h" #include "skia/ext/bitmap_platform_device.h" @@ -131,7 +132,7 @@ TestShell::~TestShell() { // Navigate to an empty page to fire all the destruction logic for the // current page. - LoadURL(L"about:blank"); + LoadURL(GURL("about:blank")); // Call GC twice to clean up garbage. CallJSGC(); @@ -160,10 +161,10 @@ TestShell::~TestShell() { } } -bool TestShell::CreateNewWindow(const std::wstring& startingURL, +bool TestShell::CreateNewWindow(const GURL& starting_url, TestShell** result) { TestShell* shell = new TestShell(); - bool rv = shell->Initialize(startingURL); + bool rv = shell->Initialize(starting_url); if (rv) { if (result) *result = shell; @@ -486,12 +487,16 @@ WebView* TestShell::CreateWebView(WebView* webview) { return NULL; TestShell* new_win; - if (!CreateNewWindow(std::wstring(), &new_win)) + if (!CreateNewWindow(GURL(), &new_win)) return NULL; return new_win->webView(); } +bool TestShell::IsSVGTestURL(const GURL& url) { + return url.is_valid() && url.spec().find("W3C-SVG-1.1") != std::string::npos; +} + void TestShell::SizeToSVG() { SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); } @@ -506,8 +511,12 @@ void TestShell::ResetTestController() { delegate_->Reset(); } -void TestShell::LoadURL(const wchar_t* url) { - LoadURLForFrame(url, NULL); +void TestShell::LoadFile(const FilePath& file) { + LoadURLForFrame(net::FilePathToFileURL(file), std::wstring()); +} + +void TestShell::LoadURL(const GURL& url) { + LoadURLForFrame(url, std::wstring()); } bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index b1bff50..b99cbea 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -147,8 +147,9 @@ public: return layout_test_controller_->AcceptsEditing(); } - void LoadURL(const wchar_t* url); - void LoadURLForFrame(const wchar_t* url, const wchar_t* frame_name); + void LoadFile(const FilePath& file); + void LoadURL(const GURL& url); + void LoadURLForFrame(const GURL& url, const std::wstring& frame_name); void GoBackOrForward(int offset); void Reload(); bool Navigate(const TestNavigationEntry& entry, bool reload); @@ -166,7 +167,7 @@ public: static WindowList* windowList() { return window_list_; } // If shell is non-null, then *shell is assigned upon successful return - static bool CreateNewWindow(const std::wstring& startingURL, + static bool CreateNewWindow(const GURL& starting_url, TestShell** shell = NULL); static void DestroyWindow(gfx::NativeWindow windowHandle); @@ -270,7 +271,8 @@ public: static StringPiece NetResourceProvider(int key); protected: - bool Initialize(const std::wstring& startingURL); + bool Initialize(const GURL& starting_url); + bool IsSVGTestURL(const GURL& url); void SizeToSVG(); void SizeToDefault(); void SizeTo(int width, int height); diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index 86ce5d6..72864e2 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -97,7 +97,7 @@ void ReloadButtonClicked(GtkButton* button, TestShell* shell) { // Callback for when you press enter in the URL box. void URLEntryActivate(GtkEntry* entry, TestShell* shell) { const gchar* url = gtk_entry_get_text(entry); - shell->LoadURL(UTF8ToWide(url).c_str()); + shell->LoadURL(GURL(url)); } // Callback for Debug > Dump body text... menu item. @@ -313,7 +313,7 @@ void TestShell::PlatformCleanUp() { } } -bool TestShell::Initialize(const std::wstring& startingURL) { +bool TestShell::Initialize(const GURL& starting_url) { m_mainWnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); gtk_window_set_title(m_mainWnd, "Test Shell"); // Null out m_mainWnd when it is destroyed so we don't destroy it twice. @@ -358,7 +358,7 @@ bool TestShell::Initialize(const std::wstring& startingURL) { m_editWnd = gtk_entry_new(); g_signal_connect(G_OBJECT(m_editWnd), "activate", G_CALLBACK(URLEntryActivate), this); - gtk_entry_set_text(GTK_ENTRY(m_editWnd), WideToUTF8(startingURL).c_str()); + gtk_entry_set_text(GTK_ENTRY(m_editWnd), starting_url.spec().c_str()); GtkToolItem* tool_item = gtk_tool_item_new(); gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd); @@ -374,11 +374,10 @@ bool TestShell::Initialize(const std::wstring& startingURL) { // LoadURL will do a resize, so make sure we don't call LoadURL // until we've completed all of our GTK setup. - if (!startingURL.empty()) - LoadURL(startingURL.c_str()); + if (starting_url.is_valid()) + LoadURL(starting_url); - bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; - if (bIsSVGTest) + if (IsSVGTestURL(starting_url)) SizeToSVG(); else SizeToDefault(); @@ -554,8 +553,7 @@ void TestShell::ResizeSubViews() { shell->test_is_preparing_ = true; shell->set_test_params(¶ms); - std::wstring wstr = UTF8ToWide(params.test_url.c_str()); - shell->LoadURL(wstr.c_str()); + shell->LoadURL(GURL(params.test_url)); shell->test_is_preparing_ = false; shell->WaitTestFinished(); @@ -564,36 +562,21 @@ void TestShell::ResizeSubViews() { return true; } -void TestShell::LoadURLForFrame(const wchar_t* url, - const wchar_t* frame_name) { - if (!url) +void TestShell::LoadURLForFrame(const GURL& url, + const std::wstring& frame_name) { + if (!url.is_valid()) return; - bool bIsSVGTest = wcsstr(url, L"W3C-SVG-1.1") > 0; - - if (bIsSVGTest) + if (IsSVGTestURL(url)) { SizeToSVG(); - else { + } else { // only resize back to the default when running tests if (layout_test_mode()) SizeToDefault(); } - std::wstring frame_string; - if (frame_name) - frame_string = frame_name; - - std::wstring path(url); - GURL gurl; - // PathExists will reject any string with no leading '/' - // as well as empty strings. - if (file_util::AbsolutePath(&path)) - gurl = net::FilePathToFileURL(FilePath::FromWStringHack(path)); - else - gurl = GURL(WideToUTF8(url)); - - navigation_controller_->LoadEntry(new TestNavigationEntry( - -1, gurl, std::wstring(), frame_string)); + navigation_controller_->LoadEntry( + new TestNavigationEntry(-1, url, std::wstring(), frame_name)); } // TODO(agl): PromptForSaveFile should use FilePath diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index c3c0985..54e77d7 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -225,7 +225,7 @@ NSButton* MakeTestButton(NSRect* rect, NSString* title, NSView* parent) { return button; } -bool TestShell::Initialize(const std::wstring& startingURL) { +bool TestShell::Initialize(const GURL& starting_url) { // Perform application initialization: // send message to app controller? need to work this out @@ -313,12 +313,10 @@ bool TestShell::Initialize(const std::wstring& startingURL) { [m_mainWnd makeKeyAndOrderFront: nil]; // Load our initial content. - if (!startingURL.empty()) - LoadURL(startingURL.c_str()); + if (starting_url.is_valid()) + LoadURL(starting_url); - bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; - - if (bIsSVGTest) { + if (IsSVGTestURL(starting_url)) { SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); } else { SizeToDefault(); @@ -536,8 +534,7 @@ void TestShell::ResizeSubViews() { shell->test_is_preparing_ = true; shell->set_test_params(¶ms); - std::wstring wstr = UTF8ToWide(params.test_url.c_str()); - shell->LoadURL(wstr.c_str()); + shell->LoadURL(GURL(params.test_url)); shell->test_is_preparing_ = false; shell->WaitTestFinished(); @@ -546,16 +543,12 @@ void TestShell::ResizeSubViews() { return true; } -void TestShell::LoadURLForFrame(const wchar_t* url, - const wchar_t* frame_name) { - if (!url) +void TestShell::LoadURLForFrame(const GURL& url, + const std::wstring& frame_name) { + if (!url.is_valid()) return; - std::string url8 = WideToUTF8(url); - - bool bIsSVGTest = strstr(url8.c_str(), "W3C-SVG-1.1") > 0; - - if (bIsSVGTest) { + if (IsSVGTestURL(url)) { SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); } else { // only resize back to the default when running tests @@ -563,18 +556,8 @@ void TestShell::LoadURLForFrame(const wchar_t* url, SizeToDefault(); } - std::string urlString(url8); - struct stat stat_buf; - if (!urlString.empty() && stat(url8.c_str(), &stat_buf) == 0) { - urlString.insert(0, "file://"); - } - - std::wstring frame_string; - if (frame_name) - frame_string = frame_name; - - navigation_controller_->LoadEntry(new TestNavigationEntry( - -1, GURL(urlString), std::wstring(), frame_string)); + navigation_controller_->LoadEntry( + new TestNavigationEntry(-1, url, std::wstring(), frame_name)); } bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc index 6ef35df..d35df77 100644 --- a/webkit/tools/test_shell/test_shell_main.cc +++ b/webkit/tools/test_shell/test_shell_main.cc @@ -208,7 +208,7 @@ int main(int argc, char* argv[]) { StatsTable::set_current(table); TestShell* shell; - if (TestShell::CreateNewWindow(uri.ToWStringHack(), &shell)) { + if (TestShell::CreateNewWindow(net::FilePathToFileURL(uri), &shell)) { if (record_mode || playback_mode) { platform.SetWindowPositionForRecording(shell); WebKit::registerExtension(extensions_v8::PlaybackExtension::Get()); diff --git a/webkit/tools/test_shell/test_shell_test.cc b/webkit/tools/test_shell/test_shell_test.cc index 87b5347..a85b618 100644 --- a/webkit/tools/test_shell/test_shell_test.cc +++ b/webkit/tools/test_shell/test_shell_test.cc @@ -12,10 +12,11 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/string_util.h" +#include "net/base/net_util.h" -std::wstring TestShellTest::GetTestURL(const FilePath& test_case_path, - const std::string& test_case) { - return test_case_path.AppendASCII(test_case).ToWStringHack(); +GURL TestShellTest::GetTestURL(const FilePath& test_case_path, + const std::string& test_case) { + return net::FilePathToFileURL(test_case_path.AppendASCII(test_case)); } void TestShellTest::SetUp() { @@ -32,7 +33,7 @@ void TestShellTest::SetUp() { void TestShellTest::TearDown() { // Loading a blank url clears the memory in the current page. - test_shell_->LoadURL(L"about:blank"); + test_shell_->LoadURL(GURL("about:blank")); test_shell_->DestroyWindow(test_shell_->mainWnd()); LayoutTestController::ClearShell(); @@ -41,5 +42,5 @@ void TestShellTest::TearDown() { } void TestShellTest::CreateEmptyWindow() { - TestShell::CreateNewWindow(L"about:blank", &test_shell_); + TestShell::CreateNewWindow(GURL("about:blank"), &test_shell_); } diff --git a/webkit/tools/test_shell/test_shell_test.h b/webkit/tools/test_shell/test_shell_test.h index 4e6372b..a5e0705 100644 --- a/webkit/tools/test_shell/test_shell_test.h +++ b/webkit/tools/test_shell/test_shell_test.h @@ -20,8 +20,8 @@ class TestShellTest : public testing::Test { protected: // Returns the path "test_case_path/test_case". - std::wstring GetTestURL(const FilePath& test_case_path, - const std::string& test_case); + GURL GetTestURL(const FilePath& test_case_path, + const std::string& test_case); virtual void SetUp(); virtual void TearDown(); diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index 17a707a..e097b25 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -267,8 +267,7 @@ bool TestShell::RunFileTest(const TestParams& params) { shell->test_is_preparing_ = true; shell->set_test_params(¶ms); - std::wstring wstr = UTF8ToWide(params.test_url.c_str()); - shell->LoadURL(wstr.c_str()); + shell->LoadURL(GURL(params.test_url)); shell->test_is_preparing_ = false; shell->WaitTestFinished(); @@ -311,7 +310,7 @@ void TestShell::PlatformCleanUp() { win_util::SetWindowUserData(m_editWnd, NULL); } -bool TestShell::Initialize(const std::wstring& startingURL) { +bool TestShell::Initialize(const GURL& starting_url) { // Perform application initialization: m_mainWnd = CreateWindow(g_windowClass, g_windowTitle, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, @@ -362,14 +361,12 @@ bool TestShell::Initialize(const std::wstring& startingURL) { delegate_->RegisterDragDrop(); // Load our initial content. - if (!startingURL.empty()) - LoadURL(startingURL.c_str()); + if (starting_url.is_valid()) + LoadURL(starting_url); ShowWindow(webViewWnd(), SW_SHOW); - bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; - - if (bIsSVGTest) { + if (IsSVGTestURL(starting_url)) { SizeToSVG(); } else { SizeToDefault(); @@ -500,15 +497,14 @@ void TestShell::ResizeSubViews() { rc.bottom - URLBAR_HEIGHT, TRUE); } -void TestShell::LoadURLForFrame(const wchar_t* url, - const wchar_t* frame_name) { - if (!url) - return; +void TestShell::LoadURLForFrame(const GURL& url, + const std::wstring& frame_name) { + if (!url.is_valid()) + return; - TRACE_EVENT_BEGIN("url.load", this, WideToUTF8(url)); - bool bIsSVGTest = wcsstr(url, L"W3C-SVG-1.1") > 0; + TRACE_EVENT_BEGIN("url.load", this, url.spec()); - if (bIsSVGTest) { + if (IsSVGTestURL(url)) { SizeToSVG(); } else { // only resize back to the default when running tests @@ -516,20 +512,8 @@ void TestShell::LoadURLForFrame(const wchar_t* url, SizeToDefault(); } - std::wstring urlString(url); - if (!urlString.empty() && (PathFileExists(url) || PathIsUNC(url))) { - wchar_t fileURL[INTERNET_MAX_URL_LENGTH]; - DWORD fileURLLength = INTERNET_MAX_URL_LENGTH; - if (SUCCEEDED(UrlCreateFromPath(url, fileURL, &fileURLLength, 0))) - urlString.assign(fileURL); - } - - std::wstring frame_string; - if (frame_name) - frame_string = frame_name; - - navigation_controller_->LoadEntry(new TestNavigationEntry( - -1, GURL(urlString), std::wstring(), frame_string)); + navigation_controller_->LoadEntry( + new TestNavigationEntry(-1, url, std::wstring(), frame_name)); } LRESULT CALLBACK TestShell::WndProc(HWND hwnd, UINT message, WPARAM wParam, @@ -612,12 +596,12 @@ LRESULT CALLBACK TestShell::EditWndProc(HWND hwnd, UINT message, switch (message) { case WM_CHAR: if (wParam == VK_RETURN) { - wchar_t strPtr[MAX_URL_LENGTH + 1]; // Leave room for adding a NULL; - *((LPWORD)strPtr) = MAX_URL_LENGTH; - LRESULT strLen = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)strPtr); - if (strLen > 0) { - strPtr[strLen] = 0; // EM_GETLINE doesn't NULL terminate. - shell->LoadURL(strPtr); + wchar_t str[MAX_URL_LENGTH + 1]; // Leave room for adding a NULL; + *((LPWORD)str) = MAX_URL_LENGTH; + LRESULT str_len = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)str); + if (str_len > 0) { + str[str_len] = 0; // EM_GETLINE doesn't NULL terminate. + shell->LoadURL(GURL(str)); } return 0; diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 63917e9..4116df0 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -20,6 +20,7 @@ #include "base/string_util.h" #include "base/trace_event.h" #include "net/base/net_errors.h" +#include "webkit/api/public/WebCString.h" #include "webkit/api/public/WebData.h" #include "webkit/api/public/WebDataSource.h" #include "webkit/api/public/WebDragData.h" @@ -64,8 +65,11 @@ using WebKit::WebDataSource; using WebKit::WebDragData; using WebKit::WebDragOperationsMask; using WebKit::WebEditingAction; +using WebKit::WebForm; using WebKit::WebFrame; using WebKit::WebHistoryItem; +using WebKit::WebMediaPlayer; +using WebKit::WebMediaPlayerClient; using WebKit::WebNavigationType; using WebKit::WebNavigationPolicy; using WebKit::WebNode; @@ -251,329 +255,11 @@ WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview, return shell_->CreatePopupWidget(webview); } -WebPlugin* TestWebViewDelegate::CreatePlugin( - WebFrame* frame, const WebPluginParams& params) { - return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); -} - -WebKit::WebMediaPlayer* TestWebViewDelegate::CreateWebMediaPlayer( - WebKit::WebMediaPlayerClient* client) { - scoped_refptr<media::FilterFactoryCollection> factory = - new media::FilterFactoryCollection(); - - // TODO(hclam): this is the same piece of code as in RenderView, maybe they - // should be grouped together. - webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = - new webkit_glue::MediaResourceLoaderBridgeFactory( - GURL::EmptyGURL(), // referrer - "null", // frame origin - "null", // main_frame_origin - base::GetCurrentProcId(), - appcache::kNoHostId, - 0); - factory->AddFactory(webkit_glue::BufferedDataSource::CreateFactory( - MessageLoop::current(), bridge_factory)); - // TODO(hclam): Use command line switch to determine which data source to use. - return new webkit_glue::WebMediaPlayerImpl(client, factory); -} - -WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) { -#if ENABLE(WORKERS) - return TestWebWorkerHelper::CreateWebWorker(client); -#else - return NULL; -#endif -} - -void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url, - const GURL& referrer, - WebNavigationPolicy policy) { - DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab); - TestShell* shell = NULL; - if (TestShell::CreateNewWindow(UTF8ToWide(url.spec()), &shell)) - shell->Show(policy); -} - -void TestWebViewDelegate::WindowObjectCleared(WebFrame* webframe) { - shell_->BindJSObjectsToWindow(webframe); -} - -WebNavigationPolicy TestWebViewDelegate::PolicyForNavigationAction( - WebView* webview, - WebFrame* frame, - const WebURLRequest& request, - WebNavigationType type, - WebNavigationPolicy default_policy, - bool is_redirect) { - WebNavigationPolicy result; - if (policy_delegate_enabled_) { - printf("Policy delegate: attempt to load %s with navigation type '%s'\n", - GetURLDescription(request.url()).c_str(), - WebNavigationTypeToString(type)); - if (policy_delegate_is_permissive_) { - result = WebKit::WebNavigationPolicyCurrentTab; - } else { - result = WebKit::WebNavigationPolicyIgnore; - } - if (policy_delegate_should_notify_done_) - shell_->layout_test_controller()->PolicyDelegateDone(); - } else { - result = default_policy; - } - return result; -} - -void TestWebViewDelegate::AssignIdentifierToRequest( - WebFrame* webframe, - uint32 identifier, - const WebURLRequest& request) { - if (shell_->ShouldDumpResourceLoadCallbacks()) - resource_identifier_map_[identifier] = request.url().spec(); -} - std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { ResourceMap::iterator it = resource_identifier_map_.find(identifier); return it != resource_identifier_map_.end() ? it->second : "<unknown>"; } -void TestWebViewDelegate::WillSendRequest( - WebFrame* webframe, - uint32 identifier, - WebURLRequest* request, - const WebURLResponse& redirect_response) { - GURL url = request->url(); - std::string request_url = url.possibly_invalid_spec(); - - if (shell_->ShouldDumpResourceLoadCallbacks()) { - GURL main_document_url = request->firstPartyForCookies(); - printf("%s - willSendRequest <NSURLRequest URL %s, main document URL %s," - " http method %s> redirectResponse %s\n", - GetResourceDescription(identifier).c_str(), - request_url.c_str(), - GetURLDescription(main_document_url).c_str(), - request->httpMethod().utf8().data(), - GetResponseDescription(redirect_response).c_str()); - } - - if (!redirect_response.isNull() && 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; - } - - std::string host = url.host(); - if (TestShell::layout_test_mode() && !host.empty() && - (url.SchemeIs("http") || url.SchemeIs("https")) && - host != "127.0.0.1" && - host != "255.255.255.255" && // Used in some tests that expect to get - // back an error. - host != "localhost") { - printf("Blocked access to external URL %s\n", request_url.c_str()); - - // To block the request, we set its URL to an empty one. - request->setURL(WebURL()); - return; - } - - TRACE_EVENT_BEGIN("url.load", identifier, request_url); - // Set the new substituted URL. - request->setURL(GURL(TestShell::RewriteLocalUrl(request_url))); -} - -void TestWebViewDelegate::DidReceiveResponse( - WebFrame* webframe, - uint32 identifier, - const WebURLResponse& response) { - if (shell_->ShouldDumpResourceLoadCallbacks()) { - printf("%s - didReceiveResponse %s\n", - GetResourceDescription(identifier).c_str(), - GetResponseDescription(response).c_str()); - } -} - -void TestWebViewDelegate::DidFinishLoading(WebFrame* webframe, - uint32 identifier) { - TRACE_EVENT_END("url.load", identifier, ""); - if (shell_->ShouldDumpResourceLoadCallbacks()) { - printf("%s - didFinishLoading\n", - GetResourceDescription(identifier).c_str()); - } - - resource_identifier_map_.erase(identifier); -} - -void TestWebViewDelegate::DidFailLoadingWithError(WebFrame* webframe, - uint32 identifier, - const WebURLError& error) { - if (shell_->ShouldDumpResourceLoadCallbacks()) { - printf("%s - didFailLoadingWithError: %s\n", - GetResourceDescription(identifier).c_str(), - GetErrorDescription(error).c_str()); - } - - resource_identifier_map_.erase(identifier); -} - -void TestWebViewDelegate::DidCreateDataSource(WebFrame* frame, - WebDataSource* ds) { - ds->setExtraData(pending_extra_data_.release()); -} - -void TestWebViewDelegate::DidStartProvisionalLoadForFrame( - WebView* webview, - WebFrame* frame, - NavigationGesture gesture) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didStartProvisionalLoadForFrame\n", - GetFrameDescription(frame).c_str()); - } - - if (!top_loading_frame_) { - top_loading_frame_ = frame; - } - - if (shell_->layout_test_controller()->StopProvisionalFrameLoads()) { - printf("%S - stopping load in didStartProvisionalLoadForFrame callback\n", - GetFrameDescription(frame).c_str()); - frame->stopLoading(); - } - UpdateAddressBar(webview); -} - -void TestWebViewDelegate::DidReceiveProvisionalLoadServerRedirect( - WebView* webview, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didReceiveServerRedirectForProvisionalLoadForFrame\n", - GetFrameDescription(frame).c_str()); - } - - UpdateAddressBar(webview); -} - -void TestWebViewDelegate::DidFailProvisionalLoadWithError( - WebView* webview, - const WebURLError& error, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didFailProvisionalLoadWithError\n", - GetFrameDescription(frame).c_str()); - } - - LocationChangeDone(frame); - - // Don't display an error page if we're running layout tests, because - // DumpRenderTree doesn't. - if (shell_->layout_test_mode()) - return; - - // Don't display an error page if this is simply a cancelled load. Aside - // from being dumb, WebCore doesn't expect it and it will cause a crash. - if (error.reason == net::ERR_ABORTED) - return; - - const WebDataSource* failed_ds = frame->provisionalDataSource(); - - TestShellExtraData* extra_data = - static_cast<TestShellExtraData*>(failed_ds->extraData()); - bool replace = extra_data && extra_data->pending_page_id != -1; - - const std::string& error_text = - StringPrintf("Error %d when loading url %s", error.reason, - failed_ds->request().url().spec().data()); - - // Make sure we never show errors in view source mode. - frame->enableViewSourceMode(false); - - frame->loadHTMLString( - error_text, GURL("testshell-error:"), error.unreachableURL, replace); -} - -void TestWebViewDelegate::DidCommitLoadForFrame(WebView* webview, - WebFrame* frame, - bool is_new_navigation) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didCommitLoadForFrame\n", - GetFrameDescription(frame).c_str()); - } - - UpdateForCommittedLoad(frame, is_new_navigation); -} - -void TestWebViewDelegate::DidReceiveTitle(WebView* webview, - const std::wstring& title, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didReceiveTitle\n", - GetFrameDescription(frame).c_str()); - } - - if (shell_->ShouldDumpTitleChanges()) { - printf("TITLE CHANGED: %S\n", title.c_str()); - } - - SetPageTitle(title); -} - -void TestWebViewDelegate::DidFinishLoadForFrame(WebView* webview, - WebFrame* frame) { - TRACE_EVENT_END("frame.load", this, frame->url().spec()); - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didFinishLoadForFrame\n", - GetFrameDescription(frame).c_str()); - } - - UpdateAddressBar(webview); - LocationChangeDone(frame); -} - -void TestWebViewDelegate::DidFailLoadWithError(WebView* webview, - const WebURLError& error, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didFailLoadWithError\n", - GetFrameDescription(frame).c_str()); - } - - LocationChangeDone(frame); -} - -void TestWebViewDelegate::DidFinishDocumentLoadForFrame(WebView* webview, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didFinishDocumentLoadForFrame\n", - GetFrameDescription(frame).c_str()); - } else { - unsigned pending_unload_events = frame->unloadListenerCount(); - if (pending_unload_events) { - printf("%S - has %u onunload handler(s)\n", - GetFrameDescription(frame).c_str(), pending_unload_events); - } - } -} - -void TestWebViewDelegate::DidHandleOnloadEventsForFrame(WebView* webview, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didHandleOnloadEventsForFrame\n", - GetFrameDescription(frame).c_str()); - } -} - -void TestWebViewDelegate::DidChangeLocationWithinPageForFrame( - WebView* webview, WebFrame* frame, bool is_new_navigation) { - frame->dataSource()->setExtraData(pending_extra_data_.release()); - - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didChangeLocationWithinPageForFrame\n", - GetFrameDescription(frame).c_str()); - } - - UpdateForCommittedLoad(frame, is_new_navigation); -} - void TestWebViewDelegate::DidReceiveIconForFrame(WebView* webview, WebFrame* frame) { if (shell_->ShouldDumpFrameLoadCallbacks()) { @@ -582,27 +268,6 @@ void TestWebViewDelegate::DidReceiveIconForFrame(WebView* webview, } } -void TestWebViewDelegate::WillPerformClientRedirect(WebView* webview, - WebFrame* frame, - const GURL& src_url, - const GURL& dest_url, - unsigned int delay_seconds, - unsigned int fire_date) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - willPerformClientRedirectToURL: %s \n", - GetFrameDescription(frame).c_str(), - dest_url.possibly_invalid_spec().c_str()); - } -} - -void TestWebViewDelegate::DidCancelClientRedirect(WebView* webview, - WebFrame* frame) { - if (shell_->ShouldDumpFrameLoadCallbacks()) { - printf("%S - didCancelClientRedirectForFrame\n", - GetFrameDescription(frame).c_str()); - } -} - void TestWebViewDelegate::AddMessageToConsole(WebView* webview, const std::wstring& message, unsigned int line_no, @@ -900,6 +565,352 @@ void TestWebViewDelegate::didEndEditing() { } } +// WebFrameClient ------------------------------------------------------------ + +WebPlugin* TestWebViewDelegate::createPlugin( + WebFrame* frame, const WebPluginParams& params) { + return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); +} + +WebWorker* TestWebViewDelegate::createWorker( + WebFrame* frame, WebWorkerClient* client) { +#if ENABLE(WORKERS) + return TestWebWorkerHelper::CreateWebWorker(client); +#else + return NULL; +#endif +} + +WebMediaPlayer* TestWebViewDelegate::createMediaPlayer( + WebFrame* frame, WebMediaPlayerClient* client) { + scoped_refptr<media::FilterFactoryCollection> factory = + new media::FilterFactoryCollection(); + + // TODO(hclam): this is the same piece of code as in RenderView, maybe they + // should be grouped together. + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL::EmptyGURL(), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache::kNoHostId, + 0); + factory->AddFactory(webkit_glue::BufferedDataSource::CreateFactory( + MessageLoop::current(), bridge_factory)); + // TODO(hclam): Use command line switch to determine which data source to use. + return new webkit_glue::WebMediaPlayerImpl(client, factory); +} + +void TestWebViewDelegate::willClose(WebFrame* frame) { +} + +void TestWebViewDelegate::loadURLExternally( + WebFrame* frame, const WebURLRequest& request, + WebNavigationPolicy policy) { + DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab); + TestShell* shell = NULL; + if (TestShell::CreateNewWindow(request.url(), &shell)) + shell->Show(policy); +} + +WebNavigationPolicy TestWebViewDelegate::decidePolicyForNavigation( + WebFrame* frame, const WebURLRequest& request, + WebNavigationType type, WebNavigationPolicy default_policy, + bool is_redirect) { + WebNavigationPolicy result; + if (policy_delegate_enabled_) { + printf("Policy delegate: attempt to load %s with navigation type '%s'\n", + GetURLDescription(request.url()).c_str(), + WebNavigationTypeToString(type)); + if (policy_delegate_is_permissive_) { + result = WebKit::WebNavigationPolicyCurrentTab; + } else { + result = WebKit::WebNavigationPolicyIgnore; + } + if (policy_delegate_should_notify_done_) + shell_->layout_test_controller()->PolicyDelegateDone(); + } else { + result = default_policy; + } + return result; +} + +void TestWebViewDelegate::willSubmitForm(WebFrame* frame, const WebForm&) { + // Ignore +} + +void TestWebViewDelegate::willPerformClientRedirect( + WebFrame* frame, const WebURL& from, const WebURL& to, + double interval, double fire_time) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - willPerformClientRedirectToURL: %s \n", + GetFrameDescription(frame).c_str(), + to.spec().data()); + } +} + +void TestWebViewDelegate::didCancelClientRedirect(WebFrame* frame) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didCancelClientRedirectForFrame\n", + GetFrameDescription(frame).c_str()); + } +} + +void TestWebViewDelegate::didCompleteClientRedirect( + WebFrame* frame, const WebURL& from) { +} + +void TestWebViewDelegate::didCreateDataSource( + WebFrame* frame, WebDataSource* ds) { + ds->setExtraData(pending_extra_data_.release()); +} + +void TestWebViewDelegate::didStartProvisionalLoad(WebFrame* frame) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didStartProvisionalLoadForFrame\n", + GetFrameDescription(frame).c_str()); + } + + if (!top_loading_frame_) { + top_loading_frame_ = frame; + } + + if (shell_->layout_test_controller()->StopProvisionalFrameLoads()) { + printf("%S - stopping load in didStartProvisionalLoadForFrame callback\n", + GetFrameDescription(frame).c_str()); + frame->stopLoading(); + } + UpdateAddressBar(frame->view()); +} + +void TestWebViewDelegate::didReceiveServerRedirectForProvisionalLoad( + WebFrame* frame) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didReceiveServerRedirectForProvisionalLoadForFrame\n", + GetFrameDescription(frame).c_str()); + } + UpdateAddressBar(frame->view()); +} + +void TestWebViewDelegate::didFailProvisionalLoad( + WebFrame* frame, const WebURLError& error) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didFailProvisionalLoadWithError\n", + GetFrameDescription(frame).c_str()); + } + + LocationChangeDone(frame); + + // Don't display an error page if we're running layout tests, because + // DumpRenderTree doesn't. + if (shell_->layout_test_mode()) + return; + + // Don't display an error page if this is simply a cancelled load. Aside + // from being dumb, WebCore doesn't expect it and it will cause a crash. + if (error.reason == net::ERR_ABORTED) + return; + + const WebDataSource* failed_ds = frame->provisionalDataSource(); + + TestShellExtraData* extra_data = + static_cast<TestShellExtraData*>(failed_ds->extraData()); + bool replace = extra_data && extra_data->pending_page_id != -1; + + const std::string& error_text = + StringPrintf("Error %d when loading url %s", error.reason, + failed_ds->request().url().spec().data()); + + // Make sure we never show errors in view source mode. + frame->enableViewSourceMode(false); + + frame->loadHTMLString( + error_text, GURL("testshell-error:"), error.unreachableURL, replace); +} + +void TestWebViewDelegate::didReceiveDocumentData( + WebFrame* frame, const char* data, size_t length, + bool& preventDefault) { + // Ignore +} + +void TestWebViewDelegate::didCommitProvisionalLoad( + WebFrame* frame, bool is_new_navigation) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didCommitLoadForFrame\n", + GetFrameDescription(frame).c_str()); + } + UpdateForCommittedLoad(frame, is_new_navigation); +} + +void TestWebViewDelegate::didClearWindowObject(WebFrame* frame) { + shell_->BindJSObjectsToWindow(frame); +} + +void TestWebViewDelegate::didCreateDocumentElement(WebFrame* frame) { + // Ignore +} + +void TestWebViewDelegate::didReceiveTitle( + WebFrame* frame, const WebString& title) { + std::wstring wtitle = UTF16ToWideHack(title); + + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didReceiveTitle\n", + GetFrameDescription(frame).c_str()); + } + + if (shell_->ShouldDumpTitleChanges()) { + printf("TITLE CHANGED: %S\n", wtitle.c_str()); + } + + SetPageTitle(wtitle); +} + +void TestWebViewDelegate::didFinishDocumentLoad(WebFrame* frame) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didFinishDocumentLoadForFrame\n", + GetFrameDescription(frame).c_str()); + } else { + unsigned pending_unload_events = frame->unloadListenerCount(); + if (pending_unload_events) { + printf("%S - has %u onunload handler(s)\n", + GetFrameDescription(frame).c_str(), pending_unload_events); + } + } +} + +void TestWebViewDelegate::didHandleOnloadEvents(WebFrame* frame) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didHandleOnloadEventsForFrame\n", + GetFrameDescription(frame).c_str()); + } +} + +void TestWebViewDelegate::didFailLoad( + WebFrame* frame, const WebURLError& error) { + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didFailLoadWithError\n", + GetFrameDescription(frame).c_str()); + } + LocationChangeDone(frame); +} + +void TestWebViewDelegate::didFinishLoad(WebFrame* frame) { + TRACE_EVENT_END("frame.load", this, frame->url().spec()); + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didFinishLoadForFrame\n", + GetFrameDescription(frame).c_str()); + } + UpdateAddressBar(frame->view()); + LocationChangeDone(frame); +} + +void TestWebViewDelegate::didChangeLocationWithinPage( + WebFrame* frame, bool is_new_navigation) { + frame->dataSource()->setExtraData(pending_extra_data_.release()); + + if (shell_->ShouldDumpFrameLoadCallbacks()) { + printf("%S - didChangeLocationWithinPageForFrame\n", + GetFrameDescription(frame).c_str()); + } + + UpdateForCommittedLoad(frame, is_new_navigation); +} + +void TestWebViewDelegate::assignIdentifierToRequest( + WebFrame* frame, unsigned identifier, const WebURLRequest& request) { + if (shell_->ShouldDumpResourceLoadCallbacks()) + resource_identifier_map_[identifier] = request.url().spec(); +} + +void TestWebViewDelegate::willSendRequest( + WebFrame* frame, unsigned identifier, WebURLRequest& request, + const WebURLResponse& redirect_response) { + GURL url = request.url(); + std::string request_url = url.possibly_invalid_spec(); + + if (shell_->ShouldDumpResourceLoadCallbacks()) { + GURL main_document_url = request.firstPartyForCookies(); + printf("%s - willSendRequest <NSURLRequest URL %s, main document URL %s," + " http method %s> redirectResponse %s\n", + GetResourceDescription(identifier).c_str(), + request_url.c_str(), + GetURLDescription(main_document_url).c_str(), + request.httpMethod().utf8().data(), + GetResponseDescription(redirect_response).c_str()); + } + + if (!redirect_response.isNull() && 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; + } + + std::string host = url.host(); + if (TestShell::layout_test_mode() && !host.empty() && + (url.SchemeIs("http") || url.SchemeIs("https")) && + host != "127.0.0.1" && + host != "255.255.255.255" && // Used in some tests that expect to get + // back an error. + host != "localhost") { + printf("Blocked access to external URL %s\n", request_url.c_str()); + + // To block the request, we set its URL to an empty one. + request.setURL(WebURL()); + return; + } + + TRACE_EVENT_BEGIN("url.load", identifier, request_url); + // Set the new substituted URL. + request.setURL(GURL(TestShell::RewriteLocalUrl(request_url))); +} + +void TestWebViewDelegate::didReceiveResponse( + WebFrame* frame, unsigned identifier, const WebURLResponse& response) { + if (shell_->ShouldDumpResourceLoadCallbacks()) { + printf("%s - didReceiveResponse %s\n", + GetResourceDescription(identifier).c_str(), + GetResponseDescription(response).c_str()); + } +} + +void TestWebViewDelegate::didFinishResourceLoad( + WebFrame* frame, unsigned identifier) { + TRACE_EVENT_END("url.load", identifier, ""); + if (shell_->ShouldDumpResourceLoadCallbacks()) { + printf("%s - didFinishLoading\n", + GetResourceDescription(identifier).c_str()); + } + resource_identifier_map_.erase(identifier); +} + +void TestWebViewDelegate::didFailResourceLoad( + WebFrame* frame, unsigned identifier, const WebURLError& error) { + if (shell_->ShouldDumpResourceLoadCallbacks()) { + printf("%s - didFailLoadingWithError: %s\n", + GetResourceDescription(identifier).c_str(), + GetErrorDescription(error).c_str()); + } + resource_identifier_map_.erase(identifier); +} + +void TestWebViewDelegate::didLoadResourceFromMemoryCache( + WebFrame* frame, const WebURLRequest&, + const WebURLResponse&) { +} + +void TestWebViewDelegate::didExhaustMemoryAvailableForScript(WebFrame* frame) { +} + +void TestWebViewDelegate::didChangeContentsSize( + WebFrame* frame, const WebSize&) { +} + + // Public methods ------------------------------------------------------------ TestWebViewDelegate::TestWebViewDelegate(TestShell* shell) diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 91e439d..dc8d984 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -25,6 +25,7 @@ #include "base/scoped_ptr.h" #include "base/weak_ptr.h" #include "webkit/api/public/WebEditingClient.h" +#include "webkit/api/public/WebFrameClient.h" #if defined(OS_MACOSX) #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebPopupMenuInfo.h" @@ -46,6 +47,7 @@ class WebWidgetHost; class TestWebViewDelegate : public WebViewDelegate, public WebKit::WebEditingClient, + public WebKit::WebFrameClient, public webkit_glue::WebPluginPageDelegate, public base::SupportsWeakPtr<TestWebViewDelegate> { public: @@ -77,16 +79,6 @@ class TestWebViewDelegate : public WebViewDelegate, WebView* webview, const WebKit::WebPopupMenuInfo& info); #endif - virtual WebKit::WebPlugin* CreatePlugin( - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params); - virtual WebKit::WebMediaPlayer* CreateWebMediaPlayer( - WebKit::WebMediaPlayerClient* client); - virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client); - virtual void OpenURL(WebView* webview, - const GURL& url, - const GURL& referrer, - WebKit::WebNavigationPolicy policy); virtual void RunJavaScriptAlert(WebKit::WebFrame* webframe, const std::wstring& message); virtual bool RunJavaScriptConfirm(WebKit::WebFrame* webframe, @@ -121,99 +113,7 @@ class TestWebViewDelegate : public WebViewDelegate, int edit_flags, const std::string& security_info, const std::string& frame_charset); - virtual void DidCreateDataSource(WebKit::WebFrame* frame, - WebKit::WebDataSource* ds); - virtual void DidStartProvisionalLoadForFrame( - WebView* webview, - WebKit::WebFrame* frame, - NavigationGesture gesture); - virtual void DidReceiveProvisionalLoadServerRedirect( - WebView* webview, WebKit::WebFrame* frame); - virtual void DidFailProvisionalLoadWithError( - WebView* webview, - const WebKit::WebURLError& error, - WebKit::WebFrame* frame); - virtual void DidCommitLoadForFrame( - WebView* webview, - WebKit::WebFrame* frame, - bool is_new_navigation); - virtual void DidReceiveTitle(WebView* webview, - const std::wstring& title, - WebKit::WebFrame* frame); - virtual void DidFinishDocumentLoadForFrame(WebView* webview, - WebKit::WebFrame* frame); - virtual void DidHandleOnloadEventsForFrame(WebView* webview, - WebKit::WebFrame* frame); - virtual void DidChangeLocationWithinPageForFrame(WebView* webview, - WebKit::WebFrame* frame, - bool is_new_navigation); virtual void DidReceiveIconForFrame(WebView* webview, WebKit::WebFrame* frame); - - virtual void WillPerformClientRedirect(WebView* webview, - WebKit::WebFrame* frame, - const GURL& src_url, - const GURL& dest_url, - unsigned int delay_seconds, - unsigned int fire_date); - virtual void DidCancelClientRedirect(WebView* webview, - WebKit::WebFrame* frame); - - virtual void DidFinishLoadForFrame(WebView* webview, WebKit::WebFrame* frame); - virtual void DidFailLoadWithError(WebView* webview, - const WebKit::WebURLError& error, - WebKit::WebFrame* for_frame); - - virtual void AssignIdentifierToRequest(WebKit::WebFrame* webframe, - uint32 identifier, - const WebKit::WebURLRequest& request); - virtual void WillSendRequest(WebKit::WebFrame* webframe, - uint32 identifier, - WebKit::WebURLRequest* request, - const WebKit::WebURLResponse& redirect_response); - virtual void DidReceiveResponse(WebKit::WebFrame* webframe, - uint32 identifier, - const WebKit::WebURLResponse& response); - virtual void DidFinishLoading(WebKit::WebFrame* webframe, uint32 identifier); - virtual void DidFailLoadingWithError(WebKit::WebFrame* webframe, - uint32 identifier, - const WebKit::WebURLError& error); - -#if 0 - virtual bool ShouldBeginEditing(WebView* webview, std::wstring range); - virtual bool ShouldEndEditing(WebView* webview, std::wstring range); - virtual bool ShouldInsertNode(WebView* webview, - std::wstring node, - std::wstring range, - std::wstring action); - virtual bool ShouldInsertText(WebView* webview, - std::wstring text, - std::wstring range, - std::wstring action); - virtual bool ShouldChangeSelectedRange(WebView* webview, - std::wstring fromRange, - std::wstring toRange, - std::wstring affinity, - bool stillSelecting); - virtual bool ShouldDeleteRange(WebView* webview, std::wstring range); - virtual bool ShouldApplyStyle(WebView* webview, - std::wstring style, - std::wstring range); - virtual bool SmartInsertDeleteEnabled(); - virtual bool IsSelectTrailingWhitespaceEnabled(); - virtual void DidBeginEditing(); - virtual void DidChangeSelection(bool is_empty_selection); - virtual void DidChangeContents(); - virtual void DidEndEditing(); -#endif - - virtual void WindowObjectCleared(WebKit::WebFrame* webframe); - virtual WebKit::WebNavigationPolicy PolicyForNavigationAction( - WebView* webview, - WebKit::WebFrame* frame, - const WebKit::WebURLRequest& request, - WebKit::WebNavigationType type, - WebKit::WebNavigationPolicy default_policy, - bool is_redirect); virtual void NavigateBackForwardSoon(int offset); virtual int GetHistoryBackListCount(); virtual int GetHistoryForwardListCount(); @@ -258,6 +158,68 @@ class TestWebViewDelegate : public WebViewDelegate, virtual void didExecuteCommand(const WebKit::WebString& command_name) {} virtual void didEndEditing(); + // WebKit::WebFrameClient + virtual WebKit::WebPlugin* createPlugin( + WebKit::WebFrame*, const WebKit::WebPluginParams&); + virtual WebKit::WebWorker* createWorker( + WebKit::WebFrame*, WebKit::WebWorkerClient*); + virtual WebKit::WebMediaPlayer* createMediaPlayer( + WebKit::WebFrame*, WebKit::WebMediaPlayerClient*); + virtual void willClose(WebKit::WebFrame*); + virtual void loadURLExternally( + WebKit::WebFrame*, const WebKit::WebURLRequest&, + WebKit::WebNavigationPolicy); + virtual WebKit::WebNavigationPolicy decidePolicyForNavigation( + WebKit::WebFrame*, const WebKit::WebURLRequest&, + WebKit::WebNavigationType, WebKit::WebNavigationPolicy default_policy, + bool isRedirect); + virtual void willSubmitForm(WebKit::WebFrame*, const WebKit::WebForm&); + virtual void willPerformClientRedirect( + WebKit::WebFrame*, const WebKit::WebURL& from, const WebKit::WebURL& to, + double interval, double fire_time); + virtual void didCancelClientRedirect(WebKit::WebFrame*); + virtual void didCompleteClientRedirect( + WebKit::WebFrame*, const WebKit::WebURL& from); + virtual void didCreateDataSource( + WebKit::WebFrame*, WebKit::WebDataSource*); + virtual void didStartProvisionalLoad(WebKit::WebFrame*); + virtual void didReceiveServerRedirectForProvisionalLoad(WebKit::WebFrame*); + virtual void didFailProvisionalLoad( + WebKit::WebFrame*, const WebKit::WebURLError&); + virtual void didReceiveDocumentData( + WebKit::WebFrame*, const char* data, size_t length, + bool& preventDefault); + virtual void didCommitProvisionalLoad( + WebKit::WebFrame*, bool is_new_navigation); + virtual void didClearWindowObject(WebKit::WebFrame*); + virtual void didCreateDocumentElement(WebKit::WebFrame*); + virtual void didReceiveTitle( + WebKit::WebFrame*, const WebKit::WebString& title); + virtual void didFinishDocumentLoad(WebKit::WebFrame*); + virtual void didHandleOnloadEvents(WebKit::WebFrame*); + virtual void didFailLoad( + WebKit::WebFrame*, const WebKit::WebURLError&); + virtual void didFinishLoad(WebKit::WebFrame*); + virtual void didChangeLocationWithinPage( + WebKit::WebFrame*, bool isNewNavigation); + virtual void assignIdentifierToRequest( + WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&); + virtual void willSendRequest( + WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, + const WebKit::WebURLResponse& redirectResponse); + virtual void didReceiveResponse( + WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&); + virtual void didFinishResourceLoad( + WebKit::WebFrame*, unsigned identifier); + virtual void didFailResourceLoad( + WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLError&); + virtual void didLoadResourceFromMemoryCache( + WebKit::WebFrame*, const WebKit::WebURLRequest&, + const WebKit::WebURLResponse&); + virtual void didExhaustMemoryAvailableForScript(WebKit::WebFrame*); + virtual void didChangeContentsSize( + WebKit::WebFrame*, const WebKit::WebSize&); + // webkit_glue::WebPluginPageDelegate virtual webkit_glue::WebPluginDelegate* CreatePluginDelegate( const GURL& url, diff --git a/webkit/tools/test_shell/webview_host_gtk.cc b/webkit/tools/test_shell/webview_host_gtk.cc index ededb21..65335d0 100644 --- a/webkit/tools/test_shell/webview_host_gtk.cc +++ b/webkit/tools/test_shell/webview_host_gtk.cc @@ -26,7 +26,7 @@ WebViewHost* WebViewHost::Create(GtkWidget* parent_view, host->webwidget_ = WebView::Create(delegate, delegate); prefs.Apply(host->webview()); - host->webview()->InitializeMainFrame(); + host->webview()->InitializeMainFrame(delegate); host->webwidget_->layout(); return host; diff --git a/webkit/tools/test_shell/webview_host_win.cc b/webkit/tools/test_shell/webview_host_win.cc index 216e54d..68af5f9 100644 --- a/webkit/tools/test_shell/webview_host_win.cc +++ b/webkit/tools/test_shell/webview_host_win.cc @@ -41,7 +41,7 @@ WebViewHost* WebViewHost::Create(HWND parent_view, host->webwidget_ = WebView::Create(delegate, delegate); prefs.Apply(host->webview()); - host->webview()->InitializeMainFrame(); + host->webview()->InitializeMainFrame(delegate); return host; } diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 7d363da..66c3722 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1008,6 +1008,7 @@ 'api/public/WebEditingClient.h', 'api/public/WebFindOptions.h', 'api/public/WebFrame.h', + 'api/public/WebFrameClient.h', 'api/public/WebForm.h', 'api/public/WebHistoryItem.h', 'api/public/WebHTTPBody.h', |