OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "chrome/browser/media/router/create_presentation_session_request.h" | |
10 #include "content/public/browser/web_contents_observer.h" | |
11 #include "content/public/browser/web_contents_user_data.h" | |
12 | |
13 namespace media_router { | |
14 | |
15 // An instance of this class is tied to a WebContents known as the initiator, | |
16 // and is lazily created when a Media Router dialog needs to be shown. | |
17 // The MediaRouterDialogController allows creating, querying, and removing a | |
18 // Media Router dialog modal to the initiator WebContents. | |
19 // This class is not thread safe and must be called on the UI thread. | |
20 class MediaRouterDialogController | |
21 : public content::WebContentsUserData<MediaRouterDialogController> { | |
22 public: | |
23 ~MediaRouterDialogController() override; | |
24 | |
25 // Gets a reference to the MediaRouterDialogController associated with | |
26 // |web_contents|, creating one if it does not exist. The returned pointer is | |
27 // guaranteed to be non-null. | |
28 static MediaRouterDialogController* GetOrCreateForWebContents( | |
29 content::WebContents* web_contents); | |
30 | |
31 // Shows the media router dialog modal to the initiator WebContents. | |
32 // Creates the dialog if it did not exist prior to this call. | |
33 // If the dialog already exists, brings the dialog to the front. | |
34 // Returns WebContents for the media router dialog. | |
35 content::WebContents* ShowMediaRouterDialog(); | |
36 | |
37 // Creates a Media Router modal dialog using the initiator and parameters | |
38 // specified in |request|. If the dialog already exists, brings the dialog | |
39 // to the front, but does not change the dialog with |request|. | |
40 // Returns WebContents for the media router dialog if a dialog was created. | |
41 // Otherwise returns nullptr and |request| is deleted. | |
42 content::WebContents* ShowMediaRouterDialogForPresentation( | |
43 scoped_ptr<CreatePresentationSessionRequest> request); | |
44 | |
45 // Returns the media router dialog WebContents. | |
46 // Returns nullptr if there is no dialog. | |
47 content::WebContents* GetMediaRouterDialog() const; | |
48 | |
49 // Closes the media router dialog. This will destroy the dialog WebContents. | |
50 // It is an error to call this function if there is currently no dialog. | |
51 void CloseMediaRouterDialog(); | |
52 | |
53 private: | |
54 class DialogWebContentsObserver; | |
55 class InitiatorWebContentsObserver; | |
56 friend class content::WebContentsUserData<MediaRouterDialogController>; | |
57 | |
58 // Use MediaRouterDialogController::CreateForWebContents() to create an | |
59 // instance. | |
60 explicit MediaRouterDialogController(content::WebContents* web_contents); | |
61 | |
62 // Creates a new media router dialog modal to |initiator_|. | |
63 void CreateMediaRouterDialog(); | |
64 | |
65 // Resets this dialog controller to an empty state. | |
66 void Reset(); | |
67 | |
68 // Invoked when the dialog WebContents has navigated. | |
69 void OnDialogNavigated(const content::LoadCommittedDetails& details); | |
70 | |
71 void PopulateDialog(content::WebContents* media_router_dialog); | |
72 | |
73 scoped_ptr<InitiatorWebContentsObserver> initiator_observer_; | |
74 scoped_ptr<DialogWebContentsObserver> dialog_observer_; | |
75 | |
76 content::WebContents* const initiator_; | |
77 | |
78 // True if the controller is waiting for a new media router dialog to be | |
79 // created. | |
80 bool media_router_dialog_pending_; | |
81 | |
82 // Data for dialogs created under a Presentation API context. | |
83 // Passed from the caller of ShowMediaRouterDialogForPresentation(), and | |
84 // passed to the MediaRouterUI when it is initialized. | |
85 scoped_ptr<CreatePresentationSessionRequest> presentation_request_; | |
86 | |
87 base::ThreadChecker thread_checker_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogController); | |
90 }; | |
91 | |
92 } // namespace media_router | |
93 | |
94 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H
_ | |
OLD | NEW |