diff options
author | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 18:17:55 +0000 |
---|---|---|
committer | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 18:17:55 +0000 |
commit | 2910a1b662c04634c9e8fd4d4d58b06c88ff729b (patch) | |
tree | f29bb5f1dc82e4c7adf2bbaa73b0737bd52c11c6 /chrome/browser | |
parent | 25fba3fde8096d254d7823b19d0ecdcf717aac05 (diff) | |
download | chromium_src-2910a1b662c04634c9e8fd4d4d58b06c88ff729b.zip chromium_src-2910a1b662c04634c9e8fd4d4d58b06c88ff729b.tar.gz chromium_src-2910a1b662c04634c9e8fd4d4d58b06c88ff729b.tar.bz2 |
[uber page] Remove extensions sub-page from options2.
BUG=107469
TEST=Verify that chrome://settings-frame still functions sans extensions.
Review URL: http://codereview.chromium.org/8949006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
16 files changed, 0 insertions, 2550 deletions
diff --git a/chrome/browser/resources/options2/extension_list.js b/chrome/browser/resources/options2/extension_list.js deleted file mode 100644 index 5cbad97..0000000 --- a/chrome/browser/resources/options2/extension_list.js +++ /dev/null @@ -1,764 +0,0 @@ -// Copyright (c) 2011 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. - -cr.define('options', function() { - 'use strict'; - - /** - * A lookup helper function to find the first node that has an id (starting - * at |node| and going up the parent chain). - * @param {Element} node The node to start looking at. - */ - function findIdNode(node) { - while (node && !node.id) { - node = node.parentNode; - } - return node; - } - - /** - * Creates a new list of extensions. - * @param {Object=} opt_propertyBag Optional properties. - * @constructor - * @extends {cr.ui.div} - */ - var ExtensionsList = cr.ui.define('div'); - - var handlersInstalled = false; - - /** - * @type {Object.<string, boolean>} A map from extension id to a boolean - * indicating whether its details section is expanded. This persists - * between calls to decorate. - */ - var showingDetails = {}; - - /** - * @type {Object.<string, boolean>} A map from extension id to a boolean - * indicating whether the incognito warning is showing. This persists - * between calls to decorate. - */ - var showingWarning = {}; - - ExtensionsList.prototype = { - __proto__: HTMLDivElement.prototype, - - /** @inheritDoc */ - decorate: function() { - this.initControlsAndHandlers_(); - - this.deleteExistingExtensionNodes_(); - - this.showExtensionNodes_(); - }, - - /** - * Initializes the controls (toggle section and button) and installs - * handlers. - * @private - */ - initControlsAndHandlers_: function() { - // Make sure developer mode section is set correctly as per saved setting. - var toggleButton = $('toggle-dev-on'); - var toggleSection = $('dev'); - if (this.data_.developerMode) { - toggleSection.classList.add('dev-open'); - toggleSection.classList.remove('dev-closed'); - toggleButton.checked = true; - } else { - toggleSection.classList.remove('dev-open'); - toggleSection.classList.add('dev-closed'); - } - - // Instal global event handlers. - if (!handlersInstalled) { - var searchPage = SearchPage.getInstance(); - searchPage.addEventListener('searchChanged', - this.searchChangedHandler_.bind(this)); - - // Support full keyboard accessibility without making things ugly - // for users who click, by hiding some focus outlines when the user - // clicks anywhere, but showing them when the user presses any key. - this.ownerDocument.body.classList.add('hide-some-focus-outlines'); - this.ownerDocument.addEventListener('click', (function(e) { - this.ownerDocument.body.classList.add('hide-some-focus-outlines'); - return true; - }).bind(this), true); - this.ownerDocument.addEventListener('keydown', (function(e) { - this.ownerDocument.body.classList.remove('hide-some-focus-outlines'); - return true; - }).bind(this), true); - - handlersInstalled = true; - } - }, - - /** - * Deletes the existing Extension nodes from the page to make room for new - * ones. - * @private - */ - deleteExistingExtensionNodes_: function() { - while (this.hasChildNodes()){ - this.removeChild(this.firstChild); - } - }, - - /** - * Handles decorating the details section. - * @param {Element} details The div that the details should be attached to. - * @param {Object} extension The extension we are showing the details for. - * @private - */ - showExtensionNodes_: function() { - // Iterate over the extension data and add each item to the list. - for (var i = 0; i < this.data_.extensions.length; i++) { - var extension = this.data_.extensions[i]; - var id = extension.id; - - var wrapper = this.ownerDocument.createElement('div'); - - var expanded = showingDetails[id]; - var butterbar = showingWarning[id]; - - wrapper.classList.add(expanded ? 'extension-list-item-expanded' : - 'extension-list-item-collaped'); - if (!extension.enabled) - wrapper.classList.add('disabled'); - wrapper.id = id; - this.appendChild(wrapper); - - var vboxOuter = this.ownerDocument.createElement('div'); - vboxOuter.classList.add('vbox'); - vboxOuter.classList.add('extension-list-item'); - wrapper.appendChild(vboxOuter); - - var hbox = this.ownerDocument.createElement('div'); - hbox.classList.add('hbox'); - vboxOuter.appendChild(hbox); - - // Add a container div for the zippy, so we can extend the hit area. - var container = this.ownerDocument.createElement('div'); - // Clicking anywhere on the div expands/collapses the details. - container.classList.add('extension-zippy-container'); - container.title = expanded ? - localStrings.getString('extensionSettingsHideDetails') : - localStrings.getString('extensionSettingsShowDetails'); - container.tabIndex = 0; - container.setAttribute('role', 'button'); - container.setAttribute('aria-controls', extension.id + '_details'); - container.setAttribute('aria-expanded', expanded); - container.addEventListener('click', this.handleZippyClick_.bind(this)); - container.addEventListener('keydown', - this.handleZippyKeyDown_.bind(this)); - hbox.appendChild(container); - - // On the far left we have the zippy icon. - var div = this.ownerDocument.createElement('div'); - div.id = id + '_zippy'; - div.classList.add('extension-zippy-default'); - div.classList.add(expanded ? 'extension-zippy-expanded' : - 'extension-zippy-collapsed'); - container.appendChild(div); - - // Next to it, we have the extension icon. - var icon = this.ownerDocument.createElement('img'); - icon.classList.add('extension-icon'); - icon.src = extension.icon; - hbox.appendChild(icon); - - // Start a vertical box for showing the details. - var vbox = this.ownerDocument.createElement('div'); - vbox.classList.add('vbox'); - vbox.classList.add('stretch'); - vbox.classList.add('details-view'); - hbox.appendChild(vbox); - - div = this.ownerDocument.createElement('div'); - vbox.appendChild(div); - - // Title comes next. - var title = this.ownerDocument.createElement('span'); - title.classList.add('extension-title'); - title.textContent = extension.name; - vbox.appendChild(title); - - // Followed by version. - var version = this.ownerDocument.createElement('span'); - version.classList.add('extension-version'); - version.textContent = extension.version; - vbox.appendChild(version); - - // And the additional info label (unpacked/crashed). - if (extension.terminated || extension.isUnpacked) { - var version = this.ownerDocument.createElement('span'); - version.classList.add('extension-version'); - version.textContent = extension.terminated ? - localStrings.getString('extensionSettingsCrashMessage') : - localStrings.getString('extensionSettingsInDevelopment'); - vbox.appendChild(version); - } - - div = this.ownerDocument.createElement('div'); - vbox.appendChild(div); - - // And below that we have description (if provided). - if (extension.description.length > 0) { - var description = this.ownerDocument.createElement('span'); - description.classList.add('extension-description'); - description.textContent = extension.description; - vbox.appendChild(description); - } - - // Immediately following the description, we have the - // Options link (optional). - if (extension.options_url) { - var link = this.ownerDocument.createElement('a'); - link.classList.add('extension-links-trailing'); - link.textContent = localStrings.getString('extensionSettingsOptions'); - link.href = '#'; - link.addEventListener('click', this.handleOptions_.bind(this)); - vbox.appendChild(link); - } - - // Then the optional Visit Website link. - if (extension.homepageUrl) { - var link = this.ownerDocument.createElement('a'); - link.classList.add('extension-links-trailing'); - link.textContent = - localStrings.getString('extensionSettingsVisitWebsite'); - link.href = extension.homepageUrl; - vbox.appendChild(link); - } - - if (extension.warnings.length > 0) { - var warningsDiv = this.ownerDocument.createElement('div'); - warningsDiv.classList.add('extension-warnings'); - - var warningsHeader = this.ownerDocument.createElement('span'); - warningsHeader.classList.add('extension-warnings-title'); - warningsHeader.textContent = - localStrings.getString('extensionSettingsWarningsTitle'); - warningsDiv.appendChild(warningsHeader); - - var warningList = this.ownerDocument.createElement('ul'); - for (var j = 0; j < extension.warnings.length; ++j) { - var warningEntry = this.ownerDocument.createElement('li'); - warningEntry.textContent = extension.warnings[j]; - warningList.appendChild(warningEntry); - } - warningsDiv.appendChild(warningList); - - vbox.appendChild(warningsDiv); - } - - // And now the details section that is normally hidden. - var details = this.ownerDocument.createElement('div'); - details.classList.add('vbox'); - vbox.appendChild(details); - - this.decorateDetailsSection_(details, extension, expanded, butterbar); - - // And on the right of the details we have the Enable/Enabled checkbox. - div = this.ownerDocument.createElement('div'); - hbox.appendChild(div); - - var section = this.ownerDocument.createElement('section'); - section.classList.add('extension-enabling'); - div.appendChild(section); - - if (!extension.terminated) { - // The Enable checkbox. - var input = this.ownerDocument.createElement('input'); - input.addEventListener('click', this.handleEnable_.bind(this)); - input.type = 'checkbox'; - input.name = 'toggle-' + id; - input.disabled = !extension.mayDisable; - if (extension.enabled) - input.checked = true; - input.id = 'toggle-' + id; - section.appendChild(input); - var label = this.ownerDocument.createElement('label'); - label.classList.add('extension-enabling-label'); - if (extension.enabled) - label.classList.add('extension-enabling-label-bold'); - label.htmlFor = 'toggle-' + id; - label.id = 'toggle-' + id + '-label'; - if (extension.enabled) { - // Enabled (with a d). - label.textContent = - localStrings.getString('extensionSettingsEnabled'); - } else { - // Enable (no d). - label.textContent = - localStrings.getString('extensionSettingsEnable'); - } - section.appendChild(label); - } else { - // Extension has been terminated, show a Reload link. - var link = this.ownerDocument.createElement('a'); - link.classList.add('extension-links-trailing'); - link.id = extension.id; - link.textContent = - localStrings.getString('extensionSettingsReload'); - link.href = '#'; - link.addEventListener('click', this.handleReload_.bind(this)); - section.appendChild(link); - } - - // And, on the far right we have the uninstall button. - var button = this.ownerDocument.createElement('button'); - button.classList.add('extension-delete'); - button.id = id; - if (!extension.mayDisable) - button.disabled = true; - button.textContent = localStrings.getString('extensionSettingsRemove'); - button.addEventListener('click', this.handleUninstall_.bind(this)); - hbox.appendChild(button); - } - - // Do one pass to find what the size of the checkboxes should be. - var minCheckboxWidth = Infinity; - var maxCheckboxWidth = 0; - for (var i = 0; i < this.data_.extensions.length; ++i) { - var label = $('toggle-' + this.data_.extensions[i].id + '-label'); - if (label.offsetWidth > maxCheckboxWidth) - maxCheckboxWidth = label.offsetWidth; - if (label.offsetWidth < minCheckboxWidth) - minCheckboxWidth = label.offsetWidth; - } - - // Do another pass, making sure checkboxes line up. - var difference = maxCheckboxWidth - minCheckboxWidth; - for (var i = 0; i < this.data_.extensions.length; ++i) { - var label = $('toggle-' + this.data_.extensions[i].id + '-label'); - if (label.offsetWidth < maxCheckboxWidth) - label.style.WebkitMarginEnd = difference.toString() + 'px'; - } - }, - - /** - * Handles decorating the details section. - * @param {Element} details The div that the details should be attached to. - * @param {Object} extension The extension we are shoting the details for. - * @param {boolean} expanded Whether to show the details expanded or not. - * @param {boolean} showButterbar Whether to show the incognito warning or - * not. - * @private - */ - decorateDetailsSection_: function(details, extension, - expanded, showButterbar) { - // This container div is needed because vbox display - // overrides display:hidden. - var detailsContents = this.ownerDocument.createElement('div'); - detailsContents.classList.add(expanded ? 'extension-details-visible' : - 'extension-details-hidden'); - detailsContents.id = extension.id + '_details'; - details.appendChild(detailsContents); - - var div = this.ownerDocument.createElement('div'); - div.classList.add('informative-text'); - detailsContents.appendChild(div); - - // Keep track of how many items we'll show in the details section. - var itemsShown = 0; - - if (this.data_.developerMode) { - // First we have the id. - var content = this.ownerDocument.createElement('div'); - content.textContent = - localStrings.getString('extensionSettingsExtensionId') + - ' ' + extension.id; - div.appendChild(content); - itemsShown++; - - // Then, the path, if provided by unpacked extension. - if (extension.isUnpacked) { - content = this.ownerDocument.createElement('div'); - content.textContent = - localStrings.getString('extensionSettingsExtensionPath') + - ' ' + extension.path; - div.appendChild(content); - itemsShown++; - } - - // Then, the 'managed, cannot uninstall/disable' message. - if (!extension.mayDisable) { - content = this.ownerDocument.createElement('div'); - content.textContent = - localStrings.getString('extensionSettingsPolicyControlled'); - div.appendChild(content); - itemsShown++; - } - - // Then active views: - if (extension.views.length > 0) { - var table = this.ownerDocument.createElement('table'); - table.classList.add('extension-inspect-table'); - div.appendChild(table); - var tr = this.ownerDocument.createElement('tr'); - table.appendChild(tr); - var td = this.ownerDocument.createElement('td'); - td.classList.add('extension-inspect-left-column'); - tr.appendChild(td); - var span = this.ownerDocument.createElement('span'); - td.appendChild(span); - span.textContent = - localStrings.getString('extensionSettingsInspectViews'); - - td = this.ownerDocument.createElement('td'); - for (var i = 0; i < extension.views.length; ++i) { - // Then active views: - content = this.ownerDocument.createElement('div'); - var link = this.ownerDocument.createElement('a'); - link.classList.add('extension-links-view'); - link.textContent = extension.views[i].path; - link.id = extension.id; - link.href = '#'; - link.addEventListener('click', this.sendInspectMessage_.bind(this)); - content.appendChild(link); - - if (extension.views[i].incognito) { - var incognito = this.ownerDocument.createElement('span'); - incognito.classList.add('extension-links-view'); - incognito.textContent = - localStrings.getString('viewIncognito'); - content.appendChild(incognito); - } - - td.appendChild(content); - tr.appendChild(td); - - itemsShown++; - } - } - } - - var content = this.ownerDocument.createElement('div'); - detailsContents.appendChild(content); - - // Then Reload: - if (extension.enabled && extension.allow_reload) { - this.addLinkTo_(content, - localStrings.getString('extensionSettingsReload'), - extension.id, - this.handleReload_.bind(this)); - itemsShown++; - } - - // Then Show (Browser Action) Button: - if (extension.enabled && extension.enable_show_button) { - this.addLinkTo_(content, - localStrings.getString('extensionSettingsShowButton'), - extension.id, - this.handleShowButton_.bind(this)); - itemsShown++; - } - - if (extension.enabled) { - // The 'allow in incognito' checkbox. - var label = this.ownerDocument.createElement('label'); - label.classList.add('extension-checkbox-label'); - content.appendChild(label); - var input = this.ownerDocument.createElement('input'); - input.addEventListener('click', - this.handleToggleEnableIncognito_.bind(this)); - input.id = extension.id; - input.type = 'checkbox'; - if (extension.enabledIncognito) - input.checked = true; - label.appendChild(input); - var span = this.ownerDocument.createElement('span'); - span.classList.add('extension-checkbox-span'); - span.textContent = - localStrings.getString('extensionSettingsEnableIncognito'); - label.appendChild(span); - itemsShown++; - } - - if (extension.enabled && extension.wantsFileAccess) { - // The 'allow access to file URLs' checkbox. - label = this.ownerDocument.createElement('label'); - label.classList.add('extension-checkbox-label'); - content.appendChild(label); - var input = this.ownerDocument.createElement('input'); - input.addEventListener('click', - this.handleToggleAllowFileUrls_.bind(this)); - input.id = extension.id; - input.type = 'checkbox'; - if (extension.allowFileAccess) - input.checked = true; - label.appendChild(input); - var span = this.ownerDocument.createElement('span'); - span.classList.add('extension-checkbox-span'); - span.textContent = - localStrings.getString('extensionSettingsAllowFileAccess'); - label.appendChild(span); - itemsShown++; - } - - if (extension.enabled && !extension.is_hosted_app) { - // And add a hidden warning message for allowInIncognito. - content = this.ownerDocument.createElement('div'); - content.id = extension.id + '_incognitoWarning'; - content.classList.add('butter-bar'); - content.hidden = !showButterbar; - detailsContents.appendChild(content); - - var span = this.ownerDocument.createElement('span'); - span.innerHTML = - localStrings.getString('extensionSettingsIncognitoWarning'); - content.appendChild(span); - itemsShown++; - } - - var zippy = extension.id + '_zippy'; - $(zippy).hidden = !itemsShown; - - // If this isn't expanded now, make sure the newly-added controls - // are not part of the tab order. - if (!expanded) { - var detailsControls = details.querySelectorAll('a, input'); - for (var i = 0; i < detailsControls.length; i++) - detailsControls[i].tabIndex = -1; - } - }, - - /** - * A helper function to add contextual actions for extensions (action links) - * to the page. - */ - addLinkTo_: function(parent, linkText, id, handler) { - var link = this.ownerDocument.createElement('a'); - link.className = 'extension-links-trailing'; - link.textContent = linkText; - link.id = id; - link.href = '#'; - link.addEventListener('click', handler); - parent.appendChild(link); - }, - - /** - * A lookup helper function to find an extension based on an id. - * @param {string} id The |id| of the extension to look up. - * @private - */ - getExtensionWithId_: function(id) { - for (var i = 0; i < this.data_.extensions.length; ++i) { - if (this.data_.extensions[i].id == id) - return this.data_.extensions[i]; - } - return null; - }, - - /** - * Handles a key down on the zippy icon. - * @param {Event} e Key event. - * @private - */ - handleZippyKeyDown_: function(e) { - if (e.keyCode == 13 || e.keyCode == 32) // Enter or Space. - this.handleZippyClick_(e); - }, - - /** - * Handles the mouseclick on the zippy icon (that expands and collapses the - * details section). - * @param {Event} e Mouse event. - * @private - */ - handleZippyClick_: function(e) { - var node = findIdNode(e.target.parentNode); - var iter = this.firstChild; - while (iter) { - var zippy = $(iter.id + '_zippy'); - var details = $(iter.id + '_details'); - var container = zippy.parentElement; - if (iter.id == node.id) { - // Toggle visibility. - if (iter.classList.contains('extension-list-item-expanded')) { - // Hide yo kids! Hide yo wife! - showingDetails[iter.id] = false; - zippy.classList.remove('extension-zippy-expanded'); - zippy.classList.add('extension-zippy-collapsed'); - details.classList.remove('extension-details-visible'); - details.classList.add('extension-details-hidden'); - iter.classList.remove('extension-list-item-expanded'); - iter.classList.add('extension-list-item-collaped'); - container.setAttribute('aria-expanded', 'false'); - container.title = - localStrings.getString('extensionSettingsShowDetails'); - var detailsControls = details.querySelectorAll('a, input'); - for (var i = 0; i < detailsControls.length; i++) - detailsControls[i].tabIndex = -1; - - // Hide yo incognito warning. - var butterBar = - this.querySelector('#' + iter.id + '_incognitoWarning'); - if (butterBar !== null) { - butterBar.hidden = true; - showingWarning[iter.id] = false; - } - } else { - // Show the contents. - showingDetails[iter.id] = true; - zippy.classList.remove('extension-zippy-collapsed'); - zippy.classList.add('extension-zippy-expanded'); - details.classList.remove('extension-details-hidden'); - details.classList.add('extension-details-visible'); - iter.classList.remove('extension-list-item-collaped'); - iter.classList.add('extension-list-item-expanded'); - container.setAttribute('aria-expanded', 'true'); - container.title = - localStrings.getString('extensionSettingsHideDetails'); - var detailsControls = details.querySelectorAll('a, input'); - for (var i = 0; i < detailsControls.length; i++) - detailsControls[i].tabIndex = 0; - } - } - iter = iter.nextSibling; - } - }, - - /** - * Handles the 'searchChanged' event. This is used to limit the number of - * items to show in the list, when the user is searching for items with the - * search box. Otherwise, if one match is found, the whole list of - * extensions would be shown when we only want the matching items to be - * found. - * @param {Event} e Change event. - * @private - */ - searchChangedHandler_: function(e) { - var searchString = e.searchText; - var child = this.firstChild; - while (child) { - var extension = this.getExtensionWithId_(child.id); - if (searchString.length == 0) { - // Show all. - child.classList.remove('search-suppress'); - } else { - // If the search string does not appear within the text of the - // extension, then hide it. - if ((extension.name.toLowerCase().indexOf(searchString) < 0) && - (extension.version.toLowerCase().indexOf(searchString) < 0) && - (extension.description.toLowerCase().indexOf(searchString) < 0)) { - // Hide yo extension! - child.classList.add('search-suppress'); - } else { - // Show yourself! - child.classList.remove('search-suppress'); - } - } - child = child.nextSibling; - } - }, - - /** - * Handles the Reload Extension functionality. - * @param {Event} e Change event. - * @private - */ - handleReload_: function(e) { - var node = findIdNode(e.target); - chrome.send('extensionSettingsReload', [node.id]); - }, - - /** - * Handles the Show (Browser Action) Button functionality. - * @param {Event} e Change event. - * @private - */ - handleShowButton_: function(e) { - var node = findIdNode(e.target); - chrome.send('extensionSettingsShowButton', [node.id]); - }, - - /** - * Handles the Enable/Disable Extension functionality. - * @param {Event} e Change event. - * @private - */ - handleEnable_: function(e) { - var node = findIdNode(e.target.parentNode); - var extension = this.getExtensionWithId_(node.id); - chrome.send('extensionSettingsEnable', - [node.id, extension.enabled ? 'false' : 'true']); - chrome.send('extensionSettingsRequestExtensionsData'); - }, - - /** - * Handles the Uninstall Extension functionality. - * @param {Event} e Change event. - * @private - */ - handleUninstall_: function(e) { - var node = findIdNode(e.target.parentNode); - chrome.send('extensionSettingsUninstall', [node.id]); - chrome.send('extensionSettingsRequestExtensionsData'); - }, - - /** - * Handles the View Options link. - * @param {Event} e Change event. - * @private - */ - handleOptions_: function(e) { - var node = findIdNode(e.target.parentNode); - var extension = this.getExtensionWithId_(node.id); - chrome.send('extensionSettingsOptions', [extension.id]); - e.preventDefault(); - }, - - /** - * Handles the Enable Extension In Incognito functionality. - * @param {Event} e Change event. - * @private - */ - handleToggleEnableIncognito_: function(e) { - var node = findIdNode(e.target); - var butterBar = document.getElementById(node.id + '_incognitoWarning'); - butterBar.hidden = !e.target.checked; - showingWarning[node.id] = e.target.checked; - chrome.send('extensionSettingsEnableIncognito', - [node.id, String(e.target.checked)]); - }, - - /** - * Handles the Allow On File URLs functionality. - * @param {Event} e Change event. - * @private - */ - handleToggleAllowFileUrls_: function(e) { - var node = findIdNode(e.target); - chrome.send('extensionSettingsAllowFileAccess', - [node.id, String(e.target.checked)]); - }, - - /** - * Tell the C++ ExtensionDOMHandler to inspect the page detailed in - * |viewData|. - * @param {Event} e Change event. - * @private - */ - sendInspectMessage_: function(e) { - var extension = this.getExtensionWithId_(e.srcElement.id); - for (var i = 0; i < extension.views.length; ++i) { - if (extension.views[i].path == e.srcElement.innerText) { - // TODO(aa): This is ghetto, but WebUIBindings doesn't support sending - // anything other than arrays of strings, and this is all going to get - // replaced with V8 extensions soon anyway. - chrome.send('extensionSettingsInspect', [ - String(extension.views[i].renderProcessId), - String(extension.views[i].renderViewId) - ]); - } - } - }, - }; - - return { - ExtensionsList: ExtensionsList - }; -}); diff --git a/chrome/browser/resources/options2/extension_settings.css b/chrome/browser/resources/options2/extension_settings.css deleted file mode 100644 index 35ca397..0000000 --- a/chrome/browser/resources/options2/extension_settings.css +++ /dev/null @@ -1,274 +0,0 @@ -/* -Copyright (c) 2011 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. -*/ - -.details-view { - -webkit-padding-end: 10px; -} - -.extension-list-item { - padding-bottom: 7px; - padding-top: 7px; - width: 100%; - -webkit-user-select: auto; -} - -/* Get rid of display: table, which causes width issues. */ -#extension-settings .displaytable { - display: block; -} -/* Get rid of display: table row, which causes width issues. */ -#extension-settings .displaytable > section { - display: block; -} -/* Get rid of display: table cell, which causes width issues. */ -#extension-settings .displaytable > section > * { - display: block; -} - -.extension-settings-content { - border-bottom : 0px solid #eee; - margin-top: 3px; -} - -#extension-settings-list { - min-height: 0; - overflow-y: hidden; -} - -/* Get rid of the light-blue background on list item hover. */ -#extension-settings-list:not([disabled]) > :hover { - background-color: white; - border-color: #CDCDCD; -} - -.butter-bar { - background: #FFF299; - padding: 2px 5px; - border-radius: 3px; - white-space: normal; -} - -.search-suppress { - display: none; - height: 0; -} - -.extension-list-item-collaped { - height: auto; - margin-bottom: 16px; - -webkit-transition: padding 300ms, overflow 300ms, opacity 700ms; -} - -.extension-list-item-expanded { - height: auto; - margin-bottom: 16px; - overflow: visible; - -webkit-transition: padding 300ms, overflow 300ms, opacity 700ms; -} - -.extension-settings { - overflow-x: hidden; -} - -.extension-icon { - height: 48px; - vertical-align: text-top; - width: 48px; - -webkit-padding-start: 15px; - -webkit-padding-end: 15px; - -webkit-user-select: none; -} - -.extension-title { - font-size: 16px; - font-weight: 500; - -webkit-padding-end: 20px; -} - -.extension-version { - font-size: 13px; - font-weight: 400; - -webkit-padding-end: 7px; -} - -.extension-description { - font-size: 13px; - white-space: normal; - -webkit-padding-end: 5px; -} - -.extension-checkbox-span { - -webkit-margin-start: 7px; -} - -.extension-checkbox-label { - -webkit-margin-end: 10px; -} - -.extension-delete { - -webkit-margin-start: 5px; -} - -.extension-details-hidden { - opacity: 0; - max-height: 0; - -webkit-transition: max-height 400ms, opacity 200ms; -} - -.extension-details-visible { - opacity: 1; - max-height: 1000px; - -webkit-transition: max-height 200ms, opacity 300ms; -} - -.extension-links-view { - -webkit-padding-start: 15px; -} - -.extension-links-trailing { - -webkit-padding-end: 7px; -} - -.extension-zippy-container { - cursor: pointer; - width: 20px; - -webkit-user-select: none; -} - -.extension-warnings-title { - color: red; -} - -.extension-warnings { - margin-top: 6px; -} - -.extension-warnings ul { - margin: 0; -} - -.extension-warnings > * { - white-space: normal; -} - -.informative-text { - color: gray; -} - -.extension-zippy-default { - background-image: url('zippy.png'); - background-repeat: no-repeat; - background-position: center top; - position: absolute; - left: 12px; - top: 25px; - width: 6px; - height: 16px; - opacity: .25; -} - -.extension-zippy-collapsed { - -webkit-transition: -webkit-transform 100ms; - -webkit-transform: rotate(0deg); -} - -.extension-zippy-collapsed:hover { - opacity: .5; - -webkit-transform: rotate(5deg); - -webkit-transition: -webkit-transform 100ms, opacity 100ms; -} - -.extension-zippy-expanded { - -webkit-transition: -webkit-transform 100ms; - -webkit-transform: rotate(90deg); -} - -.extension-zippy-expanded:hover { - -webkit-transition: -webkit-transform 100ms; - -webkit-transform: rotate(85deg); -} - -.extension-enabling { - position: relative; - top: 3px; -} - -.extension-enabling-label { - color: black; - -webkit-padding-start: 3px; - -webkit-padding-end: 9px; -} - -.extension-enabling-label-bold { - font-weight: bold; -} - -.extension-inspect-table { - padding: 0; - border-spacing: 0; -} - -.extension-inspect-left-column { - vertical-align: text-top; -} - -/* Dev */ - -.dev-open { - border-bottom: 1px solid rgb(205, 205, 205); - height: 32px; - padding-bottom: 7px; - padding-top: 13px; - -webkit-padding-start: 4px; - -webkit-padding-end: 3px; - -webkit-transition: padding 300ms, height 300ms, opacity 700ms; -} -.dev-closed { - height: 0; - opacity: 0; - padding-top: 9px; - -webkit-padding-start: 4px; - -webkit-padding-end: 3px; - -webkit-transition: padding 300ms, height 700ms, opacity 200ms; -} - -.dev-button-visible { - display: inherit; - opacity: 1; - -webkit-transition: opacity 200ms; -} - -.dev-button-hidden { - display: none; -} - -#suggest-gallery { - -webkit-padding-start: 10px; -} - -#dev-toggle { - display: block; - text-align: end; - margin-top: -28px; - -webkit-margin-end: 8px; -} - -#get-more-extensions-container { - display: -webkit-box; -} - -#get-more-extensions { - padding-top: 5px; - font-size: 15px; - -webkit-padding-start: 10px; -} - -/* Support full keyboard accessibility without making things ugly - for users who click, by hiding some focus outlines when the user - clicks anywhere, but showing them when the user presses any key. */ -body.hide-some-focus-outlines .extension-zippy-container { - outline: none; -} diff --git a/chrome/browser/resources/options2/extension_settings.html b/chrome/browser/resources/options2/extension_settings.html deleted file mode 100644 index 2858316..0000000 --- a/chrome/browser/resources/options2/extension_settings.html +++ /dev/null @@ -1,40 +0,0 @@ -<div id="extension-settings" class="page" hidden> - <h1 i18n-content="extensionSettings"></h1> - <div id="dev-toggle"> - <input id="toggle-dev-on" type="checkbox" value="off"></input> - <label for="toggle-dev-on" i18n-content="extensionSettingsDeveloperMode" /> - </div> - <div class="displaytable"> - <div id="dev" class="dev-closed"> - <table id="dev-table" width="100%"> - <tr> - <td> - <button id="load-unpacked" - i18n-content="extensionSettingsLoadUnpackedButton"></button> - <button id="pack-extension" - i18n-content="extensionSettingsPackButton"></button> - </td> - <td align="right"> - <button id="update-extensions-now" - i18n-content="extensionSettingsUpdateButton"></button> - </td> - </tr> - </table> - </div> - <section class="extension-settings-content"> - <div class="extension-settings"> - <list id="extension-settings-list"></list> - </div> - </section> - </div> - <section> - <div><strong id="no-extensions" - i18n-content="extensionSettingsNoExtensions" - hidden="true"></strong></div> - <div id="suggest-gallery" hidden="true"></div> - <div id="get-more-extensions-container" hidden="true"> - <img src="chrome://theme/IDR_WEBSTORE_ICON_32"> - <div id="get-more-extensions"></div> - </div> - </section> -</div> diff --git a/chrome/browser/resources/options2/extension_settings.js b/chrome/browser/resources/options2/extension_settings.js deleted file mode 100644 index e88ba85..0000000 --- a/chrome/browser/resources/options2/extension_settings.js +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (c) 2011 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. - -// Used for observing function of the backend datasource for this page by -// tests. -var webui_responded_ = false; - -cr.define('options', function() { - var OptionsPage = options.OptionsPage; - var ExtensionsList = options.ExtensionsList; - - /** - * ExtensionSettings class - * Encapsulated handling of the 'Manage Extensions' page. - * @class - */ - function ExtensionSettings() { - OptionsPage.call(this, 'extensions', - templateData.extensionSettingsTabTitle, - 'extension-settings'); - } - - cr.addSingletonGetter(ExtensionSettings); - - ExtensionSettings.prototype = { - __proto__: OptionsPage.prototype, - - /** - * Initialize the page. - */ - initializePage: function() { - OptionsPage.prototype.initializePage.call(this); - - // This will request the data to show on the page and will get a response - // back in returnExtensionsData. - chrome.send('extensionSettingsRequestExtensionsData'); - - // Set up the developer mode button. - var toggleDevMode = $('toggle-dev-on'); - toggleDevMode.addEventListener('click', - this.handleToggleDevMode_.bind(this)); - - // Setup the gallery related links and text. - $('suggest-gallery').innerHTML = - localStrings.getString('extensionSettingsSuggestGallery'); - $('get-more-extensions').innerHTML = - localStrings.getString('extensionSettingsGetMoreExtensions'); - - // Set up the three dev mode buttons (load unpacked, pack and update). - $('load-unpacked').addEventListener('click', - this.handleLoadUnpackedExtension_.bind(this)); - $('pack-extension').addEventListener('click', - this.handlePackExtension_.bind(this)); - $('update-extensions-now').addEventListener('click', - this.handleUpdateExtensionNow_.bind(this)); - }, - - /** - * Utility function which asks the C++ to show a platform-specific file - * select dialog, and fire |callback| with the |filePath| that resulted. - * |selectType| can be either 'file' or 'folder'. |operation| can be 'load', - * 'packRoot', or 'pem' which are signals to the C++ to do some - * operation-specific configuration. - * @private - */ - showFileDialog_: function(selectType, operation, callback) { - handleFilePathSelected = function(filePath) { - callback(filePath); - handleFilePathSelected = function() {}; - }; - - chrome.send('extensionSettingsSelectFilePath', [selectType, operation]); - }, - - /** - * Handles the Load Unpacked Extension button. - * @param {Event} e Change event. - * @private - */ - handleLoadUnpackedExtension_: function(e) { - this.showFileDialog_('folder', 'load', function(filePath) { - chrome.send('extensionSettingsLoad', [String(filePath)]); - }); - - chrome.send('coreOptionsUserMetricsAction', - ['Options_LoadUnpackedExtension']); - }, - - /** - * Handles the Pack Extension button. - * @param {Event} e Change event. - * @private - */ - handlePackExtension_: function(e) { - OptionsPage.navigateToPage('packExtensionOverlay'); - chrome.send('coreOptionsUserMetricsAction', ['Options_PackExtension']); - }, - - /** - * Handles the Update Extension Now button. - * @param {Event} e Change event. - * @private - */ - handleUpdateExtensionNow_: function(e) { - chrome.send('extensionSettingsAutoupdate', []); - }, - - /** - * Handles the Toggle Dev Mode button. - * @param {Event} e Change event. - * @private - */ - handleToggleDevMode_: function(e) { - var dev = $('dev'); - if (!dev.classList.contains('dev-open')) { - // Make the Dev section visible. - dev.classList.add('dev-open'); - dev.classList.remove('dev-closed'); - - $('load-unpacked').classList.add('dev-button-visible'); - $('load-unpacked').classList.remove('dev-button-hidden'); - $('pack-extension').classList.add('dev-button-visible'); - $('pack-extension').classList.remove('dev-button-hidden'); - $('update-extensions-now').classList.add('dev-button-visible'); - $('update-extensions-now').classList.remove('dev-button-hidden'); - } else { - // Hide the Dev section. - dev.classList.add('dev-closed'); - dev.classList.remove('dev-open'); - - $('load-unpacked').classList.add('dev-button-hidden'); - $('load-unpacked').classList.remove('dev-button-visible'); - $('pack-extension').classList.add('dev-button-hidden'); - $('pack-extension').classList.remove('dev-button-visible'); - $('update-extensions-now').classList.add('dev-button-hidden'); - $('update-extensions-now').classList.remove('dev-button-visible'); - } - - chrome.send('extensionSettingsToggleDeveloperMode', []); - }, - }; - - /** - * Called by the dom_ui_ to re-populate the page with data representing - * the current state of installed extensions. - */ - ExtensionSettings.returnExtensionsData = function(extensionsData) { - webui_responded_ = true; - - $('no-extensions').hidden = true; - $('suggest-gallery').hidden = true; - $('get-more-extensions-container').hidden = true; - - if (extensionsData.extensions.length > 0) { - // Enforce order specified in the data or (if equal) then sort by - // extension name (case-insensitive). - extensionsData.extensions.sort(function(a, b) { - if (a.order == b.order) { - a = a.name.toLowerCase(); - b = b.name.toLowerCase(); - return a < b ? -1 : (a > b ? 1 : 0); - } else { - return a.order < b.order ? -1 : 1; - } - }); - - $('get-more-extensions-container').hidden = false; - } else { - $('no-extensions').hidden = false; - $('suggest-gallery').hidden = false; - } - - ExtensionsList.prototype.data_ = extensionsData; - - var extensionList = $('extension-settings-list'); - ExtensionsList.decorate(extensionList); - } - - // Export - return { - ExtensionSettings: ExtensionSettings - }; -}); diff --git a/chrome/browser/resources/options2/options.html b/chrome/browser/resources/options2/options.html index 5751729..e56e849 100644 --- a/chrome/browser/resources/options2/options.html +++ b/chrome/browser/resources/options2/options.html @@ -24,7 +24,6 @@ <link rel="stylesheet" href="clear_browser_data_overlay.css"> <link rel="stylesheet" href="content_settings.css"> <link rel="stylesheet" href="cookies_view.css"> -<link rel="stylesheet" href="extension_settings.css"> <link rel="stylesheet" href="font_settings.css"> <if expr="pp_ifdef('enable_register_protocol_handler')"> <link rel="stylesheet" href="handler_options.css"> @@ -35,7 +34,6 @@ </if> <link rel="stylesheet" href="language_options.css"> <link rel="stylesheet" href="manage_profile_overlay.css"> -<link rel="stylesheet" href="pack_extension_overlay.css"> <link rel="stylesheet" href="password_manager.css"> <link rel="stylesheet" href="password_manager_list.css"> <link rel="stylesheet" href="personal_options.css"> @@ -90,7 +88,6 @@ <include src="instant_confirm_overlay.html"> <include src="language_add_language_overlay.html"> <include src="manage_profile_overlay.html"> - <include src="pack_extension_overlay.html"> <include src="../sync_setup_overlay.html"> <if expr="pp_ifdef('chromeos')"> <include @@ -129,7 +126,6 @@ <include src="chromeos/accounts_options.html"> </if> <include src="advanced_options.html"> - <include src="extension_settings.html"> </div> <div id="subpage-sheet-container-1" class="subpage-sheet-container transparent" hidden> diff --git a/chrome/browser/resources/options2/options.js b/chrome/browser/resources/options2/options.js index 5a744f3..3f28573 100644 --- a/chrome/browser/resources/options2/options.js +++ b/chrome/browser/resources/options2/options.js @@ -14,7 +14,6 @@ var ContentSettings = options.ContentSettings; var ContentSettingsExceptionsArea = options.contentSettings.ContentSettingsExceptionsArea; var CookiesView = options.CookiesView; -var ExtensionSettings = options.ExtensionSettings; var FontSettings = options.FontSettings; var HandlerOptions = options.HandlerOptions; var ImportDataOverlay = options.ImportDataOverlay; @@ -22,7 +21,6 @@ var IntentsView = options.IntentsView; var InstantConfirmOverlay = options.InstantConfirmOverlay; var LanguageOptions = options.LanguageOptions; var OptionsPage = options.OptionsPage; -var PackExtensionOverlay = options.PackExtensionOverlay; var PasswordManager = options.PasswordManager; var PersonalOptions = options.PersonalOptions; var Preferences = options.Preferences; @@ -173,10 +171,6 @@ function load() { OptionsPage.registerOverlay(ManageProfileOverlay.getInstance(), PersonalOptions.getInstance()); - OptionsPage.register(ExtensionSettings.getInstance()); - OptionsPage.registerOverlay(PackExtensionOverlay.getInstance(), - ExtensionSettings.getInstance()); - if (cr.isChromeOS) { OptionsPage.register(AccountsOptions.getInstance()); OptionsPage.registerSubPage(ProxyOptions.getInstance(), diff --git a/chrome/browser/resources/options2/options_bundle.js b/chrome/browser/resources/options2/options_bundle.js index f6e9939..9254c5f 100644 --- a/chrome/browser/resources/options2/options_bundle.js +++ b/chrome/browser/resources/options2/options_bundle.js @@ -64,8 +64,6 @@ <include src="content_settings_ui.js"></include> <include src="cookies_list.js"></include> <include src="cookies_view.js"></include> -<include src="extension_list.js"></include> -<include src="extension_settings.js"></include> <include src="font_settings.js"></include> <if expr="pp_ifdef('enable_register_protocol_handler')"> <include src="handler_options.js"></script> @@ -81,7 +79,6 @@ <include src="language_list.js"></include> <include src="language_options.js"></include> <include src="manage_profile_overlay.js"></include> -<include src="pack_extension_overlay.js"></include> <include src="password_manager.js"></include> <include src="password_manager_list.js"></include> <include src="personal_options.js"></include> diff --git a/chrome/browser/resources/options2/pack_extension_overlay.css b/chrome/browser/resources/options2/pack_extension_overlay.css deleted file mode 100644 index 169750b..0000000 --- a/chrome/browser/resources/options2/pack_extension_overlay.css +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright (c) 2011 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. -*/ - -.packExtensionHeading { - width: 520px; - padding-bottom: 5px; -} - -.packExtensionTextBoxes { - text-align: right; -} - -.packExtensionTextArea { - width: 260px; -} diff --git a/chrome/browser/resources/options2/pack_extension_overlay.html b/chrome/browser/resources/options2/pack_extension_overlay.html deleted file mode 100644 index bd77789..0000000 --- a/chrome/browser/resources/options2/pack_extension_overlay.html +++ /dev/null @@ -1,28 +0,0 @@ -<div id="packExtensionOverlay" class="page" hidden> - <h1 i18n-content="packExtensionOverlay"></h1> - <div id="cbdContentArea" class="content-area"> - <div class="packExtensionHeading" i18n-content="packExtensionHeading"></div> - <div class="packExtensionTextBoxes"> - <label i18n-content="packExtensionRootDir"></label> - <input class="packExtensionTextArea" id="extensionRootDir" type="text" /> - <button id="browseExtensionDir" - i18n-content="packExtensionBrowseButton"></button> - </div> - <div class="packExtensionTextBoxes"> - <label i18n-content="packExtensionPrivateKey"></label> - <input class="packExtensionTextArea" - id="extensionPrivateKey" type="text" /> - <button id="browsePrivateKey" - i18n-content="packExtensionBrowseButton"></button> - </div> - </div> - <div class="action-area"> - <div class="action-area-right"> - <div class="button-strip"> - <button id="packExtensionDismiss" i18n-content="cancel"></button> - <button id="packExtensionCommit" - i18n-content="packExtensionCommit"></button> - </div> - </div> - </div> -</div>
\ No newline at end of file diff --git a/chrome/browser/resources/options2/pack_extension_overlay.js b/chrome/browser/resources/options2/pack_extension_overlay.js deleted file mode 100644 index 4154dcd..0000000 --- a/chrome/browser/resources/options2/pack_extension_overlay.js +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2011 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. - -cr.define('options', function() { - const OptionsPage = options.OptionsPage; - - /** - * PackExtensionOverlay class - * Encapsulated handling of the 'Pack Extension' overlay page. - * @constructor - */ - function PackExtensionOverlay() { - OptionsPage.call(this, 'packExtensionOverlay', - templateData.packExtensionOverlayTabTitle, - 'packExtensionOverlay'); - } - - cr.addSingletonGetter(PackExtensionOverlay); - - PackExtensionOverlay.prototype = { - // Inherit PackExtensionOverlay from OptionsPage. - __proto__: OptionsPage.prototype, - - /** - * Initialize the page. - */ - initializePage: function() { - // Call base class implementation to starts preference initialization. - OptionsPage.prototype.initializePage.call(this); - - $('packExtensionDismiss').onclick = function(event) { - OptionsPage.closeOverlay(); - }; - $('packExtensionCommit').onclick = function(event) { - var extensionPath = $('extensionRootDir').value; - var privateKeyPath = $('extensionPrivateKey').value; - chrome.send('pack', [extensionPath, privateKeyPath]); - }; - $('browseExtensionDir').addEventListener('click', - this.handleBrowseExtensionDir_.bind(this)); - $('browsePrivateKey').addEventListener('click', - this.handleBrowsePrivateKey_.bind(this)); - }, - - /** - * Utility function which asks the C++ to show a platform-specific file - * select dialog, and fire |callback| with the |filePath| that resulted. - * |selectType| can be either 'file' or 'folder'. |operation| can be 'load', - * 'packRoot', or 'pem' which are signals to the C++ to do some - * operation-specific configuration. - * @private - */ - showFileDialog_: function(selectType, operation, callback) { - handleFilePathSelected = function(filePath) { - callback(filePath); - handleFilePathSelected = function() {}; - }; - - chrome.send('extensionSettingsSelectFilePath', [selectType, operation]); - }, - - /** - * Handles the showing of the extension directory browser. - * @param {Event} e Change event. - * @private - */ - handleBrowseExtensionDir_: function(e) { - this.showFileDialog_('folder', 'load', function(filePath) { - $('extensionRootDir').value = filePath; - }); - }, - - /** - * Handles the showing of the extension private key file. - * @param {Event} e Change event. - * @private - */ - handleBrowsePrivateKey_: function(e) { - this.showFileDialog_('file', 'load', function(filePath) { - $('extensionPrivateKey').value = filePath; - }); - }, - }; - - // Export - return { - PackExtensionOverlay: PackExtensionOverlay - }; -}); diff --git a/chrome/browser/resources/options2/zippy.png b/chrome/browser/resources/options2/zippy.png Binary files differdeleted file mode 100644 index c16f42e..0000000 --- a/chrome/browser/resources/options2/zippy.png +++ /dev/null diff --git a/chrome/browser/ui/webui/options2/extension_settings_handler.cc b/chrome/browser/ui/webui/options2/extension_settings_handler.cc deleted file mode 100644 index fddf7f1..0000000 --- a/chrome/browser/ui/webui/options2/extension_settings_handler.cc +++ /dev/null @@ -1,785 +0,0 @@ -// Copyright (c) 2011 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. - -#include "chrome/browser/ui/webui/options2/extension_settings_handler.h" - -#include "base/auto_reset.h" -#include "base/base64.h" -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/string_number_conversions.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "base/version.h" -#include "chrome/browser/debugger/devtools_window.h" -#include "chrome/browser/extensions/crx_installer.h" -#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_updater.h" -#include "chrome/browser/extensions/extension_warning_set.h" -#include "chrome/browser/extensions/unpacked_installer.h" -#include "chrome/browser/google/google_util.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/tab_contents/background_contents.h" -#include "chrome/browser/ui/webui/extensions/extension_icon_source.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/chrome_view_type.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "content/browser/browsing_instance.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/tab_contents/tab_contents_view.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" -#include "grit/browser_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -namespace { - -bool ShouldShowExtension(const Extension* extension) { - // Don't show themes since this page's UI isn't really useful for themes. - if (extension->is_theme()) - return false; - - // Don't show component extensions because they are only extensions as an - // implementation detail of Chrome. - if (extension->location() == Extension::COMPONENT && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kShowComponentExtensionOptions)) - return false; - - // Always show unpacked extensions and apps. - if (extension->location() == Extension::LOAD) - return true; - - // Unless they are unpacked, never show hosted apps. - if (extension->is_hosted_app()) - return false; - - return true; -} - -} // namespace - -/////////////////////////////////////////////////////////////////////////////// -// -// ExtensionSettingsHandler -// -/////////////////////////////////////////////////////////////////////////////// - -ExtensionSettingsHandler::ExtensionSettingsHandler() - : extension_service_(NULL), - ignore_notifications_(false), - deleting_rvh_(NULL), - registered_for_notifications_(false) { -} - -ExtensionSettingsHandler::~ExtensionSettingsHandler() { - // There may be pending file dialogs, we need to tell them that we've gone - // away so they don't try and call back to us. - if (load_extension_dialog_.get()) - load_extension_dialog_->ListenerDestroyed(); - - registrar_.RemoveAll(); -} - -// static -void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, - false, - PrefService::SYNCABLE_PREF); -} - -void ExtensionSettingsHandler::RegisterMessages() { - web_ui_->RegisterMessageCallback("extensionSettingsRequestExtensionsData", - base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", - base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsInspect", - base::Bind(&ExtensionSettingsHandler::HandleInspectMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsReload", - base::Bind(&ExtensionSettingsHandler::HandleReloadMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsEnable", - base::Bind(&ExtensionSettingsHandler::HandleEnableMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsEnableIncognito", - base::Bind(&ExtensionSettingsHandler::HandleEnableIncognitoMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsAllowFileAccess", - base::Bind(&ExtensionSettingsHandler::HandleAllowFileAccessMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsUninstall", - base::Bind(&ExtensionSettingsHandler::HandleUninstallMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsOptions", - base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsShowButton", - base::Bind(&ExtensionSettingsHandler::HandleShowButtonMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsLoad", - base::Bind(&ExtensionSettingsHandler::HandleLoadMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsAutoupdate", - base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, - base::Unretained(this))); - web_ui_->RegisterMessageCallback("extensionSettingsSelectFilePath", - base::Bind(&ExtensionSettingsHandler::HandleSelectFilePathMessage, - base::Unretained(this))); -} - -void ExtensionSettingsHandler::HandleRequestExtensionsData( - const ListValue* args) { - DictionaryValue results; - - // Add the extensions to the results structure. - ListValue *extensions_list = new ListValue(); - - ExtensionWarningSet* warnings = extension_service_->extension_warnings(); - - const ExtensionSet* extensions = extension_service_->extensions(); - for (ExtensionSet::const_iterator extension = extensions->begin(); - extension != extensions->end(); ++extension) { - if (ShouldShowExtension(*extension)) { - extensions_list->Append(CreateExtensionDetailValue( - extension_service_, - *extension, - GetActivePagesForExtension(*extension), - warnings, - true, false)); // enabled, terminated - } - } - extensions = extension_service_->disabled_extensions(); - for (ExtensionSet::const_iterator extension = extensions->begin(); - extension != extensions->end(); ++extension) { - if (ShouldShowExtension(*extension)) { - extensions_list->Append(CreateExtensionDetailValue( - extension_service_, - *extension, - GetActivePagesForExtension(*extension), - warnings, - false, false)); // enabled, terminated - } - } - extensions = extension_service_->terminated_extensions(); - std::vector<ExtensionPage> empty_pages; - for (ExtensionSet::const_iterator extension = extensions->begin(); - extension != extensions->end(); ++extension) { - if (ShouldShowExtension(*extension)) { - extensions_list->Append(CreateExtensionDetailValue( - extension_service_, - *extension, - empty_pages, // Terminated process has no active pages. - warnings, - false, true)); // enabled, terminated - } - } - results.Set("extensions", extensions_list); - - Profile* profile = Profile::FromWebUI(web_ui_); - bool developer_mode = - profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); - results.SetBoolean("developerMode", developer_mode); - - web_ui_->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", - results); - - MaybeRegisterForNotifications(); -} - -void ExtensionSettingsHandler::MaybeRegisterForNotifications() { - if (registered_for_notifications_) - return; - - registered_for_notifications_ = true; - Profile* profile = Profile::FromWebUI(web_ui_); - - // Register for notifications that we need to reload the page. - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, - content::Source<Profile>(profile)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, - content::Source<Profile>(profile)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, - content::Source<Profile>(profile)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, - content::Source<Profile>(profile)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, - content::NotificationService::AllBrowserContextsAndSources()); - registrar_.Add(this, - content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, - content::NotificationService::AllBrowserContextsAndSources()); - registrar_.Add(this, - content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, - content::NotificationService::AllBrowserContextsAndSources()); - registrar_.Add(this, - chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, - content::NotificationService::AllBrowserContextsAndSources()); - registrar_.Add(this, - chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, - content::NotificationService::AllBrowserContextsAndSources()); - registrar_.Add( - this, - chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, - content::Source<ExtensionPrefs>(profile->GetExtensionService()-> - extension_prefs())); -} - -ExtensionUninstallDialog* -ExtensionSettingsHandler::GetExtensionUninstallDialog() { - if (!extension_uninstall_dialog_.get()) { - extension_uninstall_dialog_.reset( - ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui_), this)); - } - return extension_uninstall_dialog_.get(); -} - -void ExtensionSettingsHandler::HandleToggleDeveloperMode( - const ListValue* args) { - Profile* profile = Profile::FromWebUI(web_ui_); - bool developer_mode = - profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); - profile->GetPrefs()->SetBoolean( - prefs::kExtensionsUIDeveloperMode, !developer_mode); - HandleRequestExtensionsData(NULL); -} - -void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { - std::string render_process_id_str; - std::string render_view_id_str; - int render_process_id; - int render_view_id; - CHECK_EQ(2U, args->GetSize()); - CHECK(args->GetString(0, &render_process_id_str)); - CHECK(args->GetString(1, &render_view_id_str)); - CHECK(base::StringToInt(render_process_id_str, &render_process_id)); - CHECK(base::StringToInt(render_view_id_str, &render_view_id)); - RenderViewHost* host = RenderViewHost::FromID(render_process_id, - render_view_id); - if (!host) { - // This can happen if the host has gone away since the page was displayed. - return; - } - - DevToolsWindow::OpenDevToolsWindow(host); -} - -void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { - std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); - CHECK(!extension_id.empty()); - extension_service_->ReloadExtension(extension_id); -} - -void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { - CHECK_EQ(2U, args->GetSize()); - std::string extension_id, enable_str; - CHECK(args->GetString(0, &extension_id)); - CHECK(args->GetString(1, &enable_str)); - - const Extension* extension = - extension_service_->GetExtensionById(extension_id, true); - if (!Extension::UserMayDisable(extension->location())) { - LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" - << "made. Extension id: " << extension->id(); - return; - } - - if (enable_str == "true") { - ExtensionPrefs* prefs = extension_service_->extension_prefs(); - if (prefs->DidExtensionEscalatePermissions(extension_id)) { - ShowExtensionDisabledDialog(extension_service_, - Profile::FromWebUI(web_ui_), extension); - } else { - extension_service_->EnableExtension(extension_id); - } - } else { - extension_service_->DisableExtension(extension_id); - } -} - -void ExtensionSettingsHandler::HandleEnableIncognitoMessage( - const ListValue* args) { - CHECK_EQ(2U, args->GetSize()); - std::string extension_id, enable_str; - CHECK(args->GetString(0, &extension_id)); - CHECK(args->GetString(1, &enable_str)); - const Extension* extension = - extension_service_->GetExtensionById(extension_id, true); - DCHECK(extension); - - // Flipping the incognito bit will generate unload/load notifications for the - // extension, but we don't want to reload the page, because a) we've already - // updated the UI to reflect the change, and b) we want the yellow warning - // text to stay until the user has left the page. - // - // TODO(aa): This creates crapiness in some cases. For example, in a main - // window, when toggling this, the browser action will flicker because it gets - // unloaded, then reloaded. It would be better to have a dedicated - // notification for this case. - // - // Bug: http://crbug.com/41384 - AutoReset<bool> auto_reset_ignore_notifications(&ignore_notifications_, true); - extension_service_->SetIsIncognitoEnabled(extension->id(), - enable_str == "true"); -} - -void ExtensionSettingsHandler::HandleAllowFileAccessMessage( - const ListValue* args) { - CHECK_EQ(2U, args->GetSize()); - std::string extension_id, allow_str; - CHECK(args->GetString(0, &extension_id)); - CHECK(args->GetString(1, &allow_str)); - const Extension* extension = - extension_service_->GetExtensionById(extension_id, true); - DCHECK(extension); - - if (!Extension::UserMayDisable(extension->location())) { - LOG(ERROR) << "Attempt to change allow file access of an extension that is " - << "non-usermanagable was made. Extension id : " - << extension->id(); - return; - } - - extension_service_->SetAllowFileAccess(extension, allow_str == "true"); -} - -void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { - std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); - CHECK(!extension_id.empty()); - const Extension* extension = - extension_service_->GetExtensionById(extension_id, true); - if (!extension) - extension = extension_service_->GetTerminatedExtension(extension_id); - if (!extension) - return; - - if (!Extension::UserMayDisable(extension->location())) { - LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " - << "was made. Extension id : " << extension->id(); - return; - } - - if (!extension_id_prompting_.empty()) - return; // Only one prompt at a time. - - extension_id_prompting_ = extension_id; - - GetExtensionUninstallDialog()->ConfirmUninstall(extension); -} - -void ExtensionSettingsHandler::ExtensionUninstallAccepted() { - DCHECK(!extension_id_prompting_.empty()); - - bool was_terminated = false; - - // The extension can be uninstalled in another window while the UI was - // showing. Do nothing in that case. - const Extension* extension = - extension_service_->GetExtensionById(extension_id_prompting_, true); - if (!extension) { - extension = extension_service_->GetTerminatedExtension( - extension_id_prompting_); - was_terminated = true; - } - if (!extension) - return; - - extension_service_->UninstallExtension(extension_id_prompting_, - false, // External uninstall. - NULL); // Error. - extension_id_prompting_ = ""; - - // There will be no EXTENSION_UNLOADED notification for terminated - // extensions as they were already unloaded. - if (was_terminated) - HandleRequestExtensionsData(NULL); -} - -void ExtensionSettingsHandler::ExtensionUninstallCanceled() { - extension_id_prompting_ = ""; -} - -void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) { - const Extension* extension = GetExtension(args); - if (!extension || extension->options_url().is_empty()) - return; - Profile::FromWebUI(web_ui_)->GetExtensionProcessManager()->OpenOptionsPage( - extension, NULL); -} - -void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) { - const Extension* extension = GetExtension(args); - extension_service_->SetBrowserActionVisibility(extension, true); -} - -void ExtensionSettingsHandler::HandleLoadMessage(const ListValue* args) { - FilePath::StringType string_path; - CHECK_EQ(1U, args->GetSize()) << args->GetSize(); - CHECK(args->GetString(0, &string_path)); - extensions::UnpackedInstaller::Create(extension_service_)-> - Load(FilePath(string_path)); -} - -void ExtensionSettingsHandler::ShowAlert(const std::string& message) { - ListValue arguments; - arguments.Append(Value::CreateStringValue(message)); - web_ui_->CallJavascriptFunction("alert", arguments); -} - -void ExtensionSettingsHandler::HandleAutoUpdateMessage(const ListValue* args) { - ExtensionUpdater* updater = extension_service_->updater(); - if (updater) - updater->CheckNow(); -} - -void ExtensionSettingsHandler::HandleSelectFilePathMessage( - const ListValue* args) { - std::string select_type; - std::string operation; - CHECK_EQ(2U, args->GetSize()); - CHECK(args->GetString(0, &select_type)); - CHECK(args->GetString(1, &operation)); - - SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; - SelectFileDialog::FileTypeInfo info; - int file_type_index = 0; - if (select_type == "file") - type = SelectFileDialog::SELECT_OPEN_FILE; - - string16 select_title; - if (operation == "load") { - select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); - } else if (operation == "packRoot") { - select_title = l10n_util::GetStringUTF16( - IDS_EXTENSION_PACK_DIALOG_SELECT_ROOT); - } else if (operation == "pem") { - select_title = l10n_util::GetStringUTF16( - IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); - info.extensions.push_back(std::vector<FilePath::StringType>()); - info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); - info.extension_description_overrides.push_back( - l10n_util::GetStringUTF16( - IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); - info.include_all_files = true; - file_type_index = 1; - } else { - NOTREACHED(); - return; - } - - load_extension_dialog_ = SelectFileDialog::Create(this); - load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, - file_type_index, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), - web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); -} - - -void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, - void* params) { - // Add the extensions to the results structure. - ListValue results; - results.Append(Value::CreateStringValue(path.value())); - web_ui_->CallJavascriptFunction("window.handleFilePathSelected", results); -} - -void ExtensionSettingsHandler::MultiFilesSelected( - const std::vector<FilePath>& files, void* params) { - NOTREACHED(); -} - -void ExtensionSettingsHandler::GetLocalizedValues( - DictionaryValue* localized_strings) { - DCHECK(localized_strings); - - RegisterTitle(localized_strings, "extensionSettings", - IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); - - localized_strings->SetString("extensionSettingsVisitWebsite", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); - - localized_strings->SetString("extensionSettingsDeveloperMode", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); - localized_strings->SetString("extensionSettingsNoExtensions", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); - localized_strings->SetString("extensionSettingsSuggestGallery", - l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, - ASCIIToUTF16("<a href='") + - ASCIIToUTF16(google_util::AppendGoogleLocaleParam( - GURL(extension_urls::GetWebstoreLaunchURL())).spec()) + - ASCIIToUTF16("'>"), - ASCIIToUTF16("</a>"))); - localized_strings->SetString("extensionSettingsGetMoreExtensions", - ASCIIToUTF16("<a href='") + - ASCIIToUTF16(google_util::AppendGoogleLocaleParam( - GURL(extension_urls::GetWebstoreLaunchURL())).spec()) + - ASCIIToUTF16("'>") + - l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS) + - ASCIIToUTF16("</a>")); - localized_strings->SetString("extensionSettingsExtensionId", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); - localized_strings->SetString("extensionSettingsExtensionPath", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH)); - localized_strings->SetString("extensionSettingsInspectViews", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); - localized_strings->SetString("viewIncognito", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); - localized_strings->SetString("extensionSettingsEnable", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); - localized_strings->SetString("extensionSettingsEnabled", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED)); - localized_strings->SetString("extensionSettingsRemove", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE)); - localized_strings->SetString("extensionSettingsEnableIncognito", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); - localized_strings->SetString("extensionSettingsAllowFileAccess", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); - localized_strings->SetString("extensionSettingsIncognitoWarning", - l10n_util::GetStringFUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); - localized_strings->SetString("extensionSettingsReload", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); - localized_strings->SetString("extensionSettingsOptions", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS)); - localized_strings->SetString("extensionSettingsPolicyControlled", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); - localized_strings->SetString("extensionSettingsShowButton", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); - localized_strings->SetString("extensionSettingsLoadUnpackedButton", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); - localized_strings->SetString("extensionSettingsPackButton", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); - localized_strings->SetString("extensionSettingsUpdateButton", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); - localized_strings->SetString("extensionSettingsCrashMessage", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); - localized_strings->SetString("extensionSettingsInDevelopment", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); - localized_strings->SetString("extensionSettingsWarningsTitle", - l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE)); - localized_strings->SetString("extensionSettingsShowDetails", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); - localized_strings->SetString("extensionSettingsHideDetails", - l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); -} - -void ExtensionSettingsHandler::Initialize() { -} - -WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) { - // Call through to superclass. - WebUIMessageHandler* handler = OptionsPage2UIHandler::Attach(web_ui); - - extension_service_ = Profile::FromWebUI(web_ui_) - ->GetOriginalProfile()->GetExtensionService(); - - // Return result from the superclass. - return handler; -} - -void ExtensionSettingsHandler::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - Profile* profile = Profile::FromWebUI(web_ui_); - Profile* source_profile = NULL; - switch (type) { - // We listen for notifications that will result in the page being - // repopulated with data twice for the same event in certain cases. - // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because - // we don't know about the views for an extension at EXTENSION_LOADED, but - // if we only listen to EXTENSION_HOST_CREATED, we'll miss extensions - // that don't have a process at startup. - // - // Doing it this way gets everything but causes the page to be rendered - // more than we need. It doesn't seem to result in any noticeable flicker. - case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: - deleting_rvh_ = content::Source<RenderViewHost>(source).ptr(); - // Fall through. - case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: - source_profile = Profile::FromBrowserContext( - content::Source<RenderViewHost>(source)->site_instance()-> - browsing_instance()->browser_context()); - if (!profile->IsSameProfile(source_profile)) - return; - MaybeUpdateAfterNotification(); - break; - case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: - deleting_rvh_ = content::Details<BackgroundContents>(details)-> - tab_contents()->render_view_host(); - // Fall through. - case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: - case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: - source_profile = content::Source<Profile>(source).ptr(); - if (!profile->IsSameProfile(source_profile)) - return; - MaybeUpdateAfterNotification(); - break; - case chrome::NOTIFICATION_EXTENSION_LOADED: - case chrome::NOTIFICATION_EXTENSION_UNLOADED: - case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: - case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: - case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: - MaybeUpdateAfterNotification(); - break; - default: - NOTREACHED(); - } -} - -const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { - std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); - CHECK(!extension_id.empty()); - return extension_service_->GetExtensionById(extension_id, true); -} - -void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { - TabContents* contents = web_ui_->tab_contents(); - if (!ignore_notifications_ && contents && contents->render_view_host()) - HandleRequestExtensionsData(NULL); - deleting_rvh_ = NULL; -} - -// Static -DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( - ExtensionService* service, const Extension* extension, - const std::vector<ExtensionPage>& pages, - const ExtensionWarningSet* warnings_set, - bool enabled, bool terminated) { - DictionaryValue* extension_data = new DictionaryValue(); - GURL icon = - ExtensionIconSource::GetIconURL(extension, - Extension::EXTENSION_ICON_MEDIUM, - ExtensionIconSet::MATCH_BIGGER, - !enabled, NULL); - extension_data->SetString("id", extension->id()); - extension_data->SetString("name", extension->name()); - extension_data->SetString("description", extension->description()); - if (extension->location() == Extension::LOAD) - extension_data->SetString("path", extension->path().value()); - extension_data->SetString("version", extension->version()->GetString()); - extension_data->SetString("icon", icon.spec()); - extension_data->SetBoolean("isUnpacked", - extension->location() == Extension::LOAD); - extension_data->SetBoolean("mayDisable", - Extension::UserMayDisable(extension->location())); - extension_data->SetBoolean("enabled", enabled); - extension_data->SetBoolean("terminated", terminated); - extension_data->SetBoolean("enabledIncognito", - service ? service->IsIncognitoEnabled(extension->id()) : false); - extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); - extension_data->SetBoolean("allowFileAccess", - service ? service->AllowFileAccess(extension) : false); - extension_data->SetBoolean("allow_reload", - extension->location() == Extension::LOAD); - extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); - - // Determine the sort order: Extensions loaded through --load-extensions show - // up at the top. Disabled extensions show up at the bottom. - if (extension->location() == Extension::LOAD) - extension_data->SetInteger("order", 1); - else - extension_data->SetInteger("order", 2); - - if (!extension->options_url().is_empty() && enabled) - extension_data->SetString("options_url", extension->options_url().spec()); - - if (service && !service->GetBrowserActionVisibility(extension)) - extension_data->SetBoolean("enable_show_button", true); - - // Add views - ListValue* views = new ListValue; - for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); - iter != pages.end(); ++iter) { - DictionaryValue* view_value = new DictionaryValue; - if (iter->url.scheme() == chrome::kExtensionScheme) { - // No leading slash. - view_value->SetString("path", iter->url.path().substr(1)); - } else { - // For live pages, use the full URL. - view_value->SetString("path", iter->url.spec()); - } - view_value->SetInteger("renderViewId", iter->render_view_id); - view_value->SetInteger("renderProcessId", iter->render_process_id); - view_value->SetBoolean("incognito", iter->incognito); - views->Append(view_value); - } - extension_data->Set("views", views); - extension_data->SetBoolean("hasPopupAction", - extension->browser_action() || extension->page_action()); - extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); - - // Add warnings. - ListValue* warnings_list = new ListValue; - if (warnings_set) { - std::set<ExtensionWarningSet::WarningType> warnings; - warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); - - for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = - warnings.begin(); - iter != warnings.end(); - ++iter) { - string16 warning_string(ExtensionWarningSet::GetLocalizedWarning(*iter)); - warnings_list->Append(Value::CreateStringValue(warning_string)); - } - } - extension_data->Set("warnings", warnings_list); - - return extension_data; -} - -std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( - const Extension* extension) { - std::vector<ExtensionPage> result; - - // Get the extension process's active views. - ExtensionProcessManager* process_manager = - extension_service_->profile()->GetExtensionProcessManager(); - GetActivePagesForExtensionProcess( - process_manager->GetRenderViewHostsForExtension( - extension->id()), &result); - - // Repeat for the incognito process, if applicable. - if (extension_service_->profile()->HasOffTheRecordProfile() && - extension->incognito_split_mode()) { - ExtensionProcessManager* process_manager = - extension_service_->profile()->GetOffTheRecordProfile()-> - GetExtensionProcessManager(); - GetActivePagesForExtensionProcess( - process_manager->GetRenderViewHostsForExtension( - extension->id()), &result); - } - - return result; -} - -void ExtensionSettingsHandler::GetActivePagesForExtensionProcess( - const std::set<RenderViewHost*>& views, - std::vector<ExtensionPage> *result) { - for (std::set<RenderViewHost*>::const_iterator iter = views.begin(); - iter != views.end(); ++iter) { - RenderViewHost* host = *iter; - int host_type = host->delegate()->GetRenderViewType(); - if (host == deleting_rvh_ || - chrome::VIEW_TYPE_EXTENSION_POPUP == host_type || - chrome::VIEW_TYPE_EXTENSION_DIALOG == host_type) - continue; - - GURL url = host->delegate()->GetURL(); - content::RenderProcessHost* process = host->process(); - result->push_back( - ExtensionPage(url, process->GetID(), host->routing_id(), - process->GetBrowserContext()->IsOffTheRecord())); - } -} diff --git a/chrome/browser/ui/webui/options2/extension_settings_handler.h b/chrome/browser/ui/webui/options2/extension_settings_handler.h deleted file mode 100644 index 9ac9713..0000000 --- a/chrome/browser/ui/webui/options2/extension_settings_handler.h +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_EXTENSION_SETTINGS_HANDLER_H_ -#define CHROME_BROWSER_UI_WEBUI_OPTIONS2_EXTENSION_SETTINGS_HANDLER_H_ -#pragma once - -#include <set> -#include <string> -#include <vector> - -#include "chrome/browser/extensions/extension_install_ui.h" -#include "chrome/browser/extensions/extension_uninstall_dialog.h" -#include "chrome/browser/extensions/extension_warning_set.h" -#include "chrome/browser/ui/select_file_dialog.h" -#include "chrome/browser/ui/webui/options2/options_ui2.h" -#include "chrome/browser/ui/webui/chrome_web_ui.h" -#include "chrome/common/extensions/extension_resource.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "googleurl/src/gurl.h" - -class Extension; -class ExtensionService; -class FilePath; -class PrefService; -class UserScript; - -namespace base { -class DictionaryValue; -class ListValue; -} - -// Information about a page running in an extension, for example a popup bubble, -// a background page, or a tab contents. -struct ExtensionPage { - ExtensionPage(const GURL& url, int render_process_id, int render_view_id, - bool incognito) - : url(url), - render_process_id(render_process_id), - render_view_id(render_view_id), - incognito(incognito) {} - GURL url; - int render_process_id; - int render_view_id; - bool incognito; -}; - -// Extension Settings UI handler. -class ExtensionSettingsHandler : public OptionsPage2UIHandler, - public SelectFileDialog::Listener, - public ExtensionUninstallDialog::Delegate { - public: - ExtensionSettingsHandler(); - virtual ~ExtensionSettingsHandler(); - - static void RegisterUserPrefs(PrefService* prefs); - - // Extension Detail JSON Struct for page. (static for ease of testing). - // Note: |service| and |warnings| can be NULL in unit tests. - static base::DictionaryValue* CreateExtensionDetailValue( - ExtensionService* service, - const Extension* extension, - const std::vector<ExtensionPage>& pages, - const ExtensionWarningSet* warnings, - bool enabled, - bool terminated); - - // ContentScript JSON Struct for page. (static for ease of testing). - static base::DictionaryValue* CreateContentScriptDetailValue( - const UserScript& script, - const FilePath& extension_path); - - // Callback for "requestExtensionsData" message. - void HandleRequestExtensionsData(const base::ListValue* args); - - // Callback for "toggleDeveloperMode" message. - void HandleToggleDeveloperMode(const base::ListValue* args); - - // Callback for "inspect" message. - void HandleInspectMessage(const base::ListValue* args); - - // Callback for "reload" message. - void HandleReloadMessage(const base::ListValue* args); - - // Callback for "enable" message. - void HandleEnableMessage(const base::ListValue* args); - - // Callback for "enableIncognito" message. - void HandleEnableIncognitoMessage(const base::ListValue* args); - - // Callback for "allowFileAcces" message. - void HandleAllowFileAccessMessage(const base::ListValue* args); - - // Callback for "uninstall" message. - void HandleUninstallMessage(const base::ListValue* args); - - // Callback for "options" message. - void HandleOptionsMessage(const base::ListValue* args); - - // Callback for "showButton" message. - void HandleShowButtonMessage(const base::ListValue* args); - - // Callback for "load" message. - void HandleLoadMessage(const base::ListValue* args); - - // Callback for "pack" message. - void HandlePackMessage(const base::ListValue* args); - - // Callback for "autoupdate" message. - void HandleAutoUpdateMessage(const base::ListValue* args); - - // Utility for calling javascript window.alert in the page. - void ShowAlert(const std::string& message); - - // Callback for "selectFilePath" message. - void HandleSelectFilePathMessage(const base::ListValue* args); - - // Utility for callbacks that get an extension ID as the sole argument. - const Extension* GetExtension(const base::ListValue* args); - - // Forces a UI update if appropriate after a notification is received. - void MaybeUpdateAfterNotification(); - - // Register for notifications that we need to reload the page. - void MaybeRegisterForNotifications(); - - // SelectFileDialog::Listener - virtual void FileSelected(const FilePath& path, - int index, void* params) OVERRIDE; - virtual void MultiFilesSelected( - const std::vector<FilePath>& files, void* params) OVERRIDE; - virtual void FileSelectionCanceled(void* params) OVERRIDE {} - - // WebUIMessageHandler implementation. - virtual void RegisterMessages() OVERRIDE; - virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; - - // OptionsUIHandler implementation. - virtual void GetLocalizedValues( - base::DictionaryValue* localized_strings) OVERRIDE; - virtual void Initialize() OVERRIDE; - - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - // ExtensionUninstallDialog::Delegate implementation, used for receiving - // notification about uninstall confirmation dialog selections. - virtual void ExtensionUninstallAccepted() OVERRIDE; - virtual void ExtensionUninstallCanceled() OVERRIDE; - - private: - // Helper that lists the current active html pages for an extension. - std::vector<ExtensionPage> GetActivePagesForExtension( - const Extension* extension); - void GetActivePagesForExtensionProcess( - const std::set<RenderViewHost*>& views, - std::vector<ExtensionPage> *result); - - // Returns the ExtensionUninstallDialog object for this class, creating it if - // needed. - ExtensionUninstallDialog* GetExtensionUninstallDialog(); - - // Our model. Outlives us since it's owned by our containing profile. - ExtensionService* extension_service_; - - // Used to pick the directory when loading an extension. - scoped_refptr<SelectFileDialog> load_extension_dialog_; - - // Used to show confirmation UI for uninstalling extensions in incognito mode. - scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; - - // The id of the extension we are prompting the user about. - std::string extension_id_prompting_; - - // If true, we will ignore notifications in ::Observe(). This is needed - // to prevent reloading the page when we were the cause of the - // notification. - bool ignore_notifications_; - - // The page may be refreshed in response to a RENDER_VIEW_HOST_DELETED, - // but the iteration over RenderViewHosts will include the host because the - // notification is sent when it is in the process of being deleted (and before - // it is removed from the process). Keep a pointer to it so we can exclude - // it from the active views. - RenderViewHost* deleting_rvh_; - - // We want to register for notifications only after we've responded at least - // once to the page, otherwise we'd be calling javacsript functions on objects - // that don't exist yet when notifications come in. This variable makes sure - // we do so only once. - bool registered_for_notifications_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsHandler); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_EXTENSION_SETTINGS_HANDLER_H_ diff --git a/chrome/browser/ui/webui/options2/options_ui2.cc b/chrome/browser/ui/webui/options2/options_ui2.cc index 879361a..c30742c 100644 --- a/chrome/browser/ui/webui/options2/options_ui2.cc +++ b/chrome/browser/ui/webui/options2/options_ui2.cc @@ -26,14 +26,12 @@ #include "chrome/browser/ui/webui/options2/content_settings_handler.h" #include "chrome/browser/ui/webui/options2/cookies_view_handler.h" #include "chrome/browser/ui/webui/options2/core_options_handler.h" -#include "chrome/browser/ui/webui/options2/extension_settings_handler.h" #include "chrome/browser/ui/webui/options2/font_settings_handler.h" #include "chrome/browser/ui/webui/options2/handler_options_handler.h" #include "chrome/browser/ui/webui/options2/import_data_handler.h" #include "chrome/browser/ui/webui/options2/language_options_handler.h" #include "chrome/browser/ui/webui/options2/manage_profile_handler.h" #include "chrome/browser/ui/webui/options2/options_sync_setup_handler.h" -#include "chrome/browser/ui/webui/options2/pack_extension_handler.h" #include "chrome/browser/ui/webui/options2/password_manager_handler.h" #include "chrome/browser/ui/webui/options2/personal_options_handler.h" #include "chrome/browser/ui/webui/options2/search_engine_manager_handler.h" @@ -213,7 +211,6 @@ Options2UI::Options2UI(TabContents* contents) AddOptionsPageUIHandler(localized_strings, new ClearBrowserDataHandler()); AddOptionsPageUIHandler(localized_strings, new ContentSettingsHandler()); AddOptionsPageUIHandler(localized_strings, new CookiesViewHandler()); - AddOptionsPageUIHandler(localized_strings, new ExtensionSettingsHandler()); AddOptionsPageUIHandler(localized_strings, new FontSettingsHandler()); AddOptionsPageUIHandler(localized_strings, new WebIntentsSettingsHandler()); #if defined(OS_CHROMEOS) @@ -223,7 +220,6 @@ Options2UI::Options2UI(TabContents* contents) AddOptionsPageUIHandler(localized_strings, new LanguageOptionsHandler()); #endif AddOptionsPageUIHandler(localized_strings, new ManageProfileHandler()); - AddOptionsPageUIHandler(localized_strings, new PackExtensionHandler()); AddOptionsPageUIHandler(localized_strings, new PasswordManagerHandler()); AddOptionsPageUIHandler(localized_strings, new PersonalOptionsHandler()); AddOptionsPageUIHandler(localized_strings, new SearchEngineManagerHandler()); diff --git a/chrome/browser/ui/webui/options2/pack_extension_handler.cc b/chrome/browser/ui/webui/options2/pack_extension_handler.cc deleted file mode 100644 index 0790482..0000000 --- a/chrome/browser/ui/webui/options2/pack_extension_handler.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2011 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. - -#include "chrome/browser/ui/webui/options2/pack_extension_handler.h" - -#include "base/bind.h" -#include "base/utf_string_conversions.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -PackExtensionHandler::PackExtensionHandler() { -} - -PackExtensionHandler::~PackExtensionHandler() { - if (pack_job_.get()) - pack_job_->ClearClient(); -} - -void PackExtensionHandler::Initialize() { -} - -void PackExtensionHandler::GetLocalizedValues( - DictionaryValue* localized_strings) { - DCHECK(localized_strings); - RegisterTitle(localized_strings, "clearBrowserDataOverlay", - IDS_CLEAR_BROWSING_DATA_TITLE); - - localized_strings->SetString("packExtensionOverlay", - l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_TITLE)); - localized_strings->SetString("packExtensionHeading", - l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING)); - localized_strings->SetString("packExtensionCommit", - l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_BUTTON)); - localized_strings->SetString("packExtensionRootDir", - l10n_util::GetStringUTF16( - IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL)); - localized_strings->SetString("packExtensionPrivateKey", - l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL)); - localized_strings->SetString("packExtensionBrowseButton", - l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE)); -} - -void PackExtensionHandler::RegisterMessages() { - // Setup handlers specific to this panel. - web_ui_->RegisterMessageCallback("pack", - base::Bind(&PackExtensionHandler::HandlePackMessage, - base::Unretained(this))); -} - -void PackExtensionHandler::OnPackSuccess(const FilePath& crx_file, - const FilePath& pem_file) { - ListValue results; - web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay", results); - - ShowAlert(UTF16ToUTF8(PackExtensionJob::StandardSuccessMessage(crx_file, - pem_file))); -} - -void PackExtensionHandler::OnPackFailure(const std::string& error) { - ShowAlert(error); -} - -void PackExtensionHandler::HandlePackMessage(const ListValue* args) { - std::string extension_path; - std::string private_key_path; - CHECK_EQ(2U, args->GetSize()); - CHECK(args->GetString(0, &extension_path)); - CHECK(args->GetString(1, &private_key_path)); - - FilePath root_directory = - FilePath::FromWStringHack(UTF8ToWide(extension_path)); - FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path)); - - if (root_directory.empty()) { - if (extension_path.empty()) { - ShowAlert(l10n_util::GetStringUTF8( - IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED)); - } else { - ShowAlert(l10n_util::GetStringUTF8( - IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID)); - } - - return; - } - - if (!private_key_path.empty() && key_file.empty()) { - ShowAlert(l10n_util::GetStringUTF8( - IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID)); - return; - } - - pack_job_ = new PackExtensionJob(this, root_directory, key_file); - pack_job_->Start(); -} - -void PackExtensionHandler::ShowAlert(const std::string& message) { - ListValue arguments; - arguments.Append(Value::CreateStringValue(message)); - web_ui_->CallJavascriptFunction("alert", arguments); -} diff --git a/chrome/browser/ui/webui/options2/pack_extension_handler.h b/chrome/browser/ui/webui/options2/pack_extension_handler.h deleted file mode 100644 index 47b6f0a..0000000 --- a/chrome/browser/ui/webui/options2/pack_extension_handler.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_PACK_EXTENSION_HANDLER_H_ -#define CHROME_BROWSER_UI_WEBUI_OPTIONS2_PACK_EXTENSION_HANDLER_H_ -#pragma once - -#include <string> - -#include "chrome/browser/browsing_data_remover.h" -#include "chrome/browser/extensions/pack_extension_job.h" -#include "chrome/browser/plugin_data_remover_helper.h" -#include "chrome/browser/ui/webui/options2/options_ui2.h" - -// Clear browser data handler page UI handler. -class PackExtensionHandler : public OptionsPage2UIHandler, - public PackExtensionJob::Client { - public: - PackExtensionHandler(); - virtual ~PackExtensionHandler(); - - // OptionsPage2UIHandler implementation. - virtual void Initialize() OVERRIDE; - virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE; - - // WebUIMessageHandler implementation. - virtual void RegisterMessages() OVERRIDE; - - // ExtensionPackJob::Client - virtual void OnPackSuccess(const FilePath& crx_file, - const FilePath& key_file) OVERRIDE; - - virtual void OnPackFailure(const std::string& error) OVERRIDE; - - private: - // Javascript callback to start packing an extension. - void HandlePackMessage(const ListValue* args); - - // A function to ask the webpage to show an alert. - void ShowAlert(const std::string& message); - - // Used to package the extension. - scoped_refptr<PackExtensionJob> pack_job_; - - DISALLOW_COPY_AND_ASSIGN(PackExtensionHandler); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_PACK_EXTENSION_HANDLER_H_ |