Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/component_updater/pepper_flash_component_installer.cc

Issue 7670003: Wire experimental Flapper part two (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
46 // The pepper flash plugins are in a directory with this name. 55 // The pepper flash plugins are in a directory with this name.
47 const FilePath::CharType kPepperFlashBaseDirectory[] = 56 const FilePath::CharType kPepperFlashBaseDirectory[] =
48 FILE_PATH_LITERAL("PepperFlash"); 57 FILE_PATH_LITERAL("PepperFlash");
49 58
50 // If we don't have a flash pepper component, this is the version we claim. 59 // If we don't have a flash pepper component, this is the version we claim.
51 const char kNullVersion[] = "0.0.0.0"; 60 const char kNullVersion[] = "0.0.0.0";
52 61
53 // The base directory on windows looks like: 62 // The base directory on windows looks like:
54 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. 63 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\.
55 FilePath GetPepperFlashBaseDirectory() { 64 FilePath GetPepperFlashBaseDirectory() {
(...skipping 20 matching lines...) Expand all
76 *latest = version; 85 *latest = version;
77 *result = path; 86 *result = path;
78 found = true; 87 found = true;
79 } 88 }
80 } 89 }
81 return found; 90 return found;
82 } 91 }
83 92
84 } // namespace 93 } // namespace
85 94
95 bool MakePepperFlashPluginInfo(const FilePath& flash_path,
96 const Version& flash_version,
97 bool out_of_process,
98 bool enabled,
99 PepperPluginInfo* plugin_info) {
100 if (!flash_version.IsValid())
101 return false;
102 const std::vector<uint16> ver_nums = flash_version.components();
103 if (ver_nums.size() < 3)
104 return false;
105
106 plugin_info->is_internal = false;
107 plugin_info->is_out_of_process = out_of_process;
108 plugin_info->path = flash_path;
109 plugin_info->name = kFlashPluginName;
110 plugin_info->enabled = enabled;
111
112 // The description is like "Shockwave Flash 10.2 r154".
113 plugin_info->description = StringPrintf("%s %d.%d r%d",
114 kFlashPluginName, ver_nums[0], ver_nums[1], ver_nums[2]);
115
116 plugin_info->version = flash_version.GetString();
117
118 webkit::WebPluginMimeType swf_mime_type(kFlashPluginSwfMimeType,
119 kFlashPluginSwfExtension,
120 kFlashPluginName);
121 plugin_info->mime_types.push_back(swf_mime_type);
122 webkit::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType,
123 kFlashPluginSplExtension,
124 kFlashPluginName);
125 plugin_info->mime_types.push_back(spl_mime_type);
126 return true;
127 }
128
129 void RegisterPepperFlashWithChrome(const FilePath& path,
130 const Version& version) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
132 PepperPluginInfo plugin_info;
133 // Register it as out-of-process and disabled.
134 if (!MakePepperFlashPluginInfo(path, version, true, false, &plugin_info))
135 return;
136 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(
137 plugin_info.ToWebPluginInfo());
138 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
139 }
140
86 class PepperFlashComponentInstaller : public ComponentInstaller { 141 class PepperFlashComponentInstaller : public ComponentInstaller {
87 public: 142 public:
88 explicit PepperFlashComponentInstaller(const Version& version); 143 explicit PepperFlashComponentInstaller(const Version& version);
89 144
90 virtual ~PepperFlashComponentInstaller() {} 145 virtual ~PepperFlashComponentInstaller() {}
91 146
92 virtual void OnUpdateError(int error) OVERRIDE; 147 virtual void OnUpdateError(int error) OVERRIDE;
93 148
94 virtual bool Install(base::DictionaryValue* manifest, 149 virtual bool Install(base::DictionaryValue* manifest,
95 const FilePath& unpack_path) OVERRIDE; 150 const FilePath& unpack_path) OVERRIDE;
(...skipping 26 matching lines...) Expand all
122 return false; 177 return false;
123 if (!file_util::PathExists(unpack_path.Append(kPepperFlashPluginFileName))) 178 if (!file_util::PathExists(unpack_path.Append(kPepperFlashPluginFileName)))
124 return false; 179 return false;
125 // Passed the basic tests. Time to install it. 180 // Passed the basic tests. Time to install it.
126 FilePath path = 181 FilePath path =
127 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); 182 GetPepperFlashBaseDirectory().AppendASCII(version.GetString());
128 if (file_util::PathExists(path)) 183 if (file_util::PathExists(path))
129 return false; 184 return false;
130 if (!file_util::Move(unpack_path, path)) 185 if (!file_util::Move(unpack_path, path))
131 return false; 186 return false;
132 // Installation is done. Now update the path service. 187 // Installation is done. Now tell the rest of chrome. Both the path service
188 // and to the plugin service.
133 current_version_ = version; 189 current_version_ = version;
134 path = path.Append(kPepperFlashPluginFileName); 190 path = path.Append(kPepperFlashPluginFileName);
135 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path); 191 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path);
192 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
193 NewRunnableFunction(&RegisterPepperFlashWithChrome, path, version));
136 return true; 194 return true;
137 } 195 }
138 196
139 void FinishPepperFlashRegistration(ComponentUpdateService* cus, 197 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus,
140 const Version& version) { 198 const Version& version) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142 CrxComponent pepflash; 200 CrxComponent pepflash;
143 pepflash.name = "pepper_flash"; 201 pepflash.name = "pepper_flash";
144 pepflash.installer = new PepperFlashComponentInstaller(version); 202 pepflash.installer = new PepperFlashComponentInstaller(version);
145 pepflash.version = version; 203 pepflash.version = version;
146 pepflash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]); 204 pepflash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]);
147 if (cus->RegisterComponent(pepflash) != ComponentUpdateService::kOk) { 205 if (cus->RegisterComponent(pepflash) != ComponentUpdateService::kOk) {
148 NOTREACHED() << "pepper flash component registration fail"; 206 NOTREACHED() << "pepper flash component registration fail";
149 } 207 }
150 } 208 }
151 209
152 void StartPepperFlashRegistration(ComponentUpdateService* cus) { 210 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
154 FilePath path = GetPepperFlashBaseDirectory(); 212 FilePath path = GetPepperFlashBaseDirectory();
155 if (!file_util::PathExists(path)) { 213 if (!file_util::PathExists(path)) {
156 if (!file_util::CreateDirectory(path)) { 214 if (!file_util::CreateDirectory(path)) {
157 NOTREACHED() << "cannot create pepper flash directory"; 215 NOTREACHED() << "cannot create pepper flash directory";
158 return; 216 return;
159 } 217 }
160 } 218 }
161 219
162 Version version(kNullVersion); 220 Version version(kNullVersion);
163 if (GetLatestPepperFlashDirectory(&path, &version)) { 221 if (GetLatestPepperFlashDirectory(&path, &version)) {
164 path = path.Append(kPepperFlashPluginFileName); 222 path = path.Append(kPepperFlashPluginFileName);
165 if (file_util::PathExists(path)) 223 if (file_util::PathExists(path)) {
166 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path); 224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
167 else 225 NewRunnableFunction(&RegisterPepperFlashWithChrome, path, version));
226 } else {
168 version = Version(kNullVersion); 227 version = Version(kNullVersion);
228 }
169 } 229 }
170 230
171 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 231 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
172 NewRunnableFunction(&FinishPepperFlashRegistration, cus, version)); 232 NewRunnableFunction(&FinishPepperFlashUpdateRegistration, cus, version));
173 } 233 }
174 234
175 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { 235 void RegisterPepperFlashComponent(ComponentUpdateService* cus) {
176 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) 236 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
177 // TODO(cpu): support Mac and Linux flash pepper. 237 // TODO(cpu): support Mac and Linux flash pepper.
178 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 238 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
179 NewRunnableFunction(&StartPepperFlashRegistration, cus)); 239 NewRunnableFunction(&StartPepperFlashUpdateRegistration, cus));
180 #endif 240 #endif
181 } 241 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698