1 // Copyright 2013 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.
5 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/content_settings/core/common/permission_request_id.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_contents.h"
15 #if defined(ENABLE_EXTENSIONS)
16 #include "chrome/browser/extensions/extension_service.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/suggest_permission_util.h"
19 #include "extensions/browser/view_type_utils.h"
20 #include "extensions/common/extension.h"
22 using extensions::APIPermission
;
25 ProtectedMediaIdentifierPermissionContext::
26 ProtectedMediaIdentifierPermissionContext(Profile
* profile
)
27 : PermissionContextBase(profile
,
28 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
) {
31 ProtectedMediaIdentifierPermissionContext::
32 ~ProtectedMediaIdentifierPermissionContext() {
35 void ProtectedMediaIdentifierPermissionContext::RequestPermission(
36 content::WebContents
* web_contents
,
37 const PermissionRequestID
& id
,
38 const GURL
& requesting_frame_origin
,
40 const BrowserPermissionCallback
& callback
) {
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
43 #if defined(ENABLE_EXTENSIONS)
44 if (extensions::GetViewType(web_contents
) !=
45 extensions::VIEW_TYPE_TAB_CONTENTS
) {
46 // The tab may have gone away, or the request may not be from a tab at all.
48 << "Attempt to use protected media identifier in tabless renderer: "
50 << " (can't prompt user without a visible tab)";
51 NotifyPermissionSet(id
,
53 web_contents
->GetLastCommittedURL().GetOrigin(),
54 callback
, false, false);
59 #if defined(OS_ANDROID)
60 // Check if the protected media identifier master switch is disabled.
61 if (!profile()->GetPrefs()->GetBoolean(
62 prefs::kProtectedMediaIdentifierEnabled
)) {
63 NotifyPermissionSet(id
,
64 requesting_frame_origin
,
65 web_contents
->GetLastCommittedURL().GetOrigin(),
66 callback
, false, false);
71 PermissionContextBase::RequestPermission(web_contents
, id
,
72 requesting_frame_origin
,
77 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
78 const PermissionRequestID
& id
,
79 const GURL
& requesting_frame
,
81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
83 // WebContents may have gone away.
84 TabSpecificContentSettings
* content_settings
=
85 TabSpecificContentSettings::Get(id
.render_process_id(),
87 if (content_settings
) {
88 content_settings
->OnProtectedMediaIdentifierPermissionSet(
89 requesting_frame
.GetOrigin(), allowed
);