summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/js/net.js
blob: 92933b20ffc2c3933b74f2d3a0a4f1d8cd95cfa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview 'Net' manages resources along with the corresponding
 * HTTP requests and responses.
 * web inspector.
 */
goog.provide('devtools.Net');

devtools.Net = function() {
  this.resources_ = {};
  this.id_for_url_ = {};
};


devtools.Net.prototype.willSendRequest = function(identifier, request) {
  var mainResource = false;
  var cached = false;
  var resource = new WebInspector.Resource(request.requestHeaders, 
      request.url, request.domain, request.path, request.lastPathComponent,
      identifier, mainResource, cached);
  resource.startTime = request.startTime;
  WebInspector.addResource(resource);
  this.resources_[identifier] = resource;
  this.id_for_url_[request.url] = identifier;
};


devtools.Net.prototype.didReceiveResponse = function(identifier, response) {
  var resource = this.resources_[identifier];
  if (!resource) {
    return;
  }
  resource.expectedContentLength = response.expectedContentLength;
  resource.responseStatusCode = response.responseStatusCode;
  resource.mimeType = response.mimeType;
  resource.suggestedFilename = response.suggestedFilename;
  var mimeType = response.mimeType;
  if (mimeType.indexOf("image/") == 0) {
    resource.type = WebInspector.Resource.Type.Image;
  } else if (mimeType.indexOf("text/html") == 0) {
    resource.type = WebInspector.Resource.Type.Document;
  } else if (mimeType.indexOf("script") != -1 ||
      response.url.indexOf(".js") != -1) {
    resource.type = WebInspector.Resource.Type.Script;
  } else {
    resource.type = WebInspector.Resource.Type.Other;
  } 
  resource.responseReceivedTime = response.responseReceivedTime;
};


devtools.Net.prototype.didFinishLoading = function(identifier, value) {
  var resource = this.resources_[identifier];
  if (!resource) {
    return;
  }
  resource.endTime = value.endTime;
  resource.finished = true;
  resource.failed = false;
};


devtools.Net.prototype.didFailLoading = function(identifier, value) {
  var resource = this.resources_[identifier];
  if (!resource) {
    return;
  }
  resource.endTime = value.endTime;
  resource.finished = false;
  resource.failed = true;
};


devtools.Net.prototype.setResourceContent = function(identifier,
    content) {
};