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"
9 #include "base/debug/crash_logging.h"
10 #include "base/file_util.h"
11 #include "base/path_service.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/pepper_flash.h"
24 #include "chrome/common/render_messages.h"
25 #include "chrome/common/url_constants.h"
26 #include "components/nacl/common/nacl_process_type.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 "extensions/common/constants.h"
32 #include "gpu/config/gpu_info.h"
33 #include "grit/common_resources.h"
34 #include "ppapi/shared_impl/ppapi_permissions.h"
35 #include "remoting/client/plugin/pepper_entrypoints.h"
36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/layout.h"
38 #include "ui/base/resource/resource_bundle.h"
39 #include "webkit/common/user_agent/user_agent_util.h"
41 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR.
42 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
45 #include "base/win/registry.h"
46 #include "base/win/windows_version.h"
47 #include "sandbox/win/src/sandbox.h"
48 #elif defined(OS_MACOSX)
49 #include "components/nacl/common/nacl_sandbox_type_mac.h"
52 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && \
53 !defined(WIDEVINE_CDM_IS_COMPONENT)
54 #include "chrome/common/widevine_cdm_constants.h"
59 const char kPDFPluginMimeType
[] = "application/pdf";
60 const char kPDFPluginExtension
[] = "pdf";
61 const char kPDFPluginDescription
[] = "Portable Document Format";
62 const char kPDFPluginPrintPreviewMimeType
63 [] = "application/x-google-chrome-print-preview-pdf";
64 const uint32 kPDFPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
65 ppapi::PERMISSION_DEV
;
67 const char kNaClPluginMimeType
[] = "application/x-nacl";
68 const char kNaClPluginExtension
[] = "";
69 const char kNaClPluginDescription
[] = "Native Client Executable";
70 const uint32 kNaClPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
71 ppapi::PERMISSION_DEV
;
73 const char kPnaclPluginMimeType
[] = "application/x-pnacl";
74 const char kPnaclPluginExtension
[] = "";
75 const char kPnaclPluginDescription
[] = "Portable Native Client Executable";
76 const uint32 kPnaclPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
77 ppapi::PERMISSION_DEV
;
79 const char kO3DPluginName
[] = "Google Talk Plugin Video Accelerator";
80 const char kO3DPluginMimeType
[] ="application/vnd.o3d.auto";
81 const char kO3DPluginExtension
[] = "";
82 const char kO3DPluginDescription
[] = "O3D MIME";
83 const uint32 kO3DPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
84 ppapi::PERMISSION_DEV
;
86 const char kO1DPluginName
[] = "Google Talk Plugin Video Renderer";
87 const char kO1DPluginMimeType
[] ="application/o1d";
88 const char kO1DPluginExtension
[] = "";
89 const char kO1DPluginDescription
[] = "Google Talk Plugin Video Renderer";
90 const uint32 kO1DPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
91 ppapi::PERMISSION_DEV
;
93 const char kEffectsPluginName
[] = "Google Talk Effects Plugin";
94 const char kEffectsPluginMimeType
[] ="application/x-ppapi-hangouts-effects";
95 const char kEffectsPluginExtension
[] = "";
96 const char kEffectsPluginDescription
[] = "Google Talk Effects Plugin";
97 const uint32 kEffectsPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
98 ppapi::PERMISSION_DEV
;
100 const char kGTalkPluginName
[] = "Google Talk Plugin";
101 const char kGTalkPluginMimeType
[] ="application/googletalk";
102 const char kGTalkPluginExtension
[] = ".googletalk";
103 const char kGTalkPluginDescription
[] = "Google Talk Plugin";
104 const uint32 kGTalkPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
105 ppapi::PERMISSION_DEV
;
107 #if defined(ENABLE_REMOTING)
108 #if defined(GOOGLE_CHROME_BUILD)
109 const char kRemotingViewerPluginName
[] = "Chrome Remote Desktop Viewer";
111 const char kRemotingViewerPluginName
[] = "Chromoting Viewer";
112 #endif // defined(GOOGLE_CHROME_BUILD)
113 const char kRemotingViewerPluginDescription
[] =
114 "This plugin allows you to securely access other computers that have been "
115 "shared with you. To use this plugin you must first install the "
116 "<a href=\"https://chrome.google.com/remotedesktop\">"
117 "Chrome Remote Desktop</a> webapp.";
118 const base::FilePath::CharType kRemotingViewerPluginPath
[] =
119 FILE_PATH_LITERAL("internal-remoting-viewer");
120 // Use a consistent MIME-type regardless of branding.
121 const char kRemotingViewerPluginMimeType
[] =
122 "application/vnd.chromium.remoting-viewer";
123 const char kRemotingViewerPluginMimeExtension
[] = "";
124 const char kRemotingViewerPluginMimeDescription
[] = "";
125 const uint32 kRemotingViewerPluginPermissions
= ppapi::PERMISSION_PRIVATE
|
126 ppapi::PERMISSION_DEV
;
127 #endif // defined(ENABLE_REMOTING)
129 const char kInterposeLibraryPath
[] =
130 "@executable_path/../../../libplugin_carbon_interpose.dylib";
132 // Appends the known built-in plugins to the given vector. Some built-in
133 // plugins are "internal" which means they are compiled into the Chrome binary,
134 // and some are extra shared libraries distributed with the browser (these are
135 // not marked internal, aside from being automatically registered, they're just
137 void ComputeBuiltInPlugins(std::vector
<content::PepperPluginInfo
>* plugins
) {
140 // Once we're sandboxed, we can't know if the PDF plugin is available or not;
141 // but (on Linux) this function is always called once before we're sandboxed.
142 // So the first time through test if the file is available and then skip the
143 // check on subsequent calls if yes.
144 static bool skip_pdf_file_check
= false;
146 if (PathService::Get(chrome::FILE_PDF_PLUGIN
, &path
)) {
147 if (skip_pdf_file_check
|| base::PathExists(path
)) {
148 content::PepperPluginInfo pdf
;
150 pdf
.name
= chrome::ChromeContentClient::kPDFPluginName
;
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
);
160 pdf
.permissions
= kPDFPluginPermissions
;
161 plugins
->push_back(pdf
);
163 skip_pdf_file_check
= true;
167 // Handle Native Client just like the PDF plugin. This means that it is
168 // enabled by default for the non-portable case. This allows apps installed
169 // from the Chrome Web Store to use NaCl even if the command line switch
170 // isn't set. For other uses of NaCl we check for the command line switch.
171 // Specifically, Portable Native Client is only enabled by the command line
173 static bool skip_nacl_file_check
= false;
174 if (PathService::Get(chrome::FILE_NACL_PLUGIN
, &path
)) {
175 if (skip_nacl_file_check
|| base::PathExists(path
)) {
176 content::PepperPluginInfo nacl
;
178 nacl
.name
= chrome::ChromeContentClient::kNaClPluginName
;
179 content::WebPluginMimeType
nacl_mime_type(kNaClPluginMimeType
,
180 kNaClPluginExtension
,
181 kNaClPluginDescription
);
182 nacl
.mime_types
.push_back(nacl_mime_type
);
183 if (!CommandLine::ForCurrentProcess()->HasSwitch(
184 switches::kDisablePnacl
)) {
185 content::WebPluginMimeType
pnacl_mime_type(kPnaclPluginMimeType
,
186 kPnaclPluginExtension
,
187 kPnaclPluginDescription
);
188 nacl
.mime_types
.push_back(pnacl_mime_type
);
190 nacl
.permissions
= kNaClPluginPermissions
;
191 plugins
->push_back(nacl
);
193 skip_nacl_file_check
= true;
197 // TODO(jhorwich|noahric): Remove o3d ppapi code once o3d is replaced
198 // entirely with o1d.
199 static bool skip_o3d_file_check
= false;
200 if (PathService::Get(chrome::FILE_O3D_PLUGIN
, &path
)) {
201 if (skip_o3d_file_check
|| base::PathExists(path
)) {
202 content::PepperPluginInfo o3d
;
204 o3d
.name
= kO3DPluginName
;
205 o3d
.is_out_of_process
= true;
206 o3d
.is_sandboxed
= false;
207 o3d
.permissions
= kO3DPluginPermissions
;
208 content::WebPluginMimeType
o3d_mime_type(kO3DPluginMimeType
,
210 kO3DPluginDescription
);
211 o3d
.mime_types
.push_back(o3d_mime_type
);
212 plugins
->push_back(o3d
);
214 skip_o3d_file_check
= true;
218 static bool skip_o1d_file_check
= false;
219 if (PathService::Get(chrome::FILE_O1D_PLUGIN
, &path
)) {
220 if (skip_o1d_file_check
|| base::PathExists(path
)) {
221 content::PepperPluginInfo o1d
;
223 o1d
.name
= kO1DPluginName
;
224 o1d
.is_out_of_process
= true;
225 o1d
.is_sandboxed
= false;
226 o1d
.permissions
= kO1DPluginPermissions
;
227 content::WebPluginMimeType
o1d_mime_type(kO1DPluginMimeType
,
229 kO1DPluginDescription
);
230 o1d
.mime_types
.push_back(o1d_mime_type
);
231 plugins
->push_back(o1d
);
233 skip_o1d_file_check
= true;
237 // TODO(vrk): Remove this when NaCl effects plugin replaces the ppapi effects
239 static bool skip_effects_file_check
= false;
240 if (PathService::Get(chrome::FILE_EFFECTS_PLUGIN
, &path
)) {
241 if (skip_effects_file_check
|| base::PathExists(path
)) {
242 content::PepperPluginInfo effects
;
244 effects
.name
= kEffectsPluginName
;
245 effects
.is_out_of_process
= true;
246 effects
.is_sandboxed
= true;
247 effects
.permissions
= kEffectsPluginPermissions
;
248 content::WebPluginMimeType
effects_mime_type(kEffectsPluginMimeType
,
249 kEffectsPluginExtension
,
250 kEffectsPluginDescription
);
251 effects
.mime_types
.push_back(effects_mime_type
);
252 plugins
->push_back(effects
);
254 skip_effects_file_check
= true;
258 static bool skip_gtalk_file_check
= false;
259 if (PathService::Get(chrome::FILE_GTALK_PLUGIN
, &path
)) {
260 if (skip_gtalk_file_check
|| base::PathExists(path
)) {
261 content::PepperPluginInfo gtalk
;
263 gtalk
.name
= kGTalkPluginName
;
264 gtalk
.is_out_of_process
= true;
265 gtalk
.is_sandboxed
= false;
266 gtalk
.permissions
= kGTalkPluginPermissions
;
267 content::WebPluginMimeType
gtalk_mime_type(kGTalkPluginMimeType
,
268 kGTalkPluginExtension
,
269 kGTalkPluginDescription
);
270 gtalk
.mime_types
.push_back(gtalk_mime_type
);
271 plugins
->push_back(gtalk
);
273 skip_gtalk_file_check
= true;
277 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && \
278 !defined(WIDEVINE_CDM_IS_COMPONENT)
279 static bool skip_widevine_cdm_file_check
= false;
280 if (PathService::Get(chrome::FILE_WIDEVINE_CDM_ADAPTER
, &path
)) {
281 if (skip_widevine_cdm_file_check
|| base::PathExists(path
)) {
282 content::PepperPluginInfo widevine_cdm
;
283 widevine_cdm
.is_out_of_process
= true;
284 widevine_cdm
.path
= path
;
285 widevine_cdm
.name
= kWidevineCdmDisplayName
;
286 widevine_cdm
.description
= kWidevineCdmDescription
;
287 widevine_cdm
.version
= WIDEVINE_CDM_VERSION_STRING
;
288 content::WebPluginMimeType
widevine_cdm_mime_type(
289 kWidevineCdmPluginMimeType
,
290 kWidevineCdmPluginExtension
,
291 kWidevineCdmPluginMimeTypeDescription
);
292 widevine_cdm
.mime_types
.push_back(widevine_cdm_mime_type
);
293 widevine_cdm
.permissions
= kWidevineCdmPluginPermissions
;
294 plugins
->push_back(widevine_cdm
);
296 skip_widevine_cdm_file_check
= true;
299 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) &&
300 // !defined(WIDEVINE_CDM_IS_COMPONENT)
302 // The Remoting Viewer plugin is built-in.
303 #if defined(ENABLE_REMOTING)
304 content::PepperPluginInfo info
;
305 info
.is_internal
= true;
306 info
.is_out_of_process
= true;
307 info
.name
= kRemotingViewerPluginName
;
308 info
.description
= kRemotingViewerPluginDescription
;
309 info
.path
= base::FilePath(kRemotingViewerPluginPath
);
310 content::WebPluginMimeType
remoting_mime_type(
311 kRemotingViewerPluginMimeType
,
312 kRemotingViewerPluginMimeExtension
,
313 kRemotingViewerPluginMimeDescription
);
314 info
.mime_types
.push_back(remoting_mime_type
);
315 info
.internal_entry_points
.get_interface
= remoting::PPP_GetInterface
;
316 info
.internal_entry_points
.initialize_module
=
317 remoting::PPP_InitializeModule
;
318 info
.internal_entry_points
.shutdown_module
= remoting::PPP_ShutdownModule
;
319 info
.permissions
= kRemotingViewerPluginPermissions
;
321 plugins
->push_back(info
);
325 content::PepperPluginInfo
CreatePepperFlashInfo(const base::FilePath
& path
,
326 const std::string
& version
) {
327 content::PepperPluginInfo plugin
;
329 // Flash being out of process is handled separately than general plugins
330 // for testing purposes.
331 plugin
.is_out_of_process
= !CommandLine::ForCurrentProcess()->HasSwitch(
332 switches::kPpapiFlashInProcess
);
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 // For Linux ia32, Flapper requires SSE2.
399 #if defined(OS_LINUX) && defined(ARCH_CPU_X86)
400 if (!base::CPU().has_sse2())
402 #endif // ARCH_CPU_X86
404 base::FilePath flash_path
;
405 if (!PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN
, &flash_path
))
408 *plugin
= CreatePepperFlashInfo(flash_path
, FLAPPER_VERSION_STRING
);
412 #endif // FLAPPER_AVAILABLE
419 void ChromeContentClient::SetActiveURL(const GURL
& url
) {
420 base::debug::SetCrashKeyValue(crash_keys::kActiveURL
,
421 url
.possibly_invalid_spec());
424 void ChromeContentClient::SetGpuInfo(const gpu::GPUInfo
& gpu_info
) {
425 #if !defined(OS_ANDROID)
426 base::debug::SetCrashKeyValue(crash_keys::kGPUVendorID
,
427 base::StringPrintf("0x%04x", gpu_info
.gpu
.vendor_id
));
428 base::debug::SetCrashKeyValue(crash_keys::kGPUDeviceID
,
429 base::StringPrintf("0x%04x", gpu_info
.gpu
.device_id
));
431 base::debug::SetCrashKeyValue(crash_keys::kGPUDriverVersion
,
432 gpu_info
.driver_version
);
433 base::debug::SetCrashKeyValue(crash_keys::kGPUPixelShaderVersion
,
434 gpu_info
.pixel_shader_version
);
435 base::debug::SetCrashKeyValue(crash_keys::kGPUVertexShaderVersion
,
436 gpu_info
.vertex_shader_version
);
437 #if defined(OS_LINUX)
438 base::debug::SetCrashKeyValue(crash_keys::kGPUVendor
, gpu_info
.gl_vendor
);
439 base::debug::SetCrashKeyValue(crash_keys::kGPURenderer
, gpu_info
.gl_renderer
);
440 #elif defined(OS_MACOSX)
441 base::debug::SetCrashKeyValue(crash_keys::kGPUGLVersion
, gpu_info
.gl_version
);
445 void ChromeContentClient::AddPepperPlugins(
446 std::vector
<content::PepperPluginInfo
>* plugins
) {
447 ComputeBuiltInPlugins(plugins
);
448 AddPepperFlashFromCommandLine(plugins
);
450 content::PepperPluginInfo plugin
;
451 if (GetBundledPepperFlash(&plugin
))
452 plugins
->push_back(plugin
);
455 void ChromeContentClient::AddAdditionalSchemes(
456 std::vector
<std::string
>* standard_schemes
,
457 std::vector
<std::string
>* savable_schemes
) {
458 standard_schemes
->push_back(extensions::kExtensionScheme
);
459 savable_schemes
->push_back(extensions::kExtensionScheme
);
460 standard_schemes
->push_back(kExtensionResourceScheme
);
461 savable_schemes
->push_back(kExtensionResourceScheme
);
462 standard_schemes
->push_back(chrome::kChromeSearchScheme
);
463 savable_schemes
->push_back(chrome::kChromeSearchScheme
);
464 #if defined(OS_CHROMEOS)
465 standard_schemes
->push_back(kCrosScheme
);
469 bool ChromeContentClient::CanHandleWhileSwappedOut(
470 const IPC::Message
& msg
) {
471 // Any Chrome-specific messages (apart from those listed in
472 // CanSendWhileSwappedOut) that must be handled by the browser when sent from
473 // swapped out renderers.
477 std::string
ChromeContentClient::GetProduct() const {
478 chrome::VersionInfo version_info
;
479 return version_info
.is_valid() ?
480 version_info
.ProductNameAndVersionForUserAgent() : std::string();
483 std::string
ChromeContentClient::GetUserAgent() const {
484 std::string product
= GetProduct();
485 #if defined(OS_ANDROID)
486 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
487 if (command_line
->HasSwitch(switches::kUseMobileUserAgent
))
488 product
+= " Mobile";
490 return webkit_glue::BuildUserAgentFromProduct(product
);
493 string16
ChromeContentClient::GetLocalizedString(int message_id
) const {
494 return l10n_util::GetStringUTF16(message_id
);
497 base::StringPiece
ChromeContentClient::GetDataResource(
499 ui::ScaleFactor scale_factor
) const {
500 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
501 resource_id
, scale_factor
);
504 base::RefCountedStaticMemory
* ChromeContentClient::GetDataResourceBytes(
505 int resource_id
) const {
506 return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id
);
509 gfx::Image
& ChromeContentClient::GetNativeImageNamed(int resource_id
) const {
510 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id
);
513 std::string
ChromeContentClient::GetProcessTypeNameInEnglish(int type
) {
515 case PROCESS_TYPE_NACL_LOADER
:
516 return "Native Client module";
517 case PROCESS_TYPE_NACL_BROKER
:
518 return "Native Client broker";
521 DCHECK(false) << "Unknown child process type!";
525 #if defined(OS_MACOSX) && !defined(OS_IOS)
526 bool ChromeContentClient::GetSandboxProfileForSandboxType(
528 int* sandbox_profile_resource_id
) const {
529 DCHECK(sandbox_profile_resource_id
);
530 if (sandbox_type
== NACL_SANDBOX_TYPE_NACL_LOADER
) {
531 *sandbox_profile_resource_id
= IDR_NACL_SANDBOX_PROFILE
;
537 std::string
ChromeContentClient::GetCarbonInterposePath() const {
538 return std::string(kInterposeLibraryPath
);
542 } // namespace chrome