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/Source/Platform/chromium/public/WebReferrerPolicy.h"
12 #include "webkit/glue/resource_type.h"
19 class ResourceContext
;
21 // Each URLRequest allocated by the ResourceDispatcherHost has a
22 // ResourceRequestInfo instance associated with it.
23 class ResourceRequestInfo
{
25 // Returns the ResourceRequestInfo associated with the given URLRequest.
26 CONTENT_EXPORT
static const ResourceRequestInfo
* ForRequest(
27 const net::URLRequest
* request
);
29 // Allocates a new, dummy ResourceRequestInfo and associates it with the
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
,
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
,
48 // Returns the associated ResourceContext.
49 virtual ResourceContext
* GetContext() const = 0;
51 // The child process unique ID of the requestor.
52 virtual int GetChildID() const = 0;
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;
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;
62 // Unique identifier (within the scope of the child process) for this request.
63 virtual int GetRequestID() const = 0;
65 // True if GetFrameID() represents a main frame in the RenderView.
66 virtual bool IsMainFrame() const = 0;
68 // Frame ID that sent this resource request. -1 if unknown / invalid.
69 virtual int64
GetFrameID() const = 0;
71 // True if GetParentFrameID() represents a main frame in the RenderView.
72 virtual bool ParentIsMainFrame() const = 0;
74 // Frame ID of parent frame of frame that sent this resource request.
75 // -1 if unknown / invalid.
76 virtual int64
GetParentFrameID() const = 0;
78 // Returns the associated resource type.
79 virtual ResourceType::Type
GetResourceType() const = 0;
81 // Returns the associated referrer policy.
82 virtual WebKit::WebReferrerPolicy
GetReferrerPolicy() const = 0;
84 // Returns the associated page transition type.
85 virtual PageTransition
GetPageTransition() const = 0;
87 // True if the request was initiated by a user action (like a tap to follow
89 virtual bool HasUserGesture() const = 0;
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;
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;
99 // Returns true if this is associated with an asynchronous request.
100 virtual bool IsAsync() const = 0;
103 virtual ~ResourceRequestInfo() {}
106 } // namespace content
108 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_