OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media/protected_media_identifier_permission_context.h" | 5 #include "chrome/browser/media/protected_media_identifier_permission_context.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "components/content_settings/core/common/permission_request_id.h" | 11 #include "components/content_settings/core/common/permission_request_id.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 | 14 |
15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
16 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | |
16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
17 #include "chromeos/settings/cros_settings_names.h" | 18 #include "chromeos/settings/cros_settings_names.h" |
19 #include "ui/views/widget/widget.h" | |
Jun Mukai
2015/02/05 02:08:14
blank line between #include and using.
xhwang
2015/02/05 02:49:34
Done.
| |
20 using chromeos::attestation::PlatformVerificationDialog; | |
21 using chromeos::attestation::PlatformVerificationFlow; | |
18 #endif | 22 #endif |
19 | 23 |
24 namespace { | |
25 | |
26 PermissionRequestID GetInvalidPendingId() { | |
27 return PermissionRequestID(-1, -1, -1, GURL()); | |
28 } | |
29 | |
30 } | |
31 | |
20 ProtectedMediaIdentifierPermissionContext:: | 32 ProtectedMediaIdentifierPermissionContext:: |
21 ProtectedMediaIdentifierPermissionContext(Profile* profile) | 33 ProtectedMediaIdentifierPermissionContext(Profile* profile) |
22 : PermissionContextBase(profile, | 34 : PermissionContextBase(profile, |
23 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { | 35 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER), |
36 #if defined(OS_CHROMEOS) | |
37 pending_id_(GetInvalidPendingId()), | |
Jun Mukai
2015/02/05 02:08:14
It seems that pending_id_ and widget_ have really
xhwang
2015/02/05 02:49:34
There are two reasons I like pending_id_:
1, We do
| |
38 widget_(nullptr), | |
39 #endif | |
40 weak_factory_(this) { | |
24 } | 41 } |
25 | 42 |
26 ProtectedMediaIdentifierPermissionContext:: | 43 ProtectedMediaIdentifierPermissionContext:: |
27 ~ProtectedMediaIdentifierPermissionContext() { | 44 ~ProtectedMediaIdentifierPermissionContext() { |
Jun Mukai
2015/02/05 02:08:14
Should invoke CancelPermissionRequest? Otherwise,
xhwang
2015/02/05 02:49:34
It seems no other *PermissionContext is doing this
| |
28 } | 45 } |
29 | 46 |
30 void ProtectedMediaIdentifierPermissionContext::RequestPermission( | 47 void ProtectedMediaIdentifierPermissionContext::RequestPermission( |
31 content::WebContents* web_contents, | 48 content::WebContents* web_contents, |
32 const PermissionRequestID& id, | 49 const PermissionRequestID& id, |
33 const GURL& requesting_frame_origin, | 50 const GURL& requesting_origin, |
34 bool user_gesture, | 51 bool user_gesture, |
35 const BrowserPermissionCallback& callback) { | 52 const BrowserPermissionCallback& callback) { |
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
37 | 54 |
38 if (!IsProtectedMediaIdentifierEnabled()) { | 55 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
39 NotifyPermissionSet(id, | 56 |
40 requesting_frame_origin, | 57 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || |
41 web_contents->GetLastCommittedURL().GetOrigin(), | 58 !IsProtectedMediaIdentifierEnabled()) { |
42 callback, false, false); | 59 NotifyPermissionSet(id, requesting_origin, embedding_origin, |
60 callback, false /* persist */, false /* granted */); | |
43 return; | 61 return; |
44 } | 62 } |
45 | 63 |
64 #if defined(OS_CHROMEOS) | |
65 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which | |
66 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 | |
67 // Instead, we check the content setting and show existing platform | |
ddorwin
2015/02/05 02:23:24
nit: show the...
xhwang
2015/02/05 02:49:35
Done.
| |
68 // verification UI. | |
69 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. | |
70 ContentSetting content_setting = | |
71 GetPermissionStatus(requesting_origin, embedding_origin); | |
72 | |
73 switch (content_setting) { | |
74 case CONTENT_SETTING_BLOCK: | |
75 callback.Run(false); | |
ddorwin
2015/02/05 02:23:24
I'm a little concerned about the differences betwe
xhwang
2015/02/05 02:49:35
Thanks for checking that. Updated to match base.
| |
76 return; | |
77 case CONTENT_SETTING_ALLOW: | |
78 callback.Run(true); | |
79 return; | |
80 default: | |
81 break; | |
82 } | |
83 | |
84 // We only support one prompt and one pending permission request. | |
ddorwin
2015/02/05 02:23:24
Reference 447005?
xhwang
2015/02/05 02:49:35
Done.
| |
85 // Reject the new one if there is already one pending. | |
86 if (!pending_id_.Equals(GetInvalidPendingId())) { | |
87 callback.Run(false); | |
88 return; | |
89 } | |
90 | |
91 pending_id_ = id; | |
92 widget_ = PlatformVerificationDialog::ShowDialog( | |
93 web_contents, requesting_origin, | |
94 base::Bind(&ProtectedMediaIdentifierPermissionContext:: | |
95 OnPlatformVerificationResult, | |
96 weak_factory_.GetWeakPtr(), id, requesting_origin, | |
97 embedding_origin, callback)); | |
98 return; | |
ddorwin
2015/02/05 02:23:24
#else to avoid unreachable code
xhwang
2015/02/05 02:49:34
Done.
| |
99 #endif | |
100 | |
46 PermissionContextBase::RequestPermission(web_contents, id, | 101 PermissionContextBase::RequestPermission(web_contents, id, |
47 requesting_frame_origin, | 102 requesting_origin, |
48 user_gesture, | 103 user_gesture, |
49 callback); | 104 callback); |
50 } | 105 } |
51 | 106 |
52 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( | 107 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( |
53 const GURL& requesting_origin, | 108 const GURL& requesting_origin, |
54 const GURL& embedding_origin) const { | 109 const GURL& embedding_origin) const { |
55 if (!IsProtectedMediaIdentifierEnabled()) | 110 if (!IsProtectedMediaIdentifierEnabled()) |
56 return CONTENT_SETTING_BLOCK; | 111 return CONTENT_SETTING_BLOCK; |
57 | 112 |
58 return PermissionContextBase::GetPermissionStatus(requesting_origin, | 113 return PermissionContextBase::GetPermissionStatus(requesting_origin, |
59 embedding_origin); | 114 embedding_origin); |
60 } | 115 } |
61 | 116 |
117 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( | |
118 content::WebContents* web_contents, | |
119 const PermissionRequestID& id) { | |
120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
121 | |
122 #if defined(OS_CHROMEOS) | |
123 if (!widget_ || !pending_id_.Equals(id)) | |
Jun Mukai
2015/02/05 02:08:14
Do we have to care about pending_id_ here?
ddorwin
2015/02/05 02:23:24
Should we DCHECK(pending_id_.Equals(id))? This wo
xhwang
2015/02/05 02:49:34
See above.
xhwang
2015/02/05 02:49:34
IN case there are multiple requests, this can be t
| |
124 return; | |
125 | |
126 // Close the |widget_|. OnPlatformVerificationResult() will be fired | |
127 // during this process, but since |pending_id_| is cleared, the callback will | |
128 // be dropped. | |
129 pending_id_ = GetInvalidPendingId(); | |
130 widget_->Close(); | |
Jun Mukai
2015/02/05 02:08:14
then, widget_ = nullptr;
xhwang
2015/02/05 02:49:34
widget->Close() could cause OnPlatformVerification
| |
131 return; | |
132 #endif | |
ddorwin
2015/02/05 02:23:24
Ditto on #else. Or just ifdef the existence of thi
xhwang
2015/02/05 02:49:34
Done.
| |
133 | |
134 PermissionContextBase::CancelPermissionRequest(web_contents, id); | |
135 } | |
136 | |
62 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( | 137 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( |
63 const PermissionRequestID& id, | 138 const PermissionRequestID& id, |
64 const GURL& requesting_frame, | 139 const GURL& requesting_frame, |
65 bool allowed) { | 140 bool allowed) { |
66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
67 | 142 |
68 // WebContents may have gone away. | 143 // WebContents may have gone away. |
69 TabSpecificContentSettings* content_settings = | 144 TabSpecificContentSettings* content_settings = |
70 TabSpecificContentSettings::Get(id.render_process_id(), | 145 TabSpecificContentSettings::Get(id.render_process_id(), |
71 id.render_view_id()); | 146 id.render_view_id()); |
72 if (content_settings) { | 147 if (content_settings) { |
73 content_settings->OnProtectedMediaIdentifierPermissionSet( | 148 content_settings->OnProtectedMediaIdentifierPermissionSet( |
74 requesting_frame.GetOrigin(), allowed); | 149 requesting_frame.GetOrigin(), allowed); |
75 } | 150 } |
76 | |
77 } | 151 } |
78 | 152 |
79 // TODO(xhwang): We should consolidate the "protected content" related pref | 153 // TODO(xhwang): We should consolidate the "protected content" related pref |
80 // across platforms. | 154 // across platforms. |
81 bool ProtectedMediaIdentifierPermissionContext:: | 155 bool ProtectedMediaIdentifierPermissionContext:: |
82 IsProtectedMediaIdentifierEnabled() const { | 156 IsProtectedMediaIdentifierEnabled() const { |
83 bool enabled = false; | 157 bool enabled = false; |
84 | 158 |
85 #if defined(OS_ANDROID) | 159 #if defined(OS_ANDROID) |
86 enabled = profile()->GetPrefs()->GetBoolean( | 160 enabled = profile()->GetPrefs()->GetBoolean( |
87 prefs::kProtectedMediaIdentifierEnabled); | 161 prefs::kProtectedMediaIdentifierEnabled); |
88 #endif | 162 #endif |
89 | 163 |
90 #if defined(OS_CHROMEOS) | 164 #if defined(OS_CHROMEOS) |
91 // This could be disabled by the device policy. | 165 // This could be disabled by the device policy. |
92 bool enabled_for_device = false; | 166 bool enabled_for_device = false; |
93 enabled = chromeos::CrosSettings::Get()->GetBoolean( | 167 enabled = chromeos::CrosSettings::Get()->GetBoolean( |
94 chromeos::kAttestationForContentProtectionEnabled, | 168 chromeos::kAttestationForContentProtectionEnabled, |
95 &enabled_for_device) && | 169 &enabled_for_device) && |
96 enabled_for_device && | 170 enabled_for_device && |
97 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); | 171 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); |
98 #endif | 172 #endif |
99 | 173 |
100 DVLOG_IF(1, !enabled) | 174 DVLOG_IF(1, !enabled) |
101 << "Protected media identifier disabled by the user or by device policy."; | 175 << "Protected media identifier disabled by the user or by device policy."; |
102 return enabled; | 176 return enabled; |
103 } | 177 } |
178 | |
179 #if defined(OS_CHROMEOS) | |
180 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult( | |
181 const PermissionRequestID& id, | |
182 const GURL& requesting_origin, | |
183 const GURL& embedding_origin, | |
184 const BrowserPermissionCallback& callback, | |
185 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { | |
186 DCHECK(widget_); | |
187 widget_ = nullptr; | |
188 | |
189 // The request may have been canceled. Drop the callback here. | |
190 if (!pending_id_.Equals(id)) | |
ddorwin
2015/02/05 02:23:24
ditto on DCHECK
xhwang
2015/02/05 02:49:35
This will happen if CancelPermissionRequest() is c
| |
191 return; | |
192 | |
193 pending_id_ = GetInvalidPendingId(); | |
194 | |
195 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { | |
196 // Deny request and do not save to content settings. | |
197 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
ddorwin
2015/02/05 02:23:24
Like the base code, this appears to store by reque
xhwang
2015/02/05 02:49:35
This is what I have in the preference file:
"con
| |
198 false, // Do not save to content settings. | |
199 false); // Do not allow the permission. | |
200 return; | |
201 } | |
202 | |
203 NotifyPermissionSet( | |
204 id, requesting_origin, embedding_origin, callback, | |
205 true, // Save to content settings. | |
206 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); | |
207 } | |
208 #endif | |
OLD | NEW |