Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1652)

Unified Diff: services/kiosk_wm/kiosk_wm_controller.cc

Issue 1536713004: Revert "Delete the ViewManager and WindowManager services." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/kiosk_wm/kiosk_wm_controller.h ('k') | services/kiosk_wm/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/kiosk_wm/kiosk_wm_controller.cc
diff --git a/services/kiosk_wm/kiosk_wm_controller.cc b/services/kiosk_wm/kiosk_wm_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b1434ed9dc6fe6756d831d54a9dbfe7a47dbf022
--- /dev/null
+++ b/services/kiosk_wm/kiosk_wm_controller.cc
@@ -0,0 +1,109 @@
+// Copyright 2014 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 "services/kiosk_wm/kiosk_wm_controller.h"
+
+#include "services/kiosk_wm/merged_service_provider.h"
+#include "services/window_manager/basic_focus_rules.h"
+#include "services/window_manager/window_manager_root.h"
+
+namespace kiosk_wm {
+
+KioskWMController::KioskWMController(window_manager::WindowManagerRoot* wm_root)
+ : window_manager_root_(wm_root),
+ root_(nullptr),
+ content_(nullptr),
+ navigator_host_(this),
+ weak_factory_(this) {
+ exposed_services_impl_.AddService(this);
+}
+
+KioskWMController::~KioskWMController() {}
+
+base::WeakPtr<KioskWMController> KioskWMController::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+}
+
+void KioskWMController::OnEmbed(
+ mojo::View* root,
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services) {
+ // KioskWMController does not support being embedded more than once.
+ CHECK(!root_);
+
+ root_ = root;
+ root_->AddObserver(this);
+
+ // Resize to match the Nexus 5 aspect ratio:
+ window_manager_root_->SetViewportSize(gfx::Size(320, 640));
+
+ content_ = root->view_manager()->CreateView();
+ content_->SetBounds(root_->bounds());
+ root_->AddChild(content_);
+ content_->SetVisible(true);
+
+ window_manager_root_->InitFocus(
+ make_scoped_ptr(new window_manager::BasicFocusRules(root_)));
+ window_manager_root_->accelerator_manager()->Register(
+ ui::Accelerator(ui::VKEY_BROWSER_BACK, 0),
+ ui::AcceleratorManager::kNormalPriority, this);
+}
+
+void KioskWMController::Embed(
+ const mojo::String& url,
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services) {
+ // KioskWMController is embedded in a WindowManagerRoot. WindowManagerRoot
+ // queues pending embed requests while we connect to the ViewManager. This
+ // method should only be called once ::OnEmbed has been called.
+ CHECK(content_);
+
+ merged_service_provider_.reset(
+ new MergedServiceProvider(exposed_services.Pass(), this));
+ content_->Embed(url, services.Pass(),
+ merged_service_provider_->GetServiceProviderPtr().Pass());
+
+ navigator_host_.RecordNavigation(url);
+}
+
+void KioskWMController::Create(
+ mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mojo::NavigatorHost> request) {
+ navigator_host_.Bind(request.Pass());
+}
+
+void KioskWMController::OnViewManagerDisconnected(
+ mojo::ViewManager* view_manager) {
+ root_ = nullptr;
+ delete this;
+}
+
+void KioskWMController::OnViewDestroyed(mojo::View* view) {
+ view->RemoveObserver(this);
+}
+
+void KioskWMController::OnViewBoundsChanged(mojo::View* view,
+ const mojo::Rect& old_bounds,
+ const mojo::Rect& new_bounds) {
+ content_->SetBounds(new_bounds);
+}
+
+// Convenience method:
+void KioskWMController::ReplaceContentWithURL(const mojo::String& url) {
+ Embed(url, nullptr, nullptr);
+}
+
+bool KioskWMController::AcceleratorPressed(const ui::Accelerator& accelerator,
+ mojo::View* target) {
+ if (accelerator.key_code() != ui::VKEY_BROWSER_BACK)
+ return false;
+ navigator_host_.RequestNavigateHistory(-1);
+ return true;
+}
+
+bool KioskWMController::CanHandleAccelerators() const {
+ return true;
+}
+
+} // namespace kiosk_wm
« no previous file with comments | « services/kiosk_wm/kiosk_wm_controller.h ('k') | services/kiosk_wm/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698