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