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/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 // PermissionRequestManager ---------------------------------------------------- | 73 // PermissionRequestManager ---------------------------------------------------- |
74 | 74 |
75 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionRequestManager); | 75 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionRequestManager); |
76 | 76 |
77 PermissionRequestManager::PermissionRequestManager( | 77 PermissionRequestManager::PermissionRequestManager( |
78 content::WebContents* web_contents) | 78 content::WebContents* web_contents) |
79 : content::WebContentsObserver(web_contents), | 79 : content::WebContentsObserver(web_contents), |
80 view_factory_(base::Bind(&PermissionPrompt::Create)), | 80 view_factory_(base::Bind(&PermissionPrompt::Create)), |
81 view_(nullptr), | 81 view_(nullptr), |
| 82 browser_visible_(true), |
82 main_frame_has_fully_loaded_(false), | 83 main_frame_has_fully_loaded_(false), |
83 persist_(true), | 84 persist_(true), |
84 auto_response_for_test_(NONE), | 85 auto_response_for_test_(NONE), |
85 weak_factory_(this) {} | 86 weak_factory_(this) {} |
86 | 87 |
87 PermissionRequestManager::~PermissionRequestManager() { | 88 PermissionRequestManager::~PermissionRequestManager() { |
88 if (view_ != NULL) | 89 if (view_ != NULL) |
89 view_->SetDelegate(NULL); | 90 view_->SetDelegate(NULL); |
90 | 91 |
91 for (PermissionRequest* request : requests_) | 92 for (PermissionRequest* request : requests_) |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 content::BrowserThread::PostTask( | 366 content::BrowserThread::PostTask( |
366 content::BrowserThread::UI, | 367 content::BrowserThread::UI, |
367 FROM_HERE, | 368 FROM_HERE, |
368 base::Bind(&PermissionRequestManager::TriggerShowBubble, | 369 base::Bind(&PermissionRequestManager::TriggerShowBubble, |
369 weak_factory_.GetWeakPtr())); | 370 weak_factory_.GetWeakPtr())); |
370 } | 371 } |
371 | 372 |
372 void PermissionRequestManager::TriggerShowBubble() { | 373 void PermissionRequestManager::TriggerShowBubble() { |
373 if (!view_) | 374 if (!view_) |
374 return; | 375 return; |
| 376 if (!browser_visible_) |
| 377 return; |
375 if (IsBubbleVisible()) | 378 if (IsBubbleVisible()) |
376 return; | 379 return; |
377 if (!main_frame_has_fully_loaded_) | 380 if (!main_frame_has_fully_loaded_) |
378 return; | 381 return; |
379 if (requests_.empty() && queued_requests_.empty() && | 382 if (requests_.empty() && queued_requests_.empty() && |
380 queued_frame_requests_.empty()) { | 383 queued_frame_requests_.empty()) { |
381 return; | 384 return; |
382 } | 385 } |
383 | 386 |
384 if (requests_.empty()) { | 387 if (requests_.empty()) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 504 } |
502 | 505 |
503 void PermissionRequestManager::AddObserver(Observer* observer) { | 506 void PermissionRequestManager::AddObserver(Observer* observer) { |
504 observer_list_.AddObserver(observer); | 507 observer_list_.AddObserver(observer); |
505 } | 508 } |
506 | 509 |
507 void PermissionRequestManager::RemoveObserver(Observer* observer) { | 510 void PermissionRequestManager::RemoveObserver(Observer* observer) { |
508 observer_list_.RemoveObserver(observer); | 511 observer_list_.RemoveObserver(observer); |
509 } | 512 } |
510 | 513 |
| 514 void PermissionRequestManager::OnBrowserVisibilityChanged(bool visible) { |
| 515 browser_visible_ = visible; |
| 516 if (visible) |
| 517 ScheduleShowBubble(); |
| 518 } |
| 519 |
511 void PermissionRequestManager::NotifyBubbleAdded() { | 520 void PermissionRequestManager::NotifyBubbleAdded() { |
512 for (Observer& observer : observer_list_) | 521 for (Observer& observer : observer_list_) |
513 observer.OnBubbleAdded(); | 522 observer.OnBubbleAdded(); |
514 } | 523 } |
515 | 524 |
516 void PermissionRequestManager::DoAutoResponseForTesting() { | 525 void PermissionRequestManager::DoAutoResponseForTesting() { |
517 switch (auto_response_for_test_) { | 526 switch (auto_response_for_test_) { |
518 case ACCEPT_ALL: | 527 case ACCEPT_ALL: |
519 Accept(); | 528 Accept(); |
520 break; | 529 break; |
521 case DENY_ALL: | 530 case DENY_ALL: |
522 Deny(); | 531 Deny(); |
523 break; | 532 break; |
524 case DISMISS: | 533 case DISMISS: |
525 Closing(); | 534 Closing(); |
526 break; | 535 break; |
527 case NONE: | 536 case NONE: |
528 NOTREACHED(); | 537 NOTREACHED(); |
529 } | 538 } |
530 } | 539 } |
OLD | NEW |