[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 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 | #include "chrome/browser/pepper_flash_settings_manager.h" |
| 6 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <utility> |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/compiler_specific.h" |
| 13 | #include "base/sequenced_task_runner_helpers.h" |
| 14 | #include "base/utf_string_conversions.h" |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 15 | #include "chrome/browser/plugins/plugin_prefs.h" |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 16 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 18 | #include "chrome/common/pref_names.h" |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 19 | #include "content/public/browser/browser_context.h" |
| 20 | #include "content/public/browser/browser_thread.h" |
| 21 | #include "content/public/browser/pepper_flash_settings_helper.h" |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 22 | #include "content/public/browser/plugin_service.h" |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 23 | #include "content/public/common/content_constants.h" |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 24 | #include "googleurl/src/gurl.h" |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 25 | #include "ipc/ipc_channel.h" |
| 26 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 27 | #include "webkit/plugins/plugin_constants.h" |
| 28 | #include "webkit/plugins/webplugininfo.h" |
| 29 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 30 | using content::BrowserThread; |
| 31 | |
| 32 | class PepperFlashSettingsManager::Core |
[email protected] | b44f8ad | 2012-06-15 20:52:58 | [diff] [blame] | 33 | : public IPC::Listener, |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 34 | public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> { |
| 35 | public: |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 36 | Core(base::WeakPtr<PepperFlashSettingsManager> manager, |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 37 | content::BrowserContext* browser_context); |
| 38 | |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 39 | void Initialize(); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 40 | |
| 41 | // Notifies the core that it has been detached. Afterwards, no method should |
| 42 | // be called any more. |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 43 | void Detach(); |
| 44 | |
| 45 | void DeauthorizeContentLicenses(uint32 request_id); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 46 | void GetPermissionSettings( |
| 47 | uint32 request_id, |
| 48 | PP_Flash_BrowserOperations_SettingType setting_type); |
| 49 | void SetDefaultPermission( |
| 50 | uint32 request_id, |
| 51 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 52 | PP_Flash_BrowserOperations_Permission permission, |
| 53 | bool clear_site_specific); |
| 54 | void SetSitePermission(uint32 request_id, |
| 55 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 56 | const ppapi::FlashSiteSettings& sites); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 57 | void GetSitesWithData(uint32 request_id); |
| 58 | void ClearSiteData(uint32 request_id, |
| 59 | const std::string& site, |
| 60 | uint64 flags, |
| 61 | uint64 max_age); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 62 | |
[email protected] | b44f8ad | 2012-06-15 20:52:58 | [diff] [blame] | 63 | // IPC::Listener implementation. |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 64 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 65 | virtual void OnChannelError() OVERRIDE; |
| 66 | |
| 67 | private: |
| 68 | friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 69 | friend class base::DeleteHelper<Core>; |
| 70 | |
| 71 | enum RequestType { |
| 72 | INVALID_REQUEST_TYPE = 0, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 73 | DEAUTHORIZE_CONTENT_LICENSES, |
| 74 | GET_PERMISSION_SETTINGS, |
| 75 | SET_DEFAULT_PERMISSION, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 76 | SET_SITE_PERMISSION, |
| 77 | GET_SITES_WITH_DATA, |
| 78 | CLEAR_SITE_DATA, |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 79 | }; |
| 80 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 81 | enum State { |
| 82 | STATE_UNINITIALIZED = 0, |
| 83 | STATE_INITIALIZED, |
| 84 | STATE_ERROR, |
| 85 | STATE_DETACHED, |
| 86 | }; |
| 87 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 88 | struct PendingRequest { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 89 | PendingRequest() |
| 90 | : id(0), |
| 91 | type(INVALID_REQUEST_TYPE), |
| 92 | setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC), |
| 93 | permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT), |
[email protected] | 3695fe3 | 2012-08-03 01:55:59 | [diff] [blame] | 94 | clear_site_specific(false), |
| 95 | flags(0), |
| 96 | max_age(0) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 97 | } |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 98 | |
| 99 | uint32 id; |
| 100 | RequestType type; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 101 | |
| 102 | // Used by GET_PERMISSION_SETTINGS, SET_DEFAULT_PERMISSION and |
| 103 | // SET_SITE_PERMISSION. |
| 104 | PP_Flash_BrowserOperations_SettingType setting_type; |
| 105 | |
| 106 | // Used by SET_DEFAULT_PERMISSION. |
| 107 | PP_Flash_BrowserOperations_Permission permission; |
| 108 | bool clear_site_specific; |
| 109 | |
| 110 | // Used by SET_SITE_PERMISSION. |
| 111 | ppapi::FlashSiteSettings sites; |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 112 | |
| 113 | // Used by CLEAR_SITE_DATA |
| 114 | std::string site; |
| 115 | uint64 flags; |
| 116 | uint64 max_age; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | virtual ~Core(); |
| 120 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 121 | void ConnectToChannel(bool success, const IPC::ChannelHandle& handle); |
| 122 | |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 123 | void InitializeOnIOThread(); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 124 | void DeauthorizeContentLicensesOnIOThread(uint32 request_id); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 125 | void GetPermissionSettingsOnIOThread( |
| 126 | uint32 request_id, |
| 127 | PP_Flash_BrowserOperations_SettingType setting_type); |
| 128 | void SetDefaultPermissionOnIOThread( |
| 129 | uint32 request_id, |
| 130 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 131 | PP_Flash_BrowserOperations_Permission permission, |
| 132 | bool clear_site_specific); |
| 133 | void SetSitePermissionOnIOThread( |
| 134 | uint32 request_id, |
| 135 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 136 | const ppapi::FlashSiteSettings& sites); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 137 | void GetSitesWithDataOnIOThread(uint32 request_id); |
| 138 | void ClearSiteDataOnIOThread(uint32 request_id, |
| 139 | const std::string& site, |
| 140 | uint64 flags, |
| 141 | uint64 max_age); |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 142 | void DetachOnIOThread(); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 143 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 144 | void NotifyErrorFromIOThread(); |
| 145 | |
| 146 | void NotifyDeauthorizeContentLicensesCompleted(uint32 request_id, |
| 147 | bool success); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 148 | void NotifyGetPermissionSettingsCompleted( |
| 149 | uint32 request_id, |
| 150 | bool success, |
| 151 | PP_Flash_BrowserOperations_Permission default_permission, |
| 152 | const ppapi::FlashSiteSettings& sites); |
| 153 | void NotifySetDefaultPermissionCompleted(uint32 request_id, bool success); |
| 154 | void NotifySetSitePermissionCompleted(uint32 request_id, bool success); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 155 | void NotifyGetSitesWithDataCompleted(uint32 request_id, |
| 156 | const std::vector<std::string>& sites); |
| 157 | void NotifyClearSiteDataCompleted(uint32 request_id, bool success); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 158 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 159 | void NotifyError( |
| 160 | const std::vector<std::pair<uint32, RequestType> >& notifications); |
| 161 | |
| 162 | // Message handlers. |
| 163 | void OnDeauthorizeContentLicensesResult(uint32 request_id, bool success); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 164 | void OnGetPermissionSettingsResult( |
| 165 | uint32 request_id, |
| 166 | bool success, |
| 167 | PP_Flash_BrowserOperations_Permission default_permission, |
| 168 | const ppapi::FlashSiteSettings& sites); |
| 169 | void OnSetDefaultPermissionResult(uint32 request_id, bool success); |
| 170 | void OnSetSitePermissionResult(uint32 request_id, bool success); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 171 | void OnGetSitesWithDataResult(uint32 request_id, |
| 172 | const std::vector<std::string>& sites); |
| 173 | void OnClearSiteDataResult(uint32 request_id, bool success); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 174 | |
| 175 | // Used only on the UI thread. |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 176 | base::WeakPtr<PepperFlashSettingsManager> manager_; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 177 | |
| 178 | // Used only on the I/O thread. |
| 179 | FilePath plugin_data_path_; |
| 180 | |
| 181 | // The channel is NULL until we have opened a connection to the broker |
| 182 | // process. Used only on the I/O thread. |
| 183 | scoped_ptr<IPC::Channel> channel_; |
| 184 | |
| 185 | // Used only on the I/O thread. |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 186 | State state_; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 187 | |
| 188 | // Requests that need to be sent once the channel to the broker process is |
| 189 | // established. Used only on the I/O thread. |
| 190 | std::vector<PendingRequest> pending_requests_; |
| 191 | // Requests that have been sent but haven't got replied. Used only on the |
| 192 | // I/O thread. |
| 193 | std::map<uint32, RequestType> pending_responses_; |
| 194 | |
| 195 | // Used only on the I/O thread. |
| 196 | scoped_refptr<content::PepperFlashSettingsHelper> helper_; |
| 197 | |
| 198 | // Path for the current profile. Must be retrieved on the UI thread from the |
| 199 | // browser context when we start so we can use it later on the I/O thread. |
| 200 | FilePath browser_context_path_; |
| 201 | |
| 202 | scoped_refptr<PluginPrefs> plugin_prefs_; |
| 203 | }; |
| 204 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 205 | PepperFlashSettingsManager::Core::Core( |
| 206 | base::WeakPtr<PepperFlashSettingsManager> manager, |
| 207 | content::BrowserContext* browser_context) |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 208 | : manager_(manager), |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 209 | state_(STATE_UNINITIALIZED), |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 210 | browser_context_path_(browser_context->GetPath()), |
| 211 | plugin_prefs_(PluginPrefs::GetForProfile( |
| 212 | Profile::FromBrowserContext(browser_context))) { |
| 213 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | PepperFlashSettingsManager::Core::~Core() { |
| 217 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 218 | } |
| 219 | |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 220 | void PepperFlashSettingsManager::Core::Initialize() { |
| 221 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 222 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 223 | base::Bind(&Core::InitializeOnIOThread, this)); |
| 224 | } |
| 225 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 226 | void PepperFlashSettingsManager::Core::Detach() { |
| 227 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 228 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 229 | // This call guarantees that one ref is retained until we get to the DETACHED |
| 230 | // state. This is important. Otherwise, if the ref count drops to zero on the |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 231 | // UI thread (which posts a task to delete this object on the I/O thread) |
| 232 | // while the I/O thread doesn't know about it, methods on the I/O thread might |
| 233 | // increase the ref count again and cause double deletion. |
| 234 | BrowserThread::PostTask( |
| 235 | BrowserThread::IO, FROM_HERE, base::Bind(&Core::DetachOnIOThread, this)); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses( |
| 239 | uint32 request_id) { |
| 240 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 241 | |
| 242 | BrowserThread::PostTask( |
| 243 | BrowserThread::IO, FROM_HERE, |
| 244 | base::Bind(&Core::DeauthorizeContentLicensesOnIOThread, this, |
| 245 | request_id)); |
| 246 | } |
| 247 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 248 | void PepperFlashSettingsManager::Core::GetPermissionSettings( |
| 249 | uint32 request_id, |
| 250 | PP_Flash_BrowserOperations_SettingType setting_type) { |
| 251 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 252 | |
| 253 | BrowserThread::PostTask( |
| 254 | BrowserThread::IO, FROM_HERE, |
| 255 | base::Bind(&Core::GetPermissionSettingsOnIOThread, this, request_id, |
| 256 | setting_type)); |
| 257 | } |
| 258 | |
| 259 | void PepperFlashSettingsManager::Core::SetDefaultPermission( |
| 260 | uint32 request_id, |
| 261 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 262 | PP_Flash_BrowserOperations_Permission permission, |
| 263 | bool clear_site_specific) { |
| 264 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 265 | |
| 266 | BrowserThread::PostTask( |
| 267 | BrowserThread::IO, FROM_HERE, |
| 268 | base::Bind(&Core::SetDefaultPermissionOnIOThread, this, request_id, |
| 269 | setting_type, permission, clear_site_specific)); |
| 270 | } |
| 271 | |
| 272 | void PepperFlashSettingsManager::Core::SetSitePermission( |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 273 | uint32 request_id, |
| 274 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 275 | const ppapi::FlashSiteSettings& sites) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 276 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 277 | |
| 278 | BrowserThread::PostTask( |
| 279 | BrowserThread::IO, FROM_HERE, |
| 280 | base::Bind(&Core::SetSitePermissionOnIOThread, this, request_id, |
| 281 | setting_type, sites)); |
| 282 | } |
| 283 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 284 | void PepperFlashSettingsManager::Core::GetSitesWithData(uint32 request_id) { |
| 285 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 286 | |
| 287 | BrowserThread::PostTask( |
| 288 | BrowserThread::IO, FROM_HERE, |
| 289 | base::Bind(&Core::GetSitesWithDataOnIOThread, this, request_id)); |
| 290 | } |
| 291 | |
| 292 | void PepperFlashSettingsManager::Core::ClearSiteData(uint32 request_id, |
| 293 | const std::string& site, |
| 294 | uint64 flags, |
| 295 | uint64 max_age) { |
| 296 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 297 | |
| 298 | BrowserThread::PostTask( |
| 299 | BrowserThread::IO, FROM_HERE, |
| 300 | base::Bind(&Core::ClearSiteDataOnIOThread, this, request_id, |
| 301 | site, flags, max_age)); |
| 302 | } |
| 303 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 304 | bool PepperFlashSettingsManager::Core::OnMessageReceived( |
| 305 | const IPC::Message& message) { |
| 306 | IPC_BEGIN_MESSAGE_MAP(Core, message) |
| 307 | IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult, |
| 308 | OnDeauthorizeContentLicensesResult) |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 309 | IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult, |
| 310 | OnGetPermissionSettingsResult) |
| 311 | IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult, |
| 312 | OnSetDefaultPermissionResult) |
| 313 | IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult, |
| 314 | OnSetSitePermissionResult) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 315 | IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult, |
| 316 | OnGetSitesWithDataResult) |
| 317 | IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult, |
| 318 | OnClearSiteDataResult) |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 319 | IPC_MESSAGE_UNHANDLED_ERROR() |
| 320 | IPC_END_MESSAGE_MAP() |
| 321 | |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | void PepperFlashSettingsManager::Core::OnChannelError() { |
| 326 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 327 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 328 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 329 | |
| 330 | NotifyErrorFromIOThread(); |
| 331 | } |
| 332 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 333 | void PepperFlashSettingsManager::Core::ConnectToChannel( |
| 334 | bool success, |
| 335 | const IPC::ChannelHandle& handle) { |
| 336 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 337 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 338 | return; |
| 339 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 340 | DCHECK(state_ == STATE_UNINITIALIZED); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 341 | DCHECK(!channel_.get()); |
| 342 | |
| 343 | if (!success) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 344 | DLOG(ERROR) << "Couldn't open plugin channel"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 345 | NotifyErrorFromIOThread(); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this)); |
| 350 | if (!channel_->Connect()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 351 | DLOG(ERROR) << "Couldn't connect to plugin"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 352 | NotifyErrorFromIOThread(); |
| 353 | return; |
| 354 | } |
| 355 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 356 | state_ = STATE_INITIALIZED; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 357 | |
| 358 | std::vector<PendingRequest> temp_pending_requests; |
| 359 | temp_pending_requests.swap(pending_requests_); |
| 360 | for (std::vector<PendingRequest>::iterator iter = |
| 361 | temp_pending_requests.begin(); |
| 362 | iter != temp_pending_requests.end(); ++iter) { |
| 363 | switch (iter->type) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 364 | case INVALID_REQUEST_TYPE: |
| 365 | NOTREACHED(); |
| 366 | break; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 367 | case DEAUTHORIZE_CONTENT_LICENSES: |
| 368 | DeauthorizeContentLicensesOnIOThread(iter->id); |
| 369 | break; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 370 | case GET_PERMISSION_SETTINGS: |
| 371 | GetPermissionSettingsOnIOThread(iter->id, iter->setting_type); |
| 372 | break; |
| 373 | case SET_DEFAULT_PERMISSION: |
| 374 | SetDefaultPermissionOnIOThread( |
| 375 | iter->id, iter->setting_type, iter->permission, |
| 376 | iter->clear_site_specific); |
| 377 | break; |
| 378 | case SET_SITE_PERMISSION: |
| 379 | SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites); |
| 380 | break; |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 381 | case GET_SITES_WITH_DATA: |
| 382 | GetSitesWithDataOnIOThread(iter->id); |
| 383 | break; |
| 384 | case CLEAR_SITE_DATA: |
| 385 | ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags, |
| 386 | iter->max_age); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 387 | break; |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 392 | void PepperFlashSettingsManager::Core::InitializeOnIOThread() { |
| 393 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 394 | DCHECK_EQ(STATE_UNINITIALIZED, state_); |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 395 | |
| 396 | webkit::WebPluginInfo plugin_info; |
| 397 | if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(), |
| 398 | &plugin_info)) { |
| 399 | NotifyErrorFromIOThread(); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | FilePath profile_path = |
| 404 | browser_context_path_.Append(content::kPepperDataDirname); |
| 405 | #if defined(OS_WIN) |
| 406 | plugin_data_path_ = profile_path.Append(plugin_info.name); |
| 407 | #else |
| 408 | plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name)); |
| 409 | #endif |
| 410 | |
| 411 | helper_ = content::PepperFlashSettingsHelper::Create(); |
| 412 | content::PepperFlashSettingsHelper::OpenChannelCallback callback = |
| 413 | base::Bind(&Core::ConnectToChannel, this); |
| 414 | helper_->OpenChannelToBroker(plugin_info.path, callback); |
| 415 | } |
| 416 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 417 | void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread( |
| 418 | uint32 request_id) { |
| 419 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 420 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 421 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 422 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 423 | PendingRequest request; |
| 424 | request.id = request_id; |
| 425 | request.type = DEAUTHORIZE_CONTENT_LICENSES; |
| 426 | pending_requests_.push_back(request); |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | pending_responses_.insert( |
| 431 | std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 432 | if (state_ == STATE_ERROR) { |
| 433 | NotifyErrorFromIOThread(); |
| 434 | return; |
| 435 | } |
| 436 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 437 | IPC::Message* msg = |
| 438 | new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_); |
| 439 | if (!channel_->Send(msg)) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 440 | DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message"; |
| 441 | // A failure notification for the current request will be sent since |
| 442 | // |pending_responses_| has been updated. |
| 443 | NotifyErrorFromIOThread(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread( |
| 448 | uint32 request_id, |
| 449 | PP_Flash_BrowserOperations_SettingType setting_type) { |
| 450 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 451 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 452 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 453 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 454 | PendingRequest request; |
| 455 | request.id = request_id; |
| 456 | request.type = GET_PERMISSION_SETTINGS; |
| 457 | request.setting_type = setting_type; |
| 458 | pending_requests_.push_back(request); |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | pending_responses_.insert( |
| 463 | std::make_pair(request_id, GET_PERMISSION_SETTINGS)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 464 | if (state_ == STATE_ERROR) { |
| 465 | NotifyErrorFromIOThread(); |
| 466 | return; |
| 467 | } |
| 468 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 469 | IPC::Message* msg = new PpapiMsg_GetPermissionSettings( |
| 470 | request_id, plugin_data_path_, setting_type); |
| 471 | if (!channel_->Send(msg)) { |
| 472 | DLOG(ERROR) << "Couldn't send GetPermissionSettings message"; |
| 473 | // A failure notification for the current request will be sent since |
| 474 | // |pending_responses_| has been updated. |
| 475 | NotifyErrorFromIOThread(); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread( |
| 480 | uint32 request_id, |
| 481 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 482 | PP_Flash_BrowserOperations_Permission permission, |
| 483 | bool clear_site_specific) { |
| 484 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 485 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 486 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 487 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 488 | PendingRequest request; |
| 489 | request.id = request_id; |
| 490 | request.type = SET_DEFAULT_PERMISSION; |
| 491 | request.setting_type = setting_type; |
| 492 | request.permission = permission; |
| 493 | request.clear_site_specific = clear_site_specific; |
| 494 | pending_requests_.push_back(request); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 499 | if (state_ == STATE_ERROR) { |
| 500 | NotifyErrorFromIOThread(); |
| 501 | return; |
| 502 | } |
| 503 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 504 | IPC::Message* msg = new PpapiMsg_SetDefaultPermission( |
| 505 | request_id, plugin_data_path_, setting_type, permission, |
| 506 | clear_site_specific); |
| 507 | if (!channel_->Send(msg)) { |
| 508 | DLOG(ERROR) << "Couldn't send SetDefaultPermission message"; |
| 509 | // A failure notification for the current request will be sent since |
| 510 | // |pending_responses_| has been updated. |
| 511 | NotifyErrorFromIOThread(); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread( |
| 516 | uint32 request_id, |
| 517 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 518 | const ppapi::FlashSiteSettings& sites) { |
| 519 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 520 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 521 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 522 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 523 | pending_requests_.push_back(PendingRequest()); |
| 524 | PendingRequest& request = pending_requests_.back(); |
| 525 | request.id = request_id; |
| 526 | request.type = SET_SITE_PERMISSION; |
| 527 | request.setting_type = setting_type; |
| 528 | request.sites = sites; |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 533 | if (state_ == STATE_ERROR) { |
| 534 | NotifyErrorFromIOThread(); |
| 535 | return; |
| 536 | } |
| 537 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 538 | IPC::Message* msg = new PpapiMsg_SetSitePermission( |
| 539 | request_id, plugin_data_path_, setting_type, sites); |
| 540 | if (!channel_->Send(msg)) { |
| 541 | DLOG(ERROR) << "Couldn't send SetSitePermission message"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 542 | // A failure notification for the current request will be sent since |
| 543 | // |pending_responses_| has been updated. |
| 544 | NotifyErrorFromIOThread(); |
| 545 | } |
| 546 | } |
| 547 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 548 | void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread( |
| 549 | uint32 request_id) { |
| 550 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 551 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 552 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 553 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 554 | pending_requests_.push_back(PendingRequest()); |
| 555 | PendingRequest& request = pending_requests_.back(); |
| 556 | request.id = request_id; |
| 557 | request.type = GET_SITES_WITH_DATA; |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 562 | if (state_ == STATE_ERROR) { |
| 563 | NotifyErrorFromIOThread(); |
| 564 | return; |
| 565 | } |
| 566 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 567 | IPC::Message* msg = new PpapiMsg_GetSitesWithData( |
| 568 | request_id, plugin_data_path_); |
| 569 | if (!channel_->Send(msg)) { |
| 570 | DLOG(ERROR) << "Couldn't send GetSitesWithData message"; |
| 571 | // A failure notification for the current request will be sent since |
| 572 | // |pending_responses_| has been updated. |
| 573 | NotifyErrorFromIOThread(); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread( |
| 578 | uint32 request_id, |
| 579 | const std::string& site, |
| 580 | uint64 flags, |
| 581 | uint64 max_age) { |
| 582 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 583 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 584 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 585 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 586 | pending_requests_.push_back(PendingRequest()); |
| 587 | PendingRequest& request = pending_requests_.back(); |
| 588 | request.id = request_id; |
| 589 | request.type = CLEAR_SITE_DATA; |
| 590 | request.site = site; |
| 591 | request.flags = flags; |
| 592 | request.max_age = max_age; |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 597 | if (state_ == STATE_ERROR) { |
| 598 | NotifyErrorFromIOThread(); |
| 599 | return; |
| 600 | } |
| 601 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 602 | IPC::Message* msg = new PpapiMsg_ClearSiteData( |
| 603 | request_id, plugin_data_path_, site, flags, max_age); |
| 604 | if (!channel_->Send(msg)) { |
| 605 | DLOG(ERROR) << "Couldn't send ClearSiteData message"; |
| 606 | // A failure notification for the current request will be sent since |
| 607 | // |pending_responses_| has been updated. |
| 608 | NotifyErrorFromIOThread(); |
| 609 | } |
| 610 | } |
| 611 | |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 612 | void PepperFlashSettingsManager::Core::DetachOnIOThread() { |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 613 | state_ = STATE_DETACHED; |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 614 | } |
| 615 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 616 | void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() { |
| 617 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 618 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 619 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 620 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 621 | state_ = STATE_ERROR; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 622 | std::vector<std::pair<uint32, RequestType> > notifications; |
| 623 | for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin(); |
| 624 | iter != pending_requests_.end(); ++iter) { |
| 625 | notifications.push_back(std::make_pair(iter->id, iter->type)); |
| 626 | } |
| 627 | pending_requests_.clear(); |
| 628 | notifications.insert(notifications.end(), pending_responses_.begin(), |
| 629 | pending_responses_.end()); |
| 630 | pending_responses_.clear(); |
| 631 | |
| 632 | BrowserThread::PostTask( |
| 633 | BrowserThread::UI, FROM_HERE, |
| 634 | base::Bind(&Core::NotifyError, this, notifications)); |
| 635 | } |
| 636 | |
| 637 | void |
| 638 | PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted( |
| 639 | uint32 request_id, |
| 640 | bool success) { |
| 641 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 642 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 643 | if (manager_.get()) { |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 644 | manager_->client_->OnDeauthorizeContentLicensesCompleted( |
| 645 | request_id, success); |
| 646 | } |
| 647 | } |
| 648 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 649 | void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted( |
| 650 | uint32 request_id, |
| 651 | bool success, |
| 652 | PP_Flash_BrowserOperations_Permission default_permission, |
| 653 | const ppapi::FlashSiteSettings& sites) { |
| 654 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 655 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 656 | if (manager_.get()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 657 | manager_->client_->OnGetPermissionSettingsCompleted( |
| 658 | request_id, success, default_permission, sites); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted( |
| 663 | uint32 request_id, |
| 664 | bool success) { |
| 665 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 666 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 667 | if (manager_.get()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 668 | manager_->client_->OnSetDefaultPermissionCompleted( |
| 669 | request_id, success); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted( |
| 674 | uint32 request_id, |
| 675 | bool success) { |
| 676 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 677 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 678 | if (manager_.get()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 679 | manager_->client_->OnSetSitePermissionCompleted( |
| 680 | request_id, success); |
| 681 | } |
| 682 | } |
| 683 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 684 | void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted( |
| 685 | uint32 request_id, |
| 686 | const std::vector<std::string>& sites) { |
| 687 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 688 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 689 | if (manager_.get()) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 690 | manager_->client_->OnGetSitesWithDataCompleted( |
| 691 | request_id, sites); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted( |
| 696 | uint32 request_id, |
| 697 | bool success) { |
| 698 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 699 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 700 | if (manager_.get()) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 701 | manager_->client_->OnClearSiteDataCompleted(request_id, success); |
| 702 | } |
| 703 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 704 | void PepperFlashSettingsManager::Core::NotifyError( |
| 705 | const std::vector<std::pair<uint32, RequestType> >& notifications) { |
| 706 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 707 | |
| 708 | scoped_refptr<Core> protector(this); |
| 709 | for (std::vector<std::pair<uint32, RequestType> >::const_iterator iter = |
| 710 | notifications.begin(); iter != notifications.end(); ++iter) { |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 711 | // Check |manager_| for each iteration in case it is destroyed in one of |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 712 | // the callbacks. |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 713 | if (!manager_.get()) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 714 | return; |
| 715 | |
| 716 | switch (iter->second) { |
| 717 | case INVALID_REQUEST_TYPE: |
| 718 | NOTREACHED(); |
| 719 | break; |
| 720 | case DEAUTHORIZE_CONTENT_LICENSES: |
| 721 | manager_->client_->OnDeauthorizeContentLicensesCompleted( |
| 722 | iter->first, false); |
| 723 | break; |
| 724 | case GET_PERMISSION_SETTINGS: |
| 725 | manager_->client_->OnGetPermissionSettingsCompleted( |
| 726 | iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, |
| 727 | ppapi::FlashSiteSettings()); |
| 728 | break; |
| 729 | case SET_DEFAULT_PERMISSION: |
| 730 | manager_->client_->OnSetDefaultPermissionCompleted( |
| 731 | iter->first, false); |
| 732 | break; |
| 733 | case SET_SITE_PERMISSION: |
| 734 | manager_->client_->OnSetSitePermissionCompleted(iter->first, false); |
| 735 | break; |
| 736 | case GET_SITES_WITH_DATA: |
| 737 | manager_->client_->OnGetSitesWithDataCompleted( |
| 738 | iter->first, std::vector<std::string>()); |
| 739 | break; |
| 740 | case CLEAR_SITE_DATA: |
| 741 | manager_->client_->OnClearSiteDataCompleted(iter->first, false); |
| 742 | break; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 746 | if (manager_.get()) |
| 747 | manager_->OnError(this); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult( |
| 751 | uint32 request_id, |
| 752 | bool success) { |
| 753 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 754 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 755 | return; |
| 756 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 757 | DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 758 | |
| 759 | std::map<uint32, RequestType>::iterator iter = |
| 760 | pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 761 | if (iter == pending_responses_.end()) |
| 762 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 763 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 764 | DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES); |
| 765 | |
| 766 | pending_responses_.erase(iter); |
| 767 | BrowserThread::PostTask( |
| 768 | BrowserThread::UI, FROM_HERE, |
| 769 | base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this, |
| 770 | request_id, success)); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 771 | } |
| 772 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 773 | void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult( |
| 774 | uint32 request_id, |
| 775 | bool success, |
| 776 | PP_Flash_BrowserOperations_Permission default_permission, |
| 777 | const ppapi::FlashSiteSettings& sites) { |
| 778 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 779 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 780 | return; |
| 781 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 782 | DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error"; |
| 783 | |
| 784 | std::map<uint32, RequestType>::iterator iter = |
| 785 | pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 786 | if (iter == pending_responses_.end()) |
| 787 | return; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 788 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 789 | DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS); |
| 790 | |
| 791 | pending_responses_.erase(iter); |
| 792 | BrowserThread::PostTask( |
| 793 | BrowserThread::UI, FROM_HERE, |
| 794 | base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this, |
| 795 | request_id, success, default_permission, sites)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult( |
| 799 | uint32 request_id, |
| 800 | bool success) { |
| 801 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 802 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 803 | return; |
| 804 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 805 | DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error"; |
| 806 | |
| 807 | std::map<uint32, RequestType>::iterator iter = |
| 808 | pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 809 | if (iter == pending_responses_.end()) |
| 810 | return; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 811 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 812 | DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION); |
| 813 | |
| 814 | pending_responses_.erase(iter); |
| 815 | BrowserThread::PostTask( |
| 816 | BrowserThread::UI, FROM_HERE, |
| 817 | base::Bind(&Core::NotifySetDefaultPermissionCompleted, this, |
| 818 | request_id, success)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | void PepperFlashSettingsManager::Core::OnSetSitePermissionResult( |
| 822 | uint32 request_id, |
| 823 | bool success) { |
| 824 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 825 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 826 | return; |
| 827 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 828 | DLOG_IF(ERROR, !success) << "SetSitePermission returned error"; |
| 829 | |
| 830 | std::map<uint32, RequestType>::iterator iter = |
| 831 | pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 832 | if (iter == pending_responses_.end()) |
| 833 | return; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 834 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 835 | DCHECK_EQ(iter->second, SET_SITE_PERMISSION); |
| 836 | |
| 837 | pending_responses_.erase(iter); |
| 838 | BrowserThread::PostTask( |
| 839 | BrowserThread::UI, FROM_HERE, |
| 840 | base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id, |
| 841 | success)); |
| 842 | } |
| 843 | |
| 844 | void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult( |
| 845 | uint32 request_id, |
| 846 | const std::vector<std::string>& sites) { |
| 847 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 848 | if (state_ == STATE_DETACHED) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 849 | return; |
| 850 | |
| 851 | std::map<uint32, RequestType>::iterator iter = |
| 852 | pending_responses_.find(request_id); |
| 853 | if (iter == pending_responses_.end()) |
| 854 | return; |
| 855 | |
| 856 | DCHECK_EQ(iter->second, GET_SITES_WITH_DATA); |
| 857 | |
| 858 | pending_responses_.erase(iter); |
| 859 | BrowserThread::PostTask( |
| 860 | BrowserThread::UI, FROM_HERE, |
| 861 | base::Bind(&Core::NotifyGetSitesWithDataCompleted, this, request_id, |
| 862 | sites)); |
| 863 | } |
| 864 | |
| 865 | void PepperFlashSettingsManager::Core::OnClearSiteDataResult( |
| 866 | uint32 request_id, |
| 867 | bool success) { |
| 868 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 869 | if (state_ == STATE_DETACHED) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 870 | return; |
| 871 | |
| 872 | DLOG_IF(ERROR, !success) << "ClearSiteData returned error"; |
| 873 | |
| 874 | std::map<uint32, RequestType>::iterator iter = |
| 875 | pending_responses_.find(request_id); |
| 876 | if (iter == pending_responses_.end()) |
| 877 | return; |
| 878 | |
| 879 | DCHECK_EQ(iter->second, CLEAR_SITE_DATA); |
| 880 | |
| 881 | pending_responses_.erase(iter); |
| 882 | BrowserThread::PostTask( |
| 883 | BrowserThread::UI, FROM_HERE, |
| 884 | base::Bind(&Core::NotifyClearSiteDataCompleted, this, request_id, |
| 885 | success)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 886 | } |
| 887 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 888 | PepperFlashSettingsManager::PepperFlashSettingsManager( |
| 889 | Client* client, |
| 890 | content::BrowserContext* browser_context) |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 891 | : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 892 | client_(client), |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 893 | browser_context_(browser_context), |
| 894 | next_request_id_(1) { |
| 895 | DCHECK(client); |
| 896 | DCHECK(browser_context); |
| 897 | } |
| 898 | |
| 899 | PepperFlashSettingsManager::~PepperFlashSettingsManager() { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 900 | if (core_.get()) |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 901 | core_->Detach(); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 902 | } |
| 903 | |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 904 | // static |
| 905 | bool PepperFlashSettingsManager::IsPepperFlashInUse( |
| 906 | PluginPrefs* plugin_prefs, |
| 907 | webkit::WebPluginInfo* plugin_info) { |
| 908 | if (!plugin_prefs) |
| 909 | return false; |
| 910 | |
| 911 | content::PluginService* plugin_service = |
| 912 | content::PluginService::GetInstance(); |
| 913 | std::vector<webkit::WebPluginInfo> plugins; |
| 914 | plugin_service->GetPluginInfoArray( |
| 915 | GURL(), kFlashPluginSwfMimeType, false, &plugins, NULL); |
| 916 | |
| 917 | for (std::vector<webkit::WebPluginInfo>::iterator iter = plugins.begin(); |
| 918 | iter != plugins.end(); ++iter) { |
| 919 | if (webkit::IsPepperPlugin(*iter) && plugin_prefs->IsPluginEnabled(*iter)) { |
| 920 | if (plugin_info) |
| 921 | *plugin_info = *iter; |
| 922 | return true; |
| 923 | } |
| 924 | } |
| 925 | return false; |
| 926 | } |
| 927 | |
| 928 | // static |
| 929 | void PepperFlashSettingsManager::RegisterUserPrefs(PrefService* prefs) { |
| 930 | prefs->RegisterBooleanPref(prefs::kDeauthorizeContentLicenses, |
| 931 | false, |
| 932 | PrefService::UNSYNCABLE_PREF); |
| 933 | |
| 934 | prefs->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, |
| 935 | true, |
| 936 | PrefService::UNSYNCABLE_PREF); |
| 937 | } |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 938 | |
| 939 | uint32 PepperFlashSettingsManager::DeauthorizeContentLicenses() { |
| 940 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 941 | |
| 942 | EnsureCoreExists(); |
| 943 | uint32 id = GetNextRequestId(); |
| 944 | core_->DeauthorizeContentLicenses(id); |
| 945 | return id; |
| 946 | } |
| 947 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 948 | uint32 PepperFlashSettingsManager::GetPermissionSettings( |
| 949 | PP_Flash_BrowserOperations_SettingType setting_type) { |
| 950 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 951 | |
| 952 | EnsureCoreExists(); |
| 953 | uint32 id = GetNextRequestId(); |
| 954 | core_->GetPermissionSettings(id, setting_type); |
| 955 | return id; |
| 956 | } |
| 957 | |
| 958 | uint32 PepperFlashSettingsManager::SetDefaultPermission( |
| 959 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 960 | PP_Flash_BrowserOperations_Permission permission, |
| 961 | bool clear_site_specific) { |
| 962 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 963 | |
| 964 | EnsureCoreExists(); |
| 965 | uint32 id = GetNextRequestId(); |
| 966 | core_->SetDefaultPermission(id, setting_type, permission, |
| 967 | clear_site_specific); |
| 968 | return id; |
| 969 | } |
| 970 | |
| 971 | uint32 PepperFlashSettingsManager::SetSitePermission( |
| 972 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 973 | const ppapi::FlashSiteSettings& sites) { |
| 974 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 975 | |
| 976 | EnsureCoreExists(); |
| 977 | uint32 id = GetNextRequestId(); |
| 978 | core_->SetSitePermission(id, setting_type, sites); |
| 979 | return id; |
| 980 | } |
| 981 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 982 | uint32 PepperFlashSettingsManager::GetSitesWithData() { |
| 983 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 984 | |
| 985 | EnsureCoreExists(); |
| 986 | uint32 id = GetNextRequestId(); |
| 987 | core_->GetSitesWithData(id); |
| 988 | return id; |
| 989 | } |
| 990 | |
| 991 | uint32 PepperFlashSettingsManager::ClearSiteData(const std::string& site, |
| 992 | uint64 flags, |
| 993 | uint64 max_age) { |
| 994 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 995 | |
| 996 | EnsureCoreExists(); |
| 997 | uint32 id = GetNextRequestId(); |
| 998 | core_->ClearSiteData(id, site, flags, max_age); |
| 999 | return id; |
| 1000 | } |
| 1001 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 1002 | uint32 PepperFlashSettingsManager::GetNextRequestId() { |
| 1003 | return next_request_id_++; |
| 1004 | } |
| 1005 | |
| 1006 | void PepperFlashSettingsManager::EnsureCoreExists() { |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 1007 | if (!core_.get()) { |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 1008 | core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_); |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 1009 | core_->Initialize(); |
| 1010 | } |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 1011 | } |
| 1012 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 1013 | void PepperFlashSettingsManager::OnError(Core* core) { |
| 1014 | DCHECK(core); |
| 1015 | if (core != core_.get()) |
| 1016 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 1017 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame^] | 1018 | core_->Detach(); |
| 1019 | core_ = NULL; |
| 1020 | } |