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"
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"
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
;
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());
61 SkTypeface
* typeface
= fontmgr
->createFromFile(i
->c_str());
62 DoPreSandboxWarmupForTypeface(typeface
);
63 blink::WebFontRendering::addSideloadedFontForTesting(typeface
);
70 ShellContentRendererClient::ShellContentRendererClient() {
71 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
)) {
72 EnableWebTestProxyCreation(
73 base::Bind(&ShellContentRendererClient::WebTestProxyCreated
,
74 base::Unretained(this)));
78 if (ShouldUseDirectWrite())
79 RegisterSideloadedTypefaces(GetPreSandboxWarmupFontMgr());
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
91 base::debug::BeingDebugged();
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
))
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
) {
122 WebMediaStreamCenter
*
123 ShellContentRendererClient::OverrideCreateWebMediaStreamCenter(
124 WebMediaStreamCenterClient
* client
) {
125 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
127 #if defined(ENABLE_WEBRTC)
128 WebTestInterfaces
* interfaces
=
129 ShellRenderProcessObserver::GetInstance()->test_interfaces();
130 return interfaces
->createMediaStreamCenter(client
);
136 WebRTCPeerConnectionHandler
*
137 ShellContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
138 WebRTCPeerConnectionHandlerClient
* client
) {
139 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
141 #if defined(ENABLE_WEBRTC)
142 WebTestInterfaces
* interfaces
=
143 ShellRenderProcessObserver::GetInstance()->test_interfaces();
144 return interfaces
->createWebRTCPeerConnectionHandler(client
);
151 ShellContentRendererClient::OverrideCreateMIDIAccessor(
152 WebMIDIAccessorClient
* client
) {
153 WebTestInterfaces
* interfaces
=
154 ShellRenderProcessObserver::GetInstance()->test_interfaces();
155 return interfaces
->createMIDIAccessor(client
);
159 ShellContentRendererClient::OverrideCreateAudioDevice(
160 double sample_rate
) {
161 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
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
))
172 clipboard_
.reset(new MockWebClipboardImpl
);
173 return clipboard_
.get();
176 WebThemeEngine
* ShellContentRendererClient::OverrideThemeEngine() {
177 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
179 return ShellRenderProcessObserver::GetInstance()->test_interfaces()
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(
197 return CommandLine::ForCurrentProcess()->HasSwitch(
198 switches::kEnablePepperTesting
);
201 bool ShellContentRendererClient::IsPluginAllowedToUseVideoDecodeAPI(
203 return CommandLine::ForCurrentProcess()->HasSwitch(
204 switches::kEnablePepperTesting
);
207 bool ShellContentRendererClient::IsPluginAllowedToUseDevChannelAPIs() {
208 return CommandLine::ForCurrentProcess()->HasSwitch(
209 switches::kEnablePepperTesting
);
212 } // namespace content