Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 <chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_launcher.h> | |
| 6 | |
| 7 #include "ash/wm/window_util.h" | |
| 8 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | |
| 9 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | |
| 10 #include "ui/aura/env.h" | |
| 11 | |
| 12 namespace chromeos { | |
| 13 | |
| 14 ArcKioskAppLauncher::ArcKioskAppLauncher(content::BrowserContext* context, | |
| 15 const std::string& app_id) | |
| 16 : app_id_(app_id) { | |
| 17 prefs_ = ArcAppListPrefs::Get(context); | |
| 18 prefs_->AddObserver(this); | |
| 19 aura::Env::GetInstance()->AddObserver(this); | |
| 20 // Launching the app by app id in landscape mode. | |
| 21 arc::LaunchApp(context, app_id_); | |
| 22 } | |
| 23 | |
| 24 ArcKioskAppLauncher::~ArcKioskAppLauncher() { | |
| 25 StopObserving(); | |
| 26 } | |
| 27 | |
| 28 void ArcKioskAppLauncher::OnTaskCreated(int32_t task_id, | |
| 29 const std::string& package_name, | |
| 30 const std::string& activity) { | |
| 31 std::unique_ptr<ArcAppListPrefs::AppInfo> app = prefs_->GetApp(app_id_); | |
| 32 if (!app || app->package_name != package_name || app->activity != activity) | |
| 33 return; | |
| 34 task_id_ = task_id; | |
| 35 // The app window may have been created already. | |
| 36 for (aura::Window* window : windows_) { | |
| 37 if (CheckWindow(window)) | |
| 38 break; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 void ArcKioskAppLauncher::OnWindowInitialized(aura::Window* window) { | |
| 43 // The |window|’s task ID is not set yet. We need to observe | |
| 44 // the window until the |kApplicationIdKey| property is set. | |
| 45 window->AddObserver(this); | |
| 46 windows_.insert(window); | |
| 47 } | |
| 48 | |
| 49 void ArcKioskAppLauncher::OnWindowPropertyChanged(aura::Window* window, | |
| 50 const void* key, | |
| 51 intptr_t old) { | |
| 52 // If we do not know yet what task ID to look for, do nothing. | |
| 53 // Existing windows will be revisited the moment the task ID | |
| 54 // becomes known. | |
| 55 if (task_id_ == -1) | |
| 56 return; | |
| 57 | |
| 58 // We are only interested in changes to |kApplicationIdKey|, | |
| 59 // but that constant is not accessible outside shell_surface.cc. | |
| 60 // So we react to all property changes. | |
| 61 CheckWindow(window); | |
| 62 } | |
| 63 | |
| 64 void ArcKioskAppLauncher::OnWindowDestroying(aura::Window* window) { | |
| 65 window->RemoveObserver(this); | |
| 66 windows_.erase(window); | |
| 67 } | |
| 68 | |
| 69 bool ArcKioskAppLauncher::CheckWindow(aura::Window* const window) { | |
| 70 DCHECK_GE(task_id_, 0); | |
| 71 if (ArcAppWindowLauncherController::GetWindowTaskId(window) != task_id_) | |
| 72 return false; | |
| 73 // Stop observing as target window is already found. | |
| 74 StopObserving(); | |
| 75 ash::wm::PinWindow(window, true); | |
|
Nikita (slow)
2016/11/16 15:33:28
nit: true /* trusted */
Sergey Poromov
2016/11/16 15:54:09
Done.
| |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 void ArcKioskAppLauncher::StopObserving() { | |
| 80 aura::Env::GetInstance()->RemoveObserver(this); | |
| 81 for (auto* window : windows_) | |
| 82 window->RemoveObserver(this); | |
| 83 windows_.clear(); | |
| 84 prefs_->RemoveObserver(this); | |
| 85 } | |
| 86 | |
| 87 } // namespace chromeos | |
| OLD | NEW |