| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/permissions/permission_service_impl.h" | 5 #include "content/browser/permissions/permission_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 12 #include "content/public/browser/permission_manager.h" | 12 #include "content/public/browser/permission_manager.h" |
| 13 #include "content/public/browser/permission_type.h" | 13 #include "content/public/browser/permission_type.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 PermissionType PermissionNameToPermissionType(PermissionName name) { | 19 PermissionType PermissionNameToPermissionType(mojom::PermissionName name) { |
| 20 switch(name) { | 20 switch(name) { |
| 21 case PermissionName::GEOLOCATION: | 21 case mojom::PermissionName::GEOLOCATION: |
| 22 return PermissionType::GEOLOCATION; | 22 return PermissionType::GEOLOCATION; |
| 23 case PermissionName::NOTIFICATIONS: | 23 case mojom::PermissionName::NOTIFICATIONS: |
| 24 return PermissionType::NOTIFICATIONS; | 24 return PermissionType::NOTIFICATIONS; |
| 25 case PermissionName::PUSH_NOTIFICATIONS: | 25 case mojom::PermissionName::PUSH_NOTIFICATIONS: |
| 26 return PermissionType::PUSH_MESSAGING; | 26 return PermissionType::PUSH_MESSAGING; |
| 27 case PermissionName::MIDI: | 27 case mojom::PermissionName::MIDI: |
| 28 return PermissionType::MIDI; | 28 return PermissionType::MIDI; |
| 29 case PermissionName::MIDI_SYSEX: | 29 case mojom::PermissionName::MIDI_SYSEX: |
| 30 return PermissionType::MIDI_SYSEX; | 30 return PermissionType::MIDI_SYSEX; |
| 31 case PermissionName::PROTECTED_MEDIA_IDENTIFIER: | 31 case mojom::PermissionName::PROTECTED_MEDIA_IDENTIFIER: |
| 32 return PermissionType::PROTECTED_MEDIA_IDENTIFIER; | 32 return PermissionType::PROTECTED_MEDIA_IDENTIFIER; |
| 33 case PermissionName::DURABLE_STORAGE: | 33 case mojom::PermissionName::DURABLE_STORAGE: |
| 34 return PermissionType::DURABLE_STORAGE; | 34 return PermissionType::DURABLE_STORAGE; |
| 35 case PermissionName::AUDIO_CAPTURE: | 35 case mojom::PermissionName::AUDIO_CAPTURE: |
| 36 return PermissionType::AUDIO_CAPTURE; | 36 return PermissionType::AUDIO_CAPTURE; |
| 37 case PermissionName::VIDEO_CAPTURE: | 37 case mojom::PermissionName::VIDEO_CAPTURE: |
| 38 return PermissionType::VIDEO_CAPTURE; | 38 return PermissionType::VIDEO_CAPTURE; |
| 39 } | 39 } |
| 40 | 40 |
| 41 NOTREACHED(); | 41 NOTREACHED(); |
| 42 return PermissionType::NUM; | 42 return PermissionType::NUM; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // This function allows the usage of the the multiple request map | 45 // This function allows the usage of the the multiple request map |
| 46 // with single requests. | 46 // with single requests. |
| 47 void PermissionRequestResponseCallbackWrapper( | 47 void PermissionRequestResponseCallbackWrapper( |
| 48 const mojo::Callback<void(PermissionStatus)>& callback, | 48 const mojo::Callback<void(mojom::PermissionStatus)>& callback, |
| 49 const mojo::Array<PermissionStatus>& vector) { | 49 const mojo::Array<mojom::PermissionStatus>& vector) { |
| 50 DCHECK_EQ(vector.size(), 1ul); | 50 DCHECK_EQ(vector.size(), 1ul); |
| 51 callback.Run(vector[0]); | 51 callback.Run(vector[0]); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // anonymous namespace | 54 } // anonymous namespace |
| 55 | 55 |
| 56 PermissionServiceImpl::PendingRequest::PendingRequest( | 56 PermissionServiceImpl::PendingRequest::PendingRequest( |
| 57 const PermissionsStatusCallback& callback, | 57 const PermissionsStatusCallback& callback, |
| 58 int request_count) | 58 int request_count) |
| 59 : callback(callback), | 59 : callback(callback), |
| 60 request_count(request_count) { | 60 request_count(request_count) { |
| 61 } | 61 } |
| 62 | 62 |
| 63 PermissionServiceImpl::PendingRequest::~PendingRequest() { | 63 PermissionServiceImpl::PendingRequest::~PendingRequest() { |
| 64 if (callback.is_null()) | 64 if (callback.is_null()) |
| 65 return; | 65 return; |
| 66 | 66 |
| 67 mojo::Array<PermissionStatus> result = | 67 mojo::Array<mojom::PermissionStatus> result = |
| 68 mojo::Array<PermissionStatus>::New(request_count); | 68 mojo::Array<mojom::PermissionStatus>::New(request_count); |
| 69 for (int i = 0; i < request_count; ++i) | 69 for (int i = 0; i < request_count; ++i) |
| 70 result[i] = PermissionStatus::DENIED; | 70 result[i] = mojom::PermissionStatus::DENIED; |
| 71 callback.Run(std::move(result)); | 71 callback.Run(std::move(result)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 PermissionServiceImpl::PendingSubscription::PendingSubscription( | 74 PermissionServiceImpl::PendingSubscription::PendingSubscription( |
| 75 PermissionType permission, | 75 PermissionType permission, |
| 76 const GURL& origin, | 76 const GURL& origin, |
| 77 const PermissionStatusCallback& callback) | 77 const PermissionStatusCallback& callback) |
| 78 : id(-1), | 78 : id(-1), |
| 79 permission(permission), | 79 permission(permission), |
| 80 origin(origin), | 80 origin(origin), |
| 81 callback(callback) { | 81 callback(callback) { |
| 82 } | 82 } |
| 83 | 83 |
| 84 PermissionServiceImpl::PendingSubscription::~PendingSubscription() { | 84 PermissionServiceImpl::PendingSubscription::~PendingSubscription() { |
| 85 if (!callback.is_null()) | 85 if (!callback.is_null()) |
| 86 callback.Run(PermissionStatus::ASK); | 86 callback.Run(mojom::PermissionStatus::ASK); |
| 87 } | 87 } |
| 88 | 88 |
| 89 PermissionServiceImpl::PermissionServiceImpl( | 89 PermissionServiceImpl::PermissionServiceImpl( |
| 90 PermissionServiceContext* context, | 90 PermissionServiceContext* context, |
| 91 mojo::InterfaceRequest<PermissionService> request) | 91 mojo::InterfaceRequest<mojom::PermissionService> request) |
| 92 : context_(context), | 92 : context_(context), |
| 93 binding_(this, std::move(request)), | 93 binding_(this, std::move(request)), |
| 94 weak_factory_(this) { | 94 weak_factory_(this) { |
| 95 binding_.set_connection_error_handler( | 95 binding_.set_connection_error_handler( |
| 96 base::Bind(&PermissionServiceImpl::OnConnectionError, | 96 base::Bind(&PermissionServiceImpl::OnConnectionError, |
| 97 base::Unretained(this))); | 97 base::Unretained(this))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 PermissionServiceImpl::~PermissionServiceImpl() { | 100 PermissionServiceImpl::~PermissionServiceImpl() { |
| 101 DCHECK(pending_requests_.IsEmpty()); | 101 DCHECK(pending_requests_.IsEmpty()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void PermissionServiceImpl::OnConnectionError() { | 104 void PermissionServiceImpl::OnConnectionError() { |
| 105 context_->ServiceHadConnectionError(this); | 105 context_->ServiceHadConnectionError(this); |
| 106 // After that call, |this| will be deleted. | 106 // After that call, |this| will be deleted. |
| 107 } | 107 } |
| 108 | 108 |
| 109 void PermissionServiceImpl::RequestPermission( | 109 void PermissionServiceImpl::RequestPermission( |
| 110 PermissionName permission, | 110 mojom::PermissionName permission, |
| 111 const mojo::String& origin, | 111 const mojo::String& origin, |
| 112 const PermissionStatusCallback& callback) { | 112 const PermissionStatusCallback& callback) { |
| 113 // This condition is valid if the call is coming from a ChildThread instead of | 113 // This condition is valid if the call is coming from a ChildThread instead of |
| 114 // a RenderFrame. Some consumers of the service run in Workers and some in | 114 // a RenderFrame. Some consumers of the service run in Workers and some in |
| 115 // Frames. In the context of a Worker, it is not possible to show a | 115 // Frames. In the context of a Worker, it is not possible to show a |
| 116 // permission prompt because there is no tab. In the context of a Frame, we | 116 // permission prompt because there is no tab. In the context of a Frame, we |
| 117 // can. Even if the call comes from a context where it is not possible to show | 117 // can. Even if the call comes from a context where it is not possible to show |
| 118 // any UI, we want to still return something relevant so the current | 118 // any UI, we want to still return something relevant so the current |
| 119 // permission status is returned. | 119 // permission status is returned. |
| 120 BrowserContext* browser_context = context_->GetBrowserContext(); | 120 BrowserContext* browser_context = context_->GetBrowserContext(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 // callback if it was run synchronously. | 139 // callback if it was run synchronously. |
| 140 PendingRequest* pending_request = pending_requests_.Lookup( | 140 PendingRequest* pending_request = pending_requests_.Lookup( |
| 141 pending_request_id); | 141 pending_request_id); |
| 142 if (!pending_request) | 142 if (!pending_request) |
| 143 return; | 143 return; |
| 144 pending_request->id = id; | 144 pending_request->id = id; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void PermissionServiceImpl::OnRequestPermissionResponse( | 147 void PermissionServiceImpl::OnRequestPermissionResponse( |
| 148 int pending_request_id, | 148 int pending_request_id, |
| 149 PermissionStatus status) { | 149 mojom::PermissionStatus status) { |
| 150 OnRequestPermissionsResponse(pending_request_id, | 150 OnRequestPermissionsResponse(pending_request_id, |
| 151 std::vector<PermissionStatus>(1, status)); | 151 std::vector<mojom::PermissionStatus>(1, status)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void PermissionServiceImpl::RequestPermissions( | 154 void PermissionServiceImpl::RequestPermissions( |
| 155 mojo::Array<PermissionName> permissions, | 155 mojo::Array<mojom::PermissionName> permissions, |
| 156 const mojo::String& origin, | 156 const mojo::String& origin, |
| 157 const PermissionsStatusCallback& callback) { | 157 const PermissionsStatusCallback& callback) { |
| 158 if (permissions.is_null()) { | 158 if (permissions.is_null()) { |
| 159 callback.Run(mojo::Array<PermissionStatus>()); | 159 callback.Run(mojo::Array<mojom::PermissionStatus>()); |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // This condition is valid if the call is coming from a ChildThread instead of | 163 // This condition is valid if the call is coming from a ChildThread instead of |
| 164 // a RenderFrame. Some consumers of the service run in Workers and some in | 164 // a RenderFrame. Some consumers of the service run in Workers and some in |
| 165 // Frames. In the context of a Worker, it is not possible to show a | 165 // Frames. In the context of a Worker, it is not possible to show a |
| 166 // permission prompt because there is no tab. In the context of a Frame, we | 166 // permission prompt because there is no tab. In the context of a Frame, we |
| 167 // can. Even if the call comes from a context where it is not possible to show | 167 // can. Even if the call comes from a context where it is not possible to show |
| 168 // any UI, we want to still return something relevant so the current | 168 // any UI, we want to still return something relevant so the current |
| 169 // permission status is returned for each permission. | 169 // permission status is returned for each permission. |
| 170 BrowserContext* browser_context = context_->GetBrowserContext(); | 170 BrowserContext* browser_context = context_->GetBrowserContext(); |
| 171 DCHECK(browser_context); | 171 DCHECK(browser_context); |
| 172 if (!context_->render_frame_host() || | 172 if (!context_->render_frame_host() || |
| 173 !browser_context->GetPermissionManager()) { | 173 !browser_context->GetPermissionManager()) { |
| 174 mojo::Array<PermissionStatus> result(permissions.size()); | 174 mojo::Array<mojom::PermissionStatus> result(permissions.size()); |
| 175 for (size_t i = 0; i < permissions.size(); ++i) { | 175 for (size_t i = 0; i < permissions.size(); ++i) { |
| 176 result[i] = | 176 result[i] = |
| 177 GetPermissionStatusFromName(permissions[i], GURL(origin.get())); | 177 GetPermissionStatusFromName(permissions[i], GURL(origin.get())); |
| 178 } | 178 } |
| 179 callback.Run(std::move(result)); | 179 callback.Run(std::move(result)); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 std::vector<PermissionType> types(permissions.size()); | 183 std::vector<PermissionType> types(permissions.size()); |
| 184 for (size_t i = 0; i < types.size(); ++i) | 184 for (size_t i = 0; i < types.size(); ++i) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 // the response callback. | 198 // the response callback. |
| 199 PendingRequest* pending_request = pending_requests_.Lookup( | 199 PendingRequest* pending_request = pending_requests_.Lookup( |
| 200 pending_request_id); | 200 pending_request_id); |
| 201 if (!pending_request) | 201 if (!pending_request) |
| 202 return; | 202 return; |
| 203 pending_request->id = id; | 203 pending_request->id = id; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void PermissionServiceImpl::OnRequestPermissionsResponse( | 206 void PermissionServiceImpl::OnRequestPermissionsResponse( |
| 207 int pending_request_id, | 207 int pending_request_id, |
| 208 const std::vector<PermissionStatus>& result) { | 208 const std::vector<mojom::PermissionStatus>& result) { |
| 209 PendingRequest* request = pending_requests_.Lookup(pending_request_id); | 209 PendingRequest* request = pending_requests_.Lookup(pending_request_id); |
| 210 PermissionsStatusCallback callback(request->callback); | 210 PermissionsStatusCallback callback(request->callback); |
| 211 request->callback.reset(); | 211 request->callback.reset(); |
| 212 pending_requests_.Remove(pending_request_id); | 212 pending_requests_.Remove(pending_request_id); |
| 213 callback.Run(mojo::Array<PermissionStatus>::From(result)); | 213 callback.Run(mojo::Array<mojom::PermissionStatus>::From(result)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void PermissionServiceImpl::CancelPendingOperations() { | 216 void PermissionServiceImpl::CancelPendingOperations() { |
| 217 DCHECK(context_->GetBrowserContext()); | 217 DCHECK(context_->GetBrowserContext()); |
| 218 | 218 |
| 219 PermissionManager* permission_manager = | 219 PermissionManager* permission_manager = |
| 220 context_->GetBrowserContext()->GetPermissionManager(); | 220 context_->GetBrowserContext()->GetPermissionManager(); |
| 221 if (!permission_manager) | 221 if (!permission_manager) |
| 222 return; | 222 return; |
| 223 | 223 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 235 it.GetCurrentValue()->callback.Run(GetPermissionStatusFromType( | 235 it.GetCurrentValue()->callback.Run(GetPermissionStatusFromType( |
| 236 it.GetCurrentValue()->permission, it.GetCurrentValue()->origin)); | 236 it.GetCurrentValue()->permission, it.GetCurrentValue()->origin)); |
| 237 it.GetCurrentValue()->callback.reset(); | 237 it.GetCurrentValue()->callback.reset(); |
| 238 permission_manager->UnsubscribePermissionStatusChange( | 238 permission_manager->UnsubscribePermissionStatusChange( |
| 239 it.GetCurrentValue()->id); | 239 it.GetCurrentValue()->id); |
| 240 } | 240 } |
| 241 pending_subscriptions_.Clear(); | 241 pending_subscriptions_.Clear(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void PermissionServiceImpl::HasPermission( | 244 void PermissionServiceImpl::HasPermission( |
| 245 PermissionName permission, | 245 mojom::PermissionName permission, |
| 246 const mojo::String& origin, | 246 const mojo::String& origin, |
| 247 const PermissionStatusCallback& callback) { | 247 const PermissionStatusCallback& callback) { |
| 248 callback.Run(GetPermissionStatusFromName(permission, GURL(origin.get()))); | 248 callback.Run(GetPermissionStatusFromName(permission, GURL(origin.get()))); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void PermissionServiceImpl::RevokePermission( | 251 void PermissionServiceImpl::RevokePermission( |
| 252 PermissionName permission, | 252 mojom::PermissionName permission, |
| 253 const mojo::String& origin, | 253 const mojo::String& origin, |
| 254 const PermissionStatusCallback& callback) { | 254 const PermissionStatusCallback& callback) { |
| 255 GURL origin_url(origin.get()); | 255 GURL origin_url(origin.get()); |
| 256 PermissionType permission_type = PermissionNameToPermissionType(permission); | 256 PermissionType permission_type = PermissionNameToPermissionType(permission); |
| 257 PermissionStatus status = GetPermissionStatusFromType(permission_type, | 257 mojom::PermissionStatus status = |
| 258 origin_url); | 258 GetPermissionStatusFromType(permission_type, origin_url); |
| 259 | 259 |
| 260 // Resetting the permission should only be possible if the permission is | 260 // Resetting the permission should only be possible if the permission is |
| 261 // already granted. | 261 // already granted. |
| 262 if (status != PermissionStatus::GRANTED) { | 262 if (status != mojom::PermissionStatus::GRANTED) { |
| 263 callback.Run(status); | 263 callback.Run(status); |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 | 266 |
| 267 ResetPermissionStatus(permission_type, origin_url); | 267 ResetPermissionStatus(permission_type, origin_url); |
| 268 | 268 |
| 269 callback.Run(GetPermissionStatusFromType(permission_type, origin_url)); | 269 callback.Run(GetPermissionStatusFromType(permission_type, origin_url)); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void PermissionServiceImpl::GetNextPermissionChange( | 272 void PermissionServiceImpl::GetNextPermissionChange( |
| 273 PermissionName permission, | 273 mojom::PermissionName permission, |
| 274 const mojo::String& mojo_origin, | 274 const mojo::String& mojo_origin, |
| 275 PermissionStatus last_known_status, | 275 mojom::PermissionStatus last_known_status, |
| 276 const PermissionStatusCallback& callback) { | 276 const PermissionStatusCallback& callback) { |
| 277 GURL origin(mojo_origin.get()); | 277 GURL origin(mojo_origin.get()); |
| 278 PermissionStatus current_status = | 278 mojom::PermissionStatus current_status = |
| 279 GetPermissionStatusFromName(permission, origin); | 279 GetPermissionStatusFromName(permission, origin); |
| 280 if (current_status != last_known_status) { | 280 if (current_status != last_known_status) { |
| 281 callback.Run(current_status); | 281 callback.Run(current_status); |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 | 284 |
| 285 BrowserContext* browser_context = context_->GetBrowserContext(); | 285 BrowserContext* browser_context = context_->GetBrowserContext(); |
| 286 DCHECK(browser_context); | 286 DCHECK(browser_context); |
| 287 if (!browser_context->GetPermissionManager()) { | 287 if (!browser_context->GetPermissionManager()) { |
| 288 callback.Run(current_status); | 288 callback.Run(current_status); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 303 browser_context->GetPermissionManager()->SubscribePermissionStatusChange( | 303 browser_context->GetPermissionManager()->SubscribePermissionStatusChange( |
| 304 permission_type, | 304 permission_type, |
| 305 origin, | 305 origin, |
| 306 // If the embedding_origin is empty, we,ll use the |origin| instead. | 306 // If the embedding_origin is empty, we,ll use the |origin| instead. |
| 307 embedding_origin.is_empty() ? origin : embedding_origin, | 307 embedding_origin.is_empty() ? origin : embedding_origin, |
| 308 base::Bind(&PermissionServiceImpl::OnPermissionStatusChanged, | 308 base::Bind(&PermissionServiceImpl::OnPermissionStatusChanged, |
| 309 weak_factory_.GetWeakPtr(), | 309 weak_factory_.GetWeakPtr(), |
| 310 pending_subscription_id)); | 310 pending_subscription_id)); |
| 311 } | 311 } |
| 312 | 312 |
| 313 PermissionStatus PermissionServiceImpl::GetPermissionStatusFromName( | 313 mojom::PermissionStatus PermissionServiceImpl::GetPermissionStatusFromName( |
| 314 PermissionName permission, const GURL& origin) { | 314 mojom::PermissionName permission, |
| 315 const GURL& origin) { |
| 315 return GetPermissionStatusFromType(PermissionNameToPermissionType(permission), | 316 return GetPermissionStatusFromType(PermissionNameToPermissionType(permission), |
| 316 origin); | 317 origin); |
| 317 } | 318 } |
| 318 | 319 |
| 319 PermissionStatus PermissionServiceImpl::GetPermissionStatusFromType( | 320 mojom::PermissionStatus PermissionServiceImpl::GetPermissionStatusFromType( |
| 320 PermissionType type, const GURL& origin) { | 321 PermissionType type, |
| 322 const GURL& origin) { |
| 321 BrowserContext* browser_context = context_->GetBrowserContext(); | 323 BrowserContext* browser_context = context_->GetBrowserContext(); |
| 322 DCHECK(browser_context); | 324 DCHECK(browser_context); |
| 323 if (!browser_context->GetPermissionManager()) | 325 if (!browser_context->GetPermissionManager()) |
| 324 return PermissionStatus::DENIED; | 326 return mojom::PermissionStatus::DENIED; |
| 325 | 327 |
| 326 // If the embedding_origin is empty we'll use |origin| instead. | 328 // If the embedding_origin is empty we'll use |origin| instead. |
| 327 GURL embedding_origin = context_->GetEmbeddingOrigin(); | 329 GURL embedding_origin = context_->GetEmbeddingOrigin(); |
| 328 return browser_context->GetPermissionManager()->GetPermissionStatus( | 330 return browser_context->GetPermissionManager()->GetPermissionStatus( |
| 329 type, origin, embedding_origin.is_empty() ? origin : embedding_origin); | 331 type, origin, embedding_origin.is_empty() ? origin : embedding_origin); |
| 330 } | 332 } |
| 331 | 333 |
| 332 void PermissionServiceImpl::ResetPermissionStatus(PermissionType type, | 334 void PermissionServiceImpl::ResetPermissionStatus(PermissionType type, |
| 333 const GURL& origin) { | 335 const GURL& origin) { |
| 334 BrowserContext* browser_context = context_->GetBrowserContext(); | 336 BrowserContext* browser_context = context_->GetBrowserContext(); |
| 335 DCHECK(browser_context); | 337 DCHECK(browser_context); |
| 336 if (!browser_context->GetPermissionManager()) | 338 if (!browser_context->GetPermissionManager()) |
| 337 return; | 339 return; |
| 338 | 340 |
| 339 // If the embedding_origin is empty we'll use |origin| instead. | 341 // If the embedding_origin is empty we'll use |origin| instead. |
| 340 GURL embedding_origin = context_->GetEmbeddingOrigin(); | 342 GURL embedding_origin = context_->GetEmbeddingOrigin(); |
| 341 browser_context->GetPermissionManager()->ResetPermission( | 343 browser_context->GetPermissionManager()->ResetPermission( |
| 342 type, origin, embedding_origin.is_empty() ? origin : embedding_origin); | 344 type, origin, embedding_origin.is_empty() ? origin : embedding_origin); |
| 343 } | 345 } |
| 344 | 346 |
| 345 void PermissionServiceImpl::OnPermissionStatusChanged( | 347 void PermissionServiceImpl::OnPermissionStatusChanged( |
| 346 int pending_subscription_id, | 348 int pending_subscription_id, |
| 347 PermissionStatus status) { | 349 mojom::PermissionStatus status) { |
| 348 PendingSubscription* subscription = | 350 PendingSubscription* subscription = |
| 349 pending_subscriptions_.Lookup(pending_subscription_id); | 351 pending_subscriptions_.Lookup(pending_subscription_id); |
| 350 | 352 |
| 351 BrowserContext* browser_context = context_->GetBrowserContext(); | 353 BrowserContext* browser_context = context_->GetBrowserContext(); |
| 352 DCHECK(browser_context); | 354 DCHECK(browser_context); |
| 353 if (browser_context->GetPermissionManager()) { | 355 if (browser_context->GetPermissionManager()) { |
| 354 browser_context->GetPermissionManager()->UnsubscribePermissionStatusChange( | 356 browser_context->GetPermissionManager()->UnsubscribePermissionStatusChange( |
| 355 subscription->id); | 357 subscription->id); |
| 356 } | 358 } |
| 357 | 359 |
| 358 PermissionStatusCallback callback = subscription->callback; | 360 PermissionStatusCallback callback = subscription->callback; |
| 359 | 361 |
| 360 subscription->callback.reset(); | 362 subscription->callback.reset(); |
| 361 pending_subscriptions_.Remove(pending_subscription_id); | 363 pending_subscriptions_.Remove(pending_subscription_id); |
| 362 | 364 |
| 363 callback.Run(status); | 365 callback.Run(status); |
| 364 } | 366 } |
| 365 | 367 |
| 366 } // namespace content | 368 } // namespace content |
| OLD | NEW |