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

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

Issue 1269813002: Add a NavigationThrottle to the public content/ interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigation-api
Patch Set: Rebase on https://codereview.chromium.org/1312213010/ Created 5 years, 3 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;
18 class WebContents;
14 19
15 // A NavigationHandle tracks information related to a single navigation. 20 // A NavigationHandle tracks information related to a single navigation.
16 class CONTENT_EXPORT NavigationHandle { 21 class CONTENT_EXPORT NavigationHandle {
17 public: 22 public:
18 virtual ~NavigationHandle() {} 23 virtual ~NavigationHandle() {}
19 24
25 // Parameters available at navigation start time -----------------------------
26 //
27 // These parameters are always available during the navigation. Note that
28 // some may change during navigation (e.g. due to server redirects).
29
20 // The URL the frame is navigating to. This may change during the navigation 30 // The URL the frame is navigating to. This may change during the navigation
21 // when encountering a server redirect. 31 // when encountering a server redirect.
22 virtual const GURL& GetURL() const = 0; 32 virtual const GURL& GetURL() = 0;
33
34 // Whether the navigation is taking place in the main frame or in a subframe.
35 // This remains constant over the navigation lifetime.
36 virtual bool IsInMainFrame() = 0;
37
38 // The WebContents the navigation is taking place in.
39 WebContents* GetWebContents();
40
41 // Parameters available at network request start time ------------------------
42 //
43 // The following parameters are only available when the network request is
44 // made for the navigation (or at commit time if no network request is made).
45 // This corresponds to NavigationThrottle::WillSendRequest. They should not
46 // be queried before that.
47
48 // Whether the navigation is a POST or a GET. This may change during the
49 // navigation when encountering a server redirect.
50 virtual bool IsPost() = 0;
51
52 // Returns a sanitized version of the referrer for this request.
53 virtual const Referrer& GetReferrer() = 0;
54
55 // Whether the navigation was initiated by a user gesture. Note that this
56 // will return false for browser-initiated navigations.
57 // TODO(clamy): when PlzNavigate launches, this should return true for
58 // browser-initiated navigations.
59 virtual bool HasUserGesture() = 0;
60
61 // Returns the page transition type.
62 virtual ui::PageTransition GetPageTransition() = 0;
63
64 // Whether the target URL cannot be handled by the browser's internal protocol
65 // handlers.
66 virtual bool IsExternalProtocol() = 0;
67
68 // Navigation control flow --------------------------------------------------
23 69
24 // The net error code if an error happened prior to commit. Otherwise it will 70 // The net error code if an error happened prior to commit. Otherwise it will
25 // be net::OK. 71 // be net::OK.
26 virtual net::Error GetNetErrorCode() const = 0; 72 virtual net::Error GetNetErrorCode() = 0;
27
28 // Whether the navigation is taking place in the main frame or in a subframe.
29 virtual bool IsInMainFrame() const = 0;
30 73
31 // Whether the navigation happened in the same page. This is only known 74 // Whether the navigation happened in the same page. This is only known
32 // after the navigation has committed. It is an error to call this method 75 // after the navigation has committed. It is an error to call this method
33 // before the navigation has committed. 76 // before the navigation has committed.
34 virtual bool IsSamePage() = 0; 77 virtual bool IsSamePage() = 0;
35 78
36 // Whether the navigation has successfully committed a document. 79 // Whether the navigation has successfully committed a document.
37 virtual bool HasCommittedDocument() const = 0; 80 virtual bool HasCommittedDocument() = 0;
38 81
39 // Whether an error page has committed for the navigation. 82 // Whether an error page has committed for the navigation.
40 virtual bool HasCommittedErrorPage() const = 0; 83 virtual bool HasCommittedErrorPage() = 0;
84
85 // Testing methods ----------------------------------------------------------
86 //
87 // The following methods should be used exclusively for writing unit tests.
88
89 static scoped_ptr<NavigationHandle> CreateNavigationHandleForTesting(
90 const GURL& url,
91 bool is_main_frame,
92 WebContents* web_contents);
93
94 // Registers a NavigationThrottle for tests. The throttle can
95 // modify the request, pause the request or cancel the request. This will
96 // take ownership of the NavigationThrottle.
97 // Note: in non-test cases, NavigationThrottles should not be added directly
98 // but returned by the implementation of
99 // ContentBrowserClient::CreateThrottlesForNavigation. This ensures proper
100 // ordering of the throttles.
101 virtual void RegisterThrottleForTesting(
102 scoped_ptr<NavigationThrottle> navigation_throttle) = 0;
103
104 // Simulates the network request starting.
105 virtual NavigationThrottle::ThrottleCheckResult
106 CallWillStartRequestForTesting(bool is_post,
107 const Referrer& sanitized_referrer,
108 bool has_user_gesture,
109 ui::PageTransition transition,
110 bool is_external_protocol) = 0;
111
112 // Simulates the network request being redirected.
113 virtual NavigationThrottle::ThrottleCheckResult
114 CallWillRedirectRequestForTesting(const GURL& new_url,
115 bool new_method_is_post,
116 const GURL& new_referrer_url,
117 bool new_is_external_protocol) = 0;
41 }; 118 };
42 119
43 } // namespace content 120 } // namespace content
44 121
45 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ 122 #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