OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_manager.h" | 5 #include "chrome/browser/permissions/permission_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
9 #include "chrome/browser/permissions/permission_context.h" | 9 #include "chrome/browser/permissions/permission_context.h" |
10 #include "chrome/browser/permissions/permission_context_base.h" | 10 #include "chrome/browser/permissions/permission_context_base.h" |
| 11 #include "chrome/browser/permissions/permission_infobar_manager.h" |
11 #include "chrome/browser/permissions/permission_request_id.h" | 12 #include "chrome/browser/permissions/permission_request_id.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 14 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
15 #include "content/public/browser/permission_type.h" | 16 #include "content/public/browser/permission_type.h" |
16 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
19 | 20 |
20 using content::PermissionStatus; | 21 using content::PermissionStatus; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 154 } |
154 | 155 |
155 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 156 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
156 if (!context) { | 157 if (!context) { |
157 callback.Run(content::PERMISSION_STATUS_DENIED); | 158 callback.Run(content::PERMISSION_STATUS_DENIED); |
158 return; | 159 return; |
159 } | 160 } |
160 | 161 |
161 content::WebContents* web_contents = | 162 content::WebContents* web_contents = |
162 content::WebContents::FromRenderFrameHost(render_frame_host); | 163 content::WebContents::FromRenderFrameHost(render_frame_host); |
163 if (IsPermissionBubbleManagerMissing(web_contents)) { | 164 if (IsPermissionUIManagerMissing(web_contents)) { |
164 callback.Run( | 165 callback.Run( |
165 GetPermissionStatus(permission, requesting_origin, | 166 GetPermissionStatus(permission, requesting_origin, |
166 web_contents->GetLastCommittedURL().GetOrigin())); | 167 web_contents->GetLastCommittedURL().GetOrigin())); |
167 return; | 168 return; |
168 } | 169 } |
169 | 170 |
170 int render_process_id = render_frame_host->GetProcess()->GetID(); | 171 int render_process_id = render_frame_host->GetProcess()->GetID(); |
171 int render_frame_id = render_frame_host->GetRoutingID(); | 172 int render_frame_id = render_frame_host->GetRoutingID(); |
172 const PermissionRequestID request(render_process_id, | 173 const PermissionRequestID request(render_process_id, |
173 render_frame_id, | 174 render_frame_id, |
174 request_id); | 175 request_id); |
175 | 176 |
176 context->RequestPermission( | 177 context->RequestPermission( |
177 web_contents, request, requesting_origin, user_gesture, | 178 web_contents, request, requesting_origin, user_gesture, |
178 base::Bind(&PermissionStatusCallbackWrapper, callback)); | 179 base::Bind(&PermissionStatusCallbackWrapper, callback)); |
179 } | 180 } |
180 | 181 |
181 void PermissionManager::CancelPermissionRequest( | 182 void PermissionManager::CancelPermissionRequest( |
182 PermissionType permission, | 183 PermissionType permission, |
183 content::RenderFrameHost* render_frame_host, | 184 content::RenderFrameHost* render_frame_host, |
184 int request_id, | 185 int request_id, |
185 const GURL& requesting_origin) { | 186 const GURL& requesting_origin) { |
186 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 187 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
187 if (!context) | 188 if (!context) |
188 return; | 189 return; |
189 | 190 |
190 content::WebContents* web_contents = | 191 content::WebContents* web_contents = |
191 content::WebContents::FromRenderFrameHost(render_frame_host); | 192 content::WebContents::FromRenderFrameHost(render_frame_host); |
192 if (IsPermissionBubbleManagerMissing(web_contents)) | 193 if (IsPermissionUIManagerMissing(web_contents)) |
193 return; | 194 return; |
194 | 195 |
195 int render_process_id = render_frame_host->GetProcess()->GetID(); | 196 int render_process_id = render_frame_host->GetProcess()->GetID(); |
196 int render_frame_id = render_frame_host->GetRoutingID(); | 197 int render_frame_id = render_frame_host->GetRoutingID(); |
197 const PermissionRequestID request(render_process_id, | 198 const PermissionRequestID request(render_process_id, |
198 render_frame_id, | 199 render_frame_id, |
199 request_id); | 200 request_id); |
200 | 201 |
201 context->CancelPermissionRequest(web_contents, request); | 202 context->CancelPermissionRequest(web_contents, request); |
202 } | 203 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 270 |
270 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { | 271 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { |
271 // Whether |subscription_id| is known will be checked by the Remove() call. | 272 // Whether |subscription_id| is known will be checked by the Remove() call. |
272 subscriptions_.Remove(subscription_id); | 273 subscriptions_.Remove(subscription_id); |
273 | 274 |
274 if (subscriptions_.IsEmpty()) | 275 if (subscriptions_.IsEmpty()) |
275 HostContentSettingsMapFactory::GetForProfile(profile_) | 276 HostContentSettingsMapFactory::GetForProfile(profile_) |
276 ->RemoveObserver(this); | 277 ->RemoveObserver(this); |
277 } | 278 } |
278 | 279 |
279 bool PermissionManager::IsPermissionBubbleManagerMissing( | 280 bool PermissionManager::IsPermissionUIManagerMissing( |
280 content::WebContents* web_contents) { | 281 content::WebContents* web_contents) { |
281 // Can't be missing if it isn't needed to begin with. | 282 if (PermissionBubbleManager::Enabled()) |
282 if (!PermissionBubbleManager::Enabled()) | 283 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; |
283 return false; | |
284 | 284 |
285 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; | 285 // Consider PermissionInfoBarManager's state instead |
| 286 return PermissionInfoBarManager::FromWebContents(web_contents) == nullptr; |
286 } | 287 } |
287 | 288 |
288 void PermissionManager::OnContentSettingChanged( | 289 void PermissionManager::OnContentSettingChanged( |
289 const ContentSettingsPattern& primary_pattern, | 290 const ContentSettingsPattern& primary_pattern, |
290 const ContentSettingsPattern& secondary_pattern, | 291 const ContentSettingsPattern& secondary_pattern, |
291 ContentSettingsType content_type, | 292 ContentSettingsType content_type, |
292 std::string resource_identifier) { | 293 std::string resource_identifier) { |
293 std::list<base::Closure> callbacks; | 294 std::list<base::Closure> callbacks; |
294 | 295 |
295 for (SubscriptionsMap::iterator iter(&subscriptions_); | 296 for (SubscriptionsMap::iterator iter(&subscriptions_); |
(...skipping 23 matching lines...) Expand all Loading... |
319 // Add the callback to |callbacks| which will be run after the loop to | 320 // Add the callback to |callbacks| which will be run after the loop to |
320 // prevent re-entrance issues. | 321 // prevent re-entrance issues. |
321 callbacks.push_back( | 322 callbacks.push_back( |
322 base::Bind(subscription->callback, | 323 base::Bind(subscription->callback, |
323 ContentSettingToPermissionStatus(new_value))); | 324 ContentSettingToPermissionStatus(new_value))); |
324 } | 325 } |
325 | 326 |
326 for (const auto& callback : callbacks) | 327 for (const auto& callback : callbacks) |
327 callback.Run(); | 328 callback.Run(); |
328 } | 329 } |
OLD | NEW |