OLD | NEW |
1 // Copyright (c) 2006-2009 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 "chrome/browser/renderer_host/render_message_filter.h" | 5 #include "chrome/browser/renderer_host/render_message_filter.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
12 #import "chrome/browser/ui/cocoa/find_pasteboard.h" | 12 #import "chrome/browser/ui/cocoa/find_pasteboard.h" |
| 13 #import "chrome/browser/ui/cocoa/lookup_in_dictionary.h" |
| 14 #include "gfx/rect.h" |
13 | 15 |
14 // The number of utf16 code units that will be written to the find pasteboard, | 16 // The number of utf16 code units that will be written to the find pasteboard, |
15 // longer texts are silently ignored. This is to prevent that a compromised | 17 // longer texts are silently ignored. This is to prevent that a compromised |
16 // renderer can write unlimited amounts of data into the find pasteboard. | 18 // renderer can write unlimited amounts of data into the find pasteboard. |
17 static const size_t kMaxFindPboardStringLength = 4096; | 19 static const size_t kMaxFindPboardStringLength = 4096; |
18 | 20 |
19 class WriteFindPboardTask : public Task { | 21 class WriteFindPboardTask : public Task { |
20 public: | 22 public: |
21 explicit WriteFindPboardTask(NSString* text) | 23 explicit WriteFindPboardTask(NSString* text) |
22 : text_([text retain]) {} | 24 : text_([text retain]) {} |
(...skipping 11 matching lines...) Expand all Loading... |
34 const string16& text) { | 36 const string16& text) { |
35 if (text.length() <= kMaxFindPboardStringLength) { | 37 if (text.length() <= kMaxFindPboardStringLength) { |
36 NSString* nsText = base::SysUTF16ToNSString(text); | 38 NSString* nsText = base::SysUTF16ToNSString(text); |
37 if (nsText) { | 39 if (nsText) { |
38 // FindPasteboard must be used on the UI thread. | 40 // FindPasteboard must be used on the UI thread. |
39 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
40 BrowserThread::UI, FROM_HERE, new WriteFindPboardTask(nsText)); | 42 BrowserThread::UI, FROM_HERE, new WriteFindPboardTask(nsText)); |
41 } | 43 } |
42 } | 44 } |
43 } | 45 } |
| 46 |
| 47 void RenderMessageFilter::OnGotCharacterIndexForPoint(uint index) { |
| 48 LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| 49 service->SetCharacterIndexAndSignal(index); |
| 50 } |
| 51 |
| 52 void RenderMessageFilter::OnGotFirstRectForRange(const gfx::Rect& rect) { |
| 53 CGRect cgrect(rect.ToCGRect()); |
| 54 LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| 55 service->SetFirstRectAndSignal(NSRectFromCGRect(rect.ToCGRect())); |
| 56 } |
| 57 |
| 58 void RenderMessageFilter::OnGotStringFromRange(const string16& string) { |
| 59 LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| 60 if (!string.length()) { |
| 61 service->SetSubstringAndSignal(nil); |
| 62 } else { |
| 63 NSData* data = [NSData dataWithBytes:string.data() length:string.length()]; |
| 64 NSAttributedString* string = [NSUnarchiver unarchiveObjectWithData:data]; |
| 65 service->SetSubstringAndSignal(string); |
| 66 } |
| 67 } |
OLD | NEW |