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(this));
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
;
762 #if defined(ENABLE_PLUGINS)
763 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
&&
764 base::CommandLine::ForCurrentProcess()->HasSwitch(
765 switches::kEnablePluginPowerSaver
)) {
767 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent
;
772 // In Windows we need to check if we can load NPAPI plugins.
773 // For example, if the render view is in the Ash desktop, we should not.
774 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
&&
775 info
.type
== content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
776 if (observer
->AreNPAPIPluginsBlocked())
778 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
;
782 auto create_blocked_plugin
=
783 [&render_frame
, &frame
, ¶ms
, &info
, &identifier
, &group_name
](
784 int template_id
, const base::string16
& message
) {
785 return ChromePluginPlaceholder::CreateBlockedPlugin(
786 render_frame
, frame
, params
, info
, identifier
, group_name
,
787 template_id
, message
, std::string(), GURL());
789 switch (status_value
) {
790 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
: {
794 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
:
795 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent
: {
796 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
797 const bool is_nacl_plugin
=
798 info
.name
== ASCIIToUTF16(nacl::kNaClPluginName
);
799 const bool is_nacl_mime_type
=
800 actual_mime_type
== nacl::kNaClPluginMimeType
;
801 const bool is_pnacl_mime_type
=
802 actual_mime_type
== nacl::kPnaclPluginMimeType
;
803 if (is_nacl_plugin
|| is_nacl_mime_type
|| is_pnacl_mime_type
) {
804 bool is_nacl_unrestricted
= false;
805 if (is_nacl_mime_type
) {
806 is_nacl_unrestricted
=
807 base::CommandLine::ForCurrentProcess()->HasSwitch(
808 switches::kEnableNaCl
);
809 } else if (is_pnacl_mime_type
) {
810 is_nacl_unrestricted
= true;
814 if (is_nacl_mime_type
|| is_pnacl_mime_type
) {
815 // Normal NaCl/PNaCl embed. The app URL is the page URL.
817 app_url
= frame
->top()->document().url();
819 // NaCl is being invoked as a content handler. Look up the NaCl
820 // module using the MIME type. The app URL is the manifest URL.
821 manifest_url
= GetNaClContentHandlerURL(actual_mime_type
, info
);
822 app_url
= manifest_url
;
824 const Extension
* extension
=
825 g_current_client
->extension_dispatcher_
->extensions()->
826 GetExtensionOrAppByURL(manifest_url
);
827 if (!IsNaClAllowed(manifest_url
,
829 is_nacl_unrestricted
,
832 WebString error_message
;
833 if (is_nacl_mime_type
) {
835 "Only unpacked extensions and apps installed from the Chrome "
836 "Web Store can load NaCl modules without enabling Native "
837 "Client in about:flags.";
838 } else if (is_pnacl_mime_type
) {
840 "Portable Native Client must not be disabled in about:flags.";
842 frame
->addMessageToConsole(
843 WebConsoleMessage(WebConsoleMessage::LevelError
,
845 placeholder
= create_blocked_plugin(
846 IDR_BLOCKED_PLUGIN_HTML
,
847 #if defined(OS_CHROMEOS)
848 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED
));
850 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
855 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
857 #if defined(ENABLE_PLUGINS)
858 bool power_saver_enabled
=
860 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent
;
861 bool blocked_for_background_tab
=
862 render_frame
->IsHidden() && power_saver_enabled
;
864 if (info
.name
== ASCIIToUTF16(content::kFlashPluginName
))
865 TrackPosterParamPresence(params
, power_saver_enabled
);
867 std::string poster_attribute
;
868 if (power_saver_enabled
)
869 poster_attribute
= GetPluginInstancePosterAttribute(params
);
871 // Delay loading plugins if prerendering.
872 // TODO(mmenke): In the case of prerendering, feed into
873 // ChromeContentRendererClient::CreatePlugin instead, to
874 // reduce the chance of future regressions.
875 bool is_prerendering
=
876 prerender::PrerenderHelper::IsPrerendering(render_frame
);
877 if (blocked_for_background_tab
|| is_prerendering
||
878 !poster_attribute
.empty()) {
879 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
880 render_frame
, frame
, params
, info
, identifier
, group_name
,
881 poster_attribute
.empty() ? IDR_BLOCKED_PLUGIN_HTML
882 : IDR_PLUGIN_POSTER_HTML
,
883 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
),
884 poster_attribute
, frame
->document().url());
885 placeholder
->set_blocked_for_background_tab(
886 blocked_for_background_tab
);
887 placeholder
->set_blocked_for_prerendering(is_prerendering
);
888 placeholder
->set_power_saver_enabled(power_saver_enabled
);
889 placeholder
->set_allow_loading(true);
893 scoped_ptr
<content::PluginInstanceThrottler
> throttler
=
894 PluginInstanceThrottler::Create(power_saver_enabled
);
895 if (power_saver_enabled
) {
896 // PluginPreroller manages its own lifetime.
898 render_frame
, frame
, params
, info
, identifier
, group_name
,
899 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
),
903 return render_frame
->CreatePlugin(frame
, info
, params
,
905 #else // !defined(ENABLE_PLUGINS)
906 return render_frame
->CreatePlugin(frame
, info
, params
, nullptr);
907 #endif // defined(ENABLE_PLUGINS)
909 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
: {
910 RenderThread::Get()->RecordAction(
911 UserMetricsAction("Plugin_NPAPINotSupported"));
912 placeholder
= create_blocked_plugin(
913 IDR_BLOCKED_PLUGIN_HTML
,
914 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO
));
915 render_frame
->Send(new ChromeViewHostMsg_NPAPINotSupported(
916 render_frame
->GetRoutingID(), identifier
));
919 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled
: {
920 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type
,
922 placeholder
= create_blocked_plugin(
923 IDR_DISABLED_PLUGIN_HTML
,
924 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED
, group_name
));
927 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked
: {
928 #if defined(ENABLE_PLUGIN_INSTALLATION)
929 placeholder
= create_blocked_plugin(
930 IDR_BLOCKED_PLUGIN_HTML
,
931 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
932 placeholder
->set_allow_loading(true);
933 render_frame
->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
934 render_frame
->GetRoutingID(), placeholder
->CreateRoutingId(),
941 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed
: {
942 placeholder
= create_blocked_plugin(
943 IDR_BLOCKED_PLUGIN_HTML
,
944 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
947 case ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
: {
948 placeholder
= create_blocked_plugin(
949 IDR_BLOCKED_PLUGIN_HTML
,
950 l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED
, group_name
));
951 placeholder
->set_allow_loading(true);
952 if (info
.type
!= content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
953 render_frame
->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin(
954 render_frame
->GetRoutingID(),
958 observer
->DidBlockContentType(content_type
, group_name
);
961 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
: {
962 placeholder
= create_blocked_plugin(
963 IDR_BLOCKED_PLUGIN_HTML
,
964 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
965 placeholder
->set_allow_loading(true);
966 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked"));
967 observer
->DidBlockContentType(content_type
, group_name
);
970 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy
: {
971 placeholder
= create_blocked_plugin(
972 IDR_BLOCKED_PLUGIN_HTML
,
973 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
974 placeholder
->set_allow_loading(false);
975 RenderThread::Get()->RecordAction(
976 UserMetricsAction("Plugin_BlockedByPolicy"));
977 observer
->DidBlockContentType(content_type
, group_name
);
982 placeholder
->SetStatus(status
);
983 return placeholder
->plugin();
986 // For NaCl content handling plugins, the NaCl manifest is stored in an
987 // additonal 'nacl' param associated with the MIME type.
989 GURL
ChromeContentRendererClient::GetNaClContentHandlerURL(
990 const std::string
& actual_mime_type
,
991 const content::WebPluginInfo
& plugin
) {
992 // Look for the manifest URL among the MIME type's additonal parameters.
993 const char kNaClPluginManifestAttribute
[] = "nacl";
994 base::string16 nacl_attr
= ASCIIToUTF16(kNaClPluginManifestAttribute
);
995 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
996 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
997 const content::WebPluginMimeType
& content_type
= plugin
.mime_types
[i
];
998 for (size_t i
= 0; i
< content_type
.additional_param_names
.size(); ++i
) {
999 if (content_type
.additional_param_names
[i
] == nacl_attr
)
1000 return GURL(content_type
.additional_param_values
[i
]);
1008 #if !defined(DISABLE_NACL)
1010 bool ChromeContentRendererClient::IsNaClAllowed(
1011 const GURL
& manifest_url
,
1012 const GURL
& app_url
,
1013 bool is_nacl_unrestricted
,
1014 const Extension
* extension
,
1015 WebPluginParams
* params
) {
1016 // Temporarily allow these whitelisted apps and WebUIs to use NaCl.
1017 std::string app_url_host
= app_url
.host();
1018 std::string manifest_url_path
= manifest_url
.path();
1020 bool is_whitelisted_web_ui
=
1021 app_url
.spec() == chrome::kChromeUIAppListStartPageURL
;
1024 // Whitelisted apps must be served over https.
1025 app_url
.SchemeIs("https") &&
1026 manifest_url
.SchemeIs("https") &&
1027 (EndsWith(app_url_host
, "plus.google.com", false) ||
1028 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
1029 manifest_url
.DomainIs("ssl.gstatic.com") &&
1030 (manifest_url_path
.find("s2/oz/nacl/") == 1 ||
1031 manifest_url_path
.find("photos/nacl/") == 1);
1033 std::string manifest_fs_host
;
1034 if (manifest_url
.SchemeIsFileSystem() && manifest_url
.inner_url()) {
1035 manifest_fs_host
= manifest_url
.inner_url()->host();
1037 bool is_hangouts_app
=
1038 // Whitelisted apps must be served over secure scheme.
1039 app_url
.SchemeIs("https") &&
1040 manifest_url
.SchemeIsSecure() &&
1041 manifest_url
.SchemeIsFileSystem() &&
1042 (EndsWith(app_url_host
, "talkgadget.google.com", false) ||
1043 EndsWith(app_url_host
, "plus.google.com", false) ||
1044 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
1045 // The manifest must be loaded from the host's FileSystem.
1046 (manifest_fs_host
== app_url_host
);
1048 bool is_whitelisted_app
= is_photo_app
|| is_hangouts_app
;
1050 bool is_extension_from_webstore
= false;
1051 bool is_invoked_by_hosted_app
= false;
1052 bool is_extension_unrestricted
= false;
1053 #if defined(ENABLE_EXTENSIONS)
1054 is_extension_from_webstore
= extension
&& extension
->from_webstore();
1056 is_invoked_by_hosted_app
= extension
&&
1057 extension
->is_hosted_app() &&
1058 extension
->web_extent().MatchesURL(app_url
);
1060 // Allow built-in extensions and extensions under development.
1061 is_extension_unrestricted
= extension
&&
1062 (extension
->location() == extensions::Manifest::COMPONENT
||
1063 extensions::Manifest::IsUnpackedLocation(extension
->location()));
1064 #endif // defined(ENABLE_EXTENSIONS)
1066 bool is_invoked_by_extension
= app_url
.SchemeIs("chrome-extension");
1068 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces.
1069 bool is_nacl_pdf_viewer
=
1070 (is_extension_from_webstore
&&
1071 manifest_url
.SchemeIs("chrome-extension") &&
1072 manifest_url
.host() == "acadkphlmlegjaadjagenfimbpphcgnh");
1074 // Allow Chrome Web Store extensions, built-in extensions and extensions
1075 // under development if the invocation comes from a URL with an extension
1076 // scheme. Also allow invocations if they are from whitelisted URLs or
1077 // if --enable-nacl is set.
1078 bool is_nacl_allowed
= is_nacl_unrestricted
||
1079 is_whitelisted_web_ui
||
1080 is_whitelisted_app
||
1081 is_nacl_pdf_viewer
||
1082 is_invoked_by_hosted_app
||
1083 (is_invoked_by_extension
&&
1084 (is_extension_from_webstore
||
1085 is_extension_unrestricted
));
1086 if (is_nacl_allowed
) {
1087 bool app_can_use_dev_interfaces
= is_nacl_pdf_viewer
;
1088 // Make sure that PPAPI 'dev' interfaces aren't available for production
1089 // apps unless they're whitelisted.
1090 WebString dev_attribute
= WebString::fromUTF8("@dev");
1091 if ((!is_whitelisted_app
&& !is_extension_from_webstore
) ||
1092 app_can_use_dev_interfaces
) {
1093 // Add the special '@dev' attribute.
1094 std::vector
<base::string16
> param_names
;
1095 std::vector
<base::string16
> param_values
;
1096 param_names
.push_back(dev_attribute
);
1097 param_values
.push_back(WebString());
1101 ¶ms
->attributeNames
,
1102 ¶ms
->attributeValues
);
1104 // If the params somehow contain '@dev', remove it.
1105 size_t attribute_count
= params
->attributeNames
.size();
1106 for (size_t i
= 0; i
< attribute_count
; ++i
) {
1107 if (params
->attributeNames
[i
].equals(dev_attribute
))
1108 params
->attributeNames
[i
] = WebString();
1112 return is_nacl_allowed
;
1114 #endif // defined(DISABLE_NACL)
1116 bool ChromeContentRendererClient::HasErrorPage(int http_status_code
,
1117 std::string
* error_domain
) {
1118 // Use an internal error page, if we have one for the status code.
1119 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain
,
1120 http_status_code
)) {
1124 *error_domain
= LocalizedError::kHttpErrorDomain
;
1128 bool ChromeContentRendererClient::ShouldSuppressErrorPage(
1129 content::RenderFrame
* render_frame
,
1131 // Unit tests for ChromeContentRendererClient pass a NULL RenderFrame here.
1132 // Unfortunately it's very difficult to construct a mock RenderView, so skip
1133 // this functionality in this case.
1135 content::RenderView
* render_view
= render_frame
->GetRenderView();
1136 content::RenderFrame
* main_render_frame
= render_view
->GetMainRenderFrame();
1137 blink::WebFrame
* web_frame
= render_frame
->GetWebFrame();
1138 NetErrorHelper
* net_error_helper
= NetErrorHelper::Get(main_render_frame
);
1139 if (net_error_helper
->ShouldSuppressErrorPage(web_frame
, url
))
1142 // Do not flash an error page if the Instant new tab page fails to load.
1143 return search_bouncer_
.get() && search_bouncer_
->IsNewTabPage(url
);
1146 void ChromeContentRendererClient::GetNavigationErrorStrings(
1147 content::RenderView
* render_view
,
1148 blink::WebFrame
* frame
,
1149 const blink::WebURLRequest
& failed_request
,
1150 const blink::WebURLError
& error
,
1151 std::string
* error_html
,
1152 base::string16
* error_description
) {
1153 const GURL failed_url
= error
.unreachableURL
;
1154 const Extension
* extension
= NULL
;
1156 #if defined(ENABLE_EXTENSIONS)
1157 if (failed_url
.is_valid() &&
1158 !failed_url
.SchemeIs(extensions::kExtensionScheme
)) {
1159 extension
= extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(
1164 bool is_post
= EqualsASCII(failed_request
.httpMethod(), "POST");
1167 bool extension_but_not_bookmark_app
= false;
1168 #if defined(ENABLE_EXTENSIONS)
1169 extension_but_not_bookmark_app
= extension
&& !extension
->from_bookmark();
1171 // Use a local error page.
1172 if (extension_but_not_bookmark_app
) {
1173 #if defined(ENABLE_EXTENSIONS)
1174 // TODO(erikkay): Should we use a different template for different
1176 int resource_id
= IDR_ERROR_APP_HTML
;
1177 const base::StringPiece
template_html(
1178 ResourceBundle::GetSharedInstance().GetRawDataResource(
1180 if (template_html
.empty()) {
1181 NOTREACHED() << "unable to load template. ID: " << resource_id
;
1183 base::DictionaryValue error_strings
;
1184 const std::string locale
= RenderThread::Get()->GetLocale();
1185 LocalizedError::GetAppErrorStrings(failed_url
, extension
, locale
,
1187 // "t" is the id of the template's root node.
1188 *error_html
= webui::GetTemplatesHtml(template_html
, &error_strings
,
1193 // TODO(ellyjones): change GetNavigationErrorStrings to take a RenderFrame
1194 // instead of a RenderView, then pass that in.
1195 // This is safe for now because we only install the NetErrorHelper on the
1196 // main render frame anyway; see the TODO(ellyjones) in
1197 // RenderFrameCreated.
1198 content::RenderFrame
* main_render_frame
=
1199 render_view
->GetMainRenderFrame();
1200 NetErrorHelper
* helper
= NetErrorHelper::Get(main_render_frame
);
1201 helper
->GetErrorHTML(frame
, error
, is_post
, error_html
);
1205 if (error_description
) {
1207 *error_description
= LocalizedError::GetErrorDetails(error
, is_post
);
1211 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
1212 #if defined(ENABLE_EXTENSIONS)
1213 return !IsStandaloneExtensionProcess();
1219 bool ChromeContentRendererClient::AllowPopup() {
1220 #if defined(ENABLE_EXTENSIONS)
1221 extensions::ScriptContext
* current_context
=
1222 extension_dispatcher_
->script_context_set().GetCurrent();
1223 if (!current_context
|| !current_context
->extension())
1225 // See http://crbug.com/117446 for the subtlety of this check.
1226 switch (current_context
->context_type()) {
1227 case extensions::Feature::UNSPECIFIED_CONTEXT
:
1228 case extensions::Feature::WEB_PAGE_CONTEXT
:
1229 case extensions::Feature::UNBLESSED_EXTENSION_CONTEXT
:
1230 case extensions::Feature::WEBUI_CONTEXT
:
1232 case extensions::Feature::BLESSED_EXTENSION_CONTEXT
:
1233 case extensions::Feature::CONTENT_SCRIPT_CONTEXT
:
1235 case extensions::Feature::BLESSED_WEB_PAGE_CONTEXT
:
1236 return !current_context
->web_frame()->parent();
1243 bool ChromeContentRendererClient::ShouldFork(blink::WebFrame
* frame
,
1245 const std::string
& http_method
,
1246 bool is_initial_navigation
,
1247 bool is_server_redirect
,
1248 bool* send_referrer
) {
1249 DCHECK(!frame
->parent());
1251 // If this is the Instant process, fork all navigations originating from the
1252 // renderer. The destination page will then be bucketed back to this Instant
1253 // process if it is an Instant url, or to another process if not. Conversely,
1254 // fork if this is a non-Instant process navigating to an Instant url, so that
1255 // such navigations can also be bucketed into an Instant renderer.
1256 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1257 switches::kInstantProcess
) ||
1258 (search_bouncer_
.get() && search_bouncer_
->ShouldFork(url
))) {
1259 *send_referrer
= true;
1263 // For now, we skip the rest for POST submissions. This is because
1264 // http://crbug.com/101395 is more likely to cause compatibility issues
1265 // with hosted apps and extensions than WebUI pages. We will remove this
1266 // check when cross-process POST submissions are supported.
1267 if (http_method
!= "GET")
1270 // If |url| matches one of the prerendered URLs, stop this navigation and try
1271 // to swap in the prerendered page on the browser process. If the prerendered
1272 // page no longer exists by the time the OpenURL IPC is handled, a normal
1273 // navigation is attempted.
1274 if (prerender_dispatcher_
.get() &&
1275 prerender_dispatcher_
->IsPrerenderURL(url
)) {
1276 *send_referrer
= true;
1280 #if defined(ENABLE_EXTENSIONS)
1281 const extensions::ExtensionSet
* extensions
=
1282 extension_dispatcher_
->extensions();
1284 // Determine if the new URL is an extension (excluding bookmark apps).
1285 const Extension
* new_url_extension
= extensions::GetNonBookmarkAppExtension(
1287 bool is_extension_url
= !!new_url_extension
;
1289 // If the navigation would cross an app extent boundary, we also need
1290 // to defer to the browser to ensure process isolation. This is not necessary
1291 // for server redirects, which will be transferred to a new process by the
1292 // browser process when they are ready to commit. It is necessary for client
1293 // redirects, which won't be transferred in the same way.
1294 if (!is_server_redirect
&&
1295 CrossesExtensionExtents(frame
, url
, *extensions
, is_extension_url
,
1296 is_initial_navigation
)) {
1297 // Include the referrer in this case since we're going from a hosted web
1298 // page. (the packaged case is handled previously by the extension
1300 *send_referrer
= true;
1302 const Extension
* extension
=
1303 extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(url
);
1304 if (extension
&& extension
->is_app()) {
1305 extensions::RecordAppLaunchType(
1306 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION
, extension
->GetType());
1311 // If this is a reload, check whether it has the wrong process type. We
1312 // should send it to the browser if it's an extension URL (e.g., hosted app)
1313 // in a normal process, or if it's a process for an extension that has been
1315 if (frame
->top()->document().url() == url
) {
1316 if (is_extension_url
!= IsStandaloneExtensionProcess())
1319 #endif // defined(ENABLE_EXTENSIONS)
1324 #if defined(ENABLE_EXTENSIONS)
1325 bool ChromeContentRendererClient::ShouldForwardToGuestContainer(
1326 const IPC::Message
& msg
) {
1327 return extensions::GuestViewContainer::HandlesMessage(msg
);
1331 bool ChromeContentRendererClient::WillSendRequest(
1332 blink::WebFrame
* frame
,
1333 ui::PageTransition transition_type
,
1335 const GURL
& first_party_for_cookies
,
1337 // Check whether the request should be allowed. If not allowed, we reset the
1338 // URL to something invalid to prevent the request and cause an error.
1339 #if defined(ENABLE_EXTENSIONS)
1340 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1341 !extensions::ResourceRequestPolicy::CanRequestResource(
1345 extension_dispatcher_
->extensions())) {
1346 *new_url
= GURL(chrome::kExtensionInvalidRequestURL
);
1350 if (url
.SchemeIs(extensions::kExtensionResourceScheme
) &&
1351 !extensions::ResourceRequestPolicy::CanRequestExtensionResourceScheme(
1354 *new_url
= GURL(chrome::kExtensionResourceInvalidRequestURL
);
1359 const content::RenderView
* render_view
=
1360 content::RenderView::FromWebView(frame
->view());
1361 SearchBox
* search_box
= SearchBox::Get(render_view
);
1362 if (search_box
&& url
.SchemeIs(chrome::kChromeSearchScheme
)) {
1363 SearchBox::ImageSourceType type
= SearchBox::NONE
;
1364 if (url
.host() == chrome::kChromeUIFaviconHost
)
1365 type
= SearchBox::FAVICON
;
1366 else if (url
.host() == chrome::kChromeUILargeIconHost
)
1367 type
= SearchBox::LARGE_ICON
;
1368 else if (url
.host() == chrome::kChromeUIFallbackIconHost
)
1369 type
= SearchBox::FALLBACK_ICON
;
1370 else if (url
.host() == chrome::kChromeUIThumbnailHost
)
1371 type
= SearchBox::THUMB
;
1372 if (type
!= SearchBox::NONE
)
1373 return search_box
->GenerateImageURLFromTransientURL(url
, type
, new_url
);
1379 void ChromeContentRendererClient::DidCreateScriptContext(
1380 blink::WebLocalFrame
* frame
,
1381 v8::Handle
<v8::Context
> context
,
1382 int extension_group
,
1384 #if defined(ENABLE_EXTENSIONS)
1385 extension_dispatcher_
->DidCreateScriptContext(
1386 frame
, context
, extension_group
, world_id
);
1390 unsigned long long ChromeContentRendererClient::VisitedLinkHash(
1391 const char* canonical_url
, size_t length
) {
1392 return visited_link_slave_
->ComputeURLFingerprint(canonical_url
, length
);
1395 bool ChromeContentRendererClient::IsLinkVisited(unsigned long long link_hash
) {
1396 return visited_link_slave_
->IsVisited(link_hash
);
1399 blink::WebPrescientNetworking
*
1400 ChromeContentRendererClient::GetPrescientNetworking() {
1401 return prescient_networking_dispatcher_
.get();
1404 bool ChromeContentRendererClient::ShouldOverridePageVisibilityState(
1405 const content::RenderFrame
* render_frame
,
1406 blink::WebPageVisibilityState
* override_state
) {
1407 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
))
1410 *override_state
= blink::WebPageVisibilityStatePrerender
;
1414 #if defined(ENABLE_EXTENSIONS)
1415 void ChromeContentRendererClient::SetExtensionDispatcherForTest(
1416 extensions::Dispatcher
* extension_dispatcher
) {
1417 extension_dispatcher_
.reset(extension_dispatcher
);
1418 permissions_policy_delegate_
.reset(
1419 new extensions::RendererPermissionsPolicyDelegate(
1420 extension_dispatcher_
.get()));
1423 extensions::Dispatcher
*
1424 ChromeContentRendererClient::GetExtensionDispatcherForTest() {
1425 return extension_dispatcher_
.get();
1428 bool ChromeContentRendererClient::CrossesExtensionExtents(
1429 blink::WebFrame
* frame
,
1430 const GURL
& new_url
,
1431 const extensions::ExtensionSet
& extensions
,
1432 bool is_extension_url
,
1433 bool is_initial_navigation
) {
1434 GURL
old_url(frame
->top()->document().url());
1436 // If old_url is still empty and this is an initial navigation, then this is
1437 // a window.open operation. We should look at the opener URL.
1438 if (is_initial_navigation
&& old_url
.is_empty() && frame
->opener()) {
1439 // If we're about to open a normal web page from a same-origin opener stuck
1440 // in an extension process, we want to keep it in process to allow the
1441 // opener to script it.
1442 WebDocument opener_document
= frame
->opener()->document();
1443 WebSecurityOrigin opener
= frame
->opener()->document().securityOrigin();
1444 bool opener_is_extension_url
=
1445 !opener
.isUnique() && extensions
.GetExtensionOrAppByURL(
1446 opener_document
.url()) != NULL
;
1447 if (!is_extension_url
&&
1448 !opener_is_extension_url
&&
1449 IsStandaloneExtensionProcess() &&
1450 opener
.canRequest(WebURL(new_url
)))
1453 // In all other cases, we want to compare against the top frame's URL (as
1454 // opposed to the opener frame's), since that's what determines the type of
1455 // process. This allows iframes outside an app to open a popup in the app.
1456 old_url
= frame
->top()->opener()->top()->document().url();
1459 // Only consider keeping non-app URLs in an app process if this window
1460 // has an opener (in which case it might be an OAuth popup that tries to
1461 // script an iframe within the app).
1462 bool should_consider_workaround
= !!frame
->opener();
1464 return extensions::CrossesExtensionProcessBoundary(
1465 extensions
, old_url
, new_url
, should_consider_workaround
);
1467 #endif // defined(ENABLE_EXTENSIONS)
1469 #if defined(ENABLE_SPELLCHECK)
1470 void ChromeContentRendererClient::SetSpellcheck(SpellCheck
* spellcheck
) {
1471 RenderThread
* thread
= RenderThread::Get();
1472 if (spellcheck_
.get() && thread
)
1473 thread
->RemoveObserver(spellcheck_
.get());
1474 spellcheck_
.reset(spellcheck
);
1475 SpellCheckReplacer
replacer(spellcheck_
.get());
1476 content::RenderView::ForEach(&replacer
);
1478 thread
->AddObserver(spellcheck_
.get());
1483 bool ChromeContentRendererClient::WasWebRequestUsedBySomeExtensions() {
1484 #if defined(ENABLE_EXTENSIONS)
1485 return g_current_client
->extension_dispatcher_
1486 ->WasWebRequestUsedBySomeExtensions();
1492 const void* ChromeContentRendererClient::CreatePPAPIInterface(
1493 const std::string
& interface_name
) {
1494 #if defined(ENABLE_PLUGINS)
1495 #if !defined(DISABLE_NACL)
1496 if (interface_name
== PPB_NACL_PRIVATE_INTERFACE
)
1497 return nacl::GetNaClPrivateInterface();
1498 #endif // DISABLE_NACL
1499 if (interface_name
== PPB_PDF_INTERFACE
)
1500 return pdf::PPB_PDF_Impl::GetInterface();
1505 bool ChromeContentRendererClient::IsExternalPepperPlugin(
1506 const std::string
& module_name
) {
1507 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
1508 // We must defer certain plugin events for NaCl instances since we switch
1509 // from the in-process to the out-of-process proxy after instantiating them.
1510 return module_name
== "Native Client";
1513 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1514 bool ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
1515 const GURL
& url
, const std::set
<std::string
>& whitelist
) {
1516 const extensions::ExtensionSet
* extension_set
=
1517 g_current_client
->extension_dispatcher_
->extensions();
1518 return chrome::IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
1523 blink::WebSpeechSynthesizer
*
1524 ChromeContentRendererClient::OverrideSpeechSynthesizer(
1525 blink::WebSpeechSynthesizerClient
* client
) {
1526 return new TtsDispatcher(client
);
1529 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI(
1531 #if !defined(OS_ANDROID)
1532 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check
1533 // the whitelist in the renderer, since we're only preventing access until
1534 // these APIs are public and stable.
1535 std::string url_host
= url
.host();
1536 if (url
.SchemeIs("https") &&
1537 (EndsWith(url_host
, "talkgadget.google.com", false) ||
1538 EndsWith(url_host
, "plus.google.com", false) ||
1539 EndsWith(url_host
, "plus.sandbox.google.com", false)) &&
1540 StartsWithASCII(url
.path(), "/hangouts/", false)) {
1543 // Allow access for tests.
1544 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1545 switches::kEnablePepperTesting
)) {
1548 #endif // !defined(OS_ANDROID)
1552 void ChromeContentRendererClient::AddKeySystems(
1553 std::vector
<media::KeySystemInfo
>* key_systems
) {
1554 AddChromeKeySystems(key_systems
);
1557 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource(
1558 const base::string16
& source
) const {
1559 #if defined(ENABLE_EXTENSIONS)
1560 return extensions::IsSourceFromAnExtension(source
);
1566 bool ChromeContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
1567 // SiteIsolationPolicy is off by default. We would like to activate cross-site
1568 // document blocking (for UMA data collection) for normal renderer processes
1569 // running a normal web page from the Internet. We only turn on
1570 // SiteIsolationPolicy for a renderer process that does not have the extension
1572 #if defined(ENABLE_EXTENSIONS)
1573 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
1574 return !command_line
->HasSwitch(extensions::switches::kExtensionProcess
);
1580 blink::WebWorkerContentSettingsClientProxy
*
1581 ChromeContentRendererClient::CreateWorkerContentSettingsClientProxy(
1582 content::RenderFrame
* render_frame
,
1583 blink::WebFrame
* frame
) {
1584 return new WorkerContentSettingsClientProxy(render_frame
, frame
);
1587 bool ChromeContentRendererClient::IsPluginAllowedToUseDevChannelAPIs() {
1588 #if defined(ENABLE_PLUGINS)
1589 // Allow access for tests.
1590 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1591 switches::kEnablePepperTesting
)) {
1595 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1596 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
1597 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
1598 // Chromium builds as well.
1599 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1605 bool ChromeContentRendererClient::IsPluginAllowedToUseCameraDeviceAPI(
1607 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1608 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1609 switches::kEnablePepperTesting
))
1612 if (IsExtensionOrSharedModuleWhitelisted(url
, allowed_camera_device_origins_
))
1619 bool ChromeContentRendererClient::IsPluginAllowedToUseCompositorAPI(
1621 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1622 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1623 switches::kEnablePepperTesting
))
1625 if (IsExtensionOrSharedModuleWhitelisted(url
, allowed_compositor_origins_
))
1628 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1629 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1635 content::BrowserPluginDelegate
*
1636 ChromeContentRendererClient::CreateBrowserPluginDelegate(
1637 content::RenderFrame
* render_frame
,
1638 const std::string
& mime_type
,
1639 const GURL
& original_url
) {
1640 #if defined(ENABLE_EXTENSIONS)
1641 if (mime_type
== content::kBrowserPluginMimeType
) {
1642 return new extensions::ExtensionsGuestViewContainer(render_frame
);
1644 return new extensions::MimeHandlerViewContainer(
1645 render_frame
, mime_type
, original_url
);