|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('options', function() { | |
6 var OptionsPage = options.OptionsPage; | |
7 var ExtensionsList = options.ExtensionsList; | |
8 | |
9 /** | |
10 * ExtensionSettings class | |
11 * Encapsulated handling of the 'Manage Extensions' page. | |
12 * @class | |
13 */ | |
14 function ExtensionSettings() { | |
15 OptionsPage.call(this, | |
16 'extensionSettings', | |
17 templateData.extensionSettingsTitle, | |
18 'extension-settings'); | |
19 } | |
20 | |
21 cr.addSingletonGetter(ExtensionSettings); | |
22 | |
23 ExtensionSettings.prototype = { | |
24 __proto__: OptionsPage.prototype, | |
25 | |
26 /** | |
27 * Initialize the page. | |
28 */ | |
29 initializePage: function() { | |
30 OptionsPage.prototype.initializePage.call(this); | |
31 | |
32 // This will request the data to show on the page and will get a response | |
33 // back in returnExtensionsData. | |
34 chrome.send('requestExtensionsData'); | |
35 | |
36 // Set up the developer mode button. | |
37 var toggleDevMode = $('toggle-dev-on'); | |
38 toggleDevMode.addEventListener('click', | |
39 this.handleToggleDevMode_.bind(this)); | |
40 | |
41 // Setup the gallery related links and text. | |
42 $('suggest-gallery').innerHTML = | |
43 localStrings.getString('suggestGallery'); | |
csilv
2011/09/01 21:10:45
This can be done more concisely by setting the i18
Finnur
2011/09/02 13:58:47
Not quite. suggestGallery content is HTML passed d
csilv
2011/09/02 17:41:11
Ah, thanks for the correction.
On 2011/09/02 13:5
| |
44 $('get-more-extensions').innerHTML = | |
45 localStrings.getString('getMoreExtensions'); | |
46 | |
47 // Set up the three dev mode buttons (load unpacked, pack and update). | |
48 $('load-unpacked').addEventListener('click', | |
49 this.handleLoadUnpackedExtension_.bind(this)); | |
50 $('pack-extension').addEventListener('click', | |
51 this.handlePackExtension_.bind(this)); | |
52 $('update-extensions-now').addEventListener('click', | |
53 this.handleUpdateExtensionNow_.bind(this)); | |
54 }, | |
55 | |
56 /** | |
57 * Utility function which asks the C++ to show a platform-specific file | |
58 * select dialog, and fire |callback| with the |filePath| that resulted. | |
59 * |selectType| can be either 'file' or 'folder'. |operation| can be 'load', | |
60 * 'packRoot', or 'pem' which are signals to the C++ to do some | |
61 * operation-specific configuration. | |
62 */ | |
csilv
2011/09/01 21:10:45
@private
Finnur
2011/09/02 13:58:47
Done.
| |
63 showFileDialog_: function(selectType, operation, callback) { | |
64 handleFilePathSelected = function(filePath) { | |
65 callback(filePath); | |
66 handleFilePathSelected = function() {}; | |
67 }; | |
68 | |
69 chrome.send('selectFilePath', [selectType, operation]); | |
70 }, | |
71 | |
72 /** | |
73 * Handles the Load Unpacked Extension button. | |
74 * @param {Event} e Change event. | |
75 * @private | |
76 */ | |
77 handleLoadUnpackedExtension_: function(e) { | |
78 this.showFileDialog_('folder', 'load', function(filePath) { | |
79 chrome.send('load', [String(filePath)]); | |
80 }); | |
81 | |
82 chrome.send('coreOptionsUserMetricsAction', | |
83 ['Options_LoadUnpackedExtension']); | |
84 }, | |
85 | |
86 /** | |
87 * Handles the Pack Extension button. | |
88 * @param {Event} e Change event. | |
89 * @private | |
90 */ | |
91 handlePackExtension_: function(e) { | |
92 OptionsPage.navigateToPage('packExtensionOverlay'); | |
93 chrome.send('coreOptionsUserMetricsAction', ['Options_PackExtension']); | |
94 }, | |
95 | |
96 /** | |
97 * Handles the Update Extension Now button. | |
98 * @param {Event} e Change event. | |
99 * @private | |
100 */ | |
101 handleUpdateExtensionNow_: function(e) { | |
102 chrome.send('autoupdate', []); | |
103 }, | |
104 | |
105 /** | |
106 * Handles the Toggle Dev Mode button. | |
107 * @param {Event} e Change event. | |
108 * @private | |
109 */ | |
110 handleToggleDevMode_: function(e) { | |
111 var dev = $('dev'); | |
112 if (dev.className.indexOf('dev-open') == -1) { | |
csilv
2011/09/01 21:10:45
dev.classList.contains
Finnur
2011/09/02 13:58:47
Done.
| |
113 // Make the Dev section visible. | |
114 dev.classList.add('dev-open'); | |
115 dev.classList.remove('dev-closed'); | |
116 | |
117 $('load-unpacked').classList.add('dev-button-visible'); | |
118 $('load-unpacked').classList.remove('dev-button-hidden'); | |
119 $('pack-extension').classList.add('dev-button-visible'); | |
120 $('pack-extension').classList.remove('dev-button-hidden'); | |
121 $('update-extensions-now').classList.add('dev-button-visible'); | |
122 $('update-extensions-now').classList.remove('dev-button-hidden'); | |
123 } else { | |
124 // Hide the Dev section. | |
125 dev.classList.add('dev-closed'); | |
126 dev.classList.remove('dev-open'); | |
127 | |
128 $('load-unpacked').classList.add('dev-button-hidden'); | |
129 $('load-unpacked').classList.remove('dev-button-visible'); | |
130 $('pack-extension').classList.add('dev-button-hidden'); | |
131 $('pack-extension').classList.remove('dev-button-visible'); | |
132 $('update-extensions-now').classList.add('dev-button-hidden'); | |
133 $('update-extensions-now').classList.remove('dev-button-visible'); | |
134 } | |
135 | |
136 chrome.send('toggleDeveloperMode', []); | |
137 }, | |
138 }; | |
139 | |
140 /** | |
141 * Called by the dom_ui_ to re-populate the page with data representing | |
142 * the current state of installed extensions. | |
143 */ | |
144 ExtensionSettings.returnExtensionsData = function(extensionsData) { | |
145 $('no-extensions').style.display = "none"; | |
csilv
2011/09/01 21:10:45
use hidden attribute, here and below
Finnur
2011/09/02 13:58:47
Done.
| |
146 $('suggest-gallery').style.display = "none"; | |
147 $('get-more-extensions-container').style.display = "none"; | |
148 | |
149 if (extensionsData.extensions.length > 0) { | |
150 // Enforce order specified in the data or (if equal) then sort by | |
151 // extension name (case-insensitive). | |
152 extensionsData.extensions.sort(function(a, b) { | |
153 if (a.order == b.order) { | |
154 a = a.name.toLowerCase(); | |
155 b = b.name.toLowerCase(); | |
156 return a < b ? -1 : (a > b ? 1 : 0); | |
157 } else { | |
158 return a.order < b.order ? -1 : 1; | |
159 } | |
160 }); | |
161 | |
162 $('get-more-extensions-container').style.display = "-webkit-box"; | |
163 } else { | |
164 $('no-extensions').style.display = "-webkit-box"; | |
165 $('suggest-gallery').style.display = "-webkit-box"; | |
166 } | |
167 | |
168 ExtensionsList.prototype.data_ = extensionsData; | |
169 | |
170 var extensionList = $('extension-settings-list'); | |
171 ExtensionsList.decorate(extensionList); | |
172 } | |
173 | |
174 // Export | |
175 return { | |
176 ExtensionSettings: ExtensionSettings | |
177 }; | |
178 }); | |
OLD | NEW |