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/tab_contents/tab_util.h" | 14 #include "chrome/browser/tab_contents/tab_util.h" |
14 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
15 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
16 #include "content/public/browser/permission_type.h" | 17 #include "content/public/browser/permission_type.h" |
17 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 | 21 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 160 } |
160 | 161 |
161 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 162 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
162 if (!context) { | 163 if (!context) { |
163 callback.Run(content::PERMISSION_STATUS_DENIED); | 164 callback.Run(content::PERMISSION_STATUS_DENIED); |
164 return kNoPendingOperation; | 165 return kNoPendingOperation; |
165 } | 166 } |
166 | 167 |
167 content::WebContents* web_contents = | 168 content::WebContents* web_contents = |
168 content::WebContents::FromRenderFrameHost(render_frame_host); | 169 content::WebContents::FromRenderFrameHost(render_frame_host); |
169 if (IsPermissionBubbleManagerMissing(web_contents)) { | 170 if (IsPermissionUIManagerMissing(web_contents)) { |
170 callback.Run( | 171 callback.Run( |
171 GetPermissionStatus(permission, requesting_origin, | 172 GetPermissionStatus(permission, requesting_origin, |
172 web_contents->GetLastCommittedURL().GetOrigin())); | 173 web_contents->GetLastCommittedURL().GetOrigin())); |
173 return kNoPendingOperation; | 174 return kNoPendingOperation; |
174 } | 175 } |
175 | 176 |
176 PendingRequest* pending_request = new PendingRequest( | 177 PendingRequest* pending_request = new PendingRequest( |
177 permission, render_frame_host); | 178 permission, render_frame_host); |
178 int request_id = pending_requests_.Add(pending_request); | 179 int request_id = pending_requests_.Add(pending_request); |
179 const PermissionRequestID request(pending_request->render_process_id, | 180 const PermissionRequestID request(pending_request->render_process_id, |
(...skipping 25 matching lines...) Expand all Loading... |
205 PendingRequest* pending_request = pending_requests_.Lookup(request_id); | 206 PendingRequest* pending_request = pending_requests_.Lookup(request_id); |
206 if (!pending_request) | 207 if (!pending_request) |
207 return; | 208 return; |
208 | 209 |
209 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 210 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
210 if (!context) | 211 if (!context) |
211 return; | 212 return; |
212 | 213 |
213 content::WebContents* web_contents = | 214 content::WebContents* web_contents = |
214 content::WebContents::FromRenderFrameHost(render_frame_host); | 215 content::WebContents::FromRenderFrameHost(render_frame_host); |
215 if (IsPermissionBubbleManagerMissing(web_contents)) | 216 if (IsPermissionUIManagerMissing(web_contents)) |
216 return; | 217 return; |
217 | 218 |
218 int render_process_id = render_frame_host->GetProcess()->GetID(); | 219 int render_process_id = render_frame_host->GetProcess()->GetID(); |
219 int render_frame_id = render_frame_host->GetRoutingID(); | 220 int render_frame_id = render_frame_host->GetRoutingID(); |
220 const PermissionRequestID request(render_process_id, | 221 const PermissionRequestID request(render_process_id, |
221 render_frame_id, | 222 render_frame_id, |
222 request_id); | 223 request_id); |
223 | 224 |
224 context->CancelPermissionRequest(web_contents, request); | 225 context->CancelPermissionRequest(web_contents, request); |
225 pending_requests_.Remove(request_id); | 226 pending_requests_.Remove(request_id); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 294 |
294 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { | 295 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { |
295 // Whether |subscription_id| is known will be checked by the Remove() call. | 296 // Whether |subscription_id| is known will be checked by the Remove() call. |
296 subscriptions_.Remove(subscription_id); | 297 subscriptions_.Remove(subscription_id); |
297 | 298 |
298 if (subscriptions_.IsEmpty()) | 299 if (subscriptions_.IsEmpty()) |
299 HostContentSettingsMapFactory::GetForProfile(profile_) | 300 HostContentSettingsMapFactory::GetForProfile(profile_) |
300 ->RemoveObserver(this); | 301 ->RemoveObserver(this); |
301 } | 302 } |
302 | 303 |
303 bool PermissionManager::IsPermissionBubbleManagerMissing( | 304 bool PermissionManager::IsPermissionUIManagerMissing( |
304 content::WebContents* web_contents) { | 305 content::WebContents* web_contents) { |
305 // Can't be missing if it isn't needed to begin with. | 306 if (PermissionBubbleManager::Enabled()) |
306 if (!PermissionBubbleManager::Enabled()) | 307 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; |
307 return false; | |
308 | 308 |
309 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; | 309 // Consider PermissionInfoBarManager's state instead |
| 310 return PermissionInfoBarManager::FromWebContents(web_contents) == nullptr; |
310 } | 311 } |
311 | 312 |
312 void PermissionManager::OnContentSettingChanged( | 313 void PermissionManager::OnContentSettingChanged( |
313 const ContentSettingsPattern& primary_pattern, | 314 const ContentSettingsPattern& primary_pattern, |
314 const ContentSettingsPattern& secondary_pattern, | 315 const ContentSettingsPattern& secondary_pattern, |
315 ContentSettingsType content_type, | 316 ContentSettingsType content_type, |
316 std::string resource_identifier) { | 317 std::string resource_identifier) { |
317 std::list<base::Closure> callbacks; | 318 std::list<base::Closure> callbacks; |
318 | 319 |
319 for (SubscriptionsMap::iterator iter(&subscriptions_); | 320 for (SubscriptionsMap::iterator iter(&subscriptions_); |
(...skipping 23 matching lines...) Expand all Loading... |
343 // Add the callback to |callbacks| which will be run after the loop to | 344 // Add the callback to |callbacks| which will be run after the loop to |
344 // prevent re-entrance issues. | 345 // prevent re-entrance issues. |
345 callbacks.push_back( | 346 callbacks.push_back( |
346 base::Bind(subscription->callback, | 347 base::Bind(subscription->callback, |
347 ContentSettingToPermissionStatus(new_value))); | 348 ContentSettingToPermissionStatus(new_value))); |
348 } | 349 } |
349 | 350 |
350 for (const auto& callback : callbacks) | 351 for (const auto& callback : callbacks) |
351 callback.Run(); | 352 callback.Run(); |
352 } | 353 } |
OLD | NEW |