Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Side by Side Diff: ui/base/dragdrop/os_exchange_data_provider_win.cc

Issue 207013003: Mark drags starting in web content as tainted to avoid file path forgery (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_provider_win.h" 5 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/i18n/file_util_icu.h" 11 #include "base/i18n/file_util_icu.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_handle.h" 13 #include "base/memory/scoped_handle.h"
14 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/win/scoped_hglobal.h" 16 #include "base/win/scoped_hglobal.h"
17 #include "grit/ui_strings.h" 17 #include "grit/ui_strings.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "ui/base/clipboard/clipboard.h" 19 #include "ui/base/clipboard/clipboard.h"
20 #include "ui/base/clipboard/clipboard_util_win.h" 20 #include "ui/base/clipboard/clipboard_util_win.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace ui { 24 namespace ui {
25 25
26 static const OSExchangeData::CustomFormat& GetRendererTaintCustomType() {
27 CR_DEFINE_STATIC_LOCAL(
28 ui::OSExchangeData::CustomFormat,
29 format,
30 (ui::Clipboard::GetFormatType("chromium/x-renderer-taint")));
31 return format;
32 }
33
26 // Creates a new STGMEDIUM object to hold the specified text. The caller 34 // Creates a new STGMEDIUM object to hold the specified text. The caller
27 // owns the resulting object. The "Bytes" version does not NULL terminate, the 35 // owns the resulting object. The "Bytes" version does not NULL terminate, the
28 // string version does. 36 // string version does.
29 static STGMEDIUM* GetStorageForBytes(const void* data, size_t bytes); 37 static STGMEDIUM* GetStorageForBytes(const void* data, size_t bytes);
30 template <typename T> 38 template <typename T>
31 static STGMEDIUM* GetStorageForString(const std::basic_string<T>& data); 39 static STGMEDIUM* GetStorageForString(const std::basic_string<T>& data);
32 // Creates the contents of an Internet Shortcut file for the given URL. 40 // Creates the contents of an Internet Shortcut file for the given URL.
33 static void GetInternetShortcutFileContents(const GURL& url, std::string* data); 41 static void GetInternetShortcutFileContents(const GURL& url, std::string* data);
34 // Creates a valid file name given a suggested title and URL. 42 // Creates a valid file name given a suggested title and URL.
35 static void CreateValidFileNameFromTitle(const GURL& url, 43 static void CreateValidFileNameFromTitle(const GURL& url,
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 source_object_(data_.get()) { 270 source_object_(data_.get()) {
263 } 271 }
264 272
265 OSExchangeDataProviderWin::~OSExchangeDataProviderWin() { 273 OSExchangeDataProviderWin::~OSExchangeDataProviderWin() {
266 } 274 }
267 275
268 OSExchangeData::Provider* OSExchangeDataProviderWin::Clone() const { 276 OSExchangeData::Provider* OSExchangeDataProviderWin::Clone() const {
269 return new OSExchangeDataProviderWin(data_object()); 277 return new OSExchangeDataProviderWin(data_object());
270 } 278 }
271 279
280 void OSExchangeDataProviderWin::MarkOriginatedFromRenderer() {
281 STGMEDIUM* storage = GetStorageForString(std::string());
282 data_->contents_.push_back(new DataObjectImpl::StoredDataInfo(
283 GetRendererTaintCustomType().ToFormatEtc(), storage));
284 }
285
286 bool OSExchangeDataProviderWin::DidOriginateFromRenderer() const {
287 return HasCustomFormat(GetRendererTaintCustomType());
288 }
289
272 void OSExchangeDataProviderWin::SetString(const base::string16& data) { 290 void OSExchangeDataProviderWin::SetString(const base::string16& data) {
273 STGMEDIUM* storage = GetStorageForString(data); 291 STGMEDIUM* storage = GetStorageForString(data);
274 data_->contents_.push_back(new DataObjectImpl::StoredDataInfo( 292 data_->contents_.push_back(new DataObjectImpl::StoredDataInfo(
275 Clipboard::GetPlainTextWFormatType().ToFormatEtc(), storage)); 293 Clipboard::GetPlainTextWFormatType().ToFormatEtc(), storage));
276 294
277 // Also add the UTF8-encoded version. 295 // Also add the UTF8-encoded version.
278 storage = GetStorageForString(base::UTF16ToUTF8(data)); 296 storage = GetStorageForString(base::UTF16ToUTF8(data));
279 data_->contents_.push_back(new DataObjectImpl::StoredDataInfo( 297 data_->contents_.push_back(new DataObjectImpl::StoredDataInfo(
280 Clipboard::GetPlainTextFormatType().ToFormatEtc(), storage)); 298 Clipboard::GetPlainTextFormatType().ToFormatEtc(), storage));
281 } 299 }
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1060
1043 /////////////////////////////////////////////////////////////////////////////// 1061 ///////////////////////////////////////////////////////////////////////////////
1044 // OSExchangeData, public: 1062 // OSExchangeData, public:
1045 1063
1046 // static 1064 // static
1047 OSExchangeData::Provider* OSExchangeData::CreateProvider() { 1065 OSExchangeData::Provider* OSExchangeData::CreateProvider() {
1048 return new OSExchangeDataProviderWin(); 1066 return new OSExchangeDataProviderWin();
1049 } 1067 }
1050 1068
1051 } // namespace ui 1069 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698