OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "services/kiosk_wm/navigator_host_impl.h" | |
6 | |
7 #include "services/kiosk_wm/kiosk_wm_controller.h" | |
8 | |
9 namespace kiosk_wm { | |
10 | |
11 NavigatorHostImpl::NavigatorHostImpl(KioskWMController* window_manager) | |
12 : current_index_(-1), kiosk_wm_(window_manager) { | |
13 } | |
14 | |
15 NavigatorHostImpl::~NavigatorHostImpl() { | |
16 } | |
17 | |
18 void NavigatorHostImpl::Bind( | |
19 mojo::InterfaceRequest<mojo::NavigatorHost> request) { | |
20 bindings_.AddBinding(this, request.Pass()); | |
21 } | |
22 | |
23 void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) { | |
24 RecordNavigation(url); | |
25 // TODO(abarth): Do something interesting. | |
26 } | |
27 | |
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); | |
32 } | |
33 | |
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_]); | |
41 } | |
42 | |
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; | |
47 } | |
48 | |
49 history_.erase(history_.begin() + (current_index_ + 1), history_.end()); | |
50 history_.push_back(url); | |
51 ++current_index_; | |
52 } | |
53 | |
54 } // namespace kiosk_wm | |
OLD | NEW |