Browse Source

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

Samuel Maddock 5 years ago
parent
commit
68c6d53156

+ 3 - 0
docs/api/structures/extension.md

@@ -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 - 0
shell/common/gin_converters/extension_converter.cc

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

+ 13 - 0
spec-main/extensions-spec.ts

@@ -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'))