Home | History | Annotate | Download | only in loader
      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/memory/ref_counted.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/supports_user_data.h"
     14 #include "content/public/browser/resource_request_info.h"
     15 #include "content/public/common/referrer.h"
     16 #include "net/base/load_states.h"
     17 #include "webkit/common/resource_type.h"
     18 
     19 namespace webkit_blob {
     20 class BlobData;
     21 }
     22 
     23 namespace content {
     24 class CrossSiteResourceHandler;
     25 class ResourceContext;
     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       bool is_main_frame,
     49       int64 frame_id,
     50       bool parent_is_main_frame,
     51       int64 parent_frame_id,
     52       ResourceType::Type resource_type,
     53       PageTransition transition_type,
     54       bool is_download,
     55       bool is_stream,
     56       bool allow_download,
     57       bool has_user_gesture,
     58       WebKit::WebReferrerPolicy referrer_policy,
     59       ResourceContext* context,
     60       bool is_async);
     61   virtual ~ResourceRequestInfoImpl();
     62 
     63   // ResourceRequestInfo implementation:
     64   virtual ResourceContext* GetContext() const OVERRIDE;
     65   virtual int GetChildID() const OVERRIDE;
     66   virtual int GetRouteID() const OVERRIDE;
     67   virtual int GetOriginPID() const OVERRIDE;
     68   virtual int GetRequestID() const OVERRIDE;
     69   virtual bool IsMainFrame() const OVERRIDE;
     70   virtual int64 GetFrameID() const OVERRIDE;
     71   virtual bool ParentIsMainFrame() const OVERRIDE;
     72   virtual int64 GetParentFrameID() const OVERRIDE;
     73   virtual ResourceType::Type GetResourceType() const OVERRIDE;
     74   virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE;
     75   virtual PageTransition GetPageTransition() const OVERRIDE;
     76   virtual bool HasUserGesture() const OVERRIDE;
     77   virtual bool WasIgnoredByHandler() const OVERRIDE;
     78   virtual bool GetAssociatedRenderView(int* render_process_id,
     79                                        int* render_view_id) const OVERRIDE;
     80   virtual bool IsAsync() const OVERRIDE;
     81 
     82 
     83   CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
     84 
     85   CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const;
     86   GlobalRoutingID GetGlobalRoutingID() const;
     87 
     88   // CrossSiteResourceHandler for this request.  May be null.
     89   CrossSiteResourceHandler* cross_site_handler() {
     90     return cross_site_handler_;
     91   }
     92   void set_cross_site_handler(CrossSiteResourceHandler* h) {
     93     cross_site_handler_ = h;
     94   }
     95 
     96   // Identifies the type of process (renderer, plugin, etc.) making the request.
     97   int process_type() const { return process_type_; }
     98 
     99   // Downloads are allowed only as a top level request.
    100   bool allow_download() const { return allow_download_; }
    101 
    102   // Whether this is a download.
    103   bool is_download() const { return is_download_; }
    104   void set_is_download(bool download) { is_download_ = download; }
    105 
    106   // Whether this is a stream.
    107   bool is_stream() const { return is_stream_; }
    108   void set_is_stream(bool stream) { is_stream_ = stream; }
    109 
    110   void set_was_ignored_by_handler(bool value) {
    111     was_ignored_by_handler_ = value;
    112   }
    113 
    114   // The approximate in-memory size (bytes) that we credited this request
    115   // as consuming in |outstanding_requests_memory_cost_map_|.
    116   int memory_cost() const { return memory_cost_; }
    117   void set_memory_cost(int cost) { memory_cost_ = cost; }
    118 
    119   // We hold a reference to the requested blob data to ensure it doesn't
    120   // get finally released prior to the net::URLRequestJob being started.
    121   webkit_blob::BlobData* requested_blob_data() const {
    122     return requested_blob_data_.get();
    123   }
    124   void set_requested_blob_data(webkit_blob::BlobData* data);
    125 
    126  private:
    127   // Non-owning, may be NULL.
    128   CrossSiteResourceHandler* cross_site_handler_;
    129 
    130   int process_type_;
    131   int child_id_;
    132   int route_id_;
    133   int origin_pid_;
    134   int request_id_;
    135   bool is_main_frame_;
    136   int64 frame_id_;
    137   bool parent_is_main_frame_;
    138   int64 parent_frame_id_;
    139   bool is_download_;
    140   bool is_stream_;
    141   bool allow_download_;
    142   bool has_user_gesture_;
    143   bool was_ignored_by_handler_;
    144   ResourceType::Type resource_type_;
    145   PageTransition transition_type_;
    146   int memory_cost_;
    147   scoped_refptr<webkit_blob::BlobData> requested_blob_data_;
    148   WebKit::WebReferrerPolicy referrer_policy_;
    149   ResourceContext* context_;
    150   bool is_async_;
    151 
    152   DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
    153 };
    154 
    155 }  // namespace content
    156 
    157 #endif  // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
    158