Pass embedder when creating WebContents

This commit is contained in:
Cheng Zhao 2015-06-09 15:50:20 +08:00
parent 5459137d3d
commit 9f0ac13edc
2 changed files with 8 additions and 13 deletions

View file

@ -9,7 +9,6 @@
#include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_context.h"
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "atom/browser/web_view_manager.h"
#include "atom/common/api/api_messages.h" #include "atom/common/api/api_messages.h"
#include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h" #include "atom/common/native_mate_converters/gurl_converter.h"
@ -83,15 +82,6 @@ v8::Persistent<v8::ObjectTemplate> template_;
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>; using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
WrapWebContentsCallback g_wrap_web_contents; WrapWebContentsCallback g_wrap_web_contents;
// Get the window that has the |guest| embedded.
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
WebViewManager::WebViewInfo info;
if (WebViewManager::GetInfoForWebContents(guest, &info))
return NativeWindow::FromWebContents(info.embedder);
else
return nullptr;
}
content::ServiceWorkerContext* GetServiceWorkerContext( content::ServiceWorkerContext* GetServiceWorkerContext(
const content::WebContents* web_contents) { const content::WebContents* web_contents) {
auto context = web_contents->GetBrowserContext(); auto context = web_contents->GetBrowserContext();
@ -136,9 +126,14 @@ WebContents::WebContents(const mate::Dictionary& options)
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); auto web_contents = content::WebContents::Create(params);
InitWithWebContents(web_contents, GetWindowFromGuest(web_contents));
NativeWindow* owner_window = nullptr;
WebContents* embedder = nullptr;
if (options.Get("embedder", &embedder) && embedder)
owner_window = NativeWindow::FromWebContents(embedder->web_contents());
InitWithWebContents(web_contents, owner_window);
inspectable_web_contents_ = managed_web_contents(); inspectable_web_contents_ = managed_web_contents();
Observe(GetWebContents()); Observe(GetWebContents());

View file

@ -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() guest = webContents.create {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.