resource_request_info.h revision 116680a4aac90f2aa7413d9095a592090648e557
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 "content/public/common/resource_type.h"
12#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
13#include "third_party/WebKit/public/web/WebPageVisibilityState.h"
14
15namespace net {
16class URLRequest;
17}
18
19namespace content {
20class ResourceContext;
21
22// Each URLRequest allocated by the ResourceDispatcherHost has a
23// ResourceRequestInfo instance associated with it.
24class ResourceRequestInfo {
25 public:
26  // Returns the ResourceRequestInfo associated with the given URLRequest.
27  CONTENT_EXPORT static const ResourceRequestInfo* ForRequest(
28      const net::URLRequest* request);
29
30  // Allocates a new, dummy ResourceRequestInfo and associates it with the
31  // given URLRequest.
32  // NOTE: Add more parameters if you need to initialize other fields.
33  CONTENT_EXPORT static void AllocateForTesting(
34      net::URLRequest* request,
35      ResourceType::Type resource_type,
36      ResourceContext* context,
37      int render_process_id,
38      int render_view_id,
39      int render_frame_id,
40      bool is_async);
41
42  // Returns the associated RenderFrame for a given process. Returns false, if
43  // there is no associated RenderFrame. This method does not rely on the
44  // request being allocated by the ResourceDispatcherHost, but works for all
45  // URLRequests that are associated with a RenderFrame.
46  CONTENT_EXPORT static bool GetRenderFrameForRequest(
47      const net::URLRequest* request,
48      int* render_process_id,
49      int* render_frame_id);
50
51  // Returns the associated ResourceContext.
52  virtual ResourceContext* GetContext() const = 0;
53
54  // The child process unique ID of the requestor.
55  virtual int GetChildID() const = 0;
56
57  // The IPC route identifier for this request (this identifies the RenderView
58  // or like-thing in the renderer that the request gets routed to).
59  virtual int GetRouteID() const = 0;
60
61  // The pid of the originating process, if the request is sent on behalf of a
62  // another process.  Otherwise it is 0.
63  virtual int GetOriginPID() const = 0;
64
65  // Unique identifier (within the scope of the child process) for this request.
66  virtual int GetRequestID() const = 0;
67
68  // The IPC route identifier of the RenderFrame.
69  // TODO(jam): once all navigation and resource requests are sent between
70  // frames and RenderView/RenderViewHost aren't involved we can remove this and
71  // just use GetRouteID above.
72  virtual int GetRenderFrameID() const = 0;
73
74  // True if GetRenderFrameID() represents a main frame in the RenderView.
75  virtual bool IsMainFrame() const = 0;
76
77  // True if GetParentRenderFrameID() represents a main frame in the RenderView.
78  virtual bool ParentIsMainFrame() const = 0;
79
80  // Routing ID of parent frame of frame that sent this resource request.
81  // -1 if unknown / invalid.
82  virtual int GetParentRenderFrameID() const = 0;
83
84  // Returns the associated resource type.
85  virtual ResourceType::Type GetResourceType() const = 0;
86
87  // Returns the process type that initiated this request.
88  virtual int GetProcessType() const = 0;
89
90  // Returns the associated referrer policy.
91  virtual blink::WebReferrerPolicy GetReferrerPolicy() const = 0;
92
93  // Returns the associated visibility state at the time the request was started
94  // in the renderer.
95  virtual blink::WebPageVisibilityState GetVisibilityState() const = 0;
96
97  // Returns the associated page transition type.
98  virtual PageTransition GetPageTransition() const = 0;
99
100  // True if the request was initiated by a user action (like a tap to follow
101  // a link).
102  virtual bool HasUserGesture() const = 0;
103
104  // True if ResourceController::CancelAndIgnore() was called.  For example,
105  // the requested URL may be being loaded by an external program.
106  virtual bool WasIgnoredByHandler() const = 0;
107
108  // Returns false if there is NOT an associated render frame.
109  virtual bool GetAssociatedRenderFrame(int* render_process_id,
110                                        int* render_frame_id) const = 0;
111
112  // Returns true if this is associated with an asynchronous request.
113  virtual bool IsAsync() const = 0;
114
115  // Whether this is a download.
116  virtual bool IsDownload() const = 0;
117
118 protected:
119  virtual ~ResourceRequestInfo() {}
120};
121
122}  // namespace content
123
124#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
125