OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/clipboard_message_filter.h" | 5 #include "content/browser/renderer_host/clipboard_message_filter.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "content/browser/find_pasteboard.h" | 10 #import "content/browser/find_pasteboard.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 | 12 |
| 13 using content::BrowserThread; |
| 14 |
13 // The number of utf16 code units that will be written to the find pasteboard, | 15 // The number of utf16 code units that will be written to the find pasteboard, |
14 // longer texts are silently ignored. This is to prevent that a compromised | 16 // longer texts are silently ignored. This is to prevent that a compromised |
15 // renderer can write unlimited amounts of data into the find pasteboard. | 17 // renderer can write unlimited amounts of data into the find pasteboard. |
16 static const size_t kMaxFindPboardStringLength = 4096; | 18 static const size_t kMaxFindPboardStringLength = 4096; |
17 | 19 |
18 class WriteFindPboardTask : public Task { | 20 class WriteFindPboardTask : public Task { |
19 public: | 21 public: |
20 explicit WriteFindPboardTask(NSString* text) | 22 explicit WriteFindPboardTask(NSString* text) |
21 : text_([text retain]) {} | 23 : text_([text retain]) {} |
22 | 24 |
23 void Run() { | 25 void Run() { |
24 [[FindPasteboard sharedInstance] setFindText:text_]; | 26 [[FindPasteboard sharedInstance] setFindText:text_]; |
25 } | 27 } |
26 | 28 |
27 private: | 29 private: |
28 scoped_nsobject<NSString> text_; | 30 scoped_nsobject<NSString> text_; |
29 }; | 31 }; |
30 | 32 |
31 // Called on the IO thread. | 33 // Called on the IO thread. |
32 void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) { | 34 void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) { |
33 if (text.length() <= kMaxFindPboardStringLength) { | 35 if (text.length() <= kMaxFindPboardStringLength) { |
34 NSString* nsText = base::SysUTF16ToNSString(text); | 36 NSString* nsText = base::SysUTF16ToNSString(text); |
35 if (nsText) { | 37 if (nsText) { |
36 // FindPasteboard must be used on the UI thread. | 38 // FindPasteboard must be used on the UI thread. |
37 BrowserThread::PostTask( | 39 BrowserThread::PostTask( |
38 BrowserThread::UI, FROM_HERE, new WriteFindPboardTask(nsText)); | 40 BrowserThread::UI, FROM_HERE, new WriteFindPboardTask(nsText)); |
39 } | 41 } |
40 } | 42 } |
41 } | 43 } |
OLD | NEW |