| 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 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
| 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
| 10 #include "chrome/browser/media/router/issues_observer.h" | 10 #include "chrome/browser/media/router/issues_observer.h" |
| 11 #include "chrome/browser/media/router/media_routes_observer.h" | 11 #include "chrome/browser/media/router/media_routes_observer.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 13 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" | 13 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" |
| 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h" | |
| 17 #include "ui/gfx/vector_icons_public.h" | 16 #include "ui/gfx/vector_icons_public.h" |
| 18 | 17 |
| 19 class Browser; | 18 class Browser; |
| 20 class MediaRouterActionPlatformDelegate; | 19 class MediaRouterActionPlatformDelegate; |
| 21 class TabStripModel; | 20 class TabStripModel; |
| 22 | 21 |
| 23 namespace media_router { | 22 namespace media_router { |
| 24 class MediaRouterDialogControllerImpl; | 23 class MediaRouterDialogControllerImpl; |
| 25 } // namespace media_router | 24 } // namespace media_router |
| 26 | 25 |
| 27 // The class for the Media Router component action that will be shown in | 26 // The class for the Media Router component action that will be shown in |
| 28 // the toolbar. | 27 // the toolbar. |
| 29 class MediaRouterAction : public ToolbarActionViewController, | 28 class MediaRouterAction : public ToolbarActionViewController, |
| 30 public media_router::IssuesObserver, | 29 public media_router::IssuesObserver, |
| 31 public media_router::MediaRoutesObserver, | 30 public media_router::MediaRoutesObserver, |
| 32 public TabStripModelObserver, | 31 public TabStripModelObserver { |
| 33 public ToolbarActionsBarObserver { | |
| 34 public: | 32 public: |
| 35 MediaRouterAction(Browser* browser, ToolbarActionsBar* toolbar_actions_bar); | 33 MediaRouterAction(Browser* browser, ToolbarActionsBar* toolbar_actions_bar); |
| 36 ~MediaRouterAction() override; | 34 ~MediaRouterAction() override; |
| 37 | 35 |
| 38 // ToolbarActionViewController implementation. | 36 // ToolbarActionViewController implementation. |
| 39 std::string GetId() const override; | 37 std::string GetId() const override; |
| 40 void SetDelegate(ToolbarActionViewDelegate* delegate) override; | 38 void SetDelegate(ToolbarActionViewDelegate* delegate) override; |
| 41 gfx::Image GetIcon(content::WebContents* web_contents, | 39 gfx::Image GetIcon(content::WebContents* web_contents, |
| 42 const gfx::Size& size) override; | 40 const gfx::Size& size) override; |
| 43 base::string16 GetActionName() const override; | 41 base::string16 GetActionName() const override; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 62 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, | 60 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, |
| 63 const std::vector<media_router::MediaRoute::Id>& | 61 const std::vector<media_router::MediaRoute::Id>& |
| 64 joinable_route_ids) override; | 62 joinable_route_ids) override; |
| 65 | 63 |
| 66 // ToolbarStripModelObserver: | 64 // ToolbarStripModelObserver: |
| 67 void ActiveTabChanged(content::WebContents* old_contents, | 65 void ActiveTabChanged(content::WebContents* old_contents, |
| 68 content::WebContents* new_contents, | 66 content::WebContents* new_contents, |
| 69 int index, | 67 int index, |
| 70 int reason) override; | 68 int reason) override; |
| 71 | 69 |
| 72 // ToolbarActionsBarObserver: | 70 void OnPopupHidden(); |
| 73 void OnToolbarActionsBarAnimationEnded() override; | 71 void OnPopupShown(); |
| 74 | |
| 75 void OnDialogHidden(); | |
| 76 void OnDialogShown(); | |
| 77 | |
| 78 // Toggle the "Always show icon" option. | |
| 79 void ToggleVisibilityPreference(); | |
| 80 | |
| 81 // Removes the action from the toolbar and deletes |this| if the Media Router | |
| 82 // dialog is closed and there are no active local Media Routes. | |
| 83 // Overridden by tests. | |
| 84 virtual void MaybeRemoveAction(); | |
| 85 | |
| 86 protected: | |
| 87 // For accessing from tests. | |
| 88 base::WeakPtr<MediaRouterAction> GetWeakPtr(); | |
| 89 | 72 |
| 90 private: | 73 private: |
| 91 // Called when a new browser window is opened or when |delegate_| is swapped | 74 // Called when a new browser window is opened, the user switches tabs in the |
| 92 // out to be non-null and has a valid WebContents. | 75 // browser window, or when |delegate_| is swapped out to be non-null and has |
| 76 // a valid WebContents. |
| 93 // This updates the pressed/unpressed state of the icon, which is different | 77 // This updates the pressed/unpressed state of the icon, which is different |
| 94 // on a per-tab basis. | 78 // on a per-tab basis. |
| 95 void UpdateDialogState(); | 79 void UpdatePopupState(); |
| 96 | 80 |
| 97 // Returns a reference to the MediaRouterDialogControllerImpl associated with | 81 // Returns a reference to the MediaRouterDialogControllerImpl associated with |
| 98 // |delegate_|'s current WebContents. Guaranteed to be non-null. | 82 // |delegate_|'s current WebContents. Guaranteed to be non-null. |
| 99 // |delegate_| and its current WebContents must not be null. | 83 // |delegate_| and its current WebContents must not be null. |
| 100 // Marked virtual for tests. | 84 // Marked virtual for tests. |
| 101 virtual media_router::MediaRouterDialogControllerImpl* | 85 virtual media_router::MediaRouterDialogControllerImpl* |
| 102 GetMediaRouterDialogController(); | 86 GetMediaRouterDialogController(); |
| 103 | 87 |
| 104 // Overridden by tests. | 88 // Overridden by tests. |
| 105 virtual MediaRouterActionPlatformDelegate* GetPlatformDelegate(); | 89 virtual MediaRouterActionPlatformDelegate* GetPlatformDelegate(); |
| 106 | 90 |
| 107 // Checks if the current icon of MediaRouterAction has changed. If so, | 91 // Checks if the current icon of MediaRouterAction has changed. If so, |
| 108 // updates |current_icon_|. | 92 // updates |current_icon_|. |
| 109 void MaybeUpdateIcon(); | 93 void MaybeUpdateIcon(); |
| 110 | 94 |
| 111 // Returns whether the "Always show icon" option is checked. | |
| 112 bool ShouldAlwaysShowIcon(); | |
| 113 | |
| 114 gfx::VectorIconId GetCurrentIcon() const; | 95 gfx::VectorIconId GetCurrentIcon() const; |
| 115 | 96 |
| 116 // The current icon to show. This is updated based on the current issues and | 97 // The current icon to show. This is updated based on the current issues and |
| 117 // routes since |this| is an IssueObserver and MediaRoutesObserver. | 98 // routes since |this| is an IssueObserver and MediaRoutesObserver. |
| 118 gfx::VectorIconId current_icon_; | 99 gfx::VectorIconId current_icon_; |
| 119 | 100 |
| 120 // The current issue shown in the Media Router WebUI. Can be null. It is set | 101 // The current issue shown in the Media Router WebUI. Can be null. It is set |
| 121 // in OnIssueUpdated(), which is called by the IssueManager. | 102 // in OnIssueUpdated(), which is called by the IssueManager. |
| 122 std::unique_ptr<media_router::Issue> issue_; | 103 std::unique_ptr<media_router::Issue> issue_; |
| 123 | 104 |
| 124 // Whether a local displayable active route exists. | 105 // Whether a local displayable active route exists. |
| 125 bool has_local_display_route_; | 106 bool has_local_display_route_; |
| 126 | 107 |
| 127 // Whether the Media Router dialog is shown in the current tab. | |
| 128 // This should only be updated in OnDialogShown() and OnDialogHidden(). | |
| 129 bool has_dialog_; | |
| 130 | |
| 131 ToolbarActionViewDelegate* delegate_; | 108 ToolbarActionViewDelegate* delegate_; |
| 132 | 109 |
| 133 Browser* const browser_; | 110 Browser* const browser_; |
| 134 ToolbarActionsBar* const toolbar_actions_bar_; | 111 ToolbarActionsBar* const toolbar_actions_bar_; |
| 135 | 112 |
| 136 // The delegate to handle platform-specific implementations. | 113 // The delegate to handle platform-specific implementations. |
| 137 std::unique_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; | 114 std::unique_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; |
| 138 | 115 |
| 139 MediaRouterContextualMenu contextual_menu_; | 116 MediaRouterContextualMenu contextual_menu_; |
| 140 | 117 |
| 141 ScopedObserver<TabStripModel, TabStripModelObserver> | 118 ScopedObserver<TabStripModel, TabStripModelObserver> |
| 142 tab_strip_model_observer_; | 119 tab_strip_model_observer_; |
| 143 ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver> | |
| 144 toolbar_actions_bar_observer_; | |
| 145 | 120 |
| 146 base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_; | 121 base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_; |
| 147 | 122 |
| 148 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); | 123 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); |
| 149 }; | 124 }; |
| 150 | 125 |
| 151 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ | 126 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
| OLD | NEW |