Title: [126215] trunk/Source/WebCore
Revision
126215
Author
[email protected]
Date
2012-08-21 16:30:25 -0700 (Tue, 21 Aug 2012)

Log Message

Web Inspector: Embeddable Web Inspector
https://bugs.webkit.org/show_bug.cgi?id=91528

Patch by Gabriel Peal <[email protected]> on 2012-08-21
Reviewed by Pavel Feldman.

Adds functionality to the inspector such that it is better suited to run embedded in another webpage. It adds the ability to prepopulate the timeline panel with an existing recording among other controls.

* English.lproj/localizedStrings.js:
* inspector/front-end/InspectorFrontendAPI.js:
(InspectorFrontendAPI.dispatchQueryParameters):
(InspectorFrontendAPI.loadTimelineFromURL):
* inspector/front-end/InspectorFrontendHostStub.js:
(.WebInspector.InspectorFrontendHostStub.prototype.hiddenPanels):
(.WebInspector.InspectorFrontendHostStub.prototype.loadResourceSynchronously):
* inspector/front-end/InspectorView.js:
* inspector/front-end/TimelineModel.js:
(WebInspector.TimelineModel.prototype.loadFromURL.onDataReceived):
(WebInspector.TimelineModel.prototype.loadFromURL.parseAndImportData):
(WebInspector.TimelineModel.prototype.loadFromURL.onLoad):
(WebInspector.TimelineModel.prototype.loadFromURL):
* inspector/front-end/TimelinePanel.js:
(WebInspector.TimelinePanel.prototype.loadFromURL):
* inspector/front-end/inspector.js:
(WebInspector._createPanels):
(WebInspector.loaded):
* inspector/front-end/utilities.js:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126214 => 126215)


--- trunk/Source/WebCore/ChangeLog	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/ChangeLog	2012-08-21 23:30:25 UTC (rev 126215)
@@ -1,3 +1,32 @@
+2012-08-21  Gabriel Peal  <[email protected]>
+
+        Web Inspector: Embeddable Web Inspector
+        https://bugs.webkit.org/show_bug.cgi?id=91528
+
+        Reviewed by Pavel Feldman.
+
+        Adds functionality to the inspector such that it is better suited to run embedded in another webpage. It adds the ability to prepopulate the timeline panel with an existing recording among other controls.
+
+        * English.lproj/localizedStrings.js:
+        * inspector/front-end/InspectorFrontendAPI.js:
+        (InspectorFrontendAPI.dispatchQueryParameters):
+        (InspectorFrontendAPI.loadTimelineFromURL):
+        * inspector/front-end/InspectorFrontendHostStub.js:
+        (.WebInspector.InspectorFrontendHostStub.prototype.hiddenPanels):
+        (.WebInspector.InspectorFrontendHostStub.prototype.loadResourceSynchronously):
+        * inspector/front-end/InspectorView.js:
+        * inspector/front-end/TimelineModel.js:
+        (WebInspector.TimelineModel.prototype.loadFromURL.onDataReceived):
+        (WebInspector.TimelineModel.prototype.loadFromURL.parseAndImportData):
+        (WebInspector.TimelineModel.prototype.loadFromURL.onLoad):
+        (WebInspector.TimelineModel.prototype.loadFromURL):
+        * inspector/front-end/TimelinePanel.js:
+        (WebInspector.TimelinePanel.prototype.loadFromURL):
+        * inspector/front-end/inspector.js:
+        (WebInspector._createPanels):
+        (WebInspector.loaded):
+        * inspector/front-end/utilities.js:
+
 2012-08-21  Robin Cao  <[email protected]>
 
         [BlackBerry] Add support for getUserMedia

Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (126214 => 126215)


--- trunk/Source/WebCore/English.lproj/localizedStrings.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -582,9 +582,9 @@
 localizedStrings["Save timeline data\u2026"] = "Save Timeline data\u2026";
 localizedStrings["Load timeline data"] = "Load Timeline data";
 localizedStrings["Save timeline data"] = "Save Timeline data";
-localizedStrings["Timeline.loadFromFile: An error occurred reading the file \"%s\""] = "Timeline.loadFromFile: An error occurred while reading the file \"%s\"";
-localizedStrings["Timeline.loadFromFile: File \"%s\" is not readable"] = "Timeline.loadFromFile: File \"%s\" is not readable";
-localizedStrings["Timeline.loadFromFile: File \"%s\" not found."] = "Timeline.loadFromFile: File \"%s\" not found.";
+localizedStrings["An error occurred reading the file \"%s\""] = "An error occurred while reading the file \"%s\"";
+localizedStrings["File \"%s\" is not readable"] = "File \"%s\" is not readable";
+localizedStrings["File \"%s\" not found."] = "File \"%s\" not found.";
 localizedStrings["Filter out records shorter than %s"] = "Filter out records shorter than %s";
 localizedStrings["Show user agent styles"] = "Show user agent styles";
 localizedStrings["Show script folders"] = "Show script folders";

Modified: trunk/Source/WebCore/inspector/front-end/InspectorFrontendAPI.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/InspectorFrontendAPI.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/InspectorFrontendAPI.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -52,7 +52,7 @@
 
     setTimelineProfilingEnabled: function(enabled)
     {
-        WebInspector.panel("timeline").setTimelineProfilingEnabled(enabled);
+        WebInspector.showPanel("timeline").setTimelineProfilingEnabled(enabled);
     },
 
     isProfilingJavaScript: function()
@@ -133,6 +133,20 @@
         InspectorFrontendAPI._pendingCommands.push(signature);
     },
 
+    dispatchQueryParameters: function()
+    {
+        if ("dispatch" in WebInspector.queryParamsObject)
+            InspectorFrontendAPI.dispatch(JSON.parse(window.decodeURI(WebInspector.queryParamsObject["dispatch"])));
+    },
+
+    /**
+     * @param {string} url
+     */
+    loadTimelineFromURL: function(url) 
+    {
+        WebInspector.showPanel("timeline").loadFromURL(url);
+    },
+
     loadCompleted: function()
     {
         InspectorFrontendAPI._isLoaded = true;

Modified: trunk/Source/WebCore/inspector/front-end/InspectorFrontendHostStub.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/InspectorFrontendHostStub.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/InspectorFrontendHostStub.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -102,7 +102,7 @@
 
     hiddenPanels: function()
     {
-        return "";
+        return WebInspector.queryParamsObject["hiddenPanels"] || "";
     },
 
     inspectedURLChanged: function(url)
@@ -179,7 +179,7 @@
 
     loadResourceSynchronously: function(url)
     {
-        return "";
+        return loadXHR(url);
     },
 
     setZoomFactor: function(zoom)

Modified: trunk/Source/WebCore/inspector/front-end/InspectorView.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/InspectorView.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/InspectorView.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -95,7 +95,10 @@
     {
         return this._currentPanel;
     },
-
+    
+    /**
+     * @param {WebInspector.Panel} x
+     */
     setCurrentPanel: function(x)
     {
         if (this._currentPanel === x)

Modified: trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -160,7 +160,7 @@
     _didEditContent: function(error)
     {
         if (error) {
-            WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
+            WebInspector.showErrorMessage(error);
             return;
         }
         if (!this._javaScriptSource.supportsEnabledBreakpointsWhileEditing())

Modified: trunk/Source/WebCore/inspector/front-end/TimelineModel.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/TimelineModel.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/TimelineModel.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -197,11 +197,16 @@
 
         function parseAndImportData(data)
         {
-            var records = JSON.parse(data);
-            parsingProgress.done();
-            this.reset();
-            processingProgress.setTotalWork(records.length);
-            this._loadNextChunk(processingProgress, records, 1);
+            try {
+                var records = JSON.parse(data);
+                parsingProgress.done();
+                this.reset();
+                processingProgress.setTotalWork(records.length);
+                this._loadNextChunk(processingProgress, records, 1);
+            } catch (e) {
+                WebInspector.showErrorMessage("Malformed timeline data.");
+                progress.done();
+            }
         }
 
         function onLoad(e)
@@ -216,15 +221,15 @@
             progress.done();
             switch(e.target.error.code) {
             case e.target.error.NOT_FOUND_ERR:
-                WebInspector.log(WebInspector.UIString('Timeline.loadFromFile: File "%s" not found.', file.name));
+                WebInspector.showErrorMessage(WebInspector.UIString("File \"%s\" not found.", file.name));
             break;
             case e.target.error.NOT_READABLE_ERR:
-                WebInspector.log(WebInspector.UIString('Timeline.loadFromFile: File "%s" is not readable', file.name));
+                WebInspector.showErrorMessage(WebInspector.UIString("File \"%s\" is not readable", file.name));
             break;
             case e.target.error.ABORT_ERR:
                 break;
             default:
-                WebInspector.log(WebInspector.UIString('Timeline.loadFromFile: An error occurred while reading the file "%s"', file.name));
+                WebInspector.showErrorMessage(WebInspector.UIString("An error occurred while reading the file \"%s\"", file.name));
             }
         }
 
@@ -243,6 +248,39 @@
         reader.readAsText(file);
     },
 
+    /**
+     * @param {string} url
+     */
+    loadFromURL: function(url, progress)
+    {
+        var compositeProgress = new WebInspector.CompositeProgress(progress);
+        var loadingProgress = compositeProgress.createSubProgress(1);
+        var parsingProgress = compositeProgress.createSubProgress(1);
+        var processingProgress = compositeProgress.createSubProgress(1);
+
+        // FIXME: extract parsing routines so that they did not require too many progress objects.
+        function parseAndImportData(data)
+        {
+            try {
+                var records = JSON.parse(data);
+                parsingProgress.done();
+                this.reset();
+                processingProgress.setTotalWork(records.length);
+                this._loadNextChunk(processingProgress, records, 1);
+            } catch (e) {
+                WebInspector.showErrorMessage("Malformed timeline data.");
+                progress.done();
+            }
+        }
+
+        var responseText = loadXHR(url);
+        if (responseText) {
+            loadingProgress.done();
+            parsingProgress.setTotalWork(1);
+            setTimeout(parseAndImportData.bind(this, responseText), 0);
+        }
+    },
+
     saveToFile: function()
     {
         var records = ['[' + JSON.stringify(new String(window.navigator.appVersion))];

Modified: trunk/Source/WebCore/inspector/front-end/TimelinePanel.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/TimelinePanel.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/TimelinePanel.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -349,8 +349,31 @@
 
     _loadFromFile: function()
     {
+        var progressIndicator = this._prepareToLoadTimeline();
+        if (!progressIndicator)
+            return;
+        this._model.loadFromFile(this._fileSelectorElement.files[0], progressIndicator);
+        this._createFileSelector();
+    },
+
+    /**
+     * @param {string} url
+     */
+    loadFromURL: function(url)
+    {
+        var progressIndicator = this._prepareToLoadTimeline();
+        if (!progressIndicator)
+            return;
+        this._model.loadFromURL(url, progressIndicator);
+    },
+
+    /**
+     * @return {?WebInspector.ProgressIndicator}
+     */
+    _prepareToLoadTimeline: function()
+    {
         if (this._operationInProgress)
-            return;
+            return null;
         if (this.toggleTimelineButton.toggled) {
             this.toggleTimelineButton.toggled = false;
             this._model.stopRecord();
@@ -358,8 +381,7 @@
         var progressIndicator = new WebInspector.ProgressIndicator();
         progressIndicator.addEventListener(WebInspector.ProgressIndicator.Events.Done, this._setOperationInProgress.bind(this, null));
         this._setOperationInProgress(progressIndicator);
-        this._model.loadFromFile(this._fileSelectorElement.files[0], progressIndicator);
-        this._createFileSelector();
+        return progressIndicator;
     },
 
     _rootRecord: function()

Modified: trunk/Source/WebCore/inspector/front-end/externs.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/externs.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/externs.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -142,6 +142,8 @@
  */
 WebInspector.log = function(message, messageLevel, showConsole) {}
 
+WebInspector.showErrorMessage = function(error) {}
+
 WebInspector.addMainEventListeners = function(doc) {}
 
 WebInspector.openResource = function(url, external) {}

Modified: trunk/Source/WebCore/inspector/front-end/inspector.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/inspector.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -56,7 +56,7 @@
             return panelDescriptors;
         }
         var allDescriptors = [elements, resources, network, scripts, timeline, profiles, audits, console];
-        var hiddenPanels = (InspectorFrontendHost.hiddenPanels() || "").split(',');
+        var hiddenPanels = InspectorFrontendHost.hiddenPanels();
         for (var i = 0; i < allDescriptors.length; ++i) {
             if (hiddenPanels.indexOf(allDescriptors[i].name) === -1)
                 panelDescriptors.push(allDescriptors[i]);
@@ -433,7 +433,14 @@
         }
         return;
     }
+
     WebInspector.doLoadedDone();
+
+    // In case of loading as a web page with no bindings / harness, kick off initialization manually.
+    if (InspectorFrontendHost.isStub) {
+        InspectorFrontendAPI.dispatchQueryParameters();
+        WebInspector._doLoadedDoneWithCapabilities();
+    }
 }
 
 WebInspector.doLoadedDone = function()
@@ -458,8 +465,6 @@
     PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", null));
     PageAgent.canOverrideGeolocation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideGeolocation", null));
     PageAgent.canOverrideDeviceOrientation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceOrientation", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
-    if ("debugLoad" in WebInspector.queryParamsObject)
-        WebInspector._doLoadedDoneWithCapabilities();
 }
 
 WebInspector._doLoadedDoneWithCapabilities = function()
@@ -993,6 +998,11 @@
     logMessage(message);
 }
 
+WebInspector.showErrorMessage = function(error)
+{
+    WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
+}
+
 WebInspector.inspect = function(payload, hints)
 {
     var object = WebInspector.RemoteObject.fromPayload(payload);

Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (126214 => 126215)


--- trunk/Source/WebCore/inspector/front-end/utilities.js	2012-08-21 23:30:19 UTC (rev 126214)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js	2012-08-21 23:30:25 UTC (rev 126215)
@@ -726,7 +726,41 @@
     }
 };
 
+/**
+ * @param {string} url
+ * @param {boolean=} async
+ * @param {function(?string)=} callback
+ * @return {?string}
+ */
+function loadXHR(url, async, callback) 
+{
+    function onReadyStateChanged() 
+    {
+        if (xhr.readyState !== XMLHttpRequest.DONE)
+            return;
 
+        if (xhr.status === 200) {
+            callback(xhr.responseText);
+            return;
+        }
+
+        callback(null); 
+   }
+
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", url, async);
+    if (async)
+        xhr._onreadystatechange_ = onReadyStateChanged;        
+    xhr.send(null);
+
+    if (!async) {
+        if (xhr.status === 200) 
+            return xhr.responseText;
+        return null;
+    }
+    return null;
+}
+
 /**
  * @constructor
  */
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to