Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/core/blimp_navigation_controller_impl.h" | 5 #include "blimp/client/core/blimp_navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "blimp/client/core/blimp_navigation_controller_delegate.h" | 11 #include "blimp/client/core/blimp_navigation_controller_delegate.h" |
| 12 | 12 |
| 13 namespace blimp { | 13 namespace blimp { |
| 14 namespace client { | 14 namespace client { |
| 15 | 15 |
| 16 const int kDummyTabId = 0; | |
|
David Trainor- moved to gerrit
2016/06/29 17:27:15
Can we add a comment about this? We'll need to so
shaktisahu
2016/07/19 21:45:29
Done.
| |
| 17 | |
| 16 BlimpNavigationControllerImpl::BlimpNavigationControllerImpl( | 18 BlimpNavigationControllerImpl::BlimpNavigationControllerImpl( |
| 17 BlimpNavigationControllerDelegate* delegate) | 19 BlimpNavigationControllerDelegate* delegate) |
| 18 : delegate_(delegate), weak_ptr_factory_(this) {} | 20 : // TODO(shaktisahu): Hook up to the real one from BlimpClientSession |
| 21 // later. | |
| 22 navigation_feature_(new NavigationFeature), | |
| 23 delegate_(delegate) { | |
| 24 navigation_feature_->SetDelegate(kDummyTabId, this); | |
| 25 } | |
| 19 | 26 |
| 20 BlimpNavigationControllerImpl::~BlimpNavigationControllerImpl() = default; | 27 BlimpNavigationControllerImpl::~BlimpNavigationControllerImpl() = default; |
| 21 | 28 |
| 29 void BlimpNavigationControllerImpl::SetNavigationFeatureForTesting( | |
| 30 NavigationFeature* feature) { | |
| 31 navigation_feature_ = feature; | |
| 32 navigation_feature_->SetDelegate(kDummyTabId, this); | |
| 33 } | |
| 34 | |
| 22 void BlimpNavigationControllerImpl::LoadURL(const GURL& url) { | 35 void BlimpNavigationControllerImpl::LoadURL(const GURL& url) { |
| 23 current_url_ = url; | 36 current_url_ = url; |
| 24 // Temporary trick to ensure that the delegate is not invoked before this | 37 navigation_feature_->NavigateToUrlText(kDummyTabId, current_url_.spec()); |
| 25 // method has finished executing. This enables tests to test the | 38 } |
| 26 // asynchronous nature of the API. | 39 |
| 27 // TODO(shaktisahu): Remove this after integration with NavigationFeature. | 40 void BlimpNavigationControllerImpl::Reload() { |
| 28 base::ThreadTaskRunnerHandle::Get()->PostTask( | 41 navigation_feature_->Reload(kDummyTabId); |
| 29 FROM_HERE, | 42 } |
| 30 base::Bind(&BlimpNavigationControllerImpl::NotifyDelegateURLLoaded, | 43 |
| 31 weak_ptr_factory_.GetWeakPtr(), url)); | 44 bool BlimpNavigationControllerImpl::CanGoBack() const { |
| 45 // TODO(shaktisahu): Implement the client-side logic. | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 bool BlimpNavigationControllerImpl::CanGoForward() const { | |
| 50 // TODO(shaktisahu): Implement the client-side logic. | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 void BlimpNavigationControllerImpl::GoBack() { | |
| 55 navigation_feature_->GoBack(kDummyTabId); | |
| 56 } | |
| 57 | |
| 58 void BlimpNavigationControllerImpl::GoForward() { | |
| 59 navigation_feature_->GoForward(kDummyTabId); | |
| 32 } | 60 } |
| 33 | 61 |
| 34 const GURL& BlimpNavigationControllerImpl::GetURL() { | 62 const GURL& BlimpNavigationControllerImpl::GetURL() { |
| 35 return current_url_; | 63 return current_url_; |
| 36 } | 64 } |
| 37 | 65 |
| 38 void BlimpNavigationControllerImpl::NotifyDelegateURLLoaded(const GURL& url) { | 66 void BlimpNavigationControllerImpl::OnUrlChanged(int tab_id, const GURL& url) { |
| 39 delegate_->NotifyURLLoaded(url); | 67 delegate_->OnUrlChanged(url); |
| 68 } | |
| 69 | |
| 70 void BlimpNavigationControllerImpl::OnFaviconChanged(int tab_id, | |
| 71 const SkBitmap& favicon) { | |
| 72 delegate_->OnFaviconChanged(favicon); | |
| 73 } | |
| 74 | |
| 75 void BlimpNavigationControllerImpl::OnTitleChanged(int tab_id, | |
| 76 const std::string& title) { | |
| 77 delegate_->OnTitleChanged(title); | |
| 78 } | |
| 79 | |
| 80 void BlimpNavigationControllerImpl::OnLoadingChanged(int tab_id, bool loading) { | |
| 81 delegate_->OnLoadingChanged(loading); | |
| 82 } | |
| 83 | |
| 84 void BlimpNavigationControllerImpl::OnPageLoadStatusUpdate(int tab_id, | |
| 85 bool completed) { | |
| 86 delegate_->OnPageLoadStatusUpdate(completed); | |
| 40 } | 87 } |
| 41 | 88 |
| 42 } // namespace client | 89 } // namespace client |
| 43 } // namespace blimp | 90 } // namespace blimp |
| OLD | NEW |