Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/hosted_mode/protocol_files_proxy.js |
| diff --git a/third_party/WebKit/Source/devtools/hosted_mode/protocol_files_proxy.js b/third_party/WebKit/Source/devtools/hosted_mode/protocol_files_proxy.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8cdd9f014b0f5e3a583881933fd7d94f0769a742 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/hosted_mode/protocol_files_proxy.js |
| @@ -0,0 +1,65 @@ |
| +var Cache = require("./cache"); |
|
lushnikov
2016/07/22 02:56:21
let's add LICENSE
chenwilliam
2016/07/22 17:35:25
OK. I'll add this snippet to the top of each of my
|
| +var request = require("./request"); |
| + |
| +var protocolFileCache = new Cache(); |
| +var protocolFileToPath = { |
| + "/front_end/sdk/protocol/js_protocol.json": "core/inspector/browser_protocol.json", |
| + "/front_end/sdk/protocol/browser_protocol.json": "platform/v8_inspector/js_protocol.json" |
| +}; |
| +var protocolFiles = Object.keys(protocolFileToPath); |
| + |
| +function getProtocolFile(protocolFile) |
| +{ |
| + return request("http://localhost:9222/json/version") |
| + .then(response => JSON.parse(response)) |
| + .then(getVersion) |
|
lushnikov
2016/07/22 02:56:21
let's inline all this .then statements, as well as
chenwilliam
2016/07/22 17:35:25
Done.
|
| + .then(version => { |
| + protocolFileCache.setVersion(version); |
| + if (protocolFileCache.hasFile(protocolFile)) { |
| + return protocolFileCache.getFile(protocolFile); |
| + } |
| + return requestProtocolFile(protocolFile, version); |
| + }); |
| +} |
| + |
| +function getVersion(browserMetadata) |
| +{ |
| + var match = browserMetadata["WebKit-Version"].match(/\s\(@(\b[0-9a-f]{5,40}\b)/); |
| + var commitHash = match[1]; |
| + return commitHash; |
| +} |
| + |
| +function requestProtocolFile(protocolFile, version) |
| +{ |
| + return request(getURL(protocolFile, version)) |
| + .then(text => convertBase64AsciiToBinary(text)) |
| + .then(data => { |
| + protocolFileCache.cacheFile(protocolFile, data); |
| + return data; |
| + }); |
| +} |
| + |
| +function getURL(protocolFile, commitHash) |
| +{ |
| + var path = protocolFileToPath[protocolFile]; |
| + return `https://chromium.googlesource.com/chromium/src/+/${commitHash}/third_party/WebKit/Source/${path}?format=TEXT`; |
| +} |
| + |
| +function convertBase64AsciiToBinary(string) |
|
lushnikov
2016/07/22 02:56:21
let's inline this
chenwilliam
2016/07/22 17:35:25
Done.
|
| +{ |
| + return new Buffer(string, "base64").toString("binary"); |
| +} |
| + |
| +function loadCache() |
|
lushnikov
2016/07/22 02:56:21
let's remove this - it doesn't give much benefit
chenwilliam
2016/07/22 17:35:25
Done.
|
| +{ |
| + for (file of protocolFiles) { |
| + getProtocolFile(file) |
| + .catch(err => console.log("Make sure you have launched chrome with remote-debugging-port on 9222")); |
| + } |
| +} |
| + |
| +module.exports = { |
| + protocolFiles, |
|
lushnikov
2016/07/22 02:56:21
lets just export a single proxy function:
functio
chenwilliam
2016/07/22 17:35:25
Done.
|
| + getProtocolFile, |
| + loadCache |
| +}; |