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/browser/component_updater/pepper_flash_component_installer.h" | 5 #include "chrome/browser/component_updater/pepper_flash_component_installer.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_util.h" | |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/component_updater/component_updater_service.h" | 15 #include "chrome/browser/component_updater/component_updater_service.h" |
15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
16 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
18 #include "content/common/pepper_plugin_registry.h" | |
19 #include "webkit/plugins/npapi/plugin_list.h" | |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. | 23 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. |
21 const uint8 sha2_hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, | 24 const uint8 sha2_hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, |
22 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, | 25 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, |
23 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, | 26 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, |
24 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; | 27 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; |
25 | 28 |
26 // File name of the Pepper Flash plugin on different platforms. | 29 // File name of the Pepper Flash plugin on different platforms. |
27 const FilePath::CharType kPepperFlashPluginFileName[] = | 30 const FilePath::CharType kPepperFlashPluginFileName[] = |
28 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
29 FILE_PATH_LITERAL("PepperFlashPlayer.plugin"); | 32 FILE_PATH_LITERAL("PepperFlashPlayer.plugin"); |
30 #elif defined(OS_WIN) | 33 #elif defined(OS_WIN) |
31 FILE_PATH_LITERAL("pepflashplayer.dll"); | 34 FILE_PATH_LITERAL("pepflashplayer.dll"); |
32 #else // OS_LINUX, etc. | 35 #else // OS_LINUX, etc. |
33 FILE_PATH_LITERAL("libpepflashplayer.so"); | 36 FILE_PATH_LITERAL("libpepflashplayer.so"); |
34 #endif | 37 #endif |
35 | 38 |
36 // File name of the Pepper Flash component manifest on different platforms. | 39 // File name of the Pepper Flash component manifest on different platforms. |
37 const char kPepperFlashManifestName[] = | 40 const char kPepperFlashManifestName[] = |
38 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
39 "MacFlapper"; | 42 "MacFlapper"; |
40 #elif defined(OS_WIN) | 43 #elif defined(OS_WIN) |
41 "WinFlapper"; | 44 "WinFlapper"; |
42 #else // OS_LINUX, etc. | 45 #else // OS_LINUX, etc. |
43 "NixFlapper"; | 46 "NixFlapper"; |
44 #endif | 47 #endif |
45 | 48 |
49 const char* kFlashPluginName = "Shockwave Flash"; | |
50 const char* kFlashPluginSwfMimeType = "application/x-shockwave-flash"; | |
51 const char* kFlashPluginSwfExtension = "swf"; | |
52 const char* kFlashPluginSplMimeType = "application/futuresplash"; | |
53 const char* kFlashPluginSplExtension = "spl"; | |
54 const char* kFlashPluginSplDescription = "FutureSplash Player"; | |
55 | |
46 // The pepper flash plugins are in a directory with this name. | 56 // The pepper flash plugins are in a directory with this name. |
47 const FilePath::CharType kPepperFlashBaseDirectory[] = | 57 const FilePath::CharType kPepperFlashBaseDirectory[] = |
48 FILE_PATH_LITERAL("PepperFlash"); | 58 FILE_PATH_LITERAL("PepperFlash"); |
49 | 59 |
50 // If we don't have a flash pepper component, this is the version we claim. | 60 // If we don't have a flash pepper component, this is the version we claim. |
51 const char kNullVersion[] = "0.0.0.0"; | 61 const char kNullVersion[] = "0.0.0.0"; |
52 | 62 |
53 // The base directory on windows looks like: | 63 // The base directory on windows looks like: |
54 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. | 64 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. |
55 FilePath GetPepperFlashBaseDirectory() { | 65 FilePath GetPepperFlashBaseDirectory() { |
(...skipping 20 matching lines...) Expand all Loading... | |
76 *latest = version; | 86 *latest = version; |
77 *result = path; | 87 *result = path; |
78 found = true; | 88 found = true; |
79 } | 89 } |
80 } | 90 } |
81 return found; | 91 return found; |
82 } | 92 } |
83 | 93 |
84 } // namespace | 94 } // namespace |
85 | 95 |
96 bool MakePepperFlashPluginInfo(const FilePath& flash_path, | |
97 const Version& flash_version, | |
98 bool out_of_process, | |
99 bool enabled, | |
100 PepperPluginInfo* plugin_info) { | |
101 if (!flash_version.IsValid()) | |
102 return false; | |
103 const std::vector<uint16> ver_nums = flash_version.components(); | |
104 if (ver_nums.size() < 3) | |
105 return false; | |
106 | |
107 plugin_info->is_internal = false; | |
108 plugin_info->is_out_of_process = out_of_process; | |
109 plugin_info->path = flash_path; | |
110 plugin_info->name = kFlashPluginName; | |
111 plugin_info->enabled = enabled; | |
112 | |
113 // The description is like "Shockwave Flash (pepper) 10.2 r154". | |
brettw
2011/08/16 23:28:05
I think this comment shouldn't have "(pepper)" in
| |
114 plugin_info->description = StringPrintf("%s %d.%d r%d", | |
115 kFlashPluginName, ver_nums[0], ver_nums[1], ver_nums[2]); | |
116 | |
117 plugin_info->version = flash_version.GetString(); | |
118 | |
119 webkit::WebPluginMimeType swf_mime_type(kFlashPluginSwfMimeType, | |
120 kFlashPluginSwfExtension, | |
121 kFlashPluginName); | |
122 plugin_info->mime_types.push_back(swf_mime_type); | |
123 webkit::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, | |
124 kFlashPluginSplExtension, | |
125 kFlashPluginName); | |
126 plugin_info->mime_types.push_back(spl_mime_type); | |
127 return true; | |
128 } | |
129 | |
130 void RegisterPepperFlashWithChrome(const FilePath& path, | |
131 const Version& version) { | |
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
133 PepperPluginInfo plugin_info; | |
134 // Register it as out-of-process and disabled. | |
135 if (!MakePepperFlashPluginInfo(path, version, true, false, &plugin_info)) | |
136 return; | |
137 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( | |
138 plugin_info.ToWebPluginInfo()); | |
139 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | |
140 } | |
141 | |
86 class PepperFlashComponentInstaller : public ComponentInstaller { | 142 class PepperFlashComponentInstaller : public ComponentInstaller { |
87 public: | 143 public: |
88 explicit PepperFlashComponentInstaller(const Version& version); | 144 explicit PepperFlashComponentInstaller(const Version& version); |
89 | 145 |
90 virtual ~PepperFlashComponentInstaller() {} | 146 virtual ~PepperFlashComponentInstaller() {} |
91 | 147 |
92 virtual void OnUpdateError(int error) OVERRIDE; | 148 virtual void OnUpdateError(int error) OVERRIDE; |
93 | 149 |
94 virtual bool Install(base::DictionaryValue* manifest, | 150 virtual bool Install(base::DictionaryValue* manifest, |
95 const FilePath& unpack_path) OVERRIDE; | 151 const FilePath& unpack_path) OVERRIDE; |
(...skipping 26 matching lines...) Expand all Loading... | |
122 return false; | 178 return false; |
123 if (!file_util::PathExists(unpack_path.Append(kPepperFlashPluginFileName))) | 179 if (!file_util::PathExists(unpack_path.Append(kPepperFlashPluginFileName))) |
124 return false; | 180 return false; |
125 // Passed the basic tests. Time to install it. | 181 // Passed the basic tests. Time to install it. |
126 FilePath path = | 182 FilePath path = |
127 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); | 183 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); |
128 if (file_util::PathExists(path)) | 184 if (file_util::PathExists(path)) |
129 return false; | 185 return false; |
130 if (!file_util::Move(unpack_path, path)) | 186 if (!file_util::Move(unpack_path, path)) |
131 return false; | 187 return false; |
132 // Installation is done. Now update the path service. | 188 // Installation is done. Now tell the rest of chrome. Both the path service |
189 // and to the plugin service. | |
133 current_version_ = version; | 190 current_version_ = version; |
134 path = path.Append(kPepperFlashPluginFileName); | 191 path = path.Append(kPepperFlashPluginFileName); |
135 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path); | 192 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path); |
193 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
194 NewRunnableFunction(&RegisterPepperFlashWithChrome, path, version)); | |
136 return true; | 195 return true; |
137 } | 196 } |
138 | 197 |
139 void FinishPepperFlashRegistration(ComponentUpdateService* cus, | 198 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, |
140 const Version& version) { | 199 const Version& version) { |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
142 CrxComponent pepflash; | 201 CrxComponent pepflash; |
143 pepflash.name = "pepper_flash"; | 202 pepflash.name = "pepper_flash"; |
144 pepflash.installer = new PepperFlashComponentInstaller(version); | 203 pepflash.installer = new PepperFlashComponentInstaller(version); |
145 pepflash.version = version; | 204 pepflash.version = version; |
146 pepflash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]); | 205 pepflash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]); |
147 if (cus->RegisterComponent(pepflash) != ComponentUpdateService::kOk) { | 206 if (cus->RegisterComponent(pepflash) != ComponentUpdateService::kOk) { |
148 NOTREACHED() << "pepper flash component registration fail"; | 207 NOTREACHED() << "pepper flash component registration fail"; |
149 } | 208 } |
150 } | 209 } |
151 | 210 |
152 void StartPepperFlashRegistration(ComponentUpdateService* cus) { | 211 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { |
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
154 FilePath path = GetPepperFlashBaseDirectory(); | 213 FilePath path = GetPepperFlashBaseDirectory(); |
155 if (!file_util::PathExists(path)) { | 214 if (!file_util::PathExists(path)) { |
156 if (!file_util::CreateDirectory(path)) { | 215 if (!file_util::CreateDirectory(path)) { |
157 NOTREACHED() << "cannot create pepper flash directory"; | 216 NOTREACHED() << "cannot create pepper flash directory"; |
158 return; | 217 return; |
159 } | 218 } |
160 } | 219 } |
161 | 220 |
162 Version version(kNullVersion); | 221 Version version(kNullVersion); |
163 if (GetLatestPepperFlashDirectory(&path, &version)) { | 222 if (GetLatestPepperFlashDirectory(&path, &version)) { |
164 path = path.Append(kPepperFlashPluginFileName); | 223 path = path.Append(kPepperFlashPluginFileName); |
165 if (file_util::PathExists(path)) | 224 if (file_util::PathExists(path)) { |
166 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path); | 225 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
167 else | 226 NewRunnableFunction(&RegisterPepperFlashWithChrome, path, version)); |
227 } else { | |
168 version = Version(kNullVersion); | 228 version = Version(kNullVersion); |
229 } | |
169 } | 230 } |
170 | 231 |
171 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 232 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
172 NewRunnableFunction(&FinishPepperFlashRegistration, cus, version)); | 233 NewRunnableFunction(&FinishPepperFlashUpdateRegistration, cus, version)); |
173 } | 234 } |
174 | 235 |
175 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { | 236 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { |
176 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 237 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
177 // TODO(cpu): support Mac and Linux flash pepper. | 238 // TODO(cpu): support Mac and Linux flash pepper. |
178 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 239 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
179 NewRunnableFunction(&StartPepperFlashRegistration, cus)); | 240 NewRunnableFunction(&StartPepperFlashUpdateRegistration, cus)); |
180 #endif | 241 #endif |
181 } | 242 } |
OLD | NEW |