Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.h

Issue 2155293002: Show the Cast toolbar icon ephemerally when Cast is in use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL _H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL _H_
6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL _H_ 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL _H_
7 7
8 #include "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/scoped_observer.h"
11 #include "chrome/browser/media/router/media_router_dialog_controller.h" 12 #include "chrome/browser/media/router/media_router_dialog_controller.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
12 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
14 16
15 FORWARD_DECLARE_TEST(MediaRouterActionUnitTest, IconPressedState); 17 FORWARD_DECLARE_TEST(MediaRouterActionUnitTest, IconPressedState);
16 18
17 class MediaRouterAction; 19 class MediaRouterAction;
18 20
19 namespace media_router { 21 namespace media_router {
20 22
21 // A desktop implementation of MediaRouterDialogController. 23 // A desktop implementation of MediaRouterDialogController.
22 // This class is not thread safe and must be called on the UI thread. 24 // This class is not thread safe and must be called on the UI thread.
23 class MediaRouterDialogControllerImpl : 25 class MediaRouterDialogControllerImpl :
24 public content::WebContentsUserData<MediaRouterDialogControllerImpl>, 26 public content::WebContentsUserData<MediaRouterDialogControllerImpl>,
25 public MediaRouterDialogController { 27 public MediaRouterDialogController,
28 public TabStripModelObserver {
26 public: 29 public:
27 ~MediaRouterDialogControllerImpl() override; 30 ~MediaRouterDialogControllerImpl() override;
28 31
29 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( 32 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents(
30 content::WebContents* web_contents); 33 content::WebContents* web_contents);
31 34
32 // Returns the media router dialog WebContents. 35 // Returns the media router dialog WebContents.
33 // Returns nullptr if there is no dialog. 36 // Returns nullptr if there is no dialog.
34 content::WebContents* GetMediaRouterDialog() const; 37 content::WebContents* GetMediaRouterDialog() const;
35 38
36 // |action| must always be non-null. 39 // |action| must always be non-null.
37 void SetMediaRouterAction(const base::WeakPtr<MediaRouterAction>& action); 40 void SetMediaRouterAction(const base::WeakPtr<MediaRouterAction>& action);
38 41
42 void UpdateMaxDialogSize();
43
39 // MediaRouterDialogController: 44 // MediaRouterDialogController:
40 bool IsShowingMediaRouterDialog() const override; 45 bool IsShowingMediaRouterDialog() const override;
46 bool ShowMediaRouterDialog() override;
41 47
42 void UpdateMaxDialogSize(); 48 // ToolbarStripModelObserver:
49 void ActiveTabChanged(content::WebContents* old_contents,
50 content::WebContents* new_contents,
51 int index,
52 int reason) override;
53
54 MediaRouterAction* action_for_test() { return action_.get(); }
43 55
44 private: 56 private:
45 class DialogWebContentsObserver; 57 class DialogWebContentsObserver;
46 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; 58 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>;
47 FRIEND_TEST_ALL_PREFIXES(::MediaRouterActionUnitTest, IconPressedState); 59 FRIEND_TEST_ALL_PREFIXES(::MediaRouterActionUnitTest, IconPressedState);
48 60
49 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an 61 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an
50 // instance. 62 // instance.
51 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); 63 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents);
52 64
53 // MediaRouterDialogController: 65 // MediaRouterDialogController:
54 void CreateMediaRouterDialog() override; 66 void CreateMediaRouterDialog() override;
55 void CloseMediaRouterDialog() override; 67 void CloseMediaRouterDialog() override;
56 void Reset() override; 68 void Reset() override;
57 69
58 // Invoked when the dialog WebContents has navigated. 70 // Invoked when the dialog WebContents has navigated.
59 void OnDialogNavigated(const content::LoadCommittedDetails& details); 71 void OnDialogNavigated(const content::LoadCommittedDetails& details);
60 72
61 void PopulateDialog(content::WebContents* media_router_dialog); 73 void PopulateDialog(content::WebContents* media_router_dialog);
62 74
75 void ShowMediaRouterAction();
76
63 std::unique_ptr<DialogWebContentsObserver> dialog_observer_; 77 std::unique_ptr<DialogWebContentsObserver> dialog_observer_;
64 78
65 // True if the controller is waiting for a new media router dialog to be 79 // True if the controller is waiting for a new media router dialog to be
66 // created. 80 // created.
67 bool media_router_dialog_pending_; 81 bool media_router_dialog_pending_;
68 82
83 ScopedObserver<TabStripModel, TabStripModelObserver>
84 tab_strip_model_observer_;
85
69 // |action_| refers to the MediaRouterAction on the toolbar, rather than 86 // |action_| refers to the MediaRouterAction on the toolbar, rather than
70 // overflow menu. A MediaRouterAction is always created for the toolbar 87 // overflow menu. A MediaRouterAction is always created for the toolbar
71 // first. Any subsequent creations for the overflow menu will not be set as 88 // first. Any subsequent creations for the overflow menu will not be set as
72 // |action_|. 89 // |action_|.
73 // The lifetime of |action_| is dependent on the creation and destruction of 90 // The lifetime of |action_| is dependent on the creation and destruction of
74 // a browser window. The overflow menu's MediaRouterAction is only created 91 // a browser window. The overflow menu's MediaRouterAction is only created
75 // when the overflow menu is opened and destroyed when the menu is closed. 92 // when the overflow menu is opened and destroyed when the menu is closed.
76 base::WeakPtr<MediaRouterAction> action_; 93 base::WeakPtr<MediaRouterAction> action_;
77 94
78 base::WeakPtrFactory<MediaRouterDialogControllerImpl> weak_ptr_factory_; 95 base::WeakPtrFactory<MediaRouterDialogControllerImpl> weak_ptr_factory_;
79 96
80 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); 97 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl);
81 }; 98 };
82 99
83 } // namespace media_router 100 } // namespace media_router
84 101
85 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I MPL_H_ 102 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I MPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698