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