File: per_profile_webui_tracker.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (62 lines) | stat: -rw-r--r-- 2,511 bytes parent folder | download | duplicates (5)
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
// Copyright 2024 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_WEBUI_TOP_CHROME_PER_PROFILE_WEBUI_TRACKER_H_
#define CHROME_BROWSER_UI_WEBUI_TOP_CHROME_PER_PROFILE_WEBUI_TRACKER_H_

#include <memory>
#include <string>

#include "base/observer_list_types.h"

namespace content {
class WebContents;
}  // namespace content

class Profile;

// PerProfileWebUITracker tracks WebUIs associated with a profile. It provides
// an API to query if a profile has any WebUI instances of a given URL. This
// class considers only the existence of a WebUI's WebContents, ignoring its
// status.
class PerProfileWebUITracker {
 public:
  class Observer : public base::CheckedObserver {
   public:
    // Called when a tracked WebContents is destroyed.
    virtual void OnWebContentsDestroyed(content::WebContents* web_contents) = 0;
    // Called when a tracked WebContents' primary page changed.
    virtual void OnWebContentsPrimaryPageChanged(
        content::WebContents* web_contents) = 0;
  };

  static std::unique_ptr<PerProfileWebUITracker> Create();

  virtual ~PerProfileWebUITracker() = default;

  // Starts tracking `web_contents`.
  // This class automatically handles the destruction of WebContents, so manual
  // handling is not needed.
  virtual void AddWebContents(content::WebContents* web_contents) = 0;

  // Returns true if a WebUI with the specified URL exists within the profile.
  // This includes all WebContents, regardless of their visibility, hidden
  // state, crash state, preload state, or any errors.
  virtual bool ProfileHasWebUI(Profile* profile,
                               const std::string& webui_url) const = 0;

  // Returns true if a WebUI with the specified URL exists within the profile
  // and is in the background, i.e. it is preloaded and pending to be shown.
  // Note that a preloaded WebUI is not equivalent to a background WebUI. A
  // foreground WebUI may be preloaded before it is shown, in which case
  // WebUIContentsPreloadState::preloaded is true.
  virtual bool ProfileHasBackgroundWebUI(Profile* profile,
                                         const std::string& webui_url) const = 0;

  // Adds an observer that will be notified of tracked WebContents destroy.
  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;
};

#endif  // CHROME_BROWSER_UI_WEBUI_TOP_CHROME_PER_PROFILE_WEBUI_TRACKER_H_