navigation_impl.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef WEBLAYER_BROWSER_NAVIGATION_IMPL_H_
  5. #define WEBLAYER_BROWSER_NAVIGATION_IMPL_H_
  6. #include <memory>
  7. #include "base/memory/raw_ptr.h"
  8. #include "build/build_config.h"
  9. #include "weblayer/public/navigation.h"
  10. #if BUILDFLAG(IS_ANDROID)
  11. #include "base/android/scoped_java_ref.h"
  12. #endif
  13. namespace content {
  14. class NavigationHandle;
  15. }
  16. namespace embedder_support {
  17. class WebResourceResponse;
  18. }
  19. namespace weblayer {
  20. class NavigationImpl : public Navigation {
  21. public:
  22. explicit NavigationImpl(content::NavigationHandle* navigation_handle);
  23. NavigationImpl(const NavigationImpl&) = delete;
  24. NavigationImpl& operator=(const NavigationImpl&) = delete;
  25. ~NavigationImpl() override;
  26. int navigation_entry_unique_id() const { return navigation_entry_unique_id_; }
  27. void set_should_stop_when_throttle_created() {
  28. should_stop_when_throttle_created_ = true;
  29. }
  30. bool should_stop_when_throttle_created() const {
  31. return should_stop_when_throttle_created_;
  32. }
  33. void set_safe_to_set_request_headers(bool value) {
  34. safe_to_set_request_headers_ = value;
  35. }
  36. void set_safe_to_set_user_agent(bool value) {
  37. safe_to_set_user_agent_ = value;
  38. }
  39. void set_safe_to_disable_network_error_auto_reload(bool value) {
  40. safe_to_disable_network_error_auto_reload_ = value;
  41. }
  42. void set_safe_to_disable_intent_processing(bool value) {
  43. safe_to_disable_intent_processing_ = value;
  44. }
  45. void set_safe_to_get_page() { safe_to_get_page_ = true; }
  46. void set_was_stopped() { was_stopped_ = true; }
  47. bool set_user_agent_string_called() { return set_user_agent_string_called_; }
  48. bool disable_network_error_auto_reload() {
  49. return disable_network_error_auto_reload_;
  50. }
  51. bool disable_intent_processing() { return disable_intent_processing_; }
  52. void set_finished() { finished_ = true; }
  53. #if BUILDFLAG(IS_ANDROID)
  54. int GetState(JNIEnv* env) { return static_cast<int>(GetState()); }
  55. base::android::ScopedJavaLocalRef<jstring> GetUri(JNIEnv* env);
  56. base::android::ScopedJavaLocalRef<jobjectArray> GetRedirectChain(JNIEnv* env);
  57. int GetHttpStatusCode(JNIEnv* env) { return GetHttpStatusCode(); }
  58. base::android::ScopedJavaLocalRef<jobjectArray> GetResponseHeaders(
  59. JNIEnv* env);
  60. bool IsSameDocument(JNIEnv* env) { return IsSameDocument(); }
  61. bool IsErrorPage(JNIEnv* env) { return IsErrorPage(); }
  62. bool IsDownload(JNIEnv* env) { return IsDownload(); }
  63. bool IsKnownProtocol(JNIEnv* env) { return IsKnownProtocol(); }
  64. bool WasStopCalled(JNIEnv* env) { return WasStopCalled(); }
  65. int GetLoadError(JNIEnv* env) { return static_cast<int>(GetLoadError()); }
  66. jboolean SetRequestHeader(JNIEnv* env,
  67. const base::android::JavaParamRef<jstring>& name,
  68. const base::android::JavaParamRef<jstring>& value);
  69. jboolean SetUserAgentString(
  70. JNIEnv* env,
  71. const base::android::JavaParamRef<jstring>& value);
  72. jboolean IsPageInitiated(JNIEnv* env) { return IsPageInitiated(); }
  73. jboolean IsReload(JNIEnv* env) { return IsReload(); }
  74. jboolean IsServedFromBackForwardCache(JNIEnv* env) {
  75. return IsServedFromBackForwardCache();
  76. }
  77. jboolean DisableNetworkErrorAutoReload(JNIEnv* env);
  78. jboolean DisableIntentProcessing(JNIEnv* env);
  79. jboolean AreIntentLaunchesAllowedInBackground(JNIEnv* env);
  80. jboolean IsFormSubmission(JNIEnv* env) { return IsFormSubmission(); }
  81. base::android::ScopedJavaLocalRef<jstring> GetReferrer(JNIEnv* env);
  82. jlong GetPage(JNIEnv* env);
  83. int GetNavigationEntryOffset(JNIEnv* env);
  84. jboolean WasFetchedFromCache(JNIEnv* env);
  85. void SetResponse(
  86. std::unique_ptr<embedder_support::WebResourceResponse> response);
  87. std::unique_ptr<embedder_support::WebResourceResponse> TakeResponse();
  88. void SetJavaNavigation(
  89. const base::android::ScopedJavaGlobalRef<jobject>& java_navigation);
  90. base::android::ScopedJavaGlobalRef<jobject> java_navigation() {
  91. return java_navigation_;
  92. }
  93. #endif
  94. // Navigation implementation:
  95. GURL GetURL() override;
  96. const std::vector<GURL>& GetRedirectChain() override;
  97. NavigationState GetState() override;
  98. int GetHttpStatusCode() override;
  99. const net::HttpResponseHeaders* GetResponseHeaders() override;
  100. bool IsSameDocument() override;
  101. bool IsErrorPage() override;
  102. bool IsDownload() override;
  103. bool IsKnownProtocol() override;
  104. bool WasStopCalled() override;
  105. LoadError GetLoadError() override;
  106. void SetRequestHeader(const std::string& name,
  107. const std::string& value) override;
  108. void SetUserAgentString(const std::string& value) override;
  109. void DisableNetworkErrorAutoReload() override;
  110. bool IsPageInitiated() override;
  111. bool IsReload() override;
  112. bool IsServedFromBackForwardCache() override;
  113. bool IsFormSubmission() override;
  114. GURL GetReferrer() override;
  115. Page* GetPage() override;
  116. int GetNavigationEntryOffset() override;
  117. bool WasFetchedFromCache() override;
  118. private:
  119. raw_ptr<content::NavigationHandle> navigation_handle_;
  120. // The NavigationEntry's unique ID for this navigation, or -1 if there isn't
  121. // one.
  122. int navigation_entry_unique_id_ = -1;
  123. // Used to delay calling Stop() until safe. See
  124. // NavigationControllerImpl::NavigationThrottleImpl for details.
  125. bool should_stop_when_throttle_created_ = false;
  126. // Whether SetRequestHeader() is allowed at this time.
  127. bool safe_to_set_request_headers_ = false;
  128. // Whether SetUserAgentString() is allowed at this time.
  129. bool safe_to_set_user_agent_ = false;
  130. // Whether NavigationController::Stop() was called for this navigation.
  131. bool was_stopped_ = false;
  132. // Whether SetUserAgentString was called.
  133. bool set_user_agent_string_called_ = false;
  134. // Whether DisableNetworkErrorAutoReload is allowed at this time.
  135. bool safe_to_disable_network_error_auto_reload_ = false;
  136. // Whether DisableIntentProcessing is allowed at this time.
  137. bool safe_to_disable_intent_processing_ = false;
  138. // Whether GetPage is allowed at this time.
  139. bool safe_to_get_page_ = false;
  140. bool disable_network_error_auto_reload_ = false;
  141. bool disable_intent_processing_ = false;
  142. // Whether this navigation has finished.
  143. bool finished_ = false;
  144. #if BUILDFLAG(IS_ANDROID)
  145. base::android::ScopedJavaGlobalRef<jobject> java_navigation_;
  146. std::unique_ptr<embedder_support::WebResourceResponse> response_;
  147. #endif
  148. };
  149. } // namespace weblayer
  150. #endif // WEBLAYER_BROWSER_NAVIGATION_IMPL_H_