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/flash_component_installer.h" | 5 #include "chrome/browser/component_updater/flash_component_installer.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/component_updater/component_updater_service.h" | 16 #include "chrome/browser/component_updater/component_updater_service.h" |
16 #include "chrome/browser/plugin_prefs.h" | 17 #include "chrome/browser/plugin_prefs.h" |
17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 20 #include "content/browser/plugin_service.h" |
19 #include "webkit/plugins/npapi/plugin_list.h" | 21 #include "webkit/plugins/npapi/plugin_list.h" |
| 22 #include "webkit/plugins/webplugininfo.h" |
20 | 23 |
21 namespace { | 24 namespace { |
22 | 25 |
23 // CRX hash. The extension id is: immdilkhigodmjbnngapbehchmihabbg. | 26 // CRX hash. The extension id is: immdilkhigodmjbnngapbehchmihabbg. |
24 const uint8 sha2_hash[] = {0x5c, 0x40, 0x30, 0xe3, 0x5d, 0x83, 0x2b, 0xd9, | 27 const uint8 sha2_hash[] = {0x5c, 0x40, 0x30, 0xe3, 0x5d, 0x83, 0x2b, 0xd9, |
25 0x7b, 0xa3, 0x69, 0xae, 0xbc, 0x7c, 0x5e, 0x5a, | 28 0x7b, 0xa3, 0x69, 0xae, 0xbc, 0x7c, 0x5e, 0x5a, |
26 0xef, 0xa5, 0xdf, 0x64, 0x6a, 0xe1, 0xc6, 0xdf, | 29 0xef, 0xa5, 0xdf, 0x64, 0x6a, 0xe1, 0xc6, 0xdf, |
27 0x23, 0x47, 0x30, 0x2a, 0xde, 0xae, 0x9d, 0xf7}; | 30 0x23, 0x47, 0x30, 0x2a, 0xde, 0xae, 0x9d, 0xf7}; |
28 | 31 |
29 // File name of the internal Flash plugin on different platforms. | 32 // File name of the internal Flash plugin on different platforms. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 flash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]); | 129 flash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]); |
127 if (cus->RegisterComponent(flash) != ComponentUpdateService::kOk) { | 130 if (cus->RegisterComponent(flash) != ComponentUpdateService::kOk) { |
128 NOTREACHED() << "Flash component registration fail"; | 131 NOTREACHED() << "Flash component registration fail"; |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 // The code in this function is only concerned about learning what flash plugin | 135 // The code in this function is only concerned about learning what flash plugin |
133 // chrome is using and what is its version. This will determine if we register | 136 // chrome is using and what is its version. This will determine if we register |
134 // for component update or not. Read the comments on RegisterNPAPIFlashComponent | 137 // for component update or not. Read the comments on RegisterNPAPIFlashComponent |
135 // for more background. | 138 // for more background. |
136 void StartFlashUpdateRegistration(ComponentUpdateService* cus) { | 139 void StartFlashUpdateRegistration(ComponentUpdateService* cus, |
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 140 const std::vector<webkit::WebPluginInfo>&) { |
138 | |
139 FilePath builtin_plugin_path; | 141 FilePath builtin_plugin_path; |
140 if (!PathService::Get(chrome::FILE_FLASH_PLUGIN, &builtin_plugin_path)) | 142 if (!PathService::Get(chrome::FILE_FLASH_PLUGIN, &builtin_plugin_path)) |
141 return; | 143 return; |
142 | 144 |
143 FilePath updated_plugin_path = | 145 FilePath updated_plugin_path = |
144 GetNPAPIFlashBaseDirectory().Append(kFlashPluginFileName); | 146 GetNPAPIFlashBaseDirectory().Append(kFlashPluginFileName); |
145 | 147 |
146 webkit::npapi::PluginList* plugins = webkit::npapi::PluginList::Singleton(); | 148 PluginService* plugins = PluginService::GetInstance(); |
147 webkit::WebPluginInfo plugin_info; | 149 webkit::WebPluginInfo plugin_info; |
148 | 150 |
149 if (plugins->GetPluginInfoByPath(updated_plugin_path, &plugin_info)) { | 151 if (plugins->GetPluginInfoByPath(updated_plugin_path, &plugin_info)) { |
150 // The updated plugin is newer. Since flash is used by pretty much every | 152 // The updated plugin is newer. Since flash is used by pretty much every |
151 // webpage out there, odds are it is going to be loaded, which means | 153 // webpage out there, odds are it is going to be loaded, which means |
152 // receiving an update is pointless since we can't swap them. You might | 154 // receiving an update is pointless since we can't swap them. You might |
153 // find this pessimistic. The way we get out of this situation is when | 155 // find this pessimistic. The way we get out of this situation is when |
154 // we update the whole product. | 156 // we update the whole product. |
155 DLOG(INFO) << "updated plugin overriding built-in flash"; | 157 DLOG(INFO) << "updated plugin overriding built-in flash"; |
156 return; | 158 return; |
157 } else if (plugins->GetPluginInfoByPath(builtin_plugin_path, &plugin_info)) { | 159 } else if (plugins->GetPluginInfoByPath(builtin_plugin_path, &plugin_info)) { |
158 // The built plugin is newer. Delete the updated plugin and register for | 160 // The built plugin is newer. Delete the updated plugin and register for |
159 // updates. This should be the normal case. | 161 // updates. This should be the normal case. |
160 file_util::Delete(GetNPAPIFlashBaseDirectory(), true); | 162 file_util::Delete(GetNPAPIFlashBaseDirectory(), true); |
161 } else { | 163 } else { |
162 // Strange installation. Log and abort registration. | 164 // Strange installation. Log and abort registration. |
163 DLOG(WARNING) << "Strange flash npapi configuration"; | 165 DLOG(WARNING) << "Strange flash npapi configuration"; |
164 return; | 166 return; |
165 } | 167 } |
166 | 168 |
167 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 169 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
168 NewRunnableFunction(&FinishFlashUpdateRegistration, cus, plugin_info)); | 170 base::Bind(&FinishFlashUpdateRegistration, cus, plugin_info)); |
169 } | 171 } |
170 | 172 |
171 // Here is the general plan of action: we are going to update flash and we have | 173 // Here is the general plan of action: we are going to update flash and we have |
172 // the following cases: | 174 // the following cases: |
173 // 1- The active flash is not the built-in flash (user override). | 175 // 1- The active flash is not the built-in flash (user override). |
174 // 2- The active flash is the built-in flash. | 176 // 2- The active flash is the built-in flash. |
175 // 3- The active flash is the one from the component updater. | 177 // 3- The active flash is the one from the component updater. |
176 // In case 1 we do nothing. In cases 2 and 3 we need to compare versions | 178 // In case 1 we do nothing. In cases 2 and 3 we need to compare versions |
177 // and if the higher version is: | 179 // and if the higher version is: |
178 // case 2: remove the component update flash, register with component updater. | 180 // case 2: remove the component update flash, register with component updater. |
(...skipping 19 matching lines...) Expand all Loading... |
198 // on the IO thread to learn which one won. Since we do it in a delayed task | 200 // on the IO thread to learn which one won. Since we do it in a delayed task |
199 // probably somebody (unknowingly) will pay for the file IO, so usually get | 201 // probably somebody (unknowingly) will pay for the file IO, so usually get |
200 // the information for free. | 202 // the information for free. |
201 void RegisterNPAPIFlashComponent(ComponentUpdateService* cus) { | 203 void RegisterNPAPIFlashComponent(ComponentUpdateService* cus) { |
202 #if defined(OS_WIN) | 204 #if defined(OS_WIN) |
203 webkit::npapi::PluginList* plugins = webkit::npapi::PluginList::Singleton(); | 205 webkit::npapi::PluginList* plugins = webkit::npapi::PluginList::Singleton(); |
204 FilePath path = GetNPAPIFlashBaseDirectory().Append(kFlashPluginFileName); | 206 FilePath path = GetNPAPIFlashBaseDirectory().Append(kFlashPluginFileName); |
205 plugins->AddExtraPluginPath(path); | 207 plugins->AddExtraPluginPath(path); |
206 plugins->RefreshPlugins(); | 208 plugins->RefreshPlugins(); |
207 | 209 |
208 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, | 210 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
209 NewRunnableFunction(&StartFlashUpdateRegistration, cus), 8000); | 211 base::Bind(&PluginService::GetPlugins, |
| 212 base::Unretained(PluginService::GetInstance()), |
| 213 base::Bind(&StartFlashUpdateRegistration, cus)), |
| 214 8000); |
210 #endif | 215 #endif |
211 } | 216 } |
OLD | NEW |