Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: content/public/browser/navigation_handle.h

Issue 1363483007: Reland of Add a NavigationThrottle to the public content/ interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_
6 #define CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ 6 #define CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_
7 7
8 #include "content/common/content_export.h" 8 #include "content/common/content_export.h"
9 #include "content/public/browser/navigation_throttle.h"
10 #include "content/public/common/referrer.h"
9 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "ui/base/page_transition_types.h"
10 13
11 class GURL; 14 class GURL;
12 15
13 namespace content { 16 namespace content {
17 class NavigationThrottle;
14 class RenderFrameHost; 18 class RenderFrameHost;
19 class WebContents;
15 20
16 // A NavigationHandle tracks information related to a single navigation. 21 // A NavigationHandle tracks information related to a single navigation.
17 class CONTENT_EXPORT NavigationHandle { 22 class CONTENT_EXPORT NavigationHandle {
18 public: 23 public:
19 virtual ~NavigationHandle() {} 24 virtual ~NavigationHandle() {}
20 25
26 // Parameters available at navigation start time -----------------------------
27 //
28 // These parameters are always available during the navigation. Note that
29 // some may change during navigation (e.g. due to server redirects).
30
21 // The URL the frame is navigating to. This may change during the navigation 31 // The URL the frame is navigating to. This may change during the navigation
22 // when encountering a server redirect. 32 // when encountering a server redirect.
23 virtual const GURL& GetURL() const = 0; 33 virtual const GURL& GetURL() = 0;
34
35 // Whether the navigation is taking place in the main frame or in a subframe.
36 // This remains constant over the navigation lifetime.
37 virtual bool IsInMainFrame() = 0;
38
39 // The WebContents the navigation is taking place in.
40 WebContents* GetWebContents();
41
42 // Parameters available at network request start time ------------------------
43 //
44 // The following parameters are only available when the network request is
45 // made for the navigation (or at commit time if no network request is made).
46 // This corresponds to NavigationThrottle::WillSendRequest. They should not
47 // be queried before that.
48
49 // Whether the navigation is a POST or a GET. This may change during the
50 // navigation when encountering a server redirect.
51 virtual bool IsPost() = 0;
52
53 // Returns a sanitized version of the referrer for this request.
54 virtual const Referrer& GetReferrer() = 0;
55
56 // Whether the navigation was initiated by a user gesture. Note that this
57 // will return false for browser-initiated navigations.
58 // TODO(clamy): when PlzNavigate launches, this should return true for
59 // browser-initiated navigations.
60 virtual bool HasUserGesture() = 0;
61
62 // Returns the page transition type.
63 virtual ui::PageTransition GetPageTransition() = 0;
64
65 // Whether the target URL cannot be handled by the browser's internal protocol
66 // handlers.
67 virtual bool IsExternalProtocol() = 0;
68
69 // Navigation control flow --------------------------------------------------
24 70
25 // The net error code if an error happened prior to commit. Otherwise it will 71 // The net error code if an error happened prior to commit. Otherwise it will
26 // be net::OK. 72 // be net::OK.
27 virtual net::Error GetNetErrorCode() const = 0; 73 virtual net::Error GetNetErrorCode() = 0;
28
29 // Whether the navigation is taking place in the main frame or in a subframe.
30 virtual bool IsInMainFrame() const = 0;
31 74
32 // Returns the RenderFrameHost this navigation is taking place in. This can 75 // Returns the RenderFrameHost this navigation is taking place in. This can
33 // only be accessed after the navigation is ready to commit. 76 // only be accessed after the navigation is ready to commit.
34 virtual RenderFrameHost* GetRenderFrameHost() = 0; 77 virtual RenderFrameHost* GetRenderFrameHost() = 0;
35 78
36 // Whether the navigation happened in the same page. This is only known 79 // Whether the navigation happened in the same page. This is only known
37 // after the navigation has committed. It is an error to call this method 80 // after the navigation has committed. It is an error to call this method
38 // before the navigation has committed. 81 // before the navigation has committed.
39 virtual bool IsSamePage() = 0; 82 virtual bool IsSamePage() = 0;
40 83
41 // Whether the navigation has committed. This returns true for either 84 // Whether the navigation has committed. This returns true for either
42 // successful commits or error pages that replace the previous page 85 // successful commits or error pages that replace the previous page
43 // (distinguished by |IsErrorPage|), and false for errors that leave the user 86 // (distinguished by |IsErrorPage|), and false for errors that leave the user
44 // on the previous page. 87 // on the previous page.
45 virtual bool HasCommitted() = 0; 88 virtual bool HasCommitted() = 0;
46 89
47 // Whether the navigation resulted in an error page. 90 // Whether the navigation resulted in an error page.
48 virtual bool IsErrorPage() = 0; 91 virtual bool IsErrorPage() = 0;
92
93 // Testing methods ----------------------------------------------------------
94 //
95 // The following methods should be used exclusively for writing unit tests.
96
97 static scoped_ptr<NavigationHandle> CreateNavigationHandleForTesting(
98 const GURL& url,
99 bool is_main_frame,
100 WebContents* web_contents);
101
102 // Registers a NavigationThrottle for tests. The throttle can
103 // modify the request, pause the request or cancel the request. This will
104 // take ownership of the NavigationThrottle.
105 // Note: in non-test cases, NavigationThrottles should not be added directly
106 // but returned by the implementation of
107 // ContentBrowserClient::CreateThrottlesForNavigation. This ensures proper
108 // ordering of the throttles.
109 virtual void RegisterThrottleForTesting(
110 scoped_ptr<NavigationThrottle> navigation_throttle) = 0;
111
112 // Simulates the network request starting.
113 virtual NavigationThrottle::ThrottleCheckResult
114 CallWillStartRequestForTesting(bool is_post,
115 const Referrer& sanitized_referrer,
116 bool has_user_gesture,
117 ui::PageTransition transition,
118 bool is_external_protocol) = 0;
119
120 // Simulates the network request being redirected.
121 virtual NavigationThrottle::ThrottleCheckResult
122 CallWillRedirectRequestForTesting(const GURL& new_url,
123 bool new_method_is_post,
124 const GURL& new_referrer_url,
125 bool new_is_external_protocol) = 0;
49 }; 126 };
50 127
51 } // namespace content 128 } // namespace content
52 129
53 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ 130 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_
OLDNEW
« no previous file with comments | « content/public/browser/content_browser_client.cc ('k') | content/public/browser/navigation_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698