OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/chrome_content_client.h" | 5 #include "chrome/common/chrome_content_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
16 #include "chrome/common/child_process_logging.h" | 16 #include "chrome/common/child_process_logging.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 20 #include "chrome/common/render_messages.h" |
20 #include "content/common/pepper_plugin_registry.h" | 21 #include "content/common/pepper_plugin_registry.h" |
21 #include "remoting/client/plugin/pepper_entrypoints.h" | 22 #include "remoting/client/plugin/pepper_entrypoints.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
24 #include "webkit/glue/user_agent.h" | 25 #include "webkit/glue/user_agent.h" |
25 #include "webkit/plugins/plugin_constants.h" | 26 #include "webkit/plugins/plugin_constants.h" |
26 | 27 |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 #include "content/common/sandbox_policy.h" | 29 #include "content/common/sandbox_policy.h" |
29 #include "sandbox/src/sandbox.h" | 30 #include "sandbox/src/sandbox.h" |
30 #endif | 31 #endif |
31 | 32 |
32 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
33 #include "chrome/common/render_messages.h" | |
34 #endif | |
35 | |
36 namespace { | 33 namespace { |
37 | 34 |
38 const char kPDFPluginName[] = "Chrome PDF Viewer"; | 35 const char kPDFPluginName[] = "Chrome PDF Viewer"; |
39 const char kPDFPluginMimeType[] = "application/pdf"; | 36 const char kPDFPluginMimeType[] = "application/pdf"; |
40 const char kPDFPluginExtension[] = "pdf"; | 37 const char kPDFPluginExtension[] = "pdf"; |
41 const char kPDFPluginDescription[] = "Portable Document Format"; | 38 const char kPDFPluginDescription[] = "Portable Document Format"; |
42 const char kPDFPluginPrintPreviewMimeType | 39 const char kPDFPluginPrintPreviewMimeType |
43 [] = "application/x-google-chrome-print-preview-pdf"; | 40 [] = "application/x-google-chrome-print-preview-pdf"; |
44 | 41 |
45 const char kNaClPluginName[] = "Native Client"; | 42 const char kNaClPluginName[] = "Native Client"; |
46 const char kNaClPluginMimeType[] = "application/x-nacl"; | 43 const char kNaClPluginMimeType[] = "application/x-nacl"; |
47 const char kNaClPluginExtension[] = "nexe"; | 44 const char kNaClPluginExtension[] = "nexe"; |
48 const char kNaClPluginDescription[] = "Native Client Executable"; | 45 const char kNaClPluginDescription[] = "Native Client Executable"; |
49 | 46 |
50 const char kNaClOldPluginName[] = "Chrome NaCl"; | 47 const char kNaClOldPluginName[] = "Chrome NaCl"; |
51 | 48 |
52 #if defined(ENABLE_REMOTING) | 49 #if defined(ENABLE_REMOTING) |
53 const char kRemotingViewerPluginName[] = "Remoting Viewer"; | 50 const char kRemotingViewerPluginName[] = "Remoting Viewer"; |
54 const FilePath::CharType kRemotingViewerPluginPath[] = | 51 const FilePath::CharType kRemotingViewerPluginPath[] = |
55 FILE_PATH_LITERAL("internal-remoting-viewer"); | 52 FILE_PATH_LITERAL("internal-remoting-viewer"); |
56 // Use a consistent MIME-type regardless of branding. | 53 // Use a consistent MIME-type regardless of branding. |
57 const char kRemotingViewerPluginMimeType[] = | 54 const char kRemotingViewerPluginMimeType[] = |
58 "application/vnd.chromium.remoting-viewer"; | 55 "application/vnd.chromium.remoting-viewer"; |
59 // TODO(wez): Remove the old MIME-type once client code no longer needs it. | 56 // TODO(wez): Remove the old MIME-type once client code no longer needs it. |
60 const char kRemotingViewerPluginOldMimeType[] = | 57 const char kRemotingViewerPluginOldMimeType[] = |
61 "pepper-application/x-chromoting"; | 58 "pepper-application/x-chromoting"; |
62 #endif | 59 #endif |
63 | 60 |
64 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
65 // Appends the known built-in plugins to the given vector. Some built-in | 61 // Appends the known built-in plugins to the given vector. Some built-in |
66 // plugins are "internal" which means they are compiled into the Chrome binary, | 62 // plugins are "internal" which means they are compiled into the Chrome binary, |
67 // and some are extra shared libraries distributed with the browser (these are | 63 // and some are extra shared libraries distributed with the browser (these are |
68 // not marked internal, aside from being automatically registered, they're just | 64 // not marked internal, aside from being automatically registered, they're just |
69 // regular plugins). | 65 // regular plugins). |
70 void ComputeBuiltInPlugins(std::vector<PepperPluginInfo>* plugins) { | 66 void ComputeBuiltInPlugins(std::vector<PepperPluginInfo>* plugins) { |
71 // PDF. | 67 // PDF. |
72 // | 68 // |
73 // Once we're sandboxed, we can't know if the PDF plugin is available or not; | 69 // Once we're sandboxed, we can't know if the PDF plugin is available or not; |
74 // but (on Linux) this function is always called once before we're sandboxed. | 70 // but (on Linux) this function is always called once before we're sandboxed. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 kFlashPluginSwfExtension, | 179 kFlashPluginSwfExtension, |
184 kFlashPluginSwfDescription); | 180 kFlashPluginSwfDescription); |
185 plugin.mime_types.push_back(swf_mime_type); | 181 plugin.mime_types.push_back(swf_mime_type); |
186 webkit::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, | 182 webkit::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, |
187 kFlashPluginSplExtension, | 183 kFlashPluginSplExtension, |
188 kFlashPluginSplDescription); | 184 kFlashPluginSplDescription); |
189 plugin.mime_types.push_back(spl_mime_type); | 185 plugin.mime_types.push_back(spl_mime_type); |
190 plugins->push_back(plugin); | 186 plugins->push_back(plugin); |
191 } | 187 } |
192 | 188 |
193 #endif // !defined(NACL_WIN64) | |
194 | |
195 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
196 // Launches the privileged flash broker, used when flash is sandboxed. | 190 // Launches the privileged flash broker, used when flash is sandboxed. |
197 // The broker is the same flash dll, except that it uses a different | 191 // The broker is the same flash dll, except that it uses a different |
198 // entrypoint (BrokerMain) and it is hosted in windows' generic surrogate | 192 // entrypoint (BrokerMain) and it is hosted in windows' generic surrogate |
199 // process rundll32. After launching the broker we need to pass to | 193 // process rundll32. After launching the broker we need to pass to |
200 // the flash plugin the process id of the broker via the command line | 194 // the flash plugin the process id of the broker via the command line |
201 // using --flash-broker=pid. | 195 // using --flash-broker=pid. |
202 // More info about rundll32 at http://support.microsoft.com/kb/164787. | 196 // More info about rundll32 at http://support.microsoft.com/kb/164787. |
203 bool LoadFlashBroker(const FilePath& plugin_path, CommandLine* cmd_line) { | 197 bool LoadFlashBroker(const FilePath& plugin_path, CommandLine* cmd_line) { |
204 FilePath rundll; | 198 FilePath rundll; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 void ChromeContentClient::SetActiveURL(const GURL& url) { | 263 void ChromeContentClient::SetActiveURL(const GURL& url) { |
270 child_process_logging::SetActiveURL(url); | 264 child_process_logging::SetActiveURL(url); |
271 } | 265 } |
272 | 266 |
273 void ChromeContentClient::SetGpuInfo(const GPUInfo& gpu_info) { | 267 void ChromeContentClient::SetGpuInfo(const GPUInfo& gpu_info) { |
274 child_process_logging::SetGpuInfo(gpu_info); | 268 child_process_logging::SetGpuInfo(gpu_info); |
275 } | 269 } |
276 | 270 |
277 void ChromeContentClient::AddPepperPlugins( | 271 void ChromeContentClient::AddPepperPlugins( |
278 std::vector<PepperPluginInfo>* plugins) { | 272 std::vector<PepperPluginInfo>* plugins) { |
279 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
280 ComputeBuiltInPlugins(plugins); | 273 ComputeBuiltInPlugins(plugins); |
281 AddOutOfProcessFlash(plugins); | 274 AddOutOfProcessFlash(plugins); |
282 #endif | |
283 } | 275 } |
284 | 276 |
285 bool ChromeContentClient::CanSendWhileSwappedOut(const IPC::Message* msg) { | 277 bool ChromeContentClient::CanSendWhileSwappedOut(const IPC::Message* msg) { |
286 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
287 // Any Chrome-specific messages that must be allowed to be sent from swapped | 278 // Any Chrome-specific messages that must be allowed to be sent from swapped |
288 // out renderers. | 279 // out renderers. |
289 switch (msg->type()) { | 280 switch (msg->type()) { |
290 case ChromeViewHostMsg_DomOperationResponse::ID: | 281 case ChromeViewHostMsg_DomOperationResponse::ID: |
291 return true; | 282 return true; |
292 default: | 283 default: |
293 break; | 284 break; |
294 } | 285 } |
295 #endif | |
296 return false; | 286 return false; |
297 } | 287 } |
298 | 288 |
299 bool ChromeContentClient::CanHandleWhileSwappedOut( | 289 bool ChromeContentClient::CanHandleWhileSwappedOut( |
300 const IPC::Message& msg) { | 290 const IPC::Message& msg) { |
301 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
302 // Any Chrome-specific messages (apart from those listed in | 291 // Any Chrome-specific messages (apart from those listed in |
303 // CanSendWhileSwappedOut) that must be handled by the browser when sent from | 292 // CanSendWhileSwappedOut) that must be handled by the browser when sent from |
304 // swapped out renderers. | 293 // swapped out renderers. |
305 switch (msg.type()) { | 294 switch (msg.type()) { |
306 case ChromeViewHostMsg_Snapshot::ID: | 295 case ChromeViewHostMsg_Snapshot::ID: |
307 return true; | 296 return true; |
308 default: | 297 default: |
309 break; | 298 break; |
310 } | 299 } |
311 #endif | |
312 return false; | 300 return false; |
313 } | 301 } |
314 | 302 |
315 std::string ChromeContentClient::GetUserAgent(bool mimic_windows) const { | 303 std::string ChromeContentClient::GetUserAgent(bool mimic_windows) const { |
316 chrome::VersionInfo version_info; | 304 chrome::VersionInfo version_info; |
317 std::string product("Chrome/"); | 305 std::string product("Chrome/"); |
318 product += version_info.is_valid() ? version_info.Version() : "0.0.0.0"; | 306 product += version_info.is_valid() ? version_info.Version() : "0.0.0.0"; |
319 | 307 |
320 return webkit_glue::BuildUserAgentHelper(mimic_windows, product); | 308 return webkit_glue::BuildUserAgentHelper(mimic_windows, product); |
321 } | 309 } |
322 | 310 |
323 string16 ChromeContentClient::GetLocalizedString(int message_id) const { | 311 string16 ChromeContentClient::GetLocalizedString(int message_id) const { |
324 #if defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
325 return string16(); | |
326 #else | |
327 return l10n_util::GetStringUTF16(message_id); | 312 return l10n_util::GetStringUTF16(message_id); |
328 #endif | |
329 } | 313 } |
330 | 314 |
331 base::StringPiece ChromeContentClient::GetDataResource(int resource_id) const { | 315 base::StringPiece ChromeContentClient::GetDataResource(int resource_id) const { |
332 #if defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
333 return base::StringPiece(); | |
334 #else | |
335 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 316 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
336 #endif | |
337 } | 317 } |
338 | 318 |
339 #if defined(OS_WIN) | 319 #if defined(OS_WIN) |
340 bool ChromeContentClient::SandboxPlugin(CommandLine* command_line, | 320 bool ChromeContentClient::SandboxPlugin(CommandLine* command_line, |
341 sandbox::TargetPolicy* policy) { | 321 sandbox::TargetPolicy* policy) { |
342 std::wstring plugin_dll = command_line-> | 322 std::wstring plugin_dll = command_line-> |
343 GetSwitchValueNative(switches::kPluginPath); | 323 GetSwitchValueNative(switches::kPluginPath); |
344 | 324 |
345 FilePath builtin_flash; | 325 FilePath builtin_flash; |
346 if (!PathService::Get(chrome::FILE_FLASH_PLUGIN, &builtin_flash)) | 326 if (!PathService::Get(chrome::FILE_FLASH_PLUGIN, &builtin_flash)) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | 370 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); |
391 policy->SetTokenLevel( | 371 policy->SetTokenLevel( |
392 sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED); | 372 sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED); |
393 } | 373 } |
394 | 374 |
395 return true; | 375 return true; |
396 } | 376 } |
397 #endif | 377 #endif |
398 | 378 |
399 } // namespace chrome | 379 } // namespace chrome |
OLD | NEW |