diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 17:40:27 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 17:40:27 +0000 |
commit | d99d65af7628ac4709d571774b6ed545e996fb32 (patch) | |
tree | 69393f8b806690935fc2d09edddc8fe8fc947b7b /content | |
parent | edcfc5cdb6bbba2636ca390db1e817d147c9781c (diff) | |
download | chromium_src-d99d65af7628ac4709d571774b6ed545e996fb32.zip chromium_src-d99d65af7628ac4709d571774b6ed545e996fb32.tar.gz chromium_src-d99d65af7628ac4709d571774b6ed545e996fb32.tar.bz2 |
Reland 170451 - [content shell] add support for testRunner.canOpenWindows and disallow openi
BUG=111316
R=marja@chromium.org
Original Review URL: https://codereview.chromium.org/11411282
Review URL: https://chromiumcodereview.appspot.com/11488005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 13 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.h | 7 | ||||
-rw-r--r-- | content/shell/shell_messages.h | 1 | ||||
-rw-r--r-- | content/shell/webkit_test_controller.cc | 24 | ||||
-rw-r--r-- | content/shell/webkit_test_controller.h | 9 | ||||
-rw-r--r-- | content/shell/webkit_test_runner.cc | 4 | ||||
-rw-r--r-- | content/shell/webkit_test_runner.h | 1 | ||||
-rw-r--r-- | content/shell/webkit_test_runner.js | 4 | ||||
-rw-r--r-- | content/shell/webkit_test_runner_bindings.cc | 12 |
9 files changed, 74 insertions, 1 deletions
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index ee4fd62..6858810 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -114,6 +114,19 @@ WebContentsViewDelegate* ShellContentBrowserClient::GetWebContentsViewDelegate( return NULL; } +bool ShellContentBrowserClient::CanCreateWindow( + const GURL& opener_url, + const GURL& origin, + WindowContainerType container_type, + ResourceContext* context, + int render_process_id, + bool* no_javascript_access) { + *no_javascript_access = false; + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + return true; + return WebKitTestController::Get()->CanOpenWindows(); +} + #if defined(OS_ANDROID) void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( const CommandLine& command_line, diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index f5652a9..a130d89 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -37,6 +37,13 @@ class ShellContentBrowserClient : public ContentBrowserClient { virtual std::string GetDefaultDownloadName() OVERRIDE; virtual WebContentsViewDelegate* GetWebContentsViewDelegate( WebContents* web_contents) OVERRIDE; + virtual bool CanCreateWindow( + const GURL& opener_url, + const GURL& source_origin, + WindowContainerType container_type, + ResourceContext* context, + int render_process_id, + bool* no_javascript_access) OVERRIDE; #if defined(OS_ANDROID) virtual void GetAdditionalMappedFilesForChildProcess( diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h index d9df4bc..49d2738 100644 --- a/content/shell/shell_messages.h +++ b/content/shell/shell_messages.h @@ -69,6 +69,7 @@ IPC_MESSAGE_ROUTED1( IPC_MESSAGE_ROUTED0(ShellViewHostMsg_WaitUntilDone) IPC_MESSAGE_ROUTED1(ShellViewHostMsg_OverridePreferences, content::ShellWebPreferences /* preferences */) +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_CanOpenWindows) IPC_MESSAGE_ROUTED2(ShellViewHostMsg_NotImplemented, std::string /* object_name */, diff --git a/content/shell/webkit_test_controller.cc b/content/shell/webkit_test_controller.cc index 893ee31..caeee9d 100644 --- a/content/shell/webkit_test_controller.cc +++ b/content/shell/webkit_test_controller.cc @@ -120,7 +120,7 @@ WebKitTestController* WebKitTestController::instance_ = NULL; // static WebKitTestController* WebKitTestController::Get() { - DCHECK(!instance_ || instance_->CalledOnValidThread()); + DCHECK(instance_); return instance_; } @@ -181,6 +181,10 @@ bool WebKitTestController::ResetAfterLayoutTest() { should_stay_on_page_after_handling_before_unload_ = false; wait_until_done_ = false; prefs_ = ShellWebPreferences(); + { + base::AutoLock lock(lock_); + can_open_windows_ = false; + } watchdog_.Cancel(); if (main_window_) { Observe(NULL); @@ -192,11 +196,18 @@ bool WebKitTestController::ResetAfterLayoutTest() { } void WebKitTestController::RendererUnresponsive() { + DCHECK(CalledOnValidThread()); if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTimeout)) printer_->AddErrorMessage("#PROCESS UNRESPONSIVE - renderer"); } +bool WebKitTestController::CanOpenWindows() const { + base::AutoLock lock(lock_); + return can_open_windows_; +} + bool WebKitTestController::OnMessageReceived(const IPC::Message& message) { + DCHECK(CalledOnValidThread()); bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebKitTestController, message) IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad) @@ -214,6 +225,7 @@ bool WebKitTestController::OnMessageReceived(const IPC::Message& message) { ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload, OnSetShouldStayOnPageAfterHandlingBeforeUnload) IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_CanOpenWindows, OnCanOpenWindows) IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotImplemented, OnNotImplemented) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -222,15 +234,18 @@ bool WebKitTestController::OnMessageReceived(const IPC::Message& message) { } void WebKitTestController::PluginCrashed(const FilePath& plugin_path) { + DCHECK(CalledOnValidThread()); printer_->AddErrorMessage("#CRASHED - plugin"); } void WebKitTestController::RenderViewCreated(RenderViewHost* render_view_host) { + DCHECK(CalledOnValidThread()); render_view_host->Send(new ShellViewMsg_SetCurrentWorkingDirectory( render_view_host->GetRoutingID(), current_working_directory_)); } void WebKitTestController::RenderViewGone(base::TerminationStatus status) { + DCHECK(CalledOnValidThread()); if (status == base::TERMINATION_STATUS_PROCESS_CRASHED || status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { printer_->AddErrorMessage("#CRASHED - renderer"); @@ -238,6 +253,7 @@ void WebKitTestController::RenderViewGone(base::TerminationStatus status) { } void WebKitTestController::WebContentsDestroyed(WebContents* web_contents) { + DCHECK(CalledOnValidThread()); main_window_ = NULL; printer_->AddErrorMessage("FAIL: main window was destroyed"); } @@ -263,6 +279,7 @@ void WebKitTestController::CaptureDump() { } void WebKitTestController::TimeoutHandler() { + DCHECK(CalledOnValidThread()); printer_->AddErrorMessage( "FAIL: Timed out waiting for notifyDone to be called"); } @@ -375,6 +392,11 @@ void WebKitTestController::OnWaitUntilDone() { wait_until_done_ = true; } +void WebKitTestController::OnCanOpenWindows() { + base::AutoLock lock(lock_); + can_open_windows_ = true; +} + void WebKitTestController::OnNotImplemented( const std::string& object_name, const std::string& property_name) { diff --git a/content/shell/webkit_test_controller.h b/content/shell/webkit_test_controller.h index 03de47b..bd8fb11 100644 --- a/content/shell/webkit_test_controller.h +++ b/content/shell/webkit_test_controller.h @@ -10,6 +10,7 @@ #include "base/cancelable_callback.h" #include "base/file_path.h" +#include "base/synchronization/lock.h" #include "base/threading/non_thread_safe.h" #include "content/public/browser/render_view_host_observer.h" #include "content/public/browser/web_contents_observer.h" @@ -90,6 +91,9 @@ class WebKitTestController : public base::NonThreadSafe, return should_stay_on_page_after_handling_before_unload_; } + // This method can be invoked on any thread. + bool CanOpenWindows() const; + // WebContentsObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE; @@ -115,6 +119,7 @@ class WebKitTestController : public base::NonThreadSafe, void OnSetPrinting(); void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page); void OnWaitUntilDone(); + void OnCanOpenWindows(); void OnNotImplemented(const std::string& object_name, const std::string& method_name); @@ -139,6 +144,10 @@ class WebKitTestController : public base::NonThreadSafe, base::CancelableClosure watchdog_; + // Access to the following variables needs to be guarded by |lock_|. + mutable base::Lock lock_; + bool can_open_windows_; + DISALLOW_COPY_AND_ASSIGN(WebKitTestController); }; diff --git a/content/shell/webkit_test_runner.cc b/content/shell/webkit_test_runner.cc index c4e2f7d..e484d8d 100644 --- a/content/shell/webkit_test_runner.cc +++ b/content/shell/webkit_test_runner.cc @@ -306,6 +306,10 @@ void WebKitTestRunner::WaitUntilDone() { Send(new ShellViewHostMsg_WaitUntilDone(routing_id())); } +void WebKitTestRunner::CanOpenWindows() { + Send(new ShellViewHostMsg_CanOpenWindows(routing_id())); +} + void WebKitTestRunner::NotImplemented(const char* object, const char* method) { Send(new ShellViewHostMsg_NotImplemented(routing_id(), object, method)); } diff --git a/content/shell/webkit_test_runner.h b/content/shell/webkit_test_runner.h index a8d90c0..3eaff03 100644 --- a/content/shell/webkit_test_runner.h +++ b/content/shell/webkit_test_runner.h @@ -67,6 +67,7 @@ class WebKitTestRunner : public RenderViewObserver, void SetPrinting(); void SetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page); void WaitUntilDone(); + void CanOpenWindows(); void NotImplemented(const char* object, const char* method); void set_proxy(WebTestRunner::WebTestProxyBase* proxy) { proxy_ = proxy; } diff --git a/content/shell/webkit_test_runner.js b/content/shell/webkit_test_runner.js index 1cfe81d..7665a90 100644 --- a/content/shell/webkit_test_runner.js +++ b/content/shell/webkit_test_runner.js @@ -8,6 +8,7 @@ var testRunner = testRunner || {}; native function Display(); native function GetWorkerThreadCount(); native function NotifyDone(); + native function SetCanOpenWindows(); native function SetDumpAsText(); native function SetDumpChildFramesAsText(); native function SetPrinting(); @@ -41,6 +42,9 @@ var testRunner = testRunner || {}; Object.defineProperty(this, "dumpChildFramesAsText", {value: SetDumpChildFramesAsText}); + Object.defineProperty(this, + "setCanOpenWindows", + {value: SetCanOpenWindows}); Object.defineProperty(this, "setPrinting", {value: SetPrinting}); Object.defineProperty( this, diff --git a/content/shell/webkit_test_runner_bindings.cc b/content/shell/webkit_test_runner_bindings.cc index 82de19a..7f524a1 100644 --- a/content/shell/webkit_test_runner_bindings.cc +++ b/content/shell/webkit_test_runner_bindings.cc @@ -44,6 +44,16 @@ v8::Handle<v8::Value> NotifyDone(const v8::Arguments& args) { return v8::Undefined(); } +v8::Handle<v8::Value> SetCanOpenWindows(const v8::Arguments& args) { + WebKitTestRunner* runner = + ShellRenderProcessObserver::GetInstance()->main_test_runner(); + if (!runner) + return v8::Undefined(); + + runner->CanOpenWindows(); + return v8::Undefined(); +} + v8::Handle<v8::Value> SetDumpAsText(const v8::Arguments& args) { WebKitTestRunner* runner = ShellRenderProcessObserver::GetInstance()->main_test_runner(); @@ -151,6 +161,8 @@ WebKitTestRunnerBindings::GetNativeFunction(v8::Handle<v8::String> name) { return v8::FunctionTemplate::New(Display); if (name->Equals(v8::String::New("NotifyDone"))) return v8::FunctionTemplate::New(NotifyDone); + if (name->Equals(v8::String::New("SetCanOpenWindows"))) + return v8::FunctionTemplate::New(SetCanOpenWindows); if (name->Equals(v8::String::New("SetDumpAsText"))) return v8::FunctionTemplate::New(SetDumpAsText); if (name->Equals(v8::String::New("SetDumpChildFramesAsText"))) |