• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_PEPPER_FLASH_SETTINGS_MANAGER_H_
6 #define CHROME_BROWSER_PEPPER_FLASH_SETTINGS_MANAGER_H_
7 
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "ppapi/c/private/ppp_flash_browser_operations.h"
12 #include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h"
13 
14 class PluginPrefs;
15 class PrefService;
16 
17 namespace content {
18 class BrowserContext;
19 struct WebPluginInfo;
20 }
21 
22 namespace user_prefs {
23 class PrefRegistrySyncable;
24 }
25 
26 // PepperFlashSettingsManager communicates with a PPAPI broker process to
27 // read/write Pepper Flash settings.
28 class PepperFlashSettingsManager {
29  public:
30   class Client {
31    public:
~Client()32     virtual ~Client() {}
33 
OnDeauthorizeContentLicensesCompleted(uint32 request_id,bool success)34     virtual void OnDeauthorizeContentLicensesCompleted(uint32 request_id,
35                                                        bool success) {}
OnGetPermissionSettingsCompleted(uint32 request_id,bool success,PP_Flash_BrowserOperations_Permission default_permission,const ppapi::FlashSiteSettings & sites)36     virtual void OnGetPermissionSettingsCompleted(
37         uint32 request_id,
38         bool success,
39         PP_Flash_BrowserOperations_Permission default_permission,
40         const ppapi::FlashSiteSettings& sites) {}
41 
OnSetDefaultPermissionCompleted(uint32 request_id,bool success)42     virtual void OnSetDefaultPermissionCompleted(uint32 request_id,
43                                                  bool success) {}
44 
OnSetSitePermissionCompleted(uint32 request_id,bool success)45     virtual void OnSetSitePermissionCompleted(uint32 request_id,
46                                               bool success) {}
47 
OnGetSitesWithDataCompleted(uint32 request_id,const std::vector<std::string> & sites)48     virtual void OnGetSitesWithDataCompleted(
49         uint32 request_id,
50         const std::vector<std::string>& sites) {}
51 
OnClearSiteDataCompleted(uint32 request_id,bool success)52     virtual void OnClearSiteDataCompleted(uint32 request_id, bool success) {}
53   };
54 
55   // |client| must outlive this object. It is guaranteed that |client| won't
56   // receive any notifications after this object goes away.
57   PepperFlashSettingsManager(Client* client,
58                              content::BrowserContext* browser_context);
59   ~PepperFlashSettingsManager();
60 
61   // |plugin_info| will be updated if it is not NULL and the method returns
62   // true.
63   static bool IsPepperFlashInUse(PluginPrefs* plugin_prefs,
64                                  content::WebPluginInfo* plugin_info);
65 
66   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
67 
68   // Requests to deauthorize content licenses.
69   // Client::OnDeauthorizeContentLicensesCompleted() will be called when the
70   // operation is completed.
71   // The return value is the same as the request ID passed into
72   // Client::OnDeauthorizeContentLicensesCompleted().
73   uint32 DeauthorizeContentLicenses(PrefService* prefs);
74 
75   // Gets permission settings.
76   // Client::OnGetPermissionSettingsCompleted() will be called when the
77   // operation is completed.
78   uint32 GetPermissionSettings(
79       PP_Flash_BrowserOperations_SettingType setting_type);
80 
81   // Sets default permission.
82   // Client::OnSetDefaultPermissionCompleted() will be called when the
83   // operation is completed.
84   uint32 SetDefaultPermission(
85       PP_Flash_BrowserOperations_SettingType setting_type,
86       PP_Flash_BrowserOperations_Permission permission,
87       bool clear_site_specific);
88 
89   // Sets site-specific permission.
90   // Client::OnSetSitePermissionCompleted() will be called when the operation
91   // is completed.
92   uint32 SetSitePermission(PP_Flash_BrowserOperations_SettingType setting_type,
93                            const ppapi::FlashSiteSettings& sites);
94 
95   // Gets a list of sites that have stored data.
96   // Client::OnGetSitesWithDataCompleted() will be called when the operation is
97   // completed.
98   uint32 GetSitesWithData();
99 
100   // Clears data for a certain site.
101   // Client::OnClearSiteDataompleted() will be called when the operation is
102   // completed.
103   uint32 ClearSiteData(const std::string& site, uint64 flags, uint64 max_age);
104 
105  private:
106   // Core does most of the work. It is ref-counted so that its lifespan can be
107   // independent of the containing object's:
108   // - The manager can be deleted on the UI thread while the core still being
109   // used on the I/O thread.
110   // - The manager can delete the core when it encounters errors and create
111   // another one to handle new requests.
112   class Core;
113 
114   uint32 GetNextRequestId();
115 
116   void EnsureCoreExists();
117 
118   // Notifies us that an error occurred in |core|.
119   void OnError(Core* core);
120 
121   // |client_| is not owned by this object and must outlive it.
122   Client* client_;
123 
124   // The browser context for the profile.
125   content::BrowserContext* browser_context_;
126 
127   scoped_refptr<Core> core_;
128 
129   uint32 next_request_id_;
130 
131   base::WeakPtrFactory<PepperFlashSettingsManager> weak_ptr_factory_;
132 
133   DISALLOW_COPY_AND_ASSIGN(PepperFlashSettingsManager);
134 };
135 
136 #endif  // CHROME_BROWSER_PEPPER_FLASH_SETTINGS_MANAGER_H_
137