| 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 "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 #if !defined(OS_ANDROID) | 21 #if !defined(OS_ANDROID) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 PendingRequest* pending_request = new PendingRequest( | 236 PendingRequest* pending_request = new PendingRequest( |
| 236 render_frame_host, permissions, callback); | 237 render_frame_host, permissions, callback); |
| 237 int request_id = pending_requests_.Add(pending_request); | 238 int request_id = pending_requests_.Add(pending_request); |
| 238 | 239 |
| 239 const PermissionRequestID request(render_frame_host, request_id); | 240 const PermissionRequestID request(render_frame_host, request_id); |
| 240 | 241 |
| 241 for (size_t i = 0; i < permissions.size(); ++i) { | 242 for (size_t i = 0; i < permissions.size(); ++i) { |
| 242 const PermissionType permission = permissions[i]; | 243 const PermissionType permission = permissions[i]; |
| 243 | 244 |
| 244 if (IsConstantPermission(permission) || | 245 if (IsConstantPermission(permission) || |
| 245 IsPermissionBubbleManagerMissing(web_contents) || | 246 IsPermissionUIManagerMissing(web_contents) || |
| 246 !PermissionContext::Get(profile_, permission)) { | 247 !PermissionContext::Get(profile_, permission)) { |
| 247 OnPermissionsRequestResponseStatus(request_id, i, | 248 OnPermissionsRequestResponseStatus(request_id, i, |
| 248 GetPermissionStatus(permission, requesting_origin, embedding_origin)); | 249 GetPermissionStatus(permission, requesting_origin, embedding_origin)); |
| 249 continue; | 250 continue; |
| 250 } | 251 } |
| 251 | 252 |
| 252 PermissionContextBase* context = PermissionContext::Get( | 253 PermissionContextBase* context = PermissionContext::Get( |
| 253 profile_, permission); | 254 profile_, permission); |
| 254 context->RequestPermission( | 255 context->RequestPermission( |
| 255 web_contents, request, requesting_origin, user_gesture, | 256 web_contents, request, requesting_origin, user_gesture, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 280 } | 281 } |
| 281 | 282 |
| 282 void PermissionManager::CancelPermissionRequest(int request_id) { | 283 void PermissionManager::CancelPermissionRequest(int request_id) { |
| 283 PendingRequest* pending_request = pending_requests_.Lookup(request_id); | 284 PendingRequest* pending_request = pending_requests_.Lookup(request_id); |
| 284 if (!pending_request) | 285 if (!pending_request) |
| 285 return; | 286 return; |
| 286 | 287 |
| 287 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( | 288 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( |
| 288 pending_request->render_process_id(), pending_request->render_frame_id()); | 289 pending_request->render_process_id(), pending_request->render_frame_id()); |
| 289 DCHECK(web_contents); | 290 DCHECK(web_contents); |
| 290 if (IsPermissionBubbleManagerMissing(web_contents)) { | 291 if (IsPermissionUIManagerMissing(web_contents)) { |
| 291 pending_requests_.Remove(request_id); | 292 pending_requests_.Remove(request_id); |
| 292 return; | 293 return; |
| 293 } | 294 } |
| 294 | 295 |
| 295 const PermissionRequestID request(pending_request->render_process_id(), | 296 const PermissionRequestID request(pending_request->render_process_id(), |
| 296 pending_request->render_frame_id(), | 297 pending_request->render_frame_id(), |
| 297 request_id); | 298 request_id); |
| 298 for (PermissionType permission : pending_request->permissions()) { | 299 for (PermissionType permission : pending_request->permissions()) { |
| 299 PermissionContextBase* context = PermissionContext::Get( | 300 PermissionContextBase* context = PermissionContext::Get( |
| 300 profile_, permission); | 301 profile_, permission); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 374 |
| 374 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { | 375 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { |
| 375 // Whether |subscription_id| is known will be checked by the Remove() call. | 376 // Whether |subscription_id| is known will be checked by the Remove() call. |
| 376 subscriptions_.Remove(subscription_id); | 377 subscriptions_.Remove(subscription_id); |
| 377 | 378 |
| 378 if (subscriptions_.IsEmpty()) | 379 if (subscriptions_.IsEmpty()) |
| 379 HostContentSettingsMapFactory::GetForProfile(profile_) | 380 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 380 ->RemoveObserver(this); | 381 ->RemoveObserver(this); |
| 381 } | 382 } |
| 382 | 383 |
| 383 bool PermissionManager::IsPermissionBubbleManagerMissing( | 384 bool PermissionManager::IsPermissionUIManagerMissing( |
| 384 content::WebContents* web_contents) { | 385 content::WebContents* web_contents) { |
| 385 // TODO(felt): Remove this method entirely. Leaving it to make a minimal | 386 // TODO(felt): Remove this method entirely. Leaving it to make a minimal |
| 386 // last-minute merge to 46. See crbug.com/457091 and crbug.com/534631. | 387 // last-minute merge to 46. See crbug.com/457091 and crbug.com/534631. |
| 387 return false; | 388 return false; |
| 388 } | 389 } |
| 389 | 390 |
| 390 void PermissionManager::OnContentSettingChanged( | 391 void PermissionManager::OnContentSettingChanged( |
| 391 const ContentSettingsPattern& primary_pattern, | 392 const ContentSettingsPattern& primary_pattern, |
| 392 const ContentSettingsPattern& secondary_pattern, | 393 const ContentSettingsPattern& secondary_pattern, |
| 393 ContentSettingsType content_type, | 394 ContentSettingsType content_type, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 421 // Add the callback to |callbacks| which will be run after the loop to | 422 // Add the callback to |callbacks| which will be run after the loop to |
| 422 // prevent re-entrance issues. | 423 // prevent re-entrance issues. |
| 423 callbacks.push_back( | 424 callbacks.push_back( |
| 424 base::Bind(subscription->callback, | 425 base::Bind(subscription->callback, |
| 425 ContentSettingToPermissionStatus(new_value))); | 426 ContentSettingToPermissionStatus(new_value))); |
| 426 } | 427 } |
| 427 | 428 |
| 428 for (const auto& callback : callbacks) | 429 for (const auto& callback : callbacks) |
| 429 callback.Run(); | 430 callback.Run(); |
| 430 } | 431 } |
| OLD | NEW |