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

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

Issue 663483004: Webview attributes overhaul. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 6 years, 2 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/web_view_attributes.js
diff --git a/extensions/renderer/resources/guest_view/web_view_attributes.js b/extensions/renderer/resources/guest_view/web_view_attributes.js
new file mode 100644
index 0000000000000000000000000000000000000000..56f38740f5ed07244f3445ea9e367034919d6a4a
--- /dev/null
+++ b/extensions/renderer/resources/guest_view/web_view_attributes.js
@@ -0,0 +1,97 @@
+// 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 implements the attributes of the <webview> tag.
+
+var WebView = require('webView').WebView;
+var WebViewConstants = require('webViewConstants').WebViewConstants;
+
+// -----------------------------------------------------------------------------
+// Attribute objects.
+
+// Default implementation of a WebView attribute.
+function WebViewAttribute(name, webViewImpl) {
+ this.name = name;
+ this.value = '';
+ this.webViewImpl = webViewImpl;
+}
+
+WebViewAttribute.prototype.getValue = function() {
+ return this.value || '';
+};
+
+WebViewAttribute.prototype.setValue = function(value) {
+ this.value = value;
+};
+
+// Attribute representing the state of the storage partition.
+function Partition(webViewImpl) {
+ this.validPartitionId = true;
+ this.persistStorage = false;
+ this.storagePartitionId = '';
+ this.webViewImpl = webViewImpl;
+}
+
+Partition.prototype = new WebViewAttribute(
+ WebViewConstants.ATTRIBUTE_PARTITION);
+
+Partition.prototype.getValue = function() {
+ if (!this.validPartitionId) {
+ return '';
+ }
+ return (this.persistStorage ? 'persist:' : '') + this.storagePartitionId;
+};
+
+Partition.prototype.setValue = function(value) {
+ var result = {};
+ var hasNavigated = !this.webViewImpl.beforeFirstNavigation;
+ if (hasNavigated) {
+ result.error = WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED;
+ return result;
+ }
+ if (!value) {
+ value = '';
+ }
+
+ var LEN = 'persist:'.length;
+ if (value.substr(0, LEN) == 'persist:') {
+ value = value.substr(LEN);
+ if (!value) {
+ this.validPartitionId = false;
+ result.error = WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE;
+ return result;
+ }
+ this.persistStorage = true;
+ } else {
+ this.persistStorage = false;
+ }
+
+ this.storagePartitionId = value;
+ return result;
+};
+
+// -----------------------------------------------------------------------------
+
+// Sets up all of the webview attributes.
+WebView.prototype.setupWebViewAttributes = function() {
+ this.attributes = {};
+
+ // Initialize the attributes with special behavior (and custom attribute
+ // objects).
+ this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this);
+
+ // Initialize the remaining attributes, which have default behavior.
+ var defaultAttributes = [WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY,
+ WebViewConstants.ATTRIBUTE_AUTOSIZE,
+ WebViewConstants.ATTRIBUTE_MAXHEIGHT,
+ WebViewConstants.ATTRIBUTE_MAXWIDTH,
+ WebViewConstants.ATTRIBUTE_MINHEIGHT,
+ WebViewConstants.ATTRIBUTE_MINWIDTH,
+ WebViewConstants.ATTRIBUTE_NAME,
+ WebViewConstants.ATTRIBUTE_SRC];
+ for (var i = 0; defaultAttributes[i]; ++i) {
+ this.attributes[defaultAttributes[i]] =
+ new WebViewAttribute(defaultAttributes[i], this);
+ }
+};
« no previous file with comments | « extensions/renderer/resources/guest_view/web_view.js ('k') | extensions/renderer/resources/guest_view/web_view_constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698