| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 ProtectedMediaIdentifierPermissionContext:: | 50 ProtectedMediaIdentifierPermissionContext:: |
| 51 ~ProtectedMediaIdentifierPermissionContext() { | 51 ~ProtectedMediaIdentifierPermissionContext() { |
| 52 } | 52 } |
| 53 | 53 |
| 54 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 55 void ProtectedMediaIdentifierPermissionContext::RequestPermission( | 55 void ProtectedMediaIdentifierPermissionContext::RequestPermission( |
| 56 content::WebContents* web_contents, | 56 content::WebContents* web_contents, |
| 57 const PermissionRequestID& id, | 57 const PermissionRequestID& id, |
| 58 const GURL& requesting_origin, | 58 const url::Origin& requesting_origin, |
| 59 const BrowserPermissionCallback& callback) { | 59 const BrowserPermissionCallback& callback) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 61 | 61 |
| 62 // First check if this permission has been disabled. This check occurs before | 62 // First check if this permission has been disabled. This check occurs before |
| 63 // the call to GetPermissionStatus, which will return CONTENT_SETTING_BLOCK | 63 // the call to GetPermissionStatus, which will return CONTENT_SETTING_BLOCK |
| 64 // if the kill switch is on. | 64 // if the kill switch is on. |
| 65 // | 65 // |
| 66 // TODO(xhwang): Remove this kill switch block when crbug.com/454847 is fixed | 66 // TODO(xhwang): Remove this kill switch block when crbug.com/454847 is fixed |
| 67 // and we no longer call GetPermissionStatus before | 67 // and we no longer call GetPermissionStatus before |
| 68 // PermissionContextBase::RequestPermission. | 68 // PermissionContextBase::RequestPermission. |
| 69 if (IsPermissionKillSwitchOn()) { | 69 if (IsPermissionKillSwitchOn()) { |
| 70 // Log to the developer console. | 70 // Log to the developer console. |
| 71 web_contents->GetMainFrame()->AddMessageToConsole( | 71 web_contents->GetMainFrame()->AddMessageToConsole( |
| 72 content::CONSOLE_MESSAGE_LEVEL_LOG, | 72 content::CONSOLE_MESSAGE_LEVEL_LOG, |
| 73 base::StringPrintf( | 73 base::StringPrintf( |
| 74 "%s permission has been blocked.", | 74 "%s permission has been blocked.", |
| 75 PermissionUtil::GetPermissionString( | 75 PermissionUtil::GetPermissionString( |
| 76 content::PermissionType::PROTECTED_MEDIA_IDENTIFIER) | 76 content::PermissionType::PROTECTED_MEDIA_IDENTIFIER) |
| 77 .c_str())); | 77 .c_str())); |
| 78 // The kill switch is enabled for this permission; Block all requests and | 78 // The kill switch is enabled for this permission; Block all requests and |
| 79 // run the callback immediately. | 79 // run the callback immediately. |
| 80 callback.Run(CONTENT_SETTING_BLOCK); | 80 callback.Run(CONTENT_SETTING_BLOCK); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); | 84 const url::Origin embedding_origin(web_contents->GetLastCommittedURL()); |
| 85 | 85 |
| 86 DVLOG(1) << __FUNCTION__ << ": (" << requesting_origin.spec() << ", " | 86 DVLOG(1) << __FUNCTION__ << ": (" << requesting_origin << ", " |
| 87 << embedding_origin.spec() << ")"; | 87 << embedding_origin << ")"; |
| 88 | 88 |
| 89 ContentSetting content_setting = | 89 ContentSetting content_setting = |
| 90 GetPermissionStatus(requesting_origin, embedding_origin); | 90 GetPermissionStatus(requesting_origin, embedding_origin); |
| 91 | 91 |
| 92 if (content_setting == CONTENT_SETTING_ALLOW || | 92 if (content_setting == CONTENT_SETTING_ALLOW || |
| 93 content_setting == CONTENT_SETTING_BLOCK) { | 93 content_setting == CONTENT_SETTING_BLOCK) { |
| 94 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 94 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 95 false /* persist */, content_setting); | 95 false /* persist */, content_setting); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 DCHECK_EQ(CONTENT_SETTING_ASK, content_setting); | 99 DCHECK_EQ(CONTENT_SETTING_ASK, content_setting); |
| 100 | 100 |
| 101 // Since the dialog is modal, we only support one prompt per |web_contents|. | 101 // Since the dialog is modal, we only support one prompt per |web_contents|. |
| 102 // Reject the new one if there is already one pending. See | 102 // Reject the new one if there is already one pending. See |
| 103 // http://crbug.com/447005 | 103 // http://crbug.com/447005 |
| 104 if (pending_requests_.count(web_contents)) { | 104 if (pending_requests_.count(web_contents)) { |
| 105 callback.Run(CONTENT_SETTING_ASK); | 105 callback.Run(CONTENT_SETTING_ASK); |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which | 109 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which |
| 110 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 | 110 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 |
| 111 // Instead, we show the existing platform verification UI. | 111 // Instead, we show the existing platform verification UI. |
| 112 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. | 112 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. |
| 113 const GURL requesting_url(requesting_origin.Serialize()); |
| 113 views::Widget* widget = PlatformVerificationDialog::ShowDialog( | 114 views::Widget* widget = PlatformVerificationDialog::ShowDialog( |
| 114 web_contents, requesting_origin, | 115 web_contents, requesting_url, |
| 115 base::Bind(&ProtectedMediaIdentifierPermissionContext:: | 116 base::Bind(&ProtectedMediaIdentifierPermissionContext:: |
| 116 OnPlatformVerificationConsentResponse, | 117 OnPlatformVerificationConsentResponse, |
| 117 weak_factory_.GetWeakPtr(), web_contents, id, | 118 weak_factory_.GetWeakPtr(), web_contents, id, |
| 118 requesting_origin, embedding_origin, callback)); | 119 requesting_origin, embedding_origin, callback)); |
| 119 pending_requests_.insert( | 120 pending_requests_.insert( |
| 120 std::make_pair(web_contents, std::make_pair(widget, id))); | 121 std::make_pair(web_contents, std::make_pair(widget, id))); |
| 121 } | 122 } |
| 122 #endif // defined(OS_CHROMEOS) | 123 #endif // defined(OS_CHROMEOS) |
| 123 | 124 |
| 124 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( | 125 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( |
| 125 const GURL& requesting_origin, | 126 const url::Origin& requesting_origin, |
| 126 const GURL& embedding_origin) const { | 127 const url::Origin& embedding_origin) const { |
| 127 DVLOG(1) << __FUNCTION__ << ": (" << requesting_origin.spec() << ", " | 128 DVLOG(1) << __FUNCTION__ << ": (" << requesting_origin.Serialize() << ", " |
| 128 << embedding_origin.spec() << ")"; | 129 << embedding_origin.Serialize() << ")"; |
| 129 | 130 |
| 130 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || | 131 if (requesting_origin.unique() || embedding_origin.unique() || |
| 131 !IsProtectedMediaIdentifierEnabled()) { | 132 !IsProtectedMediaIdentifierEnabled()) { |
| 132 return CONTENT_SETTING_BLOCK; | 133 return CONTENT_SETTING_BLOCK; |
| 133 } | 134 } |
| 134 | 135 |
| 135 ContentSetting content_setting = PermissionContextBase::GetPermissionStatus( | 136 ContentSetting content_setting = PermissionContextBase::GetPermissionStatus( |
| 136 requesting_origin, embedding_origin); | 137 requesting_origin, embedding_origin); |
| 137 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 138 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 138 content_setting == CONTENT_SETTING_BLOCK || | 139 content_setting == CONTENT_SETTING_BLOCK || |
| 139 content_setting == CONTENT_SETTING_ASK); | 140 content_setting == CONTENT_SETTING_ASK); |
| 140 | 141 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 161 // will simply be dropped. | 162 // will simply be dropped. |
| 162 if (!web_contents->IsBeingDestroyed()) | 163 if (!web_contents->IsBeingDestroyed()) |
| 163 widget->Close(); | 164 widget->Close(); |
| 164 #else | 165 #else |
| 165 PermissionContextBase::CancelPermissionRequest(web_contents, id); | 166 PermissionContextBase::CancelPermissionRequest(web_contents, id); |
| 166 #endif | 167 #endif |
| 167 } | 168 } |
| 168 | 169 |
| 169 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( | 170 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( |
| 170 const PermissionRequestID& id, | 171 const PermissionRequestID& id, |
| 171 const GURL& requesting_frame, | 172 const url::Origin& requesting_frame, |
| 172 bool allowed) { | 173 bool allowed) { |
| 173 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 174 | 175 |
| 175 // WebContents may have gone away. | 176 // WebContents may have gone away. |
| 176 TabSpecificContentSettings* content_settings = | 177 TabSpecificContentSettings* content_settings = |
| 177 TabSpecificContentSettings::GetForFrame(id.render_process_id(), | 178 TabSpecificContentSettings::GetForFrame(id.render_process_id(), |
| 178 id.render_frame_id()); | 179 id.render_frame_id()); |
| 179 if (content_settings) { | 180 if (content_settings) { |
| 180 content_settings->OnProtectedMediaIdentifierPermissionSet( | 181 const GURL requesting_url(requesting_frame.Serialize()); |
| 181 requesting_frame.GetOrigin(), allowed); | 182 content_settings->OnProtectedMediaIdentifierPermissionSet(requesting_url, |
| 183 allowed); |
| 182 } | 184 } |
| 183 } | 185 } |
| 184 | 186 |
| 185 bool | 187 bool |
| 186 ProtectedMediaIdentifierPermissionContext::IsRestrictedToSecureOrigins() const { | 188 ProtectedMediaIdentifierPermissionContext::IsRestrictedToSecureOrigins() const { |
| 187 return false; | 189 return false; |
| 188 } | 190 } |
| 189 | 191 |
| 190 // TODO(xhwang): We should consolidate the "protected content" related pref | 192 // TODO(xhwang): We should consolidate the "protected content" related pref |
| 191 // across platforms. | 193 // across platforms. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 220 #endif | 222 #endif |
| 221 | 223 |
| 222 return true; | 224 return true; |
| 223 } | 225 } |
| 224 | 226 |
| 225 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
| 226 void ProtectedMediaIdentifierPermissionContext:: | 228 void ProtectedMediaIdentifierPermissionContext:: |
| 227 OnPlatformVerificationConsentResponse( | 229 OnPlatformVerificationConsentResponse( |
| 228 content::WebContents* web_contents, | 230 content::WebContents* web_contents, |
| 229 const PermissionRequestID& id, | 231 const PermissionRequestID& id, |
| 230 const GURL& requesting_origin, | 232 const url::Origin& requesting_origin, |
| 231 const GURL& embedding_origin, | 233 const url::Origin& embedding_origin, |
| 232 const BrowserPermissionCallback& callback, | 234 const BrowserPermissionCallback& callback, |
| 233 PlatformVerificationDialog::ConsentResponse response) { | 235 PlatformVerificationDialog::ConsentResponse response) { |
| 234 // The request may have been canceled. Drop the callback in that case. | 236 // The request may have been canceled. Drop the callback in that case. |
| 235 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | 237 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
| 236 if (request == pending_requests_.end()) | 238 if (request == pending_requests_.end()) |
| 237 return; | 239 return; |
| 238 | 240 |
| 239 DCHECK(request->second.second == id); | 241 DCHECK(request->second.second == id); |
| 240 pending_requests_.erase(request); | 242 pending_requests_.erase(request); |
| 241 | 243 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 260 content_setting = CONTENT_SETTING_BLOCK; | 262 content_setting = CONTENT_SETTING_BLOCK; |
| 261 persist = true; | 263 persist = true; |
| 262 break; | 264 break; |
| 263 } | 265 } |
| 264 | 266 |
| 265 NotifyPermissionSet( | 267 NotifyPermissionSet( |
| 266 id, requesting_origin, embedding_origin, callback, | 268 id, requesting_origin, embedding_origin, callback, |
| 267 persist, content_setting); | 269 persist, content_setting); |
| 268 } | 270 } |
| 269 #endif | 271 #endif |
| OLD | NEW |