Commit a15eb3b6 authored by fsamuel's avatar fsamuel Committed by Commit bot

<extensionoptions>: Remove dead code

autosize is no longer used in <extensionoptions> and it adds a lot of complexity.

I eventually want <extensionview> and <extensionoptions> to merge to reduce maintenance
overhead, especially on the <webview>/GuestView team. This dead code makes it harder to reach that objective.

BUG=442033

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

Cr-Commit-Position: refs/heads/master@{#319692}
parent 20f07ace
......@@ -2,24 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var DocumentNatives = requireNative('document_natives');
var ExtensionOptionsEvents =
require('extensionOptionsEvents').ExtensionOptionsEvents;
var GuestView = require('guestView').GuestView;
var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
var GuestViewInternal =
require('binding').Binding.create('guestViewInternal').generate();
var IdGenerator = requireNative('id_generator');
var utils = require('utils');
// Mapping of the autosize attribute names to default values
var AUTO_SIZE_ATTRIBUTES = {
'autosize': 'on',
'maxheight': window.innerHeight,
'maxwidth': window.innerWidth,
'minheight': 32,
'minwidth': 32
};
function ExtensionOptionsImpl(extensionoptionsElement) {
GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions');
......@@ -33,31 +19,14 @@ ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype;
ExtensionOptionsImpl.VIEW_TYPE = 'ExtensionOptions';
// Add extra functionality to |this.element|.
ExtensionOptionsImpl.setupElement = function(proto) {
var apiMethods = [
'setDeferAutoSize',
'resumeDeferredAutoSize'
];
// Forward proto.foo* method calls to ExtensionOptionsImpl.foo*.
GuestViewContainer.forwardApiMethods(proto, apiMethods);
}
ExtensionOptionsImpl.prototype.onElementAttached = function() {
this.createGuest();
}
ExtensionOptionsImpl.prototype.buildContainerParams = function() {
var params = {
'autosize': this.element.hasAttribute('autosize'),
'maxheight': parseInt(this.maxheight || 0),
'maxwidth': parseInt(this.maxwidth || 0),
'minheight': parseInt(this.minheight || 0),
'minwidth': parseInt(this.minwidth || 0),
return {
'extensionId': this.element.getAttribute('extension')
};
return params;
};
ExtensionOptionsImpl.prototype.createGuest = function() {
......@@ -92,92 +61,11 @@ ExtensionOptionsImpl.prototype.handleAttributeMutation =
if (name == 'extension') {
this.createGuest();
} else if (AUTO_SIZE_ATTRIBUTES.hasOwnProperty(name) > -1) {
this[name] = newValue;
this.resetSizeConstraintsIfInvalid();
if (!this.guest.getId())
return;
this.guest.setSize({
'enableAutoSize': this.element.hasAttribute('autosize'),
'min': {
'width': parseInt(this.minwidth || 0),
'height': parseInt(this.minheight || 0)
},
'max': {
'width': parseInt(this.maxwidth || 0),
'height': parseInt(this.maxheight || 0)
}
});
}
};
ExtensionOptionsImpl.prototype.onSizeChanged =
function(newWidth, newHeight, oldWidth, oldHeight) {
if (this.autosizeDeferred) {
this.deferredAutoSizeState = {
newWidth: newWidth,
newHeight: newHeight,
oldWidth: oldWidth,
oldHeight: oldHeight
};
} else {
this.resize(newWidth, newHeight, oldWidth, oldHeight);
}
};
ExtensionOptionsImpl.prototype.resize =
function(newWidth, newHeight, oldWidth, oldHeight) {
this.element.style.width = newWidth + 'px';
this.element.style.height = newHeight + 'px';
// Do not allow the options page's dimensions to shrink. This ensures that the
// options page has a consistent UI. If the new size is larger than the
// minimum, make that the new minimum size.
if (newWidth > this.minwidth)
this.minwidth = newWidth;
if (newHeight > this.minheight)
this.minheight = newHeight;
this.guest.setSize({
'enableAutoSize': this.element.hasAttribute('autosize'),
'min': {
'width': parseInt(this.minwidth || 0),
'height': parseInt(this.minheight || 0)
},
'max': {
'width': parseInt(this.maxwidth || 0),
'height': parseInt(this.maxheight || 0)
}
});
};
ExtensionOptionsImpl.prototype.setupElementProperties = function() {
utils.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) {
// Get the size constraints from the <extensionoptions> tag, or use the
// defaults if not specified
if (this.element.hasAttribute(attributeName)) {
this[attributeName] =
this.element.getAttribute(attributeName);
} else {
this[attributeName] = AUTO_SIZE_ATTRIBUTES[attributeName];
}
Object.defineProperty(this.element, attributeName, {
get: function() {
return this[attributeName];
}.bind(this),
set: function(value) {
this.element.setAttribute(attributeName, value);
}.bind(this),
enumerable: true
});
}, this);
this.resetSizeConstraintsIfInvalid();
Object.defineProperty(this.element, 'extension', {
$Object.defineProperty(this.element, 'extension', {
get: function() {
return this.element.getAttribute('extension');
}.bind(this),
......@@ -188,43 +76,4 @@ ExtensionOptionsImpl.prototype.setupElementProperties = function() {
});
};
ExtensionOptionsImpl.prototype.resetSizeConstraintsIfInvalid = function () {
if (this.minheight > this.maxheight || this.minheight < 0) {
this.minheight = AUTO_SIZE_ATTRIBUTES.minheight;
this.maxheight = AUTO_SIZE_ATTRIBUTES.maxheight;
}
if (this.minwidth > this.maxwidth || this.minwidth < 0) {
this.minwidth = AUTO_SIZE_ATTRIBUTES.minwidth;
this.maxwidth = AUTO_SIZE_ATTRIBUTES.maxwidth;
}
};
/**
* Toggles whether the element should automatically resize to its preferred
* size. If set to true, when the element receives new autosize dimensions,
* it passes them to the embedder in a sizechanged event, but does not resize
* itself to those dimensions until the embedder calls resumeDeferredAutoSize.
* This allows the embedder to defer the resizing until it is ready.
* When set to false, the element resizes whenever it receives new autosize
* dimensions.
*/
ExtensionOptionsImpl.prototype.setDeferAutoSize = function(value) {
if (!value)
resumeDeferredAutoSize();
this.autosizeDeferred = value;
};
/**
* Allows the element to resize to most recent set of autosize dimensions if
* autosizing is being deferred.
*/
ExtensionOptionsImpl.prototype.resumeDeferredAutoSize = function() {
if (this.autosizeDeferred) {
this.resize(this.deferredAutoSizeState.newWidth,
this.deferredAutoSizeState.newHeight,
this.deferredAutoSizeState.oldWidth,
this.deferredAutoSizeState.oldHeight);
}
};
GuestViewContainer.registerElement(ExtensionOptionsImpl);
......@@ -26,11 +26,6 @@ ExtensionOptionsEvents.EVENTS = {
'load': {
evt: CreateEvent('extensionOptionsInternal.onLoad')
},
'sizechanged': {
evt: CreateEvent('extensionOptionsInternal.onSizeChanged'),
handler: 'handleSizeChangedEvent',
fields:['newWidth', 'newHeight', 'oldWidth', 'oldHeight']
},
'preferredsizechanged': {
evt: CreateEvent('extensionOptionsInternal.onPreferredSizeChanged'),
fields:['width', 'height']
......@@ -41,13 +36,5 @@ ExtensionOptionsEvents.prototype.getEvents = function() {
return ExtensionOptionsEvents.EVENTS;
};
ExtensionOptionsEvents.prototype.handleSizeChangedEvent = function(event,
eventName) {
this.view.onSizeChanged(
event.newWidth, event.newHeight, event.oldWidth, event.oldHeight);
var extensionOptionsEvent = this.makeDomEvent(event, eventName);
this.view.dispatchEvent(extensionOptionsEvent);
}
// Exports.
exports.ExtensionOptionsEvents = ExtensionOptionsEvents;
......@@ -122,32 +122,6 @@ chrome.test.runTests([
document.body.appendChild(extensionoptions);
},
function autosizedGuestIsWithinSizeConstraints() {
var done = chrome.test.callbackAdded();
var extensionoptions = new ExtensionOptions();
extensionoptions.extension = chrome.runtime.id;
extensionoptions.autosize = 'on';
extensionoptions.minheight = 499;
extensionoptions.minwidth = 499;
extensionoptions.maxheight = 501;
extensionoptions.maxwidth = 501;
extensionoptions.onsizechanged = function(evt) {
try {
chrome.test.assertTrue(evt.newWidth >= 499);
chrome.test.assertTrue(evt.newHeight >= 499);
chrome.test.assertTrue(evt.newWidth <= 501);
chrome.test.assertTrue(evt.newHeight <= 501);
done();
} finally {
document.body.removeChild(extensionoptions);
}
};
document.body.appendChild(extensionoptions);
},
function externalLinksOpenInNewTab() {
var done = chrome.test.listenForever(chrome.runtime.onMessage,
function(message, sender, sendResponse) {
......
......@@ -139,23 +139,6 @@ int ExtensionOptionsGuest::GetTaskPrefix() const {
return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX;
}
void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize(
const gfx::Size& old_size,
const gfx::Size& new_size) {
extension_options_internal::SizeChangedOptions options;
options.old_width = old_size.width();
options.old_height = old_size.height();
options.new_width = new_size.width();
options.new_height = new_size.height();
DispatchEventToView(new GuestViewBase::Event(
extension_options_internal::OnSizeChanged::kEventName,
options.ToValue()));
}
bool ExtensionOptionsGuest::IsAutoSizeSupported() const {
return true;
}
bool ExtensionOptionsGuest::IsPreferredSizeModeEnabled() const {
return true;
}
......
......@@ -33,9 +33,6 @@ class ExtensionOptionsGuest
void DidStopLoading() override;
const char* GetAPINamespace() const override;
int GetTaskPrefix() const override;
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
const gfx::Size& new_size) override;
bool IsAutoSizeSupported() const override;
bool IsPreferredSizeModeEnabled() const override;
void OnPreferredSizeChanged(const gfx::Size& pref_size) override;
......
......@@ -19,7 +19,6 @@ namespace extensionOptionsInternal {
interface Events {
static void onClose();
static void onLoad();
static void onSizeChanged(SizeChangedOptions options);
static void onPreferredSizeChanged(PreferredSizeChangedOptions options);
};
};
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