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/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 9 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
10 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
11 #include "content/public/browser/web_contents_user_data.h" | 11 #include "content/public/browser/web_contents_user_data.h" |
12 | 12 |
13 namespace media_router { | 13 namespace media_router { |
14 | 14 |
15 // A desktop implementation of MediaRouterDialogController. | 15 // A desktop implementation of MediaRouterDialogController. |
16 // This class is not thread safe and must be called on the UI thread. | 16 // This class is not thread safe and must be called on the UI thread. |
17 class MediaRouterDialogControllerImpl | 17 class MediaRouterDialogControllerImpl : |
18 : public content::WebContentsUserData<MediaRouterDialogControllerImpl>, | 18 public content::WebContentsUserData<MediaRouterDialogControllerImpl>, |
19 public MediaRouterDialogController { | 19 public MediaRouterDialogController { |
20 public: | 20 public: |
21 ~MediaRouterDialogControllerImpl() override; | 21 ~MediaRouterDialogControllerImpl() override; |
22 | 22 |
23 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( | 23 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( |
24 content::WebContents* web_contents); | 24 content::WebContents* web_contents); |
25 | 25 |
26 // SuperClass: | 26 // MediaRouterDialogController: |
27 bool ShowMediaRouterDialogForPresentation( | 27 bool ShowMediaRouterDialogForPresentation( |
28 scoped_ptr<CreatePresentationSessionRequest> request) override; | 28 scoped_ptr<CreatePresentationSessionRequest> request) override; |
| 29 // This will destroy the dialog WebContents. |
| 30 void CloseMediaRouterDialog() override; |
29 | 31 |
30 // Shows the media router dialog modal to the initiator WebContents. | 32 // Shows the media router dialog modal to the initiator WebContents. |
31 // Creates the dialog if it did not exist prior to this call. | 33 // Creates the dialog if it did not exist prior to this call. |
32 // If the dialog already exists, brings the dialog to the front. | 34 // If the dialog already exists, brings the dialog to the front. |
33 // Returns WebContents for the media router dialog. | 35 // Returns WebContents for the media router dialog. |
34 content::WebContents* ShowMediaRouterDialog(); | 36 content::WebContents* ShowMediaRouterDialog(); |
35 | 37 |
36 // Returns the media router dialog WebContents. | 38 // Returns the media router dialog WebContents. |
37 // Returns nullptr if there is no dialog. | 39 // Returns nullptr if there is no dialog. |
38 content::WebContents* GetMediaRouterDialog() const; | 40 content::WebContents* GetMediaRouterDialog() const; |
39 | 41 |
40 // Closes the media router dialog. This will destroy the dialog WebContents. | |
41 // It is an error to call this function if there is currently no dialog. | |
42 void CloseMediaRouterDialog(); | |
43 | 42 |
44 private: | 43 private: |
45 class DialogWebContentsObserver; | 44 class DialogWebContentsObserver; |
46 class InitiatorWebContentsObserver; | |
47 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; | 45 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; |
48 | 46 |
49 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an | 47 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an |
50 // instance. | 48 // instance. |
51 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); | 49 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); |
52 | 50 |
53 // Creates a new media router dialog modal to |initiator_|. | 51 // Creates a new media router dialog modal to |initiator_|. |
54 void CreateMediaRouterDialog(); | 52 void CreateMediaRouterDialog(); |
55 | 53 |
56 // Resets this dialog controller to an empty state. | 54 // MediaRouterDialogController: |
57 void Reset(); | 55 void Reset() override; |
58 | 56 |
59 // Invoked when the dialog WebContents has navigated. | 57 // Invoked when the dialog WebContents has navigated. |
60 void OnDialogNavigated(const content::LoadCommittedDetails& details); | 58 void OnDialogNavigated(const content::LoadCommittedDetails& details); |
61 | 59 |
62 void PopulateDialog(content::WebContents* media_router_dialog); | 60 void PopulateDialog(content::WebContents* media_router_dialog); |
63 | 61 |
64 scoped_ptr<InitiatorWebContentsObserver> initiator_observer_; | |
65 scoped_ptr<DialogWebContentsObserver> dialog_observer_; | 62 scoped_ptr<DialogWebContentsObserver> dialog_observer_; |
66 | 63 |
67 content::WebContents* const initiator_; | |
68 | |
69 // True if the controller is waiting for a new media router dialog to be | 64 // True if the controller is waiting for a new media router dialog to be |
70 // created. | 65 // created. |
71 bool media_router_dialog_pending_; | 66 bool media_router_dialog_pending_; |
72 | 67 |
73 // Data for dialogs created under a Presentation API context. | |
74 // Passed from the caller of ShowMediaRouterDialogForPresentation(), and | |
75 // passed to the MediaRouterUI when it is initialized. | |
76 scoped_ptr<CreatePresentationSessionRequest> presentation_request_; | |
77 | |
78 base::ThreadChecker thread_checker_; | 68 base::ThreadChecker thread_checker_; |
79 | 69 |
80 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); | 70 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); |
81 }; | 71 }; |
82 | 72 |
83 } // namespace media_router | 73 } // namespace media_router |
84 | 74 |
85 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I
MPL_H_ | 75 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I
MPL_H_ |
OLD | NEW |