| 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 "chrome/browser/permissions/permission_request_manager.h" | 5 #include "chrome/browser/permissions/permission_request_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionRequestManager); | 76 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionRequestManager); |
| 77 | 77 |
| 78 PermissionRequestManager::PermissionRequestManager( | 78 PermissionRequestManager::PermissionRequestManager( |
| 79 content::WebContents* web_contents) | 79 content::WebContents* web_contents) |
| 80 : content::WebContentsObserver(web_contents), | 80 : content::WebContentsObserver(web_contents), |
| 81 #if !defined(OS_ANDROID) // No bubbles in android tests. | 81 #if !defined(OS_ANDROID) // No bubbles in android tests. |
| 82 view_factory_(base::Bind(&PermissionPrompt::Create)), | 82 view_factory_(base::Bind(&PermissionPrompt::Create)), |
| 83 #endif | 83 #endif |
| 84 view_(nullptr), | 84 view_(nullptr), |
| 85 main_frame_has_fully_loaded_(false), | 85 main_frame_has_fully_loaded_(false), |
| 86 persist_(true), |
| 86 auto_response_for_test_(NONE), | 87 auto_response_for_test_(NONE), |
| 87 weak_factory_(this) { | 88 weak_factory_(this) { |
| 88 } | 89 } |
| 89 | 90 |
| 90 PermissionRequestManager::~PermissionRequestManager() { | 91 PermissionRequestManager::~PermissionRequestManager() { |
| 91 if (view_ != NULL) | 92 if (view_ != NULL) |
| 92 view_->SetDelegate(NULL); | 93 view_->SetDelegate(NULL); |
| 93 | 94 |
| 94 for (PermissionRequest* request : requests_) | 95 for (PermissionRequest* request : requests_) |
| 95 request->RequestFinished(); | 96 request->RequestFinished(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 web_contents()->RemoveUserData(UserDataKey()); | 304 web_contents()->RemoveUserData(UserDataKey()); |
| 304 // That was the equivalent of "delete this". This object is now destroyed; | 305 // That was the equivalent of "delete this". This object is now destroyed; |
| 305 // returning from this function is the only safe thing to do. | 306 // returning from this function is the only safe thing to do. |
| 306 } | 307 } |
| 307 | 308 |
| 308 void PermissionRequestManager::ToggleAccept(int request_index, bool new_value) { | 309 void PermissionRequestManager::ToggleAccept(int request_index, bool new_value) { |
| 309 DCHECK(request_index < static_cast<int>(accept_states_.size())); | 310 DCHECK(request_index < static_cast<int>(accept_states_.size())); |
| 310 accept_states_[request_index] = new_value; | 311 accept_states_[request_index] = new_value; |
| 311 } | 312 } |
| 312 | 313 |
| 314 void PermissionRequestManager::TogglePersist(bool new_value) { |
| 315 persist_ = new_value; |
| 316 } |
| 317 |
| 313 void PermissionRequestManager::Accept() { | 318 void PermissionRequestManager::Accept() { |
| 314 PermissionUmaUtil::PermissionPromptAccepted(requests_, accept_states_); | 319 PermissionUmaUtil::PermissionPromptAccepted(requests_, accept_states_); |
| 315 | 320 |
| 316 std::vector<PermissionRequest*>::iterator requests_iter; | 321 std::vector<PermissionRequest*>::iterator requests_iter; |
| 317 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); | 322 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); |
| 318 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); | 323 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); |
| 319 requests_iter != requests_.end(); | 324 requests_iter != requests_.end(); |
| 320 requests_iter++, accepts_iter++) { | 325 requests_iter++, accepts_iter++) { |
| 321 if (*accepts_iter) { | 326 if (*accepts_iter) { |
| 322 PermissionGrantedIncludingDuplicates(*requests_iter); | 327 PermissionGrantedIncludingDuplicates(*requests_iter); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 for (PermissionRequest* existing_request : queued_frame_requests_) | 443 for (PermissionRequest* existing_request : queued_frame_requests_) |
| 439 if (IsMessageTextEqual(existing_request, request)) | 444 if (IsMessageTextEqual(existing_request, request)) |
| 440 return existing_request; | 445 return existing_request; |
| 441 return nullptr; | 446 return nullptr; |
| 442 } | 447 } |
| 443 | 448 |
| 444 void PermissionRequestManager::PermissionGrantedIncludingDuplicates( | 449 void PermissionRequestManager::PermissionGrantedIncludingDuplicates( |
| 445 PermissionRequest* request) { | 450 PermissionRequest* request) { |
| 446 DCHECK_EQ(request, GetExistingRequest(request)) | 451 DCHECK_EQ(request, GetExistingRequest(request)) |
| 447 << "Only requests in [queued_[frame_]]requests_ can have duplicates"; | 452 << "Only requests in [queued_[frame_]]requests_ can have duplicates"; |
| 453 request->set_persist(persist_); |
| 448 request->PermissionGranted(); | 454 request->PermissionGranted(); |
| 449 auto range = duplicate_requests_.equal_range(request); | 455 auto range = duplicate_requests_.equal_range(request); |
| 450 for (auto it = range.first; it != range.second; ++it) | 456 for (auto it = range.first; it != range.second; ++it) { |
| 457 it->second->set_persist(persist_); |
| 451 it->second->PermissionGranted(); | 458 it->second->PermissionGranted(); |
| 459 } |
| 452 } | 460 } |
| 453 void PermissionRequestManager::PermissionDeniedIncludingDuplicates( | 461 void PermissionRequestManager::PermissionDeniedIncludingDuplicates( |
| 454 PermissionRequest* request) { | 462 PermissionRequest* request) { |
| 455 DCHECK_EQ(request, GetExistingRequest(request)) | 463 DCHECK_EQ(request, GetExistingRequest(request)) |
| 456 << "Only requests in [queued_[frame_]]requests_ can have duplicates"; | 464 << "Only requests in [queued_[frame_]]requests_ can have duplicates"; |
| 465 request->set_persist(persist_); |
| 457 request->PermissionDenied(); | 466 request->PermissionDenied(); |
| 458 auto range = duplicate_requests_.equal_range(request); | 467 auto range = duplicate_requests_.equal_range(request); |
| 459 for (auto it = range.first; it != range.second; ++it) | 468 for (auto it = range.first; it != range.second; ++it) { |
| 469 it->second->set_persist(persist_); |
| 460 it->second->PermissionDenied(); | 470 it->second->PermissionDenied(); |
| 471 } |
| 461 } | 472 } |
| 462 void PermissionRequestManager::CancelledIncludingDuplicates( | 473 void PermissionRequestManager::CancelledIncludingDuplicates( |
| 463 PermissionRequest* request) { | 474 PermissionRequest* request) { |
| 464 DCHECK_EQ(request, GetExistingRequest(request)) | 475 DCHECK_EQ(request, GetExistingRequest(request)) |
| 465 << "Only requests in [queued_[frame_]]requests_ can have duplicates"; | 476 << "Only requests in [queued_[frame_]]requests_ can have duplicates"; |
| 466 request->Cancelled(); | 477 request->Cancelled(); |
| 467 auto range = duplicate_requests_.equal_range(request); | 478 auto range = duplicate_requests_.equal_range(request); |
| 468 for (auto it = range.first; it != range.second; ++it) | 479 for (auto it = range.first; it != range.second; ++it) |
| 469 it->second->Cancelled(); | 480 it->second->Cancelled(); |
| 470 } | 481 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 case DENY_ALL: | 518 case DENY_ALL: |
| 508 Deny(); | 519 Deny(); |
| 509 break; | 520 break; |
| 510 case DISMISS: | 521 case DISMISS: |
| 511 Closing(); | 522 Closing(); |
| 512 break; | 523 break; |
| 513 case NONE: | 524 case NONE: |
| 514 NOTREACHED(); | 525 NOTREACHED(); |
| 515 } | 526 } |
| 516 } | 527 } |
| OLD | NEW |