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/path_service.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h"
18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/chrome_version_info.h"
21 #include "chrome/common/crash_keys.h"
22 #include "chrome/common/extensions/chrome_extensions_client.h"
23 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/extensions/extension_process_policy.h"
25 #include "chrome/common/localized_error.h"
26 #include "chrome/common/pepper_permission_util.h"
27 #include "chrome/common/render_messages.h"
28 #include "chrome/common/url_constants.h"
29 #include "chrome/grit/generated_resources.h"
30 #include "chrome/grit/locale_settings.h"
31 #include "chrome/grit/renderer_resources.h"
32 #include "chrome/renderer/benchmarking_extension.h"
33 #include "chrome/renderer/chrome_render_frame_observer.h"
34 #include "chrome/renderer/chrome_render_process_observer.h"
35 #include "chrome/renderer/chrome_render_view_observer.h"
36 #include "chrome/renderer/content_settings_observer.h"
37 #include "chrome/renderer/external_extension.h"
38 #include "chrome/renderer/loadtimes_extension_bindings.h"
39 #include "chrome/renderer/media/cast_ipc_dispatcher.h"
40 #include "chrome/renderer/media/chrome_key_systems.h"
41 #include "chrome/renderer/net/net_error_helper.h"
42 #include "chrome/renderer/net/prescient_networking_dispatcher.h"
43 #include "chrome/renderer/net/renderer_net_predictor.h"
44 #include "chrome/renderer/net_benchmarking_extension.h"
45 #include "chrome/renderer/page_load_histograms.h"
46 #include "chrome/renderer/pepper/pepper_helper.h"
47 #include "chrome/renderer/playback_extension.h"
48 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
49 #include "chrome/renderer/plugins/plugin_uma.h"
50 #include "chrome/renderer/prefetch_helper.h"
51 #include "chrome/renderer/prerender/prerender_dispatcher.h"
52 #include "chrome/renderer/prerender/prerender_helper.h"
53 #include "chrome/renderer/prerender/prerender_media_load_deferrer.h"
54 #include "chrome/renderer/prerender/prerenderer_client.h"
55 #include "chrome/renderer/principals_extension_bindings.h"
56 #include "chrome/renderer/printing/print_web_view_helper.h"
57 #include "chrome/renderer/safe_browsing/malware_dom_details.h"
58 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
59 #include "chrome/renderer/searchbox/search_bouncer.h"
60 #include "chrome/renderer/searchbox/searchbox.h"
61 #include "chrome/renderer/searchbox/searchbox_extension.h"
62 #include "chrome/renderer/tts_dispatcher.h"
63 #include "chrome/renderer/worker_permission_client_proxy.h"
64 #include "components/autofill/content/renderer/autofill_agent.h"
65 #include "components/autofill/content/renderer/password_autofill_agent.h"
66 #include "components/autofill/content/renderer/password_generation_agent.h"
67 #include "components/content_settings/core/common/content_settings_pattern.h"
68 #include "components/dom_distiller/core/url_constants.h"
69 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
70 #include "components/password_manager/content/renderer/credential_manager_client.h"
71 #include "components/pdf/renderer/ppb_pdf_impl.h"
72 #include "components/plugins/renderer/mobile_youtube_plugin.h"
73 #include "components/signin/core/common/profile_management_switches.h"
74 #include "components/visitedlink/renderer/visitedlink_slave.h"
75 #include "components/web_cache/renderer/web_cache_render_process_observer.h"
76 #include "content/public/common/content_constants.h"
77 #include "content/public/renderer/render_frame.h"
78 #include "content/public/renderer/render_thread.h"
79 #include "content/public/renderer/render_view.h"
80 #include "content/public/renderer/render_view_visitor.h"
81 #include "extensions/common/constants.h"
82 #include "extensions/common/extension.h"
83 #include "extensions/common/extension_set.h"
84 #include "extensions/common/extension_urls.h"
85 #include "extensions/common/switches.h"
86 #include "ipc/ipc_sync_channel.h"
87 #include "net/base/net_errors.h"
88 #include "ppapi/c/private/ppb_nacl_private.h"
89 #include "ppapi/c/private/ppb_pdf.h"
90 #include "ppapi/shared_impl/ppapi_switches.h"
91 #include "third_party/WebKit/public/platform/WebURL.h"
92 #include "third_party/WebKit/public/platform/WebURLError.h"
93 #include "third_party/WebKit/public/platform/WebURLRequest.h"
94 #include "third_party/WebKit/public/web/WebCache.h"
95 #include "third_party/WebKit/public/web/WebDataSource.h"
96 #include "third_party/WebKit/public/web/WebDocument.h"
97 #include "third_party/WebKit/public/web/WebElement.h"
98 #include "third_party/WebKit/public/web/WebLocalFrame.h"
99 #include "third_party/WebKit/public/web/WebPluginContainer.h"
100 #include "third_party/WebKit/public/web/WebPluginParams.h"
101 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
102 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
103 #include "ui/base/l10n/l10n_util.h"
104 #include "ui/base/layout.h"
105 #include "ui/base/resource/resource_bundle.h"
106 #include "ui/base/webui/jstemplate_builder.h"
107 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
109 #if !defined(DISABLE_NACL)
110 #include "components/nacl/common/nacl_constants.h"
111 #include "components/nacl/renderer/nacl_helper.h"
114 #if defined(ENABLE_EXTENSIONS)
115 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h"
116 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h"
117 #include "chrome/renderer/extensions/extension_frame_helper.h"
118 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
119 #include "chrome/renderer/extensions/resource_request_policy.h"
120 #include "extensions/renderer/dispatcher.h"
121 #include "extensions/renderer/extension_helper.h"
122 #include "extensions/renderer/extensions_render_frame_observer.h"
123 #include "extensions/renderer/guest_view/guest_view_container.h"
124 #include "extensions/renderer/script_context.h"
127 #if defined(ENABLE_FULL_PRINTING)
128 #include "chrome/renderer/pepper/chrome_pdf_print_client.h"
131 #if defined(ENABLE_SPELLCHECK)
132 #include "chrome/renderer/spellchecker/spellcheck.h"
133 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
136 #if defined(ENABLE_WEBRTC)
137 #include "chrome/renderer/media/webrtc_logging_message_filter.h"
141 #include "chrome_elf/blacklist/blacklist.h"
144 using autofill::AutofillAgent
;
145 using autofill::PasswordAutofillAgent
;
146 using autofill::PasswordGenerationAgent
;
147 using base::ASCIIToUTF16
;
148 using base::UserMetricsAction
;
149 using content::RenderThread
;
150 using content::WebPluginInfo
;
151 using extensions::Extension
;
152 using blink::WebCache
;
153 using blink::WebConsoleMessage
;
154 using blink::WebDataSource
;
155 using blink::WebDocument
;
156 using blink::WebFrame
;
157 using blink::WebLocalFrame
;
158 using blink::WebPlugin
;
159 using blink::WebPluginParams
;
160 using blink::WebSecurityOrigin
;
161 using blink::WebSecurityPolicy
;
162 using blink::WebString
;
164 using blink::WebURLError
;
165 using blink::WebURLRequest
;
166 using blink::WebURLResponse
;
167 using blink::WebVector
;
171 ChromeContentRendererClient
* g_current_client
;
173 #if defined(ENABLE_PLUGINS)
174 const char* const kPredefinedAllowedCompositorOrigins
[] = {
175 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
176 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
179 const char* const kPredefinedAllowedVideoDecodeOrigins
[] = {
180 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
181 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
185 static void AppendParams(const std::vector
<base::string16
>& additional_names
,
186 const std::vector
<base::string16
>& additional_values
,
187 WebVector
<WebString
>* existing_names
,
188 WebVector
<WebString
>* existing_values
) {
189 DCHECK(additional_names
.size() == additional_values
.size());
190 DCHECK(existing_names
->size() == existing_values
->size());
192 size_t existing_size
= existing_names
->size();
193 size_t total_size
= existing_size
+ additional_names
.size();
195 WebVector
<WebString
> names(total_size
);
196 WebVector
<WebString
> values(total_size
);
198 for (size_t i
= 0; i
< existing_size
; ++i
) {
199 names
[i
] = (*existing_names
)[i
];
200 values
[i
] = (*existing_values
)[i
];
203 for (size_t i
= 0; i
< additional_names
.size(); ++i
) {
204 names
[existing_size
+ i
] = additional_names
[i
];
205 values
[existing_size
+ i
] = additional_values
[i
];
208 existing_names
->swap(names
);
209 existing_values
->swap(values
);
212 #if defined(ENABLE_SPELLCHECK)
213 class SpellCheckReplacer
: public content::RenderViewVisitor
{
215 explicit SpellCheckReplacer(SpellCheck
* spellcheck
)
216 : spellcheck_(spellcheck
) {}
217 virtual bool Visit(content::RenderView
* render_view
) override
;
220 SpellCheck
* spellcheck_
; // New shared spellcheck for all views. Weak Ptr.
221 DISALLOW_COPY_AND_ASSIGN(SpellCheckReplacer
);
224 bool SpellCheckReplacer::Visit(content::RenderView
* render_view
) {
225 SpellCheckProvider
* provider
= SpellCheckProvider::Get(render_view
);
227 provider
->set_spellcheck(spellcheck_
);
232 // For certain sandboxed Pepper plugins, use the JavaScript Content Settings.
233 bool ShouldUseJavaScriptSettingForPlugin(const WebPluginInfo
& plugin
) {
234 if (plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS
&&
235 plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
) {
239 #if !defined(DISABLE_NACL)
240 // Treat Native Client invocations like JavaScript.
241 if (plugin
.name
== ASCIIToUTF16(nacl::kNaClPluginName
))
245 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
246 // Treat CDM invocations like JavaScript.
247 if (plugin
.name
== ASCIIToUTF16(kWidevineCdmDisplayName
)) {
248 DCHECK(plugin
.type
== WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
);
251 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
256 #if defined(ENABLE_EXTENSIONS)
257 void IsGuestViewApiAvailableToScriptContext(
258 bool* api_is_available
,
259 extensions::ScriptContext
* context
) {
260 if (context
->GetAvailability("guestViewInternal").is_available()) {
261 *api_is_available
= true;
268 ChromeContentRendererClient::ChromeContentRendererClient() {
269 g_current_client
= this;
271 extensions::ExtensionsClient::Set(
272 extensions::ChromeExtensionsClient::GetInstance());
273 #if defined(ENABLE_EXTENSIONS)
274 extensions::ExtensionsRendererClient::Set(
275 ChromeExtensionsRendererClient::GetInstance());
277 #if defined(ENABLE_PLUGINS)
278 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedCompositorOrigins
); ++i
)
279 allowed_compositor_origins_
.insert(kPredefinedAllowedCompositorOrigins
[i
]);
280 for (size_t i
= 0; i
< arraysize(kPredefinedAllowedVideoDecodeOrigins
); ++i
)
281 allowed_video_decode_origins_
.insert(
282 kPredefinedAllowedVideoDecodeOrigins
[i
]);
286 ChromeContentRendererClient::~ChromeContentRendererClient() {
287 g_current_client
= NULL
;
290 void ChromeContentRendererClient::RenderThreadStarted() {
291 RenderThread
* thread
= RenderThread::Get();
293 chrome_observer_
.reset(new ChromeRenderProcessObserver(this));
294 web_cache_observer_
.reset(new web_cache::WebCacheRenderProcessObserver());
296 #if defined(ENABLE_EXTENSIONS)
297 extension_dispatcher_delegate_
.reset(
298 new ChromeExtensionsDispatcherDelegate());
299 // ChromeRenderViewTest::SetUp() creates its own ExtensionDispatcher and
300 // injects it using SetExtensionDispatcher(). Don't overwrite it.
301 if (!extension_dispatcher_
) {
302 extension_dispatcher_
.reset(
303 new extensions::Dispatcher(extension_dispatcher_delegate_
.get()));
305 permissions_policy_delegate_
.reset(
306 new extensions::RendererPermissionsPolicyDelegate(
307 extension_dispatcher_
.get()));
310 prescient_networking_dispatcher_
.reset(new PrescientNetworkingDispatcher());
311 net_predictor_
.reset(new RendererNetPredictor());
312 #if defined(ENABLE_SPELLCHECK)
313 // ChromeRenderViewTest::SetUp() creates a Spellcheck and injects it using
314 // SetSpellcheck(). Don't overwrite it.
316 spellcheck_
.reset(new SpellCheck());
317 thread
->AddObserver(spellcheck_
.get());
320 visited_link_slave_
.reset(new visitedlink::VisitedLinkSlave());
321 #if defined(FULL_SAFE_BROWSING)
322 phishing_classifier_
.reset(safe_browsing::PhishingClassifierFilter::Create());
324 prerender_dispatcher_
.reset(new prerender::PrerenderDispatcher());
325 #if defined(ENABLE_WEBRTC)
326 webrtc_logging_message_filter_
= new WebRtcLoggingMessageFilter(
327 content::RenderThread::Get()->GetIOMessageLoopProxy());
329 search_bouncer_
.reset(new SearchBouncer());
331 thread
->AddObserver(chrome_observer_
.get());
332 thread
->AddObserver(web_cache_observer_
.get());
333 #if defined(ENABLE_EXTENSIONS)
334 thread
->AddObserver(extension_dispatcher_
.get());
336 #if defined(FULL_SAFE_BROWSING)
337 thread
->AddObserver(phishing_classifier_
.get());
339 thread
->AddObserver(visited_link_slave_
.get());
340 thread
->AddObserver(prerender_dispatcher_
.get());
341 thread
->AddObserver(search_bouncer_
.get());
343 #if defined(ENABLE_WEBRTC)
344 thread
->AddFilter(webrtc_logging_message_filter_
.get());
346 thread
->AddFilter(new CastIPCDispatcher(
347 content::RenderThread::Get()->GetIOMessageLoopProxy()));
349 thread
->RegisterExtension(extensions_v8::ExternalExtension::Get());
350 thread
->RegisterExtension(extensions_v8::LoadTimesExtension::Get());
352 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
353 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
354 thread
->RegisterExtension(extensions_v8::BenchmarkingExtension::Get());
355 if (command_line
->HasSwitch(switches::kEnableNetBenchmarking
))
356 thread
->RegisterExtension(extensions_v8::NetBenchmarkingExtension::Get());
357 if (command_line
->HasSwitch(switches::kInstantProcess
))
358 thread
->RegisterExtension(extensions_v8::SearchBoxExtension::Get());
360 if (command_line
->HasSwitch(switches::kPlaybackMode
) ||
361 command_line
->HasSwitch(switches::kRecordMode
)) {
362 thread
->RegisterExtension(extensions_v8::PlaybackExtension::Get());
365 // TODO(guohui): needs to forward the new-profile-management switch to
366 // renderer processes.
367 if (switches::IsEnableAccountConsistency())
368 thread
->RegisterExtension(extensions_v8::PrincipalsExtension::Get());
370 // chrome:, chrome-search:, chrome-devtools:, and chrome-distiller: pages
371 // should not be accessible by normal content, and should also be unable to
372 // script anything but themselves (to help limit the damage that a corrupt
373 // page could cause).
374 WebString
chrome_ui_scheme(ASCIIToUTF16(content::kChromeUIScheme
));
375 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme
);
377 WebString
chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme
));
378 // The Instant process can only display the content but not read it. Other
379 // processes can't display it or read it.
380 if (!command_line
->HasSwitch(switches::kInstantProcess
))
381 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_search_scheme
);
383 WebString
dev_tools_scheme(ASCIIToUTF16(content::kChromeDevToolsScheme
));
384 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dev_tools_scheme
);
386 WebString
dom_distiller_scheme(
387 ASCIIToUTF16(dom_distiller::kDomDistillerScheme
));
388 // TODO(nyquist): Add test to ensure this happens when the flag is set.
389 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dom_distiller_scheme
);
391 #if defined(OS_CHROMEOS)
392 WebString
external_file_scheme(ASCIIToUTF16(chrome::kExternalFileScheme
));
393 WebSecurityPolicy::registerURLSchemeAsLocal(external_file_scheme
);
396 // chrome: and chrome-search: pages should not be accessible by bookmarklets
397 // or javascript: URLs typed in the omnibox.
398 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
400 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
401 chrome_search_scheme
);
403 // chrome:, chrome-search:, chrome-extension:, and chrome-extension-resource:
404 // resources shouldn't trigger insecure content warnings.
405 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_ui_scheme
);
406 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_search_scheme
);
408 WebString
extension_scheme(ASCIIToUTF16(extensions::kExtensionScheme
));
409 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme
);
411 WebString
extension_resource_scheme(
412 ASCIIToUTF16(extensions::kExtensionResourceScheme
));
413 WebSecurityPolicy::registerURLSchemeAsSecure(extension_resource_scheme
);
415 // chrome:, chrome-extension:, chrome-extension-resource: resources should be
416 // allowed to receive CORS requests.
417 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(chrome_ui_scheme
);
418 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_scheme
);
419 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_resource_scheme
);
421 // chrome-extension: resources should bypass Content Security Policy checks
422 // when included in protected resources.
423 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
425 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
426 extension_resource_scheme
);
429 // Report if the renderer process has been patched by chrome_elf.
430 // TODO(csharp): Remove once the renderer is no longer getting
432 if (blacklist::IsBlacklistInitialized())
433 UMA_HISTOGRAM_BOOLEAN("Blacklist.PatchedInRenderer", true);
435 #if defined(ENABLE_FULL_PRINTING)
436 pdf_print_client_
.reset(new ChromePDFPrintClient());
437 pdf::PPB_PDF_Impl::SetPrintClient(pdf_print_client_
.get());
441 void ChromeContentRendererClient::RenderFrameCreated(
442 content::RenderFrame
* render_frame
) {
443 new ChromeRenderFrameObserver(render_frame
);
445 extensions::Dispatcher
* ext_dispatcher
= NULL
;
446 #if defined(ENABLE_EXTENSIONS)
447 ext_dispatcher
= extension_dispatcher_
.get();
449 ContentSettingsObserver
* content_settings
=
450 new ContentSettingsObserver(render_frame
, ext_dispatcher
);
451 if (chrome_observer_
.get()) {
452 content_settings
->SetContentSettingRules(
453 chrome_observer_
->content_setting_rules());
456 #if defined(ENABLE_EXTENSIONS)
457 new extensions::ExtensionsRenderFrameObserver(render_frame
);
458 new extensions::ExtensionFrameHelper(render_frame
, ext_dispatcher
);
461 #if defined(ENABLE_PLUGINS)
462 new PepperHelper(render_frame
);
465 #if !defined(DISABLE_NACL)
466 new nacl::NaClHelper(render_frame
);
469 // TODO(jam): when the frame tree moves into content and parent() works at
470 // RenderFrame construction, simplify this by just checking parent().
471 if (render_frame
->GetRenderView()->GetMainRenderFrame() != render_frame
) {
472 // Avoid any race conditions from having the browser tell subframes that
473 // they're prerendering.
474 if (prerender::PrerenderHelper::IsPrerendering(
475 render_frame
->GetRenderView()->GetMainRenderFrame())) {
476 new prerender::PrerenderHelper(render_frame
);
480 if (render_frame
->GetRenderView()->GetMainRenderFrame() == render_frame
) {
481 // Only attach NetErrorHelper to the main frame, since only the main frame
482 // should get error pages.
483 // PrefetchHelper is also needed only for main frames.
484 new NetErrorHelper(render_frame
);
485 new prefetch::PrefetchHelper(render_frame
);
489 void ChromeContentRendererClient::RenderViewCreated(
490 content::RenderView
* render_view
) {
491 #if defined(ENABLE_EXTENSIONS)
492 new extensions::ExtensionHelper(render_view
, extension_dispatcher_
.get());
493 extension_dispatcher_
->OnRenderViewCreated(render_view
);
495 new PageLoadHistograms(render_view
);
496 #if defined(ENABLE_PRINTING)
497 new printing::PrintWebViewHelper(render_view
);
499 #if defined(ENABLE_SPELLCHECK)
500 new SpellCheckProvider(render_view
, spellcheck_
.get());
502 new prerender::PrerendererClient(render_view
);
503 #if defined(FULL_SAFE_BROWSING)
504 safe_browsing::MalwareDOMDetails::Create(render_view
);
507 PasswordGenerationAgent
* password_generation_agent
=
508 new PasswordGenerationAgent(render_view
);
509 PasswordAutofillAgent
* password_autofill_agent
=
510 new PasswordAutofillAgent(render_view
);
511 new AutofillAgent(render_view
,
512 password_autofill_agent
,
513 password_generation_agent
);
515 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
516 if (command_line
->HasSwitch(switches::kInstantProcess
))
517 new SearchBox(render_view
);
519 new ChromeRenderViewObserver(render_view
, web_cache_observer_
.get());
521 new password_manager::CredentialManagerClient(render_view
);
524 void ChromeContentRendererClient::SetNumberOfViews(int number_of_views
) {
525 base::debug::SetCrashKeyValue(crash_keys::kNumberOfViews
,
526 base::IntToString(number_of_views
));
529 SkBitmap
* ChromeContentRendererClient::GetSadPluginBitmap() {
530 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
531 GetImageNamed(IDR_SAD_PLUGIN
).ToSkBitmap());
534 SkBitmap
* ChromeContentRendererClient::GetSadWebViewBitmap() {
535 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
536 GetImageNamed(IDR_SAD_WEBVIEW
).ToSkBitmap());
539 #if defined(ENABLE_EXTENSIONS)
540 const Extension
* ChromeContentRendererClient::GetExtensionByOrigin(
541 const WebSecurityOrigin
& origin
) const {
542 if (!EqualsASCII(origin
.protocol(), extensions::kExtensionScheme
))
545 const std::string extension_id
= origin
.host().utf8().data();
546 return extension_dispatcher_
->extensions()->GetByID(extension_id
);
550 bool ChromeContentRendererClient::OverrideCreatePlugin(
551 content::RenderFrame
* render_frame
,
552 WebLocalFrame
* frame
,
553 const WebPluginParams
& params
,
554 WebPlugin
** plugin
) {
555 std::string orig_mime_type
= params
.mimeType
.utf8();
556 #if defined(ENABLE_EXTENSIONS)
557 if (orig_mime_type
== content::kBrowserPluginMimeType
) {
558 bool guest_view_api_available
= false;
559 extension_dispatcher_
->script_context_set().ForEach(
560 render_frame
->GetRenderView(),
561 base::Bind(&IsGuestViewApiAvailableToScriptContext
,
562 &guest_view_api_available
));
563 if (guest_view_api_available
)
568 ChromeViewHostMsg_GetPluginInfo_Output output
;
569 #if defined(ENABLE_PLUGINS)
570 render_frame
->Send(new ChromeViewHostMsg_GetPluginInfo(
571 render_frame
->GetRoutingID(), GURL(params
.url
),
572 frame
->top()->document().url(), orig_mime_type
, &output
));
574 if (output
.plugin
.type
== content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN
)
577 output
.status
.value
= ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
;
579 *plugin
= CreatePlugin(render_frame
, frame
, params
, output
);
583 WebPlugin
* ChromeContentRendererClient::CreatePluginReplacement(
584 content::RenderFrame
* render_frame
,
585 const base::FilePath
& plugin_path
) {
586 ChromePluginPlaceholder
* placeholder
=
587 ChromePluginPlaceholder::CreateErrorPlugin(render_frame
, plugin_path
);
588 return placeholder
->plugin();
591 void ChromeContentRendererClient::DeferMediaLoad(
592 content::RenderFrame
* render_frame
,
593 const base::Closure
& closure
) {
594 #if defined(OS_ANDROID)
595 // Chromium for Android doesn't support prerender yet.
599 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
604 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
605 new prerender::PrerenderMediaLoadDeferrer(render_frame
, closure
);
609 WebPlugin
* ChromeContentRendererClient::CreatePlugin(
610 content::RenderFrame
* render_frame
,
611 WebLocalFrame
* frame
,
612 const WebPluginParams
& original_params
,
613 const ChromeViewHostMsg_GetPluginInfo_Output
& output
) {
614 const ChromeViewHostMsg_GetPluginInfo_Status
& status
= output
.status
;
615 const WebPluginInfo
& plugin
= output
.plugin
;
616 const std::string
& actual_mime_type
= output
.actual_mime_type
;
617 const base::string16
& group_name
= output
.group_name
;
618 const std::string
& identifier
= output
.group_identifier
;
619 ChromeViewHostMsg_GetPluginInfo_Status::Value status_value
= status
.value
;
620 GURL
url(original_params
.url
);
621 std::string orig_mime_type
= original_params
.mimeType
.utf8();
622 ChromePluginPlaceholder
* placeholder
= NULL
;
624 // If the browser plugin is to be enabled, this should be handled by the
625 // renderer, so the code won't reach here due to the early exit in
626 // OverrideCreatePlugin.
627 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
||
628 orig_mime_type
== content::kBrowserPluginMimeType
) {
629 #if defined(OS_ANDROID)
630 if (plugins::MobileYouTubePlugin::IsYouTubeURL(url
, orig_mime_type
)) {
631 base::StringPiece
template_html(
632 ResourceBundle::GetSharedInstance().GetRawDataResource(
633 IDR_MOBILE_YOUTUBE_PLUGIN_HTML
));
634 return (new plugins::MobileYouTubePlugin(
639 GURL(ChromePluginPlaceholder::kPluginPlaceholderDataURL
)))
643 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type
, url
);
644 placeholder
= ChromePluginPlaceholder::CreateMissingPlugin(
645 render_frame
, frame
, original_params
);
647 // TODO(bauerb): This should be in content/.
648 WebPluginParams
params(original_params
);
649 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
650 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
651 AppendParams(plugin
.mime_types
[i
].additional_param_names
,
652 plugin
.mime_types
[i
].additional_param_values
,
653 ¶ms
.attributeNames
,
654 ¶ms
.attributeValues
);
658 if (params
.mimeType
.isNull() && (actual_mime_type
.size() > 0)) {
659 // Webkit might say that mime type is null while we already know the
660 // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case
661 // we should use what we know since WebpluginDelegateProxy does some
662 // specific initializations based on this information.
663 params
.mimeType
= WebString::fromUTF8(actual_mime_type
.c_str());
666 ContentSettingsObserver
* observer
=
667 ContentSettingsObserver::Get(render_frame
);
669 const ContentSettingsType content_type
=
670 ShouldUseJavaScriptSettingForPlugin(plugin
) ?
671 CONTENT_SETTINGS_TYPE_JAVASCRIPT
:
672 CONTENT_SETTINGS_TYPE_PLUGINS
;
675 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
||
676 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
||
677 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
) &&
678 observer
->IsPluginTemporarilyAllowed(identifier
)) {
679 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
682 // Allow full-page plug-ins for click-to-play.
683 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
&&
686 frame
->document().isPluginDocument()) {
687 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
691 // In Windows we need to check if we can load NPAPI plugins.
692 // For example, if the render view is in the Ash desktop, we should not.
693 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
&&
694 plugin
.type
== content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
695 if (observer
->AreNPAPIPluginsBlocked())
697 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
;
701 switch (status_value
) {
702 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
: {
706 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
: {
707 #if !defined(DISABLE_NACL)
708 const bool is_nacl_plugin
=
709 plugin
.name
== ASCIIToUTF16(nacl::kNaClPluginName
);
710 const bool is_nacl_mime_type
=
711 actual_mime_type
== nacl::kNaClPluginMimeType
;
712 const bool is_pnacl_mime_type
=
713 actual_mime_type
== nacl::kPnaclPluginMimeType
;
714 if (is_nacl_plugin
|| is_nacl_mime_type
|| is_pnacl_mime_type
) {
715 bool is_nacl_unrestricted
= false;
716 if (is_nacl_mime_type
) {
717 is_nacl_unrestricted
=
718 CommandLine::ForCurrentProcess()->HasSwitch(
719 switches::kEnableNaCl
);
720 } else if (is_pnacl_mime_type
) {
721 is_nacl_unrestricted
= true;
725 if (is_nacl_mime_type
|| is_pnacl_mime_type
) {
726 // Normal NaCl/PNaCl embed. The app URL is the page URL.
728 app_url
= frame
->top()->document().url();
730 // NaCl is being invoked as a content handler. Look up the NaCl
731 // module using the MIME type. The app URL is the manifest URL.
732 manifest_url
= GetNaClContentHandlerURL(actual_mime_type
, plugin
);
733 app_url
= manifest_url
;
735 const Extension
* extension
=
736 g_current_client
->extension_dispatcher_
->extensions()->
737 GetExtensionOrAppByURL(manifest_url
);
738 if (!IsNaClAllowed(manifest_url
,
740 is_nacl_unrestricted
,
743 WebString error_message
;
744 if (is_nacl_mime_type
) {
746 "Only unpacked extensions and apps installed from the Chrome "
747 "Web Store can load NaCl modules without enabling Native "
748 "Client in about:flags.";
749 } else if (is_pnacl_mime_type
) {
751 "Portable Native Client must not be disabled in about:flags.";
753 frame
->addMessageToConsole(
754 WebConsoleMessage(WebConsoleMessage::LevelError
,
756 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
763 IDR_BLOCKED_PLUGIN_HTML
,
764 #if defined(OS_CHROMEOS)
765 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED
));
767 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
772 #endif // !defined(DISABLE_NACL)
774 // Delay loading plugins if prerendering.
775 // TODO(mmenke): In the case of prerendering, feed into
776 // ChromeContentRendererClient::CreatePlugin instead, to
777 // reduce the chance of future regressions.
778 if (prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
779 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
786 IDR_CLICK_TO_PLAY_PLUGIN_HTML
,
787 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD
, group_name
));
788 placeholder
->set_blocked_for_prerendering(true);
789 placeholder
->set_allow_loading(true);
793 return render_frame
->CreatePlugin(frame
, plugin
, params
);
795 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
: {
796 RenderThread::Get()->RecordAction(
797 UserMetricsAction("Plugin_NPAPINotSupported"));
798 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
805 IDR_BLOCKED_PLUGIN_HTML
,
806 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO
));
807 render_frame
->Send(new ChromeViewHostMsg_NPAPINotSupported(
808 render_frame
->GetRoutingID(), identifier
));
811 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled
: {
812 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type
,
814 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
821 IDR_DISABLED_PLUGIN_HTML
,
822 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED
, group_name
));
825 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked
: {
826 #if defined(ENABLE_PLUGIN_INSTALLATION)
827 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
834 IDR_BLOCKED_PLUGIN_HTML
,
835 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
836 placeholder
->set_allow_loading(true);
837 render_frame
->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
838 render_frame
->GetRoutingID(), placeholder
->CreateRoutingId(),
845 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed
: {
846 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
853 IDR_BLOCKED_PLUGIN_HTML
,
854 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
857 case ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
: {
858 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
865 IDR_BLOCKED_PLUGIN_HTML
,
866 l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED
, group_name
));
867 placeholder
->set_allow_loading(true);
868 // Check to see if old infobar should be displayed.
869 std::string trial_group
=
870 base::FieldTrialList::FindFullName("UnauthorizedPluginInfoBar");
871 if (plugin
.type
!= content::WebPluginInfo::PLUGIN_TYPE_NPAPI
||
872 trial_group
== "Enabled") {
873 render_frame
->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin(
874 render_frame
->GetRoutingID(),
878 // Send IPC for showing blocked plugins page action.
879 observer
->DidBlockContentType(content_type
);
883 case ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
: {
884 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
891 IDR_CLICK_TO_PLAY_PLUGIN_HTML
,
892 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD
, group_name
));
893 placeholder
->set_allow_loading(true);
894 RenderThread::Get()->RecordAction(
895 UserMetricsAction("Plugin_ClickToPlay"));
896 observer
->DidBlockContentType(content_type
);
899 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
: {
900 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
907 IDR_BLOCKED_PLUGIN_HTML
,
908 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
909 placeholder
->set_allow_loading(true);
910 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked"));
911 observer
->DidBlockContentType(content_type
);
914 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy
: {
915 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
922 IDR_BLOCKED_PLUGIN_HTML
,
923 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
924 placeholder
->set_allow_loading(false);
925 RenderThread::Get()->RecordAction(
926 UserMetricsAction("Plugin_BlockedByPolicy"));
927 observer
->DidBlockContentType(content_type
);
932 placeholder
->SetStatus(status
);
933 return placeholder
->plugin();
936 // For NaCl content handling plugins, the NaCl manifest is stored in an
937 // additonal 'nacl' param associated with the MIME type.
939 GURL
ChromeContentRendererClient::GetNaClContentHandlerURL(
940 const std::string
& actual_mime_type
,
941 const content::WebPluginInfo
& plugin
) {
942 // Look for the manifest URL among the MIME type's additonal parameters.
943 const char* kNaClPluginManifestAttribute
= "nacl";
944 base::string16 nacl_attr
= ASCIIToUTF16(kNaClPluginManifestAttribute
);
945 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
946 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
947 const content::WebPluginMimeType
& content_type
= plugin
.mime_types
[i
];
948 for (size_t i
= 0; i
< content_type
.additional_param_names
.size(); ++i
) {
949 if (content_type
.additional_param_names
[i
] == nacl_attr
)
950 return GURL(content_type
.additional_param_values
[i
]);
959 bool ChromeContentRendererClient::IsNaClAllowed(
960 const GURL
& manifest_url
,
962 bool is_nacl_unrestricted
,
963 const Extension
* extension
,
964 WebPluginParams
* params
) {
965 // Temporarily allow these whitelisted apps and WebUIs to use NaCl.
966 std::string app_url_host
= app_url
.host();
967 std::string manifest_url_path
= manifest_url
.path();
969 bool is_whitelisted_web_ui
=
970 app_url
.spec() == chrome::kChromeUIAppListStartPageURL
;
973 // Whitelisted apps must be served over https.
974 app_url
.SchemeIs("https") &&
975 manifest_url
.SchemeIs("https") &&
976 (EndsWith(app_url_host
, "plus.google.com", false) ||
977 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
978 manifest_url
.DomainIs("ssl.gstatic.com") &&
979 (manifest_url_path
.find("s2/oz/nacl/") == 1 ||
980 manifest_url_path
.find("photos/nacl/") == 1);
982 std::string manifest_fs_host
;
983 if (manifest_url
.SchemeIsFileSystem() && manifest_url
.inner_url()) {
984 manifest_fs_host
= manifest_url
.inner_url()->host();
986 bool is_hangouts_app
=
987 // Whitelisted apps must be served over secure scheme.
988 app_url
.SchemeIs("https") &&
989 manifest_url
.SchemeIsSecure() &&
990 manifest_url
.SchemeIsFileSystem() &&
991 (EndsWith(app_url_host
, "talkgadget.google.com", false) ||
992 EndsWith(app_url_host
, "plus.google.com", false) ||
993 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
994 // The manifest must be loaded from the host's FileSystem.
995 (manifest_fs_host
== app_url_host
);
997 bool is_whitelisted_app
= is_photo_app
|| is_hangouts_app
;
999 bool is_extension_from_webstore
= extension
&&
1000 extension
->from_webstore();
1002 bool is_invoked_by_hosted_app
= extension
&&
1003 extension
->is_hosted_app() &&
1004 extension
->web_extent().MatchesURL(app_url
);
1006 // Allow built-in extensions and extensions under development.
1007 bool is_extension_unrestricted
= extension
&&
1008 (extension
->location() == extensions::Manifest::COMPONENT
||
1009 extensions::Manifest::IsUnpackedLocation(extension
->location()));
1011 bool is_invoked_by_extension
= app_url
.SchemeIs("chrome-extension");
1013 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces.
1014 bool is_nacl_pdf_viewer
=
1015 (is_extension_from_webstore
&&
1016 manifest_url
.SchemeIs("chrome-extension") &&
1017 manifest_url
.host() == "acadkphlmlegjaadjagenfimbpphcgnh");
1019 // Allow Chrome Web Store extensions, built-in extensions and extensions
1020 // under development if the invocation comes from a URL with an extension
1021 // scheme. Also allow invocations if they are from whitelisted URLs or
1022 // if --enable-nacl is set.
1023 bool is_nacl_allowed
= is_nacl_unrestricted
||
1024 is_whitelisted_web_ui
||
1025 is_whitelisted_app
||
1026 is_nacl_pdf_viewer
||
1027 is_invoked_by_hosted_app
||
1028 (is_invoked_by_extension
&&
1029 (is_extension_from_webstore
||
1030 is_extension_unrestricted
));
1031 if (is_nacl_allowed
) {
1032 bool app_can_use_dev_interfaces
= is_nacl_pdf_viewer
;
1033 // Make sure that PPAPI 'dev' interfaces aren't available for production
1034 // apps unless they're whitelisted.
1035 WebString dev_attribute
= WebString::fromUTF8("@dev");
1036 if ((!is_whitelisted_app
&& !is_extension_from_webstore
) ||
1037 app_can_use_dev_interfaces
) {
1038 // Add the special '@dev' attribute.
1039 std::vector
<base::string16
> param_names
;
1040 std::vector
<base::string16
> param_values
;
1041 param_names
.push_back(dev_attribute
);
1042 param_values
.push_back(WebString());
1046 ¶ms
->attributeNames
,
1047 ¶ms
->attributeValues
);
1049 // If the params somehow contain '@dev', remove it.
1050 size_t attribute_count
= params
->attributeNames
.size();
1051 for (size_t i
= 0; i
< attribute_count
; ++i
) {
1052 if (params
->attributeNames
[i
].equals(dev_attribute
))
1053 params
->attributeNames
[i
] = WebString();
1057 return is_nacl_allowed
;
1060 bool ChromeContentRendererClient::HasErrorPage(int http_status_code
,
1061 std::string
* error_domain
) {
1062 // Use an internal error page, if we have one for the status code.
1063 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain
,
1064 http_status_code
)) {
1068 *error_domain
= LocalizedError::kHttpErrorDomain
;
1072 bool ChromeContentRendererClient::ShouldSuppressErrorPage(
1073 content::RenderFrame
* render_frame
,
1075 // Unit tests for ChromeContentRendererClient pass a NULL RenderFrame here.
1076 // Unfortunately it's very difficult to construct a mock RenderView, so skip
1077 // this functionality in this case.
1079 content::RenderView
* render_view
= render_frame
->GetRenderView();
1080 content::RenderFrame
* main_render_frame
= render_view
->GetMainRenderFrame();
1081 blink::WebFrame
* web_frame
= render_frame
->GetWebFrame();
1082 NetErrorHelper
* net_error_helper
= NetErrorHelper::Get(main_render_frame
);
1083 if (net_error_helper
->ShouldSuppressErrorPage(web_frame
, url
))
1086 // Do not flash an error page if the Instant new tab page fails to load.
1087 return search_bouncer_
.get() && search_bouncer_
->IsNewTabPage(url
);
1090 void ChromeContentRendererClient::GetNavigationErrorStrings(
1091 content::RenderView
* render_view
,
1092 blink::WebFrame
* frame
,
1093 const blink::WebURLRequest
& failed_request
,
1094 const blink::WebURLError
& error
,
1095 std::string
* error_html
,
1096 base::string16
* error_description
) {
1097 const GURL failed_url
= error
.unreachableURL
;
1098 const Extension
* extension
= NULL
;
1100 #if defined(ENABLE_EXTENSIONS)
1101 if (failed_url
.is_valid() &&
1102 !failed_url
.SchemeIs(extensions::kExtensionScheme
)) {
1103 extension
= extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(
1108 bool is_post
= EqualsASCII(failed_request
.httpMethod(), "POST");
1111 // Use a local error page.
1112 if (extension
&& !extension
->from_bookmark()) {
1113 // TODO(erikkay): Should we use a different template for different
1115 int resource_id
= IDR_ERROR_APP_HTML
;
1116 const base::StringPiece
template_html(
1117 ResourceBundle::GetSharedInstance().GetRawDataResource(
1119 if (template_html
.empty()) {
1120 NOTREACHED() << "unable to load template. ID: " << resource_id
;
1122 base::DictionaryValue error_strings
;
1123 LocalizedError::GetAppErrorStrings(failed_url
, extension
,
1125 // "t" is the id of the template's root node.
1126 *error_html
= webui::GetTemplatesHtml(template_html
, &error_strings
,
1130 // TODO(ellyjones): change GetNavigationErrorStrings to take a RenderFrame
1131 // instead of a RenderView, then pass that in.
1132 // This is safe for now because we only install the NetErrorHelper on the
1133 // main render frame anyway; see the TODO(ellyjones) in
1134 // RenderFrameCreated.
1135 content::RenderFrame
* main_render_frame
=
1136 render_view
->GetMainRenderFrame();
1137 NetErrorHelper
* helper
= NetErrorHelper::Get(main_render_frame
);
1138 helper
->GetErrorHTML(frame
, error
, is_post
, error_html
);
1142 if (error_description
) {
1144 *error_description
= LocalizedError::GetErrorDetails(error
, is_post
);
1148 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
1149 #if defined(ENABLE_EXTENSIONS)
1150 return !extension_dispatcher_
->is_extension_process();
1156 bool ChromeContentRendererClient::AllowPopup() {
1157 #if defined(ENABLE_EXTENSIONS)
1158 extensions::ScriptContext
* current_context
=
1159 extension_dispatcher_
->script_context_set().GetCurrent();
1160 if (!current_context
|| !current_context
->extension())
1162 // See http://crbug.com/117446 for the subtlety of this check.
1163 switch (current_context
->context_type()) {
1164 case extensions::Feature::UNSPECIFIED_CONTEXT
:
1165 case extensions::Feature::WEB_PAGE_CONTEXT
:
1166 case extensions::Feature::UNBLESSED_EXTENSION_CONTEXT
:
1167 case extensions::Feature::WEBUI_CONTEXT
:
1169 case extensions::Feature::BLESSED_EXTENSION_CONTEXT
:
1170 case extensions::Feature::CONTENT_SCRIPT_CONTEXT
:
1172 case extensions::Feature::BLESSED_WEB_PAGE_CONTEXT
:
1173 return !current_context
->web_frame()->parent();
1180 bool ChromeContentRendererClient::ShouldFork(WebFrame
* frame
,
1182 const std::string
& http_method
,
1183 bool is_initial_navigation
,
1184 bool is_server_redirect
,
1185 bool* send_referrer
) {
1186 DCHECK(!frame
->parent());
1188 // If this is the Instant process, fork all navigations originating from the
1189 // renderer. The destination page will then be bucketed back to this Instant
1190 // process if it is an Instant url, or to another process if not. Conversely,
1191 // fork if this is a non-Instant process navigating to an Instant url, so that
1192 // such navigations can also be bucketed into an Instant renderer.
1193 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess
) ||
1194 (search_bouncer_
.get() && search_bouncer_
->ShouldFork(url
))) {
1195 *send_referrer
= true;
1199 // For now, we skip the rest for POST submissions. This is because
1200 // http://crbug.com/101395 is more likely to cause compatibility issues
1201 // with hosted apps and extensions than WebUI pages. We will remove this
1202 // check when cross-process POST submissions are supported.
1203 if (http_method
!= "GET")
1206 // If this is the Signin process, fork all navigations originating from the
1207 // renderer. The destination page will then be bucketed back to this Signin
1208 // process if it is a Signin url, or to another process if not.
1209 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSigninProcess
)) {
1210 // We never want to allow non-signin pages to fork-on-POST to a
1211 // signin-related action URL. We'll need to handle this carefully once
1212 // http://crbug.com/101395 is fixed. The CHECK ensures we don't forget.
1213 CHECK_NE(http_method
, "POST");
1217 // If |url| matches one of the prerendered URLs, stop this navigation and try
1218 // to swap in the prerendered page on the browser process. If the prerendered
1219 // page no longer exists by the time the OpenURL IPC is handled, a normal
1220 // navigation is attempted.
1221 if (prerender_dispatcher_
.get() &&
1222 prerender_dispatcher_
->IsPrerenderURL(url
)) {
1223 *send_referrer
= true;
1227 #if defined(ENABLE_EXTENSIONS)
1228 const extensions::ExtensionSet
* extensions
=
1229 extension_dispatcher_
->extensions();
1231 // Determine if the new URL is an extension (excluding bookmark apps).
1232 const Extension
* new_url_extension
= extensions::GetNonBookmarkAppExtension(
1234 bool is_extension_url
= !!new_url_extension
;
1236 // If the navigation would cross an app extent boundary, we also need
1237 // to defer to the browser to ensure process isolation. This is not necessary
1238 // for server redirects, which will be transferred to a new process by the
1239 // browser process when they are ready to commit. It is necessary for client
1240 // redirects, which won't be transferred in the same way.
1241 if (!is_server_redirect
&&
1242 CrossesExtensionExtents(frame
, url
, *extensions
, is_extension_url
,
1243 is_initial_navigation
)) {
1244 // Include the referrer in this case since we're going from a hosted web
1245 // page. (the packaged case is handled previously by the extension
1247 *send_referrer
= true;
1249 const Extension
* extension
=
1250 extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(url
);
1251 if (extension
&& extension
->is_app()) {
1252 UMA_HISTOGRAM_ENUMERATION(
1253 extension
->is_platform_app() ?
1254 extension_misc::kPlatformAppLaunchHistogram
:
1255 extension_misc::kAppLaunchHistogram
,
1256 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION
,
1257 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY
);
1262 // If this is a reload, check whether it has the wrong process type. We
1263 // should send it to the browser if it's an extension URL (e.g., hosted app)
1264 // in a normal process, or if it's a process for an extension that has been
1266 if (frame
->top()->document().url() == url
) {
1267 if (is_extension_url
!= extension_dispatcher_
->is_extension_process())
1270 #endif // defined(ENABLE_EXTENSIONS)
1275 bool ChromeContentRendererClient::WillSendRequest(
1276 blink::WebFrame
* frame
,
1277 ui::PageTransition transition_type
,
1279 const GURL
& first_party_for_cookies
,
1281 // Check whether the request should be allowed. If not allowed, we reset the
1282 // URL to something invalid to prevent the request and cause an error.
1283 #if defined(ENABLE_EXTENSIONS)
1284 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1285 !extensions::ResourceRequestPolicy::CanRequestResource(
1289 extension_dispatcher_
->extensions())) {
1290 *new_url
= GURL(chrome::kExtensionInvalidRequestURL
);
1294 if (url
.SchemeIs(extensions::kExtensionResourceScheme
) &&
1295 !extensions::ResourceRequestPolicy::CanRequestExtensionResourceScheme(
1298 *new_url
= GURL(chrome::kExtensionResourceInvalidRequestURL
);
1303 const content::RenderView
* render_view
=
1304 content::RenderView::FromWebView(frame
->view());
1305 SearchBox
* search_box
= SearchBox::Get(render_view
);
1306 if (search_box
&& url
.SchemeIs(chrome::kChromeSearchScheme
)) {
1307 if (url
.host() == chrome::kChromeUIThumbnailHost
)
1308 return search_box
->GenerateThumbnailURLFromTransientURL(url
, new_url
);
1309 else if (url
.host() == chrome::kChromeUIFaviconHost
)
1310 return search_box
->GenerateFaviconURLFromTransientURL(url
, new_url
);
1316 void ChromeContentRendererClient::DidCreateScriptContext(
1317 WebFrame
* frame
, v8::Handle
<v8::Context
> context
, int extension_group
,
1319 #if defined(ENABLE_EXTENSIONS)
1320 extension_dispatcher_
->DidCreateScriptContext(
1321 frame
, context
, extension_group
, world_id
);
1325 unsigned long long ChromeContentRendererClient::VisitedLinkHash(
1326 const char* canonical_url
, size_t length
) {
1327 return visited_link_slave_
->ComputeURLFingerprint(canonical_url
, length
);
1330 bool ChromeContentRendererClient::IsLinkVisited(unsigned long long link_hash
) {
1331 return visited_link_slave_
->IsVisited(link_hash
);
1334 blink::WebPrescientNetworking
*
1335 ChromeContentRendererClient::GetPrescientNetworking() {
1336 return prescient_networking_dispatcher_
.get();
1339 bool ChromeContentRendererClient::ShouldOverridePageVisibilityState(
1340 const content::RenderFrame
* render_frame
,
1341 blink::WebPageVisibilityState
* override_state
) {
1342 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
))
1345 *override_state
= blink::WebPageVisibilityStatePrerender
;
1349 #if defined(ENABLE_EXTENSIONS)
1350 void ChromeContentRendererClient::SetExtensionDispatcherForTest(
1351 extensions::Dispatcher
* extension_dispatcher
) {
1352 extension_dispatcher_
.reset(extension_dispatcher
);
1353 permissions_policy_delegate_
.reset(
1354 new extensions::RendererPermissionsPolicyDelegate(
1355 extension_dispatcher_
.get()));
1358 extensions::Dispatcher
*
1359 ChromeContentRendererClient::GetExtensionDispatcherForTest() {
1360 return extension_dispatcher_
.get();
1363 bool ChromeContentRendererClient::CrossesExtensionExtents(
1365 const GURL
& new_url
,
1366 const extensions::ExtensionSet
& extensions
,
1367 bool is_extension_url
,
1368 bool is_initial_navigation
) {
1369 GURL
old_url(frame
->top()->document().url());
1371 // If old_url is still empty and this is an initial navigation, then this is
1372 // a window.open operation. We should look at the opener URL.
1373 if (is_initial_navigation
&& old_url
.is_empty() && frame
->opener()) {
1374 // If we're about to open a normal web page from a same-origin opener stuck
1375 // in an extension process, we want to keep it in process to allow the
1376 // opener to script it.
1377 WebDocument opener_document
= frame
->opener()->document();
1378 WebSecurityOrigin opener
= frame
->opener()->document().securityOrigin();
1379 bool opener_is_extension_url
=
1380 !opener
.isUnique() && extensions
.GetExtensionOrAppByURL(
1381 opener_document
.url()) != NULL
;
1382 if (!is_extension_url
&&
1383 !opener_is_extension_url
&&
1384 extension_dispatcher_
->is_extension_process() &&
1385 opener
.canRequest(WebURL(new_url
)))
1388 // In all other cases, we want to compare against the top frame's URL (as
1389 // opposed to the opener frame's), since that's what determines the type of
1390 // process. This allows iframes outside an app to open a popup in the app.
1391 old_url
= frame
->top()->opener()->top()->document().url();
1394 // Only consider keeping non-app URLs in an app process if this window
1395 // has an opener (in which case it might be an OAuth popup that tries to
1396 // script an iframe within the app).
1397 bool should_consider_workaround
= !!frame
->opener();
1399 return extensions::CrossesExtensionProcessBoundary(
1400 extensions
, old_url
, new_url
, should_consider_workaround
);
1402 #endif // defined(ENABLE_EXTENSIONS)
1404 #if defined(ENABLE_SPELLCHECK)
1405 void ChromeContentRendererClient::SetSpellcheck(SpellCheck
* spellcheck
) {
1406 RenderThread
* thread
= RenderThread::Get();
1407 if (spellcheck_
.get() && thread
)
1408 thread
->RemoveObserver(spellcheck_
.get());
1409 spellcheck_
.reset(spellcheck
);
1410 SpellCheckReplacer
replacer(spellcheck_
.get());
1411 content::RenderView::ForEach(&replacer
);
1413 thread
->AddObserver(spellcheck_
.get());
1418 bool ChromeContentRendererClient::WasWebRequestUsedBySomeExtensions() {
1419 #if defined(ENABLE_EXTENSIONS)
1420 return g_current_client
->extension_dispatcher_
1421 ->WasWebRequestUsedBySomeExtensions();
1427 const void* ChromeContentRendererClient::CreatePPAPIInterface(
1428 const std::string
& interface_name
) {
1429 #if defined(ENABLE_PLUGINS)
1430 #if !defined(DISABLE_NACL)
1431 if (interface_name
== PPB_NACL_PRIVATE_INTERFACE
)
1432 return nacl::GetNaClPrivateInterface();
1433 #endif // DISABLE_NACL
1434 if (interface_name
== PPB_PDF_INTERFACE
)
1435 return pdf::PPB_PDF_Impl::GetInterface();
1440 bool ChromeContentRendererClient::IsExternalPepperPlugin(
1441 const std::string
& module_name
) {
1442 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
1443 // We must defer certain plugin events for NaCl instances since we switch
1444 // from the in-process to the out-of-process proxy after instantiating them.
1445 return module_name
== "Native Client";
1448 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1449 bool ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
1450 const GURL
& url
, const std::set
<std::string
>& whitelist
) {
1451 const extensions::ExtensionSet
* extension_set
=
1452 g_current_client
->extension_dispatcher_
->extensions();
1453 return chrome::IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
1458 blink::WebSpeechSynthesizer
*
1459 ChromeContentRendererClient::OverrideSpeechSynthesizer(
1460 blink::WebSpeechSynthesizerClient
* client
) {
1461 return new TtsDispatcher(client
);
1464 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI(
1466 #if !defined(OS_ANDROID)
1467 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check
1468 // the whitelist in the renderer, since we're only preventing access until
1469 // these APIs are public and stable.
1470 std::string url_host
= url
.host();
1471 if (url
.SchemeIs("https") &&
1472 (EndsWith(url_host
, "talkgadget.google.com", false) ||
1473 EndsWith(url_host
, "plus.google.com", false) ||
1474 EndsWith(url_host
, "plus.sandbox.google.com", false)) &&
1475 StartsWithASCII(url
.path(), "/hangouts/", false)) {
1478 // Allow access for tests.
1479 if (CommandLine::ForCurrentProcess()->HasSwitch(
1480 switches::kEnablePepperTesting
)) {
1483 #endif // !defined(OS_ANDROID)
1487 void ChromeContentRendererClient::AddKeySystems(
1488 std::vector
<content::KeySystemInfo
>* key_systems
) {
1489 AddChromeKeySystems(key_systems
);
1492 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource(
1493 const base::string16
& source
) const {
1494 return extensions::IsSourceFromAnExtension(source
);
1497 bool ChromeContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
1498 // SiteIsolationPolicy is off by default. We would like to activate cross-site
1499 // document blocking (for UMA data collection) for normal renderer processes
1500 // running a normal web page from the Internet. We only turn on
1501 // SiteIsolationPolicy for a renderer process that does not have the extension
1503 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
1504 return !command_line
->HasSwitch(extensions::switches::kExtensionProcess
);
1507 blink::WebWorkerPermissionClientProxy
*
1508 ChromeContentRendererClient::CreateWorkerPermissionClientProxy(
1509 content::RenderFrame
* render_frame
,
1510 blink::WebFrame
* frame
) {
1511 return new WorkerPermissionClientProxy(render_frame
, frame
);
1514 bool ChromeContentRendererClient::IsPluginAllowedToUseDevChannelAPIs() {
1515 #if defined(ENABLE_PLUGINS)
1516 // Allow access for tests.
1517 if (CommandLine::ForCurrentProcess()->HasSwitch(
1518 switches::kEnablePepperTesting
)) {
1522 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1523 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
1524 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
1525 // Chromium builds as well.
1526 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1532 bool ChromeContentRendererClient::IsPluginAllowedToUseCompositorAPI(
1534 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1535 if (CommandLine::ForCurrentProcess()->HasSwitch(
1536 switches::kEnablePepperTesting
))
1538 if (IsExtensionOrSharedModuleWhitelisted(url
, allowed_compositor_origins_
))
1541 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1542 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1548 bool ChromeContentRendererClient::IsPluginAllowedToUseVideoDecodeAPI(
1550 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
1551 if (CommandLine::ForCurrentProcess()->HasSwitch(
1552 switches::kEnablePepperTesting
))
1555 if (IsExtensionOrSharedModuleWhitelisted(url
, allowed_video_decode_origins_
))
1558 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
1559 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
1565 content::BrowserPluginDelegate
*
1566 ChromeContentRendererClient::CreateBrowserPluginDelegate(
1567 content::RenderFrame
* render_frame
,
1568 const std::string
& mime_type
) {
1569 #if defined(ENABLE_EXTENSIONS)
1570 return new extensions::GuestViewContainer(render_frame
, mime_type
);