blob: c9a715547757cdc0b58002856ff59bd5190977aa [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"
fdoray5652bcd2017-02-07 16:03:5416#include "base/task_scheduler/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"
25#include "content/public/browser/browser_thread.h"
26#include "content/public/browser/pepper_flash_settings_helper.h"
[email protected]18a4d63c82012-05-25 23:37:0327#include "content/public/browser/plugin_service.h"
[email protected]1a559442012-05-27 07:18:4628#include "content/public/common/content_constants.h"
[email protected]d7bd3e52013-07-21 04:29:2029#include "content/public/common/webplugininfo.h"
[email protected]1a559442012-05-27 07:18:4630#include "ipc/ipc_channel.h"
[email protected]4e07f842012-11-15 22:22:1731#include "ipc/ipc_listener.h"
[email protected]1a559442012-05-27 07:18:4632#include "ppapi/proxy/ppapi_messages.h"
[email protected]761fa4702013-07-02 15:25:1533#include "url/gurl.h"
[email protected]18a4d63c82012-05-25 23:37:0334
[email protected]1a559442012-05-27 07:18:4635using content::BrowserThread;
36
37class PepperFlashSettingsManager::Core
[email protected]b44f8ad2012-06-15 20:52:5838 : public IPC::Listener,
[email protected]1a559442012-05-27 07:18:4639 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> {
40 public:
[email protected]7c826912012-10-01 22:05:2741 Core(base::WeakPtr<PepperFlashSettingsManager> manager,
[email protected]1a559442012-05-27 07:18:4642 content::BrowserContext* browser_context);
43
[email protected]6464cc12012-07-12 09:25:5344 void Initialize();
[email protected]7c826912012-10-01 22:05:2745
46 // Notifies the core that it has been detached. Afterwards, no method should
47 // be called any more.
[email protected]1a559442012-05-27 07:18:4648 void Detach();
49
avib896c712015-12-26 02:10:4350 void DeauthorizeContentLicenses(uint32_t request_id);
[email protected]ee4dd682012-06-12 15:49:3351 void GetPermissionSettings(
avib896c712015-12-26 02:10:4352 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:3353 PP_Flash_BrowserOperations_SettingType setting_type);
avib896c712015-12-26 02:10:4354 void SetDefaultPermission(uint32_t request_id,
55 PP_Flash_BrowserOperations_SettingType setting_type,
56 PP_Flash_BrowserOperations_Permission permission,
57 bool clear_site_specific);
58 void SetSitePermission(uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:3359 PP_Flash_BrowserOperations_SettingType setting_type,
60 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:4361 void GetSitesWithData(uint32_t request_id);
62 void ClearSiteData(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:5363 const std::string& site,
avib896c712015-12-26 02:10:4364 uint64_t flags,
65 uint64_t max_age);
[email protected]1a559442012-05-27 07:18:4666
[email protected]b44f8ad2012-06-15 20:52:5867 // IPC::Listener implementation.
Daniel Chenga542fca2014-10-21 09:51:2968 bool OnMessageReceived(const IPC::Message& message) override;
69 void OnChannelError() override;
[email protected]1a559442012-05-27 07:18:4670
71 private:
72 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
73 friend class base::DeleteHelper<Core>;
74
75 enum RequestType {
76 INVALID_REQUEST_TYPE = 0,
[email protected]ee4dd682012-06-12 15:49:3377 DEAUTHORIZE_CONTENT_LICENSES,
78 GET_PERMISSION_SETTINGS,
79 SET_DEFAULT_PERMISSION,
[email protected]951ef0b2012-07-27 22:46:5380 SET_SITE_PERMISSION,
81 GET_SITES_WITH_DATA,
82 CLEAR_SITE_DATA,
[email protected]1a559442012-05-27 07:18:4683 };
84
[email protected]7c826912012-10-01 22:05:2785 enum State {
86 STATE_UNINITIALIZED = 0,
87 STATE_INITIALIZED,
88 STATE_ERROR,
89 STATE_DETACHED,
90 };
91
[email protected]1a559442012-05-27 07:18:4692 struct PendingRequest {
[email protected]ee4dd682012-06-12 15:49:3393 PendingRequest()
94 : id(0),
95 type(INVALID_REQUEST_TYPE),
96 setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC),
97 permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT),
[email protected]3695fe32012-08-03 01:55:5998 clear_site_specific(false),
99 flags(0),
100 max_age(0) {
[email protected]ee4dd682012-06-12 15:49:33101 }
[email protected]1a559442012-05-27 07:18:46102
avib896c712015-12-26 02:10:43103 uint32_t id;
[email protected]1a559442012-05-27 07:18:46104 RequestType type;
[email protected]ee4dd682012-06-12 15:49:33105
106 // Used by GET_PERMISSION_SETTINGS, SET_DEFAULT_PERMISSION and
107 // SET_SITE_PERMISSION.
108 PP_Flash_BrowserOperations_SettingType setting_type;
109
110 // Used by SET_DEFAULT_PERMISSION.
111 PP_Flash_BrowserOperations_Permission permission;
112 bool clear_site_specific;
113
114 // Used by SET_SITE_PERMISSION.
115 ppapi::FlashSiteSettings sites;
[email protected]951ef0b2012-07-27 22:46:53116
117 // Used by CLEAR_SITE_DATA
118 std::string site;
avib896c712015-12-26 02:10:43119 uint64_t flags;
120 uint64_t max_age;
[email protected]1a559442012-05-27 07:18:46121 };
122
Daniel Chenga542fca2014-10-21 09:51:29123 ~Core() override;
[email protected]1a559442012-05-27 07:18:46124
[email protected]1a559442012-05-27 07:18:46125 void ConnectToChannel(bool success, const IPC::ChannelHandle& handle);
126
[email protected]6464cc12012-07-12 09:25:53127 void InitializeOnIOThread();
avib896c712015-12-26 02:10:43128 void DeauthorizeContentLicensesOnIOThread(uint32_t request_id);
fdoray5652bcd2017-02-07 16:03:54129 void DeauthorizeContentLicensesAsync(uint32_t request_id,
130 const base::FilePath& profile_path);
avib896c712015-12-26 02:10:43131 void DeauthorizeContentLicensesInPlugin(uint32_t request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33132 void GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43133 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33134 PP_Flash_BrowserOperations_SettingType setting_type);
135 void SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43136 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33137 PP_Flash_BrowserOperations_SettingType setting_type,
138 PP_Flash_BrowserOperations_Permission permission,
139 bool clear_site_specific);
140 void SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43141 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33142 PP_Flash_BrowserOperations_SettingType setting_type,
143 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:43144 void GetSitesWithDataOnIOThread(uint32_t request_id);
145 void ClearSiteDataOnIOThread(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53146 const std::string& site,
avib896c712015-12-26 02:10:43147 uint64_t flags,
148 uint64_t max_age);
[email protected]4d4ee4c2012-06-22 19:11:30149 void DetachOnIOThread();
[email protected]ee4dd682012-06-12 15:49:33150
[email protected]1a559442012-05-27 07:18:46151 void NotifyErrorFromIOThread();
152
avib896c712015-12-26 02:10:43153 void NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46154 bool success);
[email protected]ee4dd682012-06-12 15:49:33155 void NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43156 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33157 bool success,
158 PP_Flash_BrowserOperations_Permission default_permission,
159 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:43160 void NotifySetDefaultPermissionCompleted(uint32_t request_id, bool success);
161 void NotifySetSitePermissionCompleted(uint32_t request_id, bool success);
162 void NotifyGetSitesWithDataCompleted(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53163 const std::vector<std::string>& sites);
avib896c712015-12-26 02:10:43164 void NotifyClearSiteDataCompleted(uint32_t request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33165
[email protected]1a559442012-05-27 07:18:46166 void NotifyError(
avib896c712015-12-26 02:10:43167 const std::vector<std::pair<uint32_t, RequestType>>& notifications);
[email protected]1a559442012-05-27 07:18:46168
169 // Message handlers.
avib896c712015-12-26 02:10:43170 void OnDeauthorizeContentLicensesResult(uint32_t request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33171 void OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43172 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33173 bool success,
174 PP_Flash_BrowserOperations_Permission default_permission,
175 const ppapi::FlashSiteSettings& sites);
avib896c712015-12-26 02:10:43176 void OnSetDefaultPermissionResult(uint32_t request_id, bool success);
177 void OnSetSitePermissionResult(uint32_t request_id, bool success);
178 void OnGetSitesWithDataResult(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53179 const std::vector<std::string>& sites);
avib896c712015-12-26 02:10:43180 void OnClearSiteDataResult(uint32_t request_id, bool success);
[email protected]1a559442012-05-27 07:18:46181
182 // Used only on the UI thread.
[email protected]7c826912012-10-01 22:05:27183 base::WeakPtr<PepperFlashSettingsManager> manager_;
[email protected]1a559442012-05-27 07:18:46184
185 // Used only on the I/O thread.
[email protected]650b2d52013-02-10 03:41:45186 base::FilePath plugin_data_path_;
[email protected]1a559442012-05-27 07:18:46187
188 // The channel is NULL until we have opened a connection to the broker
189 // process. Used only on the I/O thread.
dcheng4af48582016-04-19 00:29:35190 std::unique_ptr<IPC::Channel> channel_;
[email protected]1a559442012-05-27 07:18:46191
192 // Used only on the I/O thread.
[email protected]7c826912012-10-01 22:05:27193 State state_;
[email protected]1a559442012-05-27 07:18:46194
195 // Requests that need to be sent once the channel to the broker process is
196 // established. Used only on the I/O thread.
197 std::vector<PendingRequest> pending_requests_;
198 // Requests that have been sent but haven't got replied. Used only on the
199 // I/O thread.
avib896c712015-12-26 02:10:43200 std::map<uint32_t, RequestType> pending_responses_;
[email protected]1a559442012-05-27 07:18:46201
202 // Used only on the I/O thread.
203 scoped_refptr<content::PepperFlashSettingsHelper> helper_;
204
205 // Path for the current profile. Must be retrieved on the UI thread from the
206 // browser context when we start so we can use it later on the I/O thread.
[email protected]650b2d52013-02-10 03:41:45207 base::FilePath browser_context_path_;
[email protected]1a559442012-05-27 07:18:46208
209 scoped_refptr<PluginPrefs> plugin_prefs_;
210};
211
[email protected]7c826912012-10-01 22:05:27212PepperFlashSettingsManager::Core::Core(
213 base::WeakPtr<PepperFlashSettingsManager> manager,
214 content::BrowserContext* browser_context)
[email protected]1a559442012-05-27 07:18:46215 : manager_(manager),
[email protected]7c826912012-10-01 22:05:27216 state_(STATE_UNINITIALIZED),
[email protected]1a559442012-05-27 07:18:46217 browser_context_path_(browser_context->GetPath()),
218 plugin_prefs_(PluginPrefs::GetForProfile(
219 Profile::FromBrowserContext(browser_context))) {
thestig00844cea2015-09-08 21:44:52220 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46221}
222
223PepperFlashSettingsManager::Core::~Core() {
thestig00844cea2015-09-08 21:44:52224 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]1a559442012-05-27 07:18:46225}
226
[email protected]6464cc12012-07-12 09:25:53227void PepperFlashSettingsManager::Core::Initialize() {
thestig00844cea2015-09-08 21:44:52228 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]6464cc12012-07-12 09:25:53229 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
230 base::Bind(&Core::InitializeOnIOThread, this));
231}
232
[email protected]1a559442012-05-27 07:18:46233void PepperFlashSettingsManager::Core::Detach() {
thestig00844cea2015-09-08 21:44:52234 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46235
[email protected]7c826912012-10-01 22:05:27236 // This call guarantees that one ref is retained until we get to the DETACHED
237 // state. This is important. Otherwise, if the ref count drops to zero on the
[email protected]4d4ee4c2012-06-22 19:11:30238 // UI thread (which posts a task to delete this object on the I/O thread)
239 // while the I/O thread doesn't know about it, methods on the I/O thread might
240 // increase the ref count again and cause double deletion.
241 BrowserThread::PostTask(
242 BrowserThread::IO, FROM_HERE, base::Bind(&Core::DetachOnIOThread, this));
[email protected]1a559442012-05-27 07:18:46243}
244
245void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
avib896c712015-12-26 02:10:43246 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52247 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46248
249 BrowserThread::PostTask(
250 BrowserThread::IO, FROM_HERE,
251 base::Bind(&Core::DeauthorizeContentLicensesOnIOThread, this,
252 request_id));
253}
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
260 BrowserThread::PostTask(
261 BrowserThread::IO, FROM_HERE,
262 base::Bind(&Core::GetPermissionSettingsOnIOThread, this, request_id,
263 setting_type));
264}
265
266void PepperFlashSettingsManager::Core::SetDefaultPermission(
avib896c712015-12-26 02:10:43267 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33268 PP_Flash_BrowserOperations_SettingType setting_type,
269 PP_Flash_BrowserOperations_Permission permission,
270 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52271 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33272
273 BrowserThread::PostTask(
274 BrowserThread::IO, FROM_HERE,
275 base::Bind(&Core::SetDefaultPermissionOnIOThread, this, request_id,
276 setting_type, permission, clear_site_specific));
277}
278
279void PepperFlashSettingsManager::Core::SetSitePermission(
avib896c712015-12-26 02:10:43280 uint32_t request_id,
[email protected]7c826912012-10-01 22:05:27281 PP_Flash_BrowserOperations_SettingType setting_type,
282 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52283 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33284
285 BrowserThread::PostTask(
286 BrowserThread::IO, FROM_HERE,
287 base::Bind(&Core::SetSitePermissionOnIOThread, this, request_id,
288 setting_type, sites));
289}
290
avib896c712015-12-26 02:10:43291void PepperFlashSettingsManager::Core::GetSitesWithData(uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52292 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53293
294 BrowserThread::PostTask(
295 BrowserThread::IO, FROM_HERE,
296 base::Bind(&Core::GetSitesWithDataOnIOThread, this, request_id));
297}
298
avib896c712015-12-26 02:10:43299void PepperFlashSettingsManager::Core::ClearSiteData(uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53300 const std::string& site,
avib896c712015-12-26 02:10:43301 uint64_t flags,
302 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52303 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53304
305 BrowserThread::PostTask(
306 BrowserThread::IO, FROM_HERE,
307 base::Bind(&Core::ClearSiteDataOnIOThread, this, request_id,
308 site, flags, max_age));
309}
310
[email protected]1a559442012-05-27 07:18:46311bool PepperFlashSettingsManager::Core::OnMessageReceived(
312 const IPC::Message& message) {
313 IPC_BEGIN_MESSAGE_MAP(Core, message)
314 IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult,
315 OnDeauthorizeContentLicensesResult)
[email protected]ee4dd682012-06-12 15:49:33316 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult,
317 OnGetPermissionSettingsResult)
318 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult,
319 OnSetDefaultPermissionResult)
320 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult,
321 OnSetSitePermissionResult)
[email protected]951ef0b2012-07-27 22:46:53322 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult,
323 OnGetSitesWithDataResult)
324 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult,
325 OnClearSiteDataResult)
[email protected]1a559442012-05-27 07:18:46326 IPC_MESSAGE_UNHANDLED_ERROR()
327 IPC_END_MESSAGE_MAP()
328
329 return true;
330}
331
332void PepperFlashSettingsManager::Core::OnChannelError() {
thestig00844cea2015-09-08 21:44:52333 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27334 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30335 return;
[email protected]1a559442012-05-27 07:18:46336
337 NotifyErrorFromIOThread();
338}
339
[email protected]1a559442012-05-27 07:18:46340void PepperFlashSettingsManager::Core::ConnectToChannel(
341 bool success,
342 const IPC::ChannelHandle& handle) {
thestig00844cea2015-09-08 21:44:52343 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27344 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30345 return;
346
[email protected]7c826912012-10-01 22:05:27347 DCHECK(state_ == STATE_UNINITIALIZED);
[email protected]1a559442012-05-27 07:18:46348 DCHECK(!channel_.get());
349
350 if (!success) {
[email protected]ee4dd682012-06-12 15:49:33351 DLOG(ERROR) << "Couldn't open plugin channel";
[email protected]1a559442012-05-27 07:18:46352 NotifyErrorFromIOThread();
353 return;
354 }
355
[email protected]e482111a82014-05-30 03:58:59356 channel_ = IPC::Channel::CreateClient(handle, this);
[email protected]1a559442012-05-27 07:18:46357 if (!channel_->Connect()) {
[email protected]ee4dd682012-06-12 15:49:33358 DLOG(ERROR) << "Couldn't connect to plugin";
[email protected]1a559442012-05-27 07:18:46359 NotifyErrorFromIOThread();
360 return;
361 }
362
[email protected]7c826912012-10-01 22:05:27363 state_ = STATE_INITIALIZED;
[email protected]1a559442012-05-27 07:18:46364
365 std::vector<PendingRequest> temp_pending_requests;
366 temp_pending_requests.swap(pending_requests_);
367 for (std::vector<PendingRequest>::iterator iter =
368 temp_pending_requests.begin();
369 iter != temp_pending_requests.end(); ++iter) {
370 switch (iter->type) {
[email protected]951ef0b2012-07-27 22:46:53371 case INVALID_REQUEST_TYPE:
372 NOTREACHED();
373 break;
[email protected]1a559442012-05-27 07:18:46374 case DEAUTHORIZE_CONTENT_LICENSES:
375 DeauthorizeContentLicensesOnIOThread(iter->id);
376 break;
[email protected]ee4dd682012-06-12 15:49:33377 case GET_PERMISSION_SETTINGS:
378 GetPermissionSettingsOnIOThread(iter->id, iter->setting_type);
379 break;
380 case SET_DEFAULT_PERMISSION:
381 SetDefaultPermissionOnIOThread(
382 iter->id, iter->setting_type, iter->permission,
383 iter->clear_site_specific);
384 break;
385 case SET_SITE_PERMISSION:
386 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites);
387 break;
[email protected]951ef0b2012-07-27 22:46:53388 case GET_SITES_WITH_DATA:
389 GetSitesWithDataOnIOThread(iter->id);
390 break;
391 case CLEAR_SITE_DATA:
392 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags,
393 iter->max_age);
[email protected]1a559442012-05-27 07:18:46394 break;
395 }
396 }
397}
398
[email protected]6464cc12012-07-12 09:25:53399void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
thestig00844cea2015-09-08 21:44:52400 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27401 DCHECK_EQ(STATE_UNINITIALIZED, state_);
[email protected]6464cc12012-07-12 09:25:53402
[email protected]d7bd3e52013-07-21 04:29:20403 content::WebPluginInfo plugin_info;
[email protected]6464cc12012-07-12 09:25:53404 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
405 &plugin_info)) {
406 NotifyErrorFromIOThread();
407 return;
408 }
409
[email protected]650b2d52013-02-10 03:41:45410 base::FilePath profile_path =
[email protected]6464cc12012-07-12 09:25:53411 browser_context_path_.Append(content::kPepperDataDirname);
412#if defined(OS_WIN)
413 plugin_data_path_ = profile_path.Append(plugin_info.name);
414#else
[email protected]6778fed2013-12-24 20:09:37415 plugin_data_path_ = profile_path.Append(base::UTF16ToUTF8(plugin_info.name));
[email protected]6464cc12012-07-12 09:25:53416#endif
417
418 helper_ = content::PepperFlashSettingsHelper::Create();
419 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
420 base::Bind(&Core::ConnectToChannel, this);
421 helper_->OpenChannelToBroker(plugin_info.path, callback);
422}
423
[email protected]1a559442012-05-27 07:18:46424void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
avib896c712015-12-26 02:10:43425 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52426 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27427 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46428
[email protected]7c826912012-10-01 22:05:27429 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46430 PendingRequest request;
431 request.id = request_id;
432 request.type = DEAUTHORIZE_CONTENT_LICENSES;
433 pending_requests_.push_back(request);
434 return;
435 }
436
437 pending_responses_.insert(
438 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
[email protected]7c826912012-10-01 22:05:27439 if (state_ == STATE_ERROR) {
440 NotifyErrorFromIOThread();
441 return;
442 }
443
[email protected]bb9c9752013-04-25 23:02:11444#if defined(OS_CHROMEOS)
fdoray5652bcd2017-02-07 16:03:54445 base::PostTaskWithTraits(FROM_HERE,
446 base::TaskTraits().MayBlock().WithPriority(
447 base::TaskPriority::BACKGROUND),
448 base::Bind(&Core::DeauthorizeContentLicensesAsync,
449 this, request_id, browser_context_path_));
[email protected]bb9c9752013-04-25 23:02:11450#else
451 DeauthorizeContentLicensesInPlugin(request_id, true);
452#endif
453}
454
455// TODO(raymes): This is temporary code to migrate ChromeOS devices to the new
456// scheme for generating device IDs. Delete this once we are sure most ChromeOS
457// devices have been migrated.
fdoray5652bcd2017-02-07 16:03:54458void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesAsync(
avib896c712015-12-26 02:10:43459 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11460 const base::FilePath& profile_path) {
461 // ChromeOS used to store the device ID in a file but this is no longer used.
462 // Wipe that file.
463 const base::FilePath& device_id_path =
464 chrome::DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
[email protected]dd3aa792013-07-16 19:10:23465 bool success = base::DeleteFile(device_id_path, false);
[email protected]bb9c9752013-04-25 23:02:11466
467 BrowserThread::PostTask(
468 BrowserThread::IO, FROM_HERE,
469 base::Bind(&Core::DeauthorizeContentLicensesInPlugin, this, request_id,
470 success));
471}
472
473void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
avib896c712015-12-26 02:10:43474 uint32_t request_id,
[email protected]bb9c9752013-04-25 23:02:11475 bool success) {
thestig00844cea2015-09-08 21:44:52476 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]bb9c9752013-04-25 23:02:11477 if (!success) {
478 NotifyErrorFromIOThread();
479 return;
480 }
[email protected]1a559442012-05-27 07:18:46481 IPC::Message* msg =
482 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
483 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33484 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
485 // A failure notification for the current request will be sent since
486 // |pending_responses_| has been updated.
487 NotifyErrorFromIOThread();
488 }
489}
490
491void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
avib896c712015-12-26 02:10:43492 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33493 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52494 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27495 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33496
[email protected]7c826912012-10-01 22:05:27497 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33498 PendingRequest request;
499 request.id = request_id;
500 request.type = GET_PERMISSION_SETTINGS;
501 request.setting_type = setting_type;
502 pending_requests_.push_back(request);
503 return;
504 }
505
506 pending_responses_.insert(
507 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
[email protected]7c826912012-10-01 22:05:27508 if (state_ == STATE_ERROR) {
509 NotifyErrorFromIOThread();
510 return;
511 }
512
[email protected]ee4dd682012-06-12 15:49:33513 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
514 request_id, plugin_data_path_, setting_type);
515 if (!channel_->Send(msg)) {
516 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
517 // A failure notification for the current request will be sent since
518 // |pending_responses_| has been updated.
519 NotifyErrorFromIOThread();
520 }
521}
522
523void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
avib896c712015-12-26 02:10:43524 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33525 PP_Flash_BrowserOperations_SettingType setting_type,
526 PP_Flash_BrowserOperations_Permission permission,
527 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:52528 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27529 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33530
[email protected]7c826912012-10-01 22:05:27531 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33532 PendingRequest request;
533 request.id = request_id;
534 request.type = SET_DEFAULT_PERMISSION;
535 request.setting_type = setting_type;
536 request.permission = permission;
537 request.clear_site_specific = clear_site_specific;
538 pending_requests_.push_back(request);
539 return;
540 }
541
542 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
[email protected]7c826912012-10-01 22:05:27543 if (state_ == STATE_ERROR) {
544 NotifyErrorFromIOThread();
545 return;
546 }
547
[email protected]ee4dd682012-06-12 15:49:33548 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
549 request_id, plugin_data_path_, setting_type, permission,
550 clear_site_specific);
551 if (!channel_->Send(msg)) {
552 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
553 // A failure notification for the current request will be sent since
554 // |pending_responses_| has been updated.
555 NotifyErrorFromIOThread();
556 }
557}
558
559void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
avib896c712015-12-26 02:10:43560 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33561 PP_Flash_BrowserOperations_SettingType setting_type,
562 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52563 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27564 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33565
[email protected]7c826912012-10-01 22:05:27566 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33567 pending_requests_.push_back(PendingRequest());
568 PendingRequest& request = pending_requests_.back();
569 request.id = request_id;
570 request.type = SET_SITE_PERMISSION;
571 request.setting_type = setting_type;
572 request.sites = sites;
573 return;
574 }
575
576 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
[email protected]7c826912012-10-01 22:05:27577 if (state_ == STATE_ERROR) {
578 NotifyErrorFromIOThread();
579 return;
580 }
581
[email protected]ee4dd682012-06-12 15:49:33582 IPC::Message* msg = new PpapiMsg_SetSitePermission(
583 request_id, plugin_data_path_, setting_type, sites);
584 if (!channel_->Send(msg)) {
585 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46586 // A failure notification for the current request will be sent since
587 // |pending_responses_| has been updated.
588 NotifyErrorFromIOThread();
589 }
590}
591
[email protected]951ef0b2012-07-27 22:46:53592void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
avib896c712015-12-26 02:10:43593 uint32_t request_id) {
thestig00844cea2015-09-08 21:44:52594 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27595 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53596
[email protected]7c826912012-10-01 22:05:27597 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53598 pending_requests_.push_back(PendingRequest());
599 PendingRequest& request = pending_requests_.back();
600 request.id = request_id;
601 request.type = GET_SITES_WITH_DATA;
602 return;
603 }
604
605 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
[email protected]7c826912012-10-01 22:05:27606 if (state_ == STATE_ERROR) {
607 NotifyErrorFromIOThread();
608 return;
609 }
610
[email protected]951ef0b2012-07-27 22:46:53611 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
612 request_id, plugin_data_path_);
613 if (!channel_->Send(msg)) {
614 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
615 // A failure notification for the current request will be sent since
616 // |pending_responses_| has been updated.
617 NotifyErrorFromIOThread();
618 }
619}
620
621void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
avib896c712015-12-26 02:10:43622 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53623 const std::string& site,
avib896c712015-12-26 02:10:43624 uint64_t flags,
625 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:52626 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27627 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53628
[email protected]7c826912012-10-01 22:05:27629 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53630 pending_requests_.push_back(PendingRequest());
631 PendingRequest& request = pending_requests_.back();
632 request.id = request_id;
633 request.type = CLEAR_SITE_DATA;
634 request.site = site;
635 request.flags = flags;
636 request.max_age = max_age;
637 return;
638 }
639
640 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
[email protected]7c826912012-10-01 22:05:27641 if (state_ == STATE_ERROR) {
642 NotifyErrorFromIOThread();
643 return;
644 }
645
[email protected]951ef0b2012-07-27 22:46:53646 IPC::Message* msg = new PpapiMsg_ClearSiteData(
647 request_id, plugin_data_path_, site, flags, max_age);
648 if (!channel_->Send(msg)) {
649 DLOG(ERROR) << "Couldn't send ClearSiteData message";
650 // A failure notification for the current request will be sent since
651 // |pending_responses_| has been updated.
652 NotifyErrorFromIOThread();
653 }
654}
655
[email protected]4d4ee4c2012-06-22 19:11:30656void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27657 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30658}
659
[email protected]1a559442012-05-27 07:18:46660void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
thestig00844cea2015-09-08 21:44:52661 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27662 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30663 return;
[email protected]1a559442012-05-27 07:18:46664
[email protected]7c826912012-10-01 22:05:27665 state_ = STATE_ERROR;
avib896c712015-12-26 02:10:43666 std::vector<std::pair<uint32_t, RequestType>> notifications;
[email protected]1a559442012-05-27 07:18:46667 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin();
668 iter != pending_requests_.end(); ++iter) {
669 notifications.push_back(std::make_pair(iter->id, iter->type));
670 }
671 pending_requests_.clear();
672 notifications.insert(notifications.end(), pending_responses_.begin(),
673 pending_responses_.end());
674 pending_responses_.clear();
675
676 BrowserThread::PostTask(
677 BrowserThread::UI, FROM_HERE,
678 base::Bind(&Core::NotifyError, this, notifications));
679}
680
avib896c712015-12-26 02:10:43681void PepperFlashSettingsManager::Core::
682 NotifyDeauthorizeContentLicensesCompleted(uint32_t request_id,
683 bool success) {
thestig00844cea2015-09-08 21:44:52684 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46685
[email protected]7c826912012-10-01 22:05:27686 if (manager_.get()) {
jrummellbffd01242016-06-30 00:30:37687 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(request_id,
688 success);
[email protected]1a559442012-05-27 07:18:46689 }
690}
691
[email protected]ee4dd682012-06-12 15:49:33692void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
avib896c712015-12-26 02:10:43693 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33694 bool success,
695 PP_Flash_BrowserOperations_Permission default_permission,
696 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52697 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33698
[email protected]7c826912012-10-01 22:05:27699 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33700 manager_->client_->OnGetPermissionSettingsCompleted(
701 request_id, success, default_permission, sites);
702 }
703}
704
705void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
avib896c712015-12-26 02:10:43706 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33707 bool success) {
thestig00844cea2015-09-08 21:44:52708 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33709
[email protected]7c826912012-10-01 22:05:27710 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33711 manager_->client_->OnSetDefaultPermissionCompleted(
712 request_id, success);
713 }
714}
715
716void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
avib896c712015-12-26 02:10:43717 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33718 bool success) {
thestig00844cea2015-09-08 21:44:52719 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33720
[email protected]7c826912012-10-01 22:05:27721 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33722 manager_->client_->OnSetSitePermissionCompleted(
723 request_id, success);
724 }
725}
726
[email protected]951ef0b2012-07-27 22:46:53727void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
avib896c712015-12-26 02:10:43728 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53729 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52730 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53731
[email protected]7c826912012-10-01 22:05:27732 if (manager_.get()) {
[email protected]951ef0b2012-07-27 22:46:53733 manager_->client_->OnGetSitesWithDataCompleted(
734 request_id, sites);
735 }
736}
737
738void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
avib896c712015-12-26 02:10:43739 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53740 bool success) {
thestig00844cea2015-09-08 21:44:52741 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:53742
[email protected]7c826912012-10-01 22:05:27743 if (manager_.get())
[email protected]951ef0b2012-07-27 22:46:53744 manager_->client_->OnClearSiteDataCompleted(request_id, success);
745}
746
[email protected]1a559442012-05-27 07:18:46747void PepperFlashSettingsManager::Core::NotifyError(
avib896c712015-12-26 02:10:43748 const std::vector<std::pair<uint32_t, RequestType>>& notifications) {
thestig00844cea2015-09-08 21:44:52749 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46750
751 scoped_refptr<Core> protector(this);
avib896c712015-12-26 02:10:43752 for (std::vector<std::pair<uint32_t, RequestType>>::const_iterator iter =
753 notifications.begin();
754 iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27755 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46756 // the callbacks.
[email protected]7c826912012-10-01 22:05:27757 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53758 return;
759
760 switch (iter->second) {
761 case INVALID_REQUEST_TYPE:
762 NOTREACHED();
763 break;
764 case DEAUTHORIZE_CONTENT_LICENSES:
jrummellbffd01242016-06-30 00:30:37765 manager_->client_->OnDeauthorizeFlashContentLicensesCompleted(
[email protected]951ef0b2012-07-27 22:46:53766 iter->first, false);
767 break;
768 case GET_PERMISSION_SETTINGS:
769 manager_->client_->OnGetPermissionSettingsCompleted(
770 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
771 ppapi::FlashSiteSettings());
772 break;
773 case SET_DEFAULT_PERMISSION:
774 manager_->client_->OnSetDefaultPermissionCompleted(
775 iter->first, false);
776 break;
777 case SET_SITE_PERMISSION:
778 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
779 break;
780 case GET_SITES_WITH_DATA:
781 manager_->client_->OnGetSitesWithDataCompleted(
782 iter->first, std::vector<std::string>());
783 break;
784 case CLEAR_SITE_DATA:
785 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
786 break;
[email protected]1a559442012-05-27 07:18:46787 }
788 }
789
[email protected]7c826912012-10-01 22:05:27790 if (manager_.get())
791 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46792}
793
794void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
avib896c712015-12-26 02:10:43795 uint32_t request_id,
[email protected]1a559442012-05-27 07:18:46796 bool success) {
thestig00844cea2015-09-08 21:44:52797 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27798 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30799 return;
800
[email protected]ee4dd682012-06-12 15:49:33801 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46802
avib896c712015-12-26 02:10:43803 std::map<uint32_t, RequestType>::iterator iter =
[email protected]1a559442012-05-27 07:18:46804 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53805 if (iter == pending_responses_.end())
806 return;
[email protected]1a559442012-05-27 07:18:46807
[email protected]951ef0b2012-07-27 22:46:53808 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
809
810 pending_responses_.erase(iter);
811 BrowserThread::PostTask(
812 BrowserThread::UI, FROM_HERE,
813 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
814 request_id, success));
[email protected]1a559442012-05-27 07:18:46815}
816
[email protected]ee4dd682012-06-12 15:49:33817void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
avib896c712015-12-26 02:10:43818 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33819 bool success,
820 PP_Flash_BrowserOperations_Permission default_permission,
821 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:52822 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27823 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30824 return;
825
[email protected]ee4dd682012-06-12 15:49:33826 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
827
avib896c712015-12-26 02:10:43828 std::map<uint32_t, RequestType>::iterator iter =
[email protected]ee4dd682012-06-12 15:49:33829 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53830 if (iter == pending_responses_.end())
831 return;
[email protected]ee4dd682012-06-12 15:49:33832
[email protected]951ef0b2012-07-27 22:46:53833 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
834
835 pending_responses_.erase(iter);
836 BrowserThread::PostTask(
837 BrowserThread::UI, FROM_HERE,
838 base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this,
839 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33840}
841
842void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
avib896c712015-12-26 02:10:43843 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33844 bool success) {
thestig00844cea2015-09-08 21:44:52845 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27846 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30847 return;
848
[email protected]ee4dd682012-06-12 15:49:33849 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
850
avib896c712015-12-26 02:10:43851 std::map<uint32_t, RequestType>::iterator iter =
[email protected]ee4dd682012-06-12 15:49:33852 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53853 if (iter == pending_responses_.end())
854 return;
[email protected]ee4dd682012-06-12 15:49:33855
[email protected]951ef0b2012-07-27 22:46:53856 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
857
858 pending_responses_.erase(iter);
859 BrowserThread::PostTask(
860 BrowserThread::UI, FROM_HERE,
861 base::Bind(&Core::NotifySetDefaultPermissionCompleted, this,
862 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33863}
864
865void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
avib896c712015-12-26 02:10:43866 uint32_t request_id,
[email protected]ee4dd682012-06-12 15:49:33867 bool success) {
thestig00844cea2015-09-08 21:44:52868 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27869 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30870 return;
871
[email protected]ee4dd682012-06-12 15:49:33872 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
873
avib896c712015-12-26 02:10:43874 std::map<uint32_t, RequestType>::iterator iter =
[email protected]ee4dd682012-06-12 15:49:33875 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53876 if (iter == pending_responses_.end())
877 return;
[email protected]ee4dd682012-06-12 15:49:33878
[email protected]951ef0b2012-07-27 22:46:53879 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
880
881 pending_responses_.erase(iter);
882 BrowserThread::PostTask(
883 BrowserThread::UI, FROM_HERE,
884 base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id,
885 success));
886}
887
888void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
avib896c712015-12-26 02:10:43889 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53890 const std::vector<std::string>& sites) {
thestig00844cea2015-09-08 21:44:52891 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27892 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53893 return;
894
avib896c712015-12-26 02:10:43895 std::map<uint32_t, RequestType>::iterator iter =
[email protected]951ef0b2012-07-27 22:46:53896 pending_responses_.find(request_id);
897 if (iter == pending_responses_.end())
898 return;
899
900 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
901
902 pending_responses_.erase(iter);
903 BrowserThread::PostTask(
904 BrowserThread::UI, FROM_HERE,
905 base::Bind(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
906 sites));
907}
908
909void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
avib896c712015-12-26 02:10:43910 uint32_t request_id,
[email protected]951ef0b2012-07-27 22:46:53911 bool success) {
thestig00844cea2015-09-08 21:44:52912 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c826912012-10-01 22:05:27913 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53914 return;
915
916 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
917
avib896c712015-12-26 02:10:43918 std::map<uint32_t, RequestType>::iterator iter =
[email protected]951ef0b2012-07-27 22:46:53919 pending_responses_.find(request_id);
920 if (iter == pending_responses_.end())
921 return;
922
923 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
924
925 pending_responses_.erase(iter);
926 BrowserThread::PostTask(
927 BrowserThread::UI, FROM_HERE,
928 base::Bind(&Core::NotifyClearSiteDataCompleted, this, request_id,
929 success));
[email protected]ee4dd682012-06-12 15:49:33930}
931
[email protected]1a559442012-05-27 07:18:46932PepperFlashSettingsManager::PepperFlashSettingsManager(
933 Client* client,
934 content::BrowserContext* browser_context)
[email protected]f3d65bd2013-10-09 16:26:19935 : client_(client),
[email protected]1a559442012-05-27 07:18:46936 browser_context_(browser_context),
[email protected]f3d65bd2013-10-09 16:26:19937 next_request_id_(1),
938 weak_ptr_factory_(this) {
[email protected]1a559442012-05-27 07:18:46939 DCHECK(client);
940 DCHECK(browser_context);
941}
942
943PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53944 if (core_.get())
[email protected]1a559442012-05-27 07:18:46945 core_->Detach();
[email protected]1a559442012-05-27 07:18:46946}
947
[email protected]18a4d63c82012-05-25 23:37:03948// static
949bool PepperFlashSettingsManager::IsPepperFlashInUse(
950 PluginPrefs* plugin_prefs,
[email protected]d7bd3e52013-07-21 04:29:20951 content::WebPluginInfo* plugin_info) {
[email protected]18a4d63c82012-05-25 23:37:03952 if (!plugin_prefs)
953 return false;
954
955 content::PluginService* plugin_service =
956 content::PluginService::GetInstance();
[email protected]d7bd3e52013-07-21 04:29:20957 std::vector<content::WebPluginInfo> plugins;
[email protected]18a4d63c82012-05-25 23:37:03958 plugin_service->GetPluginInfoArray(
[email protected]73270292013-08-09 03:48:07959 GURL(), content::kFlashPluginSwfMimeType, false, &plugins, NULL);
[email protected]18a4d63c82012-05-25 23:37:03960
[email protected]d7bd3e52013-07-21 04:29:20961 for (std::vector<content::WebPluginInfo>::iterator iter = plugins.begin();
[email protected]18a4d63c82012-05-25 23:37:03962 iter != plugins.end(); ++iter) {
[email protected]51ee5822013-07-19 16:47:09963 if (iter->is_pepper_plugin() && plugin_prefs->IsPluginEnabled(*iter)) {
[email protected]18a4d63c82012-05-25 23:37:03964 if (plugin_info)
965 *plugin_info = *iter;
966 return true;
967 }
968 }
969 return false;
970}
971
972// static
[email protected]37ca3fe02013-07-05 15:32:44973void PepperFlashSettingsManager::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34974 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:25975 registry->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled, true);
[email protected]18a4d63c82012-05-25 23:37:03976}
[email protected]1a559442012-05-27 07:18:46977
avib896c712015-12-26 02:10:43978uint32_t PepperFlashSettingsManager::DeauthorizeContentLicenses(
[email protected]bb9c9752013-04-25 23:02:11979 PrefService* prefs) {
thestig00844cea2015-09-08 21:44:52980 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]1a559442012-05-27 07:18:46981
[email protected]bb9c9752013-04-25 23:02:11982 // Clear the device ID salt which has the effect of regenerating a device
983 // ID. Since this happens synchronously (and on the UI thread), we don't have
984 // to add it to a pending request.
985 prefs->ClearPref(prefs::kDRMSalt);
986
[email protected]1a559442012-05-27 07:18:46987 EnsureCoreExists();
avib896c712015-12-26 02:10:43988 uint32_t id = GetNextRequestId();
[email protected]1a559442012-05-27 07:18:46989 core_->DeauthorizeContentLicenses(id);
990 return id;
991}
992
avib896c712015-12-26 02:10:43993uint32_t PepperFlashSettingsManager::GetPermissionSettings(
[email protected]ee4dd682012-06-12 15:49:33994 PP_Flash_BrowserOperations_SettingType setting_type) {
thestig00844cea2015-09-08 21:44:52995 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:33996
997 EnsureCoreExists();
avib896c712015-12-26 02:10:43998 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:33999 core_->GetPermissionSettings(id, setting_type);
1000 return id;
1001}
1002
avib896c712015-12-26 02:10:431003uint32_t PepperFlashSettingsManager::SetDefaultPermission(
[email protected]ee4dd682012-06-12 15:49:331004 PP_Flash_BrowserOperations_SettingType setting_type,
1005 PP_Flash_BrowserOperations_Permission permission,
1006 bool clear_site_specific) {
thestig00844cea2015-09-08 21:44:521007 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:331008
1009 EnsureCoreExists();
avib896c712015-12-26 02:10:431010 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331011 core_->SetDefaultPermission(id, setting_type, permission,
1012 clear_site_specific);
1013 return id;
1014}
1015
avib896c712015-12-26 02:10:431016uint32_t PepperFlashSettingsManager::SetSitePermission(
[email protected]ee4dd682012-06-12 15:49:331017 PP_Flash_BrowserOperations_SettingType setting_type,
1018 const ppapi::FlashSiteSettings& sites) {
thestig00844cea2015-09-08 21:44:521019 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]ee4dd682012-06-12 15:49:331020
1021 EnsureCoreExists();
avib896c712015-12-26 02:10:431022 uint32_t id = GetNextRequestId();
[email protected]ee4dd682012-06-12 15:49:331023 core_->SetSitePermission(id, setting_type, sites);
1024 return id;
1025}
1026
avib896c712015-12-26 02:10:431027uint32_t PepperFlashSettingsManager::GetSitesWithData() {
thestig00844cea2015-09-08 21:44:521028 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531029
1030 EnsureCoreExists();
avib896c712015-12-26 02:10:431031 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531032 core_->GetSitesWithData(id);
1033 return id;
1034}
1035
avib896c712015-12-26 02:10:431036uint32_t PepperFlashSettingsManager::ClearSiteData(const std::string& site,
1037 uint64_t flags,
1038 uint64_t max_age) {
thestig00844cea2015-09-08 21:44:521039 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]951ef0b2012-07-27 22:46:531040
1041 EnsureCoreExists();
avib896c712015-12-26 02:10:431042 uint32_t id = GetNextRequestId();
[email protected]951ef0b2012-07-27 22:46:531043 core_->ClearSiteData(id, site, flags, max_age);
1044 return id;
1045}
1046
avib896c712015-12-26 02:10:431047uint32_t PepperFlashSettingsManager::GetNextRequestId() {
[email protected]1a559442012-05-27 07:18:461048 return next_request_id_++;
1049}
1050
1051void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531052 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271053 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531054 core_->Initialize();
1055 }
[email protected]1a559442012-05-27 07:18:461056}
1057
[email protected]7c826912012-10-01 22:05:271058void PepperFlashSettingsManager::OnError(Core* core) {
1059 DCHECK(core);
1060 if (core != core_.get())
1061 return;
[email protected]1a559442012-05-27 07:18:461062
[email protected]7c826912012-10-01 22:05:271063 core_->Detach();
1064 core_ = NULL;
1065}