Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / public / browser / resource_request_info.h
blobe9ba86ebcc0ea4c99f84a8a312a818c429406a8c
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/WebPageVisibilityState.h"
12 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
13 #include "ui/base/page_transition_types.h"
15 namespace net {
16 class URLRequest;
19 namespace content {
20 class ResourceContext;
22 // Each URLRequest allocated by the ResourceDispatcherHost has a
23 // ResourceRequestInfo instance associated with it.
24 class ResourceRequestInfo {
25 public:
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
31 // given URLRequest.
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,
37 int render_view_id,
38 int render_frame_id,
39 bool is_main_frame,
40 bool parent_is_main_frame,
41 bool allow_download,
42 bool is_async);
44 // Returns the associated RenderFrame for a given process. Returns false, if
45 // there is no associated RenderFrame. This method does not rely on the
46 // request being allocated by the ResourceDispatcherHost, but works for all
47 // URLRequests that are associated with a RenderFrame.
48 CONTENT_EXPORT static bool GetRenderFrameForRequest(
49 const net::URLRequest* request,
50 int* render_process_id,
51 int* render_frame_id);
53 // Returns the associated ResourceContext.
54 virtual ResourceContext* GetContext() const = 0;
56 // The child process unique ID of the requestor.
57 virtual int GetChildID() const = 0;
59 // The IPC route identifier for this request (this identifies the RenderView
60 // or like-thing in the renderer that the request gets routed to).
61 virtual int GetRouteID() const = 0;
63 // The pid of the originating process, if the request is sent on behalf of a
64 // another process. Otherwise it is 0.
65 virtual int GetOriginPID() const = 0;
67 // Unique identifier (within the scope of the child process) for this request.
68 virtual int GetRequestID() const = 0;
70 // The IPC route identifier of the RenderFrame.
71 // TODO(jam): once all navigation and resource requests are sent between
72 // frames and RenderView/RenderViewHost aren't involved we can remove this and
73 // just use GetRouteID above.
74 virtual int GetRenderFrameID() const = 0;
76 // True if GetRenderFrameID() represents a main frame in the RenderView.
77 virtual bool IsMainFrame() const = 0;
79 // True if GetParentRenderFrameID() represents a main frame in the RenderView.
80 virtual bool ParentIsMainFrame() const = 0;
82 // Routing ID of parent frame of frame that sent this resource request.
83 // -1 if unknown / invalid.
84 virtual int GetParentRenderFrameID() const = 0;
86 // Returns the associated resource type.
87 virtual ResourceType GetResourceType() const = 0;
89 // Returns the process type that initiated this request.
90 virtual int GetProcessType() const = 0;
92 // Returns the associated referrer policy.
93 virtual blink::WebReferrerPolicy GetReferrerPolicy() const = 0;
95 // Returns the associated visibility state at the time the request was started
96 // in the renderer.
97 virtual blink::WebPageVisibilityState GetVisibilityState() const = 0;
99 // Returns the associated page transition type.
100 virtual ui::PageTransition GetPageTransition() const = 0;
102 // True if the request was initiated by a user action (like a tap to follow
103 // a link).
105 // Note that a false value does not mean the request was not initiated by a
106 // user gesture. Also note that the fact that a user gesture was active
107 // while the request was created does not imply that the user consciously
108 // wanted this request to happen nor is aware of it.
110 // DO NOT BASE SECURITY DECISIONS ON THIS FLAG!
111 virtual bool HasUserGesture() const = 0;
113 // True if ResourceController::CancelAndIgnore() was called. For example,
114 // the requested URL may be being loaded by an external program.
115 virtual bool WasIgnoredByHandler() const = 0;
117 // Returns false if there is NOT an associated render frame.
118 virtual bool GetAssociatedRenderFrame(int* render_process_id,
119 int* render_frame_id) const = 0;
121 // Returns true if this is associated with an asynchronous request.
122 virtual bool IsAsync() const = 0;
124 // Whether this is a download.
125 virtual bool IsDownload() const = 0;
127 protected:
128 virtual ~ResourceRequestInfo() {}
131 } // namespace content
133 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_