2010-12-15 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Dec 2010 08:22:16 +0000 (08:22 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Dec 2010 08:22:16 +0000 (08:22 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: [Extension API] add support for adding/overriding HTTP request headers
        https://bugs.webkit.org/show_bug.cgi?id=50493

        Test: http/tests/inspector/extensions-headers.html

        * inspector/Inspector.idl:
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::willSendRequest): Apply extra headers.
        (WebCore::InspectorController::setExtraHeaders):
        * inspector/InspectorController.h:
        * inspector/front-end/ExtensionAPI.js:
        (WebInspector.injectedExtensionAPI.Resources.prototype.getHAR):
        (WebInspector.injectedExtensionAPI.Resources.prototype.addRequestHeaders):
        * inspector/front-end/ExtensionServer.js:
        (WebInspector.ExtensionServer):
        (WebInspector.ExtensionServer.prototype._onAddRequestHeaders):

2010-12-15  Andrey Kosyakov  <caseq@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: [Extension API] add support for adding/overriding HTTP request headers
        Moved extensions test frameworks under http/tests/inspector, so HTTP tests may reuse it.
        https://bugs.webkit.org/show_bug.cgi?id=50493

        * http/tests/inspector/extensions-headers-expected.txt: Added.
        * http/tests/inspector/extensions-headers.html: Added.
        * http/tests/inspector/extensions-test.js: Renamed from LayoutTests/inspector/extensions-test.js.
        (log):
        (extensionFunctions):
        (initialize_ExtensionsTest.InspectorTest.dispatchOnMessage):
        (initialize_ExtensionsTest.InspectorTest.runExtensionTests):
        (initialize_ExtensionsTest.extensionOutput):
        (initialize_ExtensionsTest.dumpSidebarContent):
        (initialize_ExtensionsTest.reloadPage):
        (test):
        * http/tests/inspector/resources/echo-headers.php: Added.
        * http/tests/inspector/resources/extension-main.html: Renamed from LayoutTests/inspector/resources/extension-main.html.
        * http/tests/inspector/resources/extension-main.js: Renamed from LayoutTests/inspector/resources/extension-main.js.
        (fetchTests.callback):
        (fetchTests):
        (runTests):
        (onTestsDone):
        (dispatchOnFrontend.callbackWrapper):
        (dispatchOnFrontend):
        (callbackAndNextTest.callbackWrapper):
        (callbackAndNextTest):
        * http/tests/inspector/resources/extension-panel.html: Renamed from LayoutTests/inspector/resources/extension-panel.html.
        * http/tests/inspector/resources/extension-sidebar.html: Renamed from LayoutTests/inspector/resources/extension-sidebar.html.
        * inspector/extensions-api-expected.txt:
        * inspector/extensions-api.html:
        * inspector/extensions-audits-api.html:
        * inspector/extensions-audits.html:
        * inspector/extensions-eval.html:
        * inspector/extensions-events.html:
        * inspector/extensions-resources-expected.txt:
        * inspector/extensions-resources.html:
        * inspector/extensions.html:
        * platform/chromium/test_expectations.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74234 268f45cc-cd09-0410-ab3c-d52691b4dbfc

25 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/extensions-headers-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/inspector/extensions-headers.html [new file with mode: 0644]
LayoutTests/http/tests/inspector/extensions-test.js [moved from LayoutTests/inspector/extensions-test.js with 87% similarity]
LayoutTests/http/tests/inspector/resources/echo-headers.php [new file with mode: 0755]
LayoutTests/http/tests/inspector/resources/extension-main.html [moved from LayoutTests/inspector/resources/extension-main.html with 77% similarity]
LayoutTests/http/tests/inspector/resources/extension-main.js [moved from LayoutTests/inspector/resources/extension-main.js with 100% similarity]
LayoutTests/http/tests/inspector/resources/extension-panel.html [moved from LayoutTests/inspector/resources/extension-panel.html with 100% similarity]
LayoutTests/http/tests/inspector/resources/extension-sidebar.html [moved from LayoutTests/inspector/resources/extension-sidebar.html with 100% similarity]
LayoutTests/inspector/extensions-api-expected.txt
LayoutTests/inspector/extensions-api.html
LayoutTests/inspector/extensions-audits-api.html
LayoutTests/inspector/extensions-audits.html
LayoutTests/inspector/extensions-eval.html
LayoutTests/inspector/extensions-events.html
LayoutTests/inspector/extensions-resources-expected.txt
LayoutTests/inspector/extensions-resources.html
LayoutTests/inspector/extensions.html
LayoutTests/platform/chromium/test_expectations.txt
WebCore/ChangeLog
WebCore/inspector/Inspector.idl
WebCore/inspector/InspectorController.cpp
WebCore/inspector/InspectorController.h
WebCore/inspector/front-end/ExtensionAPI.js
WebCore/inspector/front-end/ExtensionServer.js

index e8bae7f..60bc1cf 100644 (file)
@@ -1,3 +1,46 @@
+2010-12-15  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [Extension API] add support for adding/overriding HTTP request headers
+        Moved extensions test frameworks under http/tests/inspector, so HTTP tests may reuse it.
+        https://bugs.webkit.org/show_bug.cgi?id=50493
+
+        * http/tests/inspector/extensions-headers-expected.txt: Added.
+        * http/tests/inspector/extensions-headers.html: Added.
+        * http/tests/inspector/extensions-test.js: Renamed from LayoutTests/inspector/extensions-test.js.
+        (log):
+        (extensionFunctions):
+        (initialize_ExtensionsTest.InspectorTest.dispatchOnMessage):
+        (initialize_ExtensionsTest.InspectorTest.runExtensionTests):
+        (initialize_ExtensionsTest.extensionOutput):
+        (initialize_ExtensionsTest.dumpSidebarContent):
+        (initialize_ExtensionsTest.reloadPage):
+        (test):
+        * http/tests/inspector/resources/echo-headers.php: Added.
+        * http/tests/inspector/resources/extension-main.html: Renamed from LayoutTests/inspector/resources/extension-main.html.
+        * http/tests/inspector/resources/extension-main.js: Renamed from LayoutTests/inspector/resources/extension-main.js.
+        (fetchTests.callback):
+        (fetchTests):
+        (runTests):
+        (onTestsDone):
+        (dispatchOnFrontend.callbackWrapper):
+        (dispatchOnFrontend):
+        (callbackAndNextTest.callbackWrapper):
+        (callbackAndNextTest):
+        * http/tests/inspector/resources/extension-panel.html: Renamed from LayoutTests/inspector/resources/extension-panel.html.
+        * http/tests/inspector/resources/extension-sidebar.html: Renamed from LayoutTests/inspector/resources/extension-sidebar.html.
+        * inspector/extensions-api-expected.txt:
+        * inspector/extensions-api.html:
+        * inspector/extensions-audits-api.html:
+        * inspector/extensions-audits.html:
+        * inspector/extensions-eval.html:
+        * inspector/extensions-events.html:
+        * inspector/extensions-resources-expected.txt:
+        * inspector/extensions-resources.html:
+        * inspector/extensions.html:
+        * platform/chromium/test_expectations.txt:
+
 2010-12-16  Kent Tamura  <tkent@chromium.org>
 
         Unreviewed, test expectation update.
diff --git a/LayoutTests/http/tests/inspector/extensions-headers-expected.txt b/LayoutTests/http/tests/inspector/extensions-headers-expected.txt
new file mode 100644 (file)
index 0000000..3e67a16
--- /dev/null
@@ -0,0 +1,9 @@
+Tests WebInspector extension API
+
+HTTP_X_WEBINSPECTOR_EXTENSION: test
+HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)
+Started extension.
+Running tests...
+RUNNING TEST: extension_testAddHeaders
+All tests done.
+
diff --git a/LayoutTests/http/tests/inspector/extensions-headers.html b/LayoutTests/http/tests/inspector/extensions-headers.html
new file mode 100644 (file)
index 0000000..8f106fd
--- /dev/null
@@ -0,0 +1,33 @@
+<html>
+<head>
+<script src="inspector-test2.js"></script>
+<script src="extensions-test.js"></script>
+<script type="text/javascript">
+
+function extension_testAddHeaders(nextTest)
+{
+    webInspector.resources.addRequestHeaders({
+        "x-webinspector-extension": "test",
+        "user-agent": "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
+    });
+    webInspector.inspectedWindow.eval("doXHR()", nextTest);
+}
+
+function doXHR()
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", "resources/echo-headers.php", false);
+    xhr.send(null);
+    // Can't use output() here due to output order instability: this is invoked by inspectedWindow.eval(),
+    // which is not serialized against output from extension, as the latter is posted asynchronously via
+    // postMessage to front-end window.
+    document.getElementById("headers").textContent = xhr.responseText;
+}
+
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests WebInspector extension API</p>
+<div style="white-space: pre" id="headers"></div>
+</body>
+</html>
@@ -35,7 +35,11 @@ InspectorTest.dispatchOnMessage = function(messageId, callback, recurring)
 InspectorTest.runExtensionTests = function()
 {
     InjectedScriptAccess.getDefault().evaluate("location.href", "console", function(result) {
-        var extensionURL = result.description.replace(/\/[^/]*$/, "/resources/extension-main.html");
+        var pageURL = result.description;
+        var extensionURL = (/^https?:/.test(pageURL) ?
+            pageURL.replace(/^(https?:\/\/[^/]*\/).*$/,"$1") :
+            pageURL.replace(/\/inspector\/[^/]*$/, "/http/tests")) +
+            "/inspector/resources/extension-main.html";
         WebInspector.addExtensions([{ startPage: extensionURL }]);
     });
 }
diff --git a/LayoutTests/http/tests/inspector/resources/echo-headers.php b/LayoutTests/http/tests/inspector/resources/echo-headers.php
new file mode 100755 (executable)
index 0000000..ae69597
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+$headers = Array('HTTP_X_WEBINSPECTOR_EXTENSION', 'HTTP_USER_AGENT');
+
+foreach ($headers as $header) {
+    echo $header . ": " . $_SERVER[$header] . "\n";
+}
+
+?>
@@ -1,6 +1,6 @@
 <html>
 <head>
-<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../inspector-test.js"></script>
 <script type="text/javascript">
 function output(message)
 {
index c941f63..038db59 100644 (file)
@@ -51,6 +51,7 @@ RUNNING TEST: extension_testAPI
             Other : "other"
         }
         getHAR : <function>
+        addRequestHeaders : <function>
     }
     onReset : {
         addListener : <function>
index fc9da0f..ad1109f 100644 (file)
@@ -1,7 +1,7 @@
 <html>
 <head>
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script type="text/javascript">
 
 function extension_testAPI(nextTest)
index 118fe0d..0d4b0b2 100755 (executable)
@@ -1,7 +1,7 @@
 <html>
 <head>
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script src="audits-tests2.js"></script>
 <script src="extensions-audits-tests.js"></script>
 
index ef65d51..c715d36 100755 (executable)
@@ -1,7 +1,7 @@
 <html>
 <head>
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script src="audits-tests2.js"></script>
 <script src="extensions-audits-tests.js"></script>
 
index 4fd3f9c..887e31a 100755 (executable)
@@ -1,7 +1,7 @@
 <html>
 <head>
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script type="text/javascript">
 
 window.inspectedValue = { str: "foo", num: 42 };
index 3d61701..5ffc2f6 100755 (executable)
@@ -1,7 +1,7 @@
 <html>
 <head>
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script type="text/javascript">
 
 
index b1e3b9a..adb4b30 100644 (file)
@@ -5,10 +5,10 @@ Page reloaded.
 Started extension.
 Running tests...
 RUNNING TEST: extension_testGetHAR
+resource: .../tests/inspector/extensions-test.js
 resource: .../tests/inspector/inspector-test2.js
 resource: .../LayoutTests/inspector/extensions-resources.html
 resource: .../LayoutTests/inspector/extensions-resources.html
-resource: .../LayoutTests/inspector/extensions-test.js
 resource: .../inspector/resources/abe.png
 resource: .../inspector/resources/Ahem.ttf
 resource: .../inspector/resources/audits-style1.css
index 046086f..bd208b9 100755 (executable)
@@ -11,7 +11,7 @@ p { font-family: 'test'; }
 </style>
 
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script type="text/javascript">
 
 function extension_testGetHAR(nextTest)
index 0ee2919..c2f7b7a 100644 (file)
@@ -1,7 +1,7 @@
 <html>
 <head>
 <script src="../http/tests/inspector/inspector-test2.js"></script>
-<script src="extensions-test.js"></script>
+<script src="../http/tests/inspector/extensions-test.js"></script>
 <script type="text/javascript">
 
 function extension_testCreatePanel(nextTest)
index 570fda5..f803586 100644 (file)
@@ -623,6 +623,7 @@ WONTFIX SKIP : inspector/extensions-audits-api.html = FAIL
 WONTFIX SKIP : inspector/extensions-events.html = FAIL
 WONTFIX SKIP : inspector/extensions-eval.html = FAIL
 WONTFIX SKIP : inspector/extensions-resources.html = TIMEOUT CRASH
+WONTFIX SKIP : inspector/tests/inspector/extensions-headers.html = FAIL
 
 // Inspector tests in Debug build are very slow.  If we remove SLOW, we'll see
 // random TIMEOUTs.  Is this issue DRT-specific?
index 1744ea5..f34b2d9 100644 (file)
@@ -1,3 +1,24 @@
+2010-12-15  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [Extension API] add support for adding/overriding HTTP request headers
+        https://bugs.webkit.org/show_bug.cgi?id=50493
+
+        Test: http/tests/inspector/extensions-headers.html
+
+        * inspector/Inspector.idl:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::willSendRequest): Apply extra headers.
+        (WebCore::InspectorController::setExtraHeaders):
+        * inspector/InspectorController.h:
+        * inspector/front-end/ExtensionAPI.js:
+        (WebInspector.injectedExtensionAPI.Resources.prototype.getHAR):
+        (WebInspector.injectedExtensionAPI.Resources.prototype.addRequestHeaders):
+        * inspector/front-end/ExtensionServer.js:
+        (WebInspector.ExtensionServer):
+        (WebInspector.ExtensionServer.prototype._onAddRequestHeaders):
+
 2010-12-16  Koan-Sin Tan  <koansin.tan@gmail.com>
 
         Reviewed by Kent Tamura.
index c956613..12e723d 100644 (file)
@@ -95,6 +95,8 @@ module core {
         [notify, domain=Resources] void didCommitLoadForFrame(out Object frame, out Object loader);
         [notify, domain=Resources] void frameDetachedFromParent(out unsigned long frameId);
        
+        [domain=Inspector] void setExtraHeaders(in Object headers);
+
         [domain=Resources] void cachedResources(out Object resources);
         [domain=Resources] void resourceContent(in unsigned long frameId, in String url, in boolean base64Encode, out String content);
 
index 39c8207..173a73b 100644 (file)
@@ -53,6 +53,7 @@
 #include "FrameView.h"
 #include "GraphicsContext.h"
 #include "HTMLFrameOwnerElement.h"
+#include "HTTPHeaderMap.h"
 #include "HitTestResult.h"
 #include "InjectedScript.h"
 #include "InjectedScriptHost.h"
@@ -829,6 +830,12 @@ void InspectorController::willSendRequest(unsigned long identifier, ResourceRequ
     if (m_frontend)
         request.setReportRawHeaders(true);
 
+    if (m_extraHeaders) {
+        HTTPHeaderMap::const_iterator end = m_extraHeaders->end();
+        for (HTTPHeaderMap::const_iterator it = m_extraHeaders->begin(); it != end; ++it)
+            request.setHTTPHeaderField(it->first, it->second);
+    }
+
     bool isMainResource = m_mainResourceIdentifier == identifier;
 
     if (m_timelineAgent)
@@ -1862,6 +1869,18 @@ void InspectorController::reloadPage()
     m_inspectedPage->mainFrame()->navigationScheduler()->scheduleRefresh();
 }
 
+void InspectorController::setExtraHeaders(PassRefPtr<InspectorObject> headers)
+{
+    m_extraHeaders = adoptPtr(new HTTPHeaderMap());
+    InspectorObject::const_iterator end = headers->end();
+    for (InspectorObject::const_iterator it = headers->begin(); it != end; ++it) {
+        String value;
+        if (!it->second->asString(&value))
+            continue;
+        m_extraHeaders->add(it->first, value);
+    }
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR)
index e4db9c6..aaaf53c 100644 (file)
@@ -51,6 +51,7 @@ class Document;
 class DocumentLoader;
 class FloatRect;
 class GraphicsContext;
+class HTTPHeaderMap;
 class HitTestResult;
 class InjectedScript;
 class InjectedScriptHost;
@@ -173,6 +174,8 @@ public:
     void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber);
     void scriptImported(unsigned long identifier, const String& sourceString);
 
+    void setExtraHeaders(PassRefPtr<InspectorObject>);
+
     void ensureSettingsLoaded();
 
     void startTimelineProfiler();
@@ -395,6 +398,7 @@ private:
     bool m_stickyBreakpointsRestored;
 
     OwnPtr<InspectorProfilerAgent> m_profilerAgent;
+    OwnPtr<HTTPHeaderMap> m_extraHeaders;
 #endif
 #if ENABLE(WORKERS)
     typedef HashMap<intptr_t, RefPtr<InspectorWorkerResource> > WorkersMap;
index 0234994..a9a2423 100644 (file)
@@ -126,6 +126,11 @@ Resources.prototype = {
             callback(result);
         }
         return extensionServer.sendRequest({ command: "getHAR" }, callback && callbackWrapper);
+    },
+
+    addRequestHeaders: function(headers)
+    {
+        return extensionServer.sendRequest({ command: "addRequestHeaders", headers: headers, extensionId: location.hostname });
     }
 }
 
index 1050c6f..373c855 100644 (file)
@@ -33,8 +33,10 @@ WebInspector.ExtensionServer = function()
     this._clientObjects = {};
     this._handlers = {};
     this._subscribers = {};
+    this._extraHeaders = {};
     this._status = new WebInspector.ExtensionStatus();
 
+    this._registerHandler("addRequestHeaders", this._onAddRequestHeaders.bind(this));
     this._registerHandler("addAuditCategory", this._onAddAuditCategory.bind(this));
     this._registerHandler("addAuditResult", this._onAddAuditResult.bind(this));
     this._registerHandler("createPanel", this._onCreatePanel.bind(this));
@@ -144,6 +146,29 @@ WebInspector.ExtensionServer.prototype = {
             delete this._subscribers[message.type];
     },
 
+    _onAddRequestHeaders: function(message)
+    {
+        var id = message.extensionId;
+        if (typeof id !== "string")
+            return this._status.E_BADARGTYPE("extensionId", typeof id, "string");
+        var extensionHeaders = this._extraHeaders[id];
+        if (!extensionHeaders) {
+            extensionHeaders = {};
+            this._extraHeaders[id] = extensionHeaders;
+        }
+        for (name in message.headers)
+            extensionHeaders[name] = message.headers[name];
+        var allHeaders = {};
+        for (extension in this._extraHeaders) {
+            var headers = this._extraHeaders[extension];
+            for (name in headers) {
+                if (typeof headers[name] === "string")
+                    allHeaders[name] = headers[name];
+            }
+        }
+        InspectorBackend.setExtraHeaders(allHeaders);
+    },
+
     _onCreatePanel: function(message, port)
     {
         var id = message.id;