OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_clipboard_api.h" | 5 #include "chrome/browser/extensions/extension_clipboard_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 const char kMimeTypeNotSupportedError[] = "MIME type is not supported."; | 35 const char kMimeTypeNotSupportedError[] = "MIME type is not supported."; |
36 const char kBufferReadNotSupportedError[] = | 36 const char kBufferReadNotSupportedError[] = |
37 "Reading from the buffer is not supported."; | 37 "Reading from the buffer is not supported."; |
38 const char kBufferWriteNotSupportedError[] = | 38 const char kBufferWriteNotSupportedError[] = |
39 "Writing to the buffer is not supported."; | 39 "Writing to the buffer is not supported."; |
40 const char kBufferNotSupportedError[] = "Buffer is not supported."; | 40 const char kBufferNotSupportedError[] = "Buffer is not supported."; |
41 | 41 |
42 // Converts data MIME type to data format known to ui::Clipboard. MIME type is | 42 // Converts data MIME type to data format known to ui::Clipboard. MIME type is |
43 // given as a string. Returns false iff the string could not be converted. | 43 // given as a string. Returns false iff the string could not be converted. |
44 bool ConvertMimeTypeStringToClipboardType(const std::string& mime_type, | 44 bool ConvertMimeTypeStringToClipboardType( |
45 ui::Clipboard::FormatType* format_type) { | 45 const std::string& mime_type, |
| 46 ui::Clipboard::FormatType* format_type) { |
46 if (mime_type == kMimeTypePlainText) { | 47 if (mime_type == kMimeTypePlainText) { |
47 *format_type = ui::Clipboard::GetPlainTextFormatType(); | 48 *format_type = ui::Clipboard::GetPlainTextFormatType(); |
48 return true; | 49 return true; |
49 } | 50 } |
50 if (mime_type == kMimeTypeHtml) { | 51 if (mime_type == kMimeTypeHtml) { |
51 *format_type = ui::Clipboard::GetHtmlFormatType(); | 52 *format_type = ui::Clipboard::GetHtmlFormatType(); |
52 return true; | 53 return true; |
53 } | 54 } |
54 return false; | 55 return false; |
55 } | 56 } |
56 | 57 |
57 // Converts data MIME type to data format known to ui::Clipboard. MIME type is | 58 // Converts data MIME type to data format known to ui::Clipboard. MIME type is |
58 // given as a enum value. Returns false iff the enum value could not be | 59 // given as a enum value. Returns false iff the enum value could not be |
59 // converted. | 60 // converted. |
60 bool ConvertMimeTypeEnumToClipboardType(SupportedMimeType mime_type, | 61 bool ConvertMimeTypeEnumToClipboardType( |
61 ui::Clipboard::FormatType* format_type) { | 62 SupportedMimeType mime_type, |
| 63 ui::Clipboard::FormatType* format_type) { |
62 switch (mime_type) { | 64 switch (mime_type) { |
63 case MIME_TYPE_TEXT: | 65 case MIME_TYPE_TEXT: |
64 *format_type = ui::Clipboard::GetPlainTextFormatType(); | 66 *format_type = ui::Clipboard::GetPlainTextFormatType(); |
65 return true; | 67 return true; |
66 case MIME_TYPE_HTML: | 68 case MIME_TYPE_HTML: |
67 *format_type = ui::Clipboard::GetHtmlFormatType(); | 69 *format_type = ui::Clipboard::GetHtmlFormatType(); |
68 return true; | 70 return true; |
69 default: | 71 default: |
70 return false; | 72 return false; |
71 } | 73 } |
(...skipping 11 matching lines...) Expand all Loading... |
83 *mime_type_str = kMimeTypeHtml; | 85 *mime_type_str = kMimeTypeHtml; |
84 return true; | 86 return true; |
85 default: | 87 default: |
86 return false; | 88 return false; |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
90 // Converts a buffer type given as a string to buffer type known to | 92 // Converts a buffer type given as a string to buffer type known to |
91 // ui::Clipboard. Returns false iff the conversion is not possible. | 93 // ui::Clipboard. Returns false iff the conversion is not possible. |
92 bool ConvertBufferTypeToClipboardType(const std::string& buffer, | 94 bool ConvertBufferTypeToClipboardType(const std::string& buffer, |
93 ui::Clipboard::Buffer* buffer_type) { | 95 ui::Clipboard::Buffer* buffer_type) { |
94 if (buffer == kBufferStandard) { | 96 if (buffer == kBufferStandard) { |
95 *buffer_type = ui::Clipboard::BUFFER_STANDARD; | 97 *buffer_type = ui::Clipboard::BUFFER_STANDARD; |
96 return true; | 98 return true; |
97 } | 99 } |
98 if (buffer == kBufferSelection) { | 100 if (buffer == kBufferSelection) { |
99 *buffer_type = ui::Clipboard::BUFFER_SELECTION; | 101 *buffer_type = ui::Clipboard::BUFFER_SELECTION; |
100 return true; | 102 return true; |
101 } | 103 } |
102 return false; | 104 return false; |
103 } | 105 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 bool ReadDataClipboardFunction::RunImpl() { | 164 bool ReadDataClipboardFunction::RunImpl() { |
163 if (args_->GetSize() != 2) { | 165 if (args_->GetSize() != 2) { |
164 return false; | 166 return false; |
165 } | 167 } |
166 std::string mime_type; | 168 std::string mime_type; |
167 args_->GetString(0, &mime_type); | 169 args_->GetString(0, &mime_type); |
168 | 170 |
169 std::string buffer; | 171 std::string buffer; |
170 args_->GetString(1, &buffer); | 172 args_->GetString(1, &buffer); |
171 | 173 |
172 // Windows and Mac don't support selection clipboard buffer. | 174 // Windows, Mac and Aura don't support selection clipboard buffer. |
173 #if (defined(OS_WIN) || defined(OS_MACOSX)) | 175 #if (defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA)) |
174 if (buffer != kBufferStandard) { | 176 if (buffer != kBufferStandard) { |
175 error_ = kBufferReadNotSupportedError; | 177 error_ = kBufferReadNotSupportedError; |
176 return false; | 178 return false; |
177 } | 179 } |
178 #endif | 180 #endif |
179 | 181 |
180 if (mime_type == kMimeTypePlainText) | 182 if (mime_type == kMimeTypePlainText) |
181 return ReadPlainText(buffer); | 183 return ReadPlainText(buffer); |
182 | 184 |
183 if (mime_type == kMimeTypeHtml) | 185 if (mime_type == kMimeTypeHtml) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 std::string mime_type_str; | 261 std::string mime_type_str; |
260 if (!MimeTypeEnumToString(mime_type, &mime_type_str)) | 262 if (!MimeTypeEnumToString(mime_type, &mime_type_str)) |
261 continue; | 263 continue; |
262 availableMimeTypes->Append(new StringValue(mime_type_str)); | 264 availableMimeTypes->Append(new StringValue(mime_type_str)); |
263 } | 265 } |
264 } | 266 } |
265 | 267 |
266 result_.reset(availableMimeTypes); | 268 result_.reset(availableMimeTypes); |
267 return true; | 269 return true; |
268 } | 270 } |
OLD | NEW |