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
3 // found in the LICENSE file.
5 #include "chrome/browser/pepper_flash_settings_manager.h"
11 #include "base/bind.h"
12 #include "base/compiler_specific.h"
13 #include "base/file_util.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/sequenced_task_runner_helpers.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/plugins/plugin_prefs.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
20 #include "chrome/common/pref_names.h"
21 #include "components/user_prefs/pref_registry_syncable.h"
22 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/pepper_flash_settings_helper.h"
25 #include "content/public/browser/plugin_service.h"
26 #include "content/public/common/content_constants.h"
27 #include "content/public/common/webplugininfo.h"
28 #include "ipc/ipc_channel.h"
29 #include "ipc/ipc_listener.h"
30 #include "ppapi/proxy/ppapi_messages.h"
33 using content::BrowserThread
;
35 class PepperFlashSettingsManager::Core
36 : public IPC::Listener
,
37 public base::RefCountedThreadSafe
<Core
, BrowserThread::DeleteOnIOThread
> {
39 Core(base::WeakPtr
<PepperFlashSettingsManager
> manager
,
40 content::BrowserContext
* browser_context
);
44 // Notifies the core that it has been detached. Afterwards, no method should
45 // be called any more.
48 void DeauthorizeContentLicenses(uint32 request_id
);
49 void GetPermissionSettings(
51 PP_Flash_BrowserOperations_SettingType setting_type
);
52 void SetDefaultPermission(
54 PP_Flash_BrowserOperations_SettingType setting_type
,
55 PP_Flash_BrowserOperations_Permission permission
,
56 bool clear_site_specific
);
57 void SetSitePermission(uint32 request_id
,
58 PP_Flash_BrowserOperations_SettingType setting_type
,
59 const ppapi::FlashSiteSettings
& sites
);
60 void GetSitesWithData(uint32 request_id
);
61 void ClearSiteData(uint32 request_id
,
62 const std::string
& site
,
66 // IPC::Listener implementation.
67 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
68 virtual void OnChannelError() OVERRIDE
;
71 friend struct BrowserThread::DeleteOnThread
<BrowserThread::IO
>;
72 friend class base::DeleteHelper
<Core
>;
75 INVALID_REQUEST_TYPE
= 0,
76 DEAUTHORIZE_CONTENT_LICENSES
,
77 GET_PERMISSION_SETTINGS
,
78 SET_DEFAULT_PERMISSION
,
85 STATE_UNINITIALIZED
= 0,
91 struct PendingRequest
{
94 type(INVALID_REQUEST_TYPE
),
95 setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC
),
96 permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT
),
97 clear_site_specific(false),
105 // Used by GET_PERMISSION_SETTINGS, SET_DEFAULT_PERMISSION and
106 // SET_SITE_PERMISSION.
107 PP_Flash_BrowserOperations_SettingType setting_type
;
109 // Used by SET_DEFAULT_PERMISSION.
110 PP_Flash_BrowserOperations_Permission permission
;
111 bool clear_site_specific
;
113 // Used by SET_SITE_PERMISSION.
114 ppapi::FlashSiteSettings sites
;
116 // Used by CLEAR_SITE_DATA
124 void ConnectToChannel(bool success
, const IPC::ChannelHandle
& handle
);
126 void InitializeOnIOThread();
127 void DeauthorizeContentLicensesOnIOThread(uint32 request_id
);
128 void DeauthorizeContentLicensesOnBlockingPool(
130 const base::FilePath
& profile_path
);
131 void DeauthorizeContentLicensesInPlugin(uint32 request_id
, bool success
);
132 void GetPermissionSettingsOnIOThread(
134 PP_Flash_BrowserOperations_SettingType setting_type
);
135 void SetDefaultPermissionOnIOThread(
137 PP_Flash_BrowserOperations_SettingType setting_type
,
138 PP_Flash_BrowserOperations_Permission permission
,
139 bool clear_site_specific
);
140 void SetSitePermissionOnIOThread(
142 PP_Flash_BrowserOperations_SettingType setting_type
,
143 const ppapi::FlashSiteSettings
& sites
);
144 void GetSitesWithDataOnIOThread(uint32 request_id
);
145 void ClearSiteDataOnIOThread(uint32 request_id
,
146 const std::string
& site
,
149 void DetachOnIOThread();
151 void NotifyErrorFromIOThread();
153 void NotifyDeauthorizeContentLicensesCompleted(uint32 request_id
,
155 void NotifyGetPermissionSettingsCompleted(
158 PP_Flash_BrowserOperations_Permission default_permission
,
159 const ppapi::FlashSiteSettings
& sites
);
160 void NotifySetDefaultPermissionCompleted(uint32 request_id
, bool success
);
161 void NotifySetSitePermissionCompleted(uint32 request_id
, bool success
);
162 void NotifyGetSitesWithDataCompleted(uint32 request_id
,
163 const std::vector
<std::string
>& sites
);
164 void NotifyClearSiteDataCompleted(uint32 request_id
, bool success
);
167 const std::vector
<std::pair
<uint32
, RequestType
> >& notifications
);
170 void OnDeauthorizeContentLicensesResult(uint32 request_id
, bool success
);
171 void OnGetPermissionSettingsResult(
174 PP_Flash_BrowserOperations_Permission default_permission
,
175 const ppapi::FlashSiteSettings
& sites
);
176 void OnSetDefaultPermissionResult(uint32 request_id
, bool success
);
177 void OnSetSitePermissionResult(uint32 request_id
, bool success
);
178 void OnGetSitesWithDataResult(uint32 request_id
,
179 const std::vector
<std::string
>& sites
);
180 void OnClearSiteDataResult(uint32 request_id
, bool success
);
182 // Used only on the UI thread.
183 base::WeakPtr
<PepperFlashSettingsManager
> manager_
;
185 // Used only on the I/O thread.
186 base::FilePath plugin_data_path_
;
188 // The channel is NULL until we have opened a connection to the broker
189 // process. Used only on the I/O thread.
190 scoped_ptr
<IPC::Channel
> channel_
;
192 // Used only on the I/O thread.
195 // Requests that need to be sent once the channel to the broker process is
196 // established. Used only on the I/O thread.
197 std::vector
<PendingRequest
> pending_requests_
;
198 // Requests that have been sent but haven't got replied. Used only on the
200 std::map
<uint32
, RequestType
> pending_responses_
;
202 // Used only on the I/O thread.
203 scoped_refptr
<content::PepperFlashSettingsHelper
> helper_
;
205 // Path for the current profile. Must be retrieved on the UI thread from the
206 // browser context when we start so we can use it later on the I/O thread.
207 base::FilePath browser_context_path_
;
209 scoped_refptr
<PluginPrefs
> plugin_prefs_
;
212 PepperFlashSettingsManager::Core::Core(
213 base::WeakPtr
<PepperFlashSettingsManager
> manager
,
214 content::BrowserContext
* browser_context
)
216 state_(STATE_UNINITIALIZED
),
217 browser_context_path_(browser_context
->GetPath()),
218 plugin_prefs_(PluginPrefs::GetForProfile(
219 Profile::FromBrowserContext(browser_context
))) {
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
223 PepperFlashSettingsManager::Core::~Core() {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
227 void PepperFlashSettingsManager::Core::Initialize() {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
229 BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
230 base::Bind(&Core::InitializeOnIOThread
, this));
233 void PepperFlashSettingsManager::Core::Detach() {
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
236 // This call guarantees that one ref is retained until we get to the DETACHED
237 // state. This is important. Otherwise, if the ref count drops to zero on the
238 // UI thread (which posts a task to delete this object on the I/O thread)
239 // while the I/O thread doesn't know about it, methods on the I/O thread might
240 // increase the ref count again and cause double deletion.
241 BrowserThread::PostTask(
242 BrowserThread::IO
, FROM_HERE
, base::Bind(&Core::DetachOnIOThread
, this));
245 void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
249 BrowserThread::PostTask(
250 BrowserThread::IO
, FROM_HERE
,
251 base::Bind(&Core::DeauthorizeContentLicensesOnIOThread
, this,
255 void PepperFlashSettingsManager::Core::GetPermissionSettings(
257 PP_Flash_BrowserOperations_SettingType setting_type
) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
260 BrowserThread::PostTask(
261 BrowserThread::IO
, FROM_HERE
,
262 base::Bind(&Core::GetPermissionSettingsOnIOThread
, this, request_id
,
266 void PepperFlashSettingsManager::Core::SetDefaultPermission(
268 PP_Flash_BrowserOperations_SettingType setting_type
,
269 PP_Flash_BrowserOperations_Permission permission
,
270 bool clear_site_specific
) {
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
273 BrowserThread::PostTask(
274 BrowserThread::IO
, FROM_HERE
,
275 base::Bind(&Core::SetDefaultPermissionOnIOThread
, this, request_id
,
276 setting_type
, permission
, clear_site_specific
));
279 void PepperFlashSettingsManager::Core::SetSitePermission(
281 PP_Flash_BrowserOperations_SettingType setting_type
,
282 const ppapi::FlashSiteSettings
& sites
) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
285 BrowserThread::PostTask(
286 BrowserThread::IO
, FROM_HERE
,
287 base::Bind(&Core::SetSitePermissionOnIOThread
, this, request_id
,
288 setting_type
, sites
));
291 void PepperFlashSettingsManager::Core::GetSitesWithData(uint32 request_id
) {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
294 BrowserThread::PostTask(
295 BrowserThread::IO
, FROM_HERE
,
296 base::Bind(&Core::GetSitesWithDataOnIOThread
, this, request_id
));
299 void PepperFlashSettingsManager::Core::ClearSiteData(uint32 request_id
,
300 const std::string
& site
,
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
305 BrowserThread::PostTask(
306 BrowserThread::IO
, FROM_HERE
,
307 base::Bind(&Core::ClearSiteDataOnIOThread
, this, request_id
,
308 site
, flags
, max_age
));
311 bool PepperFlashSettingsManager::Core::OnMessageReceived(
312 const IPC::Message
& message
) {
313 IPC_BEGIN_MESSAGE_MAP(Core
, message
)
314 IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult
,
315 OnDeauthorizeContentLicensesResult
)
316 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult
,
317 OnGetPermissionSettingsResult
)
318 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult
,
319 OnSetDefaultPermissionResult
)
320 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult
,
321 OnSetSitePermissionResult
)
322 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult
,
323 OnGetSitesWithDataResult
)
324 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult
,
325 OnClearSiteDataResult
)
326 IPC_MESSAGE_UNHANDLED_ERROR()
327 IPC_END_MESSAGE_MAP()
332 void PepperFlashSettingsManager::Core::OnChannelError() {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
334 if (state_
== STATE_DETACHED
)
337 NotifyErrorFromIOThread();
340 void PepperFlashSettingsManager::Core::ConnectToChannel(
342 const IPC::ChannelHandle
& handle
) {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
344 if (state_
== STATE_DETACHED
)
347 DCHECK(state_
== STATE_UNINITIALIZED
);
348 DCHECK(!channel_
.get());
351 DLOG(ERROR
) << "Couldn't open plugin channel";
352 NotifyErrorFromIOThread();
356 channel_
.reset(new IPC::Channel(handle
, IPC::Channel::MODE_CLIENT
, this));
357 if (!channel_
->Connect()) {
358 DLOG(ERROR
) << "Couldn't connect to plugin";
359 NotifyErrorFromIOThread();
363 state_
= STATE_INITIALIZED
;
365 std::vector
<PendingRequest
> temp_pending_requests
;
366 temp_pending_requests
.swap(pending_requests_
);
367 for (std::vector
<PendingRequest
>::iterator iter
=
368 temp_pending_requests
.begin();
369 iter
!= temp_pending_requests
.end(); ++iter
) {
370 switch (iter
->type
) {
371 case INVALID_REQUEST_TYPE
:
374 case DEAUTHORIZE_CONTENT_LICENSES
:
375 DeauthorizeContentLicensesOnIOThread(iter
->id
);
377 case GET_PERMISSION_SETTINGS
:
378 GetPermissionSettingsOnIOThread(iter
->id
, iter
->setting_type
);
380 case SET_DEFAULT_PERMISSION
:
381 SetDefaultPermissionOnIOThread(
382 iter
->id
, iter
->setting_type
, iter
->permission
,
383 iter
->clear_site_specific
);
385 case SET_SITE_PERMISSION
:
386 SetSitePermissionOnIOThread(iter
->id
, iter
->setting_type
, iter
->sites
);
388 case GET_SITES_WITH_DATA
:
389 GetSitesWithDataOnIOThread(iter
->id
);
391 case CLEAR_SITE_DATA
:
392 ClearSiteDataOnIOThread(iter
->id
, iter
->site
, iter
->flags
,
399 void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
401 DCHECK_EQ(STATE_UNINITIALIZED
, state_
);
403 content::WebPluginInfo plugin_info
;
404 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_
.get(),
406 NotifyErrorFromIOThread();
410 base::FilePath profile_path
=
411 browser_context_path_
.Append(content::kPepperDataDirname
);
413 plugin_data_path_
= profile_path
.Append(plugin_info
.name
);
415 plugin_data_path_
= profile_path
.Append(base::UTF16ToUTF8(plugin_info
.name
));
418 helper_
= content::PepperFlashSettingsHelper::Create();
419 content::PepperFlashSettingsHelper::OpenChannelCallback callback
=
420 base::Bind(&Core::ConnectToChannel
, this);
421 helper_
->OpenChannelToBroker(plugin_info
.path
, callback
);
424 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
427 DCHECK_NE(STATE_DETACHED
, state_
);
429 if (state_
== STATE_UNINITIALIZED
) {
430 PendingRequest request
;
431 request
.id
= request_id
;
432 request
.type
= DEAUTHORIZE_CONTENT_LICENSES
;
433 pending_requests_
.push_back(request
);
437 pending_responses_
.insert(
438 std::make_pair(request_id
, DEAUTHORIZE_CONTENT_LICENSES
));
439 if (state_
== STATE_ERROR
) {
440 NotifyErrorFromIOThread();
444 #if defined(OS_CHROMEOS)
445 BrowserThread::PostBlockingPoolTask(FROM_HERE
,
446 base::Bind(&Core::DeauthorizeContentLicensesOnBlockingPool
, this,
447 request_id
, browser_context_path_
));
449 DeauthorizeContentLicensesInPlugin(request_id
, true);
453 // TODO(raymes): This is temporary code to migrate ChromeOS devices to the new
454 // scheme for generating device IDs. Delete this once we are sure most ChromeOS
455 // devices have been migrated.
456 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnBlockingPool(
458 const base::FilePath
& profile_path
) {
459 // ChromeOS used to store the device ID in a file but this is no longer used.
461 const base::FilePath
& device_id_path
=
462 chrome::DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path
);
463 bool success
= base::DeleteFile(device_id_path
, false);
465 BrowserThread::PostTask(
466 BrowserThread::IO
, FROM_HERE
,
467 base::Bind(&Core::DeauthorizeContentLicensesInPlugin
, this, request_id
,
471 void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
476 NotifyErrorFromIOThread();
480 new PpapiMsg_DeauthorizeContentLicenses(request_id
, plugin_data_path_
);
481 if (!channel_
->Send(msg
)) {
482 DLOG(ERROR
) << "Couldn't send DeauthorizeContentLicenses message";
483 // A failure notification for the current request will be sent since
484 // |pending_responses_| has been updated.
485 NotifyErrorFromIOThread();
489 void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
491 PP_Flash_BrowserOperations_SettingType setting_type
) {
492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
493 DCHECK_NE(STATE_DETACHED
, state_
);
495 if (state_
== STATE_UNINITIALIZED
) {
496 PendingRequest request
;
497 request
.id
= request_id
;
498 request
.type
= GET_PERMISSION_SETTINGS
;
499 request
.setting_type
= setting_type
;
500 pending_requests_
.push_back(request
);
504 pending_responses_
.insert(
505 std::make_pair(request_id
, GET_PERMISSION_SETTINGS
));
506 if (state_
== STATE_ERROR
) {
507 NotifyErrorFromIOThread();
511 IPC::Message
* msg
= new PpapiMsg_GetPermissionSettings(
512 request_id
, plugin_data_path_
, setting_type
);
513 if (!channel_
->Send(msg
)) {
514 DLOG(ERROR
) << "Couldn't send GetPermissionSettings message";
515 // A failure notification for the current request will be sent since
516 // |pending_responses_| has been updated.
517 NotifyErrorFromIOThread();
521 void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
523 PP_Flash_BrowserOperations_SettingType setting_type
,
524 PP_Flash_BrowserOperations_Permission permission
,
525 bool clear_site_specific
) {
526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
527 DCHECK_NE(STATE_DETACHED
, state_
);
529 if (state_
== STATE_UNINITIALIZED
) {
530 PendingRequest request
;
531 request
.id
= request_id
;
532 request
.type
= SET_DEFAULT_PERMISSION
;
533 request
.setting_type
= setting_type
;
534 request
.permission
= permission
;
535 request
.clear_site_specific
= clear_site_specific
;
536 pending_requests_
.push_back(request
);
540 pending_responses_
.insert(std::make_pair(request_id
, SET_DEFAULT_PERMISSION
));
541 if (state_
== STATE_ERROR
) {
542 NotifyErrorFromIOThread();
546 IPC::Message
* msg
= new PpapiMsg_SetDefaultPermission(
547 request_id
, plugin_data_path_
, setting_type
, permission
,
548 clear_site_specific
);
549 if (!channel_
->Send(msg
)) {
550 DLOG(ERROR
) << "Couldn't send SetDefaultPermission message";
551 // A failure notification for the current request will be sent since
552 // |pending_responses_| has been updated.
553 NotifyErrorFromIOThread();
557 void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
559 PP_Flash_BrowserOperations_SettingType setting_type
,
560 const ppapi::FlashSiteSettings
& sites
) {
561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
562 DCHECK_NE(STATE_DETACHED
, state_
);
564 if (state_
== STATE_UNINITIALIZED
) {
565 pending_requests_
.push_back(PendingRequest());
566 PendingRequest
& request
= pending_requests_
.back();
567 request
.id
= request_id
;
568 request
.type
= SET_SITE_PERMISSION
;
569 request
.setting_type
= setting_type
;
570 request
.sites
= sites
;
574 pending_responses_
.insert(std::make_pair(request_id
, SET_SITE_PERMISSION
));
575 if (state_
== STATE_ERROR
) {
576 NotifyErrorFromIOThread();
580 IPC::Message
* msg
= new PpapiMsg_SetSitePermission(
581 request_id
, plugin_data_path_
, setting_type
, sites
);
582 if (!channel_
->Send(msg
)) {
583 DLOG(ERROR
) << "Couldn't send SetSitePermission message";
584 // A failure notification for the current request will be sent since
585 // |pending_responses_| has been updated.
586 NotifyErrorFromIOThread();
590 void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
593 DCHECK_NE(STATE_DETACHED
, state_
);
595 if (state_
== STATE_UNINITIALIZED
) {
596 pending_requests_
.push_back(PendingRequest());
597 PendingRequest
& request
= pending_requests_
.back();
598 request
.id
= request_id
;
599 request
.type
= GET_SITES_WITH_DATA
;
603 pending_responses_
.insert(std::make_pair(request_id
, GET_SITES_WITH_DATA
));
604 if (state_
== STATE_ERROR
) {
605 NotifyErrorFromIOThread();
609 IPC::Message
* msg
= new PpapiMsg_GetSitesWithData(
610 request_id
, plugin_data_path_
);
611 if (!channel_
->Send(msg
)) {
612 DLOG(ERROR
) << "Couldn't send GetSitesWithData message";
613 // A failure notification for the current request will be sent since
614 // |pending_responses_| has been updated.
615 NotifyErrorFromIOThread();
619 void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
621 const std::string
& site
,
624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
625 DCHECK_NE(STATE_DETACHED
, state_
);
627 if (state_
== STATE_UNINITIALIZED
) {
628 pending_requests_
.push_back(PendingRequest());
629 PendingRequest
& request
= pending_requests_
.back();
630 request
.id
= request_id
;
631 request
.type
= CLEAR_SITE_DATA
;
633 request
.flags
= flags
;
634 request
.max_age
= max_age
;
638 pending_responses_
.insert(std::make_pair(request_id
, CLEAR_SITE_DATA
));
639 if (state_
== STATE_ERROR
) {
640 NotifyErrorFromIOThread();
644 IPC::Message
* msg
= new PpapiMsg_ClearSiteData(
645 request_id
, plugin_data_path_
, site
, flags
, max_age
);
646 if (!channel_
->Send(msg
)) {
647 DLOG(ERROR
) << "Couldn't send ClearSiteData message";
648 // A failure notification for the current request will be sent since
649 // |pending_responses_| has been updated.
650 NotifyErrorFromIOThread();
654 void PepperFlashSettingsManager::Core::DetachOnIOThread() {
655 state_
= STATE_DETACHED
;
658 void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
660 if (state_
== STATE_DETACHED
)
663 state_
= STATE_ERROR
;
664 std::vector
<std::pair
<uint32
, RequestType
> > notifications
;
665 for (std::vector
<PendingRequest
>::iterator iter
= pending_requests_
.begin();
666 iter
!= pending_requests_
.end(); ++iter
) {
667 notifications
.push_back(std::make_pair(iter
->id
, iter
->type
));
669 pending_requests_
.clear();
670 notifications
.insert(notifications
.end(), pending_responses_
.begin(),
671 pending_responses_
.end());
672 pending_responses_
.clear();
674 BrowserThread::PostTask(
675 BrowserThread::UI
, FROM_HERE
,
676 base::Bind(&Core::NotifyError
, this, notifications
));
680 PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted(
683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
685 if (manager_
.get()) {
686 manager_
->client_
->OnDeauthorizeContentLicensesCompleted(
687 request_id
, success
);
691 void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
694 PP_Flash_BrowserOperations_Permission default_permission
,
695 const ppapi::FlashSiteSettings
& sites
) {
696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
698 if (manager_
.get()) {
699 manager_
->client_
->OnGetPermissionSettingsCompleted(
700 request_id
, success
, default_permission
, sites
);
704 void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
709 if (manager_
.get()) {
710 manager_
->client_
->OnSetDefaultPermissionCompleted(
711 request_id
, success
);
715 void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
720 if (manager_
.get()) {
721 manager_
->client_
->OnSetSitePermissionCompleted(
722 request_id
, success
);
726 void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
728 const std::vector
<std::string
>& sites
) {
729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
731 if (manager_
.get()) {
732 manager_
->client_
->OnGetSitesWithDataCompleted(
737 void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
743 manager_
->client_
->OnClearSiteDataCompleted(request_id
, success
);
746 void PepperFlashSettingsManager::Core::NotifyError(
747 const std::vector
<std::pair
<uint32
, RequestType
> >& notifications
) {
748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
750 scoped_refptr
<Core
> protector(this);
751 for (std::vector
<std::pair
<uint32
, RequestType
> >::const_iterator iter
=
752 notifications
.begin(); iter
!= notifications
.end(); ++iter
) {
753 // Check |manager_| for each iteration in case it is destroyed in one of
758 switch (iter
->second
) {
759 case INVALID_REQUEST_TYPE
:
762 case DEAUTHORIZE_CONTENT_LICENSES
:
763 manager_
->client_
->OnDeauthorizeContentLicensesCompleted(
766 case GET_PERMISSION_SETTINGS
:
767 manager_
->client_
->OnGetPermissionSettingsCompleted(
768 iter
->first
, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT
,
769 ppapi::FlashSiteSettings());
771 case SET_DEFAULT_PERMISSION
:
772 manager_
->client_
->OnSetDefaultPermissionCompleted(
775 case SET_SITE_PERMISSION
:
776 manager_
->client_
->OnSetSitePermissionCompleted(iter
->first
, false);
778 case GET_SITES_WITH_DATA
:
779 manager_
->client_
->OnGetSitesWithDataCompleted(
780 iter
->first
, std::vector
<std::string
>());
782 case CLEAR_SITE_DATA
:
783 manager_
->client_
->OnClearSiteDataCompleted(iter
->first
, false);
789 manager_
->OnError(this);
792 void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
796 if (state_
== STATE_DETACHED
)
799 DLOG_IF(ERROR
, !success
) << "DeauthorizeContentLicenses returned error";
801 std::map
<uint32
, RequestType
>::iterator iter
=
802 pending_responses_
.find(request_id
);
803 if (iter
== pending_responses_
.end())
806 DCHECK_EQ(iter
->second
, DEAUTHORIZE_CONTENT_LICENSES
);
808 pending_responses_
.erase(iter
);
809 BrowserThread::PostTask(
810 BrowserThread::UI
, FROM_HERE
,
811 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted
, this,
812 request_id
, success
));
815 void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
818 PP_Flash_BrowserOperations_Permission default_permission
,
819 const ppapi::FlashSiteSettings
& sites
) {
820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
821 if (state_
== STATE_DETACHED
)
824 DLOG_IF(ERROR
, !success
) << "GetPermissionSettings returned error";
826 std::map
<uint32
, RequestType
>::iterator iter
=
827 pending_responses_
.find(request_id
);
828 if (iter
== pending_responses_
.end())
831 DCHECK_EQ(iter
->second
, GET_PERMISSION_SETTINGS
);
833 pending_responses_
.erase(iter
);
834 BrowserThread::PostTask(
835 BrowserThread::UI
, FROM_HERE
,
836 base::Bind(&Core::NotifyGetPermissionSettingsCompleted
, this,
837 request_id
, success
, default_permission
, sites
));
840 void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
844 if (state_
== STATE_DETACHED
)
847 DLOG_IF(ERROR
, !success
) << "SetDefaultPermission returned error";
849 std::map
<uint32
, RequestType
>::iterator iter
=
850 pending_responses_
.find(request_id
);
851 if (iter
== pending_responses_
.end())
854 DCHECK_EQ(iter
->second
, SET_DEFAULT_PERMISSION
);
856 pending_responses_
.erase(iter
);
857 BrowserThread::PostTask(
858 BrowserThread::UI
, FROM_HERE
,
859 base::Bind(&Core::NotifySetDefaultPermissionCompleted
, this,
860 request_id
, success
));
863 void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
867 if (state_
== STATE_DETACHED
)
870 DLOG_IF(ERROR
, !success
) << "SetSitePermission returned error";
872 std::map
<uint32
, RequestType
>::iterator iter
=
873 pending_responses_
.find(request_id
);
874 if (iter
== pending_responses_
.end())
877 DCHECK_EQ(iter
->second
, SET_SITE_PERMISSION
);
879 pending_responses_
.erase(iter
);
880 BrowserThread::PostTask(
881 BrowserThread::UI
, FROM_HERE
,
882 base::Bind(&Core::NotifySetSitePermissionCompleted
, this, request_id
,
886 void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
888 const std::vector
<std::string
>& sites
) {
889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
890 if (state_
== STATE_DETACHED
)
893 std::map
<uint32
, RequestType
>::iterator iter
=
894 pending_responses_
.find(request_id
);
895 if (iter
== pending_responses_
.end())
898 DCHECK_EQ(iter
->second
, GET_SITES_WITH_DATA
);
900 pending_responses_
.erase(iter
);
901 BrowserThread::PostTask(
902 BrowserThread::UI
, FROM_HERE
,
903 base::Bind(&Core::NotifyGetSitesWithDataCompleted
, this, request_id
,
907 void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
911 if (state_
== STATE_DETACHED
)
914 DLOG_IF(ERROR
, !success
) << "ClearSiteData returned error";
916 std::map
<uint32
, RequestType
>::iterator iter
=
917 pending_responses_
.find(request_id
);
918 if (iter
== pending_responses_
.end())
921 DCHECK_EQ(iter
->second
, CLEAR_SITE_DATA
);
923 pending_responses_
.erase(iter
);
924 BrowserThread::PostTask(
925 BrowserThread::UI
, FROM_HERE
,
926 base::Bind(&Core::NotifyClearSiteDataCompleted
, this, request_id
,
930 PepperFlashSettingsManager::PepperFlashSettingsManager(
932 content::BrowserContext
* browser_context
)
934 browser_context_(browser_context
),
936 weak_ptr_factory_(this) {
938 DCHECK(browser_context
);
941 PepperFlashSettingsManager::~PepperFlashSettingsManager() {
947 bool PepperFlashSettingsManager::IsPepperFlashInUse(
948 PluginPrefs
* plugin_prefs
,
949 content::WebPluginInfo
* plugin_info
) {
953 content::PluginService
* plugin_service
=
954 content::PluginService::GetInstance();
955 std::vector
<content::WebPluginInfo
> plugins
;
956 plugin_service
->GetPluginInfoArray(
957 GURL(), content::kFlashPluginSwfMimeType
, false, &plugins
, NULL
);
959 for (std::vector
<content::WebPluginInfo
>::iterator iter
= plugins
.begin();
960 iter
!= plugins
.end(); ++iter
) {
961 if (iter
->is_pepper_plugin() && plugin_prefs
->IsPluginEnabled(*iter
)) {
963 *plugin_info
= *iter
;
971 void PepperFlashSettingsManager::RegisterProfilePrefs(
972 user_prefs::PrefRegistrySyncable
* registry
) {
973 registry
->RegisterBooleanPref(
974 prefs::kDeauthorizeContentLicenses
,
976 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
978 registry
->RegisterBooleanPref(
979 prefs::kPepperFlashSettingsEnabled
,
981 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
984 uint32
PepperFlashSettingsManager::DeauthorizeContentLicenses(
985 PrefService
* prefs
) {
986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
988 // Clear the device ID salt which has the effect of regenerating a device
989 // ID. Since this happens synchronously (and on the UI thread), we don't have
990 // to add it to a pending request.
991 prefs
->ClearPref(prefs::kDRMSalt
);
994 uint32 id
= GetNextRequestId();
995 core_
->DeauthorizeContentLicenses(id
);
999 uint32
PepperFlashSettingsManager::GetPermissionSettings(
1000 PP_Flash_BrowserOperations_SettingType setting_type
) {
1001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1004 uint32 id
= GetNextRequestId();
1005 core_
->GetPermissionSettings(id
, setting_type
);
1009 uint32
PepperFlashSettingsManager::SetDefaultPermission(
1010 PP_Flash_BrowserOperations_SettingType setting_type
,
1011 PP_Flash_BrowserOperations_Permission permission
,
1012 bool clear_site_specific
) {
1013 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1016 uint32 id
= GetNextRequestId();
1017 core_
->SetDefaultPermission(id
, setting_type
, permission
,
1018 clear_site_specific
);
1022 uint32
PepperFlashSettingsManager::SetSitePermission(
1023 PP_Flash_BrowserOperations_SettingType setting_type
,
1024 const ppapi::FlashSiteSettings
& sites
) {
1025 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1028 uint32 id
= GetNextRequestId();
1029 core_
->SetSitePermission(id
, setting_type
, sites
);
1033 uint32
PepperFlashSettingsManager::GetSitesWithData() {
1034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1037 uint32 id
= GetNextRequestId();
1038 core_
->GetSitesWithData(id
);
1042 uint32
PepperFlashSettingsManager::ClearSiteData(const std::string
& site
,
1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1048 uint32 id
= GetNextRequestId();
1049 core_
->ClearSiteData(id
, site
, flags
, max_age
);
1053 uint32
PepperFlashSettingsManager::GetNextRequestId() {
1054 return next_request_id_
++;
1057 void PepperFlashSettingsManager::EnsureCoreExists() {
1059 core_
= new Core(weak_ptr_factory_
.GetWeakPtr(), browser_context_
);
1060 core_
->Initialize();
1064 void PepperFlashSettingsManager::OnError(Core
* core
) {
1066 if (core
!= core_
.get())