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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
Mark Mentovai
2013/06/24 21:37:28
IWYU.
Nico
2013/06/24 22:06:27
Done.
| |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #import "ui/base/cocoa/find_pasteboard.h" | 14 #import "ui/base/cocoa/find_pasteboard.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 namespace { | 17 namespace { |
18 | 18 |
19 // The number of utf16 code units that will be written to the find pasteboard, | 19 // The number of utf16 code units that will be written to the find pasteboard, |
20 // longer texts are silently ignored. This is to prevent that a compromised | 20 // longer texts are silently ignored. This is to prevent that a compromised |
21 // renderer can write unlimited amounts of data into the find pasteboard. | 21 // renderer can write unlimited amounts of data into the find pasteboard. |
22 static const size_t kMaxFindPboardStringLength = 4096; | 22 static const size_t kMaxFindPboardStringLength = 4096; |
23 | 23 |
24 class WriteFindPboardWrapper { | 24 class WriteFindPboardWrapper { |
25 public: | 25 public: |
26 explicit WriteFindPboardWrapper(NSString* text) | 26 explicit WriteFindPboardWrapper(NSString* text) |
27 : text_([text retain]) {} | 27 : text_([text retain]) {} |
28 | 28 |
29 void Run() { | 29 void Run() { |
30 [[FindPasteboard sharedInstance] setFindText:text_]; | 30 [[FindPasteboard sharedInstance] setFindText:text_]; |
31 } | 31 } |
32 | 32 |
33 private: | 33 private: |
34 scoped_nsobject<NSString> text_; | 34 base::scoped_nsobject<NSString> text_; |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(WriteFindPboardWrapper); | 36 DISALLOW_COPY_AND_ASSIGN(WriteFindPboardWrapper); |
37 }; | 37 }; |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 // Called on the IO thread. | 41 // Called on the IO thread. |
42 void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) { | 42 void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) { |
43 if (text.length() <= kMaxFindPboardStringLength) { | 43 if (text.length() <= kMaxFindPboardStringLength) { |
44 NSString* nsText = base::SysUTF16ToNSString(text); | 44 NSString* nsText = base::SysUTF16ToNSString(text); |
45 if (nsText) { | 45 if (nsText) { |
46 // FindPasteboard must be used on the UI thread. | 46 // FindPasteboard must be used on the UI thread. |
47 BrowserThread::PostTask( | 47 BrowserThread::PostTask( |
48 BrowserThread::UI, FROM_HERE, base::Bind( | 48 BrowserThread::UI, FROM_HERE, base::Bind( |
49 &WriteFindPboardWrapper::Run, | 49 &WriteFindPboardWrapper::Run, |
50 base::Owned(new WriteFindPboardWrapper(nsText)))); | 50 base::Owned(new WriteFindPboardWrapper(nsText)))); |
51 } | 51 } |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 } // namespace content | 55 } // namespace content |
OLD | NEW |