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 {
// API namespace.
extern const char kAPINamespace[] = "extensionOptionsInternal";
const char kExtensionId[] = "extensionId";
const char kExtensionId[] = "extension";
} // namespace extensionoptions
......@@ -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("extensionOptions",
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",
IDR_EXTENSION_OPTIONS_EVENTS_JS));
resources.push_back(std::make_pair("extensionView", IDR_EXTENSION_VIEW_JS));
......@@ -1409,6 +1413,7 @@ void Dispatcher::RequireGuestViewModules(ScriptContext* context) {
// Require ExtensionOptions.
if (context->GetAvailability("extensionOptionsInternal").is_available()) {
module_system->Require("extensionOptions");
module_system->Require("extensionOptionsAttributes");
}
// Require ExtensionView.
......
......@@ -19,6 +19,8 @@
<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_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_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" />
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
var DocumentNatives = requireNative('document_natives');
var GuestView = require('guestView').GuestView;
var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
var IdGenerator = requireNative('id_generator');
......
......@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var ExtensionOptionsConstants =
require('extensionOptionsConstants').ExtensionOptionsConstants;
var ExtensionOptionsEvents =
require('extensionOptionsEvents').ExtensionOptionsEvents;
var GuestView = require('guestView').GuestView;
var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
function ExtensionOptionsImpl(extensionoptionsElement) {
GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions');
new ExtensionOptionsEvents(this);
this.setupElementProperties();
};
ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype;
......@@ -23,16 +23,14 @@ ExtensionOptionsImpl.prototype.onElementAttached = function() {
}
ExtensionOptionsImpl.prototype.buildContainerParams = function() {
return {
'extensionId': this.element.getAttribute('extension')
};
var params = {};
for (var i in this.attributes) {
params[i] = this.attributes[i].getValue();
}
return params;
};
ExtensionOptionsImpl.prototype.createGuest = function() {
if (!this.elementAttached) {
return;
}
// Destroy the old guest if one exists.
this.guest.destroy();
......@@ -48,31 +46,7 @@ ExtensionOptionsImpl.prototype.createGuest = function() {
}.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);
// 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 =
function ExtensionViewImpl(extensionviewElement) {
GuestViewContainer.call(this, extensionviewElement, 'extensionview');
this.setupExtensionViewAttributes();
new ExtensionViewEvents(this, this.viewInstanceId);
}
......@@ -42,16 +41,6 @@ ExtensionViewImpl.prototype.buildContainerParams = function() {
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() {
this.guest.destroy();
......
......@@ -5,9 +5,9 @@
// This module implements the attributes of the <extensionview> tag.
var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes;
var ExtensionViewImpl = require('extensionView').ExtensionViewImpl;
var ExtensionViewConstants =
require('extensionViewConstants').ExtensionViewConstants;
var ExtensionViewImpl = require('extensionView').ExtensionViewImpl;
var ExtensionViewInternal =
require('extensionViewInternal').ExtensionViewInternal;
......@@ -54,8 +54,7 @@ SrcAttribute.prototype.parse = function() {
// -----------------------------------------------------------------------------
// Sets up all of the extensionview attributes.
ExtensionViewImpl.prototype.setupExtensionViewAttributes = function() {
this.attributes = {};
ExtensionViewImpl.prototype.setupAttributes = function() {
this.attributes[ExtensionViewConstants.ATTRIBUTE_EXTENSION] =
new ExtensionAttribute(this);
this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC] =
......
......@@ -12,6 +12,7 @@ var IdGenerator = requireNative('id_generator');
function GuestViewContainer(element, viewType) {
privates(element).internal = this;
this.attributes = {};
this.element = element;
this.elementAttached = false;
this.viewInstanceId = IdGenerator.GetNextId();
......@@ -19,10 +20,10 @@ function GuestViewContainer(element, viewType) {
this.setupGuestProperty();
this.guest = new GuestView(viewType);
this.setupAttributes();
privates(this).browserPluginElement = this.createBrowserPluginElement();
this.setupFocusPropagation();
var shadowRoot = this.element.createShadowRoot();
shadowRoot.appendChild(privates(this).browserPluginElement);
}
......@@ -168,11 +169,9 @@ GuestViewContainer.prototype.dispatchEvent = function(event) {
// Implemented by the specific view type, if needed.
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.onElementDetached = function() {};
GuestViewContainer.prototype.setupAttributes = function() {};
// Registers the browser plugin <object> custom element. |viewType| is the
// name of the specific guestview container (e.g. 'webview').
......@@ -230,10 +229,12 @@ function registerGuestViewElement(guestViewContainerType) {
proto.attributeChangedCallback = function(name, oldValue, newValue) {
var internal = privates(this).internal;
if (!internal) {
if (!internal || !internal.attributes[name]) {
return;
}
internal.handleAttributeMutation(name, oldValue, newValue);
// Let the changed attribute handle its own mutation.
internal.attributes[name].maybeHandleMutation(oldValue, newValue);
};
proto.detachedCallback = function() {
......
......@@ -18,9 +18,7 @@ var WebViewInternal = require('webViewInternal').WebViewInternal;
function WebViewImpl(webviewElement) {
GuestViewContainer.call(this, webviewElement, 'webview');
this.setupWebViewAttributes();
this.setupElementProperties();
new WebViewEvents(this, this.viewInstanceId);
}
......@@ -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) {
var newWidth = webViewEvent.newWidth;
var newHeight = webViewEvent.newHeight;
......
......@@ -5,8 +5,8 @@
// This module implements the attributes of the <webview> tag.
var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes;
var WebViewImpl = require('webView').WebViewImpl;
var WebViewConstants = require('webViewConstants').WebViewConstants;
var WebViewImpl = require('webView').WebViewImpl;
var WebViewInternal = require('webViewInternal').WebViewInternal;
// -----------------------------------------------------------------------------
......@@ -252,9 +252,7 @@ SrcAttribute.prototype.parse = function() {
// -----------------------------------------------------------------------------
// Sets up all of the webview attributes.
WebViewImpl.prototype.setupWebViewAttributes = function() {
this.attributes = {};
WebViewImpl.prototype.setupAttributes = function() {
this.attributes[WebViewConstants.ATTRIBUTE_ALLOWSCALING] =
new AllowScalingAttribute(this);
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