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 // TODO(shaktisahu): NavigationFeautre currently needs a tab_id. Remove this | |
| 17 // later when it is fully integrated with BlimpClientSession. | |
|
David Trainor- moved to gerrit
2016/07/25 15:57:31
BlimpClientSession -> BlimpClientContext
shaktisahu
2016/07/26 01:25:27
Done.
| |
| 18 const int kDummyTabId = 0; | |
|
David Trainor- moved to gerrit
2016/07/25 15:57:31
namespace {} around this?
shaktisahu
2016/07/26 01:25:27
Done.
| |
| 19 | |
| 16 BlimpNavigationControllerImpl::BlimpNavigationControllerImpl( | 20 BlimpNavigationControllerImpl::BlimpNavigationControllerImpl( |
| 17 BlimpNavigationControllerDelegate* delegate) | 21 BlimpNavigationControllerDelegate* delegate) |
| 18 : delegate_(delegate), weak_ptr_factory_(this) {} | 22 : // TODO(shaktisahu): Get the feature from BlimpClientSession. |
|
David Trainor- moved to gerrit
2016/07/25 15:57:31
BlimpClientSession -> BlimpClientContext?
shaktisahu
2016/07/26 01:25:27
Done.
| |
| 23 navigation_feature_(new NavigationFeature), | |
| 24 delegate_(delegate) { | |
| 25 navigation_feature_->SetDelegate(kDummyTabId, this); | |
| 26 } | |
| 19 | 27 |
| 20 BlimpNavigationControllerImpl::~BlimpNavigationControllerImpl() = default; | 28 BlimpNavigationControllerImpl::~BlimpNavigationControllerImpl() = default; |
| 21 | 29 |
| 30 void BlimpNavigationControllerImpl::SetNavigationFeatureForTesting( | |
| 31 NavigationFeature* feature) { | |
| 32 navigation_feature_ = feature; | |
| 33 navigation_feature_->SetDelegate(kDummyTabId, this); | |
| 34 } | |
| 35 | |
| 22 void BlimpNavigationControllerImpl::LoadURL(const GURL& url) { | 36 void BlimpNavigationControllerImpl::LoadURL(const GURL& url) { |
| 23 current_url_ = url; | 37 current_url_ = url; |
| 24 // Temporary trick to ensure that the delegate is not invoked before this | 38 navigation_feature_->NavigateToUrlText(kDummyTabId, current_url_.spec()); |
| 25 // method has finished executing. This enables tests to test the | 39 } |
| 26 // asynchronous nature of the API. | 40 |
| 27 // TODO(shaktisahu): Remove this after integration with NavigationFeature. | 41 void BlimpNavigationControllerImpl::Reload() { |
| 28 base::ThreadTaskRunnerHandle::Get()->PostTask( | 42 navigation_feature_->Reload(kDummyTabId); |
| 29 FROM_HERE, | 43 } |
| 30 base::Bind(&BlimpNavigationControllerImpl::NotifyDelegateURLLoaded, | 44 |
| 31 weak_ptr_factory_.GetWeakPtr(), url)); | 45 bool BlimpNavigationControllerImpl::CanGoBack() const { |
| 46 // TODO(shaktisahu): Implement the client-side logic. | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 bool BlimpNavigationControllerImpl::CanGoForward() const { | |
| 51 // TODO(shaktisahu): Implement the client-side logic. | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 void BlimpNavigationControllerImpl::GoBack() { | |
| 56 navigation_feature_->GoBack(kDummyTabId); | |
| 57 } | |
| 58 | |
| 59 void BlimpNavigationControllerImpl::GoForward() { | |
| 60 navigation_feature_->GoForward(kDummyTabId); | |
| 32 } | 61 } |
| 33 | 62 |
| 34 const GURL& BlimpNavigationControllerImpl::GetURL() { | 63 const GURL& BlimpNavigationControllerImpl::GetURL() { |
| 35 return current_url_; | 64 return current_url_; |
| 36 } | 65 } |
| 37 | 66 |
| 38 void BlimpNavigationControllerImpl::NotifyDelegateURLLoaded(const GURL& url) { | 67 void BlimpNavigationControllerImpl::OnUrlChanged(int tab_id, const GURL& url) { |
| 39 delegate_->NotifyURLLoaded(url); | 68 delegate_->OnNavigationStateChanged(); |
| 69 } | |
| 70 | |
| 71 void BlimpNavigationControllerImpl::OnFaviconChanged(int tab_id, | |
| 72 const SkBitmap& favicon) { | |
| 73 delegate_->OnNavigationStateChanged(); | |
| 74 } | |
| 75 | |
| 76 void BlimpNavigationControllerImpl::OnTitleChanged(int tab_id, | |
| 77 const std::string& title) { | |
| 78 delegate_->OnNavigationStateChanged(); | |
| 79 } | |
| 80 | |
| 81 void BlimpNavigationControllerImpl::OnLoadingChanged(int tab_id, bool loading) { | |
| 82 delegate_->OnNavigationStateChanged(); | |
| 83 } | |
| 84 | |
| 85 void BlimpNavigationControllerImpl::OnPageLoadStatusUpdate(int tab_id, | |
| 86 bool completed) { | |
| 87 delegate_->OnNavigationStateChanged(); | |
| 40 } | 88 } |
| 41 | 89 |
| 42 } // namespace client | 90 } // namespace client |
| 43 } // namespace blimp | 91 } // namespace blimp |
| OLD | NEW |