blob: ca1aecb38dc386349c8348c224c7d285b320a51d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2015 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.
#include "mandoline/ui/browser/navigator_host_impl.h"
#include "mandoline/ui/browser/browser.h"
namespace mandoline {
NavigatorHostImpl::NavigatorHostImpl(Browser* browser)
: current_index_(-1), browser_(browser) {
}
NavigatorHostImpl::~NavigatorHostImpl() {
}
void NavigatorHostImpl::Bind(
mojo::InterfaceRequest<mojo::NavigatorHost> request) {
bindings_.AddBinding(this, request.Pass());
}
void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) {
RecordNavigation(url);
// TODO(abarth): Do something interesting.
}
void NavigatorHostImpl::RequestNavigate(mojo::Target target,
mojo::URLRequestPtr request) {
// The Browser sets up default services including navigation.
browser_->ReplaceContentWithRequest(request.Pass());
}
void NavigatorHostImpl::RequestNavigateHistory(int32_t delta) {
if (history_.empty())
return;
current_index_ =
std::max(0, std::min(current_index_ + delta,
static_cast<int32_t>(history_.size()) - 1));
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From(history_[current_index_]);
browser_->ReplaceContentWithRequest(request.Pass());
}
void NavigatorHostImpl::RecordNavigation(const std::string& url) {
if (current_index_ >= 0 && history_[current_index_] == url) {
// This is a navigation to the current entry, ignore.
return;
}
history_.erase(history_.begin() + (current_index_ + 1), history_.end());
history_.push_back(url);
++current_index_;
}
} // namespace mandoline
|