Commit c7b1e05c authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Remove unnecessary uses of privates in GuestView JS implementation

There are several uses of |privates| in the guest view js that are used
as if it were a means of making properties inaccessible from outside a
class (like what private does in C++). |privates| only hides
properties from outside the extension system implementation.

We remove uses of |privates| where the receiver is already inaccessible
from outside the extension system implementation.

Bug: 900940
Change-Id: Ib583aefe9daa22e095d387ffab430429870796fc
Reviewed-on: https://chromium-review.googlesource.com/c/1336052Reviewed-by: default avatarPaul Meyer <paulmeyer@chromium.org>
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611354}
parent 41b6d981
...@@ -149,9 +149,8 @@ GuestViewImpl.prototype.weakWrapper = function(func, viewInstanceId) { ...@@ -149,9 +149,8 @@ GuestViewImpl.prototype.weakWrapper = function(func, viewInstanceId) {
return function() { return function() {
var view = GuestViewInternalNatives.GetViewFromID(viewInstanceId); var view = GuestViewInternalNatives.GetViewFromID(viewInstanceId);
if (view && view.guest) { if (view && view.guest) {
return $Function.apply(func, return $Function.apply(
privates(view.guest).internal, func, view.guest.internal, $Array.slice(arguments));
$Array.slice(arguments));
} }
}; };
}; };
...@@ -309,13 +308,15 @@ GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) { ...@@ -309,13 +308,15 @@ GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) {
// attach(), create(), destroy(), and getId(). All other implementation details // attach(), create(), destroy(), and getId(). All other implementation details
// are hidden. // are hidden.
function GuestView(viewType, guestInstanceId) { function GuestView(viewType, guestInstanceId) {
privates(this).internal = new GuestViewImpl(this, viewType, guestInstanceId); this.internal = new GuestViewImpl(this, viewType, guestInstanceId);
} }
GuestView.prototype.__proto__ = null;
// Attaches the guestview to the container with ID |internalInstanceId|. // Attaches the guestview to the container with ID |internalInstanceId|.
GuestView.prototype.attach = function( GuestView.prototype.attach = function(
internalInstanceId, viewInstanceId, attachParams, callback) { internalInstanceId, viewInstanceId, attachParams, callback) {
var internal = privates(this).internal; var internal = this.internal;
$Array.push(internal.actionQueue, $Function.bind(internal.attachImpl$, $Array.push(internal.actionQueue, $Function.bind(internal.attachImpl$,
internal, internalInstanceId, viewInstanceId, attachParams, callback)); internal, internalInstanceId, viewInstanceId, attachParams, callback));
internal.performNextAction(); internal.performNextAction();
...@@ -323,7 +324,7 @@ GuestView.prototype.attach = function( ...@@ -323,7 +324,7 @@ GuestView.prototype.attach = function(
// Creates the guestview. // Creates the guestview.
GuestView.prototype.create = function(createParams, callback) { GuestView.prototype.create = function(createParams, callback) {
var internal = privates(this).internal; var internal = this.internal;
$Array.push(internal.actionQueue, $Function.bind(internal.createImpl$, $Array.push(internal.actionQueue, $Function.bind(internal.createImpl$,
internal, createParams, callback)); internal, createParams, callback));
internal.performNextAction(); internal.performNextAction();
...@@ -332,7 +333,7 @@ GuestView.prototype.create = function(createParams, callback) { ...@@ -332,7 +333,7 @@ GuestView.prototype.create = function(createParams, callback) {
// Destroys the guestview. Nothing can be done with the guestview after it has // Destroys the guestview. Nothing can be done with the guestview after it has
// been destroyed. // been destroyed.
GuestView.prototype.destroy = function(callback) { GuestView.prototype.destroy = function(callback) {
var internal = privates(this).internal; var internal = this.internal;
$Array.push( $Array.push(
internal.actionQueue, internal.actionQueue,
$Function.bind(internal.destroyImpl$, internal, callback)); $Function.bind(internal.destroyImpl$, internal, callback));
...@@ -342,7 +343,7 @@ GuestView.prototype.destroy = function(callback) { ...@@ -342,7 +343,7 @@ GuestView.prototype.destroy = function(callback) {
// Detaches the guestview from its container. // Detaches the guestview from its container.
// Note: This is not currently used. // Note: This is not currently used.
GuestView.prototype.detach = function(callback) { GuestView.prototype.detach = function(callback) {
var internal = privates(this).internal; var internal = this.internal;
$Array.push(internal.actionQueue, $Array.push(internal.actionQueue,
$Function.bind(internal.detachImpl, internal, callback)); $Function.bind(internal.detachImpl, internal, callback));
internal.performNextAction(); internal.performNextAction();
...@@ -350,7 +351,7 @@ GuestView.prototype.detach = function(callback) { ...@@ -350,7 +351,7 @@ GuestView.prototype.detach = function(callback) {
// Adjusts the guestview's sizing parameters. // Adjusts the guestview's sizing parameters.
GuestView.prototype.setSize = function(sizeParams, callback) { GuestView.prototype.setSize = function(sizeParams, callback) {
var internal = privates(this).internal; var internal = this.internal;
$Array.push(internal.actionQueue, $Array.push(internal.actionQueue,
$Function.bind(internal.setSizeImpl, internal, sizeParams, callback)); $Function.bind(internal.setSizeImpl, internal, sizeParams, callback));
internal.performNextAction(); internal.performNextAction();
...@@ -358,13 +359,13 @@ GuestView.prototype.setSize = function(sizeParams, callback) { ...@@ -358,13 +359,13 @@ GuestView.prototype.setSize = function(sizeParams, callback) {
// Returns the contentWindow for this guestview. // Returns the contentWindow for this guestview.
GuestView.prototype.getContentWindow = function() { GuestView.prototype.getContentWindow = function() {
var internal = privates(this).internal; var internal = this.internal;
return internal.contentWindow; return internal.contentWindow;
}; };
// Returns the ID for this guestview. // Returns the ID for this guestview.
GuestView.prototype.getId = function() { GuestView.prototype.getId = function() {
var internal = privates(this).internal; var internal = this.internal;
return internal.id; return internal.id;
}; };
......
...@@ -25,9 +25,9 @@ function GuestViewContainer(element, viewType) { ...@@ -25,9 +25,9 @@ function GuestViewContainer(element, viewType) {
this.guest = new GuestView(viewType); this.guest = new GuestView(viewType);
this.setupAttributes(); this.setupAttributes();
privates(this).internalElement = this.createInternalElement$(); this.internalElement = this.createInternalElement$();
var shadowRoot = this.element.attachShadow({mode: 'open'}); var shadowRoot = this.element.attachShadow({mode: 'open'});
shadowRoot.appendChild(privates(this).internalElement); shadowRoot.appendChild(this.internalElement);
GuestViewInternalNatives.RegisterView(this.viewInstanceId, this, viewType); GuestViewInternalNatives.RegisterView(this.viewInstanceId, this, viewType);
} }
...@@ -43,14 +43,14 @@ GuestViewContainer.prototype.__proto__ = null; ...@@ -43,14 +43,14 @@ GuestViewContainer.prototype.__proto__ = null;
GuestViewContainer.prototype.setupGuestProperty = function() { GuestViewContainer.prototype.setupGuestProperty = function() {
$Object.defineProperty(this, 'guest', { $Object.defineProperty(this, 'guest', {
get: $Function.bind(function() { get: $Function.bind(function() {
return privates(this).guest; return this.guest_;
}, this), }, this),
set: $Function.bind(function(value) { set: $Function.bind(function(value) {
privates(this).guest = value; this.guest_ = value;
if (!value) { if (!value) {
return; return;
} }
privates(this).guest.onresize = $Function.bind(function(e) { this.guest_.onresize = $Function.bind(function(e) {
// Dispatch the 'contentresize' event. // Dispatch the 'contentresize' event.
var contentResizeEvent = new Event('contentresize', { bubbles: true }); var contentResizeEvent = new Event('contentresize', { bubbles: true });
contentResizeEvent.oldWidth = e.oldWidth; contentResizeEvent.oldWidth = e.oldWidth;
...@@ -77,7 +77,7 @@ GuestViewContainer.prototype.prepareForReattach$ = function() {}; ...@@ -77,7 +77,7 @@ GuestViewContainer.prototype.prepareForReattach$ = function() {};
GuestViewContainer.prototype.focus = function() { GuestViewContainer.prototype.focus = function() {
// Focus the internal element when focus() is called on the GuestView element. // Focus the internal element when focus() is called on the GuestView element.
privates(this).internalElement.focus(); this.internalElement.focus();
} }
GuestViewContainer.prototype.attachWindow$ = function() { GuestViewContainer.prototype.attachWindow$ = function() {
...@@ -117,7 +117,7 @@ GuestViewContainer.prototype.onInternalInstanceId = function( ...@@ -117,7 +117,7 @@ GuestViewContainer.prototype.onInternalInstanceId = function(
GuestViewContainer.prototype.handleInternalElementAttributeMutation = GuestViewContainer.prototype.handleInternalElementAttributeMutation =
function(name, oldValue, newValue) { function(name, oldValue, newValue) {
if (name == 'internalinstanceid' && !oldValue && !!newValue) { if (name == 'internalinstanceid' && !oldValue && !!newValue) {
privates(this).internalElement.removeAttribute('internalinstanceid'); this.internalElement.removeAttribute('internalinstanceid');
this.onInternalInstanceId(parseInt(newValue)); this.onInternalInstanceId(parseInt(newValue));
} }
}; };
......
...@@ -13,7 +13,7 @@ var getIframeContentWindow = function(viewInstanceId) { ...@@ -13,7 +13,7 @@ var getIframeContentWindow = function(viewInstanceId) {
if (!view) if (!view)
return null; return null;
var internalIframeElement = privates(view).internalElement; var internalIframeElement = view.internalElement;
if (internalIframeElement) if (internalIframeElement)
return internalIframeElement.contentWindow; return internalIframeElement.contentWindow;
......
...@@ -12,7 +12,6 @@ GuestViewContainer.prototype.createInternalElement$ = function() { ...@@ -12,7 +12,6 @@ GuestViewContainer.prototype.createInternalElement$ = function() {
iframeElement.style.width = '100%'; iframeElement.style.width = '100%';
iframeElement.style.height = '100%'; iframeElement.style.height = '100%';
iframeElement.style.border = '0'; iframeElement.style.border = '0';
privates(iframeElement).internal = this;
return iframeElement; return iframeElement;
}; };
...@@ -20,8 +19,8 @@ GuestViewContainer.prototype.prepareForReattach$ = function() { ...@@ -20,8 +19,8 @@ GuestViewContainer.prototype.prepareForReattach$ = function() {
// Since attachment swaps a local frame for a remote frame, we need our // Since attachment swaps a local frame for a remote frame, we need our
// internal iframe element to be local again before we can reattach. // internal iframe element to be local again before we can reattach.
var newFrame = this.createInternalElement$(); var newFrame = this.createInternalElement$();
var oldFrame = privates(this).internalElement; var oldFrame = this.internalElement;
privates(this).internalElement = newFrame; this.internalElement = newFrame;
oldFrame.parentNode.replaceChild(newFrame, oldFrame); oldFrame.parentNode.replaceChild(newFrame, oldFrame);
}; };
......
...@@ -46,8 +46,7 @@ WebViewElement.prototype.print = function() { ...@@ -46,8 +46,7 @@ WebViewElement.prototype.print = function() {
}; };
WebViewElement.prototype.back = function(callback) { WebViewElement.prototype.back = function(callback) {
return $Function.call( return $Function.call(originalGo, this, -1, callback);
privates(WebViewElement).originalGo, this, -1, callback);
}; };
WebViewElement.prototype.canGoBack = function() { WebViewElement.prototype.canGoBack = function() {
...@@ -62,7 +61,7 @@ WebViewElement.prototype.canGoForward = function() { ...@@ -62,7 +61,7 @@ WebViewElement.prototype.canGoForward = function() {
}; };
WebViewElement.prototype.forward = function(callback) { WebViewElement.prototype.forward = function(callback) {
return $Function.call(privates(WebViewElement).originalGo, this, 1, callback); return $Function.call(originalGo, this, 1, callback);
}; };
WebViewElement.prototype.getProcessId = function() { WebViewElement.prototype.getProcessId = function() {
...@@ -89,7 +88,7 @@ forwardApiMethods( ...@@ -89,7 +88,7 @@ forwardApiMethods(
// Since |back| and |forward| are implemented in terms of |go|, we need to // Since |back| and |forward| are implemented in terms of |go|, we need to
// keep a reference to the real |go| function, since user code may override // keep a reference to the real |go| function, since user code may override
// |WebViewElement.prototype.go|. // |WebViewElement.prototype.go|.
privates(WebViewElement).originalGo = WebViewElement.prototype.go; var originalGo = WebViewElement.prototype.go;
// Exports. // Exports.
exports.$set('WebViewElement', WebViewElement); exports.$set('WebViewElement', WebViewElement);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment