resource_request_info.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 "third_party/WebKit/public/web/WebPageVisibilityState.h"
13#include "webkit/common/resource_type.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 GetFrameID() represents a main frame in the RenderView.
75  virtual bool IsMainFrame() const = 0;
76
77  // Frame ID that sent this resource request. -1 if unknown / invalid.
78  virtual int64 GetFrameID() const = 0;
79
80  // True if GetParentFrameID() represents a main frame in the RenderView.
81  virtual bool ParentIsMainFrame() const = 0;
82
83  // Frame ID of parent frame of frame that sent this resource request.
84  // -1 if unknown / invalid.
85  virtual int64 GetParentFrameID() const = 0;
86
87  // Returns the associated resource type.
88  virtual ResourceType::Type GetResourceType() const = 0;
89
90  // Returns the process type that initiated this request.
91  virtual int GetProcessType() const = 0;
92
93  // Returns the associated referrer policy.
94  virtual blink::WebReferrerPolicy GetReferrerPolicy() const = 0;
95
96  // Returns the associated visibility state at the time the request was started
97  // in the renderer.
98  virtual blink::WebPageVisibilityState GetVisibilityState() const = 0;
99
100  // Returns the associated page transition type.
101  virtual PageTransition GetPageTransition() const = 0;
102
103  // True if the request was initiated by a user action (like a tap to follow
104  // a link).
105  virtual bool HasUserGesture() const = 0;
106
107  // True if ResourceController::CancelAndIgnore() was called.  For example,
108  // the requested URL may be being loaded by an external program.
109  virtual bool WasIgnoredByHandler() const = 0;
110
111  // Returns false if there is NOT an associated render frame.
112  virtual bool GetAssociatedRenderFrame(int* render_process_id,
113                                        int* render_frame_id) const = 0;
114
115  // Returns true if this is associated with an asynchronous request.
116  virtual bool IsAsync() const = 0;
117
118  // Whether this is a download.
119  virtual bool IsDownload() const = 0;
120
121 protected:
122  virtual ~ResourceRequestInfo() {}
123};
124
125}  // namespace content
126
127#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
128