| 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/permission_context_base.h" | 8 #include "chrome/browser/content_settings/permission_context_base.h" |
| 9 #include "chrome/browser/permissions/permission_context.h" | 9 #include "chrome/browser/permissions/permission_context.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 12 #include "components/content_settings/core/common/permission_request_id.h" | 12 #include "components/content_settings/core/common/permission_request_id.h" |
| 13 #include "content/public/browser/permission_type.h" | 13 #include "content/public/browser/permission_type.h" |
| 14 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_view_host.h" | |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 | 17 |
| 18 using content::PermissionStatus; | 18 using content::PermissionStatus; |
| 19 using content::PermissionType; | 19 using content::PermissionType; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Helper method to convert ContentSetting to PermissionStatus. | 23 // Helper method to convert ContentSetting to PermissionStatus. |
| 24 PermissionStatus ContentSettingToPermissionStatus(ContentSetting setting) { | 24 PermissionStatus ContentSettingToPermissionStatus(ContentSetting setting) { |
| 25 switch (setting) { | 25 switch (setting) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 : profile_(profile) { | 90 : profile_(profile) { |
| 91 } | 91 } |
| 92 | 92 |
| 93 PermissionManager::~PermissionManager() { | 93 PermissionManager::~PermissionManager() { |
| 94 if (!subscriptions_.IsEmpty()) | 94 if (!subscriptions_.IsEmpty()) |
| 95 profile_->GetHostContentSettingsMap()->RemoveObserver(this); | 95 profile_->GetHostContentSettingsMap()->RemoveObserver(this); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void PermissionManager::RequestPermission( | 98 void PermissionManager::RequestPermission( |
| 99 PermissionType permission, | 99 PermissionType permission, |
| 100 content::WebContents* web_contents, | 100 content::RenderFrameHost* render_frame_host, |
| 101 int request_id, | 101 int request_id, |
| 102 const GURL& requesting_origin, | 102 const GURL& requesting_origin, |
| 103 bool user_gesture, | 103 bool user_gesture, |
| 104 const base::Callback<void(PermissionStatus)>& callback) { | 104 const base::Callback<void(PermissionStatus)>& callback) { |
| 105 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 105 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
| 106 if (!context) { | 106 if (!context) { |
| 107 callback.Run(content::PERMISSION_STATUS_DENIED); | 107 callback.Run(content::PERMISSION_STATUS_DENIED); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 | 110 |
| 111 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 111 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 112 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 112 int render_frame_id = render_frame_host->GetRoutingID(); |
| 113 const PermissionRequestID request(render_process_id, | 113 const PermissionRequestID request(render_process_id, |
| 114 render_view_id, | 114 render_frame_id, |
| 115 request_id, | 115 request_id, |
| 116 requesting_origin); | 116 requesting_origin); |
| 117 | 117 |
| 118 context->RequestPermission(web_contents, request, requesting_origin, | 118 context->RequestPermission( |
| 119 user_gesture, | 119 content::WebContents::FromRenderFrameHost(render_frame_host), |
| 120 base::Bind(&PermissionStatusCallbackWrapper, | 120 request, requesting_origin, user_gesture, |
| 121 callback)); | 121 base::Bind(&PermissionStatusCallbackWrapper, |
| 122 callback)); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void PermissionManager::CancelPermissionRequest( | 125 void PermissionManager::CancelPermissionRequest( |
| 125 PermissionType permission, | 126 PermissionType permission, |
| 126 content::WebContents* web_contents, | 127 content::RenderFrameHost* render_frame_host, |
| 127 int request_id, | 128 int request_id, |
| 128 const GURL& requesting_origin) { | 129 const GURL& requesting_origin) { |
| 129 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 130 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
| 130 if (!context) | 131 if (!context) |
| 131 return; | 132 return; |
| 132 | 133 |
| 133 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 134 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 134 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 135 int render_frame_id = render_frame_host->GetRoutingID(); |
| 135 const PermissionRequestID request(render_process_id, | 136 const PermissionRequestID request(render_process_id, |
| 136 render_view_id, | 137 render_frame_id, |
| 137 request_id, | 138 request_id, |
| 138 requesting_origin); | 139 requesting_origin); |
| 139 | 140 |
| 140 context->CancelPermissionRequest(web_contents, request); | 141 context->CancelPermissionRequest( |
| 142 content::WebContents::FromRenderFrameHost(render_frame_host), request); |
| 141 } | 143 } |
| 142 | 144 |
| 143 void PermissionManager::ResetPermission(PermissionType permission, | 145 void PermissionManager::ResetPermission(PermissionType permission, |
| 144 const GURL& requesting_origin, | 146 const GURL& requesting_origin, |
| 145 const GURL& embedding_origin) { | 147 const GURL& embedding_origin) { |
| 146 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 148 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
| 147 if (!context) | 149 if (!context) |
| 148 return; | 150 return; |
| 149 | 151 |
| 150 context->ResetPermission(requesting_origin.GetOrigin(), | 152 context->ResetPermission(requesting_origin.GetOrigin(), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Add the callback to |callbacks| which will be run after the loop to | 237 // Add the callback to |callbacks| which will be run after the loop to |
| 236 // prevent re-entrance issues. | 238 // prevent re-entrance issues. |
| 237 callbacks.push_back( | 239 callbacks.push_back( |
| 238 base::Bind(subscription->callback, | 240 base::Bind(subscription->callback, |
| 239 ContentSettingToPermissionStatus(new_value))); | 241 ContentSettingToPermissionStatus(new_value))); |
| 240 } | 242 } |
| 241 | 243 |
| 242 for (const auto& callback : callbacks) | 244 for (const auto& callback : callbacks) |
| 243 callback.Run(); | 245 callback.Run(); |
| 244 } | 246 } |
| OLD | NEW |