blob: fbf0c847db896df7b40b17e7fcd7db5d08bd7ae5 [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"
[email protected]bb9c9752013-04-25 23:02:1113#include "base/file_util.h"
[email protected]3853a4c2013-02-11 17:15:5714#include "base/prefs/pref_service.h"
[email protected]fb441962013-05-08 05:35:2415#include "base/sequenced_task_runner_helpers.h"
[email protected]e309f312013-06-07 21:50:0816#include "base/strings/utf_string_conversions.h"
[email protected]0f5e57f52012-09-20 20:53:1817#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]1a559442012-05-27 07:18:4618#include "chrome/browser/profiles/profile.h"
[email protected]bb9c9752013-04-25 23:02:1119#include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
[email protected]18a4d63c82012-05-25 23:37:0320#include "chrome/common/pref_names.h"
[email protected]75fee372013-03-06 00:42:4421#include "components/user_prefs/pref_registry_syncable.h"
[email protected]1a559442012-05-27 07:18:4622#include "content/public/browser/browser_context.h"
23#include "content/public/browser/browser_thread.h"
24#include "content/public/browser/pepper_flash_settings_helper.h"
[email protected]18a4d63c82012-05-25 23:37:0325#include "content/public/browser/plugin_service.h"
[email protected]1a559442012-05-27 07:18:4626#include "content/public/common/content_constants.h"
[email protected]18a4d63c82012-05-25 23:37:0327#include "googleurl/src/gurl.h"
[email protected]1a559442012-05-27 07:18:4628#include "ipc/ipc_channel.h"
[email protected]4e07f842012-11-15 22:22:1729#include "ipc/ipc_listener.h"
[email protected]1a559442012-05-27 07:18:4630#include "ppapi/proxy/ppapi_messages.h"
[email protected]18a4d63c82012-05-25 23:37:0331#include "webkit/plugins/plugin_constants.h"
32#include "webkit/plugins/webplugininfo.h"
33
[email protected]1a559442012-05-27 07:18:4634using content::BrowserThread;
35
36class PepperFlashSettingsManager::Core
[email protected]b44f8ad2012-06-15 20:52:5837 : public IPC::Listener,
[email protected]1a559442012-05-27 07:18:4638 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> {
39 public:
[email protected]7c826912012-10-01 22:05:2740 Core(base::WeakPtr<PepperFlashSettingsManager> manager,
[email protected]1a559442012-05-27 07:18:4641 content::BrowserContext* browser_context);
42
[email protected]6464cc12012-07-12 09:25:5343 void Initialize();
[email protected]7c826912012-10-01 22:05:2744
45 // Notifies the core that it has been detached. Afterwards, no method should
46 // be called any more.
[email protected]1a559442012-05-27 07:18:4647 void Detach();
48
49 void DeauthorizeContentLicenses(uint32 request_id);
[email protected]ee4dd682012-06-12 15:49:3350 void GetPermissionSettings(
51 uint32 request_id,
52 PP_Flash_BrowserOperations_SettingType setting_type);
53 void SetDefaultPermission(
54 uint32 request_id,
55 PP_Flash_BrowserOperations_SettingType setting_type,
56 PP_Flash_BrowserOperations_Permission permission,
57 bool clear_site_specific);
58 void SetSitePermission(uint32 request_id,
59 PP_Flash_BrowserOperations_SettingType setting_type,
60 const ppapi::FlashSiteSettings& sites);
[email protected]951ef0b2012-07-27 22:46:5361 void GetSitesWithData(uint32 request_id);
62 void ClearSiteData(uint32 request_id,
63 const std::string& site,
64 uint64 flags,
65 uint64 max_age);
[email protected]1a559442012-05-27 07:18:4666
[email protected]b44f8ad2012-06-15 20:52:5867 // IPC::Listener implementation.
[email protected]1a559442012-05-27 07:18:4668 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
69 virtual void OnChannelError() OVERRIDE;
70
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
103 uint32 id;
104 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;
119 uint64 flags;
120 uint64 max_age;
[email protected]1a559442012-05-27 07:18:46121 };
122
123 virtual ~Core();
124
[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();
[email protected]1a559442012-05-27 07:18:46128 void DeauthorizeContentLicensesOnIOThread(uint32 request_id);
[email protected]bb9c9752013-04-25 23:02:11129 void DeauthorizeContentLicensesOnBlockingPool(
130 uint32 request_id,
131 const base::FilePath& profile_path);
132 void DeauthorizeContentLicensesInPlugin(uint32 request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33133 void GetPermissionSettingsOnIOThread(
134 uint32 request_id,
135 PP_Flash_BrowserOperations_SettingType setting_type);
136 void SetDefaultPermissionOnIOThread(
137 uint32 request_id,
138 PP_Flash_BrowserOperations_SettingType setting_type,
139 PP_Flash_BrowserOperations_Permission permission,
140 bool clear_site_specific);
141 void SetSitePermissionOnIOThread(
142 uint32 request_id,
143 PP_Flash_BrowserOperations_SettingType setting_type,
144 const ppapi::FlashSiteSettings& sites);
[email protected]951ef0b2012-07-27 22:46:53145 void GetSitesWithDataOnIOThread(uint32 request_id);
146 void ClearSiteDataOnIOThread(uint32 request_id,
147 const std::string& site,
148 uint64 flags,
149 uint64 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
154 void NotifyDeauthorizeContentLicensesCompleted(uint32 request_id,
155 bool success);
[email protected]ee4dd682012-06-12 15:49:33156 void NotifyGetPermissionSettingsCompleted(
157 uint32 request_id,
158 bool success,
159 PP_Flash_BrowserOperations_Permission default_permission,
160 const ppapi::FlashSiteSettings& sites);
161 void NotifySetDefaultPermissionCompleted(uint32 request_id, bool success);
162 void NotifySetSitePermissionCompleted(uint32 request_id, bool success);
[email protected]951ef0b2012-07-27 22:46:53163 void NotifyGetSitesWithDataCompleted(uint32 request_id,
164 const std::vector<std::string>& sites);
165 void NotifyClearSiteDataCompleted(uint32 request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33166
[email protected]1a559442012-05-27 07:18:46167 void NotifyError(
168 const std::vector<std::pair<uint32, RequestType> >& notifications);
169
170 // Message handlers.
171 void OnDeauthorizeContentLicensesResult(uint32 request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33172 void OnGetPermissionSettingsResult(
173 uint32 request_id,
174 bool success,
175 PP_Flash_BrowserOperations_Permission default_permission,
176 const ppapi::FlashSiteSettings& sites);
177 void OnSetDefaultPermissionResult(uint32 request_id, bool success);
178 void OnSetSitePermissionResult(uint32 request_id, bool success);
[email protected]951ef0b2012-07-27 22:46:53179 void OnGetSitesWithDataResult(uint32 request_id,
180 const std::vector<std::string>& sites);
181 void OnClearSiteDataResult(uint32 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.
191 scoped_ptr<IPC::Channel> channel_;
192
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.
201 std::map<uint32, RequestType> pending_responses_;
202
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))) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]1a559442012-05-27 07:18:46222}
223
224PepperFlashSettingsManager::Core::~Core() {
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
226}
227
[email protected]6464cc12012-07-12 09:25:53228void PepperFlashSettingsManager::Core::Initialize() {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
230 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
231 base::Bind(&Core::InitializeOnIOThread, this));
232}
233
[email protected]1a559442012-05-27 07:18:46234void PepperFlashSettingsManager::Core::Detach() {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236
[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.
242 BrowserThread::PostTask(
243 BrowserThread::IO, FROM_HERE, base::Bind(&Core::DetachOnIOThread, this));
[email protected]1a559442012-05-27 07:18:46244}
245
246void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
247 uint32 request_id) {
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
249
250 BrowserThread::PostTask(
251 BrowserThread::IO, FROM_HERE,
252 base::Bind(&Core::DeauthorizeContentLicensesOnIOThread, this,
253 request_id));
254}
255
[email protected]ee4dd682012-06-12 15:49:33256void PepperFlashSettingsManager::Core::GetPermissionSettings(
257 uint32 request_id,
258 PP_Flash_BrowserOperations_SettingType setting_type) {
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
260
261 BrowserThread::PostTask(
262 BrowserThread::IO, FROM_HERE,
263 base::Bind(&Core::GetPermissionSettingsOnIOThread, this, request_id,
264 setting_type));
265}
266
267void PepperFlashSettingsManager::Core::SetDefaultPermission(
268 uint32 request_id,
269 PP_Flash_BrowserOperations_SettingType setting_type,
270 PP_Flash_BrowserOperations_Permission permission,
271 bool clear_site_specific) {
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
273
274 BrowserThread::PostTask(
275 BrowserThread::IO, FROM_HERE,
276 base::Bind(&Core::SetDefaultPermissionOnIOThread, this, request_id,
277 setting_type, permission, clear_site_specific));
278}
279
280void PepperFlashSettingsManager::Core::SetSitePermission(
[email protected]7c826912012-10-01 22:05:27281 uint32 request_id,
282 PP_Flash_BrowserOperations_SettingType setting_type,
283 const ppapi::FlashSiteSettings& sites) {
[email protected]ee4dd682012-06-12 15:49:33284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
285
286 BrowserThread::PostTask(
287 BrowserThread::IO, FROM_HERE,
288 base::Bind(&Core::SetSitePermissionOnIOThread, this, request_id,
289 setting_type, sites));
290}
291
[email protected]951ef0b2012-07-27 22:46:53292void PepperFlashSettingsManager::Core::GetSitesWithData(uint32 request_id) {
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
294
295 BrowserThread::PostTask(
296 BrowserThread::IO, FROM_HERE,
297 base::Bind(&Core::GetSitesWithDataOnIOThread, this, request_id));
298}
299
300void PepperFlashSettingsManager::Core::ClearSiteData(uint32 request_id,
301 const std::string& site,
302 uint64 flags,
303 uint64 max_age) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
305
306 BrowserThread::PostTask(
307 BrowserThread::IO, FROM_HERE,
308 base::Bind(&Core::ClearSiteDataOnIOThread, this, request_id,
309 site, flags, max_age));
310}
311
[email protected]1a559442012-05-27 07:18:46312bool PepperFlashSettingsManager::Core::OnMessageReceived(
313 const IPC::Message& message) {
314 IPC_BEGIN_MESSAGE_MAP(Core, message)
315 IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult,
316 OnDeauthorizeContentLicensesResult)
[email protected]ee4dd682012-06-12 15:49:33317 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult,
318 OnGetPermissionSettingsResult)
319 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult,
320 OnSetDefaultPermissionResult)
321 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult,
322 OnSetSitePermissionResult)
[email protected]951ef0b2012-07-27 22:46:53323 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult,
324 OnGetSitesWithDataResult)
325 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult,
326 OnClearSiteDataResult)
[email protected]1a559442012-05-27 07:18:46327 IPC_MESSAGE_UNHANDLED_ERROR()
328 IPC_END_MESSAGE_MAP()
329
330 return true;
331}
332
333void PepperFlashSettingsManager::Core::OnChannelError() {
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27335 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30336 return;
[email protected]1a559442012-05-27 07:18:46337
338 NotifyErrorFromIOThread();
339}
340
[email protected]1a559442012-05-27 07:18:46341void PepperFlashSettingsManager::Core::ConnectToChannel(
342 bool success,
343 const IPC::ChannelHandle& handle) {
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27345 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30346 return;
347
[email protected]7c826912012-10-01 22:05:27348 DCHECK(state_ == STATE_UNINITIALIZED);
[email protected]1a559442012-05-27 07:18:46349 DCHECK(!channel_.get());
350
351 if (!success) {
[email protected]ee4dd682012-06-12 15:49:33352 DLOG(ERROR) << "Couldn't open plugin channel";
[email protected]1a559442012-05-27 07:18:46353 NotifyErrorFromIOThread();
354 return;
355 }
356
357 channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this));
358 if (!channel_->Connect()) {
[email protected]ee4dd682012-06-12 15:49:33359 DLOG(ERROR) << "Couldn't connect to plugin";
[email protected]1a559442012-05-27 07:18:46360 NotifyErrorFromIOThread();
361 return;
362 }
363
[email protected]7c826912012-10-01 22:05:27364 state_ = STATE_INITIALIZED;
[email protected]1a559442012-05-27 07:18:46365
366 std::vector<PendingRequest> temp_pending_requests;
367 temp_pending_requests.swap(pending_requests_);
368 for (std::vector<PendingRequest>::iterator iter =
369 temp_pending_requests.begin();
370 iter != temp_pending_requests.end(); ++iter) {
371 switch (iter->type) {
[email protected]951ef0b2012-07-27 22:46:53372 case INVALID_REQUEST_TYPE:
373 NOTREACHED();
374 break;
[email protected]1a559442012-05-27 07:18:46375 case DEAUTHORIZE_CONTENT_LICENSES:
376 DeauthorizeContentLicensesOnIOThread(iter->id);
377 break;
[email protected]ee4dd682012-06-12 15:49:33378 case GET_PERMISSION_SETTINGS:
379 GetPermissionSettingsOnIOThread(iter->id, iter->setting_type);
380 break;
381 case SET_DEFAULT_PERMISSION:
382 SetDefaultPermissionOnIOThread(
383 iter->id, iter->setting_type, iter->permission,
384 iter->clear_site_specific);
385 break;
386 case SET_SITE_PERMISSION:
387 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites);
388 break;
[email protected]951ef0b2012-07-27 22:46:53389 case GET_SITES_WITH_DATA:
390 GetSitesWithDataOnIOThread(iter->id);
391 break;
392 case CLEAR_SITE_DATA:
393 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags,
394 iter->max_age);
[email protected]1a559442012-05-27 07:18:46395 break;
396 }
397 }
398}
399
[email protected]6464cc12012-07-12 09:25:53400void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27402 DCHECK_EQ(STATE_UNINITIALIZED, state_);
[email protected]6464cc12012-07-12 09:25:53403
404 webkit::WebPluginInfo plugin_info;
405 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
406 &plugin_info)) {
407 NotifyErrorFromIOThread();
408 return;
409 }
410
[email protected]650b2d52013-02-10 03:41:45411 base::FilePath profile_path =
[email protected]6464cc12012-07-12 09:25:53412 browser_context_path_.Append(content::kPepperDataDirname);
413#if defined(OS_WIN)
414 plugin_data_path_ = profile_path.Append(plugin_info.name);
415#else
416 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name));
417#endif
418
419 helper_ = content::PepperFlashSettingsHelper::Create();
420 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
421 base::Bind(&Core::ConnectToChannel, this);
422 helper_->OpenChannelToBroker(plugin_info.path, callback);
423}
424
[email protected]1a559442012-05-27 07:18:46425void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
426 uint32 request_id) {
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27428 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46429
[email protected]7c826912012-10-01 22:05:27430 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46431 PendingRequest request;
432 request.id = request_id;
433 request.type = DEAUTHORIZE_CONTENT_LICENSES;
434 pending_requests_.push_back(request);
435 return;
436 }
437
438 pending_responses_.insert(
439 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
[email protected]7c826912012-10-01 22:05:27440 if (state_ == STATE_ERROR) {
441 NotifyErrorFromIOThread();
442 return;
443 }
444
[email protected]bb9c9752013-04-25 23:02:11445#if defined(OS_CHROMEOS)
446 BrowserThread::PostBlockingPoolTask(FROM_HERE,
447 base::Bind(&Core::DeauthorizeContentLicensesOnBlockingPool, this,
448 request_id, browser_context_path_));
449#else
450 DeauthorizeContentLicensesInPlugin(request_id, true);
451#endif
452}
453
454// TODO(raymes): This is temporary code to migrate ChromeOS devices to the new
455// scheme for generating device IDs. Delete this once we are sure most ChromeOS
456// devices have been migrated.
457void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnBlockingPool(
458 uint32 request_id,
459 const base::FilePath& profile_path) {
460 // ChromeOS used to store the device ID in a file but this is no longer used.
461 // Wipe that file.
462 const base::FilePath& device_id_path =
463 chrome::DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
464 bool success = file_util::Delete(device_id_path, false);
465
466 BrowserThread::PostTask(
467 BrowserThread::IO, FROM_HERE,
468 base::Bind(&Core::DeauthorizeContentLicensesInPlugin, this, request_id,
469 success));
470}
471
472void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
473 uint32 request_id,
474 bool success) {
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
476 if (!success) {
477 NotifyErrorFromIOThread();
478 return;
479 }
[email protected]1a559442012-05-27 07:18:46480 IPC::Message* msg =
481 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
482 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33483 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
484 // A failure notification for the current request will be sent since
485 // |pending_responses_| has been updated.
486 NotifyErrorFromIOThread();
487 }
488}
489
490void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
491 uint32 request_id,
492 PP_Flash_BrowserOperations_SettingType setting_type) {
493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27494 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33495
[email protected]7c826912012-10-01 22:05:27496 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33497 PendingRequest request;
498 request.id = request_id;
499 request.type = GET_PERMISSION_SETTINGS;
500 request.setting_type = setting_type;
501 pending_requests_.push_back(request);
502 return;
503 }
504
505 pending_responses_.insert(
506 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
[email protected]7c826912012-10-01 22:05:27507 if (state_ == STATE_ERROR) {
508 NotifyErrorFromIOThread();
509 return;
510 }
511
[email protected]ee4dd682012-06-12 15:49:33512 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
513 request_id, plugin_data_path_, setting_type);
514 if (!channel_->Send(msg)) {
515 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
516 // A failure notification for the current request will be sent since
517 // |pending_responses_| has been updated.
518 NotifyErrorFromIOThread();
519 }
520}
521
522void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
523 uint32 request_id,
524 PP_Flash_BrowserOperations_SettingType setting_type,
525 PP_Flash_BrowserOperations_Permission permission,
526 bool clear_site_specific) {
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27528 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33529
[email protected]7c826912012-10-01 22:05:27530 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33531 PendingRequest request;
532 request.id = request_id;
533 request.type = SET_DEFAULT_PERMISSION;
534 request.setting_type = setting_type;
535 request.permission = permission;
536 request.clear_site_specific = clear_site_specific;
537 pending_requests_.push_back(request);
538 return;
539 }
540
541 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
[email protected]7c826912012-10-01 22:05:27542 if (state_ == STATE_ERROR) {
543 NotifyErrorFromIOThread();
544 return;
545 }
546
[email protected]ee4dd682012-06-12 15:49:33547 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
548 request_id, plugin_data_path_, setting_type, permission,
549 clear_site_specific);
550 if (!channel_->Send(msg)) {
551 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
552 // A failure notification for the current request will be sent since
553 // |pending_responses_| has been updated.
554 NotifyErrorFromIOThread();
555 }
556}
557
558void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
559 uint32 request_id,
560 PP_Flash_BrowserOperations_SettingType setting_type,
561 const ppapi::FlashSiteSettings& sites) {
562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27563 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33564
[email protected]7c826912012-10-01 22:05:27565 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33566 pending_requests_.push_back(PendingRequest());
567 PendingRequest& request = pending_requests_.back();
568 request.id = request_id;
569 request.type = SET_SITE_PERMISSION;
570 request.setting_type = setting_type;
571 request.sites = sites;
572 return;
573 }
574
575 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
[email protected]7c826912012-10-01 22:05:27576 if (state_ == STATE_ERROR) {
577 NotifyErrorFromIOThread();
578 return;
579 }
580
[email protected]ee4dd682012-06-12 15:49:33581 IPC::Message* msg = new PpapiMsg_SetSitePermission(
582 request_id, plugin_data_path_, setting_type, sites);
583 if (!channel_->Send(msg)) {
584 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46585 // A failure notification for the current request will be sent since
586 // |pending_responses_| has been updated.
587 NotifyErrorFromIOThread();
588 }
589}
590
[email protected]951ef0b2012-07-27 22:46:53591void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
592 uint32 request_id) {
593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27594 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53595
[email protected]7c826912012-10-01 22:05:27596 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53597 pending_requests_.push_back(PendingRequest());
598 PendingRequest& request = pending_requests_.back();
599 request.id = request_id;
600 request.type = GET_SITES_WITH_DATA;
601 return;
602 }
603
604 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
[email protected]7c826912012-10-01 22:05:27605 if (state_ == STATE_ERROR) {
606 NotifyErrorFromIOThread();
607 return;
608 }
609
[email protected]951ef0b2012-07-27 22:46:53610 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
611 request_id, plugin_data_path_);
612 if (!channel_->Send(msg)) {
613 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
614 // A failure notification for the current request will be sent since
615 // |pending_responses_| has been updated.
616 NotifyErrorFromIOThread();
617 }
618}
619
620void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
621 uint32 request_id,
622 const std::string& site,
623 uint64 flags,
624 uint64 max_age) {
625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27626 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53627
[email protected]7c826912012-10-01 22:05:27628 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53629 pending_requests_.push_back(PendingRequest());
630 PendingRequest& request = pending_requests_.back();
631 request.id = request_id;
632 request.type = CLEAR_SITE_DATA;
633 request.site = site;
634 request.flags = flags;
635 request.max_age = max_age;
636 return;
637 }
638
639 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
[email protected]7c826912012-10-01 22:05:27640 if (state_ == STATE_ERROR) {
641 NotifyErrorFromIOThread();
642 return;
643 }
644
[email protected]951ef0b2012-07-27 22:46:53645 IPC::Message* msg = new PpapiMsg_ClearSiteData(
646 request_id, plugin_data_path_, site, flags, max_age);
647 if (!channel_->Send(msg)) {
648 DLOG(ERROR) << "Couldn't send ClearSiteData message";
649 // A failure notification for the current request will be sent since
650 // |pending_responses_| has been updated.
651 NotifyErrorFromIOThread();
652 }
653}
654
[email protected]4d4ee4c2012-06-22 19:11:30655void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27656 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30657}
658
[email protected]1a559442012-05-27 07:18:46659void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27661 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30662 return;
[email protected]1a559442012-05-27 07:18:46663
[email protected]7c826912012-10-01 22:05:27664 state_ = STATE_ERROR;
[email protected]1a559442012-05-27 07:18:46665 std::vector<std::pair<uint32, RequestType> > notifications;
666 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin();
667 iter != pending_requests_.end(); ++iter) {
668 notifications.push_back(std::make_pair(iter->id, iter->type));
669 }
670 pending_requests_.clear();
671 notifications.insert(notifications.end(), pending_responses_.begin(),
672 pending_responses_.end());
673 pending_responses_.clear();
674
675 BrowserThread::PostTask(
676 BrowserThread::UI, FROM_HERE,
677 base::Bind(&Core::NotifyError, this, notifications));
678}
679
680void
681PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted(
682 uint32 request_id,
683 bool success) {
684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
685
[email protected]7c826912012-10-01 22:05:27686 if (manager_.get()) {
[email protected]1a559442012-05-27 07:18:46687 manager_->client_->OnDeauthorizeContentLicensesCompleted(
688 request_id, success);
689 }
690}
691
[email protected]ee4dd682012-06-12 15:49:33692void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
693 uint32 request_id,
694 bool success,
695 PP_Flash_BrowserOperations_Permission default_permission,
696 const ppapi::FlashSiteSettings& sites) {
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
698
[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(
706 uint32 request_id,
707 bool success) {
708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
709
[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(
717 uint32 request_id,
718 bool success) {
719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
720
[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(
728 uint32 request_id,
729 const std::vector<std::string>& sites) {
730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
731
[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(
739 uint32 request_id,
740 bool success) {
741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
742
[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(
748 const std::vector<std::pair<uint32, RequestType> >& notifications) {
749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
750
751 scoped_refptr<Core> protector(this);
752 for (std::vector<std::pair<uint32, RequestType> >::const_iterator iter =
753 notifications.begin(); iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27754 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46755 // the callbacks.
[email protected]7c826912012-10-01 22:05:27756 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53757 return;
758
759 switch (iter->second) {
760 case INVALID_REQUEST_TYPE:
761 NOTREACHED();
762 break;
763 case DEAUTHORIZE_CONTENT_LICENSES:
764 manager_->client_->OnDeauthorizeContentLicensesCompleted(
765 iter->first, false);
766 break;
767 case GET_PERMISSION_SETTINGS:
768 manager_->client_->OnGetPermissionSettingsCompleted(
769 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
770 ppapi::FlashSiteSettings());
771 break;
772 case SET_DEFAULT_PERMISSION:
773 manager_->client_->OnSetDefaultPermissionCompleted(
774 iter->first, false);
775 break;
776 case SET_SITE_PERMISSION:
777 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
778 break;
779 case GET_SITES_WITH_DATA:
780 manager_->client_->OnGetSitesWithDataCompleted(
781 iter->first, std::vector<std::string>());
782 break;
783 case CLEAR_SITE_DATA:
784 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
785 break;
[email protected]1a559442012-05-27 07:18:46786 }
787 }
788
[email protected]7c826912012-10-01 22:05:27789 if (manager_.get())
790 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46791}
792
793void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
794 uint32 request_id,
795 bool success) {
796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27797 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30798 return;
799
[email protected]ee4dd682012-06-12 15:49:33800 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46801
802 std::map<uint32, RequestType>::iterator iter =
803 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53804 if (iter == pending_responses_.end())
805 return;
[email protected]1a559442012-05-27 07:18:46806
[email protected]951ef0b2012-07-27 22:46:53807 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
808
809 pending_responses_.erase(iter);
810 BrowserThread::PostTask(
811 BrowserThread::UI, FROM_HERE,
812 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
813 request_id, success));
[email protected]1a559442012-05-27 07:18:46814}
815
[email protected]ee4dd682012-06-12 15:49:33816void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
817 uint32 request_id,
818 bool success,
819 PP_Flash_BrowserOperations_Permission default_permission,
820 const ppapi::FlashSiteSettings& sites) {
821 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27822 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30823 return;
824
[email protected]ee4dd682012-06-12 15:49:33825 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
826
827 std::map<uint32, RequestType>::iterator iter =
828 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53829 if (iter == pending_responses_.end())
830 return;
[email protected]ee4dd682012-06-12 15:49:33831
[email protected]951ef0b2012-07-27 22:46:53832 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
833
834 pending_responses_.erase(iter);
835 BrowserThread::PostTask(
836 BrowserThread::UI, FROM_HERE,
837 base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this,
838 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33839}
840
841void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
842 uint32 request_id,
843 bool success) {
844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27845 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30846 return;
847
[email protected]ee4dd682012-06-12 15:49:33848 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
849
850 std::map<uint32, RequestType>::iterator iter =
851 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53852 if (iter == pending_responses_.end())
853 return;
[email protected]ee4dd682012-06-12 15:49:33854
[email protected]951ef0b2012-07-27 22:46:53855 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
856
857 pending_responses_.erase(iter);
858 BrowserThread::PostTask(
859 BrowserThread::UI, FROM_HERE,
860 base::Bind(&Core::NotifySetDefaultPermissionCompleted, this,
861 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33862}
863
864void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
865 uint32 request_id,
866 bool success) {
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27868 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30869 return;
870
[email protected]ee4dd682012-06-12 15:49:33871 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
872
873 std::map<uint32, RequestType>::iterator iter =
874 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53875 if (iter == pending_responses_.end())
876 return;
[email protected]ee4dd682012-06-12 15:49:33877
[email protected]951ef0b2012-07-27 22:46:53878 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
879
880 pending_responses_.erase(iter);
881 BrowserThread::PostTask(
882 BrowserThread::UI, FROM_HERE,
883 base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id,
884 success));
885}
886
887void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
888 uint32 request_id,
889 const std::vector<std::string>& sites) {
890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27891 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53892 return;
893
894 std::map<uint32, RequestType>::iterator iter =
895 pending_responses_.find(request_id);
896 if (iter == pending_responses_.end())
897 return;
898
899 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
900
901 pending_responses_.erase(iter);
902 BrowserThread::PostTask(
903 BrowserThread::UI, FROM_HERE,
904 base::Bind(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
905 sites));
906}
907
908void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
909 uint32 request_id,
910 bool success) {
911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27912 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53913 return;
914
915 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
916
917 std::map<uint32, RequestType>::iterator iter =
918 pending_responses_.find(request_id);
919 if (iter == pending_responses_.end())
920 return;
921
922 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
923
924 pending_responses_.erase(iter);
925 BrowserThread::PostTask(
926 BrowserThread::UI, FROM_HERE,
927 base::Bind(&Core::NotifyClearSiteDataCompleted, this, request_id,
928 success));
[email protected]ee4dd682012-06-12 15:49:33929}
930
[email protected]1a559442012-05-27 07:18:46931PepperFlashSettingsManager::PepperFlashSettingsManager(
932 Client* client,
933 content::BrowserContext* browser_context)
[email protected]9c009092013-05-01 03:14:09934 : weak_ptr_factory_(this),
[email protected]7c826912012-10-01 22:05:27935 client_(client),
[email protected]1a559442012-05-27 07:18:46936 browser_context_(browser_context),
937 next_request_id_(1) {
938 DCHECK(client);
939 DCHECK(browser_context);
940}
941
942PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53943 if (core_.get())
[email protected]1a559442012-05-27 07:18:46944 core_->Detach();
[email protected]1a559442012-05-27 07:18:46945}
946
[email protected]18a4d63c82012-05-25 23:37:03947// static
948bool PepperFlashSettingsManager::IsPepperFlashInUse(
949 PluginPrefs* plugin_prefs,
950 webkit::WebPluginInfo* plugin_info) {
951 if (!plugin_prefs)
952 return false;
953
954 content::PluginService* plugin_service =
955 content::PluginService::GetInstance();
956 std::vector<webkit::WebPluginInfo> plugins;
957 plugin_service->GetPluginInfoArray(
958 GURL(), kFlashPluginSwfMimeType, false, &plugins, NULL);
959
960 for (std::vector<webkit::WebPluginInfo>::iterator iter = plugins.begin();
961 iter != plugins.end(); ++iter) {
962 if (webkit::IsPepperPlugin(*iter) && plugin_prefs->IsPluginEnabled(*iter)) {
963 if (plugin_info)
964 *plugin_info = *iter;
965 return true;
966 }
967 }
968 return false;
969}
970
971// static
[email protected]c753f142013-02-10 13:14:04972void PepperFlashSettingsManager::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34973 user_prefs::PrefRegistrySyncable* registry) {
974 registry->RegisterBooleanPref(
975 prefs::kDeauthorizeContentLicenses,
976 false,
977 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]18a4d63c82012-05-25 23:37:03978
[email protected]443e9312013-05-06 06:17:34979 registry->RegisterBooleanPref(
980 prefs::kPepperFlashSettingsEnabled,
981 true,
982 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]18a4d63c82012-05-25 23:37:03983}
[email protected]1a559442012-05-27 07:18:46984
[email protected]bb9c9752013-04-25 23:02:11985uint32 PepperFlashSettingsManager::DeauthorizeContentLicenses(
986 PrefService* prefs) {
[email protected]1a559442012-05-27 07:18:46987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
988
[email protected]bb9c9752013-04-25 23:02:11989 // Clear the device ID salt which has the effect of regenerating a device
990 // ID. Since this happens synchronously (and on the UI thread), we don't have
991 // to add it to a pending request.
992 prefs->ClearPref(prefs::kDRMSalt);
993
[email protected]1a559442012-05-27 07:18:46994 EnsureCoreExists();
995 uint32 id = GetNextRequestId();
996 core_->DeauthorizeContentLicenses(id);
997 return id;
998}
999
[email protected]ee4dd682012-06-12 15:49:331000uint32 PepperFlashSettingsManager::GetPermissionSettings(
1001 PP_Flash_BrowserOperations_SettingType setting_type) {
1002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1003
1004 EnsureCoreExists();
1005 uint32 id = GetNextRequestId();
1006 core_->GetPermissionSettings(id, setting_type);
1007 return id;
1008}
1009
1010uint32 PepperFlashSettingsManager::SetDefaultPermission(
1011 PP_Flash_BrowserOperations_SettingType setting_type,
1012 PP_Flash_BrowserOperations_Permission permission,
1013 bool clear_site_specific) {
1014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1015
1016 EnsureCoreExists();
1017 uint32 id = GetNextRequestId();
1018 core_->SetDefaultPermission(id, setting_type, permission,
1019 clear_site_specific);
1020 return id;
1021}
1022
1023uint32 PepperFlashSettingsManager::SetSitePermission(
1024 PP_Flash_BrowserOperations_SettingType setting_type,
1025 const ppapi::FlashSiteSettings& sites) {
1026 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1027
1028 EnsureCoreExists();
1029 uint32 id = GetNextRequestId();
1030 core_->SetSitePermission(id, setting_type, sites);
1031 return id;
1032}
1033
[email protected]951ef0b2012-07-27 22:46:531034uint32 PepperFlashSettingsManager::GetSitesWithData() {
1035 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1036
1037 EnsureCoreExists();
1038 uint32 id = GetNextRequestId();
1039 core_->GetSitesWithData(id);
1040 return id;
1041}
1042
1043uint32 PepperFlashSettingsManager::ClearSiteData(const std::string& site,
1044 uint64 flags,
1045 uint64 max_age) {
1046 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1047
1048 EnsureCoreExists();
1049 uint32 id = GetNextRequestId();
1050 core_->ClearSiteData(id, site, flags, max_age);
1051 return id;
1052}
1053
[email protected]1a559442012-05-27 07:18:461054uint32 PepperFlashSettingsManager::GetNextRequestId() {
1055 return next_request_id_++;
1056}
1057
1058void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531059 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271060 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531061 core_->Initialize();
1062 }
[email protected]1a559442012-05-27 07:18:461063}
1064
[email protected]7c826912012-10-01 22:05:271065void PepperFlashSettingsManager::OnError(Core* core) {
1066 DCHECK(core);
1067 if (core != core_.get())
1068 return;
[email protected]1a559442012-05-27 07:18:461069
[email protected]7c826912012-10-01 22:05:271070 core_->Detach();
1071 core_ = NULL;
1072}