2015-02-04 23:39:41 +00: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-09-05 02:43:30 +00:00
|
|
|
#include "atom/browser/web_contents_preferences.h"
|
2017-01-30 11:18:40 +00:00
|
|
|
#include "atom/browser/web_contents_zoom_controller.h"
|
2015-02-04 23:39:41 +00:00
|
|
|
#include "atom/browser/web_view_manager.h"
|
2016-04-26 07:31:56 +00:00
|
|
|
#include "atom/common/native_mate_converters/content_converter.h"
|
2015-09-05 02:43:30 +00:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2017-01-31 09:25:48 +00:00
|
|
|
#include "atom/common/options_switches.h"
|
2015-02-05 08:17:45 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2015-02-04 23:39:41 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2018-08-16 22:57:40 +00:00
|
|
|
|
2017-08-28 15:27:03 +00:00
|
|
|
// Must be the last in the includes list.
|
|
|
|
// See https://github.com/electron/electron/issues/10363
|
|
|
|
#include "atom/common/node_includes.h"
|
2015-02-04 23:39:41 +00:00
|
|
|
|
2015-09-07 07:55:08 +00:00
|
|
|
using atom::WebContentsPreferences;
|
|
|
|
|
2015-02-04 23:39:41 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-02-04 23:52:59 +00:00
|
|
|
void AddGuest(int guest_instance_id,
|
|
|
|
int element_instance_id,
|
|
|
|
content::WebContents* embedder,
|
|
|
|
content::WebContents* guest_web_contents,
|
2015-09-05 02:43:30 +00:00
|
|
|
const base::DictionaryValue& options) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* manager = atom::WebViewManager::GetWebViewManager(embedder);
|
2015-09-03 00:47:58 +00:00
|
|
|
if (manager)
|
2015-02-04 23:52:59 +00:00
|
|
|
manager->AddGuest(guest_instance_id, element_instance_id, embedder,
|
2015-09-03 00:47:58 +00:00
|
|
|
guest_web_contents);
|
|
|
|
|
2017-01-30 11:18:40 +00:00
|
|
|
double zoom_factor;
|
2017-01-31 09:25:48 +00:00
|
|
|
if (options.GetDouble(atom::options::kZoomFactor, &zoom_factor)) {
|
2017-01-30 11:18:40 +00:00
|
|
|
atom::WebContentsZoomController::FromWebContents(guest_web_contents)
|
|
|
|
->SetDefaultZoomFactor(zoom_factor);
|
|
|
|
}
|
|
|
|
|
2018-03-08 07:12:45 +00:00
|
|
|
WebContentsPreferences::From(guest_web_contents)->Merge(options);
|
2015-02-04 23:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* manager = atom::WebViewManager::GetWebViewManager(embedder);
|
2015-02-04 23:52:59 +00:00
|
|
|
if (manager)
|
|
|
|
manager->RemoveGuest(guest_instance_id);
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2015-02-04 23:39:41 +00:00
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
2015-02-04 23:52:59 +00:00
|
|
|
dict.SetMethod("addGuest", &AddGuest);
|
|
|
|
dict.SetMethod("removeGuest", &RemoveGuest);
|
2015-02-04 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-08 18:29:52 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_web_view_manager, Initialize)
|