• 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_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
7 
8 #include "base/basictypes.h"
9 #include "content/common/content_export.h"
10 #include "content/public/common/page_transition_types.h"
11 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
12 #include "webkit/common/resource_type.h"
13 
14 namespace net {
15 class URLRequest;
16 }
17 
18 namespace content {
19 class ResourceContext;
20 
21 // Each URLRequest allocated by the ResourceDispatcherHost has a
22 // ResourceRequestInfo instance associated with it.
23 class ResourceRequestInfo {
24  public:
25   // Returns the ResourceRequestInfo associated with the given URLRequest.
26   CONTENT_EXPORT static const ResourceRequestInfo* ForRequest(
27       const net::URLRequest* request);
28 
29   // Allocates a new, dummy ResourceRequestInfo and associates it with the
30   // given URLRequest.
31   // NOTE: Add more parameters if you need to initialize other fields.
32   CONTENT_EXPORT static void AllocateForTesting(
33       net::URLRequest* request,
34       ResourceType::Type resource_type,
35       ResourceContext* context,
36       int render_process_id,
37       int render_view_id,
38       bool is_async);
39 
40   // Returns the associated RenderView for a given process. Returns false, if
41   // there is no associated RenderView. This method does not rely on the
42   // request being allocated by the ResourceDispatcherHost, but works for all
43   // URLRequests that are associated with a RenderView.
44   CONTENT_EXPORT static bool GetRenderViewForRequest(
45       const net::URLRequest* request,
46       int* render_process_id,
47       int* render_view_id);
48 
49   // Returns the associated ResourceContext.
50   virtual ResourceContext* GetContext() const = 0;
51 
52   // The child process unique ID of the requestor.
53   virtual int GetChildID() const = 0;
54 
55   // The IPC route identifier for this request (this identifies the RenderView
56   // or like-thing in the renderer that the request gets routed to).
57   virtual int GetRouteID() const = 0;
58 
59   // The pid of the originating process, if the request is sent on behalf of a
60   // another process.  Otherwise it is 0.
61   virtual int GetOriginPID() const = 0;
62 
63   // Unique identifier (within the scope of the child process) for this request.
64   virtual int GetRequestID() const = 0;
65 
66   // The IPC route identifier of the RenderFrame.
67   // TODO(jam): once all navigation and resource requests are sent between
68   // frames and RenderView/RenderViewHost aren't involved we can remove this and
69   // just use GetRouteID above.
70   virtual int GetRenderFrameID() const = 0;
71 
72   // True if GetFrameID() represents a main frame in the RenderView.
73   virtual bool IsMainFrame() const = 0;
74 
75   // Frame ID that sent this resource request. -1 if unknown / invalid.
76   virtual int64 GetFrameID() const = 0;
77 
78   // True if GetParentFrameID() represents a main frame in the RenderView.
79   virtual bool ParentIsMainFrame() const = 0;
80 
81   // Frame ID of parent frame of frame that sent this resource request.
82   // -1 if unknown / invalid.
83   virtual int64 GetParentFrameID() const = 0;
84 
85   // Returns the associated resource type.
86   virtual ResourceType::Type GetResourceType() const = 0;
87 
88   // Returns the associated referrer policy.
89   virtual blink::WebReferrerPolicy GetReferrerPolicy() const = 0;
90 
91   // Returns the associated page transition type.
92   virtual PageTransition GetPageTransition() const = 0;
93 
94   // True if the request was initiated by a user action (like a tap to follow
95   // a link).
96   virtual bool HasUserGesture() const = 0;
97 
98   // True if ResourceController::CancelAndIgnore() was called.  For example,
99   // the requested URL may be being loaded by an external program.
100   virtual bool WasIgnoredByHandler() const = 0;
101 
102   // Returns false if there is NOT an associated render view.
103   virtual bool GetAssociatedRenderView(int* render_process_id,
104                                        int* render_view_id) const = 0;
105 
106   // Returns true if this is associated with an asynchronous request.
107   virtual bool IsAsync() const = 0;
108 
109   // Whether this is a download.
110   virtual bool IsDownload() const = 0;
111 
112  protected:
~ResourceRequestInfo()113   virtual ~ResourceRequestInfo() {}
114 };
115 
116 }  // namespace content
117 
118 #endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_REQUEST_INFO_H_
119