• 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 "net/base/load_states.h"
19 #include "webkit/common/resource_type.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       int64 frame_id,
51       bool parent_is_main_frame,
52       int64 parent_frame_id,
53       ResourceType::Type resource_type,
54       PageTransition transition_type,
55       bool should_replace_current_entry,
56       bool is_download,
57       bool is_stream,
58       bool allow_download,
59       bool has_user_gesture,
60       blink::WebReferrerPolicy referrer_policy,
61       ResourceContext* context,
62       base::WeakPtr<ResourceMessageFilter> filter,
63       bool is_async);
64   virtual ~ResourceRequestInfoImpl();
65 
66   // ResourceRequestInfo implementation:
67   virtual ResourceContext* GetContext() const OVERRIDE;
68   virtual int GetChildID() const OVERRIDE;
69   virtual int GetRouteID() const OVERRIDE;
70   virtual int GetOriginPID() const OVERRIDE;
71   virtual int GetRequestID() const OVERRIDE;
72   virtual int GetRenderFrameID() const OVERRIDE;
73   virtual bool IsMainFrame() const OVERRIDE;
74   virtual int64 GetFrameID() const OVERRIDE;
75   virtual bool ParentIsMainFrame() const OVERRIDE;
76   virtual int64 GetParentFrameID() const OVERRIDE;
77   virtual ResourceType::Type GetResourceType() const OVERRIDE;
78   virtual blink::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE;
79   virtual PageTransition GetPageTransition() const OVERRIDE;
80   virtual bool HasUserGesture() const OVERRIDE;
81   virtual bool WasIgnoredByHandler() const OVERRIDE;
82   virtual bool GetAssociatedRenderView(int* render_process_id,
83                                        int* render_view_id) const OVERRIDE;
84   virtual bool IsAsync() const OVERRIDE;
85   virtual bool IsDownload() const OVERRIDE;
86 
87 
88   CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
89 
90   CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const;
91   GlobalRoutingID GetGlobalRoutingID() const;
92 
93   // May be NULL (e.g., if process dies during a transfer).
filter()94   ResourceMessageFilter* filter() const {
95     return filter_.get();
96   }
97 
98   // Updates the data associated with this request after it is is transferred
99   // to a new renderer process.  Not all data will change during a transfer.
100   // We do not expect the ResourceContext to change during navigation, so that
101   // does not need to be updated.
102   void UpdateForTransfer(int child_id,
103                          int route_id,
104                          int origin_pid,
105                          int request_id,
106                          int64 frame_id,
107                          int64 parent_frame_id,
108                          base::WeakPtr<ResourceMessageFilter> filter);
109 
110   // CrossSiteResourceHandler for this request.  May be null.
cross_site_handler()111   CrossSiteResourceHandler* cross_site_handler() {
112     return cross_site_handler_;
113   }
set_cross_site_handler(CrossSiteResourceHandler * h)114   void set_cross_site_handler(CrossSiteResourceHandler* h) {
115     cross_site_handler_ = h;
116   }
117 
118   // Whether this request is part of a navigation that should replace the
119   // current session history entry. This state is shuffled up and down the stack
120   // for request transfers.
should_replace_current_entry()121   bool should_replace_current_entry() const {
122     return should_replace_current_entry_;
123   }
124 
125   // DetachableResourceHandler for this request.  May be NULL.
detachable_handler()126   DetachableResourceHandler* detachable_handler() const {
127     return detachable_handler_;
128   }
set_detachable_handler(DetachableResourceHandler * h)129   void set_detachable_handler(DetachableResourceHandler* h) {
130     detachable_handler_ = h;
131   }
132 
133   // Identifies the type of process (renderer, plugin, etc.) making the request.
process_type()134   int process_type() const { return process_type_; }
135 
136   // Downloads are allowed only as a top level request.
allow_download()137   bool allow_download() const { return allow_download_; }
138 
139   // Whether this is a download.
set_is_download(bool download)140   void set_is_download(bool download) { is_download_ = download; }
141 
142   // Whether this is a stream.
is_stream()143   bool is_stream() const { return is_stream_; }
set_is_stream(bool stream)144   void set_is_stream(bool stream) { is_stream_ = stream; }
145 
set_was_ignored_by_handler(bool value)146   void set_was_ignored_by_handler(bool value) {
147     was_ignored_by_handler_ = value;
148   }
149 
150   // The approximate in-memory size (bytes) that we credited this request
151   // as consuming in |outstanding_requests_memory_cost_map_|.
memory_cost()152   int memory_cost() const { return memory_cost_; }
set_memory_cost(int cost)153   void set_memory_cost(int cost) { memory_cost_ = cost; }
154 
155  private:
156   FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
157                            DeletedFilterDetached);
158   FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
159                            DeletedFilterDetachedRedirect);
160   // Non-owning, may be NULL.
161   CrossSiteResourceHandler* cross_site_handler_;
162   DetachableResourceHandler* detachable_handler_;
163 
164   int process_type_;
165   int child_id_;
166   int route_id_;
167   int origin_pid_;
168   int request_id_;
169   int render_frame_id_;
170   bool is_main_frame_;
171   int64 frame_id_;
172   bool parent_is_main_frame_;
173   int64 parent_frame_id_;
174   bool should_replace_current_entry_;
175   bool is_download_;
176   bool is_stream_;
177   bool allow_download_;
178   bool has_user_gesture_;
179   bool was_ignored_by_handler_;
180   ResourceType::Type resource_type_;
181   PageTransition transition_type_;
182   int memory_cost_;
183   blink::WebReferrerPolicy referrer_policy_;
184   ResourceContext* context_;
185   // The filter might be deleted without deleting this object if the process
186   // exits during a transfer.
187   base::WeakPtr<ResourceMessageFilter> filter_;
188   bool is_async_;
189 
190   DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
191 };
192 
193 }  // namespace content
194 
195 #endif  // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
196