refactor: consolidate WebContents::{Create,New} (#26521)

This commit is contained in:
Jeremy Rose 2020-11-17 14:14:33 -08:00 committed by GitHub
parent a303813d15
commit 92643a5a1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 15 deletions

View file

@ -729,8 +729,8 @@ WebContents.prototype._init = function () {
}; };
// Public APIs. // Public APIs.
export function create (options = {}) { export function create (options = {}): Electron.WebContents {
return binding.create(options); return new (WebContents as any)(options);
} }
export function fromId (id: string) { export function fromId (id: string) {

View file

@ -79,7 +79,7 @@ BrowserView::BrowserView(gin::Arguments* args,
options.Get(options::kWebPreferences, &web_preferences); options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView"); web_preferences.Set("type", "browserView");
gin::Handle<class WebContents> web_contents = gin::Handle<class WebContents> web_contents =
WebContents::Create(isolate, web_preferences); WebContents::New(isolate, web_preferences);
web_contents_.Reset(isolate, web_contents.ToV8()); web_contents_.Reset(isolate, web_contents.ToV8());
api_web_contents_ = web_contents.get(); api_web_contents_ = web_contents.get();

View file

@ -3727,7 +3727,7 @@ ElectronBrowserContext* WebContents::GetBrowserContext() const {
} }
// static // static
gin::Handle<WebContents> WebContents::Create( gin::Handle<WebContents> WebContents::New(
v8::Isolate* isolate, v8::Isolate* isolate,
const gin_helper::Dictionary& options) { const gin_helper::Dictionary& options) {
gin::Handle<WebContents> handle = gin::Handle<WebContents> handle =
@ -3736,13 +3736,6 @@ gin::Handle<WebContents> WebContents::Create(
return handle; return handle;
} }
// static
gin::Handle<WebContents> WebContents::New(
v8::Isolate* isolate,
const gin_helper::Dictionary& options) {
return Create(isolate, options);
}
// static // static
gin::Handle<WebContents> WebContents::CreateAndTake( gin::Handle<WebContents> WebContents::CreateAndTake(
v8::Isolate* isolate, v8::Isolate* isolate,
@ -3809,7 +3802,6 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Isolate* isolate = context->GetIsolate(); v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary dict(isolate, exports); gin_helper::Dictionary dict(isolate, exports);
dict.Set("WebContents", WebContents::GetConstructor(context)); dict.Set("WebContents", WebContents::GetConstructor(context));
dict.SetMethod("create", &WebContents::Create);
dict.SetMethod("fromId", &WebContents::FromID); dict.SetMethod("fromId", &WebContents::FromID);
dict.SetMethod("getAllWebContents", &GetAllWebContentsAsV8); dict.SetMethod("getAllWebContents", &GetAllWebContentsAsV8);
} }

View file

@ -111,8 +111,6 @@ class WebContents : public gin::Wrappable<WebContents>,
}; };
// Create a new WebContents and return the V8 wrapper of it. // Create a new WebContents and return the V8 wrapper of it.
static gin::Handle<WebContents> Create(v8::Isolate* isolate,
const gin_helper::Dictionary& options);
static gin::Handle<WebContents> New(v8::Isolate* isolate, static gin::Handle<WebContents> New(v8::Isolate* isolate,
const gin_helper::Dictionary& options); const gin_helper::Dictionary& options);

View file

@ -113,7 +113,7 @@ gin_helper::WrappableBase* WebContentsView::New(
} }
} else { } else {
// Create one if not. // Create one if not.
web_contents = WebContents::Create(args->isolate(), web_preferences); web_contents = WebContents::New(args->isolate(), web_preferences);
} }
// Constructor call. // Constructor call.
auto* view = new WebContentsView(args->isolate(), web_contents); auto* view = new WebContentsView(args->isolate(), web_contents);