Disable tab_switching.tough_energy_cases on Linux
[chromium-blink-merge.git] / mandoline / ui / browser / navigator_host_impl.cc
blob07f406f7b9c8022b95aaf9d5dc2c9d883c77ec8d
1 // Copyright 2015 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.
5 #include "mandoline/ui/browser/navigator_host_impl.h"
7 #include "mandoline/ui/browser/browser.h"
9 namespace mandoline {
11 NavigatorHostImpl::NavigatorHostImpl(Browser* browser)
12 : current_index_(-1), browser_(browser) {
15 NavigatorHostImpl::~NavigatorHostImpl() {
18 void NavigatorHostImpl::Bind(
19 mojo::InterfaceRequest<mojo::NavigatorHost> request) {
20 bindings_.AddBinding(this, request.Pass());
23 void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) {
24 RecordNavigation(url);
25 // TODO(abarth): Do something interesting.
28 void NavigatorHostImpl::RequestNavigate(mojo::Target target,
29 mojo::URLRequestPtr request) {
30 // The Browser sets up default services including navigation.
31 browser_->ReplaceContentWithURL(request->url);
34 void NavigatorHostImpl::RequestNavigateHistory(int32_t delta) {
35 if (history_.empty())
36 return;
37 current_index_ =
38 std::max(0, std::min(current_index_ + delta,
39 static_cast<int32_t>(history_.size()) - 1));
40 browser_->ReplaceContentWithURL(history_[current_index_]);
43 void NavigatorHostImpl::RecordNavigation(const std::string& url) {
44 if (current_index_ >= 0 && history_[current_index_] == url) {
45 // This is a navigation to the current entry, ignore.
46 return;
49 history_.erase(history_.begin() + (current_index_ + 1), history_.end());
50 history_.push_back(url);
51 ++current_index_;
54 } // namespace mandoline