1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBLAYER_BROWSER_NAVIGATION_CONTROLLER_IMPL_H_
#define WEBLAYER_BROWSER_NAVIGATION_CONTROLLER_IMPL_H_
#include <map>
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "build/build_config.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents_observer.h"
#include "weblayer/browser/navigation_impl.h"
#include "weblayer/public/navigation_controller.h"
#if defined(OS_ANDROID)
#include "base/android/scoped_java_ref.h"
#endif
namespace content {
class NavigationThrottle;
}
namespace weblayer {
class TabImpl;
class NavigationControllerImpl : public NavigationController,
public content::WebContentsObserver {
public:
explicit NavigationControllerImpl(TabImpl* tab);
~NavigationControllerImpl() override;
// Creates the NavigationThrottle used to ensure WebContents::Stop() is called
// at safe times. See NavigationControllerImpl for details.
std::unique_ptr<content::NavigationThrottle> CreateNavigationThrottle(
content::NavigationHandle* handle);
#if defined(OS_ANDROID)
void SetNavigationControllerImpl(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& java_controller);
void Navigate(JNIEnv* env,
const base::android::JavaParamRef<jstring>& url);
void NavigateWithParams(JNIEnv* env,
const base::android::JavaParamRef<jstring>& url,
jboolean should_replace_current_entry);
void GoBack(JNIEnv* env) { GoBack(); }
void GoForward(JNIEnv* env) { GoForward(); }
bool CanGoBack(JNIEnv* env) { return CanGoBack(); }
bool CanGoForward(JNIEnv* env) { return CanGoForward(); }
void GoToIndex(JNIEnv* env, int index) { return GoToIndex(index); }
void Reload(JNIEnv* env) { Reload(); }
void Stop(JNIEnv* env) { Stop(); }
int GetNavigationListSize(JNIEnv* env) { return GetNavigationListSize(); }
int GetNavigationListCurrentIndex(JNIEnv* env) {
return GetNavigationListCurrentIndex();
}
base::android::ScopedJavaLocalRef<jstring> GetNavigationEntryDisplayUri(
JNIEnv* env,
int index);
base::android::ScopedJavaLocalRef<jstring> GetNavigationEntryTitle(
JNIEnv* env,
int index);
bool IsNavigationEntrySkippable(JNIEnv* env, int index);
#endif
private:
class NavigationThrottleImpl;
// Called from NavigationControllerImpl::WillRedirectRequest(). See
// description of NavigationControllerImpl for details.
void WillRedirectRequest(NavigationThrottleImpl* throttle,
content::NavigationHandle* navigation_handle);
// NavigationController implementation:
void AddObserver(NavigationObserver* observer) override;
void RemoveObserver(NavigationObserver* observer) override;
void Navigate(const GURL& url) override;
void Navigate(const GURL& url, const NavigateParams& params) override;
void GoBack() override;
void GoForward() override;
bool CanGoBack() override;
bool CanGoForward() override;
void GoToIndex(int index) override;
void Reload() override;
void Stop() override;
int GetNavigationListSize() override;
int GetNavigationListCurrentIndex() override;
GURL GetNavigationEntryDisplayURL(int index) override;
std::string GetNavigationEntryTitle(int index) override;
bool IsNavigationEntrySkippable(int index) override;
// content::WebContentsObserver implementation:
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void DidRedirectNavigation(
content::NavigationHandle* navigation_handle) override;
void ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
void DidStartLoading() override;
void DidStopLoading() override;
void LoadProgressChanged(double progress) override;
void DidFirstVisuallyNonEmptyPaint() override;
void OldPageNoLongerRendered(const GURL& url, bool success);
void NotifyLoadStateChanged();
void DoNavigate(
std::unique_ptr<content::NavigationController::LoadURLParams> params);
base::ObserverList<NavigationObserver>::Unchecked observers_;
std::map<content::NavigationHandle*, std::unique_ptr<NavigationImpl>>
navigation_map_;
// If non-null then processing is inside DidStartNavigation() and
// |navigation_starting_| is the NavigationImpl that was created.
NavigationImpl* navigation_starting_ = nullptr;
// Set to non-null while in WillRedirectRequest().
NavigationThrottleImpl* active_throttle_ = nullptr;
#if defined(OS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> java_controller_;
#endif
base::WeakPtrFactory<NavigationControllerImpl> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(NavigationControllerImpl);
};
} // namespace weblayer
#endif // WEBLAYER_BROWSER_NAVIGATION_CONTROLLER_IMPL_H_
|