blob: defd2b38ef93d038abdd7a8218e3288de7243442 [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);
Sami Kyostila7d640eb2019-07-31 18:50:26230 base::PostTask(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.
Sami Kyostila7d640eb2019-07-31 18:50:26242 base::PostTask(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
Sami Kyostila7d640eb2019-07-31 18:50:26250 base::PostTask(FROM_HERE, {BrowserThread::IO},
251 base::BindOnce(&Core::DeauthorizeContentLicensesOnIOThread,
252 this, request_id));
[email protected]1a559442012-05-27 07:18:46253}
254
[email protected]ee4dd682012-06-12 15:49:33255void PepperFlashSettingsManager::Core::GetPermissionSettings(
avib896c712015-12-26 02:10:43256 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33257 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52258 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33259
Sami Kyostila7d640eb2019-07-31 18:50:26260 base::PostTask(FROM_HERE, {BrowserThread::IO},
261 base::BindOnce(&Core::GetPermissionSettingsOnIOThread, this,
262 request_id, setting_type));
[email protected]ee4dd682012-06-12 15:49:33263}
264
265void PepperFlashSettingsManager::Core::SetDefaultPermission(
avib896c712015-12-26 02:10:43266 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33267 PP_Flash_BrowserOperations_SettingType setting_type,
268 PP_Flash_BrowserOperations_Permission permission,
269 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52270 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33271
Sami Kyostila7d640eb2019-07-31 18:50:26272 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28273 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33274 base::BindOnce(&Core::SetDefaultPermissionOnIOThread, this, request_id,
275 setting_type, permission, clear_site_specific));
[email protected]ee4dd682012-06-12 15:49:33276}
277
278void PepperFlashSettingsManager::Core::SetSitePermission(
avib896c712015-12-26 02:10:43279 uint32_t request_id,
[email protected]7c826912012-10-01 22:05:27280 PP_Flash_BrowserOperations_SettingType setting_type,
281 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52282 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33283
Sami Kyostila7d640eb2019-07-31 18:50:26284 base::PostTask(FROM_HERE, {BrowserThread::IO},
285 base::BindOnce(&Core::SetSitePermissionOnIOThread, this,
286 request_id, setting_type, sites));
[email protected]ee4dd682012-06-12 15:49:33287}
288
avib896c712015-12-26 02:10:43289void PepperFlashSettingsManager::Core::GetSitesWithData(uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52290 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53291
Sami Kyostila7d640eb2019-07-31 18:50:26292 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28293 FROM_HERE, {BrowserThread::IO},
tzik3f7781d2017-04-20 17:09:33294 base::BindOnce(&Core::GetSitesWithDataOnIOThread, this, request_id));
[email protected]951ef0b2012-07-27 22:46:53295}
296
avib896c712015-12-26 02:10:43297void PepperFlashSettingsManager::Core::ClearSiteData(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53298 const std::string& site,
avib896c712015-12-26 02:10:43299 uint64_t flags,
300 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52301 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53302
Sami Kyostila7d640eb2019-07-31 18:50:26303 base::PostTask(FROM_HERE, {BrowserThread::IO},
304 base::BindOnce(&Core::ClearSiteDataOnIOThread, this,
305 request_id, site, flags, max_age));
[email protected]951ef0b2012-07-27 22:46:53306}
307
[email protected]1a559442012-05-27 07:18:46308bool PepperFlashSettingsManager::Core::OnMessageReceived(
309 const IPC::Message& message) {
310 IPC_BEGIN_MESSAGE_MAP(Core, message)
311 IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult,
312 OnDeauthorizeContentLicensesResult)
[email protected]ee4dd682012-06-12 15:49:33313 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult,
314 OnGetPermissionSettingsResult)
315 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult,
316 OnSetDefaultPermissionResult)
317 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult,
318 OnSetSitePermissionResult)
[email protected]951ef0b2012-07-27 22:46:53319 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult,
320 OnGetSitesWithDataResult)
321 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult,
322 OnClearSiteDataResult)
[email protected]1a559442012-05-27 07:18:46323 IPC_MESSAGE_UNHANDLED_ERROR()
324 IPC_END_MESSAGE_MAP()
325
326 return true;
327}
328
329void PepperFlashSettingsManager::Core::OnChannelError() {
thestig00844cea2015-09-08 21:44:52330 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27331 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30332 return;
[email protected]1a559442012-05-27 07:18:46333
334 NotifyErrorFromIOThread();
335}
336
[email protected]1a559442012-05-27 07:18:46337void PepperFlashSettingsManager::Core::ConnectToChannel(
338 bool success,
339 const IPC::ChannelHandle& handle) {
thestig00844cea2015-09-08 21:44:52340 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27341 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30342 return;
343
[email protected]7c826912012-10-01 22:05:27344 DCHECK(state_ == STATE_UNINITIALIZED);
[email protected]1a559442012-05-27 07:18:46345 DCHECK(!channel_.get());
346
347 if (!success) {
[email protected]ee4dd682012-06-12 15:49:33348 DLOG(ERROR) << "Couldn't open plugin channel";
[email protected]1a559442012-05-27 07:18:46349 NotifyErrorFromIOThread();
350 return;
351 }
352
Hajime Hoshife3ecdc2017-11-28 03:34:13353 channel_ = IPC::Channel::CreateClient(handle, this,
354 base::ThreadTaskRunnerHandle::Get());
[email protected]1a559442012-05-27 07:18:46355 if (!channel_->Connect()) {
[email protected]ee4dd682012-06-12 15:49:33356 DLOG(ERROR) << "Couldn't connect to plugin";
[email protected]1a559442012-05-27 07:18:46357 NotifyErrorFromIOThread();
358 return;
359 }
360
[email protected]7c826912012-10-01 22:05:27361 state_ = STATE_INITIALIZED;
[email protected]1a559442012-05-27 07:18:46362
363 std::vector<PendingRequest> temp_pending_requests;
364 temp_pending_requests.swap(pending_requests_);
jdoerrie2f1af512018-10-03 00:59:37365 for (auto iter = temp_pending_requests.begin();
[email protected]1a559442012-05-27 07:18:46366 iter != temp_pending_requests.end(); ++iter) {
367 switch (iter->type) {
[email protected]951ef0b2012-07-27 22:46:53368 case INVALID_REQUEST_TYPE:
369 NOTREACHED();
370 break;
[email protected]1a559442012-05-27 07:18:46371 case DEAUTHORIZE_CONTENT_LICENSES:
372 DeauthorizeContentLicensesOnIOThread(iter->id);
373 break;
[email protected]ee4dd682012-06-12 15:49:33374 case GET_PERMISSION_SETTINGS:
375 GetPermissionSettingsOnIOThread(iter->id, iter->setting_type);
376 break;
377 case SET_DEFAULT_PERMISSION:
378 SetDefaultPermissionOnIOThread(
379 iter->id, iter->setting_type, iter->permission,
380 iter->clear_site_specific);
381 break;
382 case SET_SITE_PERMISSION:
383 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites);
384 break;
[email protected]951ef0b2012-07-27 22:46:53385 case GET_SITES_WITH_DATA:
386 GetSitesWithDataOnIOThread(iter->id);
387 break;
388 case CLEAR_SITE_DATA:
389 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags,
390 iter->max_age);
[email protected]1a559442012-05-27 07:18:46391 break;
392 }
393 }
394}
395
[email protected]6464cc12012-07-12 09:25:53396void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
thestig00844cea2015-09-08 21:44:52397 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27398 DCHECK_EQ(STATE_UNINITIALIZED, state_);
[email protected]6464cc12012-07-12 09:25:53399
[email protected]d7bd3e52013-07-21 04:29:20400 content::WebPluginInfo plugin_info;
[email protected]6464cc12012-07-12 09:25:53401 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
402 &plugin_info)) {
403 NotifyErrorFromIOThread();
404 return;
405 }
406
[email protected]650b2d52013-02-10 03:41:45407 base::FilePath profile_path =
[email protected]6464cc12012-07-12 09:25:53408 browser_context_path_.Append(content::kPepperDataDirname);
409#if defined(OS_WIN)
410 plugin_data_path_ = profile_path.Append(plugin_info.name);
411#else
[email protected]6778fed2013-12-24 20:09:37412 plugin_data_path_ = profile_path.Append(base::UTF16ToUTF8(plugin_info.name));
[email protected]6464cc12012-07-12 09:25:53413#endif
414
415 helper_ = content::PepperFlashSettingsHelper::Create();
danakjb8a784ea2019-12-10 14:51:44416 helper_->OpenChannelToBroker(plugin_info.path,
417 base::BindOnce(&Core::ConnectToChannel, this));
[email protected]6464cc12012-07-12 09:25:53418}
419
[email protected]1a559442012-05-27 07:18:46420void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
avib896c712015-12-26 02:10:43421 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52422 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27423 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46424
[email protected]7c826912012-10-01 22:05:27425 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46426 PendingRequest request;
427 request.id = request_id;
428 request.type = DEAUTHORIZE_CONTENT_LICENSES;
429 pending_requests_.push_back(request);
430 return;
431 }
432
433 pending_responses_.insert(
434 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
[email protected]7c826912012-10-01 22:05:27435 if (state_ == STATE_ERROR) {
436 NotifyErrorFromIOThread();
437 return;
438 }
439
[email protected]bb9c9752013-04-25 23:02:11440#if defined(OS_CHROMEOS)
Sami Kyostila7d640eb2019-07-31 18:50:26441 base::PostTask(
442 FROM_HERE,
443 {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT},
kylechar99ef9042019-02-25 18:09:43444 base::BindOnce(&Core::DeauthorizeContentLicensesAsync, this, request_id,
445 browser_context_path_));
[email protected]bb9c9752013-04-25 23:02:11446#else
447 DeauthorizeContentLicensesInPlugin(request_id, true);
448#endif
449}
450
451// TODO(raymes): This is temporary code to migrate ChromeOS devices to the new
452// scheme for generating device IDs. Delete this once we are sure most ChromeOS
453// devices have been migrated.
fdoray5652bcd2017-02-07 16:03:54454void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesAsync(
avib896c712015-12-26 02:10:43455 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11456 const base::FilePath& profile_path) {
457 // ChromeOS used to store the device ID in a file but this is no longer used.
458 // Wipe that file.
459 const base::FilePath& device_id_path =
cm.sanchi4b717262017-11-20 08:02:40460 DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
[email protected]dd3aa792013-07-16 19:10:23461 bool success = base::DeleteFile(device_id_path, false);
[email protected]bb9c9752013-04-25 23:02:11462
Sami Kyostila7d640eb2019-07-31 18:50:26463 base::PostTask(FROM_HERE, {BrowserThread::IO},
464 base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this,
465 request_id, success));
[email protected]bb9c9752013-04-25 23:02:11466}
467
468void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
avib896c712015-12-26 02:10:43469 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11470 bool success) {
thestig00844cea2015-09-08 21:44:52471 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]bb9c9752013-04-25 23:02:11472 if (!success) {
473 NotifyErrorFromIOThread();
474 return;
475 }
[email protected]1a559442012-05-27 07:18:46476 IPC::Message* msg =
477 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
478 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33479 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
480 // A failure notification for the current request will be sent since
481 // |pending_responses_| has been updated.
482 NotifyErrorFromIOThread();
483 }
484}
485
486void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43487 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33488 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52489 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27490 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33491
[email protected]7c826912012-10-01 22:05:27492 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33493 PendingRequest request;
494 request.id = request_id;
495 request.type = GET_PERMISSION_SETTINGS;
496 request.setting_type = setting_type;
497 pending_requests_.push_back(request);
498 return;
499 }
500
501 pending_responses_.insert(
502 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
[email protected]7c826912012-10-01 22:05:27503 if (state_ == STATE_ERROR) {
504 NotifyErrorFromIOThread();
505 return;
506 }
507
[email protected]ee4dd682012-06-12 15:49:33508 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
509 request_id, plugin_data_path_, setting_type);
510 if (!channel_->Send(msg)) {
511 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
512 // A failure notification for the current request will be sent since
513 // |pending_responses_| has been updated.
514 NotifyErrorFromIOThread();
515 }
516}
517
518void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43519 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33520 PP_Flash_BrowserOperations_SettingType setting_type,
521 PP_Flash_BrowserOperations_Permission permission,
522 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52523 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27524 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33525
[email protected]7c826912012-10-01 22:05:27526 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33527 PendingRequest request;
528 request.id = request_id;
529 request.type = SET_DEFAULT_PERMISSION;
530 request.setting_type = setting_type;
531 request.permission = permission;
532 request.clear_site_specific = clear_site_specific;
533 pending_requests_.push_back(request);
534 return;
535 }
536
537 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
[email protected]7c826912012-10-01 22:05:27538 if (state_ == STATE_ERROR) {
539 NotifyErrorFromIOThread();
540 return;
541 }
542
[email protected]ee4dd682012-06-12 15:49:33543 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
544 request_id, plugin_data_path_, setting_type, permission,
545 clear_site_specific);
546 if (!channel_->Send(msg)) {
547 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
548 // A failure notification for the current request will be sent since
549 // |pending_responses_| has been updated.
550 NotifyErrorFromIOThread();
551 }
552}
553
554void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43555 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33556 PP_Flash_BrowserOperations_SettingType setting_type,
557 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52558 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27559 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33560
[email protected]7c826912012-10-01 22:05:27561 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33562 pending_requests_.push_back(PendingRequest());
563 PendingRequest& request = pending_requests_.back();
564 request.id = request_id;
565 request.type = SET_SITE_PERMISSION;
566 request.setting_type = setting_type;
567 request.sites = sites;
568 return;
569 }
570
571 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
[email protected]7c826912012-10-01 22:05:27572 if (state_ == STATE_ERROR) {
573 NotifyErrorFromIOThread();
574 return;
575 }
576
[email protected]ee4dd682012-06-12 15:49:33577 IPC::Message* msg = new PpapiMsg_SetSitePermission(
578 request_id, plugin_data_path_, setting_type, sites);
579 if (!channel_->Send(msg)) {
580 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46581 // A failure notification for the current request will be sent since
582 // |pending_responses_| has been updated.
583 NotifyErrorFromIOThread();
584 }
585}
586
[email protected]951ef0b2012-07-27 22:46:53587void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
avib896c712015-12-26 02:10:43588 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52589 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27590 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53591
[email protected]7c826912012-10-01 22:05:27592 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53593 pending_requests_.push_back(PendingRequest());
594 PendingRequest& request = pending_requests_.back();
595 request.id = request_id;
596 request.type = GET_SITES_WITH_DATA;
597 return;
598 }
599
600 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
[email protected]7c826912012-10-01 22:05:27601 if (state_ == STATE_ERROR) {
602 NotifyErrorFromIOThread();
603 return;
604 }
605
[email protected]951ef0b2012-07-27 22:46:53606 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
607 request_id, plugin_data_path_);
608 if (!channel_->Send(msg)) {
609 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
610 // A failure notification for the current request will be sent since
611 // |pending_responses_| has been updated.
612 NotifyErrorFromIOThread();
613 }
614}
615
616void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
avib896c712015-12-26 02:10:43617 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53618 const std::string& site,
avib896c712015-12-26 02:10:43619 uint64_t flags,
620 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52621 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27622 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53623
[email protected]7c826912012-10-01 22:05:27624 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53625 pending_requests_.push_back(PendingRequest());
626 PendingRequest& request = pending_requests_.back();
627 request.id = request_id;
628 request.type = CLEAR_SITE_DATA;
629 request.site = site;
630 request.flags = flags;
631 request.max_age = max_age;
632 return;
633 }
634
635 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
[email protected]7c826912012-10-01 22:05:27636 if (state_ == STATE_ERROR) {
637 NotifyErrorFromIOThread();
638 return;
639 }
640
[email protected]951ef0b2012-07-27 22:46:53641 IPC::Message* msg = new PpapiMsg_ClearSiteData(
642 request_id, plugin_data_path_, site, flags, max_age);
643 if (!channel_->Send(msg)) {
644 DLOG(ERROR) << "Couldn't send ClearSiteData message";
645 // A failure notification for the current request will be sent since
646 // |pending_responses_| has been updated.
647 NotifyErrorFromIOThread();
648 }
649}
650
[email protected]4d4ee4c2012-06-22 19:11:30651void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27652 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30653}
654
[email protected]1a559442012-05-27 07:18:46655void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
thestig00844cea2015-09-08 21:44:52656 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27657 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30658 return;
[email protected]1a559442012-05-27 07:18:46659
[email protected]7c826912012-10-01 22:05:27660 state_ = STATE_ERROR;
avib896c712015-12-26 02:10:43661 std::vector<std::pair<uint32_t, RequestType>> notifications;
jdoerrie2f1af512018-10-03 00:59:37662 for (auto iter = pending_requests_.begin(); iter != pending_requests_.end();
663 ++iter) {
[email protected]1a559442012-05-27 07:18:46664 notifications.push_back(std::make_pair(iter->id, iter->type));
665 }
666 pending_requests_.clear();
667 notifications.insert(notifications.end(), pending_responses_.begin(),
668 pending_responses_.end());
669 pending_responses_.clear();
670
Sami Kyostila7d640eb2019-07-31 18:50:26671 base::PostTask(FROM_HERE, {BrowserThread::UI},
672 base::BindOnce(&Core::NotifyError, this, notifications));
[email protected]1a559442012-05-27 07:18:46673}
674
avib896c712015-12-26 02:10:43675void PepperFlashSettingsManager::Core::
676 NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
677 bool success) {
thestig00844cea2015-09-08 21:44:52678 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46679
[email protected]7c826912012-10-01 22:05:27680 if (manager_.get()) {
jrummellbffd01242016-06-30 00:30:37681 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(request_id,
682 success);
[email protected]1a559442012-05-27 07:18:46683 }
684}
685
[email protected]ee4dd682012-06-12 15:49:33686void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43687 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33688 bool success,
689 PP_Flash_BrowserOperations_Permission default_permission,
690 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52691 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33692
[email protected]7c826912012-10-01 22:05:27693 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33694 manager_->client_->OnGetPermissionSettingsCompleted(
695 request_id, success, default_permission, sites);
696 }
697}
698
699void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
avib896c712015-12-26 02:10:43700 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33701 bool success) {
thestig00844cea2015-09-08 21:44:52702 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33703
[email protected]7c826912012-10-01 22:05:27704 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33705 manager_->client_->OnSetDefaultPermissionCompleted(
706 request_id, success);
707 }
708}
709
710void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
avib896c712015-12-26 02:10:43711 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33712 bool success) {
thestig00844cea2015-09-08 21:44:52713 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33714
[email protected]7c826912012-10-01 22:05:27715 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33716 manager_->client_->OnSetSitePermissionCompleted(
717 request_id, success);
718 }
719}
720
[email protected]951ef0b2012-07-27 22:46:53721void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
avib896c712015-12-26 02:10:43722 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53723 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52724 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53725
[email protected]7c826912012-10-01 22:05:27726 if (manager_.get()) {
[email protected]951ef0b2012-07-27 22:46:53727 manager_->client_->OnGetSitesWithDataCompleted(
728 request_id, sites);
729 }
730}
731
732void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
avib896c712015-12-26 02:10:43733 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53734 bool success) {
thestig00844cea2015-09-08 21:44:52735 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53736
[email protected]7c826912012-10-01 22:05:27737 if (manager_.get())
[email protected]951ef0b2012-07-27 22:46:53738 manager_->client_->OnClearSiteDataCompleted(request_id, success);
739}
740
[email protected]1a559442012-05-27 07:18:46741void PepperFlashSettingsManager::Core::NotifyError(
avib896c712015-12-26 02:10:43742 const std::vector<std::pair<uint32_t, RequestType>>& notifications) {
thestig00844cea2015-09-08 21:44:52743 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46744
745 scoped_refptr<Core> protector(this);
jdoerrie2f1af512018-10-03 00:59:37746 for (auto iter = notifications.begin(); iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27747 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46748 // the callbacks.
[email protected]7c826912012-10-01 22:05:27749 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53750 return;
751
752 switch (iter->second) {
753 case INVALID_REQUEST_TYPE:
754 NOTREACHED();
755 break;
756 case DEAUTHORIZE_CONTENT_LICENSES:
jrummellbffd01242016-06-30 00:30:37757 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(
[email protected]951ef0b2012-07-27 22:46:53758 iter->first, false);
759 break;
760 case GET_PERMISSION_SETTINGS:
761 manager_->client_->OnGetPermissionSettingsCompleted(
762 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
763 ppapi::FlashSiteSettings());
764 break;
765 case SET_DEFAULT_PERMISSION:
766 manager_->client_->OnSetDefaultPermissionCompleted(
767 iter->first, false);
768 break;
769 case SET_SITE_PERMISSION:
770 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
771 break;
772 case GET_SITES_WITH_DATA:
773 manager_->client_->OnGetSitesWithDataCompleted(
774 iter->first, std::vector<std::string>());
775 break;
776 case CLEAR_SITE_DATA:
777 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
778 break;
[email protected]1a559442012-05-27 07:18:46779 }
780 }
781
[email protected]7c826912012-10-01 22:05:27782 if (manager_.get())
783 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46784}
785
786void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
avib896c712015-12-26 02:10:43787 uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46788 bool success) {
thestig00844cea2015-09-08 21:44:52789 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27790 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30791 return;
792
[email protected]ee4dd682012-06-12 15:49:33793 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46794
jdoerrie2f1af512018-10-03 00:59:37795 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53796 if (iter == pending_responses_.end())
797 return;
[email protected]1a559442012-05-27 07:18:46798
[email protected]951ef0b2012-07-27 22:46:53799 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
800
801 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26802 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28803 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33804 base::BindOnce(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
805 request_id, success));
[email protected]1a559442012-05-27 07:18:46806}
807
[email protected]ee4dd682012-06-12 15:49:33808void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43809 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33810 bool success,
811 PP_Flash_BrowserOperations_Permission default_permission,
812 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52813 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27814 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30815 return;
816
[email protected]ee4dd682012-06-12 15:49:33817 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
818
jdoerrie2f1af512018-10-03 00:59:37819 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53820 if (iter == pending_responses_.end())
821 return;
[email protected]ee4dd682012-06-12 15:49:33822
[email protected]951ef0b2012-07-27 22:46:53823 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
824
825 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26826 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28827 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33828 base::BindOnce(&Core::NotifyGetPermissionSettingsCompleted, this,
829 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33830}
831
832void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
avib896c712015-12-26 02:10:43833 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33834 bool success) {
thestig00844cea2015-09-08 21:44:52835 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27836 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30837 return;
838
[email protected]ee4dd682012-06-12 15:49:33839 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
840
jdoerrie2f1af512018-10-03 00:59:37841 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53842 if (iter == pending_responses_.end())
843 return;
[email protected]ee4dd682012-06-12 15:49:33844
[email protected]951ef0b2012-07-27 22:46:53845 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
846
847 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26848 base::PostTask(FROM_HERE, {BrowserThread::UI},
849 base::BindOnce(&Core::NotifySetDefaultPermissionCompleted,
850 this, request_id, success));
[email protected]ee4dd682012-06-12 15:49:33851}
852
853void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
avib896c712015-12-26 02:10:43854 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33855 bool success) {
thestig00844cea2015-09-08 21:44:52856 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27857 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30858 return;
859
[email protected]ee4dd682012-06-12 15:49:33860 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
861
jdoerrie2f1af512018-10-03 00:59:37862 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53863 if (iter == pending_responses_.end())
864 return;
[email protected]ee4dd682012-06-12 15:49:33865
[email protected]951ef0b2012-07-27 22:46:53866 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
867
868 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26869 base::PostTask(FROM_HERE, {BrowserThread::UI},
870 base::BindOnce(&Core::NotifySetSitePermissionCompleted, this,
871 request_id, success));
[email protected]951ef0b2012-07-27 22:46:53872}
873
874void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
avib896c712015-12-26 02:10:43875 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53876 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52877 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27878 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53879 return;
880
jdoerrie2f1af512018-10-03 00:59:37881 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53882 if (iter == pending_responses_.end())
883 return;
884
885 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
886
887 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26888 base::PostTask(FROM_HERE, {BrowserThread::UI},
889 base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this,
890 request_id, sites));
[email protected]951ef0b2012-07-27 22:46:53891}
892
893void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
avib896c712015-12-26 02:10:43894 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53895 bool success) {
thestig00844cea2015-09-08 21:44:52896 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27897 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53898 return;
899
900 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
901
jdoerrie2f1af512018-10-03 00:59:37902 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53903 if (iter == pending_responses_.end())
904 return;
905
906 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
907
908 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26909 base::PostTask(FROM_HERE, {BrowserThread::UI},
910 base::BindOnce(&Core::NotifyClearSiteDataCompleted, this,
911 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33912}
913
[email protected]1a559442012-05-27 07:18:46914PepperFlashSettingsManager::PepperFlashSettingsManager(
915 Client* client,
916 content::BrowserContext* browser_context)
Jeremy Roman495db682019-07-12 16:03:24917 : client_(client), browser_context_(browser_context), next_request_id_(1) {
[email protected]1a559442012-05-27 07:18:46918 DCHECK(client);
919 DCHECK(browser_context);
920}
921
922PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53923 if (core_.get())
[email protected]1a559442012-05-27 07:18:46924 core_->Detach();
[email protected]1a559442012-05-27 07:18:46925}
926
[email protected]18a4d63c82012-05-25 23:37:03927// static
928bool PepperFlashSettingsManager::IsPepperFlashInUse(
929 PluginPrefs* plugin_prefs,
[email protected]d7bd3e52013-07-21 04:29:20930 content::WebPluginInfo* plugin_info) {
[email protected]18a4d63c82012-05-25 23:37:03931 if (!plugin_prefs)
932 return false;
933
934 content::PluginService* plugin_service =
935 content::PluginService::GetInstance();
[email protected]d7bd3e52013-07-21 04:29:20936 std::vector<content::WebPluginInfo> plugins;
[email protected]18a4d63c82012-05-25 23:37:03937 plugin_service->GetPluginInfoArray(
[email protected]73270292013-08-09 03:48:07938 GURL(), content::kFlashPluginSwfMimeType, false, &plugins, NULL);
[email protected]18a4d63c82012-05-25 23:37:03939
jdoerrie2f1af512018-10-03 00:59:37940 for (auto iter = plugins.begin(); iter != plugins.end(); ++iter) {
[email protected]51ee5822013-07-19 16:47:09941 if (iter->is_pepper_plugin() && plugin_prefs->IsPluginEnabled(*iter)) {
[email protected]18a4d63c82012-05-25 23:37:03942 if (plugin_info)
943 *plugin_info = *iter;
944 return true;
945 }
946 }
947 return false;
948}
949
950// static
[email protected]37ca3fe02013-07-05 15:32:44951void PepperFlashSettingsManager::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34952 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:25953 registry->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, true);
[email protected]18a4d63c82012-05-25 23:37:03954}
[email protected]1a559442012-05-27 07:18:46955
avib896c712015-12-26 02:10:43956uint32_t PepperFlashSettingsManager::DeauthorizeContentLicenses(
[email protected]bb9c9752013-04-25 23:02:11957 PrefService* prefs) {
thestig00844cea2015-09-08 21:44:52958 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46959
[email protected]bb9c9752013-04-25 23:02:11960 // Clear the device ID salt which has the effect of regenerating a device
961 // ID. Since this happens synchronously (and on the UI thread), we don't have
962 // to add it to a pending request.
963 prefs->ClearPref(prefs::kDRMSalt);
964
[email protected]1a559442012-05-27 07:18:46965 EnsureCoreExists();
avib896c712015-12-26 02:10:43966 uint32_t id = GetNextRequestId();
[email protected]1a559442012-05-27 07:18:46967 core_->DeauthorizeContentLicenses(id);
968 return id;
969}
970
avib896c712015-12-26 02:10:43971uint32_t PepperFlashSettingsManager::GetPermissionSettings(
[email protected]ee4dd682012-06-12 15:49:33972 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52973 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33974
975 EnsureCoreExists();
avib896c712015-12-26 02:10:43976 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33977 core_->GetPermissionSettings(id, setting_type);
978 return id;
979}
980
avib896c712015-12-26 02:10:43981uint32_t PepperFlashSettingsManager::SetDefaultPermission(
[email protected]ee4dd682012-06-12 15:49:33982 PP_Flash_BrowserOperations_SettingType setting_type,
983 PP_Flash_BrowserOperations_Permission permission,
984 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52985 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33986
987 EnsureCoreExists();
avib896c712015-12-26 02:10:43988 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33989 core_->SetDefaultPermission(id, setting_type, permission,
990 clear_site_specific);
991 return id;
992}
993
avib896c712015-12-26 02:10:43994uint32_t PepperFlashSettingsManager::SetSitePermission(
[email protected]ee4dd682012-06-12 15:49:33995 PP_Flash_BrowserOperations_SettingType setting_type,
996 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52997 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33998
999 EnsureCoreExists();
avib896c712015-12-26 02:10:431000 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331001 core_->SetSitePermission(id, setting_type, sites);
1002 return id;
1003}
1004
avib896c712015-12-26 02:10:431005uint32_t PepperFlashSettingsManager::GetSitesWithData() {
thestig00844cea2015-09-08 21:44:521006 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531007
1008 EnsureCoreExists();
avib896c712015-12-26 02:10:431009 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531010 core_->GetSitesWithData(id);
1011 return id;
1012}
1013
avib896c712015-12-26 02:10:431014uint32_t PepperFlashSettingsManager::ClearSiteData(const std::string& site,
1015 uint64_t flags,
1016 uint64_t max_age) {
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_->ClearSiteData(id, site, flags, max_age);
1022 return id;
1023}
1024
avib896c712015-12-26 02:10:431025uint32_t PepperFlashSettingsManager::GetNextRequestId() {
[email protected]1a559442012-05-27 07:18:461026 return next_request_id_++;
1027}
1028
1029void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531030 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271031 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531032 core_->Initialize();
1033 }
[email protected]1a559442012-05-27 07:18:461034}
1035
[email protected]7c826912012-10-01 22:05:271036void PepperFlashSettingsManager::OnError(Core* core) {
1037 DCHECK(core);
1038 if (core != core_.get())
1039 return;
[email protected]1a559442012-05-27 07:18:461040
[email protected]7c826912012-10-01 22:05:271041 core_->Detach();
kylecharc5fd9612019-11-15 03:21:271042 core_.reset();
[email protected]7c826912012-10-01 22:05:271043}