Fix browser plugin API changes
This commit is contained in:
parent
a9072049ea
commit
882a08f61a
9 changed files with 66 additions and 35 deletions
1
atom.gyp
1
atom.gyp
|
@ -49,6 +49,7 @@
|
||||||
'atom/renderer/lib/override.coffee',
|
'atom/renderer/lib/override.coffee',
|
||||||
'atom/renderer/lib/web-view/guest-view-internal.coffee',
|
'atom/renderer/lib/web-view/guest-view-internal.coffee',
|
||||||
'atom/renderer/lib/web-view/web-view.coffee',
|
'atom/renderer/lib/web-view/web-view.coffee',
|
||||||
|
'atom/renderer/lib/web-view/web-view-constants.coffee',
|
||||||
'atom/renderer/api/lib/ipc.coffee',
|
'atom/renderer/api/lib/ipc.coffee',
|
||||||
'atom/renderer/api/lib/remote.coffee',
|
'atom/renderer/api/lib/remote.coffee',
|
||||||
'atom/renderer/api/lib/web-frame.coffee',
|
'atom/renderer/api/lib/web-frame.coffee',
|
||||||
|
|
|
@ -37,12 +37,14 @@ v8::Persistent<v8::ObjectTemplate> template_;
|
||||||
WebContents::WebContents(content::WebContents* web_contents)
|
WebContents::WebContents(content::WebContents* web_contents)
|
||||||
: content::WebContentsObserver(web_contents),
|
: content::WebContentsObserver(web_contents),
|
||||||
guest_instance_id_(-1),
|
guest_instance_id_(-1),
|
||||||
|
element_instance_id_(-1),
|
||||||
guest_opaque_(true),
|
guest_opaque_(true),
|
||||||
auto_size_enabled_(false) {
|
auto_size_enabled_(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::WebContents(const mate::Dictionary& options)
|
WebContents::WebContents(const mate::Dictionary& options)
|
||||||
: guest_instance_id_(-1),
|
: guest_instance_id_(-1),
|
||||||
|
element_instance_id_(-1),
|
||||||
guest_opaque_(true),
|
guest_opaque_(true),
|
||||||
auto_size_enabled_(false) {
|
auto_size_enabled_(false) {
|
||||||
options.Get("guestInstanceId", &guest_instance_id_);
|
options.Get("guestInstanceId", &guest_instance_id_);
|
||||||
|
@ -226,9 +228,7 @@ void WebContents::WebContentsDestroyed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::DidAttach(int guest_proxy_routing_id) {
|
void WebContents::DidAttach(int guest_proxy_routing_id) {
|
||||||
base::ListValue args;
|
Emit("did-attach");
|
||||||
args.Append(extra_params_.release());
|
|
||||||
Emit("did-attach", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::ElementSizeChanged(const gfx::Size& old_size,
|
void WebContents::ElementSizeChanged(const gfx::Size& old_size,
|
||||||
|
@ -252,6 +252,7 @@ void WebContents::RegisterDestructionCallback(
|
||||||
void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
||||||
int browser_plugin_instance_id) {
|
int browser_plugin_instance_id) {
|
||||||
embedder_web_contents_ = embedder_web_contents;
|
embedder_web_contents_ = embedder_web_contents;
|
||||||
|
element_instance_id_ = browser_plugin_instance_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::Destroy() {
|
void WebContents::Destroy() {
|
||||||
|
|
|
@ -163,17 +163,15 @@ class WebContents : public mate::EventEmitter,
|
||||||
// Unique ID for a guest WebContents.
|
// Unique ID for a guest WebContents.
|
||||||
int guest_instance_id_;
|
int guest_instance_id_;
|
||||||
|
|
||||||
|
// |element_instance_id_| is an identifer that's unique to a particular
|
||||||
|
// element.
|
||||||
|
int element_instance_id_;
|
||||||
|
|
||||||
DestructionCallback destruction_callback_;
|
DestructionCallback destruction_callback_;
|
||||||
|
|
||||||
// Stores whether the contents of the guest can be transparent.
|
// Stores whether the contents of the guest can be transparent.
|
||||||
bool guest_opaque_;
|
bool guest_opaque_;
|
||||||
|
|
||||||
// The extra parameters associated with this guest view passed
|
|
||||||
// in from JavaScript. This will typically be the view instance ID,
|
|
||||||
// the API to use, and view-specific parameters. These parameters
|
|
||||||
// are passed along to new guests that are created from this guest.
|
|
||||||
scoped_ptr<base::DictionaryValue> extra_params_;
|
|
||||||
|
|
||||||
// Stores the WebContents that managed by this class.
|
// Stores the WebContents that managed by this class.
|
||||||
scoped_ptr<brightray::InspectableWebContents> storage_;
|
scoped_ptr<brightray::InspectableWebContents> storage_;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ supportedWebViewEvents = [
|
||||||
|
|
||||||
nextInstanceId = 0
|
nextInstanceId = 0
|
||||||
guestInstances = {}
|
guestInstances = {}
|
||||||
|
embedderElementsMap = {}
|
||||||
|
reverseEmbedderElementsMap = {}
|
||||||
|
|
||||||
# Generate guestInstanceId.
|
# Generate guestInstanceId.
|
||||||
getNextInstanceId = (webContents) ->
|
getNextInstanceId = (webContents) ->
|
||||||
|
@ -41,7 +43,10 @@ createGuest = (embedder, params) ->
|
||||||
destroyGuest id if guestInstances[id]?
|
destroyGuest id if guestInstances[id]?
|
||||||
|
|
||||||
# Init guest web view after attached.
|
# Init guest web view after attached.
|
||||||
guest.once 'did-attach', (event, params) ->
|
guest.once 'did-attach', ->
|
||||||
|
params = @attachParams
|
||||||
|
delete @attachParams
|
||||||
|
|
||||||
@viewInstanceId = params.instanceId
|
@viewInstanceId = params.instanceId
|
||||||
min = width: params.minwidth, height: params.minheight
|
min = width: params.minwidth, height: params.minheight
|
||||||
max = width: params.maxwidth, height: params.maxheight
|
max = width: params.maxwidth, height: params.maxheight
|
||||||
|
@ -66,15 +71,42 @@ createGuest = (embedder, params) ->
|
||||||
|
|
||||||
id
|
id
|
||||||
|
|
||||||
|
# Attach the guest to an element of embedder.
|
||||||
|
attachGuest = (embedder, elementInstanceId, guestInstanceId, params) ->
|
||||||
|
guest = guestInstances[guestInstanceId].guest
|
||||||
|
|
||||||
|
# Destroy the old guest when attaching.
|
||||||
|
key = "#{embedder.getId()}-#{elementInstanceId}"
|
||||||
|
oldGuestInstanceId = embedderElementsMap[key]
|
||||||
|
if oldGuestInstanceId?
|
||||||
|
# Reattachment to the same guest is not currently supported.
|
||||||
|
return unless oldGuestInstanceId != guestInstanceId
|
||||||
|
|
||||||
|
return unless guestInstances[oldGuestInstanceId]?
|
||||||
|
destroyGuest oldGuestInstanceId
|
||||||
|
|
||||||
|
guest.attachParams = params
|
||||||
|
embedderElementsMap[key] = guestInstanceId
|
||||||
|
reverseEmbedderElementsMap[guestInstanceId] = key
|
||||||
|
|
||||||
# Destroy an existing guest instance.
|
# Destroy an existing guest instance.
|
||||||
destroyGuest = (id) ->
|
destroyGuest = (id) ->
|
||||||
webViewManager.removeGuest id
|
webViewManager.removeGuest id
|
||||||
guestInstances[id].guest.destroy()
|
guestInstances[id].guest.destroy()
|
||||||
delete guestInstances[id]
|
delete guestInstances[id]
|
||||||
|
|
||||||
|
key = reverseEmbedderElementsMap[id]
|
||||||
|
if key?
|
||||||
|
delete reverseEmbedderElementsMap[id]
|
||||||
|
delete embedderElementsMap[key]
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
|
||||||
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
||||||
|
|
||||||
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId, guestInstanceId, params, requestId) ->
|
||||||
|
attachGuest event.sender, elementInstanceId, guestInstanceId, params
|
||||||
|
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}"
|
||||||
|
|
||||||
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 id
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "atom/renderer/api/atom_api_web_frame.h"
|
#include "atom/renderer/api/atom_api_web_frame.h"
|
||||||
|
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
|
#include "content/public/renderer/render_frame.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "third_party/WebKit/public/web/WebDocument.h"
|
#include "third_party/WebKit/public/web/WebDocument.h"
|
||||||
|
@ -51,6 +52,10 @@ v8::Handle<v8::Value> WebFrame::RegisterEmbedderCustomElement(
|
||||||
return web_frame_->document().registerEmbedderCustomElement(name, options, c);
|
return web_frame_->document().registerEmbedderCustomElement(name, options, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebFrame::AttachGuest(int id) {
|
||||||
|
content::RenderFrame::FromWebFrame(web_frame_)->AttachGuest(id);
|
||||||
|
}
|
||||||
|
|
||||||
mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
|
mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
|
||||||
v8::Isolate* isolate) {
|
v8::Isolate* isolate) {
|
||||||
return mate::ObjectTemplateBuilder(isolate)
|
return mate::ObjectTemplateBuilder(isolate)
|
||||||
|
@ -60,7 +65,8 @@ mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
|
||||||
.SetMethod("setZoomFactor", &WebFrame::SetZoomFactor)
|
.SetMethod("setZoomFactor", &WebFrame::SetZoomFactor)
|
||||||
.SetMethod("getZoomFactor", &WebFrame::GetZoomFactor)
|
.SetMethod("getZoomFactor", &WebFrame::GetZoomFactor)
|
||||||
.SetMethod("registerEmbedderCustomElement",
|
.SetMethod("registerEmbedderCustomElement",
|
||||||
&WebFrame::RegisterEmbedderCustomElement);
|
&WebFrame::RegisterEmbedderCustomElement)
|
||||||
|
.SetMethod("attachGuest", &WebFrame::AttachGuest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -35,6 +35,7 @@ class WebFrame : public mate::Wrappable {
|
||||||
|
|
||||||
v8::Handle<v8::Value> RegisterEmbedderCustomElement(
|
v8::Handle<v8::Value> RegisterEmbedderCustomElement(
|
||||||
const base::string16& name, v8::Handle<v8::Object> options);
|
const base::string16& name, v8::Handle<v8::Object> options);
|
||||||
|
void AttachGuest(int element_instance_id);
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc'
|
||||||
|
webFrame = require 'web-frame'
|
||||||
|
|
||||||
requestId = 0
|
requestId = 0
|
||||||
|
|
||||||
|
@ -36,7 +37,12 @@ module.exports =
|
||||||
createGuest: (type, params, callback) ->
|
createGuest: (type, params, callback) ->
|
||||||
requestId++
|
requestId++
|
||||||
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', type, params, requestId
|
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', type, params, requestId
|
||||||
ipc.on "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
||||||
|
|
||||||
|
attachGuest: (elementInstanceId, guestInstanceId, params, callback) ->
|
||||||
|
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params
|
||||||
|
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
||||||
|
webFrame.attachGuest elementInstanceId
|
||||||
|
|
||||||
destroyGuest: (guestInstanceId) ->
|
destroyGuest: (guestInstanceId) ->
|
||||||
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId
|
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId
|
||||||
|
|
0
atom/renderer/lib/web-view/web-view-constants.coffee
Normal file
0
atom/renderer/lib/web-view/web-view-constants.coffee
Normal file
|
@ -7,10 +7,6 @@ remote = require 'remote'
|
||||||
nextId = 0
|
nextId = 0
|
||||||
getNextId = -> ++nextId
|
getNextId = -> ++nextId
|
||||||
|
|
||||||
# FIXME
|
|
||||||
# Discarded after Chrome 39
|
|
||||||
PLUGIN_METHOD_ATTACH = '-internal-attach'
|
|
||||||
|
|
||||||
# Attributes.
|
# Attributes.
|
||||||
WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY = 'allowtransparency'
|
WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY = 'allowtransparency'
|
||||||
WEB_VIEW_ATTRIBUTE_AUTOSIZE = 'autosize'
|
WEB_VIEW_ATTRIBUTE_AUTOSIZE = 'autosize'
|
||||||
|
@ -103,6 +99,8 @@ class WebView
|
||||||
@setupWebviewNodeProperties()
|
@setupWebviewNodeProperties()
|
||||||
|
|
||||||
@viewInstanceId = getNextId()
|
@viewInstanceId = getNextId()
|
||||||
|
|
||||||
|
# UPSTREAM: new WebViewEvents(this, this.viewInstanceId);
|
||||||
guestViewInternal.registerEvents this, @viewInstanceId
|
guestViewInternal.registerEvents this, @viewInstanceId
|
||||||
|
|
||||||
shadowRoot.appendChild @browserPluginNode
|
shadowRoot.appendChild @browserPluginNode
|
||||||
|
@ -126,6 +124,7 @@ class WebView
|
||||||
# heard back from createGuest yet. We will not reset the flag in this case so
|
# heard back from createGuest yet. We will not reset the flag in this case so
|
||||||
# that we don't end up allocating a second guest.
|
# that we don't end up allocating a second guest.
|
||||||
if @guestInstanceId
|
if @guestInstanceId
|
||||||
|
# FIXME
|
||||||
guestViewInternal.destroyGuest @guestInstanceId
|
guestViewInternal.destroyGuest @guestInstanceId
|
||||||
@guestInstanceId = undefined
|
@guestInstanceId = undefined
|
||||||
@beforeFirstNavigation = true
|
@beforeFirstNavigation = true
|
||||||
|
@ -295,23 +294,14 @@ class WebView
|
||||||
@partition.fromAttribute newValue, @hasNavigated()
|
@partition.fromAttribute newValue, @hasNavigated()
|
||||||
|
|
||||||
handleBrowserPluginAttributeMutation: (name, oldValue, newValue) ->
|
handleBrowserPluginAttributeMutation: (name, oldValue, newValue) ->
|
||||||
# FIXME
|
if name is 'internalinstanceid' and !oldValue and !!newValue
|
||||||
# internalbindings => internalInstanceid after Chrome 39
|
@browserPluginNode.removeAttribute 'internalinstanceid'
|
||||||
if name is 'internalbindings' and !oldValue and !!newValue
|
@internalInstanceId = parseInt newValue
|
||||||
@browserPluginNode.removeAttribute 'internalbindings'
|
|
||||||
# FIXME
|
|
||||||
# @internalInstanceId = parseInt newValue
|
|
||||||
|
|
||||||
if !!@guestInstanceId and @guestInstanceId != 0
|
if !!@guestInstanceId and @guestInstanceId != 0
|
||||||
isNewWindow = if @deferredAttachState then @deferredAttachState.isNewWindow else false
|
isNewWindow = if @deferredAttachState then @deferredAttachState.isNewWindow else false
|
||||||
params = @buildAttachParams isNewWindow
|
params = @buildAttachParams isNewWindow
|
||||||
# FIXME
|
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, params, (w) => @contentWindow = w
|
||||||
# guestViewInternalNatives.AttachGuest
|
|
||||||
# @internalInstanceId,
|
|
||||||
# @guestInstanceId,
|
|
||||||
# params,
|
|
||||||
# (w) => @contentWindow = w
|
|
||||||
@browserPluginNode[PLUGIN_METHOD_ATTACH] @guestInstanceId, params
|
|
||||||
|
|
||||||
onSizeChanged: (webViewEvent) ->
|
onSizeChanged: (webViewEvent) ->
|
||||||
newWidth = webViewEvent.newWidth
|
newWidth = webViewEvent.newWidth
|
||||||
|
@ -363,9 +353,7 @@ class WebView
|
||||||
|
|
||||||
# Returns if <object> is in the render tree.
|
# Returns if <object> is in the render tree.
|
||||||
isPluginInRenderTree: ->
|
isPluginInRenderTree: ->
|
||||||
# FIXME
|
!!@internalInstanceId && @internalInstanceId != 0
|
||||||
# !!@internalInstanceId && @internalInstanceId != 0
|
|
||||||
'function' == typeof this.browserPluginNode[PLUGIN_METHOD_ATTACH]
|
|
||||||
|
|
||||||
hasNavigated: ->
|
hasNavigated: ->
|
||||||
not @beforeFirstNavigation
|
not @beforeFirstNavigation
|
||||||
|
@ -480,9 +468,7 @@ class WebView
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@deferredAttachState = null
|
@deferredAttachState = null
|
||||||
# FIXME
|
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, params, (w) => @contentWindow = w
|
||||||
# guestViewInternalNatives.AttachGuest @internalInstanceId, @guestInstanceId, params, (w) => @contentWindow = w
|
|
||||||
@browserPluginNode[PLUGIN_METHOD_ATTACH] @guestInstanceId, params
|
|
||||||
|
|
||||||
# Registers browser plugin <object> custom element.
|
# Registers browser plugin <object> custom element.
|
||||||
registerBrowserPluginElement = ->
|
registerBrowserPluginElement = ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue