feat(extensions): add more properties to extension object (#22244)

This commit is contained in:
Samuel Maddock 2020-02-23 22:30:32 -05:00 committed by GitHub
parent 41931aa5fa
commit 68c6d53156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View file

@ -1,5 +1,8 @@
# Extension Object
* `id` String
* `manifest` any - Copy of the [extension's manifest data](https://developer.chrome.com/extensions/manifest).
* `name` String
* `path` String - The extension's file path.
* `version` String
* `url` String - The extension's `chrome-extension://` URL.

View file

@ -6,6 +6,9 @@
#include "extensions/common/extension.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 {
@ -16,7 +19,11 @@ v8::Local<v8::Value> Converter<const extensions::Extension*>::ToV8(
auto dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("id", extension->id());
dict.Set("name", extension->name());
dict.Set("path", extension->path());
dict.Set("url", extension->url());
dict.Set("version", extension->VersionString());
dict.Set("manifest", *(extension->manifest()->value()));
return gin::ConvertToV8(isolate, dict);
}

View file

@ -44,6 +44,19 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
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 () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
const { id } = await customSession.loadExtension(path.join(fixtures, 'extensions', 'red-bg'))