OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/net_util.h" |
8 | 10 |
9 namespace ui { | 11 namespace ui { |
10 | 12 |
11 // OSExchangeData::Provider implementation for aura on linux. | 13 OSExchangeDataProviderAura::OSExchangeDataProviderAura() : formats_(0) {} |
12 class OSExchangeDataProviderAura : public OSExchangeData::Provider { | 14 |
13 public: | 15 void OSExchangeDataProviderAura::SetString(const string16& data) { |
14 OSExchangeDataProviderAura() { | 16 string_ = data; |
| 17 formats_ |= OSExchangeData::STRING; |
| 18 } |
| 19 |
| 20 void OSExchangeDataProviderAura::SetURL(const GURL& url, |
| 21 const string16& title) { |
| 22 url_ = url; |
| 23 title_ = title; |
| 24 formats_ |= OSExchangeData::URL; |
| 25 } |
| 26 |
| 27 void OSExchangeDataProviderAura::SetFilename(const FilePath& path) { |
| 28 filename_ = path; |
| 29 formats_ |= OSExchangeData::FILE_NAME; |
| 30 } |
| 31 |
| 32 void OSExchangeDataProviderAura::SetPickledData( |
| 33 OSExchangeData::CustomFormat format, |
| 34 const Pickle& data) { |
| 35 pickle_data_[format] = data; |
| 36 formats_ |= OSExchangeData::PICKLED_DATA; |
| 37 } |
| 38 |
| 39 bool OSExchangeDataProviderAura::GetString(string16* data) const { |
| 40 if ((formats_ & OSExchangeData::STRING) == 0) |
| 41 return false; |
| 42 *data = string_; |
| 43 return true; |
| 44 } |
| 45 |
| 46 bool OSExchangeDataProviderAura::GetURLAndTitle(GURL* url, |
| 47 string16* title) const { |
| 48 if ((formats_ & OSExchangeData::URL) == 0) { |
| 49 title->clear(); |
| 50 return GetPlainTextURL(url); |
| 51 } |
| 52 |
| 53 if (!url_.is_valid()) |
| 54 return false; |
| 55 |
| 56 *url = url_; |
| 57 *title = title_; |
| 58 return true; |
| 59 } |
| 60 |
| 61 bool OSExchangeDataProviderAura::GetFilename(FilePath* path) const { |
| 62 if ((formats_ & OSExchangeData::FILE_NAME) == 0) |
| 63 return false; |
| 64 *path = filename_; |
| 65 return true; |
| 66 } |
| 67 |
| 68 bool OSExchangeDataProviderAura::GetPickledData( |
| 69 OSExchangeData::CustomFormat format, |
| 70 Pickle* data) const { |
| 71 PickleData::const_iterator i = pickle_data_.find(format); |
| 72 if (i == pickle_data_.end()) |
| 73 return false; |
| 74 |
| 75 *data = i->second; |
| 76 return true; |
| 77 } |
| 78 |
| 79 bool OSExchangeDataProviderAura::HasString() const { |
| 80 return (formats_ & OSExchangeData::STRING) != 0; |
| 81 } |
| 82 |
| 83 bool OSExchangeDataProviderAura::HasURL() const { |
| 84 if ((formats_ & OSExchangeData::URL) != 0) { |
| 85 return true; |
| 86 } |
| 87 // No URL, see if we have plain text that can be parsed as a URL. |
| 88 return GetPlainTextURL(NULL); |
| 89 } |
| 90 |
| 91 bool OSExchangeDataProviderAura::HasFile() const { |
| 92 return (formats_ & OSExchangeData::FILE_NAME) != 0; |
| 93 } |
| 94 |
| 95 bool OSExchangeDataProviderAura::HasCustomFormat( |
| 96 OSExchangeData::CustomFormat format) const { |
| 97 return pickle_data_.find(format) != pickle_data_.end(); |
| 98 } |
| 99 |
| 100 #if defined(OS_WIN) |
| 101 void OSExchangeDataProviderAura::SetFileContents( |
| 102 const FilePath& filename, |
| 103 const std::string& file_contents) { |
15 NOTIMPLEMENTED(); | 104 NOTIMPLEMENTED(); |
16 } | 105 } |
17 | 106 |
18 virtual ~OSExchangeDataProviderAura() { | 107 void OSExchangeDataProviderAura::SetHtml(const string16& html, |
| 108 const GURL& base_url) { |
| 109 NOTIMPLEMENTED(); |
19 } | 110 } |
20 | 111 |
21 virtual void SetString(const string16& data) OVERRIDE { | 112 bool OSExchangeDataProviderAura::GetFileContents( |
22 } | 113 FilePath* filename, |
23 virtual void SetURL(const GURL& url, const string16& title) OVERRIDE { | 114 std::string* file_contents) const { |
24 } | 115 NOTIMPLEMENTED(); |
25 virtual void SetFilename(const FilePath& path) OVERRIDE { | |
26 } | |
27 virtual void SetPickledData(OSExchangeData::CustomFormat format, | |
28 const Pickle& data) OVERRIDE { | |
29 } | |
30 | |
31 virtual bool GetString(string16* data) const OVERRIDE { | |
32 return false; | |
33 } | |
34 virtual bool GetURLAndTitle(GURL* url, string16* title) const OVERRIDE { | |
35 return false; | |
36 } | |
37 virtual bool GetFilename(FilePath* path) const OVERRIDE { | |
38 return false; | |
39 } | |
40 virtual bool GetPickledData(OSExchangeData::CustomFormat format, | |
41 Pickle* data) const OVERRIDE { | |
42 return false; | 116 return false; |
43 } | 117 } |
44 | 118 |
45 virtual bool HasString() const OVERRIDE { | 119 bool OSExchangeDataProviderAura::GetHtml(string16* html, |
46 return false; | 120 GURL* base_url) const { |
47 } | 121 NOTIMPLEMENTED(); |
48 virtual bool HasURL() const OVERRIDE { | |
49 return false; | |
50 } | |
51 virtual bool HasFile() const OVERRIDE { | |
52 return false; | |
53 } | |
54 virtual bool HasCustomFormat( | |
55 OSExchangeData::CustomFormat format) const OVERRIDE { | |
56 return false; | 122 return false; |
57 } | 123 } |
58 | 124 |
59 private: | 125 bool OSExchangeDataProviderAura::HasFileContents() const { |
60 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAura); | 126 NOTIMPLEMENTED(); |
61 }; | 127 return false; |
| 128 } |
| 129 |
| 130 bool OSExchangeDataProviderAura::HasHtml() const { |
| 131 NOTIMPLEMENTED(); |
| 132 return false; |
| 133 } |
| 134 |
| 135 void OSExchangeDataProviderAura::SetDownloadFileInfo( |
| 136 const OSExchangeData::DownloadFileInfo& download) { |
| 137 NOTIMPLEMENTED(); |
| 138 } |
| 139 #endif |
| 140 |
| 141 bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const { |
| 142 if ((formats_ & OSExchangeData::STRING) == 0) |
| 143 return false; |
| 144 |
| 145 GURL test_url(string_); |
| 146 if (!test_url.is_valid()) |
| 147 return false; |
| 148 |
| 149 if (url) |
| 150 *url = test_url; |
| 151 return true; |
| 152 } |
62 | 153 |
63 /////////////////////////////////////////////////////////////////////////////// | 154 /////////////////////////////////////////////////////////////////////////////// |
64 // OSExchangeData, public: | 155 // OSExchangeData, public: |
65 | 156 |
66 // static | 157 // static |
67 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 158 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
68 return new OSExchangeDataProviderAura(); | 159 return new OSExchangeDataProviderAura(); |
69 } | 160 } |
70 | 161 |
71 // static | 162 // static |
72 OSExchangeData::CustomFormat | 163 OSExchangeData::CustomFormat |
73 OSExchangeData::RegisterCustomFormat(const std::string& type) { | 164 OSExchangeData::RegisterCustomFormat(const std::string& type) { |
74 // TODO(davemoore) Implement this for aura. | 165 // TODO(davemoore) Implement this for aura. |
75 return NULL; | 166 return NULL; |
76 } | 167 } |
77 | 168 |
78 } // namespace ui | 169 } // namespace ui |
OLD | NEW |