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

Side by Side Diff: chrome/browser/extensions/extension_message_bubble_controller.cc

Issue 2076093004: [Extensions UI] Handle multiple warning bubbles racing to show (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: woot Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/extension_message_bubble_controller.h" 5 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 acknowledged_pref_name_ = pref_name; 93 acknowledged_pref_name_ = pref_name;
94 } 94 }
95 95
96 //////////////////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////////////////
97 // ExtensionMessageBubbleController 97 // ExtensionMessageBubbleController
98 98
99 ExtensionMessageBubbleController::ExtensionMessageBubbleController( 99 ExtensionMessageBubbleController::ExtensionMessageBubbleController(
100 Delegate* delegate, 100 Delegate* delegate,
101 Browser* browser) 101 Browser* browser)
102 : browser_(browser), 102 : browser_(browser),
103 model_(ToolbarActionsModel::Get(browser_->profile())),
103 user_action_(ACTION_BOUNDARY), 104 user_action_(ACTION_BOUNDARY),
104 delegate_(delegate), 105 delegate_(delegate),
105 initialized_(false), 106 initialized_(false),
106 did_highlight_(false), 107 did_highlight_(false),
108 is_active_bubble_(false),
107 browser_list_observer_(this) { 109 browser_list_observer_(this) {
108 browser_list_observer_.Add(BrowserList::GetInstance()); 110 browser_list_observer_.Add(BrowserList::GetInstance());
109 } 111 }
110 112
111 ExtensionMessageBubbleController::~ExtensionMessageBubbleController() { 113 ExtensionMessageBubbleController::~ExtensionMessageBubbleController() {
114 if (is_active_bubble_)
115 model_->set_has_active_bubble(false);
112 if (did_highlight_) 116 if (did_highlight_)
113 ToolbarActionsModel::Get(profile())->StopHighlighting(); 117 model_->StopHighlighting();
114 } 118 }
115 119
116 Profile* ExtensionMessageBubbleController::profile() { 120 Profile* ExtensionMessageBubbleController::profile() {
117 return browser_->profile(); 121 return browser_->profile();
118 } 122 }
119 123
120 bool ExtensionMessageBubbleController::ShouldShow() { 124 bool ExtensionMessageBubbleController::ShouldShow() {
121 std::set<Profile*>* profiles = GetProfileSet(); 125 std::set<Profile*>* profiles = GetProfileSet();
122 return !profiles->count(profile()->GetOriginalProfile()) && 126 return !profiles->count(profile()->GetOriginalProfile()) &&
127 (!model_->has_active_bubble() || is_active_bubble_) &&
123 !GetExtensionList().empty(); 128 !GetExtensionList().empty();
124 } 129 }
125 130
126 std::vector<base::string16> 131 std::vector<base::string16>
127 ExtensionMessageBubbleController::GetExtensionList() { 132 ExtensionMessageBubbleController::GetExtensionList() {
128 ExtensionIdList* list = GetOrCreateExtensionList(); 133 ExtensionIdList* list = GetOrCreateExtensionList();
129 if (list->empty()) 134 if (list->empty())
130 return std::vector<base::string16>(); 135 return std::vector<base::string16>();
131 136
132 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 137 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
(...skipping 30 matching lines...) Expand all
163 168
164 const ExtensionIdList& ExtensionMessageBubbleController::GetExtensionIdList() { 169 const ExtensionIdList& ExtensionMessageBubbleController::GetExtensionIdList() {
165 return *GetOrCreateExtensionList(); 170 return *GetOrCreateExtensionList();
166 } 171 }
167 172
168 bool ExtensionMessageBubbleController::CloseOnDeactivate() { 173 bool ExtensionMessageBubbleController::CloseOnDeactivate() {
169 return delegate_->ShouldCloseOnDeactivate(); 174 return delegate_->ShouldCloseOnDeactivate();
170 } 175 }
171 176
172 void ExtensionMessageBubbleController::HighlightExtensionsIfNecessary() { 177 void ExtensionMessageBubbleController::HighlightExtensionsIfNecessary() {
178 DCHECK(is_active_bubble_);
173 if (delegate_->ShouldHighlightExtensions() && !did_highlight_) { 179 if (delegate_->ShouldHighlightExtensions() && !did_highlight_) {
174 did_highlight_ = true; 180 did_highlight_ = true;
175 const ExtensionIdList& extension_ids = GetExtensionIdList(); 181 const ExtensionIdList& extension_ids = GetExtensionIdList();
176 DCHECK(!extension_ids.empty()); 182 DCHECK(!extension_ids.empty());
177 ToolbarActionsModel::Get(profile())->HighlightActions( 183 model_->HighlightActions(extension_ids,
178 extension_ids, ToolbarActionsModel::HIGHLIGHT_WARNING); 184 ToolbarActionsModel::HIGHLIGHT_WARNING);
179 } 185 }
180 } 186 }
181 187
182 void ExtensionMessageBubbleController::OnShown() { 188 void ExtensionMessageBubbleController::OnShown() {
189 DCHECK(is_active_bubble_);
183 GetProfileSet()->insert(profile()->GetOriginalProfile()); 190 GetProfileSet()->insert(profile()->GetOriginalProfile());
184 } 191 }
185 192
186 void ExtensionMessageBubbleController::OnBubbleAction() { 193 void ExtensionMessageBubbleController::OnBubbleAction() {
187 DCHECK_EQ(ACTION_BOUNDARY, user_action_); 194 DCHECK_EQ(ACTION_BOUNDARY, user_action_);
188 user_action_ = ACTION_EXECUTE; 195 user_action_ = ACTION_EXECUTE;
189 196
190 delegate_->LogAction(ACTION_EXECUTE); 197 delegate_->LogAction(ACTION_EXECUTE);
191 delegate_->PerformAction(*GetOrCreateExtensionList()); 198 delegate_->PerformAction(*GetOrCreateExtensionList());
192 199
(...skipping 28 matching lines...) Expand all
221 browser_->OpenURL( 228 browser_->OpenURL(
222 content::OpenURLParams(delegate_->GetLearnMoreUrl(), 229 content::OpenURLParams(delegate_->GetLearnMoreUrl(),
223 content::Referrer(), 230 content::Referrer(),
224 NEW_FOREGROUND_TAB, 231 NEW_FOREGROUND_TAB,
225 ui::PAGE_TRANSITION_LINK, 232 ui::PAGE_TRANSITION_LINK,
226 false)); 233 false));
227 } 234 }
228 OnClose(); 235 OnClose();
229 } 236 }
230 237
238 void ExtensionMessageBubbleController::SetIsActiveBubble() {
239 DCHECK(!is_active_bubble_);
240 DCHECK(!model_->has_active_bubble());
241 is_active_bubble_ = true;
242 model_->set_has_active_bubble(true);
243 }
244
231 void ExtensionMessageBubbleController::ClearProfileListForTesting() { 245 void ExtensionMessageBubbleController::ClearProfileListForTesting() {
232 GetProfileSet()->clear(); 246 GetProfileSet()->clear();
233 } 247 }
234 248
235 // static 249 // static
236 void ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( 250 void ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing(
237 bool should_ignore) { 251 bool should_ignore) {
238 g_should_ignore_learn_more_for_testing = should_ignore; 252 g_should_ignore_learn_more_for_testing = should_ignore;
239 } 253 }
240 254
241 void ExtensionMessageBubbleController::OnBrowserRemoved(Browser* browser) { 255 void ExtensionMessageBubbleController::OnBrowserRemoved(Browser* browser) {
242 if (browser == browser_ && did_highlight_) { 256 if (browser == browser_) {
243 ToolbarActionsModel::Get(profile())->StopHighlighting(); 257 if (did_highlight_) {
244 did_highlight_ = false; 258 model_->StopHighlighting();
259 did_highlight_ = false;
Finnur 2016/06/20 10:39:00 nit: The name of this variable is misleading. It *
Devlin 2016/06/20 17:58:39 Changed.
260 }
261 if (is_active_bubble_) {
262 model_->set_has_active_bubble(false);
263 is_active_bubble_ = false;
264 }
245 } 265 }
246 } 266 }
247 267
248 void ExtensionMessageBubbleController::AcknowledgeExtensions() { 268 void ExtensionMessageBubbleController::AcknowledgeExtensions() {
249 ExtensionIdList* list = GetOrCreateExtensionList(); 269 ExtensionIdList* list = GetOrCreateExtensionList();
250 for (ExtensionIdList::const_iterator it = list->begin(); 270 for (ExtensionIdList::const_iterator it = list->begin();
251 it != list->end(); ++it) 271 it != list->end(); ++it)
252 delegate_->AcknowledgeExtension(*it, user_action_); 272 delegate_->AcknowledgeExtension(*it, user_action_);
253 } 273 }
254 274
(...skipping 28 matching lines...) Expand all
283 if (delegate_->ClearProfileSetAfterAction()) 303 if (delegate_->ClearProfileSetAfterAction())
284 GetProfileSet()->clear(); 304 GetProfileSet()->clear();
285 } 305 }
286 } 306 }
287 307
288 std::set<Profile*>* ExtensionMessageBubbleController::GetProfileSet() { 308 std::set<Profile*>* ExtensionMessageBubbleController::GetProfileSet() {
289 return &g_shown_for_profiles.Get()[delegate_->GetKey()]; 309 return &g_shown_for_profiles.Get()[delegate_->GetKey()];
290 } 310 }
291 311
292 } // namespace extensions 312 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698