Skip to content

Commit 92643a5

Browse files
authored
refactor: consolidate WebContents::{Create,New} (electron#26521)
1 parent a303813 commit 92643a5

File tree

5 files changed

+5
-15
lines changed

5 files changed

+5
-15
lines changed

lib/browser/api/web-contents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ WebContents.prototype._init = function () {
729729
};
730730

731731
// Public APIs.
732-
export function create (options = {}) {
733-
return binding.create(options);
732+
export function create (options = {}): Electron.WebContents {
733+
return new (WebContents as any)(options);
734734
}
735735

736736
export function fromId (id: string) {

shell/browser/api/electron_api_browser_view.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ BrowserView::BrowserView(gin::Arguments* args,
7979
options.Get(options::kWebPreferences, &web_preferences);
8080
web_preferences.Set("type", "browserView");
8181
gin::Handle<class WebContents> web_contents =
82-
WebContents::Create(isolate, web_preferences);
82+
WebContents::New(isolate, web_preferences);
8383

8484
web_contents_.Reset(isolate, web_contents.ToV8());
8585
api_web_contents_ = web_contents.get();

shell/browser/api/electron_api_web_contents.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,7 +3727,7 @@ ElectronBrowserContext* WebContents::GetBrowserContext() const {
37273727
}
37283728

37293729
// static
3730-
gin::Handle<WebContents> WebContents::Create(
3730+
gin::Handle<WebContents> WebContents::New(
37313731
v8::Isolate* isolate,
37323732
const gin_helper::Dictionary& options) {
37333733
gin::Handle<WebContents> handle =
@@ -3736,13 +3736,6 @@ gin::Handle<WebContents> WebContents::Create(
37363736
return handle;
37373737
}
37383738

3739-
// static
3740-
gin::Handle<WebContents> WebContents::New(
3741-
v8::Isolate* isolate,
3742-
const gin_helper::Dictionary& options) {
3743-
return Create(isolate, options);
3744-
}
3745-
37463739
// static
37473740
gin::Handle<WebContents> WebContents::CreateAndTake(
37483741
v8::Isolate* isolate,
@@ -3809,7 +3802,6 @@ void Initialize(v8::Local<v8::Object> exports,
38093802
v8::Isolate* isolate = context->GetIsolate();
38103803
gin_helper::Dictionary dict(isolate, exports);
38113804
dict.Set("WebContents", WebContents::GetConstructor(context));
3812-
dict.SetMethod("create", &WebContents::Create);
38133805
dict.SetMethod("fromId", &WebContents::FromID);
38143806
dict.SetMethod("getAllWebContents", &GetAllWebContentsAsV8);
38153807
}

shell/browser/api/electron_api_web_contents.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class WebContents : public gin::Wrappable<WebContents>,
111111
};
112112

113113
// Create a new WebContents and return the V8 wrapper of it.
114-
static gin::Handle<WebContents> Create(v8::Isolate* isolate,
115-
const gin_helper::Dictionary& options);
116114
static gin::Handle<WebContents> New(v8::Isolate* isolate,
117115
const gin_helper::Dictionary& options);
118116

shell/browser/api/electron_api_web_contents_view.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ gin_helper::WrappableBase* WebContentsView::New(
113113
}
114114
} else {
115115
// Create one if not.
116-
web_contents = WebContents::Create(args->isolate(), web_preferences);
116+
web_contents = WebContents::New(args->isolate(), web_preferences);
117117
}
118118
// Constructor call.
119119
auto* view = new WebContentsView(args->isolate(), web_contents);

0 commit comments

Comments
 (0)