Skip to content

Instantly share code, notes, and snippets.

@vivekgalatage
Created February 25, 2013 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivekgalatage/5028382 to your computer and use it in GitHub Desktop.
Save vivekgalatage/5028382 to your computer and use it in GitHub Desktop.
diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi
index fb69071..c05f4f3 100644
--- a/Source/WebCore/WebCore.gypi
+++ b/Source/WebCore/WebCore.gypi
@@ -5457,6 +5457,7 @@
'webinspector_audits_js_files': [
'inspector/front-end/AuditCategories.js',
+ 'inspector/front-end/AuditController.js',
'inspector/front-end/AuditFormatters.js',
'inspector/front-end/AuditLauncherView.js',
'inspector/front-end/AuditResultView.js',
diff --git a/Source/WebCore/inspector/front-end/AuditController.js b/Source/WebCore/inspector/front-end/AuditController.js
new file mode 100644
index 0000000..21eb639
--- /dev/null
+++ b/Source/WebCore/inspector/front-end/AuditController.js
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.AuditController = function(auditPanel, launcherView)
+{
+ this._auditPanel = auditPanel;
+ this._launcherView = launcherView;
+ this._launcherView.setRunnerCallback(this.initiateAudit.bind(this));
+ WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._didMainResourceLoad, this);
+}
+
+WebInspector.AuditController.prototype = {
+ __proto__: WebInspector.Object.prototype,
+
+ /**
+ * @param {!Array.<!WebInspector.AuditCategory>} categories
+ * @param {function(string, !Array.<!WebInspector.AuditCategoryResult>)} resultCallback
+ */
+ _executeAudit: function(categories, resultCallback)
+ {
+ this._progress.setTitle(WebInspector.UIString("Running audit"));
+
+ function ruleResultReadyCallback(categoryResult, ruleResult)
+ {
+ if (ruleResult && ruleResult.children)
+ categoryResult.addRuleResult(ruleResult);
+
+ if (this._progress.isCanceled())
+ this._progress.done();
+ }
+
+ var results = [];
+ var mainResourceURL = WebInspector.inspectedPageURL;
+ var categoriesDone = 0;
+ function categoryDoneCallback()
+ {
+ if (++categoriesDone !== categories.length)
+ return;
+ this._progress.done();
+ resultCallback(mainResourceURL, results)
+ }
+
+ var requests = WebInspector.networkLog.requests.slice();
+ var compositeProgress = new WebInspector.CompositeProgress(this._progress);
+ var subprogresses = [];
+ for (var i = 0; i < categories.length; ++i)
+ subprogresses.push(compositeProgress.createSubProgress());
+ for (var i = 0; i < categories.length; ++i) {
+ var category = categories[i];
+ var result = new WebInspector.AuditCategoryResult(category);
+ results.push(result);
+ category.run(requests, ruleResultReadyCallback.bind(this, result), categoryDoneCallback.bind(this), subprogresses[i]);
+ }
+ },
+
+ /**
+ * @param {function()} launcherCallback
+ * @param {string} mainResourceURL
+ * @param {!Array.<!WebInspector.AuditCategoryResult>} results
+ */
+ _auditFinishedCallback: function(launcherCallback, mainResourceURL, results)
+ {
+ this._auditPanel._auditFinishedCallback(mainResourceURL, results);
+ if (!this._progress.isCanceled())
+ launcherCallback();
+ },
+
+ /**
+ * @param {Array.<string>} categoryIds
+ * @param {WebInspector.Progress} progress
+ * @param {boolean} runImmediately
+ * @param {function()} startedCallback
+ * @param {function()} finishedCallback
+ */
+ initiateAudit: function(categoryIds, progress, runImmediately, startedCallback, finishedCallback)
+ {
+ if (!categoryIds || !categoryIds.length)
+ return;
+
+ this._progress = progress;
+
+ var categories = [];
+ for (var i = 0; i < categoryIds.length; ++i)
+ categories.push(this._auditPanel.categoriesById[categoryIds[i]]);
+
+ function startAuditWhenResourcesReady()
+ {
+ startedCallback();
+ this._executeAudit(categories, this._auditFinishedCallback.bind(this, finishedCallback));
+ }
+
+ if (runImmediately)
+ startAuditWhenResourcesReady.call(this);
+ else
+ this._reloadResources(startAuditWhenResourcesReady.bind(this));
+
+ WebInspector.userMetrics.AuditsStarted.record();
+ },
+
+ _reloadResources: function(callback)
+ {
+ this._pageReloadCallback = callback;
+ PageAgent.reload(false);
+ },
+
+ _didMainResourceLoad: function()
+ {
+ if (this._pageReloadCallback) {
+ var callback = this._pageReloadCallback;
+ delete this._pageReloadCallback;
+ callback();
+ }
+ }
+}
diff --git a/Source/WebCore/inspector/front-end/AuditLauncherView.js b/Source/WebCore/inspector/front-end/AuditLauncherView.js
index fe4a426..c468df5 100644
--- a/Source/WebCore/inspector/front-end/AuditLauncherView.js
+++ b/Source/WebCore/inspector/front-end/AuditLauncherView.js
@@ -33,11 +33,10 @@
* @param {function(Array.<string>, WebInspector.Progress, boolean, function(), function()):undefined} runnerCallback
* @extends {WebInspector.View}
*/
-WebInspector.AuditLauncherView = function(runnerCallback)
+WebInspector.AuditLauncherView = function()
{
WebInspector.View.call(this);
- this._runnerCallback = runnerCallback;
this._categoryIdPrefix = "audit-category-item-";
this._auditRunning = false;
@@ -95,6 +94,11 @@ WebInspector.AuditLauncherView.prototype = {
this._updateResourceProgress();
},
+ setRunnerCallback: function(runnerCallback)
+ {
+ this._runnerCallback = runnerCallback;
+ },
+
/**
* @param {!WebInspector.AuditCategory} category
*/
diff --git a/Source/WebCore/inspector/front-end/AuditsPanel.js b/Source/WebCore/inspector/front-end/AuditsPanel.js
index c6ed17d..b4562eb 100644
--- a/Source/WebCore/inspector/front-end/AuditsPanel.js
+++ b/Source/WebCore/inspector/front-end/AuditsPanel.js
@@ -57,11 +57,10 @@ WebInspector.AuditsPanel = function()
this._constructCategories();
- this._launcherView = new WebInspector.AuditLauncherView(this.initiateAudit.bind(this));
+ this._launcherView = new WebInspector.AuditLauncherView();
+ this._auditController = new WebInspector.AuditController(this, this._launcherView);
for (var id in this.categoriesById)
this._launcherView.addCategory(this.categoriesById[id]);
-
- WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._didMainResourceLoad, this);
}
WebInspector.AuditsPanel.prototype = {
@@ -107,52 +106,10 @@ WebInspector.AuditsPanel.prototype = {
},
/**
- * @param {!Array.<!WebInspector.AuditCategory>} categories
- * @param {function(string, !Array.<!WebInspector.AuditCategoryResult>)} resultCallback
- */
- _executeAudit: function(categories, resultCallback)
- {
- this._progress.setTitle(WebInspector.UIString("Running audit"));
-
- function ruleResultReadyCallback(categoryResult, ruleResult)
- {
- if (ruleResult && ruleResult.children)
- categoryResult.addRuleResult(ruleResult);
-
- if (this._progress.isCanceled())
- this._progress.done();
- }
-
- var results = [];
- var mainResourceURL = WebInspector.inspectedPageURL;
- var categoriesDone = 0;
- function categoryDoneCallback()
- {
- if (++categoriesDone !== categories.length)
- return;
- this._progress.done();
- resultCallback(mainResourceURL, results)
- }
-
- var requests = WebInspector.networkLog.requests.slice();
- var compositeProgress = new WebInspector.CompositeProgress(this._progress);
- var subprogresses = [];
- for (var i = 0; i < categories.length; ++i)
- subprogresses.push(compositeProgress.createSubProgress());
- for (var i = 0; i < categories.length; ++i) {
- var category = categories[i];
- var result = new WebInspector.AuditCategoryResult(category);
- results.push(result);
- category.run(requests, ruleResultReadyCallback.bind(this, result), categoryDoneCallback.bind(this), subprogresses[i]);
- }
- },
-
- /**
- * @param {function()} launcherCallback
* @param {string} mainResourceURL
* @param {!Array.<!WebInspector.AuditCategoryResult>} results
*/
- _auditFinishedCallback: function(launcherCallback, mainResourceURL, results)
+ _auditFinishedCallback: function(mainResourceURL, results)
{
var children = this.auditResultsTreeElement.children;
var ordinal = 1;
@@ -164,55 +121,6 @@ WebInspector.AuditsPanel.prototype = {
var resultTreeElement = new WebInspector.AuditResultSidebarTreeElement(this, results, mainResourceURL, ordinal);
this.auditResultsTreeElement.appendChild(resultTreeElement);
resultTreeElement.revealAndSelect();
- if (!this._progress.isCanceled())
- launcherCallback();
- },
-
- /**
- * @param {Array.<string>} categoryIds
- * @param {WebInspector.Progress} progress
- * @param {boolean} runImmediately
- * @param {function()} startedCallback
- * @param {function()} finishedCallback
- */
- initiateAudit: function(categoryIds, progress, runImmediately, startedCallback, finishedCallback)
- {
- if (!categoryIds || !categoryIds.length)
- return;
-
- this._progress = progress;
-
- var categories = [];
- for (var i = 0; i < categoryIds.length; ++i)
- categories.push(this.categoriesById[categoryIds[i]]);
-
- function startAuditWhenResourcesReady()
- {
- startedCallback();
- this._executeAudit(categories, this._auditFinishedCallback.bind(this, finishedCallback));
- }
-
- if (runImmediately)
- startAuditWhenResourcesReady.call(this);
- else
- this._reloadResources(startAuditWhenResourcesReady.bind(this));
-
- WebInspector.userMetrics.AuditsStarted.record();
- },
-
- _reloadResources: function(callback)
- {
- this._pageReloadCallback = callback;
- PageAgent.reload(false);
- },
-
- _didMainResourceLoad: function()
- {
- if (this._pageReloadCallback) {
- var callback = this._pageReloadCallback;
- delete this._pageReloadCallback;
- callback();
- }
},
/**
@@ -607,6 +515,7 @@ WebInspector.AuditRules = {};
WebInspector.AuditCategories = {};
importScript("AuditCategories.js");
+importScript("AuditController.js");
importScript("AuditFormatters.js");
importScript("AuditLauncherView.js");
importScript("AuditResultView.js");
diff --git a/Source/WebCore/inspector/front-end/WebKit.qrc b/Source/WebCore/inspector/front-end/WebKit.qrc
index 1deef31..35abe2b 100644
--- a/Source/WebCore/inspector/front-end/WebKit.qrc
+++ b/Source/WebCore/inspector/front-end/WebKit.qrc
@@ -5,6 +5,7 @@
<file>ApplicationCacheItemsView.js</file>
<file>ApplicationCacheModel.js</file>
<file>AuditCategories.js</file>
+ <file>AuditController.js</file>
<file>AuditFormatters.js</file>
<file>AuditLauncherView.js</file>
<file>AuditResultView.js</file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment