OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "app/os_exchange_data.h" | |
6 | |
7 #include "base/pickle.h" | |
8 #include "googleurl/src/gurl.h" | |
9 | |
10 OSExchangeData::DownloadFileInfo::DownloadFileInfo( | |
11 const FilePath& filename, | |
12 DownloadFileProvider* downloader) | |
13 : filename(filename), | |
14 downloader(downloader) { | |
15 } | |
16 | |
17 OSExchangeData::DownloadFileInfo::~DownloadFileInfo() {} | |
18 | |
19 OSExchangeData::OSExchangeData() : provider_(CreateProvider()) { | |
20 } | |
21 | |
22 OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) { | |
23 } | |
24 | |
25 OSExchangeData::~OSExchangeData() { | |
26 } | |
27 | |
28 void OSExchangeData::SetString(const std::wstring& data) { | |
29 provider_->SetString(data); | |
30 } | |
31 | |
32 void OSExchangeData::SetURL(const GURL& url, const std::wstring& title) { | |
33 provider_->SetURL(url, title); | |
34 } | |
35 | |
36 void OSExchangeData::SetFilename(const std::wstring& full_path) { | |
37 provider_->SetFilename(full_path); | |
38 } | |
39 | |
40 void OSExchangeData::SetPickledData(CustomFormat format, const Pickle& data) { | |
41 provider_->SetPickledData(format, data); | |
42 } | |
43 | |
44 bool OSExchangeData::GetString(std::wstring* data) const { | |
45 return provider_->GetString(data); | |
46 } | |
47 | |
48 bool OSExchangeData::GetURLAndTitle(GURL* url, std::wstring* title) const { | |
49 return provider_->GetURLAndTitle(url, title); | |
50 } | |
51 | |
52 bool OSExchangeData::GetFilename(std::wstring* full_path) const { | |
53 return provider_->GetFilename(full_path); | |
54 } | |
55 | |
56 bool OSExchangeData::GetPickledData(CustomFormat format, Pickle* data) const { | |
57 return provider_->GetPickledData(format, data); | |
58 } | |
59 | |
60 bool OSExchangeData::HasString() const { | |
61 return provider_->HasString(); | |
62 } | |
63 | |
64 bool OSExchangeData::HasURL() const { | |
65 return provider_->HasURL(); | |
66 } | |
67 | |
68 bool OSExchangeData::HasFile() const { | |
69 return provider_->HasFile(); | |
70 } | |
71 | |
72 bool OSExchangeData::HasCustomFormat(CustomFormat format) const { | |
73 return provider_->HasCustomFormat(format); | |
74 } | |
75 | |
76 bool OSExchangeData::HasAllFormats( | |
77 int formats, | |
78 const std::set<CustomFormat>& custom_formats) const { | |
79 if ((formats & STRING) != 0 && !HasString()) | |
80 return false; | |
81 if ((formats & URL) != 0 && !HasURL()) | |
82 return false; | |
83 #if defined(OS_WIN) | |
84 if ((formats & FILE_CONTENTS) != 0 && !provider_->HasFileContents()) | |
85 return false; | |
86 if ((formats & HTML) != 0 && !provider_->HasHtml()) | |
87 return false; | |
88 #endif | |
89 if ((formats & FILE_NAME) != 0 && !provider_->HasFile()) | |
90 return false; | |
91 for (std::set<CustomFormat>::const_iterator i = custom_formats.begin(); | |
92 i != custom_formats.end(); ++i) { | |
93 if (!HasCustomFormat(*i)) | |
94 return false; | |
95 } | |
96 return true; | |
97 } | |
98 | |
99 bool OSExchangeData::HasAnyFormat( | |
100 int formats, | |
101 const std::set<CustomFormat>& custom_formats) const { | |
102 if ((formats & STRING) != 0 && HasString()) | |
103 return true; | |
104 if ((formats & URL) != 0 && HasURL()) | |
105 return true; | |
106 #if defined(OS_WIN) | |
107 if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents()) | |
108 return true; | |
109 if ((formats & HTML) != 0 && provider_->HasHtml()) | |
110 return true; | |
111 #endif | |
112 if ((formats & FILE_NAME) != 0 && provider_->HasFile()) | |
113 return true; | |
114 for (std::set<CustomFormat>::const_iterator i = custom_formats.begin(); | |
115 i != custom_formats.end(); ++i) { | |
116 if (HasCustomFormat(*i)) | |
117 return true; | |
118 } | |
119 return false; | |
120 } | |
121 | |
122 #if defined(OS_WIN) | |
123 void OSExchangeData::SetFileContents(const std::wstring& filename, | |
124 const std::string& file_contents) { | |
125 provider_->SetFileContents(filename, file_contents); | |
126 } | |
127 | |
128 void OSExchangeData::SetHtml(const std::wstring& html, const GURL& base_url) { | |
129 provider_->SetHtml(html, base_url); | |
130 } | |
131 | |
132 bool OSExchangeData::GetFileContents(std::wstring* filename, | |
133 std::string* file_contents) const { | |
134 return provider_->GetFileContents(filename, file_contents); | |
135 } | |
136 | |
137 bool OSExchangeData::GetHtml(std::wstring* html, GURL* base_url) const { | |
138 return provider_->GetHtml(html, base_url); | |
139 } | |
140 | |
141 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) { | |
142 return provider_->SetDownloadFileInfo(download); | |
143 } | |
144 #endif | |
OLD | NEW |