OLD | NEW |
---|---|
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 | |
nasko
2015/09/17 21:10:25
nit: No empty line above. The statement below clar
clamy
2015/09/18 17:35:39
Done.
Charlie Reis
2015/09/18 17:58:39
nit: We should be consistent with the sections abo
clamy
2015/09/18 21:58:47
Done. I went with having a line starting with // a
| |
82 // The following methods should be used exclusively for writing unit tests. | |
83 | |
84 static scoped_ptr<NavigationHandle> CreateNavigationHandleForTesting( | |
85 const GURL& url, | |
86 bool is_main_frame, | |
87 WebContents* web_contents); | |
88 | |
89 // Registers a NavigationThrottle for tests. The throttle can | |
90 // modify the request, pause the request or cancel the request. This will | |
91 // take ownership of the NavigationThrottle. | |
92 // Note: in non-test cases, NavigationThrottles should not be added directly | |
93 // but returned by the implementation of | |
94 // ContentBrowserClient::CreateThrottlesForNavigation. This ensures proper | |
95 // ordering of the throttles. | |
96 virtual void RegisterThrottleForTesting( | |
97 scoped_ptr<NavigationThrottle> navigation_throttle) = 0; | |
98 | |
99 // Simulates the network request starting. | |
100 virtual NavigationThrottle::ThrottleCheckResult | |
101 CallWillStartRequestForTesting(bool is_post, | |
102 const Referrer& sanitized_referrer, | |
103 bool has_user_gesture, | |
104 ui::PageTransition transition, | |
105 bool is_external_protocol) = 0; | |
106 | |
107 // Simulates the network request being redirected. | |
108 virtual NavigationThrottle::ThrottleCheckResult | |
109 CallWillRedirectRequestForTesting(const GURL& new_url, | |
110 bool new_method_is_post, | |
111 const GURL& new_referrer_url, | |
112 bool new_is_external_protocol) = 0; | |
36 }; | 113 }; |
37 | 114 |
38 } // namespace content | 115 } // namespace content |
39 | 116 |
40 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ | 117 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ |
OLD | NEW |