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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/audits/AuditLauncherView.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.AuditLauncherView = class extends WebInspector.VBox { 34 Audits.AuditLauncherView = class extends UI.VBox {
35 /** 35 /**
36 * @param {!WebInspector.AuditController} auditController 36 * @param {!Audits.AuditController} auditController
37 */ 37 */
38 constructor(auditController) { 38 constructor(auditController) {
39 super(); 39 super();
40 this.setMinimumSize(100, 25); 40 this.setMinimumSize(100, 25);
41 41
42 this._auditController = auditController; 42 this._auditController = auditController;
43 43
44 this._categoryIdPrefix = 'audit-category-item-'; 44 this._categoryIdPrefix = 'audit-category-item-';
45 this._auditRunning = false; 45 this._auditRunning = false;
46 46
47 this.element.classList.add('audit-launcher-view'); 47 this.element.classList.add('audit-launcher-view');
48 this.element.classList.add('panel-enabler-view'); 48 this.element.classList.add('panel-enabler-view');
49 49
50 this._contentElement = createElement('div'); 50 this._contentElement = createElement('div');
51 this._contentElement.className = 'audit-launcher-view-content'; 51 this._contentElement.className = 'audit-launcher-view-content';
52 this.element.appendChild(this._contentElement); 52 this.element.appendChild(this._contentElement);
53 this._boundCategoryClickListener = this._categoryClicked.bind(this); 53 this._boundCategoryClickListener = this._categoryClicked.bind(this);
54 54
55 this._resetResourceCount(); 55 this._resetResourceCount();
56 56
57 this._sortedCategories = []; 57 this._sortedCategories = [];
58 58
59 this._headerElement = createElement('h1'); 59 this._headerElement = createElement('h1');
60 this._headerElement.className = 'no-audits'; 60 this._headerElement.className = 'no-audits';
61 this._headerElement.textContent = WebInspector.UIString('No audits to run'); 61 this._headerElement.textContent = Common.UIString('No audits to run');
62 this._contentElement.appendChild(this._headerElement); 62 this._contentElement.appendChild(this._headerElement);
63 63
64 WebInspector.targetManager.addModelListener( 64 SDK.targetManager.addModelListener(
65 WebInspector.NetworkManager, WebInspector.NetworkManager.Events.RequestS tarted, this._onRequestStarted, this); 65 SDK.NetworkManager, SDK.NetworkManager.Events.RequestStarted, this._onRe questStarted, this);
66 WebInspector.targetManager.addModelListener( 66 SDK.targetManager.addModelListener(
67 WebInspector.NetworkManager, WebInspector.NetworkManager.Events.RequestF inished, this._onRequestFinished, this); 67 SDK.NetworkManager, SDK.NetworkManager.Events.RequestFinished, this._onR equestFinished, this);
68 68
69 var defaultSelectedAuditCategory = {}; 69 var defaultSelectedAuditCategory = {};
70 defaultSelectedAuditCategory[WebInspector.AuditLauncherView.AllCategoriesKey ] = true; 70 defaultSelectedAuditCategory[Audits.AuditLauncherView.AllCategoriesKey] = tr ue;
71 this._selectedCategoriesSetting = 71 this._selectedCategoriesSetting =
72 WebInspector.settings.createSetting('selectedAuditCategories', defaultSe lectedAuditCategory); 72 Common.settings.createSetting('selectedAuditCategories', defaultSelected AuditCategory);
73 } 73 }
74 74
75 _resetResourceCount() { 75 _resetResourceCount() {
76 this._loadedResources = 0; 76 this._loadedResources = 0;
77 this._totalResources = 0; 77 this._totalResources = 0;
78 } 78 }
79 79
80 _onRequestStarted(event) { 80 _onRequestStarted(event) {
81 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); 81 var request = /** @type {!SDK.NetworkRequest} */ (event.data);
82 // Ignore long-living WebSockets for the sake of progress indicator, as we w on't be waiting them anyway. 82 // Ignore long-living WebSockets for the sake of progress indicator, as we w on't be waiting them anyway.
83 if (request.resourceType() === WebInspector.resourceTypes.WebSocket) 83 if (request.resourceType() === Common.resourceTypes.WebSocket)
84 return; 84 return;
85 ++this._totalResources; 85 ++this._totalResources;
86 this._updateResourceProgress(); 86 this._updateResourceProgress();
87 } 87 }
88 88
89 _onRequestFinished(event) { 89 _onRequestFinished(event) {
90 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); 90 var request = /** @type {!SDK.NetworkRequest} */ (event.data);
91 // See resorceStarted for details. 91 // See resorceStarted for details.
92 if (request.resourceType() === WebInspector.resourceTypes.WebSocket) 92 if (request.resourceType() === Common.resourceTypes.WebSocket)
93 return; 93 return;
94 ++this._loadedResources; 94 ++this._loadedResources;
95 this._updateResourceProgress(); 95 this._updateResourceProgress();
96 } 96 }
97 97
98 /** 98 /**
99 * @param {!WebInspector.AuditCategory} category 99 * @param {!Audits.AuditCategory} category
100 */ 100 */
101 addCategory(category) { 101 addCategory(category) {
102 if (!this._sortedCategories.length) 102 if (!this._sortedCategories.length)
103 this._createLauncherUI(); 103 this._createLauncherUI();
104 104
105 var selectedCategories = this._selectedCategoriesSetting.get(); 105 var selectedCategories = this._selectedCategoriesSetting.get();
106 var categoryElement = this._createCategoryElement(category.displayName, cate gory.id); 106 var categoryElement = this._createCategoryElement(category.displayName, cate gory.id);
107 category._checkboxElement = categoryElement.checkboxElement; 107 category._checkboxElement = categoryElement.checkboxElement;
108 if (this._selectAllCheckboxElement.checked || selectedCategories[category.di splayName]) { 108 if (this._selectAllCheckboxElement.checked || selectedCategories[category.di splayName]) {
109 category._checkboxElement.checked = true; 109 category._checkboxElement.checked = true;
110 ++this._currentCategoriesCount; 110 ++this._currentCategoriesCount;
111 } 111 }
112 112
113 /** 113 /**
114 * @param {!WebInspector.AuditCategory} a 114 * @param {!Audits.AuditCategory} a
115 * @param {!WebInspector.AuditCategory} b 115 * @param {!Audits.AuditCategory} b
116 * @return {number} 116 * @return {number}
117 */ 117 */
118 function compareCategories(a, b) { 118 function compareCategories(a, b) {
119 var aTitle = a.displayName || ''; 119 var aTitle = a.displayName || '';
120 var bTitle = b.displayName || ''; 120 var bTitle = b.displayName || '';
121 return aTitle.localeCompare(bTitle); 121 return aTitle.localeCompare(bTitle);
122 } 122 }
123 var insertBefore = this._sortedCategories.lowerBound(category, compareCatego ries); 123 var insertBefore = this._sortedCategories.lowerBound(category, compareCatego ries);
124 this._categoriesElement.insertBefore(categoryElement, this._categoriesElemen t.children[insertBefore]); 124 this._categoriesElement.insertBefore(categoryElement, this._categoriesElemen t.children[insertBefore]);
125 this._sortedCategories.splice(insertBefore, 0, category); 125 this._sortedCategories.splice(insertBefore, 0, category);
126 this._selectedCategoriesUpdated(); 126 this._selectedCategoriesUpdated();
127 } 127 }
128 128
129 _startAudit() { 129 _startAudit() {
130 this._auditRunning = true; 130 this._auditRunning = true;
131 this._updateButton(); 131 this._updateButton();
132 this._toggleUIComponents(this._auditRunning); 132 this._toggleUIComponents(this._auditRunning);
133 133
134 var catIds = []; 134 var catIds = [];
135 for (var category = 0; category < this._sortedCategories.length; ++category) { 135 for (var category = 0; category < this._sortedCategories.length; ++category) {
136 if (this._sortedCategories[category]._checkboxElement.checked) 136 if (this._sortedCategories[category]._checkboxElement.checked)
137 catIds.push(this._sortedCategories[category].id); 137 catIds.push(this._sortedCategories[category].id);
138 } 138 }
139 139
140 this._resetResourceCount(); 140 this._resetResourceCount();
141 this._progressIndicator = new WebInspector.ProgressIndicator(); 141 this._progressIndicator = new UI.ProgressIndicator();
142 this._buttonContainerElement.appendChild(this._progressIndicator.element); 142 this._buttonContainerElement.appendChild(this._progressIndicator.element);
143 this._displayResourceLoadingProgress = true; 143 this._displayResourceLoadingProgress = true;
144 144
145 /** 145 /**
146 * @this {WebInspector.AuditLauncherView} 146 * @this {Audits.AuditLauncherView}
147 */ 147 */
148 function onAuditStarted() { 148 function onAuditStarted() {
149 this._displayResourceLoadingProgress = false; 149 this._displayResourceLoadingProgress = false;
150 } 150 }
151 this._auditController.initiateAudit( 151 this._auditController.initiateAudit(
152 catIds, new WebInspector.ProgressProxy(this._progressIndicator, this._au ditsDone.bind(this)), 152 catIds, new Common.ProgressProxy(this._progressIndicator, this._auditsDo ne.bind(this)),
153 this._auditPresentStateElement.checked, onAuditStarted.bind(this)); 153 this._auditPresentStateElement.checked, onAuditStarted.bind(this));
154 } 154 }
155 155
156 _auditsDone() { 156 _auditsDone() {
157 this._displayResourceLoadingProgress = false; 157 this._displayResourceLoadingProgress = false;
158 delete this._progressIndicator; 158 delete this._progressIndicator;
159 this._launchButton.disabled = false; 159 this._launchButton.disabled = false;
160 this._auditRunning = false; 160 this._auditRunning = false;
161 this._updateButton(); 161 this._updateButton();
162 this._toggleUIComponents(this._auditRunning); 162 this._toggleUIComponents(this._auditRunning);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 labelElement.id = this._categoryIdPrefix + id; 214 labelElement.id = this._categoryIdPrefix + id;
215 labelElement.checkboxElement.addEventListener('click', this._boundCategory ClickListener, false); 215 labelElement.checkboxElement.addEventListener('click', this._boundCategory ClickListener, false);
216 } 216 }
217 labelElement.__displayName = title; 217 labelElement.__displayName = title;
218 218
219 return labelElement; 219 return labelElement;
220 } 220 }
221 221
222 _createLauncherUI() { 222 _createLauncherUI() {
223 this._headerElement = createElement('h1'); 223 this._headerElement = createElement('h1');
224 this._headerElement.textContent = WebInspector.UIString('Select audits to ru n'); 224 this._headerElement.textContent = Common.UIString('Select audits to run');
225 225
226 this._contentElement.removeChildren(); 226 this._contentElement.removeChildren();
227 this._contentElement.appendChild(this._headerElement); 227 this._contentElement.appendChild(this._headerElement);
228 228
229 /** 229 /**
230 * @param {!Event} event 230 * @param {!Event} event
231 * @this {WebInspector.AuditLauncherView} 231 * @this {Audits.AuditLauncherView}
232 */ 232 */
233 function handleSelectAllClick(event) { 233 function handleSelectAllClick(event) {
234 this._selectAllClicked(event.target.checked, true); 234 this._selectAllClicked(event.target.checked, true);
235 } 235 }
236 var categoryElement = this._createCategoryElement(WebInspector.UIString('Sel ect All'), ''); 236 var categoryElement = this._createCategoryElement(Common.UIString('Select Al l'), '');
237 categoryElement.id = 'audit-launcher-selectall'; 237 categoryElement.id = 'audit-launcher-selectall';
238 this._selectAllCheckboxElement = categoryElement.checkboxElement; 238 this._selectAllCheckboxElement = categoryElement.checkboxElement;
239 this._selectAllCheckboxElement.checked = 239 this._selectAllCheckboxElement.checked =
240 this._selectedCategoriesSetting.get()[WebInspector.AuditLauncherView.All CategoriesKey]; 240 this._selectedCategoriesSetting.get()[Audits.AuditLauncherView.AllCatego riesKey];
241 this._selectAllCheckboxElement.addEventListener('click', handleSelectAllClic k.bind(this), false); 241 this._selectAllCheckboxElement.addEventListener('click', handleSelectAllClic k.bind(this), false);
242 this._contentElement.appendChild(categoryElement); 242 this._contentElement.appendChild(categoryElement);
243 243
244 this._categoriesElement = this._contentElement.createChild('fieldset', 'audi t-categories-container'); 244 this._categoriesElement = this._contentElement.createChild('fieldset', 'audi t-categories-container');
245 this._currentCategoriesCount = 0; 245 this._currentCategoriesCount = 0;
246 246
247 this._contentElement.createChild('div', 'flexible-space'); 247 this._contentElement.createChild('div', 'flexible-space');
248 248
249 this._buttonContainerElement = this._contentElement.createChild('div', 'butt on-container'); 249 this._buttonContainerElement = this._contentElement.createChild('div', 'butt on-container');
250 250
251 var radio = createRadioLabel('audit-mode', WebInspector.UIString('Audit Pres ent State'), true); 251 var radio = createRadioLabel('audit-mode', Common.UIString('Audit Present St ate'), true);
252 this._buttonContainerElement.appendChild(radio); 252 this._buttonContainerElement.appendChild(radio);
253 this._auditPresentStateElement = radio.radioElement; 253 this._auditPresentStateElement = radio.radioElement;
254 254
255 radio = createRadioLabel('audit-mode', WebInspector.UIString('Reload Page an d Audit on Load')); 255 radio = createRadioLabel('audit-mode', Common.UIString('Reload Page and Audi t on Load'));
256 this._buttonContainerElement.appendChild(radio); 256 this._buttonContainerElement.appendChild(radio);
257 this._auditReloadedStateElement = radio.radioElement; 257 this._auditReloadedStateElement = radio.radioElement;
258 258
259 this._launchButton = createTextButton(WebInspector.UIString('Run'), this._la unchButtonClicked.bind(this)); 259 this._launchButton = createTextButton(Common.UIString('Run'), this._launchBu ttonClicked.bind(this));
260 this._buttonContainerElement.appendChild(this._launchButton); 260 this._buttonContainerElement.appendChild(this._launchButton);
261 261
262 this._clearButton = createTextButton(WebInspector.UIString('Clear'), this._c learButtonClicked.bind(this)); 262 this._clearButton = createTextButton(Common.UIString('Clear'), this._clearBu ttonClicked.bind(this));
263 this._buttonContainerElement.appendChild(this._clearButton); 263 this._buttonContainerElement.appendChild(this._clearButton);
264 264
265 this._selectAllClicked(this._selectAllCheckboxElement.checked); 265 this._selectAllClicked(this._selectAllCheckboxElement.checked);
266 } 266 }
267 267
268 _updateResourceProgress() { 268 _updateResourceProgress() {
269 if (this._displayResourceLoadingProgress) 269 if (this._displayResourceLoadingProgress)
270 this._progressIndicator.setTitle( 270 this._progressIndicator.setTitle(
271 WebInspector.UIString('Loading (%d of %d)', this._loadedResources, thi s._totalResources)); 271 Common.UIString('Loading (%d of %d)', this._loadedResources, this._tot alResources));
272 } 272 }
273 273
274 /** 274 /**
275 * @param {boolean=} userGesture 275 * @param {boolean=} userGesture
276 */ 276 */
277 _selectedCategoriesUpdated(userGesture) { 277 _selectedCategoriesUpdated(userGesture) {
278 // Save present categories only upon user gesture to clean up junk from past versions and removed extensions. 278 // Save present categories only upon user gesture to clean up junk from past versions and removed extensions.
279 // Do not remove old categories if not handling a user gesture, as there's c hance categories will be added 279 // Do not remove old categories if not handling a user gesture, as there's c hance categories will be added
280 // later during start-up. 280 // later during start-up.
281 var selectedCategories = userGesture ? {} : this._selectedCategoriesSetting. get(); 281 var selectedCategories = userGesture ? {} : this._selectedCategoriesSetting. get();
282 var childNodes = this._categoriesElement.childNodes; 282 var childNodes = this._categoriesElement.childNodes;
283 for (var i = 0, length = childNodes.length; i < length; ++i) 283 for (var i = 0, length = childNodes.length; i < length; ++i)
284 selectedCategories[childNodes[i].__displayName] = childNodes[i].checkboxEl ement.checked; 284 selectedCategories[childNodes[i].__displayName] = childNodes[i].checkboxEl ement.checked;
285 selectedCategories[WebInspector.AuditLauncherView.AllCategoriesKey] = this._ selectAllCheckboxElement.checked; 285 selectedCategories[Audits.AuditLauncherView.AllCategoriesKey] = this._select AllCheckboxElement.checked;
286 this._selectedCategoriesSetting.set(selectedCategories); 286 this._selectedCategoriesSetting.set(selectedCategories);
287 this._updateButton(); 287 this._updateButton();
288 } 288 }
289 289
290 _updateButton() { 290 _updateButton() {
291 this._launchButton.textContent = this._auditRunning ? WebInspector.UIString( 'Stop') : WebInspector.UIString('Run'); 291 this._launchButton.textContent = this._auditRunning ? Common.UIString('Stop' ) : Common.UIString('Run');
292 this._launchButton.disabled = !this._currentCategoriesCount; 292 this._launchButton.disabled = !this._currentCategoriesCount;
293 } 293 }
294 }; 294 };
295 295
296 WebInspector.AuditLauncherView.AllCategoriesKey = '__AllCategories'; 296 Audits.AuditLauncherView.AllCategoriesKey = '__AllCategories';
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698