diff options
-rw-r--r-- | content/content_shell.gypi | 8 | ||||
-rw-r--r-- | content/shell/layout_test_controller.cc (renamed from content/shell/shell_render_view_observer.cc) | 19 | ||||
-rw-r--r-- | content/shell/layout_test_controller.h (renamed from content/shell/shell_render_view_observer.h) | 17 | ||||
-rw-r--r-- | content/shell/layout_test_controller.js | 3 | ||||
-rw-r--r-- | content/shell/layout_test_controller_bindings.cc | 14 | ||||
-rw-r--r-- | content/shell/layout_test_controller_host.cc (renamed from content/shell/shell_render_view_host_observer.cc) | 52 | ||||
-rw-r--r-- | content/shell/layout_test_controller_host.h | 59 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 6 | ||||
-rw-r--r-- | content/shell/shell_content_renderer_client.cc | 9 | ||||
-rw-r--r-- | content/shell/shell_javascript_dialog_creator.cc | 9 | ||||
-rw-r--r-- | content/shell/shell_messages.h | 3 | ||||
-rw-r--r-- | content/shell/shell_render_view_host_observer.h | 47 |
12 files changed, 158 insertions, 88 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 588723e..c8fc373 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -46,8 +46,12 @@ '..', ], 'sources': [ + 'shell/layout_test_controller.cc', + 'shell/layout_test_controller.h', 'shell/layout_test_controller_bindings.cc', 'shell/layout_test_controller_bindings.h', + 'shell/layout_test_controller_host.cc', + 'shell/layout_test_controller_host.h', 'shell/paths_mac.h', 'shell/paths_mac.mm', 'shell/shell.cc', @@ -92,10 +96,6 @@ 'shell/shell_network_delegate.h', 'shell/shell_render_process_observer.cc', 'shell/shell_render_process_observer.h', - 'shell/shell_render_view_host_observer.cc', - 'shell/shell_render_view_host_observer.h', - 'shell/shell_render_view_observer.cc', - 'shell/shell_render_view_observer.h', 'shell/shell_resource_context.cc', 'shell/shell_resource_context.h', 'shell/shell_resource_dispatcher_host_delegate.cc', diff --git a/content/shell/shell_render_view_observer.cc b/content/shell/layout_test_controller.cc index 0179ea2..faef0cd 100644 --- a/content/shell/shell_render_view_observer.cc +++ b/content/shell/layout_test_controller.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/shell/shell_render_view_observer.h" +#include "content/shell/layout_test_controller.h" #include "base/stringprintf.h" #include "content/public/renderer/render_view.h" @@ -85,21 +85,22 @@ std::string DumpFrameScrollPosition(WebFrame* frame, bool recursive) { } } // namespace -ShellRenderViewObserver::ShellRenderViewObserver(RenderView* render_view) + +LayoutTestController::LayoutTestController(RenderView* render_view) : RenderViewObserver(render_view) { } -ShellRenderViewObserver::~ShellRenderViewObserver() { +LayoutTestController::~LayoutTestController() { } -void ShellRenderViewObserver::DidFinishLoad(WebFrame* frame) { +void LayoutTestController::DidFinishLoad(WebFrame* frame) { if (!frame->parent()) Send(new ShellViewHostMsg_DidFinishLoad(routing_id())); } -bool ShellRenderViewObserver::OnMessageReceived(const IPC::Message& message) { +bool LayoutTestController::OnMessageReceived(const IPC::Message& message) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP(ShellRenderViewObserver, message) + IPC_BEGIN_MESSAGE_MAP(LayoutTestController, message) IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureTextDump, OnCaptureTextDump) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -107,9 +108,9 @@ bool ShellRenderViewObserver::OnMessageReceived(const IPC::Message& message) { return handled; } -void ShellRenderViewObserver::OnCaptureTextDump(bool as_text, - bool printing, - bool recursive) { +void LayoutTestController::OnCaptureTextDump(bool as_text, + bool printing, + bool recursive) { WebFrame* frame = render_view()->GetWebView()->mainFrame(); std::string dump; if (as_text) { diff --git a/content/shell/shell_render_view_observer.h b/content/shell/layout_test_controller.h index 5ea7d60..b8e06b5 100644 --- a/content/shell/shell_render_view_observer.h +++ b/content/shell/layout_test_controller.h @@ -2,20 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_SHELL_SHELL_RENDER_VIEW_OBSERVER_H_ -#define CONTENT_SHELL_SHELL_RENDER_VIEW_OBSERVER_H_ +#ifndef CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_H_ +#define CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_H_ #pragma once #include "content/public/renderer/render_view_observer.h" namespace content { -// This class holds the content_shell specific parts of RenderView, and has the -// same lifetime. -class ShellRenderViewObserver : public RenderViewObserver { +// This is the renderer side of the layout test controller. +class LayoutTestController : public RenderViewObserver { public: - explicit ShellRenderViewObserver(RenderView* render_view); - virtual ~ShellRenderViewObserver(); + explicit LayoutTestController(RenderView* render_view); + virtual ~LayoutTestController(); // RenderViewObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; @@ -25,9 +24,9 @@ class ShellRenderViewObserver : public RenderViewObserver { // Message handlers. void OnCaptureTextDump(bool as_text, bool printing, bool recursive); - DISALLOW_COPY_AND_ASSIGN(ShellRenderViewObserver); + DISALLOW_COPY_AND_ASSIGN(LayoutTestController); }; } // namespace content -#endif // CONTENT_SHELL_SHELL_RENDER_VIEW_OBSERVER_H_ +#endif // CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_H_ diff --git a/content/shell/layout_test_controller.js b/content/shell/layout_test_controller.js index 14d0332..5cab912 100644 --- a/content/shell/layout_test_controller.js +++ b/content/shell/layout_test_controller.js @@ -9,6 +9,7 @@ var layoutTestController = layoutTestController || {}; native function SetDumpAsText(); native function SetDumpChildFramesAsText(); native function SetPrinting(); + native function SetShouldStayOnPageAfterHandlingBeforeUnload(); native function SetWaitUntilDone(); layoutTestController = new function() { @@ -16,6 +17,8 @@ var layoutTestController = layoutTestController || {}; this.dumpAsText = SetDumpAsText; this.dumpChildFramesAsText = SetDumpChildFramesAsText; this.setPrinting = SetPrinting; + this.setShouldStayOnPageAfterHandlingBeforeUnload = + SetShouldStayOnPageAfterHandlingBeforeUnload; this.waitUntilDone = SetWaitUntilDone; }(); })(); diff --git a/content/shell/layout_test_controller_bindings.cc b/content/shell/layout_test_controller_bindings.cc index 0d5d4ed..59fecec 100644 --- a/content/shell/layout_test_controller_bindings.cc +++ b/content/shell/layout_test_controller_bindings.cc @@ -76,6 +76,20 @@ v8::Handle<v8::Value> SetPrinting(const v8::Arguments& args) { return v8::Undefined(); } +v8::Handle<v8::Value> SetShouldStayOnPageAfterHandlingBeforeUnload( + const v8::Arguments& args) { + RenderView* view = GetCurrentRenderView(); + if (!view) + return v8::Undefined(); + + if (args.Length() != 1 || args[0]->IsBoolean()) + return v8::Undefined(); + + view->Send(new ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload( + view->GetRoutingID(), args[0]->BooleanValue())); + return v8::Undefined(); +} + v8::Handle<v8::Value> SetWaitUntilDone(const v8::Arguments& args) { RenderView* view = GetCurrentRenderView(); if (!view) diff --git a/content/shell/shell_render_view_host_observer.cc b/content/shell/layout_test_controller_host.cc index b191126..94b534c 100644 --- a/content/shell/shell_render_view_host_observer.cc +++ b/content/shell/layout_test_controller_host.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/shell/shell_render_view_host_observer.h" +#include "content/shell/layout_test_controller_host.h" #include <iostream> @@ -12,19 +12,35 @@ namespace content { -ShellRenderViewHostObserver::ShellRenderViewHostObserver( +std::map<RenderViewHost*, LayoutTestControllerHost*> + LayoutTestControllerHost::controllers_; + +// static +LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost( + RenderViewHost* render_view_host) { + const std::map<RenderViewHost*, LayoutTestControllerHost*>::iterator it = + controllers_.find(render_view_host); + if (it == controllers_.end()) + return NULL; + return it->second; +} + +LayoutTestControllerHost::LayoutTestControllerHost( RenderViewHost* render_view_host) : RenderViewHostObserver(render_view_host), dump_as_text_(false), - is_printing_(false), dump_child_frames_(false), + is_printing_(false), + should_stay_on_page_after_handling_before_unload_(false), wait_until_done_(false) { + controllers_[render_view_host] = this; } -ShellRenderViewHostObserver::~ShellRenderViewHostObserver() { +LayoutTestControllerHost::~LayoutTestControllerHost() { + controllers_.erase(render_view_host()); } -void ShellRenderViewHostObserver::CaptureDump() { +void LayoutTestControllerHost::CaptureDump() { render_view_host()->Send( new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(), dump_as_text_, @@ -32,10 +48,10 @@ void ShellRenderViewHostObserver::CaptureDump() { dump_child_frames_)); } -bool ShellRenderViewHostObserver::OnMessageReceived( +bool LayoutTestControllerHost::OnMessageReceived( const IPC::Message& message) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP(ShellRenderViewHostObserver, message) + IPC_BEGIN_MESSAGE_MAP(LayoutTestControllerHost, message) IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad) IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone) @@ -43,6 +59,9 @@ bool ShellRenderViewHostObserver::OnMessageReceived( IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText, OnDumpChildFramesAsText) IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPrinting, OnSetPrinting) + IPC_MESSAGE_HANDLER( + ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload, + OnSetShouldStayOnPageAfterHandlingBeforeUnload) IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -50,14 +69,14 @@ bool ShellRenderViewHostObserver::OnMessageReceived( return handled; } -void ShellRenderViewHostObserver::OnDidFinishLoad() { +void LayoutTestControllerHost::OnDidFinishLoad() { if (wait_until_done_) return; CaptureDump(); } -void ShellRenderViewHostObserver::OnTextDump(const std::string& dump) { +void LayoutTestControllerHost::OnTextDump(const std::string& dump) { std::cout << dump; std::cout << "#EOF\n"; std::cerr << "#EOF\n"; @@ -65,23 +84,28 @@ void ShellRenderViewHostObserver::OnTextDump(const std::string& dump) { MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); } -void ShellRenderViewHostObserver::OnNotifyDone() { +void LayoutTestControllerHost::OnNotifyDone() { CaptureDump(); } -void ShellRenderViewHostObserver::OnDumpAsText() { +void LayoutTestControllerHost::OnDumpAsText() { dump_as_text_ = true; } -void ShellRenderViewHostObserver::OnSetPrinting() { +void LayoutTestControllerHost::OnSetPrinting() { is_printing_ = true; } -void ShellRenderViewHostObserver::OnDumpChildFramesAsText() { +void LayoutTestControllerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload( + bool should_stay_on_page) { + should_stay_on_page_after_handling_before_unload_ = should_stay_on_page; +} + +void LayoutTestControllerHost::OnDumpChildFramesAsText() { dump_child_frames_ = true; } -void ShellRenderViewHostObserver::OnWaitUntilDone() { +void LayoutTestControllerHost::OnWaitUntilDone() { wait_until_done_ = true; } diff --git a/content/shell/layout_test_controller_host.h b/content/shell/layout_test_controller_host.h new file mode 100644 index 0000000..733dfc9 --- /dev/null +++ b/content/shell/layout_test_controller_host.h @@ -0,0 +1,59 @@ +// Copyright (c) 2012 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 CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_HOST_H_ +#define CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_HOST_H_ +#pragma once + +#include <map> +#include <string> + +#include "content/public/browser/render_view_host_observer.h" + +namespace content { + +class LayoutTestControllerHost : public RenderViewHostObserver { + public: + static LayoutTestControllerHost* FromRenderViewHost( + RenderViewHost* render_view_host); + + explicit LayoutTestControllerHost(RenderViewHost* render_view_host); + virtual ~LayoutTestControllerHost(); + + bool should_stay_on_page_after_handling_before_unload() const { + return should_stay_on_page_after_handling_before_unload_; + } + + // RenderViewHostObserver implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + private: + void CaptureDump(); + + // Message handlers. + void OnDidFinishLoad(); + void OnTextDump(const std::string& dump); + + // layoutTestController handlers. + void OnNotifyDone(); + void OnDumpAsText(); + void OnDumpChildFramesAsText(); + void OnSetPrinting(); + void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page); + void OnWaitUntilDone(); + + static std::map<RenderViewHost*, LayoutTestControllerHost*> controllers_; + + bool dump_as_text_; + bool dump_child_frames_; + bool is_printing_; + bool should_stay_on_page_after_handling_before_unload_; + bool wait_until_done_; + + DISALLOW_COPY_AND_ASSIGN(LayoutTestControllerHost); +}; + +} // namespace content + +#endif // CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_HOST_H_ diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index dca4df0..d00b033 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -7,10 +7,10 @@ #include "base/command_line.h" #include "base/file_path.h" #include "content/public/browser/resource_dispatcher_host.h" +#include "content/shell/layout_test_controller_host.h" #include "content/shell/shell.h" #include "content/shell/shell_browser_main_parts.h" #include "content/shell/shell_devtools_delegate.h" -#include "content/shell/shell_render_view_host_observer.h" #include "content/shell/shell_resource_dispatcher_host_delegate.h" #include "content/shell/shell_switches.h" #include "googleurl/src/gurl.h" @@ -32,7 +32,9 @@ BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( void ShellContentBrowserClient::RenderViewHostCreated( RenderViewHost* render_view_host) { - new ShellRenderViewHostObserver(render_view_host); + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + return; + new LayoutTestControllerHost(render_view_host); } void ShellContentBrowserClient::AppendExtraCommandLineSwitches( diff --git a/content/shell/shell_content_renderer_client.cc b/content/shell/shell_content_renderer_client.cc index 0619e67c..a120158 100644 --- a/content/shell/shell_content_renderer_client.cc +++ b/content/shell/shell_content_renderer_client.cc @@ -4,8 +4,10 @@ #include "content/shell/shell_content_renderer_client.h" +#include "base/command_line.h" +#include "content/shell/layout_test_controller.h" #include "content/shell/shell_render_process_observer.h" -#include "content/shell/shell_render_view_observer.h" +#include "content/shell/shell_switches.h" #include "v8/include/v8.h" namespace content { @@ -21,7 +23,10 @@ void ShellContentRendererClient::RenderThreadStarted() { } void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) { - new content::ShellRenderViewObserver(render_view); + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + return; + + new content::LayoutTestController(render_view); } } // namespace content diff --git a/content/shell/shell_javascript_dialog_creator.cc b/content/shell/shell_javascript_dialog_creator.cc index 9441b49..37518acf 100644 --- a/content/shell/shell_javascript_dialog_creator.cc +++ b/content/shell/shell_javascript_dialog_creator.cc @@ -9,6 +9,8 @@ #include "base/command_line.h" #include "base/logging.h" #include "base/utf_string_conversions.h" +#include "content/public/browser/web_contents.h" +#include "content/shell/layout_test_controller_host.h" #include "content/shell/shell_javascript_dialog.h" #include "content/shell/shell_switches.h" #include "net/base/net_util.h" @@ -76,7 +78,12 @@ void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog( const DialogClosedCallback& callback) { if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { std::cout << "CONFIRM NAVIGATION: " << UTF16ToUTF8(message_text) << "\n"; - callback.Run(true, string16()); + LayoutTestControllerHost* controller = + LayoutTestControllerHost::FromRenderViewHost( + web_contents->GetRenderViewHost()); + callback.Run( + !controller->should_stay_on_page_after_handling_before_unload(), + string16()); return; } diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h index eccc863..50ce122 100644 --- a/content/shell/shell_messages.h +++ b/content/shell/shell_messages.h @@ -28,4 +28,7 @@ IPC_MESSAGE_ROUTED0(ShellViewHostMsg_NotifyDone) IPC_MESSAGE_ROUTED0(ShellViewHostMsg_DumpAsText) IPC_MESSAGE_ROUTED0(ShellViewHostMsg_DumpChildFramesAsText) IPC_MESSAGE_ROUTED0(ShellViewHostMsg_SetPrinting) +IPC_MESSAGE_ROUTED1( + ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload, + bool /* should_stay_on_page */) IPC_MESSAGE_ROUTED0(ShellViewHostMsg_WaitUntilDone) diff --git a/content/shell/shell_render_view_host_observer.h b/content/shell/shell_render_view_host_observer.h deleted file mode 100644 index 165c802..0000000 --- a/content/shell/shell_render_view_host_observer.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2012 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 CONTENT_SHELL_SHELL_RENDER_VIEW_HOST_OBSERVER_H_ -#define CONTENT_SHELL_SHELL_RENDER_VIEW_HOST_OBSERVER_H_ -#pragma once - -#include <string> - -#include "content/public/browser/render_view_host_observer.h" - -namespace content { - -class ShellRenderViewHostObserver : public RenderViewHostObserver { - public: - explicit ShellRenderViewHostObserver(RenderViewHost* render_view_host); - virtual ~ShellRenderViewHostObserver(); - - // RenderViewHostObserver implementation. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - - private: - void CaptureDump(); - - // Message handlers. - void OnDidFinishLoad(); - void OnTextDump(const std::string& dump); - - // layoutTestController handlers. - void OnNotifyDone(); - void OnDumpAsText(); - void OnDumpChildFramesAsText(); - void OnSetPrinting(); - void OnWaitUntilDone(); - - bool dump_as_text_; - bool is_printing_; - bool dump_child_frames_; - bool wait_until_done_; - - DISALLOW_COPY_AND_ASSIGN(ShellRenderViewHostObserver); -}; - -} // namespace content - -#endif // CONTENT_SHELL_SHELL_RENDER_VIEW_HOST_OBSERVER_H_ |