feat(extensions): expose ExtensionRegistryObserver events in Session (#25385)

* feat(extensions): expose ExtensionRegistryObserver events in Session

Extensions can be loaded and unloaded for various reasons. In some cases this can
occur by no means of the Electron programmer, such as in the case of chrome.runtime.reload().

In order to be able to manage state about extensions outside of Electron's APIs, events
reloaded to loading and unloaded are needed.

* docs(extensions): elaborate on extension-loaded/unloaded details

* fix: remove scoped extension registry observer

* docs: update extension-unloaded
This commit is contained in:
Samuel Maddock 2020-09-23 15:29:08 -04:00 committed by GitHub
parent 881ac995da
commit 9d0d9a1664
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 0 deletions

View file

@ -281,6 +281,10 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
service->SetHunspellObserver(this);
}
#endif
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
extensions::ExtensionRegistry::Get(browser_context)->AddObserver(this);
#endif
}
Session::~Session() {
@ -294,6 +298,10 @@ Session::~Session() {
service->SetHunspellObserver(nullptr);
}
#endif
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
extensions::ExtensionRegistry::Get(browser_context())->RemoveObserver(this);
#endif
}
void Session::OnDownloadCreated(content::DownloadManager* manager,
@ -749,6 +757,22 @@ v8::Local<v8::Value> Session::GetAllExtensions() {
}
return gin::ConvertToV8(v8::Isolate::GetCurrent(), extensions_vector);
}
void Session::OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) {
Emit("extension-loaded", extension);
}
void Session::OnExtensionUnloaded(content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) {
Emit("extension-unloaded", extension);
}
void Session::OnExtensionReady(content::BrowserContext* browser_context,
const extensions::Extension* extension) {
Emit("extension-ready", extension);
}
#endif
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {