wayland.data_device: Early return on protocol error

This commit is contained in:
Poly 2021-07-25 18:14:21 +02:00 committed by Victor Berger
parent 6856ae891f
commit c136cd5f34
2 changed files with 10 additions and 0 deletions

View File

@ -273,24 +273,28 @@ fn implement_dnd_data_offer(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer that is no longer active.".into(), "Cannot finish a data offer that is no longer active.".into(),
); );
return;
} }
if !data.accepted { if !data.accepted {
offer.as_ref().post_error( offer.as_ref().post_error(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer that has not been accepted.".into(), "Cannot finish a data offer that has not been accepted.".into(),
); );
return;
} }
if !data.dropped { if !data.dropped {
offer.as_ref().post_error( offer.as_ref().post_error(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer that has not been dropped.".into(), "Cannot finish a data offer that has not been dropped.".into(),
); );
return;
} }
if data.chosen_action.is_empty() { if data.chosen_action.is_empty() {
offer.as_ref().post_error( offer.as_ref().post_error(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer with no valid action.".into(), "Cannot finish a data offer with no valid action.".into(),
); );
return;
} }
source.dnd_finished(); source.dnd_finished();
data.active = false; data.active = false;
@ -309,6 +313,7 @@ fn implement_dnd_data_offer(
wl_data_offer::Error::InvalidAction as u32, wl_data_offer::Error::InvalidAction as u32,
"Invalid preferred action.".into(), "Invalid preferred action.".into(),
); );
return;
} }
let source_actions = with_source_metadata(&source, |meta| meta.dnd_action) let source_actions = with_source_metadata(&source, |meta| meta.dnd_action)
.unwrap_or_else(|_| DndAction::empty()); .unwrap_or_else(|_| DndAction::empty());

View File

@ -268,24 +268,28 @@ where
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer that is no longer active.".into(), "Cannot finish a data offer that is no longer active.".into(),
); );
return;
} }
if !data.accepted { if !data.accepted {
offer.as_ref().post_error( offer.as_ref().post_error(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer that has not been accepted.".into(), "Cannot finish a data offer that has not been accepted.".into(),
); );
return;
} }
if !data.dropped { if !data.dropped {
offer.as_ref().post_error( offer.as_ref().post_error(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer that has not been dropped.".into(), "Cannot finish a data offer that has not been dropped.".into(),
); );
return;
} }
if data.chosen_action.is_empty() { if data.chosen_action.is_empty() {
offer.as_ref().post_error( offer.as_ref().post_error(
wl_data_offer::Error::InvalidFinish as u32, wl_data_offer::Error::InvalidFinish as u32,
"Cannot finish a data offer with no valid action.".into(), "Cannot finish a data offer with no valid action.".into(),
); );
return;
} }
(&mut *callback.borrow_mut())(ServerDndEvent::Finished); (&mut *callback.borrow_mut())(ServerDndEvent::Finished);
data.active = false; data.active = false;
@ -304,6 +308,7 @@ where
wl_data_offer::Error::InvalidAction as u32, wl_data_offer::Error::InvalidAction as u32,
"Invalid preferred action.".into(), "Invalid preferred action.".into(),
); );
return;
} }
let possible_actions = metadata.dnd_action & dnd_actions; let possible_actions = metadata.dnd_action & dnd_actions;
data.chosen_action = (&mut *action_choice.borrow_mut())(possible_actions, preferred_action); data.chosen_action = (&mut *action_choice.borrow_mut())(possible_actions, preferred_action);