Pass isGuest when creating WebContents
This commit is contained in:
parent
4b61683cdf
commit
081a4597e9
5 changed files with 46 additions and 28 deletions
|
@ -163,29 +163,42 @@ WebContents::WebContents(const mate::Dictionary& options)
|
||||||
: guest_opaque_(true),
|
: guest_opaque_(true),
|
||||||
guest_host_(nullptr),
|
guest_host_(nullptr),
|
||||||
auto_size_enabled_(false),
|
auto_size_enabled_(false),
|
||||||
is_full_page_plugin_(false),
|
is_full_page_plugin_(false) {
|
||||||
type_(WEB_VIEW) {
|
bool is_guest = false;
|
||||||
|
options.Get("isGuest", &is_guest);
|
||||||
|
|
||||||
|
type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW;
|
||||||
|
|
||||||
auto browser_context = AtomBrowserMainParts::Get()->browser_context();
|
auto browser_context = AtomBrowserMainParts::Get()->browser_context();
|
||||||
|
content::WebContents* web_contents;
|
||||||
|
if (is_guest) {
|
||||||
content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
|
content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
|
||||||
browser_context, GURL("chrome-guest://fake-host"));
|
browser_context, GURL("chrome-guest://fake-host"));
|
||||||
|
|
||||||
content::WebContents::CreateParams params(browser_context, site_instance);
|
content::WebContents::CreateParams params(browser_context, site_instance);
|
||||||
params.guest_delegate = this;
|
params.guest_delegate = this;
|
||||||
auto web_contents = content::WebContents::Create(params);
|
web_contents = content::WebContents::Create(params);
|
||||||
|
} else {
|
||||||
|
content::WebContents::CreateParams params(browser_context);
|
||||||
|
web_contents = content::WebContents::Create(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
Observe(web_contents);
|
||||||
|
AttachAsUserData(web_contents);
|
||||||
|
InitWithWebContents(web_contents);
|
||||||
|
inspectable_web_contents_ = managed_web_contents();
|
||||||
|
|
||||||
|
if (is_guest) {
|
||||||
NativeWindow* owner_window = nullptr;
|
NativeWindow* owner_window = nullptr;
|
||||||
WebContents* embedder = nullptr;
|
WebContents* embedder = nullptr;
|
||||||
if (options.Get("embedder", &embedder) && embedder) {
|
if (options.Get("embedder", &embedder) && embedder) {
|
||||||
|
// New WebContents's owner_window is the embedder's owner_window.
|
||||||
auto relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
|
auto relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
|
||||||
if (relay)
|
if (relay)
|
||||||
owner_window = relay->window.get();
|
owner_window = relay->window.get();
|
||||||
}
|
}
|
||||||
|
if (owner_window)
|
||||||
AttachAsUserData(web_contents);
|
SetOwnerWindow(owner_window);
|
||||||
InitWithWebContents(web_contents, owner_window);
|
}
|
||||||
inspectable_web_contents_ = managed_web_contents();
|
|
||||||
|
|
||||||
Observe(GetWebContents());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::~WebContents() {
|
WebContents::~WebContents() {
|
||||||
|
|
|
@ -116,14 +116,9 @@ CommonWebContentsDelegate::~CommonWebContentsDelegate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::InitWithWebContents(
|
void CommonWebContentsDelegate::InitWithWebContents(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents) {
|
||||||
NativeWindow* owner_window) {
|
|
||||||
owner_window_ = owner_window->GetWeakPtr();
|
|
||||||
web_contents->SetDelegate(this);
|
web_contents->SetDelegate(this);
|
||||||
|
|
||||||
NativeWindowRelay* relay = new NativeWindowRelay(owner_window_);
|
|
||||||
web_contents->SetUserData(relay->key, relay);
|
|
||||||
|
|
||||||
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
||||||
printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
|
printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
|
||||||
|
|
||||||
|
@ -132,6 +127,13 @@ void CommonWebContentsDelegate::InitWithWebContents(
|
||||||
web_contents_->SetDelegate(this);
|
web_contents_->SetDelegate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommonWebContentsDelegate::SetOwnerWindow(NativeWindow* owner_window) {
|
||||||
|
content::WebContents* web_contents = GetWebContents();
|
||||||
|
owner_window_ = owner_window->GetWeakPtr();
|
||||||
|
NativeWindowRelay* relay = new NativeWindowRelay(owner_window_);
|
||||||
|
web_contents->SetUserData(relay->key, relay);
|
||||||
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::DestroyWebContents() {
|
void CommonWebContentsDelegate::DestroyWebContents() {
|
||||||
web_contents_.reset();
|
web_contents_.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,12 @@ class CommonWebContentsDelegate
|
||||||
CommonWebContentsDelegate();
|
CommonWebContentsDelegate();
|
||||||
virtual ~CommonWebContentsDelegate();
|
virtual ~CommonWebContentsDelegate();
|
||||||
|
|
||||||
// Create a InspectableWebContents object and takes onwership of
|
// Creates a InspectableWebContents object and takes onwership of
|
||||||
// |web_contents|.
|
// |web_contents|.
|
||||||
void InitWithWebContents(content::WebContents* web_contents,
|
void InitWithWebContents(content::WebContents* web_contents);
|
||||||
NativeWindow* owner_window);
|
|
||||||
|
// Set the window as owner window.
|
||||||
|
void SetOwnerWindow(NativeWindow* owner_window);
|
||||||
|
|
||||||
// Destroy the managed InspectableWebContents object.
|
// Destroy the managed InspectableWebContents object.
|
||||||
void DestroyWebContents();
|
void DestroyWebContents();
|
||||||
|
|
|
@ -38,7 +38,7 @@ createGuest = (embedder, params) ->
|
||||||
webViewManager ?= process.atomBinding 'web_view_manager'
|
webViewManager ?= process.atomBinding 'web_view_manager'
|
||||||
|
|
||||||
id = getNextInstanceId embedder
|
id = getNextInstanceId embedder
|
||||||
guest = webContents.create {embedder}
|
guest = webContents.create {isGuest: true, embedder}
|
||||||
guestInstances[id] = {guest, embedder}
|
guestInstances[id] = {guest, embedder}
|
||||||
|
|
||||||
# Destroy guest when the embedder is gone or navigated.
|
# Destroy guest when the embedder is gone or navigated.
|
||||||
|
|
|
@ -94,7 +94,8 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
has_dialog_attached_(false),
|
has_dialog_attached_(false),
|
||||||
zoom_factor_(1.0),
|
zoom_factor_(1.0),
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
InitWithWebContents(web_contents, this);
|
InitWithWebContents(web_contents);
|
||||||
|
SetOwnerWindow(this);
|
||||||
|
|
||||||
options.Get(switches::kFrame, &has_frame_);
|
options.Get(switches::kFrame, &has_frame_);
|
||||||
options.Get(switches::kTransparent, &transparent_);
|
options.Get(switches::kTransparent, &transparent_);
|
||||||
|
|
Loading…
Reference in a new issue