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.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
8 #include "base/scoped_observer.h"
9 #include "chrome/browser/media/router/issues_observer.h"
10 #include "chrome/browser/media/router/media_routes_observer.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
12 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
16 class MediaRouterActionPlatformDelegate
;
19 namespace media_router
{
20 class MediaRouterDialogControllerImpl
;
21 } // namespace media_router
23 // The class for the Media Router component action that will be shown in
25 class MediaRouterAction
: public ToolbarActionViewController
,
26 public media_router::IssuesObserver
,
27 public media_router::MediaRoutesObserver
,
28 public TabStripModelObserver
{
30 explicit MediaRouterAction(Browser
* browser
);
31 ~MediaRouterAction() override
;
33 // ToolbarActionViewController implementation.
34 std::string
GetId() const override
;
35 void SetDelegate(ToolbarActionViewDelegate
* delegate
) override
;
36 gfx::Image
GetIcon(content::WebContents
* web_contents
,
37 const gfx::Size
& size
) override
;
38 base::string16
GetActionName() const override
;
39 base::string16
GetAccessibleName(content::WebContents
* web_contents
)
41 base::string16
GetTooltip(content::WebContents
* web_contents
)
43 bool IsEnabled(content::WebContents
* web_contents
) const override
;
44 bool WantsToRun(content::WebContents
* web_contents
) const override
;
45 bool HasPopup(content::WebContents
* web_contents
) const override
;
46 void HidePopup() override
;
47 gfx::NativeView
GetPopupNativeView() override
;
48 ui::MenuModel
* GetContextMenu() override
;
49 bool ExecuteAction(bool by_user
) override
;
50 void UpdateState() override
;
51 bool DisabledClickOpensMenu() const override
;
53 // media_router::IssuesObserver:
54 void OnIssueUpdated(const media_router::Issue
* issue
) override
;
56 // media_router::MediaRoutesObserver:
57 void OnRoutesUpdated(const std::vector
<media_router::MediaRoute
>& routes
)
60 // ToolbarStripModelObserver:
61 void ActiveTabChanged(content::WebContents
* old_contents
,
62 content::WebContents
* new_contents
,
70 void UpdatePopupState();
72 // Returns a reference to the MediaRouterDialogControllerImpl associated with
73 // |delegate_|'s current WebContents. Guaranteed to be non-null.
74 // |delegate_| and its current WebContents must not be null.
75 // Marked virtual for tests.
76 virtual media_router::MediaRouterDialogControllerImpl
*
77 GetMediaRouterDialogController();
79 // Overridden by tests.
80 virtual media_router::MediaRouter
* GetMediaRouter(Browser
* browser
);
81 virtual MediaRouterActionPlatformDelegate
* GetPlatformDelegate();
83 // Checks if the current icon of MediaRouterAction has changed. If so,
84 // updates |current_icon_|.
85 void MaybeUpdateIcon();
87 const gfx::Image
* GetCurrentIcon() const;
90 // Indicates that the current Chrome profile is using at least one device.
91 const gfx::Image media_router_active_icon_
;
92 // Indicates a failure, e.g. session launch failure.
93 const gfx::Image media_router_error_icon_
;
94 // Indicates that the current Chrome profile is not using any devices.
95 // Devices may or may not be available.
96 const gfx::Image media_router_idle_icon_
;
97 // Indicates there is a warning message.
98 const gfx::Image media_router_warning_icon_
;
100 // The current icon to show. This is updated based on the current issues and
101 // routes since |this| is an IssueObserver and MediaRoutesObserver.
102 const gfx::Image
* current_icon_
;
104 // The current issue shown in the Media Router WebUI. Can be null. It is set
105 // in OnIssueUpdated(), which is called by the IssueManager.
106 scoped_ptr
<media_router::Issue
> issue_
;
108 // Whether a local active route exists.
109 bool has_local_route_
;
111 ToolbarActionViewDelegate
* delegate_
;
113 Browser
* const browser_
;
115 // The delegate to handle platform-specific implementations.
116 scoped_ptr
<MediaRouterActionPlatformDelegate
> platform_delegate_
;
118 MediaRouterContextualMenu contextual_menu_
;
120 ScopedObserver
<TabStripModel
, TabStripModelObserver
>
121 tab_strip_model_observer_
;
123 base::WeakPtrFactory
<MediaRouterAction
> weak_ptr_factory_
;
125 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction
);
128 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_