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"
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_
->ReplaceContentWithRequest(request
.Pass());
34 void NavigatorHostImpl::RequestNavigateHistory(int32_t delta
) {
38 std::max(0, std::min(current_index_
+ delta
,
39 static_cast<int32_t>(history_
.size()) - 1));
40 mojo::URLRequestPtr
request(mojo::URLRequest::New());
41 request
->url
= mojo::String::From(history_
[current_index_
]);
42 browser_
->ReplaceContentWithRequest(request
.Pass());
45 void NavigatorHostImpl::RecordNavigation(const std::string
& url
) {
46 if (current_index_
>= 0 && history_
[current_index_
] == url
) {
47 // This is a navigation to the current entry, ignore.
51 history_
.erase(history_
.begin() + (current_index_
+ 1), history_
.end());
52 history_
.push_back(url
);
56 } // namespace mandoline