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