Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 var fs = require("fs"); | 4 var fs = require("fs"); |
| 5 var http = require("http"); | 5 var http = require("http"); |
| 6 var https = require("https"); | 6 var https = require("https"); |
| 7 var path = require("path"); | 7 var path = require("path"); |
| 8 var parseURL = require("url").parse; | 8 var parseURL = require("url").parse; |
| 9 var Stream = require("stream").Transform; | 9 var Stream = require("stream").Transform; |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 function handleProxyError(err) | 35 function handleProxyError(err) |
| 36 { | 36 { |
| 37 console.log(`Error fetching over the internet file ${filePath}:`, err); | 37 console.log(`Error fetching over the internet file ${filePath}:`, err); |
| 38 console.log(`Make sure you opened Chrome with the flag "--remote-debuggi ng-port=${remoteDebuggingPort}"`); | 38 console.log(`Make sure you opened Chrome with the flag "--remote-debuggi ng-port=${remoteDebuggingPort}"`); |
| 39 sendResponse(500, "500 - Internal Server Error"); | 39 sendResponse(500, "500 - Internal Server Error"); |
| 40 } | 40 } |
| 41 | 41 |
| 42 var absoluteFilePath = path.join(process.cwd(), filePath); | 42 var absoluteFilePath = path.join(process.cwd(), filePath); |
| 43 if (!path.resolve(absoluteFilePath).startsWith(devtoolsFolder)) { | 43 if (!path.resolve(absoluteFilePath).startsWith(devtoolsFolder)) { |
| 44 console.log(`File requested is outside of devtools folder: ${devtoolsFol der}`); | 44 console.log(`File requested is outside of devtools folder: ${devtoolsFol der}`); |
| 45 sendResponse(403, "`403 - Access denied. File requested is outside of de vtools folder: ${devtoolsFolder}`"); | 45 sendResponse(403, `403 - Access denied. File requested is outside of dev tools folder: ${devtoolsFolder}`); |
|
chenwilliam
2016/08/10 22:04:55
The surrounding double quotes were causing the pla
| |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 fs.exists(absoluteFilePath, fsExistsCallback); | 49 fs.exists(absoluteFilePath, fsExistsCallback); |
| 50 | 50 |
| 51 function fsExistsCallback(fileExists) | 51 function fsExistsCallback(fileExists) |
| 52 { | 52 { |
| 53 if (!fileExists) { | 53 if (!fileExists) { |
| 54 console.log(`Cannot find file ${absoluteFilePath}`); | 54 console.log(`Cannot find file ${absoluteFilePath}`); |
| 55 sendResponse(404, "404 - File not found"); | 55 sendResponse(404, "404 - File not found"); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 86 { | 86 { |
| 87 return `https://chrome-devtools-frontend.appspot.com/serve_file/@${commitHas h}/${path}`; | 87 return `https://chrome-devtools-frontend.appspot.com/serve_file/@${commitHas h}/${path}`; |
| 88 } | 88 } |
| 89 | 89 |
| 90 var proxyFileCache = new Map(); | 90 var proxyFileCache = new Map(); |
| 91 | 91 |
| 92 function proxy(filePath) | 92 function proxy(filePath) |
| 93 { | 93 { |
| 94 if (!(filePath in proxyFilePathToURL)) | 94 if (!(filePath in proxyFilePathToURL)) |
| 95 return null; | 95 return null; |
| 96 if (process.env.CHROMIUM_COMMIT) | |
| 97 return onProxyFileURL(proxyFilePathToURL[filePath](process.env.CHROMIUM_ COMMIT)); | |
| 96 return fetch(`http://localhost:${remoteDebuggingPort}/json/version`) | 98 return fetch(`http://localhost:${remoteDebuggingPort}/json/version`) |
| 97 .then(onBrowserMetadata); | 99 .then(onBrowserMetadata) |
| 100 .then(onProxyFileURL); | |
| 98 | 101 |
| 99 function onBrowserMetadata(metadata) | 102 function onBrowserMetadata(metadata) |
| 100 { | 103 { |
| 101 var metadataObject = JSON.parse(metadata); | 104 var metadataObject = JSON.parse(metadata); |
| 102 var match = metadataObject["WebKit-Version"].match(/\s\(@(\b[0-9a-f]{5,4 0}\b)/); | 105 var match = metadataObject["WebKit-Version"].match(/\s\(@(\b[0-9a-f]{5,4 0}\b)/); |
| 103 var commitHash = match[1]; | 106 var commitHash = match[1]; |
| 104 var proxyFileURL = proxyFilePathToURL[filePath](commitHash); | 107 var proxyFileURL = proxyFilePathToURL[filePath](commitHash); |
| 108 return proxyFileURL; | |
| 109 } | |
| 110 | |
| 111 function onProxyFileURL(proxyFileURL) | |
| 112 { | |
| 105 if (proxyFileCache.has(proxyFileURL)) | 113 if (proxyFileCache.has(proxyFileURL)) |
| 106 return proxyFileCache.get(proxyFileURL); | 114 return Promise.resolve(proxyFileCache.get(proxyFileURL)); |
| 107 return fetch(proxyFileURL) | 115 return fetch(proxyFileURL) |
| 108 .then(cacheProxyFile.bind(null, proxyFileURL)); | 116 .then(cacheProxyFile.bind(null, proxyFileURL)); |
| 109 } | 117 } |
| 110 | 118 |
| 111 function cacheProxyFile(proxyFileURL, data) | 119 function cacheProxyFile(proxyFileURL, data) |
| 112 { | 120 { |
| 113 proxyFileCache.set(proxyFileURL, data); | 121 proxyFileCache.set(proxyFileURL, data); |
| 114 return data; | 122 return data; |
| 115 } | 123 } |
| 116 } | 124 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 140 if (response.statusCode !== 200) { | 148 if (response.statusCode !== 200) { |
| 141 reject(new Error(`Request error: + ${response.statusCode}`)); | 149 reject(new Error(`Request error: + ${response.statusCode}`)); |
| 142 return; | 150 return; |
| 143 } | 151 } |
| 144 var body = new Stream(); | 152 var body = new Stream(); |
| 145 response.on("data", chunk => body.push(chunk)); | 153 response.on("data", chunk => body.push(chunk)); |
| 146 response.on("end", () => resolve(body.read())); | 154 response.on("end", () => resolve(body.read())); |
| 147 } | 155 } |
| 148 } | 156 } |
| 149 | 157 |
| OLD | NEW |