refactor: ginify Archive (#24799)
This commit is contained in:
parent
6fd302f745
commit
1350dc46ed
1 changed files with 19 additions and 15 deletions
|
@ -2,35 +2,36 @@
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "gin/handle.h"
|
||||||
|
#include "gin/object_template_builder.h"
|
||||||
|
#include "gin/wrappable.h"
|
||||||
#include "shell/common/asar/archive.h"
|
#include "shell/common/asar/archive.h"
|
||||||
#include "shell/common/asar/asar_util.h"
|
#include "shell/common/asar/asar_util.h"
|
||||||
#include "shell/common/gin_converters/callback_converter.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/gin_converters/file_path_converter.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/gin_helper/object_template_builder.h"
|
|
||||||
#include "shell/common/gin_helper/wrappable.h"
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/node_util.h"
|
#include "shell/common/node_util.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class Archive : public gin_helper::Wrappable<Archive> {
|
class Archive : public gin::Wrappable<Archive> {
|
||||||
public:
|
public:
|
||||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate,
|
static gin::Handle<Archive> Create(v8::Isolate* isolate,
|
||||||
const base::FilePath& path) {
|
const base::FilePath& path) {
|
||||||
auto archive = std::make_unique<asar::Archive>(path);
|
auto archive = std::make_unique<asar::Archive>(path);
|
||||||
if (!archive->Init())
|
if (!archive->Init())
|
||||||
return v8::False(isolate);
|
return gin::Handle<Archive>();
|
||||||
return (new Archive(isolate, std::move(archive)))->GetWrapper();
|
return gin::CreateHandle(isolate, new Archive(isolate, std::move(archive)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
// gin::Wrappable
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
prototype->SetClassName(gin::StringToV8(isolate, "Archive"));
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
v8::Isolate* isolate) override {
|
||||||
|
return gin::ObjectTemplateBuilder(isolate)
|
||||||
.SetProperty("path", &Archive::GetPath)
|
.SetProperty("path", &Archive::GetPath)
|
||||||
.SetMethod("getFileInfo", &Archive::GetFileInfo)
|
.SetMethod("getFileInfo", &Archive::GetFileInfo)
|
||||||
.SetMethod("stat", &Archive::Stat)
|
.SetMethod("stat", &Archive::Stat)
|
||||||
|
@ -40,11 +41,11 @@ class Archive : public gin_helper::Wrappable<Archive> {
|
||||||
.SetMethod("getFd", &Archive::GetFD);
|
.SetMethod("getFd", &Archive::GetFD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* GetTypeName() override { return "Archive"; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Archive(v8::Isolate* isolate, std::unique_ptr<asar::Archive> archive)
|
Archive(v8::Isolate* isolate, std::unique_ptr<asar::Archive> archive)
|
||||||
: archive_(std::move(archive)) {
|
: archive_(std::move(archive)) {}
|
||||||
Init(isolate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the path of the file.
|
// Returns the path of the file.
|
||||||
base::FilePath GetPath() { return archive_->path(); }
|
base::FilePath GetPath() { return archive_->path(); }
|
||||||
|
@ -116,6 +117,9 @@ class Archive : public gin_helper::Wrappable<Archive> {
|
||||||
DISALLOW_COPY_AND_ASSIGN(Archive);
|
DISALLOW_COPY_AND_ASSIGN(Archive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// static
|
||||||
|
gin::WrapperInfo Archive::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
|
|
||||||
void InitAsarSupport(v8::Isolate* isolate, v8::Local<v8::Value> require) {
|
void InitAsarSupport(v8::Isolate* isolate, v8::Local<v8::Value> require) {
|
||||||
// Evaluate asar_bundle.js.
|
// Evaluate asar_bundle.js.
|
||||||
std::vector<v8::Local<v8::String>> asar_bundle_params = {
|
std::vector<v8::Local<v8::String>> asar_bundle_params = {
|
||||||
|
|
Loading…
Reference in a new issue