diff options
author | jyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-13 05:13:03 +0000 |
---|---|---|
committer | jyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-13 05:13:03 +0000 |
commit | 8ddcc9268dcf791e0f6e65168ef9f4f8500a8056 (patch) | |
tree | 3f9fec4ccc434489282fa428d5251fcbd0b4de18 /chrome/browser | |
parent | 9f046020554dfcd3d268b7484634e2482c2ce4a4 (diff) | |
download | chromium_src-8ddcc9268dcf791e0f6e65168ef9f4f8500a8056.zip chromium_src-8ddcc9268dcf791e0f6e65168ef9f4f8500a8056.tar.gz chromium_src-8ddcc9268dcf791e0f6e65168ef9f4f8500a8056.tar.bz2 |
Move extension_action.* from common/ to browser/
This is the third step of a four-part refactoring to simplify icon
handling. The final part will be to move the icon-loading and
-caching classes into ExtensionAction methods.
BUG=153463
Review URL: https://chromiumcodereview.appspot.com/11093030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161718 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
45 files changed, 1148 insertions, 48 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 1805c8a..b64e99a 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -50,6 +50,7 @@ #include "chrome/browser/download/save_package_file_picker.h" #include "chrome/browser/extensions/browser_action_test_util.h" #include "chrome/browser/extensions/crx_installer.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" @@ -123,7 +124,6 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/permissions/permission_set.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/extensions/url_pattern_set.h" diff --git a/chrome/browser/extensions/api/context_menu/context_menu_apitest.cc b/chrome/browser/extensions/api/context_menu/context_menu_apitest.cc index 179a743..b3be154 100644 --- a/chrome/browser/extensions/api/context_menu/context_menu_apitest.cc +++ b/chrome/browser/extensions/api/context_menu/context_menu_apitest.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/test/base/ui_test_utils.h" namespace extensions { diff --git a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc index 7457216..181f39e 100644 --- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc @@ -9,6 +9,7 @@ #endif #include "chrome/browser/extensions/browser_action_test_util.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_apitest.h" @@ -20,7 +21,6 @@ #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/extensions/api/extension_action/extension_actions_api.cc b/chrome/browser/extensions/api/extension_action/extension_actions_api.cc index 2f21ad2..3b7a2b49 100644 --- a/chrome/browser/extensions/api/extension_action/extension_actions_api.cc +++ b/chrome/browser/extensions/api/extension_action/extension_actions_api.cc @@ -11,6 +11,7 @@ #include "base/string_piece.h" #include "base/values.h" #include "chrome/browser/extensions/api/extension_action/extension_page_actions_api_constants.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" @@ -22,7 +23,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_error_utils.h" #include "chrome/common/render_messages.h" #include "content/public/browser/navigation_entry.h" diff --git a/chrome/browser/extensions/api/extension_action/extension_actions_api.h b/chrome/browser/extensions/api/extension_action/extension_actions_api.h index 5c15218..167170e 100644 --- a/chrome/browser/extensions/api/extension_action/extension_actions_api.h +++ b/chrome/browser/extensions/api/extension_action/extension_actions_api.h @@ -6,8 +6,8 @@ #define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTIONS_API_H_ #include "base/memory/weak_ptr.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_function.h" -#include "chrome/common/extensions/extension_action.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h b/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h index e99fd4d..07f2819 100644 --- a/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h +++ b/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h @@ -6,8 +6,8 @@ #define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_BROWSER_ACTIONS_API_H_ #include "chrome/browser/extensions/api/extension_action/extension_actions_api.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_function.h" -#include "chrome/common/extensions/extension_action.h" // // browserAction.* aliases for supported browserActions APIs. diff --git a/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc b/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc index 705ceb1..c2cb5b1 100644 --- a/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc +++ b/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc @@ -8,16 +8,16 @@ #include "base/string_number_conversions.h" #include "chrome/browser/extensions/api/extension_action/extension_page_actions_api_constants.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/location_bar_controller.h" +#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_error_utils.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/extensions/api/extension_action/page_action_apitest.cc b/chrome/browser/extensions/api/extension_action/page_action_apitest.cc index 9d51d94..601bfc6 100644 --- a/chrome/browser/extensions/api/extension_action/page_action_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/page_action_apitest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/extensions/browser_event_router.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_apitest.h" @@ -16,7 +17,6 @@ #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/extensions/api/extension_action/page_as_browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/page_as_browser_action_apitest.cc index 263571e..6984073 100644 --- a/chrome/browser/extensions/api/extension_action/page_as_browser_action_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/page_as_browser_action_apitest.cc @@ -4,6 +4,7 @@ #include "base/command_line.h" #include "chrome/browser/extensions/browser_action_test_util.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_apitest.h" @@ -18,7 +19,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/extensions/api/extension_action/script_badge_apitest.cc b/chrome/browser/extensions/api/extension_action/script_badge_apitest.cc index b15dcf8..5a9baf1 100644 --- a/chrome/browser/extensions/api/extension_action/script_badge_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/script_badge_apitest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/extensions/browser_event_router.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_service.h" @@ -14,7 +15,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/features/feature.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/extensions/browser_event_router.cc b/chrome/browser/extensions/browser_event_router.cc index ce87028..09e9fc8 100644 --- a/chrome/browser/extensions/browser_event_router.cc +++ b/chrome/browser/extensions/browser_event_router.cc @@ -9,6 +9,7 @@ #include "chrome/browser/extensions/api/extension_action/extension_page_actions_api_constants.h" #include "chrome/browser/extensions/api/tabs/tabs_constants.h" #include "chrome/browser/extensions/event_names.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_tab_util.h" @@ -21,7 +22,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_constants.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/extensions/extension_action.cc b/chrome/browser/extensions/extension_action.cc new file mode 100644 index 0000000..0b3c5a5 --- /dev/null +++ b/chrome/browser/extensions/extension_action.cc @@ -0,0 +1,554 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/extension_action.h" + +#include <algorithm> + +#include "base/bind.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "chrome/common/badge_util.h" +#include "chrome/common/extensions/extension_constants.h" +#include "googleurl/src/gurl.h" +#include "grit/theme_resources.h" +#include "grit/ui_resources.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkDevice.h" +#include "third_party/skia/include/core/SkPaint.h" +#include "third_party/skia/include/effects/SkGradientShader.h" +#include "ui/base/animation/animation_delegate.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/color_utils.h" +#include "ui/gfx/image/canvas_image_source.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/image/image_skia_source.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/size.h" +#include "ui/gfx/image/image_skia_source.h" +#include "ui/gfx/skbitmap_operations.h" + +namespace { + +// Different platforms need slightly different constants to look good. +#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) +const float kTextSize = 9.0; +const int kBottomMarginBrowserAction = 0; +const int kBottomMarginPageAction = 2; +const int kPadding = 2; +const int kTopTextPadding = 0; +#elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) +const float kTextSize = 8.0; +const int kBottomMarginBrowserAction = 5; +const int kBottomMarginPageAction = 2; +const int kPadding = 2; +const int kTopTextPadding = 1; +#elif defined(OS_MACOSX) +const float kTextSize = 9.0; +const int kBottomMarginBrowserAction = 5; +const int kBottomMarginPageAction = 2; +const int kPadding = 2; +const int kTopTextPadding = 0; +#else +const float kTextSize = 10; +const int kBottomMarginBrowserAction = 5; +const int kBottomMarginPageAction = 2; +const int kPadding = 2; +// The padding between the top of the badge and the top of the text. +const int kTopTextPadding = -1; +#endif + +const int kBadgeHeight = 11; +const int kMaxTextWidth = 23; +// The minimum width for center-aligning the badge. +const int kCenterAlignThreshold = 20; + +class GetAttentionImageSource : public gfx::ImageSkiaSource { + public: + explicit GetAttentionImageSource(const gfx::ImageSkia& icon) + : icon_(icon) {} + + // gfx::ImageSkiaSource overrides: + virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) + OVERRIDE { + gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale_factor); + color_utils::HSL shift = {-1, 0, 0.5}; + return gfx::ImageSkiaRep( + SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), + icon_rep.scale_factor()); + } + + private: + const gfx::ImageSkia icon_; +}; + +} // namespace + +// TODO(tbarzic): Merge AnimationIconImageSource and IconAnimation together. +// Source for painting animated skia image. +class AnimatedIconImageSource : public gfx::ImageSkiaSource { + public: + AnimatedIconImageSource( + const gfx::ImageSkia& image, + base::WeakPtr<ExtensionAction::IconAnimation> animation) + : image_(image), + animation_(animation) { + } + + private: + virtual ~AnimatedIconImageSource() {} + + virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale) OVERRIDE { + gfx::ImageSkiaRep original_rep = image_.GetRepresentation(scale); + if (!animation_) + return original_rep; + + // Original representation's scale factor may be different from scale + // factor passed to this method. We want to use the former (since we are + // using bitmap for that scale). + return gfx::ImageSkiaRep( + animation_->Apply(original_rep.sk_bitmap()), + original_rep.scale_factor()); + } + + gfx::ImageSkia image_; + base::WeakPtr<ExtensionAction::IconAnimation> animation_; + + DISALLOW_COPY_AND_ASSIGN(AnimatedIconImageSource); +}; + +// CanvasImageSource for creating browser action icon with a badge. +class ExtensionAction::IconWithBadgeImageSource + : public gfx::CanvasImageSource { + public: + IconWithBadgeImageSource(const gfx::ImageSkia& icon, + const gfx::Size& spacing, + const std::string& text, + const SkColor& text_color, + const SkColor& background_color, + extensions::Extension::ActionInfo::Type action_type) + : gfx::CanvasImageSource(icon.size(), false), + icon_(icon), + spacing_(spacing), + text_(text), + text_color_(text_color), + background_color_(background_color), + action_type_(action_type) { + } + + virtual ~IconWithBadgeImageSource() {} + + private: + virtual void Draw(gfx::Canvas* canvas) OVERRIDE { + canvas->DrawImageInt(icon_, 0, 0, SkPaint()); + + gfx::Rect bounds(size_.width() + spacing_.width(), + size_.height() + spacing_.height()); + + // Draw a badge on the provided browser action icon's canvas. + ExtensionAction::DoPaintBadge(canvas, bounds, text_, text_color_, + background_color_, size_.width(), + action_type_); + } + + // Browser action icon image. + gfx::ImageSkia icon_; + // Extra spacing for badge compared to icon bounds. + gfx::Size spacing_; + // Text to be displayed on the badge. + std::string text_; + // Color of badge text. + SkColor text_color_; + // Color of the badge. + SkColor background_color_; + // Type of extension action this is for. + extensions::Extension::ActionInfo::Type action_type_; + + DISALLOW_COPY_AND_ASSIGN(IconWithBadgeImageSource); +}; + + +const int ExtensionAction::kDefaultTabId = -1; +// 100ms animation at 50fps (so 5 animation frames in total). +const int kIconFadeInDurationMs = 100; +const int kIconFadeInFramesPerSecond = 50; + +ExtensionAction::IconAnimation::IconAnimation() + : ui::LinearAnimation(kIconFadeInDurationMs, kIconFadeInFramesPerSecond, + NULL), + weak_ptr_factory_(this) {} + +ExtensionAction::IconAnimation::~IconAnimation() { + // Make sure observers don't access *this after its destructor has started. + weak_ptr_factory_.InvalidateWeakPtrs(); + // In case the animation was destroyed before it finished (likely due to + // delays in timer scheduling), make sure it's fully visible. + FOR_EACH_OBSERVER(Observer, observers_, OnIconChanged()); +} + +const SkBitmap& ExtensionAction::IconAnimation::Apply( + const SkBitmap& icon) const { + DCHECK_GT(icon.width(), 0); + DCHECK_GT(icon.height(), 0); + + if (!device_.get() || + (device_->width() != icon.width()) || + (device_->height() != icon.height())) { + device_.reset(new SkDevice( + SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true)); + } + + SkCanvas canvas(device_.get()); + canvas.clear(SK_ColorWHITE); + SkPaint paint; + paint.setAlpha(CurrentValueBetween(0, 255)); + canvas.drawBitmap(icon, 0, 0, &paint); + return device_->accessBitmap(false); +} + +base::WeakPtr<ExtensionAction::IconAnimation> +ExtensionAction::IconAnimation::AsWeakPtr() { + return weak_ptr_factory_.GetWeakPtr(); +} + +void ExtensionAction::IconAnimation::AddObserver( + ExtensionAction::IconAnimation::Observer* observer) { + observers_.AddObserver(observer); +} + +void ExtensionAction::IconAnimation::RemoveObserver( + ExtensionAction::IconAnimation::Observer* observer) { + observers_.RemoveObserver(observer); +} + +void ExtensionAction::IconAnimation::AnimateToState(double state) { + FOR_EACH_OBSERVER(Observer, observers_, OnIconChanged()); +} + +ExtensionAction::IconAnimation::ScopedObserver::ScopedObserver( + const base::WeakPtr<IconAnimation>& icon_animation, + Observer* observer) + : icon_animation_(icon_animation), + observer_(observer) { + if (icon_animation.get()) + icon_animation->AddObserver(observer); +} + +ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() { + if (icon_animation_.get()) + icon_animation_->RemoveObserver(observer_); +} + +ExtensionAction::ExtensionAction( + const std::string& extension_id, + extensions::Extension::ActionInfo::Type action_type, + const extensions::Extension::ActionInfo& manifest_data) + : extension_id_(extension_id), + action_type_(action_type), + has_changed_(false) { + // Page/script actions are hidden/disabled by default, and browser actions are + // visible/enabled by default. + SetAppearance(kDefaultTabId, + action_type == extensions::Extension::ActionInfo::TYPE_BROWSER ? + ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); + SetTitle(kDefaultTabId, manifest_data.default_title); + SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url); + if (!manifest_data.default_icon.empty()) { + set_default_icon(make_scoped_ptr(new ExtensionIconSet( + manifest_data.default_icon))); + } + set_id(manifest_data.id); +} + +ExtensionAction::~ExtensionAction() { +} + +scoped_ptr<ExtensionAction> ExtensionAction::CopyForTest() const { + scoped_ptr<ExtensionAction> copy( + new ExtensionAction(extension_id_, action_type_, + extensions::Extension::ActionInfo())); + copy->popup_url_ = popup_url_; + copy->title_ = title_; + copy->icon_ = icon_; + copy->badge_text_ = badge_text_; + copy->badge_background_color_ = badge_background_color_; + copy->badge_text_color_ = badge_text_color_; + copy->appearance_ = appearance_; + copy->icon_animation_ = icon_animation_; + copy->id_ = id_; + + if (default_icon_.get()) + copy->default_icon_.reset(new ExtensionIconSet(*default_icon_)); + + return copy.Pass(); +} + +// static +int ExtensionAction::GetIconSizeForType( + extensions::Extension::ActionInfo::Type type) { + switch (type) { + case extensions::Extension::ActionInfo::TYPE_BROWSER: + case extensions::Extension::ActionInfo::TYPE_PAGE: + return extension_misc::EXTENSION_ICON_ACTION; + case extensions::Extension::ActionInfo::TYPE_SCRIPT_BADGE: + return extension_misc::EXTENSION_ICON_BITTY; + default: + NOTREACHED(); + return 0; + } +} + +void ExtensionAction::SetPopupUrl(int tab_id, const GURL& url) { + // We store |url| even if it is empty, rather than removing a URL from the + // map. If an extension has a default popup, and removes it for a tab via + // the API, we must remember that there is no popup for that specific tab. + // If we removed the tab's URL, GetPopupURL would incorrectly return the + // default URL. + SetValue(&popup_url_, tab_id, url); +} + +bool ExtensionAction::HasPopup(int tab_id) const { + return !GetPopupUrl(tab_id).is_empty(); +} + +GURL ExtensionAction::GetPopupUrl(int tab_id) const { + return GetValue(&popup_url_, tab_id); +} + +void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) { + SetValue(&icon_, tab_id, image.AsImageSkia()); +} + +gfx::Image ExtensionAction::ApplyAttentionAndAnimation( + const gfx::ImageSkia& original_icon, + int tab_id) const { + gfx::ImageSkia icon = original_icon; + if (GetValue(&appearance_, tab_id) == WANTS_ATTENTION) + icon = gfx::ImageSkia(new GetAttentionImageSource(icon), icon.size()); + + return gfx::Image(ApplyIconAnimation(tab_id, icon)); +} + +gfx::ImageSkia ExtensionAction::GetExplicitlySetIcon(int tab_id) const { + return GetValue(&icon_, tab_id); +} + +bool ExtensionAction::SetAppearance(int tab_id, Appearance new_appearance) { + const Appearance old_appearance = GetValue(&appearance_, tab_id); + + if (old_appearance == new_appearance) + return false; + + SetValue(&appearance_, tab_id, new_appearance); + + // When showing a script badge for the first time on a web page, fade it in. + // Other transitions happen instantly. + if (old_appearance == INVISIBLE && tab_id != kDefaultTabId && + action_type_ == extensions::Extension::ActionInfo::TYPE_SCRIPT_BADGE) { + RunIconAnimation(tab_id); + } + + return true; +} + +void ExtensionAction::ClearAllValuesForTab(int tab_id) { + popup_url_.erase(tab_id); + title_.erase(tab_id); + icon_.erase(tab_id); + badge_text_.erase(tab_id); + badge_text_color_.erase(tab_id); + badge_background_color_.erase(tab_id); + appearance_.erase(tab_id); + icon_animation_.erase(tab_id); +} + +void ExtensionAction::PaintBadge(gfx::Canvas* canvas, + const gfx::Rect& bounds, + int tab_id) { + ExtensionAction::DoPaintBadge( + canvas, + bounds, + GetBadgeText(tab_id), + GetBadgeTextColor(tab_id), + GetBadgeBackgroundColor(tab_id), + GetIconWidth(tab_id), + action_type()); +} + +gfx::ImageSkia ExtensionAction::GetIconWithBadge( + const gfx::ImageSkia& icon, + int tab_id, + const gfx::Size& spacing) const { + if (tab_id < 0) + return icon; + + return gfx::ImageSkia( + new IconWithBadgeImageSource(icon, + spacing, + GetBadgeText(tab_id), + GetBadgeTextColor(tab_id), + GetBadgeBackgroundColor(tab_id), + action_type()), + icon.size()); +} + +// Determines which icon would be returned by |GetIcon|, and returns its width. +int ExtensionAction::GetIconWidth(int tab_id) const { + // If icon has been set, return its width. + gfx::ImageSkia icon = GetValue(&icon_, tab_id); + if (!icon.isNull()) + return icon.width(); + // If there is a default icon, the icon width will be set depending on our + // action type. + if (default_icon_.get()) + return GetIconSizeForType(action_type()); + + // If no icon has been set and there is no default icon, we need favicon + // width. + return ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); +} + +// static +void ExtensionAction::DoPaintBadge( + gfx::Canvas* canvas, + const gfx::Rect& bounds, + const std::string& text, + const SkColor& text_color_in, + const SkColor& background_color_in, + int icon_width, + extensions::Extension::ActionInfo::Type action_type) { + if (text.empty()) + return; + + SkColor text_color = text_color_in; + if (SkColorGetA(text_color_in) == 0x00) + text_color = SK_ColorWHITE; + + SkColor background_color = background_color_in; + if (SkColorGetA(background_color_in) == 0x00) + background_color = SkColorSetARGB(255, 218, 0, 24); + + canvas->Save(); + + SkPaint* text_paint = badge_util::GetBadgeTextPaintSingleton(); + text_paint->setTextSize(SkFloatToScalar(kTextSize)); + text_paint->setColor(text_color); + + // Calculate text width. We clamp it to a max size. + SkScalar sk_text_width = text_paint->measureText(text.c_str(), text.size()); + int text_width = std::min(kMaxTextWidth, SkScalarFloor(sk_text_width)); + + // Calculate badge size. It is clamped to a min width just because it looks + // silly if it is too skinny. + int badge_width = text_width + kPadding * 2; + // Force the pixel width of badge to be either odd (if the icon width is odd) + // or even otherwise. If there is a mismatch you get http://crbug.com/26400. + if (icon_width != 0 && (badge_width % 2 != icon_width % 2)) + badge_width += 1; + badge_width = std::max(kBadgeHeight, badge_width); + + // Paint the badge background color in the right location. It is usually + // right-aligned, but it can also be center-aligned if it is large. + int rect_height = kBadgeHeight; + int bottom_margin = + action_type == extensions::Extension::ActionInfo::TYPE_BROWSER ? + kBottomMarginBrowserAction : kBottomMarginPageAction; + int rect_y = bounds.bottom() - bottom_margin - kBadgeHeight; + int rect_width = badge_width; + int rect_x = (badge_width >= kCenterAlignThreshold) ? + (bounds.x() + bounds.width() - badge_width) / 2 : + bounds.right() - badge_width; + gfx::Rect rect(rect_x, rect_y, rect_width, rect_height); + + SkPaint rect_paint; + rect_paint.setStyle(SkPaint::kFill_Style); + rect_paint.setAntiAlias(true); + rect_paint.setColor(background_color); + canvas->DrawRoundRect(rect, 2, rect_paint); + + // Overlay the gradient. It is stretchy, so we do this in three parts. + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + gfx::ImageSkia* gradient_left = rb.GetImageSkiaNamed( + IDR_BROWSER_ACTION_BADGE_LEFT); + gfx::ImageSkia* gradient_right = rb.GetImageSkiaNamed( + IDR_BROWSER_ACTION_BADGE_RIGHT); + gfx::ImageSkia* gradient_center = rb.GetImageSkiaNamed( + IDR_BROWSER_ACTION_BADGE_CENTER); + + canvas->DrawImageInt(*gradient_left, rect.x(), rect.y()); + canvas->TileImageInt(*gradient_center, + rect.x() + gradient_left->width(), + rect.y(), + rect.width() - gradient_left->width() - gradient_right->width(), + rect.height()); + canvas->DrawImageInt(*gradient_right, + rect.right() - gradient_right->width(), rect.y()); + + // Finally, draw the text centered within the badge. We set a clip in case the + // text was too large. + rect.Inset(kPadding, 0); + canvas->ClipRect(rect); + canvas->sk_canvas()->drawText( + text.c_str(), text.size(), + SkFloatToScalar(rect.x() + + static_cast<float>(rect.width() - text_width) / 2), + SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding), + *text_paint); + canvas->Restore(); +} + +base::WeakPtr<ExtensionAction::IconAnimation> ExtensionAction::GetIconAnimation( + int tab_id) const { + std::map<int, base::WeakPtr<IconAnimation> >::iterator it = + icon_animation_.find(tab_id); + if (it == icon_animation_.end()) + return base::WeakPtr<ExtensionAction::IconAnimation>(); + if (it->second) + return it->second; + + // Take this opportunity to remove all the NULL IconAnimations from + // icon_animation_. + icon_animation_.erase(it); + for (it = icon_animation_.begin(); it != icon_animation_.end();) { + if (it->second) { + ++it; + } else { + // The WeakPtr is null; remove it from the map. + icon_animation_.erase(it++); + } + } + return base::WeakPtr<ExtensionAction::IconAnimation>(); +} + +gfx::ImageSkia ExtensionAction::ApplyIconAnimation( + int tab_id, + const gfx::ImageSkia& icon) const { + base::WeakPtr<IconAnimation> animation = GetIconAnimation(tab_id); + if (animation == NULL) + return icon; + + return gfx::ImageSkia(new AnimatedIconImageSource(icon, animation), + icon.size()); +} + +namespace { +// Used to create a Callback owning an IconAnimation. +void DestroyIconAnimation(scoped_ptr<ExtensionAction::IconAnimation>) {} +} +void ExtensionAction::RunIconAnimation(int tab_id) { + scoped_ptr<IconAnimation> icon_animation(new IconAnimation()); + icon_animation_[tab_id] = icon_animation->AsWeakPtr(); + icon_animation->Start(); + // After the icon is finished fading in (plus some padding to handle random + // timer delays), destroy it. We use a delayed task so that the Animation is + // deleted even if it hasn't finished by the time the MessageLoop is + // destroyed. + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&DestroyIconAnimation, base::Passed(icon_animation.Pass())), + base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); +} diff --git a/chrome/browser/extensions/extension_action.h b/chrome/browser/extensions/extension_action.h new file mode 100644 index 0000000..28a9ba8 --- /dev/null +++ b/chrome/browser/extensions/extension_action.h @@ -0,0 +1,342 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ + +#include <map> +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/memory/linked_ptr.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" +#include "base/memory/weak_ptr.h" +#include "base/observer_list.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/base/animation/linear_animation.h" + +class GURL; +class SkBitmap; +class SkDevice; + +namespace gfx { +class Canvas; +class Image; +class ImageSkia; +class Rect; +class Size; +} + +// ExtensionAction encapsulates the state of a browser action, page action, or +// script badge. +// Instances can have both global and per-tab state. If a property does not have +// a per-tab value, the global value is used instead. +class ExtensionAction { + public: + // Use this ID to indicate the default state for properties that take a tab_id + // parameter. + static const int kDefaultTabId; + + enum Appearance { + // The action icon is hidden. + INVISIBLE, + // The action is trying to get the user's attention but isn't yet + // running on the page. Currently only used for script badges. + WANTS_ATTENTION, + // The action icon is visible with its normal appearance. + ACTIVE, + }; + + // A fade-in animation. + class IconAnimation : public ui::LinearAnimation { + public: + // Observes changes to icon animation state. + class Observer { + public: + virtual void OnIconChanged() = 0; + + protected: + virtual ~Observer() {} + }; + + // A holder for an IconAnimation with a scoped observer. + class ScopedObserver { + public: + ScopedObserver(const base::WeakPtr<IconAnimation>& icon_animation, + Observer* observer); + ~ScopedObserver(); + + // Gets the icon animation, or NULL if the reference has expired. + const IconAnimation* icon_animation() const { + return icon_animation_.get(); + } + + private: + base::WeakPtr<IconAnimation> icon_animation_; + Observer* observer_; + + DISALLOW_COPY_AND_ASSIGN(ScopedObserver); + }; + + virtual ~IconAnimation(); + + // Returns the icon derived from the current animation state applied to + // |icon|. Ownership remains with this. + const SkBitmap& Apply(const SkBitmap& icon) const; + + void AddObserver(Observer* observer); + void RemoveObserver(Observer* observer); + + private: + // Construct using ExtensionAction::RunIconAnimation(). + friend class ExtensionAction; + IconAnimation(); + + base::WeakPtr<IconAnimation> AsWeakPtr(); + + // ui::LinearAnimation implementation. + virtual void AnimateToState(double state) OVERRIDE; + + // Device we use to paint icons to. + mutable scoped_ptr<SkDevice> device_; + + ObserverList<Observer> observers_; + + base::WeakPtrFactory<IconAnimation> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(IconAnimation); + }; + + ExtensionAction(const std::string& extension_id, + extensions::Extension::ActionInfo::Type action_type, + const extensions::Extension::ActionInfo& manifest_data); + ~ExtensionAction(); + + // Gets a copy of this, ownership passed to caller. + // It doesn't make sense to copy of an ExtensionAction except in tests. + scoped_ptr<ExtensionAction> CopyForTest() const; + + // Given the extension action type, returns the size the extension action icon + // should have. The icon should be square, so only one dimension is + // returned. + static int GetIconSizeForType(extensions::Extension::ActionInfo::Type type); + + // extension id + const std::string& extension_id() const { return extension_id_; } + + // What kind of action is this? + extensions::Extension::ActionInfo::Type action_type() const { + return action_type_; + } + + // action id -- only used with legacy page actions API + std::string id() const { return id_; } + void set_id(const std::string& id) { id_ = id; } + + bool has_changed() const { return has_changed_; } + void set_has_changed(bool value) { has_changed_ = value; } + + // Set the url which the popup will load when the user clicks this action's + // icon. Setting an empty URL will disable the popup for a given tab. + void SetPopupUrl(int tab_id, const GURL& url); + + // Use HasPopup() to see if a popup should be displayed. + bool HasPopup(int tab_id) const; + + // Get the URL to display in a popup. + GURL GetPopupUrl(int tab_id) const; + + // Set this action's title on a specific tab. + void SetTitle(int tab_id, const std::string& title) { + SetValue(&title_, tab_id, title); + } + + // If tab |tab_id| has a set title, return it. Otherwise, return + // the default title. + std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } + + // Icons are a bit different because the default value can be set to either a + // bitmap or a path. However, conceptually, there is only one default icon. + // Setting the default icon using a path clears the bitmap and vice-versa. + // To retrieve the icon for the extension action, use + // ExtensionActionIconFactory. + + // Set this action's icon bitmap on a specific tab. + void SetIcon(int tab_id, const gfx::Image& image); + + // Applies the attention and animation image transformations registered for + // the tab on the provided icon. + gfx::Image ApplyAttentionAndAnimation(const gfx::ImageSkia& icon, + int tab_id) const; + + // Gets the icon that has been set using |SetIcon| for the tab. + gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; + + // Non-tab-specific icon path. This is used to support the default_icon key of + // page and browser actions. + void set_default_icon(scoped_ptr<ExtensionIconSet> icon_set) { + default_icon_ = icon_set.Pass(); + } + + const ExtensionIconSet* default_icon() const { + return default_icon_.get(); + } + + // Set this action's badge text on a specific tab. + void SetBadgeText(int tab_id, const std::string& text) { + SetValue(&badge_text_, tab_id, text); + } + // Get the badge text for a tab, or the default if no badge text was set. + std::string GetBadgeText(int tab_id) const { + return GetValue(&badge_text_, tab_id); + } + + // Set this action's badge text color on a specific tab. + void SetBadgeTextColor(int tab_id, SkColor text_color) { + SetValue(&badge_text_color_, tab_id, text_color); + } + // Get the text color for a tab, or the default color if no text color + // was set. + SkColor GetBadgeTextColor(int tab_id) const { + return GetValue(&badge_text_color_, tab_id); + } + + // Set this action's badge background color on a specific tab. + void SetBadgeBackgroundColor(int tab_id, SkColor color) { + SetValue(&badge_background_color_, tab_id, color); + } + // Get the badge background color for a tab, or the default if no color + // was set. + SkColor GetBadgeBackgroundColor(int tab_id) const { + return GetValue(&badge_background_color_, tab_id); + } + + // Set this action's badge visibility on a specific tab. This takes + // care of any appropriate transition animations. Returns true if + // the appearance has changed. + bool SetAppearance(int tab_id, Appearance value); + // Get the badge visibility for a tab, or the default badge visibility + // if none was set. + bool GetIsVisible(int tab_id) const { + return GetValue(&appearance_, tab_id) != INVISIBLE; + } + + // True if the tab's action wants the user's attention. + bool WantsAttention(int tab_id) const { + return GetValue(&appearance_, tab_id) == WANTS_ATTENTION; + } + + // Remove all tab-specific state. + void ClearAllValuesForTab(int tab_id); + + // If the specified tab has a badge, paint it into the provided bounds. + void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); + + // Returns icon image with badge for specified tab. + gfx::ImageSkia GetIconWithBadge(const gfx::ImageSkia& icon, + int tab_id, + const gfx::Size& spacing) const; + + // Gets a weak reference to the icon animation for a tab, if any. The + // reference will only have a value while the animation is running. + base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; + + private: + class IconWithBadgeImageSource; + + // Runs an animation on a tab. + void RunIconAnimation(int tab_id); + + // If the icon animation is running on tab |tab_id|, applies it to + // |orig| and returns the result. Otherwise, just returns |orig|. + gfx::ImageSkia ApplyIconAnimation(int tab_id, + const gfx::ImageSkia& orig) const; + + // Returns width of the current icon for tab_id. + // TODO(tbarzic): The icon selection is done in ExtensionActionIconFactory. + // We should probably move this there too. + int GetIconWidth(int tab_id) const; + + // Paints badge with specified parameters to |canvas|. + static void DoPaintBadge(gfx::Canvas* canvas, + const gfx::Rect& bounds, + const std::string& text, + const SkColor& text_color_in, + const SkColor& background_color_in, + int icon_width, + extensions::Extension::ActionInfo::Type action_type); + + template <class T> + struct ValueTraits { + static T CreateEmpty() { + return T(); + } + }; + + template<class T> + void SetValue(std::map<int, T>* map, int tab_id, const T& val) { + (*map)[tab_id] = val; + } + + template<class T> + T GetValue(const std::map<int, T>* map, int tab_id) const { + typename std::map<int, T>::const_iterator iter = map->find(tab_id); + if (iter != map->end()) { + return iter->second; + } else { + iter = map->find(kDefaultTabId); + return iter != map->end() ? iter->second : ValueTraits<T>::CreateEmpty(); + } + } + + // The id for the extension this action belongs to (as defined in the + // extension manifest). + const std::string extension_id_; + + const extensions::Extension::ActionInfo::Type action_type_; + + // Each of these data items can have both a global state (stored with the key + // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). + std::map<int, GURL> popup_url_; + std::map<int, std::string> title_; + std::map<int, gfx::ImageSkia> icon_; + std::map<int, std::string> badge_text_; + std::map<int, SkColor> badge_background_color_; + std::map<int, SkColor> badge_text_color_; + std::map<int, Appearance> appearance_; + + // IconAnimations are destroyed by a delayed task on the UI message loop so + // that even if the Extension and ExtensionAction are destroyed on a non-UI + // thread, the animation will still only be touched from the UI thread. This + // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes + // NULLs to prevent the map from growing without bound. + mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; + + // ExtensionIconSet containing paths to bitmaps from which default icon's + // image representations will be selected. + scoped_ptr<const ExtensionIconSet> default_icon_; + + // The id for the ExtensionAction, for example: "RssPageAction". This is + // needed for compat with an older version of the page actions API. + std::string id_; + + // True if the ExtensionAction's settings have changed from what was + // specified in the manifest. + bool has_changed_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionAction); +}; + +template<> +struct ExtensionAction::ValueTraits<int> { + static int CreateEmpty() { + return -1; + } +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ diff --git a/chrome/browser/extensions/extension_action_icon_factory.cc b/chrome/browser/extensions/extension_action_icon_factory.cc index 8638159..658f09e 100644 --- a/chrome/browser/extensions/extension_action_icon_factory.cc +++ b/chrome/browser/extensions/extension_action_icon_factory.cc @@ -4,8 +4,8 @@ #include "chrome/browser/extensions/extension_action_icon_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_icon_set.h" #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" @@ -63,4 +63,3 @@ gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) { return GetDefaultIcon(); } - diff --git a/chrome/browser/extensions/extension_action_icon_factory_unittest.cc b/chrome/browser/extensions/extension_action_icon_factory_unittest.cc index 0e34233..55fdb8e 100644 --- a/chrome/browser/extensions/extension_action_icon_factory_unittest.cc +++ b/chrome/browser/extensions/extension_action_icon_factory_unittest.cc @@ -9,12 +9,12 @@ #include "base/json/json_file_value_serializer.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/test_extension_system.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/test/base/testing_profile.h" #include "content/public/test/test_browser_thread.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/extensions/extension_action_manager.cc b/chrome/browser/extensions/extension_action_manager.cc index b962961..054d679 100644 --- a/chrome/browser/extensions/extension_action_manager.cc +++ b/chrome/browser/extensions/extension_action_manager.cc @@ -4,11 +4,11 @@ #include "chrome/browser/extensions/extension_action_manager.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_switch_utils.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" diff --git a/chrome/browser/extensions/extension_action_unittest.cc b/chrome/browser/extensions/extension_action_unittest.cc new file mode 100644 index 0000000..8607c0c --- /dev/null +++ b/chrome/browser/extensions/extension_action_unittest.cc @@ -0,0 +1,204 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/message_loop.h" +#include "chrome/browser/extensions/extension_action.h" +#include "googleurl/src/gurl.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +using extensions::Extension; + +TEST(ExtensionActionTest, Title) { + Extension::ActionInfo action_info; + action_info.default_title = "Initial Title"; + ExtensionAction action("", Extension::ActionInfo::TYPE_PAGE, action_info); + + ASSERT_EQ("Initial Title", action.GetTitle(1)); + action.SetTitle(ExtensionAction::kDefaultTabId, "foo"); + ASSERT_EQ("foo", action.GetTitle(1)); + ASSERT_EQ("foo", action.GetTitle(100)); + action.SetTitle(100, "bar"); + ASSERT_EQ("foo", action.GetTitle(1)); + ASSERT_EQ("bar", action.GetTitle(100)); + action.SetTitle(ExtensionAction::kDefaultTabId, "baz"); + ASSERT_EQ("baz", action.GetTitle(1)); + action.ClearAllValuesForTab(100); + ASSERT_EQ("baz", action.GetTitle(100)); +} + +TEST(ExtensionActionTest, Visibility) { + ExtensionAction action("", Extension::ActionInfo::TYPE_PAGE, + Extension::ActionInfo()); + + ASSERT_FALSE(action.GetIsVisible(1)); + action.SetAppearance(ExtensionAction::kDefaultTabId, ExtensionAction::ACTIVE); + ASSERT_TRUE(action.GetIsVisible(1)); + ASSERT_TRUE(action.GetIsVisible(100)); + + action.SetAppearance(ExtensionAction::kDefaultTabId, + ExtensionAction::INVISIBLE); + ASSERT_FALSE(action.GetIsVisible(1)); + ASSERT_FALSE(action.GetIsVisible(100)); + action.SetAppearance(100, ExtensionAction::ACTIVE); + ASSERT_FALSE(action.GetIsVisible(1)); + ASSERT_TRUE(action.GetIsVisible(100)); + EXPECT_FALSE(action.GetIconAnimation(100)) + << "Page actions should not animate."; + + action.ClearAllValuesForTab(100); + ASSERT_FALSE(action.GetIsVisible(1)); + ASSERT_FALSE(action.GetIsVisible(100)); + + ExtensionAction browser_action("", Extension::ActionInfo::TYPE_BROWSER, + Extension::ActionInfo()); + ASSERT_TRUE(browser_action.GetIsVisible(1)); +} + +TEST(ExtensionActionTest, ScriptBadgeAnimation) { + // Supports the icon animation. + MessageLoop message_loop; + + ExtensionAction script_badge("", Extension::ActionInfo::TYPE_SCRIPT_BADGE, + Extension::ActionInfo()); + EXPECT_FALSE(script_badge.GetIconAnimation(ExtensionAction::kDefaultTabId)); + script_badge.SetAppearance(ExtensionAction::kDefaultTabId, + ExtensionAction::ACTIVE); + EXPECT_FALSE(script_badge.GetIconAnimation(ExtensionAction::kDefaultTabId)) + << "Showing the default tab should not animate script badges."; + + script_badge.SetAppearance(ExtensionAction::kDefaultTabId, + ExtensionAction::INVISIBLE); + EXPECT_FALSE(script_badge.GetIconAnimation(1)) + << "Making a script badge invisible should not show its animation."; + script_badge.SetAppearance(1, ExtensionAction::ACTIVE); + EXPECT_TRUE(script_badge.GetIconAnimation(1)) + << "Making a script badge visible should show its animation."; + + script_badge.ClearAllValuesForTab(1); + EXPECT_FALSE(script_badge.GetIconAnimation(100)); +} + +TEST(ExtensionActionTest, GetAttention) { + // Supports the icon animation. + scoped_ptr<MessageLoop> message_loop(new MessageLoop); + + ExtensionAction script_badge("", Extension::ActionInfo::TYPE_SCRIPT_BADGE, + Extension::ActionInfo()); + EXPECT_FALSE(script_badge.GetIsVisible(1)); + EXPECT_FALSE(script_badge.GetIconAnimation(1)); + script_badge.SetAppearance(1, ExtensionAction::WANTS_ATTENTION); + EXPECT_TRUE(script_badge.GetIsVisible(1)); + EXPECT_TRUE(script_badge.GetIconAnimation(1)); + + // Simulate waiting long enough for the animation to end. + message_loop.reset(); // Can't have 2 MessageLoops alive at once. + message_loop.reset(new MessageLoop); + EXPECT_FALSE(script_badge.GetIconAnimation(1)); // Sanity check. + + script_badge.SetAppearance(1, ExtensionAction::ACTIVE); + EXPECT_FALSE(script_badge.GetIconAnimation(1)) + << "The animation should not play again if the icon was already visible."; +} + +TEST(ExtensionActionTest, Icon) { + Extension::ActionInfo action_info; + action_info.default_icon.Add(16, "icon16.png"); + ExtensionAction page_action("", Extension::ActionInfo::TYPE_PAGE, + action_info); + ASSERT_TRUE(page_action.default_icon()); + EXPECT_EQ("icon16.png", + page_action.default_icon()->Get( + 16, ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("", + page_action.default_icon()->Get( + 17, ExtensionIconSet::MATCH_BIGGER)); +} + +TEST(ExtensionActionTest, Badge) { + ExtensionAction action("", Extension::ActionInfo::TYPE_PAGE, + Extension::ActionInfo()); + ASSERT_EQ("", action.GetBadgeText(1)); + action.SetBadgeText(ExtensionAction::kDefaultTabId, "foo"); + ASSERT_EQ("foo", action.GetBadgeText(1)); + ASSERT_EQ("foo", action.GetBadgeText(100)); + action.SetBadgeText(100, "bar"); + ASSERT_EQ("foo", action.GetBadgeText(1)); + ASSERT_EQ("bar", action.GetBadgeText(100)); + action.SetBadgeText(ExtensionAction::kDefaultTabId, "baz"); + ASSERT_EQ("baz", action.GetBadgeText(1)); + action.ClearAllValuesForTab(100); + ASSERT_EQ("baz", action.GetBadgeText(100)); +} + +TEST(ExtensionActionTest, BadgeTextColor) { + ExtensionAction action("", Extension::ActionInfo::TYPE_PAGE, + Extension::ActionInfo()); + ASSERT_EQ(0x00000000u, action.GetBadgeTextColor(1)); + action.SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFFFF0000u); + ASSERT_EQ(0xFFFF0000u, action.GetBadgeTextColor(1)); + ASSERT_EQ(0xFFFF0000u, action.GetBadgeTextColor(100)); + action.SetBadgeTextColor(100, 0xFF00FF00); + ASSERT_EQ(0xFFFF0000u, action.GetBadgeTextColor(1)); + ASSERT_EQ(0xFF00FF00u, action.GetBadgeTextColor(100)); + action.SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFF0000FFu); + ASSERT_EQ(0xFF0000FFu, action.GetBadgeTextColor(1)); + action.ClearAllValuesForTab(100); + ASSERT_EQ(0xFF0000FFu, action.GetBadgeTextColor(100)); +} + +TEST(ExtensionActionTest, BadgeBackgroundColor) { + ExtensionAction action("", Extension::ActionInfo::TYPE_PAGE, + Extension::ActionInfo()); + ASSERT_EQ(0x00000000u, action.GetBadgeBackgroundColor(1)); + action.SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId, + 0xFFFF0000u); + ASSERT_EQ(0xFFFF0000u, action.GetBadgeBackgroundColor(1)); + ASSERT_EQ(0xFFFF0000u, action.GetBadgeBackgroundColor(100)); + action.SetBadgeBackgroundColor(100, 0xFF00FF00); + ASSERT_EQ(0xFFFF0000u, action.GetBadgeBackgroundColor(1)); + ASSERT_EQ(0xFF00FF00u, action.GetBadgeBackgroundColor(100)); + action.SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId, + 0xFF0000FFu); + ASSERT_EQ(0xFF0000FFu, action.GetBadgeBackgroundColor(1)); + action.ClearAllValuesForTab(100); + ASSERT_EQ(0xFF0000FFu, action.GetBadgeBackgroundColor(100)); +} + +TEST(ExtensionActionTest, PopupUrl) { + GURL url_unset; + GURL url_foo("http://www.example.com/foo.html"); + GURL url_bar("http://www.example.com/bar.html"); + GURL url_baz("http://www.example.com/baz.html"); + + Extension::ActionInfo action_info; + action_info.default_popup_url = url_foo; + ExtensionAction action("", Extension::ActionInfo::TYPE_PAGE, action_info); + + ASSERT_EQ(url_foo, action.GetPopupUrl(1)); + ASSERT_EQ(url_foo, action.GetPopupUrl(100)); + ASSERT_TRUE(action.HasPopup(1)); + ASSERT_TRUE(action.HasPopup(100)); + + action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_unset); + ASSERT_EQ(url_unset, action.GetPopupUrl(1)); + ASSERT_EQ(url_unset, action.GetPopupUrl(100)); + ASSERT_FALSE(action.HasPopup(1)); + ASSERT_FALSE(action.HasPopup(100)); + + action.SetPopupUrl(100, url_bar); + ASSERT_EQ(url_unset, action.GetPopupUrl(1)); + ASSERT_EQ(url_bar, action.GetPopupUrl(100)); + + action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); + ASSERT_EQ(url_baz, action.GetPopupUrl(1)); + ASSERT_EQ(url_bar, action.GetPopupUrl(100)); + + action.ClearAllValuesForTab(100); + ASSERT_EQ(url_baz, action.GetPopupUrl(1)); + ASSERT_EQ(url_baz, action.GetPopupUrl(100)); +} + +} // namespace diff --git a/chrome/browser/extensions/extension_context_menu_model.cc b/chrome/browser/extensions/extension_context_menu_model.cc index 02d254a..5e41f44 100644 --- a/chrome/browser/extensions/extension_context_menu_model.cc +++ b/chrome/browser/extensions/extension_context_menu_model.cc @@ -5,6 +5,7 @@ #include "chrome/browser/extensions/extension_context_menu_model.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" @@ -15,7 +16,6 @@ #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" diff --git a/chrome/browser/extensions/extension_keybinding_apitest.cc b/chrome/browser/extensions/extension_keybinding_apitest.cc index f438dbd..d19ee79 100644 --- a/chrome/browser/extensions/extension_keybinding_apitest.cc +++ b/chrome/browser/extensions/extension_keybinding_apitest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/extensions/active_tab_permission_granter.h" #include "chrome/browser/extensions/browser_action_test_util.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/tab_helper.h" @@ -13,7 +14,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc index e72d54a..496cc44 100644 --- a/chrome/browser/extensions/extension_toolbar_model.cc +++ b/chrome/browser/extensions/extension_toolbar_model.cc @@ -5,6 +5,7 @@ #include "chrome/browser/extensions/extension_toolbar_model.h" #include "chrome/browser/extensions/browser_event_router.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extension_service.h" @@ -17,7 +18,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_switch_utils.h" #include "chrome/common/pref_names.h" #include "content/public/browser/notification_details.h" diff --git a/chrome/browser/extensions/page_action_browsertest.cc b/chrome/browser/extensions/page_action_browsertest.cc index 9f1e794..a7b1bfc 100644 --- a/chrome/browser/extensions/page_action_browsertest.cc +++ b/chrome/browser/extensions/page_action_browsertest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/utf_string_conversions.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.h" @@ -11,7 +12,6 @@ #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/test/base/ui_test_utils.h" namespace extensions { diff --git a/chrome/browser/extensions/page_action_controller.cc b/chrome/browser/extensions/page_action_controller.cc index 690167c..95a82dc 100644 --- a/chrome/browser/extensions/page_action_controller.cc +++ b/chrome/browser/extensions/page_action_controller.cc @@ -6,15 +6,15 @@ #include "chrome/browser/extensions/browser_event_router.h" #include "chrome/browser/extensions/component_loader.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/extension_tab_util.h" +#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_set.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/navigation_details.h" diff --git a/chrome/browser/extensions/page_action_controller_unittest.cc b/chrome/browser/extensions/page_action_controller_unittest.cc index a82548c..72ffbe5 100644 --- a/chrome/browser/extensions/page_action_controller_unittest.cc +++ b/chrome/browser/extensions/page_action_controller_unittest.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/page_action_controller.h" @@ -15,7 +16,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tab_contents/test_tab_contents.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_builder.h" #include "chrome/common/extensions/value_builder.h" #include "chrome/test/base/testing_profile.h" diff --git a/chrome/browser/extensions/script_badge_controller.cc b/chrome/browser/extensions/script_badge_controller.cc index c5274ae..24f6691 100644 --- a/chrome/browser/extensions/script_badge_controller.cc +++ b/chrome/browser/extensions/script_badge_controller.cc @@ -8,6 +8,7 @@ #include "base/string_util.h" #include "base/stringprintf.h" #include "chrome/browser/extensions/browser_event_router.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" @@ -15,7 +16,6 @@ #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/chrome_notification_types.h" diff --git a/chrome/browser/extensions/script_bubble_controller.cc b/chrome/browser/extensions/script_bubble_controller.cc index fb12ea6..7337830 100644 --- a/chrome/browser/extensions/script_bubble_controller.cc +++ b/chrome/browser/extensions/script_bubble_controller.cc @@ -6,15 +6,15 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/extensions/component_loader.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/location_bar_controller.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "third_party/skia/include/core/SkColor.h" namespace extensions { diff --git a/chrome/browser/extensions/script_bubble_controller_unittest.cc b/chrome/browser/extensions/script_bubble_controller_unittest.cc index b7618db..3851add 100644 --- a/chrome/browser/extensions/script_bubble_controller_unittest.cc +++ b/chrome/browser/extensions/script_bubble_controller_unittest.cc @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "chrome/browser/extensions/component_loader.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/script_bubble_controller.h" @@ -16,7 +17,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tab_contents/test_tab_contents.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_builder.h" #include "chrome/common/extensions/feature_switch.h" #include "chrome/common/extensions/value_builder.h" diff --git a/chrome/browser/extensions/tab_helper.cc b/chrome/browser/extensions/tab_helper.cc index be70e97..b6e53e9 100644 --- a/chrome/browser/extensions/tab_helper.cc +++ b/chrome/browser/extensions/tab_helper.cc @@ -7,6 +7,7 @@ #include "chrome/browser/extensions/activity_log.h" #include "chrome/browser/extensions/app_notify_channel_ui.h" #include "chrome/browser/extensions/crx_installer.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" @@ -22,7 +23,6 @@ #include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_messages.h" diff --git a/chrome/browser/ui/cocoa/extensions/browser_action_button.mm b/chrome/browser/ui/cocoa/extensions/browser_action_button.mm index 1443a2d..ae3a948 100644 --- a/chrome/browser/ui/cocoa/extensions/browser_action_button.mm +++ b/chrome/browser/ui/cocoa/extensions/browser_action_button.mm @@ -9,13 +9,13 @@ #include "base/logging.h" #include "base/sys_string_conversions.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_resource.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm index 2948333..a178818 100644 --- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm @@ -8,6 +8,7 @@ #include <string> #include "base/sys_string_conversions.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_toolbar_model.h" @@ -24,7 +25,6 @@ #import "chrome/browser/ui/cocoa/menu_button.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/pref_names.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm b/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm index ec2832b..30daa72 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm @@ -6,6 +6,7 @@ #include "base/sys_string_conversions.h" #include "chrome/browser/api/prefs/pref_change_registrar.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" @@ -26,7 +27,6 @@ #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" diff --git a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm index d332e32..7919129 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm @@ -11,8 +11,9 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" -#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/bundle_installer.h" +#include "chrome/browser/extensions/extension_action.h" +#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" @@ -26,7 +27,6 @@ #include "chrome/browser/ui/singleton_tabs.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/url_constants.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index cb95413..5ca2c99 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -19,6 +19,7 @@ #include "chrome/browser/command_updater.h" #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/api/tabs/tabs.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/location_bar_controller.h" #include "chrome/browser/extensions/tab_helper.h" @@ -58,7 +59,6 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/extension_switch_utils.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/ui/cocoa/location_bar/page_action_decoration.h b/chrome/browser/ui/cocoa/location_bar/page_action_decoration.h index 9e1de56..99dfba9 100644 --- a/chrome/browser/ui/cocoa/location_bar/page_action_decoration.h +++ b/chrome/browser/ui/cocoa/location_bar/page_action_decoration.h @@ -5,9 +5,9 @@ #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_ #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_ +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h" -#include "chrome/common/extensions/extension_action.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" diff --git a/chrome/browser/ui/cocoa/location_bar/page_action_decoration.mm b/chrome/browser/ui/cocoa/location_bar/page_action_decoration.mm index e54e15b..983f7d7 100644 --- a/chrome/browser/ui/cocoa/location_bar/page_action_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/page_action_decoration.mm @@ -7,6 +7,7 @@ #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" #include "base/sys_string_conversions.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/location_bar_controller.h" @@ -23,7 +24,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_resource.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc index ea9f46d..bcdb515 100644 --- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc @@ -15,6 +15,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_context_menu_model.h" @@ -36,7 +37,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/extension_resource.h" #include "content/public/browser/notification_details.h" diff --git a/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc index 0c93494..e15b67b 100644 --- a/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_dialogs.h" @@ -25,7 +26,6 @@ #include "chrome/browser/ui/singleton_tabs.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/url_constants.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index cfc5ac2..3ba6e35 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -28,6 +28,7 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/location_bar_controller.h" @@ -72,7 +73,6 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/extension_switch_utils.h" diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index 401c9b1..9c84004 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -17,6 +17,7 @@ #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/api/prefs/pref_member.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_context_menu_model.h" #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" @@ -25,7 +26,6 @@ #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/view_ids.h" #include "chrome/common/content_settings_types.h" -#include "chrome/common/extensions/extension_action.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/common/page_transition_types.h" diff --git a/chrome/browser/ui/omnibox/location_bar_util.cc b/chrome/browser/ui/omnibox/location_bar_util.cc index 7bbb5ec..e02468d 100644 --- a/chrome/browser/ui/omnibox/location_bar_util.cc +++ b/chrome/browser/ui/omnibox/location_bar_util.cc @@ -6,7 +6,7 @@ #include "base/i18n/rtl.h" #include "base/string_util.h" -#include "chrome/common/extensions/extension_action.h" +#include "chrome/browser/extensions/extension_action.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/base/text/text_elider.h" diff --git a/chrome/browser/ui/views/browser_action_view.cc b/chrome/browser/ui/views/browser_action_view.cc index 61ea06b..0fb725a 100644 --- a/chrome/browser/ui/views/browser_action_view.cc +++ b/chrome/browser/ui/views/browser_action_view.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_context_menu_model.h" #include "chrome/browser/ui/browser.h" @@ -14,7 +15,6 @@ #include "chrome/browser/ui/views/toolbar_view.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/ui/views/browser_actions_container_browsertest.cc b/chrome/browser/ui/views/browser_actions_container_browsertest.cc index d8a4998..0761c34 100644 --- a/chrome/browser/ui/views/browser_actions_container_browsertest.cc +++ b/chrome/browser/ui/views/browser_actions_container_browsertest.cc @@ -2,15 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/ui/views/browser_actions_container.h" + #include "chrome/browser/extensions/browser_action_test_util.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/views/browser_actions_container.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_resource.h" diff --git a/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.cc b/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.cc index 3f77da7..8962d021 100644 --- a/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.cc +++ b/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.cc @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_context_menu_model.h" #include "chrome/browser/profiles/profile.h" @@ -14,7 +15,6 @@ #include "chrome/browser/ui/views/browser_actions_container.h" #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/menu/menu_item_view.h" #include "ui/views/controls/menu/menu_model_adapter.h" diff --git a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc index 7587d28..57583f2 100644 --- a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc +++ b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_install_ui.h" #include "chrome/browser/profiles/profile.h" @@ -28,7 +29,6 @@ #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/url_constants.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" diff --git a/chrome/browser/ui/views/location_bar/page_action_image_view.cc b/chrome/browser/ui/views/location_bar/page_action_image_view.cc index 536287b..0a0ec62 100644 --- a/chrome/browser/ui/views/location_bar/page_action_image_view.cc +++ b/chrome/browser/ui/views/location_bar/page_action_image_view.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service_factory.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_context_menu_model.h" @@ -24,7 +25,6 @@ #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/extension_resource.h" #include "content/public/browser/notification_details.h" diff --git a/chrome/browser/ui/views/location_bar/page_action_image_view.h b/chrome/browser/ui/views/location_bar/page_action_image_view.h index 9e00fce..990503a 100644 --- a/chrome/browser/ui/views/location_bar/page_action_image_view.h +++ b/chrome/browser/ui/views/location_bar/page_action_image_view.h @@ -9,10 +9,10 @@ #include <string> #include "base/memory/scoped_ptr.h" +#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" #include "chrome/browser/extensions/extension_context_menu_model.h" #include "chrome/browser/ui/views/extensions/extension_popup.h" -#include "chrome/common/extensions/extension_action.h" #include "ui/views/context_menu_controller.h" #include "ui/views/controls/image_view.h" #include "ui/views/widget/widget_observer.h" |