Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/toolbar/media_router_action.h" | 5 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 6 | 6 |
| 7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/media/router/issue.h" | 9 #include "chrome/browser/media/router/issue.h" |
| 10 #include "chrome/browser/media/router/media_route.h" | 10 #include "chrome/browser/media/router/media_route.h" |
| 11 #include "chrome/browser/media/router/media_router.h" | 11 #include "chrome/browser/media/router/media_router.h" |
| 12 #include "chrome/browser/media/router/media_router_factory.h" | 12 #include "chrome/browser/media/router/media_router_factory.h" |
| 13 #include "chrome/browser/media/router/media_router_metrics.h" | 13 #include "chrome/browser/media/router/media_router_metrics.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 17 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 18 #include "chrome/browser/ui/toolbar/media_router_action_platform_delegate.h" | 18 #include "chrome/browser/ui/toolbar/media_router_action_platform_delegate.h" |
| 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 20 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" | 20 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" |
| 21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
|
apacible
2016/07/13 22:30:19
Can we remove resource_bundle.h?
| |
| 25 #include "ui/gfx/color_palette.h" | |
| 25 #include "ui/gfx/image/image_skia.h" | 26 #include "ui/gfx/image/image_skia.h" |
| 27 #include "ui/gfx/paint_vector_icon.h" | |
| 26 | 28 |
| 27 using media_router::MediaRouterDialogControllerImpl; | 29 using media_router::MediaRouterDialogControllerImpl; |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 media_router::MediaRouter* GetMediaRouter(Browser* browser) { | 33 media_router::MediaRouter* GetMediaRouter(Browser* browser) { |
| 32 return media_router::MediaRouterFactory::GetApiForBrowserContext( | 34 return media_router::MediaRouterFactory::GetApiForBrowserContext( |
| 33 browser->profile()); | 35 browser->profile()); |
| 34 } | 36 } |
| 35 | 37 |
| 36 } // namespace | 38 } // namespace |
| 37 | 39 |
| 38 MediaRouterAction::MediaRouterAction(Browser* browser, | 40 MediaRouterAction::MediaRouterAction(Browser* browser, |
| 39 ToolbarActionsBar* toolbar_actions_bar) | 41 ToolbarActionsBar* toolbar_actions_bar) |
| 40 : media_router::IssuesObserver(GetMediaRouter(browser)), | 42 : media_router::IssuesObserver(GetMediaRouter(browser)), |
| 41 media_router::MediaRoutesObserver(GetMediaRouter(browser)), | 43 media_router::MediaRoutesObserver(GetMediaRouter(browser)), |
| 42 media_router_active_icon_( | 44 current_icon_(gfx::VectorIconId::MEDIA_ROUTER_IDLE), |
| 43 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 44 IDR_MEDIA_ROUTER_ACTIVE_ICON)), | |
| 45 media_router_error_icon_( | |
| 46 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 47 IDR_MEDIA_ROUTER_ERROR_ICON)), | |
| 48 media_router_idle_icon_( | |
| 49 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 50 IDR_MEDIA_ROUTER_IDLE_ICON)), | |
| 51 media_router_warning_icon_( | |
| 52 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 53 IDR_MEDIA_ROUTER_WARNING_ICON)), | |
| 54 current_icon_(&media_router_idle_icon_), | |
| 55 has_local_display_route_(false), | 45 has_local_display_route_(false), |
| 56 delegate_(nullptr), | 46 delegate_(nullptr), |
| 57 browser_(browser), | 47 browser_(browser), |
| 58 toolbar_actions_bar_(toolbar_actions_bar), | 48 toolbar_actions_bar_(toolbar_actions_bar), |
| 59 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), | 49 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), |
| 60 contextual_menu_(browser), | 50 contextual_menu_(browser), |
| 61 tab_strip_model_observer_(this), | 51 tab_strip_model_observer_(this), |
| 62 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) { |
| 63 DCHECK(browser_); | 53 DCHECK(browser_); |
| 64 DCHECK(toolbar_actions_bar_); | 54 DCHECK(toolbar_actions_bar_); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 82 // WebContents ready. | 72 // WebContents ready. |
| 83 // In cases such as opening a new browser window, SetDelegate() will be | 73 // In cases such as opening a new browser window, SetDelegate() will be |
| 84 // called before the WebContents is set. In those cases, we update the popup | 74 // called before the WebContents is set. In those cases, we update the popup |
| 85 // state when ActiveTabChanged() is called. | 75 // state when ActiveTabChanged() is called. |
| 86 if (delegate_ && delegate_->GetCurrentWebContents()) | 76 if (delegate_ && delegate_->GetCurrentWebContents()) |
| 87 UpdatePopupState(); | 77 UpdatePopupState(); |
| 88 } | 78 } |
| 89 | 79 |
| 90 gfx::Image MediaRouterAction::GetIcon(content::WebContents* web_contents, | 80 gfx::Image MediaRouterAction::GetIcon(content::WebContents* web_contents, |
| 91 const gfx::Size& size) { | 81 const gfx::Size& size) { |
| 92 return *current_icon_; | 82 // Color is defined in the icon. |
| 83 return gfx::Image( | |
| 84 gfx::CreateVectorIcon(current_icon_, gfx::kPlaceholderColor)); | |
| 93 } | 85 } |
| 94 | 86 |
| 95 base::string16 MediaRouterAction::GetActionName() const { | 87 base::string16 MediaRouterAction::GetActionName() const { |
| 96 return l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE); | 88 return l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE); |
| 97 } | 89 } |
| 98 | 90 |
| 99 base::string16 MediaRouterAction::GetAccessibleName( | 91 base::string16 MediaRouterAction::GetAccessibleName( |
| 100 content::WebContents* web_contents) const { | 92 content::WebContents* web_contents) const { |
| 101 return GetTooltip(web_contents); | 93 return GetTooltip(web_contents); |
| 102 } | 94 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 DCHECK(web_contents); | 219 DCHECK(web_contents); |
| 228 return MediaRouterDialogControllerImpl::GetOrCreateForWebContents( | 220 return MediaRouterDialogControllerImpl::GetOrCreateForWebContents( |
| 229 web_contents); | 221 web_contents); |
| 230 } | 222 } |
| 231 | 223 |
| 232 MediaRouterActionPlatformDelegate* MediaRouterAction::GetPlatformDelegate() { | 224 MediaRouterActionPlatformDelegate* MediaRouterAction::GetPlatformDelegate() { |
| 233 return platform_delegate_.get(); | 225 return platform_delegate_.get(); |
| 234 } | 226 } |
| 235 | 227 |
| 236 void MediaRouterAction::MaybeUpdateIcon() { | 228 void MediaRouterAction::MaybeUpdateIcon() { |
| 237 const gfx::Image* new_icon = GetCurrentIcon(); | 229 gfx::VectorIconId new_icon = GetCurrentIcon(); |
| 238 | 230 |
| 239 // Update the current state if it has changed. | 231 // Update the current state if it has changed. |
| 240 if (new_icon != current_icon_) { | 232 if (new_icon != current_icon_) { |
| 241 current_icon_ = new_icon; | 233 current_icon_ = new_icon; |
| 242 | 234 |
| 243 // Tell the associated view to update its icon to reflect the change made | 235 // Tell the associated view to update its icon to reflect the change made |
| 244 // above. | 236 // above. |
| 245 if (delegate_) | 237 if (delegate_) |
| 246 delegate_->UpdateState(); | 238 delegate_->UpdateState(); |
| 247 } | 239 } |
| 248 } | 240 } |
| 249 | 241 |
| 250 const gfx::Image* MediaRouterAction::GetCurrentIcon() const { | 242 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { |
| 251 // Highest priority is to indicate whether there's an issue. | 243 // Highest priority is to indicate whether there's an issue. |
| 252 if (issue_) { | 244 if (issue_) { |
| 253 if (issue_->severity() == media_router::Issue::FATAL) | 245 if (issue_->severity() == media_router::Issue::FATAL) |
| 254 return &media_router_error_icon_; | 246 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; |
| 255 if (issue_->severity() == media_router::Issue::WARNING) | 247 if (issue_->severity() == media_router::Issue::WARNING) |
| 256 return &media_router_warning_icon_; | 248 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; |
| 257 } | 249 } |
| 258 | 250 |
| 259 return has_local_display_route_ ? &media_router_active_icon_ | 251 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE |
| 260 : &media_router_idle_icon_; | 252 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; |
| 261 } | 253 } |
| OLD | NEW |