Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/resources/extensions/extension_error.js

Issue 22938005: Add ErrorConsole UI for Extension Install Warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_install_warnings
Patch Set: Yoyo's + temporarily remove *.png for apply issue Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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('extensions', function() {
6 'use strict';
7
8 /**
9 * Returns whether or not a given |url| is associated with an extension.
10 * @param {string} url The url to examine.
11 * @param {string} extensionUrl The url of the extension.
12 * @return {boolean} Whether or not the url is associated with the extension.
13 */
14 function isExtensionUrl(url, extensionUrl) {
15 return url.substring(0, extensionUrl.length) === extensionUrl;
16 }
17
18 /**
19 * Get the url relative to the main extension url. If the url is
20 * unassociated with the extension, this will be the full url.
21 * @param {url} The url to make relative.
Dan Beam 2013/08/20 21:39:26 @param {string} url The url to make relative.
Devlin 2013/08/20 23:06:51 D'oh. Fixed.
22 * @param {extensionUrl} The host for which the url is relative.
Dan Beam 2013/08/20 21:39:26 @param {string} extensionURL The host for which th
Devlin 2013/08/20 23:06:51 Is chrome JS style 'URL' or 'Url'? Kept 'Url' her
23 * @return {string} The url relative to the host.
24 */
25 function getRelativeUrl(url, extensionUrl) {
26 return isExtensionUrl(url, extensionUrl) ?
27 url.substring(extensionUrl.length) : url;
28 }
29
30 /**
31 * Clone a template within the extension error template collection.
32 * @param {string} templateName The class name of the template to clone.
33 * @return {HTMLElement} The clone of the template.
34 */
35 function cloneTemplate(templateName) {
36 return $('template-collection-extension-error')
Dan Beam 2013/08/20 21:39:26 nit: operators at end return $('template-collecti
Devlin 2013/08/20 23:06:51 Done.
37 .querySelector(templateName).cloneNode(true);
38 }
39
40 /**
41 * Creates a new ExtensionError HTMLElement.
42 * @param {Object} error The error the element should represent.
43 * @return {HTMLElement} The created error element.
Dan Beam 2013/08/20 21:39:26 nit: remove @return
Dan Beam 2013/08/20 21:39:26 * @constructor * @extends {HTMLDivElement}
Devlin 2013/08/20 23:06:51 Done.
Devlin 2013/08/20 23:06:51 Done.
44 */
45 function ExtensionError(error) {
46 var div = document.createElement('div');
47 div.__proto__ = ExtensionError.prototype;
48 div.className = 'extension-error-simple-wrapper';
49 div.error_ = error;
50 div.decorate();
51 return div;
52 }
53
54 ExtensionError.prototype = {
55 __proto__: HTMLDivElement.prototype,
56
57 /** @override */
58 decorate: function() {
59 var metadata = cloneTemplate('.extension-error-metadata');
60
61 // Set an icon for the level of severity...
62 var iconNode = metadata.querySelector('img');
63 iconNode.className =
64 this.error_.level == 0 ? 'extension-error-icon-log' :
65 this.error_.level == 1 ? 'extension-error-icon-warn' :
66 'extension-error-icon-error';
Dan Beam 2013/08/20 21:39:26 nit: something like this is easier to read, IMO i
Devlin 2013/08/20 23:06:51 Done.
67
68 // Add a property for the extension's base url in order to determine if
69 // a url belongs to the extension.
70 this.extensionUrl_ =
71 'chrome-extension://' + this.error_.extensionId + '/';
72
73 // The error message...
Dan Beam 2013/08/20 21:39:26 ^ this seems to be self-evident
Devlin 2013/08/20 23:06:51 Done.
74 metadata.querySelector('.extension-error-message').innerText =
75 this.error_.message;
76
77 // The error source...
Dan Beam 2013/08/20 21:39:26 ^ and this (so comments probably aren't required)
Devlin 2013/08/20 23:06:51 Done.
78 metadata.querySelector('.extension-error-source').innerText =
79 '(' + getRelativeUrl(this.error_.source, this.extensionUrl_) + ')';
80
81 this.appendChild(metadata);
82 this.addViewLinkToNode_(this, this.error_.source);
83 },
84
85 /**
86 * Add a "view" link to the given node, if a user can view the source of the
87 * specified url.
88 * @param {HTMLElement} node The node to which we append the view link.
89 * @param {string} url The url to the resource to view.
Dan Beam 2013/08/20 21:39:26 * @private
Devlin 2013/08/20 23:06:51 Done.
90 */
91 addViewLinkToNode_: function(node, url) {
92 if (this.canViewSource_(url))
93 node.appendChild(this.getViewSourceLink_(url));
94 },
95
96 /**
97 * Determine whether we can view the source of a given url.
98 * @param {string} url The url to the resource to view.
99 * @return {boolean} Whether or not we can view the source for the url.
Dan Beam 2013/08/20 21:39:26 * @private
Devlin 2013/08/20 23:06:51 Done.
100 */
101 canViewSource_: function(url) {
102 return isExtensionUrl(url, this.extensionUrl_) ||
103 url === 'manifest.json';
Dan Beam 2013/08/20 21:39:26 nit: s/===/==/ IMO
Devlin 2013/08/20 23:06:51 Mmkay (it's definitely not done enough for any of
104 },
105
106 /**
107 * Create a clickable node to view the source for the given url.
108 * @param {string} url The url to the resource to view.
109 * @return {HTMLElement} The clickable node to view the source.
Dan Beam 2013/08/20 21:39:26 * @private
Devlin 2013/08/20 23:06:51 Done.
110 */
111 getViewSourceLink_: function(url) {
112 var node = document.createElement('a');
113 node.innerText = loadTimeData.getString('extensionErrorViewSource');
114
115 var relativeLink = getRelativeUrl(url, this.extensionUrl_);
116 node.addEventListener('click', function(e) {
117 chrome.send('extensionErrorRequestFileSource',
118 [{
Dan Beam 2013/08/20 21:39:26 nit: chrome.send('extensionErrorRequestFileSource
Devlin 2013/08/20 23:06:51 Done.
119 'extensionId': this.error_.extensionId,
120 'errorMessage': this.error_.message,
121 'fileType': 'manifest',
122 'pathSuffix': relativeLink,
123 'feature': this.error_.manifestKey,
124 'specific': this.error_.manifestSpecific
125 }]);
126 }.bind(this));
127 return node;
128 }
Dan Beam 2013/08/20 21:39:26 nit: },
Devlin 2013/08/20 23:06:51 Done.
129 };
130
Dan Beam 2013/08/20 21:39:26 /** * What an ExtensionErrorList does in prose as
Devlin 2013/08/20 23:06:51 Done.
131 function ExtensionErrorList(errors) {
132 var div = cloneTemplate('.extension-error-list');
133 div.__proto__ = ExtensionErrorList.prototype;
134 div.errors_ = errors;
135 div.decorate();
136 return div;
137 }
138
139 ExtensionErrorList.prototype = {
140 __proto__: HTMLDivElement.prototype,
141
142 kMaxErrorsToShow_: 3,
Dan Beam 2013/08/20 21:39:26 /** * @private * @const */ MAX_ERRORS_TO_SHOW_:
Devlin 2013/08/20 23:06:51 Done.
143
144 /** @override */
145 decorate: function() {
146 this.contents_ = this.querySelector('.extension-error-list-contents');
147 this.errors_.forEach(function(error) {
148 this.contents_.appendChild(document.createElement('li')).appendChild(
149 new ExtensionError(error));
150 }.bind(this));
Dan Beam 2013/08/20 21:39:26 }, this); (forEach() takes a thisArg)
Devlin 2013/08/20 23:06:51 Ooh, much cleaner. :)
151
152 if (this.contents_.children.length > this.kMaxErrorsToShow_) {
153 for (var i = this.kMaxErrorsToShow_;
154 i < this.contents_.children.length; ++i)
Dan Beam 2013/08/20 21:39:26 nit: curlies
Devlin 2013/08/20 23:06:51 Done.
155 this.contents_.children[i].hidden = true;
156 this.initShowMoreButton_();
157 }
158 },
159
Dan Beam 2013/08/20 21:39:26 /** @private */
Devlin 2013/08/20 23:06:51 Done.
160 initShowMoreButton_: function() {
161 var button = this.querySelector('.extension-error-list-show-more')
Dan Beam 2013/08/20 21:39:26 this.querySelector('.extension-error-list-show-mor
Devlin 2013/08/20 23:06:51 nifty. Done.
162 .querySelector('a');
163 button.hidden = false;
164 button.isShowingAll = false;
165 button.addEventListener('click', function(e) {
Dan Beam 2013/08/20 21:39:26 nit: for (var i = this.MAX_ERRORS_TO_SHOW_;
Devlin 2013/08/20 23:06:51 Done.
166 if (button.isShowingAll) {
167 for (var i = this.kMaxErrorsToShow_;
168 i < this.contents_.children.length; ++i) {
169 this.contents_.children[i].hidden = true;
170 }
171 button.innerText = loadTimeData.getString('extensionErrorsShowMore');
172 } else {
173 for (var i = this.kMaxErrorsToShow_;
174 i < this.contents_.children.length; ++i) {
175 this.contents_.children[i].hidden = false;
176 }
177 button.innerText = loadTimeData.getString('extensionErrorsShowFewer');
178 }
179
180 button.isShowingAll = !button.isShowingAll;
181 }.bind(this));
182 }
183 };
184
185 return {
186 ExtensionErrorList: ExtensionErrorList
187 };
188 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698