Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: ui/base/clipboard/scoped_clipboard_writer.cc

Issue 740003003: Revert of Rewrite clipboard write IPC handling to be easier to understand. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/clipboard/scoped_clipboard_writer.h ('k') | ui/base/test/test_clipboard.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file implements the ScopedClipboardWriter class. Documentation on its 5 // This file implements the ScopedClipboardWriter class. Documentation on its
6 // purpose can be found in our header. Documentation on the format of the 6 // purpose can be found in our header. Documentation on the format of the
7 // parameters for each clipboard target can be found in clipboard.h. 7 // parameters for each clipboard target can be found in clipboard.h.
8 8
9 #include "ui/base/clipboard/scoped_clipboard_writer.h" 9 #include "ui/base/clipboard/scoped_clipboard_writer.h"
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 html.append("\">"); 79 html.append("\">");
80 html.append(net::EscapeForHTML(base::UTF16ToUTF8(anchor_text))); 80 html.append(net::EscapeForHTML(base::UTF16ToUTF8(anchor_text)));
81 html.append("</a>"); 81 html.append("</a>");
82 WriteHTML(base::UTF8ToUTF16(html), std::string()); 82 WriteHTML(base::UTF8ToUTF16(html), std::string());
83 } 83 }
84 84
85 void ScopedClipboardWriter::WriteWebSmartPaste() { 85 void ScopedClipboardWriter::WriteWebSmartPaste() {
86 objects_[Clipboard::CBF_WEBKIT] = Clipboard::ObjectMapParams(); 86 objects_[Clipboard::CBF_WEBKIT] = Clipboard::ObjectMapParams();
87 } 87 }
88 88
89 void ScopedClipboardWriter::WriteImage(const SkBitmap& bitmap) {
90 if (bitmap.drawsNothing()) {
91 NOTREACHED();
92 return;
93 }
94 bitmap_ = bitmap;
95 // TODO(dcheng): This is slightly less horrible than what we used to do, but
96 // only very slightly less.
97 SkBitmap* bitmap_pointer = &bitmap_;
98 Clipboard::ObjectMapParam packed_pointer;
99 packed_pointer.resize(sizeof(bitmap_pointer));
100 *reinterpret_cast<SkBitmap**>(&*packed_pointer.begin()) = bitmap_pointer;
101 Clipboard::ObjectMapParams parameters;
102 parameters.push_back(packed_pointer);
103 objects_[Clipboard::CBF_SMBITMAP] = parameters;
104 }
105
106 void ScopedClipboardWriter::WritePickledData( 89 void ScopedClipboardWriter::WritePickledData(
107 const Pickle& pickle, const Clipboard::FormatType& format) { 90 const Pickle& pickle, const Clipboard::FormatType& format) {
108 std::string format_string = format.Serialize(); 91 std::string format_string = format.Serialize();
109 Clipboard::ObjectMapParam format_parameter(format_string.begin(), 92 Clipboard::ObjectMapParam format_parameter(format_string.begin(),
110 format_string.end()); 93 format_string.end());
111 Clipboard::ObjectMapParam data_parameter; 94 Clipboard::ObjectMapParam data_parameter;
112 95
113 data_parameter.resize(pickle.size()); 96 data_parameter.resize(pickle.size());
114 memcpy(const_cast<char*>(&data_parameter.front()), 97 memcpy(const_cast<char*>(&data_parameter.front()),
115 pickle.data(), pickle.size()); 98 pickle.data(), pickle.size());
116 99
117 Clipboard::ObjectMapParams parameters; 100 Clipboard::ObjectMapParams parameters;
118 parameters.push_back(format_parameter); 101 parameters.push_back(format_parameter);
119 parameters.push_back(data_parameter); 102 parameters.push_back(data_parameter);
120 objects_[Clipboard::CBF_DATA] = parameters; 103 objects_[Clipboard::CBF_DATA] = parameters;
121 } 104 }
122 105
123 void ScopedClipboardWriter::Reset() { 106 void ScopedClipboardWriter::Reset() {
124 url_text_.clear(); 107 url_text_.clear();
125 objects_.clear(); 108 objects_.clear();
126 bitmap_.reset();
127 } 109 }
128 110
129 void ScopedClipboardWriter::WriteTextOrURL(const base::string16& text, 111 void ScopedClipboardWriter::WriteTextOrURL(const base::string16& text,
130 bool is_url) { 112 bool is_url) {
131 std::string utf8_text = base::UTF16ToUTF8(text); 113 std::string utf8_text = base::UTF16ToUTF8(text);
132 114
133 Clipboard::ObjectMapParams parameters; 115 Clipboard::ObjectMapParams parameters;
134 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(), 116 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(),
135 utf8_text.end())); 117 utf8_text.end()));
136 objects_[Clipboard::CBF_TEXT] = parameters; 118 objects_[Clipboard::CBF_TEXT] = parameters;
137 119
138 if (is_url) { 120 if (is_url) {
139 url_text_ = utf8_text; 121 url_text_ = utf8_text;
140 } else { 122 } else {
141 url_text_.clear(); 123 url_text_.clear();
142 } 124 }
143 } 125 }
144 126
145 } // namespace ui 127 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/scoped_clipboard_writer.h ('k') | ui/base/test/test_clipboard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698