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/profile_management_switches.h"
28 #include "chrome/common/render_messages.h"
29 #include "chrome/common/url_constants.h"
30 #include "chrome/renderer/benchmarking_extension.h"
31 #include "chrome/renderer/chrome_render_frame_observer.h"
32 #include "chrome/renderer/chrome_render_process_observer.h"
33 #include "chrome/renderer/chrome_render_view_observer.h"
34 #include "chrome/renderer/content_settings_observer.h"
35 #include "chrome/renderer/extensions/chrome_v8_context.h"
36 #include "chrome/renderer/extensions/chrome_v8_extension.h"
37 #include "chrome/renderer/extensions/dispatcher.h"
38 #include "chrome/renderer/extensions/extension_frame_helper.h"
39 #include "chrome/renderer/extensions/extension_helper.h"
40 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
41 #include "chrome/renderer/extensions/resource_request_policy.h"
42 #include "chrome/renderer/external_extension.h"
43 #include "chrome/renderer/loadtimes_extension_bindings.h"
44 #include "chrome/renderer/media/chrome_key_systems.h"
45 #include "chrome/renderer/net/net_error_helper.h"
46 #include "chrome/renderer/net/prescient_networking_dispatcher.h"
47 #include "chrome/renderer/net/renderer_net_predictor.h"
48 #include "chrome/renderer/net_benchmarking_extension.h"
49 #include "chrome/renderer/page_load_histograms.h"
50 #include "chrome/renderer/pepper/pepper_helper.h"
51 #include "chrome/renderer/pepper/ppb_pdf_impl.h"
52 #include "chrome/renderer/playback_extension.h"
53 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
54 #include "chrome/renderer/plugins/plugin_uma.h"
55 #include "chrome/renderer/prerender/prerender_dispatcher.h"
56 #include "chrome/renderer/prerender/prerender_helper.h"
57 #include "chrome/renderer/prerender/prerender_media_load_deferrer.h"
58 #include "chrome/renderer/prerender/prerenderer_client.h"
59 #include "chrome/renderer/principals_extension_bindings.h"
60 #include "chrome/renderer/printing/print_web_view_helper.h"
61 #include "chrome/renderer/safe_browsing/malware_dom_details.h"
62 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
63 #include "chrome/renderer/searchbox/search_bouncer.h"
64 #include "chrome/renderer/searchbox/searchbox.h"
65 #include "chrome/renderer/searchbox/searchbox_extension.h"
66 #include "chrome/renderer/tts_dispatcher.h"
67 #include "chrome/renderer/worker_permission_client_proxy.h"
68 #include "components/autofill/content/renderer/autofill_agent.h"
69 #include "components/autofill/content/renderer/password_autofill_agent.h"
70 #include "components/autofill/content/renderer/password_generation_agent.h"
71 #include "components/autofill/core/common/password_generation_util.h"
72 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
73 #include "components/plugins/renderer/mobile_youtube_plugin.h"
74 #include "components/visitedlink/renderer/visitedlink_slave.h"
75 #include "content/public/common/content_constants.h"
76 #include "content/public/renderer/render_frame.h"
77 #include "content/public/renderer/render_thread.h"
78 #include "content/public/renderer/render_view.h"
79 #include "content/public/renderer/render_view_visitor.h"
80 #include "extensions/common/constants.h"
81 #include "extensions/common/extension.h"
82 #include "extensions/common/extension_set.h"
83 #include "extensions/common/extension_urls.h"
84 #include "extensions/common/switches.h"
85 #include "grit/generated_resources.h"
86 #include "grit/locale_settings.h"
87 #include "grit/renderer_resources.h"
88 #include "ipc/ipc_sync_channel.h"
89 #include "net/base/net_errors.h"
90 #include "ppapi/c/private/ppb_nacl_private.h"
91 #include "ppapi/c/private/ppb_pdf.h"
92 #include "ppapi/shared_impl/ppapi_switches.h"
93 #include "third_party/WebKit/public/platform/WebURL.h"
94 #include "third_party/WebKit/public/platform/WebURLError.h"
95 #include "third_party/WebKit/public/platform/WebURLRequest.h"
96 #include "third_party/WebKit/public/web/WebCache.h"
97 #include "third_party/WebKit/public/web/WebDataSource.h"
98 #include "third_party/WebKit/public/web/WebDocument.h"
99 #include "third_party/WebKit/public/web/WebElement.h"
100 #include "third_party/WebKit/public/web/WebFrame.h"
101 #include "third_party/WebKit/public/web/WebPluginContainer.h"
102 #include "third_party/WebKit/public/web/WebPluginParams.h"
103 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
104 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
105 #include "ui/base/l10n/l10n_util.h"
106 #include "ui/base/layout.h"
107 #include "ui/base/resource/resource_bundle.h"
108 #include "ui/base/webui/jstemplate_builder.h"
109 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
111 #if defined(ENABLE_WEBRTC)
112 #include "chrome/renderer/media/webrtc_logging_message_filter.h"
115 #if defined(ENABLE_SPELLCHECK)
116 #include "chrome/renderer/spellchecker/spellcheck.h"
117 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
120 using autofill::AutofillAgent
;
121 using autofill::PasswordAutofillAgent
;
122 using autofill::PasswordGenerationAgent
;
123 using base::ASCIIToUTF16
;
124 using base::UserMetricsAction
;
125 using content::RenderThread
;
126 using content::WebPluginInfo
;
127 using extensions::Extension
;
128 using blink::WebCache
;
129 using blink::WebConsoleMessage
;
130 using blink::WebDataSource
;
131 using blink::WebDocument
;
132 using blink::WebFrame
;
133 using blink::WebPlugin
;
134 using blink::WebPluginParams
;
135 using blink::WebSecurityOrigin
;
136 using blink::WebSecurityPolicy
;
137 using blink::WebString
;
139 using blink::WebURLError
;
140 using blink::WebURLRequest
;
141 using blink::WebURLResponse
;
142 using blink::WebVector
;
146 const char kWebViewTagName
[] = "WEBVIEW";
147 const char kAdViewTagName
[] = "ADVIEW";
149 ChromeContentRendererClient
* g_current_client
;
151 static void AppendParams(const std::vector
<base::string16
>& additional_names
,
152 const std::vector
<base::string16
>& additional_values
,
153 WebVector
<WebString
>* existing_names
,
154 WebVector
<WebString
>* existing_values
) {
155 DCHECK(additional_names
.size() == additional_values
.size());
156 DCHECK(existing_names
->size() == existing_values
->size());
158 size_t existing_size
= existing_names
->size();
159 size_t total_size
= existing_size
+ additional_names
.size();
161 WebVector
<WebString
> names(total_size
);
162 WebVector
<WebString
> values(total_size
);
164 for (size_t i
= 0; i
< existing_size
; ++i
) {
165 names
[i
] = (*existing_names
)[i
];
166 values
[i
] = (*existing_values
)[i
];
169 for (size_t i
= 0; i
< additional_names
.size(); ++i
) {
170 names
[existing_size
+ i
] = additional_names
[i
];
171 values
[existing_size
+ i
] = additional_values
[i
];
174 existing_names
->swap(names
);
175 existing_values
->swap(values
);
178 #if defined(ENABLE_SPELLCHECK)
179 class SpellCheckReplacer
: public content::RenderViewVisitor
{
181 explicit SpellCheckReplacer(SpellCheck
* spellcheck
)
182 : spellcheck_(spellcheck
) {}
183 virtual bool Visit(content::RenderView
* render_view
) OVERRIDE
;
186 SpellCheck
* spellcheck_
; // New shared spellcheck for all views. Weak Ptr.
187 DISALLOW_COPY_AND_ASSIGN(SpellCheckReplacer
);
190 bool SpellCheckReplacer::Visit(content::RenderView
* render_view
) {
191 SpellCheckProvider
* provider
= SpellCheckProvider::Get(render_view
);
193 provider
->set_spellcheck(spellcheck_
);
198 // For certain sandboxed Pepper plugins, use the JavaScript Content Settings.
199 bool ShouldUseJavaScriptSettingForPlugin(const WebPluginInfo
& plugin
) {
200 if (plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS
&&
201 plugin
.type
!= WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
) {
205 // Treat Native Client invocations like JavaScript.
206 if (plugin
.name
== ASCIIToUTF16(ChromeContentClient::kNaClPluginName
))
209 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
210 // Treat CDM invocations like JavaScript.
211 if (plugin
.name
== ASCIIToUTF16(kWidevineCdmDisplayName
)) {
212 DCHECK(plugin
.type
== WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
);
215 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
222 ChromeContentRendererClient::ChromeContentRendererClient() {
223 g_current_client
= this;
226 ChromeContentRendererClient::~ChromeContentRendererClient() {
227 g_current_client
= NULL
;
230 void ChromeContentRendererClient::RenderThreadStarted() {
231 RenderThread
* thread
= RenderThread::Get();
233 chrome_observer_
.reset(new ChromeRenderProcessObserver(this));
234 // ChromeRenderViewTest::SetUp() creates its own ExtensionDispatcher and
235 // injects it using SetExtensionDispatcher(). Don't overwrite it.
236 if (!extension_dispatcher_
)
237 extension_dispatcher_
.reset(new extensions::Dispatcher());
238 permissions_policy_delegate_
.reset(
239 new extensions::RendererPermissionsPolicyDelegate(
240 extension_dispatcher_
.get()));
241 prescient_networking_dispatcher_
.reset(new PrescientNetworkingDispatcher());
242 net_predictor_
.reset(new RendererNetPredictor());
243 #if defined(ENABLE_SPELLCHECK)
244 // ChromeRenderViewTest::SetUp() creates a Spellcheck and injects it using
245 // SetSpellcheck(). Don't overwrite it.
247 spellcheck_
.reset(new SpellCheck());
248 thread
->AddObserver(spellcheck_
.get());
251 visited_link_slave_
.reset(new visitedlink::VisitedLinkSlave());
252 #if defined(FULL_SAFE_BROWSING)
253 phishing_classifier_
.reset(safe_browsing::PhishingClassifierFilter::Create());
255 prerender_dispatcher_
.reset(new prerender::PrerenderDispatcher());
256 #if defined(ENABLE_WEBRTC)
257 webrtc_logging_message_filter_
= new WebRtcLoggingMessageFilter(
258 content::RenderThread::Get()->GetIOMessageLoopProxy());
260 search_bouncer_
.reset(new SearchBouncer());
262 thread
->AddObserver(chrome_observer_
.get());
263 thread
->AddObserver(extension_dispatcher_
.get());
264 #if defined(FULL_SAFE_BROWSING)
265 thread
->AddObserver(phishing_classifier_
.get());
267 thread
->AddObserver(visited_link_slave_
.get());
268 thread
->AddObserver(prerender_dispatcher_
.get());
269 thread
->AddObserver(search_bouncer_
.get());
271 #if defined(ENABLE_WEBRTC)
272 thread
->AddFilter(webrtc_logging_message_filter_
.get());
275 thread
->RegisterExtension(extensions_v8::ExternalExtension::Get());
276 thread
->RegisterExtension(extensions_v8::LoadTimesExtension::Get());
278 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
279 if (command_line
->HasSwitch(switches::kEnableBenchmarking
))
280 thread
->RegisterExtension(extensions_v8::BenchmarkingExtension::Get());
281 if (command_line
->HasSwitch(switches::kEnableNetBenchmarking
))
282 thread
->RegisterExtension(extensions_v8::NetBenchmarkingExtension::Get());
283 if (command_line
->HasSwitch(switches::kInstantProcess
))
284 thread
->RegisterExtension(extensions_v8::SearchBoxExtension::Get());
286 if (command_line
->HasSwitch(switches::kPlaybackMode
) ||
287 command_line
->HasSwitch(switches::kRecordMode
) ||
288 command_line
->HasSwitch(switches::kNoJsRandomness
)) {
289 thread
->RegisterExtension(extensions_v8::PlaybackExtension::Get());
292 // TODO(guohui): needs to forward the new-profile-management switch to
293 // renderer processes.
294 if (switches::IsNewProfileManagement())
295 thread
->RegisterExtension(extensions_v8::PrincipalsExtension::Get());
297 // chrome:, chrome-search:, and chrome-devtools: pages should not be
298 // accessible by normal content, and should also be unable to script anything
299 // but themselves (to help limit the damage that a corrupt page could cause).
300 WebString
chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme
));
301 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme
);
303 WebString
chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme
));
304 // The Instant process can only display the content but not read it. Other
305 // processes can't display it or read it.
306 if (!command_line
->HasSwitch(switches::kInstantProcess
))
307 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_search_scheme
);
309 WebString
dev_tools_scheme(ASCIIToUTF16(chrome::kChromeDevToolsScheme
));
310 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dev_tools_scheme
);
312 #if defined(OS_CHROMEOS)
313 WebString
drive_scheme(ASCIIToUTF16(chrome::kDriveScheme
));
314 WebSecurityPolicy::registerURLSchemeAsLocal(drive_scheme
);
317 // chrome: and chrome-search: pages should not be accessible by bookmarklets
318 // or javascript: URLs typed in the omnibox.
319 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
321 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
322 chrome_search_scheme
);
324 // chrome:, chrome-search:, and chrome-extension: resources shouldn't trigger
325 // insecure content warnings.
326 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_ui_scheme
);
327 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_search_scheme
);
329 WebString
extension_scheme(ASCIIToUTF16(extensions::kExtensionScheme
));
330 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme
);
332 // chrome-extension: resources should be allowed to receive CORS requests.
333 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_scheme
);
335 WebString
extension_resource_scheme(
336 ASCIIToUTF16(extensions::kExtensionResourceScheme
));
337 WebSecurityPolicy::registerURLSchemeAsSecure(extension_resource_scheme
);
339 // chrome-extension-resource: resources should be allowed to receive CORS
341 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_resource_scheme
);
343 // chrome-extension: resources should bypass Content Security Policy checks
344 // when included in protected resources.
345 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
347 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
348 extension_resource_scheme
);
350 extensions::ExtensionsClient::Set(
351 extensions::ChromeExtensionsClient::GetInstance());
354 void ChromeContentRendererClient::RenderFrameCreated(
355 content::RenderFrame
* render_frame
) {
356 new ChromeRenderFrameObserver(render_frame
);
358 ContentSettingsObserver
* content_settings
=
359 new ContentSettingsObserver(render_frame
, extension_dispatcher_
.get());
360 if (chrome_observer_
.get()) {
361 content_settings
->SetContentSettingRules(
362 chrome_observer_
->content_setting_rules());
365 new extensions::ExtensionFrameHelper(render_frame
);
367 #if defined(ENABLE_PLUGINS)
368 new PepperHelper(render_frame
);
371 // TODO(jam): when a RenderFrame is per WebFrame, this can be simplified by
372 // getting a RenderFrame's WebFrame and calling its parent() method.
373 if (render_frame
->GetRenderView()->GetMainRenderFrame() != render_frame
) {
374 // Avoid any race conditions from having the browser tell subframes that
375 // they're prerendering.
376 if (prerender::PrerenderHelper::IsPrerendering(
377 render_frame
->GetRenderView()->GetMainRenderFrame())) {
378 new prerender::PrerenderHelper(render_frame
);
383 void ChromeContentRendererClient::RenderViewCreated(
384 content::RenderView
* render_view
) {
385 new extensions::ExtensionHelper(render_view
, extension_dispatcher_
.get());
386 new PageLoadHistograms(render_view
);
387 #if defined(ENABLE_PRINTING)
388 new printing::PrintWebViewHelper(render_view
);
390 #if defined(ENABLE_SPELLCHECK)
391 new SpellCheckProvider(render_view
, spellcheck_
.get());
393 new prerender::PrerendererClient(render_view
);
394 #if defined(FULL_SAFE_BROWSING)
395 safe_browsing::MalwareDOMDetails::Create(render_view
);
398 PasswordAutofillAgent
* password_autofill_agent
=
399 new PasswordAutofillAgent(render_view
);
400 new AutofillAgent(render_view
, password_autofill_agent
);
402 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
403 if (autofill::password_generation::IsPasswordGenerationEnabled())
404 new PasswordGenerationAgent(render_view
);
405 if (command_line
->HasSwitch(switches::kInstantProcess
))
406 new SearchBox(render_view
);
408 new ChromeRenderViewObserver(render_view
, chrome_observer_
.get());
410 new NetErrorHelper(render_view
);
413 void ChromeContentRendererClient::SetNumberOfViews(int number_of_views
) {
414 base::debug::SetCrashKeyValue(crash_keys::kNumberOfViews
,
415 base::IntToString(number_of_views
));
418 SkBitmap
* ChromeContentRendererClient::GetSadPluginBitmap() {
419 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
420 GetImageNamed(IDR_SAD_PLUGIN
).ToSkBitmap());
423 SkBitmap
* ChromeContentRendererClient::GetSadWebViewBitmap() {
424 return const_cast<SkBitmap
*>(ResourceBundle::GetSharedInstance().
425 GetImageNamed(IDR_SAD_WEBVIEW
).ToSkBitmap());
428 std::string
ChromeContentRendererClient::GetDefaultEncoding() {
429 return l10n_util::GetStringUTF8(IDS_DEFAULT_ENCODING
);
432 const Extension
* ChromeContentRendererClient::GetExtensionByOrigin(
433 const WebSecurityOrigin
& origin
) const {
434 if (!EqualsASCII(origin
.protocol(), extensions::kExtensionScheme
))
437 const std::string extension_id
= origin
.host().utf8().data();
438 return extension_dispatcher_
->extensions()->GetByID(extension_id
);
441 bool ChromeContentRendererClient::OverrideCreatePlugin(
442 content::RenderFrame
* render_frame
,
444 const WebPluginParams
& params
,
445 WebPlugin
** plugin
) {
446 std::string orig_mime_type
= params
.mimeType
.utf8();
447 if (orig_mime_type
== content::kBrowserPluginMimeType
) {
448 if (CommandLine::ForCurrentProcess()->HasSwitch(
449 switches::kEnableBrowserPluginForAllViewTypes
))
451 WebDocument document
= frame
->document();
452 const Extension
* extension
=
453 GetExtensionByOrigin(document
.securityOrigin());
455 const extensions::APIPermission::ID perms
[] = {
456 extensions::APIPermission::kWebView
,
457 extensions::APIPermission::kAdView
459 for (size_t i
= 0; i
< arraysize(perms
); ++i
) {
460 if (extension
->HasAPIPermission(perms
[i
]))
466 ChromeViewHostMsg_GetPluginInfo_Output output
;
467 #if defined(ENABLE_PLUGINS)
468 render_frame
->Send(new ChromeViewHostMsg_GetPluginInfo(
469 render_frame
->GetRoutingID(), GURL(params
.url
),
470 frame
->top()->document().url(), orig_mime_type
, &output
));
472 output
.status
.value
= ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
;
474 *plugin
= CreatePlugin(render_frame
, frame
, params
, output
);
478 WebPlugin
* ChromeContentRendererClient::CreatePluginReplacement(
479 content::RenderFrame
* render_frame
,
480 const base::FilePath
& plugin_path
) {
481 ChromePluginPlaceholder
* placeholder
=
482 ChromePluginPlaceholder::CreateErrorPlugin(render_frame
, plugin_path
);
483 return placeholder
->plugin();
486 void ChromeContentRendererClient::DeferMediaLoad(
487 content::RenderFrame
* render_frame
,
488 const base::Closure
& closure
) {
489 #if defined(OS_ANDROID)
490 // Chromium for Android doesn't support prerender yet.
494 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
499 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
500 new prerender::PrerenderMediaLoadDeferrer(render_frame
, closure
);
504 WebPlugin
* ChromeContentRendererClient::CreatePlugin(
505 content::RenderFrame
* render_frame
,
507 const WebPluginParams
& original_params
,
508 const ChromeViewHostMsg_GetPluginInfo_Output
& output
) {
509 const ChromeViewHostMsg_GetPluginInfo_Status
& status
= output
.status
;
510 const WebPluginInfo
& plugin
= output
.plugin
;
511 const std::string
& actual_mime_type
= output
.actual_mime_type
;
512 const base::string16
& group_name
= output
.group_name
;
513 const std::string
& identifier
= output
.group_identifier
;
514 ChromeViewHostMsg_GetPluginInfo_Status::Value status_value
= status
.value
;
515 GURL
url(original_params
.url
);
516 std::string orig_mime_type
= original_params
.mimeType
.utf8();
517 ChromePluginPlaceholder
* placeholder
= NULL
;
519 // If the browser plugin is to be enabled, this should be handled by the
520 // renderer, so the code won't reach here due to the early exit in
521 // OverrideCreatePlugin.
522 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
||
523 orig_mime_type
== content::kBrowserPluginMimeType
) {
524 #if defined(OS_ANDROID)
525 if (plugins::MobileYouTubePlugin::IsYouTubeURL(url
, orig_mime_type
)) {
526 base::StringPiece
template_html(
527 ResourceBundle::GetSharedInstance().GetRawDataResource(
528 IDR_MOBILE_YOUTUBE_PLUGIN_HTML
));
529 return (new plugins::MobileYouTubePlugin(
534 GURL(ChromePluginPlaceholder::kPluginPlaceholderDataURL
)))
538 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type
, url
);
539 placeholder
= ChromePluginPlaceholder::CreateMissingPlugin(
540 render_frame
, frame
, original_params
);
542 // TODO(bauerb): This should be in content/.
543 WebPluginParams
params(original_params
);
544 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
545 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
546 AppendParams(plugin
.mime_types
[i
].additional_param_names
,
547 plugin
.mime_types
[i
].additional_param_values
,
548 ¶ms
.attributeNames
,
549 ¶ms
.attributeValues
);
553 if (params
.mimeType
.isNull() && (actual_mime_type
.size() > 0)) {
554 // Webkit might say that mime type is null while we already know the
555 // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case
556 // we should use what we know since WebpluginDelegateProxy does some
557 // specific initializations based on this information.
558 params
.mimeType
= WebString::fromUTF8(actual_mime_type
.c_str());
561 ContentSettingsObserver
* observer
=
562 ContentSettingsObserver::Get(render_frame
);
564 const ContentSettingsType content_type
=
565 ShouldUseJavaScriptSettingForPlugin(plugin
) ?
566 CONTENT_SETTINGS_TYPE_JAVASCRIPT
:
567 CONTENT_SETTINGS_TYPE_PLUGINS
;
570 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
||
571 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
||
572 status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
) &&
573 observer
->IsPluginTemporarilyAllowed(identifier
)) {
574 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
577 // Allow full-page plug-ins for click-to-play.
578 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
&&
581 frame
->document().isPluginDocument()) {
582 status_value
= ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
;
585 #if defined(USE_AURA) && defined(OS_WIN)
586 // In Aura for Windows we need to check if we can load NPAPI plugins.
587 // For example, if the render view is in the Ash desktop, we should not.
588 if (status_value
== ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
&&
589 plugin
.type
== content::WebPluginInfo::PLUGIN_TYPE_NPAPI
) {
590 if (observer
->AreNPAPIPluginsBlocked())
592 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
;
596 switch (status_value
) {
597 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound
: {
601 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed
: {
602 const bool is_nacl_plugin
=
603 plugin
.name
== ASCIIToUTF16(ChromeContentClient::kNaClPluginName
);
604 const bool is_nacl_mime_type
=
605 actual_mime_type
== "application/x-nacl";
606 const bool is_pnacl_mime_type
=
607 actual_mime_type
== "application/x-pnacl";
608 if (is_nacl_plugin
|| is_nacl_mime_type
|| is_pnacl_mime_type
) {
609 bool is_nacl_unrestricted
= false;
610 if (is_nacl_mime_type
) {
611 is_nacl_unrestricted
=
612 CommandLine::ForCurrentProcess()->HasSwitch(
613 switches::kEnableNaCl
);
614 } else if (is_pnacl_mime_type
) {
615 is_nacl_unrestricted
=
616 !CommandLine::ForCurrentProcess()->HasSwitch(
617 switches::kDisablePnacl
);
621 if (is_nacl_mime_type
|| is_pnacl_mime_type
) {
622 // Normal NaCl/PNaCl embed. The app URL is the page URL.
624 app_url
= frame
->top()->document().url();
626 // NaCl is being invoked as a content handler. Look up the NaCl
627 // module using the MIME type. The app URL is the manifest URL.
628 manifest_url
= GetNaClContentHandlerURL(actual_mime_type
, plugin
);
629 app_url
= manifest_url
;
631 const Extension
* extension
=
632 g_current_client
->extension_dispatcher_
->extensions()->
633 GetExtensionOrAppByURL(manifest_url
);
634 if (!IsNaClAllowed(manifest_url
,
636 is_nacl_unrestricted
,
639 WebString error_message
;
640 if (is_nacl_mime_type
) {
642 "Only unpacked extensions and apps installed from the Chrome "
643 "Web Store can load NaCl modules without enabling Native "
644 "Client in about:flags.";
645 } else if (is_pnacl_mime_type
) {
647 "Portable Native Client must not be disabled in about:flags.";
649 frame
->addMessageToConsole(
650 WebConsoleMessage(WebConsoleMessage::LevelError
,
652 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
659 IDR_BLOCKED_PLUGIN_HTML
,
660 #if defined(OS_CHROMEOS)
661 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED
));
663 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
669 // Delay loading plugins if prerendering.
670 // TODO(mmenke): In the case of prerendering, feed into
671 // ChromeContentRendererClient::CreatePlugin instead, to
672 // reduce the chance of future regressions.
673 if (prerender::PrerenderHelper::IsPrerendering(render_frame
)) {
674 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
681 IDR_CLICK_TO_PLAY_PLUGIN_HTML
,
682 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD
, group_name
));
683 placeholder
->set_blocked_for_prerendering(true);
684 placeholder
->set_allow_loading(true);
688 return render_frame
->CreatePlugin(frame
, plugin
, params
);
690 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported
: {
691 RenderThread::Get()->RecordAction(
692 UserMetricsAction("Plugin_NPAPINotSupported"));
693 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
700 IDR_BLOCKED_PLUGIN_HTML
,
701 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO
));
702 render_frame
->Send(new ChromeViewHostMsg_NPAPINotSupported(
703 render_frame
->GetRoutingID(), identifier
));
706 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled
: {
707 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type
,
709 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
716 IDR_DISABLED_PLUGIN_HTML
,
717 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED
, group_name
));
720 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked
: {
721 #if defined(ENABLE_PLUGIN_INSTALLATION)
722 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
729 IDR_BLOCKED_PLUGIN_HTML
,
730 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
731 placeholder
->set_allow_loading(true);
732 render_frame
->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
733 render_frame
->GetRoutingID(), placeholder
->CreateRoutingId(),
740 case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed
: {
741 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
748 IDR_BLOCKED_PLUGIN_HTML
,
749 l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED
, group_name
));
752 case ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized
: {
753 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
760 IDR_BLOCKED_PLUGIN_HTML
,
761 l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED
, group_name
));
762 placeholder
->set_allow_loading(true);
763 render_frame
->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin(
764 render_frame
->GetRoutingID(),
769 case ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay
: {
770 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
777 IDR_CLICK_TO_PLAY_PLUGIN_HTML
,
778 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD
, group_name
));
779 placeholder
->set_allow_loading(true);
780 RenderThread::Get()->RecordAction(
781 UserMetricsAction("Plugin_ClickToPlay"));
782 observer
->DidBlockContentType(content_type
);
785 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked
: {
786 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
793 IDR_BLOCKED_PLUGIN_HTML
,
794 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
795 placeholder
->set_allow_loading(true);
796 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked"));
797 observer
->DidBlockContentType(content_type
);
800 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy
: {
801 placeholder
= ChromePluginPlaceholder::CreateBlockedPlugin(
808 IDR_BLOCKED_PLUGIN_HTML
,
809 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED
, group_name
));
810 placeholder
->set_allow_loading(false);
811 RenderThread::Get()->RecordAction(
812 UserMetricsAction("Plugin_BlockedByPolicy"));
813 observer
->DidBlockContentType(content_type
);
818 placeholder
->SetStatus(status
);
819 return placeholder
->plugin();
822 // For NaCl content handling plugins, the NaCl manifest is stored in an
823 // additonal 'nacl' param associated with the MIME type.
825 GURL
ChromeContentRendererClient::GetNaClContentHandlerURL(
826 const std::string
& actual_mime_type
,
827 const content::WebPluginInfo
& plugin
) {
828 // Look for the manifest URL among the MIME type's additonal parameters.
829 const char* kNaClPluginManifestAttribute
= "nacl";
830 base::string16 nacl_attr
= ASCIIToUTF16(kNaClPluginManifestAttribute
);
831 for (size_t i
= 0; i
< plugin
.mime_types
.size(); ++i
) {
832 if (plugin
.mime_types
[i
].mime_type
== actual_mime_type
) {
833 const content::WebPluginMimeType
& content_type
= plugin
.mime_types
[i
];
834 for (size_t i
= 0; i
< content_type
.additional_param_names
.size(); ++i
) {
835 if (content_type
.additional_param_names
[i
] == nacl_attr
)
836 return GURL(content_type
.additional_param_values
[i
]);
845 bool ChromeContentRendererClient::IsNaClAllowed(
846 const GURL
& manifest_url
,
848 bool is_nacl_unrestricted
,
849 const Extension
* extension
,
850 WebPluginParams
* params
) {
851 // Temporarily allow these whitelisted apps and WebUIs to use NaCl.
852 std::string app_url_host
= app_url
.host();
853 std::string manifest_url_path
= manifest_url
.path();
855 bool is_whitelisted_web_ui
=
856 app_url
.spec() == chrome::kChromeUIAppListStartPageURL
;
859 // Whitelisted apps must be served over https.
860 app_url
.SchemeIs("https") &&
861 manifest_url
.SchemeIs("https") &&
862 (EndsWith(app_url_host
, "plus.google.com", false) ||
863 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
864 manifest_url
.DomainIs("ssl.gstatic.com") &&
865 (manifest_url_path
.find("s2/oz/nacl/") == 1 ||
866 manifest_url_path
.find("photos/nacl/") == 1);
868 std::string manifest_fs_host
;
869 if (manifest_url
.SchemeIsFileSystem() && manifest_url
.inner_url()) {
870 manifest_fs_host
= manifest_url
.inner_url()->host();
872 bool is_hangouts_app
=
873 // Whitelisted apps must be served over secure scheme.
874 app_url
.SchemeIs("https") &&
875 manifest_url
.SchemeIsSecure() &&
876 manifest_url
.SchemeIsFileSystem() &&
877 (EndsWith(app_url_host
, "talkgadget.google.com", false) ||
878 EndsWith(app_url_host
, "plus.google.com", false) ||
879 EndsWith(app_url_host
, "plus.sandbox.google.com", false)) &&
880 // The manifest must be loaded from the host's FileSystem.
881 (manifest_fs_host
== app_url_host
);
883 bool is_whitelisted_app
= is_photo_app
|| is_hangouts_app
;
885 bool is_extension_from_webstore
= extension
&&
886 extension
->from_webstore();
888 bool is_invoked_by_hosted_app
= extension
&&
889 extension
->is_hosted_app() &&
890 extension
->web_extent().MatchesURL(app_url
);
892 // Allow built-in extensions and extensions under development.
893 bool is_extension_unrestricted
= extension
&&
894 (extension
->location() == extensions::Manifest::COMPONENT
||
895 extensions::Manifest::IsUnpackedLocation(extension
->location()));
897 bool is_invoked_by_extension
= app_url
.SchemeIs("chrome-extension");
899 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces.
900 bool is_nacl_pdf_viewer
=
901 (is_extension_from_webstore
&&
902 manifest_url
.SchemeIs("chrome-extension") &&
903 manifest_url
.host() == "acadkphlmlegjaadjagenfimbpphcgnh");
905 // Allow Chrome Web Store extensions, built-in extensions and extensions
906 // under development if the invocation comes from a URL with an extension
907 // scheme. Also allow invocations if they are from whitelisted URLs or
908 // if --enable-nacl is set.
909 bool is_nacl_allowed
= is_nacl_unrestricted
||
910 is_whitelisted_web_ui
||
911 is_whitelisted_app
||
912 is_nacl_pdf_viewer
||
913 is_invoked_by_hosted_app
||
914 (is_invoked_by_extension
&&
915 (is_extension_from_webstore
||
916 is_extension_unrestricted
));
917 if (is_nacl_allowed
) {
918 bool app_can_use_dev_interfaces
= is_nacl_pdf_viewer
;
919 // Make sure that PPAPI 'dev' interfaces aren't available for production
920 // apps unless they're whitelisted.
921 WebString dev_attribute
= WebString::fromUTF8("@dev");
922 if ((!is_whitelisted_app
&& !is_extension_from_webstore
) ||
923 app_can_use_dev_interfaces
) {
924 // Add the special '@dev' attribute.
925 std::vector
<base::string16
> param_names
;
926 std::vector
<base::string16
> param_values
;
927 param_names
.push_back(dev_attribute
);
928 param_values
.push_back(WebString());
932 ¶ms
->attributeNames
,
933 ¶ms
->attributeValues
);
935 // If the params somehow contain '@dev', remove it.
936 size_t attribute_count
= params
->attributeNames
.size();
937 for (size_t i
= 0; i
< attribute_count
; ++i
) {
938 if (params
->attributeNames
[i
].equals(dev_attribute
))
939 params
->attributeNames
[i
] = WebString();
943 return is_nacl_allowed
;
946 bool ChromeContentRendererClient::HasErrorPage(int http_status_code
,
947 std::string
* error_domain
) {
948 // Use an internal error page, if we have one for the status code.
949 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain
,
954 *error_domain
= LocalizedError::kHttpErrorDomain
;
958 bool ChromeContentRendererClient::ShouldSuppressErrorPage(
959 content::RenderFrame
* render_frame
,
961 // Do not flash an error page if the Instant new tab page fails to load.
962 return search_bouncer_
.get() && search_bouncer_
->IsNewTabPage(url
);
965 void ChromeContentRendererClient::GetNavigationErrorStrings(
966 content::RenderView
* render_view
,
967 blink::WebFrame
* frame
,
968 const blink::WebURLRequest
& failed_request
,
969 const blink::WebURLError
& error
,
970 std::string
* error_html
,
971 base::string16
* error_description
) {
972 const GURL failed_url
= error
.unreachableURL
;
973 const Extension
* extension
= NULL
;
975 if (failed_url
.is_valid() &&
976 !failed_url
.SchemeIs(extensions::kExtensionScheme
)) {
977 extension
= extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(
981 bool is_post
= EqualsASCII(failed_request
.httpMethod(), "POST");
984 // Use a local error page.
985 if (extension
&& !extension
->from_bookmark()) {
986 // TODO(erikkay): Should we use a different template for different
988 int resource_id
= IDR_ERROR_APP_HTML
;
989 const base::StringPiece
template_html(
990 ResourceBundle::GetSharedInstance().GetRawDataResource(
992 if (template_html
.empty()) {
993 NOTREACHED() << "unable to load template. ID: " << resource_id
;
995 base::DictionaryValue error_strings
;
996 LocalizedError::GetAppErrorStrings(failed_url
, extension
,
998 // "t" is the id of the template's root node.
999 *error_html
= webui::GetTemplatesHtml(template_html
, &error_strings
,
1003 NetErrorHelper
* helper
= NetErrorHelper::Get(render_view
);
1004 helper
->GetErrorHTML(frame
, error
, is_post
, error_html
);
1008 if (error_description
) {
1010 *error_description
= LocalizedError::GetErrorDetails(error
, is_post
);
1014 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
1015 return !extension_dispatcher_
->is_extension_process();
1018 bool ChromeContentRendererClient::AllowPopup() {
1019 extensions::ChromeV8Context
* current_context
=
1020 extension_dispatcher_
->v8_context_set().GetCurrent();
1021 if (!current_context
|| !current_context
->extension())
1023 // See http://crbug.com/117446 for the subtlety of this check.
1024 switch (current_context
->context_type()) {
1025 case extensions::Feature::UNSPECIFIED_CONTEXT
:
1026 case extensions::Feature::WEB_PAGE_CONTEXT
:
1027 case extensions::Feature::UNBLESSED_EXTENSION_CONTEXT
:
1029 case extensions::Feature::BLESSED_EXTENSION_CONTEXT
:
1030 case extensions::Feature::CONTENT_SCRIPT_CONTEXT
:
1032 case extensions::Feature::BLESSED_WEB_PAGE_CONTEXT
:
1033 return !current_context
->web_frame()->parent();
1039 bool ChromeContentRendererClient::ShouldFork(WebFrame
* frame
,
1041 const std::string
& http_method
,
1042 bool is_initial_navigation
,
1043 bool is_server_redirect
,
1044 bool* send_referrer
) {
1045 DCHECK(!frame
->parent());
1047 // If this is the Instant process, fork all navigations originating from the
1048 // renderer. The destination page will then be bucketed back to this Instant
1049 // process if it is an Instant url, or to another process if not. Conversely,
1050 // fork if this is a non-Instant process navigating to an Instant url, so that
1051 // such navigations can also be bucketed into an Instant renderer.
1052 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess
) ||
1053 (search_bouncer_
.get() && search_bouncer_
->ShouldFork(url
))) {
1054 *send_referrer
= true;
1058 // For now, we skip the rest for POST submissions. This is because
1059 // http://crbug.com/101395 is more likely to cause compatibility issues
1060 // with hosted apps and extensions than WebUI pages. We will remove this
1061 // check when cross-process POST submissions are supported.
1062 if (http_method
!= "GET")
1065 // If this is the Signin process, fork all navigations originating from the
1066 // renderer. The destination page will then be bucketed back to this Signin
1067 // process if it is a Signin url, or to another process if not.
1068 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSigninProcess
)) {
1069 // We never want to allow non-signin pages to fork-on-POST to a
1070 // signin-related action URL. We'll need to handle this carefully once
1071 // http://crbug.com/101395 is fixed. The CHECK ensures we don't forget.
1072 CHECK_NE(http_method
, "POST");
1076 // If |url| matches one of the prerendered URLs, stop this navigation and try
1077 // to swap in the prerendered page on the browser process. If the prerendered
1078 // page no longer exists by the time the OpenURL IPC is handled, a normal
1079 // navigation is attempted.
1080 if (prerender_dispatcher_
.get() &&
1081 prerender_dispatcher_
->IsPrerenderURL(url
)) {
1082 *send_referrer
= true;
1086 const extensions::ExtensionSet
* extensions
=
1087 extension_dispatcher_
->extensions();
1089 // Determine if the new URL is an extension (excluding bookmark apps).
1090 const Extension
* new_url_extension
= extensions::GetNonBookmarkAppExtension(
1092 bool is_extension_url
= !!new_url_extension
;
1094 // If the navigation would cross an app extent boundary, we also need
1095 // to defer to the browser to ensure process isolation. This is not necessary
1096 // for server redirects, which will be transferred to a new process by the
1097 // browser process when they are ready to commit. It is necessary for client
1098 // redirects, which won't be transferred in the same way.
1099 if (!is_server_redirect
&&
1100 CrossesExtensionExtents(frame
, url
, *extensions
, is_extension_url
,
1101 is_initial_navigation
)) {
1102 // Include the referrer in this case since we're going from a hosted web
1103 // page. (the packaged case is handled previously by the extension
1105 *send_referrer
= true;
1107 const Extension
* extension
=
1108 extension_dispatcher_
->extensions()->GetExtensionOrAppByURL(url
);
1109 if (extension
&& extension
->is_app()) {
1110 UMA_HISTOGRAM_ENUMERATION(
1111 extension
->is_platform_app() ?
1112 extension_misc::kPlatformAppLaunchHistogram
:
1113 extension_misc::kAppLaunchHistogram
,
1114 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION
,
1115 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY
);
1120 // If this is a reload, check whether it has the wrong process type. We
1121 // should send it to the browser if it's an extension URL (e.g., hosted app)
1122 // in a normal process, or if it's a process for an extension that has been
1124 if (frame
->top()->document().url() == url
) {
1125 if (is_extension_url
!= extension_dispatcher_
->is_extension_process())
1132 bool ChromeContentRendererClient::WillSendRequest(
1133 blink::WebFrame
* frame
,
1134 content::PageTransition transition_type
,
1136 const GURL
& first_party_for_cookies
,
1138 // Check whether the request should be allowed. If not allowed, we reset the
1139 // URL to something invalid to prevent the request and cause an error.
1140 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
1141 !extensions::ResourceRequestPolicy::CanRequestResource(
1145 extension_dispatcher_
->extensions())) {
1146 *new_url
= GURL(chrome::kExtensionInvalidRequestURL
);
1150 if (url
.SchemeIs(extensions::kExtensionResourceScheme
) &&
1151 !extensions::ResourceRequestPolicy::CanRequestExtensionResourceScheme(
1154 *new_url
= GURL(chrome::kExtensionResourceInvalidRequestURL
);
1158 const content::RenderView
* render_view
=
1159 content::RenderView::FromWebView(frame
->view());
1160 SearchBox
* search_box
= SearchBox::Get(render_view
);
1161 if (search_box
&& url
.SchemeIs(chrome::kChromeSearchScheme
)) {
1162 if (url
.host() == chrome::kChromeUIThumbnailHost
)
1163 return search_box
->GenerateThumbnailURLFromTransientURL(url
, new_url
);
1164 else if (url
.host() == chrome::kChromeUIFaviconHost
)
1165 return search_box
->GenerateFaviconURLFromTransientURL(url
, new_url
);
1171 void ChromeContentRendererClient::DidCreateScriptContext(
1172 WebFrame
* frame
, v8::Handle
<v8::Context
> context
, int extension_group
,
1174 extension_dispatcher_
->DidCreateScriptContext(
1175 frame
, context
, extension_group
, world_id
);
1178 void ChromeContentRendererClient::WillReleaseScriptContext(
1179 WebFrame
* frame
, v8::Handle
<v8::Context
> context
, int world_id
) {
1180 extension_dispatcher_
->WillReleaseScriptContext(frame
, context
, world_id
);
1183 unsigned long long ChromeContentRendererClient::VisitedLinkHash(
1184 const char* canonical_url
, size_t length
) {
1185 return visited_link_slave_
->ComputeURLFingerprint(canonical_url
, length
);
1188 bool ChromeContentRendererClient::IsLinkVisited(unsigned long long link_hash
) {
1189 return visited_link_slave_
->IsVisited(link_hash
);
1192 blink::WebPrescientNetworking
*
1193 ChromeContentRendererClient::GetPrescientNetworking() {
1194 return prescient_networking_dispatcher_
.get();
1197 bool ChromeContentRendererClient::ShouldOverridePageVisibilityState(
1198 const content::RenderFrame
* render_frame
,
1199 blink::WebPageVisibilityState
* override_state
) {
1200 if (!prerender::PrerenderHelper::IsPrerendering(render_frame
))
1203 *override_state
= blink::WebPageVisibilityStatePrerender
;
1207 void ChromeContentRendererClient::SetExtensionDispatcher(
1208 extensions::Dispatcher
* extension_dispatcher
) {
1209 extension_dispatcher_
.reset(extension_dispatcher
);
1210 permissions_policy_delegate_
.reset(
1211 new extensions::RendererPermissionsPolicyDelegate(
1212 extension_dispatcher_
.get()));
1215 bool ChromeContentRendererClient::CrossesExtensionExtents(
1217 const GURL
& new_url
,
1218 const extensions::ExtensionSet
& extensions
,
1219 bool is_extension_url
,
1220 bool is_initial_navigation
) {
1221 GURL
old_url(frame
->top()->document().url());
1223 // If old_url is still empty and this is an initial navigation, then this is
1224 // a window.open operation. We should look at the opener URL.
1225 if (is_initial_navigation
&& old_url
.is_empty() && frame
->opener()) {
1226 // If we're about to open a normal web page from a same-origin opener stuck
1227 // in an extension process, we want to keep it in process to allow the
1228 // opener to script it.
1229 WebDocument opener_document
= frame
->opener()->document();
1230 WebSecurityOrigin opener
= frame
->opener()->document().securityOrigin();
1231 bool opener_is_extension_url
=
1232 !opener
.isUnique() && extensions
.GetExtensionOrAppByURL(
1233 opener_document
.url()) != NULL
;
1234 if (!is_extension_url
&&
1235 !opener_is_extension_url
&&
1236 extension_dispatcher_
->is_extension_process() &&
1237 opener
.canRequest(WebURL(new_url
)))
1240 // In all other cases, we want to compare against the top frame's URL (as
1241 // opposed to the opener frame's), since that's what determines the type of
1242 // process. This allows iframes outside an app to open a popup in the app.
1243 old_url
= frame
->top()->opener()->top()->document().url();
1246 // Only consider keeping non-app URLs in an app process if this window
1247 // has an opener (in which case it might be an OAuth popup that tries to
1248 // script an iframe within the app).
1249 bool should_consider_workaround
= !!frame
->opener();
1251 return extensions::CrossesExtensionProcessBoundary(
1252 extensions
, old_url
, new_url
, should_consider_workaround
);
1255 #if defined(ENABLE_SPELLCHECK)
1256 void ChromeContentRendererClient::SetSpellcheck(SpellCheck
* spellcheck
) {
1257 RenderThread
* thread
= RenderThread::Get();
1258 if (spellcheck_
.get() && thread
)
1259 thread
->RemoveObserver(spellcheck_
.get());
1260 spellcheck_
.reset(spellcheck
);
1261 SpellCheckReplacer
replacer(spellcheck_
.get());
1262 content::RenderView::ForEach(&replacer
);
1264 thread
->AddObserver(spellcheck_
.get());
1268 void ChromeContentRendererClient::OnPurgeMemory() {
1269 #if defined(ENABLE_SPELLCHECK)
1270 DVLOG(1) << "Resetting spellcheck in renderer client";
1271 SetSpellcheck(new SpellCheck());
1275 bool ChromeContentRendererClient::IsAdblockInstalled() {
1276 return g_current_client
->extension_dispatcher_
->extensions()->Contains(
1277 "gighmmpiobklfepjocnamgkkbiglidom");
1280 bool ChromeContentRendererClient::IsAdblockPlusInstalled() {
1281 return g_current_client
->extension_dispatcher_
->extensions()->Contains(
1282 "cfhdojbkjhnklbpkdaibdccddilifddb");
1285 bool ChromeContentRendererClient::IsAdblockWithWebRequestInstalled() {
1286 return g_current_client
->extension_dispatcher_
->
1287 IsAdblockWithWebRequestInstalled();
1290 bool ChromeContentRendererClient::IsAdblockPlusWithWebRequestInstalled() {
1291 return g_current_client
->extension_dispatcher_
->
1292 IsAdblockPlusWithWebRequestInstalled();
1295 bool ChromeContentRendererClient::IsOtherExtensionWithWebRequestInstalled() {
1296 return g_current_client
->extension_dispatcher_
->
1297 IsOtherExtensionWithWebRequestInstalled();
1300 const void* ChromeContentRendererClient::CreatePPAPIInterface(
1301 const std::string
& interface_name
) {
1302 #if defined(ENABLE_PLUGINS)
1303 #if !defined(DISABLE_NACL)
1304 if (interface_name
== PPB_NACL_PRIVATE_INTERFACE
)
1305 return nacl::GetNaClPrivateInterface();
1306 #endif // DISABLE_NACL
1307 if (interface_name
== PPB_PDF_INTERFACE
)
1308 return PPB_PDF_Impl::GetInterface();
1313 bool ChromeContentRendererClient::IsExternalPepperPlugin(
1314 const std::string
& module_name
) {
1315 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
1316 // We must defer certain plugin events for NaCl instances since we switch
1317 // from the in-process to the out-of-process proxy after instantiating them.
1318 return module_name
== "Native Client";
1321 blink::WebSpeechSynthesizer
*
1322 ChromeContentRendererClient::OverrideSpeechSynthesizer(
1323 blink::WebSpeechSynthesizerClient
* client
) {
1324 return new TtsDispatcher(client
);
1327 bool ChromeContentRendererClient::AllowBrowserPlugin(
1328 blink::WebPluginContainer
* container
) {
1329 if (CommandLine::ForCurrentProcess()->HasSwitch(
1330 switches::kEnableBrowserPluginForAllViewTypes
))
1333 // If this |BrowserPlugin| <object> in the |container| is not inside a
1334 // <webview>/<adview> shadowHost, we disable instantiating this plugin. This
1335 // is to discourage and prevent developers from accidentally attaching
1336 // <object> directly in apps.
1338 // Note that this check below does *not* ensure any security, it is still
1339 // possible to bypass this check.
1340 // TODO(lazyboy): http://crbug.com/178663, Ensure we properly disallow
1341 // instantiating BrowserPlugin outside of the <webview>/<adview> shim.
1342 if (container
->element().isNull())
1345 if (container
->element().shadowHost().isNull())
1348 WebString tag_name
= container
->element().shadowHost().tagName();
1349 return tag_name
.equals(WebString::fromUTF8(kWebViewTagName
)) ||
1350 tag_name
.equals(WebString::fromUTF8(kAdViewTagName
));
1353 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI(
1355 #if !defined(OS_ANDROID)
1356 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check
1357 // the whitelist in the renderer, since we're only preventing access until
1358 // these APIs are public and stable.
1359 std::string url_host
= url
.host();
1360 if (url
.SchemeIs("https") &&
1361 (EndsWith(url_host
, "talkgadget.google.com", false) ||
1362 EndsWith(url_host
, "plus.google.com", false) ||
1363 EndsWith(url_host
, "plus.sandbox.google.com", false)) &&
1364 StartsWithASCII(url
.path(), "/hangouts/", false)) {
1367 // Allow access for tests.
1368 if (CommandLine::ForCurrentProcess()->HasSwitch(
1369 switches::kEnablePepperTesting
)) {
1372 #endif // !defined(OS_ANDROID)
1376 void ChromeContentRendererClient::AddKeySystems(
1377 std::vector
<content::KeySystemInfo
>* key_systems
) {
1378 AddChromeKeySystems(key_systems
);
1381 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource(
1382 const base::string16
& source
) const {
1383 return extensions::IsSourceFromAnExtension(source
);
1386 bool ChromeContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
1387 // SiteIsolationPolicy is off by default. We would like to activate cross-site
1388 // document blocking (for UMA data collection) for normal renderer processes
1389 // running a normal web page from the Internet. We only turn on
1390 // SiteIsolationPolicy for a renderer process that does not have the extension
1392 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
1393 return !command_line
->HasSwitch(extensions::switches::kExtensionProcess
);
1396 blink::WebWorkerPermissionClientProxy
*
1397 ChromeContentRendererClient::CreateWorkerPermissionClientProxy(
1398 content::RenderFrame
* render_frame
,
1399 blink::WebFrame
* frame
) {
1400 return new WorkerPermissionClientProxy(render_frame
, frame
);