Commit 6021292b authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

Disable camera intent filters in ArcIntentHelper if CCA is disabled

The corresponding CL on ARC side is:
http://ag/9684171

Bug: b/144062362
Test: Tested with an enterprise account and policy which blocks CCA
and CCA will not show up as an option when forwarding camera intent.

Change-Id: Ie27c899f044d7e72cd58439510adbb4af6b7775e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903238
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarDavid Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714830}
parent 70693f1c
......@@ -5,8 +5,6 @@
#ifndef ASH_PUBLIC_CPP_NEW_WINDOW_DELEGATE_H_
#define ASH_PUBLIC_CPP_NEW_WINDOW_DELEGATE_H_
#include <string>
#include "ash/public/cpp/ash_public_export.h"
#include "base/macros.h"
......@@ -53,13 +51,6 @@ class ASH_PUBLIC_EXPORT NewWindowDelegate {
// true then the page is triggered from Assistant.
virtual void OpenFeedbackPage(bool from_assistant = false) = 0;
// Launches the camera app from Android camera intent with the intent
// information as url |queries|.
virtual void LaunchCameraApp(const std::string& queries) = 0;
// Closes the camera app.
virtual void CloseCameraApp() = 0;
protected:
NewWindowDelegate();
virtual ~NewWindowDelegate();
......
......@@ -20,7 +20,5 @@ void TestNewWindowDelegate::RestoreTab() {}
void TestNewWindowDelegate::ShowKeyboardShortcutViewer() {}
void TestNewWindowDelegate::ShowTaskManager() {}
void TestNewWindowDelegate::OpenFeedbackPage(bool from_assistant) {}
void TestNewWindowDelegate::LaunchCameraApp(const std::string& queries) {}
void TestNewWindowDelegate::CloseCameraApp() {}
} // namespace ash
......@@ -28,8 +28,6 @@ class ASH_PUBLIC_EXPORT TestNewWindowDelegate : public NewWindowDelegate {
void ShowKeyboardShortcutViewer() override;
void ShowTaskManager() override;
void OpenFeedbackPage(bool from_assistant) override;
void LaunchCameraApp(const std::string& queries) override;
void CloseCameraApp() override;
DISALLOW_COPY_AND_ASSIGN(TestNewWindowDelegate);
};
......
......@@ -48,9 +48,5 @@ void ShellNewWindowDelegate::ShowTaskManager() {}
void ShellNewWindowDelegate::OpenFeedbackPage(bool from_assistant) {}
void ShellNewWindowDelegate::LaunchCameraApp(const std::string& queries) {}
void ShellNewWindowDelegate::CloseCameraApp() {}
} // namespace shell
} // namespace ash
......@@ -32,8 +32,6 @@ class ShellNewWindowDelegate : public ash::NewWindowDelegate {
void ShowKeyboardShortcutViewer() override;
void ShowTaskManager() override;
void OpenFeedbackPage(bool from_assistant) override;
void LaunchCameraApp(const std::string& queries) override;
void CloseCameraApp() override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellNewWindowDelegate);
......
......@@ -162,9 +162,11 @@ ChromeNewWindowClient::ChromeNewWindowClient()
about_pages_(std::cbegin(kAboutPagesMapping),
std::cend(kAboutPagesMapping)) {
arc::ArcIntentHelperBridge::SetOpenUrlDelegate(this);
arc::ArcIntentHelperBridge::SetControlCameraAppDelegate(this);
}
ChromeNewWindowClient::~ChromeNewWindowClient() {
arc::ArcIntentHelperBridge::SetControlCameraAppDelegate(nullptr);
arc::ArcIntentHelperBridge::SetOpenUrlDelegate(nullptr);
}
......@@ -332,37 +334,6 @@ void ChromeNewWindowClient::OpenFeedbackPage(bool from_assistant) {
chrome::OpenFeedbackDialog(chrome::FindBrowserWithActiveWindow(), source);
}
void ChromeNewWindowClient::LaunchCameraApp(const std::string& queries) {
Profile* const profile = ProfileManager::GetActiveUserProfile();
const extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile);
const extensions::Extension* extension =
registry->GetInstalledExtension(extension_misc::kChromeCameraAppId);
auto url = GURL(extensions::Extension::GetBaseURLFromExtensionId(
extension_misc::kChromeCameraAppId)
.spec() +
queries);
apps::LaunchPlatformAppWithUrl(profile, extension,
/*handler_id=*/std::string(), url,
/*referrer_url=*/GURL());
}
void ChromeNewWindowClient::CloseCameraApp() {
const ash::ShelfID shelf_id(ash::kInternalAppIdCamera);
AppWindowLauncherItemController* const app_controller =
ChromeLauncherController::instance()
->shelf_model()
->GetAppWindowLauncherItemController(shelf_id);
if (!app_controller)
return;
DCHECK_LE(app_controller->window_count(), 1lu);
if (app_controller->window_count() > 0)
app_controller->windows().front()->Close();
}
void ChromeNewWindowClient::OpenUrlFromArc(const GURL& url) {
if (!url.is_valid())
return;
......@@ -504,3 +475,41 @@ void ChromeNewWindowClient::OpenChromePageFromArc(ChromePage page) {
NOTREACHED();
}
void ChromeNewWindowClient::LaunchCameraApp(const std::string& queries) {
Profile* const profile = ProfileManager::GetActiveUserProfile();
const extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile);
const extensions::Extension* extension =
registry->GetInstalledExtension(extension_misc::kChromeCameraAppId);
auto url = GURL(extensions::Extension::GetBaseURLFromExtensionId(
extension_misc::kChromeCameraAppId)
.spec() +
queries);
apps::LaunchPlatformAppWithUrl(profile, extension,
/*handler_id=*/std::string(), url,
/*referrer_url=*/GURL());
}
void ChromeNewWindowClient::CloseCameraApp() {
const ash::ShelfID shelf_id(ash::kInternalAppIdCamera);
AppWindowLauncherItemController* const app_controller =
ChromeLauncherController::instance()
->shelf_model()
->GetAppWindowLauncherItemController(shelf_id);
if (!app_controller)
return;
DCHECK_LE(app_controller->window_count(), 1lu);
if (app_controller->window_count() > 0)
app_controller->windows().front()->Close();
}
bool ChromeNewWindowClient::IsCameraAppEnabled() {
return extensions::ExtensionRegistry::Get(
ProfileManager::GetActiveUserProfile())
->enabled_extensions()
.GetByID(extension_misc::kCameraAppId) != nullptr;
}
......@@ -11,6 +11,7 @@
#include "ash/public/cpp/new_window_delegate.h"
#include "base/macros.h"
#include "components/arc/intent_helper/control_camera_app_delegate.h"
#include "components/arc/intent_helper/open_url_delegate.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "url/gurl.h"
......@@ -28,7 +29,8 @@ class WebContents;
// Handles opening new tabs and windows on behalf of ash (over mojo) and the
// ARC bridge (via a delegate in the browser process).
class ChromeNewWindowClient : public ash::NewWindowDelegate,
public arc::OpenUrlDelegate {
public arc::OpenUrlDelegate,
public arc::ControlCameraAppDelegate {
public:
ChromeNewWindowClient();
~ChromeNewWindowClient() override;
......@@ -46,8 +48,6 @@ class ChromeNewWindowClient : public ash::NewWindowDelegate,
void ShowKeyboardShortcutViewer() override;
void ShowTaskManager() override;
void OpenFeedbackPage(bool from_assistant) override;
void LaunchCameraApp(const std::string& queries) override;
void CloseCameraApp() override;
// arc::OpenUrlDelegate:
void OpenUrlFromArc(const GURL& url) override;
......@@ -60,6 +60,11 @@ class ChromeNewWindowClient : public ash::NewWindowDelegate,
arc::mojom::IntentHelperHost::OnOpenCustomTabCallback callback) override;
void OpenChromePageFromArc(arc::mojom::ChromePage page) override;
// arc::ControlCameraAppDelegate:
void LaunchCameraApp(const std::string& queries) override;
void CloseCameraApp() override;
bool IsCameraAppEnabled() override;
private:
class TabRestoreHelper;
......
......@@ -32,6 +32,7 @@ static_library("arc") {
"intent_helper/arc_intent_helper_bridge.cc",
"intent_helper/arc_intent_helper_bridge.h",
"intent_helper/arc_intent_helper_observer.h",
"intent_helper/control_camera_app_delegate.h",
"intent_helper/factory_reset_delegate.h",
"intent_helper/font_size_util.cc",
"intent_helper/font_size_util.h",
......
......@@ -20,6 +20,7 @@
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/audio/arc_audio_bridge.h"
#include "components/arc/intent_helper/control_camera_app_delegate.h"
#include "components/arc/intent_helper/factory_reset_delegate.h"
#include "components/arc/intent_helper/open_url_delegate.h"
#include "components/arc/session/arc_bridge_service.h"
......@@ -39,6 +40,7 @@ constexpr const char* kArcSchemes[] = {url::kHttpScheme, url::kHttpsScheme,
// Not owned. Must outlive all ArcIntentHelperBridge instances. Typically this
// is ChromeNewWindowClient in the browser.
OpenUrlDelegate* g_open_url_delegate = nullptr;
ControlCameraAppDelegate* g_control_camera_app_delegate = nullptr;
FactoryResetDelegate* g_factory_reset_delegate = nullptr;
// Singleton factory for ArcIntentHelperBridge.
......@@ -107,6 +109,12 @@ void ArcIntentHelperBridge::SetOpenUrlDelegate(OpenUrlDelegate* delegate) {
g_open_url_delegate = delegate;
}
// static
void ArcIntentHelperBridge::SetControlCameraAppDelegate(
ControlCameraAppDelegate* delegate) {
g_control_camera_app_delegate = delegate;
}
// static
void ArcIntentHelperBridge::SetFactoryResetDelegate(
FactoryResetDelegate* delegate) {
......@@ -239,13 +247,28 @@ void ArcIntentHelperBridge::LaunchCameraApp(uint32_t intent_id,
<< "&shouldHandleResult=" << should_handle_result
<< "&shouldDownScale=" << should_down_scale
<< "&isSecure=" << is_secure;
ash::NewWindowDelegate::GetInstance()->LaunchCameraApp(queries.str());
g_control_camera_app_delegate->LaunchCameraApp(queries.str());
}
void ArcIntentHelperBridge::CloseCameraApp() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
ash::NewWindowDelegate::GetInstance()->CloseCameraApp();
g_control_camera_app_delegate->CloseCameraApp();
}
void ArcIntentHelperBridge::IsChromeAppEnabled(
arc::mojom::ChromeApp app,
IsChromeAppEnabledCallback callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (app == arc::mojom::ChromeApp::CAMERA) {
std::move(callback).Run(
g_control_camera_app_delegate->IsCameraAppEnabled());
return;
}
NOTREACHED() << "Unknown chrome app";
std::move(callback).Run(false);
}
ArcIntentHelperBridge::GetResult ArcIntentHelperBridge::GetActivityIcons(
......
......@@ -30,6 +30,7 @@ class BrowserContext;
namespace arc {
class ArcBridgeService;
class ControlCameraAppDelegate;
class FactoryResetDelegate;
class IntentFilter;
class OpenUrlDelegate;
......@@ -52,6 +53,8 @@ class ArcIntentHelperBridge : public KeyedService,
static void SetOpenUrlDelegate(OpenUrlDelegate* delegate);
static void SetControlCameraAppDelegate(ControlCameraAppDelegate* delegate);
static void SetFactoryResetDelegate(FactoryResetDelegate* delegate);
ArcIntentHelperBridge(content::BrowserContext* context,
......@@ -90,10 +93,12 @@ class ArcIntentHelperBridge : public KeyedService,
bool should_handle_result,
bool should_down_scale,
bool is_secure) override;
void CloseCameraApp() override;
void OnIntentFiltersUpdatedForPackage(
const std::string& package_name,
std::vector<IntentFilter> intent_filters) override;
void CloseCameraApp() override;
void IsChromeAppEnabled(arc::mojom::ChromeApp app,
IsChromeAppEnabledCallback callback) override;
// Retrieves icons for the |activities| and calls |callback|.
// See ActivityIconLoader::GetActivityIcons() for more details.
......
// Copyright 2019 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 COMPONENTS_ARC_INTENT_HELPER_CONTROL_CAMERA_APP_DELEGATE_H_
#define COMPONENTS_ARC_INTENT_HELPER_CONTROL_CAMERA_APP_DELEGATE_H_
#include <string>
namespace arc {
class ControlCameraAppDelegate {
public:
virtual ~ControlCameraAppDelegate() = default;
// Launches the camera app from Android camera intent with the intent
// information as url |queries|.
virtual void LaunchCameraApp(const std::string& queries) = 0;
// Closes the camera app.
virtual void CloseCameraApp() = 0;
// Checks if Chrome Camera App is enabled.
virtual bool IsCameraAppEnabled() = 0;
};
} // namespace arc
#endif // COMPONENTS_ARC_INTENT_HELPER_CONTROL_CAMERA_APP_DELEGATE_H_
......@@ -151,6 +151,14 @@ enum ChromePage {
LAST = ABOUTHISTORY,
};
// Describes an unique chrome app.
[Extensible]
enum ChromeApp {
CAMERA,
LAST = CAMERA,
};
// Describes an action given by the android text selection delegate (e.g. open
// maps).
struct TextSelectionAction {
......@@ -184,7 +192,7 @@ interface CustomTabSession {
// Handles intents from ARC in Chrome.
// Deprecated method ID: 4
// Next method ID: 15
// Next method ID: 16
interface IntentHelperHost {
// Called when icons associated with the package are no longer up to date.
[MinVersion=3] OnIconInvalidated@1(string package_name);
......@@ -257,6 +265,9 @@ interface IntentHelperHost {
// Closes Chrome camera app.
[MinVersion=31] CloseCameraApp@14();
// Checks if given chrome app is enabled.
[MinVersion=32] IsChromeAppEnabled@15(ChromeApp app) => (bool is_enabled);
};
// Sends intents to ARC on behalf of Chrome.
......
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