-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a subsystem for loading backend API specs from user's browser
- Loading branch information
Showing
17 changed files
with
364 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
resources/unpacked/devtools/front_end/sdk/InspectorBackendExtensionMode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
WebInspector.InspectorBackendExtensionMode = {}; | ||
|
||
WebInspector.InspectorBackendExtensionMode.loadFromExtensionIfNeeded = function() { | ||
if (InspectorBackend.isInitialized()) { | ||
return; | ||
} | ||
|
||
const evalAPI = (lines) => { | ||
let lineNum = 0; | ||
for (let line of lines) { | ||
lineNum += 1; | ||
if (dirac._DEBUG_BACKEND_API) { | ||
console.log("BackendAPI: (eval) ", line); | ||
} | ||
try { | ||
eval(line); | ||
} catch (e) { | ||
throw new Error("BackendAPI: unable to eval API at line #" + lineNum + ":\n" + " " + line + "\n" + e); | ||
} | ||
} | ||
}; | ||
|
||
const backendAPI = Runtime.queryParam("backend_api"); | ||
if (backendAPI) { | ||
const decodedBackendAPI = decodeURIComponent(backendAPI); | ||
const lines = decodedBackendAPI.split("\n"); | ||
if (dirac._DEBUG_BACKEND_API) { | ||
console.log("BackendAPI: backend_api url parameter present (" + lines.length + " registrations)."); | ||
} | ||
evalAPI(lines); | ||
WebInspector.BakedInspectorBackendMode = "external"; | ||
} else { | ||
const lines = WebInspector.BakedInspectorBackendAPI.split("\n"); | ||
if (dirac._DEBUG_BACKEND_API) { | ||
console.log("BackendAPI: backend_api url parameter not present. Using pre-baked backend API (" + lines.length + " registrations)."); | ||
} | ||
evalAPI(lines); | ||
WebInspector.BakedInspectorBackendMode = "internal"; | ||
} | ||
}; | ||
|
||
WebInspector.InspectorBackendExtensionMode.loadFromExtensionIfNeeded(); |
32 changes: 32 additions & 0 deletions
32
resources/unpacked/devtools/front_end/sdk/SupportedCSSPropertiesExtensionMode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
WebInspector.SupportedCSSPropertiesExtensionMode = {}; | ||
|
||
WebInspector.SupportedCSSPropertiesExtensionMode.loadFromExtensionIfNeeded = function() { | ||
const evalCSS = (definitions) => { | ||
try { | ||
eval("WebInspector.CSSMetadata._generatedProperties = " + definitions); | ||
} catch (e) { | ||
throw new Error("BackendCSS: unable to eval CSS" + e); | ||
} | ||
}; | ||
|
||
const encodedBackendCSS = Runtime.queryParam("backend_css"); | ||
if (encodedBackendCSS) { | ||
const backendCSS = decodeURIComponent(encodedBackendCSS); | ||
const lines = backendCSS.split("\n"); | ||
if (dirac._DEBUG_BACKEND_CSS) { | ||
console.log("BackendCSS: backend_css url parameter present (" + lines.length + " definitions)."); | ||
} | ||
evalCSS(backendCSS); | ||
WebInspector.BakedSupportedCSSPropertiesMode = "external"; | ||
} else { | ||
const backendCSS = WebInspector.BakedSupportedCSSProperties; | ||
const lines = backendCSS.split("\n"); | ||
if (dirac._DEBUG_BACKEND_CSS) { | ||
console.log("BackendCSS: backend_css url parameter not present. Using pre-baked backend CSS (" + lines.length + " definitions)."); | ||
} | ||
evalCSS(backendCSS); | ||
WebInspector.BakedSupportedCSSPropertiesMode = "internal"; | ||
} | ||
}; | ||
|
||
WebInspector.SupportedCSSPropertiesExtensionMode.loadFromExtensionIfNeeded(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,9 @@ | |
"storage", | ||
"webRequest", | ||
"http://*/json", | ||
"<all_urls>", | ||
"pageCapture", | ||
"tabs" | ||
], | ||
"manifest_version": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(ns dirac.background.thief | ||
(:require-macros [cljs.core.async.macros :refer [go go-loop]]) | ||
(:require [cljs.core.async :refer [<! chan timeout]] | ||
[chromex.support :refer-macros [oget oset ocall oapply]] | ||
[chromex.logging :refer-macros [log info warn error group group-end]] | ||
[chromex.ext.page-capture :as page-capture] | ||
[dirac.mime :as mime] | ||
[dirac.quoted-printable :as qp] | ||
[goog.string :as gstring] | ||
[dirac.utils :as utils] | ||
[dirac.background.tools :as tools] | ||
[clojure.string :as string])) | ||
|
||
; -- inspector-js ----------------------------------------------------------------------------------------------------------- | ||
|
||
(defn extract-inspector-js [source] | ||
(let [multipart (mime/parse-multipart-mime source) | ||
_ (assert (= (count (:parts multipart)) 1)) | ||
parsed-first-part (mime/parse-mime (first (:parts multipart))) | ||
content-type (get (:headers parsed-first-part) "Content-Type") | ||
_ (assert (= content-type "text/html")) | ||
content-transfer-encoding (get (:headers parsed-first-part) "Content-Transfer-Encoding") | ||
_ (assert (= content-transfer-encoding "quoted-printable")) | ||
encoded-body (:body parsed-first-part)] | ||
(case content-transfer-encoding | ||
"quoted-printable" (qp/decode-quoted-printable encoded-body)))) | ||
|
||
; -- backend api ------------------------------------------------------------------------------------------------------------ | ||
|
||
(defn extract-backend-api [inspector-js-source] | ||
(let [re (js/RegExp. ";InspectorBackend\\.register(.*?)\\)" "gm") | ||
res #js []] | ||
(loop [] | ||
(when-let [m (.exec re inspector-js-source)] | ||
(.push res (.substring (first m) 1)) | ||
(recur))) | ||
(.join res "\n"))) | ||
|
||
(defn steal-inspector-js [multipart-mime] | ||
(-> multipart-mime | ||
(gstring/canonicalizeNewlines) | ||
(extract-inspector-js))) | ||
|
||
(defn steal-backend-api [inspector-js] | ||
(-> inspector-js | ||
(extract-backend-api))) | ||
|
||
; -- backend css ------------------------------------------------------------------------------------------------------------ | ||
|
||
(defn extract-backend-css [inspector-js-source] | ||
(let [re (js/RegExp. ";WebInspector\\.CSSMetadata\\._generatedProperties=(\\[.*\\])" "g")] | ||
(if-let [m (re-find re inspector-js-source)] | ||
(second m)))) | ||
|
||
(defn insert-css-newlines [source] | ||
(string/replace source "}," "},\n")) | ||
|
||
(defn steal-backend-css [inspector-js] | ||
(-> inspector-js | ||
(extract-backend-css) | ||
(insert-css-newlines))) | ||
|
||
; -- robbery entry point ---------------------------------------------------------------------------------------------------- | ||
|
||
(defn scrape-bundled-devtools! [] | ||
(go | ||
(let [tab-id (<! (tools/create-bundled-devtools-inspector-window!)) | ||
[mhtml] (<! (page-capture/save-as-mhtml (js-obj "tabId" tab-id))) | ||
_ (tools/close-tab-with-id! tab-id) | ||
multipart-mime (<! (utils/convert-blob-to-string mhtml)) | ||
inspector-js (steal-inspector-js multipart-mime) | ||
backend-api (steal-backend-api inspector-js) | ||
backend-css (steal-backend-css inspector-js)] | ||
[backend-api backend-css]))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.