Commit 7a226412 authored by Wei Lee's avatar Wei Lee Committed by Chromium LUCI CQ

[CCA]: Cancel intent on Chrome for SWA version

Originally, we cancel intent in window unload listener when closing CCA.
However, the the callback of the cancel() method is triggered, the
connection between CCA and Chrome might already be tore down.

This CL moves the logic to Chrome for SWA version. For platform app
version, it still cancels the intent in background page.

Bug: b/172337144
Test: tast run [DUT] camera.CCAUIIntent.swa

Change-Id: I8362242ad4990aeda947061f756bf35ecf8bf736
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573261
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834602}
parent 264bf5c7
...@@ -44,6 +44,7 @@ static_library("camera_app_ui") { ...@@ -44,6 +44,7 @@ static_library("camera_app_ui") {
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/platform", "//mojo/public/cpp/platform",
"//mojo/public/js:resources_grit", "//mojo/public/js:resources_grit",
"//net",
"//services/network/public/mojom", "//services/network/public/mojom",
"//ui/views", "//ui/views",
"//ui/webui", "//ui/webui",
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include "ash/public/cpp/tablet_mode.h" #include "ash/public/cpp/tablet_mode.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "net/base/url_util.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
namespace chromeos_camera { namespace chromeos_camera {
...@@ -37,6 +39,19 @@ bool HasExternalScreen() { ...@@ -37,6 +39,19 @@ bool HasExternalScreen() {
return false; return false;
} }
base::Optional<uint32_t> ParseIntentIdFromUrl(const GURL& url) {
std::string id_str;
if (!net::GetValueForKeyInQuery(url, "intentId", &id_str)) {
return base::nullopt;
}
uint32_t intent_id;
if (!base::StringToUint(id_str, &intent_id)) {
return base::nullopt;
}
return intent_id;
}
} // namespace } // namespace
CameraAppHelperImpl::CameraAppHelperImpl( CameraAppHelperImpl::CameraAppHelperImpl(
...@@ -46,6 +61,7 @@ CameraAppHelperImpl::CameraAppHelperImpl( ...@@ -46,6 +61,7 @@ CameraAppHelperImpl::CameraAppHelperImpl(
: camera_app_ui_(camera_app_ui), : camera_app_ui_(camera_app_ui),
camera_result_callback_(std::move(camera_result_callback)), camera_result_callback_(std::move(camera_result_callback)),
has_external_screen_(HasExternalScreen()), has_external_screen_(HasExternalScreen()),
pending_intent_id_(base::nullopt),
window_(window) { window_(window) {
DCHECK(window); DCHECK(window);
window->SetProperty(ash::kCanConsumeSystemKeysKey, true); window->SetProperty(ash::kCanConsumeSystemKeysKey, true);
...@@ -58,12 +74,22 @@ CameraAppHelperImpl::~CameraAppHelperImpl() { ...@@ -58,12 +74,22 @@ CameraAppHelperImpl::~CameraAppHelperImpl() {
ash::TabletMode::Get()->RemoveObserver(this); ash::TabletMode::Get()->RemoveObserver(this);
ash::ScreenBacklight::Get()->RemoveObserver(this); ash::ScreenBacklight::Get()->RemoveObserver(this);
display::Screen::GetScreen()->RemoveObserver(this); display::Screen::GetScreen()->RemoveObserver(this);
if (pending_intent_id_.has_value()) {
camera_result_callback_.Run(*pending_intent_id_,
arc::mojom::CameraIntentAction::CANCEL, {},
base::DoNothing());
}
} }
void CameraAppHelperImpl::Bind( void CameraAppHelperImpl::Bind(
mojo::PendingReceiver<mojom::CameraAppHelper> receiver) { mojo::PendingReceiver<mojom::CameraAppHelper> receiver) {
receiver_.reset(); receiver_.reset();
receiver_.Bind(std::move(receiver)); receiver_.Bind(std::move(receiver));
if (camera_app_ui_) {
pending_intent_id_ = ParseIntentIdFromUrl(camera_app_ui_->url());
}
} }
void CameraAppHelperImpl::HandleCameraResult( void CameraAppHelperImpl::HandleCameraResult(
...@@ -71,6 +97,11 @@ void CameraAppHelperImpl::HandleCameraResult( ...@@ -71,6 +97,11 @@ void CameraAppHelperImpl::HandleCameraResult(
arc::mojom::CameraIntentAction action, arc::mojom::CameraIntentAction action,
const std::vector<uint8_t>& data, const std::vector<uint8_t>& data,
HandleCameraResultCallback callback) { HandleCameraResultCallback callback) {
if (pending_intent_id_.has_value() && *pending_intent_id_ == intent_id &&
(action == arc::mojom::CameraIntentAction::FINISH ||
action == arc::mojom::CameraIntentAction::CANCEL)) {
pending_intent_id_ = base::nullopt;
}
camera_result_callback_.Run(intent_id, action, data, std::move(callback)); camera_result_callback_.Run(intent_id, action, data, std::move(callback));
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/public/cpp/screen_backlight.h" #include "ash/public/cpp/screen_backlight.h"
#include "ash/public/cpp/tablet_mode_observer.h" #include "ash/public/cpp/tablet_mode_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "chromeos/components/camera_app_ui/camera_app_helper.mojom.h" #include "chromeos/components/camera_app_ui/camera_app_helper.mojom.h"
#include "chromeos/components/camera_app_ui/camera_app_ui.h" #include "chromeos/components/camera_app_ui/camera_app_ui.h"
#include "chromeos/components/camera_app_ui/camera_app_window_state_controller.h" #include "chromeos/components/camera_app_ui/camera_app_window_state_controller.h"
...@@ -90,6 +91,8 @@ class CameraAppHelperImpl : public ash::TabletModeObserver, ...@@ -90,6 +91,8 @@ class CameraAppHelperImpl : public ash::TabletModeObserver,
bool has_external_screen_; bool has_external_screen_;
base::Optional<uint32_t> pending_intent_id_;
aura::Window* window_; aura::Window* window_;
mojo::Remote<TabletModeMonitor> tablet_mode_monitor_; mojo::Remote<TabletModeMonitor> tablet_mode_monitor_;
......
...@@ -244,6 +244,10 @@ CameraAppWindowManager* CameraAppUI::app_window_manager() { ...@@ -244,6 +244,10 @@ CameraAppWindowManager* CameraAppUI::app_window_manager() {
web_ui()->GetWebContents()->GetBrowserContext()); web_ui()->GetWebContents()->GetBrowserContext());
} }
const GURL& CameraAppUI::url() {
return web_ui()->GetWebContents()->GetURL();
}
WEB_UI_CONTROLLER_TYPE_IMPL(CameraAppUI) WEB_UI_CONTROLLER_TYPE_IMPL(CameraAppUI)
} // namespace chromeos } // namespace chromeos
...@@ -61,6 +61,8 @@ class CameraAppUI : public ui::MojoWebUIController { ...@@ -61,6 +61,8 @@ class CameraAppUI : public ui::MojoWebUIController {
CameraAppWindowManager* app_window_manager(); CameraAppWindowManager* app_window_manager();
const GURL& url();
private: private:
std::unique_ptr<CameraAppUIDelegate> delegate_; std::unique_ptr<CameraAppUIDelegate> delegate_;
......
...@@ -345,12 +345,10 @@ let instance = null; ...@@ -345,12 +345,10 @@ let instance = null;
} }
browserProxy.setupUnloadListener(() => { browserProxy.setupUnloadListener(() => {
const intent = bgOps.getIntent(); // For SWA, we don't cancel the unhandled intent here since there is no
if (intent !== null && !intent.done) { // guarantee that asynchronous calls in unload listener can be executed
// TODO(crbug.com/1125997): Move the task to ServiceWorker once it is // properly. Therefore, we moved the logic for canceling unhandled intent to
// supported on SWA. // Chrome (CameraAppHelper).
intent.cancel();
}
if (appWindow !== null) { if (appWindow !== null) {
appWindow.notifyClosed(); appWindow.notifyClosed();
} }
......
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