| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/shell_content_renderer_client.h" | 5 #include "content/shell/shell_content_renderer_client.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "content/public/common/content_constants.h" | 9 #include "content/public/common/content_constants.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 #include "content/public/test/layouttest_support.h" | 11 #include "content/public/test/layouttest_support.h" |
| 12 #include "content/shell/shell_render_process_observer.h" | 12 #include "content/shell/shell_render_process_observer.h" |
| 13 #include "content/shell/shell_switches.h" | 13 #include "content/shell/shell_switches.h" |
| 14 #include "content/shell/webkit_test_runner.h" | 14 #include "content/shell/webkit_test_runner.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
| 17 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestProxy.h" | 17 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestProxy.h" |
| 18 #include "v8/include/v8.h" | 18 #include "v8/include/v8.h" |
| 19 | 19 |
| 20 using WebTestRunner::WebTestProxyBase; | 20 using WebTestRunner::WebTestProxyBase; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 ShellContentRendererClient::ShellContentRendererClient() | 24 ShellContentRendererClient::ShellContentRendererClient() { |
| 25 : latest_test_runner_(NULL) { | |
| 26 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 25 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { |
| 27 EnableWebTestProxyCreation( | 26 EnableWebTestProxyCreation( |
| 28 base::Bind(&ShellContentRendererClient::WebTestProxyCreated, | 27 base::Bind(&ShellContentRendererClient::WebTestProxyCreated, |
| 29 base::Unretained(this))); | 28 base::Unretained(this))); |
| 30 } | 29 } |
| 31 } | 30 } |
| 32 | 31 |
| 33 ShellContentRendererClient::~ShellContentRendererClient() { | 32 ShellContentRendererClient::~ShellContentRendererClient() { |
| 34 } | 33 } |
| 35 | 34 |
| 36 void ShellContentRendererClient::RenderThreadStarted() { | 35 void ShellContentRendererClient::RenderThreadStarted() { |
| 37 shell_observer_.reset(new ShellRenderProcessObserver()); | 36 shell_observer_.reset(new ShellRenderProcessObserver()); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) { | |
| 41 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | |
| 42 return; | |
| 43 | |
| 44 CHECK(!latest_test_runner_); | |
| 45 latest_test_runner_ = new WebKitTestRunner(render_view); | |
| 46 } | |
| 47 | |
| 48 bool ShellContentRendererClient::OverrideCreatePlugin( | 39 bool ShellContentRendererClient::OverrideCreatePlugin( |
| 49 RenderView* render_view, | 40 RenderView* render_view, |
| 50 WebKit::WebFrame* frame, | 41 WebKit::WebFrame* frame, |
| 51 const WebKit::WebPluginParams& params, | 42 const WebKit::WebPluginParams& params, |
| 52 WebKit::WebPlugin** plugin) { | 43 WebKit::WebPlugin** plugin) { |
| 53 std::string mime_type = params.mimeType.utf8(); | 44 std::string mime_type = params.mimeType.utf8(); |
| 54 if (mime_type == content::kBrowserPluginMimeType) { | 45 if (mime_type == content::kBrowserPluginMimeType) { |
| 55 // Allow browser plugin in content_shell only if it is forced by flag. | 46 // Allow browser plugin in content_shell only if it is forced by flag. |
| 56 // Returning true here disables the plugin. | 47 // Returning true here disables the plugin. |
| 57 return !CommandLine::ForCurrentProcess()->HasSwitch( | 48 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 58 switches::kEnableBrowserPluginForAllViewTypes); | 49 switches::kEnableBrowserPluginForAllViewTypes); |
| 59 } | 50 } |
| 60 return false; | 51 return false; |
| 61 } | 52 } |
| 62 | 53 |
| 63 void ShellContentRendererClient::WebTestProxyCreated(WebTestProxyBase* proxy) { | 54 void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view, |
| 64 CHECK(latest_test_runner_); | 55 WebTestProxyBase* proxy) { |
| 65 proxy->setDelegate(latest_test_runner_); | 56 WebKitTestRunner* test_runner = new WebKitTestRunner(render_view); |
| 66 latest_test_runner_->set_proxy(proxy); | 57 if (!ShellRenderProcessObserver::GetInstance()->test_delegate()) { |
| 67 latest_test_runner_ = NULL; | 58 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view, |
| 59 test_runner); |
| 60 } |
| 61 test_runner->set_proxy(proxy); |
| 62 proxy->setDelegate( |
| 63 ShellRenderProcessObserver::GetInstance()->test_delegate()); |
| 68 proxy->setInterfaces( | 64 proxy->setInterfaces( |
| 69 ShellRenderProcessObserver::GetInstance()->test_interfaces()); | 65 ShellRenderProcessObserver::GetInstance()->test_interfaces()); |
| 70 } | 66 } |
| 71 | 67 |
| 72 } // namespace content | 68 } // namespace content |
| OLD | NEW |