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

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: Addressed comments 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 has successfully committed a document. 74 // Whether the navigation has successfully committed a document.
32 virtual bool HasCommittedDocument() const = 0; 75 virtual bool HasCommittedDocument() = 0;
33 76
34 // Whether an error page has committed for the navigation. 77 // Whether an error page has committed for the navigation.
35 virtual bool HasCommittedErrorPage() const = 0; 78 virtual bool HasCommittedErrorPage() = 0;
79
80 // Testing methods ----------------------------------------------------------
81 // The following methods should be used exclusively for writing unit tests.
82
83 static scoped_ptr<NavigationHandle> CreateNavigationHandleForTesting(
84 const GURL& url,
85 bool is_main_frame,
86 WebContents* web_contents);
87
88 // Registers a NavigationThrottle for tests. The throttle can
89 // modify the request, pause the request or cancel the request. This will
90 // take ownership of the NavigationThrottle.
91 // Note: in non-test cases, NavigationThrottles should not be added directly
92 // but returned by the implementation of
93 // ContentBrowserClient::CreateThrottlesForNavigation. This ensures proper
94 // ordering of the throttles.
95 virtual void RegisterThrottleForTesting(
96 scoped_ptr<NavigationThrottle> navigation_throttle) = 0;
97
98 // Simulates the network request starting.
99 virtual NavigationThrottle::ThrottleCheckResult
100 CallWillStartRequestForTesting(bool is_post,
101 const Referrer& sanitized_referrer,
102 bool has_user_gesture,
103 ui::PageTransition transition,
104 bool is_external_protocol) = 0;
105
106 // Simulates the network request being redirected.
107 virtual NavigationThrottle::ThrottleCheckResult
108 CallWillRedirectRequestForTesting(const GURL& new_url,
109 bool new_method_is_post,
110 const GURL& new_referrer_url,
111 bool new_is_external_protocol) = 0;
36 }; 112 };
37 113
38 } // namespace content 114 } // namespace content
39 115
40 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ 116 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698