File: presentation_receiver_window_controller.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (131 lines) | stat: -rw-r--r-- 5,124 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_MEDIA_ROUTER_PRESENTATION_RECEIVER_WINDOW_CONTROLLER_H_
#define CHROME_BROWSER_UI_MEDIA_ROUTER_PRESENTATION_RECEIVER_WINDOW_CONTROLLER_H_

#include <memory>
#include <string>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/media/router/providers/wired_display/wired_display_presentation_receiver.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/media_router/presentation_receiver_window_delegate.h"
#include "components/media_router/browser/presentation/presentation_navigation_policy.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"

class GURL;
class PresentationReceiverWindow;

namespace content {
class WebContents;
}

namespace gfx {
class Rect;
}

// This class controls a window which is used to render a receiver page for the
// Presentation API.  It handles creating the window to show the desired URL and
// showing it in fullscreen on the desired display.  This class should not be
// destroyed until |termination_callback| has been called, which may be called
// before Terminate() is ever called.
class PresentationReceiverWindowController final
    : public PresentationReceiverWindowDelegate,
      public content::WebContentsObserver,
      public content::WebContentsDelegate,
      public media_router::WiredDisplayPresentationReceiver,
      public ProfileObserver {
 public:
  using TitleChangeCallback = base::RepeatingCallback<void(const std::string&)>;

  static std::unique_ptr<PresentationReceiverWindowController>
  CreateFromOriginalProfile(Profile* profile,
                            const gfx::Rect& bounds,
                            base::OnceClosure termination_callback,
                            TitleChangeCallback title_change_callback);

  PresentationReceiverWindowController(
      const PresentationReceiverWindowController&) = delete;
  PresentationReceiverWindowController& operator=(
      const PresentationReceiverWindowController&) = delete;

  ~PresentationReceiverWindowController() final;

  // WiredDisplayPresentationReceiver overrides.
  void Start(const std::string& presentation_id,
             const GURL& start_url) override;
  void Terminate() override;
  void ExitFullscreen() override;

  // PresentationReceiverWindowDelegate overrides.
  content::WebContents* web_contents() const final;

 private:
  friend class PresentationReceiverWindowControllerBrowserTest;

  PresentationReceiverWindowController(
      Profile* profile,
      const gfx::Rect& bounds,
      base::OnceClosure termination_callback,
      TitleChangeCallback title_change_callback);

  // ProfileObserver:
  void OnProfileWillBeDestroyed(Profile* profile) override;

  // These methods are intended to be used by tests.
  void CloseWindowForTest();
  bool IsWindowActiveForTest() const;
  bool IsWindowFullscreenForTest() const;
  gfx::Rect GetWindowBoundsForTest() const;

  // PresentationReceiverWindowDelegate overrides.
  void WindowClosed() final;

  // content::WebContentsObserver overrides.
  void DidStartNavigation(content::NavigationHandle* handle) final;
  void TitleWasSet(content::NavigationEntry* entry) final;

  // content::WebContentsDelegate overrides.
  void NavigationStateChanged(content::WebContents* source,
                              content::InvalidateTypes changed_flags) final;
  void CloseContents(content::WebContents* source) final;
  bool ShouldSuppressDialogs(content::WebContents* source) final;
  bool ShouldFocusLocationBarByDefault(content::WebContents* source) final;
  bool ShouldFocusPageAfterCrash(content::WebContents* source) final;
  void CanDownload(const GURL& url,
                   const std::string& request_method,
                   base::OnceCallback<void(bool)> callback) final;
  bool IsWebContentsCreationOverridden(
      content::RenderFrameHost* opener,
      content::SiteInstance* source_site_instance,
      content::mojom::WindowContainerType window_container_type,
      const GURL& opener_url,
      const std::string& frame_name,
      const GURL& target_url) override;

  // The profile used for the presentation.
  raw_ptr<Profile, DanglingUntriaged> otr_profile_;
  base::ScopedObservation<Profile, ProfileObserver> otr_profile_observation_{
      this};

  // WebContents for rendering the receiver page.
  std::unique_ptr<content::WebContents> web_contents_;

  // The actual UI window for displaying the receiver page.
  raw_ptr<PresentationReceiverWindow, DanglingUntriaged> window_;

  base::OnceClosure termination_callback_;

  // Gets called with the new title whenever TitleWasSet() is called.
  TitleChangeCallback title_change_callback_;

  media_router::PresentationNavigationPolicy navigation_policy_;
};

#endif  // CHROME_BROWSER_UI_MEDIA_ROUTER_PRESENTATION_RECEIVER_WINDOW_CONTROLLER_H_