diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 21:58:18 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 21:58:18 +0000 |
commit | 8c3dc79bc13ba84f418d3c135e1bf296a3e29722 (patch) | |
tree | 32eb9688d500a90eb74a7c4f8cb5a97e507dd0fc /app/os_exchange_data.h | |
parent | abaccb2cb8cff8138e5ea9daf420645e5852c9eb (diff) | |
download | chromium_src-8c3dc79bc13ba84f418d3c135e1bf296a3e29722.zip chromium_src-8c3dc79bc13ba84f418d3c135e1bf296a3e29722.tar.gz chromium_src-8c3dc79bc13ba84f418d3c135e1bf296a3e29722.tar.bz2 |
Refactors OSExchangeData for easier portability.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/164401
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/os_exchange_data.h')
-rw-r--r-- | app/os_exchange_data.h | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/app/os_exchange_data.h b/app/os_exchange_data.h index 2400266..a956b80 100644 --- a/app/os_exchange_data.h +++ b/app/os_exchange_data.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,15 +7,18 @@ #include "build/build_config.h" +#include <set> +#include <string> +#include <vector> + #if defined(OS_WIN) #include <objidl.h> -#include "base/scoped_comptr_win.h" +#elif defined(OS_LINUX) +#include <gtk/gtk.h> #endif -#include <string> -#include <vector> - #include "base/basictypes.h" +#include "base/scoped_ptr.h" class GURL; class Pickle; @@ -29,25 +32,71 @@ class Pickle; // translating that into something the OS can understand. // /////////////////////////////////////////////////////////////////////////////// -#if defined(OS_WIN) -class OSExchangeData : public IDataObject { -#else class OSExchangeData { -#endif public: + // CustomFormats are used for non-standard data types. For example, bookmark + // nodes are written using a CustomFormat. #if defined(OS_WIN) - // Returns true if source has plain text that is a valid url. - static bool HasPlainTextURL(IDataObject* source); + typedef CLIPFORMAT CustomFormat; +#elif defined(OS_LINUX) + typedef GdkAtom CustomFormat; +#endif - // Returns true if source has plain text that is a valid URL and sets url to - // that url. - static bool GetPlainTextURL(IDataObject* source, GURL* url); + // Enumeration of the known formats. + enum Format { + STRING = 1 << 0, + URL = 1 << 1, + FILE_CONTENTS = 1 << 2, + FILE_NAME = 1 << 3, + PICKLED_DATA = 1 << 4, + HTML = 1 << 5 + }; - explicit OSExchangeData(IDataObject* source); -#endif + // Provider defines the platform specific part of OSExchangeData that + // interacts with the native system. + class Provider { + public: + Provider() {} + virtual ~Provider() {} + + virtual void SetString(const std::wstring& data) = 0; + virtual void SetURL(const GURL& url, const std::wstring& title) = 0; + virtual void SetFilename(const std::wstring& full_path) = 0; + virtual void SetPickledData(CustomFormat format, const Pickle& data) = 0; + virtual void SetFileContents(const std::wstring& filename, + const std::string& file_contents) = 0; + virtual void SetHtml(const std::wstring& html, const GURL& base_url) = 0; + + virtual bool GetString(std::wstring* data) const = 0; + virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const = 0; + virtual bool GetFilename(std::wstring* full_path) const = 0; + virtual bool GetPickledData(CustomFormat format, Pickle* data) const = 0; + virtual bool GetFileContents(std::wstring* filename, + std::string* file_contents) const = 0; + virtual bool GetHtml(std::wstring* html, GURL* base_url) const = 0; + + virtual bool HasString() const = 0; + virtual bool HasURL() const = 0; + virtual bool HasFile() const = 0; + virtual bool HasFileContents() const = 0; + virtual bool HasHtml() const = 0; + virtual bool HasCustomFormat( + OSExchangeData::CustomFormat format) const = 0; + }; OSExchangeData(); - virtual ~OSExchangeData(); + // Creates an OSExchangeData with the specified provider. OSExchangeData + // takes ownership of the supplied provider. + explicit OSExchangeData(Provider* provider); + + ~OSExchangeData(); + + // Registers the specific string as a possible format for data. + static CustomFormat RegisterCustomFormat(const std::string& type); + + // Returns the Provider, which actually stores and manages the data. + const Provider& provider() const { return *provider_; } + Provider& provider() { return *provider_; } // These functions add data to the OSExchangeData object of various Chrome // types. The OSExchangeData object takes care of translating the data into @@ -64,10 +113,8 @@ class OSExchangeData { void SetURL(const GURL& url, const std::wstring& title); // A full path to a file void SetFilename(const std::wstring& full_path); -#if defined(OS_WIN) // Adds pickled data of the specified format. - void SetPickledData(CLIPFORMAT format, const Pickle& data); -#endif + void SetPickledData(CustomFormat format, const Pickle& data); // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). void SetFileContents(const std::wstring& filename, const std::string& file_contents); @@ -83,9 +130,7 @@ class OSExchangeData { bool GetURLAndTitle(GURL* url, std::wstring* title) const; // Return the path of a file, if available. bool GetFilename(std::wstring* full_path) const; -#if defined(OS_WIN) - bool GetPickledData(CLIPFORMAT format, Pickle* data) const; -#endif + bool GetPickledData(CustomFormat format, Pickle* data) const; bool GetFileContents(std::wstring* filename, std::string* file_contents) const; bool GetHtml(std::wstring* html, GURL* base_url) const; @@ -94,70 +139,25 @@ class OSExchangeData { // returning anything. bool HasString() const; bool HasURL() const; - bool HasURLTitle() const; bool HasFile() const; -#if defined(OS_WIN) - bool HasFormat(CLIPFORMAT format) const; - - // IDataObject implementation: - HRESULT __stdcall GetData(FORMATETC* format_etc, STGMEDIUM* medium); - HRESULT __stdcall GetDataHere(FORMATETC* format_etc, STGMEDIUM* medium); - HRESULT __stdcall QueryGetData(FORMATETC* format_etc); - HRESULT __stdcall GetCanonicalFormatEtc( - FORMATETC* format_etc, FORMATETC* result); - HRESULT __stdcall SetData( - FORMATETC* format_etc, STGMEDIUM* medium, BOOL should_release); - HRESULT __stdcall EnumFormatEtc( - DWORD direction, IEnumFORMATETC** enumerator); - HRESULT __stdcall DAdvise( - FORMATETC* format_etc, DWORD advf, IAdviseSink* sink, DWORD* connection); - HRESULT __stdcall DUnadvise(DWORD connection); - HRESULT __stdcall EnumDAdvise(IEnumSTATDATA** enumerator); - - // IUnknown implementation: - HRESULT __stdcall QueryInterface(const IID& iid, void** object); - ULONG __stdcall AddRef(); - ULONG __stdcall Release(); -#endif + bool HasCustomFormat(CustomFormat format) const; - private: -#if defined(OS_WIN) - // FormatEtcEnumerator only likes us for our StoredDataMap typedef. - friend class FormatEtcEnumerator; - - // Our internal representation of stored data & type info. - struct StoredDataInfo { - FORMATETC format_etc; - STGMEDIUM* medium; - bool owns_medium; - - StoredDataInfo(CLIPFORMAT cf, STGMEDIUM* a_medium) { - format_etc.cfFormat = cf; - format_etc.dwAspect = DVASPECT_CONTENT; - format_etc.lindex = -1; - format_etc.ptd = NULL; - format_etc.tymed = a_medium->tymed; - - owns_medium = true; - - medium = a_medium; - } - - ~StoredDataInfo() { - if (owns_medium) { - ReleaseStgMedium(medium); - delete medium; - } - } - }; + // Returns true if this OSExchangeData has data for ALL the formats in + // |formats| and ALL the custom formats in |custom_formats|. + bool HasAllFormats(int formats, + const std::set<CustomFormat>& custom_formats) const; - typedef std::vector<StoredDataInfo*> StoredData; - StoredData contents_; + // Returns true if this OSExchangeData has data in any of the formats in + // |formats| or any custom format in |custom_formats|. + bool HasAnyFormat(int formats, + const std::set<CustomFormat>& custom_formats) const; - ScopedComPtr<IDataObject> source_object_; + private: + // Creates the platform specific Provider. + static Provider* CreateProvider(); - LONG ref_count_; -#endif + // Provides the actual data. + scoped_ptr<Provider> provider_; DISALLOW_COPY_AND_ASSIGN(OSExchangeData); }; |