Commit 363ba85c authored by Andrew Xu's avatar Andrew Xu Committed by Chromium LUCI CQ

[Multipaste] Enable all menu items regardless of clipboard data access

Currently menu items may be disabled due to lack of access to clipboard
data. In fact, the code in the DLP side should decide whether pasting
clipboard data should work and abort the paste if the paste destination
has no data access. Hence, disabling menu items in the view side is
meaningless.

In this CL, the code of disabling menu items is removed.

Bug: 1151497
Change-Id: Iaf140ac9151a21a4ff17859d6702cafe3a5ebe08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2561105Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833743}
parent 01e8a28e
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -27,17 +25,6 @@ ...@@ -27,17 +25,6 @@
namespace ash { namespace ash {
namespace {
bool IsDataReadAllowed(const ui::DataTransferEndpoint* source,
const ui::DataTransferEndpoint* destination) {
ui::DataTransferPolicyController* policy_controller =
ui::DataTransferPolicyController::Get();
if (!policy_controller)
return true;
return policy_controller->IsDataReadAllowed(source, destination);
}
} // namespace
// static // static
std::unique_ptr<ClipboardHistoryMenuModelAdapter> std::unique_ptr<ClipboardHistoryMenuModelAdapter>
ClipboardHistoryMenuModelAdapter::Create( ClipboardHistoryMenuModelAdapter::Create(
...@@ -74,14 +61,6 @@ void ClipboardHistoryMenuModelAdapter::Run( ...@@ -74,14 +61,6 @@ void ClipboardHistoryMenuModelAdapter::Run(
/*notify_if_restricted=*/false); /*notify_if_restricted=*/false);
for (const auto& item : items) { for (const auto& item : items) {
model_->AddItem(command_id, base::string16()); model_->AddItem(command_id, base::string16());
// Enable or disable the command depending on whether its corresponding
// clipboard history item is allowed to read or not.
// This clipboard read isn't initiated by the user, that's why it shouldn't
// notify if the clipboard is restricted.
model_->SetEnabledAt(model_->GetIndexOfCommandId(command_id),
IsDataReadAllowed(item.data().source(), &data_dst));
item_snapshots_.emplace(command_id, item); item_snapshots_.emplace(command_id, item);
++command_id; ++command_id;
} }
...@@ -274,34 +253,26 @@ void ClipboardHistoryMenuModelAdapter::AdvancePseudoFocusFromSelectedItem( ...@@ -274,34 +253,26 @@ void ClipboardHistoryMenuModelAdapter::AdvancePseudoFocusFromSelectedItem(
SelectMenuItemWithCommandId(next_selected_item_command); SelectMenuItemWithCommandId(next_selected_item_command);
} }
base::Optional<int> int ClipboardHistoryMenuModelAdapter::CalculateSelectedCommandIdAfterDeletion(
ClipboardHistoryMenuModelAdapter::CalculateSelectedCommandIdAfterDeletion(
int command_id) const { int command_id) const {
// If the menu item view to be deleted is the last one, Cancel() // If the menu item view to be deleted is the last one, Cancel()
// should be called so this function should not be hit. // should be called so this function should not be hit.
DCHECK_GT(item_snapshots_.size(), 1u); DCHECK_GT(item_snapshots_.size(), 1u);
auto start_item = item_snapshots_.find(command_id); auto item_to_delete = item_snapshots_.find(command_id);
DCHECK(start_item != item_snapshots_.cend()); DCHECK(item_to_delete != item_snapshots_.cend());
// Search in the forward direction. // Use the menu item right after the one to be deleted if any. Otherwise,
auto check_function = [this](const auto& key_value) -> bool { // select the previous one.
return model_->IsEnabledAt(model_->GetIndexOfCommandId(key_value.first));
}; auto next_item_iter = item_to_delete;
auto selectable_iter_forward = std::find_if( ++next_item_iter;
std::next(start_item, 1), item_snapshots_.cend(), check_function); if (next_item_iter != item_snapshots_.cend())
if (selectable_iter_forward != item_snapshots_.cend()) return next_item_iter->first;
return selectable_iter_forward->first;
auto previous_item_iter = item_to_delete;
// If no selectable item is found, then search in the reverse direction. --previous_item_iter;
auto selectable_iter_reverse = return previous_item_iter->first;
std::find_if(std::make_reverse_iterator(start_item),
item_snapshots_.crend(), check_function);
if (selectable_iter_reverse != item_snapshots_.crend())
return selectable_iter_reverse->first;
// No other selectable item, then returns the invalid id.
return base::nullopt;
} }
void ClipboardHistoryMenuModelAdapter::RemoveItemView(int command_id) { void ClipboardHistoryMenuModelAdapter::RemoveItemView(int command_id) {
......
...@@ -105,11 +105,9 @@ class ASH_EXPORT ClipboardHistoryMenuModelAdapter : views::MenuModelAdapter { ...@@ -105,11 +105,9 @@ class ASH_EXPORT ClipboardHistoryMenuModelAdapter : views::MenuModelAdapter {
// `reverse` is true). // `reverse` is true).
void AdvancePseudoFocusFromSelectedItem(bool reverse); void AdvancePseudoFocusFromSelectedItem(bool reverse);
// Returns the command id of the menu item to be selected if any after the // Returns the command id of the menu item to be selected after the
// menu item specified by `command_id` is deleted. If no menu item is // menu item specified by `command_id` is deleted.
// selectable after deletion, an absent value is returned. int CalculateSelectedCommandIdAfterDeletion(int command_id) const;
base::Optional<int> CalculateSelectedCommandIdAfterDeletion(
int command_id) const;
// Removes the item view specified by `command_id` from the root menu. // Removes the item view specified by `command_id` from the root menu.
void RemoveItemView(int command_id); void RemoveItemView(int command_id);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -51,13 +50,11 @@ class FadeImageView : public RoundedImageView, ...@@ -51,13 +50,11 @@ class FadeImageView : public RoundedImageView,
public: public:
FadeImageView(const ClipboardHistoryItem* clipboard_history_item, FadeImageView(const ClipboardHistoryItem* clipboard_history_item,
const ClipboardHistoryResourceManager* resource_manager, const ClipboardHistoryResourceManager* resource_manager,
float opacity,
base::RepeatingClosure update_callback) base::RepeatingClosure update_callback)
: RoundedImageView(ClipboardHistoryViews::kImageRoundedCornerRadius, : RoundedImageView(ClipboardHistoryViews::kImageRoundedCornerRadius,
RoundedImageView::Alignment::kCenter), RoundedImageView::Alignment::kCenter),
resource_manager_(resource_manager), resource_manager_(resource_manager),
clipboard_history_item_(*clipboard_history_item), clipboard_history_item_(*clipboard_history_item),
opacity_(opacity),
update_callback_(update_callback) { update_callback_(update_callback) {
resource_manager_->AddObserver(this); resource_manager_->AddObserver(this);
SetImageFromModel(); SetImageFromModel();
...@@ -119,12 +116,7 @@ class FadeImageView : public RoundedImageView, ...@@ -119,12 +116,7 @@ class FadeImageView : public RoundedImageView,
*(resource_manager_->GetImageModel(clipboard_history_item_) *(resource_manager_->GetImageModel(clipboard_history_item_)
.GetImage() .GetImage()
.ToImageSkia()); .ToImageSkia());
if (opacity_ != 1.f) {
SetImage(
gfx::ImageSkiaOperations::CreateTransparentImage(image, opacity_));
} else {
SetImage(image); SetImage(image);
}
// When fading in a new image, the ImageView's image has likely changed // When fading in a new image, the ImageView's image has likely changed
// sizes. // sizes.
...@@ -149,9 +141,6 @@ class FadeImageView : public RoundedImageView, ...@@ -149,9 +141,6 @@ class FadeImageView : public RoundedImageView,
// The ClipboardHistoryItem represented by this class. // The ClipboardHistoryItem represented by this class.
const ClipboardHistoryItem clipboard_history_item_; const ClipboardHistoryItem clipboard_history_item_;
// The opacity of the image content.
const float opacity_;
// Used to notify of image changes. // Used to notify of image changes.
base::RepeatingClosure update_callback_; base::RepeatingClosure update_callback_;
}; };
...@@ -231,16 +220,11 @@ class ClipboardHistoryBitmapItemView::BitmapContentsView ...@@ -231,16 +220,11 @@ class ClipboardHistoryBitmapItemView::BitmapContentsView
// if menu items have their own layers, the part beyond the container's // if menu items have their own layers, the part beyond the container's
// bounds is still visible when the context menu is in overflow. // bounds is still visible when the context menu is in overflow.
const float image_opacity =
container_->IsItemEnabled()
? 1.f
: ClipboardHistoryViews::kDisabledImageAlpha;
const auto* clipboard_history_item = container_->clipboard_history_item(); const auto* clipboard_history_item = container_->clipboard_history_item();
switch (container_->data_format_) { switch (container_->data_format_) {
case ui::ClipboardInternalFormat::kHtml: case ui::ClipboardInternalFormat::kHtml:
return std::make_unique<FadeImageView>( return std::make_unique<FadeImageView>(
clipboard_history_item, container_->resource_manager_, clipboard_history_item, container_->resource_manager_,
image_opacity,
base::BindRepeating(&BitmapContentsView::UpdateImageViewSize, base::BindRepeating(&BitmapContentsView::UpdateImageViewSize,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
case ui::ClipboardInternalFormat::kBitmap: { case ui::ClipboardInternalFormat::kBitmap: {
...@@ -249,10 +233,6 @@ class ClipboardHistoryBitmapItemView::BitmapContentsView ...@@ -249,10 +233,6 @@ class ClipboardHistoryBitmapItemView::BitmapContentsView
RoundedImageView::Alignment::kCenter); RoundedImageView::Alignment::kCenter);
gfx::ImageSkia bitmap_image = gfx::ImageSkia::CreateFrom1xBitmap( gfx::ImageSkia bitmap_image = gfx::ImageSkia::CreateFrom1xBitmap(
clipboard_history_item->data().bitmap()); clipboard_history_item->data().bitmap());
if (image_opacity != 1.f) {
bitmap_image = gfx::ImageSkiaOperations::CreateTransparentImage(
bitmap_image, image_opacity);
}
image_view->SetImage(bitmap_image); image_view->SetImage(bitmap_image);
return image_view; return image_view;
} }
......
...@@ -234,10 +234,6 @@ void ClipboardHistoryItemView::RecordButtonPressedHistogram() const { ...@@ -234,10 +234,6 @@ void ClipboardHistoryItemView::RecordButtonPressedHistogram() const {
} }
} }
bool ClipboardHistoryItemView::IsItemEnabled() const {
return container_->GetEnabled();
}
gfx::Size ClipboardHistoryItemView::CalculatePreferredSize() const { gfx::Size ClipboardHistoryItemView::CalculatePreferredSize() const {
const int preferred_width = const int preferred_width =
views::MenuConfig::instance().touchable_menu_width; views::MenuConfig::instance().touchable_menu_width;
...@@ -283,7 +279,7 @@ Action ClipboardHistoryItemView::CalculateActionForMainButtonClick() const { ...@@ -283,7 +279,7 @@ Action ClipboardHistoryItemView::CalculateActionForMainButtonClick() const {
} }
bool ClipboardHistoryItemView::ShouldHighlight() const { bool ClipboardHistoryItemView::ShouldHighlight() const {
return pseudo_focus_ == PseudoFocus::kMainButton && IsItemEnabled(); return pseudo_focus_ == PseudoFocus::kMainButton;
} }
bool ClipboardHistoryItemView::ShouldShowDeleteButton() const { bool ClipboardHistoryItemView::ShouldShowDeleteButton() const {
......
...@@ -109,10 +109,6 @@ class ClipboardHistoryItemView : public views::View { ...@@ -109,10 +109,6 @@ class ClipboardHistoryItemView : public views::View {
// Returns the name of the accessible node. // Returns the name of the accessible node.
virtual base::string16 GetAccessibleName() const = 0; virtual base::string16 GetAccessibleName() const = 0;
// Returns whether the item view is enabled. The item view is disabled when
// it is not allowed to read clipboard data.
bool IsItemEnabled() const;
const ClipboardHistoryItem* clipboard_history_item() const { const ClipboardHistoryItem* clipboard_history_item() const {
return clipboard_history_item_; return clipboard_history_item_;
} }
......
...@@ -32,12 +32,8 @@ void ClipboardHistoryLabel::OnThemeChanged() { ...@@ -32,12 +32,8 @@ void ClipboardHistoryLabel::OnThemeChanged() {
// TODO(andrewxu): remove this line after https://crbug.com/1143009 is fixed. // TODO(andrewxu): remove this line after https://crbug.com/1143009 is fixed.
ash::ScopedLightModeAsDefault scoped_light_mode_as_default; ash::ScopedLightModeAsDefault scoped_light_mode_as_default;
const auto color_type = SetEnabledColor(ash::AshColorProvider::Get()->GetContentLayerColor(
GetEnabled() ash::AshColorProvider::ContentLayerType::kTextColorPrimary));
? ash::AshColorProvider::ContentLayerType::kTextColorPrimary
: ash::AshColorProvider::ContentLayerType::kTextColorSecondary;
SetEnabledColor(
ash::AshColorProvider::Get()->GetContentLayerColor(color_type));
} }
} // namespace ash } // namespace ash
...@@ -33,7 +33,6 @@ class ClipboardHistoryTextItemView::TextContentsView ...@@ -33,7 +33,6 @@ class ClipboardHistoryTextItemView::TextContentsView
auto* label = auto* label =
AddChildView(std::make_unique<ClipboardHistoryLabel>(container->text_)); AddChildView(std::make_unique<ClipboardHistoryLabel>(container->text_));
layout->SetFlexForView(label, /*flex_weight=*/1); layout->SetFlexForView(label, /*flex_weight=*/1);
label->SetEnabled(container->IsItemEnabled());
InstallDeleteButton(); InstallDeleteButton();
} }
......
...@@ -41,9 +41,6 @@ constexpr int kImageRoundedCornerRadius = 4; ...@@ -41,9 +41,6 @@ constexpr int kImageRoundedCornerRadius = 4;
// The thickness of the image border. // The thickness of the image border.
constexpr int kImageBorderThickness = 1; constexpr int kImageBorderThickness = 1;
// The opacity of the image shown in a disabled item view.
constexpr float kDisabledImageAlpha = 0.38f;
} // namespace ClipboardHistoryViews } // namespace ClipboardHistoryViews
} // namespace ash } // namespace ash
......
...@@ -866,26 +866,9 @@ IN_PROC_BROWSER_TEST_F(ClipboardHistoryWithMockDLPBrowserTest, Basics) { ...@@ -866,26 +866,9 @@ IN_PROC_BROWSER_TEST_F(ClipboardHistoryWithMockDLPBrowserTest, Basics) {
GetContextMenu()->GetMenuItemViewAtForTest(/*index=*/0); GetContextMenu()->GetMenuItemViewAtForTest(/*index=*/0);
GetEventGenerator()->MoveMouseTo( GetEventGenerator()->MoveMouseTo(
inaccessible_menu_item_view->GetBoundsInScreen().CenterPoint()); inaccessible_menu_item_view->GetBoundsInScreen().CenterPoint());
// Verify that `inaccessible_menu_item_view` cannot be selected by mouse
// hovering. It does not respond to mouse click either.
EXPECT_FALSE(inaccessible_menu_item_view->IsSelected());
GetEventGenerator()->ClickLeftButton(); GetEventGenerator()->ClickLeftButton();
EXPECT_EQ("", base::UTF16ToUTF8(textfield_->GetText()));
// Move the selection through the arrow key. Then delete the item by the
// backspace key. After deletion, `inaccessible_menu_item_view` is left.
PressAndRelease(ui::KeyboardCode::VKEY_DOWN, ui::EF_NONE);
PressAndRelease(ui::KeyboardCode::VKEY_BACK, ui::EF_NONE);
EXPECT_TRUE(VerifyClipboardTextData({"B"}));
EXPECT_EQ(1, GetContextMenu()->GetMenuItemsCount());
// Move the selection through the arrow key again. Verify that // Verify that the text is not pasted and menu is closed after click.
// `inaccessible_menu_item_view` cannot be selected. Pressing the backspace EXPECT_EQ("", base::UTF16ToUTF8(textfield_->GetText()));
// key does not delete the item. EXPECT_FALSE(GetClipboardHistoryController()->IsMenuShowing());
PressAndRelease(ui::KeyboardCode::VKEY_DOWN, ui::EF_NONE);
PressAndRelease(ui::KeyboardCode::VKEY_BACK, ui::EF_NONE);
EXPECT_FALSE(inaccessible_menu_item_view->IsSelected());
EXPECT_TRUE(VerifyClipboardTextData({"B"}));
EXPECT_EQ(1, GetContextMenu()->GetMenuItemsCount());
} }
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