Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: third_party/WebKit/Source/devtools/hosted_mode/protocol_files_proxy.js

Issue 2167413002: DevTools: implement proxy server for hosted mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 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
2 var request = require("./request");
3
4 var protocolFileCache = new Cache();
5 var protocolFileToPath = {
6 "/front_end/sdk/protocol/js_protocol.json": "core/inspector/browser_protocol .json",
7 "/front_end/sdk/protocol/browser_protocol.json": "platform/v8_inspector/js_p rotocol.json"
8 };
9 var protocolFiles = Object.keys(protocolFileToPath);
10
11 function getProtocolFile(protocolFile)
12 {
13 return request("http://localhost:9222/json/version")
14 .then(response => JSON.parse(response))
15 .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.
16 .then(version => {
17 protocolFileCache.setVersion(version);
18 if (protocolFileCache.hasFile(protocolFile)) {
19 return protocolFileCache.getFile(protocolFile);
20 }
21 return requestProtocolFile(protocolFile, version);
22 });
23 }
24
25 function getVersion(browserMetadata)
26 {
27 var match = browserMetadata["WebKit-Version"].match(/\s\(@(\b[0-9a-f]{5,40}\ b)/);
28 var commitHash = match[1];
29 return commitHash;
30 }
31
32 function requestProtocolFile(protocolFile, version)
33 {
34 return request(getURL(protocolFile, version))
35 .then(text => convertBase64AsciiToBinary(text))
36 .then(data => {
37 protocolFileCache.cacheFile(protocolFile, data);
38 return data;
39 });
40 }
41
42 function getURL(protocolFile, commitHash)
43 {
44 var path = protocolFileToPath[protocolFile];
45 return `https://chromium.googlesource.com/chromium/src/+/${commitHash}/third _party/WebKit/Source/${path}?format=TEXT`;
46 }
47
48 function convertBase64AsciiToBinary(string)
lushnikov 2016/07/22 02:56:21 let's inline this
chenwilliam 2016/07/22 17:35:25 Done.
49 {
50 return new Buffer(string, "base64").toString("binary");
51 }
52
53 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.
54 {
55 for (file of protocolFiles) {
56 getProtocolFile(file)
57 .catch(err => console.log("Make sure you have launched chrome with r emote-debugging-port on 9222"));
58 }
59 }
60
61 module.exports = {
62 protocolFiles,
lushnikov 2016/07/22 02:56:21 lets just export a single proxy function: functio
chenwilliam 2016/07/22 17:35:25 Done.
63 getProtocolFile,
64 loadCache
65 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698