Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1087)

Side by Side Diff: ui/base/x/selection_requestor.cc

Issue 17029020: linux_aura: Redo how memory is handled in clipboard/drag code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes for sky; ptal Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/x/selection_requestor.h ('k') | ui/base/x/selection_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/base/x/selection_requestor.h" 5 #include "ui/base/x/selection_requestor.h"
6 6
7 #include "base/message_loop/message_pump_aurax11.h" 7 #include "base/message_loop/message_pump_aurax11.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "ui/base/x/selection_utils.h" 9 #include "ui/base/x/selection_utils.h"
10 #include "ui/base/x/x11_util.h" 10 #include "ui/base/x/x11_util.h"
(...skipping 20 matching lines...) Expand all
31 selection_name_(selection_name), 31 selection_name_(selection_name),
32 current_target_(None), 32 current_target_(None),
33 returned_property_(None), 33 returned_property_(None),
34 atom_cache_(x_display_, kAtomsToCache) { 34 atom_cache_(x_display_, kAtomsToCache) {
35 } 35 }
36 36
37 SelectionRequestor::~SelectionRequestor() {} 37 SelectionRequestor::~SelectionRequestor() {}
38 38
39 bool SelectionRequestor::PerformBlockingConvertSelection( 39 bool SelectionRequestor::PerformBlockingConvertSelection(
40 Atom target, 40 Atom target,
41 unsigned char** out_data, 41 scoped_refptr<base::RefCountedMemory>* out_data,
42 size_t* out_data_bytes, 42 size_t* out_data_bytes,
43 size_t* out_data_items, 43 size_t* out_data_items,
44 Atom* out_type) { 44 Atom* out_type) {
45 // The name of the property we're asking to be set on |x_window_|. 45 // The name of the property we're asking to be set on |x_window_|.
46 Atom property_to_set = atom_cache_.GetAtom(kChromeSelection); 46 Atom property_to_set = atom_cache_.GetAtom(kChromeSelection);
47 47
48 XConvertSelection(x_display_, 48 XConvertSelection(x_display_,
49 selection_name_, 49 selection_name_,
50 target, 50 target,
51 property_to_set, 51 property_to_set,
(...skipping 14 matching lines...) Expand all
66 current_target_ = None; 66 current_target_ = None;
67 67
68 if (returned_property_ != property_to_set) 68 if (returned_property_ != property_to_set)
69 return false; 69 return false;
70 70
71 return ui::GetRawBytesOfProperty(x_window_, returned_property_, 71 return ui::GetRawBytesOfProperty(x_window_, returned_property_,
72 out_data, out_data_bytes, out_data_items, 72 out_data, out_data_bytes, out_data_items,
73 out_type); 73 out_type);
74 } 74 }
75 75
76 scoped_ptr<SelectionData> SelectionRequestor::RequestAndWaitForTypes( 76 SelectionData SelectionRequestor::RequestAndWaitForTypes(
77 const std::vector< ::Atom>& types) { 77 const std::vector< ::Atom>& types) {
78 for (std::vector< ::Atom>::const_iterator it = types.begin(); 78 for (std::vector< ::Atom>::const_iterator it = types.begin();
79 it != types.end(); ++it) { 79 it != types.end(); ++it) {
80 unsigned char* data = NULL; 80 scoped_refptr<base::RefCountedMemory> data;
81 size_t data_bytes = 0; 81 size_t data_bytes = 0;
82 ::Atom type = None; 82 ::Atom type = None;
83 if (PerformBlockingConvertSelection(*it, 83 if (PerformBlockingConvertSelection(*it,
84 &data, 84 &data,
85 &data_bytes, 85 &data_bytes,
86 NULL, 86 NULL,
87 &type) && 87 &type) &&
88 type == *it) { 88 type == *it) {
89 scoped_ptr<SelectionData> data_out(new SelectionData); 89 return SelectionData(type, data);
90 data_out->Set(type, (char*)data, data_bytes, true);
91 return data_out.Pass();
92 } 90 }
93 } 91 }
94 92
95 return scoped_ptr<SelectionData>(); 93 return SelectionData();
96 } 94 }
97 95
98 void SelectionRequestor::OnSelectionNotify(const XSelectionEvent& event) { 96 void SelectionRequestor::OnSelectionNotify(const XSelectionEvent& event) {
99 if (!in_nested_loop_) { 97 if (!in_nested_loop_) {
100 // This shouldn't happen; we're not waiting on the X server for data, but 98 // This shouldn't happen; we're not waiting on the X server for data, but
101 // any client can send any message... 99 // any client can send any message...
102 return; 100 return;
103 } 101 }
104 102
105 if (selection_name_ == event.selection && 103 if (selection_name_ == event.selection &&
106 current_target_ == event.target) { 104 current_target_ == event.target) {
107 returned_property_ = event.property; 105 returned_property_ = event.property;
108 } else { 106 } else {
109 // I am assuming that if some other client sent us a message after we've 107 // I am assuming that if some other client sent us a message after we've
110 // asked for data, but it's malformed, we should just treat as if they sent 108 // asked for data, but it's malformed, we should just treat as if they sent
111 // us an error message. 109 // us an error message.
112 returned_property_ = None; 110 returned_property_ = None;
113 } 111 }
114 112
115 quit_closure_.Run(); 113 quit_closure_.Run();
116 } 114 }
117 115
118 } // namespace ui 116 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/selection_requestor.h ('k') | ui/base/x/selection_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698