blob: 5d9a0ecfbf70302b6d611866511374aa24902f9f [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();
416 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
417 base::Bind(&Core::ConnectToChannel, this);
418 helper_->OpenChannelToBroker(plugin_info.path, callback);
419}
420
[email protected]1a559442012-05-27 07:18:46421void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
avib896c712015-12-26 02:10:43422 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52423 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27424 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46425
[email protected]7c826912012-10-01 22:05:27426 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46427 PendingRequest request;
428 request.id = request_id;
429 request.type = DEAUTHORIZE_CONTENT_LICENSES;
430 pending_requests_.push_back(request);
431 return;
432 }
433
434 pending_responses_.insert(
435 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
[email protected]7c826912012-10-01 22:05:27436 if (state_ == STATE_ERROR) {
437 NotifyErrorFromIOThread();
438 return;
439 }
440
[email protected]bb9c9752013-04-25 23:02:11441#if defined(OS_CHROMEOS)
Sami Kyostila7d640eb2019-07-31 18:50:26442 base::PostTask(
443 FROM_HERE,
444 {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT},
kylechar99ef9042019-02-25 18:09:43445 base::BindOnce(&Core::DeauthorizeContentLicensesAsync, this, request_id,
446 browser_context_path_));
[email protected]bb9c9752013-04-25 23:02:11447#else
448 DeauthorizeContentLicensesInPlugin(request_id, true);
449#endif
450}
451
452// TODO(raymes): This is temporary code to migrate ChromeOS devices to the new
453// scheme for generating device IDs. Delete this once we are sure most ChromeOS
454// devices have been migrated.
fdoray5652bcd2017-02-07 16:03:54455void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesAsync(
avib896c712015-12-26 02:10:43456 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11457 const base::FilePath& profile_path) {
458 // ChromeOS used to store the device ID in a file but this is no longer used.
459 // Wipe that file.
460 const base::FilePath& device_id_path =
cm.sanchi4b717262017-11-20 08:02:40461 DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
[email protected]dd3aa792013-07-16 19:10:23462 bool success = base::DeleteFile(device_id_path, false);
[email protected]bb9c9752013-04-25 23:02:11463
Sami Kyostila7d640eb2019-07-31 18:50:26464 base::PostTask(FROM_HERE, {BrowserThread::IO},
465 base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this,
466 request_id, success));
[email protected]bb9c9752013-04-25 23:02:11467}
468
469void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
avib896c712015-12-26 02:10:43470 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11471 bool success) {
thestig00844cea2015-09-08 21:44:52472 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]bb9c9752013-04-25 23:02:11473 if (!success) {
474 NotifyErrorFromIOThread();
475 return;
476 }
[email protected]1a559442012-05-27 07:18:46477 IPC::Message* msg =
478 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
479 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33480 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
481 // A failure notification for the current request will be sent since
482 // |pending_responses_| has been updated.
483 NotifyErrorFromIOThread();
484 }
485}
486
487void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43488 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33489 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52490 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27491 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33492
[email protected]7c826912012-10-01 22:05:27493 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33494 PendingRequest request;
495 request.id = request_id;
496 request.type = GET_PERMISSION_SETTINGS;
497 request.setting_type = setting_type;
498 pending_requests_.push_back(request);
499 return;
500 }
501
502 pending_responses_.insert(
503 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
[email protected]7c826912012-10-01 22:05:27504 if (state_ == STATE_ERROR) {
505 NotifyErrorFromIOThread();
506 return;
507 }
508
[email protected]ee4dd682012-06-12 15:49:33509 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
510 request_id, plugin_data_path_, setting_type);
511 if (!channel_->Send(msg)) {
512 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
513 // A failure notification for the current request will be sent since
514 // |pending_responses_| has been updated.
515 NotifyErrorFromIOThread();
516 }
517}
518
519void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43520 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33521 PP_Flash_BrowserOperations_SettingType setting_type,
522 PP_Flash_BrowserOperations_Permission permission,
523 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52524 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27525 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33526
[email protected]7c826912012-10-01 22:05:27527 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33528 PendingRequest request;
529 request.id = request_id;
530 request.type = SET_DEFAULT_PERMISSION;
531 request.setting_type = setting_type;
532 request.permission = permission;
533 request.clear_site_specific = clear_site_specific;
534 pending_requests_.push_back(request);
535 return;
536 }
537
538 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
[email protected]7c826912012-10-01 22:05:27539 if (state_ == STATE_ERROR) {
540 NotifyErrorFromIOThread();
541 return;
542 }
543
[email protected]ee4dd682012-06-12 15:49:33544 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
545 request_id, plugin_data_path_, setting_type, permission,
546 clear_site_specific);
547 if (!channel_->Send(msg)) {
548 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
549 // A failure notification for the current request will be sent since
550 // |pending_responses_| has been updated.
551 NotifyErrorFromIOThread();
552 }
553}
554
555void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43556 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33557 PP_Flash_BrowserOperations_SettingType setting_type,
558 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52559 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27560 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33561
[email protected]7c826912012-10-01 22:05:27562 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33563 pending_requests_.push_back(PendingRequest());
564 PendingRequest& request = pending_requests_.back();
565 request.id = request_id;
566 request.type = SET_SITE_PERMISSION;
567 request.setting_type = setting_type;
568 request.sites = sites;
569 return;
570 }
571
572 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
[email protected]7c826912012-10-01 22:05:27573 if (state_ == STATE_ERROR) {
574 NotifyErrorFromIOThread();
575 return;
576 }
577
[email protected]ee4dd682012-06-12 15:49:33578 IPC::Message* msg = new PpapiMsg_SetSitePermission(
579 request_id, plugin_data_path_, setting_type, sites);
580 if (!channel_->Send(msg)) {
581 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46582 // A failure notification for the current request will be sent since
583 // |pending_responses_| has been updated.
584 NotifyErrorFromIOThread();
585 }
586}
587
[email protected]951ef0b2012-07-27 22:46:53588void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
avib896c712015-12-26 02:10:43589 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52590 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27591 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53592
[email protected]7c826912012-10-01 22:05:27593 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53594 pending_requests_.push_back(PendingRequest());
595 PendingRequest& request = pending_requests_.back();
596 request.id = request_id;
597 request.type = GET_SITES_WITH_DATA;
598 return;
599 }
600
601 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
[email protected]7c826912012-10-01 22:05:27602 if (state_ == STATE_ERROR) {
603 NotifyErrorFromIOThread();
604 return;
605 }
606
[email protected]951ef0b2012-07-27 22:46:53607 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
608 request_id, plugin_data_path_);
609 if (!channel_->Send(msg)) {
610 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
611 // A failure notification for the current request will be sent since
612 // |pending_responses_| has been updated.
613 NotifyErrorFromIOThread();
614 }
615}
616
617void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
avib896c712015-12-26 02:10:43618 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53619 const std::string& site,
avib896c712015-12-26 02:10:43620 uint64_t flags,
621 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52622 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27623 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53624
[email protected]7c826912012-10-01 22:05:27625 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53626 pending_requests_.push_back(PendingRequest());
627 PendingRequest& request = pending_requests_.back();
628 request.id = request_id;
629 request.type = CLEAR_SITE_DATA;
630 request.site = site;
631 request.flags = flags;
632 request.max_age = max_age;
633 return;
634 }
635
636 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
[email protected]7c826912012-10-01 22:05:27637 if (state_ == STATE_ERROR) {
638 NotifyErrorFromIOThread();
639 return;
640 }
641
[email protected]951ef0b2012-07-27 22:46:53642 IPC::Message* msg = new PpapiMsg_ClearSiteData(
643 request_id, plugin_data_path_, site, flags, max_age);
644 if (!channel_->Send(msg)) {
645 DLOG(ERROR) << "Couldn't send ClearSiteData message";
646 // A failure notification for the current request will be sent since
647 // |pending_responses_| has been updated.
648 NotifyErrorFromIOThread();
649 }
650}
651
[email protected]4d4ee4c2012-06-22 19:11:30652void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27653 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30654}
655
[email protected]1a559442012-05-27 07:18:46656void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
thestig00844cea2015-09-08 21:44:52657 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27658 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30659 return;
[email protected]1a559442012-05-27 07:18:46660
[email protected]7c826912012-10-01 22:05:27661 state_ = STATE_ERROR;
avib896c712015-12-26 02:10:43662 std::vector<std::pair<uint32_t, RequestType>> notifications;
jdoerrie2f1af512018-10-03 00:59:37663 for (auto iter = pending_requests_.begin(); iter != pending_requests_.end();
664 ++iter) {
[email protected]1a559442012-05-27 07:18:46665 notifications.push_back(std::make_pair(iter->id, iter->type));
666 }
667 pending_requests_.clear();
668 notifications.insert(notifications.end(), pending_responses_.begin(),
669 pending_responses_.end());
670 pending_responses_.clear();
671
Sami Kyostila7d640eb2019-07-31 18:50:26672 base::PostTask(FROM_HERE, {BrowserThread::UI},
673 base::BindOnce(&Core::NotifyError, this, notifications));
[email protected]1a559442012-05-27 07:18:46674}
675
avib896c712015-12-26 02:10:43676void PepperFlashSettingsManager::Core::
677 NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
678 bool success) {
thestig00844cea2015-09-08 21:44:52679 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46680
[email protected]7c826912012-10-01 22:05:27681 if (manager_.get()) {
jrummellbffd01242016-06-30 00:30:37682 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(request_id,
683 success);
[email protected]1a559442012-05-27 07:18:46684 }
685}
686
[email protected]ee4dd682012-06-12 15:49:33687void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43688 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33689 bool success,
690 PP_Flash_BrowserOperations_Permission default_permission,
691 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52692 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33693
[email protected]7c826912012-10-01 22:05:27694 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33695 manager_->client_->OnGetPermissionSettingsCompleted(
696 request_id, success, default_permission, sites);
697 }
698}
699
700void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
avib896c712015-12-26 02:10:43701 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33702 bool success) {
thestig00844cea2015-09-08 21:44:52703 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33704
[email protected]7c826912012-10-01 22:05:27705 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33706 manager_->client_->OnSetDefaultPermissionCompleted(
707 request_id, success);
708 }
709}
710
711void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
avib896c712015-12-26 02:10:43712 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33713 bool success) {
thestig00844cea2015-09-08 21:44:52714 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33715
[email protected]7c826912012-10-01 22:05:27716 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33717 manager_->client_->OnSetSitePermissionCompleted(
718 request_id, success);
719 }
720}
721
[email protected]951ef0b2012-07-27 22:46:53722void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
avib896c712015-12-26 02:10:43723 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53724 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52725 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53726
[email protected]7c826912012-10-01 22:05:27727 if (manager_.get()) {
[email protected]951ef0b2012-07-27 22:46:53728 manager_->client_->OnGetSitesWithDataCompleted(
729 request_id, sites);
730 }
731}
732
733void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
avib896c712015-12-26 02:10:43734 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53735 bool success) {
thestig00844cea2015-09-08 21:44:52736 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53737
[email protected]7c826912012-10-01 22:05:27738 if (manager_.get())
[email protected]951ef0b2012-07-27 22:46:53739 manager_->client_->OnClearSiteDataCompleted(request_id, success);
740}
741
[email protected]1a559442012-05-27 07:18:46742void PepperFlashSettingsManager::Core::NotifyError(
avib896c712015-12-26 02:10:43743 const std::vector<std::pair<uint32_t, RequestType>>& notifications) {
thestig00844cea2015-09-08 21:44:52744 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46745
746 scoped_refptr<Core> protector(this);
jdoerrie2f1af512018-10-03 00:59:37747 for (auto iter = notifications.begin(); iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27748 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46749 // the callbacks.
[email protected]7c826912012-10-01 22:05:27750 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53751 return;
752
753 switch (iter->second) {
754 case INVALID_REQUEST_TYPE:
755 NOTREACHED();
756 break;
757 case DEAUTHORIZE_CONTENT_LICENSES:
jrummellbffd01242016-06-30 00:30:37758 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(
[email protected]951ef0b2012-07-27 22:46:53759 iter->first, false);
760 break;
761 case GET_PERMISSION_SETTINGS:
762 manager_->client_->OnGetPermissionSettingsCompleted(
763 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
764 ppapi::FlashSiteSettings());
765 break;
766 case SET_DEFAULT_PERMISSION:
767 manager_->client_->OnSetDefaultPermissionCompleted(
768 iter->first, false);
769 break;
770 case SET_SITE_PERMISSION:
771 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
772 break;
773 case GET_SITES_WITH_DATA:
774 manager_->client_->OnGetSitesWithDataCompleted(
775 iter->first, std::vector<std::string>());
776 break;
777 case CLEAR_SITE_DATA:
778 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
779 break;
[email protected]1a559442012-05-27 07:18:46780 }
781 }
782
[email protected]7c826912012-10-01 22:05:27783 if (manager_.get())
784 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46785}
786
787void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
avib896c712015-12-26 02:10:43788 uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46789 bool success) {
thestig00844cea2015-09-08 21:44:52790 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27791 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30792 return;
793
[email protected]ee4dd682012-06-12 15:49:33794 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46795
jdoerrie2f1af512018-10-03 00:59:37796 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53797 if (iter == pending_responses_.end())
798 return;
[email protected]1a559442012-05-27 07:18:46799
[email protected]951ef0b2012-07-27 22:46:53800 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
801
802 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26803 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28804 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33805 base::BindOnce(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
806 request_id, success));
[email protected]1a559442012-05-27 07:18:46807}
808
[email protected]ee4dd682012-06-12 15:49:33809void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43810 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33811 bool success,
812 PP_Flash_BrowserOperations_Permission default_permission,
813 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52814 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27815 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30816 return;
817
[email protected]ee4dd682012-06-12 15:49:33818 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
819
jdoerrie2f1af512018-10-03 00:59:37820 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53821 if (iter == pending_responses_.end())
822 return;
[email protected]ee4dd682012-06-12 15:49:33823
[email protected]951ef0b2012-07-27 22:46:53824 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
825
826 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26827 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28828 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:33829 base::BindOnce(&Core::NotifyGetPermissionSettingsCompleted, this,
830 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33831}
832
833void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
avib896c712015-12-26 02:10:43834 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33835 bool success) {
thestig00844cea2015-09-08 21:44:52836 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27837 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30838 return;
839
[email protected]ee4dd682012-06-12 15:49:33840 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
841
jdoerrie2f1af512018-10-03 00:59:37842 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53843 if (iter == pending_responses_.end())
844 return;
[email protected]ee4dd682012-06-12 15:49:33845
[email protected]951ef0b2012-07-27 22:46:53846 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
847
848 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26849 base::PostTask(FROM_HERE, {BrowserThread::UI},
850 base::BindOnce(&Core::NotifySetDefaultPermissionCompleted,
851 this, request_id, success));
[email protected]ee4dd682012-06-12 15:49:33852}
853
854void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
avib896c712015-12-26 02:10:43855 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33856 bool success) {
thestig00844cea2015-09-08 21:44:52857 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27858 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30859 return;
860
[email protected]ee4dd682012-06-12 15:49:33861 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
862
jdoerrie2f1af512018-10-03 00:59:37863 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53864 if (iter == pending_responses_.end())
865 return;
[email protected]ee4dd682012-06-12 15:49:33866
[email protected]951ef0b2012-07-27 22:46:53867 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
868
869 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26870 base::PostTask(FROM_HERE, {BrowserThread::UI},
871 base::BindOnce(&Core::NotifySetSitePermissionCompleted, this,
872 request_id, success));
[email protected]951ef0b2012-07-27 22:46:53873}
874
875void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
avib896c712015-12-26 02:10:43876 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53877 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52878 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27879 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53880 return;
881
jdoerrie2f1af512018-10-03 00:59:37882 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53883 if (iter == pending_responses_.end())
884 return;
885
886 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
887
888 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26889 base::PostTask(FROM_HERE, {BrowserThread::UI},
890 base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this,
891 request_id, sites));
[email protected]951ef0b2012-07-27 22:46:53892}
893
894void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
avib896c712015-12-26 02:10:43895 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53896 bool success) {
thestig00844cea2015-09-08 21:44:52897 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27898 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53899 return;
900
901 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
902
jdoerrie2f1af512018-10-03 00:59:37903 auto iter = pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53904 if (iter == pending_responses_.end())
905 return;
906
907 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
908
909 pending_responses_.erase(iter);
Sami Kyostila7d640eb2019-07-31 18:50:26910 base::PostTask(FROM_HERE, {BrowserThread::UI},
911 base::BindOnce(&Core::NotifyClearSiteDataCompleted, this,
912 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33913}
914
[email protected]1a559442012-05-27 07:18:46915PepperFlashSettingsManager::PepperFlashSettingsManager(
916 Client* client,
917 content::BrowserContext* browser_context)
Jeremy Roman495db682019-07-12 16:03:24918 : client_(client), browser_context_(browser_context), next_request_id_(1) {
[email protected]1a559442012-05-27 07:18:46919 DCHECK(client);
920 DCHECK(browser_context);
921}
922
923PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53924 if (core_.get())
[email protected]1a559442012-05-27 07:18:46925 core_->Detach();
[email protected]1a559442012-05-27 07:18:46926}
927
[email protected]18a4d63c82012-05-25 23:37:03928// static
929bool PepperFlashSettingsManager::IsPepperFlashInUse(
930 PluginPrefs* plugin_prefs,
[email protected]d7bd3e52013-07-21 04:29:20931 content::WebPluginInfo* plugin_info) {
[email protected]18a4d63c82012-05-25 23:37:03932 if (!plugin_prefs)
933 return false;
934
935 content::PluginService* plugin_service =
936 content::PluginService::GetInstance();
[email protected]d7bd3e52013-07-21 04:29:20937 std::vector<content::WebPluginInfo> plugins;
[email protected]18a4d63c82012-05-25 23:37:03938 plugin_service->GetPluginInfoArray(
[email protected]73270292013-08-09 03:48:07939 GURL(), content::kFlashPluginSwfMimeType, false, &plugins, NULL);
[email protected]18a4d63c82012-05-25 23:37:03940
jdoerrie2f1af512018-10-03 00:59:37941 for (auto iter = plugins.begin(); iter != plugins.end(); ++iter) {
[email protected]51ee5822013-07-19 16:47:09942 if (iter->is_pepper_plugin() && plugin_prefs->IsPluginEnabled(*iter)) {
[email protected]18a4d63c82012-05-25 23:37:03943 if (plugin_info)
944 *plugin_info = *iter;
945 return true;
946 }
947 }
948 return false;
949}
950
951// static
[email protected]37ca3fe02013-07-05 15:32:44952void PepperFlashSettingsManager::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34953 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:25954 registry->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, true);
[email protected]18a4d63c82012-05-25 23:37:03955}
[email protected]1a559442012-05-27 07:18:46956
avib896c712015-12-26 02:10:43957uint32_t PepperFlashSettingsManager::DeauthorizeContentLicenses(
[email protected]bb9c9752013-04-25 23:02:11958 PrefService* prefs) {
thestig00844cea2015-09-08 21:44:52959 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46960
[email protected]bb9c9752013-04-25 23:02:11961 // Clear the device ID salt which has the effect of regenerating a device
962 // ID. Since this happens synchronously (and on the UI thread), we don't have
963 // to add it to a pending request.
964 prefs->ClearPref(prefs::kDRMSalt);
965
[email protected]1a559442012-05-27 07:18:46966 EnsureCoreExists();
avib896c712015-12-26 02:10:43967 uint32_t id = GetNextRequestId();
[email protected]1a559442012-05-27 07:18:46968 core_->DeauthorizeContentLicenses(id);
969 return id;
970}
971
avib896c712015-12-26 02:10:43972uint32_t PepperFlashSettingsManager::GetPermissionSettings(
[email protected]ee4dd682012-06-12 15:49:33973 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52974 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33975
976 EnsureCoreExists();
avib896c712015-12-26 02:10:43977 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33978 core_->GetPermissionSettings(id, setting_type);
979 return id;
980}
981
avib896c712015-12-26 02:10:43982uint32_t PepperFlashSettingsManager::SetDefaultPermission(
[email protected]ee4dd682012-06-12 15:49:33983 PP_Flash_BrowserOperations_SettingType setting_type,
984 PP_Flash_BrowserOperations_Permission permission,
985 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52986 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33987
988 EnsureCoreExists();
avib896c712015-12-26 02:10:43989 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33990 core_->SetDefaultPermission(id, setting_type, permission,
991 clear_site_specific);
992 return id;
993}
994
avib896c712015-12-26 02:10:43995uint32_t PepperFlashSettingsManager::SetSitePermission(
[email protected]ee4dd682012-06-12 15:49:33996 PP_Flash_BrowserOperations_SettingType setting_type,
997 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52998 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33999
1000 EnsureCoreExists();
avib896c712015-12-26 02:10:431001 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331002 core_->SetSitePermission(id, setting_type, sites);
1003 return id;
1004}
1005
avib896c712015-12-26 02:10:431006uint32_t PepperFlashSettingsManager::GetSitesWithData() {
thestig00844cea2015-09-08 21:44:521007 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531008
1009 EnsureCoreExists();
avib896c712015-12-26 02:10:431010 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531011 core_->GetSitesWithData(id);
1012 return id;
1013}
1014
avib896c712015-12-26 02:10:431015uint32_t PepperFlashSettingsManager::ClearSiteData(const std::string& site,
1016 uint64_t flags,
1017 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:521018 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531019
1020 EnsureCoreExists();
avib896c712015-12-26 02:10:431021 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531022 core_->ClearSiteData(id, site, flags, max_age);
1023 return id;
1024}
1025
avib896c712015-12-26 02:10:431026uint32_t PepperFlashSettingsManager::GetNextRequestId() {
[email protected]1a559442012-05-27 07:18:461027 return next_request_id_++;
1028}
1029
1030void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531031 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271032 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531033 core_->Initialize();
1034 }
[email protected]1a559442012-05-27 07:18:461035}
1036
[email protected]7c826912012-10-01 22:05:271037void PepperFlashSettingsManager::OnError(Core* core) {
1038 DCHECK(core);
1039 if (core != core_.get())
1040 return;
[email protected]1a559442012-05-27 07:18:461041
[email protected]7c826912012-10-01 22:05:271042 core_->Detach();
kylecharc5fd9612019-11-15 03:21:271043 core_.reset();
[email protected]7c826912012-10-01 22:05:271044}