| 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 "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
| 26 #include "ui/gfx/vector_icon_types.h" |
| 27 #include "ui/vector_icons/vector_icons.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 current_icon_(gfx::VectorIconId::MEDIA_ROUTER_IDLE), | 44 current_icon_(&ui::kMediaRouterIdleIcon), |
| 43 has_local_display_route_(false), | 45 has_local_display_route_(false), |
| 44 has_dialog_(false), | 46 has_dialog_(false), |
| 45 delegate_(nullptr), | 47 delegate_(nullptr), |
| 46 browser_(browser), | 48 browser_(browser), |
| 47 toolbar_actions_bar_(toolbar_actions_bar), | 49 toolbar_actions_bar_(toolbar_actions_bar), |
| 48 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), | 50 platform_delegate_(MediaRouterActionPlatformDelegate::Create(browser)), |
| 49 contextual_menu_(browser), | 51 contextual_menu_(browser), |
| 50 tab_strip_model_observer_(this), | 52 tab_strip_model_observer_(this), |
| 51 toolbar_actions_bar_observer_(this), | 53 toolbar_actions_bar_observer_(this), |
| 52 weak_ptr_factory_(this) { | 54 weak_ptr_factory_(this) { |
| 53 DCHECK(browser_); | 55 DCHECK(browser_); |
| 54 DCHECK(toolbar_actions_bar_); | 56 DCHECK(toolbar_actions_bar_); |
| 55 tab_strip_model_observer_.Add(browser_->tab_strip_model()); | 57 tab_strip_model_observer_.Add(browser_->tab_strip_model()); |
| 56 toolbar_actions_bar_observer_.Add(toolbar_actions_bar_); | 58 toolbar_actions_bar_observer_.Add(toolbar_actions_bar_); |
| 57 IssuesObserver::Init(); | 59 IssuesObserver::Init(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 MediaRouterAction::~MediaRouterAction() { | 62 MediaRouterAction::~MediaRouterAction() { |
| 61 } | 63 } |
| 62 | 64 |
| 63 // static | 65 // static |
| 64 SkColor MediaRouterAction::GetIconColor(gfx::VectorIconId icon_id) { | 66 SkColor MediaRouterAction::GetIconColor(const gfx::VectorIcon& icon_id) { |
| 65 switch (icon_id) { | 67 if (&icon_id == &ui::kMediaRouterIdleIcon) |
| 66 case gfx::VectorIconId::MEDIA_ROUTER_IDLE: | 68 return gfx::kChromeIconGrey; |
| 67 return gfx::kChromeIconGrey; | 69 else if (&icon_id == &ui::kMediaRouterActiveIcon) |
| 68 case gfx::VectorIconId::MEDIA_ROUTER_ACTIVE: | 70 return gfx::kGoogleBlue500; |
| 69 return gfx::kGoogleBlue500; | 71 else if (&icon_id == &ui::kMediaRouterWarningIcon) |
| 70 case gfx::VectorIconId::MEDIA_ROUTER_WARNING: | 72 return gfx::kGoogleYellow700; |
| 71 return gfx::kGoogleYellow700; | 73 else if (&icon_id == &ui::kMediaRouterErrorIcon) |
| 72 case gfx::VectorIconId::MEDIA_ROUTER_ERROR: | 74 return gfx::kGoogleRed700; |
| 73 return gfx::kGoogleRed700; | 75 |
| 74 default: | 76 NOTREACHED(); |
| 75 NOTREACHED(); | 77 return gfx::kPlaceholderColor; |
| 76 return gfx::kPlaceholderColor; | |
| 77 } | |
| 78 } | 78 } |
| 79 | 79 |
| 80 std::string MediaRouterAction::GetId() const { | 80 std::string MediaRouterAction::GetId() const { |
| 81 return ComponentToolbarActionsFactory::kMediaRouterActionId; | 81 return ComponentToolbarActionsFactory::kMediaRouterActionId; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void MediaRouterAction::SetDelegate(ToolbarActionViewDelegate* delegate) { | 84 void MediaRouterAction::SetDelegate(ToolbarActionViewDelegate* delegate) { |
| 85 delegate_ = delegate; | 85 delegate_ = delegate; |
| 86 | 86 |
| 87 // In cases such as opening a new browser window, SetDelegate() will be | 87 // In cases such as opening a new browser window, SetDelegate() will be |
| 88 // called before the WebContents is set. In those cases, we register with the | 88 // called before the WebContents is set. In those cases, we register with the |
| 89 // dialog controller when ActiveTabChanged() is called. | 89 // dialog controller when ActiveTabChanged() is called. |
| 90 if (delegate_ && delegate_->GetCurrentWebContents()) | 90 if (delegate_ && delegate_->GetCurrentWebContents()) |
| 91 RegisterWithDialogController(); | 91 RegisterWithDialogController(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 gfx::Image MediaRouterAction::GetIcon(content::WebContents* web_contents, | 94 gfx::Image MediaRouterAction::GetIcon(content::WebContents* web_contents, |
| 95 const gfx::Size& size) { | 95 const gfx::Size& size) { |
| 96 return gfx::Image( | 96 return gfx::Image( |
| 97 gfx::CreateVectorIcon(current_icon_, GetIconColor(current_icon_))); | 97 gfx::CreateVectorIcon(*current_icon_, GetIconColor(*current_icon_))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 base::string16 MediaRouterAction::GetActionName() const { | 100 base::string16 MediaRouterAction::GetActionName() const { |
| 101 return l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE); | 101 return l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE); |
| 102 } | 102 } |
| 103 | 103 |
| 104 base::string16 MediaRouterAction::GetAccessibleName( | 104 base::string16 MediaRouterAction::GetAccessibleName( |
| 105 content::WebContents* web_contents) const { | 105 content::WebContents* web_contents) const { |
| 106 return GetTooltip(web_contents); | 106 return GetTooltip(web_contents); |
| 107 } | 107 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 DCHECK(web_contents); | 254 DCHECK(web_contents); |
| 255 return MediaRouterDialogControllerImpl::GetOrCreateForWebContents( | 255 return MediaRouterDialogControllerImpl::GetOrCreateForWebContents( |
| 256 web_contents); | 256 web_contents); |
| 257 } | 257 } |
| 258 | 258 |
| 259 MediaRouterActionPlatformDelegate* MediaRouterAction::GetPlatformDelegate() { | 259 MediaRouterActionPlatformDelegate* MediaRouterAction::GetPlatformDelegate() { |
| 260 return platform_delegate_.get(); | 260 return platform_delegate_.get(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void MediaRouterAction::MaybeUpdateIcon() { | 263 void MediaRouterAction::MaybeUpdateIcon() { |
| 264 gfx::VectorIconId new_icon = GetCurrentIcon(); | 264 const gfx::VectorIcon& new_icon = GetCurrentIcon(); |
| 265 | 265 |
| 266 // Update the current state if it has changed. | 266 // Update the current state if it has changed. |
| 267 if (new_icon != current_icon_) { | 267 if (&new_icon != current_icon_) { |
| 268 current_icon_ = new_icon; | 268 current_icon_ = &new_icon; |
| 269 | 269 |
| 270 // Tell the associated view to update its icon to reflect the change made | 270 // Tell the associated view to update its icon to reflect the change made |
| 271 // above. If MaybeUpdateIcon() was called as a result of instantiating | 271 // above. If MaybeUpdateIcon() was called as a result of instantiating |
| 272 // |this|, then |delegate_| may not be set yet. | 272 // |this|, then |delegate_| may not be set yet. |
| 273 if (delegate_) | 273 if (delegate_) |
| 274 UpdateState(); | 274 UpdateState(); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 gfx::VectorIconId MediaRouterAction::GetCurrentIcon() const { | 278 const gfx::VectorIcon& MediaRouterAction::GetCurrentIcon() const { |
| 279 // Highest priority is to indicate whether there's an issue. | 279 // Highest priority is to indicate whether there's an issue. |
| 280 if (current_issue_) { | 280 if (current_issue_) { |
| 281 media_router::IssueInfo::Severity severity = current_issue_->severity; | 281 media_router::IssueInfo::Severity severity = current_issue_->severity; |
| 282 if (severity == media_router::IssueInfo::Severity::FATAL) | 282 if (severity == media_router::IssueInfo::Severity::FATAL) |
| 283 return gfx::VectorIconId::MEDIA_ROUTER_ERROR; | 283 return ui::kMediaRouterErrorIcon; |
| 284 if (severity == media_router::IssueInfo::Severity::WARNING) | 284 if (severity == media_router::IssueInfo::Severity::WARNING) |
| 285 return gfx::VectorIconId::MEDIA_ROUTER_WARNING; | 285 return ui::kMediaRouterWarningIcon; |
| 286 // Fall through for Severity::NOTIFICATION. | 286 // Fall through for Severity::NOTIFICATION. |
| 287 } | 287 } |
| 288 | 288 |
| 289 return has_local_display_route_ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE | 289 return has_local_display_route_ ? ui::kMediaRouterActiveIcon |
| 290 : gfx::VectorIconId::MEDIA_ROUTER_IDLE; | 290 : ui::kMediaRouterIdleIcon; |
| 291 } | 291 } |
| OLD | NEW |