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