diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-02 18:14:34 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-02 18:14:34 +0000 |
commit | fc0f7aa679b48f458ecf4e207eefbceef429f063 (patch) | |
tree | cbb9700aca67eb1281fe20a51e9b8bc3ba71f0d9 | |
parent | 53920585775589db07c49b8b3a19f71c128e2582 (diff) | |
download | chromium_src-fc0f7aa679b48f458ecf4e207eefbceef429f063.zip chromium_src-fc0f7aa679b48f458ecf4e207eefbceef429f063.tar.gz chromium_src-fc0f7aa679b48f458ecf4e207eefbceef429f063.tar.bz2 |
De-wstringify OSExchangeData.
(Note that I didn't need to adjust many callers on the Windows
side because wstring and string16 are compatible on Windows.)
BUG=23581
Review URL: http://codereview.chromium.org/6596087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76563 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 10 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_node_data.cc | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_util.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_root_view.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/tabs/tab_strip.cc | 2 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data.cc | 16 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data.h | 32 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data_provider_gtk.cc | 17 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data_provider_gtk.h | 8 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data_provider_win.cc | 76 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data_provider_win.h | 16 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data_win_unittest.cc | 6 | ||||
-rw-r--r-- | views/drag_utils.cc | 2 | ||||
-rw-r--r-- | views/widget/drop_target_gtk.cc | 8 |
15 files changed, 109 insertions, 106 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index e089d9b..3af297b 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -856,20 +856,20 @@ views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) { int AutocompleteEditViewGtk::OnPerformDrop( const views::DropTargetEvent& event) { - std::wstring text; + string16 text; const ui::OSExchangeData& data = event.data(); if (data.HasURL()) { GURL url; - std::wstring title; + string16 title; if (data.GetURLAndTitle(&url, &title)) - text = UTF8ToWide(url.spec()); + text = UTF8ToUTF16(url.spec()); } else { - std::wstring data_string; + string16 data_string; if (data.GetString(&data_string)) text = CollapseWhitespace(data_string, true); } - if (!text.empty() && OnPerformDropImpl(WideToUTF16(text))) + if (!text.empty() && OnPerformDropImpl(text)) return CopyOrLinkDragOperation(event.source_operations()); return ui::DragDropTypes::DRAG_NONE; diff --git a/chrome/browser/bookmarks/bookmark_node_data.cc b/chrome/browser/bookmarks/bookmark_node_data.cc index c94d207..5c00445 100644 --- a/chrome/browser/bookmarks/bookmark_node_data.cc +++ b/chrome/browser/bookmarks/bookmark_node_data.cc @@ -224,9 +224,9 @@ void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const { // clipboard. if (elements.size() == 1 && elements[0].is_url) { if (elements[0].url.SchemeIs(chrome::kJavaScriptScheme)) { - data->SetString(UTF8ToWide(elements[0].url.spec())); + data->SetString(UTF8ToUTF16(elements[0].url.spec())); } else { - data->SetURL(elements[0].url, UTF16ToWide(elements[0].title)); + data->SetURL(elements[0].url, elements[0].title); } } @@ -251,9 +251,9 @@ bool BookmarkNodeData::Read(const ui::OSExchangeData& data) { // See if there is a URL on the clipboard. Element element; GURL url; - std::wstring title; + string16 title; if (data.GetURLAndTitle(&url, &title)) - ReadFromTuple(url, WideToUTF16(title)); + ReadFromTuple(url, title); } return is_valid(); diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 215997f..69dcce6 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -526,7 +526,7 @@ void DragDownload(const DownloadItem* download, // Add URL so that we can load supported files when dragged to TabContents. if (net::IsSupportedMimeType(mime_type)) { data.SetURL(GURL(WideToUTF8(full_path.ToWStringHack())), - download->GetFileNameToReportUser().ToWStringHack()); + download->GetFileNameToReportUser().LossyDisplayName()); } #if defined(OS_WIN) diff --git a/chrome/browser/ui/views/frame/browser_root_view.cc b/chrome/browser/ui/views/frame/browser_root_view.cc index bba2945..094e6c3 100644 --- a/chrome/browser/ui/views/frame/browser_root_view.cc +++ b/chrome/browser/ui/views/frame/browser_root_view.cc @@ -92,17 +92,17 @@ int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { // do this as the TabStrip doesn't know about the autocomplete edit and needs // to know about it to handle 'paste and go'. GURL url; - std::wstring title; + string16 title; ui::OSExchangeData mapped_data; if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) { // The url isn't valid. Use the paste and go url. if (GetPasteAndGoURL(event.data(), &url)) - mapped_data.SetURL(url, std::wstring()); + mapped_data.SetURL(url, string16()); // else case: couldn't extract a url or 'paste and go' url. This ends up // passing through an ui::OSExchangeData with nothing in it. We need to do // this so that the tab strip cleans up properly. } else { - mapped_data.SetURL(url, std::wstring()); + mapped_data.SetURL(url, string16()); } forwarding_to_tab_strip_ = false; scoped_ptr<views::DropTargetEvent> mapped_event( @@ -141,13 +141,13 @@ bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, if (!data.HasString()) return false; - std::wstring text; + string16 text; if (!data.GetString(&text) || text.empty()) return false; AutocompleteMatch match; browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify( - WideToUTF16Hack(text), string16(), false, &match, NULL); + text, string16(), false, &match, NULL); if (!match.destination_url.is_valid()) return false; diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc index bbc1476..e983bd0 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc @@ -240,7 +240,7 @@ void TabContentsDragWin::PrepareDragForFileContents( } } file_name = file_name.ReplaceExtension(drop_data.file_extension); - data->SetFileContents(file_name.value(), drop_data.file_contents); + data->SetFileContents(file_name, drop_data.file_contents); } void TabContentsDragWin::PrepareDragForUrl(const WebDropData& drop_data, diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 7541747..059c7e5 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -354,7 +354,7 @@ int TabStrip::OnPerformDrop(const DropTargetEvent& event) { SetDropIndex(-1, false); GURL url; - std::wstring title; + string16 title; if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) return ui::DragDropTypes::DRAG_NONE; diff --git a/ui/base/dragdrop/os_exchange_data.cc b/ui/base/dragdrop/os_exchange_data.cc index a655a900..a81f8e7 100644 --- a/ui/base/dragdrop/os_exchange_data.cc +++ b/ui/base/dragdrop/os_exchange_data.cc @@ -27,11 +27,11 @@ OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) { OSExchangeData::~OSExchangeData() { } -void OSExchangeData::SetString(const std::wstring& data) { +void OSExchangeData::SetString(const string16& data) { provider_->SetString(data); } -void OSExchangeData::SetURL(const GURL& url, const std::wstring& title) { +void OSExchangeData::SetURL(const GURL& url, const string16& title) { provider_->SetURL(url, title); } @@ -43,11 +43,11 @@ void OSExchangeData::SetPickledData(CustomFormat format, const Pickle& data) { provider_->SetPickledData(format, data); } -bool OSExchangeData::GetString(std::wstring* data) const { +bool OSExchangeData::GetString(string16* data) const { return provider_->GetString(data); } -bool OSExchangeData::GetURLAndTitle(GURL* url, std::wstring* title) const { +bool OSExchangeData::GetURLAndTitle(GURL* url, string16* title) const { return provider_->GetURLAndTitle(url, title); } @@ -122,21 +122,21 @@ bool OSExchangeData::HasAnyFormat( } #if defined(OS_WIN) -void OSExchangeData::SetFileContents(const std::wstring& filename, +void OSExchangeData::SetFileContents(const FilePath& filename, const std::string& file_contents) { provider_->SetFileContents(filename, file_contents); } -void OSExchangeData::SetHtml(const std::wstring& html, const GURL& base_url) { +void OSExchangeData::SetHtml(const string16& html, const GURL& base_url) { provider_->SetHtml(html, base_url); } -bool OSExchangeData::GetFileContents(std::wstring* filename, +bool OSExchangeData::GetFileContents(FilePath* filename, std::string* file_contents) const { return provider_->GetFileContents(filename, file_contents); } -bool OSExchangeData::GetHtml(std::wstring* html, GURL* base_url) const { +bool OSExchangeData::GetHtml(string16* html, GURL* base_url) const { return provider_->GetHtml(html, base_url); } diff --git a/ui/base/dragdrop/os_exchange_data.h b/ui/base/dragdrop/os_exchange_data.h index f1db906..3ef254a 100644 --- a/ui/base/dragdrop/os_exchange_data.h +++ b/ui/base/dragdrop/os_exchange_data.h @@ -80,13 +80,13 @@ class OSExchangeData { Provider() {} virtual ~Provider() {} - virtual void SetString(const std::wstring& data) = 0; - virtual void SetURL(const GURL& url, const std::wstring& title) = 0; + virtual void SetString(const string16& data) = 0; + virtual void SetURL(const GURL& url, const string16& title) = 0; virtual void SetFilename(const FilePath& path) = 0; virtual void SetPickledData(CustomFormat format, const Pickle& data) = 0; - virtual bool GetString(std::wstring* data) const = 0; - virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const = 0; + virtual bool GetString(string16* data) const = 0; + virtual bool GetURLAndTitle(GURL* url, string16* title) const = 0; virtual bool GetFilename(FilePath* path) const = 0; virtual bool GetPickledData(CustomFormat format, Pickle* data) const = 0; @@ -97,12 +97,12 @@ class OSExchangeData { OSExchangeData::CustomFormat format) const = 0; #if defined(OS_WIN) - virtual void SetFileContents(const std::wstring& filename, + virtual void SetFileContents(const FilePath& filename, const std::string& file_contents) = 0; - virtual void SetHtml(const std::wstring& html, const GURL& base_url) = 0; - virtual bool GetFileContents(std::wstring* filename, + virtual void SetHtml(const string16& html, const GURL& base_url) = 0; + virtual bool GetFileContents(FilePath* filename, std::string* file_contents) const = 0; - virtual bool GetHtml(std::wstring* html, GURL* base_url) const = 0; + virtual bool GetHtml(string16* html, GURL* base_url) const = 0; virtual bool HasFileContents() const = 0; virtual bool HasHtml() const = 0; virtual void SetDownloadFileInfo(const DownloadFileInfo& download) = 0; @@ -133,9 +133,9 @@ class OSExchangeData { // the order of enumeration in our IEnumFORMATETC implementation! // This comes into play when selecting the best (most preferable) // data type for insertion into a DropTarget. - void SetString(const std::wstring& data); + void SetString(const string16& data); // A URL can have an optional title in some exchange formats. - void SetURL(const GURL& url, const std::wstring& title); + void SetURL(const GURL& url, const string16& title); // A full path to a file. void SetFilename(const FilePath& path); // Adds pickled data of the specified format. @@ -145,8 +145,8 @@ class OSExchangeData { // functions return and the result is in the out parameter. If the data does // not exist, the out parameter is not touched. The out parameter cannot be // NULL. - bool GetString(std::wstring* data) const; - bool GetURLAndTitle(GURL* url, std::wstring* title) const; + bool GetString(string16* data) const; + bool GetURLAndTitle(GURL* url, string16* title) const; // Return the path of a file, if available. bool GetFilename(FilePath* path) const; bool GetPickledData(CustomFormat format, Pickle* data) const; @@ -170,14 +170,14 @@ class OSExchangeData { #if defined(OS_WIN) // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). - void SetFileContents(const std::wstring& filename, + void SetFileContents(const FilePath& filename, const std::string& file_contents); // Adds a snippet of HTML. |html| is just raw html but this sets both // text/html and CF_HTML. - void SetHtml(const std::wstring& html, const GURL& base_url); - bool GetFileContents(std::wstring* filename, + void SetHtml(const string16& html, const GURL& base_url); + bool GetFileContents(FilePath* filename, std::string* file_contents) const; - bool GetHtml(std::wstring* html, GURL* base_url) const; + bool GetHtml(string16* html, GURL* base_url) const; // Adds a download file with full path (CF_HDROP). void SetDownloadFileInfo(const DownloadFileInfo& download); diff --git a/ui/base/dragdrop/os_exchange_data_provider_gtk.cc b/ui/base/dragdrop/os_exchange_data_provider_gtk.cc index cc27d05..ba53d77 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_gtk.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_gtk.cc @@ -125,15 +125,14 @@ void OSExchangeDataProviderGtk::WriteFormatToSelection( } } -void OSExchangeDataProviderGtk::SetString(const std::wstring& data) { - string_ = WideToUTF16Hack(data); +void OSExchangeDataProviderGtk::SetString(const string16& data) { + string_ = data; formats_ |= OSExchangeData::STRING; } -void OSExchangeDataProviderGtk::SetURL(const GURL& url, - const std::wstring& title) { +void OSExchangeDataProviderGtk::SetURL(const GURL& url, const string16& title) { url_ = url; - title_ = WideToUTF16Hack(title); + title_ = title; formats_ |= OSExchangeData::URL; } @@ -148,15 +147,15 @@ void OSExchangeDataProviderGtk::SetPickledData(GdkAtom format, formats_ |= OSExchangeData::PICKLED_DATA; } -bool OSExchangeDataProviderGtk::GetString(std::wstring* data) const { +bool OSExchangeDataProviderGtk::GetString(string16* data) const { if ((formats_ & OSExchangeData::STRING) == 0) return false; - *data = UTF16ToWideHack(string_); + *data = string_; return true; } bool OSExchangeDataProviderGtk::GetURLAndTitle(GURL* url, - std::wstring* title) const { + string16* title) const { if ((formats_ & OSExchangeData::URL) == 0) { title->clear(); return GetPlainTextURL(url); @@ -166,7 +165,7 @@ bool OSExchangeDataProviderGtk::GetURLAndTitle(GURL* url, return false; *url = url_; - *title = UTF16ToWideHack(title_); + *title = title_; return true; } diff --git a/ui/base/dragdrop/os_exchange_data_provider_gtk.h b/ui/base/dragdrop/os_exchange_data_provider_gtk.h index b90bd89b..443e69b 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_gtk.h +++ b/ui/base/dragdrop/os_exchange_data_provider_gtk.h @@ -58,13 +58,13 @@ class OSExchangeDataProviderGtk : public OSExchangeData::Provider { GtkSelectionData* selection) const; // Provider methods. - virtual void SetString(const std::wstring& data); - virtual void SetURL(const GURL& url, const std::wstring& title); + virtual void SetString(const string16& data); + virtual void SetURL(const GURL& url, const string16& title); virtual void SetFilename(const FilePath& path); virtual void SetPickledData(OSExchangeData::CustomFormat format, const Pickle& data); - virtual bool GetString(std::wstring* data) const; - virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const; + virtual bool GetString(string16* data) const; + virtual bool GetURLAndTitle(GURL* url, string16* title) const; virtual bool GetFilename(FilePath* path) const; virtual bool GetPickledData(OSExchangeData::CustomFormat format, Pickle* data) const; diff --git a/ui/base/dragdrop/os_exchange_data_provider_win.cc b/ui/base/dragdrop/os_exchange_data_provider_win.cc index fb5c496..5e2ea1b 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_win.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_win.cc @@ -24,20 +24,19 @@ namespace ui { // owns the resulting object. The "Bytes" version does not NULL terminate, the // string version does. static STGMEDIUM* GetStorageForBytes(const char* data, size_t bytes); -static STGMEDIUM* GetStorageForWString(const std::wstring& data); +static STGMEDIUM* GetStorageForString16(const string16& data); static STGMEDIUM* GetStorageForString(const std::string& data); // Creates the contents of an Internet Shortcut file for the given URL. static void GetInternetShortcutFileContents(const GURL& url, std::string* data); // Creates a valid file name given a suggested title and URL. static void CreateValidFileNameFromTitle(const GURL& url, - const std::wstring& title, - std::wstring* validated); + const string16& title, + string16* validated); // Creates a new STGMEDIUM object to hold a file. static STGMEDIUM* GetStorageForFileName(const FilePath& path); // Creates a File Descriptor for the creation of a file to the given URL and // returns a handle to it. -static STGMEDIUM* GetStorageForFileDescriptor( - const std::wstring& valid_file_name); +static STGMEDIUM* GetStorageForFileDescriptor(const FilePath& path); /////////////////////////////////////////////////////////////////////////////// // FormatEtcEnumerator @@ -209,7 +208,7 @@ FormatEtcEnumerator* FormatEtcEnumerator::CloneFromOther( // static bool OSExchangeDataProviderWin::HasPlainTextURL(IDataObject* source) { - std::wstring plain_text; + string16 plain_text; return (ClipboardUtil::GetPlainText(source, &plain_text) && !plain_text.empty() && GURL(plain_text).is_valid()); } @@ -217,7 +216,7 @@ bool OSExchangeDataProviderWin::HasPlainTextURL(IDataObject* source) { // static bool OSExchangeDataProviderWin::GetPlainTextURL(IDataObject* source, GURL* url) { - std::wstring plain_text; + string16 plain_text; if (ClipboardUtil::GetPlainText(source, &plain_text) && !plain_text.empty()) { GURL gurl(plain_text); @@ -263,19 +262,19 @@ OSExchangeDataProviderWin::OSExchangeDataProviderWin() OSExchangeDataProviderWin::~OSExchangeDataProviderWin() { } -void OSExchangeDataProviderWin::SetString(const std::wstring& data) { - STGMEDIUM* storage = GetStorageForWString(data); +void OSExchangeDataProviderWin::SetString(const string16& data) { + STGMEDIUM* storage = GetStorageForString16(data); data_->contents_.push_back( new DataObjectImpl::StoredDataInfo(CF_UNICODETEXT, storage)); // Also add plain text. - storage = GetStorageForString(WideToUTF8(data)); + storage = GetStorageForString(UTF16ToUTF8(data)); data_->contents_.push_back( new DataObjectImpl::StoredDataInfo(CF_TEXT, storage)); } void OSExchangeDataProviderWin::SetURL(const GURL& url, - const std::wstring& title) { + const string16& title) { // NOTE WELL: // Every time you change the order of the first two CLIPFORMATS that get // added here, you need to update the EnumerationViaCOM test case in @@ -283,22 +282,22 @@ void OSExchangeDataProviderWin::SetURL(const GURL& url, // will fail! It assumes an insertion order. // Add text/x-moz-url for drags from Firefox - std::wstring x_moz_url_str = UTF8ToWide(url.spec()); + string16 x_moz_url_str = UTF8ToUTF16(url.spec()); x_moz_url_str += '\n'; x_moz_url_str += title; - STGMEDIUM* storage = GetStorageForWString(x_moz_url_str); + STGMEDIUM* storage = GetStorageForString16(x_moz_url_str); data_->contents_.push_back(new DataObjectImpl::StoredDataInfo( ClipboardUtil::GetMozUrlFormat()->cfFormat, storage)); // Add a .URL shortcut file for dragging to Explorer. - std::wstring valid_file_name; + string16 valid_file_name; CreateValidFileNameFromTitle(url, title, &valid_file_name); std::string shortcut_url_file_contents; GetInternetShortcutFileContents(url, &shortcut_url_file_contents); - SetFileContents(valid_file_name, shortcut_url_file_contents); + SetFileContents(FilePath(valid_file_name), shortcut_url_file_contents); // Add a UniformResourceLocator link for apps like IE and Word. - storage = GetStorageForWString(UTF8ToWide(url.spec())); + storage = GetStorageForString16(UTF8ToUTF16(url.spec())); data_->contents_.push_back(new DataObjectImpl::StoredDataInfo( ClipboardUtil::GetUrlWFormat()->cfFormat, storage)); storage = GetStorageForString(url.spec()); @@ -310,7 +309,7 @@ void OSExchangeDataProviderWin::SetURL(const GURL& url, // Also add text representations (these should be last since they're the // least preferable). - storage = GetStorageForWString(UTF8ToWide(url.spec())); + storage = GetStorageForString16(UTF8ToUTF16(url.spec())); data_->contents_.push_back( new DataObjectImpl::StoredDataInfo(CF_UNICODETEXT, storage)); storage = GetStorageForString(url.spec()); @@ -335,7 +334,7 @@ void OSExchangeDataProviderWin::SetPickledData(CLIPFORMAT format, } void OSExchangeDataProviderWin::SetFileContents( - const std::wstring& filename, + const FilePath& filename, const std::string& file_contents) { // Add CFSTR_FILEDESCRIPTOR STGMEDIUM* storage = GetStorageForFileDescriptor(filename); @@ -348,10 +347,10 @@ void OSExchangeDataProviderWin::SetFileContents( ClipboardUtil::GetFileContentFormatZero(), storage)); } -void OSExchangeDataProviderWin::SetHtml(const std::wstring& html, +void OSExchangeDataProviderWin::SetHtml(const string16& html, const GURL& base_url) { // Add both MS CF_HTML and text/html format. CF_HTML should be in utf-8. - std::string utf8_html = WideToUTF8(html); + std::string utf8_html = UTF16ToUTF8(html); std::string url = base_url.is_valid() ? base_url.spec() : std::string(); std::string cf_html = ClipboardUtil::HtmlToCFHtml(utf8_html, url); @@ -365,13 +364,13 @@ void OSExchangeDataProviderWin::SetHtml(const std::wstring& html, ClipboardUtil::GetTextHtmlFormat()->cfFormat, storage_plain)); } -bool OSExchangeDataProviderWin::GetString(std::wstring* data) const { +bool OSExchangeDataProviderWin::GetString(string16* data) const { return ClipboardUtil::GetPlainText(source_object_, data); } bool OSExchangeDataProviderWin::GetURLAndTitle(GURL* url, - std::wstring* title) const { - std::wstring url_str; + string16* title) const { + string16 url_str; bool success = ClipboardUtil::GetUrl(source_object_, &url_str, title, true); if (success) { GURL test_url(url_str); @@ -387,7 +386,7 @@ bool OSExchangeDataProviderWin::GetURLAndTitle(GURL* url, } bool OSExchangeDataProviderWin::GetFilename(FilePath* path) const { - std::vector<std::wstring> filenames; + std::vector<string16> filenames; bool success = ClipboardUtil::GetFilenames(source_object_, &filenames); if (success) *path = FilePath(filenames[0]); @@ -415,13 +414,18 @@ bool OSExchangeDataProviderWin::GetPickledData(CLIPFORMAT format, } bool OSExchangeDataProviderWin::GetFileContents( - std::wstring* filename, + FilePath* filename, std::string* file_contents) const { - return ClipboardUtil::GetFileContents(source_object_, filename, - file_contents); + string16 filename_str; + if (!ClipboardUtil::GetFileContents(source_object_, &filename_str, + file_contents)) { + return false; + } + *filename = FilePath(filename_str); + return true; } -bool OSExchangeDataProviderWin::GetHtml(std::wstring* html, +bool OSExchangeDataProviderWin::GetHtml(string16* html, GURL* base_url) const { std::string url; bool success = ClipboardUtil::GetHtml(source_object_, html, &url); @@ -813,9 +817,9 @@ static HGLOBAL CopyStringToGlobalHandle(const T& payload) { return handle; } -static STGMEDIUM* GetStorageForWString(const std::wstring& data) { +static STGMEDIUM* GetStorageForString16(const string16& data) { STGMEDIUM* storage = new STGMEDIUM; - storage->hGlobal = CopyStringToGlobalHandle<std::wstring>(data); + storage->hGlobal = CopyStringToGlobalHandle<string16>(data); storage->tymed = TYMED_HGLOBAL; storage->pUnkForRelease = NULL; return storage; @@ -840,12 +844,11 @@ static void GetInternetShortcutFileContents(const GURL& url, } static void CreateValidFileNameFromTitle(const GURL& url, - const std::wstring& title, - std::wstring* validated) { + const string16& title, + string16* validated) { if (title.empty()) { if (url.is_valid()) { - *validated = UTF16ToWide( - net::GetSuggestedFilename(url, "", "", string16())); + *validated = net::GetSuggestedFilename(url, "", "", string16()); } else { // Nothing else can be done, just use a default. *validated = @@ -886,7 +889,8 @@ static STGMEDIUM* GetStorageForFileName(const FilePath& path) { } static STGMEDIUM* GetStorageForFileDescriptor( - const std::wstring& valid_file_name) { + const FilePath& path) { + string16 valid_file_name = path.value(); DCHECK(!valid_file_name.empty() && valid_file_name.size() + 1 <= MAX_PATH); HANDLE handle = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR)); FILEGROUPDESCRIPTOR* descriptor = @@ -919,7 +923,7 @@ OSExchangeData::Provider* OSExchangeData::CreateProvider() { // static OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( const std::string& type) { - return RegisterClipboardFormat(ASCIIToWide(type).c_str()); + return RegisterClipboardFormat(ASCIIToUTF16(type).c_str()); } } // namespace ui diff --git a/ui/base/dragdrop/os_exchange_data_provider_win.h b/ui/base/dragdrop/os_exchange_data_provider_win.h index 7aba9ca..d321161 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_win.h +++ b/ui/base/dragdrop/os_exchange_data_provider_win.h @@ -142,23 +142,23 @@ class OSExchangeDataProviderWin : public OSExchangeData::Provider { IAsyncOperation* async_operation() const { return data_.get(); } // OSExchangeData::Provider methods. - virtual void SetString(const std::wstring& data); - virtual void SetURL(const GURL& url, const std::wstring& title); + virtual void SetString(const string16& data); + virtual void SetURL(const GURL& url, const string16& title); virtual void SetFilename(const FilePath& path); virtual void SetPickledData(OSExchangeData::CustomFormat format, const Pickle& data); - virtual void SetFileContents(const std::wstring& filename, + virtual void SetFileContents(const FilePath& filename, const std::string& file_contents); - virtual void SetHtml(const std::wstring& html, const GURL& base_url); + virtual void SetHtml(const string16& html, const GURL& base_url); - virtual bool GetString(std::wstring* data) const; - virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const; + virtual bool GetString(string16* data) const; + virtual bool GetURLAndTitle(GURL* url, string16* title) const; virtual bool GetFilename(FilePath* path) const; virtual bool GetPickledData(OSExchangeData::CustomFormat format, Pickle* data) const; - virtual bool GetFileContents(std::wstring* filename, + virtual bool GetFileContents(FilePath* filename, std::string* file_contents) const; - virtual bool GetHtml(std::wstring* html, GURL* base_url) const; + virtual bool GetHtml(string16* html, GURL* base_url) const; virtual bool HasString() const; virtual bool HasURL() const; virtual bool HasFile() const; diff --git a/ui/base/dragdrop/os_exchange_data_win_unittest.cc b/ui/base/dragdrop/os_exchange_data_win_unittest.cc index d9509b9..8f65716 100644 --- a/ui/base/dragdrop/os_exchange_data_win_unittest.cc +++ b/ui/base/dragdrop/os_exchange_data_win_unittest.cc @@ -313,13 +313,13 @@ TEST(OSExchangeDataTest, TestPickledData) { TEST(OSExchangeDataTest, FileContents) { OSExchangeData data; std::string file_contents("data\0with\0nulls", 15); - data.SetFileContents(L"filename.txt", file_contents); + data.SetFileContents(FilePath(L"filename.txt"), file_contents); OSExchangeData copy(CloneProvider(data)); - std::wstring filename; + FilePath filename; std::string read_contents; EXPECT_TRUE(copy.GetFileContents(&filename, &read_contents)); - EXPECT_EQ(L"filename.txt", filename); + EXPECT_EQ(L"filename.txt", filename.value()); EXPECT_EQ(file_contents, read_contents); } diff --git a/views/drag_utils.cc b/views/drag_utils.cc index dd7c887..b315130 100644 --- a/views/drag_utils.cc +++ b/views/drag_utils.cc @@ -33,7 +33,7 @@ void SetURLAndDragImage(const GURL& url, OSExchangeData* data) { DCHECK(url.is_valid() && data); - data->SetURL(url, title); + data->SetURL(url, WideToUTF16(title)); // Create a button to render the drag image for us. views::TextButton button(NULL, diff --git a/views/widget/drop_target_gtk.cc b/views/widget/drop_target_gtk.cc index 8f30d14..ee2abfd 100644 --- a/views/widget/drop_target_gtk.cc +++ b/views/widget/drop_target_gtk.cc @@ -104,7 +104,7 @@ void DropTargetGtk::OnDragDataReceived(GdkDragContext* context, UTF8ToUTF16(as_char, strlen(as_char), &result); g_free(text_data); } - data_provider().SetString(UTF16ToWideHack(result)); + data_provider().SetString(result); } else if (requested_custom_formats_.find(data->type) != requested_custom_formats_.end()) { Pickle result; @@ -115,12 +115,12 @@ void DropTargetGtk::OnDragDataReceived(GdkDragContext* context, GURL url; string16 title; ui::ExtractNamedURL(data, &url, &title); - data_provider().SetURL(url, UTF16ToWideHack(title)); + data_provider().SetURL(url, title); } else if (data->type == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { std::vector<GURL> urls; ui::ExtractURIList(data, &urls); if (urls.size() == 1 && urls[0].is_valid()) { - data_provider().SetURL(urls[0], std::wstring()); + data_provider().SetURL(urls[0], string16()); // TEXT_URI_LIST is used for files as well as urls. if (urls[0].SchemeIsFile()) { @@ -132,7 +132,7 @@ void DropTargetGtk::OnDragDataReceived(GdkDragContext* context, // Consumers of OSExchangeData will see this as an invalid URL. That is, // when GetURL is invoked on the OSExchangeData this triggers false to // be returned. - data_provider().SetURL(GURL(), std::wstring()); + data_provider().SetURL(GURL(), string16()); } } |