Commit 10491538 authored by Prameet Shah's avatar Prameet Shah Committed by Commit Bot

arc: Add new ArcSharesheetBridge

The ArcSharesheetBridge will receive share requests from Android
and handle them with Chrome's sharesheet in a Chrome Custom Tab.

This change sets up the skeleton to accept connections from
Android.

BUG=b:172963488
TEST=Deployed chrome, and verified share intents is received from
     Android using Android's APIDemos apk.

Change-Id: Ib14e414f65c3bb7b675a0d1a0d846fc3a17b0769
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531394
Auto-Submit: Prameet Shah <phshah@chromium.org>
Commit-Queue: Josh Horwich <jhorwich@chromium.org>
Reviewed-by: default avatarJosh Horwich <jhorwich@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarMaggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826374}
parent 5d3983ec
......@@ -757,6 +757,8 @@ source_set("chromeos") {
"arc/session/arc_session_manager.cc",
"arc/session/arc_session_manager.h",
"arc/session/arc_session_manager_observer.h",
"arc/sharesheet/arc_sharesheet_bridge.cc",
"arc/sharesheet/arc_sharesheet_bridge.h",
"arc/tracing/arc_app_performance_tracing.cc",
"arc/tracing/arc_app_performance_tracing.h",
"arc/tracing/arc_app_performance_tracing_custom_session.cc",
......
......@@ -41,6 +41,7 @@
#include "chrome/browser/chromeos/arc/screen_capture/arc_screen_capture_bridge.h"
#include "chrome/browser/chromeos/arc/session/arc_play_store_enabled_preference_handler.h"
#include "chrome/browser/chromeos/arc/session/arc_session_manager.h"
#include "chrome/browser/chromeos/arc/sharesheet/arc_sharesheet_bridge.h"
#include "chrome/browser/chromeos/arc/tracing/arc_app_performance_tracing.h"
#include "chrome/browser/chromeos/arc/tracing/arc_tracing_bridge.h"
#include "chrome/browser/chromeos/arc/tts/arc_tts_service.h"
......@@ -223,6 +224,7 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
ArcScreenCaptureBridge::GetForBrowserContext(profile);
ArcSensorBridge::GetForBrowserContext(profile);
ArcSettingsService::GetForBrowserContext(profile);
ArcSharesheetBridge::GetForBrowserContext(profile);
ArcSmartCardManagerBridge::GetForBrowserContext(profile);
ArcTimerBridge::GetForBrowserContext(profile);
ArcTracingBridge::GetForBrowserContext(profile);
......
melzhang@chromium.org
mxcai@chromium.org
phshah@chromium.org
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/arc/sharesheet/arc_sharesheet_bridge.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/session/arc_bridge_service.h"
#include "content/public/browser/browser_thread.h"
namespace arc {
namespace {
// Singleton factory for ArcSharesheetBridgeFactory.
class ArcSharesheetBridgeFactory
: public internal::ArcBrowserContextKeyedServiceFactoryBase<
ArcSharesheetBridge,
ArcSharesheetBridgeFactory> {
public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
static constexpr const char* kName = "ArcSharesheetBridgeFactory";
static ArcSharesheetBridgeFactory* GetInstance() {
return base::Singleton<ArcSharesheetBridgeFactory>::get();
}
private:
friend base::DefaultSingletonTraits<ArcSharesheetBridgeFactory>;
ArcSharesheetBridgeFactory() = default;
~ArcSharesheetBridgeFactory() override = default;
};
} // namespace
// static
ArcSharesheetBridge* ArcSharesheetBridge::GetForBrowserContext(
content::BrowserContext* context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return ArcSharesheetBridgeFactory::GetForBrowserContext(context);
}
ArcSharesheetBridge::ArcSharesheetBridge(content::BrowserContext* context,
ArcBridgeService* bridge_service)
: arc_bridge_service_(bridge_service),
profile_(Profile::FromBrowserContext(context)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc_bridge_service_->sharesheet()->SetHost(this);
VLOG(1) << "ArcSharesheetBridge created";
}
ArcSharesheetBridge::~ArcSharesheetBridge() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc_bridge_service_->sharesheet()->SetHost(nullptr);
}
} // namespace arc
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_ARC_SHARESHEET_ARC_SHARESHEET_BRIDGE_H_
#define CHROME_BROWSER_CHROMEOS_ARC_SHARESHEET_ARC_SHARESHEET_BRIDGE_H_
#include "base/memory/weak_ptr.h"
#include "components/arc/mojom/sharesheet.mojom.h"
#include "components/keyed_service/core/keyed_service.h"
class Profile;
namespace content {
class BrowserContext;
} // namespace content
namespace arc {
class ArcBridgeService;
// This class handles sharesheet related IPC from ARC++ and allows sharesheet
// to be displayed and managed in Chrome preview instead of the Android
// sharesheet activity.
class ArcSharesheetBridge : public KeyedService, public mojom::SharesheetHost {
public:
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcSharesheetBridge* GetForBrowserContext(
content::BrowserContext* context);
ArcSharesheetBridge(content::BrowserContext* context,
ArcBridgeService* bridge_service);
ArcSharesheetBridge(const ArcSharesheetBridge&) = delete;
ArcSharesheetBridge& operator=(const ArcSharesheetBridge&) = delete;
~ArcSharesheetBridge() override;
// mojom::SharesheetHost overrides:
// TODO(phshah): Add overrides.
private:
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
Profile* const profile_;
base::WeakPtrFactory<ArcSharesheetBridge> weak_ptr_factory_{this};
};
} // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_SHARESHEET_ARC_SHARESHEET_BRIDGE_H_
......@@ -55,6 +55,7 @@ if (is_chromeos) {
"screen_capture.mojom",
"sensor.mojom",
"sensor_service.mojom",
"sharesheet.mojom",
"storage_manager.mojom",
"timer.mojom",
"tracing.mojom",
......
......@@ -45,6 +45,7 @@ import "components/arc/mojom/property.mojom";
import "components/arc/mojom/rotation_lock.mojom";
import "components/arc/mojom/screen_capture.mojom";
import "components/arc/mojom/sensor.mojom";
import "components/arc/mojom/sharesheet.mojom";
import "components/arc/mojom/storage_manager.mojom";
import "components/arc/mojom/timer.mojom";
import "components/arc/mojom/tracing.mojom";
......@@ -57,9 +58,9 @@ import "components/arc/mojom/volume_mounter.mojom";
import "components/arc/mojom/wake_lock.mojom";
import "components/arc/mojom/wallpaper.mojom";
// Next MinVersion: 52
// Next MinVersion: 53
// Deprecated method IDs: 101, 105, 121
// Next method ID: 157
// Next method ID: 158
interface ArcBridgeHost {
// Keep the entries alphabetical. In order to do so without breaking
// compatibility with the ARC instance, explicitly assign each interface a
......@@ -226,6 +227,10 @@ interface ArcBridgeHost {
[MinVersion=49] OnSensorInstanceReady@154(
pending_remote<SensorInstance> instance_ptr);
// Notifies Chrome that the SharesheetInstance interface is ready.
[MinVersion=53] OnSharesheetInstanceReady@158(
pending_remote<SharesheetInstance> instance_remote);
// Notifies Chrome that the SmartCardManagerInstance interface is ready.
[MinVersion=48] OnSmartCardManagerInstanceReady@153(
pending_remote<SmartCardManagerInstance> instance_remote);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Next MinVersion: 1
module arc.mojom;
// Used by ARC to create a new sharesheet session. A sharesheet session is used
// to show the Chrome sharesheet initiated from an Android app
// Next method ID: 0
interface SharesheetHost {
// TODO(phshah): Add methods to open sharesheet view
};
// Next method ID: 1
interface SharesheetInstance {
// Establishes full-duplex communication with the host.
[MinVersion=0] Init@0(pending_remote<SharesheetHost> host_remote) => ();
};
......@@ -52,6 +52,7 @@
#include "components/arc/mojom/rotation_lock.mojom.h"
#include "components/arc/mojom/screen_capture.mojom.h"
#include "components/arc/mojom/sensor.mojom.h"
#include "components/arc/mojom/sharesheet.mojom.h"
#include "components/arc/mojom/storage_manager.mojom.h"
#include "components/arc/mojom/timer.mojom.h"
#include "components/arc/mojom/tracing.mojom.h"
......@@ -327,6 +328,12 @@ void ArcBridgeHostImpl::OnSensorInstanceReady(
OnInstanceReady(arc_bridge_service_->sensor(), std::move(sensor_remote));
}
void ArcBridgeHostImpl::OnSharesheetInstanceReady(
mojo::PendingRemote<mojom::SharesheetInstance> sharesheet_remote) {
OnInstanceReady(arc_bridge_service_->sharesheet(),
std::move(sharesheet_remote));
}
void ArcBridgeHostImpl::OnSmartCardManagerInstanceReady(
mojo::PendingRemote<mojom::SmartCardManagerInstance>
smart_card_manager_remote) {
......
......@@ -135,6 +135,8 @@ class ArcBridgeHostImpl : public mojom::ArcBridgeHost {
override;
void OnSensorInstanceReady(
mojo::PendingRemote<mojom::SensorInstance> sensor_ptr) override;
void OnSharesheetInstanceReady(mojo::PendingRemote<mojom::SharesheetInstance>
sharesheet_remote) override;
void OnSmartCardManagerInstanceReady(
mojo::PendingRemote<mojom::SmartCardManagerInstance>
smart_card_manager_remote) override;
......
......@@ -46,6 +46,7 @@
#include "components/arc/mojom/rotation_lock.mojom.h"
#include "components/arc/mojom/screen_capture.mojom.h"
#include "components/arc/mojom/sensor.mojom.h"
#include "components/arc/mojom/sharesheet.mojom.h"
#include "components/arc/mojom/storage_manager.mojom.h"
#include "components/arc/mojom/timer.mojom.h"
#include "components/arc/mojom/tracing.mojom.h"
......
......@@ -85,6 +85,8 @@ class ScreenCaptureHost;
class ScreenCaptureInstance;
class SensorHost;
class SensorInstance;
class SharesheetHost;
class SharesheetInstance;
class SmartCardManagerHost;
class SmartCardManagerInstance;
class StorageManagerInstance;
......@@ -262,6 +264,10 @@ class ArcBridgeService {
ConnectionHolder<mojom::SensorInstance, mojom::SensorHost>* sensor() {
return &sensor_;
}
ConnectionHolder<mojom::SharesheetInstance, mojom::SharesheetHost>*
sharesheet() {
return &sharesheet_;
}
ConnectionHolder<mojom::SmartCardManagerInstance,
mojom::SmartCardManagerHost>*
smart_card_manager() {
......@@ -350,6 +356,8 @@ class ArcBridgeService {
ConnectionHolder<mojom::ScreenCaptureInstance, mojom::ScreenCaptureHost>
screen_capture_;
ConnectionHolder<mojom::SensorInstance, mojom::SensorHost> sensor_;
ConnectionHolder<mojom::SharesheetInstance, mojom::SharesheetHost>
sharesheet_;
ConnectionHolder<mojom::SmartCardManagerInstance, mojom::SmartCardManagerHost>
smart_card_manager_;
ConnectionHolder<mojom::StorageManagerInstance> storage_manager_;
......
melzhang@chromium.org
mxcai@chromium.org
phshah@chromium.org
......@@ -44,6 +44,7 @@
#include "components/arc/mojom/rotation_lock.mojom.h"
#include "components/arc/mojom/screen_capture.mojom.h"
#include "components/arc/mojom/sensor.mojom.h"
#include "components/arc/mojom/sharesheet.mojom.h"
#include "components/arc/mojom/storage_manager.mojom.h"
#include "components/arc/mojom/timer.mojom.h"
#include "components/arc/mojom/tracing.mojom.h"
......@@ -192,6 +193,9 @@ void FakeArcBridgeHost::OnScreenCaptureInstanceReady(
void FakeArcBridgeHost::OnSensorInstanceReady(
mojo::PendingRemote<mojom::SensorInstance> sensor_remote) {}
void FakeArcBridgeHost::OnSharesheetInstanceReady(
mojo::PendingRemote<mojom::SharesheetInstance> sharesheet_remote) {}
void FakeArcBridgeHost::OnSmartCardManagerInstanceReady(
mojo::PendingRemote<mojom::SmartCardManagerInstance>
smart_cardManager_remote) {}
......
......@@ -114,6 +114,8 @@ class FakeArcBridgeHost : public mojom::ArcBridgeHost {
override;
void OnSensorInstanceReady(
mojo::PendingRemote<mojom::SensorInstance> sensor_remote) override;
void OnSharesheetInstanceReady(mojo::PendingRemote<mojom::SharesheetInstance>
sharesheet_remote) override;
void OnSmartCardManagerInstanceReady(
mojo::PendingRemote<mojom::SmartCardManagerInstance>
smart_card_manager_remote) override;
......
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