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.
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "chrome/browser/media/router/create_presentation_session_request.h"
14 #include "content/public/browser/web_contents_observer.h"
18 } // namespace content
20 namespace media_router
{
22 // An abstract base class for Media Router dialog controllers. Tied to a
23 // WebContents known as the |initiator|, and is lazily created when a Media
24 // Router dialog needs to be shown. The MediaRouterDialogController allows
25 // showing and closing a Media Router dialog modal to the initiator WebContents.
26 // This class is not thread safe and must be called on the UI thread.
27 class MediaRouterDialogController
{
29 virtual ~MediaRouterDialogController();
31 // Gets a reference to the MediaRouterDialogController associated with
32 // |web_contents|, creating one if it does not exist. The returned pointer is
33 // guaranteed to be non-null.
34 static MediaRouterDialogController
* GetOrCreateForWebContents(
35 content::WebContents
* web_contents
);
37 // Shows the media router dialog modal to |initiator_| and the parameters
38 // specified in |request|.
39 // Creates the dialog if it did not exist prior to this call, returns true.
40 // If the dialog already exists, brings it to the front but doesn't change the
41 // dialog with |request|, returns false and |request| is deleted.
42 bool ShowMediaRouterDialogForPresentation(
43 scoped_ptr
<CreatePresentationSessionRequest
> request
);
45 // Shows the media router dialog modal to |initiator_|.
46 // Creates the dialog if it did not exist prior to this call, returns true.
47 // If the dialog already exists, brings it to the front, returns false.
48 virtual bool ShowMediaRouterDialog();
50 // Hides the media router dialog.
51 // It is a no-op to call this function if there is currently no dialog.
52 void HideMediaRouterDialog();
54 // Indicates if the media router dialog already exists.
55 virtual bool IsShowingMediaRouterDialog() const = 0;
58 // Use MediaRouterDialogController::GetOrCreateForWebContents() to create an
60 explicit MediaRouterDialogController(content::WebContents
* initiator
);
62 // Activates the WebContents that initiated the dialog, e.g. focuses the tab.
63 void ActivateInitiatorWebContents();
65 // Passes the ownership of the CreatePresentationSessionRequest to the caller.
66 scoped_ptr
<CreatePresentationSessionRequest
> TakePresentationRequest();
68 // Returns the CreatePresentationSessionRequest to the caller but keeps the
69 // ownership with the MediaRouterDialogController.
70 const CreatePresentationSessionRequest
* presentation_request() const {
71 return presentation_request_
.get();
74 // Returns the WebContents that initiated showing the dialog.
75 content::WebContents
* initiator() const { return initiator_
; }
77 // Resets the state of the controller. Must be called from the overrides.
79 // Creates a new media router dialog modal to |initiator_|.
80 virtual void CreateMediaRouterDialog() = 0;
81 // Closes the media router dialog if it exists.
82 virtual void CloseMediaRouterDialog() = 0;
84 base::ThreadChecker thread_checker_
;
87 class InitiatorWebContentsObserver
;
89 // An observer for the |initiator_| that closes the dialog when |initiator_|
90 // is destroyed or navigated.
91 scoped_ptr
<InitiatorWebContentsObserver
> initiator_observer_
;
92 content::WebContents
* const initiator_
;
94 // Data for dialogs created at the request of the Presentation API.
95 // Passed from the caller via ShowMediaRouterDialogForPresentation to the
96 // dialog when it is initialized.
97 scoped_ptr
<CreatePresentationSessionRequest
> presentation_request_
;
99 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogController
);
102 } // namespace media_router
104 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_