Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6910)

Unified Diff: extensions/renderer/resources/guest_view/guest_view.js

Issue 1165773004: Extract the element implementation logic to function mods in <webview>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@qui
Patch Set: fix comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/resources/guest_view/guest_view.js
diff --git a/extensions/renderer/resources/guest_view/guest_view.js b/extensions/renderer/resources/guest_view/guest_view.js
index a09f7c6026a9d79bfb6a92be8ab82662ef703881..66d48a2d3ba2c1219cd7af8fa35ef12e8d3faddc 100644
--- a/extensions/renderer/resources/guest_view/guest_view.js
+++ b/extensions/renderer/resources/guest_view/guest_view.js
@@ -14,11 +14,6 @@ var GuestViewInternalNatives = requireNative('guest_view_internal');
// Events.
var ResizeEvent = CreateEvent('guestViewInternal.onResize');
-// Possible states.
-var GUEST_STATE_ATTACHED = 2;
-var GUEST_STATE_CREATED = 1;
-var GUEST_STATE_START = 0;
-
// Error messages.
var ERROR_MSG_ALREADY_ATTACHED = 'The guest has already been attached.';
var ERROR_MSG_ALREADY_CREATED = 'The guest has already been created.';
@@ -35,10 +30,10 @@ var PROPERTY_ON_RESIZE = 'onresize';
function GuestViewImpl(guestView, viewType, guestInstanceId) {
if (guestInstanceId) {
this.id = guestInstanceId;
- this.state = GUEST_STATE_CREATED;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
} else {
this.id = 0;
- this.state = GUEST_STATE_START;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_START;
}
this.actionQueue = [];
this.contentWindow = null;
@@ -50,6 +45,13 @@ function GuestViewImpl(guestView, viewType, guestInstanceId) {
this.setupOnResize();
}
+// Possible states.
+GuestViewImpl.GuestState = {
+ GUEST_STATE_START: 0,
+ GUEST_STATE_CREATED: 1,
+ GUEST_STATE_ATTACHED: 2
+};
+
// Sets up the onResize property on the GuestView.
GuestViewImpl.prototype.setupOnResize = function() {
$Object.defineProperty(this.guestView, PROPERTY_ON_RESIZE, {
@@ -145,7 +147,7 @@ GuestViewImpl.prototype.weakWrapper = function(func, viewInstanceId) {
};
// Internal implementation of attach().
-GuestViewImpl.prototype.attachImpl = function(
+GuestViewImpl.prototype.attachImpl$ = function(
internalInstanceId, viewInstanceId, attachParams, callback) {
// Check the current state.
if (!this.checkState('attach')) {
@@ -159,7 +161,7 @@ GuestViewImpl.prototype.attachImpl = function(
var callbackWrapper = function(callback, contentWindow) {
// Check if attaching failed.
if (!contentWindow) {
- this.state = GUEST_STATE_CREATED;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
this.internalInstanceId = 0;
} else {
// Only update the contentWindow if attaching is successful.
@@ -176,23 +178,23 @@ GuestViewImpl.prototype.attachImpl = function(
callbackWrapper.bind(this, callback));
this.internalInstanceId = internalInstanceId;
- this.state = GUEST_STATE_ATTACHED;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_ATTACHED;
// Detach automatically when the container is destroyed.
GuestViewInternalNatives.RegisterDestructionCallback(
internalInstanceId, this.weakWrapper(function() {
- if (this.state != GUEST_STATE_ATTACHED ||
+ if (this.state != GuestViewImpl.GuestState.GUEST_STATE_ATTACHED ||
this.internalInstanceId != internalInstanceId) {
return;
}
this.internalInstanceId = 0;
- this.state = GUEST_STATE_CREATED;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
}, viewInstanceId));
};
// Internal implementation of create().
-GuestViewImpl.prototype.createImpl = function(createParams, callback) {
+GuestViewImpl.prototype.createImpl$ = function(createParams, callback) {
// Check the current state.
if (!this.checkState('create')) {
this.handleCallback(callback);
@@ -209,7 +211,7 @@ GuestViewImpl.prototype.createImpl = function(createParams, callback) {
// Check if creation failed.
if (this.id === 0) {
- this.state = GUEST_STATE_START;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_START;
this.contentWindow = null;
}
@@ -217,11 +219,14 @@ GuestViewImpl.prototype.createImpl = function(createParams, callback) {
this.handleCallback(callback);
};
- GuestViewInternal.createGuest(this.viewType,
- createParams,
- callbackWrapper.bind(this, callback));
+ this.sendCreateRequest(createParams, callbackWrapper.bind(this, callback));
+
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
+};
- this.state = GUEST_STATE_CREATED;
+GuestViewImpl.prototype.sendCreateRequest = function(
+ createParams, boundCallback) {
+ GuestViewInternal.createGuest(this.viewType, createParams, boundCallback);
};
// Internal implementation of destroy().
@@ -232,7 +237,7 @@ GuestViewImpl.prototype.destroyImpl = function(callback) {
return;
}
- if (this.state == GUEST_STATE_START) {
+ if (this.state == GuestViewImpl.GuestState.GUEST_STATE_START) {
// destroy() does nothing in this case.
this.handleCallback(callback);
return;
@@ -250,7 +255,7 @@ GuestViewImpl.prototype.destroyImpl = function(callback) {
this.contentWindow = null;
this.id = 0;
this.internalInstanceId = 0;
- this.state = GUEST_STATE_START;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_START;
if (ResizeEvent.hasListener(this.callOnResize)) {
ResizeEvent.removeListener(this.callOnResize);
}
@@ -269,7 +274,7 @@ GuestViewImpl.prototype.detachImpl = function(callback) {
this.handleCallback.bind(this, callback));
this.internalInstanceId = 0;
- this.state = GUEST_STATE_CREATED;
+ this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
};
// Internal implementation of setSize().
@@ -295,7 +300,7 @@ function GuestView(viewType, guestInstanceId) {
GuestView.prototype.attach = function(
internalInstanceId, viewInstanceId, attachParams, callback) {
var internal = privates(this).internal;
- internal.actionQueue.push(internal.attachImpl.bind(
+ internal.actionQueue.push(internal.attachImpl$.bind(
internal, internalInstanceId, viewInstanceId, attachParams, callback));
internal.performNextAction();
};
@@ -303,7 +308,7 @@ GuestView.prototype.attach = function(
// Creates the guestview.
GuestView.prototype.create = function(createParams, callback) {
var internal = privates(this).internal;
- internal.actionQueue.push(internal.createImpl.bind(
+ internal.actionQueue.push(internal.createImpl$.bind(
internal, createParams, callback));
internal.performNextAction();
};
@@ -346,3 +351,5 @@ GuestView.prototype.getId = function() {
// Exports
exports.GuestView = GuestView;
+exports.GuestViewImpl = GuestViewImpl;
+exports.ResizeEvent = ResizeEvent;

Powered by Google App Engine
This is Rietveld 408576698