Commit 99d84da5 authored by paulmeyer's avatar paulmeyer Committed by Commit bot

Refactored extensionOptions to use the new guestViewAttributes module.

BUG=466215

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

Cr-Commit-Position: refs/heads/master@{#322044}
parent b234648c
...@@ -9,6 +9,6 @@ namespace extensionoptions { ...@@ -9,6 +9,6 @@ namespace extensionoptions {
// API namespace. // API namespace.
extern const char kAPINamespace[] = "extensionOptionsInternal"; extern const char kAPINamespace[] = "extensionOptionsInternal";
const char kExtensionId[] = "extensionId"; const char kExtensionId[] = "extension";
} // namespace extensionoptions } // namespace extensionoptions
...@@ -478,6 +478,10 @@ std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() { ...@@ -478,6 +478,10 @@ std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() {
resources.push_back(std::make_pair(kEventBindings, IDR_EVENT_BINDINGS_JS)); resources.push_back(std::make_pair(kEventBindings, IDR_EVENT_BINDINGS_JS));
resources.push_back(std::make_pair("extensionOptions", resources.push_back(std::make_pair("extensionOptions",
IDR_EXTENSION_OPTIONS_JS)); IDR_EXTENSION_OPTIONS_JS));
resources.push_back(std::make_pair("extensionOptionsAttributes",
IDR_EXTENSION_OPTIONS_ATTRIBUTES_JS));
resources.push_back(std::make_pair("extensionOptionsConstants",
IDR_EXTENSION_OPTIONS_CONSTANTS_JS));
resources.push_back(std::make_pair("extensionOptionsEvents", resources.push_back(std::make_pair("extensionOptionsEvents",
IDR_EXTENSION_OPTIONS_EVENTS_JS)); IDR_EXTENSION_OPTIONS_EVENTS_JS));
resources.push_back(std::make_pair("extensionView", IDR_EXTENSION_VIEW_JS)); resources.push_back(std::make_pair("extensionView", IDR_EXTENSION_VIEW_JS));
...@@ -1409,6 +1413,7 @@ void Dispatcher::RequireGuestViewModules(ScriptContext* context) { ...@@ -1409,6 +1413,7 @@ void Dispatcher::RequireGuestViewModules(ScriptContext* context) {
// Require ExtensionOptions. // Require ExtensionOptions.
if (context->GetAvailability("extensionOptionsInternal").is_available()) { if (context->GetAvailability("extensionOptionsInternal").is_available()) {
module_system->Require("extensionOptions"); module_system->Require("extensionOptions");
module_system->Require("extensionOptionsAttributes");
} }
// Require ExtensionView. // Require ExtensionView.
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
<include name="IDR_ENTRY_ID_MANAGER" file="entry_id_manager.js" type="BINDATA" /> <include name="IDR_ENTRY_ID_MANAGER" file="entry_id_manager.js" type="BINDATA" />
<include name="IDR_EVENT_BINDINGS_JS" file="event.js" type="BINDATA" /> <include name="IDR_EVENT_BINDINGS_JS" file="event.js" type="BINDATA" />
<include name="IDR_EXTENSION_OPTIONS_JS" file="guest_view/extension_options/extension_options.js" type="BINDATA"/> <include name="IDR_EXTENSION_OPTIONS_JS" file="guest_view/extension_options/extension_options.js" type="BINDATA"/>
<include name="IDR_EXTENSION_OPTIONS_ATTRIBUTES_JS" file="guest_view/extension_options/extension_options_attributes.js" type="BINDATA"/>
<include name="IDR_EXTENSION_OPTIONS_CONSTANTS_JS" file="guest_view/extension_options/extension_options_constants.js" type="BINDATA"/>
<include name="IDR_EXTENSION_OPTIONS_EVENTS_JS" file="guest_view/extension_options/extension_options_events.js" type="BINDATA"/> <include name="IDR_EXTENSION_OPTIONS_EVENTS_JS" file="guest_view/extension_options/extension_options_events.js" type="BINDATA"/>
<include name="IDR_EXTENSION_VIEW_JS" file="guest_view/extension_view/extension_view.js" type="BINDATA" /> <include name="IDR_EXTENSION_VIEW_JS" file="guest_view/extension_view/extension_view.js" type="BINDATA" />
<include name="IDR_EXTENSION_VIEW_API_METHODS_JS" file="guest_view/extension_view/extension_view_api_methods.js" type="BINDATA" /> <include name="IDR_EXTENSION_VIEW_API_METHODS_JS" file="guest_view/extension_view/extension_view_api_methods.js" type="BINDATA" />
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
var DocumentNatives = requireNative('document_natives'); var DocumentNatives = requireNative('document_natives');
var GuestView = require('guestView').GuestView;
var GuestViewContainer = require('guestViewContainer').GuestViewContainer; var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
var IdGenerator = requireNative('id_generator'); var IdGenerator = requireNative('id_generator');
......
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var ExtensionOptionsConstants =
require('extensionOptionsConstants').ExtensionOptionsConstants;
var ExtensionOptionsEvents = var ExtensionOptionsEvents =
require('extensionOptionsEvents').ExtensionOptionsEvents; require('extensionOptionsEvents').ExtensionOptionsEvents;
var GuestView = require('guestView').GuestView;
var GuestViewContainer = require('guestViewContainer').GuestViewContainer; var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
function ExtensionOptionsImpl(extensionoptionsElement) { function ExtensionOptionsImpl(extensionoptionsElement) {
GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions'); GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions');
new ExtensionOptionsEvents(this); new ExtensionOptionsEvents(this);
this.setupElementProperties();
}; };
ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype; ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype;
...@@ -23,16 +23,14 @@ ExtensionOptionsImpl.prototype.onElementAttached = function() { ...@@ -23,16 +23,14 @@ ExtensionOptionsImpl.prototype.onElementAttached = function() {
} }
ExtensionOptionsImpl.prototype.buildContainerParams = function() { ExtensionOptionsImpl.prototype.buildContainerParams = function() {
return { var params = {};
'extensionId': this.element.getAttribute('extension') for (var i in this.attributes) {
}; params[i] = this.attributes[i].getValue();
}
return params;
}; };
ExtensionOptionsImpl.prototype.createGuest = function() { ExtensionOptionsImpl.prototype.createGuest = function() {
if (!this.elementAttached) {
return;
}
// Destroy the old guest if one exists. // Destroy the old guest if one exists.
this.guest.destroy(); this.guest.destroy();
...@@ -48,31 +46,7 @@ ExtensionOptionsImpl.prototype.createGuest = function() { ...@@ -48,31 +46,7 @@ ExtensionOptionsImpl.prototype.createGuest = function() {
}.bind(this)); }.bind(this));
}; };
ExtensionOptionsImpl.prototype.handleAttributeMutation =
function(name, oldValue, newValue) {
// We treat null attribute (attribute removed) and the empty string as
// one case.
oldValue = oldValue || '';
newValue = newValue || '';
if (oldValue === newValue)
return;
if (name == 'extension') {
this.createGuest();
}
};
ExtensionOptionsImpl.prototype.setupElementProperties = function() {
$Object.defineProperty(this.element, 'extension', {
get: function() {
return this.element.getAttribute('extension');
}.bind(this),
set: function(value) {
this.element.setAttribute('extension', value);
}.bind(this),
enumerable: true
});
};
GuestViewContainer.registerElement(ExtensionOptionsImpl); GuestViewContainer.registerElement(ExtensionOptionsImpl);
// Exports.
exports.ExtensionOptionsImpl = ExtensionOptionsImpl;
// Copyright 2015 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 <extensionoptions> tag.
var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes;
var ExtensionOptionsConstants =
require('extensionOptionsConstants').ExtensionOptionsConstants;
var ExtensionOptionsImpl = require('extensionOptions').ExtensionOptionsImpl;
// -----------------------------------------------------------------------------
// ExtensionAttribute object.
// Attribute that handles extension binded to the extensionoptions.
function ExtensionAttribute(view) {
GuestViewAttributes.Attribute.call(
this, ExtensionOptionsConstants.ATTRIBUTE_EXTENSION, view);
}
ExtensionAttribute.prototype.__proto__ =
GuestViewAttributes.Attribute.prototype;
ExtensionAttribute.prototype.handleMutation = function(oldValue, newValue) {
// Once this attribute has been set, it cannot be unset.
if (!newValue && oldValue) {
this.setValueIgnoreMutation(oldValue);
return;
}
if (!newValue || !this.elementAttached)
return;
this.view.createGuest();
};
// -----------------------------------------------------------------------------
// Sets up all of the extensionoptions attributes.
ExtensionOptionsImpl.prototype.setupAttributes = function() {
this.attributes[ExtensionOptionsConstants.ATTRIBUTE_EXTENSION] =
new ExtensionAttribute(this);
};
// Copyright 2015 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 extensionoptions.
// Container for the extensionview constants.
var ExtensionOptionsConstants = {
// Attributes.
ATTRIBUTE_EXTENSION: 'extension'
};
exports.ExtensionOptionsConstants = $Object.freeze(ExtensionOptionsConstants);
...@@ -13,7 +13,6 @@ var ExtensionViewInternal = ...@@ -13,7 +13,6 @@ var ExtensionViewInternal =
function ExtensionViewImpl(extensionviewElement) { function ExtensionViewImpl(extensionviewElement) {
GuestViewContainer.call(this, extensionviewElement, 'extensionview'); GuestViewContainer.call(this, extensionviewElement, 'extensionview');
this.setupExtensionViewAttributes();
new ExtensionViewEvents(this, this.viewInstanceId); new ExtensionViewEvents(this, this.viewInstanceId);
} }
...@@ -42,16 +41,6 @@ ExtensionViewImpl.prototype.buildContainerParams = function() { ...@@ -42,16 +41,6 @@ ExtensionViewImpl.prototype.buildContainerParams = function() {
return params; return params;
}; };
// This observer monitors mutations to attributes of the <extensionview>.
ExtensionViewImpl.prototype.handleAttributeMutation = function(
attributeName, oldValue, newValue) {
if (!this.attributes[attributeName])
return;
// Let the changed attribute handle its own mutation.
this.attributes[attributeName].maybeHandleMutation(oldValue, newValue);
};
ExtensionViewImpl.prototype.onElementDetached = function() { ExtensionViewImpl.prototype.onElementDetached = function() {
this.guest.destroy(); this.guest.destroy();
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
// This module implements the attributes of the <extensionview> tag. // This module implements the attributes of the <extensionview> tag.
var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes; var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes;
var ExtensionViewImpl = require('extensionView').ExtensionViewImpl;
var ExtensionViewConstants = var ExtensionViewConstants =
require('extensionViewConstants').ExtensionViewConstants; require('extensionViewConstants').ExtensionViewConstants;
var ExtensionViewImpl = require('extensionView').ExtensionViewImpl;
var ExtensionViewInternal = var ExtensionViewInternal =
require('extensionViewInternal').ExtensionViewInternal; require('extensionViewInternal').ExtensionViewInternal;
...@@ -54,8 +54,7 @@ SrcAttribute.prototype.parse = function() { ...@@ -54,8 +54,7 @@ SrcAttribute.prototype.parse = function() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Sets up all of the extensionview attributes. // Sets up all of the extensionview attributes.
ExtensionViewImpl.prototype.setupExtensionViewAttributes = function() { ExtensionViewImpl.prototype.setupAttributes = function() {
this.attributes = {};
this.attributes[ExtensionViewConstants.ATTRIBUTE_EXTENSION] = this.attributes[ExtensionViewConstants.ATTRIBUTE_EXTENSION] =
new ExtensionAttribute(this); new ExtensionAttribute(this);
this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC] = this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC] =
......
...@@ -12,6 +12,7 @@ var IdGenerator = requireNative('id_generator'); ...@@ -12,6 +12,7 @@ var IdGenerator = requireNative('id_generator');
function GuestViewContainer(element, viewType) { function GuestViewContainer(element, viewType) {
privates(element).internal = this; privates(element).internal = this;
this.attributes = {};
this.element = element; this.element = element;
this.elementAttached = false; this.elementAttached = false;
this.viewInstanceId = IdGenerator.GetNextId(); this.viewInstanceId = IdGenerator.GetNextId();
...@@ -19,10 +20,10 @@ function GuestViewContainer(element, viewType) { ...@@ -19,10 +20,10 @@ function GuestViewContainer(element, viewType) {
this.setupGuestProperty(); this.setupGuestProperty();
this.guest = new GuestView(viewType); this.guest = new GuestView(viewType);
this.setupAttributes();
privates(this).browserPluginElement = this.createBrowserPluginElement(); privates(this).browserPluginElement = this.createBrowserPluginElement();
this.setupFocusPropagation(); this.setupFocusPropagation();
var shadowRoot = this.element.createShadowRoot(); var shadowRoot = this.element.createShadowRoot();
shadowRoot.appendChild(privates(this).browserPluginElement); shadowRoot.appendChild(privates(this).browserPluginElement);
} }
...@@ -168,11 +169,9 @@ GuestViewContainer.prototype.dispatchEvent = function(event) { ...@@ -168,11 +169,9 @@ GuestViewContainer.prototype.dispatchEvent = function(event) {
// Implemented by the specific view type, if needed. // Implemented by the specific view type, if needed.
GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; GuestViewContainer.prototype.buildContainerParams = function() { return {}; };
// TODO(paulmeyer): remove once all view types use attribute objects.
GuestViewContainer.prototype.handleAttributeMutation = function(
attributeName, oldValue, newValue) {};
GuestViewContainer.prototype.onElementAttached = function() {}; GuestViewContainer.prototype.onElementAttached = function() {};
GuestViewContainer.prototype.onElementDetached = function() {}; GuestViewContainer.prototype.onElementDetached = function() {};
GuestViewContainer.prototype.setupAttributes = function() {};
// Registers the browser plugin <object> custom element. |viewType| is the // Registers the browser plugin <object> custom element. |viewType| is the
// name of the specific guestview container (e.g. 'webview'). // name of the specific guestview container (e.g. 'webview').
...@@ -230,10 +229,12 @@ function registerGuestViewElement(guestViewContainerType) { ...@@ -230,10 +229,12 @@ function registerGuestViewElement(guestViewContainerType) {
proto.attributeChangedCallback = function(name, oldValue, newValue) { proto.attributeChangedCallback = function(name, oldValue, newValue) {
var internal = privates(this).internal; var internal = privates(this).internal;
if (!internal) { if (!internal || !internal.attributes[name]) {
return; return;
} }
internal.handleAttributeMutation(name, oldValue, newValue);
// Let the changed attribute handle its own mutation.
internal.attributes[name].maybeHandleMutation(oldValue, newValue);
}; };
proto.detachedCallback = function() { proto.detachedCallback = function() {
......
...@@ -18,9 +18,7 @@ var WebViewInternal = require('webViewInternal').WebViewInternal; ...@@ -18,9 +18,7 @@ var WebViewInternal = require('webViewInternal').WebViewInternal;
function WebViewImpl(webviewElement) { function WebViewImpl(webviewElement) {
GuestViewContainer.call(this, webviewElement, 'webview'); GuestViewContainer.call(this, webviewElement, 'webview');
this.setupWebViewAttributes();
this.setupElementProperties(); this.setupElementProperties();
new WebViewEvents(this, this.viewInstanceId); new WebViewEvents(this, this.viewInstanceId);
} }
...@@ -98,17 +96,6 @@ WebViewImpl.prototype.setupElementProperties = function() { ...@@ -98,17 +96,6 @@ WebViewImpl.prototype.setupElementProperties = function() {
}); });
}; };
// This observer monitors mutations to attributes of the <webview>.
WebViewImpl.prototype.handleAttributeMutation = function(
attributeName, oldValue, newValue) {
if (!this.attributes[attributeName]) {
return;
}
// Let the changed attribute handle its own mutation;
this.attributes[attributeName].maybeHandleMutation(oldValue, newValue);
};
WebViewImpl.prototype.onSizeChanged = function(webViewEvent) { WebViewImpl.prototype.onSizeChanged = function(webViewEvent) {
var newWidth = webViewEvent.newWidth; var newWidth = webViewEvent.newWidth;
var newHeight = webViewEvent.newHeight; var newHeight = webViewEvent.newHeight;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
// This module implements the attributes of the <webview> tag. // This module implements the attributes of the <webview> tag.
var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes; var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes;
var WebViewImpl = require('webView').WebViewImpl;
var WebViewConstants = require('webViewConstants').WebViewConstants; var WebViewConstants = require('webViewConstants').WebViewConstants;
var WebViewImpl = require('webView').WebViewImpl;
var WebViewInternal = require('webViewInternal').WebViewInternal; var WebViewInternal = require('webViewInternal').WebViewInternal;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -252,9 +252,7 @@ SrcAttribute.prototype.parse = function() { ...@@ -252,9 +252,7 @@ SrcAttribute.prototype.parse = function() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Sets up all of the webview attributes. // Sets up all of the webview attributes.
WebViewImpl.prototype.setupWebViewAttributes = function() { WebViewImpl.prototype.setupAttributes = function() {
this.attributes = {};
this.attributes[WebViewConstants.ATTRIBUTE_ALLOWSCALING] = this.attributes[WebViewConstants.ATTRIBUTE_ALLOWSCALING] =
new AllowScalingAttribute(this); new AllowScalingAttribute(this);
this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] = this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
......
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