OLD | NEW |
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" | |
12 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 11 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | |
14 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
16 | 14 |
17 FORWARD_DECLARE_TEST(MediaRouterActionUnitTest, IconPressedState); | 15 FORWARD_DECLARE_TEST(MediaRouterActionUnitTest, IconPressedState); |
18 | 16 |
19 class MediaRouterAction; | 17 class MediaRouterAction; |
20 | 18 |
21 namespace media_router { | 19 namespace media_router { |
22 | 20 |
23 // A desktop implementation of MediaRouterDialogController. | 21 // A desktop implementation of MediaRouterDialogController. |
24 // This class is not thread safe and must be called on the UI thread. | 22 // This class is not thread safe and must be called on the UI thread. |
25 class MediaRouterDialogControllerImpl : | 23 class MediaRouterDialogControllerImpl : |
26 public content::WebContentsUserData<MediaRouterDialogControllerImpl>, | 24 public content::WebContentsUserData<MediaRouterDialogControllerImpl>, |
27 public MediaRouterDialogController, | 25 public MediaRouterDialogController { |
28 public TabStripModelObserver { | |
29 public: | 26 public: |
30 ~MediaRouterDialogControllerImpl() override; | 27 ~MediaRouterDialogControllerImpl() override; |
31 | 28 |
32 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( | 29 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( |
33 content::WebContents* web_contents); | 30 content::WebContents* web_contents); |
34 | 31 |
35 // Returns the media router dialog WebContents. | 32 // Returns the media router dialog WebContents. |
36 // Returns nullptr if there is no dialog. | 33 // Returns nullptr if there is no dialog. |
37 content::WebContents* GetMediaRouterDialog() const; | 34 content::WebContents* GetMediaRouterDialog() const; |
38 | 35 |
39 // |action| must always be non-null. | 36 // |action| must always be non-null. |
40 void SetMediaRouterAction(const base::WeakPtr<MediaRouterAction>& action); | 37 void SetMediaRouterAction(const base::WeakPtr<MediaRouterAction>& action); |
41 | 38 |
42 void UpdateMaxDialogSize(); | |
43 | |
44 // MediaRouterDialogController: | 39 // MediaRouterDialogController: |
45 bool IsShowingMediaRouterDialog() const override; | 40 bool IsShowingMediaRouterDialog() const override; |
46 bool ShowMediaRouterDialog() override; | |
47 | 41 |
48 // ToolbarStripModelObserver: | 42 void UpdateMaxDialogSize(); |
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(); } | |
55 | 43 |
56 private: | 44 private: |
57 class DialogWebContentsObserver; | 45 class DialogWebContentsObserver; |
58 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; | 46 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; |
59 FRIEND_TEST_ALL_PREFIXES(::MediaRouterActionUnitTest, IconPressedState); | 47 FRIEND_TEST_ALL_PREFIXES(::MediaRouterActionUnitTest, IconPressedState); |
60 | 48 |
61 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an | 49 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an |
62 // instance. | 50 // instance. |
63 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); | 51 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); |
64 | 52 |
65 // MediaRouterDialogController: | 53 // MediaRouterDialogController: |
66 void CreateMediaRouterDialog() override; | 54 void CreateMediaRouterDialog() override; |
67 void CloseMediaRouterDialog() override; | 55 void CloseMediaRouterDialog() override; |
68 void Reset() override; | 56 void Reset() override; |
69 | 57 |
70 // Invoked when the dialog WebContents has navigated. | 58 // Invoked when the dialog WebContents has navigated. |
71 void OnDialogNavigated(const content::LoadCommittedDetails& details); | 59 void OnDialogNavigated(const content::LoadCommittedDetails& details); |
72 | 60 |
73 void PopulateDialog(content::WebContents* media_router_dialog); | 61 void PopulateDialog(content::WebContents* media_router_dialog); |
74 | 62 |
75 void ShowMediaRouterAction(); | |
76 | |
77 std::unique_ptr<DialogWebContentsObserver> dialog_observer_; | 63 std::unique_ptr<DialogWebContentsObserver> dialog_observer_; |
78 | 64 |
79 // True if the controller is waiting for a new media router dialog to be | 65 // True if the controller is waiting for a new media router dialog to be |
80 // created. | 66 // created. |
81 bool media_router_dialog_pending_; | 67 bool media_router_dialog_pending_; |
82 | 68 |
83 ScopedObserver<TabStripModel, TabStripModelObserver> | |
84 tab_strip_model_observer_; | |
85 | |
86 // |action_| refers to the MediaRouterAction on the toolbar, rather than | 69 // |action_| refers to the MediaRouterAction on the toolbar, rather than |
87 // overflow menu. A MediaRouterAction is always created for the toolbar | 70 // overflow menu. A MediaRouterAction is always created for the toolbar |
88 // first. Any subsequent creations for the overflow menu will not be set as | 71 // first. Any subsequent creations for the overflow menu will not be set as |
89 // |action_|. | 72 // |action_|. |
90 // The lifetime of |action_| is dependent on the creation and destruction of | 73 // The lifetime of |action_| is dependent on the creation and destruction of |
91 // a browser window. The overflow menu's MediaRouterAction is only created | 74 // a browser window. The overflow menu's MediaRouterAction is only created |
92 // when the overflow menu is opened and destroyed when the menu is closed. | 75 // when the overflow menu is opened and destroyed when the menu is closed. |
93 base::WeakPtr<MediaRouterAction> action_; | 76 base::WeakPtr<MediaRouterAction> action_; |
94 | 77 |
95 base::WeakPtrFactory<MediaRouterDialogControllerImpl> weak_ptr_factory_; | 78 base::WeakPtrFactory<MediaRouterDialogControllerImpl> weak_ptr_factory_; |
96 | 79 |
97 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); | 80 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); |
98 }; | 81 }; |
99 | 82 |
100 } // namespace media_router | 83 } // namespace media_router |
101 | 84 |
102 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I
MPL_H_ | 85 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I
MPL_H_ |
OLD | NEW |