| Index: services/ui/ws/window_tree.cc
|
| diff --git a/services/ui/ws/window_tree.cc b/services/ui/ws/window_tree.cc
|
| index 4b5e7498f6b69c0d5f4cff8d3b71779087c0f6f0..5b9bc168e8eb5093fd35ea5bdf22ceafd87609ab 100644
|
| --- a/services/ui/ws/window_tree.cc
|
| +++ b/services/ui/ws/window_tree.cc
|
| @@ -12,6 +12,7 @@
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/stl_util.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| #include "services/ui/ws/default_access_policy.h"
|
| #include "services/ui/ws/display.h"
|
| #include "services/ui/ws/display_manager.h"
|
| @@ -973,16 +974,35 @@ void WindowTree::DispatchInputEventImpl(ServerWindow* target,
|
| event_source_wms_ = display_root->window_manager_state();
|
| // Should only get events from windows attached to a host.
|
| DCHECK(event_source_wms_);
|
| - bool matched_observer =
|
| - event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event);
|
| + mojo::Array<uint32_t> event_observer_ids;
|
| + std::map<uint32_t, std::unique_ptr<EventMatcher>>::iterator it;
|
| + for (it = event_observer_matchers_.begin();
|
| + it != event_observer_matchers_.end(); ++it) {
|
| + bool matched_observer = it->second->MatchesEvent(event);
|
| + if (matched_observer) {
|
| + event_observer_ids.push_back(it->first);
|
| + } else {
|
| + event_observer_ids.push_back(0);
|
| + }
|
| + }
|
| client()->OnWindowInputEvent(
|
| event_ack_id_, ClientWindowIdForWindow(target).id,
|
| - ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0);
|
| + ui::Event::Clone(event), std::move(event_observer_ids));
|
| }
|
|
|
| void WindowTree::SendToEventObserver(const ui::Event& event) {
|
| - if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event))
|
| - client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_);
|
| + mojo::Array<uint32_t> event_observer_ids;
|
| + std::map<uint32_t, std::unique_ptr<EventMatcher>>::iterator it;
|
| + for (it = event_observer_matchers_.begin();
|
| + it != event_observer_matchers_.end(); ++it) {
|
| + if(it->second->MatchesEvent(event)) {
|
| + event_observer_ids.push_back(it->first);
|
| + }
|
| + }
|
| + if (!event_observer_ids.empty()) {
|
| + client()->OnEventObserved(ui::Event::Clone(event),
|
| + std::move(event_observer_ids));
|
| + }
|
| }
|
|
|
| void WindowTree::NewWindow(
|
| @@ -1146,31 +1166,43 @@ void WindowTree::ReleaseCapture(uint32_t change_id, Id window_id) {
|
| client()->OnChangeCompleted(change_id, success);
|
| }
|
|
|
| -void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher,
|
| +void WindowTree::AddEventObserver(mojom::EventMatcherPtr matcher,
|
| uint32_t observer_id) {
|
| if (matcher.is_null() || observer_id == 0) {
|
| - // Clear any existing event observer.
|
| - event_observer_matcher_.reset();
|
| - event_observer_id_ = 0;
|
| return;
|
| }
|
|
|
| // Do not allow key events to be observed, as a compromised app could register
|
| // itself as an event observer and spy on keystrokes to another app.
|
| - if (!matcher->type_matcher) {
|
| + if (!matcher->type_matcher && !matcher->pointer_kind_matcher) {
|
| DVLOG(1) << "SetEventObserver must specify an event type.";
|
| return;
|
| }
|
| +
|
| const ui::mojom::EventType event_type_whitelist[] = {
|
| ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN,
|
| ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP,
|
| ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL,
|
| };
|
| + const ui::mojom::PointerKind pointer_kind_whitelist[] = {
|
| + ui::mojom::PointerKind::MOUSE, ui::mojom::PointerKind::TOUCH,
|
| + };
|
| +
|
| bool allowed = false;
|
| - for (ui::mojom::EventType event_type : event_type_whitelist) {
|
| - if (matcher->type_matcher->type == event_type) {
|
| - allowed = true;
|
| - break;
|
| + if (matcher->type_matcher) {
|
| + for (ui::mojom::EventType event_type : event_type_whitelist) {
|
| + if (matcher->type_matcher->type == event_type) {
|
| + allowed = true;
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + if (matcher->pointer_kind_matcher) {
|
| + for (ui::mojom::PointerKind pointer : pointer_kind_whitelist) {
|
| + if (matcher->pointer_kind_matcher->pointer_kind == pointer) {
|
| + allowed = true;
|
| + break;
|
| + }
|
| }
|
| }
|
| if (!allowed) {
|
| @@ -1178,8 +1210,16 @@ void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher,
|
| return;
|
| }
|
|
|
| - event_observer_matcher_.reset(new EventMatcher(*matcher));
|
| - event_observer_id_ = observer_id;
|
| + std::unique_ptr<EventMatcher> event_observer_matcher;
|
| + event_observer_matcher.reset(new EventMatcher(*matcher));
|
| + event_observer_matchers_[observer_id] = std::move(event_observer_matcher);
|
| +}
|
| +
|
| +void WindowTree::RemoveEventObserver(uint32_t observer_id) {
|
| + std::map<uint32_t, std::unique_ptr<EventMatcher>>::iterator it =
|
| + event_observer_matchers_.find(observer_id);
|
| + if (it != event_observer_matchers_.end())
|
| + event_observer_matchers_.erase(it);
|
| }
|
|
|
| void WindowTree::SetWindowBounds(uint32_t change_id,
|
|
|