OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/string_split.h" | 18 #include "base/string_split.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
| 21 #include "base/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "base/version.h" | 23 #include "base/version.h" |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "chrome/browser/component_updater/component_updater_service.h" | 25 #include "chrome/browser/component_updater/component_updater_service.h" |
25 #include "chrome/browser/plugins/plugin_prefs.h" | 26 #include "chrome/browser/plugins/plugin_prefs.h" |
26 #include "chrome/common/pepper_flash.h" | 27 #include "chrome/common/pepper_flash.h" |
27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/pepper_flash.h" | 30 #include "chrome/common/pepper_flash.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 kFlashPluginSwfExtension, | 157 kFlashPluginSwfExtension, |
157 kFlashPluginName); | 158 kFlashPluginName); |
158 plugin_info->mime_types.push_back(swf_mime_type); | 159 plugin_info->mime_types.push_back(swf_mime_type); |
159 webkit::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, | 160 webkit::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, |
160 kFlashPluginSplExtension, | 161 kFlashPluginSplExtension, |
161 kFlashPluginName); | 162 kFlashPluginName); |
162 plugin_info->mime_types.push_back(spl_mime_type); | 163 plugin_info->mime_types.push_back(spl_mime_type); |
163 return true; | 164 return true; |
164 } | 165 } |
165 | 166 |
| 167 bool IsPepperFlash(const webkit::WebPluginInfo& plugin) { |
| 168 // We try to recognize Pepper Flash by the following criteria: |
| 169 // * It is a Pepper plug-in. |
| 170 // * It has the special Flash permissions. |
| 171 return webkit::IsPepperPlugin(plugin) && |
| 172 (plugin.pepper_permissions & ppapi::PERMISSION_FLASH); |
| 173 } |
| 174 |
166 void RegisterPepperFlashWithChrome(const FilePath& path, | 175 void RegisterPepperFlashWithChrome(const FilePath& path, |
167 const Version& version) { | 176 const Version& version) { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
169 content::PepperPluginInfo plugin_info; | 178 content::PepperPluginInfo plugin_info; |
170 if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info)) | 179 if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info)) |
171 return; | 180 return; |
| 181 |
| 182 std::vector<webkit::WebPluginInfo> plugins; |
| 183 PluginService::GetInstance()->GetInternalPlugins(&plugins); |
| 184 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
| 185 it != plugins.end(); ++it) { |
| 186 if (!IsPepperFlash(*it)) |
| 187 continue; |
| 188 |
| 189 // If the version we're trying to register is older than the existing one, |
| 190 // don't do it. |
| 191 if (version.IsOlderThan(UTF16ToUTF8(it->version))) |
| 192 return; |
| 193 |
| 194 // If the version is newer, remove the old one first. |
| 195 PluginService::GetInstance()->UnregisterInternalPlugin(it->path); |
| 196 break; |
| 197 } |
| 198 |
172 bool add_to_front = IsPepperFlashEnabledByDefault(); | 199 bool add_to_front = IsPepperFlashEnabledByDefault(); |
173 PluginService::GetInstance()->RegisterInternalPlugin( | 200 PluginService::GetInstance()->RegisterInternalPlugin( |
174 plugin_info.ToWebPluginInfo(), add_to_front); | 201 plugin_info.ToWebPluginInfo(), add_to_front); |
175 PluginService::GetInstance()->RefreshPlugins(); | 202 PluginService::GetInstance()->RefreshPlugins(); |
176 } | 203 } |
177 | 204 |
178 // Returns true if this browser implements one of the interfaces given in | 205 // Returns true if this browser implements one of the interfaces given in |
179 // |interface_string|, which is a '|'-separated string of interface names. | 206 // |interface_string|, which is a '|'-separated string of interface names. |
180 bool CheckPepperFlashInterfaceString(const std::string& interface_string) { | 207 bool CheckPepperFlashInterfaceString(const std::string& interface_string) { |
181 std::vector<std::string> interface_names; | 208 std::vector<std::string> interface_names; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 #endif // defined(GOOGLE_CHROME_BUILD) | 379 #endif // defined(GOOGLE_CHROME_BUILD) |
353 | 380 |
354 } // namespace | 381 } // namespace |
355 | 382 |
356 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { | 383 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { |
357 #if defined(GOOGLE_CHROME_BUILD) | 384 #if defined(GOOGLE_CHROME_BUILD) |
358 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 385 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
359 base::Bind(&StartPepperFlashUpdateRegistration, cus)); | 386 base::Bind(&StartPepperFlashUpdateRegistration, cus)); |
360 #endif | 387 #endif |
361 } | 388 } |
OLD | NEW |