Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/ui/website_settings/permission_bubble_manager.cc

Issue 176053002: [WebsiteSettings] Change permission bubble API to adapt to new mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/website_settings/permission_bubble_manager.h" 5 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 8 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 10
11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionBubbleManager); 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionBubbleManager);
12 12
13 namespace { 13 namespace {
14 14
15 // This is how many ms to wait to see if there's another permission request 15 // This is how many ms to wait to see if there's another permission request
16 // we should coalesce. 16 // we should coalesce.
17 const int kPermissionsCoalesceIntervalMs = 400; 17 const int kPermissionsCoalesceIntervalMs = 400;
18 18
19 } 19 }
20 20
21 // static 21 // static
22 bool PermissionBubbleManager::Enabled() { 22 bool PermissionBubbleManager::Enabled() {
23 return CommandLine::ForCurrentProcess()->HasSwitch( 23 return CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kEnablePermissionsBubbles); 24 switches::kEnablePermissionsBubbles);
25 } 25 }
26 26
27
28
29 PermissionBubbleManager::PermissionBubbleManager(
30 content::WebContents* web_contents)
31 : content::WebContentsObserver(web_contents),
32 bubble_showing_(false),
33 view_(NULL),
34 customization_mode_(false) {
35 timer_.reset(new base::Timer(FROM_HERE,
36 base::TimeDelta::FromMilliseconds(kPermissionsCoalesceIntervalMs),
37 base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)),
38 false));
39 }
40
41 PermissionBubbleManager::~PermissionBubbleManager() {
42 if (view_ != NULL)
43 view_->SetDelegate(NULL);
44
45 std::vector<PermissionBubbleRequest*>::iterator requests_iter;
46 for (requests_iter = requests_.begin();
47 requests_iter != requests_.end();
48 requests_iter++) {
49 (*requests_iter)->RequestFinished();
50 }
51 requests_.clear();
groby-ooo-7-16 2014/02/25 22:27:36 Why clear? The dtor does that already?
Greg Billock 2014/02/26 00:28:44 Just gives me a warm fuzzy. :-) I'll take it out.
52 accept_states_.clear();
53 for (requests_iter = queued_requests_.begin();
54 requests_iter != queued_requests_.end();
55 requests_iter++) {
56 (*requests_iter)->RequestFinished();
57 }
58 queued_requests_.clear();
59 }
60
27 void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) { 61 void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) {
28 // Don't re-add an existing request. 62 // Don't re-add an existing request or one with a duplicate text request.
29 std::vector<PermissionBubbleRequest*>::iterator requests_iter; 63 std::vector<PermissionBubbleRequest*>::iterator requests_iter;
30 for (requests_iter = requests_.begin(); 64 for (requests_iter = requests_.begin();
31 requests_iter != requests_.end(); 65 requests_iter != requests_.end();
32 requests_iter++) { 66 requests_iter++) {
33 if (*requests_iter == request) 67 if (*requests_iter == request)
34 return; 68 return;
69 if ((*requests_iter)->GetMessageTextFragment() ==
70 request->GetMessageTextFragment()) {
71 request->RequestFinished();
groby-ooo-7-16 2014/02/25 22:27:36 Is that really "RequestFinished"? Shouldn't that b
Greg Billock 2014/02/26 00:28:44 This is basically rejecting requests that the user
72 return;
73 }
74 }
75 for (requests_iter = queued_requests_.begin();
groby-ooo-7-16 2014/02/25 22:27:36 This is a lot of duplicated code - worth factoring
76 requests_iter != queued_requests_.end();
77 requests_iter++) {
78 if (*requests_iter == request)
79 return;
80 if ((*requests_iter)->GetMessageTextFragment() ==
81 request->GetMessageTextFragment()) {
82 request->RequestFinished();
83 return;
84 }
35 } 85 }
36 86
37 if (bubble_showing_) { 87 if (bubble_showing_) {
groby-ooo-7-16 2014/02/25 22:27:36 It's technically outside of this CL's scope, but:
Greg Billock 2014/02/26 00:28:44 The way I have the handshake working right now, th
38 for (requests_iter = queued_requests_.begin();
39 requests_iter != queued_requests_.end();
40 requests_iter++) {
41 if (*requests_iter == request)
42 return;
43 }
44 queued_requests_.push_back(request); 88 queued_requests_.push_back(request);
45 return; 89 return;
46 } 90 }
47 91
48 requests_.push_back(request); 92 requests_.push_back(request);
49 // TODO(gbillock): do we need to make default state a request property? 93 // TODO(gbillock): do we need to make default state a request property?
50 accept_states_.push_back(true); 94 accept_states_.push_back(true);
51 95
52 // Start the timer when there is both a view and a request. 96 // Start the timer when there is both a view and a request.
53 if (view_ && !timer_->IsRunning()) 97 if (view_ && !timer_->IsRunning())
54 timer_->Reset(); 98 timer_->Reset();
55 } 99 }
56 100
101 void PermissionBubbleManager::CancelRequest(PermissionBubbleRequest* request) {
102 // TODO(gbillock): implement
103 NOTREACHED();
104 }
groby-ooo-7-16 2014/02/25 22:27:36 Why add this if it doesn't do anything yet?
Greg Billock 2014/02/26 00:28:44 I was attempting to keep the scope of the CL down.
105
57 void PermissionBubbleManager::SetView(PermissionBubbleView* view) { 106 void PermissionBubbleManager::SetView(PermissionBubbleView* view) {
58 if (view == view_) 107 if (view == view_)
59 return; 108 return;
60 109
61 if (view_ != NULL) { 110 if (view_ != NULL) {
62 view_->SetDelegate(NULL); 111 view_->SetDelegate(NULL);
63 view_->Hide(); 112 view_->Hide();
64 bubble_showing_ = false; 113 bubble_showing_ = false;
65 } 114 }
66 115
67 view_ = view; 116 view_ = view;
68 if (view_) 117 if (view_)
69 view_->SetDelegate(this); 118 view_->SetDelegate(this);
70 else 119 else
71 return; 120 return;
72 121
73 // Even if there are requests queued up, add a short delay before the bubble 122 // Even if there are requests queued up, add a short delay before the bubble
74 // appears. 123 // appears.
75 if (!requests_.empty() && !timer_->IsRunning()) 124 if (!requests_.empty() && !timer_->IsRunning())
76 timer_->Reset(); 125 timer_->Reset();
77 else 126 else
78 view_->Hide(); 127 view_->Hide();
79 } 128 }
80 129
81 PermissionBubbleManager::PermissionBubbleManager(
82 content::WebContents* web_contents)
83 : content::WebContentsObserver(web_contents),
84 bubble_showing_(false),
85 view_(NULL),
86 customization_mode_(false) {
87 timer_.reset(new base::Timer(FROM_HERE,
88 base::TimeDelta::FromMilliseconds(kPermissionsCoalesceIntervalMs),
89 base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)),
90 false));
91 }
92
93 PermissionBubbleManager::~PermissionBubbleManager() {
94 if (view_ != NULL) {
95 view_->SetDelegate(NULL);
96 view_->Hide();
97 bubble_showing_ = false;
98 }
99 }
100
101 void PermissionBubbleManager::DidFinishLoad( 130 void PermissionBubbleManager::DidFinishLoad(
102 int64 frame_id, 131 int64 frame_id,
103 const GURL& validated_url, 132 const GURL& validated_url,
104 bool is_main_frame, 133 bool is_main_frame,
105 content::RenderViewHost* render_view_host) { 134 content::RenderViewHost* render_view_host) {
106 // Allows extra time for additional requests to coalesce. 135 // Allows extra time for additional requests to coalesce.
107 if (timer_->IsRunning()) 136 if (timer_->IsRunning())
108 timer_->Reset(); 137 timer_->Reset();
109 } 138 }
110 139
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 timer_->Reset(); 224 timer_->Reset();
196 } 225 }
197 } 226 }
198 227
199 void PermissionBubbleManager::SetCoalesceIntervalForTesting(int interval_ms) { 228 void PermissionBubbleManager::SetCoalesceIntervalForTesting(int interval_ms) {
200 timer_.reset(new base::Timer(FROM_HERE, 229 timer_.reset(new base::Timer(FROM_HERE,
201 base::TimeDelta::FromMilliseconds(interval_ms), 230 base::TimeDelta::FromMilliseconds(interval_ms),
202 base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)), 231 base::Bind(&PermissionBubbleManager::ShowBubble, base::Unretained(this)),
203 false)); 232 false));
204 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698