| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/html_viewer/webclipboard_impl.h" | 5 #include "mojo/services/html_viewer/webclipboard_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "mojo/services/html_viewer/blink_basic_type_converters.h" | 8 #include "mojo/services/html_viewer/blink_basic_type_converters.h" |
| 9 | 9 |
| 10 using mojo::Array; | 10 using mojo::Array; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 case FormatBookmark: | 93 case FormatBookmark: |
| 94 // This might be difficult. | 94 // This might be difficult. |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 blink::WebVector<blink::WebString> WebClipboardImpl::readAvailableTypes( | 101 blink::WebVector<blink::WebString> WebClipboardImpl::readAvailableTypes( |
| 102 Buffer buffer, | 102 Buffer buffer, |
| 103 bool* containsFilenames) { | 103 bool* contains_filenames) { |
| 104 Clipboard::Type clipboard_type = ConvertBufferType(buffer); | 104 Clipboard::Type clipboard_type = ConvertBufferType(buffer); |
| 105 | 105 |
| 106 std::vector<std::string> types; | 106 std::vector<std::string> types; |
| 107 clipboard_->GetAvailableMimeTypes( | 107 clipboard_->GetAvailableMimeTypes( |
| 108 clipboard_type, base::Bind(&CopyVectorString, &types)); | 108 clipboard_type, base::Bind(&CopyVectorString, &types)); |
| 109 | 109 |
| 110 // Force this to be synchronous. | 110 // Force this to be synchronous. |
| 111 clipboard_.WaitForIncomingMethodCall(); | 111 clipboard_.WaitForIncomingMethodCall(); |
| 112 | 112 |
| 113 // AFAICT, every instance of setting containsFilenames is false. | 113 // AFAICT, every instance of setting contains_filenames is false. |
| 114 *containsFilenames = false; | 114 *contains_filenames = false; |
| 115 | 115 |
| 116 blink::WebVector<blink::WebString> output(types.size()); | 116 blink::WebVector<blink::WebString> output(types.size()); |
| 117 for (size_t i = 0; i < types.size(); ++i) { | 117 for (size_t i = 0; i < types.size(); ++i) { |
| 118 output[i] = blink::WebString::fromUTF8(types[i]); | 118 output[i] = blink::WebString::fromUTF8(types[i]); |
| 119 } | 119 } |
| 120 | 120 |
| 121 return output; | 121 return output; |
| 122 } | 122 } |
| 123 | 123 |
| 124 blink::WebString WebClipboardImpl::readPlainText(Buffer buffer) { | 124 blink::WebString WebClipboardImpl::readPlainText(Buffer buffer) { |
| 125 Clipboard::Type type = ConvertBufferType(buffer); | 125 Clipboard::Type type = ConvertBufferType(buffer); |
| 126 | 126 |
| 127 blink::WebString text; | 127 blink::WebString text; |
| 128 clipboard_->ReadMimeType(type, Clipboard::MIME_TYPE_TEXT, | 128 clipboard_->ReadMimeType(type, Clipboard::MIME_TYPE_TEXT, |
| 129 base::Bind(&CopyWebString, &text)); | 129 base::Bind(&CopyWebString, &text)); |
| 130 | 130 |
| 131 // Force this to be synchronous. | 131 // Force this to be synchronous. |
| 132 clipboard_.WaitForIncomingMethodCall(); | 132 clipboard_.WaitForIncomingMethodCall(); |
| 133 | 133 |
| 134 return text; | 134 return text; |
| 135 } | 135 } |
| 136 | 136 |
| 137 blink::WebString WebClipboardImpl::readHTML(Buffer buffer, | 137 blink::WebString WebClipboardImpl::readHTML(Buffer buffer, |
| 138 blink::WebURL* pageURL, | 138 blink::WebURL* page_url, |
| 139 unsigned* fragmentStart, | 139 unsigned* fragment_start, |
| 140 unsigned* fragmentEnd) { | 140 unsigned* fragment_end) { |
| 141 Clipboard::Type type = ConvertBufferType(buffer); | 141 Clipboard::Type type = ConvertBufferType(buffer); |
| 142 | 142 |
| 143 blink::WebString html; | 143 blink::WebString html; |
| 144 clipboard_->ReadMimeType(type, Clipboard::MIME_TYPE_HTML, | 144 clipboard_->ReadMimeType(type, Clipboard::MIME_TYPE_HTML, |
| 145 base::Bind(&CopyWebString, &html)); | 145 base::Bind(&CopyWebString, &html)); |
| 146 clipboard_.WaitForIncomingMethodCall(); | 146 clipboard_.WaitForIncomingMethodCall(); |
| 147 | 147 |
| 148 *fragmentStart = 0; | 148 *fragment_start = 0; |
| 149 *fragmentEnd = static_cast<unsigned>(html.length()); | 149 *fragment_end = static_cast<unsigned>(html.length()); |
| 150 | 150 |
| 151 clipboard_->ReadMimeType(type, Clipboard::MIME_TYPE_URL, | 151 clipboard_->ReadMimeType(type, Clipboard::MIME_TYPE_URL, |
| 152 base::Bind(&CopyURL, pageURL)); | 152 base::Bind(&CopyURL, page_url)); |
| 153 clipboard_.WaitForIncomingMethodCall(); | 153 clipboard_.WaitForIncomingMethodCall(); |
| 154 | 154 |
| 155 return html; | 155 return html; |
| 156 } | 156 } |
| 157 | 157 |
| 158 blink::WebString WebClipboardImpl::readCustomData( | 158 blink::WebString WebClipboardImpl::readCustomData( |
| 159 Buffer buffer, | 159 Buffer buffer, |
| 160 const blink::WebString& mime_type) { | 160 const blink::WebString& mime_type) { |
| 161 Clipboard::Type clipboard_type = ConvertBufferType(buffer); | 161 Clipboard::Type clipboard_type = ConvertBufferType(buffer); |
| 162 | 162 |
| 163 blink::WebString data; | 163 blink::WebString data; |
| 164 clipboard_->ReadMimeType( | 164 clipboard_->ReadMimeType( |
| 165 clipboard_type, mime_type.utf8(), base::Bind(&CopyWebString, &data)); | 165 clipboard_type, mime_type.utf8(), base::Bind(&CopyWebString, &data)); |
| 166 | 166 |
| 167 // Force this to be synchronous. | 167 // Force this to be synchronous. |
| 168 clipboard_.WaitForIncomingMethodCall(); | 168 clipboard_.WaitForIncomingMethodCall(); |
| 169 | 169 |
| 170 return data; | 170 return data; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void WebClipboardImpl::writePlainText(const blink::WebString& text) { | 173 void WebClipboardImpl::writePlainText(const blink::WebString& plain_text) { |
| 174 Map<String, Array<uint8_t>> data; | 174 Map<String, Array<uint8_t>> data; |
| 175 data[Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(text); | 175 data[Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(plain_text); |
| 176 | 176 |
| 177 clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE, data.Pass()); | 177 clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE, data.Pass()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void WebClipboardImpl::writeHTML(const blink::WebString& htmlText, | 180 void WebClipboardImpl::writeHTML(const blink::WebString& html_text, |
| 181 const blink::WebURL& url, | 181 const blink::WebURL& source_url, |
| 182 const blink::WebString& plainText, | 182 const blink::WebString& plain_text, |
| 183 bool writeSmartPaste) { | 183 bool writeSmartPaste) { |
| 184 Map<String, Array<uint8_t>> data; | 184 Map<String, Array<uint8_t>> data; |
| 185 data[Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(plainText); | 185 data[Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(plain_text); |
| 186 data[Clipboard::MIME_TYPE_HTML] = Array<uint8_t>::From(htmlText); | 186 data[Clipboard::MIME_TYPE_HTML] = Array<uint8_t>::From(html_text); |
| 187 data[Clipboard::MIME_TYPE_URL] = Array<uint8_t>::From(url.string()); | 187 data[Clipboard::MIME_TYPE_URL] = Array<uint8_t>::From(source_url.string()); |
| 188 | 188 |
| 189 if (writeSmartPaste) | 189 if (writeSmartPaste) |
| 190 data[kMimeTypeWebkitSmartPaste] = Array<uint8_t>::From(blink::WebString()); | 190 data[kMimeTypeWebkitSmartPaste] = Array<uint8_t>::From(blink::WebString()); |
| 191 | 191 |
| 192 clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE, data.Pass()); | 192 clipboard_->WriteClipboardData(Clipboard::TYPE_COPY_PASTE, data.Pass()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 Clipboard::Type WebClipboardImpl::ConvertBufferType(Buffer buffer) { | 195 Clipboard::Type WebClipboardImpl::ConvertBufferType(Buffer buffer) { |
| 196 switch (buffer) { | 196 switch (buffer) { |
| 197 case BufferStandard: | 197 case BufferStandard: |
| 198 return Clipboard::TYPE_COPY_PASTE; | 198 return Clipboard::TYPE_COPY_PASTE; |
| 199 case BufferSelection: | 199 case BufferSelection: |
| 200 return Clipboard::TYPE_SELECTION; | 200 return Clipboard::TYPE_SELECTION; |
| 201 } | 201 } |
| 202 | 202 |
| 203 NOTREACHED(); | 203 NOTREACHED(); |
| 204 return Clipboard::TYPE_COPY_PASTE; | 204 return Clipboard::TYPE_COPY_PASTE; |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace html_viewer | 207 } // namespace html_viewer |
| OLD | NEW |