feat: Allow WebContentsView to accept webContents object. (#42086)

feat: Allow WebContentsView to accept webContents object
This commit is contained in:
Krzysztof Halwa 2024-05-30 21:45:35 +02:00 committed by GitHub
parent d92a80dfe3
commit 85df2a86dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 69 additions and 2 deletions

View file

@ -138,6 +138,7 @@ v8::Local<v8::Function> WebContentsView::GetConstructor(v8::Isolate* isolate) {
// static
gin_helper::WrappableBase* WebContentsView::New(gin_helper::Arguments* args) {
gin_helper::Dictionary web_preferences;
v8::Local<v8::Value> existing_web_contents_value;
{
v8::Local<v8::Value> options_value;
if (args->GetNext(&options_value)) {
@ -154,12 +155,33 @@ gin_helper::WrappableBase* WebContentsView::New(gin_helper::Arguments* args) {
return nullptr;
}
}
if (options.Get("webContents", &existing_web_contents_value)) {
gin::Handle<WebContents> existing_web_contents;
if (!gin::ConvertFromV8(args->isolate(), existing_web_contents_value,
&existing_web_contents)) {
args->ThrowError("options.webContents must be a WebContents");
return nullptr;
}
if (existing_web_contents->owner_window() != nullptr) {
args->ThrowError(
"options.webContents is already attached to a window");
return nullptr;
}
}
}
}
if (web_preferences.IsEmpty())
web_preferences = gin_helper::Dictionary::CreateEmpty(args->isolate());
if (!web_preferences.Has(options::kShow))
web_preferences.Set(options::kShow, false);
if (!existing_web_contents_value.IsEmpty()) {
web_preferences.SetHidden("webContents", existing_web_contents_value);
}
auto web_contents =
WebContents::CreateFromWebPreferences(args->isolate(), web_preferences);