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/kiosk_wm_controller.h" | |
6 | |
7 #include "services/kiosk_wm/merged_service_provider.h" | |
8 #include "services/window_manager/basic_focus_rules.h" | |
9 #include "services/window_manager/window_manager_root.h" | |
10 | |
11 namespace kiosk_wm { | |
12 | |
13 KioskWMController::KioskWMController(window_manager::WindowManagerRoot* wm_root) | |
14 : window_manager_root_(wm_root), | |
15 root_(nullptr), | |
16 content_(nullptr), | |
17 navigator_host_(this), | |
18 weak_factory_(this) { | |
19 exposed_services_impl_.AddService(this); | |
20 } | |
21 | |
22 KioskWMController::~KioskWMController() {} | |
23 | |
24 base::WeakPtr<KioskWMController> KioskWMController::GetWeakPtr() { | |
25 return weak_factory_.GetWeakPtr(); | |
26 } | |
27 | |
28 void KioskWMController::OnEmbed( | |
29 mojo::View* root, | |
30 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
31 mojo::ServiceProviderPtr exposed_services) { | |
32 // KioskWMController does not support being embedded more than once. | |
33 CHECK(!root_); | |
34 | |
35 root_ = root; | |
36 root_->AddObserver(this); | |
37 | |
38 // Resize to match the Nexus 5 aspect ratio: | |
39 window_manager_root_->SetViewportSize(gfx::Size(320, 640)); | |
40 | |
41 content_ = root->view_manager()->CreateView(); | |
42 content_->SetBounds(root_->bounds()); | |
43 root_->AddChild(content_); | |
44 content_->SetVisible(true); | |
45 | |
46 window_manager_root_->InitFocus( | |
47 make_scoped_ptr(new window_manager::BasicFocusRules(root_))); | |
48 window_manager_root_->accelerator_manager()->Register( | |
49 ui::Accelerator(ui::VKEY_BROWSER_BACK, 0), | |
50 ui::AcceleratorManager::kNormalPriority, this); | |
51 } | |
52 | |
53 void KioskWMController::Embed( | |
54 const mojo::String& url, | |
55 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
56 mojo::ServiceProviderPtr exposed_services) { | |
57 // KioskWMController is embedded in a WindowManagerRoot. WindowManagerRoot | |
58 // queues pending embed requests while we connect to the ViewManager. This | |
59 // method should only be called once ::OnEmbed has been called. | |
60 CHECK(content_); | |
61 | |
62 merged_service_provider_.reset( | |
63 new MergedServiceProvider(exposed_services.Pass(), this)); | |
64 content_->Embed(url, services.Pass(), | |
65 merged_service_provider_->GetServiceProviderPtr().Pass()); | |
66 | |
67 navigator_host_.RecordNavigation(url); | |
68 } | |
69 | |
70 void KioskWMController::Create( | |
71 mojo::ApplicationConnection* connection, | |
72 mojo::InterfaceRequest<mojo::NavigatorHost> request) { | |
73 navigator_host_.Bind(request.Pass()); | |
74 } | |
75 | |
76 void KioskWMController::OnViewManagerDisconnected( | |
77 mojo::ViewManager* view_manager) { | |
78 root_ = nullptr; | |
79 delete this; | |
80 } | |
81 | |
82 void KioskWMController::OnViewDestroyed(mojo::View* view) { | |
83 view->RemoveObserver(this); | |
84 } | |
85 | |
86 void KioskWMController::OnViewBoundsChanged(mojo::View* view, | |
87 const mojo::Rect& old_bounds, | |
88 const mojo::Rect& new_bounds) { | |
89 content_->SetBounds(new_bounds); | |
90 } | |
91 | |
92 // Convenience method: | |
93 void KioskWMController::ReplaceContentWithURL(const mojo::String& url) { | |
94 Embed(url, nullptr, nullptr); | |
95 } | |
96 | |
97 bool KioskWMController::AcceleratorPressed(const ui::Accelerator& accelerator, | |
98 mojo::View* target) { | |
99 if (accelerator.key_code() != ui::VKEY_BROWSER_BACK) | |
100 return false; | |
101 navigator_host_.RequestNavigateHistory(-1); | |
102 return true; | |
103 } | |
104 | |
105 bool KioskWMController::CanHandleAccelerators() const { | |
106 return true; | |
107 } | |
108 | |
109 } // namespace kiosk_wm | |
OLD | NEW |