Chromium Code Reviews| 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 "android_webview/browser/aw_permission_manager.h" | 5 #include "android_webview/browser/aw_permission_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" | 9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.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_frame_host.h" |
| 15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 | 17 |
| 18 using blink::mojom::PermissionStatus; | 18 using blink::mojom::PermissionStatus; |
| 19 using content::PermissionType; | 19 using content::PermissionType; |
| 20 | 20 |
| 21 using RequestPermissionsCallback = | |
| 22 base::Callback<void(const std::vector<PermissionStatus>&)>; | |
| 23 | |
| 21 namespace android_webview { | 24 namespace android_webview { |
| 22 | 25 |
| 26 namespace { | |
| 27 | |
| 28 void PermissionRequestResponseCallbackWrapper( | |
| 29 const base::Callback<void(PermissionStatus)>& callback, | |
| 30 const std::vector<PermissionStatus>& vector) { | |
| 31 DCHECK_EQ(vector.size(), 1ul); | |
| 32 callback.Run(vector[0]); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 23 class LastRequestResultCache { | 37 class LastRequestResultCache { |
| 24 public: | 38 public: |
| 25 LastRequestResultCache() = default; | 39 LastRequestResultCache() = default; |
| 26 | 40 |
| 27 void SetResult(PermissionType permission, | 41 void SetResult(PermissionType permission, |
| 28 const GURL& requesting_origin, | 42 const GURL& requesting_origin, |
| 29 const GURL& embedding_origin, | 43 const GURL& embedding_origin, |
| 30 PermissionStatus status) { | 44 PermissionStatus status) { |
| 31 DCHECK(status == PermissionStatus::GRANTED || | 45 DCHECK(status == PermissionStatus::GRANTED || |
| 32 status == PermissionStatus::DENIED); | 46 status == PermissionStatus::DENIED); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 return std::string(); | 138 return std::string(); |
| 125 return requesting + "," + embedding; | 139 return requesting + "," + embedding; |
| 126 } | 140 } |
| 127 | 141 |
| 128 using StatusMap = base::hash_map<std::string, PermissionStatus>; | 142 using StatusMap = base::hash_map<std::string, PermissionStatus>; |
| 129 StatusMap pmi_result_cache_; | 143 StatusMap pmi_result_cache_; |
| 130 | 144 |
| 131 DISALLOW_COPY_AND_ASSIGN(LastRequestResultCache); | 145 DISALLOW_COPY_AND_ASSIGN(LastRequestResultCache); |
| 132 }; | 146 }; |
| 133 | 147 |
| 134 struct AwPermissionManager::PendingRequest { | 148 class AwPermissionManager::PendingRequest { |
| 135 public: | 149 public: |
| 136 PendingRequest(PermissionType permission, | 150 PendingRequest(const std::vector<PermissionType> permissions, |
| 137 GURL requesting_origin, | 151 GURL requesting_origin, |
| 138 GURL embedding_origin, | 152 GURL embedding_origin, |
| 139 content::RenderFrameHost* render_frame_host, | 153 content::RenderFrameHost* render_frame_host, |
| 140 const base::Callback<void(PermissionStatus)>& callback) | 154 const RequestPermissionsCallback callback) |
| 141 : permission(permission), | 155 : permissions(permissions), |
| 142 requesting_origin(requesting_origin), | 156 requesting_origin(requesting_origin), |
| 143 embedding_origin(embedding_origin), | 157 embedding_origin(embedding_origin), |
| 144 render_process_id(render_frame_host->GetProcess()->GetID()), | 158 render_process_id(render_frame_host->GetProcess()->GetID()), |
| 145 render_frame_id(render_frame_host->GetRoutingID()), | 159 render_frame_id(render_frame_host->GetRoutingID()), |
| 146 callback(callback) { | 160 callback(callback), |
| 161 results(permissions.size(), PermissionStatus::DENIED), | |
| 162 cancelled_(false) { | |
| 163 for (size_t i = 0; i < permissions.size(); ++i) | |
| 164 permission_index_map_.insert(std::make_pair(permissions[i], i)); | |
| 147 } | 165 } |
| 148 | 166 |
| 149 ~PendingRequest() = default; | 167 ~PendingRequest() = default; |
| 150 | 168 |
| 151 PermissionType permission; | 169 void SetPermissionStatus(int index, PermissionStatus status) { |
| 170 DCHECK(!IsComplete()); | |
| 171 | |
| 172 results[index] = status; | |
| 173 | |
| 174 DCHECK(!IsComplete(permissions[index])); | |
| 175 resolved_permissions_.insert(permissions[index]); | |
| 176 } | |
| 177 | |
| 178 void SetPermissionStatus(PermissionType type, PermissionStatus status) { | |
| 179 auto result = permission_index_map_.find(type); | |
| 180 if (result == permission_index_map_.end()) { | |
| 181 NOTREACHED(); | |
| 182 return; | |
| 183 } | |
| 184 SetPermissionStatus(result->second, status); | |
| 185 } | |
| 186 | |
| 187 PermissionStatus GetPermissionStatus(PermissionType type) { | |
| 188 auto result = permission_index_map_.find(type); | |
| 189 if (result == permission_index_map_.end()) { | |
| 190 NOTREACHED(); | |
| 191 return PermissionStatus::DENIED; | |
| 192 } | |
| 193 return results[result->second]; | |
| 194 } | |
| 195 | |
| 196 bool HasPermissionType(PermissionType type) { | |
| 197 return permission_index_map_.find(type) != permission_index_map_.end(); | |
| 198 } | |
| 199 | |
| 200 bool IsComplete() const { | |
| 201 return results.size() == resolved_permissions_.size(); | |
| 202 } | |
| 203 | |
| 204 bool IsComplete(PermissionType type) const { | |
| 205 return resolved_permissions_.count(type) != 0; | |
| 206 } | |
| 207 | |
| 208 void Cancel() { cancelled_ = true; } | |
| 209 | |
| 210 bool IsCancelled() const { return cancelled_; } | |
| 211 | |
| 212 std::vector<PermissionType> permissions; | |
| 152 GURL requesting_origin; | 213 GURL requesting_origin; |
| 153 GURL embedding_origin; | 214 GURL embedding_origin; |
| 154 int render_process_id; | 215 int render_process_id; |
| 155 int render_frame_id; | 216 int render_frame_id; |
| 156 base::Callback<void(PermissionStatus)> callback; | 217 RequestPermissionsCallback callback; |
| 218 std::vector<PermissionStatus> results; | |
| 219 | |
| 220 private: | |
| 221 std::map<PermissionType, size_t> permission_index_map_; | |
| 222 std::set<PermissionType> resolved_permissions_; | |
| 223 bool cancelled_; | |
| 157 }; | 224 }; |
| 158 | 225 |
| 159 AwPermissionManager::AwPermissionManager() | 226 AwPermissionManager::AwPermissionManager() |
| 160 : content::PermissionManager(), | 227 : content::PermissionManager(), |
| 161 result_cache_(new LastRequestResultCache), | 228 result_cache_(new LastRequestResultCache), |
| 162 weak_ptr_factory_(this) { | 229 weak_ptr_factory_(this) { |
| 163 } | 230 } |
| 164 | 231 |
| 165 AwPermissionManager::~AwPermissionManager() { | 232 AwPermissionManager::~AwPermissionManager() { |
| 233 std::vector<int> request_ids; | |
| 234 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
| 235 !it.IsAtEnd(); it.Advance()) { | |
| 236 request_ids.push_back(it.GetCurrentKey()); | |
| 237 } | |
| 238 for (auto request_id : request_ids) { | |
| 239 PendingRequest* request = pending_requests_.Lookup(request_id); | |
| 240 if (!request) | |
| 241 continue; | |
| 242 const RequestPermissionsCallback callback = request->callback; | |
| 243 std::vector<PermissionStatus> results = request->results; | |
| 244 CancelPermissionRequest(request_id); | |
| 245 callback.Run(results); | |
| 246 } | |
| 247 DCHECK(pending_requests_.IsEmpty()); | |
| 166 } | 248 } |
| 167 | 249 |
| 168 int AwPermissionManager::RequestPermission( | 250 int AwPermissionManager::RequestPermission( |
| 169 PermissionType permission, | 251 PermissionType permission, |
| 170 content::RenderFrameHost* render_frame_host, | 252 content::RenderFrameHost* render_frame_host, |
| 171 const GURL& requesting_origin, | 253 const GURL& requesting_origin, |
| 172 bool user_gesture, | 254 bool user_gesture, |
| 173 const base::Callback<void(PermissionStatus)>& callback) { | 255 const base::Callback<void(PermissionStatus)>& callback) { |
| 174 int render_process_id = render_frame_host->GetProcess()->GetID(); | 256 return RequestPermissions( |
| 175 int render_frame_id = render_frame_host->GetRoutingID(); | 257 std::vector<PermissionType>(1, permission), render_frame_host, |
| 176 AwBrowserPermissionRequestDelegate* delegate = | 258 requesting_origin, user_gesture, |
| 177 AwBrowserPermissionRequestDelegate::FromID(render_process_id, | 259 base::Bind(&PermissionRequestResponseCallbackWrapper, callback)); |
| 178 render_frame_id); | |
| 179 if (!delegate) { | |
| 180 DVLOG(0) << "Dropping permission request for " | |
| 181 << static_cast<int>(permission); | |
| 182 callback.Run(PermissionStatus::DENIED); | |
| 183 return kNoPendingOperation; | |
| 184 } | |
| 185 | |
| 186 // Do not delegate any requests which are already pending. | |
| 187 bool should_delegate_request = true; | |
| 188 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
| 189 !it.IsAtEnd(); it.Advance()) { | |
| 190 if (permission == it.GetCurrentValue()->permission) { | |
| 191 should_delegate_request = false; | |
| 192 break; | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 const GURL& embedding_origin = | |
| 197 content::WebContents::FromRenderFrameHost(render_frame_host) | |
| 198 ->GetLastCommittedURL().GetOrigin(); | |
| 199 | |
| 200 int request_id = kNoPendingOperation; | |
| 201 switch (permission) { | |
| 202 case PermissionType::GEOLOCATION: | |
| 203 request_id = pending_requests_.Add(new PendingRequest( | |
| 204 permission, requesting_origin, | |
| 205 embedding_origin, render_frame_host, | |
| 206 callback)); | |
| 207 if (should_delegate_request) { | |
| 208 delegate->RequestGeolocationPermission( | |
| 209 requesting_origin, | |
| 210 base::Bind(&OnRequestResponse, | |
| 211 weak_ptr_factory_.GetWeakPtr(), request_id, | |
| 212 callback)); | |
| 213 } | |
| 214 break; | |
| 215 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 216 request_id = pending_requests_.Add(new PendingRequest( | |
| 217 permission, requesting_origin, | |
| 218 embedding_origin, render_frame_host, | |
| 219 callback)); | |
| 220 if (should_delegate_request) { | |
| 221 delegate->RequestProtectedMediaIdentifierPermission( | |
| 222 requesting_origin, | |
| 223 base::Bind(&OnRequestResponse, | |
| 224 weak_ptr_factory_.GetWeakPtr(), request_id, | |
| 225 callback)); | |
| 226 } | |
| 227 break; | |
| 228 case PermissionType::MIDI_SYSEX: | |
| 229 request_id = pending_requests_.Add(new PendingRequest( | |
| 230 permission, requesting_origin, | |
| 231 embedding_origin, render_frame_host, | |
| 232 callback)); | |
| 233 if (should_delegate_request) { | |
| 234 delegate->RequestMIDISysexPermission( | |
| 235 requesting_origin, | |
| 236 base::Bind(&OnRequestResponse, | |
| 237 weak_ptr_factory_.GetWeakPtr(), request_id, | |
| 238 callback)); | |
| 239 } | |
| 240 break; | |
| 241 case PermissionType::AUDIO_CAPTURE: | |
| 242 case PermissionType::VIDEO_CAPTURE: | |
| 243 case PermissionType::NOTIFICATIONS: | |
| 244 case PermissionType::PUSH_MESSAGING: | |
| 245 case PermissionType::DURABLE_STORAGE: | |
| 246 case PermissionType::BACKGROUND_SYNC: | |
| 247 NOTIMPLEMENTED() << "RequestPermission is not implemented for " | |
| 248 << static_cast<int>(permission); | |
| 249 callback.Run(PermissionStatus::DENIED); | |
| 250 break; | |
| 251 case PermissionType::MIDI: | |
| 252 callback.Run(PermissionStatus::GRANTED); | |
| 253 break; | |
| 254 case PermissionType::NUM: | |
| 255 NOTREACHED() << "PermissionType::NUM was not expected here."; | |
| 256 callback.Run(PermissionStatus::DENIED); | |
| 257 break; | |
| 258 } | |
| 259 return request_id; | |
| 260 } | 260 } |
| 261 | 261 |
| 262 int AwPermissionManager::RequestPermissions( | 262 int AwPermissionManager::RequestPermissions( |
| 263 const std::vector<PermissionType>& permissions, | 263 const std::vector<PermissionType>& permissions, |
| 264 content::RenderFrameHost* render_frame_host, | 264 content::RenderFrameHost* render_frame_host, |
| 265 const GURL& requesting_origin, | 265 const GURL& requesting_origin, |
| 266 bool user_gesture, | 266 bool user_gesture, |
| 267 const base::Callback<void( | 267 const base::Callback<void(const std::vector<PermissionStatus>&)>& |
| 268 const std::vector<PermissionStatus>&)>& callback) { | 268 callback) { |
| 269 NOTIMPLEMENTED() << "RequestPermissions has not been implemented in WebView"; | 269 if (permissions.empty()) { |
| 270 callback.Run(std::vector<PermissionStatus>()); | |
| 271 return kNoPendingOperation; | |
| 272 } | |
| 270 | 273 |
| 271 std::vector<PermissionStatus> result(permissions.size()); | 274 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 275 int render_frame_id = render_frame_host->GetRoutingID(); | |
| 276 AwBrowserPermissionRequestDelegate* delegate = | |
| 277 AwBrowserPermissionRequestDelegate::FromID(render_process_id, | |
| 278 render_frame_id); | |
| 279 if (!delegate) { | |
| 280 DVLOG(0) << "Dropping permissions request"; | |
| 281 callback.Run(std::vector<PermissionStatus>(permissions.size(), | |
| 282 PermissionStatus::DENIED)); | |
| 283 return kNoPendingOperation; | |
| 284 } | |
| 285 | |
| 272 const GURL& embedding_origin = | 286 const GURL& embedding_origin = |
| 273 content::WebContents::FromRenderFrameHost(render_frame_host) | 287 content::WebContents::FromRenderFrameHost(render_frame_host) |
| 274 ->GetLastCommittedURL().GetOrigin(); | 288 ->GetLastCommittedURL().GetOrigin(); |
| 275 | 289 |
| 276 for (PermissionType type : permissions) { | 290 PendingRequest* pending_request = |
| 277 result.push_back(GetPermissionStatus( | 291 new PendingRequest(permissions, requesting_origin, embedding_origin, |
| 278 type, requesting_origin, embedding_origin)); | 292 render_frame_host, callback); |
| 293 std::vector<bool> should_delegate_requests = | |
| 294 std::vector<bool>(permissions.size()); | |
| 295 for (size_t i = 0; i < permissions.size(); ++i) { | |
| 296 bool should_delegate_request = true; | |
| 297 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
| 298 !it.IsAtEnd(); it.Advance()) { | |
| 299 if (it.GetCurrentValue()->HasPermissionType(permissions[i])) { | |
| 300 // TODO(toyoshim): Shall we check to match requesting_origin too? | |
| 301 should_delegate_request = false; | |
| 302 if (it.GetCurrentValue()->IsComplete(permissions[i])) { | |
| 303 pending_request->SetPermissionStatus( | |
| 304 i, it.GetCurrentValue()->GetPermissionStatus(permissions[i])); | |
| 305 } | |
| 306 break; | |
| 307 } | |
| 308 } | |
| 309 should_delegate_requests[i] = should_delegate_request; | |
| 279 } | 310 } |
| 280 | 311 |
| 281 callback.Run(result); | 312 int request_id = pending_requests_.Add(pending_request); |
| 282 return kNoPendingOperation; | 313 |
| 314 for (size_t i = 0; i < permissions.size(); ++i) { | |
| 315 if (!should_delegate_requests[i]) | |
| 316 continue; | |
| 317 | |
| 318 switch (permissions[i]) { | |
| 319 case PermissionType::GEOLOCATION: | |
| 320 delegate->RequestGeolocationPermission( | |
| 321 requesting_origin, | |
| 322 base::Bind(&OnRequestResponse, weak_ptr_factory_.GetWeakPtr(), | |
| 323 request_id, i)); | |
| 324 break; | |
| 325 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 326 delegate->RequestProtectedMediaIdentifierPermission( | |
| 327 requesting_origin, | |
| 328 base::Bind(&OnRequestResponse, weak_ptr_factory_.GetWeakPtr(), | |
| 329 request_id, i)); | |
| 330 break; | |
| 331 case PermissionType::MIDI_SYSEX: | |
| 332 delegate->RequestMIDISysexPermission( | |
| 333 requesting_origin, | |
| 334 base::Bind(&OnRequestResponse, weak_ptr_factory_.GetWeakPtr(), | |
| 335 request_id, i)); | |
| 336 break; | |
| 337 case PermissionType::AUDIO_CAPTURE: | |
| 338 case PermissionType::VIDEO_CAPTURE: | |
| 339 case PermissionType::NOTIFICATIONS: | |
| 340 case PermissionType::PUSH_MESSAGING: | |
| 341 case PermissionType::DURABLE_STORAGE: | |
| 342 case PermissionType::BACKGROUND_SYNC: | |
| 343 NOTIMPLEMENTED() << "RequestPermissions is not implemented for " | |
| 344 << static_cast<int>(permissions[i]); | |
| 345 pending_request->SetPermissionStatus(i, PermissionStatus::DENIED); | |
| 346 break; | |
| 347 case PermissionType::MIDI: | |
| 348 pending_request->SetPermissionStatus(i, PermissionStatus::GRANTED); | |
| 349 break; | |
| 350 case PermissionType::NUM: | |
| 351 NOTREACHED() << "PermissionType::NUM was not expected here."; | |
| 352 pending_request->SetPermissionStatus(i, PermissionStatus::DENIED); | |
| 353 break; | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 // If delegate resolve the permission synchronously, all requests could be | |
| 358 // already resolved here. | |
| 359 if (!pending_requests_.Lookup(request_id)) | |
| 360 return kNoPendingOperation; | |
| 361 | |
| 362 // If requests are resolved without calling delegate functions, e.g. | |
| 363 // PermissionType::MIDI is permitted within the previous for-loop, all | |
| 364 // requests could be already resolved, but still in the |pending_requests_| | |
| 365 // without invoking the callback. | |
| 366 if (pending_request->IsComplete()) { | |
| 367 std::vector<PermissionStatus> results = pending_request->results; | |
| 368 pending_requests_.Remove(request_id); | |
| 369 callback.Run(results); | |
| 370 return kNoPendingOperation; | |
| 371 } | |
| 372 | |
| 373 return request_id; | |
| 283 } | 374 } |
| 284 | 375 |
| 285 // static | 376 // static |
| 286 void AwPermissionManager::OnRequestResponse( | 377 void AwPermissionManager::OnRequestResponse( |
| 287 const base::WeakPtr<AwPermissionManager>& manager, | 378 const base::WeakPtr<AwPermissionManager>& manager, |
| 288 int request_id, | 379 int request_id, |
| 289 const base::Callback<void(PermissionStatus)>& callback, | 380 int request_index, |
| 290 bool allowed) { | 381 bool allowed) { |
| 382 // All delegate functions should be cancelled when the manager runs | |
| 383 // destructor. Therefore |manager| should be always valid here. | |
| 384 DCHECK(manager); | |
| 385 | |
| 291 PermissionStatus status = | 386 PermissionStatus status = |
| 292 allowed ? PermissionStatus::GRANTED : PermissionStatus::DENIED; | 387 allowed ? PermissionStatus::GRANTED : PermissionStatus::DENIED; |
| 293 if (manager.get()) { | 388 PendingRequest* pending_request = |
| 294 PendingRequest* pending_request = | 389 manager->pending_requests_.Lookup(request_id); |
| 295 manager->pending_requests_.Lookup(request_id); | 390 PermissionType permission_type = pending_request->permissions[request_index]; |
| 296 | 391 |
| 297 for (PendingRequestsMap::Iterator<PendingRequest> it( | 392 manager->result_cache_->SetResult(permission_type, |
| 298 &manager->pending_requests_); | 393 pending_request->requesting_origin, |
| 299 !it.IsAtEnd(); it.Advance()) { | 394 pending_request->embedding_origin, status); |
| 300 if (pending_request->permission == it.GetCurrentValue()->permission && | 395 |
| 301 it.GetCurrentKey() != request_id) { | 396 std::vector<int> complete_request_ids; |
| 302 it.GetCurrentValue()->callback.Run(status); | 397 std::vector<std::pair<const RequestPermissionsCallback, |
| 303 manager->pending_requests_.Remove(it.GetCurrentKey()); | 398 std::vector<PermissionStatus>>> |
| 399 complete_request_pairs; | |
| 400 for (PendingRequestsMap::Iterator<PendingRequest> it( | |
| 401 &manager->pending_requests_); | |
| 402 !it.IsAtEnd(); it.Advance()) { | |
| 403 it.GetCurrentValue()->SetPermissionStatus(permission_type, status); | |
| 404 if (it.GetCurrentValue()->IsComplete()) { | |
| 405 complete_request_ids.push_back(it.GetCurrentKey()); | |
| 406 if (!it.GetCurrentValue()->IsCancelled()) { | |
| 407 complete_request_pairs.push_back(std::make_pair( | |
| 408 it.GetCurrentValue()->callback, it.GetCurrentValue()->results)); | |
| 304 } | 409 } |
| 305 } | 410 } |
| 306 | |
| 307 manager->result_cache_->SetResult( | |
| 308 pending_request->permission, | |
| 309 pending_request->requesting_origin, | |
| 310 pending_request->embedding_origin, | |
| 311 status); | |
| 312 manager->pending_requests_.Remove(request_id); | |
| 313 } | 411 } |
| 314 callback.Run(status); | 412 for (auto id : complete_request_ids) |
| 413 manager->pending_requests_.Remove(id); | |
| 414 for (auto pair : complete_request_pairs) | |
| 415 pair.first.Run(pair.second); | |
| 315 } | 416 } |
| 316 | 417 |
| 317 void AwPermissionManager::CancelPermissionRequest(int request_id) { | 418 void AwPermissionManager::CancelPermissionRequest(int request_id) { |
| 318 PendingRequest* pending_request = pending_requests_.Lookup(request_id); | 419 PendingRequest* pending_request = pending_requests_.Lookup(request_id); |
| 319 if (!pending_request) | 420 if (!pending_request || pending_request->IsCancelled()) |
| 320 return; | 421 return; |
| 422 pending_request->Cancel(); | |
| 321 | 423 |
| 322 content::RenderFrameHost* render_frame_host = | 424 const GURL& embedding_origin = pending_request->embedding_origin; |
| 323 content::RenderFrameHost::FromID(pending_request->render_process_id, | 425 const GURL& requesting_origin = pending_request->requesting_origin; |
| 324 pending_request->render_frame_id); | 426 for (auto permission : pending_request->permissions) |
| 325 content::WebContents* web_contents = | 427 result_cache_->ClearResult(permission, requesting_origin, embedding_origin); |
| 326 content::WebContents::FromRenderFrameHost(render_frame_host); | |
| 327 DCHECK(web_contents); | |
| 328 | |
| 329 // The caller is canceling (presumably) the most recent request. Assuming the | |
| 330 // request did not complete, the user did not respond to the requset. | |
| 331 // Thus, assume we do not know the result. | |
| 332 const GURL& embedding_origin = web_contents | |
| 333 ->GetLastCommittedURL().GetOrigin(); | |
| 334 result_cache_->ClearResult( | |
| 335 pending_request->permission, | |
| 336 pending_request->requesting_origin, | |
| 337 embedding_origin); | |
| 338 | 428 |
| 339 AwBrowserPermissionRequestDelegate* delegate = | 429 AwBrowserPermissionRequestDelegate* delegate = |
| 340 AwBrowserPermissionRequestDelegate::FromID( | 430 AwBrowserPermissionRequestDelegate::FromID( |
| 341 pending_request->render_process_id, | 431 pending_request->render_process_id, |
| 342 pending_request->render_frame_id); | 432 pending_request->render_frame_id); |
| 343 if (!delegate) { | 433 if (!delegate) { |
| 344 pending_requests_.Remove(request_id); | 434 pending_requests_.Remove(request_id); |
| 345 return; | 435 return; |
| 346 } | 436 } |
| 347 | 437 |
| 348 switch (pending_request->permission) { | 438 for (auto permission : pending_request->permissions) { |
| 349 case PermissionType::GEOLOCATION: | 439 // If the permission was already resolved, we do not need to cancel it. |
| 350 delegate->CancelGeolocationPermissionRequests( | 440 if (pending_request->IsComplete(permission)) |
| 351 pending_request->requesting_origin); | 441 continue; |
| 352 break; | 442 |
| 353 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 443 // If another pending_request waits for the same permission being resolved, |
| 354 delegate->CancelProtectedMediaIdentifierPermissionRequests( | 444 // we should not cancel the request. |
| 355 pending_request->requesting_origin); | 445 bool should_not_cancel_ = false; |
| 356 break; | 446 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
| 357 case PermissionType::MIDI_SYSEX: | 447 !it.IsAtEnd(); it.Advance()) { |
| 358 delegate->CancelMIDISysexPermissionRequests( | 448 if (it.GetCurrentValue() == pending_request) |
| 359 pending_request->requesting_origin); | 449 continue; |
| 360 break; | 450 // We need to check if |permission| was resolved for the current request |
| 361 case PermissionType::NOTIFICATIONS: | 451 // in addition to the |pending_request|. This is because |permission| |
| 362 case PermissionType::PUSH_MESSAGING: | 452 // might be resolved for the current request before |pending_request| was |
| 363 case PermissionType::DURABLE_STORAGE: | 453 // issued. |
| 364 case PermissionType::AUDIO_CAPTURE: | 454 if (it.GetCurrentValue()->HasPermissionType(permission) && |
|
Tobias Sargeant
2016/07/14 10:03:40
checking the requesting origin when making the req
Takashi Toyoshima
2016/07/14 12:40:49
Done.
| |
| 365 case PermissionType::VIDEO_CAPTURE: | 455 !it.GetCurrentValue()->IsComplete(permission)) { |
| 366 case PermissionType::BACKGROUND_SYNC: | 456 should_not_cancel_ = true; |
| 367 NOTIMPLEMENTED() << "CancelPermission not implemented for " | 457 break; |
| 368 << static_cast<int>(pending_request->permission); | 458 } |
| 369 break; | 459 } |
| 370 case PermissionType::MIDI: | 460 if (should_not_cancel_) |
| 371 // There is nothing to cancel so this is simply ignored. | 461 continue; |
| 372 break; | 462 |
| 373 case PermissionType::NUM: | 463 switch (permission) { |
| 374 NOTREACHED() << "PermissionType::NUM was not expected here."; | 464 case PermissionType::GEOLOCATION: |
| 375 break; | 465 delegate->CancelGeolocationPermissionRequests(requesting_origin); |
| 466 break; | |
| 467 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 468 delegate->CancelProtectedMediaIdentifierPermissionRequests( | |
| 469 requesting_origin); | |
| 470 break; | |
| 471 case PermissionType::MIDI_SYSEX: | |
| 472 delegate->CancelMIDISysexPermissionRequests(requesting_origin); | |
| 473 break; | |
| 474 case PermissionType::NOTIFICATIONS: | |
| 475 case PermissionType::PUSH_MESSAGING: | |
| 476 case PermissionType::DURABLE_STORAGE: | |
| 477 case PermissionType::AUDIO_CAPTURE: | |
| 478 case PermissionType::VIDEO_CAPTURE: | |
| 479 case PermissionType::BACKGROUND_SYNC: | |
| 480 NOTIMPLEMENTED() << "CancelPermission not implemented for " | |
| 481 << static_cast<int>(permission); | |
| 482 break; | |
| 483 case PermissionType::MIDI: | |
| 484 // There is nothing to cancel so this is simply ignored. | |
| 485 break; | |
| 486 case PermissionType::NUM: | |
| 487 NOTREACHED() << "PermissionType::NUM was not expected here."; | |
| 488 break; | |
| 489 } | |
| 490 pending_request->SetPermissionStatus(permission, PermissionStatus::DENIED); | |
| 376 } | 491 } |
| 377 | 492 |
| 378 pending_requests_.Remove(request_id); | 493 // If there are still active requests, we should not remove request_id here, |
| 494 // but just do not invoke a relevant callback when the request is resolved in | |
| 495 // OnRequestResponse(). | |
| 496 if (pending_request->IsComplete()) | |
| 497 pending_requests_.Remove(request_id); | |
| 379 } | 498 } |
| 380 | 499 |
| 381 void AwPermissionManager::ResetPermission(PermissionType permission, | 500 void AwPermissionManager::ResetPermission(PermissionType permission, |
| 382 const GURL& requesting_origin, | 501 const GURL& requesting_origin, |
| 383 const GURL& embedding_origin) { | 502 const GURL& embedding_origin) { |
| 384 result_cache_->ClearResult(permission, requesting_origin, embedding_origin); | 503 result_cache_->ClearResult(permission, requesting_origin, embedding_origin); |
| 385 } | 504 } |
| 386 | 505 |
| 387 PermissionStatus AwPermissionManager::GetPermissionStatus( | 506 PermissionStatus AwPermissionManager::GetPermissionStatus( |
| 388 PermissionType permission, | 507 PermissionType permission, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 411 const GURL& embedding_origin, | 530 const GURL& embedding_origin, |
| 412 const base::Callback<void(PermissionStatus)>& callback) { | 531 const base::Callback<void(PermissionStatus)>& callback) { |
| 413 return kNoPendingOperation; | 532 return kNoPendingOperation; |
| 414 } | 533 } |
| 415 | 534 |
| 416 void AwPermissionManager::UnsubscribePermissionStatusChange( | 535 void AwPermissionManager::UnsubscribePermissionStatusChange( |
| 417 int subscription_id) { | 536 int subscription_id) { |
| 418 } | 537 } |
| 419 | 538 |
| 420 } // namespace android_webview | 539 } // namespace android_webview |
| OLD | NEW |