| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/os_exchange_data_provider_win.h" | 5 #include "app/os_exchange_data_provider_win.h" |
| 6 | 6 |
| 7 #include "app/clipboard/clipboard_util_win.h" | 7 #include "app/clipboard/clipboard_util_win.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/i18n/file_util_icu.h" | 10 #include "base/i18n/file_util_icu.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 static FormatEtcEnumerator* CloneFromOther(const FormatEtcEnumerator* other); | 77 static FormatEtcEnumerator* CloneFromOther(const FormatEtcEnumerator* other); |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // We are _forced_ to use a vector as our internal data model as Windows' | 80 // We are _forced_ to use a vector as our internal data model as Windows' |
| 81 // retarded IEnumFORMATETC API assumes a deterministic ordering of elements | 81 // retarded IEnumFORMATETC API assumes a deterministic ordering of elements |
| 82 // through methods like Next and Skip. This exposes the underlying data | 82 // through methods like Next and Skip. This exposes the underlying data |
| 83 // structure to the user. Bah. | 83 // structure to the user. Bah. |
| 84 std::vector<FORMATETC*> contents_; | 84 std::vector<FORMATETC*> contents_; |
| 85 | 85 |
| 86 // The cursor of the active enumeration - an index into |contents_|. | 86 // The cursor of the active enumeration - an index into |contents_|. |
| 87 size_t cursor_; | 87 int cursor_; |
| 88 | 88 |
| 89 LONG ref_count_; | 89 LONG ref_count_; |
| 90 | 90 |
| 91 DISALLOW_EVIL_CONSTRUCTORS(FormatEtcEnumerator); | 91 DISALLOW_EVIL_CONSTRUCTORS(FormatEtcEnumerator); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // Safely makes a copy of all of the relevant bits of a FORMATETC object. | 94 // Safely makes a copy of all of the relevant bits of a FORMATETC object. |
| 95 static void CloneFormatEtc(FORMATETC* source, FORMATETC* clone) { | 95 static void CloneFormatEtc(FORMATETC* source, FORMATETC* clone) { |
| 96 *clone = *source; | 96 *clone = *source; |
| 97 if (source->ptd) { | 97 if (source->ptd) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 118 STLDeleteContainerPointers(contents_.begin(), contents_.end()); | 118 STLDeleteContainerPointers(contents_.begin(), contents_.end()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 STDMETHODIMP FormatEtcEnumerator::Next( | 121 STDMETHODIMP FormatEtcEnumerator::Next( |
| 122 ULONG count, FORMATETC* elements_array, ULONG* elements_fetched) { | 122 ULONG count, FORMATETC* elements_array, ULONG* elements_fetched) { |
| 123 // MSDN says |elements_fetched| is allowed to be NULL if count is 1. | 123 // MSDN says |elements_fetched| is allowed to be NULL if count is 1. |
| 124 if (!elements_fetched) | 124 if (!elements_fetched) |
| 125 DCHECK(count == 1); | 125 DCHECK(count == 1); |
| 126 | 126 |
| 127 // This method copies count elements into |elements_array|. | 127 // This method copies count elements into |elements_array|. |
| 128 ULONG index = 0; | 128 int index = 0; |
| 129 while (cursor_ < contents_.size() && index < count) { | 129 while (cursor_ < static_cast<int>(contents_.size()) && |
| 130 static_cast<ULONG>(index) < count) { |
| 130 CloneFormatEtc(contents_.at(cursor_), &elements_array[index]); | 131 CloneFormatEtc(contents_.at(cursor_), &elements_array[index]); |
| 131 ++cursor_; | 132 ++cursor_; |
| 132 ++index; | 133 ++index; |
| 133 } | 134 } |
| 134 // The out param is for how many we actually copied. | 135 // The out param is for how many we actually copied. |
| 135 if (elements_fetched) | 136 if (elements_fetched) |
| 136 *elements_fetched = index; | 137 *elements_fetched = index; |
| 137 | 138 |
| 138 // If the two don't agree, then we fail. | 139 // If the two don't agree, then we fail. |
| 139 return index == count ? S_OK : S_FALSE; | 140 return index == count ? S_OK : S_FALSE; |
| 140 } | 141 } |
| 141 | 142 |
| 142 STDMETHODIMP FormatEtcEnumerator::Skip(ULONG skip_count) { | 143 STDMETHODIMP FormatEtcEnumerator::Skip(ULONG skip_count) { |
| 143 cursor_ += skip_count; | 144 cursor_ += skip_count; |
| 144 // MSDN implies it's OK to leave the enumerator trashed. | 145 // MSDN implies it's OK to leave the enumerator trashed. |
| 145 // "Whatever you say, boss" | 146 // "Whatever you say, boss" |
| 146 return cursor_ <= contents_.size() ? S_OK : S_FALSE; | 147 return cursor_ <= static_cast<int>(contents_.size()) ? S_OK : S_FALSE; |
| 147 } | 148 } |
| 148 | 149 |
| 149 STDMETHODIMP FormatEtcEnumerator::Reset() { | 150 STDMETHODIMP FormatEtcEnumerator::Reset() { |
| 150 cursor_ = 0; | 151 cursor_ = 0; |
| 151 return S_OK; | 152 return S_OK; |
| 152 } | 153 } |
| 153 | 154 |
| 154 STDMETHODIMP FormatEtcEnumerator::Clone(IEnumFORMATETC** clone) { | 155 STDMETHODIMP FormatEtcEnumerator::Clone(IEnumFORMATETC** clone) { |
| 155 // Clone the current enumerator in its exact state, including cursor. | 156 // Clone the current enumerator in its exact state, including cursor. |
| 156 FormatEtcEnumerator* e = CloneFromOther(this); | 157 FormatEtcEnumerator* e = CloneFromOther(this); |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 // static | 911 // static |
| 911 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 912 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 912 return new OSExchangeDataProviderWin(); | 913 return new OSExchangeDataProviderWin(); |
| 913 } | 914 } |
| 914 | 915 |
| 915 // static | 916 // static |
| 916 OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( | 917 OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( |
| 917 const std::string& type) { | 918 const std::string& type) { |
| 918 return RegisterClipboardFormat(ASCIIToWide(type).c_str()); | 919 return RegisterClipboardFormat(ASCIIToWide(type).c_str()); |
| 919 } | 920 } |
| OLD | NEW |