apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
| 6 | #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
| 7 | |
apacible | 4eebb13 | 2015-08-11 17:51:02 | [diff] [blame] | 8 | #include "chrome/browser/media/router/issues_observer.h" |
| 9 | #include "chrome/browser/media/router/media_routes_observer.h" |
apacible | e3aa6665 | 2015-07-23 22:18:24 | [diff] [blame] | 10 | #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 11 | #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 12 | |
apacible | 4b169035 | 2015-07-20 16:32:36 | [diff] [blame] | 13 | class Browser; |
| 14 | class MediaRouterActionPlatformDelegate; |
| 15 | |
imcheng | 12fcff4 | 2015-06-04 18:37:12 | [diff] [blame] | 16 | namespace media_router { |
avayvod | 69b3a41f | 2015-07-29 16:58:17 | [diff] [blame] | 17 | class MediaRouterDialogController; |
imcheng | 12fcff4 | 2015-06-04 18:37:12 | [diff] [blame] | 18 | } // namespace media_router |
| 19 | |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 20 | // The class for the Media Router component action that will be shown in |
| 21 | // the toolbar. |
apacible | 4eebb13 | 2015-08-11 17:51:02 | [diff] [blame] | 22 | class MediaRouterAction : public ToolbarActionViewController, |
| 23 | public media_router::IssuesObserver, |
| 24 | public media_router::MediaRoutesObserver { |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 25 | public: |
apacible | 4b169035 | 2015-07-20 16:32:36 | [diff] [blame] | 26 | explicit MediaRouterAction(Browser* browser); |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 27 | ~MediaRouterAction() override; |
| 28 | |
| 29 | // ToolbarActionViewController implementation. |
| 30 | const std::string& GetId() const override; |
| 31 | void SetDelegate(ToolbarActionViewDelegate* delegate) override; |
rdevlin.cronin | 3a57a7f | 2015-07-06 21:22:43 | [diff] [blame] | 32 | gfx::Image GetIcon(content::WebContents* web_contents, |
| 33 | const gfx::Size& size) override; |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 34 | base::string16 GetActionName() const override; |
| 35 | base::string16 GetAccessibleName(content::WebContents* web_contents) |
| 36 | const override; |
| 37 | base::string16 GetTooltip(content::WebContents* web_contents) |
| 38 | const override; |
| 39 | bool IsEnabled(content::WebContents* web_contents) const override; |
| 40 | bool WantsToRun(content::WebContents* web_contents) const override; |
| 41 | bool HasPopup(content::WebContents* web_contents) const override; |
| 42 | void HidePopup() override; |
| 43 | gfx::NativeView GetPopupNativeView() override; |
| 44 | ui::MenuModel* GetContextMenu() override; |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 45 | bool CanDrag() const override; |
| 46 | bool ExecuteAction(bool by_user) override; |
| 47 | void UpdateState() override; |
rdevlin.cronin | ac27cf3 | 2015-07-09 17:12:34 | [diff] [blame] | 48 | bool DisabledClickOpensMenu() const override; |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 49 | |
apacible | 4eebb13 | 2015-08-11 17:51:02 | [diff] [blame] | 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 | |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 57 | private: |
imcheng | 12fcff4 | 2015-06-04 18:37:12 | [diff] [blame] | 58 | // Returns a reference to the MediaRouterDialogController associated with |
| 59 | // |delegate_|'s current WebContents. Guaranteed to be non-null. |
| 60 | // |delegate_| and its current WebContents must not be null. |
avayvod | 69b3a41f | 2015-07-29 16:58:17 | [diff] [blame] | 61 | media_router::MediaRouterDialogController* GetMediaRouterDialogController(); |
imcheng | 12fcff4 | 2015-06-04 18:37:12 | [diff] [blame] | 62 | |
apacible | 4eebb13 | 2015-08-11 17:51:02 | [diff] [blame] | 63 | // Overridden by tests. |
| 64 | virtual media_router::MediaRouter* GetMediaRouter(Browser* browser); |
| 65 | |
| 66 | // Checks if the current icon of MediaRouterAction has changed. If so, |
| 67 | // updates |current_icon_|. |
| 68 | void MaybeUpdateIcon(); |
| 69 | |
| 70 | const gfx::Image* GetCurrentIcon() const; |
| 71 | |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 72 | const std::string id_; |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 73 | |
| 74 | // Cached icons. |
apacible | 4eebb13 | 2015-08-11 17:51:02 | [diff] [blame] | 75 | // Indicates that the current Chrome profile is using at least one device. |
| 76 | const gfx::Image media_router_active_icon_; |
| 77 | // Indicates a failure, e.g. session launch failure. |
| 78 | const gfx::Image media_router_error_icon_; |
| 79 | // Indicates that the current Chrome profile is not using any devices. |
| 80 | // Devices may or may not be available. |
| 81 | const gfx::Image media_router_idle_icon_; |
| 82 | // Indicates there is a warning message. |
| 83 | const gfx::Image media_router_warning_icon_; |
| 84 | |
| 85 | // The current icon to show. This is updated based on the current issues and |
| 86 | // routes since |this| is an IssueObserver and MediaRoutesObserver. |
| 87 | const gfx::Image* current_icon_; |
| 88 | |
| 89 | // The current issue shown in the Media Router WebUI. Can be null. It is set |
| 90 | // in OnIssueUpdated(), which is called by the IssueManager. |
| 91 | scoped_ptr<media_router::Issue> issue_; |
| 92 | |
| 93 | // Whether a local active route exists. |
| 94 | bool has_local_route_; |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 95 | |
| 96 | ToolbarActionViewDelegate* delegate_; |
| 97 | |
apacible | 4b169035 | 2015-07-20 16:32:36 | [diff] [blame] | 98 | // The delegate to handle platform-specific implementations. |
| 99 | scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; |
| 100 | |
apacible | e3aa6665 | 2015-07-23 22:18:24 | [diff] [blame] | 101 | MediaRouterContextualMenu contextual_menu_; |
| 102 | |
apacible | 86792f6 | 2015-04-19 03:40:00 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); |
| 104 | }; |
| 105 | |
| 106 | #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |