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 GURL requesting_origin = requesting_frame.GetOrigin(); |
| 75 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
| 76 |
| 77 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { |
| 78 std::string type_name = |
| 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( |
| 113 permission_type_, requesting_origin, embedding_origin, profile_); |
| 114 |
74 DecidePermission(web_contents, | 115 DecidePermission(web_contents, |
75 id, | 116 id, |
76 requesting_frame.GetOrigin(), | 117 requesting_origin, |
77 web_contents->GetLastCommittedURL().GetOrigin(), | 118 embedding_origin, |
78 user_gesture, | 119 user_gesture, |
79 callback); | 120 callback); |
80 } | 121 } |
81 | 122 |
82 ContentSetting PermissionContextBase::GetPermissionStatus( | 123 ContentSetting PermissionContextBase::GetPermissionStatus( |
83 const GURL& requesting_origin, | 124 const GURL& requesting_origin, |
84 const GURL& embedding_origin) const { | 125 const GURL& embedding_origin) const { |
85 | 126 |
86 // If the permission has been disabled through Finch, block all requests. | 127 // If the permission has been disabled through Finch, block all requests. |
87 if (IsPermissionKillSwitchOn()) | 128 if (IsPermissionKillSwitchOn()) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 168 |
128 void PermissionContextBase::DecidePermission( | 169 void PermissionContextBase::DecidePermission( |
129 content::WebContents* web_contents, | 170 content::WebContents* web_contents, |
130 const PermissionRequestID& id, | 171 const PermissionRequestID& id, |
131 const GURL& requesting_origin, | 172 const GURL& requesting_origin, |
132 const GURL& embedding_origin, | 173 const GURL& embedding_origin, |
133 bool user_gesture, | 174 bool user_gesture, |
134 const BrowserPermissionCallback& callback) { | 175 const BrowserPermissionCallback& callback) { |
135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
136 | 177 |
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) | 178 #if !defined(OS_ANDROID) |
176 PermissionBubbleManager* bubble_manager = | 179 PermissionBubbleManager* bubble_manager = |
177 PermissionBubbleManager::FromWebContents(web_contents); | 180 PermissionBubbleManager::FromWebContents(web_contents); |
178 // TODO(felt): sometimes |bubble_manager| is null. This check is meant to | 181 // TODO(felt): sometimes |bubble_manager| is null. This check is meant to |
179 // prevent crashes. See crbug.com/457091. | 182 // prevent crashes. See crbug.com/457091. |
180 if (!bubble_manager) | 183 if (!bubble_manager) |
181 return; | 184 return; |
182 scoped_ptr<PermissionBubbleRequest> request_ptr( | 185 scoped_ptr<PermissionBubbleRequest> request_ptr( |
183 new PermissionBubbleRequestImpl( | 186 new PermissionBubbleRequestImpl( |
184 requesting_origin, user_gesture, permission_type_, | 187 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); | 291 permission_type_, std::string(), content_setting); |
289 } | 292 } |
290 | 293 |
291 bool PermissionContextBase::IsPermissionKillSwitchOn() const { | 294 bool PermissionContextBase::IsPermissionKillSwitchOn() const { |
292 const std::string param = | 295 const std::string param = |
293 variations::GetVariationParamValue(kPermissionsKillSwitchFieldStudy, | 296 variations::GetVariationParamValue(kPermissionsKillSwitchFieldStudy, |
294 PermissionUtil::GetPermissionString(permission_type_)); | 297 PermissionUtil::GetPermissionString(permission_type_)); |
295 | 298 |
296 return param == kPermissionsKillSwitchBlockedValue; | 299 return param == kPermissionsKillSwitchBlockedValue; |
297 } | 300 } |
OLD | NEW |