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 #include "content/renderer/text_input_client_observer.h" | 5 #include "content/renderer/text_input_client_observer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 IPC_END_MESSAGE_MAP() | 46 IPC_END_MESSAGE_MAP() |
47 return handled; | 47 return handled; |
48 } | 48 } |
49 | 49 |
50 bool TextInputClientObserver::Send(IPC::Message* message) { | 50 bool TextInputClientObserver::Send(IPC::Message* message) { |
51 return render_widget_->Send(message); | 51 return render_widget_->Send(message); |
52 } | 52 } |
53 | 53 |
54 blink::WebFrameWidget* TextInputClientObserver::GetWebFrameWidget() const { | 54 blink::WebFrameWidget* TextInputClientObserver::GetWebFrameWidget() const { |
55 blink::WebWidget* widget = render_widget_->GetWebWidget(); | 55 blink::WebWidget* widget = render_widget_->GetWebWidget(); |
56 // We should always receive a WebFrameWidget in the call above. RenderViewImpl | 56 if (!widget->isWebFrameWidget()) { |
57 // however might return a WebView if the main frame is destroyed, but as long | 57 // When a page navigation occurs, for a brief period |
58 // as there is a rendered page, we should not be in that state and the RVImpl | 58 // RenderViewImpl::GetWebWidget() will return a WebViewImpl instead of a |
59 // should be returning a frame widget. | 59 // WebViewFrameWidget. Therefore, casting to WebFrameWidget is invalid and |
60 DCHECK(widget->isWebFrameWidget()); | 60 // could cause crashes. Also, WebView::mainFrame() could be a remote frame |
61 return static_cast<blink::WebFrameWidget*>(render_widget_->GetWebWidget()); | 61 // which will yield a nullptr for localRoot() (https://crbug.com/664890). |
62 return nullptr; | |
63 } | |
64 return static_cast<blink::WebFrameWidget*>(widget); | |
62 } | 65 } |
63 | 66 |
64 blink::WebLocalFrame* TextInputClientObserver::GetFocusedFrame() const { | 67 blink::WebLocalFrame* TextInputClientObserver::GetFocusedFrame() const { |
65 blink::WebLocalFrame* focused = | 68 if (auto* frame_widget = GetWebFrameWidget()) { |
66 RenderFrameImpl::FromWebFrame(GetWebFrameWidget()->localRoot()) | 69 blink::WebLocalFrame* localRoot = frame_widget->localRoot(); |
67 ->render_view() | 70 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(localRoot); |
68 ->webview() | 71 if (!render_frame) { |
69 ->focusedFrame(); | 72 // TODO(ekaramad): Can this ever be nullptr? (https://crbug.com/664890). |
70 return focused->localRoot() == GetWebFrameWidget()->localRoot() ? focused | 73 return nullptr; |
71 : nullptr; | 74 } |
75 blink::WebLocalFrame* focused = | |
76 render_frame->render_view()->webview()->focusedFrame(); | |
77 return focused->localRoot() == localRoot ? focused : nullptr; | |
78 } | |
79 return nullptr; | |
72 } | 80 } |
73 | 81 |
74 #if BUILDFLAG(ENABLE_PLUGINS) | 82 #if BUILDFLAG(ENABLE_PLUGINS) |
75 PepperPluginInstanceImpl* TextInputClientObserver::GetFocusedPepperPlugin() | 83 PepperPluginInstanceImpl* TextInputClientObserver::GetFocusedPepperPlugin() |
76 const { | 84 const { |
77 blink::WebLocalFrame* focusedFrame = GetFocusedFrame(); | 85 blink::WebLocalFrame* focusedFrame = GetFocusedFrame(); |
78 return focusedFrame | 86 return focusedFrame |
79 ? RenderFrameImpl::FromWebFrame(focusedFrame) | 87 ? RenderFrameImpl::FromWebFrame(focusedFrame) |
80 ->focused_pepper_plugin() | 88 ->focused_pepper_plugin() |
81 : nullptr; | 89 : nullptr; |
82 } | 90 } |
83 #endif | 91 #endif |
84 | 92 |
85 void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { | 93 void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { |
86 #if defined(OS_MACOSX) | 94 #if defined(OS_MACOSX) |
87 blink::WebPoint baselinePoint; | 95 blink::WebPoint baselinePoint; |
88 NSAttributedString* string = blink::WebSubstringUtil::attributedWordAtPoint( | 96 NSAttributedString* string = nil; |
89 GetWebFrameWidget(), point, baselinePoint); | 97 |
98 if (auto* frame_widget = GetWebFrameWidget()) | |
99 blink::WebSubstringUtil::attributedWordAtPoint(frame_widget, point, | |
100 baselinePoint); | |
90 | 101 |
91 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 102 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
92 mac::AttributedStringCoder::Encode(string)); | 103 mac::AttributedStringCoder::Encode(string)); |
Avi (use Gerrit)
2016/11/23 21:17:36
Is it safe to pass nil to mac::AttributedStringCod
EhsanK
2016/11/23 21:31:32
I believe so. We already do this further below OnS
| |
93 Send(new TextInputClientReplyMsg_GotStringAtPoint( | 104 Send(new TextInputClientReplyMsg_GotStringAtPoint( |
94 render_widget_->routing_id(), *encoded.get(), baselinePoint)); | 105 render_widget_->routing_id(), *encoded.get(), baselinePoint)); |
95 #else | 106 #else |
96 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
97 #endif | 108 #endif |
98 } | 109 } |
99 | 110 |
100 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { | 111 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
101 blink::WebPoint web_point(point); | 112 blink::WebPoint web_point(point); |
102 uint32_t index = static_cast<uint32_t>( | 113 uint32_t index = 0U; |
103 GetFocusedFrame()->characterIndexForPoint(web_point)); | 114 if (auto* frame = GetFocusedFrame()) |
115 index = static_cast<uint32_t>(frame->characterIndexForPoint(web_point)); | |
116 | |
104 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint( | 117 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint( |
105 render_widget_->routing_id(), index)); | 118 render_widget_->routing_id(), index)); |
106 } | 119 } |
107 | 120 |
108 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { | 121 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { |
109 gfx::Rect rect; | 122 gfx::Rect rect; |
110 #if BUILDFLAG(ENABLE_PLUGINS) | 123 #if BUILDFLAG(ENABLE_PLUGINS) |
111 PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); | 124 PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); |
112 if (focused_plugin) { | 125 if (focused_plugin) { |
113 rect = focused_plugin->GetCaretBounds(); | 126 rect = focused_plugin->GetCaretBounds(); |
(...skipping 28 matching lines...) Expand all Loading... | |
142 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 155 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
143 mac::AttributedStringCoder::Encode(string)); | 156 mac::AttributedStringCoder::Encode(string)); |
144 Send(new TextInputClientReplyMsg_GotStringForRange( | 157 Send(new TextInputClientReplyMsg_GotStringForRange( |
145 render_widget_->routing_id(), *encoded.get(), baselinePoint)); | 158 render_widget_->routing_id(), *encoded.get(), baselinePoint)); |
146 #else | 159 #else |
147 NOTIMPLEMENTED(); | 160 NOTIMPLEMENTED(); |
148 #endif | 161 #endif |
149 } | 162 } |
150 | 163 |
151 } // namespace content | 164 } // namespace content |
OLD | NEW |