Commit dc584e77 authored by Azeem Arshad's avatar Azeem Arshad Committed by Chromium LUCI CQ

[NearbyShare] Hide sharesheet action when disabled by policy.

This CL adds sharesheet shouldShowAction logic that hides
nearbyshare sharesheet when the feature is disabled by
policy.

Fixed: 1156857
Change-Id: I61532c71aa67e2d1ab55f0b39d6cd36d7268ad8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586084Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836173}
parent 99b55faa
...@@ -77,6 +77,11 @@ const std::vector<std::string> NearbyShareSettings::GetAllowedContacts() const { ...@@ -77,6 +77,11 @@ const std::vector<std::string> NearbyShareSettings::GetAllowedContacts() const {
return allowed_contacts; return allowed_contacts;
} }
bool NearbyShareSettings::IsDisabledByPolicy() const {
return !GetEnabled() && pref_service_->IsManagedPreference(
prefs::kNearbySharingEnabledPrefName);
}
void NearbyShareSettings::AddSettingsObserver( void NearbyShareSettings::AddSettingsObserver(
::mojo::PendingRemote<nearby_share::mojom::NearbyShareSettingsObserver> ::mojo::PendingRemote<nearby_share::mojom::NearbyShareSettingsObserver>
observer) { observer) {
......
...@@ -53,6 +53,9 @@ class NearbyShareSettings : public nearby_share::mojom::NearbyShareSettings, ...@@ -53,6 +53,9 @@ class NearbyShareSettings : public nearby_share::mojom::NearbyShareSettings,
nearby_share::mojom::Visibility GetVisibility() const; nearby_share::mojom::Visibility GetVisibility() const;
const std::vector<std::string> GetAllowedContacts() const; const std::vector<std::string> GetAllowedContacts() const;
// Returns true if the feature is disabled by policy.
bool IsDisabledByPolicy() const;
// nearby_share::mojom::NearbyShareSettings // nearby_share::mojom::NearbyShareSettings
void AddSettingsObserver( void AddSettingsObserver(
::mojo::PendingRemote<nearby_share::mojom::NearbyShareSettingsObserver> ::mojo::PendingRemote<nearby_share::mojom::NearbyShareSettingsObserver>
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/nearby_sharing/attachment.h" #include "chrome/browser/nearby_sharing/attachment.h"
#include "chrome/browser/nearby_sharing/file_attachment.h" #include "chrome/browser/nearby_sharing/file_attachment.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service_factory.h"
#include "chrome/browser/nearby_sharing/sharesheet/nearby_share_web_view.h" #include "chrome/browser/nearby_sharing/sharesheet/nearby_share_web_view.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sharesheet/sharesheet_types.h" #include "chrome/browser/sharesheet/sharesheet_types.h"
...@@ -127,6 +129,20 @@ void NearbyShareAction::OnClose() { ...@@ -127,6 +129,20 @@ void NearbyShareAction::OnClose() {
} }
} }
bool NearbyShareAction::ShouldShowAction(const apps::mojom::IntentPtr& intent,
bool contains_hosted_document) {
Profile* profile = ProfileManager::GetPrimaryUserProfile();
if (!profile) {
return false;
}
NearbySharingService* nearby_share_service =
NearbySharingServiceFactory::GetForBrowserContext(profile);
if (!nearby_share_service) {
return false;
}
return !nearby_share_service->GetSettings()->IsDisabledByPolicy();
}
void NearbyShareAction::OnClosing( void NearbyShareAction::OnClosing(
sharesheet::SharesheetController* controller) { sharesheet::SharesheetController* controller) {
if (nearby_ui_) { if (nearby_ui_) {
......
...@@ -23,6 +23,8 @@ class NearbyShareAction : public sharesheet::ShareAction, ...@@ -23,6 +23,8 @@ class NearbyShareAction : public sharesheet::ShareAction,
views::View* root_view, views::View* root_view,
apps::mojom::IntentPtr intent) override; apps::mojom::IntentPtr intent) override;
void OnClosing(sharesheet::SharesheetController* controller) override; void OnClosing(sharesheet::SharesheetController* controller) override;
bool ShouldShowAction(const apps::mojom::IntentPtr& intent,
bool contains_hosted_document) override;
// nearby_share::NearbyShareDialogUI::Observer: // nearby_share::NearbyShareDialogUI::Observer:
void OnClose() override; void OnClose() 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