Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / shell / renderer / shell_content_renderer_client.cc
blob7c2f316e1fb439b13ab4a5da554f1e1a8a067f5f
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/common/sandbox_win.h"
11 #include "content/public/common/content_constants.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/renderer/render_view.h"
14 #include "content/public/test/layouttest_support.h"
15 #include "content/shell/common/shell_switches.h"
16 #include "content/shell/common/webkit_test_helpers.h"
17 #include "content/shell/renderer/shell_render_frame_observer.h"
18 #include "content/shell/renderer/shell_render_process_observer.h"
19 #include "content/shell/renderer/shell_render_view_observer.h"
20 #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
21 #include "content/shell/renderer/test_runner/web_test_proxy.h"
22 #include "content/shell/renderer/webkit_test_runner.h"
23 #include "content/test/mock_webclipboard_impl.h"
24 #include "ppapi/shared_impl/ppapi_switches.h"
25 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
26 #include "third_party/WebKit/public/web/WebPluginParams.h"
27 #include "third_party/WebKit/public/web/WebView.h"
28 #include "v8/include/v8.h"
30 #if defined(OS_WIN)
31 #include "content/public/renderer/render_font_warmup_win.h"
32 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
33 #include "third_party/skia/include/ports/SkFontMgr.h"
34 #endif
36 using blink::WebAudioDevice;
37 using blink::WebClipboard;
38 using blink::WebLocalFrame;
39 using blink::WebMIDIAccessor;
40 using blink::WebMIDIAccessorClient;
41 using blink::WebMediaStreamCenter;
42 using blink::WebMediaStreamCenterClient;
43 using blink::WebPlugin;
44 using blink::WebPluginParams;
45 using blink::WebRTCPeerConnectionHandler;
46 using blink::WebRTCPeerConnectionHandlerClient;
47 using blink::WebThemeEngine;
49 namespace content {
51 #if defined(OS_WIN)
52 namespace {
54 // DirectWrite only has access to %WINDIR%\Fonts by default. For developer
55 // side-loading, support kRegisterFontFiles to allow access to additional fonts.
56 void RegisterSideloadedTypefaces(SkFontMgr* fontmgr) {
57 std::vector<std::string> files = GetSideloadFontFiles();
58 for (std::vector<std::string>::const_iterator i(files.begin());
59 i != files.end();
60 ++i) {
61 SkTypeface* typeface = fontmgr->createFromFile(i->c_str());
62 DoPreSandboxWarmupForTypeface(typeface);
63 blink::WebFontRendering::addSideloadedFontForTesting(typeface);
67 } // namespace
68 #endif // OS_WIN
70 ShellContentRendererClient::ShellContentRendererClient() {
71 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
72 EnableWebTestProxyCreation(
73 base::Bind(&ShellContentRendererClient::WebTestProxyCreated,
74 base::Unretained(this)));
77 #if defined(OS_WIN)
78 if (ShouldUseDirectWrite())
79 RegisterSideloadedTypefaces(GetPreSandboxWarmupFontMgr());
80 #endif
83 ShellContentRendererClient::~ShellContentRendererClient() {
86 void ShellContentRendererClient::RenderThreadStarted() {
87 shell_observer_.reset(new ShellRenderProcessObserver());
88 #if defined(OS_MACOSX)
89 // We need to call this once before the sandbox was initialized to cache the
90 // value.
91 base::debug::BeingDebugged();
92 #endif
95 void ShellContentRendererClient::RenderFrameCreated(RenderFrame* render_frame) {
96 new ShellRenderFrameObserver(render_frame);
99 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) {
100 new ShellRenderViewObserver(render_view);
102 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
103 return;
104 WebKitTestRunner* test_runner = WebKitTestRunner::Get(render_view);
105 test_runner->Reset();
106 render_view->GetWebView()->setSpellCheckClient(
107 test_runner->proxy()->GetSpellCheckClient());
108 WebTestDelegate* delegate =
109 ShellRenderProcessObserver::GetInstance()->test_delegate();
110 if (delegate == static_cast<WebTestDelegate*>(test_runner))
111 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view);
114 bool ShellContentRendererClient::OverrideCreatePlugin(
115 RenderFrame* render_frame,
116 WebLocalFrame* frame,
117 const WebPluginParams& params,
118 WebPlugin** plugin) {
119 return false;
122 WebMediaStreamCenter*
123 ShellContentRendererClient::OverrideCreateWebMediaStreamCenter(
124 WebMediaStreamCenterClient* client) {
125 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
126 return NULL;
127 #if defined(ENABLE_WEBRTC)
128 WebTestInterfaces* interfaces =
129 ShellRenderProcessObserver::GetInstance()->test_interfaces();
130 return interfaces->createMediaStreamCenter(client);
131 #else
132 return NULL;
133 #endif
136 WebRTCPeerConnectionHandler*
137 ShellContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
138 WebRTCPeerConnectionHandlerClient* client) {
139 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
140 return NULL;
141 #if defined(ENABLE_WEBRTC)
142 WebTestInterfaces* interfaces =
143 ShellRenderProcessObserver::GetInstance()->test_interfaces();
144 return interfaces->createWebRTCPeerConnectionHandler(client);
145 #else
146 return NULL;
147 #endif
150 WebMIDIAccessor*
151 ShellContentRendererClient::OverrideCreateMIDIAccessor(
152 WebMIDIAccessorClient* client) {
153 WebTestInterfaces* interfaces =
154 ShellRenderProcessObserver::GetInstance()->test_interfaces();
155 return interfaces->createMIDIAccessor(client);
158 WebAudioDevice*
159 ShellContentRendererClient::OverrideCreateAudioDevice(
160 double sample_rate) {
161 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
162 return NULL;
163 WebTestInterfaces* interfaces =
164 ShellRenderProcessObserver::GetInstance()->test_interfaces();
165 return interfaces->createAudioDevice(sample_rate);
168 WebClipboard* ShellContentRendererClient::OverrideWebClipboard() {
169 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
170 return NULL;
171 if (!clipboard_)
172 clipboard_.reset(new MockWebClipboardImpl);
173 return clipboard_.get();
176 WebThemeEngine* ShellContentRendererClient::OverrideThemeEngine() {
177 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
178 return NULL;
179 return ShellRenderProcessObserver::GetInstance()->test_interfaces()
180 ->themeEngine();
183 void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view,
184 WebTestProxyBase* proxy) {
185 WebKitTestRunner* test_runner = new WebKitTestRunner(render_view);
186 test_runner->set_proxy(proxy);
187 if (!ShellRenderProcessObserver::GetInstance()->test_delegate())
188 ShellRenderProcessObserver::GetInstance()->SetTestDelegate(test_runner);
189 proxy->SetInterfaces(
190 ShellRenderProcessObserver::GetInstance()->test_interfaces());
191 test_runner->proxy()->SetDelegate(
192 ShellRenderProcessObserver::GetInstance()->test_delegate());
195 bool ShellContentRendererClient::IsPluginAllowedToUseCompositorAPI(
196 const GURL& url) {
197 return CommandLine::ForCurrentProcess()->HasSwitch(
198 switches::kEnablePepperTesting);
201 bool ShellContentRendererClient::IsPluginAllowedToUseVideoDecodeAPI(
202 const GURL& url) {
203 return CommandLine::ForCurrentProcess()->HasSwitch(
204 switches::kEnablePepperTesting);
207 bool ShellContentRendererClient::IsPluginAllowedToUseDevChannelAPIs() {
208 return CommandLine::ForCurrentProcess()->HasSwitch(
209 switches::kEnablePepperTesting);
212 } // namespace content