Skip to content

Commit

Permalink
Remove WebDragData::valid_ member and related methods
Browse files Browse the repository at this point in the history
Replace the validity of a blink::WebDragData object with the usage of
base::Optional.

This CL removes WebDragData::valid_, and Initialize(), IsNull() and
Reset() methods.

Bug: 1039255
Change-Id: Ieca195ab87bbf28f574959e0f5418941a8b80d25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216074
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#773090}
  • Loading branch information
hferreiro authored and Commit Bot committed May 29, 2020
1 parent 169c336 commit 85095e5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 33 deletions.
2 changes: 0 additions & 2 deletions content/renderer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ WebDragData DropMetaDataToWebDragData(
}

WebDragData result;
result.Initialize();
result.SetItems(item_list);
return result;
}
Expand Down Expand Up @@ -328,7 +327,6 @@ WebDragData DropDataToWebDragData(const DropData& drop_data) {
}

WebDragData result;
result.Initialize();
result.SetItems(item_list);
result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
return result;
Expand Down
32 changes: 16 additions & 16 deletions content/shell/renderer/web_test/event_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ EventSender::EventSender(WebWidgetTestProxy* web_widget_test_proxy)
EventSender::~EventSender() {}

void EventSender::Reset() {
current_drag_data_.Reset();
current_drag_data_ = base::nullopt;
current_drag_effect_ = blink::kWebDragOperationNone;
current_drag_effects_allowed_ = blink::kWebDragOperationNone;
if (widget() && current_pointer_state_[kRawMousePointerId].pressed_button_ !=
Expand Down Expand Up @@ -1856,7 +1856,7 @@ void EventSender::KeyDown(const std::string& code_str,

HandleInputEventOnViewOrPopup(event_down);

if (code == ui::VKEY_ESCAPE && !current_drag_data_.IsNull()) {
if (code == ui::VKEY_ESCAPE && current_drag_data_) {
WebMouseEvent event(WebInputEvent::Type::kMouseDown,
ModifiersForPointer(kRawMousePointerId),
GetCurrentEventTime());
Expand Down Expand Up @@ -2001,10 +2001,10 @@ void EventSender::SetTouchCancelable(bool cancelable) {
}

void EventSender::DumpFilenameBeingDragged() {
if (current_drag_data_.IsNull())
if (!current_drag_data_)
return;

WebVector<WebDragData::Item> items = current_drag_data_.Items();
WebVector<WebDragData::Item> items = current_drag_data_->Items();
for (size_t i = 0; i < items.size(); ++i) {
if (items[i].storage_type == WebDragData::Item::kStorageTypeBinaryData) {
WebURL url = items[i].binary_data_source_url;
Expand Down Expand Up @@ -2071,7 +2071,7 @@ void EventSender::LeapForward(int milliseconds) {

void EventSender::BeginDragWithItems(
const WebVector<WebDragData::Item>& items) {
if (!current_drag_data_.IsNull()) {
if (current_drag_data_) {
// Nested dragging not supported, fuzzer code a likely culprit.
// Cancel the current drag operation and throw an error.
KeyDown("Escape", 0, DOMKeyLocationStandard);
Expand All @@ -2082,15 +2082,15 @@ void EventSender::BeginDragWithItems(
return;
}

current_drag_data_.Initialize();
current_drag_data_ = blink::WebDragData();
WebVector<WebString> absolute_filenames;
for (size_t i = 0; i < items.size(); ++i) {
current_drag_data_.AddItem(items[i]);
current_drag_data_->AddItem(items[i]);
if (items[i].storage_type == WebDragData::Item::kStorageTypeFilename)
absolute_filenames.emplace_back(items[i].filename_data);
}
if (!absolute_filenames.empty()) {
current_drag_data_.SetFilesystemId(
current_drag_data_->SetFilesystemId(
blink_test_runner()->RegisterIsolatedFileSystem(absolute_filenames));
}
current_drag_effects_allowed_ = blink::kWebDragOperationCopy;
Expand All @@ -2099,7 +2099,8 @@ void EventSender::BeginDragWithItems(
current_pointer_state_[kRawMousePointerId].last_pos_;

// Provide a drag source.
MainFrameWidget()->DragTargetDragEnter(current_drag_data_, last_pos, last_pos,
MainFrameWidget()->DragTargetDragEnter(*current_drag_data_, last_pos,
last_pos,
current_drag_effects_allowed_, 0);
// |is_drag_mode_| saves events and then replays them later. We don't
// need/want that.
Expand Down Expand Up @@ -2629,8 +2630,7 @@ void EventSender::GestureEvent(WebInputEvent::Type type,
WebInputEventResult result = HandleInputEventOnViewOrPopup(event);

// Long press might start a drag drop session. Complete it if so.
if (type == WebInputEvent::Type::kGestureLongPress &&
!current_drag_data_.IsNull()) {
if (type == WebInputEvent::Type::kGestureLongPress && current_drag_data_) {
WebMouseEvent mouse_event(WebInputEvent::Type::kMouseDown,
ModifiersForPointer(kRawMousePointerId),
GetCurrentEventTime());
Expand Down Expand Up @@ -2804,12 +2804,12 @@ void EventSender::FinishDragAndDrop(const WebMouseEvent& event,
// Specifically pass any keyboard modifiers to the drop method. This allows
// tests to control the drop type (i.e. copy or move).
MainFrameWidget()->DragTargetDrop(
current_drag_data_, event.PositionInWidget(), event.PositionInScreen(),
*current_drag_data_, event.PositionInWidget(), event.PositionInScreen(),
event.GetModifiers());
} else {
MainFrameWidget()->DragTargetDragLeave(gfx::PointF(), gfx::PointF());
}
current_drag_data_.Reset();
current_drag_data_ = base::nullopt;
MainFrameWidget()->DragSourceEndedAt(
event.PositionInWidget(), event.PositionInScreen(), current_drag_effect_);
MainFrameWidget()->DragSourceSystemDragEnded();
Expand All @@ -2820,15 +2820,15 @@ void EventSender::DoDragAfterMouseUp(const WebMouseEvent& event) {
last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_;

// If we're in a drag operation, complete it.
if (current_drag_data_.IsNull())
if (!current_drag_data_)
return;

blink::WebDragOperation drag_effect = MainFrameWidget()->DragTargetDragOver(
event.PositionInWidget(), event.PositionInScreen(),
current_drag_effects_allowed_, event.GetModifiers());

// Bail if dragover caused cancellation.
if (current_drag_data_.IsNull())
if (!current_drag_data_)
return;

FinishDragAndDrop(event, drag_effect);
Expand All @@ -2837,7 +2837,7 @@ void EventSender::DoDragAfterMouseUp(const WebMouseEvent& event) {
void EventSender::DoDragAfterMouseMove(const WebMouseEvent& event) {
if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
WebMouseEvent::Button::kNoButton ||
current_drag_data_.IsNull()) {
!current_drag_data_) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion content/shell/renderer/web_test/event_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "third_party/blink/public/common/input/web_input_event.h"
Expand Down Expand Up @@ -295,7 +296,7 @@ class EventSender {

std::unique_ptr<blink::WebContextMenuData> last_context_menu_data_;

blink::WebDragData current_drag_data_;
base::Optional<blink::WebDragData> current_drag_data_;

// Location of the touch point that initiated a gesture.
gfx::PointF current_gesture_location_;
Expand Down
10 changes: 1 addition & 9 deletions third_party/blink/public/platform/web_drag_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WebDragData {
WebString file_system_id;
};

WebDragData() : valid_(false), modifier_key_state_(0) {}
WebDragData() : modifier_key_state_(0) {}

WebDragData(const WebDragData& object) = default;

Expand All @@ -105,13 +105,6 @@ class WebDragData {
// Instead, use SwapItems.
void SwapItems(WebVector<Item>& item_list) { item_list_.Swap(item_list); }

void Initialize() { valid_ = true; }
bool IsNull() const { return !valid_; }
void Reset() {
item_list_ = WebVector<Item>();
valid_ = false;
}

BLINK_PLATFORM_EXPORT void AddItem(const Item&);

WebString FilesystemId() const { return filesystem_id_; }
Expand All @@ -126,7 +119,6 @@ class WebDragData {
void SetModifierKeyState(int state) { modifier_key_state_ = state; }

private:
bool valid_;
WebVector<Item> item_list_;
int modifier_key_state_; // State of Shift/Ctrl/Alt/Meta keys.
WebString filesystem_id_;
Expand Down
1 change: 0 additions & 1 deletion third_party/blink/renderer/core/clipboard/data_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ DataObject* DataObject::Create(WebDragData data) {

WebDragData DataObject::ToWebDragData() {
WebDragData data;
data.Initialize();
data.SetModifierKeyState(modifiers_);
WebVector<WebDragData::Item> item_list(length());

Expand Down
2 changes: 0 additions & 2 deletions third_party/blink/renderer/core/exported/web_view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2596,8 +2596,6 @@ TEST_F(WebViewTest, PrintWithXHRInFlight) {

static void DragAndDropURL(WebViewImpl* web_view, const std::string& url) {
WebDragData drag_data;
drag_data.Initialize();

WebDragData::Item item;
item.storage_type = WebDragData::Item::kStorageTypeString;
item.string_type = "text/uri-list";
Expand Down
2 changes: 0 additions & 2 deletions third_party/blink/renderer/platform/exported/web_drag_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
namespace blink {

void WebDragData::SetItems(WebVector<Item> item_list) {
DCHECK(!IsNull());
item_list_.Swap(item_list);
}

void WebDragData::AddItem(const Item& item) {
DCHECK(!IsNull());
WebVector<Item> item_list(item_list_.size() + 1);

for (unsigned i = 0; i < item_list_.size(); ++i)
Expand Down

0 comments on commit 85095e5

Please sign in to comment.