Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "content/browser/renderer_host/text_input_client_mac.h" | 5 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_delegate.h" | |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "content/common/text_input_client_messages.h" | 13 #include "content/common/text_input_client_messages.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 17 namespace { | |
| 18 | |
| 19 // TODO(ekaramad): TextInputClientObserver, the renderer side of | |
| 20 // TextInputClientMac for each RenderWidgetHost, expects to have a | |
| 21 // WebFrameWidget to use for handling these IPCs. However, for fullscreen flash, | |
| 22 // we end up with a PepperWidget. For those scenarios, do not send the IPCs. We | |
| 23 // need to figure out what features are properly supported and perhaps send the | |
| 24 // IPC to the parent widget of the plugin. | |
|
alexmos
2016/11/04 20:34:03
Let's add a bug reference here.
EhsanK
2016/11/08 16:59:44
Done.
| |
| 25 bool SendMessageToRenderWidge(RenderWidgetHostImpl* widget, | |
|
alexmos
2016/11/04 20:34:03
s/SendMessageToRenderWidge/SendMessageToRenderWidg
EhsanK
2016/11/08 16:59:44
Done.
| |
| 26 IPC::Message* message) { | |
| 27 if (!widget->delegate()) | |
| 28 return false; | |
|
alexmos
2016/11/04 20:34:03
Do you need to delete the message here as well?
EhsanK
2016/11/08 16:59:44
Yes. Thanks!
| |
| 29 | |
| 30 if (widget == widget->delegate()->GetFullscreenRenderWidgetHost()) { | |
| 31 delete message; | |
| 32 return false; | |
| 33 } | |
| 34 | |
|
alexmos
2016/11/04 20:34:03
maybe DCHECK that message->routing_id() == widget-
EhsanK
2016/11/08 16:59:44
Acknowledged. I guess this makes sure we cannot se
| |
| 35 return widget->Send(message); | |
| 36 } | |
| 37 } | |
| 38 | |
| 16 // The amount of time in milliseconds that the browser process will wait for a | 39 // The amount of time in milliseconds that the browser process will wait for a |
| 17 // response from the renderer. | 40 // response from the renderer. |
| 18 // TODO(rsesek): Using the histogram data, find the best upper-bound for this | 41 // TODO(rsesek): Using the histogram data, find the best upper-bound for this |
| 19 // value. | 42 // value. |
| 20 const float kWaitTimeout = 1500; | 43 const float kWaitTimeout = 1500; |
| 21 | 44 |
| 22 TextInputClientMac::TextInputClientMac() | 45 TextInputClientMac::TextInputClientMac() |
| 23 : character_index_(NSNotFound), | 46 : character_index_(NSNotFound), |
| 24 lock_(), | 47 lock_(), |
| 25 condition_(&lock_) { | 48 condition_(&lock_) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 RenderWidgetHost* rwh, | 60 RenderWidgetHost* rwh, |
| 38 gfx::Point point, | 61 gfx::Point point, |
| 39 void (^reply_handler)(NSAttributedString*, NSPoint)) { | 62 void (^reply_handler)(NSAttributedString*, NSPoint)) { |
| 40 // TODO(ekaramad): In principle, we are using the same handler regardless of | 63 // TODO(ekaramad): In principle, we are using the same handler regardless of |
| 41 // the |rwh| which requested this. We should track the callbacks for each | 64 // the |rwh| which requested this. We should track the callbacks for each |
| 42 // |rwh| individually so that one slow RWH will not end up clearing the | 65 // |rwh| individually so that one slow RWH will not end up clearing the |
| 43 // callback for another (https://crbug.com/643233). | 66 // callback for another (https://crbug.com/643233). |
| 44 DCHECK(replyForPointHandler_.get() == nil); | 67 DCHECK(replyForPointHandler_.get() == nil); |
| 45 replyForPointHandler_.reset(reply_handler, base::scoped_policy::RETAIN); | 68 replyForPointHandler_.reset(reply_handler, base::scoped_policy::RETAIN); |
| 46 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 69 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 47 rwhi->Send(new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), point)); | 70 SendMessageToRenderWidge( |
| 71 rwhi, new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), point)); | |
| 48 } | 72 } |
| 49 | 73 |
| 50 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string, | 74 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string, |
| 51 NSPoint point) { | 75 NSPoint point) { |
| 52 if (replyForPointHandler_.get()) { | 76 if (replyForPointHandler_.get()) { |
| 53 replyForPointHandler_.get()(string, point); | 77 replyForPointHandler_.get()(string, point); |
| 54 replyForPointHandler_.reset(); | 78 replyForPointHandler_.reset(); |
| 55 } | 79 } |
| 56 } | 80 } |
| 57 | 81 |
| 58 void TextInputClientMac::GetStringFromRange( | 82 void TextInputClientMac::GetStringFromRange( |
| 59 RenderWidgetHost* rwh, | 83 RenderWidgetHost* rwh, |
| 60 NSRange range, | 84 NSRange range, |
| 61 void (^reply_handler)(NSAttributedString*, NSPoint)) { | 85 void (^reply_handler)(NSAttributedString*, NSPoint)) { |
| 62 DCHECK(replyForRangeHandler_.get() == nil); | 86 DCHECK(replyForRangeHandler_.get() == nil); |
| 63 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN); | 87 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN); |
| 64 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 88 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 65 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), | 89 SendMessageToRenderWidge(rwhi, new TextInputClientMsg_StringForRange( |
| 66 gfx::Range(range))); | 90 rwhi->GetRoutingID(), gfx::Range(range))); |
| 67 } | 91 } |
| 68 | 92 |
| 69 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string, | 93 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string, |
| 70 NSPoint point) { | 94 NSPoint point) { |
| 71 if (replyForRangeHandler_.get()) { | 95 if (replyForRangeHandler_.get()) { |
| 72 replyForRangeHandler_.get()(string, point); | 96 replyForRangeHandler_.get()(string, point); |
| 73 replyForRangeHandler_.reset(); | 97 replyForRangeHandler_.reset(); |
| 74 } | 98 } |
| 75 } | 99 } |
| 76 | 100 |
| 77 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, | 101 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, |
| 78 gfx::Point point) { | 102 gfx::Point point) { |
| 79 base::TimeTicks start = base::TimeTicks::Now(); | 103 base::TimeTicks start = base::TimeTicks::Now(); |
| 80 | 104 |
| 81 BeforeRequest(); | 105 BeforeRequest(); |
| 82 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 106 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 83 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), | 107 if (!SendMessageToRenderWidge(rwhi, |
| 84 point)); | 108 new TextInputClientMsg_CharacterIndexForPoint( |
| 109 rwhi->GetRoutingID(), point))) | |
| 110 return NSNotFound; | |
| 111 | |
| 85 // http://crbug.com/121917 | 112 // http://crbug.com/121917 |
| 86 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 113 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 87 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 114 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
| 88 AfterRequest(); | 115 AfterRequest(); |
| 89 | 116 |
| 90 base::TimeDelta delta(base::TimeTicks::Now() - start); | 117 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 91 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.CharacterIndex", | 118 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.CharacterIndex", |
| 92 delta * base::Time::kMicrosecondsPerMillisecond); | 119 delta * base::Time::kMicrosecondsPerMillisecond); |
| 93 | 120 |
| 94 return character_index_; | 121 return character_index_; |
| 95 } | 122 } |
| 96 | 123 |
| 97 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, | 124 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, |
| 98 NSRange range) { | 125 NSRange range) { |
| 99 base::TimeTicks start = base::TimeTicks::Now(); | 126 base::TimeTicks start = base::TimeTicks::Now(); |
| 100 | 127 |
| 101 BeforeRequest(); | 128 BeforeRequest(); |
| 102 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 129 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 103 rwhi->Send( | 130 if (!SendMessageToRenderWidge( |
| 104 new TextInputClientMsg_FirstRectForCharacterRange(rwhi->GetRoutingID(), | 131 rwhi, new TextInputClientMsg_FirstRectForCharacterRange( |
| 105 gfx::Range(range))); | 132 rwhi->GetRoutingID(), gfx::Range(range)))) |
| 133 return NSRect(); | |
| 134 | |
| 106 // http://crbug.com/121917 | 135 // http://crbug.com/121917 |
| 107 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 136 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 108 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 137 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
| 109 AfterRequest(); | 138 AfterRequest(); |
| 110 | 139 |
| 111 base::TimeDelta delta(base::TimeTicks::Now() - start); | 140 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 112 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect", | 141 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect", |
| 113 delta * base::Time::kMicrosecondsPerMillisecond); | 142 delta * base::Time::kMicrosecondsPerMillisecond); |
| 114 | 143 |
| 115 return first_rect_; | 144 return first_rect_; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 140 | 169 |
| 141 character_index_ = NSNotFound; | 170 character_index_ = NSNotFound; |
| 142 first_rect_ = NSZeroRect; | 171 first_rect_ = NSZeroRect; |
| 143 } | 172 } |
| 144 | 173 |
| 145 void TextInputClientMac::AfterRequest() { | 174 void TextInputClientMac::AfterRequest() { |
| 146 lock_.Release(); | 175 lock_.Release(); |
| 147 } | 176 } |
| 148 | 177 |
| 149 } // namespace content | 178 } // namespace content |
| OLD | NEW |