| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Log to the developer console. | 64 // Log to the developer console. |
| 65 web_contents->GetMainFrame()->AddMessageToConsole( | 65 web_contents->GetMainFrame()->AddMessageToConsole( |
| 66 content::CONSOLE_MESSAGE_LEVEL_LOG, | 66 content::CONSOLE_MESSAGE_LEVEL_LOG, |
| 67 base::StringPrintf("%s permission has been blocked.", | 67 base::StringPrintf("%s permission has been blocked.", |
| 68 PermissionUtil::GetPermissionString(permission_type_).c_str())); | 68 PermissionUtil::GetPermissionString(permission_type_).c_str())); |
| 69 // The kill switch is enabled for this permission; Block all requests. | 69 // The kill switch is enabled for this permission; Block all requests. |
| 70 callback.Run(CONTENT_SETTING_BLOCK); | 70 callback.Run(CONTENT_SETTING_BLOCK); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 DecidePermission(web_contents, | 74 GURL requesting_origin = requesting_frame.GetOrigin(); |
| 75 id, | 75 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
| 76 requesting_frame.GetOrigin(), | 76 |
| 77 web_contents->GetLastCommittedURL().GetOrigin(), | 77 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { |
| 78 user_gesture, | 78 std::string type_name = |
| 79 callback); | 79 content_settings::WebsiteSettingsRegistry::GetInstance() |
| 80 ->Get(permission_type_) |
| 81 ->name(); |
| 82 |
| 83 DVLOG(1) << "Attempt to use " << type_name |
| 84 << " from an invalid URL: " << requesting_origin << "," |
| 85 << embedding_origin << " (" << type_name |
| 86 << " is not supported in popups)"; |
| 87 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 88 false /* persist */, CONTENT_SETTING_BLOCK); |
| 89 return; |
| 90 } |
| 91 |
| 92 if (IsRestrictedToSecureOrigins() && |
| 93 !content::IsOriginSecure(requesting_origin)) { |
| 94 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 95 false /* persist */, CONTENT_SETTING_BLOCK); |
| 96 return; |
| 97 } |
| 98 |
| 99 ContentSetting content_setting = |
| 100 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 101 ->GetContentSettingAndMaybeUpdateLastUsage( |
| 102 requesting_origin, embedding_origin, permission_type_, |
| 103 std::string()); |
| 104 |
| 105 if (content_setting == CONTENT_SETTING_ALLOW || |
| 106 content_setting == CONTENT_SETTING_BLOCK) { |
| 107 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 108 false /* persist */, content_setting); |
| 109 return; |
| 110 } |
| 111 |
| 112 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, |
| 113 embedding_origin, profile_); |
| 114 |
| 115 DecidePermission(web_contents, id, requesting_origin, embedding_origin, |
| 116 user_gesture, callback); |
| 80 } | 117 } |
| 81 | 118 |
| 82 ContentSetting PermissionContextBase::GetPermissionStatus( | 119 ContentSetting PermissionContextBase::GetPermissionStatus( |
| 83 const GURL& requesting_origin, | 120 const GURL& requesting_origin, |
| 84 const GURL& embedding_origin) const { | 121 const GURL& embedding_origin) const { |
| 85 | 122 |
| 86 // If the permission has been disabled through Finch, block all requests. | 123 // If the permission has been disabled through Finch, block all requests. |
| 87 if (IsPermissionKillSwitchOn()) | 124 if (IsPermissionKillSwitchOn()) |
| 88 return CONTENT_SETTING_BLOCK; | 125 return CONTENT_SETTING_BLOCK; |
| 89 | 126 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 164 |
| 128 void PermissionContextBase::DecidePermission( | 165 void PermissionContextBase::DecidePermission( |
| 129 content::WebContents* web_contents, | 166 content::WebContents* web_contents, |
| 130 const PermissionRequestID& id, | 167 const PermissionRequestID& id, |
| 131 const GURL& requesting_origin, | 168 const GURL& requesting_origin, |
| 132 const GURL& embedding_origin, | 169 const GURL& embedding_origin, |
| 133 bool user_gesture, | 170 bool user_gesture, |
| 134 const BrowserPermissionCallback& callback) { | 171 const BrowserPermissionCallback& callback) { |
| 135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 172 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 136 | 173 |
| 137 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { | |
| 138 std::string type_name = | |
| 139 content_settings::WebsiteSettingsRegistry::GetInstance() | |
| 140 ->Get(permission_type_) | |
| 141 ->name(); | |
| 142 | |
| 143 DVLOG(1) << "Attempt to use " << type_name | |
| 144 << " from an invalid URL: " << requesting_origin << "," | |
| 145 << embedding_origin << " (" << type_name | |
| 146 << " is not supported in popups)"; | |
| 147 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 148 false /* persist */, CONTENT_SETTING_BLOCK); | |
| 149 return; | |
| 150 } | |
| 151 | |
| 152 if (IsRestrictedToSecureOrigins() && | |
| 153 !content::IsOriginSecure(requesting_origin)) { | |
| 154 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 155 false /* persist */, CONTENT_SETTING_BLOCK); | |
| 156 return; | |
| 157 } | |
| 158 | |
| 159 ContentSetting content_setting = | |
| 160 HostContentSettingsMapFactory::GetForProfile(profile_) | |
| 161 ->GetContentSettingAndMaybeUpdateLastUsage( | |
| 162 requesting_origin, embedding_origin, permission_type_, | |
| 163 std::string()); | |
| 164 | |
| 165 if (content_setting == CONTENT_SETTING_ALLOW || | |
| 166 content_setting == CONTENT_SETTING_BLOCK) { | |
| 167 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 168 false /* persist */, content_setting); | |
| 169 return; | |
| 170 } | |
| 171 | |
| 172 PermissionUmaUtil::PermissionRequested( | |
| 173 permission_type_, requesting_origin, embedding_origin, profile_); | |
| 174 | |
| 175 #if !defined(OS_ANDROID) | 174 #if !defined(OS_ANDROID) |
| 176 PermissionBubbleManager* bubble_manager = | 175 PermissionBubbleManager* bubble_manager = |
| 177 PermissionBubbleManager::FromWebContents(web_contents); | 176 PermissionBubbleManager::FromWebContents(web_contents); |
| 178 // TODO(felt): sometimes |bubble_manager| is null. This check is meant to | 177 // TODO(felt): sometimes |bubble_manager| is null. This check is meant to |
| 179 // prevent crashes. See crbug.com/457091. | 178 // prevent crashes. See crbug.com/457091. |
| 180 if (!bubble_manager) | 179 if (!bubble_manager) |
| 181 return; | 180 return; |
| 182 scoped_ptr<PermissionBubbleRequest> request_ptr( | 181 scoped_ptr<PermissionBubbleRequest> request_ptr( |
| 183 new PermissionBubbleRequestImpl( | 182 new PermissionBubbleRequestImpl( |
| 184 requesting_origin, user_gesture, permission_type_, | 183 requesting_origin, user_gesture, permission_type_, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 permission_type_, std::string(), content_setting); | 287 permission_type_, std::string(), content_setting); |
| 289 } | 288 } |
| 290 | 289 |
| 291 bool PermissionContextBase::IsPermissionKillSwitchOn() const { | 290 bool PermissionContextBase::IsPermissionKillSwitchOn() const { |
| 292 const std::string param = | 291 const std::string param = |
| 293 variations::GetVariationParamValue(kPermissionsKillSwitchFieldStudy, | 292 variations::GetVariationParamValue(kPermissionsKillSwitchFieldStudy, |
| 294 PermissionUtil::GetPermissionString(permission_type_)); | 293 PermissionUtil::GetPermissionString(permission_type_)); |
| 295 | 294 |
| 296 return param == kPermissionsKillSwitchBlockedValue; | 295 return param == kPermissionsKillSwitchBlockedValue; |
| 297 } | 296 } |
| OLD | NEW |