| 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 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Helper method to convert ContentSetting to content::PermissionStatus. | 20 // Helper method to convert ContentSetting to content::PermissionStatus. |
| 21 content::PermissionStatus | 21 content::PermissionStatus |
| 22 ContentSettingToPermissionStatus(ContentSetting setting) { | 22 ContentSettingToPermissionStatus(ContentSetting setting) { |
| 23 switch (setting) { | 23 switch (setting) { |
| 24 case CONTENT_SETTING_ALLOW: | 24 case CONTENT_SETTING_ALLOW: |
| 25 case CONTENT_SETTING_SESSION_ONLY: | 25 case CONTENT_SETTING_SESSION_ONLY: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 : profile_(profile) { | 89 : profile_(profile) { |
| 90 } | 90 } |
| 91 | 91 |
| 92 PermissionManager::~PermissionManager() { | 92 PermissionManager::~PermissionManager() { |
| 93 if (!subscriptions_.IsEmpty()) | 93 if (!subscriptions_.IsEmpty()) |
| 94 profile_->GetHostContentSettingsMap()->RemoveObserver(this); | 94 profile_->GetHostContentSettingsMap()->RemoveObserver(this); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void PermissionManager::RequestPermission( | 97 void PermissionManager::RequestPermission( |
| 98 content::PermissionType permission, | 98 content::PermissionType permission, |
| 99 content::WebContents* web_contents, | 99 content::RenderFrameHost* render_frame_host, |
| 100 int request_id, | 100 int request_id, |
| 101 const GURL& requesting_origin, | 101 const GURL& requesting_origin, |
| 102 bool user_gesture, | 102 bool user_gesture, |
| 103 const base::Callback<void(content::PermissionStatus)>& callback) { | 103 const base::Callback<void(content::PermissionStatus)>& callback) { |
| 104 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 104 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
| 105 if (!context) { | 105 if (!context) { |
| 106 callback.Run(content::PERMISSION_STATUS_DENIED); | 106 callback.Run(content::PERMISSION_STATUS_DENIED); |
| 107 return; | 107 return; |
| 108 } | 108 } |
| 109 | 109 |
| 110 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 110 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 111 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 111 int render_frame_id = render_frame_host->GetRoutingID(); |
| 112 const PermissionRequestID request(render_process_id, | 112 const PermissionRequestID request(render_process_id, |
| 113 render_view_id, | 113 render_frame_id, |
| 114 request_id, | 114 request_id, |
| 115 requesting_origin); | 115 requesting_origin); |
| 116 | 116 |
| 117 context->RequestPermission(web_contents, request, requesting_origin, | 117 context->RequestPermission( |
| 118 user_gesture, | 118 content::WebContents::FromRenderFrameHost(render_frame_host), |
| 119 base::Bind(&PermissionStatusCallbackWrapper, | 119 request, requesting_origin, user_gesture, |
| 120 callback)); | 120 base::Bind(&PermissionStatusCallbackWrapper, |
| 121 callback)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void PermissionManager::CancelPermissionRequest( | 124 void PermissionManager::CancelPermissionRequest( |
| 124 content::PermissionType permission, | 125 content::PermissionType permission, |
| 125 content::WebContents* web_contents, | 126 content::RenderFrameHost* render_frame_host, |
| 126 int request_id, | 127 int request_id, |
| 127 const GURL& requesting_origin) { | 128 const GURL& requesting_origin) { |
| 128 PermissionContextBase* context = PermissionContext::Get(profile_, permission); | 129 PermissionContextBase* context = PermissionContext::Get(profile_, permission); |
| 129 if (!context) | 130 if (!context) |
| 130 return; | 131 return; |
| 131 | 132 |
| 132 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 133 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 133 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 134 int render_frame_id = render_frame_host->GetRoutingID(); |
| 134 const PermissionRequestID request(render_process_id, | 135 const PermissionRequestID request(render_process_id, |
| 135 render_view_id, | 136 render_frame_id, |
| 136 request_id, | 137 request_id, |
| 137 requesting_origin); | 138 requesting_origin); |
| 138 | 139 |
| 139 context->CancelPermissionRequest(web_contents, request); | 140 context->CancelPermissionRequest( |
| 141 content::WebContents::FromRenderFrameHost(render_frame_host), request); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void PermissionManager::ResetPermission( | 144 void PermissionManager::ResetPermission( |
| 143 content::PermissionType permission, | 145 content::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 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // Add the callback to |callbacks| which will be run after the loop to | 238 // Add the callback to |callbacks| which will be run after the loop to |
| 237 // prevent re-entrance issues. | 239 // prevent re-entrance issues. |
| 238 callbacks.push_back( | 240 callbacks.push_back( |
| 239 base::Bind(subscription->callback, | 241 base::Bind(subscription->callback, |
| 240 ContentSettingToPermissionStatus(new_value))); | 242 ContentSettingToPermissionStatus(new_value))); |
| 241 } | 243 } |
| 242 | 244 |
| 243 for (const auto& callback : callbacks) | 245 for (const auto& callback : callbacks) |
| 244 callback.Run(); | 246 callback.Run(); |
| 245 } | 247 } |
| OLD | NEW |