blob: 7bab99bfdac90d1f773495926b40f9b629e0bfcf [file] [log] [blame]
apacible86792f62015-04-19 03:40:001// 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
apacible4eebb132015-08-11 17:51:028#include "chrome/browser/media/router/issues_observer.h"
9#include "chrome/browser/media/router/media_routes_observer.h"
apaciblee3aa66652015-07-23 22:18:2410#include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
apacible86792f62015-04-19 03:40:0011#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
12
apacible4b1690352015-07-20 16:32:3613class Browser;
14class MediaRouterActionPlatformDelegate;
15
imcheng12fcff42015-06-04 18:37:1216namespace media_router {
avayvod69b3a41f2015-07-29 16:58:1717class MediaRouterDialogController;
imcheng12fcff42015-06-04 18:37:1218} // namespace media_router
19
apacible86792f62015-04-19 03:40:0020// The class for the Media Router component action that will be shown in
21// the toolbar.
apacible4eebb132015-08-11 17:51:0222class MediaRouterAction : public ToolbarActionViewController,
23 public media_router::IssuesObserver,
24 public media_router::MediaRoutesObserver {
apacible86792f62015-04-19 03:40:0025 public:
apacible4b1690352015-07-20 16:32:3626 explicit MediaRouterAction(Browser* browser);
apacible86792f62015-04-19 03:40:0027 ~MediaRouterAction() override;
28
29 // ToolbarActionViewController implementation.
30 const std::string& GetId() const override;
31 void SetDelegate(ToolbarActionViewDelegate* delegate) override;
rdevlin.cronin3a57a7f2015-07-06 21:22:4332 gfx::Image GetIcon(content::WebContents* web_contents,
33 const gfx::Size& size) override;
apacible86792f62015-04-19 03:40:0034 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;
apacible86792f62015-04-19 03:40:0045 bool CanDrag() const override;
46 bool ExecuteAction(bool by_user) override;
47 void UpdateState() override;
rdevlin.croninac27cf32015-07-09 17:12:3448 bool DisabledClickOpensMenu() const override;
apacible86792f62015-04-19 03:40:0049
apacible4eebb132015-08-11 17:51:0250 // 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
apacible86792f62015-04-19 03:40:0057 private:
imcheng12fcff42015-06-04 18:37:1258 // 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.
avayvod69b3a41f2015-07-29 16:58:1761 media_router::MediaRouterDialogController* GetMediaRouterDialogController();
imcheng12fcff42015-06-04 18:37:1262
apacible4eebb132015-08-11 17:51:0263 // 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
apacible86792f62015-04-19 03:40:0072 const std::string id_;
apacible86792f62015-04-19 03:40:0073
74 // Cached icons.
apacible4eebb132015-08-11 17:51:0275 // 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_;
apacible86792f62015-04-19 03:40:0095
96 ToolbarActionViewDelegate* delegate_;
97
apacible4b1690352015-07-20 16:32:3698 // The delegate to handle platform-specific implementations.
99 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_;
100
apaciblee3aa66652015-07-23 22:18:24101 MediaRouterContextualMenu contextual_menu_;
102
apacible86792f62015-04-19 03:40:00103 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction);
104};
105
106#endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_