Commit 3024d7c9 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Chromium LUCI CQ

Revert "Set window properties when creating widget, not after."

This reverts commit f93b22c3.

Reason for revert: It causes crashes. Please see crbug.com/1160507
Bug: 1160507

Original change's description:
> Set window properties when creating widget, not after.
>
> Optimize ArcOverlayManager so that it observe arc windows only.
>
> Bug: None
>
> Change-Id: Ic6c5f43fea647369eac092c1c4c4d68aed7d8ce9
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2578377
> Commit-Queue: Mitsuru Oshima (slow: gardener) <oshima@chromium.org>
> Reviewed-by: Yuichiro Hanada <yhanada@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#838281}

TBR=oshima@chromium.org,lpique@chromium.org,yhanada@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: None
Change-Id: I11338ea9ab9fd72aa3d0b0a14b0b47a51edb1425
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2600417Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838772}
parent 3297d839
...@@ -43,7 +43,6 @@ static_library("external_arc") { ...@@ -43,7 +43,6 @@ static_library("external_arc") {
"//base", "//base",
"//chromeos/constants", "//chromeos/constants",
"//components/account_id", "//components/account_id",
"//components/arc:arc_base_utils",
"//components/arc:arc_metrics_constants", "//components/arc:arc_metrics_constants",
"//components/arc:connection_holder", "//components/arc:connection_holder",
"//components/arc/mojom:notifications", "//components/arc/mojom:notifications",
......
include_rules = [
"+components/arc/arc_util.h",
]
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "ash/public/cpp/external_arc/overlay/arc_overlay_controller_impl.h" #include "ash/public/cpp/external_arc/overlay/arc_overlay_controller_impl.h"
#include "base/logging.h" #include "base/logging.h"
#include "components/arc/arc_util.h"
#include "components/exo/shell_surface_base.h" #include "components/exo/shell_surface_base.h"
#include "components/exo/shell_surface_util.h" #include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
...@@ -67,38 +66,78 @@ void ArcOverlayManager::DeregisterHostWindow(const std::string& overlay_token) { ...@@ -67,38 +66,78 @@ void ArcOverlayManager::DeregisterHostWindow(const std::string& overlay_token) {
} }
void ArcOverlayManager::OnWindowInitialized(aura::Window* window) { void ArcOverlayManager::OnWindowInitialized(aura::Window* window) {
// Ignore windows that are container (no delegate), or non arc window. // Ignore windows that do not have a delegate set.
if (!window->delegate() || !arc::IsArcAppWindow(window)) if (!window->delegate())
return; return;
window_observations_.AddObservation(window); // We only ever observe the most recent window being created
unknown_window_observation_.Reset();
unknown_window_observation_.Observe(window);
} }
void ArcOverlayManager::OnWindowDestroying(aura::Window* window) { void ArcOverlayManager::OnWindowDestroying(aura::Window* window) {
window_observations_.RemoveObservation(window); if (unknown_window_observation_.IsObservingSource(window))
unknown_window_observation_.Reset();
if (overlay_window_observations_.IsObservingSource(window))
overlay_window_observations_.RemoveObservation(window);
}
void ArcOverlayManager::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
// We only care about property changes on the single unknown window.
// (We also are observing other windows via overlay_window_observations_)
if (!unknown_window_observation_.IsObservingSource(window))
return;
// exo::ShellSurfaceBase sets this key soon after creating the window
if (!exo::IsShellMainSurfaceKey(key))
return;
// It may still be of interest as an overlay, but we don't need to observe it
// as an unknown window.
unknown_window_observation_.Reset();
// If this isn't actually a variant of a exo::ShellSurfaceBase, it is not an
// overlay candidate.
auto* shell_surface_base = exo::GetShellSurfaceBaseForWindow(window);
if (!shell_surface_base)
return;
auto* shell_root_surface = shell_surface_base->root_surface();
DCHECK(shell_root_surface);
// If the client_surface_id doesn't have a particular prefix, it is not an
// overlay candidate.
std::string client_surface_id = shell_root_surface->GetClientSurfaceId();
if (!base::StartsWith(client_surface_id, kBillingIdPrefix))
return;
// This window seems to be an overlay candidate. Continue observing it as one
// until it is ready. exo::ShellSurfaceBase is still setting it up.
overlay_window_observations_.AddObservation(window);
} }
void ArcOverlayManager::OnWindowVisibilityChanged(aura::Window* window, void ArcOverlayManager::OnWindowVisibilityChanged(aura::Window* window,
bool visible) { bool visible) {
// For this event, we only care about windows that are potential overlays.
if (!overlay_window_observations_.IsObservingSource(window))
return;
// We only care about windows that are now visible. // We only care about windows that are now visible.
if (!visible) if (!visible)
return; return;
// We do not need to keep observing the window. // We do not need to keep observing the window.
DCHECK(window_observations_.IsObservingSource(window)); overlay_window_observations_.RemoveObservation(window);
window_observations_.RemoveObservation(window);
auto* shell_surface_base = exo::GetShellSurfaceBaseForWindow(window); auto* shell_surface_base = exo::GetShellSurfaceBaseForWindow(window);
DCHECK(shell_surface_base); DCHECK(shell_surface_base);
auto* shell_root_surface = shell_surface_base->root_surface(); auto* shell_root_surface = shell_surface_base->root_surface();
DCHECK(shell_root_surface); DCHECK(shell_root_surface);
// If the client_surface_id doesn't have a particular prefix, it is not an
// overlay candidate.
std::string client_surface_id = shell_root_surface->GetClientSurfaceId(); std::string client_surface_id = shell_root_surface->GetClientSurfaceId();
if (!base::StartsWith(client_surface_id, kBillingIdPrefix))
return;
std::string overlay_token = std::string overlay_token =
client_surface_id.substr(strlen(kBillingIdPrefix)); client_surface_id.substr(strlen(kBillingIdPrefix));
......
...@@ -63,6 +63,9 @@ class ASH_PUBLIC_EXPORT ArcOverlayManager : public aura::EnvObserver, ...@@ -63,6 +63,9 @@ class ASH_PUBLIC_EXPORT ArcOverlayManager : public aura::EnvObserver,
// aura::WindowObserver: // aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override; void OnWindowDestroying(aura::Window* window) override;
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override;
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
private: private:
...@@ -75,10 +78,16 @@ class ASH_PUBLIC_EXPORT ArcOverlayManager : public aura::EnvObserver, ...@@ -75,10 +78,16 @@ class ASH_PUBLIC_EXPORT ArcOverlayManager : public aura::EnvObserver,
base::ScopedObservation<aura::Env, aura::EnvObserver> env_observer_{this}; base::ScopedObservation<aura::Env, aura::EnvObserver> env_observer_{this};
// This tracks newly created arc windows until they're being shown, or // This tracks a single newly created window until we get a confirmation that
// destoryed. // it is an exo::ShellSurfaceBase with the right settings to be an overlay
// (which should happen immediately after creation), or until another new
// window is created.
base::ScopedObservation<aura::Window, aura::WindowObserver>
unknown_window_observation_{this};
// This tracks all the overlay candidates until they are actually ready
base::ScopedMultiSourceObservation<aura::Window, aura::WindowObserver> base::ScopedMultiSourceObservation<aura::Window, aura::WindowObserver>
window_observations_{this}; overlay_window_observations_{this};
}; };
} // namespace ash } // namespace ash
......
...@@ -917,11 +917,9 @@ void ShellSurfaceBase::CreateShellSurfaceWidget( ...@@ -917,11 +917,9 @@ void ShellSurfaceBase::CreateShellSurfaceWidget(
startup_id_ ? *startup_id_ : std::string(), startup_id_ ? *startup_id_ : std::string(),
/*for_creation=*/true, params.init_properties_container); /*for_creation=*/true, params.init_properties_container);
SetShellApplicationId(&params.init_properties_container, application_id_);
SetShellMainSurface(&params.init_properties_container, root_surface());
SetShellStartupId(&params.init_properties_container, startup_id_);
bool activatable = activatable_; bool activatable = activatable_;
if (container_ == ash::kShellWindowId_SystemModalContainer)
activatable &= HasHitTestRegion();
// ShellSurfaces in system modal container are only activatable if input // ShellSurfaces in system modal container are only activatable if input
// region is non-empty. See OnCommitSurface() for more details. // region is non-empty. See OnCommitSurface() for more details.
...@@ -944,6 +942,9 @@ void ShellSurfaceBase::CreateShellSurfaceWidget( ...@@ -944,6 +942,9 @@ void ShellSurfaceBase::CreateShellSurfaceWidget(
window->SetEventTargetingPolicy( window->SetEventTargetingPolicy(
aura::EventTargetingPolicy::kTargetAndDescendants); aura::EventTargetingPolicy::kTargetAndDescendants);
InstallCustomWindowTargeter(); InstallCustomWindowTargeter();
SetShellApplicationId(window, application_id_);
SetShellStartupId(window, startup_id_);
SetShellMainSurface(window, root_surface());
// Start tracking changes to window bounds and window state. // Start tracking changes to window bounds and window state.
window->AddObserver(this); window->AddObserver(this);
......
...@@ -78,28 +78,28 @@ aura::WindowTargeter* FindTargeter(ui::EventTarget* target) { ...@@ -78,28 +78,28 @@ aura::WindowTargeter* FindTargeter(ui::EventTarget* target) {
} // namespace } // namespace
void SetShellApplicationId(ui::PropertyHandler* property_handler, void SetShellApplicationId(aura::Window* window,
const base::Optional<std::string>& id) { const base::Optional<std::string>& id) {
TRACE_EVENT1("exo", "SetApplicationId", "application_id", id ? *id : "null"); TRACE_EVENT1("exo", "SetApplicationId", "application_id", id ? *id : "null");
if (id) if (id)
property_handler->SetProperty(kApplicationIdKey, *id); window->SetProperty(kApplicationIdKey, *id);
else else
property_handler->ClearProperty(kApplicationIdKey); window->ClearProperty(kApplicationIdKey);
} }
const std::string* GetShellApplicationId(const aura::Window* property_handler) { const std::string* GetShellApplicationId(const aura::Window* window) {
return property_handler->GetProperty(kApplicationIdKey); return window->GetProperty(kApplicationIdKey);
} }
void SetShellStartupId(ui::PropertyHandler* property_handler, void SetShellStartupId(aura::Window* window,
const base::Optional<std::string>& id) { const base::Optional<std::string>& id) {
TRACE_EVENT1("exo", "SetStartupId", "startup_id", id ? *id : "null"); TRACE_EVENT1("exo", "SetStartupId", "startup_id", id ? *id : "null");
if (id) if (id)
property_handler->SetProperty(kStartupIdKey, *id); window->SetProperty(kStartupIdKey, *id);
else else
property_handler->ClearProperty(kStartupIdKey); window->ClearProperty(kStartupIdKey);
} }
const std::string* GetShellStartupId(aura::Window* window) { const std::string* GetShellStartupId(aura::Window* window) {
...@@ -140,9 +140,8 @@ bool IsShellMainSurfaceKey(const void* key) { ...@@ -140,9 +140,8 @@ bool IsShellMainSurfaceKey(const void* key) {
return kMainSurfaceKey == key; return kMainSurfaceKey == key;
} }
void SetShellMainSurface(ui::PropertyHandler* property_handler, void SetShellMainSurface(aura::Window* window, Surface* surface) {
Surface* surface) { window->SetProperty(kMainSurfaceKey, surface);
property_handler->SetProperty(kMainSurfaceKey, surface);
} }
Surface* GetShellMainSurface(const aura::Window* window) { Surface* GetShellMainSurface(const aura::Window* window) {
......
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
#include "base/optional.h" #include "base/optional.h"
namespace ui {
class PropertyHandler;
}
namespace aura { namespace aura {
class Window; class Window;
} }
...@@ -33,15 +29,21 @@ class Permission; ...@@ -33,15 +29,21 @@ class Permission;
class Surface; class Surface;
class ShellSurfaceBase; class ShellSurfaceBase;
// Sets the application ID to the property_handler. The application ID // Sets the application ID for the window. The application ID identifies the
// identifies the general class of applications to which the window belongs. // general class of applications to which the window belongs.
void SetShellApplicationId(ui::PropertyHandler* property_handler, void SetShellApplicationId(aura::Window* window,
const base::Optional<std::string>& id); const base::Optional<std::string>& id);
const std::string* GetShellApplicationId(const aura::Window* window); const std::string* GetShellApplicationId(const aura::Window* window);
// Sets the startup ID to the property handler. The startup ID identifies the // Sets ARC app type for the provided |window|.
void SetArcAppType(aura::Window* window);
// Sets Lacros app type for the provided |window|.
void SetLacrosAppType(aura::Window* window);
// Sets the startup ID for the window. The startup ID identifies the
// application using startup notification protocol. // application using startup notification protocol.
void SetShellStartupId(ui::PropertyHandler* property_handler, void SetShellStartupId(aura::Window* window,
const base::Optional<std::string>& id); const base::Optional<std::string>& id);
const std::string* GetShellStartupId(aura::Window* window); const std::string* GetShellStartupId(aura::Window* window);
...@@ -60,9 +62,8 @@ const base::Optional<int32_t> GetShellClientAccessibilityId( ...@@ -60,9 +62,8 @@ const base::Optional<int32_t> GetShellClientAccessibilityId(
// Returns true if the given key is the shell main surface key // Returns true if the given key is the shell main surface key
bool IsShellMainSurfaceKey(const void* key); bool IsShellMainSurfaceKey(const void* key);
// Sets the main surface to the property handler. // Sets the main surface for the window.
void SetShellMainSurface(ui::PropertyHandler* property_handler, void SetShellMainSurface(aura::Window* window, Surface* surface);
Surface* surface);
// Returns the main Surface instance or nullptr if it is not set. // Returns the main Surface instance or nullptr if it is not set.
// |window| must not be nullptr. // |window| must not be nullptr.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment