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; |
15 NOTIMPLEMENTED(); | 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); |
16 } | 51 } |
17 | 52 |
18 virtual ~OSExchangeDataProviderAura() { | 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; |
19 } | 86 } |
| 87 // No URL, see if we have plain text that can be parsed as a URL. |
| 88 return GetPlainTextURL(NULL); |
| 89 } |
20 | 90 |
21 virtual void SetString(const string16& data) OVERRIDE { | 91 bool OSExchangeDataProviderAura::HasFile() const { |
22 } | 92 return (formats_ & OSExchangeData::FILE_NAME) != 0; |
23 virtual void SetURL(const GURL& url, const string16& title) OVERRIDE { | 93 } |
24 } | |
25 virtual void SetFilename(const FilePath& path) OVERRIDE { | |
26 } | |
27 virtual void SetPickledData(OSExchangeData::CustomFormat format, | |
28 const Pickle& data) OVERRIDE { | |
29 } | |
30 | 94 |
31 virtual bool GetString(string16* data) const OVERRIDE { | 95 bool OSExchangeDataProviderAura::HasCustomFormat( |
| 96 OSExchangeData::CustomFormat format) const { |
| 97 return pickle_data_.find(format) != pickle_data_.end(); |
| 98 } |
| 99 |
| 100 bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const { |
| 101 if ((formats_ & OSExchangeData::STRING) == 0) |
32 return false; | 102 return false; |
33 } | 103 |
34 virtual bool GetURLAndTitle(GURL* url, string16* title) const OVERRIDE { | 104 GURL test_url(string_); |
| 105 if (!test_url.is_valid()) |
35 return false; | 106 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; | |
43 } | |
44 | 107 |
45 virtual bool HasString() const OVERRIDE { | 108 if (url) |
46 return false; | 109 *url = test_url; |
47 } | 110 return true; |
48 virtual bool HasURL() const OVERRIDE { | 111 } |
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; | |
57 } | |
58 | |
59 private: | |
60 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAura); | |
61 }; | |
62 | 112 |
63 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
64 // OSExchangeData, public: | 114 // OSExchangeData, public: |
65 | 115 |
66 // static | 116 // static |
67 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 117 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
68 return new OSExchangeDataProviderAura(); | 118 return new OSExchangeDataProviderAura(); |
69 } | 119 } |
70 | 120 |
71 // static | 121 // static |
72 void* OSExchangeData::RegisterCustomFormat(const std::string& type) { | 122 void* OSExchangeData::RegisterCustomFormat(const std::string& type) { |
73 // TODO(davemoore) Implement this for aura. | 123 // TODO(davemoore) Implement this for aura. |
74 return NULL; | 124 return NULL; |
75 } | 125 } |
76 | 126 |
77 } // namespace ui | 127 } // namespace ui |
OLD | NEW |