| OLD | NEW |
| 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 Loading... |
| 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 is_highlighting_(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() { |
| 112 if (did_highlight_) | 114 if (is_active_bubble_) |
| 113 ToolbarActionsModel::Get(profile())->StopHighlighting(); | 115 model_->set_has_active_bubble(false); |
| 116 if (is_highlighting_) |
| 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 Loading... |
| 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() { |
| 173 if (delegate_->ShouldHighlightExtensions() && !did_highlight_) { | 178 DCHECK(is_active_bubble_); |
| 174 did_highlight_ = true; | 179 if (delegate_->ShouldHighlightExtensions() && !is_highlighting_) { |
| 180 is_highlighting_ = 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 17 matching lines...) Expand all Loading... |
| 210 delegate_->LogAction(user_action_); | 217 delegate_->LogAction(user_action_); |
| 211 | 218 |
| 212 OnClose(); | 219 OnClose(); |
| 213 } | 220 } |
| 214 | 221 |
| 215 void ExtensionMessageBubbleController::OnLinkClicked() { | 222 void ExtensionMessageBubbleController::OnLinkClicked() { |
| 216 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | 223 DCHECK_EQ(ACTION_BOUNDARY, user_action_); |
| 217 user_action_ = ACTION_LEARN_MORE; | 224 user_action_ = ACTION_LEARN_MORE; |
| 218 | 225 |
| 219 delegate_->LogAction(ACTION_LEARN_MORE); | 226 delegate_->LogAction(ACTION_LEARN_MORE); |
| 227 // Opening a new tab for the learn more link can cause the bubble to close, so |
| 228 // perform our cleanup here before opening the new tab. |
| 229 OnClose(); |
| 220 if (!g_should_ignore_learn_more_for_testing) { | 230 if (!g_should_ignore_learn_more_for_testing) { |
| 221 browser_->OpenURL( | 231 browser_->OpenURL( |
| 222 content::OpenURLParams(delegate_->GetLearnMoreUrl(), | 232 content::OpenURLParams(delegate_->GetLearnMoreUrl(), |
| 223 content::Referrer(), | 233 content::Referrer(), |
| 224 NEW_FOREGROUND_TAB, | 234 NEW_FOREGROUND_TAB, |
| 225 ui::PAGE_TRANSITION_LINK, | 235 ui::PAGE_TRANSITION_LINK, |
| 226 false)); | 236 false)); |
| 227 } | 237 } |
| 228 OnClose(); | 238 // Warning: |this| may be deleted here! |
| 239 } |
| 240 |
| 241 void ExtensionMessageBubbleController::SetIsActiveBubble() { |
| 242 DCHECK(!is_active_bubble_); |
| 243 DCHECK(!model_->has_active_bubble()); |
| 244 is_active_bubble_ = true; |
| 245 model_->set_has_active_bubble(true); |
| 229 } | 246 } |
| 230 | 247 |
| 231 void ExtensionMessageBubbleController::ClearProfileListForTesting() { | 248 void ExtensionMessageBubbleController::ClearProfileListForTesting() { |
| 232 GetProfileSet()->clear(); | 249 GetProfileSet()->clear(); |
| 233 } | 250 } |
| 234 | 251 |
| 235 // static | 252 // static |
| 236 void ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( | 253 void ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( |
| 237 bool should_ignore) { | 254 bool should_ignore) { |
| 238 g_should_ignore_learn_more_for_testing = should_ignore; | 255 g_should_ignore_learn_more_for_testing = should_ignore; |
| 239 } | 256 } |
| 240 | 257 |
| 241 void ExtensionMessageBubbleController::OnBrowserRemoved(Browser* browser) { | 258 void ExtensionMessageBubbleController::OnBrowserRemoved(Browser* browser) { |
| 242 if (browser == browser_ && did_highlight_) { | 259 if (browser == browser_) { |
| 243 ToolbarActionsModel::Get(profile())->StopHighlighting(); | 260 if (is_highlighting_) { |
| 244 did_highlight_ = false; | 261 model_->StopHighlighting(); |
| 262 is_highlighting_ = false; |
| 263 } |
| 264 if (is_active_bubble_) { |
| 265 model_->set_has_active_bubble(false); |
| 266 is_active_bubble_ = false; |
| 267 } |
| 245 } | 268 } |
| 246 } | 269 } |
| 247 | 270 |
| 248 void ExtensionMessageBubbleController::AcknowledgeExtensions() { | 271 void ExtensionMessageBubbleController::AcknowledgeExtensions() { |
| 249 ExtensionIdList* list = GetOrCreateExtensionList(); | 272 ExtensionIdList* list = GetOrCreateExtensionList(); |
| 250 for (ExtensionIdList::const_iterator it = list->begin(); | 273 for (ExtensionIdList::const_iterator it = list->begin(); |
| 251 it != list->end(); ++it) | 274 it != list->end(); ++it) |
| 252 delegate_->AcknowledgeExtension(*it, user_action_); | 275 delegate_->AcknowledgeExtension(*it, user_action_); |
| 253 } | 276 } |
| 254 | 277 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 283 if (delegate_->ClearProfileSetAfterAction()) | 306 if (delegate_->ClearProfileSetAfterAction()) |
| 284 GetProfileSet()->clear(); | 307 GetProfileSet()->clear(); |
| 285 } | 308 } |
| 286 } | 309 } |
| 287 | 310 |
| 288 std::set<Profile*>* ExtensionMessageBubbleController::GetProfileSet() { | 311 std::set<Profile*>* ExtensionMessageBubbleController::GetProfileSet() { |
| 289 return &g_shown_for_profiles.Get()[delegate_->GetKey()]; | 312 return &g_shown_for_profiles.Get()[delegate_->GetKey()]; |
| 290 } | 313 } |
| 291 | 314 |
| 292 } // namespace extensions | 315 } // namespace extensions |
| OLD | NEW |