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); |
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(); |
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 | |
Devlin
2014/08/21 17:18:19
nit: .
ericzeng
2014/08/21 17:59:52
Done.
| |
226 window.parent.postMessage({ | |
227 method: 'updateHistory', | |
228 params: { | |
229 state: {}, | |
230 path: '?options=' + extension.id, | |
231 replace: false | |
232 } | |
233 }, 'chrome://chrome'); | |
197 extensions.ExtensionOptionsOverlay.getInstance(). | 234 extensions.ExtensionOptionsOverlay.getInstance(). |
198 setExtensionAndShowOverlay([extension.id], extension.name); | 235 setExtensionAndShowOverlay([extension.id], extension.name); |
199 } else { | 236 } else { |
200 chrome.send('extensionSettingsOptions', [extension.id]); | 237 chrome.send('extensionSettingsOptions', [extension.id]); |
201 } | 238 } |
202 e.preventDefault(); | 239 e.preventDefault(); |
203 }.bind(this)); | 240 }.bind(this)); |
204 options.hidden = false; | 241 options.hidden = false; |
205 } | 242 } |
206 | 243 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 topScroll -= pad / 2; | 451 topScroll -= pad / 2; |
415 setScrollTopForDocument(document, topScroll); | 452 setScrollTopForDocument(document, topScroll); |
416 } | 453 } |
417 }, | 454 }, |
418 }; | 455 }; |
419 | 456 |
420 return { | 457 return { |
421 ExtensionsList: ExtensionsList | 458 ExtensionsList: ExtensionsList |
422 }; | 459 }; |
423 }); | 460 }); |
OLD | NEW |