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

Side by Side Diff: Source/core/platform/chromium/ClipboardChromium.cpp

Issue 22837006: Have DataTransferItemList.add() methods return the added item (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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
« no previous file with comments | « Source/core/platform/chromium/ChromiumDataObject.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google Inc. 3 * Copyright (C) 2008, 2009 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // A wrapper class that invalidates a DataTransferItemList when the associated C lipboard object goes out of scope. 57 // A wrapper class that invalidates a DataTransferItemList when the associated C lipboard object goes out of scope.
58 class DataTransferItemListPolicyWrapper : public DataTransferItemList { 58 class DataTransferItemListPolicyWrapper : public DataTransferItemList {
59 public: 59 public:
60 static PassRefPtr<DataTransferItemListPolicyWrapper> create(PassRefPtr<Clipb oardChromium>, PassRefPtr<ChromiumDataObject>); 60 static PassRefPtr<DataTransferItemListPolicyWrapper> create(PassRefPtr<Clipb oardChromium>, PassRefPtr<ChromiumDataObject>);
61 virtual ~DataTransferItemListPolicyWrapper(); 61 virtual ~DataTransferItemListPolicyWrapper();
62 62
63 virtual size_t length() const; 63 virtual size_t length() const;
64 virtual PassRefPtr<DataTransferItem> item(unsigned long index) OVERRIDE; 64 virtual PassRefPtr<DataTransferItem> item(unsigned long index) OVERRIDE;
65 virtual void deleteItem(unsigned long index, ExceptionState&) OVERRIDE; 65 virtual void deleteItem(unsigned long index, ExceptionState&) OVERRIDE;
66 virtual void clear() OVERRIDE; 66 virtual void clear() OVERRIDE;
67 virtual void add(const String& data, const String& type, ExceptionState&) OV ERRIDE; 67 virtual PassRefPtr<DataTransferItem> add(const String& data, const String& t ype, ExceptionState&) OVERRIDE;
68 virtual void add(PassRefPtr<File>) OVERRIDE; 68 virtual PassRefPtr<DataTransferItem> add(PassRefPtr<File>) OVERRIDE;
69 69
70 private: 70 private:
71 DataTransferItemListPolicyWrapper(PassRefPtr<ClipboardChromium>, PassRefPtr< ChromiumDataObject>); 71 DataTransferItemListPolicyWrapper(PassRefPtr<ClipboardChromium>, PassRefPtr< ChromiumDataObject>);
72 72
73 RefPtr<ClipboardChromium> m_clipboard; 73 RefPtr<ClipboardChromium> m_clipboard;
74 RefPtr<ChromiumDataObject> m_dataObject; 74 RefPtr<ChromiumDataObject> m_dataObject;
75 }; 75 };
76 76
77 77
78 PassRefPtr<DataTransferItemListPolicyWrapper> DataTransferItemListPolicyWrapper: :create( 78 PassRefPtr<DataTransferItemListPolicyWrapper> DataTransferItemListPolicyWrapper: :create(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 m_dataObject->deleteItem(index); 112 m_dataObject->deleteItem(index);
113 } 113 }
114 114
115 void DataTransferItemListPolicyWrapper::clear() 115 void DataTransferItemListPolicyWrapper::clear()
116 { 116 {
117 if (!m_clipboard->canWriteData()) 117 if (!m_clipboard->canWriteData())
118 return; 118 return;
119 m_dataObject->clearAll(); 119 m_dataObject->clearAll();
120 } 120 }
121 121
122 void DataTransferItemListPolicyWrapper::add(const String& data, const String& ty pe, ExceptionState& es) 122 PassRefPtr<DataTransferItem> DataTransferItemListPolicyWrapper::add(const String & data, const String& type, ExceptionState& es)
123 { 123 {
124 if (!m_clipboard->canWriteData()) 124 if (!m_clipboard->canWriteData())
125 return; 125 return 0;
126 m_dataObject->add(data, type, es); 126 RefPtr<ChromiumDataObjectItem> item = m_dataObject->add(data, type, es);
127 if (!item)
128 return 0;
129 return DataTransferItemPolicyWrapper::create(m_clipboard, item);
127 } 130 }
128 131
129 void DataTransferItemListPolicyWrapper::add(PassRefPtr<File> file) 132 PassRefPtr<DataTransferItem> DataTransferItemListPolicyWrapper::add(PassRefPtr<F ile> file)
130 { 133 {
131 if (!m_clipboard->canWriteData()) 134 if (!m_clipboard->canWriteData())
132 return; 135 return 0;
133 m_dataObject->add(file, m_clipboard->frame()->document()->scriptExecutionCon text()); 136 RefPtr<ChromiumDataObjectItem> item = m_dataObject->add(file, m_clipboard->f rame()->document()->scriptExecutionContext());
137 if (!item)
138 return 0;
139 return DataTransferItemPolicyWrapper::create(m_clipboard, item);
134 } 140 }
135 141
136 DataTransferItemListPolicyWrapper::DataTransferItemListPolicyWrapper( 142 DataTransferItemListPolicyWrapper::DataTransferItemListPolicyWrapper(
137 PassRefPtr<ClipboardChromium> clipboard, PassRefPtr<ChromiumDataObject> data Object) 143 PassRefPtr<ClipboardChromium> clipboard, PassRefPtr<ChromiumDataObject> data Object)
138 : m_clipboard(clipboard) 144 : m_clipboard(clipboard)
139 , m_dataObject(dataObject) 145 , m_dataObject(dataObject)
140 { 146 {
141 } 147 }
142 148
143 } // namespace 149 } // namespace
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 472
467 PassRefPtr<DataTransferItemList> ClipboardChromium::items() 473 PassRefPtr<DataTransferItemList> ClipboardChromium::items()
468 { 474 {
469 // FIXME: According to the spec, we are supposed to return the same collecti on of items each 475 // FIXME: According to the spec, we are supposed to return the same collecti on of items each
470 // time. We now return a wrapper that always wraps the *same* set of items, so JS shouldn't be 476 // time. We now return a wrapper that always wraps the *same* set of items, so JS shouldn't be
471 // able to tell, but we probably still want to fix this. 477 // able to tell, but we probably still want to fix this.
472 return DataTransferItemListPolicyWrapper::create(this, m_dataObject); 478 return DataTransferItemListPolicyWrapper::create(this, m_dataObject);
473 } 479 }
474 480
475 } // namespace WebCore 481 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/chromium/ChromiumDataObject.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698