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.
5 #ifndef CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
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"
20 class ResourceContext
;
22 // Each URLRequest allocated by the ResourceDispatcherHost has a
23 // ResourceRequestInfo instance associated with it.
24 class ResourceRequestInfo
{
26 // Returns the ResourceRequestInfo associated with the given URLRequest.
27 CONTENT_EXPORT
static const ResourceRequestInfo
* ForRequest(
28 const net::URLRequest
* request
);
30 // Allocates a new, dummy ResourceRequestInfo and associates it with the
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
,
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
);
51 // Returns the associated ResourceContext.
52 virtual ResourceContext
* GetContext() const = 0;
54 // The child process unique ID of the requestor.
55 virtual int GetChildID() const = 0;
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;
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;
65 // Unique identifier (within the scope of the child process) for this request.
66 virtual int GetRequestID() const = 0;
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;
74 // True if GetRenderFrameID() represents a main frame in the RenderView.
75 virtual bool IsMainFrame() const = 0;
77 // True if GetParentRenderFrameID() represents a main frame in the RenderView.
78 virtual bool ParentIsMainFrame() const = 0;
80 // Routing ID of parent frame of frame that sent this resource request.
81 // -1 if unknown / invalid.
82 virtual int GetParentRenderFrameID() const = 0;
84 // Returns the associated resource type.
85 virtual ResourceType::Type
GetResourceType() const = 0;
87 // Returns the process type that initiated this request.
88 virtual int GetProcessType() const = 0;
90 // Returns the associated referrer policy.
91 virtual blink::WebReferrerPolicy
GetReferrerPolicy() const = 0;
93 // Returns the associated visibility state at the time the request was started
95 virtual blink::WebPageVisibilityState
GetVisibilityState() const = 0;
97 // Returns the associated page transition type.
98 virtual PageTransition
GetPageTransition() const = 0;
100 // True if the request was initiated by a user action (like a tap to follow
102 virtual bool HasUserGesture() const = 0;
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;
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;
112 // Returns true if this is associated with an asynchronous request.
113 virtual bool IsAsync() const = 0;
115 // Whether this is a download.
116 virtual bool IsDownload() const = 0;
119 virtual ~ResourceRequestInfo() {}
122 } // namespace content
124 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_