Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permissions/permission_context_base.h" | 5 #include "chrome/browser/permissions/permission_context_base.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
|
dominickn
2017/01/20 04:03:47
#include "base/time/time.h"
meredithl
2017/01/20 04:21:33
Done.
| |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 19 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 19 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
| 20 #include "chrome/browser/permissions/permission_request.h" | 20 #include "chrome/browser/permissions/permission_request.h" |
| 21 #include "chrome/browser/permissions/permission_request_id.h" | 21 #include "chrome/browser/permissions/permission_request_id.h" |
| 22 #include "chrome/browser/permissions/permission_request_impl.h" | 22 #include "chrome/browser/permissions/permission_request_impl.h" |
| 23 #include "chrome/browser/permissions/permission_request_manager.h" | 23 #include "chrome/browser/permissions/permission_request_manager.h" |
| 24 #include "chrome/browser/permissions/permission_uma_util.h" | 24 #include "chrome/browser/permissions/permission_uma_util.h" |
| 25 #include "chrome/browser/permissions/permission_util.h" | 25 #include "chrome/browser/permissions/permission_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 const ContentSettingsType content_settings_type) | 60 const ContentSettingsType content_settings_type) |
| 61 : profile_(profile), | 61 : profile_(profile), |
| 62 permission_type_(permission_type), | 62 permission_type_(permission_type), |
| 63 content_settings_type_(content_settings_type), | 63 content_settings_type_(content_settings_type), |
| 64 safe_browsing_timeout_(kCheckUrlTimeoutMs), | 64 safe_browsing_timeout_(kCheckUrlTimeoutMs), |
| 65 weak_factory_(this) { | 65 weak_factory_(this) { |
| 66 #if defined(OS_ANDROID) | 66 #if defined(OS_ANDROID) |
| 67 permission_queue_controller_.reset(new PermissionQueueController( | 67 permission_queue_controller_.reset(new PermissionQueueController( |
| 68 profile_, permission_type_, content_settings_type_)); | 68 profile_, permission_type_, content_settings_type_)); |
| 69 #endif | 69 #endif |
| 70 PermissionDecisionAutoBlocker::UpdateFromVariations(); | 70 PermissionDecisionAutoBlocker::GetForProfile(profile_) |
| 71 ->UpdateFromVariations(); | |
| 71 } | 72 } |
| 72 | 73 |
| 73 PermissionContextBase::~PermissionContextBase() { | 74 PermissionContextBase::~PermissionContextBase() { |
| 74 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void PermissionContextBase::RequestPermission( | 78 void PermissionContextBase::RequestPermission( |
| 78 content::WebContents* web_contents, | 79 content::WebContents* web_contents, |
| 79 const PermissionRequestID& id, | 80 const PermissionRequestID& id, |
| 80 const GURL& requesting_frame, | 81 const GURL& requesting_frame, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 requesting_origin, embedding_origin, content_settings_type_); | 124 requesting_origin, embedding_origin, content_settings_type_); |
| 124 } | 125 } |
| 125 | 126 |
| 126 if (content_setting == CONTENT_SETTING_ALLOW || | 127 if (content_setting == CONTENT_SETTING_ALLOW || |
| 127 content_setting == CONTENT_SETTING_BLOCK) { | 128 content_setting == CONTENT_SETTING_BLOCK) { |
| 128 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 129 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 129 false /* persist */, content_setting); | 130 false /* persist */, content_setting); |
| 130 return; | 131 return; |
| 131 } | 132 } |
| 132 | 133 |
| 133 if (!db_manager_) { | |
| 134 safe_browsing::SafeBrowsingService* sb_service = | |
| 135 g_browser_process->safe_browsing_service(); | |
| 136 if (sb_service) | |
| 137 db_manager_ = sb_service->database_manager(); | |
| 138 } | |
| 139 | |
| 140 // Asynchronously check whether the origin should be blocked from making this | 134 // Asynchronously check whether the origin should be blocked from making this |
| 141 // permission request. It may be on the Safe Browsing API blacklist, or it may | 135 // permission request. It may be on the Safe Browsing API blacklist, or it may |
| 142 // have been dismissed too many times in a row. If the origin is allowed to | 136 // have been dismissed too many times in a row. If the origin is allowed to |
| 143 // request, that request will be made to ContinueRequestPermission(). | 137 // request, that request will be made to ContinueRequestPermission(). |
| 144 PermissionDecisionAutoBlocker::UpdateEmbargoedStatus( | 138 PermissionDecisionAutoBlocker::GetForProfile(profile_)->UpdateEmbargoedStatus( |
| 145 db_manager_, permission_type_, requesting_origin, web_contents, | 139 permission_type_, requesting_origin, web_contents, base::Time::Now(), |
| 146 safe_browsing_timeout_, profile_, base::Time::Now(), | |
| 147 base::Bind(&PermissionContextBase::ContinueRequestPermission, | 140 base::Bind(&PermissionContextBase::ContinueRequestPermission, |
| 148 weak_factory_.GetWeakPtr(), web_contents, id, | 141 weak_factory_.GetWeakPtr(), web_contents, id, |
| 149 requesting_origin, embedding_origin, user_gesture, callback)); | 142 requesting_origin, embedding_origin, user_gesture, callback)); |
| 150 } | 143 } |
| 151 | 144 |
| 152 void PermissionContextBase::ContinueRequestPermission( | 145 void PermissionContextBase::ContinueRequestPermission( |
| 153 content::WebContents* web_contents, | 146 content::WebContents* web_contents, |
| 154 const PermissionRequestID& id, | 147 const PermissionRequestID& id, |
| 155 const GURL& requesting_origin, | 148 const GURL& requesting_origin, |
| 156 const GURL& embedding_origin, | 149 const GURL& embedding_origin, |
| 157 bool user_gesture, | 150 bool user_gesture, |
| 158 const BrowserPermissionCallback& callback, | 151 const BrowserPermissionCallback& callback, |
| 159 bool permission_blocked) { | 152 bool permission_blocked) { |
| 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 153 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 161 if (permission_blocked) { | 154 if (permission_blocked) { |
| 162 // TODO(meredithl): Add UMA metrics here. | 155 // TODO(meredithl): Add UMA metrics here. |
| 163 web_contents->GetMainFrame()->AddMessageToConsole( | 156 web_contents->GetMainFrame()->AddMessageToConsole( |
| 164 content::CONSOLE_MESSAGE_LEVEL_LOG, | 157 content::CONSOLE_MESSAGE_LEVEL_LOG, |
| 165 base::StringPrintf( | 158 base::StringPrintf( |
| 166 "%s permission has been auto-blocked.", | 159 "%s permission has been auto-blocked.", |
| 167 PermissionUtil::GetPermissionString(permission_type_).c_str())); | 160 PermissionUtil::GetPermissionString(permission_type_).c_str())); |
| 168 // Permission has been blacklisted, block the request. | 161 // Permission has been automatically blocked. |
| 169 // TODO(meredithl): Consider setting the content setting and persisting | 162 // TODO(meredithl): Consider setting the content setting and persisting |
|
dominickn
2017/01/20 04:03:47
You can remove this TODO :)
meredithl
2017/01/20 04:21:33
Done.
| |
| 170 // the decision to block. | 163 // the decision to block. |
| 171 callback.Run(CONTENT_SETTING_BLOCK); | 164 callback.Run(CONTENT_SETTING_BLOCK); |
| 172 return; | 165 return; |
| 173 } | 166 } |
| 174 | 167 |
| 175 // Site is not blacklisted by Safe Browsing for the requested permission. | |
| 176 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, | 168 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, |
| 177 embedding_origin, profile_); | 169 embedding_origin, profile_); |
| 178 | 170 |
| 179 DecidePermission(web_contents, id, requesting_origin, embedding_origin, | 171 DecidePermission(web_contents, id, requesting_origin, embedding_origin, |
| 180 user_gesture, callback); | 172 user_gesture, callback); |
| 181 } | 173 } |
| 182 | 174 |
| 183 ContentSetting PermissionContextBase::GetPermissionStatus( | 175 ContentSetting PermissionContextBase::GetPermissionStatus( |
| 184 const GURL& requesting_origin, | 176 const GURL& requesting_origin, |
| 185 const GURL& embedding_origin) const { | 177 const GURL& embedding_origin) const { |
| 186 // If the permission has been disabled through Finch, block all requests. | 178 // If the permission has been disabled through Finch, block all requests. |
| 187 if (IsPermissionKillSwitchOn()) | 179 if (IsPermissionKillSwitchOn()) |
| 188 return CONTENT_SETTING_BLOCK; | 180 return CONTENT_SETTING_BLOCK; |
| 189 | 181 |
| 190 if (IsRestrictedToSecureOrigins() && | 182 if (IsRestrictedToSecureOrigins() && |
| 191 !content::IsOriginSecure(requesting_origin)) { | 183 !content::IsOriginSecure(requesting_origin)) { |
| 192 return CONTENT_SETTING_BLOCK; | 184 return CONTENT_SETTING_BLOCK; |
| 193 } | 185 } |
| 194 | 186 PermissionDecisionAutoBlocker* autoblocker = |
|
dominickn
2017/01/20 04:03:47
Nit: newline above this line. Also consider not ha
meredithl
2017/01/20 04:21:33
Done.
| |
| 187 PermissionDecisionAutoBlockerFactory::GetForProfile(profile_); | |
| 195 ContentSetting content_setting = | 188 ContentSetting content_setting = |
| 196 GetPermissionStatusInternal(requesting_origin, embedding_origin); | 189 GetPermissionStatusInternal(requesting_origin, embedding_origin); |
| 197 if (content_setting == CONTENT_SETTING_ASK && | 190 if (content_setting == CONTENT_SETTING_ASK && |
| 198 PermissionDecisionAutoBlocker::IsUnderEmbargo( | 191 autoblocker->IsUnderEmbargo(permission_type_, requesting_origin, |
| 199 permission_type_, profile_, requesting_origin, base::Time::Now())) { | 192 base::Time::Now())) { |
| 200 return CONTENT_SETTING_BLOCK; | 193 return CONTENT_SETTING_BLOCK; |
| 201 } | 194 } |
| 202 return content_setting; | 195 return content_setting; |
| 203 } | 196 } |
| 204 | 197 |
| 205 void PermissionContextBase::ResetPermission( | 198 void PermissionContextBase::ResetPermission( |
| 206 const GURL& requesting_origin, | 199 const GURL& requesting_origin, |
| 207 const GURL& embedding_origin) { | 200 const GURL& embedding_origin) { |
| 208 HostContentSettingsMapFactory::GetForProfile(profile_) | 201 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 209 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 202 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 } else if (content_setting == CONTENT_SETTING_BLOCK) { | 313 } else if (content_setting == CONTENT_SETTING_BLOCK) { |
| 321 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, | 314 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, |
| 322 requesting_origin, profile_); | 315 requesting_origin, profile_); |
| 323 } else { | 316 } else { |
| 324 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, | 317 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, |
| 325 requesting_origin, profile_); | 318 requesting_origin, profile_); |
| 326 } | 319 } |
| 327 } | 320 } |
| 328 | 321 |
| 329 if (content_setting == CONTENT_SETTING_DEFAULT && | 322 if (content_setting == CONTENT_SETTING_DEFAULT && |
| 330 PermissionDecisionAutoBlocker::RecordDismissAndEmbargo( | 323 PermissionDecisionAutoBlocker::GetForProfile(profile_) |
| 331 requesting_origin, permission_type_, profile_, base::Time::Now())) { | 324 ->RecordDismissAndEmbargo(requesting_origin, permission_type_, |
| 325 base::Time::Now())) { | |
| 332 // The permission has been embargoed, so it is blocked for this permission | 326 // The permission has been embargoed, so it is blocked for this permission |
| 333 // request, but not persisted. | 327 // request, but not persisted. |
| 334 content_setting = CONTENT_SETTING_BLOCK; | 328 content_setting = CONTENT_SETTING_BLOCK; |
| 335 } | 329 } |
| 336 | 330 |
| 337 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 331 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 338 persist, content_setting); | 332 persist, content_setting); |
| 339 } | 333 } |
| 340 | 334 |
| 341 #if defined(OS_ANDROID) | 335 #if defined(OS_ANDROID) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 377 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 384 content_setting == CONTENT_SETTING_BLOCK); | 378 content_setting == CONTENT_SETTING_BLOCK); |
| 385 DCHECK(!requesting_origin.SchemeIsFile()); | 379 DCHECK(!requesting_origin.SchemeIsFile()); |
| 386 DCHECK(!embedding_origin.SchemeIsFile()); | 380 DCHECK(!embedding_origin.SchemeIsFile()); |
| 387 | 381 |
| 388 HostContentSettingsMapFactory::GetForProfile(profile_) | 382 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 389 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 383 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
| 390 content_settings_type_, std::string(), | 384 content_settings_type_, std::string(), |
| 391 content_setting); | 385 content_setting); |
| 392 } | 386 } |
| 393 | |
| 394 void PermissionContextBase::SetSafeBrowsingDatabaseManagerAndTimeoutForTest( | |
| 395 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
| 396 int timeout) { | |
| 397 db_manager_ = db_manager; | |
| 398 safe_browsing_timeout_ = timeout; | |
| 399 } | |
| OLD | NEW |