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" | |
8 #include "base/file_util.h" | |
9 #include "base/path_service.h" | |
10 #include "base/string_split.h" | |
11 #include "base/string_util.h" | |
7 #include "chrome/common/child_process_logging.h" | 12 #include "chrome/common/child_process_logging.h" |
13 #include "chrome/common/chrome_paths.h" | |
14 #include "chrome/common/chrome_switches.h" | |
15 #include "content/common/pepper_plugin_registry.h" | |
16 #include "remoting/client/plugin/pepper_entrypoints.h" | |
17 | |
18 namespace { | |
brettw
2011/04/18 05:02:12
Blank line after this.
| |
19 const char* kPDFPluginName = "Chrome PDF Viewer"; | |
20 const char* kPDFPluginMimeType = "application/pdf"; | |
21 const char* kPDFPluginExtension = "pdf"; | |
22 const char* kPDFPluginDescription = "Portable Document Format"; | |
23 | |
24 const char* kNaClPluginName = "Chrome NaCl"; | |
25 const char* kNaClPluginMimeType = "application/x-nacl"; | |
26 const char* kNaClPluginExtension = "nexe"; | |
27 const char* kNaClPluginDescription = "Native Client Executable"; | |
28 | |
29 #if defined(ENABLE_REMOTING) | |
30 const char* kRemotingPluginMimeType = "pepper-application/x-chromoting"; | |
31 #endif | |
32 | |
33 const char* kFlashPluginName = "Shockwave Flash"; | |
34 const char* kFlashPluginSwfMimeType = "application/x-shockwave-flash"; | |
35 const char* kFlashPluginSwfExtension = "swf"; | |
36 const char* kFlashPluginSwfDescription = "Shockwave Flash"; | |
37 const char* kFlashPluginSplMimeType = "application/futuresplash"; | |
38 const char* kFlashPluginSplExtension = "spl"; | |
39 const char* kFlashPluginSplDescription = "FutureSplash Player"; | |
40 | |
41 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
42 | |
43 // Appends the known built-in plugins to the given vector. Some built-in | |
44 // plugins are "internal" which means they are compiled into the Chrome binary, | |
45 // and some are extra shared libraries distributed with the browser (these are | |
46 // not marked internal, aside from being automatically registered, they're just | |
47 // regular plugins). | |
48 void ComputeBuiltInPlugins(std::vector<PepperPluginInfo>* plugins) { | |
49 // PDF. | |
50 // | |
51 // Once we're sandboxed, we can't know if the PDF plugin is available or not; | |
52 // but (on Linux) this function is always called once before we're sandboxed. | |
53 // So the first time through test if the file is available and then skip the | |
54 // check on subsequent calls if yes. | |
55 static bool skip_pdf_file_check = false; | |
56 FilePath path; | |
57 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path)) { | |
58 if (skip_pdf_file_check || file_util::PathExists(path)) { | |
59 PepperPluginInfo pdf; | |
60 pdf.path = path; | |
61 pdf.name = kPDFPluginName; | |
62 webkit::npapi::WebPluginMimeType pdf_mime_type(kPDFPluginMimeType, | |
63 kPDFPluginExtension, | |
64 kPDFPluginDescription); | |
65 pdf.mime_types.push_back(pdf_mime_type); | |
66 plugins->push_back(pdf); | |
67 | |
68 skip_pdf_file_check = true; | |
69 } | |
70 } | |
71 | |
72 // Handle the Native Client plugin just like the PDF plugin. | |
73 static bool skip_nacl_file_check = false; | |
74 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { | |
75 if (skip_nacl_file_check || file_util::PathExists(path)) { | |
76 PepperPluginInfo nacl; | |
77 nacl.path = path; | |
78 nacl.name = kNaClPluginName; | |
79 // Enable the Native Client Plugin based on the command line. | |
80 nacl.enabled = CommandLine::ForCurrentProcess()->HasSwitch( | |
81 switches::kEnableNaCl); | |
82 webkit::npapi::WebPluginMimeType nacl_mime_type(kNaClPluginMimeType, | |
83 kNaClPluginExtension, | |
84 kNaClPluginDescription); | |
85 nacl.mime_types.push_back(nacl_mime_type); | |
86 plugins->push_back(nacl); | |
87 | |
88 skip_nacl_file_check = true; | |
89 } | |
90 } | |
91 | |
92 // Remoting. | |
93 #if defined(ENABLE_REMOTING) | |
94 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
95 switches::kEnableRemoting)) { | |
96 PepperPluginInfo info; | |
97 info.is_internal = true; | |
98 info.path = FilePath(FILE_PATH_LITERAL("internal-chromoting")); | |
99 webkit::npapi::WebPluginMimeType remoting_mime_type(kRemotingPluginMimeType, | |
100 std::string(), | |
101 std::string()); | |
102 info.mime_types.push_back(remoting_mime_type); | |
103 info.internal_entry_points.get_interface = remoting::PPP_GetInterface; | |
104 info.internal_entry_points.initialize_module = | |
105 remoting::PPP_InitializeModule; | |
106 info.internal_entry_points.shutdown_module = remoting::PPP_ShutdownModule; | |
107 | |
108 plugins->push_back(info); | |
109 } | |
110 #endif | |
111 } | |
112 | |
113 void AddOutOfProcessFlash(std::vector<PepperPluginInfo>* plugins) { | |
114 // Flash being out of process is handled separately than general plugins | |
115 // for testing purposes. | |
116 bool flash_out_of_process = !CommandLine::ForCurrentProcess()->HasSwitch( | |
117 switches::kPpapiFlashInProcess); | |
118 | |
119 // Handle any Pepper Flash first. | |
120 const CommandLine::StringType flash_path = | |
121 CommandLine::ForCurrentProcess()->GetSwitchValueNative( | |
122 switches::kPpapiFlashPath); | |
123 if (flash_path.empty()) | |
124 return; | |
125 | |
126 PepperPluginInfo plugin; | |
127 plugin.is_out_of_process = flash_out_of_process; | |
128 plugin.path = FilePath(flash_path); | |
129 plugin.name = kFlashPluginName; | |
130 | |
131 const std::string flash_version = | |
132 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
133 switches::kPpapiFlashVersion); | |
134 std::vector<std::string> flash_version_numbers; | |
135 base::SplitString(flash_version, '.', &flash_version_numbers); | |
136 if (flash_version_numbers.size() < 1) | |
137 flash_version_numbers.push_back("10"); | |
138 // |SplitString()| puts in an empty string given an empty string. :( | |
139 else if (flash_version_numbers[0].empty()) | |
140 flash_version_numbers[0] = "10"; | |
141 if (flash_version_numbers.size() < 2) | |
142 flash_version_numbers.push_back("2"); | |
143 if (flash_version_numbers.size() < 3) | |
144 flash_version_numbers.push_back("999"); | |
145 if (flash_version_numbers.size() < 4) | |
146 flash_version_numbers.push_back("999"); | |
147 // E.g., "Shockwave Flash 10.2 r154": | |
148 plugin.description = plugin.name + " " + flash_version_numbers[0] + "." + | |
149 flash_version_numbers[1] + " r" + flash_version_numbers[2]; | |
150 plugin.version = JoinString(flash_version_numbers, '.'); | |
151 webkit::npapi::WebPluginMimeType swf_mime_type(kFlashPluginSwfMimeType, | |
152 kFlashPluginSwfExtension, | |
153 kFlashPluginSwfDescription); | |
154 plugin.mime_types.push_back(swf_mime_type); | |
155 webkit::npapi::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, | |
156 kFlashPluginSplExtension, | |
157 kFlashPluginSplDescription); | |
158 plugin.mime_types.push_back(spl_mime_type); | |
159 plugins->push_back(plugin); | |
160 } | |
161 | |
162 #endif // !defined(NACL_WIN64) | |
163 | |
164 } // namespace | |
8 | 165 |
9 namespace chrome { | 166 namespace chrome { |
10 | 167 |
168 const char* ChromeContentClient::kPDFPluginName = ::kPDFPluginName; | |
169 | |
11 void ChromeContentClient::SetActiveURL(const GURL& url) { | 170 void ChromeContentClient::SetActiveURL(const GURL& url) { |
12 child_process_logging::SetActiveURL(url); | 171 child_process_logging::SetActiveURL(url); |
13 } | 172 } |
14 | 173 |
15 void ChromeContentClient::SetGpuInfo(const GPUInfo& gpu_info) { | 174 void ChromeContentClient::SetGpuInfo(const GPUInfo& gpu_info) { |
16 child_process_logging::SetGpuInfo(gpu_info); | 175 child_process_logging::SetGpuInfo(gpu_info); |
17 } | 176 } |
18 | 177 |
178 void ChromeContentClient::AddPepperPlugins( | |
179 std::vector<PepperPluginInfo>* plugins) { | |
180 #if !defined(NACL_WIN64) // The code this needs isn't linked on Win64 builds. | |
181 ComputeBuiltInPlugins(plugins); | |
182 AddOutOfProcessFlash(plugins); | |
183 #endif | |
184 } | |
185 | |
19 } // namespace chrome | 186 } // namespace chrome |
OLD | NEW |