Commit ce954eec authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions Page] Add a listener on extension list for "hasExtensions" changing

Add a listener on the ExtensionList object for when the count of extensions
moves from 0 to 1, or from 1 to 0 - i.e., when we should show or hide the
list.

BUG=480110

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

Cr-Commit-Position: refs/heads/master@{#327201}
parent 44e22fa2
...@@ -226,12 +226,10 @@ void DeveloperPrivateEventRouter::OnExtensionUnloaded( ...@@ -226,12 +226,10 @@ void DeveloperPrivateEventRouter::OnExtensionUnloaded(
BroadcastItemStateChanged(developer::EVENT_TYPE_UNLOADED, extension->id()); BroadcastItemStateChanged(developer::EVENT_TYPE_UNLOADED, extension->id());
} }
void DeveloperPrivateEventRouter::OnExtensionWillBeInstalled( void DeveloperPrivateEventRouter::OnExtensionInstalled(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
bool is_update, bool is_update) {
bool from_ephemeral,
const std::string& old_name) {
DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context))); DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context)));
BroadcastItemStateChanged(developer::EVENT_TYPE_INSTALLED, extension->id()); BroadcastItemStateChanged(developer::EVENT_TYPE_INSTALLED, extension->id());
} }
......
...@@ -68,11 +68,9 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver, ...@@ -68,11 +68,9 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver,
void OnExtensionUnloaded(content::BrowserContext* browser_context, void OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
UnloadedExtensionInfo::Reason reason) override; UnloadedExtensionInfo::Reason reason) override;
void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, void OnExtensionInstalled(content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
bool is_update, bool is_update) override;
bool from_ephemeral,
const std::string& old_name) override;
void OnExtensionUninstalled(content::BrowserContext* browser_context, void OnExtensionUninstalled(content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
extensions::UninstallReason reason) override; extensions::UninstallReason reason) override;
......
...@@ -162,15 +162,26 @@ cr.define('extensions', function() { ...@@ -162,15 +162,26 @@ cr.define('extensions', function() {
compare(a.id, b.id); compare(a.id, b.id);
} }
/** @interface */
function ExtensionListDelegate() {}
ExtensionListDelegate.prototype = {
/**
* Called when the number of extensions in the list has changed.
*/
onExtensionCountChanged: assertNotReached,
};
/** /**
* Creates a new list of extensions. * Creates a new list of extensions.
* @param {extensions.ExtensionListDelegate} delegate
* @constructor * @constructor
* @extends {HTMLDivElement} * @extends {HTMLDivElement}
*/ */
function ExtensionList() { function ExtensionList(delegate) {
var div = document.createElement('div'); var div = document.createElement('div');
div.__proto__ = ExtensionList.prototype; div.__proto__ = ExtensionList.prototype;
div.initialize(); div.initialize(delegate);
return div; return div;
} }
...@@ -230,11 +241,15 @@ cr.define('extensions', function() { ...@@ -230,11 +241,15 @@ cr.define('extensions', function() {
/** /**
* Initializes the list. * Initializes the list.
* @param {!extensions.ExtensionListDelegate} delegate
*/ */
initialize: function() { initialize: function(delegate) {
/** @private {!Array<ExtensionInfo>} */ /** @private {!Array<ExtensionInfo>} */
this.extensions_ = []; this.extensions_ = [];
/** @private {!extensions.ExtensionListDelegate} */
this.delegate_ = delegate;
/** /**
* |loadFinished| should be used for testing purposes and will be * |loadFinished| should be used for testing purposes and will be
* fulfilled when this list has finished loading the first time. * fulfilled when this list has finished loading the first time.
...@@ -260,12 +275,19 @@ cr.define('extensions', function() { ...@@ -260,12 +275,19 @@ cr.define('extensions', function() {
this.updateExtension_(eventData.extensionInfo); this.updateExtension_(eventData.extensionInfo);
break; break;
case EventType.UNINSTALLED: case EventType.UNINSTALLED:
var index = this.getIndexOfExtension_(eventData.item_id);
this.extensions_.splice(index, 1);
var childNode = $(eventData.item_id); var childNode = $(eventData.item_id);
childNode.parentNode.removeChild(childNode); childNode.parentNode.removeChild(childNode);
break; break;
default: default:
assertNotReached(); assertNotReached();
} }
if (eventData.event_type == EventType.INSTALLED ||
eventData.event_type == EventType.UNINSTALLED) {
this.delegate_.onExtensionCountChanged();
}
}.bind(this)); }.bind(this));
}, },
...@@ -334,6 +356,19 @@ cr.define('extensions', function() { ...@@ -334,6 +356,19 @@ cr.define('extensions', function() {
return this.extensions_.length; return this.extensions_.length;
}, },
/**
* @param {string} id The id of the extension.
* @return {number} The index of the extension with the given id.
* @private
*/
getIndexOfExtension_: function(id) {
for (var i = 0; i < this.extensions_.length; ++i) {
if (this.extensions_[i].id == id)
return i;
}
return -1;
},
getIdQueryParam_: function() { getIdQueryParam_: function() {
return parseQueryParams(document.location)['id']; return parseQueryParams(document.location)['id'];
}, },
...@@ -1063,13 +1098,7 @@ cr.define('extensions', function() { ...@@ -1063,13 +1098,7 @@ cr.define('extensions', function() {
* @private * @private
*/ */
updateExtension_: function(extension) { updateExtension_: function(extension) {
var currIndex = -1; var currIndex = this.getIndexOfExtension_(extension.id);
for (var i = 0; i < this.extensions_.length; ++i) {
if (this.extensions_[i].id == extension.id) {
currIndex = i;
break;
}
}
if (currIndex != -1) { if (currIndex != -1) {
// If there is a current version of the extension, update it with the // If there is a current version of the extension, update it with the
// new version. // new version.
...@@ -1093,6 +1122,7 @@ cr.define('extensions', function() { ...@@ -1093,6 +1122,7 @@ cr.define('extensions', function() {
}; };
return { return {
ExtensionList: ExtensionList ExtensionList: ExtensionList,
ExtensionListDelegate: ExtensionListDelegate
}; };
}); });
...@@ -98,6 +98,8 @@ cr.define('extensions', function() { ...@@ -98,6 +98,8 @@ cr.define('extensions', function() {
/** /**
* ExtensionSettings class * ExtensionSettings class
* @class * @class
* @constructor
* @implements {extensions.ExtensionListDelegate}
*/ */
function ExtensionSettings() {} function ExtensionSettings() {}
...@@ -133,7 +135,7 @@ cr.define('extensions', function() { ...@@ -133,7 +135,7 @@ cr.define('extensions', function() {
// Set the title. // Set the title.
uber.setTitle(loadTimeData.getString('extensionSettings')); uber.setTitle(loadTimeData.getString('extensionSettings'));
var extensionList = new ExtensionList(); var extensionList = new ExtensionList(this);
extensionList.id = 'extension-settings-list'; extensionList.id = 'extension-settings-list';
var wrapper = $('extension-list-wrapper'); var wrapper = $('extension-list-wrapper');
wrapper.insertBefore(extensionList, wrapper.firstChild); wrapper.insertBefore(extensionList, wrapper.firstChild);
...@@ -274,10 +276,7 @@ cr.define('extensions', function() { ...@@ -274,10 +276,7 @@ cr.define('extensions', function() {
document.documentElement.classList.remove('loading'); document.documentElement.classList.remove('loading');
}, 0); }, 0);
/** @const */ this.onExtensionCountChanged();
var hasExtensions = extensionList.getNumExtensions() != 0;
$('no-extensions').hidden = hasExtensions;
$('extension-list-wrapper').hidden = !hasExtensions;
}.bind(this)); }.bind(this));
}, },
...@@ -293,10 +292,9 @@ cr.define('extensions', function() { ...@@ -293,10 +292,9 @@ cr.define('extensions', function() {
/** /**
* Shows the Extension Commands configuration UI. * Shows the Extension Commands configuration UI.
* @param {Event} e Change event.
* @private * @private
*/ */
showExtensionCommandsConfigUi_: function(e) { showExtensionCommandsConfigUi_: function() {
ExtensionSettings.showOverlay($('extension-commands-overlay')); ExtensionSettings.showOverlay($('extension-commands-overlay'));
chrome.send('metricsHandler:recordAction', chrome.send('metricsHandler:recordAction',
['Options_ExtensionCommands']); ['Options_ExtensionCommands']);
...@@ -347,8 +345,20 @@ cr.define('extensions', function() { ...@@ -347,8 +345,20 @@ cr.define('extensions', function() {
buttons.offsetHeight + 'px'; buttons.offsetHeight + 'px';
}.bind(this)); }.bind(this));
}, },
/** @override */
onExtensionCountChanged: function() {
/** @const */
var hasExtensions = $('extension-settings-list').getNumExtensions() != 0;
$('no-extensions').hidden = hasExtensions;
$('extension-list-wrapper').hidden = !hasExtensions;
},
}; };
/**
* Called by the WebUI when something has changed and the extensions UI needs
* to be updated.
*/
ExtensionSettings.onExtensionsChanged = function() { ExtensionSettings.onExtensionsChanged = function() {
ExtensionSettings.getInstance().update_(); ExtensionSettings.getInstance().update_();
}; };
......
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