| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 5 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/api/commands/command_service.h" | 9 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 11 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/extensions/extension_action.h" |
| 12 #include "chrome/browser/extensions/extension_view.h" | 12 #include "chrome/browser/extensions/extension_view.h" |
| 13 #include "chrome/browser/extensions/extension_view_host.h" | 13 #include "chrome/browser/extensions/extension_view_host.h" |
| 14 #include "chrome/browser/extensions/extension_view_host_factory.h" | 14 #include "chrome/browser/extensions/extension_view_host_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/extensions/accelerator_priority.h" | 18 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
| 19 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h" | 19 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 20 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 23 #include "chrome/common/extensions/api/extension_action/action_info.h" | 23 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 24 #include "chrome/common/icon_with_badge_image_source.h" |
| 24 #include "extensions/browser/extension_host.h" | 25 #include "extensions/browser/extension_host.h" |
| 25 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/feature_switch.h" | 28 #include "extensions/common/feature_switch.h" |
| 28 #include "extensions/common/manifest_constants.h" | 29 #include "extensions/common/manifest_constants.h" |
| 29 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 30 #include "ui/gfx/image/image_skia_operations.h" | 31 #include "ui/gfx/image/image_skia_operations.h" |
| 31 | 32 |
| 32 using extensions::ActionInfo; | 33 using extensions::ActionInfo; |
| 33 using extensions::CommandService; | 34 using extensions::CommandService; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 platform_delegate_->OnDelegateSet(); | 73 platform_delegate_->OnDelegateSet(); |
| 73 } else { | 74 } else { |
| 74 if (is_showing_popup()) | 75 if (is_showing_popup()) |
| 75 HidePopup(); | 76 HidePopup(); |
| 76 platform_delegate_.reset(); | 77 platform_delegate_.reset(); |
| 77 view_delegate_ = nullptr; | 78 view_delegate_ = nullptr; |
| 78 } | 79 } |
| 79 } | 80 } |
| 80 | 81 |
| 81 gfx::Image ExtensionActionViewController::GetIcon( | 82 gfx::Image ExtensionActionViewController::GetIcon( |
| 82 content::WebContents* web_contents) { | 83 content::WebContents* web_contents, |
| 84 const gfx::Size& size) { |
| 83 if (!ExtensionIsValid()) | 85 if (!ExtensionIsValid()) |
| 84 return gfx::Image(); | 86 return gfx::Image(); |
| 85 | 87 |
| 86 return icon_factory_.GetIcon(SessionTabHelper::IdForTab(web_contents)); | 88 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 87 } | 89 scoped_ptr<IconWithBadgeImageSource> image_source( |
| 90 new IconWithBadgeImageSource(size)); |
| 91 image_source->SetIcon(icon_factory_.GetIcon(tab_id)); |
| 92 scoped_ptr<IconWithBadgeImageSource::Badge> badge; |
| 93 std::string badge_text = extension_action_->GetBadgeText(tab_id); |
| 94 if (!badge_text.empty()) { |
| 95 badge.reset(new IconWithBadgeImageSource::Badge( |
| 96 badge_text, |
| 97 extension_action_->GetBadgeTextColor(tab_id), |
| 98 extension_action_->GetBadgeBackgroundColor(tab_id))); |
| 99 } |
| 100 image_source->SetBadge(badge.Pass()); |
| 88 | 101 |
| 89 gfx::ImageSkia ExtensionActionViewController::GetIconWithBadge() { | 102 return gfx::Image(gfx::ImageSkia(image_source.release(), size)); |
| 90 if (!ExtensionIsValid()) | |
| 91 return gfx::ImageSkia(); | |
| 92 | |
| 93 content::WebContents* web_contents = view_delegate_->GetCurrentWebContents(); | |
| 94 gfx::Size spacing(0, 3); | |
| 95 gfx::ImageSkia icon = *GetIcon(web_contents).ToImageSkia(); | |
| 96 if (!IsEnabled(web_contents)) | |
| 97 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | |
| 98 return extension_action_->GetIconWithBadge( | |
| 99 icon, SessionTabHelper::IdForTab(web_contents), spacing); | |
| 100 } | 103 } |
| 101 | 104 |
| 102 base::string16 ExtensionActionViewController::GetActionName() const { | 105 base::string16 ExtensionActionViewController::GetActionName() const { |
| 103 if (!ExtensionIsValid()) | 106 if (!ExtensionIsValid()) |
| 104 return base::string16(); | 107 return base::string16(); |
| 105 | 108 |
| 106 return base::UTF8ToUTF16(extension_->name()); | 109 return base::UTF8ToUTF16(extension_->name()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 base::string16 ExtensionActionViewController::GetAccessibleName( | 112 base::string16 ExtensionActionViewController::GetAccessibleName( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 extension_.get(), browser_, grant_tab_permissions) == | 217 extension_.get(), browser_, grant_tab_permissions) == |
| 215 ExtensionAction::ACTION_SHOW_POPUP) { | 218 ExtensionAction::ACTION_SHOW_POPUP) { |
| 216 GURL popup_url = extension_action_->GetPopupUrl( | 219 GURL popup_url = extension_action_->GetPopupUrl( |
| 217 SessionTabHelper::IdForTab(view_delegate_->GetCurrentWebContents())); | 220 SessionTabHelper::IdForTab(view_delegate_->GetCurrentWebContents())); |
| 218 return GetPreferredPopupViewController() | 221 return GetPreferredPopupViewController() |
| 219 ->TriggerPopupWithUrl(show_action, popup_url, grant_tab_permissions); | 222 ->TriggerPopupWithUrl(show_action, popup_url, grant_tab_permissions); |
| 220 } | 223 } |
| 221 return false; | 224 return false; |
| 222 } | 225 } |
| 223 | 226 |
| 224 void ExtensionActionViewController::PaintExtra( | |
| 225 gfx::Canvas* canvas, | |
| 226 const gfx::Rect& bounds, | |
| 227 content::WebContents* web_contents) const { | |
| 228 if (!ExtensionIsValid()) | |
| 229 return; | |
| 230 | |
| 231 int tab_id = SessionTabHelper::IdForTab(web_contents); | |
| 232 if (tab_id >= 0) | |
| 233 extension_action_->PaintBadge(canvas, bounds, tab_id); | |
| 234 } | |
| 235 | |
| 236 void ExtensionActionViewController::RegisterCommand() { | 227 void ExtensionActionViewController::RegisterCommand() { |
| 237 if (!ExtensionIsValid()) | 228 if (!ExtensionIsValid()) |
| 238 return; | 229 return; |
| 239 | 230 |
| 240 platform_delegate_->RegisterCommand(); | 231 platform_delegate_->RegisterCommand(); |
| 241 } | 232 } |
| 242 | 233 |
| 243 void ExtensionActionViewController::InspectPopup() { | 234 void ExtensionActionViewController::InspectPopup() { |
| 244 ExecuteAction(SHOW_POPUP_AND_INSPECT, true); | 235 ExecuteAction(SHOW_POPUP_AND_INSPECT, true); |
| 245 } | 236 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 popup_host_observer_.Remove(popup_host_); | 352 popup_host_observer_.Remove(popup_host_); |
| 362 popup_host_ = nullptr; | 353 popup_host_ = nullptr; |
| 363 if (toolbar_actions_bar_) { | 354 if (toolbar_actions_bar_) { |
| 364 toolbar_actions_bar_->SetPopupOwner(nullptr); | 355 toolbar_actions_bar_->SetPopupOwner(nullptr); |
| 365 if (toolbar_actions_bar_->popped_out_action() == this && | 356 if (toolbar_actions_bar_->popped_out_action() == this && |
| 366 !view_delegate_->IsMenuRunning()) | 357 !view_delegate_->IsMenuRunning()) |
| 367 toolbar_actions_bar_->UndoPopOut(); | 358 toolbar_actions_bar_->UndoPopOut(); |
| 368 } | 359 } |
| 369 view_delegate_->OnPopupClosed(); | 360 view_delegate_->OnPopupClosed(); |
| 370 } | 361 } |
| OLD | NEW |