Commit ae86f2ab authored by dcheng@chromium.org's avatar dcheng@chromium.org

Convert DataTransferItem/DataTransferItemList back into an interface class

https://bugs.webkit.org/show_bug.cgi?id=76856

When Qt implemented the DataTransferItemList, a lot of logic was moved into the shared
classes since Chromium/Qt happened to implement it the same way. Now that I want to do some
refactoring/cleanup work to better implement DataTransferItemList in Chromium, we won't
share the same data anymore so it doesn't make sense to keep that code in a common location.

Reviewed by David Levin.

Covered by existing tests.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/DataTransferItem.cpp:
* dom/DataTransferItem.h:
* dom/DataTransferItemList.cpp: Removed.
* dom/DataTransferItemList.h:
* platform/chromium/ClipboardChromium.cpp:
(WebCore::ClipboardChromium::mayUpdateItems):
* platform/chromium/DataTransferItemChromium.cpp:
(WebCore::DataTransferItemChromium::create):
(WebCore::DataTransferItemChromium::DataTransferItemChromium):
(WebCore::DataTransferItemChromium::getAsString):
(WebCore::DataTransferItemChromium::getAsFile):
(WebCore::DataTransferItemChromium::clipboardChromium):
* platform/chromium/DataTransferItemChromium.h:
(WebCore::DataTransferItemChromium::kind):
(WebCore::DataTransferItemChromium::type):
* platform/chromium/DataTransferItemListChromium.cpp:
(WebCore::DataTransferItemListChromium::DataTransferItemListChromium):
* platform/chromium/DataTransferItemListChromium.h:
* platform/qt/DataTransferItemListQt.cpp:
(WebCore::DataTransferItemListQt::DataTransferItemListQt):
(WebCore::DataTransferItemListQt::length):
(WebCore::DataTransferItemListQt::item):
(WebCore::DataTransferItemListQt::deleteItem):
(WebCore::DataTransferItemListQt::clear):
(WebCore::DataTransferItemListQt::add):
* platform/qt/DataTransferItemListQt.h:
* platform/qt/DataTransferItemQt.cpp:
(WebCore::DataTransferItemQt::create):
(WebCore::DataTransferItemQt::DataTransferItemQt):
(WebCore::DataTransferItemQt::getAsString):
(WebCore::DataTransferItemQt::getAsFile):
* platform/qt/DataTransferItemQt.h:
(WebCore::DataTransferItemQt::kind):
(WebCore::DataTransferItemQt::type):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105648 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 26421928
......@@ -1498,7 +1498,6 @@ IF (ENABLE_DATA_TRANSFER_ITEMS)
)
LIST(APPEND WebCore_SOURCES
dom/DataTransferItem.cpp
dom/DataTransferItemList.cpp
dom/StringCallback.cpp
)
ENDIF ()
......
2012-01-23 Daniel Cheng <dcheng@chromium.org>
Convert DataTransferItem/DataTransferItemList back into an interface class
https://bugs.webkit.org/show_bug.cgi?id=76856
When Qt implemented the DataTransferItemList, a lot of logic was moved into the shared
classes since Chromium/Qt happened to implement it the same way. Now that I want to do some
refactoring/cleanup work to better implement DataTransferItemList in Chromium, we won't
share the same data anymore so it doesn't make sense to keep that code in a common location.
Reviewed by David Levin.
Covered by existing tests.
* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/DataTransferItem.cpp:
* dom/DataTransferItem.h:
* dom/DataTransferItemList.cpp: Removed.
* dom/DataTransferItemList.h:
* platform/chromium/ClipboardChromium.cpp:
(WebCore::ClipboardChromium::mayUpdateItems):
* platform/chromium/DataTransferItemChromium.cpp:
(WebCore::DataTransferItemChromium::create):
(WebCore::DataTransferItemChromium::DataTransferItemChromium):
(WebCore::DataTransferItemChromium::getAsString):
(WebCore::DataTransferItemChromium::getAsFile):
(WebCore::DataTransferItemChromium::clipboardChromium):
* platform/chromium/DataTransferItemChromium.h:
(WebCore::DataTransferItemChromium::kind):
(WebCore::DataTransferItemChromium::type):
* platform/chromium/DataTransferItemListChromium.cpp:
(WebCore::DataTransferItemListChromium::DataTransferItemListChromium):
* platform/chromium/DataTransferItemListChromium.h:
* platform/qt/DataTransferItemListQt.cpp:
(WebCore::DataTransferItemListQt::DataTransferItemListQt):
(WebCore::DataTransferItemListQt::length):
(WebCore::DataTransferItemListQt::item):
(WebCore::DataTransferItemListQt::deleteItem):
(WebCore::DataTransferItemListQt::clear):
(WebCore::DataTransferItemListQt::add):
* platform/qt/DataTransferItemListQt.h:
* platform/qt/DataTransferItemQt.cpp:
(WebCore::DataTransferItemQt::create):
(WebCore::DataTransferItemQt::DataTransferItemQt):
(WebCore::DataTransferItemQt::getAsString):
(WebCore::DataTransferItemQt::getAsFile):
* platform/qt/DataTransferItemQt.h:
(WebCore::DataTransferItemQt::kind):
(WebCore::DataTransferItemQt::type):
2012-01-23 Andreas Kling <awesomekling@apple.com>
Unreviewed buildfix for ENABLE(MUTATION_OBSERVERS) following r105642.
......@@ -4662,7 +4662,6 @@ dom_binding_idls += \
webcore_sources += \
Source/WebCore/dom/DataTransferItem.cpp \
Source/WebCore/dom/DataTransferItem.h \
Source/WebCore/dom/DataTransferItemList.cpp \
Source/WebCore/dom/DataTransferItemList.h \
Source/WebCore/dom/StringCallback.cpp \
Source/WebCore/dom/StringCallback.h
......
......@@ -3014,7 +3014,6 @@ contains(DEFINES, ENABLE_DATA_TRANSFER_ITEMS=1) {
platform/qt/DataTransferItemListQt.h
SOURCES += \
dom/DataTransferItem.cpp \
dom/DataTransferItemList.cpp \
dom/StringCallback.cpp \
platform/qt/DataTransferItemQt.cpp \
platform/qt/DataTransferItemListQt.cpp
......
......@@ -5356,7 +5356,6 @@
'dom/DOMStringMap.h',
'dom/DataTransferItem.cpp',
'dom/DataTransferItem.h',
'dom/DataTransferItemList.cpp',
'dom/DataTransferItemList.h',
'dom/DatasetDOMStringMap.cpp',
'dom/DatasetDOMStringMap.h',
......
......@@ -46797,58 +46797,6 @@
RelativePath="..\dom\DataTransferItem.h"
>
</File>
<File
RelativePath="..\dom\DataTransferItemList.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Cairo_CFLite|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Cairo_CFLite|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_All|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Production|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\dom\DataTransferItemList.h"
>
......@@ -1846,7 +1846,6 @@
77A17AA712F28B2A004E02F6 /* JSOESVertexArrayObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 77A17AA312F28B2A004E02F6 /* JSOESVertexArrayObject.h */; };
77EF62F312F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 77EF62F112F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.cpp */; };
77EF62F412F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.h in Headers */ = {isa = PBXBuildFile; fileRef = 77EF62F212F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.h */; };
781755861365A1B00093BE2E /* DataTransferItemList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 781755851365A1B00093BE2E /* DataTransferItemList.cpp */; };
79AC9218109945C80021266E /* JSCompositionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79AC9216109945C80021266E /* JSCompositionEvent.cpp */; };
79AC9219109945C80021266E /* JSCompositionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 79AC9217109945C80021266E /* JSCompositionEvent.h */; };
79F2F5A11091939A000D87CB /* CompositionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79F2F59E1091939A000D87CB /* CompositionEvent.cpp */; };
......@@ -8706,7 +8705,6 @@
77A17AA312F28B2A004E02F6 /* JSOESVertexArrayObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSOESVertexArrayObject.h; sourceTree = "<group>"; };
77EF62F112F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGLVertexArrayObjectOES.cpp; sourceTree = "<group>"; };
77EF62F212F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLVertexArrayObjectOES.h; sourceTree = "<group>"; };
781755851365A1B00093BE2E /* DataTransferItemList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataTransferItemList.cpp; sourceTree = "<group>"; };
79AC9216109945C80021266E /* JSCompositionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCompositionEvent.cpp; sourceTree = "<group>"; };
79AC9217109945C80021266E /* JSCompositionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCompositionEvent.h; sourceTree = "<group>"; };
79F2F59E1091939A000D87CB /* CompositionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompositionEvent.cpp; sourceTree = "<group>"; };
......@@ -20359,7 +20357,6 @@
815E6166132587AA00B622B0 /* DataTransferItem.cpp */,
81AC5997131636E60009A7E0 /* DataTransferItem.h */,
81AC5AE81316392E0009A7E0 /* DataTransferItem.idl */,
781755851365A1B00093BE2E /* DataTransferItemList.cpp */,
81AC5998131636E60009A7E0 /* DataTransferItemList.h */,
81AC5AE91316392E0009A7E0 /* DataTransferItemList.idl */,
A8C228A011D5722E00D5A7D3 /* DecodedDataDocumentParser.cpp */,
......@@ -24670,7 +24667,6 @@
1AD51A150CB59CD300953D11 /* DatabaseTracker.cpp in Sources */,
BC64641D11D7F416006455B0 /* DatasetDOMStringMap.cpp in Sources */,
815E6167132587AA00B622B0 /* DataTransferItem.cpp in Sources */,
781755861365A1B00093BE2E /* DataTransferItemList.cpp in Sources */,
2E97CCEA12939CB800C5C8FF /* DataView.cpp in Sources */,
A5732B0A136A161D005C8D7C /* DateComponents.cpp in Sources */,
F55B3DB51251F12D003EF269 /* DateInputType.cpp in Sources */,
......@@ -31,8 +31,6 @@
#include "config.h"
#include "DataTransferItem.h"
#include "Clipboard.h"
#if ENABLE(DATA_TRANSFER_ITEMS)
namespace WebCore {
......@@ -40,35 +38,6 @@ namespace WebCore {
const char DataTransferItem::kindString[] = "string";
const char DataTransferItem::kindFile[] = "file";
DataTransferItem::DataTransferItem(PassRefPtr<Clipboard> owner, const String& kind, const String& type)
: m_owner(owner)
, m_kind(kind)
, m_type(type)
{
}
Clipboard* DataTransferItem::owner()
{
return m_owner.get();
}
String DataTransferItem::kind() const
{
if (m_owner->policy() == ClipboardNumb)
return String();
return m_kind;
}
String DataTransferItem::type() const
{
if (m_owner->policy() == ClipboardNumb)
return String();
return m_type;
}
} // namespace WebCore
#endif // ENABLE(DATA_TRANSFER_ITEMS)
......@@ -49,28 +49,14 @@ class DataTransferItem : public RefCounted<DataTransferItem> {
public:
virtual ~DataTransferItem() { }
static PassRefPtr<DataTransferItem> create(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, const String& data, const String& type);
static PassRefPtr<DataTransferItem> create(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, PassRefPtr<File>);
static const char kindString[];
static const char kindFile[];
String kind() const;
String type() const;
virtual void getAsString(PassRefPtr<StringCallback>) = 0;
virtual PassRefPtr<Blob> getAsFile() = 0;
protected:
DataTransferItem(PassRefPtr<Clipboard> owner, const String& kind, const String& type);
Clipboard* owner();
private:
friend class DataTransferItemList;
virtual String kind() const = 0;
virtual String type() const = 0;
const RefPtr<Clipboard> m_owner;
const String m_kind;
const String m_type;
virtual void getAsString(PassRefPtr<StringCallback>) const = 0;
virtual PassRefPtr<Blob> getAsFile() const = 0;
};
} // namespace WebCore
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "DataTransferItemList.h"
#include "DataTransferItem.h"
#include "ExceptionCode.h"
#if ENABLE(DATA_TRANSFER_ITEMS)
namespace WebCore {
DataTransferItemList::DataTransferItemList(PassRefPtr<Clipboard> clipboard, ScriptExecutionContext* context)
: m_owner(clipboard)
, m_context(context)
{
}
size_t DataTransferItemList::length()
{
if (m_owner->policy() == ClipboardNumb)
return 0;
return m_items.size();
}
PassRefPtr<DataTransferItem> DataTransferItemList::item(unsigned long index)
{
if (m_owner->policy() == ClipboardNumb || index >= length())
return 0;
return m_items[index];
}
void DataTransferItemList::deleteItem(unsigned long index, ExceptionCode& ec)
{
if (m_owner->policy() != ClipboardWritable) {
ec = INVALID_STATE_ERR;
return;
}
if (index >= length())
return;
m_items.remove(index);
}
void DataTransferItemList::clear()
{
if (m_owner->policy() != ClipboardWritable)
return;
m_items.clear();
}
void DataTransferItemList::add(const String& data, const String& type, ExceptionCode& ec)
{
if (m_owner->policy() != ClipboardWritable)
return;
// Only one 'string' item with a given type is allowed in the collection.
for (size_t i = 0; i < m_items.size(); ++i) {
if (m_items[i]->type() == type && m_items[i]->kind() == DataTransferItem::kindString) {
ec = NOT_SUPPORTED_ERR;
return;
}
}
m_items.append(DataTransferItem::create(m_owner, m_context, data, type));
}
void DataTransferItemList::add(PassRefPtr<File> file)
{
if (m_owner->policy() != ClipboardWritable || !file)
return;
m_items.append(DataTransferItem::create(m_owner, m_context, file));
}
}
#endif
......@@ -48,23 +48,12 @@ class DataTransferItemList : public RefCounted<DataTransferItemList> {
public:
virtual ~DataTransferItemList() { }
virtual size_t length();
virtual PassRefPtr<DataTransferItem> item(unsigned long index);
// FIXME: Implement V8DataTransferItemList::indexedPropertyDeleter to get this called.
virtual void deleteItem(unsigned long index, ExceptionCode&);
virtual void clear();
virtual void add(const String& data, const String& type, ExceptionCode&);
virtual void add(PassRefPtr<File>);
protected:
DataTransferItemList(PassRefPtr<Clipboard>, ScriptExecutionContext*);
protected:
RefPtr<Clipboard> m_owner;
// Indirectly owned by our parent.
ScriptExecutionContext* m_context;
Vector<RefPtr<DataTransferItem> > m_items;
virtual size_t length() = 0;
virtual PassRefPtr<DataTransferItem> item(unsigned long index) = 0;
virtual void deleteItem(unsigned long index, ExceptionCode&) = 0;
virtual void clear() = 0;
virtual void add(const String& data, const String& type, ExceptionCode&) = 0;
virtual void add(PassRefPtr<File>) = 0;
};
} // namespace WebCore
......
......@@ -375,17 +375,17 @@ void ClipboardChromium::mayUpdateItems(Vector<RefPtr<DataTransferItem> >& items)
bool success = false;
String plainText = m_dataObject->getData(mimeTypeTextPlain, success);
if (success)
items.append(DataTransferItem::create(this, scriptExecutionContext, plainText, mimeTypeTextPlain));
items.append(DataTransferItemChromium::create(this, scriptExecutionContext, plainText, mimeTypeTextPlain));
success = false;
String htmlText = m_dataObject->getData(mimeTypeTextHTML, success);
if (success)
items.append(DataTransferItem::create(this, scriptExecutionContext, htmlText, mimeTypeTextHTML));
items.append(DataTransferItemChromium::create(this, scriptExecutionContext, htmlText, mimeTypeTextHTML));
if (m_dataObject->containsFilenames()) {
const Vector<String>& filenames = m_dataObject->filenames();
for (Vector<String>::const_iterator it = filenames.begin(); it != filenames.end(); ++it)
items.append(DataTransferItem::create(this, scriptExecutionContext, File::create(*it)));
items.append(DataTransferItemChromium::create(this, scriptExecutionContext, File::create(*it)));
}
m_dragStorageUpdated = false;
}
......
......@@ -53,40 +53,44 @@ PassRefPtr<DataTransferItemChromium> DataTransferItemChromium::createFromPastebo
return adoptRef(new DataTransferItemChromium(owner, context, PasteboardSource, DataTransferItem::kindFile, type, ""));
}
PassRefPtr<DataTransferItem> DataTransferItem::create(PassRefPtr<Clipboard> owner,
ScriptExecutionContext* context,
const String& data,
const String& type)
PassRefPtr<DataTransferItemChromium> DataTransferItemChromium::create(PassRefPtr<Clipboard> owner,
ScriptExecutionContext* context,
const String& data,
const String& type)
{
return adoptRef(new DataTransferItemChromium(owner, context, DataTransferItemChromium::InternalSource, kindString, type, data));
}
PassRefPtr<DataTransferItem> DataTransferItem::create(PassRefPtr<Clipboard> owner,
ScriptExecutionContext* context,
PassRefPtr<File> file)
PassRefPtr<DataTransferItemChromium> DataTransferItemChromium::create(PassRefPtr<Clipboard> owner,
ScriptExecutionContext* context,
PassRefPtr<File> file)
{
return adoptRef(new DataTransferItemChromium(owner, context, DataTransferItemChromium::InternalSource, file));
}
DataTransferItemChromium::DataTransferItemChromium(PassRefPtr<Clipboard> owner, ScriptExecutionContext* context, DataSource source, const String& kind, const String& type, const String& data)
: DataTransferItem(owner, kind, type)
, m_context(context)
: m_context(context)
, m_owner(owner)
, m_kind(kind)
, m_type(type)
, m_source(source)
, m_data(data)
{
}
DataTransferItemChromium::DataTransferItemChromium(PassRefPtr<Clipboard> owner, ScriptExecutionContext* context, DataSource source, PassRefPtr<File> file)
: DataTransferItem(owner, DataTransferItem::kindFile, file.get() ? file->type() : String())
, m_context(context)
: m_context(context)
, m_owner(owner)
, m_kind(kindFile)
, m_type(file.get() ? file->type() : String())
, m_source(source)
, m_file(file)
{
}
void DataTransferItemChromium::getAsString(PassRefPtr<StringCallback> callback)
void DataTransferItemChromium::getAsString(PassRefPtr<StringCallback> callback) const
{
if ((owner()->policy() != ClipboardReadable && owner()->policy() != ClipboardWritable)
if ((m_owner->policy() != ClipboardReadable && m_owner->policy() != ClipboardWritable)
|| kind() != kindString)
return;
......@@ -116,7 +120,7 @@ void DataTransferItemChromium::getAsString(PassRefPtr<StringCallback> callback)
ASSERT_NOT_REACHED();
}
PassRefPtr<Blob> DataTransferItemChromium::getAsFile()
PassRefPtr<Blob> DataTransferItemChromium::getAsFile() const
{
if (kind() != kindFile || clipboardChromium()->storageHasUpdated())
return 0;
......@@ -146,9 +150,9 @@ PassRefPtr<Blob> DataTransferItemChromium::getAsFile()
return 0;
}
ClipboardChromium* DataTransferItemChromium::clipboardChromium()
ClipboardChromium* DataTransferItemChromium::clipboardChromium() const
{
return static_cast<ClipboardChromium*>(owner());
return static_cast<ClipboardChromium*>(m_owner.get());
}
} // namespace WebCore
......
......@@ -46,25 +46,32 @@ class ScriptExecutionContext;
class DataTransferItemChromium : public DataTransferItem {
public:
static PassRefPtr<DataTransferItemChromium> create(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, const String& data, const String& type);
static PassRefPtr<DataTransferItemChromium> create(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, PassRefPtr<File>);
static PassRefPtr<DataTransferItemChromium> createFromPasteboard(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, const String& type);
virtual void getAsString(PassRefPtr<StringCallback>);
virtual PassRefPtr<Blob> getAsFile();
virtual String kind() const { return m_kind; }
virtual String type() const { return m_type; }
virtual void getAsString(PassRefPtr<StringCallback>) const;
virtual PassRefPtr<Blob> getAsFile() const;
private:
friend class DataTransferItemListChromium;
enum DataSource {
PasteboardSource,
InternalSource,
};
friend class DataTransferItem;
DataTransferItemChromium(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, DataSource, const String& kind, const String& type, const String& data);
DataTransferItemChromium(PassRefPtr<Clipboard> owner, ScriptExecutionContext*, DataSource, PassRefPtr<File>);
ClipboardChromium* clipboardChromium();
ClipboardChromium* clipboardChromium() const;
ScriptExecutionContext* m_context;
const RefPtr<Clipboard> m_owner;
const String m_kind;
const String m_type;
const DataSource m_source;
const String m_data;
RefPtr<File> m_file;
......
......@@ -53,7 +53,8 @@ PassRefPtr<DataTransferItemListChromium> DataTransferItemListChromium::create(Pa
}
DataTransferItemListChromium::DataTransferItemListChromium(PassRefPtr<Clipboard> owner, ScriptExecutionContext* context)
: DataTransferItemList(owner, context)
: m_owner(owner)
, m_context(context)
{
}
......
......@@ -50,9 +50,9 @@ class DataTransferItemListChromium : public DataTransferItemList {
public:
static PassRefPtr<DataTransferItemListChromium> create(PassRefPtr<Clipboard>, ScriptExecutionContext*);
// DataTransferItemList overrides.
virtual size_t length();
virtual PassRefPtr<DataTransferItem> item(unsigned long index);
// FIXME: Implement V8DataTransferItemList::indexedPropertyDeleter to get this called.
virtual void deleteItem(unsigned long index, ExceptionCode&);
virtual void clear();
virtual void add(const String& data, const String& type, ExceptionCode&);
......@@ -61,6 +61,11 @@ public:
private:
DataTransferItemListChromium(PassRefPtr<Clipboard>, ScriptExecutionContext*);
ClipboardChromium* clipboardChromium() const;
RefPtr<Clipboard> m_owner;
// Indirectly owned by our parent.
ScriptExecutionContext* m_context;
Vector<RefPtr<DataTransferItem> > m_items;
};
} // namespace WebCore
......
......@@ -40,10 +40,73 @@ PassRefPtr<DataTransferItemListQt> DataTransferItemListQt::create(PassRefPtr<Cli
}
DataTransferItemListQt::DataTransferItemListQt(PassRefPtr<Clipboard> owner, ScriptExecutionContext* context)
: DataTransferItemList(owner, context)
: m_owner(clipboard)
, m_context(context)
{
}
size_t DataTransferItemListQt::length()
{
if (m_owner->policy() == ClipboardNumb)
return 0;
return m_items.size();
}
PassRefPtr<DataTransferItem> DataTransferItemListQt::item(unsigned long index)
{
if (m_owner->policy() == ClipboardNumb || index >= length())
return 0;
return m_items[index];
}
void DataTransferItemListQt::deleteItem(unsigned long index, ExceptionCode& ec)
{
if (m_owner->policy() != ClipboardWritable) {
ec = INVALID_STATE_ERR;
return;
}
if (index >= length())
return;
m_items.remove(index);
}
void DataTransferItemListQt::clear()
{
if (m_owner->policy() != ClipboardWritable)