resource_request_info.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
6#define CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
7
8#include "base/basictypes.h"
9#include "content/common/content_export.h"
10#include "content/public/common/page_transition_types.h"
11#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
12#include "webkit/common/resource_type.h"
13
14namespace net {
15class URLRequest;
16}
17
18namespace content {
19class ResourceContext;
20
21// Each URLRequest allocated by the ResourceDispatcherHost has a
22// ResourceRequestInfo instance associated with it.
23class ResourceRequestInfo {
24 public:
25  // Returns the ResourceRequestInfo associated with the given URLRequest.
26  CONTENT_EXPORT static const ResourceRequestInfo* ForRequest(
27      const net::URLRequest* request);
28
29  // Allocates a new, dummy ResourceRequestInfo and associates it with the
30  // given URLRequest.
31  // NOTE: Add more parameters if you need to initialize other fields.
32  CONTENT_EXPORT static void AllocateForTesting(
33      net::URLRequest* request,
34      ResourceType::Type resource_type,
35      ResourceContext* context,
36      int render_process_id,
37      int render_view_id,
38      bool is_async);
39
40  // Returns the associated RenderView for a given process. Returns false, if
41  // there is no associated RenderView. This method does not rely on the
42  // request being allocated by the ResourceDispatcherHost, but works for all
43  // URLRequests that are associated with a RenderView.
44  CONTENT_EXPORT static bool GetRenderViewForRequest(
45      const net::URLRequest* request,
46      int* render_process_id,
47      int* render_view_id);
48
49  // Returns the associated ResourceContext.
50  virtual ResourceContext* GetContext() const = 0;
51
52  // The child process unique ID of the requestor.
53  virtual int GetChildID() const = 0;
54
55  // The IPC route identifier for this request (this identifies the RenderView
56  // or like-thing in the renderer that the request gets routed to).
57  virtual int GetRouteID() const = 0;
58
59  // The pid of the originating process, if the request is sent on behalf of a
60  // another process.  Otherwise it is 0.
61  virtual int GetOriginPID() const = 0;
62
63  // Unique identifier (within the scope of the child process) for this request.
64  virtual int GetRequestID() const = 0;
65
66  // True if GetFrameID() represents a main frame in the RenderView.
67  virtual bool IsMainFrame() const = 0;
68
69  // Frame ID that sent this resource request. -1 if unknown / invalid.
70  virtual int64 GetFrameID() const = 0;
71
72  // True if GetParentFrameID() represents a main frame in the RenderView.
73  virtual bool ParentIsMainFrame() const = 0;
74
75  // Frame ID of parent frame of frame that sent this resource request.
76  // -1 if unknown / invalid.
77  virtual int64 GetParentFrameID() const = 0;
78
79  // Returns the associated resource type.
80  virtual ResourceType::Type GetResourceType() const = 0;
81
82  // Returns the associated referrer policy.
83  virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const = 0;
84
85  // Returns the associated page transition type.
86  virtual PageTransition GetPageTransition() const = 0;
87
88  // True if the request was initiated by a user action (like a tap to follow
89  // a link).
90  virtual bool HasUserGesture() const = 0;
91
92  // True if ResourceController::CancelAndIgnore() was called.  For example,
93  // the requested URL may be being loaded by an external program.
94  virtual bool WasIgnoredByHandler() const = 0;
95
96  // Returns false if there is NOT an associated render view.
97  virtual bool GetAssociatedRenderView(int* render_process_id,
98                                       int* render_view_id) const = 0;
99
100  // Returns true if this is associated with an asynchronous request.
101  virtual bool IsAsync() const = 0;
102
103 protected:
104  virtual ~ResourceRequestInfo() {}
105};
106
107}  // namespace content
108
109#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
110