blob: a82dcd3fc22cd328a9097fa2c97866b86bb98851 [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"
13#include "base/sequenced_task_runner_helpers.h"
14#include "base/utf_string_conversions.h"
[email protected]18a4d63c82012-05-25 23:37:0315#include "chrome/browser/plugin_prefs.h"
16#include "chrome/browser/prefs/pref_service.h"
[email protected]1a559442012-05-27 07:18:4617#include "chrome/browser/profiles/profile.h"
[email protected]18a4d63c82012-05-25 23:37:0318#include "chrome/common/pref_names.h"
[email protected]1a559442012-05-27 07:18:4619#include "content/public/browser/browser_context.h"
20#include "content/public/browser/browser_thread.h"
21#include "content/public/browser/pepper_flash_settings_helper.h"
[email protected]18a4d63c82012-05-25 23:37:0322#include "content/public/browser/plugin_service.h"
[email protected]1a559442012-05-27 07:18:4623#include "content/public/common/content_constants.h"
[email protected]18a4d63c82012-05-25 23:37:0324#include "googleurl/src/gurl.h"
[email protected]1a559442012-05-27 07:18:4625#include "ipc/ipc_channel.h"
26#include "ppapi/proxy/ppapi_messages.h"
[email protected]18a4d63c82012-05-25 23:37:0327#include "webkit/plugins/plugin_constants.h"
28#include "webkit/plugins/webplugininfo.h"
29
[email protected]1a559442012-05-27 07:18:4630using content::BrowserThread;
31
32class PepperFlashSettingsManager::Core
[email protected]b44f8ad2012-06-15 20:52:5833 : public IPC::Listener,
[email protected]1a559442012-05-27 07:18:4634 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> {
35 public:
36 Core(PepperFlashSettingsManager* manager,
37 content::BrowserContext* browser_context);
38
39 // Stops sending notifications to |manager_| and sets it to NULL.
40 void Detach();
41
42 void DeauthorizeContentLicenses(uint32 request_id);
[email protected]ee4dd682012-06-12 15:49:3343 void GetPermissionSettings(
44 uint32 request_id,
45 PP_Flash_BrowserOperations_SettingType setting_type);
46 void SetDefaultPermission(
47 uint32 request_id,
48 PP_Flash_BrowserOperations_SettingType setting_type,
49 PP_Flash_BrowserOperations_Permission permission,
50 bool clear_site_specific);
51 void SetSitePermission(uint32 request_id,
52 PP_Flash_BrowserOperations_SettingType setting_type,
53 const ppapi::FlashSiteSettings& sites);
[email protected]1a559442012-05-27 07:18:4654
[email protected]b44f8ad2012-06-15 20:52:5855 // IPC::Listener implementation.
[email protected]1a559442012-05-27 07:18:4656 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
57 virtual void OnChannelError() OVERRIDE;
58
59 private:
60 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
61 friend class base::DeleteHelper<Core>;
62
63 enum RequestType {
64 INVALID_REQUEST_TYPE = 0,
[email protected]ee4dd682012-06-12 15:49:3365 DEAUTHORIZE_CONTENT_LICENSES,
66 GET_PERMISSION_SETTINGS,
67 SET_DEFAULT_PERMISSION,
68 SET_SITE_PERMISSION
[email protected]1a559442012-05-27 07:18:4669 };
70
71 struct PendingRequest {
[email protected]ee4dd682012-06-12 15:49:3372 PendingRequest()
73 : id(0),
74 type(INVALID_REQUEST_TYPE),
75 setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC),
76 permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT),
77 clear_site_specific(false) {
78 }
[email protected]1a559442012-05-27 07:18:4679
80 uint32 id;
81 RequestType type;
[email protected]ee4dd682012-06-12 15:49:3382
83 // Used by GET_PERMISSION_SETTINGS, SET_DEFAULT_PERMISSION and
84 // SET_SITE_PERMISSION.
85 PP_Flash_BrowserOperations_SettingType setting_type;
86
87 // Used by SET_DEFAULT_PERMISSION.
88 PP_Flash_BrowserOperations_Permission permission;
89 bool clear_site_specific;
90
91 // Used by SET_SITE_PERMISSION.
92 ppapi::FlashSiteSettings sites;
[email protected]1a559442012-05-27 07:18:4693 };
94
95 virtual ~Core();
96
97 void Initialize();
98 void ConnectToChannel(bool success, const IPC::ChannelHandle& handle);
99
100 void DeauthorizeContentLicensesOnIOThread(uint32 request_id);
[email protected]ee4dd682012-06-12 15:49:33101 void GetPermissionSettingsOnIOThread(
102 uint32 request_id,
103 PP_Flash_BrowserOperations_SettingType setting_type);
104 void SetDefaultPermissionOnIOThread(
105 uint32 request_id,
106 PP_Flash_BrowserOperations_SettingType setting_type,
107 PP_Flash_BrowserOperations_Permission permission,
108 bool clear_site_specific);
109 void SetSitePermissionOnIOThread(
110 uint32 request_id,
111 PP_Flash_BrowserOperations_SettingType setting_type,
112 const ppapi::FlashSiteSettings& sites);
113
[email protected]1a559442012-05-27 07:18:46114 void NotifyErrorFromIOThread();
115
116 void NotifyDeauthorizeContentLicensesCompleted(uint32 request_id,
117 bool success);
[email protected]ee4dd682012-06-12 15:49:33118 void NotifyGetPermissionSettingsCompleted(
119 uint32 request_id,
120 bool success,
121 PP_Flash_BrowserOperations_Permission default_permission,
122 const ppapi::FlashSiteSettings& sites);
123 void NotifySetDefaultPermissionCompleted(uint32 request_id, bool success);
124 void NotifySetSitePermissionCompleted(uint32 request_id, bool success);
125
[email protected]1a559442012-05-27 07:18:46126 void NotifyError(
127 const std::vector<std::pair<uint32, RequestType> >& notifications);
128
129 // Message handlers.
130 void OnDeauthorizeContentLicensesResult(uint32 request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33131 void OnGetPermissionSettingsResult(
132 uint32 request_id,
133 bool success,
134 PP_Flash_BrowserOperations_Permission default_permission,
135 const ppapi::FlashSiteSettings& sites);
136 void OnSetDefaultPermissionResult(uint32 request_id, bool success);
137 void OnSetSitePermissionResult(uint32 request_id, bool success);
[email protected]1a559442012-05-27 07:18:46138
139 // Used only on the UI thread.
140 PepperFlashSettingsManager* manager_;
141
142 // Used only on the I/O thread.
143 FilePath plugin_data_path_;
144
145 // The channel is NULL until we have opened a connection to the broker
146 // process. Used only on the I/O thread.
147 scoped_ptr<IPC::Channel> channel_;
148
149 // Used only on the I/O thread.
150 bool initialized_;
151
152 // Requests that need to be sent once the channel to the broker process is
153 // established. Used only on the I/O thread.
154 std::vector<PendingRequest> pending_requests_;
155 // Requests that have been sent but haven't got replied. Used only on the
156 // I/O thread.
157 std::map<uint32, RequestType> pending_responses_;
158
159 // Used only on the I/O thread.
160 scoped_refptr<content::PepperFlashSettingsHelper> helper_;
161
162 // Path for the current profile. Must be retrieved on the UI thread from the
163 // browser context when we start so we can use it later on the I/O thread.
164 FilePath browser_context_path_;
165
166 scoped_refptr<PluginPrefs> plugin_prefs_;
167};
168
169PepperFlashSettingsManager::Core::Core(PepperFlashSettingsManager* manager,
170 content::BrowserContext* browser_context)
171 : manager_(manager),
172 initialized_(false),
173 browser_context_path_(browser_context->GetPath()),
174 plugin_prefs_(PluginPrefs::GetForProfile(
175 Profile::FromBrowserContext(browser_context))) {
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
177
178 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
179 base::Bind(&Core::Initialize, this));
180}
181
182PepperFlashSettingsManager::Core::~Core() {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
184}
185
186void PepperFlashSettingsManager::Core::Detach() {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
188
189 manager_ = NULL;
190}
191
192void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
193 uint32 request_id) {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
195
196 BrowserThread::PostTask(
197 BrowserThread::IO, FROM_HERE,
198 base::Bind(&Core::DeauthorizeContentLicensesOnIOThread, this,
199 request_id));
200}
201
[email protected]ee4dd682012-06-12 15:49:33202void PepperFlashSettingsManager::Core::GetPermissionSettings(
203 uint32 request_id,
204 PP_Flash_BrowserOperations_SettingType setting_type) {
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
206
207 BrowserThread::PostTask(
208 BrowserThread::IO, FROM_HERE,
209 base::Bind(&Core::GetPermissionSettingsOnIOThread, this, request_id,
210 setting_type));
211}
212
213void PepperFlashSettingsManager::Core::SetDefaultPermission(
214 uint32 request_id,
215 PP_Flash_BrowserOperations_SettingType setting_type,
216 PP_Flash_BrowserOperations_Permission permission,
217 bool clear_site_specific) {
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
219
220 BrowserThread::PostTask(
221 BrowserThread::IO, FROM_HERE,
222 base::Bind(&Core::SetDefaultPermissionOnIOThread, this, request_id,
223 setting_type, permission, clear_site_specific));
224}
225
226void PepperFlashSettingsManager::Core::SetSitePermission(
227 uint32 request_id,
228 PP_Flash_BrowserOperations_SettingType setting_type,
229 const ppapi::FlashSiteSettings& sites) {
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
231
232 BrowserThread::PostTask(
233 BrowserThread::IO, FROM_HERE,
234 base::Bind(&Core::SetSitePermissionOnIOThread, this, request_id,
235 setting_type, sites));
236}
237
[email protected]1a559442012-05-27 07:18:46238bool PepperFlashSettingsManager::Core::OnMessageReceived(
239 const IPC::Message& message) {
240 IPC_BEGIN_MESSAGE_MAP(Core, message)
241 IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult,
242 OnDeauthorizeContentLicensesResult)
[email protected]ee4dd682012-06-12 15:49:33243 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult,
244 OnGetPermissionSettingsResult)
245 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult,
246 OnSetDefaultPermissionResult)
247 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult,
248 OnSetSitePermissionResult)
[email protected]1a559442012-05-27 07:18:46249 IPC_MESSAGE_UNHANDLED_ERROR()
250 IPC_END_MESSAGE_MAP()
251
252 return true;
253}
254
255void PepperFlashSettingsManager::Core::OnChannelError() {
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
257
258 NotifyErrorFromIOThread();
259}
260
261void PepperFlashSettingsManager::Core::Initialize() {
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
263 DCHECK(!initialized_);
264
265 webkit::WebPluginInfo plugin_info;
266 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
267 &plugin_info)) {
268 NotifyErrorFromIOThread();
269 return;
270 }
271
272 FilePath profile_path =
273 browser_context_path_.Append(content::kPepperDataDirname);
274#if defined(OS_WIN)
275 plugin_data_path_ = profile_path.Append(plugin_info.name);
276#else
277 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name));
278#endif
279
280 helper_ = content::PepperFlashSettingsHelper::Create();
281 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
282 base::Bind(&Core::ConnectToChannel, this);
283 helper_->OpenChannelToBroker(plugin_info.path, callback);
284}
285
286void PepperFlashSettingsManager::Core::ConnectToChannel(
287 bool success,
288 const IPC::ChannelHandle& handle) {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
290 DCHECK(!initialized_);
291 DCHECK(!channel_.get());
292
293 if (!success) {
[email protected]ee4dd682012-06-12 15:49:33294 DLOG(ERROR) << "Couldn't open plugin channel";
[email protected]1a559442012-05-27 07:18:46295 NotifyErrorFromIOThread();
296 return;
297 }
298
299 channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this));
300 if (!channel_->Connect()) {
[email protected]ee4dd682012-06-12 15:49:33301 DLOG(ERROR) << "Couldn't connect to plugin";
[email protected]1a559442012-05-27 07:18:46302 NotifyErrorFromIOThread();
303 return;
304 }
305
306 initialized_ = true;
307
308 std::vector<PendingRequest> temp_pending_requests;
309 temp_pending_requests.swap(pending_requests_);
310 for (std::vector<PendingRequest>::iterator iter =
311 temp_pending_requests.begin();
312 iter != temp_pending_requests.end(); ++iter) {
313 switch (iter->type) {
314 case DEAUTHORIZE_CONTENT_LICENSES:
315 DeauthorizeContentLicensesOnIOThread(iter->id);
316 break;
[email protected]ee4dd682012-06-12 15:49:33317 case GET_PERMISSION_SETTINGS:
318 GetPermissionSettingsOnIOThread(iter->id, iter->setting_type);
319 break;
320 case SET_DEFAULT_PERMISSION:
321 SetDefaultPermissionOnIOThread(
322 iter->id, iter->setting_type, iter->permission,
323 iter->clear_site_specific);
324 break;
325 case SET_SITE_PERMISSION:
326 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites);
327 break;
[email protected]1a559442012-05-27 07:18:46328 default:
329 NOTREACHED();
330 break;
331 }
332 }
333}
334
335void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
336 uint32 request_id) {
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
338
339 if (!initialized_) {
340 PendingRequest request;
341 request.id = request_id;
342 request.type = DEAUTHORIZE_CONTENT_LICENSES;
343 pending_requests_.push_back(request);
344 return;
345 }
346
347 pending_responses_.insert(
348 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
349 IPC::Message* msg =
350 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
351 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33352 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
353 // A failure notification for the current request will be sent since
354 // |pending_responses_| has been updated.
355 NotifyErrorFromIOThread();
356 }
357}
358
359void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
360 uint32 request_id,
361 PP_Flash_BrowserOperations_SettingType setting_type) {
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
363
364 if (!initialized_) {
365 PendingRequest request;
366 request.id = request_id;
367 request.type = GET_PERMISSION_SETTINGS;
368 request.setting_type = setting_type;
369 pending_requests_.push_back(request);
370 return;
371 }
372
373 pending_responses_.insert(
374 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
375 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
376 request_id, plugin_data_path_, setting_type);
377 if (!channel_->Send(msg)) {
378 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
379 // A failure notification for the current request will be sent since
380 // |pending_responses_| has been updated.
381 NotifyErrorFromIOThread();
382 }
383}
384
385void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
386 uint32 request_id,
387 PP_Flash_BrowserOperations_SettingType setting_type,
388 PP_Flash_BrowserOperations_Permission permission,
389 bool clear_site_specific) {
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
391
392 if (!initialized_) {
393 PendingRequest request;
394 request.id = request_id;
395 request.type = SET_DEFAULT_PERMISSION;
396 request.setting_type = setting_type;
397 request.permission = permission;
398 request.clear_site_specific = clear_site_specific;
399 pending_requests_.push_back(request);
400 return;
401 }
402
403 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
404 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
405 request_id, plugin_data_path_, setting_type, permission,
406 clear_site_specific);
407 if (!channel_->Send(msg)) {
408 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
409 // A failure notification for the current request will be sent since
410 // |pending_responses_| has been updated.
411 NotifyErrorFromIOThread();
412 }
413}
414
415void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
416 uint32 request_id,
417 PP_Flash_BrowserOperations_SettingType setting_type,
418 const ppapi::FlashSiteSettings& sites) {
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
420
421 if (!initialized_) {
422 pending_requests_.push_back(PendingRequest());
423 PendingRequest& request = pending_requests_.back();
424 request.id = request_id;
425 request.type = SET_SITE_PERMISSION;
426 request.setting_type = setting_type;
427 request.sites = sites;
428 return;
429 }
430
431 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
432 IPC::Message* msg = new PpapiMsg_SetSitePermission(
433 request_id, plugin_data_path_, setting_type, sites);
434 if (!channel_->Send(msg)) {
435 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46436 // A failure notification for the current request will be sent since
437 // |pending_responses_| has been updated.
438 NotifyErrorFromIOThread();
439 }
440}
441
442void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
444
445 std::vector<std::pair<uint32, RequestType> > notifications;
446 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin();
447 iter != pending_requests_.end(); ++iter) {
448 notifications.push_back(std::make_pair(iter->id, iter->type));
449 }
450 pending_requests_.clear();
451 notifications.insert(notifications.end(), pending_responses_.begin(),
452 pending_responses_.end());
453 pending_responses_.clear();
454
455 BrowserThread::PostTask(
456 BrowserThread::UI, FROM_HERE,
457 base::Bind(&Core::NotifyError, this, notifications));
458}
459
460void
461PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted(
462 uint32 request_id,
463 bool success) {
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
465
466 if (manager_) {
467 manager_->client_->OnDeauthorizeContentLicensesCompleted(
468 request_id, success);
469 }
470}
471
[email protected]ee4dd682012-06-12 15:49:33472void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
473 uint32 request_id,
474 bool success,
475 PP_Flash_BrowserOperations_Permission default_permission,
476 const ppapi::FlashSiteSettings& sites) {
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
478
479 if (manager_) {
480 manager_->client_->OnGetPermissionSettingsCompleted(
481 request_id, success, default_permission, sites);
482 }
483}
484
485void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
486 uint32 request_id,
487 bool success) {
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
489
490 if (manager_) {
491 manager_->client_->OnSetDefaultPermissionCompleted(
492 request_id, success);
493 }
494}
495
496void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
497 uint32 request_id,
498 bool success) {
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
500
501 if (manager_) {
502 manager_->client_->OnSetSitePermissionCompleted(
503 request_id, success);
504 }
505}
506
[email protected]1a559442012-05-27 07:18:46507void PepperFlashSettingsManager::Core::NotifyError(
508 const std::vector<std::pair<uint32, RequestType> >& notifications) {
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
510
511 scoped_refptr<Core> protector(this);
512 for (std::vector<std::pair<uint32, RequestType> >::const_iterator iter =
513 notifications.begin(); iter != notifications.end(); ++iter) {
514 // Check |manager_| for each iteration in case Detach() happens in one of
515 // the callbacks.
516 if (manager_) {
517 switch (iter->second) {
518 case DEAUTHORIZE_CONTENT_LICENSES:
[email protected]ee4dd682012-06-12 15:49:33519 manager_->client_->OnDeauthorizeContentLicensesCompleted(
520 iter->first, false);
521 break;
522 case GET_PERMISSION_SETTINGS:
523 manager_->client_->OnGetPermissionSettingsCompleted(
524 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
525 ppapi::FlashSiteSettings());
526 break;
527 case SET_DEFAULT_PERMISSION:
528 manager_->client_->OnSetDefaultPermissionCompleted(
529 iter->first, false);
530 break;
531 case SET_SITE_PERMISSION:
532 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
[email protected]1a559442012-05-27 07:18:46533 break;
534 default:
535 NOTREACHED();
536 break;
537 }
538 }
539 }
540
541 if (manager_)
542 manager_->OnError();
543}
544
545void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
546 uint32 request_id,
547 bool success) {
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]ee4dd682012-06-12 15:49:33549 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46550
551 std::map<uint32, RequestType>::iterator iter =
552 pending_responses_.find(request_id);
553 if (iter != pending_responses_.end()) {
554 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
555
556 pending_responses_.erase(iter);
557 BrowserThread::PostTask(
558 BrowserThread::UI, FROM_HERE,
559 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
560 request_id, success));
561 }
562}
563
[email protected]ee4dd682012-06-12 15:49:33564void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
565 uint32 request_id,
566 bool success,
567 PP_Flash_BrowserOperations_Permission default_permission,
568 const ppapi::FlashSiteSettings& sites) {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
570 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
571
572 std::map<uint32, RequestType>::iterator iter =
573 pending_responses_.find(request_id);
574 if (iter != pending_responses_.end()) {
575 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
576
577 pending_responses_.erase(iter);
578 BrowserThread::PostTask(
579 BrowserThread::UI, FROM_HERE,
580 base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this,
581 request_id, success, default_permission, sites));
582 }
583}
584
585void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
586 uint32 request_id,
587 bool success) {
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
589 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
590
591 std::map<uint32, RequestType>::iterator iter =
592 pending_responses_.find(request_id);
593 if (iter != pending_responses_.end()) {
594 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
595
596 pending_responses_.erase(iter);
597 BrowserThread::PostTask(
598 BrowserThread::UI, FROM_HERE,
599 base::Bind(&Core::NotifySetDefaultPermissionCompleted, this,
600 request_id, success));
601 }
602}
603
604void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
605 uint32 request_id,
606 bool success) {
607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
608 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
609
610 std::map<uint32, RequestType>::iterator iter =
611 pending_responses_.find(request_id);
612 if (iter != pending_responses_.end()) {
613 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
614
615 pending_responses_.erase(iter);
616 BrowserThread::PostTask(
617 BrowserThread::UI, FROM_HERE,
618 base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id,
619 success));
620 }
621}
622
[email protected]1a559442012-05-27 07:18:46623PepperFlashSettingsManager::PepperFlashSettingsManager(
624 Client* client,
625 content::BrowserContext* browser_context)
626 : client_(client),
627 browser_context_(browser_context),
628 next_request_id_(1) {
629 DCHECK(client);
630 DCHECK(browser_context);
631}
632
633PepperFlashSettingsManager::~PepperFlashSettingsManager() {
634 if (core_.get()) {
635 core_->Detach();
636 core_ = NULL;
637 }
638}
639
[email protected]18a4d63c82012-05-25 23:37:03640// static
641bool PepperFlashSettingsManager::IsPepperFlashInUse(
642 PluginPrefs* plugin_prefs,
643 webkit::WebPluginInfo* plugin_info) {
644 if (!plugin_prefs)
645 return false;
646
647 content::PluginService* plugin_service =
648 content::PluginService::GetInstance();
649 std::vector<webkit::WebPluginInfo> plugins;
650 plugin_service->GetPluginInfoArray(
651 GURL(), kFlashPluginSwfMimeType, false, &plugins, NULL);
652
653 for (std::vector<webkit::WebPluginInfo>::iterator iter = plugins.begin();
654 iter != plugins.end(); ++iter) {
655 if (webkit::IsPepperPlugin(*iter) && plugin_prefs->IsPluginEnabled(*iter)) {
656 if (plugin_info)
657 *plugin_info = *iter;
658 return true;
659 }
660 }
661 return false;
662}
663
664// static
665void PepperFlashSettingsManager::RegisterUserPrefs(PrefService* prefs) {
666 prefs->RegisterBooleanPref(prefs::kDeauthorizeContentLicenses,
667 false,
668 PrefService::UNSYNCABLE_PREF);
669
670 prefs->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled,
671 true,
672 PrefService::UNSYNCABLE_PREF);
673}
[email protected]1a559442012-05-27 07:18:46674
675uint32 PepperFlashSettingsManager::DeauthorizeContentLicenses() {
676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
677
678 EnsureCoreExists();
679 uint32 id = GetNextRequestId();
680 core_->DeauthorizeContentLicenses(id);
681 return id;
682}
683
[email protected]ee4dd682012-06-12 15:49:33684uint32 PepperFlashSettingsManager::GetPermissionSettings(
685 PP_Flash_BrowserOperations_SettingType setting_type) {
686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
687
688 EnsureCoreExists();
689 uint32 id = GetNextRequestId();
690 core_->GetPermissionSettings(id, setting_type);
691 return id;
692}
693
694uint32 PepperFlashSettingsManager::SetDefaultPermission(
695 PP_Flash_BrowserOperations_SettingType setting_type,
696 PP_Flash_BrowserOperations_Permission permission,
697 bool clear_site_specific) {
698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
699
700 EnsureCoreExists();
701 uint32 id = GetNextRequestId();
702 core_->SetDefaultPermission(id, setting_type, permission,
703 clear_site_specific);
704 return id;
705}
706
707uint32 PepperFlashSettingsManager::SetSitePermission(
708 PP_Flash_BrowserOperations_SettingType setting_type,
709 const ppapi::FlashSiteSettings& sites) {
710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
711
712 EnsureCoreExists();
713 uint32 id = GetNextRequestId();
714 core_->SetSitePermission(id, setting_type, sites);
715 return id;
716}
717
[email protected]1a559442012-05-27 07:18:46718uint32 PepperFlashSettingsManager::GetNextRequestId() {
719 return next_request_id_++;
720}
721
722void PepperFlashSettingsManager::EnsureCoreExists() {
723 if (!core_.get())
724 core_ = new Core(this, browser_context_);
725}
726
727void PepperFlashSettingsManager::OnError() {
728 if (core_.get()) {
729 core_->Detach();
730 core_ = NULL;
731 } else {
732 NOTREACHED();
733 }
734}
735