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

Unified Diff: ios/web/navigation/wk_based_navigation_manager_impl.mm

Issue 2957163002: [Navigation Experiment] Add WKBasedNavigationManagerImpl. (Closed)
Patch Set: Changed WebViewNavigationProxy to a protocol Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/navigation/wk_based_navigation_manager_impl.mm
diff --git a/ios/web/navigation/wk_based_navigation_manager_impl.mm b/ios/web/navigation/wk_based_navigation_manager_impl.mm
new file mode 100644
index 0000000000000000000000000000000000000000..58e39cfbf28a6990d423b559e53a6d8ac41f1151
--- /dev/null
+++ b/ios/web/navigation/wk_based_navigation_manager_impl.mm
@@ -0,0 +1,268 @@
+// Copyright 2017 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.
+
+#import "ios/web/navigation/wk_based_navigation_manager_impl.h"
+
+#include <memory>
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#import "ios/web/navigation/navigation_item_impl.h"
+#import "ios/web/navigation/navigation_manager_delegate.h"
+#include "ios/web/public/load_committed_details.h"
+#import "ios/web/public/navigation_item.h"
+#import "ios/web/public/web_client.h"
+#import "ios/web/web_state/ui/web_view_navigation_proxy.h"
+#import "net/base/mac/url_conversions.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@class CRWSessionController;
+
+namespace web {
+
+WKBasedNavigationManagerImpl::WKBasedNavigationManagerImpl()
Eugene But (OOO till 7-30) 2017/06/29 22:28:02 Could you please add a unit test for this specific
danyao 2017/06/29 23:09:47 I was planning on adding tests to navigation_manag
Eugene But (OOO till 7-30) 2017/06/30 00:59:53 If you think you can maintain good coverage for th
+ : delegate_(nullptr), browser_state_(nullptr) {}
+
+WKBasedNavigationManagerImpl::~WKBasedNavigationManagerImpl() = default;
+
+void WKBasedNavigationManagerImpl::SetDelegate(
+ NavigationManagerDelegate* delegate) {
+ delegate_ = delegate;
+}
+
+void WKBasedNavigationManagerImpl::SetBrowserState(
+ BrowserState* browser_state) {
+ browser_state_ = browser_state;
+}
+
+void WKBasedNavigationManagerImpl::SetSessionController(
+ CRWSessionController* session_controller) {}
+
+void WKBasedNavigationManagerImpl::InitializeSession() {}
+
+void WKBasedNavigationManagerImpl::ReplaceSessionHistory(
+ std::vector<std::unique_ptr<NavigationItem>> items,
+ int current_index) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+void WKBasedNavigationManagerImpl::OnNavigationItemsPruned(
+ size_t pruned_item_count) {
+ delegate_->OnNavigationItemsPruned(pruned_item_count);
+}
+
+void WKBasedNavigationManagerImpl::OnNavigationItemChanged() {
+ delegate_->OnNavigationItemChanged();
+}
+
+void WKBasedNavigationManagerImpl::OnNavigationItemCommitted() {
+ LoadCommittedDetails details;
+ details.item = GetLastCommittedItem();
+ DCHECK(details.item);
+ details.previous_item_index = GetPreviousItemIndex();
+ if (details.previous_item_index >= 0) {
+ NavigationItem* previous_item = GetItemAtIndex(details.previous_item_index);
+ DCHECK(previous_item);
+ details.previous_url = previous_item->GetURL();
+ details.is_in_page = AreUrlsFragmentChangeNavigation(
+ details.previous_url, details.item->GetURL());
+ } else {
+ details.previous_url = GURL();
+ details.is_in_page = NO;
+ }
+
+ delegate_->OnNavigationItemCommitted(details);
+}
+
+CRWSessionController* WKBasedNavigationManagerImpl::GetSessionController()
+ const {
+ return nullptr;
Eugene But (OOO till 7-30) 2017/06/29 22:28:02 nit: Sorry, missed this previously s/nullptr/nil
danyao 2017/06/29 23:09:47 Done.
+}
+
+void WKBasedNavigationManagerImpl::AddTransientItem(const GURL& url) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+void WKBasedNavigationManagerImpl::AddPendingItem(
+ const GURL& url,
+ const web::Referrer& referrer,
+ ui::PageTransition navigation_type,
+ NavigationInitiationType initiation_type,
+ UserAgentOverrideOption user_agent_override_option) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+void WKBasedNavigationManagerImpl::CommitPendingItem() {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+int WKBasedNavigationManagerImpl::GetIndexForOffset(int offset) const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return -1;
+}
+
+BrowserState* WKBasedNavigationManagerImpl::GetBrowserState() const {
+ return browser_state_;
+}
+
+WebState* WKBasedNavigationManagerImpl::GetWebState() const {
+ return delegate_->GetWebState();
+}
+
+NavigationItem* WKBasedNavigationManagerImpl::GetVisibleItem() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return nullptr;
+}
+
+NavigationItem* WKBasedNavigationManagerImpl::GetLastCommittedItem() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return nullptr;
+}
+
+NavigationItem* WKBasedNavigationManagerImpl::GetPendingItem() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return nullptr;
+}
+
+NavigationItem* WKBasedNavigationManagerImpl::GetTransientItem() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return nullptr;
+}
+
+void WKBasedNavigationManagerImpl::DiscardNonCommittedItems() {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+void WKBasedNavigationManagerImpl::LoadURLWithParams(
+ const NavigationManager::WebLoadParams&) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+void WKBasedNavigationManagerImpl::AddTransientURLRewriter(
+ BrowserURLRewriter::URLRewriter rewriter) {
+ DCHECK(rewriter);
+ if (!transient_url_rewriters_) {
+ transient_url_rewriters_.reset(
+ new std::vector<BrowserURLRewriter::URLRewriter>());
+ }
+ transient_url_rewriters_->push_back(rewriter);
+}
+
+int WKBasedNavigationManagerImpl::GetItemCount() const {
+ id<WebViewNavigationProxy> proxy = delegate_->GetWebViewNavigationProxy();
+ if (proxy) {
+ int count_current_page = proxy.backForwardList.currentItem ? 1 : 0;
+ return static_cast<int>(proxy.backForwardList.backList.count) +
+ count_current_page +
+ static_cast<int>(proxy.backForwardList.forwardList.count);
+ }
+
+ // If WebView has not been created, it's fair to say navigation has 0 item.
+ return 0;
+}
+
+NavigationItem* WKBasedNavigationManagerImpl::GetItemAtIndex(
+ size_t index) const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return nullptr;
+}
+
+int WKBasedNavigationManagerImpl::GetIndexOfItem(
+ const NavigationItem* item) const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return -1;
+}
+
+int WKBasedNavigationManagerImpl::GetPendingItemIndex() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return -1;
+}
+
+int WKBasedNavigationManagerImpl::GetLastCommittedItemIndex() const {
+ id<WebViewNavigationProxy> proxy = delegate_->GetWebViewNavigationProxy();
+ if (proxy.backForwardList.currentItem) {
+ return static_cast<int>(proxy.backForwardList.backList.count);
+ }
+ return -1;
+}
+
+bool WKBasedNavigationManagerImpl::RemoveItemAtIndex(int index) {
+ DLOG(WARNING) << "Not yet implemented.";
+ return true;
+}
+
+bool WKBasedNavigationManagerImpl::CanGoBack() const {
+ return [delegate_->GetWebViewNavigationProxy() canGoBack];
+}
+
+bool WKBasedNavigationManagerImpl::CanGoForward() const {
+ return [delegate_->GetWebViewNavigationProxy() canGoForward];
+}
+
+bool WKBasedNavigationManagerImpl::CanGoToOffset(int offset) const {
+ int index = GetIndexForOffset(offset);
+ return index >= 0 && index < GetItemCount();
+}
+
+void WKBasedNavigationManagerImpl::GoBack() {
+ [delegate_->GetWebViewNavigationProxy() goBack];
+}
+
+void WKBasedNavigationManagerImpl::GoForward() {
+ [delegate_->GetWebViewNavigationProxy() goForward];
+}
+
+void WKBasedNavigationManagerImpl::GoToIndex(int index) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+void WKBasedNavigationManagerImpl::Reload(ReloadType reload_type,
+ bool check_for_reposts) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+NavigationItemList WKBasedNavigationManagerImpl::GetBackwardItems() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return NavigationItemList();
+}
+
+NavigationItemList WKBasedNavigationManagerImpl::GetForwardItems() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return NavigationItemList();
+}
+
+void WKBasedNavigationManagerImpl::CopyStateFromAndPrune(
+ const NavigationManager* source) {
+ DLOG(WARNING) << "Not yet implemented.";
+}
+
+bool WKBasedNavigationManagerImpl::CanPruneAllButLastCommittedItem() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return true;
+}
+
+void WKBasedNavigationManagerImpl::RemoveTransientURLRewriters() {
+ transient_url_rewriters_.reset();
+}
+
+std::unique_ptr<std::vector<BrowserURLRewriter::URLRewriter>>
+WKBasedNavigationManagerImpl::GetTransientURLRewriters() {
+ return std::move(transient_url_rewriters_);
+};
+
+NavigationItemImpl* WKBasedNavigationManagerImpl::GetNavigationItemImplAtIndex(
+ size_t index) const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return nullptr;
+}
+
+int WKBasedNavigationManagerImpl::GetPreviousItemIndex() const {
+ DLOG(WARNING) << "Not yet implemented.";
+ return -1;
+}
+
+} // namespace web

Powered by Google App Engine
This is Rietveld 408576698