Chromium Code Reviews| Index: content/renderer/text_input_client_observer.cc |
| diff --git a/content/renderer/text_input_client_observer.cc b/content/renderer/text_input_client_observer.cc |
| index 84c8b88a99e658eac7a9a8351081325aea8fb13f..8d2644102c19bf2e426247e5fc4c7f8811d2e6a3 100644 |
| --- a/content/renderer/text_input_client_observer.cc |
| +++ b/content/renderer/text_input_client_observer.cc |
| @@ -8,6 +8,7 @@ |
| #include <memory> |
| +#include "base/strings/utf_string_conversions.h" |
| #include "build/build_config.h" |
| #include "content/common/text_input_client_messages.h" |
| #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| @@ -52,12 +53,12 @@ bool TextInputClientObserver::Send(IPC::Message* message) { |
| blink::WebFrameWidget* TextInputClientObserver::GetWebFrameWidget() const { |
| blink::WebWidget* widget = render_widget_->GetWebWidget(); |
| - // We should always receive a WebFrameWidget in the call above. RenderViewImpl |
| - // however might return a WebView if the main frame is destroyed, but as long |
| - // as there is a rendered page, we should not be in that state and the RVImpl |
| - // should be returning a frame widget. |
| - DCHECK(widget->isWebFrameWidget()); |
| - return static_cast<blink::WebFrameWidget*>(render_widget_->GetWebWidget()); |
| + // |widget| should only be a WebFrameWidget. It is however possible to get |
| + // here through a fullscreen flash plugin where the |widget| is not a |
| + // WebFrameWidget. |
| + return widget->isWebFrameWidget() |
| + ? static_cast<blink::WebFrameWidget*>(widget) |
| + : nullptr; |
| } |
| blink::WebLocalFrame* TextInputClientObserver::GetFocusedFrame() const { |
| @@ -83,10 +84,12 @@ PepperPluginInstanceImpl* TextInputClientObserver::GetFocusedPepperPlugin() |
| void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { |
| #if defined(OS_MACOSX) |
| + NSAttributedString* string = nil; |
| blink::WebPoint baselinePoint; |
| - NSAttributedString* string = blink::WebSubstringUtil::attributedWordAtPoint( |
| - GetWebFrameWidget(), point, baselinePoint); |
| - |
| + if (GetWebFrameWidget()) { |
|
EhsanK
2016/10/18 01:59:37
When this is false, it is not necessarily because
Avi (use Gerrit)
2016/10/18 02:04:08
Can we find out?
alexmos
2016/10/18 17:52:01
Just to clarify, is this whole class for Mac dicti
EhsanK
2016/11/03 07:13:19
Except for OnCharacterIndexForPoint which is for I
alexmos
2016/11/04 20:34:03
Yes, I think you could opener_id_ to get the the p
EhsanK
2016/11/08 16:59:44
Acknowledged.
|
| + string = blink::WebSubstringUtil::attributedWordAtPoint( |
| + GetWebFrameWidget(), point, baselinePoint); |
| + } |
| std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| mac::AttributedStringCoder::Encode(string)); |
| Send(new TextInputClientReplyMsg_GotStringAtPoint( |
| @@ -98,29 +101,34 @@ void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { |
| void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
| blink::WebPoint web_point(point); |
| - uint32_t index = static_cast<uint32_t>( |
| + uint32_t index = 0; |
| + if (GetWebFrameWidget()) { |
| + index = static_cast<uint32_t>( |
| GetFocusedFrame()->characterIndexForPoint(web_point)); |
| + } |
| Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint( |
| render_widget_->routing_id(), index)); |
| } |
| void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { |
| gfx::Rect rect; |
| + if (GetWebFrameWidget()) { |
| #if defined(ENABLE_PLUGINS) |
| - PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); |
| - if (focused_plugin) { |
| - rect = focused_plugin->GetCaretBounds(); |
| - } else |
| + PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); |
|
lfg
2016/10/19 17:40:32
This looks strange to me. Why would flash receive
EhsanK
2016/11/03 07:13:19
This is why I think we should send the IPC to the
|
| + if (focused_plugin) { |
| + rect = focused_plugin->GetCaretBounds(); |
| + } else |
| #endif |
| - { |
| - blink::WebLocalFrame* frame = GetFocusedFrame(); |
| - // TODO(yabinh): Null check should not be necessary. |
| - // See crbug.com/304341 |
| - if (frame) { |
| - blink::WebRect web_rect; |
| - frame->firstRectForCharacterRange(range.start(), range.length(), |
| - web_rect); |
| - rect = web_rect; |
| + { |
| + blink::WebLocalFrame* frame = GetFocusedFrame(); |
| + // TODO(yabinh): Null check should not be necessary. |
| + // See crbug.com/304341 |
| + if (frame) { |
| + blink::WebRect web_rect; |
| + frame->firstRectForCharacterRange(range.start(), range.length(), |
| + web_rect); |
| + rect = web_rect; |
| + } |
| } |
| } |
| Send(new TextInputClientReplyMsg_GotFirstRectForRange( |
| @@ -131,12 +139,14 @@ void TextInputClientObserver::OnStringForRange(gfx::Range range) { |
| #if defined(OS_MACOSX) |
| blink::WebPoint baselinePoint; |
| NSAttributedString* string = nil; |
| - blink::WebLocalFrame* frame = GetFocusedFrame(); |
| - // TODO(yabinh): Null check should not be necessary. |
| - // See crbug.com/304341 |
| - if (frame) { |
| - string = blink::WebSubstringUtil::attributedSubstringInRange( |
| - frame, range.start(), range.length(), &baselinePoint); |
| + if (GetWebFrameWidget()) { |
| + blink::WebLocalFrame* frame = GetFocusedFrame(); |
| + // TODO(yabinh): Null check should not be necessary. |
| + // See crbug.com/304341 |
| + if (frame) { |
| + string = blink::WebSubstringUtil::attributedSubstringInRange( |
| + frame, range.start(), range.length(), &baselinePoint); |
| + } |
| } |
| std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| mac::AttributedStringCoder::Encode(string)); |