Commit ff534325 authored by gbillock@chromium.org's avatar gbillock@chromium.org

[WebsiteSettings] Update permission bubble manager policy

This policy is more in accord with the design doc changes. Moves to
showing the dialog upon DOMContentLoaded in source pages, and then
subsequently for user gestures.

R=leng@chromium.org
BUG=332115,364159

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266855 0039d316-1c4b-4281-b951-d872f2087c98
parent 7ee3c332
...@@ -71,7 +71,6 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { ...@@ -71,7 +71,6 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
PermissionBubbleManager* manager = PermissionBubbleManager* manager =
PermissionBubbleManager::FromWebContents(web_contents()); PermissionBubbleManager::FromWebContents(web_contents());
manager->SetView(view_.get()); manager->SetView(view_.get());
manager->SetCoalesceIntervalForTesting(0);
testing_action_ = ACCEPT; testing_action_ = ACCEPT;
ask_allow_count_ = cancel_count_ = continue_count_ = 0; ask_allow_count_ = cancel_count_ = continue_count_ = 0;
......
...@@ -7,17 +7,10 @@ ...@@ -7,17 +7,10 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/ui/website_settings/permission_bubble_request.h" #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionBubbleManager); DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionBubbleManager);
namespace {
// This is how many ms to wait to see if there's another permission request
// we should coalesce.
const int kPermissionsCoalesceIntervalMs = 400;
}
// static // static
bool PermissionBubbleManager::Enabled() { bool PermissionBubbleManager::Enabled() {
return CommandLine::ForCurrentProcess()->HasSwitch( return CommandLine::ForCurrentProcess()->HasSwitch(
...@@ -29,12 +22,8 @@ PermissionBubbleManager::PermissionBubbleManager( ...@@ -29,12 +22,8 @@ PermissionBubbleManager::PermissionBubbleManager(
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
bubble_showing_(false), bubble_showing_(false),
view_(NULL), view_(NULL),
customization_mode_(false) { request_url_has_loaded_(false),
timer_.reset(new base::Timer(FROM_HERE, customization_mode_(false) {}
base::TimeDelta::FromMilliseconds(kPermissionsCoalesceIntervalMs),
base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)),
false));
}
PermissionBubbleManager::~PermissionBubbleManager() { PermissionBubbleManager::~PermissionBubbleManager() {
if (view_ != NULL) if (view_ != NULL)
...@@ -97,9 +86,8 @@ void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) { ...@@ -97,9 +86,8 @@ void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) {
// TODO(gbillock): do we need to make default state a request property? // TODO(gbillock): do we need to make default state a request property?
accept_states_.push_back(true); accept_states_.push_back(true);
// Start the timer when there is both a view and a request. if (request->HasUserGesture())
if (view_ && !timer_->IsRunning()) ShowBubble();
timer_->Reset();
} }
void PermissionBubbleManager::CancelRequest(PermissionBubbleRequest* request) { void PermissionBubbleManager::CancelRequest(PermissionBubbleRequest* request) {
...@@ -123,22 +111,21 @@ void PermissionBubbleManager::SetView(PermissionBubbleView* view) { ...@@ -123,22 +111,21 @@ void PermissionBubbleManager::SetView(PermissionBubbleView* view) {
else else
return; return;
// Even if there are requests queued up, add a short delay before the bubble ShowBubble();
// appears.
if (!requests_.empty() && !timer_->IsRunning())
timer_->Reset();
else
view_->Hide();
} }
void PermissionBubbleManager::DidFinishLoad( void PermissionBubbleManager::DocumentOnLoadCompletedInMainFrame(
int64 frame_id, int32 page_id) {
const GURL& validated_url, request_url_has_loaded_ = true;
bool is_main_frame, // This is scheduled because while all calls to the browser have been
content::RenderViewHost* render_view_host) { // issued at DOMContentLoaded, they may be bouncing around in scheduled
// Allows extra time for additional requests to coalesce. // callbacks finding the UI thread still. This makes sure we allow those
if (timer_->IsRunning()) // scheduled calls to AddRequest to complete before we show the page-load
timer_->Reset(); // permissions bubble.
// TODO(gbillock): make this bind safe with a weak ptr.
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)));
} }
void PermissionBubbleManager::NavigationEntryCommitted( void PermissionBubbleManager::NavigationEntryCommitted(
...@@ -212,7 +199,8 @@ void PermissionBubbleManager::Closing() { ...@@ -212,7 +199,8 @@ void PermissionBubbleManager::Closing() {
} }
void PermissionBubbleManager::ShowBubble() { void PermissionBubbleManager::ShowBubble() {
if (view_ && !bubble_showing_ && requests_.size()) { if (view_ && !bubble_showing_ && request_url_has_loaded_ &&
requests_.size()) {
// Note: this should appear above Show() for testing, since in that // Note: this should appear above Show() for testing, since in that
// case we may do in-line calling of finalization. // case we may do in-line calling of finalization.
bubble_showing_ = true; bubble_showing_ = true;
...@@ -237,9 +225,7 @@ void PermissionBubbleManager::FinalizeBubble() { ...@@ -237,9 +225,7 @@ void PermissionBubbleManager::FinalizeBubble() {
requests_ = queued_requests_; requests_ = queued_requests_;
accept_states_.resize(requests_.size(), true); accept_states_.resize(requests_.size(), true);
queued_requests_.clear(); queued_requests_.clear();
// TODO(leng): Explore other options of showing the next bubble. The ShowBubble();
// advantage of this is that it uses the same code path as the first bubble.
timer_->Reset();
} else { } else {
request_url_ = GURL(); request_url_ = GURL();
} }
...@@ -253,10 +239,3 @@ void PermissionBubbleManager::CancelPendingQueue() { ...@@ -253,10 +239,3 @@ void PermissionBubbleManager::CancelPendingQueue() {
(*requests_iter)->RequestFinished(); (*requests_iter)->RequestFinished();
} }
} }
void PermissionBubbleManager::SetCoalesceIntervalForTesting(int interval_ms) {
timer_.reset(new base::Timer(FROM_HERE,
base::TimeDelta::FromMilliseconds(interval_ms),
base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)),
false));
}
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <vector> #include <vector>
#include "base/timer/timer.h"
#include "chrome/browser/ui/website_settings/permission_bubble_view.h" #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
...@@ -56,10 +55,6 @@ class PermissionBubbleManager ...@@ -56,10 +55,6 @@ class PermissionBubbleManager
// take ownership of the view. // take ownership of the view.
virtual void SetView(PermissionBubbleView* view) OVERRIDE; virtual void SetView(PermissionBubbleView* view) OVERRIDE;
protected:
// Sets the coalesce time interval to |interval_ms|. For testing only.
void SetCoalesceIntervalForTesting(int interval_ms);
private: private:
friend class PermissionBubbleManagerTest; friend class PermissionBubbleManagerTest;
friend class DownloadRequestLimiterTest; friend class DownloadRequestLimiterTest;
...@@ -67,15 +62,12 @@ class PermissionBubbleManager ...@@ -67,15 +62,12 @@ class PermissionBubbleManager
explicit PermissionBubbleManager(content::WebContents* web_contents); explicit PermissionBubbleManager(content::WebContents* web_contents);
// contents::WebContentsObserver: // WebContentsObserver:
// TODO(leng): Investigate the ordering and timing of page loading and
// permission requests with iFrames. DocumentOnLoadCompletedInMainFrame() // TODO(leng): Finalize policy for permission requests with iFrames.
// and DocumentLoadedInFrame() might be needed as well. // DocumentLoadedInFrame() might be needed as well.
virtual void DidFinishLoad( virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE;
int64 frame_id,
const GURL& validated_url,
bool is_main_frame,
content::RenderViewHost* render_view_host) OVERRIDE;
// If a page on which permissions requests are pending is navigated, // If a page on which permissions requests are pending is navigated,
// they will be finalized as if canceled by the user. // they will be finalized as if canceled by the user.
virtual void NavigationEntryCommitted( virtual void NavigationEntryCommitted(
...@@ -90,7 +82,6 @@ class PermissionBubbleManager ...@@ -90,7 +82,6 @@ class PermissionBubbleManager
virtual void Deny() OVERRIDE; virtual void Deny() OVERRIDE;
virtual void Closing() OVERRIDE; virtual void Closing() OVERRIDE;
// Called when the coalescing timer is done. Presents the bubble.
void ShowBubble(); void ShowBubble();
// Finalize the pending permissions request. // Finalize the pending permissions request.
...@@ -110,10 +101,9 @@ class PermissionBubbleManager ...@@ -110,10 +101,9 @@ class PermissionBubbleManager
std::vector<PermissionBubbleRequest*> requests_; std::vector<PermissionBubbleRequest*> requests_;
std::vector<PermissionBubbleRequest*> queued_requests_; std::vector<PermissionBubbleRequest*> queued_requests_;
GURL request_url_; GURL request_url_;
bool request_url_has_loaded_;
std::vector<bool> accept_states_; std::vector<bool> accept_states_;
bool customization_mode_; bool customization_mode_;
scoped_ptr<base::Timer> timer_;
}; };
#endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
...@@ -70,7 +70,6 @@ class PermissionBubbleManagerTest : public ChromeRenderViewHostTestHarness { ...@@ -70,7 +70,6 @@ class PermissionBubbleManagerTest : public ChromeRenderViewHostTestHarness {
SetContents(CreateTestWebContents()); SetContents(CreateTestWebContents());
manager_.reset(new PermissionBubbleManager(web_contents())); manager_.reset(new PermissionBubbleManager(web_contents()));
manager_->SetCoalesceIntervalForTesting(0);
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
...@@ -87,6 +86,7 @@ class PermissionBubbleManagerTest : public ChromeRenderViewHostTestHarness { ...@@ -87,6 +86,7 @@ class PermissionBubbleManagerTest : public ChromeRenderViewHostTestHarness {
} }
void WaitForCoalescing() { void WaitForCoalescing() {
manager_->DocumentOnLoadCompletedInMainFrame(0);
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
} }
...@@ -237,9 +237,8 @@ TEST_F(PermissionBubbleManagerTest, TwoRequestsShownInTwoBubbles) { ...@@ -237,9 +237,8 @@ TEST_F(PermissionBubbleManagerTest, TwoRequestsShownInTwoBubbles) {
view_.Hide(); view_.Hide();
Accept(); Accept();
EXPECT_FALSE(view_.shown_);
WaitForCoalescing(); WaitForCoalescing();
EXPECT_TRUE(view_.shown_); EXPECT_TRUE(view_.shown_);
ASSERT_EQ(1u, view_.permission_requests_.size()); ASSERT_EQ(1u, view_.permission_requests_.size());
EXPECT_EQ(&request2_, view_.permission_requests_[0]); EXPECT_EQ(&request2_, view_.permission_requests_[0]);
...@@ -326,8 +325,8 @@ TEST_F(PermissionBubbleManagerTest, ForgetRequestsOnPageNavigation) { ...@@ -326,8 +325,8 @@ TEST_F(PermissionBubbleManagerTest, ForgetRequestsOnPageNavigation) {
ASSERT_EQ(1u, view_.permission_requests_.size()); ASSERT_EQ(1u, view_.permission_requests_.size());
NavigateAndCommit(GURL("http://www2.google.com/")); NavigateAndCommit(GURL("http://www2.google.com/"));
WaitForCoalescing();
EXPECT_FALSE(view_.shown_);
EXPECT_TRUE(request1_.finished()); EXPECT_TRUE(request1_.finished());
EXPECT_TRUE(request2_.finished()); EXPECT_TRUE(request2_.finished());
} }
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