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

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc

Issue 2112013002: Allow arc app to lock screen orientation in TouchView/Tablet mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow arc app to lock screen orientation in TouchView/Tablet mode Created 4 years, 5 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
5 5
6 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
6 #include "ash/common/wm/window_state.h" 7 #include "ash/common/wm/window_state.h"
8 #include "ash/common/wm_shell.h"
9 #include "ash/display/screen_orientation_controller_chromeos.h"
7 #include "ash/shelf/shelf_delegate.h" 10 #include "ash/shelf/shelf_delegate.h"
8 #include "ash/shelf/shelf_util.h" 11 #include "ash/shelf/shelf_util.h"
12 #include "ash/shell.h"
9 #include "ash/wm/window_state_aura.h" 13 #include "ash/wm/window_state_aura.h"
10 #include "ash/wm/window_util.h" 14 #include "ash/wm/window_util.h"
11 #include "base/bind.h" 15 #include "base/bind.h"
12 #include "chrome/browser/chromeos/arc/arc_auth_service.h" 16 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
13 #include "chrome/browser/chromeos/arc/arc_support_host.h" 17 #include "chrome/browser/chromeos/arc/arc_support_host.h"
14 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 19 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
16 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h" 20 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h"
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
19 #include "components/arc/arc_bridge_service.h" 23 #include "components/arc/arc_bridge_service.h"
20 #include "components/exo/shell_surface.h" 24 #include "components/exo/shell_surface.h"
21 #include "components/signin/core/account_id/account_id.h" 25 #include "components/signin/core/account_id/account_id.h"
22 #include "components/user_manager/user_manager.h" 26 #include "components/user_manager/user_manager.h"
27 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
23 #include "ui/aura/client/aura_constants.h" 28 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/env.h" 29 #include "ui/aura/env.h"
25 #include "ui/base/base_window.h" 30 #include "ui/base/base_window.h"
26 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
27 32
28 namespace { 33 namespace {
29 34
30 enum class FullScreenMode { 35 enum class FullScreenMode {
31 NOT_DEFINED, // Fullscreen mode was not defined. 36 NOT_DEFINED, // Fullscreen mode was not defined.
32 ACTIVE, // Fullscreen is activated for an app. 37 ACTIVE, // Fullscreen is activated for an app.
33 NON_ACTIVE, // Fullscreen was not activated for an app. 38 NON_ACTIVE, // Fullscreen was not activated for an app.
34 }; 39 };
35 40
41 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom(
42 arc::mojom::OrientationLock orientation_lock) {
43 if (orientation_lock == arc::mojom::OrientationLock::PORTRAIT) {
44 return blink::WebScreenOrientationLockPortrait;
45 } else if (orientation_lock == arc::mojom::OrientationLock::LANDSCAPE) {
46 return blink::WebScreenOrientationLockLandscape;
47 } else {
48 return blink::WebScreenOrientationLockAny;
49 }
50 }
51
36 } // namespace 52 } // namespace
37 53
38 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { 54 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
39 public: 55 public:
40 AppWindow(int task_id, 56 AppWindow(int task_id,
41 const std::string app_id, 57 const std::string app_id,
42 ArcAppWindowLauncherController* owner) 58 ArcAppWindowLauncherController* owner)
43 : task_id_(task_id), app_id_(app_id), owner_(owner) {} 59 : task_id_(task_id), app_id_(app_id), owner_(owner) {}
44 ~AppWindow() {} 60 ~AppWindow() {}
45 61
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 164
149 void FlashFrame(bool flash) override { NOTREACHED(); } 165 void FlashFrame(bool flash) override { NOTREACHED(); }
150 166
151 bool IsAlwaysOnTop() const override { 167 bool IsAlwaysOnTop() const override {
152 NOTREACHED(); 168 NOTREACHED();
153 return false; 169 return false;
154 } 170 }
155 171
156 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); } 172 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); }
157 173
174 arc::mojom::OrientationLock requested_orientation_lock() const {
175 return requested_orientation_lock_;
176 }
177
178 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) {
179 has_requested_orientation_lock_ = true;
180 requested_orientation_lock_ = lock;
181 }
182
183 bool has_requested_orientation_lock() const {
184 return has_requested_orientation_lock_;
185 }
186
158 private: 187 private:
159 arc::mojom::AppInstance* GetAppInstance() { 188 arc::mojom::AppInstance* GetAppInstance() {
160 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); 189 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
161 arc::mojom::AppInstance* app_instance = 190 arc::mojom::AppInstance* app_instance =
162 bridge_service ? bridge_service->app_instance() : nullptr; 191 bridge_service ? bridge_service->app_instance() : nullptr;
163 if (!app_instance) { 192 if (!app_instance) {
164 VLOG(2) << "Arc Bridge is not available."; 193 VLOG(2) << "Arc Bridge is not available.";
165 return nullptr; 194 return nullptr;
166 } 195 }
167 196
168 if (bridge_service->app_version() < 3) { 197 if (bridge_service->app_version() < 3) {
169 VLOG(2) << "Arc Bridge has old version for apps." 198 VLOG(2) << "Arc Bridge has old version for apps."
170 << bridge_service->app_version(); 199 << bridge_service->app_version();
171 return nullptr; 200 return nullptr;
172 } 201 }
173 return app_instance; 202 return app_instance;
174 } 203 }
175 204
176 int task_id_; 205 int task_id_;
177 ash::ShelfID shelf_id_ = 0; 206 ash::ShelfID shelf_id_ = 0;
178 std::string app_id_; 207 std::string app_id_;
179 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; 208 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
180 // Unowned pointers 209 // Unowned pointers
181 ArcAppWindowLauncherController* owner_; 210 ArcAppWindowLauncherController* owner_;
182 ArcAppWindowLauncherItemController* controller_ = nullptr; 211 ArcAppWindowLauncherItemController* controller_ = nullptr;
183 // Unowned pointer, represents host Arc window. 212 // Unowned pointer, represents host Arc window.
184 views::Widget* widget_ = nullptr; 213 views::Widget* widget_ = nullptr;
185 214
215 arc::mojom::OrientationLock requested_orientation_lock_ =
216 arc::mojom::OrientationLock::NONE;
217 bool has_requested_orientation_lock_ = false;
218
186 DISALLOW_COPY_AND_ASSIGN(AppWindow); 219 DISALLOW_COPY_AND_ASSIGN(AppWindow);
187 }; 220 };
188 221
189 ArcAppWindowLauncherController::ArcAppWindowLauncherController( 222 ArcAppWindowLauncherController::ArcAppWindowLauncherController(
190 ChromeLauncherController* owner, 223 ChromeLauncherController* owner,
191 ash::ShelfDelegate* shelf_delegate) 224 ash::ShelfDelegate* shelf_delegate)
192 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { 225 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) {
193 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { 226 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) {
194 observed_profile_ = owner->GetProfile(); 227 observed_profile_ = owner->GetProfile();
195 StartObserving(observed_profile_); 228 StartObserving(observed_profile_);
196 } 229 }
197 } 230 }
198 231
199 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { 232 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() {
200 if (observed_profile_) 233 if (observed_profile_)
201 StopObserving(observed_profile_); 234 StopObserving(observed_profile_);
235 if (observing_shell_)
236 ash::WmShell::Get()->RemoveShellObserver(this);
202 } 237 }
203 238
204 // static 239 // static
205 std::string ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( 240 std::string ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(
206 const std::string& arc_app_id) { 241 const std::string& arc_app_id) {
207 return arc_app_id == arc::kPlayStoreAppId ? ArcSupportHost::kHostAppId 242 return arc_app_id == arc::kPlayStoreAppId ? ArcSupportHost::kHostAppId
208 : arc_app_id; 243 : arc_app_id;
209 } 244 }
210 245
211 // static 246 // static
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 aura::Window* window) { 312 aura::Window* window) {
278 const std::string app_id = exo::ShellSurface::GetApplicationId(window); 313 const std::string app_id = exo::ShellSurface::GetApplicationId(window);
279 if (app_id.empty()) 314 if (app_id.empty())
280 return; 315 return;
281 316
282 int task_id = -1; 317 int task_id = -1;
283 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 318 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
284 return; 319 return;
285 320
286 if (task_id) { 321 if (task_id) {
322 // We need to add the observer after exo started observing shell
323 // because we want to update the orientation after exo send
324 // the layout switch information.
325 if (!observing_shell_) {
326 observing_shell_ = true;
327 ash::WmShell::Get()->AddShellObserver(this);
328 }
329
287 AppWindow* app_window = GetAppWindowForTask(task_id); 330 AppWindow* app_window = GetAppWindowForTask(task_id);
288 if (app_window) { 331 if (app_window) {
289 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); 332 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window));
290 ash::SetShelfIDForWindow(app_window->shelf_id(), window); 333 ash::SetShelfIDForWindow(app_window->shelf_id(), window);
291 if (app_window->controller()) 334 if (app_window->controller())
292 window->SetTitle(app_window->controller()->GetTitle()); 335 window->SetTitle(app_window->controller()->GetTitle());
293 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( 336 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
294 window, 337 window,
295 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); 338 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
339 if (ash::WmShell::Get()
340 ->maximize_mode_controller()
341 ->IsMaximizeModeWindowManagerEnabled()) {
342 SetOrientationLockForAppWindow(app_window);
343 }
296 } 344 }
297 } 345 }
298 } 346 }
299 347
300 void ArcAppWindowLauncherController::OnAppReadyChanged( 348 void ArcAppWindowLauncherController::OnAppReadyChanged(
301 const std::string& app_id, 349 const std::string& app_id,
302 bool ready) { 350 bool ready) {
303 if (!ready) 351 if (!ready)
304 OnAppRemoved(app_id); 352 OnAppRemoved(app_id);
305 } 353 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // TODO(reveman): Figure out how to support fullscreen in interleaved 432 // TODO(reveman): Figure out how to support fullscreen in interleaved
385 // window mode. 433 // window mode.
386 // if (new_active_app_it->second->widget()) { 434 // if (new_active_app_it->second->widget()) {
387 // new_active_app_it->second->widget()->SetFullscreen( 435 // new_active_app_it->second->widget()->SetFullscreen(
388 // new_active_app_it->second->fullscreen_mode() == 436 // new_active_app_it->second->fullscreen_mode() ==
389 // FullScreenMode::ACTIVE); 437 // FullScreenMode::ACTIVE);
390 // } 438 // }
391 } 439 }
392 } 440 }
393 441
442 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested(
443 int32_t task_id,
444 const arc::mojom::OrientationLock orientation_lock) {
445 // Don't save to AppInfo because this is requested in runtime.
446 TaskIdToAppWindow::iterator app_it = task_id_to_app_window_.find(task_id);
447 if (app_it == task_id_to_app_window_.end())
448 return;
449 AppWindow* app_window = app_it->second.get();
450 app_window->set_requested_orientation_lock(orientation_lock);
451
452 if (ash::WmShell::Get()
453 ->maximize_mode_controller()
454 ->IsMaximizeModeWindowManagerEnabled()) {
455 SetOrientationLockForAppWindow(app_window);
456 }
457 }
458
394 AppWindowLauncherItemController* 459 AppWindowLauncherItemController*
395 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { 460 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) {
396 AppWindow* app_window = GetAppWindowForTask(active_task_id_); 461 AppWindow* app_window = GetAppWindowForTask(active_task_id_);
397 if (app_window && 462 if (app_window &&
398 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { 463 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) {
399 return app_window->controller(); 464 return app_window->controller();
400 } 465 }
401 466
402 for (auto& it : task_id_to_app_window_) { 467 for (auto& it : task_id_to_app_window_) {
403 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) 468 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window))
404 return it.second->controller(); 469 return it.second->controller();
405 } 470 }
406 471
407 return nullptr; 472 return nullptr;
408 } 473 }
409 474
410 void ArcAppWindowLauncherController::OnWindowActivated( 475 void ArcAppWindowLauncherController::OnWindowActivated(
411 aura::client::ActivationChangeObserver::ActivationReason reason, 476 aura::client::ActivationChangeObserver::ActivationReason reason,
412 aura::Window* gained_active, 477 aura::Window* gained_active,
413 aura::Window* lost_active) { 478 aura::Window* lost_active) {
414 OnTaskSetActive(active_task_id_); 479 OnTaskSetActive(active_task_id_);
415 } 480 }
416 481
482 void ArcAppWindowLauncherController::OnMaximizeModeStarted() {
483 for (auto& it : task_id_to_app_window_)
484 SetOrientationLockForAppWindow(it.second.get());
485 }
486
487 void ArcAppWindowLauncherController::OnMaximizeModeEnded() {
488 ash::ScreenOrientationController* orientation_controller =
489 ash::Shell::GetInstance()->screen_orientation_controller();
490 // Don't unlock one by one because it'll switch to next rotation.
491 orientation_controller->UnlockAll();
492 }
493
417 void ArcAppWindowLauncherController::StartObserving(Profile* profile) { 494 void ArcAppWindowLauncherController::StartObserving(Profile* profile) {
418 aura::Env* env = aura::Env::GetInstanceDontCreate(); 495 aura::Env* env = aura::Env::GetInstanceDontCreate();
419 if (env) 496 if (env)
420 env->AddObserver(this); 497 env->AddObserver(this);
421 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); 498 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile);
422 DCHECK(prefs); 499 DCHECK(prefs);
423 prefs->AddObserver(this); 500 prefs->AddObserver(this);
424 } 501 }
425 502
426 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { 503 void ArcAppWindowLauncherController::StopObserving(Profile* profile) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 547
471 ArcAppWindowLauncherItemController* controller = it->second; 548 ArcAppWindowLauncherItemController* controller = it->second;
472 controller->RemoveWindow(app_window); 549 controller->RemoveWindow(app_window);
473 if (!controller->window_count()) { 550 if (!controller->window_count()) {
474 ash::ShelfID shelf_id = app_window->shelf_id(); 551 ash::ShelfID shelf_id = app_window->shelf_id();
475 owner()->CloseLauncherItem(shelf_id); 552 owner()->CloseLauncherItem(shelf_id);
476 app_controller_map_.erase(it); 553 app_controller_map_.erase(it);
477 } 554 }
478 app_window->ResetController(); 555 app_window->ResetController();
479 } 556 }
557
558 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
559 AppWindow* app_window) {
560 ash::Shell* shell = ash::Shell::GetInstance();
561 aura::Window* window = app_window->widget()->GetNativeWindow();
562 if (!window)
563 return;
564 arc::mojom::OrientationLock orientation_lock;
565 if (app_window->has_requested_orientation_lock()) {
566 orientation_lock = app_window->requested_orientation_lock();
567 } else {
568 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_);
569 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
570 prefs->GetApp(app_window->app_id());
571 if (!app_info)
572 return;
573 orientation_lock = app_info->orientation_lock;
574 }
575 shell->screen_orientation_controller()->LockOrientationForWindow(
576 window, BlinkOrientationLockFromMojom(orientation_lock));
577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698