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 "chrome/browser/media/router/issues_observer.h" | |
9 #include "chrome/browser/media/router/media_routes_observer.h" | |
8 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" | 10 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" |
9 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
10 | 12 |
11 class Browser; | 13 class Browser; |
12 class MediaRouterActionPlatformDelegate; | 14 class MediaRouterActionPlatformDelegate; |
13 | 15 |
14 namespace media_router { | 16 namespace media_router { |
15 class MediaRouterDialogController; | 17 class MediaRouterDialogController; |
16 } // namespace media_router | 18 } // namespace media_router |
17 | 19 |
18 // The class for the Media Router component action that will be shown in | 20 // The class for the Media Router component action that will be shown in |
19 // the toolbar. | 21 // the toolbar. |
20 class MediaRouterAction : public ToolbarActionViewController { | 22 class MediaRouterAction : public ToolbarActionViewController, |
23 public media_router::IssuesObserver, | |
24 public media_router::MediaRoutesObserver { | |
21 public: | 25 public: |
22 explicit MediaRouterAction(Browser* browser); | 26 explicit MediaRouterAction(Browser* browser); |
23 ~MediaRouterAction() override; | 27 ~MediaRouterAction() override; |
24 | 28 |
25 // ToolbarActionViewController implementation. | 29 // ToolbarActionViewController implementation. |
26 const std::string& GetId() const override; | 30 const std::string& GetId() const override; |
27 void SetDelegate(ToolbarActionViewDelegate* delegate) override; | 31 void SetDelegate(ToolbarActionViewDelegate* delegate) override; |
28 gfx::Image GetIcon(content::WebContents* web_contents, | 32 gfx::Image GetIcon(content::WebContents* web_contents, |
29 const gfx::Size& size) override; | 33 const gfx::Size& size) override; |
30 base::string16 GetActionName() const override; | 34 base::string16 GetActionName() const override; |
31 base::string16 GetAccessibleName(content::WebContents* web_contents) | 35 base::string16 GetAccessibleName(content::WebContents* web_contents) |
32 const override; | 36 const override; |
33 base::string16 GetTooltip(content::WebContents* web_contents) | 37 base::string16 GetTooltip(content::WebContents* web_contents) |
34 const override; | 38 const override; |
35 bool IsEnabled(content::WebContents* web_contents) const override; | 39 bool IsEnabled(content::WebContents* web_contents) const override; |
36 bool WantsToRun(content::WebContents* web_contents) const override; | 40 bool WantsToRun(content::WebContents* web_contents) const override; |
37 bool HasPopup(content::WebContents* web_contents) const override; | 41 bool HasPopup(content::WebContents* web_contents) const override; |
38 void HidePopup() override; | 42 void HidePopup() override; |
39 gfx::NativeView GetPopupNativeView() override; | 43 gfx::NativeView GetPopupNativeView() override; |
40 ui::MenuModel* GetContextMenu() override; | 44 ui::MenuModel* GetContextMenu() override; |
41 bool CanDrag() const override; | 45 bool CanDrag() const override; |
42 bool ExecuteAction(bool by_user) override; | 46 bool ExecuteAction(bool by_user) override; |
43 void UpdateState() override; | 47 void UpdateState() override; |
44 bool DisabledClickOpensMenu() const override; | 48 bool DisabledClickOpensMenu() const override; |
45 | 49 |
50 // media_router::IssuesObserver: | |
51 void OnIssueUpdated(const media_router::Issue* issue) override; | |
52 | |
53 // media_router::MediaRoutesObserver: | |
54 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes) | |
55 override; | |
56 | |
46 private: | 57 private: |
47 // Returns a reference to the MediaRouterDialogController associated with | 58 // Returns a reference to the MediaRouterDialogController associated with |
48 // |delegate_|'s current WebContents. Guaranteed to be non-null. | 59 // |delegate_|'s current WebContents. Guaranteed to be non-null. |
49 // |delegate_| and its current WebContents must not be null. | 60 // |delegate_| and its current WebContents must not be null. |
50 media_router::MediaRouterDialogController* GetMediaRouterDialogController(); | 61 media_router::MediaRouterDialogController* GetMediaRouterDialogController(); |
51 | 62 |
63 // Overridden by tests. | |
64 virtual media_router::MediaRouter* GetMediaRouter(Browser* browser); | |
65 | |
66 // Checks if the currents state of MediaRouterAction has changed. Updates | |
67 // |state_|. If |state_| has changed, updates |state_| and then updates | |
68 // MediaRouterAction's icon. | |
69 void MaybeUpdateIcon(); | |
70 | |
71 gfx::Image* GetCurrentIcon(); | |
Kevin M
2015/08/05 20:20:27
const
Kevin M
2015/08/05 20:20:27
Mark this function as const.
(inspired by a miu c
apacible
2015/08/05 22:13:52
Done.
apacible
2015/08/05 22:13:52
Done.
| |
72 | |
52 const std::string id_; | 73 const std::string id_; |
53 const base::string16 name_; | 74 const base::string16 name_; |
54 | 75 |
55 // Cached icons. | 76 // Cached icons. |
77 gfx::Image media_router_active_icon_; | |
Kevin M
2015/08/05 20:20:27
Make these const?
apacible
2015/08/05 22:13:52
Done.
| |
78 gfx::Image media_router_error_icon_; | |
56 gfx::Image media_router_idle_icon_; | 79 gfx::Image media_router_idle_icon_; |
80 gfx::Image media_router_warning_icon_; | |
81 | |
82 // The current icon to show. This is updated based on the current issues and | |
83 // routes since |this| is an IssueObserver and MediaRoutesObserver. | |
84 // The possible icons and their behaviors are: | |
85 // Idle: Indicates that the current Chrome profile is not using any | |
86 // devices. Devices may or may not be available. | |
87 // Active: Indicates that the current Chrome profile is using at least one | |
88 // device. | |
89 // Error: Indicates a failure, e.g. session launch failure. | |
90 // Warning: Indicates there is a warning message. | |
91 gfx::Image* current_icon_; | |
Kevin M
2015/08/05 20:20:27
const ref?
apacible
2015/08/05 22:13:52
Talked offline, const pointer instead.
| |
92 | |
93 // The current issue shown in the Media Router WebUI. Can be null. It is set | |
94 // in |OnIssueUpdated|, which is called by the IssueManager. | |
95 scoped_ptr<media_router::Issue> issue_; | |
96 | |
97 // Whether there exists a local active route. | |
98 bool has_local_routes_; | |
57 | 99 |
58 ToolbarActionViewDelegate* delegate_; | 100 ToolbarActionViewDelegate* delegate_; |
59 | 101 |
60 // The delegate to handle platform-specific implementations. | 102 // The delegate to handle platform-specific implementations. |
61 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; | 103 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; |
62 | 104 |
63 MediaRouterContextualMenu contextual_menu_; | 105 MediaRouterContextualMenu contextual_menu_; |
64 | 106 |
65 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); | 107 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); |
66 }; | 108 }; |
67 | 109 |
68 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ | 110 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
OLD | NEW |