| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 const char kPermissionBlockedKillSwitchMessage[] = | 47 const char kPermissionBlockedKillSwitchMessage[] = |
| 48 "%s permission has been blocked."; | 48 "%s permission has been blocked."; |
| 49 | 49 |
| 50 const char kPermissionBlockedRepeatedDismissalsMessage[] = | 50 const char kPermissionBlockedRepeatedDismissalsMessage[] = |
| 51 "%s permission has been blocked as the user has dismissed the permission " | 51 "%s permission has been blocked as the user has dismissed the permission " |
| 52 "prompt several times. See " | 52 "prompt several times. See " |
| 53 "https://www.chromestatus.com/features/6443143280984064 for more " | 53 "https://www.chromestatus.com/features/6443143280984064 for more " |
| 54 "information."; | 54 "information."; |
| 55 | 55 |
| 56 const char kPermissionBlockedRepeatedIgnoresMessage[] = |
| 57 "%s permission has been blocked as the user has ignored the permission " |
| 58 "prompt several times. See " |
| 59 "https://www.chromestatus.com/features/6443143280984064 for more " |
| 60 "information."; |
| 61 |
| 56 const char kPermissionBlockedBlacklistMessage[] = | 62 const char kPermissionBlockedBlacklistMessage[] = |
| 57 "this origin is not allowed to request %s permission."; | 63 "this origin is not allowed to request %s permission."; |
| 58 | 64 |
| 59 void LogPermissionBlockedMessage(content::WebContents* web_contents, | 65 void LogPermissionBlockedMessage(content::WebContents* web_contents, |
| 60 const char* message, | 66 const char* message, |
| 61 ContentSettingsType type) { | 67 ContentSettingsType type) { |
| 62 web_contents->GetMainFrame()->AddMessageToConsole( | 68 web_contents->GetMainFrame()->AddMessageToConsole( |
| 63 content::CONSOLE_MESSAGE_LEVEL_INFO, | 69 content::CONSOLE_MESSAGE_LEVEL_INFO, |
| 64 base::StringPrintf(message, | 70 base::StringPrintf(message, |
| 65 PermissionUtil::GetPermissionString(type).c_str())); | 71 PermissionUtil::GetPermissionString(type).c_str())); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 123 |
| 118 // Synchronously check the content setting to see if the user has already made | 124 // Synchronously check the content setting to see if the user has already made |
| 119 // a decision, or if the origin is under embargo. If so, respect that | 125 // a decision, or if the origin is under embargo. If so, respect that |
| 120 // decision. | 126 // decision. |
| 121 // TODO(raymes): Pass in the RenderFrameHost of the request here. | 127 // TODO(raymes): Pass in the RenderFrameHost of the request here. |
| 122 PermissionResult result = GetPermissionStatus( | 128 PermissionResult result = GetPermissionStatus( |
| 123 nullptr /* render_frame_host */, requesting_origin, embedding_origin); | 129 nullptr /* render_frame_host */, requesting_origin, embedding_origin); |
| 124 | 130 |
| 125 if (result.content_setting == CONTENT_SETTING_ALLOW || | 131 if (result.content_setting == CONTENT_SETTING_ALLOW || |
| 126 result.content_setting == CONTENT_SETTING_BLOCK) { | 132 result.content_setting == CONTENT_SETTING_BLOCK) { |
| 127 if (result.source == PermissionStatusSource::KILL_SWITCH) { | 133 switch (result.source) { |
| 128 // Block the request and log to the developer console. | 134 case PermissionStatusSource::KILL_SWITCH: |
| 129 LogPermissionBlockedMessage(web_contents, | 135 // Block the request and log to the developer console. |
| 130 kPermissionBlockedKillSwitchMessage, | 136 LogPermissionBlockedMessage(web_contents, |
| 131 content_settings_type_); | 137 kPermissionBlockedKillSwitchMessage, |
| 132 callback.Run(CONTENT_SETTING_BLOCK); | 138 content_settings_type_); |
| 133 return; | 139 callback.Run(CONTENT_SETTING_BLOCK); |
| 134 } else if (result.source == PermissionStatusSource::MULTIPLE_DISMISSALS) { | 140 return; |
| 135 LogPermissionBlockedMessage(web_contents, | 141 case PermissionStatusSource::MULTIPLE_DISMISSALS: |
| 136 kPermissionBlockedRepeatedDismissalsMessage, | 142 LogPermissionBlockedMessage(web_contents, |
| 137 content_settings_type_); | 143 kPermissionBlockedRepeatedDismissalsMessage, |
| 144 content_settings_type_); |
| 145 break; |
| 146 case PermissionStatusSource::MULTIPLE_IGNORES: |
| 147 LogPermissionBlockedMessage(web_contents, |
| 148 kPermissionBlockedRepeatedIgnoresMessage, |
| 149 content_settings_type_); |
| 150 break; |
| 151 case PermissionStatusSource::SAFE_BROWSING_BLACKLIST: |
| 152 LogPermissionBlockedMessage(web_contents, |
| 153 kPermissionBlockedBlacklistMessage, |
| 154 content_settings_type_); |
| 155 break; |
| 156 case PermissionStatusSource::UNSPECIFIED: |
| 157 break; |
| 138 } | 158 } |
| 139 | 159 |
| 140 // If we are under embargo, record the embargo reason for which we have | 160 // If we are under embargo, record the embargo reason for which we have |
| 141 // suppressed the prompt. | 161 // suppressed the prompt. |
| 142 PermissionUmaUtil::RecordEmbargoPromptSuppressionFromSource(result.source); | 162 PermissionUmaUtil::RecordEmbargoPromptSuppressionFromSource(result.source); |
| 143 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 163 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 144 false /* persist */, result.content_setting); | 164 false /* persist */, result.content_setting); |
| 145 return; | 165 return; |
| 146 } | 166 } |
| 147 | 167 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 content_settings_storage_type(), | 443 content_settings_storage_type(), |
| 424 std::string(), content_setting); | 444 std::string(), content_setting); |
| 425 } | 445 } |
| 426 | 446 |
| 427 ContentSettingsType PermissionContextBase::content_settings_storage_type() | 447 ContentSettingsType PermissionContextBase::content_settings_storage_type() |
| 428 const { | 448 const { |
| 429 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) | 449 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) |
| 430 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | 450 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
| 431 return content_settings_type_; | 451 return content_settings_type_; |
| 432 } | 452 } |
| OLD | NEW |