resource_request_info.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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
39  // Returns the associated RenderView for a given process. Returns false, if
40  // there is no associated RenderView. This method does not rely on the
41  // request being allocated by the ResourceDispatcherHost, but works for all
42  // URLRequests that are associated with a RenderView.
43  CONTENT_EXPORT static bool GetRenderViewForRequest(
44      const net::URLRequest* request,
45      int* render_process_id,
46      int* render_view_id);
47
48  // Returns the associated ResourceContext.
49  virtual ResourceContext* GetContext() const = 0;
50
51  // The child process unique ID of the requestor.
52  virtual int GetChildID() const = 0;
53
54  // The IPC route identifier for this request (this identifies the RenderView
55  // or like-thing in the renderer that the request gets routed to).
56  virtual int GetRouteID() const = 0;
57
58  // The pid of the originating process, if the request is sent on behalf of a
59  // another process.  Otherwise it is 0.
60  virtual int GetOriginPID() const = 0;
61
62  // Unique identifier (within the scope of the child process) for this request.
63  virtual int GetRequestID() const = 0;
64
65  // True if GetFrameID() represents a main frame in the RenderView.
66  virtual bool IsMainFrame() const = 0;
67
68  // Frame ID that sent this resource request. -1 if unknown / invalid.
69  virtual int64 GetFrameID() const = 0;
70
71  // True if GetParentFrameID() represents a main frame in the RenderView.
72  virtual bool ParentIsMainFrame() const = 0;
73
74  // Frame ID of parent frame of frame that sent this resource request.
75  // -1 if unknown / invalid.
76  virtual int64 GetParentFrameID() const = 0;
77
78  // Returns the associated resource type.
79  virtual ResourceType::Type GetResourceType() const = 0;
80
81  // Returns the associated referrer policy.
82  virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const = 0;
83
84  // Returns the associated page transition type.
85  virtual PageTransition GetPageTransition() const = 0;
86
87  // True if the request was initiated by a user action (like a tap to follow
88  // a link).
89  virtual bool HasUserGesture() const = 0;
90
91  // True if ResourceController::CancelAndIgnore() was called.  For example,
92  // the requested URL may be being loaded by an external program.
93  virtual bool WasIgnoredByHandler() const = 0;
94
95  // Returns false if there is NOT an associated render view.
96  virtual bool GetAssociatedRenderView(int* render_process_id,
97                                       int* render_view_id) const = 0;
98
99  // Returns true if this is associated with an asynchronous request.
100  virtual bool IsAsync() const = 0;
101
102 protected:
103  virtual ~ResourceRequestInfo() {}
104};
105
106}  // namespace content
107
108#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
109