summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/net_agent_impl.h
blob: b9d56fcff237796382d05aa2699a4dde5365af7e (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
80
// 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.

#ifndef WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_
#define WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_

#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>

#include "webkit/glue/devtools/net_agent.h"

namespace WebCore {
class Document;
class DocumentLoader;
class HTTPHeaderMap;
class ResourceError;
class ResourceResponse;
class String;
struct ResourceRequest;
}

class Value;

// NetAgent is a utility object that covers network-related functionality of the
// WebDevToolsAgent. It is capable of sniffing network calls and passing the
// HttpRequest-related data to the client.
// NetAgent's environment is represented with the NetAgentDelegate interface.
class NetAgentImpl : public NetAgent {
 public:
  explicit NetAgentImpl(NetAgentDelegate* delegate);
  virtual ~NetAgentImpl();

  // Initializes net agent with the given document.
  void SetDocument(WebCore::Document* document);

  // NetAgent implementation.
  void GetResourceContent(int identifier, const WebCore::String& request_url);
  void AssignIdentifierToRequest(
      WebCore::DocumentLoader* loader,
      int identifier,
      const WebCore::ResourceRequest& request);
  void WillSendRequest(
      WebCore::DocumentLoader* loader,
      int identifier,
      const WebCore::ResourceRequest& request);
  void DidReceiveResponse(
      WebCore::DocumentLoader* loader,
      int identifier,
      const WebCore::ResourceResponse &response);
  void DidReceiveContentLength(
      WebCore::DocumentLoader* loader,
      int identifier,
      int length);
  void DidFinishLoading(
      WebCore::DocumentLoader* loader,
      int identifier);
  void DidFailLoading(
      WebCore::DocumentLoader* loader,
      int identifier,
      const WebCore::ResourceError& error);
  void DidLoadResourceFromMemoryCache(
      WebCore::DocumentLoader* loader,
      const WebCore::ResourceRequest& request,
      const WebCore::ResourceResponse& response,
      int length);

 private:
  // Serializes headers map into a value.
  Value* BuildValueForHeaders(const WebCore::HTTPHeaderMap& headers);

  NetAgentDelegate* delegate_;
  WebCore::Document* document_;
  HashMap<int, RefPtr<WebCore::DocumentLoader> > loaders_;
  int last_cached_identifier_;
  DISALLOW_COPY_AND_ASSIGN(NetAgentImpl);
};

#endif  // WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_