feat(extensions): add more properties to extension object (#22244)
This commit is contained in:
parent
41931aa5fa
commit
68c6d53156
3 changed files with 23 additions and 0 deletions
|
@ -1,5 +1,8 @@
|
||||||
# Extension Object
|
# Extension Object
|
||||||
|
|
||||||
* `id` String
|
* `id` String
|
||||||
|
* `manifest` any - Copy of the [extension's manifest data](https://developer.chrome.com/extensions/manifest).
|
||||||
* `name` String
|
* `name` String
|
||||||
|
* `path` String - The extension's file path.
|
||||||
* `version` String
|
* `version` String
|
||||||
|
* `url` String - The extension's `chrome-extension://` URL.
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
#include "extensions/common/extension.h"
|
#include "extensions/common/extension.h"
|
||||||
#include "gin/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
|
#include "shell/common/gin_converters/gurl_converter.h"
|
||||||
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
|
|
||||||
namespace gin {
|
namespace gin {
|
||||||
|
|
||||||
|
@ -16,7 +19,11 @@ v8::Local<v8::Value> Converter<const extensions::Extension*>::ToV8(
|
||||||
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("id", extension->id());
|
dict.Set("id", extension->id());
|
||||||
dict.Set("name", extension->name());
|
dict.Set("name", extension->name());
|
||||||
|
dict.Set("path", extension->path());
|
||||||
|
dict.Set("url", extension->url());
|
||||||
dict.Set("version", extension->VersionString());
|
dict.Set("version", extension->VersionString());
|
||||||
|
dict.Set("manifest", *(extension->manifest()->value()));
|
||||||
|
|
||||||
return gin::ConvertToV8(isolate, dict);
|
return gin::ConvertToV8(isolate, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,19 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
|
||||||
expect(bg).to.equal('red')
|
expect(bg).to.equal('red')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('serializes a loaded extension', async () => {
|
||||||
|
const extensionPath = path.join(fixtures, 'extensions', 'red-bg')
|
||||||
|
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'))
|
||||||
|
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
|
||||||
|
const extension = await customSession.loadExtension(extensionPath)
|
||||||
|
expect(extension.id).to.be.a('string')
|
||||||
|
expect(extension.name).to.be.a('string')
|
||||||
|
expect(extension.path).to.be.a('string')
|
||||||
|
expect(extension.version).to.be.a('string')
|
||||||
|
expect(extension.url).to.be.a('string')
|
||||||
|
expect(extension.manifest).to.deep.equal(manifest)
|
||||||
|
})
|
||||||
|
|
||||||
it('removes an extension', async () => {
|
it('removes an extension', async () => {
|
||||||
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
|
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
|
||||||
const { id } = await customSession.loadExtension(path.join(fixtures, 'extensions', 'red-bg'))
|
const { id } = await customSession.loadExtension(path.join(fixtures, 'extensions', 'red-bg'))
|
||||||
|
|
Loading…
Reference in a new issue