Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / media / router / media_router_dialog_controller.h
blobaa7fddd27345d13b08d8b3a1ad57a306f419637f
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_
8 #include <string>
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"
16 namespace content {
17 class WebContents;
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 {
28 public:
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 protected:
55 // Use MediaRouterDialogController::GetOrCreateForWebContents() to create an
56 // instance.
57 explicit MediaRouterDialogController(content::WebContents* initiator);
59 // Activates the WebContents that initiated the dialog, e.g. focuses the tab.
60 void ActivateInitiatorWebContents();
62 // Passes the ownership of the CreatePresentationSessionRequest to the caller.
63 scoped_ptr<CreatePresentationSessionRequest> TakePresentationRequest();
65 // Returns the CreatePresentationSessionRequest to the caller but keeps the
66 // ownership with the MediaRouterDialogController.
67 const CreatePresentationSessionRequest* presentation_request() const {
68 return presentation_request_.get();
71 // Returns the WebContents that initiated showing the dialog.
72 content::WebContents* initiator() const { return initiator_; }
74 // Resets the state of the controller. Must be called from the overrides.
75 virtual void Reset();
76 // Creates a new media router dialog modal to |initiator_|.
77 virtual void CreateMediaRouterDialog() = 0;
78 // Closes the media router dialog if it exists.
79 virtual void CloseMediaRouterDialog() = 0;
80 // Indicates if the media router dialog already exists.
81 virtual bool IsShowingMediaRouterDialog() const = 0;
83 base::ThreadChecker thread_checker_;
85 private:
86 class InitiatorWebContentsObserver;
88 // An observer for the |initiator_| that closes the dialog when |initiator_|
89 // is destroyed or navigated.
90 scoped_ptr<InitiatorWebContentsObserver> initiator_observer_;
91 content::WebContents* const initiator_;
93 // Data for dialogs created at the request of the Presentation API.
94 // Passed from the caller via ShowMediaRouterDialogForPresentation to the
95 // dialog when it is initialized.
96 scoped_ptr<CreatePresentationSessionRequest> presentation_request_;
98 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogController);
101 } // namespace media_router
103 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_