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/common/chrome_content_client.h"
7 #include "base/command_line.h"
8 #include "base/debug/crash_logging.h"
9 #include "base/files/file_util.h"
10 #include "base/path_service.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "build/build_config.h"
18 #include "chrome/common/child_process_logging.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/chrome_version_info.h"
22 #include "chrome/common/crash_keys.h"
23 #include "chrome/common/render_messages.h"
24 #include "chrome/common/url_constants.h"
25 #include "chrome/grit/common_resources.h"
26 #include "components/dom_distiller/core/url_constants.h"
27 #include "content/public/common/content_constants.h"
28 #include "content/public/common/content_switches.h"
29 #include "content/public/common/pepper_plugin_info.h"
30 #include "content/public/common/url_constants.h"
31 #include "content/public/common/user_agent.h"
32 #include "extensions/common/constants.h"
33 #include "gpu/config/gpu_info.h"
34 #include "net/http/http_util.h"
35 #include "ui/base/l10n/l10n_util.h"
36 #include "ui/base/layout.h"
37 #include "ui/base/resource/resource_bundle.h"
39 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
42 #include "base/win/registry.h"
43 #include "base/win/windows_version.h"
44 #elif defined(OS_MACOSX)
45 #include "components/nacl/common/nacl_sandbox_type_mac.h"
48 #if !defined(DISABLE_NACL)
49 #include "components/nacl/common/nacl_constants.h"
50 #include "components/nacl/common/nacl_process_type.h"
51 #include "ppapi/native_client/src/trusted/plugin/ppapi_entrypoints.h"
54 #if defined(ENABLE_PLUGINS)
55 #include "chrome/common/pepper_flash.h"
56 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR.
57 #include "ppapi/shared_impl/ppapi_permissions.h"
60 #if defined(ENABLE_REMOTING)
61 #include "remoting/client/plugin/pepper_entrypoints.h"
64 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && \
65 !defined(WIDEVINE_CDM_IS_COMPONENT)
66 #include "chrome/common/widevine_cdm_constants.h"
71 #if defined(ENABLE_PLUGINS)
72 const char kPDFPluginMimeType
[] = "application/pdf";
73 const char kPDFPluginExtension
[] = "pdf";
74 const char kPDFPluginDescription
[] = "Portable Document Format";
75 const char kPDFPluginPrintPreviewMimeType
[] =
76 "application/x-google-chrome-print-preview-pdf";
77 const char kPDFPluginOutOfProcessMimeType
[] =
78 "application/x-google-chrome-pdf";
79 const uint32 kPDFPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
80 ppapi::PERMISSION_DEV
;
82 const char kO1DPluginName
[] = "Google Talk Plugin Video Renderer";
83 const char kO1DPluginMimeType
[] ="application/o1d";
84 const char kO1DPluginExtension
[] = "";
85 const char kO1DPluginDescription
[] = "Google Talk Plugin Video Renderer";
86 const uint32 kO1DPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
87 ppapi::PERMISSION_DEV
;
89 const char kEffectsPluginName
[] = "Google Talk Effects Plugin";
90 const char kEffectsPluginMimeType
[] ="application/x-ppapi-hangouts-effects";
91 const char kEffectsPluginExtension
[] = "";
92 const char kEffectsPluginDescription
[] = "Google Talk Effects Plugin";
93 const uint32 kEffectsPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
94 ppapi::PERMISSION_DEV
;
96 const char kGTalkPluginName
[] = "Google Talk Plugin";
97 const char kGTalkPluginMimeType
[] ="application/googletalk";
98 const char kGTalkPluginExtension
[] = ".googletalk";
99 const char kGTalkPluginDescription
[] = "Google Talk Plugin";
100 const uint32 kGTalkPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
101 ppapi::PERMISSION_DEV
;
103 #if defined(ENABLE_REMOTING)
104 #if defined(GOOGLE_CHROME_BUILD)
105 const char kRemotingViewerPluginName
[] = "Chrome Remote Desktop Viewer";
107 const char kRemotingViewerPluginName
[] = "Chromoting Viewer";
108 #endif // defined(GOOGLE_CHROME_BUILD)
109 const char kRemotingViewerPluginDescription
[] =
110 "This plugin allows you to securely access other computers that have been "
111 "shared with you. To use this plugin you must first install the "
112 "<a href=\"https://chrome.google.com/remotedesktop\">"
113 "Chrome Remote Desktop</a> webapp.";
114 // Use a consistent MIME-type regardless of branding.
115 const char kRemotingViewerPluginMimeType
[] =
116 "application/vnd.chromium.remoting-viewer";
117 const char kRemotingViewerPluginMimeExtension
[] = "";
118 const char kRemotingViewerPluginMimeDescription
[] = "";
119 const uint32 kRemotingViewerPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
120 ppapi::PERMISSION_DEV
;
121 #endif // defined(ENABLE_REMOTING)
123 // Appends the known built-in plugins to the given vector. Some built-in
124 // plugins are "internal" which means they are compiled into the Chrome binary,
125 // and some are extra shared libraries distributed with the browser (these are
126 // not marked internal, aside from being automatically registered, they're just
128 void ComputeBuiltInPlugins(std::vector
<content::PepperPluginInfo
>* plugins
) {
131 // Once we're sandboxed, we can't know if the PDF plugin is available or not;
132 // but (on Linux) this function is always called once before we're sandboxed.
133 // So the first time through test if the file is available and then skip the
134 // check on subsequent calls if yes.
135 static bool skip_pdf_file_check
= false;
137 if (PathService::Get(chrome::FILE_PDF_PLUGIN
, &path
)) {
138 if (skip_pdf_file_check
|| base::PathExists(path
)) {
139 content::PepperPluginInfo pdf
;
141 pdf
.name
= ChromeContentClient::kPDFPluginName
;
142 if (CommandLine::ForCurrentProcess()->HasSwitch(
143 switches::kOutOfProcessPdf
)) {
144 pdf
.is_out_of_process
= true;
145 content::WebPluginMimeType
pdf_mime_type(kPDFPluginOutOfProcessMimeType
,
147 kPDFPluginDescription
);
148 pdf
.mime_types
.push_back(pdf_mime_type
);
149 // TODO(raymes): Make print preview work with out of process PDF.
151 content::WebPluginMimeType
pdf_mime_type(kPDFPluginMimeType
,
153 kPDFPluginDescription
);
154 content::WebPluginMimeType
print_preview_pdf_mime_type(
155 kPDFPluginPrintPreviewMimeType
,
157 kPDFPluginDescription
);
158 pdf
.mime_types
.push_back(pdf_mime_type
);
159 pdf
.mime_types
.push_back(print_preview_pdf_mime_type
);
161 pdf
.permissions
= kPDFPluginPermissions
;
162 plugins
->push_back(pdf
);
164 skip_pdf_file_check
= true;
168 #if !defined(DISABLE_NACL)
169 // Handle Native Client just like the PDF plugin. This means that it is
170 // enabled by default for the non-portable case. This allows apps installed
171 // from the Chrome Web Store to use NaCl even if the command line switch
172 // isn't set. For other uses of NaCl we check for the command line switch.
173 if (PathService::Get(chrome::FILE_NACL_PLUGIN
, &path
)) {
174 content::PepperPluginInfo nacl
;
175 // The nacl plugin is now built into the Chromium binary.
176 nacl
.is_internal
= true;
178 nacl
.name
= nacl::kNaClPluginName
;
179 content::WebPluginMimeType
nacl_mime_type(nacl::kNaClPluginMimeType
,
180 nacl::kNaClPluginExtension
,
181 nacl::kNaClPluginDescription
);
182 nacl
.mime_types
.push_back(nacl_mime_type
);
183 content::WebPluginMimeType
pnacl_mime_type(nacl::kPnaclPluginMimeType
,
184 nacl::kPnaclPluginExtension
,
185 nacl::kPnaclPluginDescription
);
186 nacl
.mime_types
.push_back(pnacl_mime_type
);
187 nacl
.internal_entry_points
.get_interface
= nacl_plugin::PPP_GetInterface
;
188 nacl
.internal_entry_points
.initialize_module
=
189 nacl_plugin::PPP_InitializeModule
;
190 nacl
.internal_entry_points
.shutdown_module
=
191 nacl_plugin::PPP_ShutdownModule
;
192 nacl
.permissions
= ppapi::PERMISSION_PRIVATE
| ppapi::PERMISSION_DEV
;
193 plugins
->push_back(nacl
);
195 #endif // !defined(DISABLE_NACL)
197 static bool skip_o1d_file_check
= false;
198 if (PathService::Get(chrome::FILE_O1D_PLUGIN
, &path
)) {
199 if (skip_o1d_file_check
|| base::PathExists(path
)) {
200 content::PepperPluginInfo o1d
;
202 o1d
.name
= kO1DPluginName
;
203 o1d
.is_out_of_process
= true;
204 o1d
.is_sandboxed
= false;
205 o1d
.permissions
= kO1DPluginPermissions
;
206 content::WebPluginMimeType
o1d_mime_type(kO1DPluginMimeType
,
208 kO1DPluginDescription
);
209 o1d
.mime_types
.push_back(o1d_mime_type
);
210 plugins
->push_back(o1d
);
212 skip_o1d_file_check
= true;
216 // TODO(vrk): Remove this when NaCl effects plugin replaces the ppapi effects
218 static bool skip_effects_file_check
= false;
219 if (PathService::Get(chrome::FILE_EFFECTS_PLUGIN
, &path
)) {
220 if (skip_effects_file_check
|| base::PathExists(path
)) {
221 content::PepperPluginInfo effects
;
223 effects
.name
= kEffectsPluginName
;
224 effects
.is_out_of_process
= true;
225 effects
.is_sandboxed
= true;
226 effects
.permissions
= kEffectsPluginPermissions
;
227 content::WebPluginMimeType
effects_mime_type(kEffectsPluginMimeType
,
228 kEffectsPluginExtension
,
229 kEffectsPluginDescription
);
230 effects
.mime_types
.push_back(effects_mime_type
);
231 plugins
->push_back(effects
);
233 skip_effects_file_check
= true;
237 static bool skip_gtalk_file_check
= false;
238 if (PathService::Get(chrome::FILE_GTALK_PLUGIN
, &path
)) {
239 if (skip_gtalk_file_check
|| base::PathExists(path
)) {
240 content::PepperPluginInfo gtalk
;
242 gtalk
.name
= kGTalkPluginName
;
243 gtalk
.is_out_of_process
= true;
244 gtalk
.is_sandboxed
= false;
245 gtalk
.permissions
= kGTalkPluginPermissions
;
246 content::WebPluginMimeType
gtalk_mime_type(kGTalkPluginMimeType
,
247 kGTalkPluginExtension
,
248 kGTalkPluginDescription
);
249 gtalk
.mime_types
.push_back(gtalk_mime_type
);
250 plugins
->push_back(gtalk
);
252 skip_gtalk_file_check
= true;
256 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && \
257 !defined(WIDEVINE_CDM_IS_COMPONENT)
258 static bool skip_widevine_cdm_file_check
= false;
259 if (PathService::Get(chrome::FILE_WIDEVINE_CDM_ADAPTER
, &path
)) {
260 if (skip_widevine_cdm_file_check
|| base::PathExists(path
)) {
261 content::PepperPluginInfo widevine_cdm
;
262 widevine_cdm
.is_out_of_process
= true;
263 widevine_cdm
.path
= path
;
264 widevine_cdm
.name
= kWidevineCdmDisplayName
;
265 widevine_cdm
.description
= kWidevineCdmDescription
;
266 widevine_cdm
.version
= WIDEVINE_CDM_VERSION_STRING
;
267 content::WebPluginMimeType
widevine_cdm_mime_type(
268 kWidevineCdmPluginMimeType
,
269 kWidevineCdmPluginExtension
,
270 kWidevineCdmPluginMimeTypeDescription
);
272 // Add the supported codecs as if they came from the component manifest.
273 std::vector
<std::string
> codecs
;
274 codecs
.push_back(kCdmSupportedCodecVorbis
);
275 codecs
.push_back(kCdmSupportedCodecVp8
);
276 codecs
.push_back(kCdmSupportedCodecVp9
);
277 #if defined(USE_PROPRIETARY_CODECS)
278 // TODO(ddorwin): Rename these macros to reflect their real meaning: whether the
279 // CDM Chrome was built [and shipped] with support these types.
280 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
281 codecs
.push_back(kCdmSupportedCodecAac
);
283 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
284 codecs
.push_back(kCdmSupportedCodecAvc1
);
286 #endif // defined(USE_PROPRIETARY_CODECS)
287 std::string codec_string
=
288 JoinString(codecs
, kCdmSupportedCodecsValueDelimiter
);
289 widevine_cdm_mime_type
.additional_param_names
.push_back(
290 base::ASCIIToUTF16(kCdmSupportedCodecsParamName
));
291 widevine_cdm_mime_type
.additional_param_values
.push_back(
292 base::ASCIIToUTF16(codec_string
));
294 widevine_cdm
.mime_types
.push_back(widevine_cdm_mime_type
);
295 widevine_cdm
.permissions
= kWidevineCdmPluginPermissions
;
296 plugins
->push_back(widevine_cdm
);
298 skip_widevine_cdm_file_check
= true;
301 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) &&
302 // !defined(WIDEVINE_CDM_IS_COMPONENT)
304 // The Remoting Viewer plugin is built-in.
305 #if defined(ENABLE_REMOTING)
306 content::PepperPluginInfo info
;
307 info
.is_internal
= true;
308 info
.is_out_of_process
= true;
309 info
.name
= kRemotingViewerPluginName
;
310 info
.description
= kRemotingViewerPluginDescription
;
311 info
.path
= base::FilePath::FromUTF8Unsafe(
312 ChromeContentClient::kRemotingViewerPluginPath
);
313 content::WebPluginMimeType
remoting_mime_type(
314 kRemotingViewerPluginMimeType
,
315 kRemotingViewerPluginMimeExtension
,
316 kRemotingViewerPluginMimeDescription
);
317 info
.mime_types
.push_back(remoting_mime_type
);
318 info
.internal_entry_points
.get_interface
= remoting::PPP_GetInterface
;
319 info
.internal_entry_points
.initialize_module
=
320 remoting::PPP_InitializeModule
;
321 info
.internal_entry_points
.shutdown_module
= remoting::PPP_ShutdownModule
;
322 info
.permissions
= kRemotingViewerPluginPermissions
;
324 plugins
->push_back(info
);
328 content::PepperPluginInfo
CreatePepperFlashInfo(const base::FilePath
& path
,
329 const std::string
& version
) {
330 content::PepperPluginInfo plugin
;
332 plugin
.is_out_of_process
= true;
333 plugin
.name
= content::kFlashPluginName
;
335 plugin
.permissions
= kPepperFlashPermissions
;
337 std::vector
<std::string
> flash_version_numbers
;
338 base::SplitString(version
, '.', &flash_version_numbers
);
339 if (flash_version_numbers
.size() < 1)
340 flash_version_numbers
.push_back("11");
341 // |SplitString()| puts in an empty string given an empty string. :(
342 else if (flash_version_numbers
[0].empty())
343 flash_version_numbers
[0] = "11";
344 if (flash_version_numbers
.size() < 2)
345 flash_version_numbers
.push_back("2");
346 if (flash_version_numbers
.size() < 3)
347 flash_version_numbers
.push_back("999");
348 if (flash_version_numbers
.size() < 4)
349 flash_version_numbers
.push_back("999");
350 // E.g., "Shockwave Flash 10.2 r154":
351 plugin
.description
= plugin
.name
+ " " + flash_version_numbers
[0] + "." +
352 flash_version_numbers
[1] + " r" + flash_version_numbers
[2];
353 plugin
.version
= JoinString(flash_version_numbers
, '.');
354 content::WebPluginMimeType
swf_mime_type(content::kFlashPluginSwfMimeType
,
355 content::kFlashPluginSwfExtension
,
356 content::kFlashPluginSwfDescription
);
357 plugin
.mime_types
.push_back(swf_mime_type
);
358 content::WebPluginMimeType
spl_mime_type(content::kFlashPluginSplMimeType
,
359 content::kFlashPluginSplExtension
,
360 content::kFlashPluginSplDescription
);
361 plugin
.mime_types
.push_back(spl_mime_type
);
366 void AddPepperFlashFromCommandLine(
367 std::vector
<content::PepperPluginInfo
>* plugins
) {
368 const CommandLine::StringType flash_path
=
369 CommandLine::ForCurrentProcess()->GetSwitchValueNative(
370 switches::kPpapiFlashPath
);
371 if (flash_path
.empty())
374 // Also get the version from the command-line. Should be something like 11.2
376 std::string flash_version
=
377 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
378 switches::kPpapiFlashVersion
);
381 CreatePepperFlashInfo(base::FilePath(flash_path
), flash_version
));
384 bool GetBundledPepperFlash(content::PepperPluginInfo
* plugin
) {
385 #if defined(FLAPPER_AVAILABLE)
386 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
388 // Ignore bundled Pepper Flash if there is Pepper Flash specified from the
390 if (command_line
->HasSwitch(switches::kPpapiFlashPath
))
394 command_line
->HasSwitch(switches::kDisableBundledPpapiFlash
);
398 base::FilePath flash_path
;
399 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN
, &flash_path
))
402 *plugin
= CreatePepperFlashInfo(flash_path
, FLAPPER_VERSION_STRING
);
406 #endif // FLAPPER_AVAILABLE
408 #endif // defined(ENABLE_PLUGINS)
410 std::string
GetProduct() {
411 chrome::VersionInfo version_info
;
412 return version_info
.is_valid() ?
413 version_info
.ProductNameAndVersionForUserAgent() : std::string();
418 std::string
GetUserAgent() {
419 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
420 if (command_line
->HasSwitch(switches::kUserAgent
)) {
421 std::string ua
= command_line
->GetSwitchValueASCII(switches::kUserAgent
);
422 if (net::HttpUtil::IsValidHeaderValue(ua
))
424 LOG(WARNING
) << "Ignored invalid value for flag --" << switches::kUserAgent
;
427 std::string product
= GetProduct();
428 #if defined(OS_ANDROID)
429 if (command_line
->HasSwitch(switches::kUseMobileUserAgent
))
430 product
+= " Mobile";
432 return content::BuildUserAgentFromProduct(product
);
435 void ChromeContentClient::SetActiveURL(const GURL
& url
) {
436 base::debug::SetCrashKeyValue(crash_keys::kActiveURL
,
437 url
.possibly_invalid_spec());
440 void ChromeContentClient::SetGpuInfo(const gpu::GPUInfo
& gpu_info
) {
441 #if !defined(OS_ANDROID)
442 base::debug::SetCrashKeyValue(crash_keys::kGPUVendorID
,
443 base::StringPrintf("0x%04x", gpu_info
.gpu
.vendor_id
));
444 base::debug::SetCrashKeyValue(crash_keys::kGPUDeviceID
,
445 base::StringPrintf("0x%04x", gpu_info
.gpu
.device_id
));
447 base::debug::SetCrashKeyValue(crash_keys::kGPUDriverVersion
,
448 gpu_info
.driver_version
);
449 base::debug::SetCrashKeyValue(crash_keys::kGPUPixelShaderVersion
,
450 gpu_info
.pixel_shader_version
);
451 base::debug::SetCrashKeyValue(crash_keys::kGPUVertexShaderVersion
,
452 gpu_info
.vertex_shader_version
);
453 #if defined(OS_MACOSX)
454 base::debug::SetCrashKeyValue(crash_keys::kGPUGLVersion
, gpu_info
.gl_version
);
455 #elif defined(OS_POSIX)
456 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor
, gpu_info
.gl_vendor
);
457 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer
, gpu_info
.gl_renderer
);
461 void ChromeContentClient::AddPepperPlugins(
462 std::vector
<content::PepperPluginInfo
>* plugins
) {
463 #if defined(ENABLE_PLUGINS)
464 ComputeBuiltInPlugins(plugins
);
465 AddPepperFlashFromCommandLine(plugins
);
467 content::PepperPluginInfo plugin
;
468 if (GetBundledPepperFlash(&plugin
))
469 plugins
->push_back(plugin
);
473 void ChromeContentClient::AddAdditionalSchemes(
474 std::vector
<std::string
>* standard_schemes
,
475 std::vector
<std::string
>* savable_schemes
) {
476 standard_schemes
->push_back(extensions::kExtensionScheme
);
477 savable_schemes
->push_back(extensions::kExtensionScheme
);
478 standard_schemes
->push_back(chrome::kChromeNativeScheme
);
479 standard_schemes
->push_back(extensions::kExtensionResourceScheme
);
480 savable_schemes
->push_back(extensions::kExtensionResourceScheme
);
481 standard_schemes
->push_back(chrome::kChromeSearchScheme
);
482 savable_schemes
->push_back(chrome::kChromeSearchScheme
);
483 standard_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
484 savable_schemes
->push_back(dom_distiller::kDomDistillerScheme
);
485 #if defined(OS_CHROMEOS)
486 standard_schemes
->push_back(chrome::kCrosScheme
);
490 std::string
ChromeContentClient::GetProduct() const {
491 return ::GetProduct();
494 std::string
ChromeContentClient::GetUserAgent() const {
495 return ::GetUserAgent();
498 base::string16
ChromeContentClient::GetLocalizedString(int message_id
) const {
499 return l10n_util::GetStringUTF16(message_id
);
502 base::StringPiece
ChromeContentClient::GetDataResource(
504 ui::ScaleFactor scale_factor
) const {
505 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
506 resource_id
, scale_factor
);
509 base::RefCountedStaticMemory
* ChromeContentClient::GetDataResourceBytes(
510 int resource_id
) const {
511 return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id
);
514 gfx::Image
& ChromeContentClient::GetNativeImageNamed(int resource_id
) const {
515 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id
);
518 std::string
ChromeContentClient::GetProcessTypeNameInEnglish(int type
) {
519 #if !defined(DISABLE_NACL)
521 case PROCESS_TYPE_NACL_LOADER
:
522 return "Native Client module";
523 case PROCESS_TYPE_NACL_BROKER
:
524 return "Native Client broker";
528 NOTREACHED() << "Unknown child process type!";
532 #if defined(OS_MACOSX) && !defined(OS_IOS)
533 bool ChromeContentClient::GetSandboxProfileForSandboxType(
535 int* sandbox_profile_resource_id
) const {
536 DCHECK(sandbox_profile_resource_id
);
537 if (sandbox_type
== NACL_SANDBOX_TYPE_NACL_LOADER
) {
538 *sandbox_profile_resource_id
= IDR_NACL_SANDBOX_PROFILE
;