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/pepper_flash_settings_manager.h" | 5 #include "chrome/browser/pepper_flash_settings_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 using content::BrowserThread; | 30 using content::BrowserThread; |
31 | 31 |
32 class PepperFlashSettingsManager::Core | 32 class PepperFlashSettingsManager::Core |
33 : public IPC::Listener, | 33 : public IPC::Listener, |
34 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> { | 34 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> { |
35 public: | 35 public: |
36 Core(PepperFlashSettingsManager* manager, | 36 Core(PepperFlashSettingsManager* manager, |
37 content::BrowserContext* browser_context); | 37 content::BrowserContext* browser_context); |
38 | 38 |
| 39 void Initialize(); |
39 // Stops sending notifications to |manager_| and sets it to NULL. | 40 // Stops sending notifications to |manager_| and sets it to NULL. |
40 void Detach(); | 41 void Detach(); |
41 | 42 |
42 void DeauthorizeContentLicenses(uint32 request_id); | 43 void DeauthorizeContentLicenses(uint32 request_id); |
43 void GetPermissionSettings( | 44 void GetPermissionSettings( |
44 uint32 request_id, | 45 uint32 request_id, |
45 PP_Flash_BrowserOperations_SettingType setting_type); | 46 PP_Flash_BrowserOperations_SettingType setting_type); |
46 void SetDefaultPermission( | 47 void SetDefaultPermission( |
47 uint32 request_id, | 48 uint32 request_id, |
48 PP_Flash_BrowserOperations_SettingType setting_type, | 49 PP_Flash_BrowserOperations_SettingType setting_type, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // Used by SET_DEFAULT_PERMISSION. | 88 // Used by SET_DEFAULT_PERMISSION. |
88 PP_Flash_BrowserOperations_Permission permission; | 89 PP_Flash_BrowserOperations_Permission permission; |
89 bool clear_site_specific; | 90 bool clear_site_specific; |
90 | 91 |
91 // Used by SET_SITE_PERMISSION. | 92 // Used by SET_SITE_PERMISSION. |
92 ppapi::FlashSiteSettings sites; | 93 ppapi::FlashSiteSettings sites; |
93 }; | 94 }; |
94 | 95 |
95 virtual ~Core(); | 96 virtual ~Core(); |
96 | 97 |
97 void Initialize(); | |
98 void ConnectToChannel(bool success, const IPC::ChannelHandle& handle); | 98 void ConnectToChannel(bool success, const IPC::ChannelHandle& handle); |
99 | 99 |
| 100 void InitializeOnIOThread(); |
100 void DeauthorizeContentLicensesOnIOThread(uint32 request_id); | 101 void DeauthorizeContentLicensesOnIOThread(uint32 request_id); |
101 void GetPermissionSettingsOnIOThread( | 102 void GetPermissionSettingsOnIOThread( |
102 uint32 request_id, | 103 uint32 request_id, |
103 PP_Flash_BrowserOperations_SettingType setting_type); | 104 PP_Flash_BrowserOperations_SettingType setting_type); |
104 void SetDefaultPermissionOnIOThread( | 105 void SetDefaultPermissionOnIOThread( |
105 uint32 request_id, | 106 uint32 request_id, |
106 PP_Flash_BrowserOperations_SettingType setting_type, | 107 PP_Flash_BrowserOperations_SettingType setting_type, |
107 PP_Flash_BrowserOperations_Permission permission, | 108 PP_Flash_BrowserOperations_Permission permission, |
108 bool clear_site_specific); | 109 bool clear_site_specific); |
109 void SetSitePermissionOnIOThread( | 110 void SetSitePermissionOnIOThread( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 173 |
173 PepperFlashSettingsManager::Core::Core(PepperFlashSettingsManager* manager, | 174 PepperFlashSettingsManager::Core::Core(PepperFlashSettingsManager* manager, |
174 content::BrowserContext* browser_context) | 175 content::BrowserContext* browser_context) |
175 : manager_(manager), | 176 : manager_(manager), |
176 initialized_(false), | 177 initialized_(false), |
177 detached_(false), | 178 detached_(false), |
178 browser_context_path_(browser_context->GetPath()), | 179 browser_context_path_(browser_context->GetPath()), |
179 plugin_prefs_(PluginPrefs::GetForProfile( | 180 plugin_prefs_(PluginPrefs::GetForProfile( |
180 Profile::FromBrowserContext(browser_context))) { | 181 Profile::FromBrowserContext(browser_context))) { |
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
182 | |
183 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
184 base::Bind(&Core::Initialize, this)); | |
185 } | 183 } |
186 | 184 |
187 PepperFlashSettingsManager::Core::~Core() { | 185 PepperFlashSettingsManager::Core::~Core() { |
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
189 } | 187 } |
190 | 188 |
| 189 void PepperFlashSettingsManager::Core::Initialize() { |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 191 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 192 base::Bind(&Core::InitializeOnIOThread, this)); |
| 193 } |
| 194 |
191 void PepperFlashSettingsManager::Core::Detach() { | 195 void PepperFlashSettingsManager::Core::Detach() { |
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
193 | 197 |
194 manager_ = NULL; | 198 manager_ = NULL; |
195 // This call guarantees that one ref is retained until |detached_| is set to | 199 // This call guarantees that one ref is retained until |detached_| is set to |
196 // true. This is important. Otherwise, if the ref count drops to zero on the | 200 // true. This is important. Otherwise, if the ref count drops to zero on the |
197 // UI thread (which posts a task to delete this object on the I/O thread) | 201 // UI thread (which posts a task to delete this object on the I/O thread) |
198 // while the I/O thread doesn't know about it, methods on the I/O thread might | 202 // while the I/O thread doesn't know about it, methods on the I/O thread might |
199 // increase the ref count again and cause double deletion. | 203 // increase the ref count again and cause double deletion. |
200 BrowserThread::PostTask( | 204 BrowserThread::PostTask( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 269 } |
266 | 270 |
267 void PepperFlashSettingsManager::Core::OnChannelError() { | 271 void PepperFlashSettingsManager::Core::OnChannelError() { |
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
269 if (detached_) | 273 if (detached_) |
270 return; | 274 return; |
271 | 275 |
272 NotifyErrorFromIOThread(); | 276 NotifyErrorFromIOThread(); |
273 } | 277 } |
274 | 278 |
275 void PepperFlashSettingsManager::Core::Initialize() { | |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
277 DCHECK(!detached_); | |
278 DCHECK(!initialized_); | |
279 | |
280 webkit::WebPluginInfo plugin_info; | |
281 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(), | |
282 &plugin_info)) { | |
283 NotifyErrorFromIOThread(); | |
284 return; | |
285 } | |
286 | |
287 FilePath profile_path = | |
288 browser_context_path_.Append(content::kPepperDataDirname); | |
289 #if defined(OS_WIN) | |
290 plugin_data_path_ = profile_path.Append(plugin_info.name); | |
291 #else | |
292 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name)); | |
293 #endif | |
294 | |
295 helper_ = content::PepperFlashSettingsHelper::Create(); | |
296 content::PepperFlashSettingsHelper::OpenChannelCallback callback = | |
297 base::Bind(&Core::ConnectToChannel, this); | |
298 helper_->OpenChannelToBroker(plugin_info.path, callback); | |
299 } | |
300 | |
301 void PepperFlashSettingsManager::Core::ConnectToChannel( | 279 void PepperFlashSettingsManager::Core::ConnectToChannel( |
302 bool success, | 280 bool success, |
303 const IPC::ChannelHandle& handle) { | 281 const IPC::ChannelHandle& handle) { |
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
305 if (detached_) | 283 if (detached_) |
306 return; | 284 return; |
307 | 285 |
308 DCHECK(!initialized_); | 286 DCHECK(!initialized_); |
309 DCHECK(!channel_.get()); | 287 DCHECK(!channel_.get()); |
310 | 288 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 case SET_SITE_PERMISSION: | 321 case SET_SITE_PERMISSION: |
344 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites); | 322 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites); |
345 break; | 323 break; |
346 default: | 324 default: |
347 NOTREACHED(); | 325 NOTREACHED(); |
348 break; | 326 break; |
349 } | 327 } |
350 } | 328 } |
351 } | 329 } |
352 | 330 |
| 331 void PepperFlashSettingsManager::Core::InitializeOnIOThread() { |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 333 DCHECK(!initialized_); |
| 334 |
| 335 if (detached_) |
| 336 return; |
| 337 |
| 338 webkit::WebPluginInfo plugin_info; |
| 339 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(), |
| 340 &plugin_info)) { |
| 341 NotifyErrorFromIOThread(); |
| 342 return; |
| 343 } |
| 344 |
| 345 FilePath profile_path = |
| 346 browser_context_path_.Append(content::kPepperDataDirname); |
| 347 #if defined(OS_WIN) |
| 348 plugin_data_path_ = profile_path.Append(plugin_info.name); |
| 349 #else |
| 350 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name)); |
| 351 #endif |
| 352 |
| 353 helper_ = content::PepperFlashSettingsHelper::Create(); |
| 354 content::PepperFlashSettingsHelper::OpenChannelCallback callback = |
| 355 base::Bind(&Core::ConnectToChannel, this); |
| 356 helper_->OpenChannelToBroker(plugin_info.path, callback); |
| 357 } |
| 358 |
353 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread( | 359 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread( |
354 uint32 request_id) { | 360 uint32 request_id) { |
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
356 if (detached_) | 362 if (detached_) |
357 return; | 363 return; |
358 | 364 |
359 if (!initialized_) { | 365 if (!initialized_) { |
360 PendingRequest request; | 366 PendingRequest request; |
361 request.id = request_id; | 367 request.id = request_id; |
362 request.type = DEAUTHORIZE_CONTENT_LICENSES; | 368 request.type = DEAUTHORIZE_CONTENT_LICENSES; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 uint32 id = GetNextRequestId(); | 763 uint32 id = GetNextRequestId(); |
758 core_->SetSitePermission(id, setting_type, sites); | 764 core_->SetSitePermission(id, setting_type, sites); |
759 return id; | 765 return id; |
760 } | 766 } |
761 | 767 |
762 uint32 PepperFlashSettingsManager::GetNextRequestId() { | 768 uint32 PepperFlashSettingsManager::GetNextRequestId() { |
763 return next_request_id_++; | 769 return next_request_id_++; |
764 } | 770 } |
765 | 771 |
766 void PepperFlashSettingsManager::EnsureCoreExists() { | 772 void PepperFlashSettingsManager::EnsureCoreExists() { |
767 if (!core_.get()) | 773 if (!core_.get()) { |
768 core_ = new Core(this, browser_context_); | 774 core_ = new Core(this, browser_context_); |
| 775 core_->Initialize(); |
| 776 } |
769 } | 777 } |
770 | 778 |
771 void PepperFlashSettingsManager::OnError() { | 779 void PepperFlashSettingsManager::OnError() { |
772 if (core_.get()) { | 780 if (core_.get()) { |
773 core_->Detach(); | 781 core_->Detach(); |
774 core_ = NULL; | 782 core_ = NULL; |
775 } else { | 783 } else { |
776 NOTREACHED(); | 784 NOTREACHED(); |
777 } | 785 } |
778 } | 786 } |
779 | 787 |
OLD | NEW |