blob: d09954a74c264b12a0f97d72dd53268792d1f2a8 [file] [log] [blame]
[email protected]18a4d63c82012-05-25 23:37:031// 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]1a559442012-05-27 07:18:467#include <map>
8#include <utility>
[email protected]18a4d63c82012-05-25 23:37:039#include <vector>
10
[email protected]1a559442012-05-27 07:18:4611#include "base/bind.h"
12#include "base/compiler_specific.h"
thestig18dfb7a52014-08-26 10:44:0413#include "base/files/file_util.h"
[email protected]fb441962013-05-08 05:35:2414#include "base/sequenced_task_runner_helpers.h"
[email protected]e309f312013-06-07 21:50:0815#include "base/strings/utf_string_conversions.h"
Gabriel Charette44db1422018-08-06 11:19:3316#include "base/task/post_task.h"
avib896c712015-12-26 02:10:4317#include "build/build_config.h"
[email protected]0f5e57f52012-09-20 20:53:1818#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]1a559442012-05-27 07:18:4619#include "chrome/browser/profiles/profile.h"
[email protected]bb9c9752013-04-25 23:02:1120#include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
[email protected]18a4d63c82012-05-25 23:37:0321#include "chrome/common/pref_names.h"
[email protected]f0c8c4992014-05-15 17:37:2622#include "components/pref_registry/pref_registry_syncable.h"
brettwb1fc1b82016-02-02 00:19:0823#include "components/prefs/pref_service.h"
[email protected]1a559442012-05-27 07:18:4624#include "content/public/browser/browser_context.h"
Eric Seckler8652dcd52018-09-20 10:42:2825#include "content/public/browser/browser_task_traits.h"
[email protected]1a559442012-05-27 07:18:4626#include "content/public/browser/browser_thread.h"
27#include "content/public/browser/pepper_flash_settings_helper.h"
[email protected]18a4d63c82012-05-25 23:37:0328#include "content/public/browser/plugin_service.h"
[email protected]1a559442012-05-27 07:18:4629#include "content/public/common/content_constants.h"
[email protected]d7bd3e52013-07-21 04:29:2030#include "content/public/common/webplugininfo.h"
[email protected]1a559442012-05-27 07:18:4631#include "ipc/ipc_channel.h"
[email protected]4e07f842012-11-15 22:22:1732#include "ipc/ipc_listener.h"
[email protected]1a559442012-05-27 07:18:4633#include "ppapi/proxy/ppapi_messages.h"
[email protected]761fa4702013-07-02 15:25:1534#include "url/gurl.h"
[email protected]18a4d63c82012-05-25 23:37:0335
[email protected]1a559442012-05-27 07:18:4636using content::BrowserThread;
37
38class PepperFlashSettingsManager::Core
[email protected]b44f8ad2012-06-15 20:52:5839 : public IPC::Listener,
[email protected]1a559442012-05-27 07:18:4640 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> {
41 public:
[email protected]7c826912012-10-01 22:05:2742 Core(base::WeakPtr<PepperFlashSettingsManager> manager,
[email protected]1a559442012-05-27 07:18:4643 content::BrowserContext* browser_context);
44
[email protected]6464cc12012-07-12 09:25:5345 void Initialize();
[email protected]7c826912012-10-01 22:05:2746
47 // Notifies the core that it has been detached. Afterwards, no method should
48 // be called any more.
[email protected]1a559442012-05-27 07:18:4649 void Detach();
50
avib896c712015-12-26 02:10:4351 void DeauthorizeContentLicenses(uint32_t request_id);
[email protected]ee4dd682012-06-12 15:49:3352 void GetPermissionSettings(
avib896c712015-12-26 02:10:4353 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:3354 PP_Flash_BrowserOperations_SettingType setting_type);
avib896c712015-12-26 02:10:4355 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]ee4dd682012-06-12 15:49:3360 PP_Flash_BrowserOperations_SettingType setting_type,
61 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:4362 void GetSitesWithData(uint32_t request_id);
63 void ClearSiteData(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:5364 const std::string& site,
avib896c712015-12-26 02:10:4365 uint64_t flags,
66 uint64_t max_age);
[email protected]1a559442012-05-27 07:18:4667
[email protected]b44f8ad2012-06-15 20:52:5868 // IPC::Listener implementation.
Daniel Chenga542fca2014-10-21 09:51:2969 bool OnMessageReceived(const IPC::Message& message) override;
70 void OnChannelError() override;
[email protected]1a559442012-05-27 07:18:4671
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]ee4dd682012-06-12 15:49:3378 DEAUTHORIZE_CONTENT_LICENSES,
79 GET_PERMISSION_SETTINGS,
80 SET_DEFAULT_PERMISSION,
[email protected]951ef0b2012-07-27 22:46:5381 SET_SITE_PERMISSION,
82 GET_SITES_WITH_DATA,
83 CLEAR_SITE_DATA,
[email protected]1a559442012-05-27 07:18:4684 };
85
[email protected]7c826912012-10-01 22:05:2786 enum State {
87 STATE_UNINITIALIZED = 0,
88 STATE_INITIALIZED,
89 STATE_ERROR,
90 STATE_DETACHED,
91 };
92
[email protected]1a559442012-05-27 07:18:4693 struct PendingRequest {
[email protected]ee4dd682012-06-12 15:49:3394 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]3695fe32012-08-03 01:55:5999 clear_site_specific(false),
100 flags(0),
101 max_age(0) {
[email protected]ee4dd682012-06-12 15:49:33102 }
[email protected]1a559442012-05-27 07:18:46103
avib896c712015-12-26 02:10:43104 uint32_t id;
[email protected]1a559442012-05-27 07:18:46105 RequestType type;
[email protected]ee4dd682012-06-12 15:49:33106
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]951ef0b2012-07-27 22:46:53117
118 // Used by CLEAR_SITE_DATA
119 std::string site;
avib896c712015-12-26 02:10:43120 uint64_t flags;
121 uint64_t max_age;
[email protected]1a559442012-05-27 07:18:46122 };
123
Daniel Chenga542fca2014-10-21 09:51:29124 ~Core() override;
[email protected]1a559442012-05-27 07:18:46125
[email protected]1a559442012-05-27 07:18:46126 void ConnectToChannel(bool success, const IPC::ChannelHandle& handle);
127
[email protected]6464cc12012-07-12 09:25:53128 void InitializeOnIOThread();
avib896c712015-12-26 02:10:43129 void DeauthorizeContentLicensesOnIOThread(uint32_t request_id);
fdoray5652bcd2017-02-07 16:03:54130 void DeauthorizeContentLicensesAsync(uint32_t request_id,
131 const base::FilePath& profile_path);
avib896c712015-12-26 02:10:43132 void DeauthorizeContentLicensesInPlugin(uint32_t request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33133 void GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43134 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33135 PP_Flash_BrowserOperations_SettingType setting_type);
136 void SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43137 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33138 PP_Flash_BrowserOperations_SettingType setting_type,
139 PP_Flash_BrowserOperations_Permission permission,
140 bool clear_site_specific);
141 void SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43142 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33143 PP_Flash_BrowserOperations_SettingType setting_type,
144 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:43145 void GetSitesWithDataOnIOThread(uint32_t request_id);
146 void ClearSiteDataOnIOThread(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53147 const std::string& site,
avib896c712015-12-26 02:10:43148 uint64_t flags,
149 uint64_t max_age);
[email protected]4d4ee4c2012-06-22 19:11:30150 void DetachOnIOThread();
[email protected]ee4dd682012-06-12 15:49:33151
[email protected]1a559442012-05-27 07:18:46152 void NotifyErrorFromIOThread();
153
avib896c712015-12-26 02:10:43154 void NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46155 bool success);
[email protected]ee4dd682012-06-12 15:49:33156 void NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43157 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33158 bool success,
159 PP_Flash_BrowserOperations_Permission default_permission,
160 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:43161 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]951ef0b2012-07-27 22:46:53164 const std::vector<std::string>& sites);
avib896c712015-12-26 02:10:43165 void NotifyClearSiteDataCompleted(uint32_t request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33166
[email protected]1a559442012-05-27 07:18:46167 void NotifyError(
avib896c712015-12-26 02:10:43168 const std::vector<std::pair<uint32_t, RequestType>>& notifications);
[email protected]1a559442012-05-27 07:18:46169
170 // Message handlers.
avib896c712015-12-26 02:10:43171 void OnDeauthorizeContentLicensesResult(uint32_t request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33172 void OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43173 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33174 bool success,
175 PP_Flash_BrowserOperations_Permission default_permission,
176 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:43177 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]951ef0b2012-07-27 22:46:53180 const std::vector<std::string>& sites);
avib896c712015-12-26 02:10:43181 void OnClearSiteDataResult(uint32_t request_id, bool success);
[email protected]1a559442012-05-27 07:18:46182
183 // Used only on the UI thread.
[email protected]7c826912012-10-01 22:05:27184 base::WeakPtr<PepperFlashSettingsManager> manager_;
[email protected]1a559442012-05-27 07:18:46185
186 // Used only on the I/O thread.
[email protected]650b2d52013-02-10 03:41:45187 base::FilePath plugin_data_path_;
[email protected]1a559442012-05-27 07:18:46188
189 // The channel is NULL until we have opened a connection to the broker
190 // process. Used only on the I/O thread.
dcheng4af48582016-04-19 00:29:35191 std::unique_ptr<IPC::Channel> channel_;
[email protected]1a559442012-05-27 07:18:46192
193 // Used only on the I/O thread.
[email protected]7c826912012-10-01 22:05:27194 State state_;
[email protected]1a559442012-05-27 07:18:46195
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.
avib896c712015-12-26 02:10:43201 std::map<uint32_t, RequestType> pending_responses_;
[email protected]1a559442012-05-27 07:18:46202
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]650b2d52013-02-10 03:41:45208 base::FilePath browser_context_path_;
[email protected]1a559442012-05-27 07:18:46209
210 scoped_refptr<PluginPrefs> plugin_prefs_;
211};
212
[email protected]7c826912012-10-01 22:05:27213PepperFlashSettingsManager::Core::Core(
214 base::WeakPtr<PepperFlashSettingsManager> manager,
215 content::BrowserContext* browser_context)
[email protected]1a559442012-05-27 07:18:46216 : manager_(manager),
[email protected]7c826912012-10-01 22:05:27217 state_(STATE_UNINITIALIZED),
[email protected]1a559442012-05-27 07:18:46218 browser_context_path_(browser_context->GetPath()),
219 plugin_prefs_(PluginPrefs::GetForProfile(
220 Profile::FromBrowserContext(browser_context))) {
thestig00844cea2015-09-08 21:44:52221 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46222}
223
224PepperFlashSettingsManager::Core::~Core() {
thestig00844cea2015-09-08 21:44:52225 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]1a559442012-05-27 07:18:46226}
227
[email protected]6464cc12012-07-12 09:25:53228void PepperFlashSettingsManager::Core::Initialize() {
thestig00844cea2015-09-08 21:44:52229 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Eric Seckler8652dcd52018-09-20 10:42:28230 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
231 base::BindOnce(&Core::InitializeOnIOThread, this));
[email protected]6464cc12012-07-12 09:25:53232}
233
[email protected]1a559442012-05-27 07:18:46234void PepperFlashSettingsManager::Core::Detach() {
thestig00844cea2015-09-08 21:44:52235 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46236
[email protected]7c826912012-10-01 22:05:27237 // 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]4d4ee4c2012-06-22 19:11:30239 // 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 Seckler8652dcd52018-09-20 10:42:28242 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
243 base::BindOnce(&Core::DetachOnIOThread, this));
[email protected]1a559442012-05-27 07:18:46244}
245
246void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
avib896c712015-12-26 02:10:43247 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52248 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46249
Eric Seckler8652dcd52018-09-20 10:42:28250 base::PostTaskWithTraits(
251 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33252 base::BindOnce(&Core::DeauthorizeContentLicensesOnIOThread, this,
253 request_id));
[email protected]1a559442012-05-27 07:18:46254}
255
[email protected]ee4dd682012-06-12 15:49:33256void PepperFlashSettingsManager::Core::GetPermissionSettings(
avib896c712015-12-26 02:10:43257 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33258 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52259 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33260
Eric Seckler8652dcd52018-09-20 10:42:28261 base::PostTaskWithTraits(
262 FROM_HERE, {BrowserThread::IO},
263 base::BindOnce(&Core::GetPermissionSettingsOnIOThread, this, request_id,
264 setting_type));
[email protected]ee4dd682012-06-12 15:49:33265}
266
267void PepperFlashSettingsManager::Core::SetDefaultPermission(
avib896c712015-12-26 02:10:43268 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33269 PP_Flash_BrowserOperations_SettingType setting_type,
270 PP_Flash_BrowserOperations_Permission permission,
271 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52272 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33273
Eric Seckler8652dcd52018-09-20 10:42:28274 base::PostTaskWithTraits(
275 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33276 base::BindOnce(&Core::SetDefaultPermissionOnIOThread, this, request_id,
277 setting_type, permission, clear_site_specific));
[email protected]ee4dd682012-06-12 15:49:33278}
279
280void PepperFlashSettingsManager::Core::SetSitePermission(
avib896c712015-12-26 02:10:43281 uint32_t request_id,
[email protected]7c826912012-10-01 22:05:27282 PP_Flash_BrowserOperations_SettingType setting_type,
283 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52284 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33285
Eric Seckler8652dcd52018-09-20 10:42:28286 base::PostTaskWithTraits(
287 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33288 base::BindOnce(&Core::SetSitePermissionOnIOThread, this, request_id,
289 setting_type, sites));
[email protected]ee4dd682012-06-12 15:49:33290}
291
avib896c712015-12-26 02:10:43292void PepperFlashSettingsManager::Core::GetSitesWithData(uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52293 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53294
Eric Seckler8652dcd52018-09-20 10:42:28295 base::PostTaskWithTraits(
296 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33297 base::BindOnce(&Core::GetSitesWithDataOnIOThread, this, request_id));
[email protected]951ef0b2012-07-27 22:46:53298}
299
avib896c712015-12-26 02:10:43300void PepperFlashSettingsManager::Core::ClearSiteData(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53301 const std::string& site,
avib896c712015-12-26 02:10:43302 uint64_t flags,
303 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52304 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53305
Eric Seckler8652dcd52018-09-20 10:42:28306 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
307 base::BindOnce(&Core::ClearSiteDataOnIOThread, this,
308 request_id, site, flags, max_age));
[email protected]951ef0b2012-07-27 22:46:53309}
310
[email protected]1a559442012-05-27 07:18:46311bool 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]ee4dd682012-06-12 15:49:33316 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]951ef0b2012-07-27 22:46:53322 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult,
323 OnGetSitesWithDataResult)
324 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult,
325 OnClearSiteDataResult)
[email protected]1a559442012-05-27 07:18:46326 IPC_MESSAGE_UNHANDLED_ERROR()
327 IPC_END_MESSAGE_MAP()
328
329 return true;
330}
331
332void PepperFlashSettingsManager::Core::OnChannelError() {
thestig00844cea2015-09-08 21:44:52333 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27334 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30335 return;
[email protected]1a559442012-05-27 07:18:46336
337 NotifyErrorFromIOThread();
338}
339
[email protected]1a559442012-05-27 07:18:46340void PepperFlashSettingsManager::Core::ConnectToChannel(
341 bool success,
342 const IPC::ChannelHandle& handle) {
thestig00844cea2015-09-08 21:44:52343 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27344 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30345 return;
346
[email protected]7c826912012-10-01 22:05:27347 DCHECK(state_ == STATE_UNINITIALIZED);
[email protected]1a559442012-05-27 07:18:46348 DCHECK(!channel_.get());
349
350 if (!success) {
[email protected]ee4dd682012-06-12 15:49:33351 DLOG(ERROR) << "Couldn't open plugin channel";
[email protected]1a559442012-05-27 07:18:46352 NotifyErrorFromIOThread();
353 return;
354 }
355
Hajime Hoshife3ecdc2017-11-28 03:34:13356 channel_ = IPC::Channel::CreateClient(handle, this,
357 base::ThreadTaskRunnerHandle::Get());
[email protected]1a559442012-05-27 07:18:46358 if (!channel_->Connect()) {
[email protected]ee4dd682012-06-12 15:49:33359 DLOG(ERROR) << "Couldn't connect to plugin";
[email protected]1a559442012-05-27 07:18:46360 NotifyErrorFromIOThread();
361 return;
362 }
363
[email protected]7c826912012-10-01 22:05:27364 state_ = STATE_INITIALIZED;
[email protected]1a559442012-05-27 07:18:46365
366 std::vector<PendingRequest> temp_pending_requests;
367 temp_pending_requests.swap(pending_requests_);
jdoerrie2f1af512018-10-03 00:59:37368 for (auto iter = temp_pending_requests.begin();
[email protected]1a559442012-05-27 07:18:46369 iter != temp_pending_requests.end(); ++iter) {
370 switch (iter->type) {
[email protected]951ef0b2012-07-27 22:46:53371 case INVALID_REQUEST_TYPE:
372 NOTREACHED();
373 break;
[email protected]1a559442012-05-27 07:18:46374 case DEAUTHORIZE_CONTENT_LICENSES:
375 DeauthorizeContentLicensesOnIOThread(iter->id);
376 break;
[email protected]ee4dd682012-06-12 15:49:33377 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]951ef0b2012-07-27 22:46:53388 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]1a559442012-05-27 07:18:46394 break;
395 }
396 }
397}
398
[email protected]6464cc12012-07-12 09:25:53399void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
thestig00844cea2015-09-08 21:44:52400 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27401 DCHECK_EQ(STATE_UNINITIALIZED, state_);
[email protected]6464cc12012-07-12 09:25:53402
[email protected]d7bd3e52013-07-21 04:29:20403 content::WebPluginInfo plugin_info;
[email protected]6464cc12012-07-12 09:25:53404 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
405 &plugin_info)) {
406 NotifyErrorFromIOThread();
407 return;
408 }
409
[email protected]650b2d52013-02-10 03:41:45410 base::FilePath profile_path =
[email protected]6464cc12012-07-12 09:25:53411 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]6778fed2013-12-24 20:09:37415 plugin_data_path_ = profile_path.Append(base::UTF16ToUTF8(plugin_info.name));
[email protected]6464cc12012-07-12 09:25:53416#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]1a559442012-05-27 07:18:46424void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
avib896c712015-12-26 02:10:43425 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52426 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27427 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46428
[email protected]7c826912012-10-01 22:05:27429 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46430 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]7c826912012-10-01 22:05:27439 if (state_ == STATE_ERROR) {
440 NotifyErrorFromIOThread();
441 return;
442 }
443
[email protected]bb9c9752013-04-25 23:02:11444#if defined(OS_CHROMEOS)
kylechar99ef9042019-02-25 18:09:43445 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]bb9c9752013-04-25 23:02:11449#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.
fdoray5652bcd2017-02-07 16:03:54457void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesAsync(
avib896c712015-12-26 02:10:43458 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11459 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.sanchi4b717262017-11-20 08:02:40463 DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
[email protected]dd3aa792013-07-16 19:10:23464 bool success = base::DeleteFile(device_id_path, false);
[email protected]bb9c9752013-04-25 23:02:11465
Eric Seckler8652dcd52018-09-20 10:42:28466 base::PostTaskWithTraits(
467 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33468 base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this,
469 request_id, success));
[email protected]bb9c9752013-04-25 23:02:11470}
471
472void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
avib896c712015-12-26 02:10:43473 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11474 bool success) {
thestig00844cea2015-09-08 21:44:52475 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]bb9c9752013-04-25 23:02:11476 if (!success) {
477 NotifyErrorFromIOThread();
478 return;
479 }
[email protected]1a559442012-05-27 07:18:46480 IPC::Message* msg =
481 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
482 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33483 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
490void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43491 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33492 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52493 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27494 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33495
[email protected]7c826912012-10-01 22:05:27496 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33497 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]7c826912012-10-01 22:05:27507 if (state_ == STATE_ERROR) {
508 NotifyErrorFromIOThread();
509 return;
510 }
511
[email protected]ee4dd682012-06-12 15:49:33512 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
522void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43523 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33524 PP_Flash_BrowserOperations_SettingType setting_type,
525 PP_Flash_BrowserOperations_Permission permission,
526 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52527 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27528 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33529
[email protected]7c826912012-10-01 22:05:27530 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33531 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]7c826912012-10-01 22:05:27542 if (state_ == STATE_ERROR) {
543 NotifyErrorFromIOThread();
544 return;
545 }
546
[email protected]ee4dd682012-06-12 15:49:33547 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
558void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43559 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33560 PP_Flash_BrowserOperations_SettingType setting_type,
561 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52562 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27563 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33564
[email protected]7c826912012-10-01 22:05:27565 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33566 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]7c826912012-10-01 22:05:27576 if (state_ == STATE_ERROR) {
577 NotifyErrorFromIOThread();
578 return;
579 }
580
[email protected]ee4dd682012-06-12 15:49:33581 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]1a559442012-05-27 07:18:46585 // A failure notification for the current request will be sent since
586 // |pending_responses_| has been updated.
587 NotifyErrorFromIOThread();
588 }
589}
590
[email protected]951ef0b2012-07-27 22:46:53591void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
avib896c712015-12-26 02:10:43592 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52593 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27594 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53595
[email protected]7c826912012-10-01 22:05:27596 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53597 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]7c826912012-10-01 22:05:27605 if (state_ == STATE_ERROR) {
606 NotifyErrorFromIOThread();
607 return;
608 }
609
[email protected]951ef0b2012-07-27 22:46:53610 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
620void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
avib896c712015-12-26 02:10:43621 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53622 const std::string& site,
avib896c712015-12-26 02:10:43623 uint64_t flags,
624 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52625 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27626 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53627
[email protected]7c826912012-10-01 22:05:27628 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53629 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]7c826912012-10-01 22:05:27640 if (state_ == STATE_ERROR) {
641 NotifyErrorFromIOThread();
642 return;
643 }
644
[email protected]951ef0b2012-07-27 22:46:53645 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]4d4ee4c2012-06-22 19:11:30655void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27656 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30657}
658
[email protected]1a559442012-05-27 07:18:46659void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
thestig00844cea2015-09-08 21:44:52660 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27661 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30662 return;
[email protected]1a559442012-05-27 07:18:46663
[email protected]7c826912012-10-01 22:05:27664 state_ = STATE_ERROR;
avib896c712015-12-26 02:10:43665 std::vector<std::pair<uint32_t, RequestType>> notifications;
jdoerrie2f1af512018-10-03 00:59:37666 for (auto iter = pending_requests_.begin(); iter != pending_requests_.end();
667 ++iter) {
[email protected]1a559442012-05-27 07:18:46668 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 Seckler8652dcd52018-09-20 10:42:28675 base::PostTaskWithTraits(
676 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33677 base::BindOnce(&Core::NotifyError, this, notifications));
[email protected]1a559442012-05-27 07:18:46678}
679
avib896c712015-12-26 02:10:43680void PepperFlashSettingsManager::Core::
681 NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
682 bool success) {
thestig00844cea2015-09-08 21:44:52683 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46684
[email protected]7c826912012-10-01 22:05:27685 if (manager_.get()) {
jrummellbffd01242016-06-30 00:30:37686 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(request_id,
687 success);
[email protected]1a559442012-05-27 07:18:46688 }
689}
690
[email protected]ee4dd682012-06-12 15:49:33691void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43692 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33693 bool success,
694 PP_Flash_BrowserOperations_Permission default_permission,
695 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52696 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33697
[email protected]7c826912012-10-01 22:05:27698 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33699 manager_->client_->OnGetPermissionSettingsCompleted(
700 request_id, success, default_permission, sites);
701 }
702}
703
704void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
avib896c712015-12-26 02:10:43705 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33706 bool success) {
thestig00844cea2015-09-08 21:44:52707 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33708
[email protected]7c826912012-10-01 22:05:27709 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33710 manager_->client_->OnSetDefaultPermissionCompleted(
711 request_id, success);
712 }
713}
714
715void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
avib896c712015-12-26 02:10:43716 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33717 bool success) {
thestig00844cea2015-09-08 21:44:52718 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33719
[email protected]7c826912012-10-01 22:05:27720 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33721 manager_->client_->OnSetSitePermissionCompleted(
722 request_id, success);
723 }
724}
725
[email protected]951ef0b2012-07-27 22:46:53726void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
avib896c712015-12-26 02:10:43727 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53728 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52729 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53730
[email protected]7c826912012-10-01 22:05:27731 if (manager_.get()) {
[email protected]951ef0b2012-07-27 22:46:53732 manager_->client_->OnGetSitesWithDataCompleted(
733 request_id, sites);
734 }
735}
736
737void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
avib896c712015-12-26 02:10:43738 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53739 bool success) {
thestig00844cea2015-09-08 21:44:52740 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53741
[email protected]7c826912012-10-01 22:05:27742 if (manager_.get())
[email protected]951ef0b2012-07-27 22:46:53743 manager_->client_->OnClearSiteDataCompleted(request_id, success);
744}
745
[email protected]1a559442012-05-27 07:18:46746void PepperFlashSettingsManager::Core::NotifyError(
avib896c712015-12-26 02:10:43747 const std::vector<std::pair<uint32_t, RequestType>>& notifications) {
thestig00844cea2015-09-08 21:44:52748 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46749
750 scoped_refptr<Core> protector(this);
jdoerrie2f1af512018-10-03 00:59:37751 for (auto iter = notifications.begin(); iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27752 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46753 // the callbacks.
[email protected]7c826912012-10-01 22:05:27754 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53755 return;
756
757 switch (iter->second) {
758 case INVALID_REQUEST_TYPE:
759 NOTREACHED();
760 break;
761 case DEAUTHORIZE_CONTENT_LICENSES:
jrummellbffd01242016-06-30 00:30:37762 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(
[email protected]951ef0b2012-07-27 22:46:53763 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]1a559442012-05-27 07:18:46784 }
785 }
786
[email protected]7c826912012-10-01 22:05:27787 if (manager_.get())
788 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46789}
790
791void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
avib896c712015-12-26 02:10:43792 uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46793 bool success) {
thestig00844cea2015-09-08 21:44:52794 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27795 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30796 return;
797
[email protected]ee4dd682012-06-12 15:49:33798 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46799
jdoerrie2f1af512018-10-03 00:59:37800 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53801 if (iter == pending_responses_.end())
802 return;
[email protected]1a559442012-05-27 07:18:46803
[email protected]951ef0b2012-07-27 22:46:53804 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
805
806 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28807 base::PostTaskWithTraits(
808 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33809 base::BindOnce(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
810 request_id, success));
[email protected]1a559442012-05-27 07:18:46811}
812
[email protected]ee4dd682012-06-12 15:49:33813void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43814 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33815 bool success,
816 PP_Flash_BrowserOperations_Permission default_permission,
817 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52818 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27819 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30820 return;
821
[email protected]ee4dd682012-06-12 15:49:33822 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
823
jdoerrie2f1af512018-10-03 00:59:37824 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53825 if (iter == pending_responses_.end())
826 return;
[email protected]ee4dd682012-06-12 15:49:33827
[email protected]951ef0b2012-07-27 22:46:53828 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
829
830 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28831 base::PostTaskWithTraits(
832 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33833 base::BindOnce(&Core::NotifyGetPermissionSettingsCompleted, this,
834 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33835}
836
837void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
avib896c712015-12-26 02:10:43838 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33839 bool success) {
thestig00844cea2015-09-08 21:44:52840 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27841 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30842 return;
843
[email protected]ee4dd682012-06-12 15:49:33844 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
845
jdoerrie2f1af512018-10-03 00:59:37846 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53847 if (iter == pending_responses_.end())
848 return;
[email protected]ee4dd682012-06-12 15:49:33849
[email protected]951ef0b2012-07-27 22:46:53850 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
851
852 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28853 base::PostTaskWithTraits(
854 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33855 base::BindOnce(&Core::NotifySetDefaultPermissionCompleted, this,
856 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33857}
858
859void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
avib896c712015-12-26 02:10:43860 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33861 bool success) {
thestig00844cea2015-09-08 21:44:52862 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27863 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30864 return;
865
[email protected]ee4dd682012-06-12 15:49:33866 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
867
jdoerrie2f1af512018-10-03 00:59:37868 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53869 if (iter == pending_responses_.end())
870 return;
[email protected]ee4dd682012-06-12 15:49:33871
[email protected]951ef0b2012-07-27 22:46:53872 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
873
874 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28875 base::PostTaskWithTraits(
876 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33877 base::BindOnce(&Core::NotifySetSitePermissionCompleted, this, request_id,
878 success));
[email protected]951ef0b2012-07-27 22:46:53879}
880
881void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
avib896c712015-12-26 02:10:43882 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53883 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52884 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27885 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53886 return;
887
jdoerrie2f1af512018-10-03 00:59:37888 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53889 if (iter == pending_responses_.end())
890 return;
891
892 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
893
894 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28895 base::PostTaskWithTraits(
896 FROM_HERE, {BrowserThread::UI},
897 base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
898 sites));
[email protected]951ef0b2012-07-27 22:46:53899}
900
901void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
avib896c712015-12-26 02:10:43902 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53903 bool success) {
thestig00844cea2015-09-08 21:44:52904 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27905 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53906 return;
907
908 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
909
jdoerrie2f1af512018-10-03 00:59:37910 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53911 if (iter == pending_responses_.end())
912 return;
913
914 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
915
916 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28917 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
918 base::BindOnce(&Core::NotifyClearSiteDataCompleted,
919 this, request_id, success));
[email protected]ee4dd682012-06-12 15:49:33920}
921
[email protected]1a559442012-05-27 07:18:46922PepperFlashSettingsManager::PepperFlashSettingsManager(
923 Client* client,
924 content::BrowserContext* browser_context)
[email protected]f3d65bd2013-10-09 16:26:19925 : client_(client),
[email protected]1a559442012-05-27 07:18:46926 browser_context_(browser_context),
[email protected]f3d65bd2013-10-09 16:26:19927 next_request_id_(1),
928 weak_ptr_factory_(this) {
[email protected]1a559442012-05-27 07:18:46929 DCHECK(client);
930 DCHECK(browser_context);
931}
932
933PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53934 if (core_.get())
[email protected]1a559442012-05-27 07:18:46935 core_->Detach();
[email protected]1a559442012-05-27 07:18:46936}
937
[email protected]18a4d63c82012-05-25 23:37:03938// static
939bool PepperFlashSettingsManager::IsPepperFlashInUse(
940 PluginPrefs* plugin_prefs,
[email protected]d7bd3e52013-07-21 04:29:20941 content::WebPluginInfo* plugin_info) {
[email protected]18a4d63c82012-05-25 23:37:03942 if (!plugin_prefs)
943 return false;
944
945 content::PluginService* plugin_service =
946 content::PluginService::GetInstance();
[email protected]d7bd3e52013-07-21 04:29:20947 std::vector<content::WebPluginInfo> plugins;
[email protected]18a4d63c82012-05-25 23:37:03948 plugin_service->GetPluginInfoArray(
[email protected]73270292013-08-09 03:48:07949 GURL(), content::kFlashPluginSwfMimeType, false, &plugins, NULL);
[email protected]18a4d63c82012-05-25 23:37:03950
jdoerrie2f1af512018-10-03 00:59:37951 for (auto iter = plugins.begin(); iter != plugins.end(); ++iter) {
[email protected]51ee5822013-07-19 16:47:09952 if (iter->is_pepper_plugin() && plugin_prefs->IsPluginEnabled(*iter)) {
[email protected]18a4d63c82012-05-25 23:37:03953 if (plugin_info)
954 *plugin_info = *iter;
955 return true;
956 }
957 }
958 return false;
959}
960
961// static
[email protected]37ca3fe02013-07-05 15:32:44962void PepperFlashSettingsManager::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34963 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:25964 registry->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, true);
[email protected]18a4d63c82012-05-25 23:37:03965}
[email protected]1a559442012-05-27 07:18:46966
avib896c712015-12-26 02:10:43967uint32_t PepperFlashSettingsManager::DeauthorizeContentLicenses(
[email protected]bb9c9752013-04-25 23:02:11968 PrefService* prefs) {
thestig00844cea2015-09-08 21:44:52969 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46970
[email protected]bb9c9752013-04-25 23:02:11971 // 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]1a559442012-05-27 07:18:46976 EnsureCoreExists();
avib896c712015-12-26 02:10:43977 uint32_t id = GetNextRequestId();
[email protected]1a559442012-05-27 07:18:46978 core_->DeauthorizeContentLicenses(id);
979 return id;
980}
981
avib896c712015-12-26 02:10:43982uint32_t PepperFlashSettingsManager::GetPermissionSettings(
[email protected]ee4dd682012-06-12 15:49:33983 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52984 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33985
986 EnsureCoreExists();
avib896c712015-12-26 02:10:43987 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33988 core_->GetPermissionSettings(id, setting_type);
989 return id;
990}
991
avib896c712015-12-26 02:10:43992uint32_t PepperFlashSettingsManager::SetDefaultPermission(
[email protected]ee4dd682012-06-12 15:49:33993 PP_Flash_BrowserOperations_SettingType setting_type,
994 PP_Flash_BrowserOperations_Permission permission,
995 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52996 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33997
998 EnsureCoreExists();
avib896c712015-12-26 02:10:43999 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331000 core_->SetDefaultPermission(id, setting_type, permission,
1001 clear_site_specific);
1002 return id;
1003}
1004
avib896c712015-12-26 02:10:431005uint32_t PepperFlashSettingsManager::SetSitePermission(
[email protected]ee4dd682012-06-12 15:49:331006 PP_Flash_BrowserOperations_SettingType setting_type,
1007 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:521008 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:331009
1010 EnsureCoreExists();
avib896c712015-12-26 02:10:431011 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331012 core_->SetSitePermission(id, setting_type, sites);
1013 return id;
1014}
1015
avib896c712015-12-26 02:10:431016uint32_t PepperFlashSettingsManager::GetSitesWithData() {
thestig00844cea2015-09-08 21:44:521017 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531018
1019 EnsureCoreExists();
avib896c712015-12-26 02:10:431020 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531021 core_->GetSitesWithData(id);
1022 return id;
1023}
1024
avib896c712015-12-26 02:10:431025uint32_t PepperFlashSettingsManager::ClearSiteData(const std::string& site,
1026 uint64_t flags,
1027 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:521028 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531029
1030 EnsureCoreExists();
avib896c712015-12-26 02:10:431031 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531032 core_->ClearSiteData(id, site, flags, max_age);
1033 return id;
1034}
1035
avib896c712015-12-26 02:10:431036uint32_t PepperFlashSettingsManager::GetNextRequestId() {
[email protected]1a559442012-05-27 07:18:461037 return next_request_id_++;
1038}
1039
1040void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531041 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271042 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531043 core_->Initialize();
1044 }
[email protected]1a559442012-05-27 07:18:461045}
1046
[email protected]7c826912012-10-01 22:05:271047void PepperFlashSettingsManager::OnError(Core* core) {
1048 DCHECK(core);
1049 if (core != core_.get())
1050 return;
[email protected]1a559442012-05-27 07:18:461051
[email protected]7c826912012-10-01 22:05:271052 core_->Detach();
1053 core_ = NULL;
1054}