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

Side by Side Diff: chrome/browser/bookmarks/bookmark_node_data.cc

Issue 10916214: Try 2 - Change how ui::Clipboard is accessed so there's only one per thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved to BrowserThreadsStarted Created 8 years, 3 months 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 | Annotate | Revision Log
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 #include "chrome/browser/bookmarks/bookmark_node_data.h" 5 #include "chrome/browser/bookmarks/bookmark_node_data.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "net/base/escape.h" 17 #include "net/base/escape.h"
18 #include "ui/base/clipboard/scoped_clipboard_writer.h" 18 #include "ui/base/clipboard/scoped_clipboard_writer.h"
19 19
20 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
21 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" 21 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h"
22 #else
23 #include "chrome/browser/browser_process.h"
24 #endif 22 #endif
25 23
26 const char* BookmarkNodeData::kClipboardFormatString = 24 const char* BookmarkNodeData::kClipboardFormatString =
27 "chromium/x-bookmark-entries"; 25 "chromium/x-bookmark-entries";
28 26
29 BookmarkNodeData::Element::Element() : is_url(false), id_(0) { 27 BookmarkNodeData::Element::Element() : is_url(false), id_(0) {
30 } 28 }
31 29
32 BookmarkNodeData::Element::Element(const BookmarkNode* node) 30 BookmarkNodeData::Element::Element(const BookmarkNode* node)
33 : is_url(node->is_url()), 31 : is_url(node->is_url()),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 element.url = url; 132 element.url = url;
135 element.is_url = true; 133 element.is_url = true;
136 134
137 elements.push_back(element); 135 elements.push_back(element);
138 136
139 return true; 137 return true;
140 } 138 }
141 139
142 #if !defined(OS_MACOSX) 140 #if !defined(OS_MACOSX)
143 void BookmarkNodeData::WriteToClipboard(Profile* profile) const { 141 void BookmarkNodeData::WriteToClipboard(Profile* profile) const {
144 ui::ScopedClipboardWriter scw(g_browser_process->clipboard(), 142 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(),
145 ui::Clipboard::BUFFER_STANDARD); 143 ui::Clipboard::BUFFER_STANDARD);
146 144
147 // If there is only one element and it is a URL, write the URL to the 145 // If there is only one element and it is a URL, write the URL to the
148 // clipboard. 146 // clipboard.
149 if (elements.size() == 1 && elements[0].is_url) { 147 if (elements.size() == 1 && elements[0].is_url) {
150 const string16& title = elements[0].title; 148 const string16& title = elements[0].title;
151 const std::string url = elements[0].url.spec(); 149 const std::string url = elements[0].url.spec();
152 150
153 scw.WriteBookmark(title, url); 151 scw.WriteBookmark(title, url);
154 scw.WriteHyperlink(net::EscapeForHTML(title), url); 152 scw.WriteHyperlink(net::EscapeForHTML(title), url);
155 153
156 // Also write the URL to the clipboard as text so that it can be pasted 154 // Also write the URL to the clipboard as text so that it can be pasted
157 // into text fields. We use WriteText instead of WriteURL because we don't 155 // into text fields. We use WriteText instead of WriteURL because we don't
158 // want to clobber the X clipboard when the user copies out of the omnibox 156 // want to clobber the X clipboard when the user copies out of the omnibox
159 // on Linux (on Windows and Mac, there is no difference between these 157 // on Linux (on Windows and Mac, there is no difference between these
160 // functions). 158 // functions).
161 scw.WriteText(UTF8ToUTF16(url)); 159 scw.WriteText(UTF8ToUTF16(url));
162 } 160 }
163 161
164 Pickle pickle; 162 Pickle pickle;
165 WriteToPickle(profile, &pickle); 163 WriteToPickle(profile, &pickle);
166 scw.WritePickledData( 164 scw.WritePickledData(
167 pickle, ui::Clipboard::GetFormatType(kClipboardFormatString)); 165 pickle, ui::Clipboard::GetFormatType(kClipboardFormatString));
168 } 166 }
169 167
170 bool BookmarkNodeData::ReadFromClipboard() { 168 bool BookmarkNodeData::ReadFromClipboard() {
171 std::string data; 169 std::string data;
172 ui::Clipboard* clipboard = g_browser_process->clipboard(); 170 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
173 clipboard->ReadData(ui::Clipboard::GetFormatType(kClipboardFormatString), 171 clipboard->ReadData(ui::Clipboard::GetFormatType(kClipboardFormatString),
174 &data); 172 &data);
175 173
176 if (!data.empty()) { 174 if (!data.empty()) {
177 Pickle pickle(data.data(), data.size()); 175 Pickle pickle(data.data(), data.size());
178 if (ReadFromPickle(&pickle)) 176 if (ReadFromPickle(&pickle))
179 return true; 177 return true;
180 } 178 }
181 179
182 string16 title; 180 string16 title;
183 std::string url; 181 std::string url;
184 clipboard->ReadBookmark(&title, &url); 182 clipboard->ReadBookmark(&title, &url);
185 if (!url.empty()) { 183 if (!url.empty()) {
186 Element element; 184 Element element;
187 element.is_url = true; 185 element.is_url = true;
188 element.url = GURL(url); 186 element.url = GURL(url);
189 element.title = title; 187 element.title = title;
190 188
191 elements.clear(); 189 elements.clear();
192 elements.push_back(element); 190 elements.push_back(element);
193 return true; 191 return true;
194 } 192 }
195 193
196 return false; 194 return false;
197 } 195 }
198 196
199 bool BookmarkNodeData::ClipboardContainsBookmarks() { 197 bool BookmarkNodeData::ClipboardContainsBookmarks() {
200 return g_browser_process->clipboard()->IsFormatAvailable( 198 return ui::Clipboard::GetForCurrentThread()->IsFormatAvailable(
201 ui::Clipboard::GetFormatType(kClipboardFormatString), 199 ui::Clipboard::GetFormatType(kClipboardFormatString),
202 ui::Clipboard::BUFFER_STANDARD); 200 ui::Clipboard::BUFFER_STANDARD);
203 } 201 }
204 #else 202 #else
205 void BookmarkNodeData::WriteToClipboard(Profile* profile) const { 203 void BookmarkNodeData::WriteToClipboard(Profile* profile) const {
206 bookmark_pasteboard_helper_mac::WriteToPasteboard( 204 bookmark_pasteboard_helper_mac::WriteToPasteboard(
207 bookmark_pasteboard_helper_mac::kCopyPastePasteboard, 205 bookmark_pasteboard_helper_mac::kCopyPastePasteboard,
208 elements, 206 elements,
209 profile_path_.value()); 207 profile_path_.value());
210 } 208 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 DCHECK(profile_path_.empty()); 343 DCHECK(profile_path_.empty());
346 344
347 if (profile) 345 if (profile)
348 profile_path_ = profile->GetPath(); 346 profile_path_ = profile->GetPath();
349 } 347 }
350 348
351 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { 349 bool BookmarkNodeData::IsFromProfile(Profile* profile) const {
352 // An empty path means the data is not associated with any profile. 350 // An empty path means the data is not associated with any profile.
353 return !profile_path_.empty() && profile_path_ == profile->GetPath(); 351 return !profile_path_.empty() && profile_path_ == profile->GetPath();
354 } 352 }
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller_unittest.cc ('k') | chrome/browser/bookmarks/bookmark_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698