OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 int cursor_; | 87 size_t 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 int index = 0; | 128 ULONG index = 0; |
129 while (cursor_ < static_cast<int>(contents_.size()) && | 129 while (cursor_ < contents_.size() && index < count) { |
130 static_cast<ULONG>(index) < count) { | |
131 CloneFormatEtc(contents_.at(cursor_), &elements_array[index]); | 130 CloneFormatEtc(contents_.at(cursor_), &elements_array[index]); |
132 ++cursor_; | 131 ++cursor_; |
133 ++index; | 132 ++index; |
134 } | 133 } |
135 // The out param is for how many we actually copied. | 134 // The out param is for how many we actually copied. |
136 if (elements_fetched) | 135 if (elements_fetched) |
137 *elements_fetched = index; | 136 *elements_fetched = index; |
138 | 137 |
139 // If the two don't agree, then we fail. | 138 // If the two don't agree, then we fail. |
140 return index == count ? S_OK : S_FALSE; | 139 return index == count ? S_OK : S_FALSE; |
141 } | 140 } |
142 | 141 |
143 STDMETHODIMP FormatEtcEnumerator::Skip(ULONG skip_count) { | 142 STDMETHODIMP FormatEtcEnumerator::Skip(ULONG skip_count) { |
144 cursor_ += skip_count; | 143 cursor_ += skip_count; |
145 // MSDN implies it's OK to leave the enumerator trashed. | 144 // MSDN implies it's OK to leave the enumerator trashed. |
146 // "Whatever you say, boss" | 145 // "Whatever you say, boss" |
147 return cursor_ <= static_cast<int>(contents_.size()) ? S_OK : S_FALSE; | 146 return cursor_ <= contents_.size() ? S_OK : S_FALSE; |
148 } | 147 } |
149 | 148 |
150 STDMETHODIMP FormatEtcEnumerator::Reset() { | 149 STDMETHODIMP FormatEtcEnumerator::Reset() { |
151 cursor_ = 0; | 150 cursor_ = 0; |
152 return S_OK; | 151 return S_OK; |
153 } | 152 } |
154 | 153 |
155 STDMETHODIMP FormatEtcEnumerator::Clone(IEnumFORMATETC** clone) { | 154 STDMETHODIMP FormatEtcEnumerator::Clone(IEnumFORMATETC** clone) { |
156 // Clone the current enumerator in its exact state, including cursor. | 155 // Clone the current enumerator in its exact state, including cursor. |
157 FormatEtcEnumerator* e = CloneFromOther(this); | 156 FormatEtcEnumerator* e = CloneFromOther(this); |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 // static | 910 // static |
912 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 911 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
913 return new OSExchangeDataProviderWin(); | 912 return new OSExchangeDataProviderWin(); |
914 } | 913 } |
915 | 914 |
916 // static | 915 // static |
917 OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( | 916 OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( |
918 const std::string& type) { | 917 const std::string& type) { |
919 return RegisterClipboardFormat(ASCIIToWide(type).c_str()); | 918 return RegisterClipboardFormat(ASCIIToWide(type).c_str()); |
920 } | 919 } |
OLD | NEW |