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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/audits/AuditController.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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 14 matching lines...) Expand all
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 /** 32 /**
33 * @unrestricted 33 * @unrestricted
34 */ 34 */
35 WebInspector.AuditController = class { 35 Audits.AuditController = class {
36 /** 36 /**
37 * @param {!WebInspector.AuditsPanel} auditsPanel 37 * @param {!Audits.AuditsPanel} auditsPanel
38 */ 38 */
39 constructor(auditsPanel) { 39 constructor(auditsPanel) {
40 this._auditsPanel = auditsPanel; 40 this._auditsPanel = auditsPanel;
41 WebInspector.targetManager.addEventListener( 41 SDK.targetManager.addEventListener(
42 WebInspector.TargetManager.Events.Load, this._didMainResourceLoad, this) ; 42 SDK.TargetManager.Events.Load, this._didMainResourceLoad, this);
43 WebInspector.targetManager.addModelListener( 43 SDK.targetManager.addModelListener(
44 WebInspector.NetworkManager, WebInspector.NetworkManager.Events.RequestF inished, this._didLoadResource, this); 44 SDK.NetworkManager, SDK.NetworkManager.Events.RequestFinished, this._did LoadResource, this);
45 } 45 }
46 46
47 /** 47 /**
48 * @param {!WebInspector.Target} target 48 * @param {!SDK.Target} target
49 * @param {!Array.<!WebInspector.AuditCategory>} categories 49 * @param {!Array.<!Audits.AuditCategory>} categories
50 * @param {function(string, !Array.<!WebInspector.AuditCategoryResult>)} resul tCallback 50 * @param {function(string, !Array.<!Audits.AuditCategoryResult>)} resultCallb ack
51 */ 51 */
52 _executeAudit(target, categories, resultCallback) { 52 _executeAudit(target, categories, resultCallback) {
53 this._progress.setTitle(WebInspector.UIString('Running audit')); 53 this._progress.setTitle(Common.UIString('Running audit'));
54 54
55 /** 55 /**
56 * @param {!WebInspector.AuditCategoryResult} categoryResult 56 * @param {!Audits.AuditCategoryResult} categoryResult
57 * @param {!WebInspector.AuditRuleResult} ruleResult 57 * @param {!Audits.AuditRuleResult} ruleResult
58 */ 58 */
59 function ruleResultReadyCallback(categoryResult, ruleResult) { 59 function ruleResultReadyCallback(categoryResult, ruleResult) {
60 if (ruleResult && ruleResult.children) 60 if (ruleResult && ruleResult.children)
61 categoryResult.addRuleResult(ruleResult); 61 categoryResult.addRuleResult(ruleResult);
62 } 62 }
63 63
64 var results = []; 64 var results = [];
65 var mainResourceURL = target.inspectedURL(); 65 var mainResourceURL = target.inspectedURL();
66 var categoriesDone = 0; 66 var categoriesDone = 0;
67 67
68 function categoryDoneCallback() { 68 function categoryDoneCallback() {
69 if (++categoriesDone !== categories.length) 69 if (++categoriesDone !== categories.length)
70 return; 70 return;
71 resultCallback(mainResourceURL, results); 71 resultCallback(mainResourceURL, results);
72 } 72 }
73 73
74 var networkLog = WebInspector.NetworkLog.fromTarget(target); 74 var networkLog = SDK.NetworkLog.fromTarget(target);
75 var requests = networkLog ? networkLog.requests().slice() : []; 75 var requests = networkLog ? networkLog.requests().slice() : [];
76 var compositeProgress = new WebInspector.CompositeProgress(this._progress); 76 var compositeProgress = new Common.CompositeProgress(this._progress);
77 var subprogresses = []; 77 var subprogresses = [];
78 for (var i = 0; i < categories.length; ++i) 78 for (var i = 0; i < categories.length; ++i)
79 subprogresses.push(new WebInspector.ProgressProxy(compositeProgress.create SubProgress(), categoryDoneCallback)); 79 subprogresses.push(new Common.ProgressProxy(compositeProgress.createSubPro gress(), categoryDoneCallback));
80 for (var i = 0; i < categories.length; ++i) { 80 for (var i = 0; i < categories.length; ++i) {
81 if (this._progress.isCanceled()) { 81 if (this._progress.isCanceled()) {
82 subprogresses[i].done(); 82 subprogresses[i].done();
83 continue; 83 continue;
84 } 84 }
85 var category = categories[i]; 85 var category = categories[i];
86 var result = new WebInspector.AuditCategoryResult(category); 86 var result = new Audits.AuditCategoryResult(category);
87 results.push(result); 87 results.push(result);
88 category.run(target, requests, ruleResultReadyCallback.bind(null, result), subprogresses[i]); 88 category.run(target, requests, ruleResultReadyCallback.bind(null, result), subprogresses[i]);
89 } 89 }
90 } 90 }
91 91
92 /** 92 /**
93 * @param {string} mainResourceURL 93 * @param {string} mainResourceURL
94 * @param {!Array.<!WebInspector.AuditCategoryResult>} results 94 * @param {!Array.<!Audits.AuditCategoryResult>} results
95 */ 95 */
96 _auditFinishedCallback(mainResourceURL, results) { 96 _auditFinishedCallback(mainResourceURL, results) {
97 if (!this._progress.isCanceled()) 97 if (!this._progress.isCanceled())
98 this._auditsPanel.auditFinishedCallback(mainResourceURL, results); 98 this._auditsPanel.auditFinishedCallback(mainResourceURL, results);
99 this._progress.done(); 99 this._progress.done();
100 } 100 }
101 101
102 /** 102 /**
103 * @param {!Array.<string>} categoryIds 103 * @param {!Array.<string>} categoryIds
104 * @param {!WebInspector.Progress} progress 104 * @param {!Common.Progress} progress
105 * @param {boolean} runImmediately 105 * @param {boolean} runImmediately
106 * @param {function()} startedCallback 106 * @param {function()} startedCallback
107 */ 107 */
108 initiateAudit(categoryIds, progress, runImmediately, startedCallback) { 108 initiateAudit(categoryIds, progress, runImmediately, startedCallback) {
109 var target = WebInspector.targetManager.mainTarget(); 109 var target = SDK.targetManager.mainTarget();
110 if (!categoryIds || !categoryIds.length || !target) 110 if (!categoryIds || !categoryIds.length || !target)
111 return; 111 return;
112 112
113 this._progress = progress; 113 this._progress = progress;
114 114
115 var categories = []; 115 var categories = [];
116 for (var i = 0; i < categoryIds.length; ++i) 116 for (var i = 0; i < categoryIds.length; ++i)
117 categories.push(this._auditsPanel.categoriesById[categoryIds[i]]); 117 categories.push(this._auditsPanel.categoriesById[categoryIds[i]]);
118 118
119 if (runImmediately) 119 if (runImmediately)
120 this._startAuditWhenResourcesReady(target, categories, startedCallback); 120 this._startAuditWhenResourcesReady(target, categories, startedCallback);
121 else 121 else
122 this._reloadResources(this._startAuditWhenResourcesReady.bind(this, target , categories, startedCallback)); 122 this._reloadResources(this._startAuditWhenResourcesReady.bind(this, target , categories, startedCallback));
123 123
124 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.AuditsS tarted); 124 Host.userMetrics.actionTaken(Host.UserMetrics.Action.AuditsStarted);
125 } 125 }
126 126
127 /** 127 /**
128 * @param {!WebInspector.Target} target 128 * @param {!SDK.Target} target
129 * @param {!Array<!WebInspector.AuditCategory>} categories 129 * @param {!Array<!Audits.AuditCategory>} categories
130 * @param {function()} startedCallback 130 * @param {function()} startedCallback
131 */ 131 */
132 _startAuditWhenResourcesReady(target, categories, startedCallback) { 132 _startAuditWhenResourcesReady(target, categories, startedCallback) {
133 if (this._progress.isCanceled()) { 133 if (this._progress.isCanceled()) {
134 this._progress.done(); 134 this._progress.done();
135 return; 135 return;
136 } 136 }
137 startedCallback(); 137 startedCallback();
138 this._executeAudit(target, categories, this._auditFinishedCallback.bind(this )); 138 this._executeAudit(target, categories, this._auditFinishedCallback.bind(this ));
139 } 139 }
140 140
141 /** 141 /**
142 * @param {function()=} callback 142 * @param {function()=} callback
143 */ 143 */
144 _reloadResources(callback) { 144 _reloadResources(callback) {
145 this._pageReloadCallback = callback; 145 this._pageReloadCallback = callback;
146 WebInspector.targetManager.reloadPage(); 146 SDK.targetManager.reloadPage();
147 } 147 }
148 148
149 _didLoadResource() { 149 _didLoadResource() {
150 if (this._pageReloadCallback && this._progress && this._progress.isCanceled( )) 150 if (this._pageReloadCallback && this._progress && this._progress.isCanceled( ))
151 this._pageReloadCallback(); 151 this._pageReloadCallback();
152 } 152 }
153 153
154 _didMainResourceLoad() { 154 _didMainResourceLoad() {
155 if (this._pageReloadCallback) { 155 if (this._pageReloadCallback) {
156 var callback = this._pageReloadCallback; 156 var callback = this._pageReloadCallback;
157 delete this._pageReloadCallback; 157 delete this._pageReloadCallback;
158 callback(); 158 callback();
159 } 159 }
160 } 160 }
161 161
162 clearResults() { 162 clearResults() {
163 this._auditsPanel.clearResults(); 163 this._auditsPanel.clearResults();
164 } 164 }
165 }; 165 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698