Get the WebViewManager from embedder WebContents
This make our lives easier when we have multiple BrowserContext support.
This commit is contained in:
parent
209840871c
commit
7c8bed7bfc
4 changed files with 38 additions and 18 deletions
|
@ -51,18 +51,40 @@ struct Converter<atom::WebViewManager::WebViewInfo> {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
atom::WebViewManager* GetWebViewManager(content::WebContents* web_contents) {
|
||||||
|
auto context = web_contents->GetBrowserContext();
|
||||||
|
if (context) {
|
||||||
|
auto manager = context->GetGuestManager();
|
||||||
|
return static_cast<atom::WebViewManager*>(manager);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddGuest(int guest_instance_id,
|
||||||
|
int element_instance_id,
|
||||||
|
content::WebContents* embedder,
|
||||||
|
content::WebContents* guest_web_contents,
|
||||||
|
atom::WebViewManager::WebViewInfo info) {
|
||||||
|
auto manager = GetWebViewManager(embedder);
|
||||||
|
if (manager) {
|
||||||
|
info.guest_instance_id = guest_instance_id;
|
||||||
|
info.embedder = embedder;
|
||||||
|
manager->AddGuest(guest_instance_id, element_instance_id, embedder,
|
||||||
|
guest_web_contents, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
||||||
|
auto manager = GetWebViewManager(embedder);
|
||||||
|
if (manager)
|
||||||
|
manager->RemoveGuest(guest_instance_id);
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||||
v8::Handle<v8::Context> context, void* priv) {
|
v8::Handle<v8::Context> context, void* priv) {
|
||||||
using atom::WebViewManager;
|
|
||||||
auto manager = static_cast<WebViewManager*>(
|
|
||||||
atom::AtomBrowserContext::Get()->GetGuestManager());
|
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||||
dict.SetMethod("addGuest",
|
dict.SetMethod("addGuest", &AddGuest);
|
||||||
base::Bind(&WebViewManager::AddGuest,
|
dict.SetMethod("removeGuest", &RemoveGuest);
|
||||||
base::Unretained(manager)));
|
|
||||||
dict.SetMethod("removeGuest",
|
|
||||||
base::Bind(&WebViewManager::RemoveGuest,
|
|
||||||
base::Unretained(manager)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -39,7 +39,7 @@ createGuest = (embedder, params) ->
|
||||||
# Destroy guest when the embedder is gone or navigated.
|
# Destroy guest when the embedder is gone or navigated.
|
||||||
destroyEvents = ['destroyed', 'crashed', 'did-navigate-to-different-page']
|
destroyEvents = ['destroyed', 'crashed', 'did-navigate-to-different-page']
|
||||||
destroy = ->
|
destroy = ->
|
||||||
destroyGuest id if guestInstances[id]?
|
destroyGuest embedder, id if guestInstances[id]?
|
||||||
embedder.once event, destroy for event in destroyEvents
|
embedder.once event, destroy for event in destroyEvents
|
||||||
guest.once 'destroyed', ->
|
guest.once 'destroyed', ->
|
||||||
embedder.removeListener event, destroy for event in destroyEvents
|
embedder.removeListener event, destroy for event in destroyEvents
|
||||||
|
@ -90,7 +90,7 @@ attachGuest = (embedder, elementInstanceId, guestInstanceId, params) ->
|
||||||
return unless oldGuestInstanceId != guestInstanceId
|
return unless oldGuestInstanceId != guestInstanceId
|
||||||
|
|
||||||
return unless guestInstances[oldGuestInstanceId]?
|
return unless guestInstances[oldGuestInstanceId]?
|
||||||
destroyGuest oldGuestInstanceId
|
destroyGuest embedder, oldGuestInstanceId
|
||||||
|
|
||||||
webViewManager.addGuest guestInstanceId, elementInstanceId, embedder, guest,
|
webViewManager.addGuest guestInstanceId, elementInstanceId, embedder, guest,
|
||||||
nodeIntegration: params.nodeintegration
|
nodeIntegration: params.nodeintegration
|
||||||
|
@ -103,8 +103,8 @@ attachGuest = (embedder, elementInstanceId, guestInstanceId, params) ->
|
||||||
reverseEmbedderElementsMap[guestInstanceId] = key
|
reverseEmbedderElementsMap[guestInstanceId] = key
|
||||||
|
|
||||||
# Destroy an existing guest instance.
|
# Destroy an existing guest instance.
|
||||||
destroyGuest = (id) ->
|
destroyGuest = (embedder, id) ->
|
||||||
webViewManager.removeGuest id
|
webViewManager.removeGuest embedder, id
|
||||||
guestInstances[id].guest.destroy()
|
guestInstances[id].guest.destroy()
|
||||||
delete guestInstances[id]
|
delete guestInstances[id]
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId,
|
||||||
attachGuest event.sender, elementInstanceId, guestInstanceId, params
|
attachGuest event.sender, elementInstanceId, guestInstanceId, params
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
|
||||||
destroyGuest id
|
destroyGuest event.sender, id
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, id, params) ->
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, id, params) ->
|
||||||
guestInstances[id]?.guest.setAutoSize params.enableAutoSize, params.min, params.max
|
guestInstances[id]?.guest.setAutoSize params.enableAutoSize, params.min, params.max
|
||||||
|
|
|
@ -34,13 +34,11 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
WebViewInfo info) {
|
const WebViewInfo& info) {
|
||||||
base::AutoLock auto_lock(lock_);
|
base::AutoLock auto_lock(lock_);
|
||||||
web_contents_embdder_map_[guest_instance_id] = { web_contents, embedder };
|
web_contents_embdder_map_[guest_instance_id] = { web_contents, embedder };
|
||||||
|
|
||||||
int guest_process_id = web_contents->GetRenderProcessHost()->GetID();
|
int guest_process_id = web_contents->GetRenderProcessHost()->GetID();
|
||||||
info.guest_instance_id = guest_instance_id;
|
|
||||||
info.embedder = embedder;
|
|
||||||
webview_info_map_[guest_process_id] = info;
|
webview_info_map_[guest_process_id] = info;
|
||||||
|
|
||||||
// Map the element in embedder to guest.
|
// Map the element in embedder to guest.
|
||||||
|
|
|
@ -41,7 +41,7 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
WebViewInfo info);
|
const WebViewInfo& info);
|
||||||
void RemoveGuest(int guest_instance_id);
|
void RemoveGuest(int guest_instance_id);
|
||||||
|
|
||||||
// Looks up the information for the embedder <webview> for a given render
|
// Looks up the information for the embedder <webview> for a given render
|
||||||
|
|
Loading…
Reference in a new issue