[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); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 230 | base::PostTaskWithTraits(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. |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 242 | base::PostTaskWithTraits(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 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 250 | base::PostTaskWithTraits( |
| 251 | FROM_HERE, {BrowserThread::IO}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 252 | base::BindOnce(&Core::DeauthorizeContentLicensesOnIOThread, this, |
| 253 | request_id)); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 254 | } |
| 255 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 256 | void PepperFlashSettingsManager::Core::GetPermissionSettings( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 257 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 258 | PP_Flash_BrowserOperations_SettingType setting_type) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 259 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 260 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 261 | base::PostTaskWithTraits( |
| 262 | FROM_HERE, {BrowserThread::IO}, |
| 263 | base::BindOnce(&Core::GetPermissionSettingsOnIOThread, this, request_id, |
| 264 | setting_type)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void PepperFlashSettingsManager::Core::SetDefaultPermission( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 268 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 269 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 270 | PP_Flash_BrowserOperations_Permission permission, |
| 271 | bool clear_site_specific) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 272 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 273 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 274 | base::PostTaskWithTraits( |
| 275 | FROM_HERE, {BrowserThread::IO}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 276 | base::BindOnce(&Core::SetDefaultPermissionOnIOThread, this, request_id, |
| 277 | setting_type, permission, clear_site_specific)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void PepperFlashSettingsManager::Core::SetSitePermission( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 281 | uint32_t request_id, |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 282 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 283 | const ppapi::FlashSiteSettings& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 284 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 285 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 286 | base::PostTaskWithTraits( |
| 287 | FROM_HERE, {BrowserThread::IO}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 288 | base::BindOnce(&Core::SetSitePermissionOnIOThread, this, request_id, |
| 289 | setting_type, sites)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 290 | } |
| 291 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 292 | void PepperFlashSettingsManager::Core::GetSitesWithData(uint32_t request_id) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 293 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 294 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 295 | base::PostTaskWithTraits( |
| 296 | FROM_HERE, {BrowserThread::IO}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 297 | base::BindOnce(&Core::GetSitesWithDataOnIOThread, this, request_id)); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 298 | } |
| 299 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 300 | void PepperFlashSettingsManager::Core::ClearSiteData(uint32_t request_id, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 301 | const std::string& site, |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 302 | uint64_t flags, |
| 303 | uint64_t max_age) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 304 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 305 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 306 | base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO}, |
| 307 | base::BindOnce(&Core::ClearSiteDataOnIOThread, this, |
| 308 | request_id, site, flags, max_age)); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 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 | |
Hajime Hoshi | fe3ecdc | 2017-11-28 03:34:13 | [diff] [blame] | 356 | channel_ = IPC::Channel::CreateClient(handle, this, |
| 357 | base::ThreadTaskRunnerHandle::Get()); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 358 | if (!channel_->Connect()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 359 | DLOG(ERROR) << "Couldn't connect to plugin"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 360 | NotifyErrorFromIOThread(); |
| 361 | return; |
| 362 | } |
| 363 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 364 | state_ = STATE_INITIALIZED; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 365 | |
| 366 | std::vector<PendingRequest> temp_pending_requests; |
| 367 | temp_pending_requests.swap(pending_requests_); |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 368 | for (auto iter = temp_pending_requests.begin(); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 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) |
kylechar | 99ef904 | 2019-02-25 18:09:43 | [diff] [blame] | 445 | base::PostTaskWithTraits( |
| 446 | FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, |
| 447 | base::BindOnce(&Core::DeauthorizeContentLicensesAsync, this, request_id, |
| 448 | browser_context_path_)); |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 449 | #else |
| 450 | DeauthorizeContentLicensesInPlugin(request_id, true); |
| 451 | #endif |
| 452 | } |
| 453 | |
| 454 | // TODO(raymes): This is temporary code to migrate ChromeOS devices to the new |
| 455 | // scheme for generating device IDs. Delete this once we are sure most ChromeOS |
| 456 | // devices have been migrated. |
fdoray | 5652bcd | 2017-02-07 16:03:54 | [diff] [blame] | 457 | void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesAsync( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 458 | uint32_t request_id, |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 459 | const base::FilePath& profile_path) { |
| 460 | // ChromeOS used to store the device ID in a file but this is no longer used. |
| 461 | // Wipe that file. |
| 462 | const base::FilePath& device_id_path = |
cm.sanchi | 4b71726 | 2017-11-20 08:02:40 | [diff] [blame] | 463 | DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 464 | bool success = base::DeleteFile(device_id_path, false); |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 465 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 466 | base::PostTaskWithTraits( |
| 467 | FROM_HERE, {BrowserThread::IO}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 468 | base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this, |
| 469 | request_id, success)); |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 473 | uint32_t request_id, |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 474 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 475 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 476 | if (!success) { |
| 477 | NotifyErrorFromIOThread(); |
| 478 | return; |
| 479 | } |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 480 | IPC::Message* msg = |
| 481 | new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_); |
| 482 | if (!channel_->Send(msg)) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 483 | DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message"; |
| 484 | // A failure notification for the current request will be sent since |
| 485 | // |pending_responses_| has been updated. |
| 486 | NotifyErrorFromIOThread(); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 491 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 492 | PP_Flash_BrowserOperations_SettingType setting_type) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 493 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 494 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 495 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 496 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 497 | PendingRequest request; |
| 498 | request.id = request_id; |
| 499 | request.type = GET_PERMISSION_SETTINGS; |
| 500 | request.setting_type = setting_type; |
| 501 | pending_requests_.push_back(request); |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | pending_responses_.insert( |
| 506 | std::make_pair(request_id, GET_PERMISSION_SETTINGS)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 507 | if (state_ == STATE_ERROR) { |
| 508 | NotifyErrorFromIOThread(); |
| 509 | return; |
| 510 | } |
| 511 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 512 | IPC::Message* msg = new PpapiMsg_GetPermissionSettings( |
| 513 | request_id, plugin_data_path_, setting_type); |
| 514 | if (!channel_->Send(msg)) { |
| 515 | DLOG(ERROR) << "Couldn't send GetPermissionSettings message"; |
| 516 | // A failure notification for the current request will be sent since |
| 517 | // |pending_responses_| has been updated. |
| 518 | NotifyErrorFromIOThread(); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 523 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 524 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 525 | PP_Flash_BrowserOperations_Permission permission, |
| 526 | bool clear_site_specific) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 527 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 528 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 529 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 530 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 531 | PendingRequest request; |
| 532 | request.id = request_id; |
| 533 | request.type = SET_DEFAULT_PERMISSION; |
| 534 | request.setting_type = setting_type; |
| 535 | request.permission = permission; |
| 536 | request.clear_site_specific = clear_site_specific; |
| 537 | pending_requests_.push_back(request); |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 542 | if (state_ == STATE_ERROR) { |
| 543 | NotifyErrorFromIOThread(); |
| 544 | return; |
| 545 | } |
| 546 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 547 | IPC::Message* msg = new PpapiMsg_SetDefaultPermission( |
| 548 | request_id, plugin_data_path_, setting_type, permission, |
| 549 | clear_site_specific); |
| 550 | if (!channel_->Send(msg)) { |
| 551 | DLOG(ERROR) << "Couldn't send SetDefaultPermission message"; |
| 552 | // A failure notification for the current request will be sent since |
| 553 | // |pending_responses_| has been updated. |
| 554 | NotifyErrorFromIOThread(); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 559 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 560 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 561 | const ppapi::FlashSiteSettings& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 562 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 563 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 564 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 565 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 566 | pending_requests_.push_back(PendingRequest()); |
| 567 | PendingRequest& request = pending_requests_.back(); |
| 568 | request.id = request_id; |
| 569 | request.type = SET_SITE_PERMISSION; |
| 570 | request.setting_type = setting_type; |
| 571 | request.sites = sites; |
| 572 | return; |
| 573 | } |
| 574 | |
| 575 | pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 576 | if (state_ == STATE_ERROR) { |
| 577 | NotifyErrorFromIOThread(); |
| 578 | return; |
| 579 | } |
| 580 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 581 | IPC::Message* msg = new PpapiMsg_SetSitePermission( |
| 582 | request_id, plugin_data_path_, setting_type, sites); |
| 583 | if (!channel_->Send(msg)) { |
| 584 | DLOG(ERROR) << "Couldn't send SetSitePermission message"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 585 | // A failure notification for the current request will be sent since |
| 586 | // |pending_responses_| has been updated. |
| 587 | NotifyErrorFromIOThread(); |
| 588 | } |
| 589 | } |
| 590 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 591 | void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 592 | uint32_t request_id) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 593 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 594 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 595 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 596 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 597 | pending_requests_.push_back(PendingRequest()); |
| 598 | PendingRequest& request = pending_requests_.back(); |
| 599 | request.id = request_id; |
| 600 | request.type = GET_SITES_WITH_DATA; |
| 601 | return; |
| 602 | } |
| 603 | |
| 604 | pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 605 | if (state_ == STATE_ERROR) { |
| 606 | NotifyErrorFromIOThread(); |
| 607 | return; |
| 608 | } |
| 609 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 610 | IPC::Message* msg = new PpapiMsg_GetSitesWithData( |
| 611 | request_id, plugin_data_path_); |
| 612 | if (!channel_->Send(msg)) { |
| 613 | DLOG(ERROR) << "Couldn't send GetSitesWithData message"; |
| 614 | // A failure notification for the current request will be sent since |
| 615 | // |pending_responses_| has been updated. |
| 616 | NotifyErrorFromIOThread(); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 621 | uint32_t request_id, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 622 | const std::string& site, |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 623 | uint64_t flags, |
| 624 | uint64_t max_age) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 625 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 626 | DCHECK_NE(STATE_DETACHED, state_); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 627 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 628 | if (state_ == STATE_UNINITIALIZED) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 629 | pending_requests_.push_back(PendingRequest()); |
| 630 | PendingRequest& request = pending_requests_.back(); |
| 631 | request.id = request_id; |
| 632 | request.type = CLEAR_SITE_DATA; |
| 633 | request.site = site; |
| 634 | request.flags = flags; |
| 635 | request.max_age = max_age; |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA)); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 640 | if (state_ == STATE_ERROR) { |
| 641 | NotifyErrorFromIOThread(); |
| 642 | return; |
| 643 | } |
| 644 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 645 | IPC::Message* msg = new PpapiMsg_ClearSiteData( |
| 646 | request_id, plugin_data_path_, site, flags, max_age); |
| 647 | if (!channel_->Send(msg)) { |
| 648 | DLOG(ERROR) << "Couldn't send ClearSiteData message"; |
| 649 | // A failure notification for the current request will be sent since |
| 650 | // |pending_responses_| has been updated. |
| 651 | NotifyErrorFromIOThread(); |
| 652 | } |
| 653 | } |
| 654 | |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 655 | void PepperFlashSettingsManager::Core::DetachOnIOThread() { |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 656 | state_ = STATE_DETACHED; |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 659 | void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 660 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 661 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 662 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 663 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 664 | state_ = STATE_ERROR; |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 665 | std::vector<std::pair<uint32_t, RequestType>> notifications; |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 666 | for (auto iter = pending_requests_.begin(); iter != pending_requests_.end(); |
| 667 | ++iter) { |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 668 | notifications.push_back(std::make_pair(iter->id, iter->type)); |
| 669 | } |
| 670 | pending_requests_.clear(); |
| 671 | notifications.insert(notifications.end(), pending_responses_.begin(), |
| 672 | pending_responses_.end()); |
| 673 | pending_responses_.clear(); |
| 674 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 675 | base::PostTaskWithTraits( |
| 676 | FROM_HERE, {BrowserThread::UI}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 677 | base::BindOnce(&Core::NotifyError, this, notifications)); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 678 | } |
| 679 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 680 | void PepperFlashSettingsManager::Core:: |
| 681 | NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id, |
| 682 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 683 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 684 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 685 | if (manager_.get()) { |
jrummell | bffd0124 | 2016-06-30 00:30:37 | [diff] [blame] | 686 | manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(request_id, |
| 687 | success); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 691 | void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 692 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 693 | bool success, |
| 694 | PP_Flash_BrowserOperations_Permission default_permission, |
| 695 | const ppapi::FlashSiteSettings& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 696 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 697 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 698 | if (manager_.get()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 699 | manager_->client_->OnGetPermissionSettingsCompleted( |
| 700 | request_id, success, default_permission, sites); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 705 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 706 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 707 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 708 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 709 | if (manager_.get()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 710 | manager_->client_->OnSetDefaultPermissionCompleted( |
| 711 | request_id, success); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 716 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 717 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 718 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 719 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 720 | if (manager_.get()) { |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 721 | manager_->client_->OnSetSitePermissionCompleted( |
| 722 | request_id, success); |
| 723 | } |
| 724 | } |
| 725 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 726 | void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 727 | uint32_t request_id, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 728 | const std::vector<std::string>& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 729 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 730 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 731 | if (manager_.get()) { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 732 | manager_->client_->OnGetSitesWithDataCompleted( |
| 733 | request_id, sites); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 738 | uint32_t request_id, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 739 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 740 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 741 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 742 | if (manager_.get()) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 743 | manager_->client_->OnClearSiteDataCompleted(request_id, success); |
| 744 | } |
| 745 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 746 | void PepperFlashSettingsManager::Core::NotifyError( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 747 | const std::vector<std::pair<uint32_t, RequestType>>& notifications) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 748 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 749 | |
| 750 | scoped_refptr<Core> protector(this); |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 751 | for (auto iter = notifications.begin(); iter != notifications.end(); ++iter) { |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 752 | // Check |manager_| for each iteration in case it is destroyed in one of |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 753 | // the callbacks. |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 754 | if (!manager_.get()) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 755 | return; |
| 756 | |
| 757 | switch (iter->second) { |
| 758 | case INVALID_REQUEST_TYPE: |
| 759 | NOTREACHED(); |
| 760 | break; |
| 761 | case DEAUTHORIZE_CONTENT_LICENSES: |
jrummell | bffd0124 | 2016-06-30 00:30:37 | [diff] [blame] | 762 | manager_->client_->OnDeauthorizeFlashContentLicensesCompleted( |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 763 | iter->first, false); |
| 764 | break; |
| 765 | case GET_PERMISSION_SETTINGS: |
| 766 | manager_->client_->OnGetPermissionSettingsCompleted( |
| 767 | iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, |
| 768 | ppapi::FlashSiteSettings()); |
| 769 | break; |
| 770 | case SET_DEFAULT_PERMISSION: |
| 771 | manager_->client_->OnSetDefaultPermissionCompleted( |
| 772 | iter->first, false); |
| 773 | break; |
| 774 | case SET_SITE_PERMISSION: |
| 775 | manager_->client_->OnSetSitePermissionCompleted(iter->first, false); |
| 776 | break; |
| 777 | case GET_SITES_WITH_DATA: |
| 778 | manager_->client_->OnGetSitesWithDataCompleted( |
| 779 | iter->first, std::vector<std::string>()); |
| 780 | break; |
| 781 | case CLEAR_SITE_DATA: |
| 782 | manager_->client_->OnClearSiteDataCompleted(iter->first, false); |
| 783 | break; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 787 | if (manager_.get()) |
| 788 | manager_->OnError(this); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 792 | uint32_t request_id, |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 793 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 794 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 795 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 796 | return; |
| 797 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 798 | DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error"; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 799 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 800 | auto iter = pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 801 | if (iter == pending_responses_.end()) |
| 802 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 803 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 804 | DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES); |
| 805 | |
| 806 | pending_responses_.erase(iter); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 807 | base::PostTaskWithTraits( |
| 808 | FROM_HERE, {BrowserThread::UI}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 809 | base::BindOnce(&Core::NotifyDeauthorizeContentLicensesCompleted, this, |
| 810 | request_id, success)); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 811 | } |
| 812 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 813 | void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 814 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 815 | bool success, |
| 816 | PP_Flash_BrowserOperations_Permission default_permission, |
| 817 | const ppapi::FlashSiteSettings& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 818 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 819 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 820 | return; |
| 821 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 822 | DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error"; |
| 823 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 824 | auto iter = pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 825 | if (iter == pending_responses_.end()) |
| 826 | return; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 827 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 828 | DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS); |
| 829 | |
| 830 | pending_responses_.erase(iter); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 831 | base::PostTaskWithTraits( |
| 832 | FROM_HERE, {BrowserThread::UI}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 833 | base::BindOnce(&Core::NotifyGetPermissionSettingsCompleted, this, |
| 834 | request_id, success, default_permission, sites)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 838 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 839 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 840 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 841 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 842 | return; |
| 843 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 844 | DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error"; |
| 845 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 846 | auto iter = pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 847 | if (iter == pending_responses_.end()) |
| 848 | return; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 849 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 850 | DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION); |
| 851 | |
| 852 | pending_responses_.erase(iter); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 853 | base::PostTaskWithTraits( |
| 854 | FROM_HERE, {BrowserThread::UI}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 855 | base::BindOnce(&Core::NotifySetDefaultPermissionCompleted, this, |
| 856 | request_id, success)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | void PepperFlashSettingsManager::Core::OnSetSitePermissionResult( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 860 | uint32_t request_id, |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 861 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 862 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 863 | if (state_ == STATE_DETACHED) |
[email protected] | 4d4ee4c | 2012-06-22 19:11:30 | [diff] [blame] | 864 | return; |
| 865 | |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 866 | DLOG_IF(ERROR, !success) << "SetSitePermission returned error"; |
| 867 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 868 | auto iter = pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 869 | if (iter == pending_responses_.end()) |
| 870 | return; |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 871 | |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 872 | DCHECK_EQ(iter->second, SET_SITE_PERMISSION); |
| 873 | |
| 874 | pending_responses_.erase(iter); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 875 | base::PostTaskWithTraits( |
| 876 | FROM_HERE, {BrowserThread::UI}, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 877 | base::BindOnce(&Core::NotifySetSitePermissionCompleted, this, request_id, |
| 878 | success)); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 882 | uint32_t request_id, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 883 | const std::vector<std::string>& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 884 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 885 | if (state_ == STATE_DETACHED) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 886 | return; |
| 887 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 888 | auto iter = pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 889 | if (iter == pending_responses_.end()) |
| 890 | return; |
| 891 | |
| 892 | DCHECK_EQ(iter->second, GET_SITES_WITH_DATA); |
| 893 | |
| 894 | pending_responses_.erase(iter); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 895 | base::PostTaskWithTraits( |
| 896 | FROM_HERE, {BrowserThread::UI}, |
| 897 | base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this, request_id, |
| 898 | sites)); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | void PepperFlashSettingsManager::Core::OnClearSiteDataResult( |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 902 | uint32_t request_id, |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 903 | bool success) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 904 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 905 | if (state_ == STATE_DETACHED) |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 906 | return; |
| 907 | |
| 908 | DLOG_IF(ERROR, !success) << "ClearSiteData returned error"; |
| 909 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 910 | auto iter = pending_responses_.find(request_id); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 911 | if (iter == pending_responses_.end()) |
| 912 | return; |
| 913 | |
| 914 | DCHECK_EQ(iter->second, CLEAR_SITE_DATA); |
| 915 | |
| 916 | pending_responses_.erase(iter); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 917 | base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, |
| 918 | base::BindOnce(&Core::NotifyClearSiteDataCompleted, |
| 919 | this, request_id, success)); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 920 | } |
| 921 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 922 | PepperFlashSettingsManager::PepperFlashSettingsManager( |
| 923 | Client* client, |
| 924 | content::BrowserContext* browser_context) |
[email protected] | f3d65bd | 2013-10-09 16:26:19 | [diff] [blame] | 925 | : client_(client), |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 926 | browser_context_(browser_context), |
[email protected] | f3d65bd | 2013-10-09 16:26:19 | [diff] [blame] | 927 | next_request_id_(1), |
| 928 | weak_ptr_factory_(this) { |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 929 | DCHECK(client); |
| 930 | DCHECK(browser_context); |
| 931 | } |
| 932 | |
| 933 | PepperFlashSettingsManager::~PepperFlashSettingsManager() { |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 934 | if (core_.get()) |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 935 | core_->Detach(); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 936 | } |
| 937 | |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 938 | // static |
| 939 | bool PepperFlashSettingsManager::IsPepperFlashInUse( |
| 940 | PluginPrefs* plugin_prefs, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 941 | content::WebPluginInfo* plugin_info) { |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 942 | if (!plugin_prefs) |
| 943 | return false; |
| 944 | |
| 945 | content::PluginService* plugin_service = |
| 946 | content::PluginService::GetInstance(); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 947 | std::vector<content::WebPluginInfo> plugins; |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 948 | plugin_service->GetPluginInfoArray( |
[email protected] | 7327029 | 2013-08-09 03:48:07 | [diff] [blame] | 949 | GURL(), content::kFlashPluginSwfMimeType, false, &plugins, NULL); |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 950 | |
jdoerrie | 2f1af51 | 2018-10-03 00:59:37 | [diff] [blame] | 951 | for (auto iter = plugins.begin(); iter != plugins.end(); ++iter) { |
[email protected] | 51ee582 | 2013-07-19 16:47:09 | [diff] [blame] | 952 | if (iter->is_pepper_plugin() && plugin_prefs->IsPluginEnabled(*iter)) { |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 953 | if (plugin_info) |
| 954 | *plugin_info = *iter; |
| 955 | return true; |
| 956 | } |
| 957 | } |
| 958 | return false; |
| 959 | } |
| 960 | |
| 961 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 962 | void PepperFlashSettingsManager::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 963 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 964 | registry->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, true); |
[email protected] | 18a4d63c8 | 2012-05-25 23:37:03 | [diff] [blame] | 965 | } |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 966 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 967 | uint32_t PepperFlashSettingsManager::DeauthorizeContentLicenses( |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 968 | PrefService* prefs) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 969 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 970 | |
[email protected] | bb9c975 | 2013-04-25 23:02:11 | [diff] [blame] | 971 | // Clear the device ID salt which has the effect of regenerating a device |
| 972 | // ID. Since this happens synchronously (and on the UI thread), we don't have |
| 973 | // to add it to a pending request. |
| 974 | prefs->ClearPref(prefs::kDRMSalt); |
| 975 | |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 976 | EnsureCoreExists(); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 977 | uint32_t id = GetNextRequestId(); |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 978 | core_->DeauthorizeContentLicenses(id); |
| 979 | return id; |
| 980 | } |
| 981 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 982 | uint32_t PepperFlashSettingsManager::GetPermissionSettings( |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 983 | PP_Flash_BrowserOperations_SettingType setting_type) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 984 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 985 | |
| 986 | EnsureCoreExists(); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 987 | uint32_t id = GetNextRequestId(); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 988 | core_->GetPermissionSettings(id, setting_type); |
| 989 | return id; |
| 990 | } |
| 991 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 992 | uint32_t PepperFlashSettingsManager::SetDefaultPermission( |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 993 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 994 | PP_Flash_BrowserOperations_Permission permission, |
| 995 | bool clear_site_specific) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 996 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 997 | |
| 998 | EnsureCoreExists(); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 999 | uint32_t id = GetNextRequestId(); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 1000 | core_->SetDefaultPermission(id, setting_type, permission, |
| 1001 | clear_site_specific); |
| 1002 | return id; |
| 1003 | } |
| 1004 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 1005 | uint32_t PepperFlashSettingsManager::SetSitePermission( |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 1006 | PP_Flash_BrowserOperations_SettingType setting_type, |
| 1007 | const ppapi::FlashSiteSettings& sites) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1008 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 1009 | |
| 1010 | EnsureCoreExists(); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 1011 | uint32_t id = GetNextRequestId(); |
[email protected] | ee4dd68 | 2012-06-12 15:49:33 | [diff] [blame] | 1012 | core_->SetSitePermission(id, setting_type, sites); |
| 1013 | return id; |
| 1014 | } |
| 1015 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 1016 | uint32_t PepperFlashSettingsManager::GetSitesWithData() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1017 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 1018 | |
| 1019 | EnsureCoreExists(); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 1020 | uint32_t id = GetNextRequestId(); |
[email protected] | 951ef0b | 2012-07-27 22:46:53 | [diff] [blame] | 1021 | core_->GetSitesWithData(id); |
| 1022 | return id; |
| 1023 | } |
| 1024 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 1025 | uint32_t PepperFlashSettingsManager::ClearSiteData(const std::string& site, |
| 1026 | uint64_t flags, |
| 1027 | uint64_t max_age) { |
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_->ClearSiteData(id, site, flags, max_age); |
| 1033 | return id; |
| 1034 | } |
| 1035 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 1036 | uint32_t PepperFlashSettingsManager::GetNextRequestId() { |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 1037 | return next_request_id_++; |
| 1038 | } |
| 1039 | |
| 1040 | void PepperFlashSettingsManager::EnsureCoreExists() { |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 1041 | if (!core_.get()) { |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 1042 | core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_); |
[email protected] | 6464cc1 | 2012-07-12 09:25:53 | [diff] [blame] | 1043 | core_->Initialize(); |
| 1044 | } |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 1045 | } |
| 1046 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 1047 | void PepperFlashSettingsManager::OnError(Core* core) { |
| 1048 | DCHECK(core); |
| 1049 | if (core != core_.get()) |
| 1050 | return; |
[email protected] | 1a55944 | 2012-05-27 07:18:46 | [diff] [blame] | 1051 | |
[email protected] | 7c82691 | 2012-10-01 22:05:27 | [diff] [blame] | 1052 | core_->Detach(); |
| 1053 | core_ = NULL; |
| 1054 | } |