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

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

Issue 11588004: Move ScriptBadge, ActionInfo out of Extension; preparation for BrowserAction (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for CQ Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_action.h" 5 #include "chrome/browser/extensions/extension_action.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 icon_animation->AddObserver(observer); 152 icon_animation->AddObserver(observer);
153 } 153 }
154 154
155 ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() { 155 ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() {
156 if (icon_animation_.get()) 156 if (icon_animation_.get())
157 icon_animation_->RemoveObserver(observer_); 157 icon_animation_->RemoveObserver(observer_);
158 } 158 }
159 159
160 ExtensionAction::ExtensionAction( 160 ExtensionAction::ExtensionAction(
161 const std::string& extension_id, 161 const std::string& extension_id,
162 extensions::Extension::ActionInfo::Type action_type, 162 extensions::ActionInfo::Type action_type,
163 const extensions::Extension::ActionInfo& manifest_data) 163 const extensions::ActionInfo& manifest_data)
164 : extension_id_(extension_id), 164 : extension_id_(extension_id),
165 action_type_(action_type), 165 action_type_(action_type),
166 has_changed_(false) { 166 has_changed_(false) {
167 // Page/script actions are hidden/disabled by default, and browser actions are 167 // Page/script actions are hidden/disabled by default, and browser actions are
168 // visible/enabled by default. 168 // visible/enabled by default.
169 SetAppearance(kDefaultTabId, 169 SetAppearance(kDefaultTabId,
170 action_type == extensions::Extension::ActionInfo::TYPE_BROWSER ? 170 action_type == extensions::ActionInfo::TYPE_BROWSER ?
171 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); 171 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE);
172 SetTitle(kDefaultTabId, manifest_data.default_title); 172 SetTitle(kDefaultTabId, manifest_data.default_title);
173 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url); 173 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url);
174 if (!manifest_data.default_icon.empty()) { 174 if (!manifest_data.default_icon.empty()) {
175 set_default_icon(make_scoped_ptr(new ExtensionIconSet( 175 set_default_icon(make_scoped_ptr(new ExtensionIconSet(
176 manifest_data.default_icon))); 176 manifest_data.default_icon)));
177 } 177 }
178 set_id(manifest_data.id); 178 set_id(manifest_data.id);
179 } 179 }
180 180
181 ExtensionAction::~ExtensionAction() { 181 ExtensionAction::~ExtensionAction() {
182 } 182 }
183 183
184 scoped_ptr<ExtensionAction> ExtensionAction::CopyForTest() const { 184 scoped_ptr<ExtensionAction> ExtensionAction::CopyForTest() const {
185 scoped_ptr<ExtensionAction> copy( 185 scoped_ptr<ExtensionAction> copy(
186 new ExtensionAction(extension_id_, action_type_, 186 new ExtensionAction(extension_id_, action_type_,
187 extensions::Extension::ActionInfo())); 187 extensions::ActionInfo()));
188 copy->popup_url_ = popup_url_; 188 copy->popup_url_ = popup_url_;
189 copy->title_ = title_; 189 copy->title_ = title_;
190 copy->icon_ = icon_; 190 copy->icon_ = icon_;
191 copy->badge_text_ = badge_text_; 191 copy->badge_text_ = badge_text_;
192 copy->badge_background_color_ = badge_background_color_; 192 copy->badge_background_color_ = badge_background_color_;
193 copy->badge_text_color_ = badge_text_color_; 193 copy->badge_text_color_ = badge_text_color_;
194 copy->appearance_ = appearance_; 194 copy->appearance_ = appearance_;
195 copy->icon_animation_ = icon_animation_; 195 copy->icon_animation_ = icon_animation_;
196 copy->id_ = id_; 196 copy->id_ = id_;
197 197
198 if (default_icon_.get()) 198 if (default_icon_.get())
199 copy->default_icon_.reset(new ExtensionIconSet(*default_icon_)); 199 copy->default_icon_.reset(new ExtensionIconSet(*default_icon_));
200 200
201 return copy.Pass(); 201 return copy.Pass();
202 } 202 }
203 203
204 // static 204 // static
205 int ExtensionAction::GetIconSizeForType( 205 int ExtensionAction::GetIconSizeForType(
206 extensions::Extension::ActionInfo::Type type) { 206 extensions::ActionInfo::Type type) {
207 switch (type) { 207 switch (type) {
208 case extensions::Extension::ActionInfo::TYPE_BROWSER: 208 case extensions::ActionInfo::TYPE_BROWSER:
209 case extensions::Extension::ActionInfo::TYPE_PAGE: 209 case extensions::ActionInfo::TYPE_PAGE:
210 case extensions::Extension::ActionInfo::TYPE_SYSTEM_INDICATOR: 210 case extensions::ActionInfo::TYPE_SYSTEM_INDICATOR:
211 // TODO(dewittj) Report the actual icon size of the system 211 // TODO(dewittj) Report the actual icon size of the system
212 // indicator. 212 // indicator.
213 return extension_misc::EXTENSION_ICON_ACTION; 213 return extension_misc::EXTENSION_ICON_ACTION;
214 case extensions::Extension::ActionInfo::TYPE_SCRIPT_BADGE: 214 case extensions::ActionInfo::TYPE_SCRIPT_BADGE:
215 return extension_misc::EXTENSION_ICON_BITTY; 215 return extension_misc::EXTENSION_ICON_BITTY;
216 default: 216 default:
217 NOTREACHED(); 217 NOTREACHED();
218 return 0; 218 return 0;
219 } 219 }
220 } 220 }
221 221
222 void ExtensionAction::SetPopupUrl(int tab_id, const GURL& url) { 222 void ExtensionAction::SetPopupUrl(int tab_id, const GURL& url) {
223 // We store |url| even if it is empty, rather than removing a URL from the 223 // We store |url| even if it is empty, rather than removing a URL from the
224 // map. If an extension has a default popup, and removes it for a tab via 224 // map. If an extension has a default popup, and removes it for a tab via
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 const Appearance old_appearance = GetValue(&appearance_, tab_id); 258 const Appearance old_appearance = GetValue(&appearance_, tab_id);
259 259
260 if (old_appearance == new_appearance) 260 if (old_appearance == new_appearance)
261 return false; 261 return false;
262 262
263 SetValue(&appearance_, tab_id, new_appearance); 263 SetValue(&appearance_, tab_id, new_appearance);
264 264
265 // When showing a script badge for the first time on a web page, fade it in. 265 // When showing a script badge for the first time on a web page, fade it in.
266 // Other transitions happen instantly. 266 // Other transitions happen instantly.
267 if (old_appearance == INVISIBLE && tab_id != kDefaultTabId && 267 if (old_appearance == INVISIBLE && tab_id != kDefaultTabId &&
268 action_type_ == extensions::Extension::ActionInfo::TYPE_SCRIPT_BADGE) { 268 action_type_ == extensions::ActionInfo::TYPE_SCRIPT_BADGE) {
269 RunIconAnimation(tab_id); 269 RunIconAnimation(tab_id);
270 } 270 }
271 271
272 return true; 272 return true;
273 } 273 }
274 274
275 void ExtensionAction::ClearAllValuesForTab(int tab_id) { 275 void ExtensionAction::ClearAllValuesForTab(int tab_id) {
276 popup_url_.erase(tab_id); 276 popup_url_.erase(tab_id);
277 title_.erase(tab_id); 277 title_.erase(tab_id);
278 icon_.erase(tab_id); 278 icon_.erase(tab_id);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 icon_animation->Start(); 375 icon_animation->Start();
376 // After the icon is finished fading in (plus some padding to handle random 376 // After the icon is finished fading in (plus some padding to handle random
377 // timer delays), destroy it. We use a delayed task so that the Animation is 377 // timer delays), destroy it. We use a delayed task so that the Animation is
378 // deleted even if it hasn't finished by the time the MessageLoop is 378 // deleted even if it hasn't finished by the time the MessageLoop is
379 // destroyed. 379 // destroyed.
380 MessageLoop::current()->PostDelayedTask( 380 MessageLoop::current()->PostDelayedTask(
381 FROM_HERE, 381 FROM_HERE,
382 base::Bind(&DestroyIconAnimation, base::Passed(icon_animation.Pass())), 382 base::Bind(&DestroyIconAnimation, base::Passed(icon_animation.Pass())),
383 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); 383 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2));
384 } 384 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action.h ('k') | chrome/browser/extensions/extension_action_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698