diff options
Diffstat (limited to 'webkit/tools/test_shell')
19 files changed, 500 insertions, 566 deletions
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; } |