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

Side by Side Diff: chrome/common/extensions/docs/examples/api/debugger/live-headers/headers.html

Issue 9289057: Changing manifest to v2 extension samples (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding zip files after rebasing with master Created 8 years, 10 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
1 <!-- 1 <!--
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be 3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file. 4 found in the LICENSE file.
5 --> 5 -->
6 6
7 <html> 7 <html>
8 <head> 8 <head>
9 <style> 9 <style>
10 body { 10 body {
11 font-family: monospace; 11 font-family: monospace;
12 word-wrap: break-word; 12 word-wrap: break-word;
13 } 13 }
14 14
15 #container { 15 #container {
16 white-space: pre; 16 white-space: pre;
17 } 17 }
18 18
19 .request { 19 .request {
20 border-top: 1px solid black; 20 border-top: 1px solid black;
21 margin-bottom: 10px; 21 margin-bottom: 10px;
22 } 22 }
23 23
24 </style> 24 </style>
25 25
26 <script> 26 <script src="headers.js"></script>
27
28 var tabId = parseInt(window.location.search.substring(1));
29
30 window.addEventListener("load", function() {
31 chrome.debugger.sendCommand({tabId:tabId}, "Network.enable");
32 chrome.debugger.onEvent.addListener(onEvent);
33 });
34
35 window.addEventListener("unload", function() {
36 chrome.debugger.detach({tabId:tabId});
37 });
38
39 var requests = {};
40
41 function onEvent(debuggeeId, message, params) {
42 if (tabId != debuggeeId.tabId)
43 return;
44
45 if (message == "Network.requestWillBeSent") {
46 var requestDiv = requests[params.requestId];
47 if (!requestDiv) {
48 var requestDiv = document.createElement("div");
49 requestDiv.className = "request";
50 requests[params.requestId] = requestDiv;
51 var urlLine = document.createElement("div");
52 urlLine.textContent = params.request.url;
53 requestDiv.appendChild(urlLine);
54 }
55
56 if (params.redirectResponse)
57 appendResponse(params.requestId, params.redirectResponse);
58
59 var requestLine = document.createElement("div");
60 requestLine.textContent = "\n" + params.request.method + " " +
61 parseURL(params.request.url).path + " HTTP/1.1";
62 requestDiv.appendChild(requestLine);
63 document.getElementById("container").appendChild(requestDiv);
64 } else if (message == "Network.responseReceived") {
65 appendResponse(params.requestId, params.response);
66 }
67 }
68
69 function appendResponse(requestId, response) {
70 var requestDiv = requests[requestId];
71 requestDiv.appendChild(formatHeaders(response.requestHeaders));
72
73 var statusLine = document.createElement("div");
74 statusLine.textContent = "\nHTTP/1.1 " + response.status + " " +
75 response.statusText;
76 requestDiv.appendChild(statusLine);
77 requestDiv.appendChild(formatHeaders(response.headers));
78 }
79
80 function formatHeaders(headers) {
81 var text = "";
82 for (name in headers)
83 text += name + ": " + headers[name] + "\n";
84 var div = document.createElement("div");
85 div.textContent = text;
86 return div;
87 }
88
89 function parseURL(url) {
90 var result = {};
91 var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*) )?)?$/i);
92 if (!match)
93 return result;
94 result.scheme = match[1].toLowerCase();
95 result.host = match[2];
96 result.port = match[3];
97 result.path = match[4] || "/";
98 result.fragment = match[5];
99 return result;
100 }
101
102 </script>
103 </head> 27 </head>
104 28
105 <body> 29 <body>
106 <div id="container"></div> 30 <div id="container"></div>
107 </body> 31 </body>
108 </html> 32 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698