OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/dragdrop/os_exchange_data_provider_aurax11.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/message_loop/message_pump_aurax11.h" | 9 #include "base/message_loop/message_pump_aurax11.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 std::vector<Atom>* targets) const { | 95 std::vector<Atom>* targets) const { |
96 selection_owner_.RetrieveTargets(targets); | 96 selection_owner_.RetrieveTargets(targets); |
97 } | 97 } |
98 | 98 |
99 SelectionFormatMap OSExchangeDataProviderAuraX11::GetFormatMap() const { | 99 SelectionFormatMap OSExchangeDataProviderAuraX11::GetFormatMap() const { |
100 // We return the |selection_owner_|'s format map instead of our own in case | 100 // We return the |selection_owner_|'s format map instead of our own in case |
101 // ours has been modified since TakeOwnershipOfSelection() was called. | 101 // ours has been modified since TakeOwnershipOfSelection() was called. |
102 return selection_owner_.selection_format_map(); | 102 return selection_owner_.selection_format_map(); |
103 } | 103 } |
104 | 104 |
105 void OSExchangeDataProviderAuraX11::SetString(const string16& text_data) { | 105 void OSExchangeDataProviderAuraX11::SetString(const base::string16& text_data) { |
106 std::string utf8 = UTF16ToUTF8(text_data); | 106 std::string utf8 = UTF16ToUTF8(text_data); |
107 scoped_refptr<base::RefCountedMemory> mem( | 107 scoped_refptr<base::RefCountedMemory> mem( |
108 base::RefCountedString::TakeString(&utf8)); | 108 base::RefCountedString::TakeString(&utf8)); |
109 | 109 |
110 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeText), mem); | 110 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeText), mem); |
111 format_map_.Insert(atom_cache_.GetAtom(kText), mem); | 111 format_map_.Insert(atom_cache_.GetAtom(kText), mem); |
112 format_map_.Insert(atom_cache_.GetAtom(kString), mem); | 112 format_map_.Insert(atom_cache_.GetAtom(kString), mem); |
113 format_map_.Insert(atom_cache_.GetAtom(kUtf8String), mem); | 113 format_map_.Insert(atom_cache_.GetAtom(kUtf8String), mem); |
114 } | 114 } |
115 | 115 |
116 void OSExchangeDataProviderAuraX11::SetURL(const GURL& url, | 116 void OSExchangeDataProviderAuraX11::SetURL(const GURL& url, |
117 const string16& title) { | 117 const base::string16& title) { |
118 NOTIMPLEMENTED(); | 118 NOTIMPLEMENTED(); |
119 } | 119 } |
120 | 120 |
121 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { | 121 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { |
122 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
123 } | 123 } |
124 | 124 |
125 void OSExchangeDataProviderAuraX11::SetFilenames( | 125 void OSExchangeDataProviderAuraX11::SetFilenames( |
126 const std::vector<OSExchangeData::FileInfo>& filenames) { | 126 const std::vector<OSExchangeData::FileInfo>& filenames) { |
127 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
128 } | 128 } |
129 | 129 |
130 void OSExchangeDataProviderAuraX11::SetPickledData( | 130 void OSExchangeDataProviderAuraX11::SetPickledData( |
131 const OSExchangeData::CustomFormat& format, | 131 const OSExchangeData::CustomFormat& format, |
132 const Pickle& data) { | 132 const Pickle& data) { |
133 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
134 } | 134 } |
135 | 135 |
136 bool OSExchangeDataProviderAuraX11::GetString(string16* result) const { | 136 bool OSExchangeDataProviderAuraX11::GetString(base::string16* result) const { |
137 std::vector< ::Atom> text_atoms = ui::GetTextAtomsFrom(&atom_cache_); | 137 std::vector< ::Atom> text_atoms = ui::GetTextAtomsFrom(&atom_cache_); |
138 std::vector< ::Atom> requested_types; | 138 std::vector< ::Atom> requested_types; |
139 ui::GetAtomIntersection(text_atoms, GetTargets(), &requested_types); | 139 ui::GetAtomIntersection(text_atoms, GetTargets(), &requested_types); |
140 | 140 |
141 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 141 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
142 if (data.IsValid()) { | 142 if (data.IsValid()) { |
143 std::string text = data.GetText(); | 143 std::string text = data.GetText(); |
144 *result = UTF8ToUTF16(text); | 144 *result = UTF8ToUTF16(text); |
145 return true; | 145 return true; |
146 } | 146 } |
147 | 147 |
148 return false; | 148 return false; |
149 } | 149 } |
150 | 150 |
151 bool OSExchangeDataProviderAuraX11::GetURLAndTitle(GURL* url, | 151 bool OSExchangeDataProviderAuraX11::GetURLAndTitle( |
152 string16* title) const { | 152 GURL* url, |
| 153 base::string16* title) const { |
153 std::vector< ::Atom> url_atoms = ui::GetURLAtomsFrom(&atom_cache_); | 154 std::vector< ::Atom> url_atoms = ui::GetURLAtomsFrom(&atom_cache_); |
154 std::vector< ::Atom> requested_types; | 155 std::vector< ::Atom> requested_types; |
155 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 156 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
156 | 157 |
157 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 158 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
158 if (data.IsValid()) { | 159 if (data.IsValid()) { |
159 // TODO(erg): Technically, both of these forms can accept multiple URLs, | 160 // TODO(erg): Technically, both of these forms can accept multiple URLs, |
160 // but that doesn't match the assumptions of the rest of the system which | 161 // but that doesn't match the assumptions of the rest of the system which |
161 // expect single types. | 162 // expect single types. |
162 | 163 |
163 if (data.GetType() == atom_cache_.GetAtom(kMimeTypeMozillaURL)) { | 164 if (data.GetType() == atom_cache_.GetAtom(kMimeTypeMozillaURL)) { |
164 // Mozilla URLs are (UTF16: URL, newline, title). | 165 // Mozilla URLs are (UTF16: URL, newline, title). |
165 string16 unparsed; | 166 base::string16 unparsed; |
166 data.AssignTo(&unparsed); | 167 data.AssignTo(&unparsed); |
167 | 168 |
168 std::vector<string16> tokens; | 169 std::vector<base::string16> tokens; |
169 size_t num_tokens = Tokenize(unparsed, ASCIIToUTF16("\n"), &tokens); | 170 size_t num_tokens = Tokenize(unparsed, ASCIIToUTF16("\n"), &tokens); |
170 if (num_tokens >= 2) { | 171 if (num_tokens >= 2) { |
171 *url = GURL(tokens[0]); | 172 *url = GURL(tokens[0]); |
172 *title = tokens[1]; | 173 *title = tokens[1]; |
173 return true; | 174 return true; |
174 } else { | 175 } else { |
175 NOTREACHED() << "Data that claimed to be a Mozilla URL has " | 176 NOTREACHED() << "Data that claimed to be a Mozilla URL has " |
176 << num_tokens << " tokens instead of 2."; | 177 << num_tokens << " tokens instead of 2."; |
177 } | 178 } |
178 } else if (data.GetType() == atom_cache_.GetAtom( | 179 } else if (data.GetType() == atom_cache_.GetAtom( |
179 Clipboard::kMimeTypeURIList)) { | 180 Clipboard::kMimeTypeURIList)) { |
180 // uri-lists are newline separated file lists in URL encoding. | 181 // uri-lists are newline separated file lists in URL encoding. |
181 std::string unparsed; | 182 std::string unparsed; |
182 data.AssignTo(&unparsed); | 183 data.AssignTo(&unparsed); |
183 | 184 |
184 std::vector<std::string> tokens; | 185 std::vector<std::string> tokens; |
185 size_t num_tokens = Tokenize(unparsed, "\n", &tokens); | 186 size_t num_tokens = Tokenize(unparsed, "\n", &tokens); |
186 if (!num_tokens) { | 187 if (!num_tokens) { |
187 NOTREACHED() << "Empty URI list"; | 188 NOTREACHED() << "Empty URI list"; |
188 return false; | 189 return false; |
189 } | 190 } |
190 | 191 |
191 *url = GURL(tokens[0]); | 192 *url = GURL(tokens[0]); |
192 *title = string16(); | 193 *title = base::string16(); |
193 | 194 |
194 return true; | 195 return true; |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 return false; | 199 return false; |
199 } | 200 } |
200 | 201 |
201 bool OSExchangeDataProviderAuraX11::GetFilename(base::FilePath* path) const { | 202 bool OSExchangeDataProviderAuraX11::GetFilename(base::FilePath* path) const { |
202 // On X11, files are passed by URL and aren't separate. | 203 // On X11, files are passed by URL and aren't separate. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 bool OSExchangeDataProviderAuraX11::HasCustomFormat( | 239 bool OSExchangeDataProviderAuraX11::HasCustomFormat( |
239 const OSExchangeData::CustomFormat& format) const { | 240 const OSExchangeData::CustomFormat& format) const { |
240 std::vector< ::Atom> url_atoms; | 241 std::vector< ::Atom> url_atoms; |
241 url_atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); | 242 url_atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); |
242 std::vector< ::Atom> requested_types; | 243 std::vector< ::Atom> requested_types; |
243 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 244 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
244 | 245 |
245 return !requested_types.empty(); | 246 return !requested_types.empty(); |
246 } | 247 } |
247 | 248 |
248 void OSExchangeDataProviderAuraX11::SetHtml(const string16& html, | 249 void OSExchangeDataProviderAuraX11::SetHtml(const base::string16& html, |
249 const GURL& base_url) { | 250 const GURL& base_url) { |
250 NOTIMPLEMENTED(); | 251 NOTIMPLEMENTED(); |
251 } | 252 } |
252 | 253 |
253 bool OSExchangeDataProviderAuraX11::GetHtml(string16* html, | 254 bool OSExchangeDataProviderAuraX11::GetHtml(base::string16* html, |
254 GURL* base_url) const { | 255 GURL* base_url) const { |
255 std::vector< ::Atom> url_atoms; | 256 std::vector< ::Atom> url_atoms; |
256 url_atoms.push_back(atom_cache_.GetAtom(Clipboard::kMimeTypeHTML)); | 257 url_atoms.push_back(atom_cache_.GetAtom(Clipboard::kMimeTypeHTML)); |
257 std::vector< ::Atom> requested_types; | 258 std::vector< ::Atom> requested_types; |
258 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 259 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
259 | 260 |
260 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 261 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
261 if (data.IsValid()) { | 262 if (data.IsValid()) { |
262 *html = data.GetHtml(); | 263 *html = data.GetHtml(); |
263 *base_url = GURL(); | 264 *base_url = GURL(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 316 |
316 /////////////////////////////////////////////////////////////////////////////// | 317 /////////////////////////////////////////////////////////////////////////////// |
317 // OSExchangeData, public: | 318 // OSExchangeData, public: |
318 | 319 |
319 // static | 320 // static |
320 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 321 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
321 return new OSExchangeDataProviderAuraX11(); | 322 return new OSExchangeDataProviderAuraX11(); |
322 } | 323 } |
323 | 324 |
324 } // namespace ui | 325 } // namespace ui |
OLD | NEW |