Chromium Code Reviews| Index: extensions/renderer/resources/guest_view/guest_view_iframe.js |
| diff --git a/extensions/renderer/resources/guest_view/guest_view_iframe.js b/extensions/renderer/resources/guest_view/guest_view_iframe.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2661586cb3dfce4dab4148be933d892854e00d85 |
| --- /dev/null |
| +++ b/extensions/renderer/resources/guest_view/guest_view_iframe.js |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// --site-per-process overrides for guest_view.js. |
| + |
| +var GuestView = require('guestView').GuestView; |
| +var GuestViewImpl = require('guestView').GuestViewImpl; |
| +var GuestViewInternalNatives = requireNative('guest_view_internal'); |
| +var ResizeEvent = require('guestView').ResizeEvent; |
| + |
| +var getIframeContentWindow = function(viewInstanceId) { |
| + var view = GuestViewInternalNatives.GetViewFromID(viewInstanceId); |
| + if (!view) |
| + return null; |
| + |
| + var internalElement = privates(view).browserPluginElement; |
|
Fady Samuel
2015/06/05 23:45:53
Renane browserPluginElement to internalElement.
lazyboy
2015/06/05 23:52:37
Done.
|
| + if (internalElement) |
| + return internalElement.contentWindow; |
| + |
| + return null; |
| +}; |
| + |
| +// Internal implementation of attach(). |
| +GuestViewImpl.prototype.attachImpl$ = function( |
| + internalInstanceId, viewInstanceId, attachParams, callback) { |
| + // Check the current state. |
| + if (!this.checkState('attach')) { |
| + this.handleCallback(callback); |
| + return; |
| + } |
| + |
| + // Callback wrapper function to store the contentWindow from the attachGuest() |
| + // callback, handle potential attaching failure, register an automatic detach, |
| + // and advance the queue. |
| + var callbackWrapper = function(callback, contentWindow) { |
| + // Check if attaching failed. |
| + contentWindow = getIframeContentWindow(viewInstanceId); |
| + if (!contentWindow) { |
| + this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED; |
| + this.internalInstanceId = 0; |
| + } else { |
| + // Only update the contentWindow if attaching is successful. |
| + this.contentWindow = contentWindow; |
| + } |
| + |
| + this.handleCallback(callback); |
| + }; |
| + |
| + attachParams['instanceId'] = viewInstanceId; |
| + var contentWindow = getIframeContentWindow(viewInstanceId); |
| + // TODO(lazyboy): Call binding function to attach this guest. |
| + // |contentWindow| should be used to retrieve the RenderFrame in cpp. |
| + |
| + this.internalInstanceId = internalInstanceId; |
| + this.state = GuestViewImpl.GuestState.GUEST_STATE_ATTACHED; |
| + |
| + // Detach automatically when the container is destroyed. |
| + GuestViewInternalNatives.RegisterDestructionCallback( |
| + internalInstanceId, this.weakWrapper(function() { |
| + if (this.state != GuestViewImpl.GuestState.GUEST_STATE_ATTACHED || |
| + this.internalInstanceId != internalInstanceId) { |
| + return; |
| + } |
| + |
| + this.internalInstanceId = 0; |
| + this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED; |
| + }, viewInstanceId)); |
| +}; |
| + |
| +// Internal implementation of create(). |
| +GuestViewImpl.prototype.createImpl$ = function(createParams, callback) { |
| + window.console.log('GuestViewImpl.prototype.createImpl$'); |
|
Fady Samuel
2015/06/05 23:45:53
Avoid spew.
lazyboy
2015/06/05 23:52:37
Done.
|
| + // Check the current state. |
| + if (!this.checkState('create')) { |
| + this.handleCallback(callback); |
| + return; |
| + } |
| + |
| + // Callback wrapper function to store the guestInstanceId from the |
| + // createGuest() callback, handle potential creation failure, and advance the |
| + // queue. |
| + var callbackWrapper = function(callback, guestInfo) { |
| + this.id = guestInfo.id; |
| + |
| + // Check if creation failed. |
| + if (this.id === 0) { |
| + this.state = GuestViewImpl.GuestState.GUEST_STATE_START; |
| + this.contentWindow = null; |
| + } |
| + |
| + ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); |
| + this.handleCallback(callback); |
| + }; |
| + |
| + this.sendCreateRequest(createParams, callbackWrapper.bind(this, callback)); |
| + |
| + this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED; |
| +}; |