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