1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
#define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/media/router/issues_observer.h"
#include "chrome/browser/media/router/media_routes_observer.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h"
#include "ui/gfx/vector_icons_public.h"
class Browser;
class MediaRouterActionPlatformDelegate;
class TabStripModel;
namespace media_router {
class MediaRouterDialogControllerImpl;
} // namespace media_router
// The class for the Media Router component action that will be shown in
// the toolbar.
class MediaRouterAction : public ToolbarActionViewController,
public media_router::IssuesObserver,
public media_router::MediaRoutesObserver,
public TabStripModelObserver,
public ToolbarActionsBarObserver {
public:
MediaRouterAction(Browser* browser, ToolbarActionsBar* toolbar_actions_bar);
~MediaRouterAction() override;
static SkColor GetIconColor(gfx::VectorIconId icon_id);
// ToolbarActionViewController implementation.
std::string GetId() const override;
void SetDelegate(ToolbarActionViewDelegate* delegate) override;
gfx::Image GetIcon(content::WebContents* web_contents,
const gfx::Size& size) override;
base::string16 GetActionName() const override;
base::string16 GetAccessibleName(content::WebContents* web_contents)
const override;
base::string16 GetTooltip(content::WebContents* web_contents)
const override;
bool IsEnabled(content::WebContents* web_contents) const override;
bool WantsToRun(content::WebContents* web_contents) const override;
bool HasPopup(content::WebContents* web_contents) const override;
void HidePopup() override;
gfx::NativeView GetPopupNativeView() override;
ui::MenuModel* GetContextMenu() override;
void OnContextMenuClosed() override;
bool ExecuteAction(bool by_user) override;
void UpdateState() override;
bool DisabledClickOpensMenu() const override;
// media_router::IssuesObserver:
void OnIssue(const media_router::Issue& issue) override;
void OnIssuesCleared() override;
// media_router::MediaRoutesObserver:
void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
const std::vector<media_router::MediaRoute::Id>&
joinable_route_ids) override;
// ToolbarStripModelObserver:
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override;
// ToolbarActionsBarObserver:
void OnToolbarActionsBarAnimationEnded() override;
void OnDialogHidden();
void OnDialogShown();
private:
// Registers |this| with the MediaRouterDialogControllerImpl associated with
// |delegate_|'s current WebContents if |this| is not shown in overflow mode.
void RegisterWithDialogController();
// Called when a new browser window is opened or when |delegate_| is swapped
// out to be non-null and has a valid WebContents.
// This updates the pressed/unpressed state of the icon, which is different
// on a per-tab basis.
void UpdateDialogState();
// Returns a reference to the MediaRouterDialogControllerImpl associated with
// |delegate_|'s current WebContents. Guaranteed to be non-null.
// |delegate_| and its current WebContents must not be null.
// Marked virtual for tests.
virtual media_router::MediaRouterDialogControllerImpl*
GetMediaRouterDialogController();
// Overridden by tests.
virtual MediaRouterActionPlatformDelegate* GetPlatformDelegate();
// Checks if the current icon of MediaRouterAction has changed. If so,
// updates |current_icon_|.
void MaybeUpdateIcon();
gfx::VectorIconId GetCurrentIcon() const;
// The current icon to show. This is updated based on the current issues and
// routes since |this| is an IssueObserver and MediaRoutesObserver.
gfx::VectorIconId current_icon_;
// The current issue shown in the Media Router WebUI, set in OnIssue() and
// cleared in OnIssuesCleared().
std::unique_ptr<media_router::IssueInfo> current_issue_;
// Whether a local displayable active route exists.
bool has_local_display_route_;
// Whether the Media Router dialog is shown in the current tab.
// This should only be updated in OnDialogShown() and OnDialogHidden().
bool has_dialog_;
ToolbarActionViewDelegate* delegate_;
Browser* const browser_;
ToolbarActionsBar* const toolbar_actions_bar_;
// The delegate to handle platform-specific implementations.
std::unique_ptr<MediaRouterActionPlatformDelegate> platform_delegate_;
MediaRouterContextualMenu contextual_menu_;
ScopedObserver<TabStripModel, TabStripModelObserver>
tab_strip_model_observer_;
ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver>
toolbar_actions_bar_observer_;
base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MediaRouterAction);
};
#endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
|