Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 <include src="extension_error.js"> | 5 <include src="extension_error.js"> |
| 6 | 6 |
| 7 cr.define('options', function() { | 7 cr.define('options', function() { |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 * @type {Object.<string, string>} A map from extension id to last reloaded | 26 * @type {Object.<string, string>} A map from extension id to last reloaded |
| 27 * timestamp. The timestamp is recorded when the user click the 'Reload' | 27 * timestamp. The timestamp is recorded when the user click the 'Reload' |
| 28 * link. It is used to refresh the icon of an unpacked extension. | 28 * link. It is used to refresh the icon of an unpacked extension. |
| 29 * This persists between calls to decorate. | 29 * This persists between calls to decorate. |
| 30 */ | 30 */ |
| 31 var extensionReloadedTimestamp = {}; | 31 var extensionReloadedTimestamp = {}; |
| 32 | 32 |
| 33 ExtensionsList.prototype = { | 33 ExtensionsList.prototype = { |
| 34 __proto__: HTMLDivElement.prototype, | 34 __proto__: HTMLDivElement.prototype, |
| 35 | 35 |
| 36 /** | |
| 37 * Indicates whether an embedded options page that was navigated to through | |
| 38 * the '?options=' URL query has been shown to the user. This is necessary | |
| 39 * to prevent showExtensionNodes_ from opening the options more than once. | |
| 40 * @type {boolean} | |
| 41 * @private | |
| 42 */ | |
| 43 optionsShown_: false, | |
| 44 | |
| 36 /** @override */ | 45 /** @override */ |
| 37 decorate: function() { | 46 decorate: function() { |
| 38 this.textContent = ''; | 47 this.textContent = ''; |
| 39 | 48 |
| 40 this.showExtensionNodes_(); | 49 this.showExtensionNodes_(); |
| 41 }, | 50 }, |
| 42 | 51 |
| 43 getIdQueryParam_: function() { | 52 getIdQueryParam_: function() { |
| 44 return parseQueryParams(document.location)['id']; | 53 return parseQueryParams(document.location)['id']; |
| 45 }, | 54 }, |
| 46 | 55 |
| 56 getOptionsQueryParam_: function() { | |
| 57 return parseQueryParams(document.location)['options']; | |
| 58 }, | |
| 59 | |
| 47 /** | 60 /** |
| 48 * Creates all extension items from scratch. | 61 * Creates all extension items from scratch. |
| 49 * @private | 62 * @private |
| 50 */ | 63 */ |
| 51 showExtensionNodes_: function() { | 64 showExtensionNodes_: function() { |
| 52 // Iterate over the extension data and add each item to the list. | 65 // Iterate over the extension data and add each item to the list. |
| 53 this.data_.extensions.forEach(this.createNode_, this); | 66 this.data_.extensions.forEach(this.createNode_, this); |
| 54 | 67 |
| 55 var idToHighlight = this.getIdQueryParam_(); | 68 var idToHighlight = this.getIdQueryParam_(); |
| 56 if (idToHighlight && $(idToHighlight)) { | 69 if (idToHighlight && $(idToHighlight)) |
| 57 // Scroll offset should be calculated slightly higher than the actual | 70 this.scrollToNode_(idToHighlight); |
|
not at google - send to devlin
2014/08/25 18:11:07
I'm seeing some weird behaviour when you specify a
| |
| 58 // offset of the element being scrolled to, so that it ends up not all | 71 |
| 59 // the way at the top. That way it is clear that there are more elements | 72 var idToOpenOptions = this.getOptionsQueryParam_(); |
| 60 // above the element being scrolled to. | 73 if (idToOpenOptions && $(idToOpenOptions) && !this.optionsShown_) { |
| 61 var scrollFudge = 1.2; | 74 this.scrollToNode_(idToOpenOptions); |
| 62 var scrollTop = $(idToHighlight).offsetTop - scrollFudge * | 75 $(idToOpenOptions).querySelector('.options-link').click(); |
|
not at google - send to devlin
2014/08/25 18:11:07
Why clicking on this link? Seems kinda roundabout.
ericzeng
2014/08/25 21:42:34
Done.
| |
| 63 $(idToHighlight).clientHeight; | 76 this.optionsShown_ = true; |
| 64 setScrollTopForDocument(document, scrollTop); | |
| 65 } | 77 } |
| 66 | 78 |
| 67 if (this.data_.extensions.length == 0) | 79 if (this.data_.extensions.length == 0) |
| 68 this.classList.add('empty-extension-list'); | 80 this.classList.add('empty-extension-list'); |
| 69 else | 81 else |
| 70 this.classList.remove('empty-extension-list'); | 82 this.classList.remove('empty-extension-list'); |
| 71 }, | 83 }, |
| 72 | 84 |
| 73 /** | 85 /** |
| 86 * Scrolls the page down to the extension node with the given id. | |
| 87 * @param {string} extensionId The id of the extension to scroll to. | |
| 88 * @private | |
| 89 */ | |
| 90 scrollToNode_: function(extensionId) { | |
| 91 // Scroll offset should be calculated slightly higher than the actual | |
| 92 // offset of the element being scrolled to, so that it ends up not all | |
| 93 // the way at the top. That way it is clear that there are more elements | |
| 94 // above the element being scrolled to. | |
| 95 var scrollFudge = 1.2; | |
| 96 var scrollTop = $(extensionId).offsetTop - scrollFudge * | |
| 97 $(extensionId).clientHeight; | |
| 98 setScrollTopForDocument(document, scrollTop); | |
| 99 }, | |
| 100 | |
| 101 /** | |
| 74 * Synthesizes and initializes an HTML element for the extension metadata | 102 * Synthesizes and initializes an HTML element for the extension metadata |
| 75 * given in |extension|. | 103 * given in |extension|. |
| 76 * @param {Object} extension A dictionary of extension metadata. | 104 * @param {Object} extension A dictionary of extension metadata. |
| 77 * @private | 105 * @private |
| 78 */ | 106 */ |
| 79 createNode_: function(extension) { | 107 createNode_: function(extension) { |
| 80 var template = $('template-collection').querySelector( | 108 var template = $('template-collection').querySelector( |
| 81 '.extension-list-item-wrapper'); | 109 '.extension-list-item-wrapper'); |
| 82 var node = template.cloneNode(true); | 110 var node = template.cloneNode(true); |
| 83 node.id = extension.id; | 111 node.id = extension.id; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 }); | 215 }); |
| 188 fileAccess.querySelector('input').checked = extension.allowFileAccess; | 216 fileAccess.querySelector('input').checked = extension.allowFileAccess; |
| 189 fileAccess.hidden = false; | 217 fileAccess.hidden = false; |
| 190 } | 218 } |
| 191 | 219 |
| 192 // The 'Options' link. | 220 // The 'Options' link. |
| 193 if (extension.enabled && extension.optionsUrl) { | 221 if (extension.enabled && extension.optionsUrl) { |
| 194 var options = node.querySelector('.options-link'); | 222 var options = node.querySelector('.options-link'); |
| 195 options.addEventListener('click', function(e) { | 223 options.addEventListener('click', function(e) { |
| 196 if (this.data_.enableEmbeddedExtensionOptions) { | 224 if (this.data_.enableEmbeddedExtensionOptions) { |
| 225 // Add the options query string. | |
|
not at google - send to devlin
2014/08/25 18:11:07
Mention why you need to postMessage here.
ericzeng
2014/08/25 21:42:34
Done.
| |
| 226 window.parent.postMessage({ | |
| 227 method: 'updateHistory', | |
| 228 params: { | |
| 229 state: {}, | |
| 230 path: '?options=' + extension.id, | |
| 231 replace: false | |
|
not at google - send to devlin
2014/08/25 18:11:07
I think that clicking on an icon should replace th
ericzeng
2014/08/25 21:42:34
Replace state is done.
It looks like the crash is
| |
| 232 } | |
| 233 }, 'chrome://chrome'); | |
| 197 extensions.ExtensionOptionsOverlay.getInstance(). | 234 extensions.ExtensionOptionsOverlay.getInstance(). |
| 198 setExtensionAndShowOverlay(extension.id, | 235 setExtensionAndShowOverlay(extension.id, |
| 199 extension.name, | 236 extension.name, |
| 200 extension.icon); | 237 extension.icon); |
| 201 } else { | 238 } else { |
| 202 chrome.send('extensionSettingsOptions', [extension.id]); | 239 chrome.send('extensionSettingsOptions', [extension.id]); |
| 203 } | 240 } |
| 204 e.preventDefault(); | 241 e.preventDefault(); |
| 205 }.bind(this)); | 242 }.bind(this)); |
| 206 options.hidden = false; | 243 options.hidden = false; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 topScroll -= pad / 2; | 453 topScroll -= pad / 2; |
| 417 setScrollTopForDocument(document, topScroll); | 454 setScrollTopForDocument(document, topScroll); |
| 418 } | 455 } |
| 419 }, | 456 }, |
| 420 }; | 457 }; |
| 421 | 458 |
| 422 return { | 459 return { |
| 423 ExtensionsList: ExtensionsList | 460 ExtensionsList: ExtensionsList |
| 424 }; | 461 }; |
| 425 }); | 462 }); |
| OLD | NEW |