-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_exchange_data_provider_aura.cc
196 lines (159 loc) · 5.15 KB
/
os_exchange_data_provider_aura.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/dragdrop/os_exchange_data_provider_aura.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/net_util.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
namespace ui {
OSExchangeDataProviderAura::OSExchangeDataProviderAura()
: formats_(0) {
}
OSExchangeDataProviderAura::~OSExchangeDataProviderAura() {}
OSExchangeData::Provider* OSExchangeDataProviderAura::Clone() const {
OSExchangeDataProviderAura* ret = new OSExchangeDataProviderAura();
ret->formats_ = formats_;
ret->string_ = string_;
ret->url_ = url_;
ret->title_ = title_;
ret->filenames_ = filenames_;
ret->pickle_data_ = pickle_data_;
// We skip copying the drag images.
ret->html_ = html_;
ret->base_url_ = base_url_;
return ret;
}
void OSExchangeDataProviderAura::SetString(const base::string16& data) {
string_ = data;
formats_ |= OSExchangeData::STRING;
}
void OSExchangeDataProviderAura::SetURL(const GURL& url,
const base::string16& title) {
url_ = url;
title_ = title;
formats_ |= OSExchangeData::URL;
SetString(UTF8ToUTF16(url.spec()));
}
void OSExchangeDataProviderAura::SetFilename(const base::FilePath& path) {
filenames_.clear();
filenames_.push_back(OSExchangeData::FileInfo(path, base::FilePath()));
formats_ |= OSExchangeData::FILE_NAME;
}
void OSExchangeDataProviderAura::SetFilenames(
const std::vector<OSExchangeData::FileInfo>& filenames) {
filenames_ = filenames;
formats_ |= OSExchangeData::FILE_NAME;
}
void OSExchangeDataProviderAura::SetPickledData(
const OSExchangeData::CustomFormat& format,
const Pickle& data) {
pickle_data_[format] = data;
formats_ |= OSExchangeData::PICKLED_DATA;
}
bool OSExchangeDataProviderAura::GetString(base::string16* data) const {
if ((formats_ & OSExchangeData::STRING) == 0)
return false;
*data = string_;
return true;
}
bool OSExchangeDataProviderAura::GetURLAndTitle(GURL* url,
base::string16* title) const {
if ((formats_ & OSExchangeData::URL) == 0) {
title->clear();
return GetPlainTextURL(url);
}
if (!url_.is_valid())
return false;
*url = url_;
*title = title_;
return true;
}
bool OSExchangeDataProviderAura::GetFilename(base::FilePath* path) const {
if ((formats_ & OSExchangeData::FILE_NAME) == 0)
return false;
DCHECK(!filenames_.empty());
*path = filenames_[0].path;
return true;
}
bool OSExchangeDataProviderAura::GetFilenames(
std::vector<OSExchangeData::FileInfo>* filenames) const {
if ((formats_ & OSExchangeData::FILE_NAME) == 0)
return false;
*filenames = filenames_;
return true;
}
bool OSExchangeDataProviderAura::GetPickledData(
const OSExchangeData::CustomFormat& format,
Pickle* data) const {
PickleData::const_iterator i = pickle_data_.find(format);
if (i == pickle_data_.end())
return false;
*data = i->second;
return true;
}
bool OSExchangeDataProviderAura::HasString() const {
return (formats_ & OSExchangeData::STRING) != 0;
}
bool OSExchangeDataProviderAura::HasURL() const {
if ((formats_ & OSExchangeData::URL) != 0) {
return true;
}
// No URL, see if we have plain text that can be parsed as a URL.
return GetPlainTextURL(NULL);
}
bool OSExchangeDataProviderAura::HasFile() const {
return (formats_ & OSExchangeData::FILE_NAME) != 0;
}
bool OSExchangeDataProviderAura::HasCustomFormat(
const OSExchangeData::CustomFormat& format) const {
return pickle_data_.find(format) != pickle_data_.end();
}
void OSExchangeDataProviderAura::SetHtml(const base::string16& html,
const GURL& base_url) {
formats_ |= OSExchangeData::HTML;
html_ = html;
base_url_ = base_url;
}
bool OSExchangeDataProviderAura::GetHtml(base::string16* html,
GURL* base_url) const {
if ((formats_ & OSExchangeData::HTML) == 0)
return false;
*html = html_;
*base_url = base_url_;
return true;
}
bool OSExchangeDataProviderAura::HasHtml() const {
return ((formats_ & OSExchangeData::HTML) != 0);
}
void OSExchangeDataProviderAura::SetDragImage(
const gfx::ImageSkia& image,
const gfx::Vector2d& cursor_offset) {
drag_image_ = image;
drag_image_offset_ = cursor_offset;
}
const gfx::ImageSkia& OSExchangeDataProviderAura::GetDragImage() const {
return drag_image_;
}
const gfx::Vector2d&
OSExchangeDataProviderAura::GetDragImageOffset() const {
return drag_image_offset_;
}
bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const {
if ((formats_ & OSExchangeData::STRING) == 0)
return false;
GURL test_url(string_);
if (!test_url.is_valid())
return false;
if (url)
*url = test_url;
return true;
}
///////////////////////////////////////////////////////////////////////////////
// OSExchangeData, public:
// static
OSExchangeData::Provider* OSExchangeData::CreateProvider() {
return new OSExchangeDataProviderAura();
}
} // namespace ui