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/resource_type.h"
11 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
12 #include "third_party/WebKit/public/web/WebPageVisibilityState.h"
13 #include "ui/base/page_transition_types.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(net::URLRequest* request,
34 ResourceType resource_type,
35 ResourceContext* context,
36 int render_process_id,
41 // Returns the associated RenderFrame for a given process. Returns false, if
42 // there is no associated RenderFrame. This method does not rely on the
43 // request being allocated by the ResourceDispatcherHost, but works for all
44 // URLRequests that are associated with a RenderFrame.
45 CONTENT_EXPORT static bool GetRenderFrameForRequest(
46 const net::URLRequest* request,
47 int* render_process_id,
48 int* render_frame_id);
50 // Returns the associated ResourceContext.
51 virtual ResourceContext* GetContext() const = 0;
53 // The child process unique ID of the requestor.
54 virtual int GetChildID() const = 0;
56 // The IPC route identifier for this request (this identifies the RenderView
57 // or like-thing in the renderer that the request gets routed to).
58 virtual int GetRouteID() const = 0;
60 // The pid of the originating process, if the request is sent on behalf of a
61 // another process. Otherwise it is 0.
62 virtual int GetOriginPID() const = 0;
64 // Unique identifier (within the scope of the child process) for this request.
65 virtual int GetRequestID() const = 0;
67 // The IPC route identifier of the RenderFrame.
68 // TODO(jam): once all navigation and resource requests are sent between
69 // frames and RenderView/RenderViewHost aren't involved we can remove this and
70 // just use GetRouteID above.
71 virtual int GetRenderFrameID() const = 0;
73 // True if GetRenderFrameID() represents a main frame in the RenderView.
74 virtual bool IsMainFrame() const = 0;
76 // True if GetParentRenderFrameID() represents a main frame in the RenderView.
77 virtual bool ParentIsMainFrame() const = 0;
79 // Routing ID of parent frame of frame that sent this resource request.
80 // -1 if unknown / invalid.
81 virtual int GetParentRenderFrameID() const = 0;
83 // Returns the associated resource type.
84 virtual ResourceType GetResourceType() const = 0;
86 // Returns the process type that initiated this request.
87 virtual int GetProcessType() const = 0;
89 // Returns the associated referrer policy.
90 virtual blink::WebReferrerPolicy GetReferrerPolicy() const = 0;
92 // Returns the associated visibility state at the time the request was started
94 virtual blink::WebPageVisibilityState GetVisibilityState() const = 0;
96 // Returns the associated page transition type.
97 virtual ui::PageTransition GetPageTransition() const = 0;
99 // True if the request was initiated by a user action (like a tap to follow
101 virtual bool HasUserGesture() const = 0;
103 // True if ResourceController::CancelAndIgnore() was called. For example,
104 // the requested URL may be being loaded by an external program.
105 virtual bool WasIgnoredByHandler() const = 0;
107 // Returns false if there is NOT an associated render frame.
108 virtual bool GetAssociatedRenderFrame(int* render_process_id,
109 int* render_frame_id) const = 0;
111 // Returns true if this is associated with an asynchronous request.
112 virtual bool IsAsync() const = 0;
114 // Whether this is a download.
115 virtual bool IsDownload() const = 0;
118 virtual ~ResourceRequestInfo() {}
121 } // namespace content
123 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_