1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
// 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.extensionSettingsTitle,
'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
};
});
|