Update ASan/Android runtime and setup script to LLVM r200682.
[chromium-blink-merge.git] / content / shell / renderer / shell_content_renderer_client.cc
blobe7046ba7547c05fe1fb27c20e068eaab767c390c
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
3 // found in the LICENSE file.
5 #include "content/shell/renderer/shell_content_renderer_client.h"
7 #include "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/debug/debugger.h"
10 #include "content/public/common/content_constants.h"
11 #include "content/public/common/content_switches.h"
12 #include "content/public/renderer/render_view.h"
13 #include "content/public/test/layouttest_support.h"
14 #include "content/shell/common/shell_switches.h"
15 #include "content/shell/renderer/shell_render_frame_observer.h"
16 #include "content/shell/renderer/shell_render_process_observer.h"
17 #include "content/shell/renderer/shell_render_view_observer.h"
18 #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
19 #include "content/shell/renderer/test_runner/WebTestProxy.h"
20 #include "content/shell/renderer/test_runner/WebTestRunner.h"
21 #include "content/shell/renderer/webkit_test_runner.h"
22 #include "content/test/mock_webclipboard_impl.h"
23 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
24 #include "third_party/WebKit/public/web/WebPluginParams.h"
25 #include "third_party/WebKit/public/web/WebView.h"
26 #include "v8/include/v8.h"
28 using blink::WebAudioDevice;
29 using blink::WebClipboard;
30 using blink::WebFrame;
31 using blink::WebMIDIAccessor;
32 using blink::WebMIDIAccessorClient;
33 using blink::WebMediaStreamCenter;
34 using blink::WebMediaStreamCenterClient;
35 using blink::WebPlugin;
36 using blink::WebPluginParams;
37 using blink::WebRTCPeerConnectionHandler;
38 using blink::WebRTCPeerConnectionHandlerClient;
39 using blink::WebThemeEngine;
40 using WebTestRunner::WebTestDelegate;
41 using WebTestRunner::WebTestInterfaces;
42 using WebTestRunner::WebTestProxyBase;
44 namespace content {
46 namespace {
47 ShellContentRendererClient* g_renderer_client;
50 ShellContentRendererClient* ShellContentRendererClient::Get() {
51 return g_renderer_client;
54 ShellContentRendererClient::ShellContentRendererClient() {
55 DCHECK(!g_renderer_client);
56 g_renderer_client = this;
57 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
58 EnableWebTestProxyCreation(
59 base::Bind(&ShellContentRendererClient::WebTestProxyCreated,
60 base::Unretained(this)));
64 ShellContentRendererClient::~ShellContentRendererClient() {
65 g_renderer_client = NULL;
68 void ShellContentRendererClient::RenderThreadStarted() {
69 shell_observer_.reset(new ShellRenderProcessObserver());
70 #if defined(OS_MACOSX)
71 // We need to call this once before the sandbox was initialized to cache the
72 // value.
73 base::debug::BeingDebugged();
74 #endif
77 void ShellContentRendererClient::RenderFrameCreated(RenderFrame* render_frame) {
78 new ShellRenderFrameObserver(render_frame);
81 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) {
82 new ShellRenderViewObserver(render_view);
84 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
85 return;
86 WebKitTestRunner* test_runner = WebKitTestRunner::Get(render_view);
87 test_runner->Reset();
88 render_view->GetWebView()->setSpellCheckClient(
89 test_runner->proxy()->spellCheckClient());
90 WebTestDelegate* delegate =
91 ShellRenderProcessObserver::GetInstance()->test_delegate();
92 if (delegate == static_cast<WebTestDelegate*>(test_runner))
93 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view);
96 bool ShellContentRendererClient::OverrideCreatePlugin(
97 RenderFrame* render_frame,
98 WebFrame* frame,
99 const WebPluginParams& params,
100 WebPlugin** plugin) {
101 std::string mime_type = params.mimeType.utf8();
102 if (mime_type == content::kBrowserPluginMimeType) {
103 // Allow browser plugin in content_shell only if it is forced by flag.
104 // Returning true here disables the plugin.
105 return !CommandLine::ForCurrentProcess()->HasSwitch(
106 switches::kEnableBrowserPluginForAllViewTypes);
108 return false;
111 WebMediaStreamCenter*
112 ShellContentRendererClient::OverrideCreateWebMediaStreamCenter(
113 WebMediaStreamCenterClient* client) {
114 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
115 return NULL;
116 #if defined(ENABLE_WEBRTC)
117 WebTestInterfaces* interfaces =
118 ShellRenderProcessObserver::GetInstance()->test_interfaces();
119 return interfaces->createMediaStreamCenter(client);
120 #else
121 return NULL;
122 #endif
125 WebRTCPeerConnectionHandler*
126 ShellContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
127 WebRTCPeerConnectionHandlerClient* client) {
128 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
129 return NULL;
130 #if defined(ENABLE_WEBRTC)
131 WebTestInterfaces* interfaces =
132 ShellRenderProcessObserver::GetInstance()->test_interfaces();
133 return interfaces->createWebRTCPeerConnectionHandler(client);
134 #else
135 return NULL;
136 #endif
139 WebMIDIAccessor*
140 ShellContentRendererClient::OverrideCreateMIDIAccessor(
141 WebMIDIAccessorClient* client) {
142 WebTestInterfaces* interfaces =
143 ShellRenderProcessObserver::GetInstance()->test_interfaces();
144 return interfaces->createMIDIAccessor(client);
147 WebAudioDevice*
148 ShellContentRendererClient::OverrideCreateAudioDevice(
149 double sample_rate) {
150 WebTestInterfaces* interfaces =
151 ShellRenderProcessObserver::GetInstance()->test_interfaces();
152 return interfaces->createAudioDevice(sample_rate);
155 WebClipboard* ShellContentRendererClient::OverrideWebClipboard() {
156 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
157 return NULL;
158 if (!clipboard_)
159 clipboard_.reset(new MockWebClipboardImpl);
160 return clipboard_.get();
163 WebThemeEngine* ShellContentRendererClient::OverrideThemeEngine() {
164 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
165 return NULL;
166 return ShellRenderProcessObserver::GetInstance()->test_interfaces()
167 ->themeEngine();
170 void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view,
171 WebTestProxyBase* proxy) {
172 WebKitTestRunner* test_runner = new WebKitTestRunner(render_view);
173 test_runner->set_proxy(proxy);
174 if (!ShellRenderProcessObserver::GetInstance()->test_delegate())
175 ShellRenderProcessObserver::GetInstance()->SetTestDelegate(test_runner);
176 proxy->setInterfaces(
177 ShellRenderProcessObserver::GetInstance()->test_interfaces());
178 test_runner->proxy()->setDelegate(
179 ShellRenderProcessObserver::GetInstance()->test_delegate());
182 bool ShellContentRendererClient::AllowBrowserPlugin(
183 blink::WebPluginContainer* container) {
184 if (CommandLine::ForCurrentProcess()->HasSwitch(
185 switches::kEnableBrowserPluginForAllViewTypes)) {
186 // Allow BrowserPlugin if forced by command line flag. This is generally
187 // true for tests.
188 return true;
190 return ContentRendererClient::AllowBrowserPlugin(container);
193 } // namespace content