[Mac] Implement Ambient Light API
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.h
blob29f0d71aefd17d87edaf243db7617a7bba4395fe
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 ui::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 bool enable_upload_progress,
61 bool do_not_prompt_for_login,
62 blink::WebReferrerPolicy referrer_policy,
63 blink::WebPageVisibilityState visibility_state,
64 ResourceContext* context,
65 base::WeakPtr<ResourceMessageFilter> filter,
66 bool is_async);
67 ~ResourceRequestInfoImpl() override;
69 // ResourceRequestInfo implementation:
70 ResourceContext* GetContext() const override;
71 int GetChildID() const override;
72 int GetRouteID() const override;
73 int GetOriginPID() const override;
74 int GetRequestID() const override;
75 int GetRenderFrameID() const override;
76 bool IsMainFrame() const override;
77 bool ParentIsMainFrame() const override;
78 int GetParentRenderFrameID() const override;
79 ResourceType GetResourceType() const override;
80 int GetProcessType() const override;
81 blink::WebReferrerPolicy GetReferrerPolicy() const override;
82 blink::WebPageVisibilityState GetVisibilityState() const override;
83 ui::PageTransition GetPageTransition() const override;
84 bool HasUserGesture() const override;
85 bool WasIgnoredByHandler() const override;
86 bool GetAssociatedRenderFrame(int* render_process_id,
87 int* render_frame_id) const override;
88 bool IsAsync() const override;
89 bool IsDownload() const override;
91 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
93 CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const;
94 GlobalRoutingID GetGlobalRoutingID() const;
96 // May be NULL (e.g., if process dies during a transfer).
97 ResourceMessageFilter* filter() const {
98 return filter_.get();
101 // Updates the data associated with this request after it is is transferred
102 // to a new renderer process. Not all data will change during a transfer.
103 // We do not expect the ResourceContext to change during navigation, so that
104 // does not need to be updated.
105 void UpdateForTransfer(int child_id,
106 int route_id,
107 int origin_pid,
108 int request_id,
109 int parent_render_frame_id,
110 base::WeakPtr<ResourceMessageFilter> filter);
112 // CrossSiteResourceHandler for this request. May be null.
113 CrossSiteResourceHandler* cross_site_handler() {
114 return cross_site_handler_;
116 void set_cross_site_handler(CrossSiteResourceHandler* h) {
117 cross_site_handler_ = h;
120 // Whether this request is part of a navigation that should replace the
121 // current session history entry. This state is shuffled up and down the stack
122 // for request transfers.
123 bool should_replace_current_entry() const {
124 return should_replace_current_entry_;
127 // DetachableResourceHandler for this request. May be NULL.
128 DetachableResourceHandler* detachable_handler() const {
129 return detachable_handler_;
131 void set_detachable_handler(DetachableResourceHandler* h) {
132 detachable_handler_ = h;
135 // Identifies the type of process (renderer, plugin, etc.) making the request.
136 int process_type() const { return process_type_; }
138 // Downloads are allowed only as a top level request.
139 bool allow_download() const { return allow_download_; }
141 // Whether this is a download.
142 void set_is_download(bool download) { is_download_ = download; }
144 // Whether this is a stream.
145 bool is_stream() const { return is_stream_; }
146 void set_is_stream(bool stream) { is_stream_ = stream; }
148 void set_was_ignored_by_handler(bool value) {
149 was_ignored_by_handler_ = value;
152 // Whether this request has been counted towards the number of in flight
153 // requests, which is only true for requests that require a file descriptor
154 // for their shared memory buffer.
155 bool counted_as_in_flight_request() const {
156 return counted_as_in_flight_request_;
158 void set_counted_as_in_flight_request(bool was_counted) {
159 counted_as_in_flight_request_ = was_counted;
162 // The approximate in-memory size (bytes) that we credited this request
163 // as consuming in |outstanding_requests_memory_cost_map_|.
164 int memory_cost() const { return memory_cost_; }
165 void set_memory_cost(int cost) { memory_cost_ = cost; }
167 bool is_load_timing_enabled() const { return enable_load_timing_; }
169 bool is_upload_progress_enabled() const { return enable_upload_progress_; }
171 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; }
172 void set_do_not_prompt_for_login(bool do_not_prompt) {
173 do_not_prompt_for_login_ = do_not_prompt;
176 private:
177 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
178 DeletedFilterDetached);
179 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
180 DeletedFilterDetachedRedirect);
181 // Non-owning, may be NULL.
182 CrossSiteResourceHandler* cross_site_handler_;
183 DetachableResourceHandler* detachable_handler_;
185 int process_type_;
186 int child_id_;
187 int route_id_;
188 int origin_pid_;
189 int request_id_;
190 int render_frame_id_;
191 bool is_main_frame_;
192 bool parent_is_main_frame_;
193 int parent_render_frame_id_;
194 bool should_replace_current_entry_;
195 bool is_download_;
196 bool is_stream_;
197 bool allow_download_;
198 bool has_user_gesture_;
199 bool enable_load_timing_;
200 bool enable_upload_progress_;
201 bool do_not_prompt_for_login_;
202 bool was_ignored_by_handler_;
203 bool counted_as_in_flight_request_;
204 ResourceType resource_type_;
205 ui::PageTransition transition_type_;
206 int memory_cost_;
207 blink::WebReferrerPolicy referrer_policy_;
208 blink::WebPageVisibilityState visibility_state_;
209 ResourceContext* context_;
210 // The filter might be deleted without deleting this object if the process
211 // exits during a transfer.
212 base::WeakPtr<ResourceMessageFilter> filter_;
213 bool is_async_;
215 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
218 } // namespace content
220 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_