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/histogram.h"
11 #include "base/metrics/user_metrics_action.h"
12 #include "base/path_service.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_content_client.h"
18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/content_settings_pattern.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/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/extensions/chrome_extension_helper.h"
35 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h"
36 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h"
37 #include "chrome/renderer/extensions/extension_frame_helper.h"
38 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
39 #include "chrome/renderer/extensions/resource_request_policy.h"
40 #include "chrome/renderer/external_extension.h"
41 #include "chrome/renderer/loadtimes_extension_bindings.h"
42 #include "chrome/renderer/media/cast_ipc_dispatcher.h"
43 #include "chrome/renderer/media/chrome_key_systems.h"
44 #include "chrome/renderer/net/net_error_helper.h"
45 #include "chrome/renderer/net/prescient_networking_dispatcher.h"
46 #include "chrome/renderer/net/renderer_net_predictor.h"
47 #include "chrome/renderer/net_benchmarking_extension.h"
48 #include "chrome/renderer/page_load_histograms.h"
49 #include "chrome/renderer/pepper/pepper_helper.h"
50 #include "chrome/renderer/pepper/ppb_pdf_impl.h"
51 #include "chrome/renderer/playback_extension.h"
52 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
53 #include "chrome/renderer/plugins/plugin_uma.h"
54 #include "chrome/renderer/prerender/prerender_dispatcher.h"
55 #include "chrome/renderer/prerender/prerender_helper.h"
56 #include "chrome/renderer/prerender/prerender_media_load_deferrer.h"
57 #include "chrome/renderer/prerender/prerenderer_client.h"
58 #include "chrome/renderer/principals_extension_bindings.h"
59 #include "chrome/renderer/printing/print_web_view_helper.h"
60 #include "chrome/renderer/safe_browsing/malware_dom_details.h"
61 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
62 #include "chrome/renderer/searchbox/search_bouncer.h"
63 #include "chrome/renderer/searchbox/searchbox.h"
64 #include "chrome/renderer/searchbox/searchbox_extension.h"
65 #include "chrome/renderer/tts_dispatcher.h"
66 #include "chrome/renderer/worker_permission_client_proxy.h"
67 #include "components/autofill/content/renderer/autofill_agent.h"
68 #include "components/autofill/content/renderer/password_autofill_agent.h"
69 #include "components/autofill/content/renderer/password_generation_agent.h"
70 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
71 #include "components/plugins/renderer/mobile_youtube_plugin.h"
72 #include "components/signin/core/common/profile_management_switches.h"
73 #include "components/visitedlink/renderer/visitedlink_slave.h"
74 #include "content/public/common/content_constants.h"
75 #include "content/public/renderer/render_frame.h"
76 #include "content/public/renderer/render_thread.h"
77 #include "content/public/renderer/render_view.h"
78 #include "content/public/renderer/render_view_visitor.h"
79 #include "extensions/common/constants.h"
80 #include "extensions/common/extension.h"
81 #include "extensions/common/extension_set.h"
82 #include "extensions/common/extension_urls.h"
83 #include "extensions/common/switches.h"
84 #include "extensions/renderer/dispatcher.h"
85 #include "extensions/renderer/extension_helper.h"
86 #include "extensions/renderer/script_context.h"
87 #include "grit/generated_resources.h"
88 #include "grit/locale_settings.h"
89 #include "grit/renderer_resources.h"
90 #include "ipc/ipc_sync_channel.h"
91 #include "net/base/net_errors.h"
92 #include "ppapi/c/private/ppb_nacl_private.h"
93 #include "ppapi/c/private/ppb_pdf.h"
94 #include "ppapi/shared_impl/ppapi_switches.h"
95 #include "third_party/WebKit/public/platform/WebURL.h"
96 #include "third_party/WebKit/public/platform/WebURLError.h"
97 #include "third_party/WebKit/public/platform/WebURLRequest.h"
98 #include "third_party/WebKit/public/web/WebCache.h"
99 #include "third_party/WebKit/public/web/WebDataSource.h"
100 #include "third_party/WebKit/public/web/WebDocument.h"
101 #include "third_party/WebKit/public/web/WebElement.h"
102 #include "third_party/WebKit/public/web/WebLocalFrame.h"
103 #include "third_party/WebKit/public/web/WebPluginContainer.h"
104 #include "third_party/WebKit/public/web/WebPluginParams.h"
105 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
106 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
107 #include "ui/base/l10n/l10n_util.h"
108 #include "ui/base/layout.h"
109 #include "ui/base/resource/resource_bundle.h"
110 #include "ui/base/webui/jstemplate_builder.h"
111 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
113 #if !defined(DISABLE_NACL)
114 #include "components/nacl/renderer/nacl_helper.h"
117 #if defined(ENABLE_EXTENSIONS)
118 #include "chrome/renderer/extensions/chrome_extensions_render_frame_observer.h"
121 #if defined(ENABLE_SPELLCHECK)
122 #include "chrome/renderer/spellchecker/spellcheck.h"
123 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
126 #if defined(ENABLE_WEBRTC)
127 #include "chrome/renderer/media/webrtc_logging_message_filter.h"
131 #include "chrome_elf/blacklist/blacklist.h"
134 using autofill::AutofillAgent
;
135 using autofill::PasswordAutofillAgent
;
136 using autofill::PasswordGenerationAgent
;
137 using base::ASCIIToUTF16
;
138 using base::UserMetricsAction
;
139 using content::RenderThread
;
140 using content::WebPluginInfo
;
141 using extensions::Extension
;
142 using blink::WebCache
;
143 using blink::WebConsoleMessage
;
144 using blink::WebDataSource
;
145 using blink::WebDocument
;
146 using blink::WebFrame
;
147 using blink::WebLocalFrame
;
148 using blink::WebPlugin
;
149 using blink::WebPluginParams
;
150 using blink::WebSecurityOrigin
;
151 using blink::WebSecurityPolicy
;
152 using blink::WebString
;
154 using blink::WebURLError
;
155 using blink::WebURLRequest
;
156 using blink::WebURLResponse
;
157 using blink::WebVector
;
161 const char kWebViewTagName
[] = "WEBVIEW";
163 ChromeContentRendererClient
* g_current_client
;
165 static void AppendParams(const std::vector
<base::string16
>& additional_names
,
166 const std::vector
<base::string16
>& additional_values
,
167 WebVector
<WebString
>* existing_names
,
168 WebVector
<WebString
>* existing_values
) {
169 DCHECK(additional_names
.size() == additional_values
.size());
170 DCHECK(existing_names
->size() == existing_values
->size());
172 size_t existing_size
= existing_names
->size();
173 size_t total_size
= existing_size
+ additional_names
.size();
175 WebVector
<WebString
> names(total_size
);
176 WebVector
<WebString
> values(total_size
);
178 for (size_t i
= 0; i
< existing_size
; ++i
) {
179 names
[i
] = (*existing_names
)[i
];
180 values
[i
] = (*existing_values
)[i
];
183 for (size_t i
= 0; i
< additional_names
.size(); ++i
) {
184 names
[existing_size
+ i
] = additional_names
[i
];
185 values
[existing_size
+ i
] = additional_values
[i
];
188 existing_names
->swap(names
);
189 existing_values
->swap(values
);
192 #if defined(ENABLE_SPELLCHECK)
193 class SpellCheckReplacer
: public content::RenderViewVisitor
{
195 explicit SpellCheckReplacer(SpellCheck
* spellcheck
)
196 : spellcheck_(spellcheck
) {}
197 virtual bool Visit(content::RenderView
* render_view
) OVERRIDE
;
200 SpellCheck
* spellcheck_
; // New shared spellcheck for all views. Weak Ptr.
201 DISALLOW_COPY_AND_ASSIGN(SpellCheckReplacer
);
204 bool SpellCheckReplacer::Visit(content::RenderView
* render_view
) {
205 SpellCheckProvider
* provider
= SpellCheckProvider::Get(render_view
);
207 provider
->set_spellcheck(spellcheck_
);
212 // For certain sandboxed Pepper plugins, use the JavaScript Content Settings.
213 bool ShouldUseJavaScriptSettingForPlugin(const WebPluginInfo
& plugin
) {
214 if (plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS
&&
215 plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
) {
219 // Treat Native Client invocations like JavaScript.
220 if (plugin
.name
== ASCIIToUTF16(ChromeContentClient::kNaClPluginName
))
223 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
224 // Treat CDM invocations like JavaScript.
225 if (plugin
.name
== ASCIIToUTF16(kWidevineCdmDisplayName
)) {
226 DCHECK(plugin
.type
== WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
);
229 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
236 ChromeContentRendererClient::ChromeContentRendererClient() {
237 g_current_client
= this;
239 extensions::ExtensionsClient::Set(
240 extensions::ChromeExtensionsClient::GetInstance());
241 extensions::ExtensionsRendererClient::Set(
242 ChromeExtensionsRendererClient::GetInstance());
245 ChromeContentRendererClient::~ChromeContentRendererClient() {
246 g_current_client
= NULL
;
249 void ChromeContentRendererClient::RenderThreadStarted() {
250 RenderThread
* thread
= RenderThread::Get();
252 chrome_observer_
.reset(new ChromeRenderProcessObserver(this));
254 extension_dispatcher_delegate_
.reset(
255 new ChromeExtensionsDispatcherDelegate());
256 // ChromeRenderViewTest::SetUp() creates its own ExtensionDispatcher and
257 // injects it using SetExtensionDispatcher(). Don't overwrite it.
258 if (!extension_dispatcher_
) {
259 extension_dispatcher_
.reset(
260 new extensions::Dispatcher(extension_dispatcher_delegate_
.get()));
262 permissions_policy_delegate_
.reset(
263 new extensions::RendererPermissionsPolicyDelegate(
264 extension_dispatcher_
.get()));
265 prescient_networking_dispatcher_
.reset(new PrescientNetworkingDispatcher());
266 net_predictor_
.reset(new RendererNetPredictor());
267 #if defined(ENABLE_SPELLCHECK)
268 // ChromeRenderViewTest::SetUp() creates a Spellcheck and injects it using
269 // SetSpellcheck(). Don't overwrite it.
271 spellcheck_
.reset(new SpellCheck());
272 thread
->AddObserver(spellcheck_
.get());
275 visited_link_slave_
.reset(new visitedlink::VisitedLinkSlave());
276 #if defined(FULL_SAFE_BROWSING)
277 phishing_classifier_
.reset(safe_browsing::PhishingClassifierFilter::Create());
279 prerender_dispatcher_
.reset(new prerender::PrerenderDispatcher());
280 #if defined(ENABLE_WEBRTC)
281 webrtc_logging_message_filter_
= new WebRtcLoggingMessageFilter(
282 content::RenderThread::Get()->GetIOMessageLoopProxy());
284 search_bouncer_
.reset(new SearchBouncer());
286 thread
->AddObserver(chrome_observer_
.get());
287 thread
->AddObserver(extension_dispatcher_
.get());
288 #if defined(FULL_SAFE_BROWSING)
289 thread
->AddObserver(phishing_classifier_
.get());
291 thread
->AddObserver(visited_link_slave_
.get());
292 thread
->AddObserver(prerender_dispatcher_
.get());
293 thread
->AddObserver(search_bouncer_
.get());
295 #if defined(ENABLE_WEBRTC)
296 thread
->AddFilter(webrtc_logging_message_filter_
.get());
298 thread
->AddFilter(new CastIPCDispatcher(
299 content::RenderThread::Get()->GetIOMessageLoopProxy()));
301 thread
->RegisterExtension(extensions_v8::ExternalExtension::Get());
302 thread
->RegisterExtension(extensions_v8::LoadTimesExtension::Get());
304 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
305 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
306 thread
->RegisterExtension(extensions_v8::BenchmarkingExtension::Get());
307 if (command_line
->HasSwitch(switches::kEnableNetBenchmarking
))
308 thread
->RegisterExtension(extensions_v8::NetBenchmarkingExtension::Get());
309 if (command_line
->HasSwitch(switches::kInstantProcess
))
310 thread
->RegisterExtension(extensions_v8::SearchBoxExtension::Get());
312 if (command_line
->HasSwitch(switches::kPlaybackMode
) ||
313 command_line
->HasSwitch(switches::kRecordMode
)) {
314 thread
->RegisterExtension(extensions_v8::PlaybackExtension::Get());
317 // TODO(guohui): needs to forward the new-profile-management switch to
318 // renderer processes.
319 if (switches::IsNewProfileManagement())
320 thread
->RegisterExtension(extensions_v8::PrincipalsExtension::Get());
322 // chrome:, chrome-search:, chrome-devtools:, and chrome-distiller: pages
323 // should not be accessible by normal content, and should also be unable to
324 // script anything but themselves (to help limit the damage that a corrupt
325 // page could cause).
326 WebString
chrome_ui_scheme(ASCIIToUTF16(content::kChromeUIScheme
));
327 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme
);
329 WebString
chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme
));
330 // The Instant process can only display the content but not read it. Other
331 // processes can't display it or read it.
332 if (!command_line
->HasSwitch(switches::kInstantProcess
))
333 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_search_scheme
);
335 WebString
dev_tools_scheme(ASCIIToUTF16(content::kChromeDevToolsScheme
));
336 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dev_tools_scheme
);
338 WebString
dom_distiller_scheme(ASCIIToUTF16(chrome::kDomDistillerScheme
));
339 // TODO(nyquist): Add test to ensure this happens when the flag is set.
340 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dom_distiller_scheme
);
342 #if defined(OS_CHROMEOS)
343 WebString
drive_scheme(ASCIIToUTF16(chrome::kDriveScheme
));
344 WebSecurityPolicy::registerURLSchemeAsLocal(drive_scheme
);
347 // chrome: and chrome-search: pages should not be accessible by bookmarklets
348 // or javascript: URLs typed in the omnibox.
349 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
351 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
352 chrome_search_scheme
);
354 // chrome:, chrome-search:, and chrome-extension: resources shouldn't trigger
355 // insecure content warnings.
356 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_ui_scheme
);
357 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_search_scheme
);
359 WebString
extension_scheme(ASCIIToUTF16(extensions::kExtensionScheme
));
360 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme
);
362 // chrome-extension: resources should be allowed to receive CORS requests.
363 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_scheme
);
365 WebString
extension_resource_scheme(
366 ASCIIToUTF16(extensions::kExtensionResourceScheme
));
367 WebSecurityPolicy::registerURLSchemeAsSecure(extension_resource_scheme
);
369 // chrome-extension-resource: resources should be allowed to receive CORS
371 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_resource_scheme
);
373 // chrome-extension: resources should bypass Content Security Policy checks
374 // when included in protected resources.
375 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
377 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
378 extension_resource_scheme
);
381 // Report if the renderer process has been patched by chrome_elf.
382 // TODO(csharp): Remove once the renderer is no longer getting
384 if (blacklist::IsBlacklistInitialized())
385 UMA_HISTOGRAM_BOOLEAN("Blacklist.PatchedInRenderer", true);
389 void ChromeContentRendererClient::RenderFrameCreated(
390 content::RenderFrame
* render_frame
) {
391 new ChromeRenderFrameObserver(render_frame
);
393 ContentSettingsObserver
* content_settings
=
394 new ContentSettingsObserver(render_frame
, extension_dispatcher_
.get());
395 if (chrome_observer_
.get()) {
396 content_settings
->SetContentSettingRules(
397 chrome_observer_
->content_setting_rules());
400 #if defined(ENABLE_EXTENSIONS)
401 new extensions::ChromeExtensionsRenderFrameObserver(render_frame
);
403 new extensions::ExtensionFrameHelper(render_frame
,
404 extension_dispatcher_
.get());
406 #if defined(ENABLE_PLUGINS)
407 new PepperHelper(render_frame
);
410 #if !defined(DISABLE_NACL)
411 new nacl::NaClHelper(render_frame
);
414 // TODO(jam): when the frame tree moves into content and parent() works at
415 // RenderFrame construction, simplify this by just checking parent().
416 if (render_frame
->GetRenderView()->GetMainRenderFrame() != render_frame
) {
417 // Avoid any race conditions from having the browser tell subframes that
418 // they're prerendering.
419 if (prerender::PrerenderHelper::IsPrerendering(
420 render_frame
->GetRenderView()->GetMainRenderFrame())) {
421 new prerender::PrerenderHelper(render_frame
);
425 if (render_frame
->GetRenderView()->GetMainRenderFrame() == render_frame
) {
426 // Only attach NetErrorHelper to the main frame, since only the main frame
427 // should get error pages.
428 new NetErrorHelper(render_frame
);
432 void ChromeContentRendererClient::RenderViewCreated(
433 content::RenderView
* render_view
) {
434 new extensions::ExtensionHelper(render_view
, extension_dispatcher_
.get());
435 new extensions::ChromeExtensionHelper(render_view
);
436 new PageLoadHistograms(render_view
);
437 #if defined(ENABLE_PRINTING)
438 new printing::PrintWebViewHelper(render_view
);
440 #if defined(ENABLE_SPELLCHECK)
441 new SpellCheckProvider(render_view
, spellcheck_
.get());
443 new prerender::PrerendererClient(render_view
);
444 #if defined(FULL_SAFE_BROWSING)
445 safe_browsing::MalwareDOMDetails::Create(render_view
);
448 PasswordGenerationAgent
* password_generation_agent
=
449 new PasswordGenerationAgent(render_view
);
450 PasswordAutofillAgent
* password_autofill_agent
=
451 new PasswordAutofillAgent(render_view
);
452 new AutofillAgent(render_view
,
453 password_autofill_agent
,
454 password_generation_agent
);
456 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
457 if (command_line
->HasSwitch(switches::kInstantProcess
))
458 new SearchBox(render_view
);
460 new ChromeRenderViewObserver(render_view
, chrome_observer_
.get());
463 void ChromeContentRendererClient::SetNumberOfViews(int number_of_views
) {
464 base::debug::SetCrashKeyValue(crash_keys::kNumberOfViews
,
465 base::IntToString(number_of_views
));
468 SkBitmap
* ChromeContentRendererClient::GetSadPluginBitmap() {
469 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
470 GetImageNamed(IDR_SAD_PLUGIN
).ToSkBitmap());
473 SkBitmap
* ChromeContentRendererClient::GetSadWebViewBitmap() {
474 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
475 GetImageNamed(IDR_SAD_WEBVIEW
).ToSkBitmap());
478 std::string
ChromeContentRendererClient::GetDefaultEncoding() {
479 return l10n_util::GetStringUTF8(IDS_DEFAULT_ENCODING
);
482 const Extension
* ChromeContentRendererClient::GetExtensionByOrigin(
483 const WebSecurityOrigin
& origin
) const {
484 if (!EqualsASCII(origin
.protocol(), extensions::kExtensionScheme
))
487 const std::string extension_id
= origin
.host().utf8().data();
488 return extension_dispatcher_
->extensions()->GetByID(extension_id
);
491 bool ChromeContentRendererClient::OverrideCreatePlugin(
492 content::RenderFrame
* render_frame
,
493 WebLocalFrame
* frame
,
494 const WebPluginParams
& params
,
495 WebPlugin
** plugin
) {
496 std::string orig_mime_type
= params
.mimeType
.utf8();
497 if (orig_mime_type
== content::kBrowserPluginMimeType
) {
498 WebDocument document
= frame
->document();
499 const Extension
* extension
=
500 GetExtensionByOrigin(document
.securityOrigin());
502 const extensions::APIPermission::ID perms
[] = {
503 extensions::APIPermission::kWebView
,
505 for (size_t i
= 0; i
< arraysize(perms
); ++i
) {
506 if (extension
->permissions_data()->HasAPIPermission(perms
[i
]))
512 ChromeViewHostMsg_GetPluginInfo_Output output
;
513 #if defined(ENABLE_PLUGINS)
514 render_frame
->Send(new ChromeViewHostMsg_GetPluginInfo(
515 render_frame
->GetRoutingID(), GURL(params
.url
),
516 frame
->top()->document().url(), orig_mime_type
, &output
));
518 if (output
.plugin
.type
== content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN
)
521 output
.status
.value
= ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
;
523 *plugin
= CreatePlugin(render_frame
, frame
, params
, output
);
527 WebPlugin
* ChromeContentRendererClient::CreatePluginReplacement(
528 content::RenderFrame
* render_frame
,
529 const base::FilePath
& plugin_path
) {
530 ChromePluginPlaceholder
* placeholder
=
531 ChromePluginPlaceholder::CreateErrorPlugin(render_frame
, plugin_path
);
532 return placeholder
->plugin();
535 void ChromeContentRendererClient::DeferMediaLoad(
536 content::RenderFrame
* render_frame
,
537 const base::Closure
& closure
) {
538 #if defined(OS_ANDROID)
539 // Chromium for Android doesn't support prerender yet.
543 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
548 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
549 new prerender::PrerenderMediaLoadDeferrer(render_frame
, closure
);
553 WebPlugin
* ChromeContentRendererClient::CreatePlugin(
554 content::RenderFrame
* render_frame
,
555 WebLocalFrame
* frame
,
556 const WebPluginParams
& original_params
,
557 const ChromeViewHostMsg_GetPluginInfo_Output
& output
) {
558 const ChromeViewHostMsg_GetPluginInfo_Status
& status
= output
.status
;
559 const WebPluginInfo
& plugin
= output
.plugin
;
560 const std::string
& actual_mime_type
= output
.actual_mime_type
;
561 const base::string16
& group_name
= output
.group_name
;
562 const std::string
& identifier
= output
.group_identifier
;
563 ChromeViewHostMsg_GetPluginInfo_Status::Value status_value
= status
.value
;
564 GURL
url(original_params
.url
);
565 std::string orig_mime_type
= original_params
.mimeType
.utf8();
566 ChromePluginPlaceholder
* placeholder
= NULL
;
568 // If the browser plugin is to be enabled, this should be handled by the
569 // renderer, so the code won't reach here due to the early exit in
570 // OverrideCreatePlugin.
571 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
||
572 orig_mime_type
== content::kBrowserPluginMimeType
) {
573 #if defined(OS_ANDROID)
574 if (plugins::MobileYouTubePlugin::IsYouTubeURL(url
, orig_mime_type
)) {
575 base::StringPiece
template_html(
576 ResourceBundle::GetSharedInstance().GetRawDataResource(
577 IDR_MOBILE_YOUTUBE_PLUGIN_HTML
));
578 return (new plugins::MobileYouTubePlugin(
583 GURL(ChromePluginPlaceholder::kPluginPlaceholderDataURL
)))
587 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type
, url
);
588 placeholder
= ChromePluginPlaceholder::CreateMissingPlugin(
589 render_frame
, frame
, original_params
);
591 // TODO(bauerb): This should be in content/.
592 WebPluginParams
params(original_params
);
593 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
594 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
595 AppendParams(plugin
.mime_types
[i
].additional_param_names
,
596 plugin
.mime_types
[i
].additional_param_values
,
597 ¶ms
.attributeNames
,
598 ¶ms
.attributeValues
);
602 if (params
.mimeType
.isNull() && (actual_mime_type
.size() > 0)) {
603 // Webkit might say that mime type is null while we already know the
604 // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case
605 // we should use what we know since WebpluginDelegateProxy does some
606 // specific initializations based on this information.
607 params
.mimeType
= WebString::fromUTF8(actual_mime_type
.c_str());
610 ContentSettingsObserver
* observer
=
611 ContentSettingsObserver::Get(render_frame
);
613 const ContentSettingsType content_type
=
614 ShouldUseJavaScriptSettingForPlugin(plugin
) ?
615 CONTENT_SETTINGS_TYPE_JAVASCRIPT
:
616 CONTENT_SETTINGS_TYPE_PLUGINS
;
619 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
||
620 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
||
621 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
) &&
622 observer
->IsPluginTemporarilyAllowed(identifier
)) {
623 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
626 // Allow full-page plug-ins for click-to-play.
627 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
&&
630 frame
->document().isPluginDocument()) {
631 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
635 // In Windows we need to check if we can load NPAPI plugins.
636 // For example, if the render view is in the Ash desktop, we should not.
637 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
&&
638 plugin
.type
== content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
639 if (observer
->AreNPAPIPluginsBlocked())
641 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
;
645 switch (status_value
) {
646 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
: {
650 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
: {
651 const bool is_nacl_plugin
=
652 plugin
.name
== ASCIIToUTF16(ChromeContentClient::kNaClPluginName
);
653 const bool is_nacl_mime_type
=
654 actual_mime_type
== "application/x-nacl";
655 const bool is_pnacl_mime_type
=
656 actual_mime_type
== "application/x-pnacl";
657 if (is_nacl_plugin
|| is_nacl_mime_type
|| is_pnacl_mime_type
) {
658 bool is_nacl_unrestricted
= false;
659 if (is_nacl_mime_type
) {
660 is_nacl_unrestricted
=
661 CommandLine::ForCurrentProcess()->HasSwitch(
662 switches::kEnableNaCl
);
663 } else if (is_pnacl_mime_type
) {
664 is_nacl_unrestricted
=
665 !CommandLine::ForCurrentProcess()->HasSwitch(
666 switches::kDisablePnacl
);
670 if (is_nacl_mime_type
|| is_pnacl_mime_type
) {
671 // Normal NaCl/PNaCl embed. The app URL is the page URL.
673 app_url
= frame
->top()->document().url();
675 // NaCl is being invoked as a content handler. Look up the NaCl
676 // module using the MIME type. The app URL is the manifest URL.
677 manifest_url
= GetNaClContentHandlerURL(actual_mime_type
, plugin
);
678 app_url
= manifest_url
;
680 const Extension
* extension
=
681 g_current_client
->extension_dispatcher_
->extensions()->
682 GetExtensionOrAppByURL(manifest_url
);
683 if (!IsNaClAllowed(manifest_url
,
685 is_nacl_unrestricted
,
688 WebString error_message
;
689 if (is_nacl_mime_type
) {
691 "Only unpacked extensions and apps installed from the Chrome "
692 "Web Store can load NaCl modules without enabling Native "
693 "Client in about:flags.";
694 } else if (is_pnacl_mime_type
) {
696 "Portable Native Client must not be disabled in about:flags.";
698 frame
->addMessageToConsole(
699 WebConsoleMessage(WebConsoleMessage::LevelError
,
701 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
708 IDR_BLOCKED_PLUGIN_HTML
,
709 #if defined(OS_CHROMEOS)
710 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED
));
712 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
718 // Delay loading plugins if prerendering.
719 // TODO(mmenke): In the case of prerendering, feed into
720 // ChromeContentRendererClient::CreatePlugin instead, to
721 // reduce the chance of future regressions.
722 if (prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
723 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
730 IDR_CLICK_TO_PLAY_PLUGIN_HTML
,
731 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD
, group_name
));
732 placeholder
->set_blocked_for_prerendering(true);
733 placeholder
->set_allow_loading(true);
737 return render_frame
->CreatePlugin(frame
, plugin
, params
);
739 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
: {
740 RenderThread::Get()->RecordAction(
741 UserMetricsAction("Plugin_NPAPINotSupported"));
742 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
749 IDR_BLOCKED_PLUGIN_HTML
,
750 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO
));
751 render_frame
->Send(new ChromeViewHostMsg_NPAPINotSupported(
752 render_frame
->GetRoutingID(), identifier
));
755 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled
: {
756 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type
,
758 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
765 IDR_DISABLED_PLUGIN_HTML
,
766 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED
, group_name
));
769 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked
: {
770 #if defined(ENABLE_PLUGIN_INSTALLATION)
771 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
778 IDR_BLOCKED_PLUGIN_HTML
,
779 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
780 placeholder
->set_allow_loading(true);
781 render_frame
->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
782 render_frame
->GetRoutingID(), placeholder
->CreateRoutingId(),
789 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed
: {
790 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
797 IDR_BLOCKED_PLUGIN_HTML
,
798 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
801 case ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
: {
802 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
809 IDR_BLOCKED_PLUGIN_HTML
,
810 l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED
, group_name
));
811 placeholder
->set_allow_loading(true);
812 render_frame
->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin(
813 render_frame
->GetRoutingID(),
818 case ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
: {
819 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
826 IDR_CLICK_TO_PLAY_PLUGIN_HTML
,
827 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD
, group_name
));
828 placeholder
->set_allow_loading(true);
829 RenderThread::Get()->RecordAction(
830 UserMetricsAction("Plugin_ClickToPlay"));
831 observer
->DidBlockContentType(content_type
);
834 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
: {
835 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
842 IDR_BLOCKED_PLUGIN_HTML
,
843 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
844 placeholder
->set_allow_loading(true);
845 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked"));
846 observer
->DidBlockContentType(content_type
);
849 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy
: {
850 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
857 IDR_BLOCKED_PLUGIN_HTML
,
858 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
859 placeholder
->set_allow_loading(false);
860 RenderThread::Get()->RecordAction(
861 UserMetricsAction("Plugin_BlockedByPolicy"));
862 observer
->DidBlockContentType(content_type
);
867 placeholder
->SetStatus(status
);
868 return placeholder
->plugin();
871 // For NaCl content handling plugins, the NaCl manifest is stored in an
872 // additonal 'nacl' param associated with the MIME type.
874 GURL
ChromeContentRendererClient::GetNaClContentHandlerURL(
875 const std::string
& actual_mime_type
,
876 const content::WebPluginInfo
& plugin
) {
877 // Look for the manifest URL among the MIME type's additonal parameters.
878 const char* kNaClPluginManifestAttribute
= "nacl";
879 base::string16 nacl_attr
= ASCIIToUTF16(kNaClPluginManifestAttribute
);
880 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
881 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
882 const content::WebPluginMimeType
& content_type
= plugin
.mime_types
[i
];
883 for (size_t i
= 0; i
< content_type
.additional_param_names
.size(); ++i
) {
884 if (content_type
.additional_param_names
[i
] == nacl_attr
)
885 return GURL(content_type
.additional_param_values
[i
]);
894 bool ChromeContentRendererClient::IsNaClAllowed(
895 const GURL
& manifest_url
,
897 bool is_nacl_unrestricted
,
898 const Extension
* extension
,
899 WebPluginParams
* params
) {
900 // Temporarily allow these whitelisted apps and WebUIs to use NaCl.
901 std::string app_url_host
= app_url
.host();
902 std::string manifest_url_path
= manifest_url
.path();
904 bool is_whitelisted_web_ui
=
905 app_url
.spec() == chrome::kChromeUIAppListStartPageURL
;
908 // Whitelisted apps must be served over https.
909 app_url
.SchemeIs("https") &&
910 manifest_url
.SchemeIs("https") &&
911 (EndsWith(app_url_host
, "plus.google.com", false) ||
912 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
913 manifest_url
.DomainIs("ssl.gstatic.com") &&
914 (manifest_url_path
.find("s2/oz/nacl/") == 1 ||
915 manifest_url_path
.find("photos/nacl/") == 1);
917 std::string manifest_fs_host
;
918 if (manifest_url
.SchemeIsFileSystem() && manifest_url
.inner_url()) {
919 manifest_fs_host
= manifest_url
.inner_url()->host();
921 bool is_hangouts_app
=
922 // Whitelisted apps must be served over secure scheme.
923 app_url
.SchemeIs("https") &&
924 manifest_url
.SchemeIsSecure() &&
925 manifest_url
.SchemeIsFileSystem() &&
926 (EndsWith(app_url_host
, "talkgadget.google.com", false) ||
927 EndsWith(app_url_host
, "plus.google.com", false) ||
928 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
929 // The manifest must be loaded from the host's FileSystem.
930 (manifest_fs_host
== app_url_host
);
932 bool is_whitelisted_app
= is_photo_app
|| is_hangouts_app
;
934 bool is_extension_from_webstore
= extension
&&
935 extension
->from_webstore();
937 bool is_invoked_by_hosted_app
= extension
&&
938 extension
->is_hosted_app() &&
939 extension
->web_extent().MatchesURL(app_url
);
941 // Allow built-in extensions and extensions under development.
942 bool is_extension_unrestricted
= extension
&&
943 (extension
->location() == extensions::Manifest::COMPONENT
||
944 extensions::Manifest::IsUnpackedLocation(extension
->location()));
946 bool is_invoked_by_extension
= app_url
.SchemeIs("chrome-extension");
948 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces.
949 bool is_nacl_pdf_viewer
=
950 (is_extension_from_webstore
&&
951 manifest_url
.SchemeIs("chrome-extension") &&
952 manifest_url
.host() == "acadkphlmlegjaadjagenfimbpphcgnh");
954 // Allow Chrome Web Store extensions, built-in extensions and extensions
955 // under development if the invocation comes from a URL with an extension
956 // scheme. Also allow invocations if they are from whitelisted URLs or
957 // if --enable-nacl is set.
958 bool is_nacl_allowed
= is_nacl_unrestricted
||
959 is_whitelisted_web_ui
||
960 is_whitelisted_app
||
961 is_nacl_pdf_viewer
||
962 is_invoked_by_hosted_app
||
963 (is_invoked_by_extension
&&
964 (is_extension_from_webstore
||
965 is_extension_unrestricted
));
966 if (is_nacl_allowed
) {
967 bool app_can_use_dev_interfaces
= is_nacl_pdf_viewer
;
968 // Make sure that PPAPI 'dev' interfaces aren't available for production
969 // apps unless they're whitelisted.
970 WebString dev_attribute
= WebString::fromUTF8("@dev");
971 if ((!is_whitelisted_app
&& !is_extension_from_webstore
) ||
972 app_can_use_dev_interfaces
) {
973 // Add the special '@dev' attribute.
974 std::vector
<base::string16
> param_names
;
975 std::vector
<base::string16
> param_values
;
976 param_names
.push_back(dev_attribute
);
977 param_values
.push_back(WebString());
981 ¶ms
->attributeNames
,
982 ¶ms
->attributeValues
);
984 // If the params somehow contain '@dev', remove it.
985 size_t attribute_count
= params
->attributeNames
.size();
986 for (size_t i
= 0; i
< attribute_count
; ++i
) {
987 if (params
->attributeNames
[i
].equals(dev_attribute
))
988 params
->attributeNames
[i
] = WebString();
992 return is_nacl_allowed
;
995 bool ChromeContentRendererClient::HasErrorPage(int http_status_code
,
996 std::string
* error_domain
) {
997 // Use an internal error page, if we have one for the status code.
998 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain
,
1003 *error_domain
= LocalizedError::kHttpErrorDomain
;
1007 bool ChromeContentRendererClient::ShouldSuppressErrorPage(
1008 content::RenderFrame
* render_frame
,
1010 // Unit tests for ChromeContentRendererClient pass a NULL RenderFrame here.
1011 // Unfortunately it's very difficult to construct a mock RenderView, so skip
1012 // this functionality in this case.
1014 content::RenderView
* render_view
= render_frame
->GetRenderView();
1015 content::RenderFrame
* main_render_frame
= render_view
->GetMainRenderFrame();
1016 blink::WebFrame
* web_frame
= render_frame
->GetWebFrame();
1017 NetErrorHelper
* net_error_helper
= NetErrorHelper::Get(main_render_frame
);
1018 if (net_error_helper
->ShouldSuppressErrorPage(web_frame
, url
))
1021 // Do not flash an error page if the Instant new tab page fails to load.
1022 return search_bouncer_
.get() && search_bouncer_
->IsNewTabPage(url
);
1025 void ChromeContentRendererClient::GetNavigationErrorStrings(
1026 content::RenderView
* render_view
,
1027 blink::WebFrame
* frame
,
1028 const blink::WebURLRequest
& failed_request
,
1029 const blink::WebURLError
& error
,
1030 std::string
* error_html
,
1031 base::string16
* error_description
) {
1032 const GURL failed_url
= error
.unreachableURL
;
1033 const Extension
* extension
= NULL
;
1035 if (failed_url
.is_valid() &&
1036 !failed_url
.SchemeIs(extensions::kExtensionScheme
)) {
1037 extension
= extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(
1041 bool is_post
= EqualsASCII(failed_request
.httpMethod(), "POST");
1044 // Use a local error page.
1045 if (extension
&& !extension
->from_bookmark()) {
1046 // TODO(erikkay): Should we use a different template for different
1048 int resource_id
= IDR_ERROR_APP_HTML
;
1049 const base::StringPiece
template_html(
1050 ResourceBundle::GetSharedInstance().GetRawDataResource(
1052 if (template_html
.empty()) {
1053 NOTREACHED() << "unable to load template. ID: " << resource_id
;
1055 base::DictionaryValue error_strings
;
1056 LocalizedError::GetAppErrorStrings(failed_url
, extension
,
1058 // "t" is the id of the template's root node.
1059 *error_html
= webui::GetTemplatesHtml(template_html
, &error_strings
,
1063 // TODO(ellyjones): change GetNavigationErrorStrings to take a RenderFrame
1064 // instead of a RenderView, then pass that in.
1065 // This is safe for now because we only install the NetErrorHelper on the
1066 // main render frame anyway; see the TODO(ellyjones) in
1067 // RenderFrameCreated.
1068 content::RenderFrame
* main_render_frame
=
1069 render_view
->GetMainRenderFrame();
1070 NetErrorHelper
* helper
= NetErrorHelper::Get(main_render_frame
);
1071 helper
->GetErrorHTML(frame
, error
, is_post
, error_html
);
1075 if (error_description
) {
1077 *error_description
= LocalizedError::GetErrorDetails(error
, is_post
);
1081 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
1082 return !extension_dispatcher_
->is_extension_process();
1085 bool ChromeContentRendererClient::AllowPopup() {
1086 extensions::ScriptContext
* current_context
=
1087 extension_dispatcher_
->script_context_set().GetCurrent();
1088 if (!current_context
|| !current_context
->extension())
1090 // See http://crbug.com/117446 for the subtlety of this check.
1091 switch (current_context
->context_type()) {
1092 case extensions::Feature::UNSPECIFIED_CONTEXT
:
1093 case extensions::Feature::WEB_PAGE_CONTEXT
:
1094 case extensions::Feature::UNBLESSED_EXTENSION_CONTEXT
:
1096 case extensions::Feature::BLESSED_EXTENSION_CONTEXT
:
1097 case extensions::Feature::CONTENT_SCRIPT_CONTEXT
:
1099 case extensions::Feature::BLESSED_WEB_PAGE_CONTEXT
:
1100 return !current_context
->web_frame()->parent();
1106 bool ChromeContentRendererClient::ShouldFork(WebFrame
* frame
,
1108 const std::string
& http_method
,
1109 bool is_initial_navigation
,
1110 bool is_server_redirect
,
1111 bool* send_referrer
) {
1112 DCHECK(!frame
->parent());
1114 // If this is the Instant process, fork all navigations originating from the
1115 // renderer. The destination page will then be bucketed back to this Instant
1116 // process if it is an Instant url, or to another process if not. Conversely,
1117 // fork if this is a non-Instant process navigating to an Instant url, so that
1118 // such navigations can also be bucketed into an Instant renderer.
1119 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess
) ||
1120 (search_bouncer_
.get() && search_bouncer_
->ShouldFork(url
))) {
1121 *send_referrer
= true;
1125 // For now, we skip the rest for POST submissions. This is because
1126 // http://crbug.com/101395 is more likely to cause compatibility issues
1127 // with hosted apps and extensions than WebUI pages. We will remove this
1128 // check when cross-process POST submissions are supported.
1129 if (http_method
!= "GET")
1132 // If this is the Signin process, fork all navigations originating from the
1133 // renderer. The destination page will then be bucketed back to this Signin
1134 // process if it is a Signin url, or to another process if not.
1135 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSigninProcess
)) {
1136 // We never want to allow non-signin pages to fork-on-POST to a
1137 // signin-related action URL. We'll need to handle this carefully once
1138 // http://crbug.com/101395 is fixed. The CHECK ensures we don't forget.
1139 CHECK_NE(http_method
, "POST");
1143 // If |url| matches one of the prerendered URLs, stop this navigation and try
1144 // to swap in the prerendered page on the browser process. If the prerendered
1145 // page no longer exists by the time the OpenURL IPC is handled, a normal
1146 // navigation is attempted.
1147 if (prerender_dispatcher_
.get() &&
1148 prerender_dispatcher_
->IsPrerenderURL(url
)) {
1149 *send_referrer
= true;
1153 const extensions::ExtensionSet
* extensions
=
1154 extension_dispatcher_
->extensions();
1156 // Determine if the new URL is an extension (excluding bookmark apps).
1157 const Extension
* new_url_extension
= extensions::GetNonBookmarkAppExtension(
1159 bool is_extension_url
= !!new_url_extension
;
1161 // If the navigation would cross an app extent boundary, we also need
1162 // to defer to the browser to ensure process isolation. This is not necessary
1163 // for server redirects, which will be transferred to a new process by the
1164 // browser process when they are ready to commit. It is necessary for client
1165 // redirects, which won't be transferred in the same way.
1166 if (!is_server_redirect
&&
1167 CrossesExtensionExtents(frame
, url
, *extensions
, is_extension_url
,
1168 is_initial_navigation
)) {
1169 // Include the referrer in this case since we're going from a hosted web
1170 // page. (the packaged case is handled previously by the extension
1172 *send_referrer
= true;
1174 const Extension
* extension
=
1175 extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(url
);
1176 if (extension
&& extension
->is_app()) {
1177 UMA_HISTOGRAM_ENUMERATION(
1178 extension
->is_platform_app() ?
1179 extension_misc::kPlatformAppLaunchHistogram
:
1180 extension_misc::kAppLaunchHistogram
,
1181 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION
,
1182 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY
);
1187 // If this is a reload, check whether it has the wrong process type. We
1188 // should send it to the browser if it's an extension URL (e.g., hosted app)
1189 // in a normal process, or if it's a process for an extension that has been
1191 if (frame
->top()->document().url() == url
) {
1192 if (is_extension_url
!= extension_dispatcher_
->is_extension_process())
1199 bool ChromeContentRendererClient::WillSendRequest(
1200 blink::WebFrame
* frame
,
1201 content::PageTransition transition_type
,
1203 const GURL
& first_party_for_cookies
,
1205 // Check whether the request should be allowed. If not allowed, we reset the
1206 // URL to something invalid to prevent the request and cause an error.
1207 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1208 !extensions::ResourceRequestPolicy::CanRequestResource(
1212 extension_dispatcher_
->extensions())) {
1213 *new_url
= GURL(chrome::kExtensionInvalidRequestURL
);
1217 if (url
.SchemeIs(extensions::kExtensionResourceScheme
) &&
1218 !extensions::ResourceRequestPolicy::CanRequestExtensionResourceScheme(
1221 *new_url
= GURL(chrome::kExtensionResourceInvalidRequestURL
);
1225 const content::RenderView
* render_view
=
1226 content::RenderView::FromWebView(frame
->view());
1227 SearchBox
* search_box
= SearchBox::Get(render_view
);
1228 if (search_box
&& url
.SchemeIs(chrome::kChromeSearchScheme
)) {
1229 if (url
.host() == chrome::kChromeUIThumbnailHost
)
1230 return search_box
->GenerateThumbnailURLFromTransientURL(url
, new_url
);
1231 else if (url
.host() == chrome::kChromeUIFaviconHost
)
1232 return search_box
->GenerateFaviconURLFromTransientURL(url
, new_url
);
1238 void ChromeContentRendererClient::DidCreateScriptContext(
1239 WebFrame
* frame
, v8::Handle
<v8::Context
> context
, int extension_group
,
1241 extension_dispatcher_
->DidCreateScriptContext(
1242 frame
, context
, extension_group
, world_id
);
1245 unsigned long long ChromeContentRendererClient::VisitedLinkHash(
1246 const char* canonical_url
, size_t length
) {
1247 return visited_link_slave_
->ComputeURLFingerprint(canonical_url
, length
);
1250 bool ChromeContentRendererClient::IsLinkVisited(unsigned long long link_hash
) {
1251 return visited_link_slave_
->IsVisited(link_hash
);
1254 blink::WebPrescientNetworking
*
1255 ChromeContentRendererClient::GetPrescientNetworking() {
1256 return prescient_networking_dispatcher_
.get();
1259 bool ChromeContentRendererClient::ShouldOverridePageVisibilityState(
1260 const content::RenderFrame
* render_frame
,
1261 blink::WebPageVisibilityState
* override_state
) {
1262 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
))
1265 *override_state
= blink::WebPageVisibilityStatePrerender
;
1269 void ChromeContentRendererClient::SetExtensionDispatcherForTest(
1270 extensions::Dispatcher
* extension_dispatcher
) {
1271 extension_dispatcher_
.reset(extension_dispatcher
);
1272 permissions_policy_delegate_
.reset(
1273 new extensions::RendererPermissionsPolicyDelegate(
1274 extension_dispatcher_
.get()));
1277 extensions::Dispatcher
*
1278 ChromeContentRendererClient::GetExtensionDispatcherForTest() {
1279 return extension_dispatcher_
.get();
1282 bool ChromeContentRendererClient::CrossesExtensionExtents(
1284 const GURL
& new_url
,
1285 const extensions::ExtensionSet
& extensions
,
1286 bool is_extension_url
,
1287 bool is_initial_navigation
) {
1288 GURL
old_url(frame
->top()->document().url());
1290 // If old_url is still empty and this is an initial navigation, then this is
1291 // a window.open operation. We should look at the opener URL.
1292 if (is_initial_navigation
&& old_url
.is_empty() && frame
->opener()) {
1293 // If we're about to open a normal web page from a same-origin opener stuck
1294 // in an extension process, we want to keep it in process to allow the
1295 // opener to script it.
1296 WebDocument opener_document
= frame
->opener()->document();
1297 WebSecurityOrigin opener
= frame
->opener()->document().securityOrigin();
1298 bool opener_is_extension_url
=
1299 !opener
.isUnique() && extensions
.GetExtensionOrAppByURL(
1300 opener_document
.url()) != NULL
;
1301 if (!is_extension_url
&&
1302 !opener_is_extension_url
&&
1303 extension_dispatcher_
->is_extension_process() &&
1304 opener
.canRequest(WebURL(new_url
)))
1307 // In all other cases, we want to compare against the top frame's URL (as
1308 // opposed to the opener frame's), since that's what determines the type of
1309 // process. This allows iframes outside an app to open a popup in the app.
1310 old_url
= frame
->top()->opener()->top()->document().url();
1313 // Only consider keeping non-app URLs in an app process if this window
1314 // has an opener (in which case it might be an OAuth popup that tries to
1315 // script an iframe within the app).
1316 bool should_consider_workaround
= !!frame
->opener();
1318 return extensions::CrossesExtensionProcessBoundary(
1319 extensions
, old_url
, new_url
, should_consider_workaround
);
1322 #if defined(ENABLE_SPELLCHECK)
1323 void ChromeContentRendererClient::SetSpellcheck(SpellCheck
* spellcheck
) {
1324 RenderThread
* thread
= RenderThread::Get();
1325 if (spellcheck_
.get() && thread
)
1326 thread
->RemoveObserver(spellcheck_
.get());
1327 spellcheck_
.reset(spellcheck
);
1328 SpellCheckReplacer
replacer(spellcheck_
.get());
1329 content::RenderView::ForEach(&replacer
);
1331 thread
->AddObserver(spellcheck_
.get());
1335 bool ChromeContentRendererClient::IsAdblockInstalled() {
1336 return g_current_client
->extension_dispatcher_
->extensions()->Contains(
1337 "gighmmpiobklfepjocnamgkkbiglidom");
1340 bool ChromeContentRendererClient::IsAdblockPlusInstalled() {
1341 return g_current_client
->extension_dispatcher_
->extensions()->Contains(
1342 "cfhdojbkjhnklbpkdaibdccddilifddb");
1345 bool ChromeContentRendererClient::IsAdblockWithWebRequestInstalled() {
1346 return g_current_client
->extension_dispatcher_delegate_
1347 ->IsAdblockWithWebRequestInstalled();
1350 bool ChromeContentRendererClient::IsAdblockPlusWithWebRequestInstalled() {
1351 return g_current_client
->extension_dispatcher_delegate_
1352 ->IsAdblockPlusWithWebRequestInstalled();
1355 bool ChromeContentRendererClient::IsOtherExtensionWithWebRequestInstalled() {
1356 return g_current_client
->extension_dispatcher_delegate_
1357 ->IsOtherExtensionWithWebRequestInstalled();
1360 const void* ChromeContentRendererClient::CreatePPAPIInterface(
1361 const std::string
& interface_name
) {
1362 #if defined(ENABLE_PLUGINS)
1363 #if !defined(DISABLE_NACL)
1364 if (interface_name
== PPB_NACL_PRIVATE_INTERFACE
)
1365 return nacl::GetNaClPrivateInterface();
1366 #endif // DISABLE_NACL
1367 if (interface_name
== PPB_PDF_INTERFACE
)
1368 return PPB_PDF_Impl::GetInterface();
1373 bool ChromeContentRendererClient::IsExternalPepperPlugin(
1374 const std::string
& module_name
) {
1375 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
1376 // We must defer certain plugin events for NaCl instances since we switch
1377 // from the in-process to the out-of-process proxy after instantiating them.
1378 return module_name
== "Native Client";
1381 bool ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
1382 const GURL
& url
, const std::set
<std::string
>& whitelist
) {
1383 const extensions::ExtensionSet
* extension_set
=
1384 g_current_client
->extension_dispatcher_
->extensions();
1385 return chrome::IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
1389 blink::WebSpeechSynthesizer
*
1390 ChromeContentRendererClient::OverrideSpeechSynthesizer(
1391 blink::WebSpeechSynthesizerClient
* client
) {
1392 return new TtsDispatcher(client
);
1395 bool ChromeContentRendererClient::AllowBrowserPlugin(
1396 blink::WebPluginContainer
* container
) {
1397 // If this |BrowserPlugin| <object> in the |container| is not inside a
1398 // <webview> shadowHost, we disable instantiating this plugin. This
1399 // is to discourage and prevent developers from accidentally attaching
1400 // <object> directly in apps.
1402 // Note that this check below does *not* ensure any security, it is still
1403 // possible to bypass this check.
1404 // TODO(lazyboy): http://crbug.com/178663, Ensure we properly disallow
1405 // instantiating BrowserPlugin outside of the <webview> shim.
1406 if (container
->element().isNull())
1409 if (container
->element().shadowHost().isNull())
1412 WebString tag_name
= container
->element().shadowHost().tagName();
1413 return tag_name
.equals(WebString::fromUTF8(kWebViewTagName
));
1416 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI(
1418 #if !defined(OS_ANDROID)
1419 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check
1420 // the whitelist in the renderer, since we're only preventing access until
1421 // these APIs are public and stable.
1422 std::string url_host
= url
.host();
1423 if (url
.SchemeIs("https") &&
1424 (EndsWith(url_host
, "talkgadget.google.com", false) ||
1425 EndsWith(url_host
, "plus.google.com", false) ||
1426 EndsWith(url_host
, "plus.sandbox.google.com", false)) &&
1427 StartsWithASCII(url
.path(), "/hangouts/", false)) {
1430 // Allow access for tests.
1431 if (CommandLine::ForCurrentProcess()->HasSwitch(
1432 switches::kEnablePepperTesting
)) {
1435 #endif // !defined(OS_ANDROID)
1439 void ChromeContentRendererClient::AddKeySystems(
1440 std::vector
<content::KeySystemInfo
>* key_systems
) {
1441 AddChromeKeySystems(key_systems
);
1444 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource(
1445 const base::string16
& source
) const {
1446 return extensions::IsSourceFromAnExtension(source
);
1449 bool ChromeContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
1450 // SiteIsolationPolicy is off by default. We would like to activate cross-site
1451 // document blocking (for UMA data collection) for normal renderer processes
1452 // running a normal web page from the Internet. We only turn on
1453 // SiteIsolationPolicy for a renderer process that does not have the extension
1455 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
1456 return !command_line
->HasSwitch(extensions::switches::kExtensionProcess
);
1459 blink::WebWorkerPermissionClientProxy
*
1460 ChromeContentRendererClient::CreateWorkerPermissionClientProxy(
1461 content::RenderFrame
* render_frame
,
1462 blink::WebFrame
* frame
) {
1463 return new WorkerPermissionClientProxy(render_frame
, frame
);