Skip to content

Commit

Permalink
feat(extensions): add more properties to extension object (#22244)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Feb 24, 2020
1 parent 41931aa commit 68c6d53
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/api/structures/extension.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions shell/common/gin_converters/extension_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}

Expand Down
13 changes: 13 additions & 0 deletions spec-main/extensions-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 68c6d53

Please sign in to comment.