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