Chromium Code Reviews| 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..bb3af0717da1c7a503adea642450bd11755f93c1 | 
| --- /dev/null | 
| +++ b/ios/web/navigation/wk_based_navigation_manager_impl.mm | 
| @@ -0,0 +1,280 @@ | 
| +// 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::WebViewNavigationProxy* GetWebViewOrDie( | 
| 
 
Eugene But (OOO till 7-30)
2017/06/29 01:48:19
Generally it is uncommon in chromium code to DHECK
 
danyao
2017/06/29 16:05:25
Done.
 
 | 
| + web::NavigationManagerDelegate* delegate) { | 
| + DCHECK(delegate); | 
| + web::WebViewNavigationProxy* proxy = delegate->GetWebViewNavigationProxy(); | 
| + DCHECK(proxy); | 
| + return proxy; | 
| +} | 
| + | 
| +} // namespace | 
| + | 
| +namespace web { | 
| + | 
| +WKBasedNavigationManagerImpl::WKBasedNavigationManagerImpl() | 
| + : delegate_(nullptr), browser_state_(nullptr) {} | 
| + | 
| +WKBasedNavigationManagerImpl::~WKBasedNavigationManagerImpl() {} | 
| 
 
Eugene But (OOO till 7-30)
2017/06/29 01:48:19
nit: WKBasedNavigationManagerImpl::~WKBasedNavigat
 
danyao
2017/06/29 16:05:26
Done.
 
 | 
| + | 
| +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 = | 
| + AreURLsInPageNavigation(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; | 
| +} | 
| + | 
| +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 { | 
| + WebViewNavigationProxy* proxy = delegate_->GetWebViewNavigationProxy(); | 
| + if (proxy) { | 
| + NSUInteger count_current_page = proxy->GetCurrentItem() ? 1 : 0; | 
| + return (int)(proxy->GetBackList().count + count_current_page + | 
| 
 
Eugene But (OOO till 7-30)
2017/06/29 01:48:19
Please use C++ casting:
https://google.github.io/
 
danyao
2017/06/29 16:05:26
Done.
 
 | 
| + proxy->GetForwardList().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 { | 
| + WebViewNavigationProxy* proxy = delegate_->GetWebViewNavigationProxy(); | 
| + if (proxy && proxy->GetCurrentItem()) { | 
| + return static_cast<int>(proxy->GetBackList().count); | 
| + } | 
| + return -1; | 
| +} | 
| + | 
| +bool WKBasedNavigationManagerImpl::RemoveItemAtIndex(int index) { | 
| + DLOG(WARNING) << "Not yet implemented."; | 
| + return true; | 
| +} | 
| + | 
| +bool WKBasedNavigationManagerImpl::CanGoBack() const { | 
| + WebViewNavigationProxy* proxy = delegate_->GetWebViewNavigationProxy(); | 
| + return proxy && proxy->CanGoBack(); | 
| +} | 
| + | 
| +bool WKBasedNavigationManagerImpl::CanGoForward() const { | 
| + WebViewNavigationProxy* proxy = delegate_->GetWebViewNavigationProxy(); | 
| + return proxy && proxy->CanGoForward(); | 
| +} | 
| + | 
| +bool WKBasedNavigationManagerImpl::CanGoToOffset(int offset) const { | 
| + int index = GetIndexForOffset(offset); | 
| + return index >= 0 && index < GetItemCount(); | 
| +} | 
| + | 
| +void WKBasedNavigationManagerImpl::GoBack() { | 
| + GetWebViewOrDie(delegate_)->GoBack(); | 
| +} | 
| + | 
| +void WKBasedNavigationManagerImpl::GoForward() { | 
| + GetWebViewOrDie(delegate_)->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 { | 
| + return std::max(-1, GetIndexForOffset(-1)); | 
| 
 
Eugene But (OOO till 7-30)
2017/06/29 01:48:19
"previous" in this context means "the old" not "cu
 
danyao
2017/06/29 16:05:26
Done.
 
 | 
| +} | 
| + | 
| +} // namespace web |