summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc2
-rw-r--r--chrome/browser/bookmarks/bookmark_node_data.cc8
-rw-r--r--chrome/browser/bookmarks/bookmark_utils_unittest.cc9
-rw-r--r--chrome/browser/browser_process.h5
-rw-r--r--chrome/browser/browser_process_impl.cc7
-rw-r--r--chrome/browser/browser_process_impl.h3
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc3
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view.cc3
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view_unittest.cc18
-rw-r--r--chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc1
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc1
-rw-r--r--chrome/browser/ui/views/chrome_views_delegate.cc5
-rw-r--r--chrome/browser/ui/views/chrome_views_delegate.h1
-rw-r--r--chrome/browser/ui/views/find_bar_host_interactive_uitest.cc2
-rw-r--r--chrome/browser/ui/views/menu_model_adapter_test.cc4
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc2
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_win.cc3
-rw-r--r--chrome/test/base/testing_browser_process.cc9
-rw-r--r--chrome/test/base/testing_browser_process.h6
-rw-r--r--chrome_frame/test/chrome_frame_test_utils.cc14
-rw-r--r--content/browser/browser_main_loop.cc2
-rw-r--r--content/browser/renderer_host/clipboard_message_filter.cc7
-rw-r--r--content/shell/shell_aura.cc8
-rw-r--r--ui/base/clipboard/clipboard.cc38
-rw-r--r--ui/base/clipboard/clipboard.h19
-rw-r--r--ui/base/clipboard/clipboard_unittest.cc263
-rw-r--r--ui/views/controls/message_box_view.cc6
-rw-r--r--ui/views/controls/textfield/native_textfield_views.cc5
-rw-r--r--ui/views/controls/textfield/native_textfield_views_unittest.cc7
-rw-r--r--ui/views/controls/textfield/native_textfield_win.cc9
-rw-r--r--ui/views/controls/textfield/textfield_views_model.cc7
-rw-r--r--ui/views/controls/textfield/textfield_views_model_unittest.cc3
-rw-r--r--ui/views/test/test_views_delegate.cc9
-rw-r--r--ui/views/test/test_views_delegate.h2
-rw-r--r--ui/views/view_unittest.cc16
-rw-r--r--ui/views/views_delegate.h7
-rw-r--r--webkit/tools/test_shell/simple_clipboard_impl.cc4
37 files changed, 221 insertions, 297 deletions
diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc
index 044b496..b7c94e8 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -503,7 +503,7 @@ TEST_F(DragDropControllerTest, ViewRemovedWhileInDragDropTest) {
}
TEST_F(DragDropControllerTest, DragLeavesClipboardAloneTest) {
- ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard();
+ ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread();
std::string clip_str("I am on the clipboard");
{
// We first copy some text to the clipboard.
diff --git a/chrome/browser/bookmarks/bookmark_node_data.cc b/chrome/browser/bookmarks/bookmark_node_data.cc
index c6a2615..bcd45d6 100644
--- a/chrome/browser/bookmarks/bookmark_node_data.cc
+++ b/chrome/browser/bookmarks/bookmark_node_data.cc
@@ -19,8 +19,6 @@
#if defined(OS_MACOSX)
#include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h"
-#else
-#include "chrome/browser/browser_process.h"
#endif
const char* BookmarkNodeData::kClipboardFormatString =
@@ -141,7 +139,7 @@ bool BookmarkNodeData::ReadFromTuple(const GURL& url, const string16& title) {
#if !defined(OS_MACOSX)
void BookmarkNodeData::WriteToClipboard(Profile* profile) const {
- ui::ScopedClipboardWriter scw(g_browser_process->clipboard(),
+ ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD);
// If there is only one element and it is a URL, write the URL to the
@@ -169,7 +167,7 @@ void BookmarkNodeData::WriteToClipboard(Profile* profile) const {
bool BookmarkNodeData::ReadFromClipboard() {
std::string data;
- ui::Clipboard* clipboard = g_browser_process->clipboard();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->ReadData(ui::Clipboard::GetFormatType(kClipboardFormatString),
&data);
@@ -197,7 +195,7 @@ bool BookmarkNodeData::ReadFromClipboard() {
}
bool BookmarkNodeData::ClipboardContainsBookmarks() {
- return g_browser_process->clipboard()->IsFormatAvailable(
+ return ui::Clipboard::GetForCurrentThread()->IsFormatAvailable(
ui::Clipboard::GetFormatType(kClipboardFormatString),
ui::Clipboard::BUFFER_STANDARD);
}
diff --git a/chrome/browser/bookmarks/bookmark_utils_unittest.cc b/chrome/browser/bookmarks/bookmark_utils_unittest.cc
index 565f60f..9b4100b 100644
--- a/chrome/browser/bookmarks/bookmark_utils_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_utils_unittest.cc
@@ -10,10 +10,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
-#if !defined(OS_MACOSX)
-#include "chrome/browser/browser_process.h"
-#endif
-
using std::string;
namespace bookmark_utils {
@@ -142,8 +138,9 @@ TEST(BookmarkUtilsTest, CopyPaste) {
// Write some text to the clipboard.
{
- ui::ScopedClipboardWriter clipboard_writer(g_browser_process->clipboard(),
- ui::Clipboard::BUFFER_STANDARD);
+ ui::ScopedClipboardWriter clipboard_writer(
+ ui::Clipboard::GetForCurrentThread(),
+ ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(ASCIIToUTF16("foo"));
}
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index b31ae0a..bc5a56b 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -71,10 +71,6 @@ namespace safe_browsing {
class ClientSideDetectionService;
}
-namespace ui {
-class Clipboard;
-}
-
// NOT THREAD SAFE, call only from the main thread.
// These functions shouldn't return NULL unless otherwise noted.
class BrowserProcess {
@@ -95,7 +91,6 @@ class BrowserProcess {
virtual MetricsService* metrics_service() = 0;
virtual ProfileManager* profile_manager() = 0;
virtual PrefService* local_state() = 0;
- virtual ui::Clipboard* clipboard() = 0;
virtual net::URLRequestContextGetter* system_request_context() = 0;
virtual chrome_variations::VariationsService* variations_service() = 0;
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 798c400..0b0524e 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -78,7 +78,6 @@
#include "content/public/common/pepper_plugin_info.h"
#include "net/socket/client_socket_pool_manager.h"
#include "net/url_request/url_request_context_getter.h"
-#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(ENABLE_CONFIGURATION_POLICY)
@@ -142,7 +141,6 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
thumbnail_generator_(new ThumbnailGenerator),
download_status_updater_(new DownloadStatusUpdater) {
g_browser_process = this;
- clipboard_.reset(new ui::Clipboard);
#if defined(ENABLE_PRINTING)
// Must be created after the NotificationService.
@@ -388,11 +386,6 @@ PrefService* BrowserProcessImpl::local_state() {
return local_state_.get();
}
-ui::Clipboard* BrowserProcessImpl::clipboard() {
- DCHECK(CalledOnValidThread());
- return clipboard_.get();
-}
-
net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
DCHECK(CalledOnValidThread());
return io_thread()->system_url_request_context_getter();
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 607cc4f..404db25 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -64,7 +64,6 @@ class BrowserProcessImpl : public BrowserProcess,
virtual WatchDogThread* watchdog_thread() OVERRIDE;
virtual ProfileManager* profile_manager() OVERRIDE;
virtual PrefService* local_state() OVERRIDE;
- virtual ui::Clipboard* clipboard() OVERRIDE;
virtual net::URLRequestContextGetter* system_request_context() OVERRIDE;
virtual chrome_variations::VariationsService* variations_service() OVERRIDE;
#if defined(OS_CHROMEOS)
@@ -178,8 +177,6 @@ class BrowserProcessImpl : public BrowserProcess,
scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
- scoped_ptr<ui::Clipboard> clipboard_;
-
scoped_ptr<chrome_variations::VariationsService> variations_service_;
// Manager for desktop notification UI.
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index daa5fb4..fc46a87 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -81,6 +81,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
+#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/favicon_size.h"
@@ -2014,7 +2015,7 @@ void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
chrome_common_net::WriteURLToClipboard(
url,
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
- g_browser_process->clipboard());
+ ui::Clipboard::GetForCurrentThread());
}
void RenderViewContextMenu::MediaPlayerActionAt(
diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc
index d87fc18..e8bd344 100644
--- a/chrome/browser/ui/omnibox/omnibox_view.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view.cc
@@ -11,7 +11,6 @@
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
-#include "chrome/browser/browser_process.h"
#include "ui/base/clipboard/clipboard.h"
// static
@@ -27,7 +26,7 @@ string16 OmniboxView::StripJavascriptSchemas(const string16& text) {
// static
string16 OmniboxView::GetClipboardText() {
// Try text format.
- ui::Clipboard* clipboard = g_browser_process->clipboard();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
ui::Clipboard::BUFFER_STANDARD)) {
string16 text;
diff --git a/chrome/browser/ui/omnibox/omnibox_view_unittest.cc b/chrome/browser/ui/omnibox/omnibox_view_unittest.cc
index 4346fca..ae932b5 100644
--- a/chrome/browser/ui/omnibox/omnibox_view_unittest.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view_unittest.cc
@@ -40,14 +40,14 @@ TEST_F(OmniboxViewTest, TestStripSchemasUnsafeForPaste) {
}
TEST_F(OmniboxViewTest, GetClipboardText) {
- ui::Clipboard clipboard;
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
const string16 kPlainText(ASCIIToUTF16("test text"));
const std::string kURL("http://www.example.com/");
// Can we pull straight text off the clipboard?
{
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
+ ui::ScopedClipboardWriter clipboard_writer(clipboard,
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(kPlainText);
}
@@ -57,8 +57,8 @@ TEST_F(OmniboxViewTest, GetClipboardText) {
// ObjectMap is empty. http://crbug.com/133848
#if !defined(USE_AURA)
// Does an empty clipboard get empty text?
- clipboard.WriteObjects(ui::Clipboard::BUFFER_STANDARD,
- ui::Clipboard::ObjectMap());
+ clipboard->WriteObjects(ui::Clipboard::BUFFER_STANDARD,
+ ui::Clipboard::ObjectMap());
EXPECT_EQ(string16(), OmniboxView::GetClipboardText());
#endif
@@ -68,7 +68,7 @@ TEST_F(OmniboxViewTest, GetClipboardText) {
const string16 kTitle(ASCIIToUTF16("The Example Company"));
// Can we pull a bookmark off the clipboard?
{
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
+ ui::ScopedClipboardWriter clipboard_writer(clipboard,
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteBookmark(kTitle, kURL);
}
@@ -76,7 +76,7 @@ TEST_F(OmniboxViewTest, GetClipboardText) {
// Do we pull text in preference to a bookmark?
{
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
+ ui::ScopedClipboardWriter clipboard_writer(clipboard,
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(kPlainText);
clipboard_writer.WriteBookmark(kTitle, kURL);
@@ -87,7 +87,7 @@ TEST_F(OmniboxViewTest, GetClipboardText) {
// Do we get nothing if there is neither text nor a bookmark?
{
const string16 kMarkup(ASCIIToUTF16("<strong>Hi!</string>"));
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
+ ui::ScopedClipboardWriter clipboard_writer(clipboard,
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteHTML(kMarkup, kURL);
}
@@ -98,7 +98,7 @@ TEST_F(OmniboxViewTest, GetClipboardText) {
const string16 kWrappedURL(ASCIIToUTF16(
"http://www.chromium.org/developers/testing/chromium-\n"
"build-infrastructure/tour-of-the-chromium-buildbot"));
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
+ ui::ScopedClipboardWriter clipboard_writer(clipboard,
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(kWrappedURL);
}
@@ -112,7 +112,7 @@ TEST_F(OmniboxViewTest, GetClipboardText) {
{
const string16 kWrappedAddress(ASCIIToUTF16(
"1600 Amphitheatre Parkway\nMountain View, CA"));
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
+ ui::ScopedClipboardWriter clipboard_writer(clipboard,
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(kWrappedAddress);
}
diff --git a/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
index b15609a..b093b95 100644
--- a/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
+++ b/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
@@ -36,7 +36,6 @@ class AccessibilityViewsDelegate : public views::ViewsDelegate {
virtual ~AccessibilityViewsDelegate() {}
// Overridden from views::ViewsDelegate:
- virtual ui::Clipboard* GetClipboard() const OVERRIDE { return NULL; }
virtual void SaveWindowPlacement(const views::Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
index 981cf92..5e6967c 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
@@ -58,7 +58,6 @@ void MoveMouseAndPress(const gfx::Point& screen_pos,
class ViewsDelegateImpl : public views::ViewsDelegate {
public:
ViewsDelegateImpl() {}
- virtual ui::Clipboard* GetClipboard() const OVERRIDE { return NULL; }
virtual void SaveWindowPlacement(const views::Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc
index 73b734b..e4cadc3 100644
--- a/chrome/browser/ui/views/chrome_views_delegate.cc
+++ b/chrome/browser/ui/views/chrome_views_delegate.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/views/accessibility/accessibility_event_router_views.h"
#include "chrome/common/pref_names.h"
-#include "ui/base/clipboard/clipboard.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/native_widget.h"
@@ -56,10 +55,6 @@ PrefService* GetPrefsForWindow(const views::Widget* window) {
///////////////////////////////////////////////////////////////////////////////
// ChromeViewsDelegate, views::ViewsDelegate implementation:
-ui::Clipboard* ChromeViewsDelegate::GetClipboard() const {
- return g_browser_process->clipboard();
-}
-
void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/chrome/browser/ui/views/chrome_views_delegate.h b/chrome/browser/ui/views/chrome_views_delegate.h
index c568d2e..d1da9a8 100644
--- a/chrome/browser/ui/views/chrome_views_delegate.h
+++ b/chrome/browser/ui/views/chrome_views_delegate.h
@@ -17,7 +17,6 @@ class ChromeViewsDelegate : public views::ViewsDelegate {
virtual ~ChromeViewsDelegate() {}
// Overridden from views::ViewsDelegate:
- virtual ui::Clipboard* GetClipboard() const OVERRIDE;
virtual void SaveWindowPlacement(const views::Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc
index ded923b..a5a4eaa 100644
--- a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc
+++ b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc
@@ -352,7 +352,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_PasteWithoutTextChange) {
browser(), ui::VKEY_C, true, false, false, false));
string16 str;
- views::ViewsDelegate::views_delegate->GetClipboard()->
+ ui::Clipboard::GetForCurrentThread()->
ReadText(ui::Clipboard::BUFFER_STANDARD, &str);
// Make sure the text is copied successfully.
diff --git a/chrome/browser/ui/views/menu_model_adapter_test.cc b/chrome/browser/ui/views/menu_model_adapter_test.cc
index 94c00be..c1ff355 100644
--- a/chrome/browser/ui/views/menu_model_adapter_test.cc
+++ b/chrome/browser/ui/views/menu_model_adapter_test.cc
@@ -35,10 +35,6 @@ class TestViewsDelegate : public views::ViewsDelegate {
}
// views::ViewsDelegate implementation
- virtual ui::Clipboard* GetClipboard() const OVERRIDE {
- return NULL;
- }
-
virtual void SaveWindowPlacement(const views::Widget* widget,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index de46181..ff24a09 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -760,7 +760,7 @@ void OmniboxViewViews::OnAfterUserAction(views::Textfield* sender) {
void OmniboxViewViews::OnAfterCutOrCopy() {
ui::Range selection_range;
textfield_->GetSelectedRange(&selection_range);
- ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard();
+ ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread();
string16 selected_text;
cb->ReadText(ui::Clipboard::BUFFER_STANDARD, &selected_text);
const string16 text = textfield_->text();
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
index d620d9e..68ed871 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
@@ -27,7 +27,6 @@
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/profiles/profile.h"
@@ -1333,7 +1332,7 @@ void OmniboxViewWin::OnCopy() {
// GetSel() doesn't preserve selection direction, so sel.cpMin will always be
// the smaller value.
model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url);
- ui::ScopedClipboardWriter scw(g_browser_process->clipboard(),
+ ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD);
scw.WriteText(text);
if (write_url)
diff --git a/chrome/test/base/testing_browser_process.cc b/chrome/test/base/testing_browser_process.cc
index d8d7a80..e1fc242 100644
--- a/chrome/test/base/testing_browser_process.cc
+++ b/chrome/test/base/testing_browser_process.cc
@@ -17,7 +17,6 @@
#include "content/public/browser/notification_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/clipboard/clipboard.h"
#if !defined(ENABLE_CONFIGURATION_POLICY)
#include "chrome/browser/policy/policy_service_stub.h"
@@ -125,14 +124,6 @@ chromeos::OomPriorityManager* TestingBrowserProcess::oom_priority_manager() {
}
#endif // defined(OS_CHROMEOS)
-ui::Clipboard* TestingBrowserProcess::clipboard() {
- if (!clipboard_.get()) {
- // Note that we need a MessageLoop for the next call to work.
- clipboard_.reset(new ui::Clipboard);
- }
- return clipboard_.get();
-}
-
extensions::EventRouterForwarder*
TestingBrowserProcess::extension_event_router_forwarder() {
return NULL;
diff --git a/chrome/test/base/testing_browser_process.h b/chrome/test/base/testing_browser_process.h
index e5c573b..8fc1990 100644
--- a/chrome/test/base/testing_browser_process.h
+++ b/chrome/test/base/testing_browser_process.h
@@ -38,10 +38,6 @@ namespace prerender {
class PrerenderTracker;
}
-namespace ui {
-class Clipboard;
-}
-
class TestingBrowserProcess : public BrowserProcess {
public:
TestingBrowserProcess();
@@ -70,7 +66,6 @@ class TestingBrowserProcess : public BrowserProcess {
virtual chromeos::OomPriorityManager* oom_priority_manager() OVERRIDE;
#endif // defined(OS_CHROMEOS)
- virtual ui::Clipboard* clipboard() OVERRIDE;
virtual extensions::EventRouterForwarder*
extension_event_router_forwarder() OVERRIDE;
virtual NotificationUIManager* notification_ui_manager() OVERRIDE;
@@ -115,7 +110,6 @@ class TestingBrowserProcess : public BrowserProcess {
private:
scoped_ptr<content::NotificationService> notification_service_;
unsigned int module_ref_count_;
- scoped_ptr<ui::Clipboard> clipboard_;
std::string app_locale_;
// Weak pointer.
diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc
index ec79019..d8d1e13 100644
--- a/chrome_frame/test/chrome_frame_test_utils.cc
+++ b/chrome_frame/test/chrome_frame_test_utils.cc
@@ -491,19 +491,17 @@ std::wstring GetPathAndQueryFromUrl(const std::wstring& url) {
}
std::wstring GetClipboardText() {
- ui::Clipboard clipboard;
string16 text16;
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &text16);
+ ui::Clipboard::GetForCurrentThread()->ReadText(
+ ui::Clipboard::BUFFER_STANDARD, &text16);
return UTF16ToWide(text16);
}
void SetClipboardText(const std::wstring& text) {
- ui::Clipboard clipboard;
- {
- ui::ScopedClipboardWriter clipboard_writer(&clipboard,
- ui::Clipboard::BUFFER_STANDARD);
- clipboard_writer.WriteText(WideToUTF16(text));
- }
+ ui::ScopedClipboardWriter clipboard_writer(
+ ui::Clipboard::GetForCurrentThread(),
+ ui::Clipboard::BUFFER_STANDARD);
+ clipboard_writer.WriteText(WideToUTF16(text));
}
bool AddCFMetaTag(std::string* html_data) {
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index faed5fc..c9a409a 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -46,6 +46,7 @@
#include "net/base/ssl_config_service.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/tcp_client_socket.h"
+#include "ui/base/clipboard/clipboard.h"
#if defined(USE_AURA)
#include "content/browser/renderer_host/image_transport_factory.h"
@@ -236,6 +237,7 @@ BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters)
BrowserMainLoop::~BrowserMainLoop() {
DCHECK_EQ(this, g_current_browser_main_loop);
+ ui::Clipboard::DestroyClipboardForCurrentThread();
g_current_browser_main_loop = NULL;
}
diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc
index 1de011e..542ec1f 100644
--- a/content/browser/renderer_host/clipboard_message_filter.cc
+++ b/content/browser/renderer_host/clipboard_message_filter.cc
@@ -31,8 +31,8 @@ namespace {
// clipboard's contents. // See http://crbug.com/5823.
void WriteObjectsHelper(const ui::Clipboard::ObjectMap* objects) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- static ui::Clipboard* clipboard = new ui::Clipboard;
- clipboard->WriteObjects(ui::Clipboard::BUFFER_STANDARD, *objects);
+ ui::Clipboard::GetForCurrentThread()->WriteObjects(
+ ui::Clipboard::BUFFER_STANDARD, *objects);
}
} // namespace
@@ -244,7 +244,6 @@ void ClipboardMessageFilter::OnReadCustomData(
ui::Clipboard* ClipboardMessageFilter::GetClipboard() {
// We have a static instance of the clipboard service for use by all message
// filters. This instance lives for the life of the browser processes.
- static ui::Clipboard* clipboard = new ui::Clipboard;
-
+ static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
return clipboard;
}
diff --git a/content/shell/shell_aura.cc b/content/shell/shell_aura.cc
index b956aec..ee4efad 100644
--- a/content/shell/shell_aura.cc
+++ b/content/shell/shell_aura.cc
@@ -52,13 +52,6 @@ class ShellViewsDelegateAura : public ViewsDelegate {
}
// Overridden from ViewsDelegate:
- virtual ui::Clipboard* GetClipboard() const OVERRIDE {
- if (!clipboard_.get()) {
- clipboard_.reset(new ui::Clipboard);
- }
- return clipboard_.get();
- }
-
virtual void SaveWindowPlacement(const Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
@@ -111,7 +104,6 @@ class ShellViewsDelegateAura : public ViewsDelegate {
}
private:
- mutable scoped_ptr<ui::Clipboard> clipboard_;
bool use_transparent_windows_;
DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegateAura);
diff --git a/ui/base/clipboard/clipboard.cc b/ui/base/clipboard/clipboard.cc
index d20d854..b793f6e 100644
--- a/ui/base/clipboard/clipboard.cc
+++ b/ui/base/clipboard/clipboard.cc
@@ -4,8 +4,10 @@
#include "ui/base/clipboard/clipboard.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
#include "ui/gfx/size.h"
namespace ui {
@@ -72,6 +74,15 @@ bool ValidateAndMapSharedBitmap(const Clipboard::ObjectMapParams& params,
return true;
}
+// Mapping from threads to clipboard objects.
+typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap;
+static base::LazyInstance<ClipboardMap> g_clipboard_map =
+ LAZY_INSTANCE_INITIALIZER;
+
+// Mutex that controls access to |g_clipboard_map|.
+static base::LazyInstance<base::Lock>::Leaky
+ g_clipboard_map_lock = LAZY_INSTANCE_INITIALIZER;
+
} // namespace
const char Clipboard::kMimeTypeText[] = "text/plain";
@@ -81,6 +92,33 @@ const char Clipboard::kMimeTypeHTML[] = "text/html";
const char Clipboard::kMimeTypeRTF[] = "text/rtf";
const char Clipboard::kMimeTypePNG[] = "image/png";
+// static
+Clipboard* Clipboard::GetForCurrentThread() {
+ base::AutoLock lock(g_clipboard_map_lock.Get());
+
+ base::PlatformThreadId id = base::PlatformThread::CurrentId();
+ ClipboardMap* clipboard_map = g_clipboard_map.Pointer();
+ ClipboardMap::iterator it = clipboard_map->find(id);
+ if (it != clipboard_map->end())
+ return it->second;
+
+ Clipboard* clipboard = new ui::Clipboard;
+ clipboard_map->insert(std::make_pair(id, clipboard));
+ return clipboard;
+}
+
+void Clipboard::DestroyClipboardForCurrentThread() {
+ base::AutoLock lock(g_clipboard_map_lock.Get());
+
+ ClipboardMap* clipboard_map = g_clipboard_map.Pointer();
+ base::PlatformThreadId id = base::PlatformThread::CurrentId();
+ ClipboardMap::iterator it = clipboard_map->find(id);
+ if (it != clipboard_map->end()) {
+ delete it->second;
+ clipboard_map->erase(it);
+ }
+}
+
void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) {
// All types apart from CBF_WEBKIT need at least 1 non-empty param.
if (type != CBF_WEBKIT && (params.empty() || params[0].empty()))
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h
index b98cfc4..82cdb91 100644
--- a/ui/base/clipboard/clipboard.h
+++ b/ui/base/clipboard/clipboard.h
@@ -46,6 +46,7 @@ class NSString;
#endif
namespace ui {
+class ClipboardTest;
class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
public:
@@ -182,8 +183,18 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
return static_cast<Buffer>(buffer);
}
- Clipboard();
- ~Clipboard();
+ // Returns the clipboard object for the current thread.
+ //
+ // Most implementations will have at most one clipboard which will live on
+ // the main UI thread, but Windows has tricky semantics where there have to
+ // be two clipboards: one that lives on the UI thread and one that lives on
+ // the IO thread.
+ static Clipboard* GetForCurrentThread();
+
+ // Destroys the clipboard for the current thread. Usually, this will clean up
+ // all clipboards, except on Windows. (Previous code leaks the IO thread
+ // clipboard, so it shouldn't be a problem.)
+ static void DestroyClipboardForCurrentThread();
// Write a bunch of objects to the system clipboard. Copies are made of the
// contents of |objects|. On Windows they are copied to the system clipboard.
@@ -284,6 +295,10 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
private:
FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest);
FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest);
+ friend class ClipboardTest;
+
+ Clipboard();
+ ~Clipboard();
void DispatchObject(ObjectType type, const ObjectMapParams& params);
diff --git a/ui/base/clipboard/clipboard_unittest.cc b/ui/base/clipboard/clipboard_unittest.cc
index 1b7eb4c..1653313 100644
--- a/ui/base/clipboard/clipboard_unittest.cc
+++ b/ui/base/clipboard/clipboard_unittest.cc
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
#include "base/pickle.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -19,7 +20,6 @@
#include "ui/gfx/size.h"
#if defined(OS_WIN)
-#include "base/message_loop.h"
#include "ui/base/clipboard/clipboard_util_win.h"
#endif
@@ -29,21 +29,14 @@
namespace ui {
-#if defined(OS_WIN)
class ClipboardTest : public PlatformTest {
protected:
- virtual void SetUp() {
- message_loop_.reset(new MessageLoopForUI());
- }
- virtual void TearDown() {
- }
+ Clipboard& clipboard() { return clipboard_; }
private:
- scoped_ptr<MessageLoop> message_loop_;
+ MessageLoopForUI message_loop_;
+ Clipboard clipboard_;
};
-#elif defined(OS_POSIX)
-typedef PlatformTest ClipboardTest;
-#endif // defined(OS_WIN)
namespace {
@@ -55,61 +48,55 @@ bool MarkupMatches(const string16& expected_markup,
} // namespace
TEST_F(ClipboardTest, ClearTest) {
- Clipboard clipboard;
-
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(ASCIIToUTF16("clear me"));
}
- clipboard.Clear(Clipboard::BUFFER_STANDARD);
+ clipboard().Clear(Clipboard::BUFFER_STANDARD);
- EXPECT_FALSE(clipboard.IsFormatAvailable(
+ EXPECT_FALSE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
- EXPECT_FALSE(clipboard.IsFormatAvailable(
+ EXPECT_FALSE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD));
}
TEST_F(ClipboardTest, TextTest) {
- Clipboard clipboard;
-
string16 text(ASCIIToUTF16("This is a string16!#$")), text_result;
std::string ascii_text;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(text);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(
+ EXPECT_TRUE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
- Clipboard::BUFFER_STANDARD));
- clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result);
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ clipboard().ReadText(Clipboard::BUFFER_STANDARD, &text_result);
EXPECT_EQ(text, text_result);
- clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
+ clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
}
TEST_F(ClipboardTest, HTMLTest) {
- Clipboard clipboard;
-
string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result;
std::string url("http://www.example.com/"), url_result;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteHTML(markup, url);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
uint32 ignored;
- clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
+ clipboard().ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
&ignored, &ignored);
EXPECT_PRED2(MarkupMatches, markup, markup_result);
#if defined(OS_WIN)
@@ -120,84 +107,79 @@ TEST_F(ClipboardTest, HTMLTest) {
}
TEST_F(ClipboardTest, RTFTest) {
- Clipboard clipboard;
-
std::string rtf =
"{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n"
"This is some {\\b bold} text.\\par\n"
"}";
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteRTF(rtf);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetRtfFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(),
+ Clipboard::BUFFER_STANDARD));
std::string result;
- clipboard.ReadRTF(Clipboard::BUFFER_STANDARD, &result);
+ clipboard().ReadRTF(Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(rtf, result);
}
#if defined(TOOLKIT_GTK)
TEST_F(ClipboardTest, MultipleBufferTest) {
- Clipboard clipboard;
-
string16 text(ASCIIToUTF16("Standard")), text_result;
string16 markup(ASCIIToUTF16("<string>Selection</string>")), markup_result;
std::string url("http://www.example.com/"), url_result;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(text);
}
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_SELECTION);
clipboard_writer.WriteHTML(markup, url);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
- Clipboard::BUFFER_STANDARD));
- EXPECT_FALSE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
- Clipboard::BUFFER_SELECTION));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ EXPECT_FALSE(clipboard().IsFormatAvailable(
+ Clipboard::GetPlainTextFormatType(),
+ Clipboard::BUFFER_SELECTION));
- EXPECT_FALSE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_SELECTION));
+ EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_SELECTION));
- clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result);
+ clipboard().ReadText(Clipboard::BUFFER_STANDARD, &text_result);
EXPECT_EQ(text, text_result);
uint32 ignored;
- clipboard.ReadHTML(Clipboard::BUFFER_SELECTION, &markup_result, &url_result,
- &ignored, &ignored);
+ clipboard().ReadHTML(Clipboard::BUFFER_SELECTION, &markup_result, &url_result,
+ &ignored, &ignored);
EXPECT_PRED2(MarkupMatches, markup, markup_result);
}
#endif
TEST_F(ClipboardTest, TrickyHTMLTest) {
- Clipboard clipboard;
-
string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")),
markup_result;
std::string url, url_result;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteHTML(markup, url);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
uint32 ignored;
- clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
- &ignored, &ignored);
+ clipboard().ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
+ &ignored, &ignored);
EXPECT_PRED2(MarkupMatches, markup, markup_result);
#if defined(OS_WIN)
// TODO(playmobil): It's not clear that non windows clipboards need to support
@@ -208,24 +190,22 @@ TEST_F(ClipboardTest, TrickyHTMLTest) {
#if defined(OS_WIN)
TEST_F(ClipboardTest, UniodeHTMLTest) {
- Clipboard clipboard;
-
string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")),
markup_result;
std::string url, url_result;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteHTML(markup, url);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
uint32 fragment_start;
uint32 fragment_end;
- clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
- &fragment_start, &fragment_end);
+ clipboard().ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
+ &fragment_start, &fragment_end);
EXPECT_PRED2(MarkupMatches, markup, markup_result);
EXPECT_EQ(url, url_result);
// Make sure that fragment indices were adjusted when converting.
@@ -237,21 +217,20 @@ TEST_F(ClipboardTest, UniodeHTMLTest) {
#if defined(TOOLKIT_GTK)
// Regression test for crbug.com/56298 (pasting empty HTML crashes Linux).
TEST_F(ClipboardTest, EmptyHTMLTest) {
- Clipboard clipboard;
// ScopedClipboardWriter doesn't let us write empty data to the clipboard.
- clipboard.clipboard_data_ = new Clipboard::TargetMap();
+ clipboard().clipboard_data_ = new Clipboard::TargetMap();
// The 1 is so the compiler doesn't warn about allocating an empty array.
char* empty = new char[1];
- clipboard.InsertMapping("text/html", empty, 0U);
- clipboard.SetGtkClipboard(Clipboard::BUFFER_STANDARD);
+ clipboard().InsertMapping("text/html", empty, 0U);
+ clipboard().SetGtkClipboard(Clipboard::BUFFER_STANDARD);
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
string16 markup_result;
std::string url_result;
uint32 ignored;
- clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
- &ignored, &ignored);
+ clipboard().ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
+ &ignored, &ignored);
EXPECT_PRED2(MarkupMatches, string16(), markup_result);
}
#endif
@@ -259,88 +238,82 @@ TEST_F(ClipboardTest, EmptyHTMLTest) {
// TODO(estade): Port the following test (decide what target we use for urls)
#if !defined(OS_POSIX) || defined(OS_MACOSX)
TEST_F(ClipboardTest, BookmarkTest) {
- Clipboard clipboard;
-
string16 title(ASCIIToUTF16("The Example Company")), title_result;
std::string url("http://www.example.com/"), url_result;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteBookmark(title, url);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType(),
- Clipboard::BUFFER_STANDARD));
- clipboard.ReadBookmark(&title_result, &url_result);
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetUrlWFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ clipboard().ReadBookmark(&title_result, &url_result);
EXPECT_EQ(title, title_result);
EXPECT_EQ(url, url_result);
}
#endif // defined(OS_WIN)
TEST_F(ClipboardTest, MultiFormatTest) {
- Clipboard clipboard;
-
string16 text(ASCIIToUTF16("Hi!")), text_result;
string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result;
std::string url("http://www.example.com/"), url_result;
std::string ascii_text;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteHTML(markup, url);
clipboard_writer.WriteText(text);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
- EXPECT_TRUE(clipboard.IsFormatAvailable(
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
- EXPECT_TRUE(clipboard.IsFormatAvailable(
+ EXPECT_TRUE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD));
uint32 ignored;
- clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
- &ignored, &ignored);
+ clipboard().ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
+ &ignored, &ignored);
EXPECT_PRED2(MarkupMatches, markup, markup_result);
#if defined(OS_WIN)
// TODO(playmobil): It's not clear that non windows clipboards need to support
// this.
EXPECT_EQ(url, url_result);
#endif // defined(OS_WIN)
- clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result);
+ clipboard().ReadText(Clipboard::BUFFER_STANDARD, &text_result);
EXPECT_EQ(text, text_result);
- clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
+ clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
}
TEST_F(ClipboardTest, URLTest) {
- Clipboard clipboard;
-
string16 url(ASCIIToUTF16("http://www.google.com/"));
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteURL(url);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(
+ EXPECT_TRUE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
+ Clipboard::BUFFER_STANDARD));
string16 text_result;
- clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result);
+ clipboard().ReadText(Clipboard::BUFFER_STANDARD, &text_result);
EXPECT_EQ(text_result, url);
std::string ascii_text;
- clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
+ clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
EXPECT_EQ(UTF16ToUTF8(url), ascii_text);
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
ascii_text.clear();
- clipboard.ReadAsciiText(Clipboard::BUFFER_SELECTION, &ascii_text);
+ clipboard().ReadAsciiText(Clipboard::BUFFER_SELECTION, &ascii_text);
EXPECT_EQ(UTF16ToUTF8(url), ascii_text);
#endif
}
@@ -366,7 +339,7 @@ TEST_F(ClipboardTest, SharedBitmapTest) {
shared_buf.ShareToProcess(current_process, &handle_to_share);
ASSERT_TRUE(shared_buf.Unmap());
- // Setup data for clipboard.
+ // Setup data for clipboard().
Clipboard::ObjectMapParam placeholder_param;
Clipboard::ObjectMapParam size_param;
const char* size_data = reinterpret_cast<const char*>(&fake_bitmap_size);
@@ -381,11 +354,10 @@ TEST_F(ClipboardTest, SharedBitmapTest) {
objects[Clipboard::CBF_SMBITMAP] = params;
Clipboard::ReplaceSharedMemHandle(&objects, handle_to_share, current_process);
- Clipboard clipboard;
- clipboard.WriteObjects(Clipboard::BUFFER_STANDARD, objects);
+ clipboard().WriteObjects(Clipboard::BUFFER_STANDARD, objects);
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(),
+ Clipboard::BUFFER_STANDARD));
}
// The following test somehow fails on GTK. The image when read back from the
@@ -393,8 +365,6 @@ TEST_F(ClipboardTest, SharedBitmapTest) {
// channels stay intact. So I am turning this on only for aura.
#if (defined(USE_AURA) && !defined(OS_WIN)) || defined(OS_ANDROID)
TEST_F(ClipboardTest, MultipleBitmapReadWriteTest) {
- Clipboard clipboard;
-
// Test first bitmap
unsigned int fake_bitmap_1[] = {
0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89,
@@ -403,13 +373,13 @@ TEST_F(ClipboardTest, MultipleBitmapReadWriteTest) {
};
gfx::Size fake_bitmap_1_size(3, 4);
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteBitmapFromPixels(fake_bitmap_1, fake_bitmap_1_size);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(),
- Clipboard::BUFFER_STANDARD));
- SkBitmap image_1 = clipboard.ReadImage(Clipboard::BUFFER_STANDARD);
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ SkBitmap image_1 = clipboard().ReadImage(Clipboard::BUFFER_STANDARD);
EXPECT_EQ(fake_bitmap_1_size, gfx::Size(image_1.width(), image_1.height()));
unsigned int* pixels_1 = reinterpret_cast<unsigned int*>(image_1.getPixels());
for (int i = 0; i < fake_bitmap_1_size.width(); ++i) {
@@ -431,13 +401,13 @@ TEST_F(ClipboardTest, MultipleBitmapReadWriteTest) {
};
gfx::Size fake_bitmap_2_size(7, 2);
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteBitmapFromPixels(fake_bitmap_2, fake_bitmap_2_size);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(),
- Clipboard::BUFFER_STANDARD));
- SkBitmap image_2 = clipboard.ReadImage(Clipboard::BUFFER_STANDARD);
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(),
+ Clipboard::BUFFER_STANDARD));
+ SkBitmap image_2 = clipboard().ReadImage(Clipboard::BUFFER_STANDARD);
EXPECT_EQ(fake_bitmap_2_size, gfx::Size(image_2.width(), image_2.height()));
unsigned int* pixels_2 = reinterpret_cast<unsigned int*>(image_2.getPixels());
for (int i = 0; i < fake_bitmap_2_size.width(); ++i) {
@@ -450,7 +420,6 @@ TEST_F(ClipboardTest, MultipleBitmapReadWriteTest) {
#endif
TEST_F(ClipboardTest, DataTest) {
- Clipboard clipboard;
const ui::Clipboard::FormatType kFormat =
ui::Clipboard::GetFormatType("chromium/x-test-format");
std::string payload("test string");
@@ -458,15 +427,15 @@ TEST_F(ClipboardTest, DataTest) {
write_pickle.WriteString(payload);
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WritePickledData(write_pickle, kFormat);
}
- ASSERT_TRUE(clipboard.IsFormatAvailable(
+ ASSERT_TRUE(clipboard().IsFormatAvailable(
kFormat, Clipboard::BUFFER_STANDARD));
std::string output;
- clipboard.ReadData(kFormat, &output);
+ clipboard().ReadData(kFormat, &output);
ASSERT_FALSE(output.empty());
Pickle read_pickle(output.data(), output.size());
@@ -477,7 +446,6 @@ TEST_F(ClipboardTest, DataTest) {
}
TEST_F(ClipboardTest, MultipleDataTest) {
- Clipboard clipboard;
const ui::Clipboard::FormatType kFormat1 =
ui::Clipboard::GetFormatType("chromium/x-test-format1");
std::string payload1("test string1");
@@ -491,19 +459,19 @@ TEST_F(ClipboardTest, MultipleDataTest) {
write_pickle2.WriteString(payload2);
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WritePickledData(write_pickle1, kFormat1);
// overwrite the previous pickle for fun
clipboard_writer.WritePickledData(write_pickle2, kFormat2);
}
- ASSERT_TRUE(clipboard.IsFormatAvailable(
+ ASSERT_TRUE(clipboard().IsFormatAvailable(
kFormat2, Clipboard::BUFFER_STANDARD));
// Check string 2.
std::string output2;
- clipboard.ReadData(kFormat2, &output2);
+ clipboard().ReadData(kFormat2, &output2);
ASSERT_FALSE(output2.empty());
Pickle read_pickle2(output2.data(), output2.size());
@@ -513,19 +481,19 @@ TEST_F(ClipboardTest, MultipleDataTest) {
EXPECT_EQ(payload2, unpickled_string2);
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WritePickledData(write_pickle2, kFormat2);
// overwrite the previous pickle for fun
clipboard_writer.WritePickledData(write_pickle1, kFormat1);
}
- ASSERT_TRUE(clipboard.IsFormatAvailable(
+ ASSERT_TRUE(clipboard().IsFormatAvailable(
kFormat1, Clipboard::BUFFER_STANDARD));
// Check string 1.
std::string output1;
- clipboard.ReadData(kFormat1, &output1);
+ clipboard().ReadData(kFormat1, &output1);
ASSERT_FALSE(output1.empty());
Pickle read_pickle1(output1.data(), output1.size());
@@ -537,8 +505,6 @@ TEST_F(ClipboardTest, MultipleDataTest) {
#if defined(OS_WIN) // Windows only tests.
TEST_F(ClipboardTest, HyperlinkTest) {
- Clipboard clipboard;
-
const std::string kTitle("The Example Company");
const std::string kUrl("http://www.example.com/");
const std::string kExpectedHtml("<a href=\"http://www.example.com/\">"
@@ -547,29 +513,27 @@ TEST_F(ClipboardTest, HyperlinkTest) {
string16 html_result;
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteHyperlink(ASCIIToUTF16(kTitle), kUrl);
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
+ Clipboard::BUFFER_STANDARD));
uint32 ignored;
- clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &html_result, &url_result,
- &ignored, &ignored);
+ clipboard().ReadHTML(Clipboard::BUFFER_STANDARD, &html_result, &url_result,
+ &ignored, &ignored);
EXPECT_PRED2(MarkupMatches, ASCIIToUTF16(kExpectedHtml), html_result);
}
TEST_F(ClipboardTest, WebSmartPasteTest) {
- Clipboard clipboard;
-
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteWebSmartPaste();
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(
+ EXPECT_TRUE(clipboard().IsFormatAvailable(
Clipboard::GetWebKitSmartPasteFormatType(), Clipboard::BUFFER_STANDARD));
}
@@ -580,16 +544,14 @@ TEST_F(ClipboardTest, BitmapTest) {
0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1,
};
- Clipboard clipboard;
-
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4));
}
- EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(),
+ Clipboard::BUFFER_STANDARD));
}
void HtmlTestHelper(const std::string& cf_html,
@@ -637,10 +599,8 @@ TEST_F(ClipboardTest, HtmlTest) {
// Test writing all formats we have simultaneously.
TEST_F(ClipboardTest, WriteEverything) {
- Clipboard clipboard;
-
{
- ScopedClipboardWriter writer(&clipboard, Clipboard::BUFFER_STANDARD);
+ ScopedClipboardWriter writer(&clipboard(), Clipboard::BUFFER_STANDARD);
writer.WriteText(UTF8ToUTF16("foo"));
writer.WriteURL(UTF8ToUTF16("foo"));
writer.WriteHTML(UTF8ToUTF16("foo"), "bar");
@@ -664,10 +624,9 @@ TEST_F(ClipboardTest, InternalClipboardInvalidation) {
0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1,
};
- // Write a bitmap in our clipboard.
- Clipboard clipboard;
+ // Write a bitmap in our clipboard().
{
- ScopedClipboardWriter clipboard_writer(&clipboard,
+ ScopedClipboardWriter clipboard_writer(&clipboard(),
Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteBitmapFromPixels(kFakeBitmap, gfx::Size(3, 4));
}
@@ -708,16 +667,16 @@ TEST_F(ClipboardTest, InternalClipboardInvalidation) {
env->NewStringUTF(new_value.c_str()));
// The bitmap that should have been available should be gone.
- EXPECT_FALSE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(),
- Clipboard::BUFFER_STANDARD));
+ EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(),
+ Clipboard::BUFFER_STANDARD));
// Make sure some text is available
- EXPECT_TRUE(clipboard.IsFormatAvailable(
+ EXPECT_TRUE(clipboard().IsFormatAvailable(
Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
// Make sure the text is what we inserted while simulating the other app
std::string contents;
- clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents);
+ clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents);
EXPECT_EQ(contents, new_value);
}
#endif
diff --git a/ui/views/controls/message_box_view.cc b/ui/views/controls/message_box_view.cc
index 960b316..5d5e909 100644
--- a/ui/views/controls/message_box_view.cc
+++ b/ui/views/controls/message_box_view.cc
@@ -17,7 +17,6 @@
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h"
@@ -140,10 +139,7 @@ bool MessageBoxView::AcceleratorPressed(const ui::Accelerator& accelerator) {
if (prompt_field_ && prompt_field_->HasFocus())
return false;
- if (!ViewsDelegate::views_delegate)
- return false;
-
- ui::Clipboard* clipboard = ViewsDelegate::views_delegate->GetClipboard();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
if (!clipboard)
return false;
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc
index f1cdf26..80474c9 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -37,7 +37,6 @@
#include "ui/views/controls/textfield/textfield_views_model.h"
#include "ui/views/ime/input_method.h"
#include "ui/views/metrics.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "unicode/uchar.h"
@@ -586,8 +585,8 @@ bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const {
case IDS_APP_COPY:
return model_->HasSelection() && !textfield_->IsObscured();
case IDS_APP_PASTE:
- ViewsDelegate::views_delegate->GetClipboard()
- ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ ui::Clipboard::GetForCurrentThread()->ReadText(
+ ui::Clipboard::BUFFER_STANDARD, &result);
return editable && !result.empty();
case IDS_APP_DELETE:
return editable && model_->HasSelection();
diff --git a/ui/views/controls/textfield/native_textfield_views_unittest.cc b/ui/views/controls/textfield/native_textfield_views_unittest.cc
index c78bbf8..392c010 100644
--- a/ui/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/ui/views/controls/textfield/native_textfield_views_unittest.cc
@@ -34,7 +34,6 @@
#include "ui/views/ime/mock_input_method.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/widget.h"
@@ -235,14 +234,14 @@ class NativeTextfieldViewsTest : public ViewsTestBase,
string16 GetClipboardText() const {
string16 text;
- views::ViewsDelegate::views_delegate->GetClipboard()->
+ ui::Clipboard::GetForCurrentThread()->
ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
return text;
}
void SetClipboardText(const std::string& text) {
ui::ScopedClipboardWriter clipboard_writer(
- views::ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(ASCIIToUTF16(text));
}
@@ -1103,7 +1102,7 @@ TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) {
EXPECT_STR_NE(" one two three ", str);
SendKeyEvent(ui::VKEY_C, false, true);
- views::ViewsDelegate::views_delegate->GetClipboard()->
+ ui::Clipboard::GetForCurrentThread()->
ReadText(ui::Clipboard::BUFFER_STANDARD, &str);
EXPECT_STR_EQ(" one two three ", str);
diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc
index c356451..d5277d9 100644
--- a/ui/views/controls/textfield/native_textfield_win.cc
+++ b/ui/views/controls/textfield/native_textfield_win.cc
@@ -33,7 +33,6 @@
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/metrics.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
namespace views {
@@ -560,9 +559,9 @@ void NativeTextfieldWin::OnCopy() {
return;
const string16 text(GetSelectedText());
- if (!text.empty() && ViewsDelegate::views_delegate) {
+ if (!text.empty()) {
ui::ScopedClipboardWriter scw(
- ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD);
scw.WriteText(text);
}
@@ -975,10 +974,10 @@ void NativeTextfieldWin::OnNonLButtonDown(UINT keys, const CPoint& point) {
}
void NativeTextfieldWin::OnPaste() {
- if (textfield_->read_only() || !ViewsDelegate::views_delegate)
+ if (textfield_->read_only())
return;
- ui::Clipboard* clipboard = ViewsDelegate::views_delegate->GetClipboard();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
if (!clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
ui::Clipboard::BUFFER_STANDARD))
return;
diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc
index d51e417..89fe947 100644
--- a/ui/views/controls/textfield/textfield_views_model.cc
+++ b/ui/views/controls/textfield/textfield_views_model.cc
@@ -20,7 +20,6 @@
#include "ui/gfx/render_text.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/views_delegate.h"
namespace views {
@@ -511,7 +510,7 @@ bool TextfieldViewsModel::Redo() {
bool TextfieldViewsModel::Cut() {
if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) {
ui::ScopedClipboardWriter(
- views::ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText());
// A trick to let undo/redo handle cursor correctly.
// Undoing CUT moves the cursor to the end of the change rather
@@ -529,7 +528,7 @@ bool TextfieldViewsModel::Cut() {
bool TextfieldViewsModel::Copy() {
if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) {
ui::ScopedClipboardWriter(
- views::ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText());
return true;
}
@@ -538,7 +537,7 @@ bool TextfieldViewsModel::Copy() {
bool TextfieldViewsModel::Paste() {
string16 result;
- views::ViewsDelegate::views_delegate->GetClipboard()
+ ui::Clipboard::GetForCurrentThread()
->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
if (!result.empty()) {
InsertTextInternal(result, false);
diff --git a/ui/views/controls/textfield/textfield_views_model_unittest.cc b/ui/views/controls/textfield/textfield_views_model_unittest.cc
index 376f7d4..a94bf4d 100644
--- a/ui/views/controls/textfield/textfield_views_model_unittest.cc
+++ b/ui/views/controls/textfield/textfield_views_model_unittest.cc
@@ -18,7 +18,6 @@
#include "ui/views/controls/textfield/textfield_views_model.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/views_delegate.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
@@ -495,7 +494,7 @@ TEST_F(TextfieldViewsModelTest, SetText) {
#endif
TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) {
ui::Clipboard* clipboard
- = views::ViewsDelegate::views_delegate->GetClipboard();
+ = ui::Clipboard::GetForCurrentThread();
string16 initial_clipboard_text = ASCIIToUTF16("initial text");
ui::ScopedClipboardWriter(
clipboard,
diff --git a/ui/views/test/test_views_delegate.cc b/ui/views/test/test_views_delegate.cc
index 2ae2aa4..e87f18d 100644
--- a/ui/views/test/test_views_delegate.cc
+++ b/ui/views/test/test_views_delegate.cc
@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "content/public/test/web_contents_tester.h"
-#include "ui/base/clipboard/clipboard.h"
namespace views {
@@ -24,14 +23,6 @@ void TestViewsDelegate::SetUseTransparentWindows(bool transparent) {
use_transparent_windows_ = transparent;
}
-ui::Clipboard* TestViewsDelegate::GetClipboard() const {
- if (!clipboard_.get()) {
- // Note that we need a MessageLoop for the next call to work.
- clipboard_.reset(new ui::Clipboard);
- }
- return clipboard_.get();
-}
-
void TestViewsDelegate::SaveWindowPlacement(const Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/ui/views/test/test_views_delegate.h b/ui/views/test/test_views_delegate.h
index 54ae0be..6568196 100644
--- a/ui/views/test/test_views_delegate.h
+++ b/ui/views/test/test_views_delegate.h
@@ -28,7 +28,6 @@ class TestViewsDelegate : public ViewsDelegate {
void SetUseTransparentWindows(bool transparent);
// Overridden from ViewsDelegate:
- virtual ui::Clipboard* GetClipboard() const OVERRIDE;
virtual void SaveWindowPlacement(const Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
@@ -69,7 +68,6 @@ class TestViewsDelegate : public ViewsDelegate {
content::SiteInstance* site_instance) OVERRIDE;
private:
- mutable scoped_ptr<ui::Clipboard> clipboard_;
bool use_transparent_windows_;
DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate);
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 45d83b5..5b08793 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -1168,8 +1168,6 @@ TEST_F(ViewTest, Textfield) {
const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!");
const string16 kEmptyString;
- ui::Clipboard clipboard;
-
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(0, 0, 100, 100);
@@ -1206,7 +1204,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
const string16 kReadOnlyText = ASCIIToUTF16("Read only");
const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **");
- ui::Clipboard clipboard;
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
@@ -1235,7 +1233,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0);
string16 result;
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kNormalText, result);
normal->SetText(kNormalText); // Let's revert to the original content.
@@ -1243,7 +1241,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
// Cut should have failed, so the clipboard content should not have changed.
EXPECT_EQ(kNormalText, result);
@@ -1251,7 +1249,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
// Cut should have failed, so the clipboard content should not have changed.
EXPECT_EQ(kNormalText, result);
@@ -1264,19 +1262,19 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kReadOnlyText, result);
normal->SelectAll(false);
::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kNormalText, result);
password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
// We don't let you copy from an obscured field, clipboard should not have
// changed.
EXPECT_EQ(kNormalText, result);
diff --git a/ui/views/views_delegate.h b/ui/views/views_delegate.h
index 5fb3929..a3f8430 100644
--- a/ui/views/views_delegate.h
+++ b/ui/views/views_delegate.h
@@ -26,10 +26,6 @@ namespace gfx {
class Rect;
}
-namespace ui {
-class Clipboard;
-}
-
namespace views {
class NonClientFrameView;
@@ -54,9 +50,6 @@ class VIEWS_EXPORT ViewsDelegate {
virtual ~ViewsDelegate() {}
- // Gets the clipboard.
- virtual ui::Clipboard* GetClipboard() const = 0;
-
// Saves the position, size and "show" state for the window with the
// specified name.
virtual void SaveWindowPlacement(const Widget* widget,
diff --git a/webkit/tools/test_shell/simple_clipboard_impl.cc b/webkit/tools/test_shell/simple_clipboard_impl.cc
index 06d6c8b..d51e109 100644
--- a/webkit/tools/test_shell/simple_clipboard_impl.cc
+++ b/webkit/tools/test_shell/simple_clipboard_impl.cc
@@ -23,8 +23,6 @@
namespace {
-base::LazyInstance<ui::Clipboard> clipboard = LAZY_INSTANCE_INITIALIZER;
-
} // anonymous namespace
SimpleClipboardClient::SimpleClipboardClient() {
@@ -35,7 +33,7 @@ SimpleClipboardClient::~SimpleClipboardClient() {
ui::Clipboard* SimpleClipboardClient::GetClipboard() {
- return clipboard.Pointer();
+ return ui::Clipboard::GetForCurrentThread();
}
uint64 SimpleClipboardClient::GetSequenceNumber(ui::Clipboard::Buffer buffer) {