OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_X_SELECTION_OWNER_H_ | 5 #ifndef UI_BASE_X_SELECTION_OWNER_H_ |
6 #define UI_BASE_X_SELECTION_OWNER_H_ | 6 #define UI_BASE_X_SELECTION_OWNER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "ui/base/ui_base_export.h" | 17 #include "ui/base/ui_base_export.h" |
18 #include "ui/base/x/selection_utils.h" | 18 #include "ui/base/x/selection_utils.h" |
19 #include "ui/gfx/x/x11_atom_cache.h" | 19 #include "ui/gfx/x/x11_atom_cache.h" |
20 #include "ui/gfx/x/x11_types.h" | 20 #include "ui/gfx/x/x11_types.h" |
21 | 21 |
22 namespace ui { | 22 namespace ui { |
23 | 23 |
24 class XScopedEventSelector; | |
25 | |
26 // Owns a specific X11 selection on an X window. | 24 // Owns a specific X11 selection on an X window. |
27 // | 25 // |
28 // The selection owner object keeps track of which xwindow is the current | 26 // The selection owner object keeps track of which xwindow is the current |
29 // owner, and when its |xwindow_|, offers different data types to other | 27 // owner, and when its |xwindow_|, offers different data types to other |
30 // processes. | 28 // processes. |
31 class UI_BASE_EXPORT SelectionOwner { | 29 class UI_BASE_EXPORT SelectionOwner { |
32 public: | 30 public: |
33 SelectionOwner(XDisplay* xdisplay, | 31 SelectionOwner(XDisplay* xdisplay, |
34 XID xwindow, | 32 XID xwindow, |
35 XAtom selection_name); | 33 XAtom selection_name); |
(...skipping 24 matching lines...) Expand all Loading... |
60 void OnPropertyEvent(const XEvent& event); | 58 void OnPropertyEvent(const XEvent& event); |
61 | 59 |
62 private: | 60 private: |
63 // Holds state related to an incremental data transfer. | 61 // Holds state related to an incremental data transfer. |
64 struct IncrementalTransfer { | 62 struct IncrementalTransfer { |
65 IncrementalTransfer(XID window, | 63 IncrementalTransfer(XID window, |
66 XAtom target, | 64 XAtom target, |
67 XAtom property, | 65 XAtom property, |
68 const scoped_refptr<base::RefCountedMemory>& data, | 66 const scoped_refptr<base::RefCountedMemory>& data, |
69 int offset, | 67 int offset, |
70 base::TimeTicks timeout); | 68 base::TimeTicks timeout, |
| 69 int foreign_window_manager_id); |
71 IncrementalTransfer(const IncrementalTransfer& other); | 70 IncrementalTransfer(const IncrementalTransfer& other); |
72 ~IncrementalTransfer(); | 71 ~IncrementalTransfer(); |
73 | 72 |
74 // Parameters from the XSelectionRequest. The data is transferred over | 73 // Parameters from the XSelectionRequest. The data is transferred over |
75 // |property| on |window|. | 74 // |property| on |window|. |
76 XID window; | 75 XID window; |
77 XAtom target; | 76 XAtom target; |
78 XAtom property; | 77 XAtom property; |
79 | 78 |
80 // The data to be transferred. | 79 // The data to be transferred. |
81 scoped_refptr<base::RefCountedMemory> data; | 80 scoped_refptr<base::RefCountedMemory> data; |
82 | 81 |
83 // The offset from the beginning of |data| of the first byte to be | 82 // The offset from the beginning of |data| of the first byte to be |
84 // transferred in the next chunk. | 83 // transferred in the next chunk. |
85 size_t offset; | 84 size_t offset; |
86 | 85 |
87 // Time when the transfer should be aborted because the selection requestor | 86 // Time when the transfer should be aborted because the selection requestor |
88 // is taking too long to notify us that we can send the next chunk. | 87 // is taking too long to notify us that we can send the next chunk. |
89 base::TimeTicks timeout; | 88 base::TimeTicks timeout; |
| 89 |
| 90 // Used to unselect PropertyChangeMask on |window| when we are done with |
| 91 // the data transfer. |
| 92 int foreign_window_manager_id; |
90 }; | 93 }; |
91 | 94 |
92 // Attempts to convert the selection to |target|. If the conversion is | 95 // Attempts to convert the selection to |target|. If the conversion is |
93 // successful, true is returned and the result is stored in the |property| | 96 // successful, true is returned and the result is stored in the |property| |
94 // of |requestor|. | 97 // of |requestor|. |
95 bool ProcessTarget(XAtom target, XID requestor, XAtom property); | 98 bool ProcessTarget(XAtom target, XID requestor, XAtom property); |
96 | 99 |
97 // Sends the next chunk of data for given the incremental data transfer. | 100 // Sends the next chunk of data for given the incremental data transfer. |
98 void ProcessIncrementalTransfer(IncrementalTransfer* transfer); | 101 void ProcessIncrementalTransfer(IncrementalTransfer* transfer); |
99 | 102 |
100 // Aborts any incremental data transfers which have timed out. | 103 // Aborts any incremental data transfers which have timed out. |
101 void AbortStaleIncrementalTransfers(); | 104 void AbortStaleIncrementalTransfers(); |
102 | 105 |
103 // Called when the transfer at |it| has completed to do cleanup. | 106 // Called when the transfer at |it| has completed to do cleanup. |
104 void CompleteIncrementalTransfer( | 107 void CompleteIncrementalTransfer( |
105 std::vector<IncrementalTransfer>::iterator it); | 108 std::vector<IncrementalTransfer>::iterator it); |
106 | 109 |
107 // Returns the incremental data transfer, if any, which was waiting for | 110 // Returns the incremental data transfer, if any, which was waiting for |
108 // |event|. | 111 // |event|. |
109 std::vector<IncrementalTransfer>::iterator FindIncrementalTransferForEvent( | 112 std::vector<IncrementalTransfer>::iterator FindIncrementalTransferForEvent( |
110 const XEvent& event); | 113 const XEvent& event); |
111 | 114 |
112 // Our X11 state. | 115 // Our X11 state. |
113 XDisplay* x_display_; | 116 XDisplay* x_display_; |
114 XID x_window_; | 117 XID x_window_; |
115 | 118 |
116 // Events selected on the requesting window. | |
117 std::unique_ptr<XScopedEventSelector> requestor_events_; | |
118 | |
119 // The X11 selection that this instance communicates on. | 119 // The X11 selection that this instance communicates on. |
120 XAtom selection_name_; | 120 XAtom selection_name_; |
121 | 121 |
122 // The time that this instance took ownership of its selection. | 122 // The time that this instance took ownership of its selection. |
123 Time acquired_selection_timestamp_; | 123 Time acquired_selection_timestamp_; |
124 | 124 |
125 // The maximum size of data we can put in XChangeProperty(). | 125 // The maximum size of data we can put in XChangeProperty(). |
126 size_t max_request_size_; | 126 size_t max_request_size_; |
127 | 127 |
128 // The data we are currently serving. | 128 // The data we are currently serving. |
129 SelectionFormatMap format_map_; | 129 SelectionFormatMap format_map_; |
130 | 130 |
131 std::vector<IncrementalTransfer> incremental_transfers_; | 131 std::vector<IncrementalTransfer> incremental_transfers_; |
132 | 132 |
133 // Used to abort stale incremental data transfers. | 133 // Used to abort stale incremental data transfers. |
134 base::RepeatingTimer incremental_transfer_abort_timer_; | 134 base::RepeatingTimer incremental_transfer_abort_timer_; |
135 | 135 |
136 X11AtomCache atom_cache_; | 136 X11AtomCache atom_cache_; |
137 | 137 |
138 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); | 138 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); |
139 }; | 139 }; |
140 | 140 |
141 } // namespace ui | 141 } // namespace ui |
142 | 142 |
143 #endif // UI_BASE_X_SELECTION_OWNER_H_ | 143 #endif // UI_BASE_X_SELECTION_OWNER_H_ |
OLD | NEW |