2015-02-04 15:39:41 -08:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-02-05 00:17:45 -08:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
|
|
#include "shell/browser/web_contents_zoom_controller.h"
|
|
|
|
#include "shell/browser/web_view_manager.h"
|
2019-10-25 22:03:28 +09:00
|
|
|
#include "shell/common/gin_converters/content_converter.h"
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/common/node_includes.h"
|
|
|
|
#include "shell/common/options_switches.h"
|
2018-08-16 15:57:40 -07:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
using electron::WebContentsPreferences;
|
2015-09-07 15:55:08 +08:00
|
|
|
|
2015-02-04 15:39:41 -08:00
|
|
|
namespace {
|
|
|
|
|
2015-02-04 15:52:59 -08:00
|
|
|
void AddGuest(int guest_instance_id,
|
|
|
|
content::WebContents* embedder,
|
|
|
|
content::WebContents* guest_web_contents,
|
2021-07-26 09:04:09 -07:00
|
|
|
const gin_helper::Dictionary& options) {
|
2019-06-19 14:23:04 -07:00
|
|
|
auto* manager = electron::WebViewManager::GetWebViewManager(embedder);
|
2015-09-03 06:17:58 +05:30
|
|
|
if (manager)
|
2021-05-04 15:59:44 +02:00
|
|
|
manager->AddGuest(guest_instance_id, embedder, guest_web_contents);
|
2015-09-03 06:17:58 +05:30
|
|
|
|
2017-01-30 16:48:40 +05:30
|
|
|
double zoom_factor;
|
2021-07-26 09:04:09 -07:00
|
|
|
if (options.Get(electron::options::kZoomFactor, &zoom_factor)) {
|
2019-06-19 14:23:04 -07:00
|
|
|
electron::WebContentsZoomController::FromWebContents(guest_web_contents)
|
2017-01-30 16:48:40 +05:30
|
|
|
->SetDefaultZoomFactor(zoom_factor);
|
|
|
|
}
|
2015-02-04 15:52:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
2019-06-19 14:23:04 -07:00
|
|
|
auto* manager = electron::WebViewManager::GetWebViewManager(embedder);
|
2015-02-04 15:52:59 -08:00
|
|
|
if (manager)
|
|
|
|
manager->RemoveGuest(guest_instance_id);
|
|
|
|
}
|
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2019-10-25 22:03:28 +09:00
|
|
|
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
2015-02-04 15:52:59 -08:00
|
|
|
dict.SetMethod("addGuest", &AddGuest);
|
|
|
|
dict.SetMethod("removeGuest", &RemoveGuest);
|
2015-02-04 15:39:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-02-14 03:25:39 -08:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_web_view_manager, Initialize)
|