Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.h
blob54dd85dbaa814e9d6ea3531eb8ff49c2d63d5149
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_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h"
16 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/common/referrer.h"
18 #include "content/public/common/resource_type.h"
19 #include "net/base/load_states.h"
21 namespace content {
22 class CrossSiteResourceHandler;
23 class DetachableResourceHandler;
24 class ResourceContext;
25 class ResourceMessageFilter;
26 struct GlobalRequestID;
27 struct GlobalRoutingID;
29 // Holds the data ResourceDispatcherHost associates with each request.
30 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest.
31 class ResourceRequestInfoImpl : public ResourceRequestInfo,
32 public base::SupportsUserData::Data {
33 public:
34 // Returns the ResourceRequestInfoImpl associated with the given URLRequest.
35 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest(
36 net::URLRequest* request);
38 // And, a const version for cases where you only need read access.
39 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest(
40 const net::URLRequest* request);
42 CONTENT_EXPORT ResourceRequestInfoImpl(
43 int process_type,
44 int child_id,
45 int route_id,
46 int origin_pid,
47 int request_id,
48 int render_frame_id,
49 bool is_main_frame,
50 bool parent_is_main_frame,
51 int parent_render_frame_id,
52 ResourceType resource_type,
53 PageTransition transition_type,
54 bool should_replace_current_entry,
55 bool is_download,
56 bool is_stream,
57 bool allow_download,
58 bool has_user_gesture,
59 bool enable_load_timing,
60 blink::WebReferrerPolicy referrer_policy,
61 blink::WebPageVisibilityState visibility_state,
62 ResourceContext* context,
63 base::WeakPtr<ResourceMessageFilter> filter,
64 bool is_async);
65 virtual ~ResourceRequestInfoImpl();
67 // ResourceRequestInfo implementation:
68 virtual ResourceContext* GetContext() const OVERRIDE;
69 virtual int GetChildID() const OVERRIDE;
70 virtual int GetRouteID() const OVERRIDE;
71 virtual int GetOriginPID() const OVERRIDE;
72 virtual int GetRequestID() const OVERRIDE;
73 virtual int GetRenderFrameID() const OVERRIDE;
74 virtual bool IsMainFrame() const OVERRIDE;
75 virtual bool ParentIsMainFrame() const OVERRIDE;
76 virtual int GetParentRenderFrameID() const OVERRIDE;
77 virtual ResourceType GetResourceType() const OVERRIDE;
78 virtual int GetProcessType() const OVERRIDE;
79 virtual blink::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE;
80 virtual blink::WebPageVisibilityState GetVisibilityState() const OVERRIDE;
81 virtual PageTransition GetPageTransition() const OVERRIDE;
82 virtual bool HasUserGesture() const OVERRIDE;
83 virtual bool WasIgnoredByHandler() const OVERRIDE;
84 virtual bool GetAssociatedRenderFrame(int* render_process_id,
85 int* render_frame_id) const OVERRIDE;
86 virtual bool IsAsync() const OVERRIDE;
87 virtual bool IsDownload() const OVERRIDE;
90 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
92 CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const;
93 GlobalRoutingID GetGlobalRoutingID() const;
95 // May be NULL (e.g., if process dies during a transfer).
96 ResourceMessageFilter* filter() const {
97 return filter_.get();
100 // Updates the data associated with this request after it is is transferred
101 // to a new renderer process. Not all data will change during a transfer.
102 // We do not expect the ResourceContext to change during navigation, so that
103 // does not need to be updated.
104 void UpdateForTransfer(int child_id,
105 int route_id,
106 int origin_pid,
107 int request_id,
108 int parent_render_frame_id,
109 base::WeakPtr<ResourceMessageFilter> filter);
111 // CrossSiteResourceHandler for this request. May be null.
112 CrossSiteResourceHandler* cross_site_handler() {
113 return cross_site_handler_;
115 void set_cross_site_handler(CrossSiteResourceHandler* h) {
116 cross_site_handler_ = h;
119 // Whether this request is part of a navigation that should replace the
120 // current session history entry. This state is shuffled up and down the stack
121 // for request transfers.
122 bool should_replace_current_entry() const {
123 return should_replace_current_entry_;
126 // DetachableResourceHandler for this request. May be NULL.
127 DetachableResourceHandler* detachable_handler() const {
128 return detachable_handler_;
130 void set_detachable_handler(DetachableResourceHandler* h) {
131 detachable_handler_ = h;
134 // Identifies the type of process (renderer, plugin, etc.) making the request.
135 int process_type() const { return process_type_; }
137 // Downloads are allowed only as a top level request.
138 bool allow_download() const { return allow_download_; }
140 // Whether this is a download.
141 void set_is_download(bool download) { is_download_ = download; }
143 // Whether this is a stream.
144 bool is_stream() const { return is_stream_; }
145 void set_is_stream(bool stream) { is_stream_ = stream; }
147 void set_was_ignored_by_handler(bool value) {
148 was_ignored_by_handler_ = value;
151 // The approximate in-memory size (bytes) that we credited this request
152 // as consuming in |outstanding_requests_memory_cost_map_|.
153 int memory_cost() const { return memory_cost_; }
154 void set_memory_cost(int cost) { memory_cost_ = cost; }
156 bool is_load_timing_enabled() const { return enable_load_timing_; }
158 private:
159 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
160 DeletedFilterDetached);
161 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
162 DeletedFilterDetachedRedirect);
163 // Non-owning, may be NULL.
164 CrossSiteResourceHandler* cross_site_handler_;
165 DetachableResourceHandler* detachable_handler_;
167 int process_type_;
168 int child_id_;
169 int route_id_;
170 int origin_pid_;
171 int request_id_;
172 int render_frame_id_;
173 bool is_main_frame_;
174 bool parent_is_main_frame_;
175 int parent_render_frame_id_;
176 bool should_replace_current_entry_;
177 bool is_download_;
178 bool is_stream_;
179 bool allow_download_;
180 bool has_user_gesture_;
181 bool enable_load_timing_;
182 bool was_ignored_by_handler_;
183 ResourceType resource_type_;
184 PageTransition transition_type_;
185 int memory_cost_;
186 blink::WebReferrerPolicy referrer_policy_;
187 blink::WebPageVisibilityState visibility_state_;
188 ResourceContext* context_;
189 // The filter might be deleted without deleting this object if the process
190 // exits during a transfer.
191 base::WeakPtr<ResourceMessageFilter> filter_;
192 bool is_async_;
194 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
197 } // namespace content
199 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_