Commit ccbfe27c authored by paulmeyer's avatar paulmeyer Committed by Commit bot

Moved constants out of web_view.js and into a new file, web_view_constants.js,...

Moved constants out of web_view.js and into a new file, web_view_constants.js, so that the constants can be shared by multiple webview files.

Review URL: https://codereview.chromium.org/661743005

Cr-Commit-Position: refs/heads/master@{#300547}
parent 48c7b1fa
...@@ -334,6 +334,7 @@ void Dispatcher::DidCreateScriptContext( ...@@ -334,6 +334,7 @@ void Dispatcher::DidCreateScriptContext(
// The API will be automatically set up when first used. // The API will be automatically set up when first used.
if (context->GetAvailability("webViewInternal").is_available()) { if (context->GetAvailability("webViewInternal").is_available()) {
module_system->Require("webView"); module_system->Require("webView");
module_system->Require("webViewConstants");
if (context->GetAvailability("webViewExperimentalInternal") if (context->GetAvailability("webViewExperimentalInternal")
.is_available()) { .is_available()) {
module_system->Require("webViewExperimental"); module_system->Require("webViewExperimental");
...@@ -548,6 +549,8 @@ std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() { ...@@ -548,6 +549,8 @@ std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() {
// Note: webView not webview so that this doesn't interfere with the // Note: webView not webview so that this doesn't interfere with the
// chrome.webview API bindings. // chrome.webview API bindings.
resources.push_back(std::make_pair("webView", IDR_WEB_VIEW_JS)); resources.push_back(std::make_pair("webView", IDR_WEB_VIEW_JS));
resources.push_back(std::make_pair("webViewConstants",
IDR_WEB_VIEW_CONSTANTS_JS));
resources.push_back(std::make_pair("webViewEvents", IDR_WEB_VIEW_EVENTS_JS)); resources.push_back(std::make_pair("webViewEvents", IDR_WEB_VIEW_EVENTS_JS));
resources.push_back( resources.push_back(
std::make_pair("webViewExperimental", IDR_WEB_VIEW_EXPERIMENTAL_JS)); std::make_pair("webViewExperimental", IDR_WEB_VIEW_EXPERIMENTAL_JS));
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
<include name="IDR_UNCAUGHT_EXCEPTION_HANDLER_JS" file="uncaught_exception_handler.js" type="BINDATA" /> <include name="IDR_UNCAUGHT_EXCEPTION_HANDLER_JS" file="uncaught_exception_handler.js" type="BINDATA" />
<include name="IDR_UNLOAD_EVENT_JS" file="unload_event.js" type="BINDATA" /> <include name="IDR_UNLOAD_EVENT_JS" file="unload_event.js" type="BINDATA" />
<include name="IDR_UTILS_JS" file="utils.js" type="BINDATA" /> <include name="IDR_UTILS_JS" file="utils.js" type="BINDATA" />
<include name="IDR_WEB_VIEW_CONSTANTS_JS" file="guest_view/web_view_constants.js" type="BINDATA" />
<include name="IDR_WEB_VIEW_DENY_JS" file="guest_view/web_view_deny.js" type="BINDATA" /> <include name="IDR_WEB_VIEW_DENY_JS" file="guest_view/web_view_deny.js" type="BINDATA" />
<include name="IDR_WEB_VIEW_EVENTS_JS" file="guest_view/web_view_events.js" type="BINDATA" /> <include name="IDR_WEB_VIEW_EVENTS_JS" file="guest_view/web_view_events.js" type="BINDATA" />
<include name="IDR_WEB_VIEW_EXPERIMENTAL_JS" file="guest_view/web_view_experimental.js" type="BINDATA" /> <include name="IDR_WEB_VIEW_EXPERIMENTAL_JS" file="guest_view/web_view_experimental.js" type="BINDATA" />
......
...@@ -11,35 +11,18 @@ var GuestViewInternal = ...@@ -11,35 +11,18 @@ var GuestViewInternal =
require('binding').Binding.create('guestViewInternal').generate(); require('binding').Binding.create('guestViewInternal').generate();
var guestViewInternalNatives = requireNative('guest_view_internal'); var guestViewInternalNatives = requireNative('guest_view_internal');
var IdGenerator = requireNative('id_generator'); var IdGenerator = requireNative('id_generator');
var WebViewConstants = require('webViewConstants').WebViewConstants;
var WebViewEvents = require('webViewEvents').WebViewEvents; var WebViewEvents = require('webViewEvents').WebViewEvents;
var WebViewInternal = require('webViewInternal').WebViewInternal; var WebViewInternal = require('webViewInternal').WebViewInternal;
// Attributes.
var WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY = 'allowtransparency';
var WEB_VIEW_ATTRIBUTE_AUTOSIZE = 'autosize';
var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight';
var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth';
var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight';
var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition';
var AUTO_SIZE_ATTRIBUTES = [ var AUTO_SIZE_ATTRIBUTES = [
WEB_VIEW_ATTRIBUTE_AUTOSIZE, WebViewConstants.ATTRIBUTE_AUTOSIZE,
WEB_VIEW_ATTRIBUTE_MAXHEIGHT, WebViewConstants.ATTRIBUTE_MAXHEIGHT,
WEB_VIEW_ATTRIBUTE_MAXWIDTH, WebViewConstants.ATTRIBUTE_MAXWIDTH,
WEB_VIEW_ATTRIBUTE_MINHEIGHT, WebViewConstants.ATTRIBUTE_MINHEIGHT,
WEB_VIEW_ATTRIBUTE_MINWIDTH WebViewConstants.ATTRIBUTE_MINWIDTH
]; ];
// Error messages.
var ERROR_MSG_ALREADY_NAVIGATED =
'The object has already navigated, so its partition cannot be changed.';
var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' +
'Script cannot be injected into content until the page has loaded.';
var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' +
'contentWindow is not available at this time. It will become available ' +
'when the page has finished loading.';
var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.';
// Represents the state of the storage partition. // Represents the state of the storage partition.
function Partition() { function Partition() {
this.validPartitionId = true; this.validPartitionId = true;
...@@ -57,7 +40,7 @@ Partition.prototype.toAttribute = function() { ...@@ -57,7 +40,7 @@ Partition.prototype.toAttribute = function() {
Partition.prototype.fromAttribute = function(value, hasNavigated) { Partition.prototype.fromAttribute = function(value, hasNavigated) {
var result = {}; var result = {};
if (hasNavigated) { if (hasNavigated) {
result.error = ERROR_MSG_ALREADY_NAVIGATED; result.error = WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED;
return result; return result;
} }
if (!value) { if (!value) {
...@@ -69,7 +52,7 @@ Partition.prototype.fromAttribute = function(value, hasNavigated) { ...@@ -69,7 +52,7 @@ Partition.prototype.fromAttribute = function(value, hasNavigated) {
value = value.substr(LEN); value = value.substr(LEN);
if (!value) { if (!value) {
this.validPartitionId = false; this.validPartitionId = false;
result.error = ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; result.error = WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE;
return result; return result;
} }
this.persistStorage = true; this.persistStorage = true;
...@@ -180,7 +163,7 @@ WebView.prototype.setupFocusPropagation = function() { ...@@ -180,7 +163,7 @@ WebView.prototype.setupFocusPropagation = function() {
// Validation helper function for executeScript() and insertCSS(). // Validation helper function for executeScript() and insertCSS().
WebView.prototype.validateExecuteCodeCall = function() { WebView.prototype.validateExecuteCodeCall = function() {
if (!this.guestInstanceId) { if (!this.guestInstanceId) {
throw new Error(ERROR_MSG_CANNOT_INJECT_SCRIPT); throw new Error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT);
} }
}; };
...@@ -203,13 +186,14 @@ WebView.prototype.setupWebviewNodeProperties = function() { ...@@ -203,13 +186,14 @@ WebView.prototype.setupWebviewNodeProperties = function() {
this.setupAutoSizeProperties(); this.setupAutoSizeProperties();
Object.defineProperty(this.webviewNode, Object.defineProperty(this.webviewNode,
WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY, { WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, {
get: function() { get: function() {
return this.allowtransparency; return this.allowtransparency;
}.bind(this), }.bind(this),
set: function(value) { set: function(value) {
this.webviewNode.setAttribute(WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY, this.webviewNode.setAttribute(
value); WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY,
value);
}.bind(this), }.bind(this),
enumerable: true enumerable: true
}); });
...@@ -221,7 +205,8 @@ WebView.prototype.setupWebviewNodeProperties = function() { ...@@ -221,7 +205,8 @@ WebView.prototype.setupWebviewNodeProperties = function() {
if (this.contentWindow) { if (this.contentWindow) {
return this.contentWindow; return this.contentWindow;
} }
window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); window.console.error(
WebViewConstants.ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE);
}.bind(this), }.bind(this),
// No setter. // No setter.
enumerable: true enumerable: true
...@@ -302,7 +287,8 @@ WebView.prototype.handleWebviewAttributeMutation = ...@@ -302,7 +287,8 @@ WebView.prototype.handleWebviewAttributeMutation =
return; return;
} }
// Convert autosize attribute to boolean. // Convert autosize attribute to boolean.
var autosize = this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE); var autosize = this.webviewNode.hasAttribute(
WebViewConstants.ATTRIBUTE_AUTOSIZE);
GuestViewInternal.setAutoSize(this.guestInstanceId, { GuestViewInternal.setAutoSize(this.guestInstanceId, {
'enableAutoSize': autosize, 'enableAutoSize': autosize,
'min': { 'min': {
...@@ -315,7 +301,7 @@ WebView.prototype.handleWebviewAttributeMutation = ...@@ -315,7 +301,7 @@ WebView.prototype.handleWebviewAttributeMutation =
} }
}); });
return; return;
} else if (name == WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY) { } else if (name == WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY) {
// We treat null attribute (attribute removed) and the empty string as // We treat null attribute (attribute removed) and the empty string as
// one case. // one case.
oldValue = oldValue || ''; oldValue = oldValue || '';
...@@ -419,17 +405,17 @@ WebView.prototype.onSizeChanged = function(webViewEvent) { ...@@ -419,17 +405,17 @@ WebView.prototype.onSizeChanged = function(webViewEvent) {
// Check the current bounds to make sure we do not resize <webview> // Check the current bounds to make sure we do not resize <webview>
// outside of current constraints. // outside of current constraints.
var maxWidth; var maxWidth;
if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXWIDTH) && if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MAXWIDTH) &&
node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]) { node[WebViewConstants.ATTRIBUTE_MAXWIDTH]) {
maxWidth = node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]; maxWidth = node[WebViewConstants.ATTRIBUTE_MAXWIDTH];
} else { } else {
maxWidth = width; maxWidth = width;
} }
var minWidth; var minWidth;
if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINWIDTH) && if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MINWIDTH) &&
node[WEB_VIEW_ATTRIBUTE_MINWIDTH]) { node[WebViewConstants.ATTRIBUTE_MINWIDTH]) {
minWidth = node[WEB_VIEW_ATTRIBUTE_MINWIDTH]; minWidth = node[WebViewConstants.ATTRIBUTE_MINWIDTH];
} else { } else {
minWidth = width; minWidth = width;
} }
...@@ -438,17 +424,17 @@ WebView.prototype.onSizeChanged = function(webViewEvent) { ...@@ -438,17 +424,17 @@ WebView.prototype.onSizeChanged = function(webViewEvent) {
} }
var maxHeight; var maxHeight;
if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXHEIGHT) && if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MAXHEIGHT) &&
node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]) { node[WebViewConstants.ATTRIBUTE_MAXHEIGHT]) {
maxHeight = node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]; maxHeight = node[WebViewConstants.ATTRIBUTE_MAXHEIGHT];
} else { } else {
maxHeight = height; maxHeight = height;
} }
var minHeight; var minHeight;
if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINHEIGHT) && if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MINHEIGHT) &&
node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]) { node[WebViewConstants.ATTRIBUTE_MINHEIGHT]) {
minHeight = node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]; minHeight = node[WebViewConstants.ATTRIBUTE_MINHEIGHT];
} else { } else {
minHeight = height; minHeight = height;
} }
...@@ -456,7 +442,7 @@ WebView.prototype.onSizeChanged = function(webViewEvent) { ...@@ -456,7 +442,7 @@ WebView.prototype.onSizeChanged = function(webViewEvent) {
minHeight = maxHeight; minHeight = maxHeight;
} }
if (!this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE) || if (!this.webviewNode.hasAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE) ||
(newWidth >= minWidth && (newWidth >= minWidth &&
newWidth <= maxWidth && newWidth <= maxWidth &&
newHeight >= minHeight && newHeight >= minHeight &&
...@@ -480,7 +466,7 @@ WebView.prototype.hasNavigated = function() { ...@@ -480,7 +466,7 @@ WebView.prototype.hasNavigated = function() {
WebView.prototype.parseSrcAttribute = function(result) { WebView.prototype.parseSrcAttribute = function(result) {
if (!this.partition.validPartitionId) { if (!this.partition.validPartitionId) {
result.error = ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; result.error = WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE;
return; return;
} }
this.src = this.webviewNode.getAttribute('src'); this.src = this.webviewNode.getAttribute('src');
...@@ -516,8 +502,8 @@ WebView.prototype.createGuest = function() { ...@@ -516,8 +502,8 @@ WebView.prototype.createGuest = function() {
return; return;
} }
var storagePartitionId = var storagePartitionId =
this.webviewNode.getAttribute(WEB_VIEW_ATTRIBUTE_PARTITION) || this.webviewNode.getAttribute(WebViewConstants.ATTRIBUTE_PARTITION) ||
this.webviewNode[WEB_VIEW_ATTRIBUTE_PARTITION]; this.webviewNode[WebViewConstants.ATTRIBUTE_PARTITION];
var params = { var params = {
'storagePartitionId': storagePartitionId 'storagePartitionId': storagePartitionId
}; };
...@@ -595,7 +581,8 @@ WebView.prototype.onAttach = function(storagePartitionId) { ...@@ -595,7 +581,8 @@ WebView.prototype.onAttach = function(storagePartitionId) {
WebView.prototype.buildAttachParams = function(isNewWindow) { WebView.prototype.buildAttachParams = function(isNewWindow) {
var params = { var params = {
'allowtransparency': this.allowtransparency || false, 'allowtransparency': this.allowtransparency || false,
'autosize': this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE), 'autosize': this.webviewNode.hasAttribute(
WebViewConstants.ATTRIBUTE_AUTOSIZE),
'instanceId': this.viewInstanceId, 'instanceId': this.viewInstanceId,
'maxheight': parseInt(this.maxheight || 0), 'maxheight': parseInt(this.maxheight || 0),
'maxwidth': parseInt(this.maxwidth || 0), 'maxwidth': parseInt(this.maxwidth || 0),
......
// Copyright (c) 2014 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.
// This module contains constants used in webview.
// Container for the webview constants.
var WebViewConstants = {
// Attributes.
ATTRIBUTE_ALLOWTRANSPARENCY: 'allowtransparency',
ATTRIBUTE_AUTOSIZE: 'autosize',
ATTRIBUTE_MAXHEIGHT: 'maxheight',
ATTRIBUTE_MAXWIDTH: 'maxwidth',
ATTRIBUTE_MINHEIGHT: 'minheight',
ATTRIBUTE_MINWIDTH: 'minwidth',
ATTRIBUTE_PARTITION: 'partition',
// Error messages.
ERROR_MSG_ALREADY_NAVIGATED:
'The object has already navigated, so its partition cannot be changed.',
ERROR_MSG_CANNOT_INJECT_SCRIPT: '<webview>: ' +
'Script cannot be injected into content until the page has loaded.',
ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE: '<webview>: ' +
'contentWindow is not available at this time. It will become available ' +
'when the page has finished loading.',
ERROR_MSG_INVALID_PARTITION_ATTRIBUTE: 'Invalid partition attribute.'
};
exports.WebViewConstants = WebViewConstants;
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