blob: 0862dc881b594dc2001bbe0a3d369a5866efa26b [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_);
368 for (std::vector<PendingRequest>::iterator iter =
369 temp_pending_requests.begin();
370 iter != temp_pending_requests.end(); ++iter) {
371 switch (iter->type) {
[email protected]951ef0b2012-07-27 22:46:53372 case INVALID_REQUEST_TYPE:
373 NOTREACHED();
374 break;
[email protected]1a559442012-05-27 07:18:46375 case DEAUTHORIZE_CONTENT_LICENSES:
376 DeauthorizeContentLicensesOnIOThread(iter->id);
377 break;
[email protected]ee4dd682012-06-12 15:49:33378 case GET_PERMISSION_SETTINGS:
379 GetPermissionSettingsOnIOThread(iter->id, iter->setting_type);
380 break;
381 case SET_DEFAULT_PERMISSION:
382 SetDefaultPermissionOnIOThread(
383 iter->id, iter->setting_type, iter->permission,
384 iter->clear_site_specific);
385 break;
386 case SET_SITE_PERMISSION:
387 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites);
388 break;
[email protected]951ef0b2012-07-27 22:46:53389 case GET_SITES_WITH_DATA:
390 GetSitesWithDataOnIOThread(iter->id);
391 break;
392 case CLEAR_SITE_DATA:
393 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags,
394 iter->max_age);
[email protected]1a559442012-05-27 07:18:46395 break;
396 }
397 }
398}
399
[email protected]6464cc12012-07-12 09:25:53400void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
thestig00844cea2015-09-08 21:44:52401 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27402 DCHECK_EQ(STATE_UNINITIALIZED, state_);
[email protected]6464cc12012-07-12 09:25:53403
[email protected]d7bd3e52013-07-21 04:29:20404 content::WebPluginInfo plugin_info;
[email protected]6464cc12012-07-12 09:25:53405 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
406 &plugin_info)) {
407 NotifyErrorFromIOThread();
408 return;
409 }
410
[email protected]650b2d52013-02-10 03:41:45411 base::FilePath profile_path =
[email protected]6464cc12012-07-12 09:25:53412 browser_context_path_.Append(content::kPepperDataDirname);
413#if defined(OS_WIN)
414 plugin_data_path_ = profile_path.Append(plugin_info.name);
415#else
[email protected]6778fed2013-12-24 20:09:37416 plugin_data_path_ = profile_path.Append(base::UTF16ToUTF8(plugin_info.name));
[email protected]6464cc12012-07-12 09:25:53417#endif
418
419 helper_ = content::PepperFlashSettingsHelper::Create();
420 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
421 base::Bind(&Core::ConnectToChannel, this);
422 helper_->OpenChannelToBroker(plugin_info.path, callback);
423}
424
[email protected]1a559442012-05-27 07:18:46425void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
avib896c712015-12-26 02:10:43426 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52427 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27428 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46429
[email protected]7c826912012-10-01 22:05:27430 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46431 PendingRequest request;
432 request.id = request_id;
433 request.type = DEAUTHORIZE_CONTENT_LICENSES;
434 pending_requests_.push_back(request);
435 return;
436 }
437
438 pending_responses_.insert(
439 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
[email protected]7c826912012-10-01 22:05:27440 if (state_ == STATE_ERROR) {
441 NotifyErrorFromIOThread();
442 return;
443 }
444
[email protected]bb9c9752013-04-25 23:02:11445#if defined(OS_CHROMEOS)
fdoray5652bcd2017-02-07 16:03:54446 base::PostTaskWithTraits(FROM_HERE,
Gabriel Charetteb10aeebc2018-07-26 20:15:00447 {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
fdoray5652bcd2017-02-07 16:03:54448 base::Bind(&Core::DeauthorizeContentLicensesAsync,
449 this, request_id, browser_context_path_));
[email protected]bb9c9752013-04-25 23:02:11450#else
451 DeauthorizeContentLicensesInPlugin(request_id, true);
452#endif
453}
454
455// TODO(raymes): This is temporary code to migrate ChromeOS devices to the new
456// scheme for generating device IDs. Delete this once we are sure most ChromeOS
457// devices have been migrated.
fdoray5652bcd2017-02-07 16:03:54458void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesAsync(
avib896c712015-12-26 02:10:43459 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11460 const base::FilePath& profile_path) {
461 // ChromeOS used to store the device ID in a file but this is no longer used.
462 // Wipe that file.
463 const base::FilePath& device_id_path =
cm.sanchi4b717262017-11-20 08:02:40464 DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
[email protected]dd3aa792013-07-16 19:10:23465 bool success = base::DeleteFile(device_id_path, false);
[email protected]bb9c9752013-04-25 23:02:11466
Eric Seckler8652dcd52018-09-20 10:42:28467 base::PostTaskWithTraits(
468 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33469 base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this,
470 request_id, success));
[email protected]bb9c9752013-04-25 23:02:11471}
472
473void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
avib896c712015-12-26 02:10:43474 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11475 bool success) {
thestig00844cea2015-09-08 21:44:52476 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]bb9c9752013-04-25 23:02:11477 if (!success) {
478 NotifyErrorFromIOThread();
479 return;
480 }
[email protected]1a559442012-05-27 07:18:46481 IPC::Message* msg =
482 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
483 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33484 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
485 // A failure notification for the current request will be sent since
486 // |pending_responses_| has been updated.
487 NotifyErrorFromIOThread();
488 }
489}
490
491void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43492 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33493 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52494 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27495 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33496
[email protected]7c826912012-10-01 22:05:27497 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33498 PendingRequest request;
499 request.id = request_id;
500 request.type = GET_PERMISSION_SETTINGS;
501 request.setting_type = setting_type;
502 pending_requests_.push_back(request);
503 return;
504 }
505
506 pending_responses_.insert(
507 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
[email protected]7c826912012-10-01 22:05:27508 if (state_ == STATE_ERROR) {
509 NotifyErrorFromIOThread();
510 return;
511 }
512
[email protected]ee4dd682012-06-12 15:49:33513 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
514 request_id, plugin_data_path_, setting_type);
515 if (!channel_->Send(msg)) {
516 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
517 // A failure notification for the current request will be sent since
518 // |pending_responses_| has been updated.
519 NotifyErrorFromIOThread();
520 }
521}
522
523void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43524 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33525 PP_Flash_BrowserOperations_SettingType setting_type,
526 PP_Flash_BrowserOperations_Permission permission,
527 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52528 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27529 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33530
[email protected]7c826912012-10-01 22:05:27531 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33532 PendingRequest request;
533 request.id = request_id;
534 request.type = SET_DEFAULT_PERMISSION;
535 request.setting_type = setting_type;
536 request.permission = permission;
537 request.clear_site_specific = clear_site_specific;
538 pending_requests_.push_back(request);
539 return;
540 }
541
542 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
[email protected]7c826912012-10-01 22:05:27543 if (state_ == STATE_ERROR) {
544 NotifyErrorFromIOThread();
545 return;
546 }
547
[email protected]ee4dd682012-06-12 15:49:33548 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
549 request_id, plugin_data_path_, setting_type, permission,
550 clear_site_specific);
551 if (!channel_->Send(msg)) {
552 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
553 // A failure notification for the current request will be sent since
554 // |pending_responses_| has been updated.
555 NotifyErrorFromIOThread();
556 }
557}
558
559void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43560 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33561 PP_Flash_BrowserOperations_SettingType setting_type,
562 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52563 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27564 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33565
[email protected]7c826912012-10-01 22:05:27566 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33567 pending_requests_.push_back(PendingRequest());
568 PendingRequest& request = pending_requests_.back();
569 request.id = request_id;
570 request.type = SET_SITE_PERMISSION;
571 request.setting_type = setting_type;
572 request.sites = sites;
573 return;
574 }
575
576 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
[email protected]7c826912012-10-01 22:05:27577 if (state_ == STATE_ERROR) {
578 NotifyErrorFromIOThread();
579 return;
580 }
581
[email protected]ee4dd682012-06-12 15:49:33582 IPC::Message* msg = new PpapiMsg_SetSitePermission(
583 request_id, plugin_data_path_, setting_type, sites);
584 if (!channel_->Send(msg)) {
585 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46586 // A failure notification for the current request will be sent since
587 // |pending_responses_| has been updated.
588 NotifyErrorFromIOThread();
589 }
590}
591
[email protected]951ef0b2012-07-27 22:46:53592void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
avib896c712015-12-26 02:10:43593 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52594 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27595 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53596
[email protected]7c826912012-10-01 22:05:27597 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53598 pending_requests_.push_back(PendingRequest());
599 PendingRequest& request = pending_requests_.back();
600 request.id = request_id;
601 request.type = GET_SITES_WITH_DATA;
602 return;
603 }
604
605 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
[email protected]7c826912012-10-01 22:05:27606 if (state_ == STATE_ERROR) {
607 NotifyErrorFromIOThread();
608 return;
609 }
610
[email protected]951ef0b2012-07-27 22:46:53611 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
612 request_id, plugin_data_path_);
613 if (!channel_->Send(msg)) {
614 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
615 // A failure notification for the current request will be sent since
616 // |pending_responses_| has been updated.
617 NotifyErrorFromIOThread();
618 }
619}
620
621void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
avib896c712015-12-26 02:10:43622 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53623 const std::string& site,
avib896c712015-12-26 02:10:43624 uint64_t flags,
625 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52626 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27627 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53628
[email protected]7c826912012-10-01 22:05:27629 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53630 pending_requests_.push_back(PendingRequest());
631 PendingRequest& request = pending_requests_.back();
632 request.id = request_id;
633 request.type = CLEAR_SITE_DATA;
634 request.site = site;
635 request.flags = flags;
636 request.max_age = max_age;
637 return;
638 }
639
640 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
[email protected]7c826912012-10-01 22:05:27641 if (state_ == STATE_ERROR) {
642 NotifyErrorFromIOThread();
643 return;
644 }
645
[email protected]951ef0b2012-07-27 22:46:53646 IPC::Message* msg = new PpapiMsg_ClearSiteData(
647 request_id, plugin_data_path_, site, flags, max_age);
648 if (!channel_->Send(msg)) {
649 DLOG(ERROR) << "Couldn't send ClearSiteData message";
650 // A failure notification for the current request will be sent since
651 // |pending_responses_| has been updated.
652 NotifyErrorFromIOThread();
653 }
654}
655
[email protected]4d4ee4c2012-06-22 19:11:30656void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27657 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30658}
659
[email protected]1a559442012-05-27 07:18:46660void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
thestig00844cea2015-09-08 21:44:52661 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27662 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30663 return;
[email protected]1a559442012-05-27 07:18:46664
[email protected]7c826912012-10-01 22:05:27665 state_ = STATE_ERROR;
avib896c712015-12-26 02:10:43666 std::vector<std::pair<uint32_t, RequestType>> notifications;
[email protected]1a559442012-05-27 07:18:46667 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin();
668 iter != pending_requests_.end(); ++iter) {
669 notifications.push_back(std::make_pair(iter->id, iter->type));
670 }
671 pending_requests_.clear();
672 notifications.insert(notifications.end(), pending_responses_.begin(),
673 pending_responses_.end());
674 pending_responses_.clear();
675
Eric Seckler8652dcd52018-09-20 10:42:28676 base::PostTaskWithTraits(
677 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33678 base::BindOnce(&Core::NotifyError, this, notifications));
[email protected]1a559442012-05-27 07:18:46679}
680
avib896c712015-12-26 02:10:43681void PepperFlashSettingsManager::Core::
682 NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
683 bool success) {
thestig00844cea2015-09-08 21:44:52684 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46685
[email protected]7c826912012-10-01 22:05:27686 if (manager_.get()) {
jrummellbffd01242016-06-30 00:30:37687 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(request_id,
688 success);
[email protected]1a559442012-05-27 07:18:46689 }
690}
691
[email protected]ee4dd682012-06-12 15:49:33692void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43693 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33694 bool success,
695 PP_Flash_BrowserOperations_Permission default_permission,
696 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52697 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33698
[email protected]7c826912012-10-01 22:05:27699 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33700 manager_->client_->OnGetPermissionSettingsCompleted(
701 request_id, success, default_permission, sites);
702 }
703}
704
705void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
avib896c712015-12-26 02:10:43706 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33707 bool success) {
thestig00844cea2015-09-08 21:44:52708 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33709
[email protected]7c826912012-10-01 22:05:27710 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33711 manager_->client_->OnSetDefaultPermissionCompleted(
712 request_id, success);
713 }
714}
715
716void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
avib896c712015-12-26 02:10:43717 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33718 bool success) {
thestig00844cea2015-09-08 21:44:52719 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33720
[email protected]7c826912012-10-01 22:05:27721 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33722 manager_->client_->OnSetSitePermissionCompleted(
723 request_id, success);
724 }
725}
726
[email protected]951ef0b2012-07-27 22:46:53727void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
avib896c712015-12-26 02:10:43728 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53729 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52730 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53731
[email protected]7c826912012-10-01 22:05:27732 if (manager_.get()) {
[email protected]951ef0b2012-07-27 22:46:53733 manager_->client_->OnGetSitesWithDataCompleted(
734 request_id, sites);
735 }
736}
737
738void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
avib896c712015-12-26 02:10:43739 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53740 bool success) {
thestig00844cea2015-09-08 21:44:52741 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53742
[email protected]7c826912012-10-01 22:05:27743 if (manager_.get())
[email protected]951ef0b2012-07-27 22:46:53744 manager_->client_->OnClearSiteDataCompleted(request_id, success);
745}
746
[email protected]1a559442012-05-27 07:18:46747void PepperFlashSettingsManager::Core::NotifyError(
avib896c712015-12-26 02:10:43748 const std::vector<std::pair<uint32_t, RequestType>>& notifications) {
thestig00844cea2015-09-08 21:44:52749 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46750
751 scoped_refptr<Core> protector(this);
avib896c712015-12-26 02:10:43752 for (std::vector<std::pair<uint32_t, RequestType>>::const_iterator iter =
753 notifications.begin();
754 iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27755 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46756 // the callbacks.
[email protected]7c826912012-10-01 22:05:27757 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53758 return;
759
760 switch (iter->second) {
761 case INVALID_REQUEST_TYPE:
762 NOTREACHED();
763 break;
764 case DEAUTHORIZE_CONTENT_LICENSES:
jrummellbffd01242016-06-30 00:30:37765 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(
[email protected]951ef0b2012-07-27 22:46:53766 iter->first, false);
767 break;
768 case GET_PERMISSION_SETTINGS:
769 manager_->client_->OnGetPermissionSettingsCompleted(
770 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
771 ppapi::FlashSiteSettings());
772 break;
773 case SET_DEFAULT_PERMISSION:
774 manager_->client_->OnSetDefaultPermissionCompleted(
775 iter->first, false);
776 break;
777 case SET_SITE_PERMISSION:
778 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
779 break;
780 case GET_SITES_WITH_DATA:
781 manager_->client_->OnGetSitesWithDataCompleted(
782 iter->first, std::vector<std::string>());
783 break;
784 case CLEAR_SITE_DATA:
785 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
786 break;
[email protected]1a559442012-05-27 07:18:46787 }
788 }
789
[email protected]7c826912012-10-01 22:05:27790 if (manager_.get())
791 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46792}
793
794void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
avib896c712015-12-26 02:10:43795 uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46796 bool success) {
thestig00844cea2015-09-08 21:44:52797 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27798 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30799 return;
800
[email protected]ee4dd682012-06-12 15:49:33801 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46802
avib896c712015-12-26 02:10:43803 std::map<uint32_t, RequestType>::iterator iter =
[email protected]1a559442012-05-27 07:18:46804 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53805 if (iter == pending_responses_.end())
806 return;
[email protected]1a559442012-05-27 07:18:46807
[email protected]951ef0b2012-07-27 22:46:53808 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
809
810 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28811 base::PostTaskWithTraits(
812 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33813 base::BindOnce(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
814 request_id, success));
[email protected]1a559442012-05-27 07:18:46815}
816
[email protected]ee4dd682012-06-12 15:49:33817void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43818 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33819 bool success,
820 PP_Flash_BrowserOperations_Permission default_permission,
821 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52822 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27823 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30824 return;
825
[email protected]ee4dd682012-06-12 15:49:33826 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
827
avib896c712015-12-26 02:10:43828 std::map<uint32_t, RequestType>::iterator iter =
[email protected]ee4dd682012-06-12 15:49:33829 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53830 if (iter == pending_responses_.end())
831 return;
[email protected]ee4dd682012-06-12 15:49:33832
[email protected]951ef0b2012-07-27 22:46:53833 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
834
835 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28836 base::PostTaskWithTraits(
837 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33838 base::BindOnce(&Core::NotifyGetPermissionSettingsCompleted, this,
839 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33840}
841
842void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
avib896c712015-12-26 02:10:43843 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33844 bool success) {
thestig00844cea2015-09-08 21:44:52845 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27846 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30847 return;
848
[email protected]ee4dd682012-06-12 15:49:33849 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
850
avib896c712015-12-26 02:10:43851 std::map<uint32_t, RequestType>::iterator iter =
[email protected]ee4dd682012-06-12 15:49:33852 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53853 if (iter == pending_responses_.end())
854 return;
[email protected]ee4dd682012-06-12 15:49:33855
[email protected]951ef0b2012-07-27 22:46:53856 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
857
858 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28859 base::PostTaskWithTraits(
860 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33861 base::BindOnce(&Core::NotifySetDefaultPermissionCompleted, this,
862 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33863}
864
865void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
avib896c712015-12-26 02:10:43866 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33867 bool success) {
thestig00844cea2015-09-08 21:44:52868 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27869 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30870 return;
871
[email protected]ee4dd682012-06-12 15:49:33872 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
873
avib896c712015-12-26 02:10:43874 std::map<uint32_t, RequestType>::iterator iter =
[email protected]ee4dd682012-06-12 15:49:33875 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53876 if (iter == pending_responses_.end())
877 return;
[email protected]ee4dd682012-06-12 15:49:33878
[email protected]951ef0b2012-07-27 22:46:53879 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
880
881 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28882 base::PostTaskWithTraits(
883 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33884 base::BindOnce(&Core::NotifySetSitePermissionCompleted, this, request_id,
885 success));
[email protected]951ef0b2012-07-27 22:46:53886}
887
888void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
avib896c712015-12-26 02:10:43889 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53890 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52891 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27892 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53893 return;
894
avib896c712015-12-26 02:10:43895 std::map<uint32_t, RequestType>::iterator iter =
[email protected]951ef0b2012-07-27 22:46:53896 pending_responses_.find(request_id);
897 if (iter == pending_responses_.end())
898 return;
899
900 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
901
902 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28903 base::PostTaskWithTraits(
904 FROM_HERE, {BrowserThread::UI},
905 base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
906 sites));
[email protected]951ef0b2012-07-27 22:46:53907}
908
909void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
avib896c712015-12-26 02:10:43910 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53911 bool success) {
thestig00844cea2015-09-08 21:44:52912 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27913 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53914 return;
915
916 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
917
avib896c712015-12-26 02:10:43918 std::map<uint32_t, RequestType>::iterator iter =
[email protected]951ef0b2012-07-27 22:46:53919 pending_responses_.find(request_id);
920 if (iter == pending_responses_.end())
921 return;
922
923 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
924
925 pending_responses_.erase(iter);
Eric Seckler8652dcd52018-09-20 10:42:28926 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
927 base::BindOnce(&Core::NotifyClearSiteDataCompleted,
928 this, request_id, success));
[email protected]ee4dd682012-06-12 15:49:33929}
930
[email protected]1a559442012-05-27 07:18:46931PepperFlashSettingsManager::PepperFlashSettingsManager(
932 Client* client,
933 content::BrowserContext* browser_context)
[email protected]f3d65bd2013-10-09 16:26:19934 : client_(client),
[email protected]1a559442012-05-27 07:18:46935 browser_context_(browser_context),
[email protected]f3d65bd2013-10-09 16:26:19936 next_request_id_(1),
937 weak_ptr_factory_(this) {
[email protected]1a559442012-05-27 07:18:46938 DCHECK(client);
939 DCHECK(browser_context);
940}
941
942PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53943 if (core_.get())
[email protected]1a559442012-05-27 07:18:46944 core_->Detach();
[email protected]1a559442012-05-27 07:18:46945}
946
[email protected]18a4d63c82012-05-25 23:37:03947// static
948bool PepperFlashSettingsManager::IsPepperFlashInUse(
949 PluginPrefs* plugin_prefs,
[email protected]d7bd3e52013-07-21 04:29:20950 content::WebPluginInfo* plugin_info) {
[email protected]18a4d63c82012-05-25 23:37:03951 if (!plugin_prefs)
952 return false;
953
954 content::PluginService* plugin_service =
955 content::PluginService::GetInstance();
[email protected]d7bd3e52013-07-21 04:29:20956 std::vector<content::WebPluginInfo> plugins;
[email protected]18a4d63c82012-05-25 23:37:03957 plugin_service->GetPluginInfoArray(
[email protected]73270292013-08-09 03:48:07958 GURL(), content::kFlashPluginSwfMimeType, false, &plugins, NULL);
[email protected]18a4d63c82012-05-25 23:37:03959
[email protected]d7bd3e52013-07-21 04:29:20960 for (std::vector<content::WebPluginInfo>::iterator iter = plugins.begin();
[email protected]18a4d63c82012-05-25 23:37:03961 iter != plugins.end(); ++iter) {
[email protected]51ee5822013-07-19 16:47:09962 if (iter->is_pepper_plugin() && plugin_prefs->IsPluginEnabled(*iter)) {
[email protected]18a4d63c82012-05-25 23:37:03963 if (plugin_info)
964 *plugin_info = *iter;
965 return true;
966 }
967 }
968 return false;
969}
970
971// static
[email protected]37ca3fe02013-07-05 15:32:44972void PepperFlashSettingsManager::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34973 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:25974 registry->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, true);
[email protected]18a4d63c82012-05-25 23:37:03975}
[email protected]1a559442012-05-27 07:18:46976
avib896c712015-12-26 02:10:43977uint32_t PepperFlashSettingsManager::DeauthorizeContentLicenses(
[email protected]bb9c9752013-04-25 23:02:11978 PrefService* prefs) {
thestig00844cea2015-09-08 21:44:52979 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46980
[email protected]bb9c9752013-04-25 23:02:11981 // Clear the device ID salt which has the effect of regenerating a device
982 // ID. Since this happens synchronously (and on the UI thread), we don't have
983 // to add it to a pending request.
984 prefs->ClearPref(prefs::kDRMSalt);
985
[email protected]1a559442012-05-27 07:18:46986 EnsureCoreExists();
avib896c712015-12-26 02:10:43987 uint32_t id = GetNextRequestId();
[email protected]1a559442012-05-27 07:18:46988 core_->DeauthorizeContentLicenses(id);
989 return id;
990}
991
avib896c712015-12-26 02:10:43992uint32_t PepperFlashSettingsManager::GetPermissionSettings(
[email protected]ee4dd682012-06-12 15:49:33993 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52994 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33995
996 EnsureCoreExists();
avib896c712015-12-26 02:10:43997 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33998 core_->GetPermissionSettings(id, setting_type);
999 return id;
1000}
1001
avib896c712015-12-26 02:10:431002uint32_t PepperFlashSettingsManager::SetDefaultPermission(
[email protected]ee4dd682012-06-12 15:49:331003 PP_Flash_BrowserOperations_SettingType setting_type,
1004 PP_Flash_BrowserOperations_Permission permission,
1005 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:521006 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:331007
1008 EnsureCoreExists();
avib896c712015-12-26 02:10:431009 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331010 core_->SetDefaultPermission(id, setting_type, permission,
1011 clear_site_specific);
1012 return id;
1013}
1014
avib896c712015-12-26 02:10:431015uint32_t PepperFlashSettingsManager::SetSitePermission(
[email protected]ee4dd682012-06-12 15:49:331016 PP_Flash_BrowserOperations_SettingType setting_type,
1017 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:521018 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:331019
1020 EnsureCoreExists();
avib896c712015-12-26 02:10:431021 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331022 core_->SetSitePermission(id, setting_type, sites);
1023 return id;
1024}
1025
avib896c712015-12-26 02:10:431026uint32_t PepperFlashSettingsManager::GetSitesWithData() {
thestig00844cea2015-09-08 21:44:521027 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531028
1029 EnsureCoreExists();
avib896c712015-12-26 02:10:431030 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531031 core_->GetSitesWithData(id);
1032 return id;
1033}
1034
avib896c712015-12-26 02:10:431035uint32_t PepperFlashSettingsManager::ClearSiteData(const std::string& site,
1036 uint64_t flags,
1037 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:521038 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531039
1040 EnsureCoreExists();
avib896c712015-12-26 02:10:431041 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531042 core_->ClearSiteData(id, site, flags, max_age);
1043 return id;
1044}
1045
avib896c712015-12-26 02:10:431046uint32_t PepperFlashSettingsManager::GetNextRequestId() {
[email protected]1a559442012-05-27 07:18:461047 return next_request_id_++;
1048}
1049
1050void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531051 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271052 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531053 core_->Initialize();
1054 }
[email protected]1a559442012-05-27 07:18:461055}
1056
[email protected]7c826912012-10-01 22:05:271057void PepperFlashSettingsManager::OnError(Core* core) {
1058 DCHECK(core);
1059 if (core != core_.get())
1060 return;
[email protected]1a559442012-05-27 07:18:461061
[email protected]7c826912012-10-01 22:05:271062 core_->Detach();
1063 core_ = NULL;
1064}