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 "chrome/renderer/chrome_content_renderer_client.h"
7 #include "base/command_line.h"
8 #include "base/debug/crash_logging.h"
9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram.h"
12 #include "base/metrics/user_metrics_action.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_version_info.h"
20 #include "chrome/common/crash_keys.h"
21 #include "chrome/common/extensions/extension_metrics.h"
22 #include "chrome/common/localized_error.h"
23 #include "chrome/common/pepper_permission_util.h"
24 #include "chrome/common/render_messages.h"
25 #include "chrome/common/url_constants.h"
26 #include "chrome/grit/generated_resources.h"
27 #include "chrome/grit/locale_settings.h"
28 #include "chrome/grit/renderer_resources.h"
29 #include "chrome/renderer/benchmarking_extension.h"
30 #include "chrome/renderer/chrome_render_frame_observer.h"
31 #include "chrome/renderer/chrome_render_process_observer.h"
32 #include "chrome/renderer/chrome_render_view_observer.h"
33 #include "chrome/renderer/content_settings_observer.h"
34 #include "chrome/renderer/external_extension.h"
35 #include "chrome/renderer/loadtimes_extension_bindings.h"
36 #include "chrome/renderer/media/chrome_key_systems.h"
37 #include "chrome/renderer/net/net_error_helper.h"
38 #include "chrome/renderer/net_benchmarking_extension.h"
39 #include "chrome/renderer/page_load_histograms.h"
40 #include "chrome/renderer/pepper/pepper_helper.h"
41 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
42 #include "chrome/renderer/plugins/plugin_preroller.h"
43 #include "chrome/renderer/plugins/plugin_uma.h"
44 #include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h"
45 #include "chrome/renderer/prefetch_helper.h"
46 #include "chrome/renderer/prerender/prerender_dispatcher.h"
47 #include "chrome/renderer/prerender/prerender_helper.h"
48 #include "chrome/renderer/prerender/prerender_media_load_deferrer.h"
49 #include "chrome/renderer/prerender/prerenderer_client.h"
50 #include "chrome/renderer/safe_browsing/malware_dom_details.h"
51 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
52 #include "chrome/renderer/searchbox/search_bouncer.h"
53 #include "chrome/renderer/searchbox/searchbox.h"
54 #include "chrome/renderer/searchbox/searchbox_extension.h"
55 #include "chrome/renderer/tts_dispatcher.h"
56 #include "chrome/renderer/worker_content_settings_client_proxy.h"
57 #include "components/autofill/content/renderer/autofill_agent.h"
58 #include "components/autofill/content/renderer/password_autofill_agent.h"
59 #include "components/autofill/content/renderer/password_generation_agent.h"
60 #include "components/content_settings/core/common/content_settings_pattern.h"
61 #include "components/dom_distiller/core/url_constants.h"
62 #include "components/nacl/renderer/ppb_nacl_private.h"
63 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
64 #include "components/network_hints/renderer/prescient_networking_dispatcher.h"
65 #include "components/password_manager/content/renderer/credential_manager_client.h"
66 #include "components/pdf/renderer/ppb_pdf_impl.h"
67 #include "components/plugins/renderer/mobile_youtube_plugin.h"
68 #include "components/signin/core/common/profile_management_switches.h"
69 #include "components/visitedlink/renderer/visitedlink_slave.h"
70 #include "components/web_cache/renderer/web_cache_render_process_observer.h"
71 #include "content/public/common/content_constants.h"
72 #include "content/public/renderer/plugin_instance_throttler.h"
73 #include "content/public/renderer/render_frame.h"
74 #include "content/public/renderer/render_thread.h"
75 #include "content/public/renderer/render_view.h"
76 #include "content/public/renderer/render_view_visitor.h"
77 #include "extensions/common/constants.h"
78 #include "ipc/ipc_sync_channel.h"
79 #include "net/base/net_errors.h"
80 #include "ppapi/c/private/ppb_pdf.h"
81 #include "ppapi/shared_impl/ppapi_switches.h"
82 #include "third_party/WebKit/public/platform/WebURL.h"
83 #include "third_party/WebKit/public/platform/WebURLError.h"
84 #include "third_party/WebKit/public/platform/WebURLRequest.h"
85 #include "third_party/WebKit/public/web/WebCache.h"
86 #include "third_party/WebKit/public/web/WebDataSource.h"
87 #include "third_party/WebKit/public/web/WebDocument.h"
88 #include "third_party/WebKit/public/web/WebElement.h"
89 #include "third_party/WebKit/public/web/WebLocalFrame.h"
90 #include "third_party/WebKit/public/web/WebPluginContainer.h"
91 #include "third_party/WebKit/public/web/WebPluginParams.h"
92 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h"
93 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
94 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
95 #include "ui/base/l10n/l10n_util.h"
96 #include "ui/base/layout.h"
97 #include "ui/base/resource/resource_bundle.h"
98 #include "ui/base/webui/jstemplate_builder.h"
99 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
101 #if !defined(DISABLE_NACL)
102 #include "components/nacl/common/nacl_constants.h"
103 #include "components/nacl/renderer/nacl_helper.h"
106 #if defined(ENABLE_EXTENSIONS)
107 #include "chrome/common/extensions/chrome_extensions_client.h"
108 #include "chrome/common/extensions/extension_process_policy.h"
109 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h"
110 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h"
111 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
112 #include "chrome/renderer/extensions/resource_request_policy.h"
113 #include "chrome/renderer/media/cast_ipc_dispatcher.h"
114 #include "extensions/common/extension.h"
115 #include "extensions/common/extension_set.h"
116 #include "extensions/common/extension_urls.h"
117 #include "extensions/common/switches.h"
118 #include "extensions/renderer/dispatcher.h"
119 #include "extensions/renderer/extension_frame_helper.h"
120 #include "extensions/renderer/extension_helper.h"
121 #include "extensions/renderer/extensions_render_frame_observer.h"
122 #include "extensions/renderer/guest_view/extensions_guest_view_container.h"
123 #include "extensions/renderer/guest_view/guest_view_container.h"
124 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h"
125 #include "extensions/renderer/script_context.h"
128 #if defined(ENABLE_IPC_FUZZER)
129 #include "chrome/common/external_ipc_dumper.h"
132 #if defined(ENABLE_PRINTING)
133 #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h"
134 #include "components/printing/renderer/print_web_view_helper.h"
137 #if defined(ENABLE_PRINT_PREVIEW)
138 #include "chrome/renderer/pepper/chrome_pdf_print_client.h"
141 #if defined(ENABLE_SPELLCHECK)
142 #include "chrome/renderer/spellchecker/spellcheck.h"
143 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
146 #if defined(ENABLE_WEBRTC)
147 #include "chrome/renderer/media/webrtc_logging_message_filter.h"
151 #include "chrome_elf/blacklist/blacklist.h"
154 using autofill::AutofillAgent
;
155 using autofill::PasswordAutofillAgent
;
156 using autofill::PasswordGenerationAgent
;
157 using base::ASCIIToUTF16
;
158 using base::UserMetricsAction
;
159 using content::PluginInstanceThrottler
;
160 using content::RenderFrame
;
161 using content::RenderThread
;
162 using content::WebPluginInfo
;
163 using extensions::Extension
;
164 using blink::WebCache
;
165 using blink::WebConsoleMessage
;
166 using blink::WebDataSource
;
167 using blink::WebDocument
;
168 using blink::WebPlugin
;
169 using blink::WebPluginParams
;
170 using blink::WebSecurityOrigin
;
171 using blink::WebSecurityPolicy
;
172 using blink::WebString
;
174 using blink::WebURLError
;
175 using blink::WebURLRequest
;
176 using blink::WebURLResponse
;
177 using blink::WebVector
;
181 ChromeContentRendererClient
* g_current_client
;
183 // Whitelist PPAPI for Android Runtime for Chromium. (See crbug.com/383937)
184 #if defined(ENABLE_PLUGINS)
185 const char* const kPredefinedAllowedCameraDeviceOrigins
[] = {
186 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F",
187 "4EB74897CB187C7633357C2FE832E0AD6A44883A"
190 const char* const kPredefinedAllowedCompositorOrigins
[] = {
191 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F",
192 "4EB74897CB187C7633357C2FE832E0AD6A44883A"
196 void AppendParams(const std::vector
<base::string16
>& additional_names
,
197 const std::vector
<base::string16
>& additional_values
,
198 WebVector
<WebString
>* existing_names
,
199 WebVector
<WebString
>* existing_values
) {
200 DCHECK(additional_names
.size() == additional_values
.size());
201 DCHECK(existing_names
->size() == existing_values
->size());
203 size_t existing_size
= existing_names
->size();
204 size_t total_size
= existing_size
+ additional_names
.size();
206 WebVector
<WebString
> names(total_size
);
207 WebVector
<WebString
> values(total_size
);
209 for (size_t i
= 0; i
< existing_size
; ++i
) {
210 names
[i
] = (*existing_names
)[i
];
211 values
[i
] = (*existing_values
)[i
];
214 for (size_t i
= 0; i
< additional_names
.size(); ++i
) {
215 names
[existing_size
+ i
] = additional_names
[i
];
216 values
[existing_size
+ i
] = additional_values
[i
];
219 existing_names
->swap(names
);
220 existing_values
->swap(values
);
223 #if defined(ENABLE_SPELLCHECK)
224 class SpellCheckReplacer
: public content::RenderViewVisitor
{
226 explicit SpellCheckReplacer(SpellCheck
* spellcheck
)
227 : spellcheck_(spellcheck
) {}
228 bool Visit(content::RenderView
* render_view
) override
;
231 SpellCheck
* spellcheck_
; // New shared spellcheck for all views. Weak Ptr.
232 DISALLOW_COPY_AND_ASSIGN(SpellCheckReplacer
);
235 bool SpellCheckReplacer::Visit(content::RenderView
* render_view
) {
236 SpellCheckProvider
* provider
= SpellCheckProvider::Get(render_view
);
238 provider
->set_spellcheck(spellcheck_
);
243 // For certain sandboxed Pepper plugins, use the JavaScript Content Settings.
244 bool ShouldUseJavaScriptSettingForPlugin(const WebPluginInfo
& plugin
) {
245 if (plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS
&&
246 plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
) {
250 #if !defined(DISABLE_NACL)
251 // Treat Native Client invocations like JavaScript.
252 if (plugin
.name
== ASCIIToUTF16(nacl::kNaClPluginName
))
256 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
257 // Treat CDM invocations like JavaScript.
258 if (plugin
.name
== ASCIIToUTF16(kWidevineCdmDisplayName
)) {
259 DCHECK(plugin
.type
== WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
);
262 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
267 #if defined(ENABLE_EXTENSIONS)
268 void IsGuestViewApiAvailableToScriptContext(
269 bool* api_is_available
,
270 extensions::ScriptContext
* context
) {
271 if (context
->GetAvailability("guestViewInternal").is_available()) {
272 *api_is_available
= true;
277 #if defined(ENABLE_PLUGINS)
278 // Presence of the poster param within plugin object tags.
279 // These numeric values are used in UMA logs; do not change them.
280 enum PosterParamPresence
{
281 POSTER_PRESENCE_NO_PARAM_PPS_DISABLED
= 0,
282 POSTER_PRESENCE_NO_PARAM_PPS_ENABLED
= 1,
283 POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED
= 2,
284 POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED
= 3,
285 POSTER_PRESENCE_NUM_ITEMS
288 const char kPluginPowerSaverPosterParamPresenceHistogram
[] =
289 "Plugin.PowerSaver.PosterParamPresence";
291 void RecordPosterParamPresence(PosterParamPresence presence
) {
292 UMA_HISTOGRAM_ENUMERATION(kPluginPowerSaverPosterParamPresenceHistogram
,
293 presence
, POSTER_PRESENCE_NUM_ITEMS
);
296 void TrackPosterParamPresence(const blink::WebPluginParams
& params
,
297 bool power_saver_enabled
) {
298 DCHECK_EQ(params
.attributeNames
.size(), params
.attributeValues
.size());
300 for (size_t i
= 0; i
< params
.attributeNames
.size(); ++i
) {
301 if (params
.attributeNames
[i
].utf8() == "poster") {
302 if (power_saver_enabled
)
303 RecordPosterParamPresence(POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED
);
305 RecordPosterParamPresence(POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED
);
311 if (power_saver_enabled
)
312 RecordPosterParamPresence(POSTER_PRESENCE_NO_PARAM_PPS_ENABLED
);
314 RecordPosterParamPresence(POSTER_PRESENCE_NO_PARAM_PPS_DISABLED
);
317 std::string
GetPluginInstancePosterAttribute(
318 const blink::WebPluginParams
& params
) {
319 DCHECK_EQ(params
.attributeNames
.size(), params
.attributeValues
.size());
321 for (size_t i
= 0; i
< params
.attributeNames
.size(); ++i
) {
322 if (params
.attributeNames
[i
].utf8() == "poster" &&
323 !params
.attributeValues
[i
].isEmpty()) {
324 return params
.attributeValues
[i
].utf8();
327 return std::string();
331 #if defined(ENABLE_EXTENSIONS)
332 bool IsStandaloneExtensionProcess() {
333 return base::CommandLine::ForCurrentProcess()->HasSwitch(
334 extensions::switches::kExtensionProcess
);
339 ChromeContentRendererClient::ChromeContentRendererClient() {
340 g_current_client
= this;
342 #if defined(ENABLE_EXTENSIONS)
343 extensions::ExtensionsClient::Set(
344 extensions::ChromeExtensionsClient::GetInstance());
345 extensions::ExtensionsRendererClient::Set(
346 ChromeExtensionsRendererClient::GetInstance());
348 #if defined(ENABLE_PLUGINS)
349 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedCameraDeviceOrigins
); ++i
)
350 allowed_camera_device_origins_
.insert(
351 kPredefinedAllowedCameraDeviceOrigins
[i
]);
352 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedCompositorOrigins
); ++i
)
353 allowed_compositor_origins_
.insert(kPredefinedAllowedCompositorOrigins
[i
]);
357 ChromeContentRendererClient::~ChromeContentRendererClient() {
358 g_current_client
= NULL
;
361 void ChromeContentRendererClient::RenderThreadStarted() {
362 RenderThread
* thread
= RenderThread::Get();
364 chrome_observer_
.reset(new ChromeRenderProcessObserver());
365 web_cache_observer_
.reset(new web_cache::WebCacheRenderProcessObserver());
367 #if defined(ENABLE_EXTENSIONS)
368 extension_dispatcher_delegate_
.reset(
369 new ChromeExtensionsDispatcherDelegate());
370 // ChromeRenderViewTest::SetUp() creates its own ExtensionDispatcher and
371 // injects it using SetExtensionDispatcher(). Don't overwrite it.
372 if (!extension_dispatcher_
) {
373 extension_dispatcher_
.reset(
374 new extensions::Dispatcher(extension_dispatcher_delegate_
.get()));
376 permissions_policy_delegate_
.reset(
377 new extensions::RendererPermissionsPolicyDelegate(
378 extension_dispatcher_
.get()));
381 prescient_networking_dispatcher_
.reset(
382 new network_hints::PrescientNetworkingDispatcher());
383 #if defined(ENABLE_SPELLCHECK)
384 // ChromeRenderViewTest::SetUp() creates a Spellcheck and injects it using
385 // SetSpellcheck(). Don't overwrite it.
387 spellcheck_
.reset(new SpellCheck());
388 thread
->AddObserver(spellcheck_
.get());
391 visited_link_slave_
.reset(new visitedlink::VisitedLinkSlave());
392 #if defined(FULL_SAFE_BROWSING)
393 phishing_classifier_
.reset(safe_browsing::PhishingClassifierFilter::Create());
395 prerender_dispatcher_
.reset(new prerender::PrerenderDispatcher());
396 #if defined(ENABLE_WEBRTC)
397 webrtc_logging_message_filter_
= new WebRtcLoggingMessageFilter(
398 RenderThread::Get()->GetIOMessageLoopProxy());
400 search_bouncer_
.reset(new SearchBouncer());
402 thread
->AddObserver(chrome_observer_
.get());
403 thread
->AddObserver(web_cache_observer_
.get());
404 #if defined(ENABLE_EXTENSIONS)
405 thread
->AddObserver(extension_dispatcher_
.get());
407 #if defined(FULL_SAFE_BROWSING)
408 thread
->AddObserver(phishing_classifier_
.get());
410 thread
->AddObserver(visited_link_slave_
.get());
411 thread
->AddObserver(prerender_dispatcher_
.get());
412 thread
->AddObserver(search_bouncer_
.get());
414 #if defined(ENABLE_WEBRTC)
415 thread
->AddFilter(webrtc_logging_message_filter_
.get());
417 #if defined(ENABLE_EXTENSIONS)
418 thread
->AddFilter(new CastIPCDispatcher(
419 RenderThread::Get()->GetIOMessageLoopProxy()));
422 thread
->RegisterExtension(extensions_v8::ExternalExtension::Get());
423 thread
->RegisterExtension(extensions_v8::LoadTimesExtension::Get());
425 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
426 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
427 thread
->RegisterExtension(extensions_v8::BenchmarkingExtension::Get());
428 if (command_line
->HasSwitch(switches::kEnableNetBenchmarking
))
429 thread
->RegisterExtension(extensions_v8::NetBenchmarkingExtension::Get());
430 if (command_line
->HasSwitch(switches::kInstantProcess
))
431 thread
->RegisterExtension(extensions_v8::SearchBoxExtension::Get());
433 // chrome:, chrome-search:, chrome-devtools:, and chrome-distiller: pages
434 // should not be accessible by normal content, and should also be unable to
435 // script anything but themselves (to help limit the damage that a corrupt
436 // page could cause).
437 WebString
chrome_ui_scheme(ASCIIToUTF16(content::kChromeUIScheme
));
438 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme
);
440 WebString
chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme
));
441 // The Instant process can only display the content but not read it. Other
442 // processes can't display it or read it.
443 if (!command_line
->HasSwitch(switches::kInstantProcess
))
444 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_search_scheme
);
446 WebString
dev_tools_scheme(ASCIIToUTF16(content::kChromeDevToolsScheme
));
447 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dev_tools_scheme
);
449 WebString
dom_distiller_scheme(
450 ASCIIToUTF16(dom_distiller::kDomDistillerScheme
));
451 // TODO(nyquist): Add test to ensure this happens when the flag is set.
452 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dom_distiller_scheme
);
454 #if defined(OS_CHROMEOS)
455 WebString
external_file_scheme(ASCIIToUTF16(content::kExternalFileScheme
));
456 WebSecurityPolicy::registerURLSchemeAsLocal(external_file_scheme
);
459 #if defined(ENABLE_IPC_FUZZER)
460 if (command_line
->HasSwitch(switches::kIpcDumpDirectory
)) {
461 base::FilePath dump_directory
=
462 command_line
->GetSwitchValuePath(switches::kIpcDumpDirectory
);
463 IPC::ChannelProxy::OutgoingMessageFilter
* filter
=
464 LoadExternalIPCDumper(dump_directory
);
465 thread
->GetChannel()->set_outgoing_message_filter(filter
);
469 // chrome: and chrome-search: pages should not be accessible by bookmarklets
470 // or javascript: URLs typed in the omnibox.
471 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
473 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
474 chrome_search_scheme
);
476 // chrome:, chrome-search:, chrome-extension:, and chrome-extension-resource:
477 // resources shouldn't trigger insecure content warnings.
478 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_ui_scheme
);
479 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_search_scheme
);
481 WebString
extension_scheme(ASCIIToUTF16(extensions::kExtensionScheme
));
482 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme
);
484 WebString
extension_resource_scheme(
485 ASCIIToUTF16(extensions::kExtensionResourceScheme
));
486 WebSecurityPolicy::registerURLSchemeAsSecure(extension_resource_scheme
);
488 // chrome:, chrome-extension:, chrome-extension-resource: resources should be
489 // allowed to receive CORS requests.
490 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(chrome_ui_scheme
);
491 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_scheme
);
492 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_resource_scheme
);
494 // chrome-extension: resources should bypass Content Security Policy checks
495 // when included in protected resources.
496 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
498 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
499 extension_resource_scheme
);
502 // Report if the renderer process has been patched by chrome_elf.
503 // TODO(csharp): Remove once the renderer is no longer getting
505 if (blacklist::IsBlacklistInitialized())
506 UMA_HISTOGRAM_BOOLEAN("Blacklist.PatchedInRenderer", true);
508 #if defined(ENABLE_PRINT_PREVIEW)
509 pdf_print_client_
.reset(new ChromePDFPrintClient());
510 pdf::PPB_PDF_Impl::SetPrintClient(pdf_print_client_
.get());
514 void ChromeContentRendererClient::RenderFrameCreated(
515 content::RenderFrame
* render_frame
) {
516 new ChromeRenderFrameObserver(render_frame
);
518 bool should_whitelist_for_content_settings
=
519 base::CommandLine::ForCurrentProcess()->HasSwitch(
520 switches::kInstantProcess
);
521 extensions::Dispatcher
* ext_dispatcher
= NULL
;
522 #if defined(ENABLE_EXTENSIONS)
523 ext_dispatcher
= extension_dispatcher_
.get();
525 ContentSettingsObserver
* content_settings
= new ContentSettingsObserver(
526 render_frame
, ext_dispatcher
, should_whitelist_for_content_settings
);
527 if (chrome_observer_
.get()) {
528 content_settings
->SetContentSettingRules(
529 chrome_observer_
->content_setting_rules());
532 #if defined(ENABLE_EXTENSIONS)
533 new extensions::ExtensionsRenderFrameObserver(render_frame
);
534 new extensions::ExtensionFrameHelper(render_frame
, ext_dispatcher
);
537 #if defined(ENABLE_PLUGINS)
538 new PepperHelper(render_frame
);
541 #if !defined(DISABLE_NACL)
542 new nacl::NaClHelper(render_frame
);
545 // TODO(jam): when the frame tree moves into content and parent() works at
546 // RenderFrame construction, simplify this by just checking parent().
547 if (render_frame
->GetRenderView()->GetMainRenderFrame() != render_frame
) {
548 // Avoid any race conditions from having the browser tell subframes that
549 // they're prerendering.
550 if (prerender::PrerenderHelper::IsPrerendering(
551 render_frame
->GetRenderView()->GetMainRenderFrame())) {
552 new prerender::PrerenderHelper(render_frame
);
556 if (render_frame
->GetRenderView()->GetMainRenderFrame() == render_frame
) {
557 // Only attach NetErrorHelper to the main frame, since only the main frame
558 // should get error pages.
559 // PrefetchHelper is also needed only for main frames.
560 new NetErrorHelper(render_frame
);
561 new prefetch::PrefetchHelper(render_frame
);
564 PasswordGenerationAgent
* password_generation_agent
=
565 new PasswordGenerationAgent(render_frame
);
566 PasswordAutofillAgent
* password_autofill_agent
=
567 new PasswordAutofillAgent(render_frame
);
568 new AutofillAgent(render_frame
, password_autofill_agent
,
569 password_generation_agent
);
572 void ChromeContentRendererClient::RenderViewCreated(
573 content::RenderView
* render_view
) {
575 #if defined(ENABLE_EXTENSIONS)
576 new extensions::ExtensionHelper(render_view
, extension_dispatcher_
.get());
577 extension_dispatcher_
->OnRenderViewCreated(render_view
);
579 new PageLoadHistograms(render_view
);
580 #if defined(ENABLE_PRINTING)
581 new printing::PrintWebViewHelper(
583 scoped_ptr
<printing::PrintWebViewHelper::Delegate
>(
584 new ChromePrintWebViewHelperDelegate()));
586 #if defined(ENABLE_SPELLCHECK)
587 new SpellCheckProvider(render_view
, spellcheck_
.get());
589 new prerender::PrerendererClient(render_view
);
590 #if defined(FULL_SAFE_BROWSING)
591 safe_browsing::MalwareDOMDetails::Create(render_view
);
594 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
595 if (command_line
->HasSwitch(switches::kInstantProcess
))
596 new SearchBox(render_view
);
598 new ChromeRenderViewObserver(render_view
, web_cache_observer_
.get());
600 new password_manager::CredentialManagerClient(render_view
);
604 SkBitmap
* ChromeContentRendererClient::GetSadPluginBitmap() {
605 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
606 GetImageNamed(IDR_SAD_PLUGIN
).ToSkBitmap());
609 SkBitmap
* ChromeContentRendererClient::GetSadWebViewBitmap() {
610 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
611 GetImageNamed(IDR_SAD_WEBVIEW
).ToSkBitmap());
614 #if defined(ENABLE_EXTENSIONS)
615 const Extension
* ChromeContentRendererClient::GetExtensionByOrigin(
616 const WebSecurityOrigin
& origin
) const {
617 if (!EqualsASCII(origin
.protocol(), extensions::kExtensionScheme
))
620 const std::string extension_id
= origin
.host().utf8().data();
621 return extension_dispatcher_
->extensions()->GetByID(extension_id
);
625 scoped_ptr
<blink::WebPluginPlaceholder
>
626 ChromeContentRendererClient::CreatePluginPlaceholder(
627 content::RenderFrame
* render_frame
,
628 blink::WebLocalFrame
* frame
,
629 const blink::WebPluginParams
& orig_params
) {
630 return CreateShadowDOMPlaceholderForPluginInfo(
631 render_frame
, frame
, orig_params
);
634 bool ChromeContentRendererClient::OverrideCreatePlugin(
635 content::RenderFrame
* render_frame
,
636 blink::WebLocalFrame
* frame
,
637 const WebPluginParams
& params
,
638 WebPlugin
** plugin
) {
639 std::string orig_mime_type
= params
.mimeType
.utf8();
640 #if defined(ENABLE_EXTENSIONS)
641 if (orig_mime_type
== content::kBrowserPluginMimeType
) {
642 bool guest_view_api_available
= false;
643 extension_dispatcher_
->script_context_set().ForEach(
644 render_frame
->GetRenderView(),
645 base::Bind(&IsGuestViewApiAvailableToScriptContext
,
646 &guest_view_api_available
));
647 if (guest_view_api_available
)
652 ChromeViewHostMsg_GetPluginInfo_Output output
;
653 #if defined(ENABLE_PLUGINS)
654 render_frame
->Send(new ChromeViewHostMsg_GetPluginInfo(
655 render_frame
->GetRoutingID(), GURL(params
.url
),
656 frame
->top()->document().url(), orig_mime_type
, &output
));
659 output
.status
.value
= ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
;
661 *plugin
= CreatePlugin(render_frame
, frame
, params
, output
);
665 WebPlugin
* ChromeContentRendererClient::CreatePluginReplacement(
666 content::RenderFrame
* render_frame
,
667 const base::FilePath
& plugin_path
) {
668 ChromePluginPlaceholder
* placeholder
=
669 ChromePluginPlaceholder::CreateErrorPlugin(render_frame
, plugin_path
);
670 return placeholder
->plugin();
673 void ChromeContentRendererClient::DeferMediaLoad(
674 content::RenderFrame
* render_frame
,
675 const base::Closure
& closure
) {
676 #if defined(OS_ANDROID)
677 // Chromium for Android doesn't support prerender yet.
681 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
686 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
687 new prerender::PrerenderMediaLoadDeferrer(render_frame
, closure
);
691 WebPlugin
* ChromeContentRendererClient::CreatePlugin(
692 content::RenderFrame
* render_frame
,
693 blink::WebLocalFrame
* frame
,
694 const WebPluginParams
& original_params
,
695 const ChromeViewHostMsg_GetPluginInfo_Output
& output
) {
696 const ChromeViewHostMsg_GetPluginInfo_Status
& status
= output
.status
;
697 const WebPluginInfo
& info
= output
.plugin
;
698 const std::string
& actual_mime_type
= output
.actual_mime_type
;
699 const base::string16
& group_name
= output
.group_name
;
700 const std::string
& identifier
= output
.group_identifier
;
701 ChromeViewHostMsg_GetPluginInfo_Status::Value status_value
= status
.value
;
702 GURL
url(original_params
.url
);
703 std::string orig_mime_type
= original_params
.mimeType
.utf8();
704 ChromePluginPlaceholder
* placeholder
= NULL
;
706 // If the browser plugin is to be enabled, this should be handled by the
707 // renderer, so the code won't reach here due to the early exit in
708 // OverrideCreatePlugin.
709 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
||
710 orig_mime_type
== content::kBrowserPluginMimeType
) {
711 #if defined(OS_ANDROID)
712 if (plugins::MobileYouTubePlugin::IsYouTubeURL(url
, orig_mime_type
)) {
713 base::StringPiece
template_html(
714 ResourceBundle::GetSharedInstance().GetRawDataResource(
715 IDR_MOBILE_YOUTUBE_PLUGIN_HTML
));
716 return (new plugins::MobileYouTubePlugin(
721 GURL(ChromePluginPlaceholder::kPluginPlaceholderDataURL
)))
725 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type
, url
);
726 placeholder
= ChromePluginPlaceholder::CreateMissingPlugin(
727 render_frame
, frame
, original_params
);
729 // TODO(bauerb): This should be in content/.
730 WebPluginParams
params(original_params
);
731 for (size_t i
= 0; i
< info
.mime_types
.size(); ++i
) {
732 if (info
.mime_types
[i
].mime_type
== actual_mime_type
) {
733 AppendParams(info
.mime_types
[i
].additional_param_names
,
734 info
.mime_types
[i
].additional_param_values
,
735 ¶ms
.attributeNames
, ¶ms
.attributeValues
);
739 if (params
.mimeType
.isNull() && (actual_mime_type
.size() > 0)) {
740 // Webkit might say that mime type is null while we already know the
741 // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case
742 // we should use what we know since WebpluginDelegateProxy does some
743 // specific initializations based on this information.
744 params
.mimeType
= WebString::fromUTF8(actual_mime_type
.c_str());
747 ContentSettingsObserver
* observer
=
748 ContentSettingsObserver::Get(render_frame
);
750 const ContentSettingsType content_type
=
751 ShouldUseJavaScriptSettingForPlugin(info
)
752 ? CONTENT_SETTINGS_TYPE_JAVASCRIPT
753 : CONTENT_SETTINGS_TYPE_PLUGINS
;
756 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
||
757 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
) &&
758 observer
->IsPluginTemporarilyAllowed(identifier
)) {
759 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
763 // In Windows we need to check if we can load NPAPI plugins.
764 // For example, if the render view is in the Ash desktop, we should not.
765 // If user is on ALLOW or DETECT setting, loading needs to be blocked here.
766 if ((status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
||
768 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent
) &&
769 info
.type
== content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
770 if (observer
->AreNPAPIPluginsBlocked())
772 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
;
776 auto create_blocked_plugin
=
777 [&render_frame
, &frame
, ¶ms
, &info
, &identifier
, &group_name
](
778 int template_id
, const base::string16
& message
) {
779 return ChromePluginPlaceholder::CreateBlockedPlugin(
780 render_frame
, frame
, params
, info
, identifier
, group_name
,
781 template_id
, message
, PlaceholderPosterInfo());
783 switch (status_value
) {
784 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
: {
788 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
:
789 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent
: {
790 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
791 const bool is_nacl_plugin
=
792 info
.name
== ASCIIToUTF16(nacl::kNaClPluginName
);
793 const bool is_nacl_mime_type
=
794 actual_mime_type
== nacl::kNaClPluginMimeType
;
795 const bool is_pnacl_mime_type
=
796 actual_mime_type
== nacl::kPnaclPluginMimeType
;
797 if (is_nacl_plugin
|| is_nacl_mime_type
|| is_pnacl_mime_type
) {
798 bool is_nacl_unrestricted
= false;
799 if (is_nacl_mime_type
) {
800 is_nacl_unrestricted
=
801 base::CommandLine::ForCurrentProcess()->HasSwitch(
802 switches::kEnableNaCl
);
803 } else if (is_pnacl_mime_type
) {
804 is_nacl_unrestricted
= true;
808 if (is_nacl_mime_type
|| is_pnacl_mime_type
) {
809 // Normal NaCl/PNaCl embed. The app URL is the page URL.
811 app_url
= frame
->top()->document().url();
813 // NaCl is being invoked as a content handler. Look up the NaCl
814 // module using the MIME type. The app URL is the manifest URL.
815 manifest_url
= GetNaClContentHandlerURL(actual_mime_type
, info
);
816 app_url
= manifest_url
;
818 const Extension
* extension
=
819 g_current_client
->extension_dispatcher_
->extensions()->
820 GetExtensionOrAppByURL(manifest_url
);
821 if (!IsNaClAllowed(manifest_url
,
823 is_nacl_unrestricted
,
826 WebString error_message
;
827 if (is_nacl_mime_type
) {
829 "Only unpacked extensions and apps installed from the Chrome "
830 "Web Store can load NaCl modules without enabling Native "
831 "Client in about:flags.";
832 } else if (is_pnacl_mime_type
) {
834 "Portable Native Client must not be disabled in about:flags.";
836 frame
->addMessageToConsole(
837 WebConsoleMessage(WebConsoleMessage::LevelError
,
839 placeholder
= create_blocked_plugin(
840 IDR_BLOCKED_PLUGIN_HTML
,
841 #if defined(OS_CHROMEOS)
842 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED
));
844 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
849 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
851 #if defined(ENABLE_PLUGINS)
852 // Delay loading plugins if prerendering.
853 // TODO(mmenke): In the case of prerendering, feed into
854 // ChromeContentRendererClient::CreatePlugin instead, to
855 // reduce the chance of future regressions.
856 bool is_prerendering
=
857 prerender::PrerenderHelper::IsPrerendering(render_frame
);
859 // TODO(tommycli): Plugin Power Saver is disabled on prerendered pages.
860 // This is because the placeholder does not feed back into
861 // ChromeContentRendererClient::CreatePlugin. Because of this, it does
862 // not handle the preroll to UI overlay placeholder flow correctly.
864 // Background tab plugin deferral is disabled for the same reason.
866 // https://crbug.com/471427
867 bool power_saver_enabled
=
870 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent
;
872 if (info
.name
== ASCIIToUTF16(content::kFlashPluginName
))
873 TrackPosterParamPresence(params
, power_saver_enabled
);
875 PlaceholderPosterInfo poster_info
;
876 if (power_saver_enabled
) {
877 poster_info
.poster_attribute
=
878 GetPluginInstancePosterAttribute(params
);
879 poster_info
.base_url
= frame
->document().url();
882 if (is_prerendering
|| !poster_info
.poster_attribute
.empty()) {
883 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
884 render_frame
, frame
, params
, info
, identifier
, group_name
,
885 poster_info
.poster_attribute
.empty() ? IDR_BLOCKED_PLUGIN_HTML
886 : IDR_PLUGIN_POSTER_HTML
,
887 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
),
889 placeholder
->set_blocked_for_prerendering(is_prerendering
);
890 placeholder
->set_power_saver_enabled(power_saver_enabled
);
891 placeholder
->set_allow_loading(true);
895 scoped_ptr
<content::PluginInstanceThrottler
> throttler
;
896 if (power_saver_enabled
) {
897 throttler
= PluginInstanceThrottler::Create();
898 // PluginPreroller manages its own lifetime.
900 render_frame
, frame
, params
, info
, identifier
, group_name
,
901 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
),
905 return render_frame
->CreatePlugin(frame
, info
, params
,
907 #else // !defined(ENABLE_PLUGINS)
908 return render_frame
->CreatePlugin(frame
, info
, params
, nullptr);
909 #endif // defined(ENABLE_PLUGINS)
911 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
: {
912 RenderThread::Get()->RecordAction(
913 UserMetricsAction("Plugin_NPAPINotSupported"));
914 placeholder
= create_blocked_plugin(
915 IDR_BLOCKED_PLUGIN_HTML
,
916 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO
));
917 render_frame
->Send(new ChromeViewHostMsg_NPAPINotSupported(
918 render_frame
->GetRoutingID(), identifier
));
921 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled
: {
922 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type
,
924 placeholder
= create_blocked_plugin(
925 IDR_DISABLED_PLUGIN_HTML
,
926 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED
, group_name
));
929 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked
: {
930 #if defined(ENABLE_PLUGIN_INSTALLATION)
931 placeholder
= create_blocked_plugin(
932 IDR_BLOCKED_PLUGIN_HTML
,
933 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
934 placeholder
->set_allow_loading(true);
935 render_frame
->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
936 render_frame
->GetRoutingID(), placeholder
->CreateRoutingId(),
943 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed
: {
944 placeholder
= create_blocked_plugin(
945 IDR_BLOCKED_PLUGIN_HTML
,
946 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
949 case ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
: {
950 placeholder
= create_blocked_plugin(
951 IDR_BLOCKED_PLUGIN_HTML
,
952 l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED
, group_name
));
953 placeholder
->set_allow_loading(true);
954 if (info
.type
!= content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
955 render_frame
->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin(
956 render_frame
->GetRoutingID(),
960 observer
->DidBlockContentType(content_type
, group_name
);
963 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
: {
964 placeholder
= create_blocked_plugin(
965 IDR_BLOCKED_PLUGIN_HTML
,
966 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
967 placeholder
->set_allow_loading(true);
968 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked"));
969 observer
->DidBlockContentType(content_type
, group_name
);
972 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy
: {
973 placeholder
= create_blocked_plugin(
974 IDR_BLOCKED_PLUGIN_HTML
,
975 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
976 placeholder
->set_allow_loading(false);
977 RenderThread::Get()->RecordAction(
978 UserMetricsAction("Plugin_BlockedByPolicy"));
979 observer
->DidBlockContentType(content_type
, group_name
);
984 placeholder
->SetStatus(status
);
985 return placeholder
->plugin();
988 // For NaCl content handling plugins, the NaCl manifest is stored in an
989 // additonal 'nacl' param associated with the MIME type.
991 GURL
ChromeContentRendererClient::GetNaClContentHandlerURL(
992 const std::string
& actual_mime_type
,
993 const content::WebPluginInfo
& plugin
) {
994 // Look for the manifest URL among the MIME type's additonal parameters.
995 const char kNaClPluginManifestAttribute
[] = "nacl";
996 base::string16 nacl_attr
= ASCIIToUTF16(kNaClPluginManifestAttribute
);
997 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
998 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
999 const content::WebPluginMimeType
& content_type
= plugin
.mime_types
[i
];
1000 for (size_t i
= 0; i
< content_type
.additional_param_names
.size(); ++i
) {
1001 if (content_type
.additional_param_names
[i
] == nacl_attr
)
1002 return GURL(content_type
.additional_param_values
[i
]);
1010 #if !defined(DISABLE_NACL)
1012 bool ChromeContentRendererClient::IsNaClAllowed(
1013 const GURL
& manifest_url
,
1014 const GURL
& app_url
,
1015 bool is_nacl_unrestricted
,
1016 const Extension
* extension
,
1017 WebPluginParams
* params
) {
1018 // Temporarily allow these whitelisted apps and WebUIs to use NaCl.
1019 std::string app_url_host
= app_url
.host();
1020 std::string manifest_url_path
= manifest_url
.path();
1022 bool is_whitelisted_web_ui
=
1023 app_url
.spec() == chrome::kChromeUIAppListStartPageURL
;
1026 // Whitelisted apps must be served over https.
1027 app_url
.SchemeIs("https") &&
1028 manifest_url
.SchemeIs("https") &&
1029 (EndsWith(app_url_host
, "plus.google.com", false) ||
1030 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
1031 manifest_url
.DomainIs("ssl.gstatic.com") &&
1032 (manifest_url_path
.find("s2/oz/nacl/") == 1 ||
1033 manifest_url_path
.find("photos/nacl/") == 1);
1035 std::string manifest_fs_host
;
1036 if (manifest_url
.SchemeIsFileSystem() && manifest_url
.inner_url()) {
1037 manifest_fs_host
= manifest_url
.inner_url()->host();
1039 bool is_hangouts_app
=
1040 // Whitelisted apps must be served over secure scheme.
1041 app_url
.SchemeIs("https") &&
1042 manifest_url
.SchemeIsSecure() &&
1043 manifest_url
.SchemeIsFileSystem() &&
1044 (EndsWith(app_url_host
, "talkgadget.google.com", false) ||
1045 EndsWith(app_url_host
, "plus.google.com", false) ||
1046 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
1047 // The manifest must be loaded from the host's FileSystem.
1048 (manifest_fs_host
== app_url_host
);
1050 bool is_whitelisted_app
= is_photo_app
|| is_hangouts_app
;
1052 bool is_extension_from_webstore
= false;
1053 bool is_invoked_by_hosted_app
= false;
1054 bool is_extension_unrestricted
= false;
1055 #if defined(ENABLE_EXTENSIONS)
1056 is_extension_from_webstore
= extension
&& extension
->from_webstore();
1058 is_invoked_by_hosted_app
= extension
&&
1059 extension
->is_hosted_app() &&
1060 extension
->web_extent().MatchesURL(app_url
);
1062 // Allow built-in extensions and extensions under development.
1063 is_extension_unrestricted
= extension
&&
1064 (extension
->location() == extensions::Manifest::COMPONENT
||
1065 extensions::Manifest::IsUnpackedLocation(extension
->location()));
1066 #endif // defined(ENABLE_EXTENSIONS)
1068 bool is_invoked_by_extension
= app_url
.SchemeIs("chrome-extension");
1070 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces.
1071 bool is_nacl_pdf_viewer
=
1072 (is_extension_from_webstore
&&
1073 manifest_url
.SchemeIs("chrome-extension") &&
1074 manifest_url
.host() == "acadkphlmlegjaadjagenfimbpphcgnh");
1076 // Allow Chrome Web Store extensions, built-in extensions and extensions
1077 // under development if the invocation comes from a URL with an extension
1078 // scheme. Also allow invocations if they are from whitelisted URLs or
1079 // if --enable-nacl is set.
1080 bool is_nacl_allowed
= is_nacl_unrestricted
||
1081 is_whitelisted_web_ui
||
1082 is_whitelisted_app
||
1083 is_nacl_pdf_viewer
||
1084 is_invoked_by_hosted_app
||
1085 (is_invoked_by_extension
&&
1086 (is_extension_from_webstore
||
1087 is_extension_unrestricted
));
1088 if (is_nacl_allowed
) {
1089 bool app_can_use_dev_interfaces
= is_nacl_pdf_viewer
;
1090 // Make sure that PPAPI 'dev' interfaces aren't available for production
1091 // apps unless they're whitelisted.
1092 WebString dev_attribute
= WebString::fromUTF8("@dev");
1093 if ((!is_whitelisted_app
&& !is_extension_from_webstore
) ||
1094 app_can_use_dev_interfaces
) {
1095 // Add the special '@dev' attribute.
1096 std::vector
<base::string16
> param_names
;
1097 std::vector
<base::string16
> param_values
;
1098 param_names
.push_back(dev_attribute
);
1099 param_values
.push_back(WebString());
1103 ¶ms
->attributeNames
,
1104 ¶ms
->attributeValues
);
1106 // If the params somehow contain '@dev', remove it.
1107 size_t attribute_count
= params
->attributeNames
.size();
1108 for (size_t i
= 0; i
< attribute_count
; ++i
) {
1109 if (params
->attributeNames
[i
].equals(dev_attribute
))
1110 params
->attributeNames
[i
] = WebString();
1114 return is_nacl_allowed
;
1116 #endif // defined(DISABLE_NACL)
1118 bool ChromeContentRendererClient::HasErrorPage(int http_status_code
,
1119 std::string
* error_domain
) {
1120 // Use an internal error page, if we have one for the status code.
1121 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain
,
1122 http_status_code
)) {
1126 *error_domain
= LocalizedError::kHttpErrorDomain
;
1130 bool ChromeContentRendererClient::ShouldSuppressErrorPage(
1131 content::RenderFrame
* render_frame
,
1133 // Unit tests for ChromeContentRendererClient pass a NULL RenderFrame here.
1134 // Unfortunately it's very difficult to construct a mock RenderView, so skip
1135 // this functionality in this case.
1137 content::RenderView
* render_view
= render_frame
->GetRenderView();
1138 content::RenderFrame
* main_render_frame
= render_view
->GetMainRenderFrame();
1139 blink::WebFrame
* web_frame
= render_frame
->GetWebFrame();
1140 NetErrorHelper
* net_error_helper
= NetErrorHelper::Get(main_render_frame
);
1141 if (net_error_helper
->ShouldSuppressErrorPage(web_frame
, url
))
1144 // Do not flash an error page if the Instant new tab page fails to load.
1145 return search_bouncer_
.get() && search_bouncer_
->IsNewTabPage(url
);
1148 void ChromeContentRendererClient::GetNavigationErrorStrings(
1149 content::RenderView
* render_view
,
1150 blink::WebFrame
* frame
,
1151 const blink::WebURLRequest
& failed_request
,
1152 const blink::WebURLError
& error
,
1153 std::string
* error_html
,
1154 base::string16
* error_description
) {
1155 const GURL failed_url
= error
.unreachableURL
;
1156 const Extension
* extension
= NULL
;
1158 #if defined(ENABLE_EXTENSIONS)
1159 if (failed_url
.is_valid() &&
1160 !failed_url
.SchemeIs(extensions::kExtensionScheme
)) {
1161 extension
= extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(
1166 bool is_post
= EqualsASCII(failed_request
.httpMethod(), "POST");
1169 bool extension_but_not_bookmark_app
= false;
1170 #if defined(ENABLE_EXTENSIONS)
1171 extension_but_not_bookmark_app
= extension
&& !extension
->from_bookmark();
1173 // Use a local error page.
1174 if (extension_but_not_bookmark_app
) {
1175 #if defined(ENABLE_EXTENSIONS)
1176 // TODO(erikkay): Should we use a different template for different
1178 int resource_id
= IDR_ERROR_APP_HTML
;
1179 const base::StringPiece
template_html(
1180 ResourceBundle::GetSharedInstance().GetRawDataResource(
1182 if (template_html
.empty()) {
1183 NOTREACHED() << "unable to load template. ID: " << resource_id
;
1185 base::DictionaryValue error_strings
;
1186 const std::string locale
= RenderThread::Get()->GetLocale();
1187 LocalizedError::GetAppErrorStrings(failed_url
, extension
, locale
,
1189 // "t" is the id of the template's root node.
1190 *error_html
= webui::GetTemplatesHtml(template_html
, &error_strings
,
1195 // TODO(ellyjones): change GetNavigationErrorStrings to take a RenderFrame
1196 // instead of a RenderView, then pass that in.
1197 // This is safe for now because we only install the NetErrorHelper on the
1198 // main render frame anyway; see the TODO(ellyjones) in
1199 // RenderFrameCreated.
1200 content::RenderFrame
* main_render_frame
=
1201 render_view
->GetMainRenderFrame();
1202 NetErrorHelper
* helper
= NetErrorHelper::Get(main_render_frame
);
1203 helper
->GetErrorHTML(frame
, error
, is_post
, error_html
);
1207 if (error_description
) {
1209 *error_description
= LocalizedError::GetErrorDetails(error
, is_post
);
1213 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
1214 #if defined(ENABLE_EXTENSIONS)
1215 return !IsStandaloneExtensionProcess();
1221 bool ChromeContentRendererClient::AllowPopup() {
1222 #if defined(ENABLE_EXTENSIONS)
1223 extensions::ScriptContext
* current_context
=
1224 extension_dispatcher_
->script_context_set().GetCurrent();
1225 if (!current_context
|| !current_context
->extension())
1227 // See http://crbug.com/117446 for the subtlety of this check.
1228 switch (current_context
->context_type()) {
1229 case extensions::Feature::UNSPECIFIED_CONTEXT
:
1230 case extensions::Feature::WEB_PAGE_CONTEXT
:
1231 case extensions::Feature::UNBLESSED_EXTENSION_CONTEXT
:
1232 case extensions::Feature::WEBUI_CONTEXT
:
1234 case extensions::Feature::BLESSED_EXTENSION_CONTEXT
:
1235 case extensions::Feature::CONTENT_SCRIPT_CONTEXT
:
1237 case extensions::Feature::BLESSED_WEB_PAGE_CONTEXT
:
1238 return !current_context
->web_frame()->parent();
1245 bool ChromeContentRendererClient::ShouldFork(blink::WebFrame
* frame
,
1247 const std::string
& http_method
,
1248 bool is_initial_navigation
,
1249 bool is_server_redirect
,
1250 bool* send_referrer
) {
1251 DCHECK(!frame
->parent());
1253 // If this is the Instant process, fork all navigations originating from the
1254 // renderer. The destination page will then be bucketed back to this Instant
1255 // process if it is an Instant url, or to another process if not. Conversely,
1256 // fork if this is a non-Instant process navigating to an Instant url, so that
1257 // such navigations can also be bucketed into an Instant renderer.
1258 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1259 switches::kInstantProcess
) ||
1260 (search_bouncer_
.get() && search_bouncer_
->ShouldFork(url
))) {
1261 *send_referrer
= true;
1265 // For now, we skip the rest for POST submissions. This is because
1266 // http://crbug.com/101395 is more likely to cause compatibility issues
1267 // with hosted apps and extensions than WebUI pages. We will remove this
1268 // check when cross-process POST submissions are supported.
1269 if (http_method
!= "GET")
1272 // If |url| matches one of the prerendered URLs, stop this navigation and try
1273 // to swap in the prerendered page on the browser process. If the prerendered
1274 // page no longer exists by the time the OpenURL IPC is handled, a normal
1275 // navigation is attempted.
1276 if (prerender_dispatcher_
.get() &&
1277 prerender_dispatcher_
->IsPrerenderURL(url
)) {
1278 *send_referrer
= true;
1282 #if defined(ENABLE_EXTENSIONS)
1283 const extensions::ExtensionSet
* extensions
=
1284 extension_dispatcher_
->extensions();
1286 // Determine if the new URL is an extension (excluding bookmark apps).
1287 const Extension
* new_url_extension
= extensions::GetNonBookmarkAppExtension(
1289 bool is_extension_url
= !!new_url_extension
;
1291 // If the navigation would cross an app extent boundary, we also need
1292 // to defer to the browser to ensure process isolation. This is not necessary
1293 // for server redirects, which will be transferred to a new process by the
1294 // browser process when they are ready to commit. It is necessary for client
1295 // redirects, which won't be transferred in the same way.
1296 if (!is_server_redirect
&&
1297 CrossesExtensionExtents(frame
, url
, *extensions
, is_extension_url
,
1298 is_initial_navigation
)) {
1299 // Include the referrer in this case since we're going from a hosted web
1300 // page. (the packaged case is handled previously by the extension
1302 *send_referrer
= true;
1304 const Extension
* extension
=
1305 extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(url
);
1306 if (extension
&& extension
->is_app()) {
1307 extensions::RecordAppLaunchType(
1308 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION
, extension
->GetType());
1313 // If this is a reload, check whether it has the wrong process type. We
1314 // should send it to the browser if it's an extension URL (e.g., hosted app)
1315 // in a normal process, or if it's a process for an extension that has been
1317 if (frame
->top()->document().url() == url
) {
1318 if (is_extension_url
!= IsStandaloneExtensionProcess())
1321 #endif // defined(ENABLE_EXTENSIONS)
1326 #if defined(ENABLE_EXTENSIONS)
1327 bool ChromeContentRendererClient::ShouldForwardToGuestContainer(
1328 const IPC::Message
& msg
) {
1329 return extensions::GuestViewContainer::HandlesMessage(msg
);
1333 bool ChromeContentRendererClient::WillSendRequest(
1334 blink::WebFrame
* frame
,
1335 ui::PageTransition transition_type
,
1337 const GURL
& first_party_for_cookies
,
1339 // Check whether the request should be allowed. If not allowed, we reset the
1340 // URL to something invalid to prevent the request and cause an error.
1341 #if defined(ENABLE_EXTENSIONS)
1342 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1343 !extensions::ResourceRequestPolicy::CanRequestResource(
1347 extension_dispatcher_
->extensions())) {
1348 *new_url
= GURL(chrome::kExtensionInvalidRequestURL
);
1352 if (url
.SchemeIs(extensions::kExtensionResourceScheme
) &&
1353 !extensions::ResourceRequestPolicy::CanRequestExtensionResourceScheme(
1356 *new_url
= GURL(chrome::kExtensionResourceInvalidRequestURL
);
1361 const content::RenderView
* render_view
=
1362 content::RenderView::FromWebView(frame
->view());
1363 SearchBox
* search_box
= SearchBox::Get(render_view
);
1364 if (search_box
&& url
.SchemeIs(chrome::kChromeSearchScheme
)) {
1365 SearchBox::ImageSourceType type
= SearchBox::NONE
;
1366 if (url
.host() == chrome::kChromeUIFaviconHost
)
1367 type
= SearchBox::FAVICON
;
1368 else if (url
.host() == chrome::kChromeUILargeIconHost
)
1369 type
= SearchBox::LARGE_ICON
;
1370 else if (url
.host() == chrome::kChromeUIFallbackIconHost
)
1371 type
= SearchBox::FALLBACK_ICON
;
1372 else if (url
.host() == chrome::kChromeUIThumbnailHost
)
1373 type
= SearchBox::THUMB
;
1374 if (type
!= SearchBox::NONE
)
1375 return search_box
->GenerateImageURLFromTransientURL(url
, type
, new_url
);
1381 unsigned long long ChromeContentRendererClient::VisitedLinkHash(
1382 const char* canonical_url
, size_t length
) {
1383 return visited_link_slave_
->ComputeURLFingerprint(canonical_url
, length
);
1386 bool ChromeContentRendererClient::IsLinkVisited(unsigned long long link_hash
) {
1387 return visited_link_slave_
->IsVisited(link_hash
);
1390 blink::WebPrescientNetworking
*
1391 ChromeContentRendererClient::GetPrescientNetworking() {
1392 return prescient_networking_dispatcher_
.get();
1395 bool ChromeContentRendererClient::ShouldOverridePageVisibilityState(
1396 const content::RenderFrame
* render_frame
,
1397 blink::WebPageVisibilityState
* override_state
) {
1398 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
))
1401 *override_state
= blink::WebPageVisibilityStatePrerender
;
1405 #if defined(ENABLE_EXTENSIONS)
1406 void ChromeContentRendererClient::SetExtensionDispatcherForTest(
1407 extensions::Dispatcher
* extension_dispatcher
) {
1408 extension_dispatcher_
.reset(extension_dispatcher
);
1409 permissions_policy_delegate_
.reset(
1410 new extensions::RendererPermissionsPolicyDelegate(
1411 extension_dispatcher_
.get()));
1414 extensions::Dispatcher
*
1415 ChromeContentRendererClient::GetExtensionDispatcherForTest() {
1416 return extension_dispatcher_
.get();
1419 bool ChromeContentRendererClient::CrossesExtensionExtents(
1420 blink::WebFrame
* frame
,
1421 const GURL
& new_url
,
1422 const extensions::ExtensionSet
& extensions
,
1423 bool is_extension_url
,
1424 bool is_initial_navigation
) {
1425 GURL
old_url(frame
->top()->document().url());
1427 // If old_url is still empty and this is an initial navigation, then this is
1428 // a window.open operation. We should look at the opener URL.
1429 if (is_initial_navigation
&& old_url
.is_empty() && frame
->opener()) {
1430 // If we're about to open a normal web page from a same-origin opener stuck
1431 // in an extension process, we want to keep it in process to allow the
1432 // opener to script it.
1433 WebDocument opener_document
= frame
->opener()->document();
1434 WebSecurityOrigin opener
= frame
->opener()->document().securityOrigin();
1435 bool opener_is_extension_url
=
1436 !opener
.isUnique() && extensions
.GetExtensionOrAppByURL(
1437 opener_document
.url()) != NULL
;
1438 if (!is_extension_url
&&
1439 !opener_is_extension_url
&&
1440 IsStandaloneExtensionProcess() &&
1441 opener
.canRequest(WebURL(new_url
)))
1444 // In all other cases, we want to compare against the top frame's URL (as
1445 // opposed to the opener frame's), since that's what determines the type of
1446 // process. This allows iframes outside an app to open a popup in the app.
1447 old_url
= frame
->top()->opener()->top()->document().url();
1450 // Only consider keeping non-app URLs in an app process if this window
1451 // has an opener (in which case it might be an OAuth popup that tries to
1452 // script an iframe within the app).
1453 bool should_consider_workaround
= !!frame
->opener();
1455 return extensions::CrossesExtensionProcessBoundary(
1456 extensions
, old_url
, new_url
, should_consider_workaround
);
1458 #endif // defined(ENABLE_EXTENSIONS)
1460 #if defined(ENABLE_SPELLCHECK)
1461 void ChromeContentRendererClient::SetSpellcheck(SpellCheck
* spellcheck
) {
1462 RenderThread
* thread
= RenderThread::Get();
1463 if (spellcheck_
.get() && thread
)
1464 thread
->RemoveObserver(spellcheck_
.get());
1465 spellcheck_
.reset(spellcheck
);
1466 SpellCheckReplacer
replacer(spellcheck_
.get());
1467 content::RenderView::ForEach(&replacer
);
1469 thread
->AddObserver(spellcheck_
.get());
1474 bool ChromeContentRendererClient::WasWebRequestUsedBySomeExtensions() {
1475 #if defined(ENABLE_EXTENSIONS)
1476 return g_current_client
->extension_dispatcher_
1477 ->WasWebRequestUsedBySomeExtensions();
1483 const void* ChromeContentRendererClient::CreatePPAPIInterface(
1484 const std::string
& interface_name
) {
1485 #if defined(ENABLE_PLUGINS)
1486 #if !defined(DISABLE_NACL)
1487 if (interface_name
== PPB_NACL_PRIVATE_INTERFACE
)
1488 return nacl::GetNaClPrivateInterface();
1489 #endif // DISABLE_NACL
1490 if (interface_name
== PPB_PDF_INTERFACE
)
1491 return pdf::PPB_PDF_Impl::GetInterface();
1496 bool ChromeContentRendererClient::IsExternalPepperPlugin(
1497 const std::string
& module_name
) {
1498 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
1499 // We must defer certain plugin events for NaCl instances since we switch
1500 // from the in-process to the out-of-process proxy after instantiating them.
1501 return module_name
== "Native Client";
1504 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1505 bool ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
1506 const GURL
& url
, const std::set
<std::string
>& whitelist
) {
1507 const extensions::ExtensionSet
* extension_set
=
1508 g_current_client
->extension_dispatcher_
->extensions();
1509 return chrome::IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
1514 blink::WebSpeechSynthesizer
*
1515 ChromeContentRendererClient::OverrideSpeechSynthesizer(
1516 blink::WebSpeechSynthesizerClient
* client
) {
1517 return new TtsDispatcher(client
);
1520 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI(
1522 #if !defined(OS_ANDROID)
1523 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check
1524 // the whitelist in the renderer, since we're only preventing access until
1525 // these APIs are public and stable.
1526 std::string url_host
= url
.host();
1527 if (url
.SchemeIs("https") &&
1528 (EndsWith(url_host
, "talkgadget.google.com", false) ||
1529 EndsWith(url_host
, "plus.google.com", false) ||
1530 EndsWith(url_host
, "plus.sandbox.google.com", false)) &&
1531 StartsWithASCII(url
.path(), "/hangouts/", false)) {
1534 // Allow access for tests.
1535 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1536 switches::kEnablePepperTesting
)) {
1539 #endif // !defined(OS_ANDROID)
1543 void ChromeContentRendererClient::AddKeySystems(
1544 std::vector
<media::KeySystemInfo
>* key_systems
) {
1545 AddChromeKeySystems(key_systems
);
1548 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource(
1549 const base::string16
& source
) const {
1550 #if defined(ENABLE_EXTENSIONS)
1551 return extensions::IsSourceFromAnExtension(source
);
1557 bool ChromeContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
1558 // SiteIsolationPolicy is off by default. We would like to activate cross-site
1559 // document blocking (for UMA data collection) for normal renderer processes
1560 // running a normal web page from the Internet. We only turn on
1561 // SiteIsolationPolicy for a renderer process that does not have the extension
1563 #if defined(ENABLE_EXTENSIONS)
1564 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
1565 return !command_line
->HasSwitch(extensions::switches::kExtensionProcess
);
1571 blink::WebWorkerContentSettingsClientProxy
*
1572 ChromeContentRendererClient::CreateWorkerContentSettingsClientProxy(
1573 content::RenderFrame
* render_frame
,
1574 blink::WebFrame
* frame
) {
1575 return new WorkerContentSettingsClientProxy(render_frame
, frame
);
1578 bool ChromeContentRendererClient::IsPluginAllowedToUseDevChannelAPIs() {
1579 #if defined(ENABLE_PLUGINS)
1580 // Allow access for tests.
1581 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1582 switches::kEnablePepperTesting
)) {
1586 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1587 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
1588 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
1589 // Chromium builds as well.
1590 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1596 bool ChromeContentRendererClient::IsPluginAllowedToUseCameraDeviceAPI(
1598 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1599 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1600 switches::kEnablePepperTesting
))
1603 if (IsExtensionOrSharedModuleWhitelisted(url
, allowed_camera_device_origins_
))
1610 bool ChromeContentRendererClient::IsPluginAllowedToUseCompositorAPI(
1612 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1613 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1614 switches::kEnablePepperTesting
))
1616 if (IsExtensionOrSharedModuleWhitelisted(url
, allowed_compositor_origins_
))
1619 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1620 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1626 content::BrowserPluginDelegate
*
1627 ChromeContentRendererClient::CreateBrowserPluginDelegate(
1628 content::RenderFrame
* render_frame
,
1629 const std::string
& mime_type
,
1630 const GURL
& original_url
) {
1631 #if defined(ENABLE_EXTENSIONS)
1632 if (mime_type
== content::kBrowserPluginMimeType
) {
1633 return new extensions::ExtensionsGuestViewContainer(render_frame
);
1635 return new extensions::MimeHandlerViewContainer(
1636 render_frame
, mime_type
, original_url
);