Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: content/renderer/text_input_client_observer.cc

Issue 2526563004: Fix renderer crashes due to non-existing RenderFrameImpl or WebFrameWidget during Navigations (Closed)
Patch Set: Fixed a Bug (and failing tests) Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 string = blink::WebSubstringUtil::attributedWordAtPoint(frame_widget, point,
100 baselinePoint);
101 }
90 102
91 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( 103 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded(
92 mac::AttributedStringCoder::Encode(string)); 104 mac::AttributedStringCoder::Encode(string));
93 Send(new TextInputClientReplyMsg_GotStringAtPoint( 105 Send(new TextInputClientReplyMsg_GotStringAtPoint(
94 render_widget_->routing_id(), *encoded.get(), baselinePoint)); 106 render_widget_->routing_id(), *encoded.get(), baselinePoint));
95 #else 107 #else
96 NOTIMPLEMENTED(); 108 NOTIMPLEMENTED();
97 #endif 109 #endif
98 } 110 }
99 111
100 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { 112 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) {
101 blink::WebPoint web_point(point); 113 blink::WebPoint web_point(point);
102 uint32_t index = static_cast<uint32_t>( 114 uint32_t index = 0U;
103 GetFocusedFrame()->characterIndexForPoint(web_point)); 115 if (auto* frame = GetFocusedFrame())
116 index = static_cast<uint32_t>(frame->characterIndexForPoint(web_point));
117
104 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint( 118 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(
105 render_widget_->routing_id(), index)); 119 render_widget_->routing_id(), index));
106 } 120 }
107 121
108 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { 122 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) {
109 gfx::Rect rect; 123 gfx::Rect rect;
110 #if BUILDFLAG(ENABLE_PLUGINS) 124 #if BUILDFLAG(ENABLE_PLUGINS)
111 PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); 125 PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin();
112 if (focused_plugin) { 126 if (focused_plugin) {
113 rect = focused_plugin->GetCaretBounds(); 127 rect = focused_plugin->GetCaretBounds();
(...skipping 28 matching lines...) Expand all
142 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( 156 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded(
143 mac::AttributedStringCoder::Encode(string)); 157 mac::AttributedStringCoder::Encode(string));
144 Send(new TextInputClientReplyMsg_GotStringForRange( 158 Send(new TextInputClientReplyMsg_GotStringForRange(
145 render_widget_->routing_id(), *encoded.get(), baselinePoint)); 159 render_widget_->routing_id(), *encoded.get(), baselinePoint));
146 #else 160 #else
147 NOTIMPLEMENTED(); 161 NOTIMPLEMENTED();
148 #endif 162 #endif
149 } 163 }
150 164
151 } // namespace content 165 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698