| 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> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/common/origin_util.h" | 38 #include "content/public/common/origin_util.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 | 40 |
| 41 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 42 #include "chrome/browser/permissions/permission_queue_controller.h" | 42 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 namespace { |
| 46 |
| 47 const char kPermissionBlockedKillSwitchMessage[] = |
| 48 "%s permission has been blocked."; |
| 49 |
| 50 const char kPermissionBlockedRepeatedDismissalsMessage[] = |
| 51 "%s permission has been blocked as the user has dismissed the permission " |
| 52 "prompt several times. See " |
| 53 "https://www.chromestatus.com/features/6443143280984064 for more " |
| 54 "information."; |
| 55 |
| 56 const char kPermissionBlockedBlacklistMessage[] = |
| 57 "this origin is not allowed to request %s permission."; |
| 58 |
| 59 void LogPermissionBlockedMessage(content::WebContents* web_contents, |
| 60 const char* message, |
| 61 ContentSettingsType type) { |
| 62 web_contents->GetMainFrame()->AddMessageToConsole( |
| 63 content::CONSOLE_MESSAGE_LEVEL_INFO, |
| 64 base::StringPrintf(message, |
| 65 PermissionUtil::GetPermissionString(type).c_str())); |
| 66 } |
| 67 |
| 68 } // namespace |
| 69 |
| 45 // static | 70 // static |
| 46 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = | 71 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = |
| 47 "PermissionsKillSwitch"; | 72 "PermissionsKillSwitch"; |
| 48 // static | 73 // static |
| 49 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = | 74 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = |
| 50 "blocked"; | 75 "blocked"; |
| 51 | 76 |
| 52 PermissionContextBase::PermissionContextBase( | 77 PermissionContextBase::PermissionContextBase( |
| 53 Profile* profile, | 78 Profile* profile, |
| 54 const ContentSettingsType content_settings_type) | 79 const ContentSettingsType content_settings_type) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Synchronously check the content setting to see if the user has already made | 118 // Synchronously check the content setting to see if the user has already made |
| 94 // a decision, or if the origin is under embargo. If so, respect that | 119 // a decision, or if the origin is under embargo. If so, respect that |
| 95 // decision. | 120 // decision. |
| 96 PermissionResult result = | 121 PermissionResult result = |
| 97 GetPermissionStatus(requesting_origin, embedding_origin); | 122 GetPermissionStatus(requesting_origin, embedding_origin); |
| 98 | 123 |
| 99 if (result.content_setting == CONTENT_SETTING_ALLOW || | 124 if (result.content_setting == CONTENT_SETTING_ALLOW || |
| 100 result.content_setting == CONTENT_SETTING_BLOCK) { | 125 result.content_setting == CONTENT_SETTING_BLOCK) { |
| 101 if (result.source == PermissionStatusSource::KILL_SWITCH) { | 126 if (result.source == PermissionStatusSource::KILL_SWITCH) { |
| 102 // Block the request and log to the developer console. | 127 // Block the request and log to the developer console. |
| 103 web_contents->GetMainFrame()->AddMessageToConsole( | 128 LogPermissionBlockedMessage(web_contents, |
| 104 content::CONSOLE_MESSAGE_LEVEL_INFO, | 129 kPermissionBlockedKillSwitchMessage, |
| 105 base::StringPrintf( | 130 content_settings_type_); |
| 106 "%s permission has been blocked.", | |
| 107 PermissionUtil::GetPermissionString(content_settings_type_) | |
| 108 .c_str())); | |
| 109 callback.Run(CONTENT_SETTING_BLOCK); | 131 callback.Run(CONTENT_SETTING_BLOCK); |
| 110 return; | 132 return; |
| 133 } else if (result.source == PermissionStatusSource::MULTIPLE_DISMISSALS) { |
| 134 LogPermissionBlockedMessage(web_contents, |
| 135 kPermissionBlockedRepeatedDismissalsMessage, |
| 136 content_settings_type_); |
| 111 } | 137 } |
| 112 | 138 |
| 113 // If we are under embargo, record the embargo reason for which we have | 139 // If we are under embargo, record the embargo reason for which we have |
| 114 // suppressed the prompt. | 140 // suppressed the prompt. |
| 115 PermissionUmaUtil::RecordEmbargoPromptSuppressionFromSource(result.source); | 141 PermissionUmaUtil::RecordEmbargoPromptSuppressionFromSource(result.source); |
| 116 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 142 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 117 false /* persist */, result.content_setting); | 143 false /* persist */, result.content_setting); |
| 118 return; | 144 return; |
| 119 } | 145 } |
| 120 | 146 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 132 void PermissionContextBase::ContinueRequestPermission( | 158 void PermissionContextBase::ContinueRequestPermission( |
| 133 content::WebContents* web_contents, | 159 content::WebContents* web_contents, |
| 134 const PermissionRequestID& id, | 160 const PermissionRequestID& id, |
| 135 const GURL& requesting_origin, | 161 const GURL& requesting_origin, |
| 136 const GURL& embedding_origin, | 162 const GURL& embedding_origin, |
| 137 bool user_gesture, | 163 bool user_gesture, |
| 138 const BrowserPermissionCallback& callback, | 164 const BrowserPermissionCallback& callback, |
| 139 bool permission_blocked) { | 165 bool permission_blocked) { |
| 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 141 if (permission_blocked) { | 167 if (permission_blocked) { |
| 142 web_contents->GetMainFrame()->AddMessageToConsole( | 168 LogPermissionBlockedMessage(web_contents, |
| 143 content::CONSOLE_MESSAGE_LEVEL_INFO, | 169 kPermissionBlockedBlacklistMessage, |
| 144 base::StringPrintf( | 170 content_settings_type_); |
| 145 "%s permission has been auto-blocked.", | |
| 146 PermissionUtil::GetPermissionString(content_settings_type_) | |
| 147 .c_str())); | |
| 148 // Permission has been automatically blocked. Record that the prompt was | 171 // Permission has been automatically blocked. Record that the prompt was |
| 149 // suppressed and that we hit the blacklist. | 172 // suppressed and that we hit the blacklist. |
| 150 PermissionUmaUtil::RecordEmbargoPromptSuppression( | 173 PermissionUmaUtil::RecordEmbargoPromptSuppression( |
| 151 PermissionEmbargoStatus::PERMISSIONS_BLACKLISTING); | 174 PermissionEmbargoStatus::PERMISSIONS_BLACKLISTING); |
| 152 PermissionUmaUtil::RecordEmbargoStatus( | 175 PermissionUmaUtil::RecordEmbargoStatus( |
| 153 PermissionEmbargoStatus::PERMISSIONS_BLACKLISTING); | 176 PermissionEmbargoStatus::PERMISSIONS_BLACKLISTING); |
| 154 callback.Run(CONTENT_SETTING_BLOCK); | 177 callback.Run(CONTENT_SETTING_BLOCK); |
| 155 return; | 178 return; |
| 156 } | 179 } |
| 157 | 180 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 content_settings_storage_type(), | 405 content_settings_storage_type(), |
| 383 std::string(), content_setting); | 406 std::string(), content_setting); |
| 384 } | 407 } |
| 385 | 408 |
| 386 ContentSettingsType PermissionContextBase::content_settings_storage_type() | 409 ContentSettingsType PermissionContextBase::content_settings_storage_type() |
| 387 const { | 410 const { |
| 388 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) | 411 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) |
| 389 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | 412 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
| 390 return content_settings_type_; | 413 return content_settings_type_; |
| 391 } | 414 } |
| OLD | NEW |