Fix the browser window app id issue in AppService instance.
When a web app is opened as a tab in a browser window, the AppService
instance id for the browser window should be the the browser app id.
However, the app id for the browser window is marked as the web app id
for the restored browser window.
This CL checks the browser window's property "aura::client::kAppType".
If it is a normal browser window, set the app id as the browser app id.
BUG=1243372
Change-Id: I8ff0e8f9d1bbcb2ff3e72806db76dff5f4e2d613
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3118193
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#915248}
diff --git a/chrome/browser/ui/ash/shelf/app_service/app_service_instance_registry_helper.cc b/chrome/browser/ui/ash/shelf/app_service/app_service_instance_registry_helper.cc
index b787317b..56dc9fe 100644
--- a/chrome/browser/ui/ash/shelf/app_service/app_service_instance_registry_helper.cc
+++ b/chrome/browser/ui/ash/shelf/app_service/app_service_instance_registry_helper.cc
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "ash/constants/app_types.h"
#include "base/containers/contains.h"
#include "base/stl_util.h"
#include "base/time/time.h"
@@ -28,6 +29,7 @@
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
+#include "ui/aura/client/aura_constants.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_client.h"
@@ -238,8 +240,13 @@
aura::Window* window = instance_key.GetEnclosingAppWindow();
const std::string top_app_id =
GetAppId(apps::Instance::InstanceKey::ForWindowBasedApp(window));
- if (!top_app_id.empty())
+ if (!top_app_id.empty()) {
app_id = top_app_id;
+ } else if (static_cast<ash::AppType>(window->GetProperty(
+ aura::client::kAppType)) == ash::AppType::BROWSER) {
+ // For a normal browser window, set the app id as the browser app id.
+ app_id = extension_misc::kChromeAppId;
+ }
OnWindowVisibilityChanged(ash::ShelfID(app_id), window, window->IsVisible());
auto* client = wm::GetActivationClient(window->GetRootWindow());
if (client) {