Clean up URLFetcher unit tests, part 8.
[chromium-blink-merge.git] / components / kiosk_wm / navigator_host_impl.cc
blob7c81310a6b2b923791cd5010c9c199b44a537237
1 // Copyright 2014 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 "components/kiosk_wm/navigator_host_impl.h"
7 #include "components/kiosk_wm/kiosk_wm.h"
9 namespace kiosk_wm {
11 NavigatorHostImpl::NavigatorHostImpl(KioskWM* window_manager)
12 : current_index_(-1), kiosk_wm_(window_manager) {
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 // kiosk_wm sets up default services including navigation.
31 kiosk_wm_->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 kiosk_wm_->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 kiosk_wm