summaryrefslogtreecommitdiff
path: root/chromium/weblayer/browser/navigation_impl.h
blob: 8e3e114b74137825b990968f4a550b469a6d30e5 (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// 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_IMPL_H_
#define WEBLAYER_BROWSER_NAVIGATION_IMPL_H_

#include <memory>

#include "build/build_config.h"
#include "weblayer/public/navigation.h"

#if defined(OS_ANDROID)
#include "base/android/scoped_java_ref.h"
#endif

namespace content {
class NavigationHandle;
}

namespace embedder_support {
class WebResourceResponse;
}

namespace weblayer {

class NavigationImpl : public Navigation {
 public:
  explicit NavigationImpl(content::NavigationHandle* navigation_handle);
  NavigationImpl(const NavigationImpl&) = delete;
  NavigationImpl& operator=(const NavigationImpl&) = delete;
  ~NavigationImpl() override;

  int navigation_entry_unique_id() const { return navigation_entry_unique_id_; }

  void set_should_stop_when_throttle_created() {
    should_stop_when_throttle_created_ = true;
  }
  bool should_stop_when_throttle_created() const {
    return should_stop_when_throttle_created_;
  }

  void set_safe_to_set_request_headers(bool value) {
    safe_to_set_request_headers_ = value;
  }

  void set_safe_to_set_user_agent(bool value) {
    safe_to_set_user_agent_ = value;
  }

  void set_safe_to_disable_network_error_auto_reload(bool value) {
    safe_to_disable_network_error_auto_reload_ = value;
  }

  void set_safe_to_get_page() { safe_to_get_page_ = true; }

  void set_was_stopped() { was_stopped_ = true; }

  bool set_user_agent_string_called() { return set_user_agent_string_called_; }

  bool disable_network_error_auto_reload() {
    return disable_network_error_auto_reload_;
  }

  void set_finished() { finished_ = true; }

#if defined(OS_ANDROID)
  int GetState(JNIEnv* env) { return static_cast<int>(GetState()); }
  base::android::ScopedJavaLocalRef<jstring> GetUri(JNIEnv* env);
  base::android::ScopedJavaLocalRef<jobjectArray> GetRedirectChain(JNIEnv* env);
  int GetHttpStatusCode(JNIEnv* env) { return GetHttpStatusCode(); }
  base::android::ScopedJavaLocalRef<jobjectArray> GetResponseHeaders(
      JNIEnv* env);
  bool IsSameDocument(JNIEnv* env) { return IsSameDocument(); }
  bool IsErrorPage(JNIEnv* env) { return IsErrorPage(); }
  bool IsDownload(JNIEnv* env) { return IsDownload(); }
  bool IsKnownProtocol(JNIEnv* env) { return IsKnownProtocol(); }
  bool WasStopCalled(JNIEnv* env) { return WasStopCalled(); }
  int GetLoadError(JNIEnv* env) { return static_cast<int>(GetLoadError()); }
  jboolean SetRequestHeader(JNIEnv* env,
                            const base::android::JavaParamRef<jstring>& name,
                            const base::android::JavaParamRef<jstring>& value);
  jboolean SetUserAgentString(
      JNIEnv* env,
      const base::android::JavaParamRef<jstring>& value);
  jboolean IsPageInitiated(JNIEnv* env) { return IsPageInitiated(); }
  jboolean IsReload(JNIEnv* env) { return IsReload(); }
  jboolean IsServedFromBackForwardCache(JNIEnv* env) {
    return IsServedFromBackForwardCache();
  }
  jboolean DisableNetworkErrorAutoReload(JNIEnv* env);
  jboolean AreIntentLaunchesAllowedInBackground(JNIEnv* env);
  jboolean IsFormSubmission(JNIEnv* env) { return IsFormSubmission(); }
  base::android::ScopedJavaLocalRef<jstring> GetReferrer(JNIEnv* env);
  jlong GetPage(JNIEnv* env);
  int GetNavigationEntryOffset(JNIEnv* env);

  void SetResponse(
      std::unique_ptr<embedder_support::WebResourceResponse> response);
  std::unique_ptr<embedder_support::WebResourceResponse> TakeResponse();

  void SetJavaNavigation(
      const base::android::ScopedJavaGlobalRef<jobject>& java_navigation);
  base::android::ScopedJavaGlobalRef<jobject> java_navigation() {
    return java_navigation_;
  }
#endif

  // Navigation implementation:
  GURL GetURL() override;
  const std::vector<GURL>& GetRedirectChain() override;
  NavigationState GetState() override;
  int GetHttpStatusCode() override;
  const net::HttpResponseHeaders* GetResponseHeaders() override;
  bool IsSameDocument() override;
  bool IsErrorPage() override;
  bool IsDownload() override;
  bool IsKnownProtocol() override;
  bool WasStopCalled() override;
  LoadError GetLoadError() override;
  void SetRequestHeader(const std::string& name,
                        const std::string& value) override;
  void SetUserAgentString(const std::string& value) override;
  void DisableNetworkErrorAutoReload() override;
  bool IsPageInitiated() override;
  bool IsReload() override;
  bool IsServedFromBackForwardCache() override;
  bool IsFormSubmission() override;
  GURL GetReferrer() override;
  Page* GetPage() override;
  int GetNavigationEntryOffset() override;

 private:
  content::NavigationHandle* navigation_handle_;

  // The NavigationEntry's unique ID for this navigation, or -1 if there isn't
  // one.
  int navigation_entry_unique_id_ = -1;

  // Used to delay calling Stop() until safe. See
  // NavigationControllerImpl::NavigationThrottleImpl for details.
  bool should_stop_when_throttle_created_ = false;

  // Whether SetRequestHeader() is allowed at this time.
  bool safe_to_set_request_headers_ = false;

  // Whether SetUserAgentString() is allowed at this time.
  bool safe_to_set_user_agent_ = false;

  // Whether NavigationController::Stop() was called for this navigation.
  bool was_stopped_ = false;

  // Whether SetUserAgentString was called.
  bool set_user_agent_string_called_ = false;

  // Whether DisableNetworkErrorAutoReload is allowed at this time.
  bool safe_to_disable_network_error_auto_reload_ = false;

  // Whether GetPage is allowed at this time.
  bool safe_to_get_page_ = false;

  bool disable_network_error_auto_reload_ = false;

  // Whether this navigation has finished.
  bool finished_ = false;

#if defined(OS_ANDROID)
  base::android::ScopedJavaGlobalRef<jobject> java_navigation_;
  std::unique_ptr<embedder_support::WebResourceResponse> response_;
#endif
};

}  // namespace weblayer

#endif  // WEBLAYER_BROWSER_NAVIGATION_IMPL_H_