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

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

Issue 2195113002: DevTools: improve UX for hosted mode + fix bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit: formatting Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/hosted_mode/favicon.ico ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var fs = require("fs"); 5 var fs = require("fs");
6 var http = require("http"); 6 var http = require("http");
7 var https = require("https"); 7 var https = require("https");
8 var path = require("path"); 8 var path = require("path");
9 var parseURL = require("url").parse; 9 var parseURL = require("url").parse;
10 10
11 var port = parseInt(process.env.PORT, 10) || 8090; 11 var remoteDebuggingPort = parseInt(process.env.REMOTE_DEBUGGING_PORT, 10) || 922 2;
12 var serverPort = parseInt(process.env.PORT, 10) || 8090;
13 var entryLink = `http://localhost:${remoteDebuggingPort}#http://localhost:${serv erPort}/front_end/inspector.html?experiments=true`;
12 14
13 http.createServer(requestHandler).listen(port); 15 http.createServer(requestHandler).listen(serverPort);
14 console.log("Started hosted mode server at http://localhost:" + port); 16 console.log("Started hosted mode server at http://localhost:" + serverPort);
15 17
16 function requestHandler(request, response) 18 function requestHandler(request, response)
17 { 19 {
18 var filePath = parseURL(request.url).pathname; 20 var filePath = parseURL(request.url).pathname;
19 if (filePath === "/front_end/InspectorBackendCommands.js") { 21 if (filePath === "/") {
20 sendResponse(200, " "); 22 sendResponse(200, `<html>Please go to <a href="${entryLink}">${entryLink }</a></html>`);
21 return; 23 return;
22 } 24 }
23 25
24 var proxiedFile = proxy(filePath, sendResponse); 26 var proxiedFile = proxy(filePath, sendResponse);
25 if (proxiedFile) { 27 if (proxiedFile) {
26 proxiedFile 28 proxiedFile
27 .then(data => sendResponse(200, data)) 29 .then(data => sendResponse(200, data))
28 .catch(handleProxyError); 30 .catch(handleProxyError);
29 return; 31 return;
30 } 32 }
31 33
32 function handleProxyError(err) 34 function handleProxyError(err)
33 { 35 {
34 console.log(`Error fetching over the internet file ${filePath}:`, err); 36 console.log(`Error fetching over the internet file ${filePath}:`, err);
37 console.log(`Make sure you opened Chrome with the flag "--remote-debuggi ng-port=${remoteDebuggingPort}"`);
35 sendResponse(500, "500 - Internal Server Error"); 38 sendResponse(500, "500 - Internal Server Error");
36 } 39 }
37 40
38 var absoluteFilePath = path.join(process.cwd(), filePath); 41 var absoluteFilePath = path.join(process.cwd(), filePath);
42 if (filePath === "/favicon.ico")
lushnikov 2016/08/02 17:17:15 isn't there a favicon in the cloud already? Let's
paulirish 2016/08/03 18:26:14 https://chrome-devtools-frontend.appspot.com/favic
chenwilliam 2016/08/03 22:30:39 Done. Discussed with Paul and we agreed the Chrome
43 absoluteFilePath = path.join(__dirname, filePath);
39 fs.exists(absoluteFilePath, fsExistsCallback); 44 fs.exists(absoluteFilePath, fsExistsCallback);
40 45
41 function fsExistsCallback(fileExists) 46 function fsExistsCallback(fileExists)
42 { 47 {
43 if (!fileExists) { 48 if (!fileExists) {
44 console.log(`Cannot find file ${absoluteFilePath}`); 49 console.log(`Cannot find file ${absoluteFilePath}`);
45 sendResponse(404, "404 - File not found"); 50 sendResponse(404, "404 - File not found");
46 return; 51 return;
47 } 52 }
48 fs.readFile(absoluteFilePath, "binary", readFileCallback); 53 fs.readFile(absoluteFilePath, "binary", readFileCallback);
(...skipping 11 matching lines...) Expand all
60 65
61 function sendResponse(statusCode, data) 66 function sendResponse(statusCode, data)
62 { 67 {
63 response.writeHead(statusCode); 68 response.writeHead(statusCode);
64 response.write(data, "binary"); 69 response.write(data, "binary");
65 response.end(); 70 response.end();
66 } 71 }
67 } 72 }
68 73
69 var proxyFilePathToURL = { 74 var proxyFilePathToURL = {
70 "/front_end/sdk/protocol/js_protocol.json": getWebKitURL.bind(null, "platfor m/v8_inspector/js_protocol.json"), 75 "/front_end/sdk/protocol/js_protocol.json": getWebKitURL.bind(null, "platfor m/v8_inspector/js_protocol.json"),
lushnikov 2016/08/02 17:17:15 let's come up with some descriptive name instead o
chenwilliam 2016/08/03 22:30:39 Done.
71 "/front_end/sdk/protocol/browser_protocol.json": getWebKitURL.bind(null, "co re/inspector/browser_protocol.json"), 76 "/front_end/sdk/protocol/browser_protocol.json": getWebKitURL.bind(null, "co re/inspector/browser_protocol.json"),
72 "/front_end/SupportedCSSProperties.js": getFrontendURL.bind(null, "Supported CSSProperties.js") 77 "/front_end/SupportedCSSProperties.js": getFrontendURL.bind(null, "Supported CSSProperties.js"),
78 "/front_end/InspectorBackendCommands.js": getFrontendURL.bind(null, "Inspect orBackendCommands.js")
lushnikov 2016/08/02 17:26:26 one more question: why do we need to serve protoco
chenwilliam 2016/08/03 22:30:39 After discussing with dgozman, we don't need to se
73 }; 79 };
74 80
75 function getWebKitURL(path, commitHash) 81 function getWebKitURL(path, commitHash)
76 { 82 {
77 return { 83 return {
78 url: `https://chromium.googlesource.com/chromium/src/+/${commitHash}/thi rd_party/WebKit/Source/${path}?format=TEXT`, 84 url: `https://chromium.googlesource.com/chromium/src/+/${commitHash}/thi rd_party/WebKit/Source/${path}?format=TEXT`,
79 isBase64: true 85 isBase64: true
80 } 86 }
81 } 87 }
82 88
83 function getFrontendURL(path, commitHash) 89 function getFrontendURL(path, commitHash)
84 { 90 {
85 return { 91 return {
86 url: `https://chrome-devtools-frontend.appspot.com/serve_file/@${commitH ash}/${path}`, 92 url: `https://chrome-devtools-frontend.appspot.com/serve_file/@${commitH ash}/${path}`,
87 isBase64: false 93 isBase64: false
88 } 94 }
89 } 95 }
90 96
91 var proxyFileCache = new Map(); 97 var proxyFileCache = new Map();
92 98
93 function proxy(filePath) 99 function proxy(filePath)
94 { 100 {
95 if (!(filePath in proxyFilePathToURL)) 101 if (!(filePath in proxyFilePathToURL))
96 return null; 102 return null;
97 return fetch("http://localhost:9222/json/version") 103 return fetch(`http://localhost:${remoteDebuggingPort}/json/version`)
98 .then(onBrowserMetadata); 104 .then(onBrowserMetadata);
99 105
100 function onBrowserMetadata(metadata) 106 function onBrowserMetadata(metadata)
101 { 107 {
102 var metadataObject = JSON.parse(metadata); 108 var metadataObject = JSON.parse(metadata);
103 var match = metadataObject["WebKit-Version"].match(/\s\(@(\b[0-9a-f]{5,4 0}\b)/); 109 var match = metadataObject["WebKit-Version"].match(/\s\(@(\b[0-9a-f]{5,4 0}\b)/);
104 var commitHash = match[1]; 110 var commitHash = match[1];
105 var proxyFile = proxyFilePathToURL[filePath](commitHash); 111 var proxyFile = proxyFilePathToURL[filePath](commitHash);
106 var proxyFileURL = proxyFile.url; 112 var proxyFileURL = proxyFile.url;
107 if (proxyFileCache.has(proxyFileURL)) 113 if (proxyFileCache.has(proxyFileURL))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (response.statusCode !== 200) { 148 if (response.statusCode !== 200) {
143 reject(new Error(`Request error: + ${response.statusCode}`)); 149 reject(new Error(`Request error: + ${response.statusCode}`));
144 return; 150 return;
145 } 151 }
146 var body = ""; 152 var body = "";
147 response.on("data", chunk => body += chunk); 153 response.on("data", chunk => body += chunk);
148 response.on("end", () => resolve(body)); 154 response.on("end", () => resolve(body));
149 } 155 }
150 } 156 }
151 157
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/hosted_mode/favicon.ico ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698