From 6a4f5af29737b966d1cb9e0ab149d7cd0055e5fd Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Wed, 23 Sep 2009 22:43:00 +0000 Subject: Let cmd-f/cmd-g use the findboard. In a nutshell, this means that the find bars honor the global find pasteboard, which is like a clipboard, but for searches. See the TEST section below for consequences, and also see the bug for more information. BUG=14562 TEST= * Select some text, hit cmd-e, cmd-g. This should search for the marked text and open the find bar if it's not open. * Open TextEdit, hit cmd-f. Enter some text, hit enter. Switch back to Chrome with an open find bar. The find bar should now contain the text you entered in TextEdit * Enter different text into chrome's find bar, switch back to TextEdit. Its find window should now contain the new text. * Search for something in one tab, switch to another tab. It should contain the same text in the findbar as the first one. * Open the findbar, select some text, hit cmd-e. The find bar should be updated with the selected text and this text should be highlighted in the web page. Find bars in other tabs should be updated with that text as well. Review URL: http://codereview.chromium.org/206035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27015 0039d316-1c4b-4281-b951-d872f2087c98 --- .../renderer_host/resource_message_filter_mac.mm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'chrome/browser/renderer_host') diff --git a/chrome/browser/renderer_host/resource_message_filter_mac.mm b/chrome/browser/renderer_host/resource_message_filter_mac.mm index b63c5bf..f7687c9 100644 --- a/chrome/browser/renderer_host/resource_message_filter_mac.mm +++ b/chrome/browser/renderer_host/resource_message_filter_mac.mm @@ -6,23 +6,36 @@ #import +#include "base/message_loop.h" #include "base/sys_string_conversions.h" +#import "chrome/browser/cocoa/find_pasteboard.h" // The number of utf16 code units that will be written to the find pasteboard, // longer texts are silently ignored. This is to prevent that a compromised // renderer can write unlimited amounts of data into the find pasteboard. static const size_t kMaxFindPboardStringLength = 4096; +class WriteFindPboardTask : public Task { + public: + explicit WriteFindPboardTask(NSString* text) + : text_([text retain]) {} + + void Run() { + [[FindPasteboard sharedInstance] setFindText:text_]; + } + + private: + scoped_nsobject text_; +}; + // Called on the IO thread. void ResourceMessageFilter::OnClipboardFindPboardWriteString( const string16& text) { if (text.length() <= kMaxFindPboardStringLength) { NSString* nsText = base::SysUTF16ToNSString(text); if (nsText) { - NSPasteboard* findPboard = [NSPasteboard pasteboardWithName:NSFindPboard]; - [findPboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] - owner:nil]; - [findPboard setString:nsText forType:NSStringPboardType]; + // FindPasteboard must be used on the UI thread. + ui_loop()->PostTask(FROM_HERE, new WriteFindPboardTask(nsText)); } } } -- cgit v1.1