Fix browser plugin API changes

This commit is contained in:
Cheng Zhao 2014-12-08 08:05:34 -08:00
parent a9072049ea
commit 882a08f61a
9 changed files with 66 additions and 35 deletions

View file

@ -37,12 +37,14 @@ v8::Persistent<v8::ObjectTemplate> template_;
WebContents::WebContents(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
guest_instance_id_(-1),
element_instance_id_(-1),
guest_opaque_(true),
auto_size_enabled_(false) {
}
WebContents::WebContents(const mate::Dictionary& options)
: guest_instance_id_(-1),
element_instance_id_(-1),
guest_opaque_(true),
auto_size_enabled_(false) {
options.Get("guestInstanceId", &guest_instance_id_);
@ -226,9 +228,7 @@ void WebContents::WebContentsDestroyed() {
}
void WebContents::DidAttach(int guest_proxy_routing_id) {
base::ListValue args;
args.Append(extra_params_.release());
Emit("did-attach", args);
Emit("did-attach");
}
void WebContents::ElementSizeChanged(const gfx::Size& old_size,
@ -252,6 +252,7 @@ void WebContents::RegisterDestructionCallback(
void WebContents::WillAttach(content::WebContents* embedder_web_contents,
int browser_plugin_instance_id) {
embedder_web_contents_ = embedder_web_contents;
element_instance_id_ = browser_plugin_instance_id;
}
void WebContents::Destroy() {

View file

@ -163,17 +163,15 @@ class WebContents : public mate::EventEmitter,
// Unique ID for a guest WebContents.
int guest_instance_id_;
// |element_instance_id_| is an identifer that's unique to a particular
// element.
int element_instance_id_;
DestructionCallback destruction_callback_;
// Stores whether the contents of the guest can be transparent.
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.
scoped_ptr<brightray::InspectableWebContents> storage_;

View file

@ -18,6 +18,8 @@ supportedWebViewEvents = [
nextInstanceId = 0
guestInstances = {}
embedderElementsMap = {}
reverseEmbedderElementsMap = {}
# Generate guestInstanceId.
getNextInstanceId = (webContents) ->
@ -41,7 +43,10 @@ createGuest = (embedder, params) ->
destroyGuest id if guestInstances[id]?
# Init guest web view after attached.
guest.once 'did-attach', (event, params) ->
guest.once 'did-attach', ->
params = @attachParams
delete @attachParams
@viewInstanceId = params.instanceId
min = width: params.minwidth, height: params.minheight
max = width: params.maxwidth, height: params.maxheight
@ -66,15 +71,42 @@ createGuest = (embedder, params) ->
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.
destroyGuest = (id) ->
webViewManager.removeGuest id
guestInstances[id].guest.destroy()
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) ->
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) ->
destroyGuest id