File: extension_registry_observer.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (114 lines) | stat: -rw-r--r-- 5,141 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
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
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
#define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_

#include "extensions/browser/uninstall_reason.h"

namespace content {
class BrowserContext;
}

namespace extensions {
class Extension;
class ExtensionRegistry;
enum class UnloadedExtensionReason;

// Observer for ExtensionRegistry. Exists in a separate header file to reduce
// the include file burden for typical clients of ExtensionRegistry.
//
// There are separate event categories for loading (the OnExtensionLoaded,
// OnExtensionReady and OnExtensionUnloaded events) and installing (the
// OnExtensionWillBeInstalled, OnExtensionInstalled and OnExtensionUninstalled)
// extensions.
//
// For example, comparing OnExtensionLoaded and OnExtensionInstalled,
// OnExtensionLoaded is called whenever an extension is added to the "enabled"
// set of the extension registry. This includes:
//
//  - Extensions being loaded at Chrome startup.
//  - Extensions being reloaded:
//    * as part of an update.
//    * from a crash.
//    * from a disabled state (if the user toggled disabled -> enabled).
//    * as part of internal bookkeeping (we reload extensions on file access
//      being granted, for instance).
//    * if the extension requested it (chrome.runtime.reload()).
//    * probably others.
//  - New extensions being loaded for the first time (as part of installation).
//
// OnExtensionInstalled is called when a *new* extension is added, *or* when an
// extension is updated to a *new* version. It is not called for existing
// extensions being loaded at startup, etc. In a common run of Chrome, you
// probably won't get many "OnInstalled" events.
//
// As a general rule, most sites should observe OnExtensionLoaded, because they
// want to see "what are the enabled extensions".
class ExtensionRegistryObserver {
 public:
  virtual ~ExtensionRegistryObserver() = default;

  // Called after an extension is loaded. The extension will exclusively exist
  // in the enabled_extensions set of ExtensionRegistry.
  virtual void OnExtensionLoaded(
      content::BrowserContext* browser_context,
      const Extension* extension) {}

  // Called after an extension is loaded and all necessary browser state is
  // initialized to support the start of the extension's child process.
  virtual void OnExtensionReady(content::BrowserContext* browser_context,
                                const Extension* extension) {}

  // Called after an extension is unloaded. The extension no longer exists in
  // the set |ExtensionRegistry::enabled_extensions()|, but it can still be a
  // member of one of the other sets, like disabled, blocklisted or terminated.
  virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
                                   const Extension* extension,
                                   UnloadedExtensionReason reason) {}

  // Called when `extension` is about to be installed. `is_update` is true if
  // the installation is the result of it updating, in which case `old_name` is
  // the name of the extension's previous version.
  // The ExtensionRegistry will not be tracking `extension` at the time this
  // event is fired, but will be immediately afterwards (note: not necessarily
  // enabled; it might be installed in the disabled or even blocklisted sets,
  // for example).
  // Note that it's much more common to care about extensions being loaded
  // (OnExtensionLoaded).
  //
  // TODO(tmdiep): We should stash the state of the previous extension version
  // somewhere and have observers retrieve it. `is_update`, and `old_name` can
  // be removed when this is done.
  virtual void OnExtensionWillBeInstalled(
      content::BrowserContext* browser_context,
      const Extension* extension,
      bool is_update,
      const std::string& old_name) {}

  // Called when the installation of `extension` is complete. At this point the
  // extension is tracked in one of the ExtensionRegistry sets, but is not
  // necessarily enabled.
  virtual void OnExtensionInstalled(content::BrowserContext* browser_context,
                                    const Extension* extension,
                                    bool is_update) {}

  // Called after an extension is uninstalled. The extension no longer exists in
  // any of the ExtensionRegistry sets (enabled, disabled, etc.).
  virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
                                      const Extension* extension,
                                      UninstallReason reason) {}

  // Called after the uninstallation of an extension is denied.
  virtual void OnExtensionUninstallationDenied(
      content::BrowserContext* browser_context,
      const Extension* extension) {}

  // Notifies observers that the observed object is going away.
  virtual void OnShutdown(ExtensionRegistry* registry) {}
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_