// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Shim extension to provide permission request API (and possibly other future
-// experimental APIs) for <webview> tag.
+// This module implements experimental API for <webview>.
// See web_view.js for details.
//
-// We want to control the permission API feature in <webview> separately from
-// the <webview> feature itself. <webview> is available in stable channel, but
-// permission API would only be available for channels CHANNEL_DEV and
-// CHANNEL_CANARY.
+// <webview> Experimental API is only available on canary and dev channels of
+// Chrome.
var CreateEvent = require('webView').CreateEvent;
var MessagingNatives = requireNative('messaging_natives');
'dialog': {
cancelable: true,
customHandler: function(webViewInternal, event, webViewEvent) {
- webViewInternal.handleDialogEvent_(event, webViewEvent);
+ webViewInternal.handleDialogEvent(event, webViewEvent);
},
evt: CreateEvent('webview.onDialog'),
fields: ['defaultPromptText', 'messageText', 'messageType', 'url']
+ },
+ 'zoomchange': {
+ evt: CreateEvent('webview.onZoomChange'),
+ fields: ['oldZoomFactor', 'newZoomFactor']
}
};
/**
* @private
*/
-WebViewInternal.prototype.maybeAttachWebRequestEventToObject_ =
+WebViewInternal.prototype.maybeAttachWebRequestEventToObject =
function(obj, eventName, webRequestEvent) {
Object.defineProperty(
obj,
/**
* @private
*/
-WebViewInternal.prototype.handleDialogEvent_ =
+WebViewInternal.prototype.setZoom = function(zoomFactor) {
+ if (!this.instanceId) {
+ return;
+ }
+ WebView.setZoom(this.instanceId, zoomFactor);
+};
+
+/**
+ * @private
+ */
+WebViewInternal.prototype.handleDialogEvent =
function(event, webViewEvent) {
var showWarningMessage = function(dialogType) {
var VOWELS = ['a', 'e', 'i', 'o', 'u'];
};
var self = this;
- var browserPluginNode = this.browserPluginNode_;
- var webviewNode = this.webviewNode_;
+ var browserPluginNode = this.browserPluginNode;
+ var webviewNode = this.webviewNode;
var requestId = event.requestId;
var actionTaken = false;
ok: function(user_input) {
validateCall();
user_input = user_input || '';
- WebView.setPermission(self.instanceId_, requestId, 'allow', user_input);
+ WebView.setPermission(self.instanceId, requestId, 'allow', user_input);
},
cancel: function() {
validateCall();
- WebView.setPermission(self.instanceId_, requestId, 'deny');
+ WebView.setPermission(self.instanceId, requestId, 'deny');
}
};
webViewEvent.dialog = dialog;
return;
}
WebView.setPermission(
- self.instanceId_, requestId, 'default', '', function(allowed) {
+ self.instanceId, requestId, 'default', '', function(allowed) {
if (allowed) {
return;
}
actionTaken = true;
// The default action is equivalent to canceling the dialog.
WebView.setPermission(
- self.instanceId_, requestId, 'default', '', function(allowed) {
+ self.instanceId, requestId, 'default', '', function(allowed) {
if (allowed) {
return;
}
}
};
-/** @private */
-WebViewInternal.prototype.maybeGetExperimentalEvents_ = function() {
+WebViewInternal.prototype.maybeGetExperimentalEvents = function() {
return WEB_VIEW_EXPERIMENTAL_EVENTS;
};
-WebViewInternal.prototype.maybeGetExperimentalPermissions_ = function() {
+/** @private */
+WebViewInternal.prototype.maybeGetExperimentalPermissions = function() {
return [];
};
/** @private */
-WebViewInternal.prototype.clearData_ = function(var_args) {
- if (!this.instanceId_) {
+WebViewInternal.prototype.maybeSetCurrentZoomFactor =
+ function(zoomFactor) {
+ this.currentZoomFactor = zoomFactor;
+};
+
+/** @private */
+WebViewInternal.prototype.clearData = function(var_args) {
+ if (!this.instanceId) {
return;
}
- var args = $Array.concat([this.instanceId_], $Array.slice(arguments));
+ var args = $Array.concat([this.instanceId], $Array.slice(arguments));
$Function.apply(WebView.clearData, null, args);
};
/** @private */
-WebViewInternal.prototype.captureVisibleRegion_ = function(spec, callback) {
- WebView.captureVisibleRegion(this.instanceId_, spec, callback);
+WebViewInternal.prototype.setZoom = function(zoomFactor, callback) {
+ if (!this.instanceId) {
+ return;
+ }
+ WebView.setZoom(this.instanceId, zoomFactor, callback);
+};
+
+WebViewInternal.prototype.getZoom = function(callback) {
+ if (!this.instanceId) {
+ return;
+ }
+ WebView.getZoom(this.instanceId, callback);
+};
+
+/** @private */
+WebViewInternal.prototype.captureVisibleRegion = function(spec, callback) {
+ WebView.captureVisibleRegion(this.instanceId, spec, callback);
};
-WebViewInternal.maybeRegisterExperimentalAPIs = function(proto, secret) {
+WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {
proto.clearData = function(var_args) {
- var internal = this.internal_(secret);
- $Function.apply(internal.clearData_, internal, arguments);
+ var internal = privates(this).internal;
+ $Function.apply(internal.clearData, internal, arguments);
+ };
+
+ proto.setZoom = function(zoomFactor, callback) {
+ privates(this).internal.setZoom(zoomFactor, callback);
+ };
+
+ proto.getZoom = function(callback) {
+ return privates(this).internal.getZoom(callback);
};
proto.captureVisibleRegion = function(spec, callback) {
- this.internal_(secret).captureVisibleRegion_(spec, callback);
+ privates(this).internal.captureVisibleRegion(spec, callback);
};
};