Index: ui/base/dragdrop/os_exchange_data_provider_aura.cc |
diff --git a/ui/base/dragdrop/os_exchange_data_provider_aura.cc b/ui/base/dragdrop/os_exchange_data_provider_aura.cc |
index 18b4128ebe7cdfe7e49a16fc166ef690457647f7..fe9cc134921829d61361e90af47ab9afff7ace29 100644 |
--- a/ui/base/dragdrop/os_exchange_data_provider_aura.cc |
+++ b/ui/base/dragdrop/os_exchange_data_provider_aura.cc |
@@ -2,63 +2,113 @@ |
// 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.h" |
+#include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
#include "base/logging.h" |
+#include "base/utf_string_conversions.h" |
+#include "net/base/net_util.h" |
namespace ui { |
-// OSExchangeData::Provider implementation for aura on linux. |
-class OSExchangeDataProviderAura : public OSExchangeData::Provider { |
- public: |
- OSExchangeDataProviderAura() { |
- NOTIMPLEMENTED(); |
- } |
+OSExchangeDataProviderAura::OSExchangeDataProviderAura() : formats_(0) {} |
- virtual ~OSExchangeDataProviderAura() { |
- } |
+void OSExchangeDataProviderAura::SetString(const string16& data) { |
+ string_ = data; |
+ formats_ |= OSExchangeData::STRING; |
+} |
- virtual void SetString(const string16& data) OVERRIDE { |
- } |
- virtual void SetURL(const GURL& url, const string16& title) OVERRIDE { |
- } |
- virtual void SetFilename(const FilePath& path) OVERRIDE { |
- } |
- virtual void SetPickledData(OSExchangeData::CustomFormat format, |
- const Pickle& data) OVERRIDE { |
- } |
+void OSExchangeDataProviderAura::SetURL(const GURL& url, |
+ const string16& title) { |
+ url_ = url; |
+ title_ = title; |
+ formats_ |= OSExchangeData::URL; |
+} |
- virtual bool GetString(string16* data) const OVERRIDE { |
- return false; |
- } |
- virtual bool GetURLAndTitle(GURL* url, string16* title) const OVERRIDE { |
- return false; |
- } |
- virtual bool GetFilename(FilePath* path) const OVERRIDE { |
+void OSExchangeDataProviderAura::SetFilename(const FilePath& path) { |
+ filename_ = path; |
+ formats_ |= OSExchangeData::FILE_NAME; |
+} |
+ |
+void OSExchangeDataProviderAura::SetPickledData( |
+ OSExchangeData::CustomFormat format, |
+ const Pickle& data) { |
+ pickle_data_[format] = data; |
+ formats_ |= OSExchangeData::PICKLED_DATA; |
+} |
+ |
+bool OSExchangeDataProviderAura::GetString(string16* data) const { |
+ if ((formats_ & OSExchangeData::STRING) == 0) |
return false; |
+ *data = string_; |
+ return true; |
+} |
+ |
+bool OSExchangeDataProviderAura::GetURLAndTitle(GURL* url, |
+ string16* title) const { |
+ if ((formats_ & OSExchangeData::URL) == 0) { |
+ title->clear(); |
+ return GetPlainTextURL(url); |
} |
- virtual bool GetPickledData(OSExchangeData::CustomFormat format, |
- Pickle* data) const OVERRIDE { |
+ |
+ if (!url_.is_valid()) |
return false; |
- } |
- virtual bool HasString() const OVERRIDE { |
+ *url = url_; |
+ *title = title_; |
+ return true; |
+} |
+ |
+bool OSExchangeDataProviderAura::GetFilename(FilePath* path) const { |
+ if ((formats_ & OSExchangeData::FILE_NAME) == 0) |
return false; |
- } |
- virtual bool HasURL() const OVERRIDE { |
+ *path = filename_; |
+ return true; |
+} |
+ |
+bool OSExchangeDataProviderAura::GetPickledData( |
+ 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; |
} |
- virtual bool HasFile() const OVERRIDE { |
+ // 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( |
+ OSExchangeData::CustomFormat format) const { |
+ return pickle_data_.find(format) != pickle_data_.end(); |
+} |
+ |
+bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const { |
+ if ((formats_ & OSExchangeData::STRING) == 0) |
return false; |
- } |
- virtual bool HasCustomFormat( |
- OSExchangeData::CustomFormat format) const OVERRIDE { |
+ |
+ GURL test_url(string_); |
+ if (!test_url.is_valid()) |
return false; |
- } |
- private: |
- DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAura); |
-}; |
+ if (url) |
+ *url = test_url; |
+ return true; |
+} |
/////////////////////////////////////////////////////////////////////////////// |
// OSExchangeData, public: |