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