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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
// Copyright (c) 2012 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 src="extension_error.js"></include>
cr.define('options', function() {
'use strict';
/**
* Creates a new list of extensions.
* @param {Object=} opt_propertyBag Optional properties.
* @constructor
* @extends {cr.ui.div}
*/
var ExtensionsList = cr.ui.define('div');
/**
* @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 butterBarVisibility = {};
/**
* @type {Object.<string, string>} A map from extension id to last reloaded
* timestamp. The timestamp is recorded when the user click the 'Reload'
* link. It is used to refresh the icon of an unpacked extension.
* This persists between calls to decorate.
*/
var extensionReloadedTimestamp = {};
ExtensionsList.prototype = {
__proto__: HTMLDivElement.prototype,
/** @override */
decorate: function() {
this.textContent = '';
this.showExtensionNodes_();
},
getIdQueryParam_: function() {
return parseQueryParams(document.location)['id'];
},
/**
* Creates all extension items from scratch.
* @private
*/
showExtensionNodes_: function() {
// Iterate over the extension data and add each item to the list.
this.data_.extensions.forEach(this.createNode_, this);
var idToHighlight = this.getIdQueryParam_();
if (idToHighlight && $(idToHighlight)) {
// Scroll offset should be calculated slightly higher than the actual
// offset of the element being scrolled to, so that it ends up not all
// the way at the top. That way it is clear that there are more elements
// above the element being scrolled to.
var scrollFudge = 1.2;
var scrollTop = $(idToHighlight).offsetTop - scrollFudge *
$(idToHighlight).clientHeight;
setScrollTopForDocument(document, scrollTop);
}
if (this.data_.extensions.length == 0)
this.classList.add('empty-extension-list');
else
this.classList.remove('empty-extension-list');
},
/**
* Synthesizes and initializes an HTML element for the extension metadata
* given in |extension|.
* @param {Object} extension A dictionary of extension metadata.
* @private
*/
createNode_: function(extension) {
var template = $('template-collection').querySelector(
'.extension-list-item-wrapper');
var node = template.cloneNode(true);
node.id = extension.id;
if (!extension.enabled || extension.terminated)
node.classList.add('inactive-extension');
if (extension.managedInstall) {
node.classList.add('may-not-modify');
node.classList.add('may-not-remove');
} else if (extension.suspiciousInstall) {
node.classList.add('may-not-modify');
}
var idToHighlight = this.getIdQueryParam_();
if (node.id == idToHighlight)
node.classList.add('extension-highlight');
var item = node.querySelector('.extension-list-item');
// Prevent the image cache of extension icon by using the reloaded
// timestamp as a query string. The timestamp is recorded when the user
// clicks the 'Reload' link. http://crbug.com/159302.
if (extensionReloadedTimestamp[extension.id]) {
item.style.backgroundImage =
'url(' + extension.icon + '?' +
extensionReloadedTimestamp[extension.id] + ')';
} else {
item.style.backgroundImage = 'url(' + extension.icon + ')';
}
var title = node.querySelector('.extension-title');
title.textContent = extension.name;
var version = node.querySelector('.extension-version');
version.textContent = extension.version;
var locationText = node.querySelector('.location-text');
locationText.textContent = extension.locationText;
var description = node.querySelector('.extension-description span');
description.textContent = extension.description;
// The 'Show Browser Action' button.
if (extension.enable_show_button) {
var showButton = node.querySelector('.show-button');
showButton.addEventListener('click', function(e) {
chrome.send('extensionSettingsShowButton', [extension.id]);
});
showButton.hidden = false;
}
// The 'allow in incognito' checkbox.
var incognito = node.querySelector('.incognito-control input');
incognito.disabled = !extension.incognitoCanBeToggled;
incognito.checked = extension.enabledIncognito;
if (!incognito.disabled) {
incognito.addEventListener('change', function(e) {
var checked = e.target.checked;
butterBarVisibility[extension.id] = checked;
butterBar.hidden = !checked || extension.is_hosted_app;
chrome.send('extensionSettingsEnableIncognito',
[extension.id, String(checked)]);
});
}
var butterBar = node.querySelector('.butter-bar');
butterBar.hidden = !butterBarVisibility[extension.id];
// The 'allow file:// access' checkbox.
if (extension.wantsFileAccess) {
var fileAccess = node.querySelector('.file-access-control');
fileAccess.addEventListener('click', function(e) {
chrome.send('extensionSettingsAllowFileAccess',
[extension.id, String(e.target.checked)]);
});
fileAccess.querySelector('input').checked = extension.allowFileAccess;
fileAccess.hidden = false;
}
// The 'Options' link.
if (extension.enabled && extension.optionsUrl) {
var options = node.querySelector('.options-link');
options.addEventListener('click', function(e) {
chrome.send('extensionSettingsOptions', [extension.id]);
e.preventDefault();
});
options.hidden = false;
}
// The 'Permissions' link.
var permissions = node.querySelector('.permissions-link');
permissions.addEventListener('click', function(e) {
chrome.send('extensionSettingsPermissions', [extension.id]);
e.preventDefault();
});
// The 'View in Web Store/View Web Site' link.
if (extension.homepageUrl) {
var siteLink = node.querySelector('.site-link');
siteLink.href = extension.homepageUrl;
siteLink.textContent = loadTimeData.getString(
extension.homepageProvided ? 'extensionSettingsVisitWebsite' :
'extensionSettingsVisitWebStore');
siteLink.hidden = false;
}
if (extension.allow_reload) {
// The 'Reload' link.
var reload = node.querySelector('.reload-link');
reload.addEventListener('click', function(e) {
chrome.send('extensionSettingsReload', [extension.id]);
extensionReloadedTimestamp[extension.id] = Date.now();
});
reload.hidden = false;
if (extension.is_platform_app) {
// The 'Launch' link.
var launch = node.querySelector('.launch-link');
launch.addEventListener('click', function(e) {
chrome.send('extensionSettingsLaunch', [extension.id]);
});
launch.hidden = false;
}
}
if (!extension.terminated) {
// The 'Enabled' checkbox.
var enable = node.querySelector('.enable-checkbox');
enable.hidden = false;
enable.querySelector('input').disabled = extension.managedInstall ||
extension.suspiciousInstall;
if (!extension.managedInstall && !extension.suspiciousInstall) {
enable.addEventListener('click', function(e) {
// When e.target is the label instead of the checkbox, it doesn't
// have the checked property and the state of the checkbox is
// left unchanged.
var checked = e.target.checked;
if (checked == undefined)
checked = !e.currentTarget.querySelector('input').checked;
chrome.send('extensionSettingsEnable',
[extension.id, checked ? 'true' : 'false']);
// This may seem counter-intuitive (to not set/clear the checkmark)
// but this page will be updated asynchronously if the extension
// becomes enabled/disabled. It also might not become enabled or
// disabled, because the user might e.g. get prompted when enabling
// and choose not to.
e.preventDefault();
});
}
enable.querySelector('input').checked = extension.enabled;
} else {
var terminatedReload = node.querySelector('.terminated-reload-link');
terminatedReload.hidden = false;
terminatedReload.addEventListener('click', function(e) {
chrome.send('extensionSettingsReload', [extension.id]);
});
}
// 'Remove' button.
var trashTemplate = $('template-collection').querySelector('.trash');
var trash = trashTemplate.cloneNode(true);
trash.title = loadTimeData.getString('extensionUninstall');
trash.addEventListener('click', function(e) {
butterBarVisibility[extension.id] = false;
chrome.send('extensionSettingsUninstall', [extension.id]);
});
node.querySelector('.enable-controls').appendChild(trash);
// Developer mode ////////////////////////////////////////////////////////
// First we have the id.
var idLabel = node.querySelector('.extension-id');
idLabel.textContent = ' ' + extension.id;
// Then the path, if provided by unpacked extension.
if (extension.isUnpacked) {
var loadPath = node.querySelector('.load-path');
loadPath.hidden = false;
loadPath.querySelector('span:nth-of-type(2)').textContent =
' ' + extension.path;
}
// Then the 'managed, cannot uninstall/disable' message.
if (extension.managedInstall) {
node.querySelector('.managed-message').hidden = false;
} else if (extension.suspiciousInstall) {
// Then the 'This isn't from the webstore, looks suspicious' message.
node.querySelector('.suspicious-install-message').hidden = false;
}
// Then active views.
if (extension.views.length > 0) {
var activeViews = node.querySelector('.active-views');
activeViews.hidden = false;
var link = activeViews.querySelector('a');
extension.views.forEach(function(view, i) {
var displayName = view.generatedBackgroundPage ?
loadTimeData.getString('backgroundPage') : view.path;
var label = displayName +
(view.incognito ?
' ' + loadTimeData.getString('viewIncognito') : '') +
(view.renderProcessId == -1 ?
' ' + loadTimeData.getString('viewInactive') : '');
link.textContent = label;
link.addEventListener('click', function(e) {
// TODO(estade): remove conversion to string?
chrome.send('extensionSettingsInspect', [
String(extension.id),
String(view.renderProcessId),
String(view.renderViewId),
view.incognito
]);
});
if (i < extension.views.length - 1) {
link = link.cloneNode(true);
activeViews.appendChild(link);
}
});
}
// The extension warnings (describing runtime issues).
if (extension.warnings) {
var panel = node.querySelector('.extension-warnings');
panel.hidden = false;
var list = panel.querySelector('ul');
extension.warnings.forEach(function(warning) {
list.appendChild(document.createElement('li')).innerText = warning;
});
}
// If the ErrorConsole is enabled, we should have manifest and/or runtime
// errors. Otherwise, we may have install warnings. We should not have
// both ErrorConsole errors and install warnings.
if (extension.manifestErrors) {
var panel = node.querySelector('.manifest-errors');
panel.hidden = false;
panel.appendChild(new extensions.ExtensionErrorList(
extension.manifestErrors, 'extensionErrorsManifestErrors'));
}
if (extension.runtimeErrors) {
var panel = node.querySelector('.runtime-errors');
panel.hidden = false;
panel.appendChild(new extensions.ExtensionErrorList(
extension.runtimeErrors, 'extensionErrorsRuntimeErrors'));
}
if (extension.installWarnings) {
var panel = node.querySelector('.install-warnings');
panel.hidden = false;
var list = panel.querySelector('ul');
extension.installWarnings.forEach(function(warning) {
var li = document.createElement('li');
li.innerText = warning.message;
list.appendChild(li);
});
}
this.appendChild(node);
if (location.hash.substr(1) == extension.id) {
// Scroll beneath the fixed header so that the extension is not
// obscured.
var topScroll = node.offsetTop - $('page-header').offsetHeight;
var pad = parseInt(getComputedStyle(node, null).marginTop, 10);
if (!isNaN(pad))
topScroll -= pad / 2;
setScrollTopForDocument(document, topScroll);
}
},
};
return {
ExtensionsList: ExtensionsList
};
});
|