File: application_client.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (122 lines) | stat: -rw-r--r-- 4,465 bytes parent folder | download | duplicates (7)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CAST_RECEIVER_BROWSER_APPLICATION_CLIENT_H_
#define COMPONENTS_CAST_RECEIVER_BROWSER_APPLICATION_CLIENT_H_

#include <memory>
#include <string_view>
#include <vector>

#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "components/cast_receiver/browser/public/application_state_observer.h"
#include "components/cast_receiver/browser/public/streaming_resolution_observer.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "services/network/public/cpp/network_context_getter.h"

namespace blink {
class URLLoaderThrottle;
}  // namespace blink

namespace content {
class WebContents;
}  // namespace content

namespace gfx {
class Rect;
}  // namespace gfx

namespace media {
struct VideoTransformation;
}  // namespace media

namespace media_control {
class MediaBlocker;
}  // namespace media_control

namespace url_rewrite {
class UrlRequestRewriteRulesManager;
}  // namespace url_rewrite

namespace cast_receiver {

class RuntimeApplication;

// This class is responsible for providing all factory methods required for
// creating the classes responsible for management and control of cast
// application types, as required for the functionality of the remainder of
// this component, as well as responding to any callbacks from the application
// process.
class ApplicationClient : public StreamingResolutionObserver,
                          public ApplicationStateObserver {
 public:
  // This class handles managing the lifetime and interaction with the Renderer
  // process for application-specific objects. All functions of this object are
  // safe to call at any point during this object's lifetime.
  class ApplicationControls {
   public:
    virtual ~ApplicationControls();

    // Returns the MediaBlocker instance associated with this application.
    virtual media_control::MediaBlocker& GetMediaBlocker() = 0;

    // Returns the UrlRequestRewriteRulesManager instance associated with this
    // application.
    virtual url_rewrite::UrlRequestRewriteRulesManager&
    GetUrlRequestRewriteRulesManager() = 0;
  };
  explicit ApplicationClient(
      network::NetworkContextGetter network_context_getter);
  ~ApplicationClient() override;

  // Returns the NetworkContext to use with the cast_streaming component for
  // network access to implement the Cast Streaming receiver.  (This
  // NetworkContext is eventually passed to the Open Screen library platform
  // implementation.)
  network::NetworkContextGetter network_context_getter() const {
    return network_context_getter_;
  }

  // Returns the ApplicationControls associated with |web_contents|. The
  // lifetime of this instance is the same as that of |web_contents|.
  ApplicationControls& GetApplicationControls(
      const content::WebContents& web_contents);

  // As defined in ContentBrowserClientMixins.
  void AddApplicationStateObserver(ApplicationStateObserver* observer);
  void RemoveApplicationStateObserver(ApplicationStateObserver* observer);
  void AddStreamingResolutionObserver(StreamingResolutionObserver* observer);
  void RemoveStreamingResolutionObserver(StreamingResolutionObserver* observer);
  void OnWebContentsCreated(content::WebContents* web_contents);
  using CorsExemptHeaderCallback =
      base::RepeatingCallback<bool(std::string_view)>;
  std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
  CreateURLLoaderThrottles(
      const base::RepeatingCallback<content::WebContents*()>& wc_getter,
      content::FrameTreeNodeId frame_tree_node_id,
      CorsExemptHeaderCallback is_cors_exempt_header_cb);

  // StreamingResolutionObserver implementation:
  void OnStreamingResolutionChanged(
      const gfx::Rect& size,
      const media::VideoTransformation& transformation) final;

  // ApplicationStateObserver implementation:
  void OnForegroundApplicationChanged(RuntimeApplication* app) final;

 private:
  network::NetworkContextGetter network_context_getter_;

  base::ObserverList<StreamingResolutionObserver>
      streaming_resolution_observer_list_;
  base::ObserverList<ApplicationStateObserver> application_state_observer_list_;

  base::WeakPtrFactory<ApplicationClient> weak_factory_;
};

}  // namespace cast_receiver

#endif  // COMPONENTS_CAST_RECEIVER_BROWSER_APPLICATION_CLIENT_H_