• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
7 
8 #include <string>
9 
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"
20 
21 namespace content {
22 class CrossSiteResourceHandler;
23 class DetachableResourceHandler;
24 class ResourceContext;
25 class ResourceMessageFilter;
26 struct GlobalRequestID;
27 struct GlobalRoutingID;
28 
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);
37 
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);
41 
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       blink::WebReferrerPolicy referrer_policy,
61       blink::WebPageVisibilityState visibility_state,
62       ResourceContext* context,
63       base::WeakPtr<ResourceMessageFilter> filter,
64       bool is_async);
65   virtual ~ResourceRequestInfoImpl();
66 
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 ui::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;
88 
89 
90   CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
91 
92   CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const;
93   GlobalRoutingID GetGlobalRoutingID() const;
94 
95   // May be NULL (e.g., if process dies during a transfer).
filter()96   ResourceMessageFilter* filter() const {
97     return filter_.get();
98   }
99 
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);
110 
111   // CrossSiteResourceHandler for this request.  May be null.
cross_site_handler()112   CrossSiteResourceHandler* cross_site_handler() {
113     return cross_site_handler_;
114   }
set_cross_site_handler(CrossSiteResourceHandler * h)115   void set_cross_site_handler(CrossSiteResourceHandler* h) {
116     cross_site_handler_ = h;
117   }
118 
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.
should_replace_current_entry()122   bool should_replace_current_entry() const {
123     return should_replace_current_entry_;
124   }
125 
126   // DetachableResourceHandler for this request.  May be NULL.
detachable_handler()127   DetachableResourceHandler* detachable_handler() const {
128     return detachable_handler_;
129   }
set_detachable_handler(DetachableResourceHandler * h)130   void set_detachable_handler(DetachableResourceHandler* h) {
131     detachable_handler_ = h;
132   }
133 
134   // Identifies the type of process (renderer, plugin, etc.) making the request.
process_type()135   int process_type() const { return process_type_; }
136 
137   // Downloads are allowed only as a top level request.
allow_download()138   bool allow_download() const { return allow_download_; }
139 
140   // Whether this is a download.
set_is_download(bool download)141   void set_is_download(bool download) { is_download_ = download; }
142 
143   // Whether this is a stream.
is_stream()144   bool is_stream() const { return is_stream_; }
set_is_stream(bool stream)145   void set_is_stream(bool stream) { is_stream_ = stream; }
146 
set_was_ignored_by_handler(bool value)147   void set_was_ignored_by_handler(bool value) {
148     was_ignored_by_handler_ = value;
149   }
150 
151   // The approximate in-memory size (bytes) that we credited this request
152   // as consuming in |outstanding_requests_memory_cost_map_|.
memory_cost()153   int memory_cost() const { return memory_cost_; }
set_memory_cost(int cost)154   void set_memory_cost(int cost) { memory_cost_ = cost; }
155 
is_load_timing_enabled()156   bool is_load_timing_enabled() const { return enable_load_timing_; }
157 
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_;
166 
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   ui::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_;
193 
194   DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
195 };
196 
197 }  // namespace content
198 
199 #endif  // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
200