Commit 299f8665 authored by felt's avatar felt Committed by Commit bot

By default, remove user gesture restriction from permission bubbles

BUG=446607

Review URL: https://codereview.chromium.org/839063003

Cr-Commit-Position: refs/heads/master@{#311481}
parent 1c7c75c0
...@@ -67,6 +67,7 @@ bool PermissionBubbleManager::Enabled() { ...@@ -67,6 +67,7 @@ bool PermissionBubbleManager::Enabled() {
PermissionBubbleManager::PermissionBubbleManager( PermissionBubbleManager::PermissionBubbleManager(
content::WebContents* web_contents) content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
require_user_gesture_(false),
bubble_showing_(false), bubble_showing_(false),
view_(NULL), view_(NULL),
request_url_has_loaded_(false), request_url_has_loaded_(false),
...@@ -135,7 +136,7 @@ void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) { ...@@ -135,7 +136,7 @@ void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) {
queued_frame_requests_.push_back(request); queued_frame_requests_.push_back(request);
} }
if (request->HasUserGesture()) if (!require_user_gesture_ || request->HasUserGesture())
ScheduleShowBubble(); ScheduleShowBubble();
} }
...@@ -202,6 +203,10 @@ void PermissionBubbleManager::SetView(PermissionBubbleView* view) { ...@@ -202,6 +203,10 @@ void PermissionBubbleManager::SetView(PermissionBubbleView* view) {
TriggerShowBubble(); TriggerShowBubble();
} }
void PermissionBubbleManager::RequireUserGesture(bool required) {
require_user_gesture_ = required;
}
void PermissionBubbleManager::DocumentOnLoadCompletedInMainFrame() { void PermissionBubbleManager::DocumentOnLoadCompletedInMainFrame() {
request_url_has_loaded_ = true; request_url_has_loaded_ = true;
// This is scheduled because while all calls to the browser have been // This is scheduled because while all calls to the browser have been
......
...@@ -57,6 +57,12 @@ class PermissionBubbleManager ...@@ -57,6 +57,12 @@ class PermissionBubbleManager
// take ownership of the view. // take ownership of the view.
void SetView(PermissionBubbleView* view) override; void SetView(PermissionBubbleView* view) override;
// Controls whether incoming permission requests require user gestures.
// If |required| is false, requests will be displayed as soon as they come in.
// If |required| is true, requests will be silently queued until a request
// comes in with a user gesture.
void RequireUserGesture(bool required);
private: private:
friend class DownloadRequestLimiterTest; friend class DownloadRequestLimiterTest;
friend class PermissionBubbleManagerTest; friend class PermissionBubbleManagerTest;
...@@ -110,6 +116,10 @@ class PermissionBubbleManager ...@@ -110,6 +116,10 @@ class PermissionBubbleManager
bool HasUserGestureRequest( bool HasUserGestureRequest(
const std::vector<PermissionBubbleRequest*>& queue); const std::vector<PermissionBubbleRequest*>& queue);
// Whether to delay displaying the bubble until a request with a user gesture.
// False by default, unless RequireUserGesture(bool) changes the value.
bool require_user_gesture_;
// Whether or not we are showing the bubble in this tab. // Whether or not we are showing the bubble in this tab.
bool bubble_showing_; bool bubble_showing_;
......
...@@ -521,3 +521,43 @@ TEST_F(PermissionBubbleManagerTest, AllUserGestureRequests) { ...@@ -521,3 +521,43 @@ TEST_F(PermissionBubbleManagerTest, AllUserGestureRequests) {
EXPECT_TRUE(iframe_request_other_domain_.finished()); EXPECT_TRUE(iframe_request_other_domain_.finished());
EXPECT_FALSE(view_.shown_); EXPECT_FALSE(view_.shown_);
} }
TEST_F(PermissionBubbleManagerTest, RequestsWithoutUserGesture) {
manager_->RequireUserGesture(true);
manager_->SetView(&view_);
WaitForFrameLoad();
WaitForCoalescing();
manager_->AddRequest(&request1_);
manager_->AddRequest(&iframe_request_other_domain_);
manager_->AddRequest(&request2_);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(view_.shown_);
}
TEST_F(PermissionBubbleManagerTest, RequestsWithUserGesture) {
manager_->RequireUserGesture(true);
manager_->SetView(&view_);
WaitForFrameLoad();
WaitForCoalescing();
request1_.SetHasUserGesture();
manager_->AddRequest(&request1_);
manager_->AddRequest(&iframe_request_other_domain_);
manager_->AddRequest(&request2_);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_TRUE(view_.shown_);
}
TEST_F(PermissionBubbleManagerTest, RequestsDontNeedUserGesture) {
manager_->SetView(&view_);
WaitForFrameLoad();
WaitForCoalescing();
manager_->AddRequest(&request1_);
manager_->AddRequest(&iframe_request_other_domain_);
manager_->AddRequest(&request2_);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_TRUE(view_.shown_);
}
...@@ -35,8 +35,9 @@ class PermissionBubbleRequest { ...@@ -35,8 +35,9 @@ class PermissionBubbleRequest {
// next to an image and indicate the user grants the permission. // next to an image and indicate the user grants the permission.
virtual base::string16 GetMessageTextFragment() const = 0; virtual base::string16 GetMessageTextFragment() const = 0;
// Get whether this request was accompanied by a user gesture. User gestured // Get whether this request was accompanied by a user gesture. Non-gestured
// permissions requests will not be suppressed. // requests will be delayed if PermissionBubbleManager::
// RequireUserGesture(true) has been called on the manager.
virtual bool HasUserGesture() const = 0; virtual bool HasUserGesture() const = 0;
// Get the hostname on whose behalf this permission request is being made. // Get the hostname on whose behalf this permission request is being made.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment