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

Side by Side Diff: content/browser/renderer_host/text_input_client_mac.mm

Issue 2422973003: Fix TextInputClientMac related crashes of Fullscreen RenderWidget (Closed)
Patch Set: Rebased Created 4 years, 1 month 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
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 #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 (https://crbug.com/663384).
25 bool SendMessageToRenderWidget(RenderWidgetHostImpl* widget,
26 IPC::Message* message) {
27 if (!widget->delegate() ||
28 widget == widget->delegate()->GetFullscreenRenderWidgetHost()) {
29 delete message;
30 return false;
31 }
32
33 DCHECK_EQ(widget->GetRoutingID(), message->routing_id());
34 return widget->Send(message);
35 }
36 }
37
16 // The amount of time in milliseconds that the browser process will wait for a 38 // The amount of time in milliseconds that the browser process will wait for a
17 // response from the renderer. 39 // response from the renderer.
18 // TODO(rsesek): Using the histogram data, find the best upper-bound for this 40 // TODO(rsesek): Using the histogram data, find the best upper-bound for this
19 // value. 41 // value.
20 const float kWaitTimeout = 1500; 42 const float kWaitTimeout = 1500;
21 43
22 TextInputClientMac::TextInputClientMac() 44 TextInputClientMac::TextInputClientMac()
23 : character_index_(NSNotFound), 45 : character_index_(NSNotFound),
24 lock_(), 46 lock_(),
25 condition_(&lock_) { 47 condition_(&lock_) {
(...skipping 11 matching lines...) Expand all
37 RenderWidgetHost* rwh, 59 RenderWidgetHost* rwh,
38 gfx::Point point, 60 gfx::Point point,
39 void (^reply_handler)(NSAttributedString*, NSPoint)) { 61 void (^reply_handler)(NSAttributedString*, NSPoint)) {
40 // TODO(ekaramad): In principle, we are using the same handler regardless of 62 // 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 63 // 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 64 // |rwh| individually so that one slow RWH will not end up clearing the
43 // callback for another (https://crbug.com/643233). 65 // callback for another (https://crbug.com/643233).
44 DCHECK(replyForPointHandler_.get() == nil); 66 DCHECK(replyForPointHandler_.get() == nil);
45 replyForPointHandler_.reset(reply_handler, base::scoped_policy::RETAIN); 67 replyForPointHandler_.reset(reply_handler, base::scoped_policy::RETAIN);
46 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 68 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
47 rwhi->Send(new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), point)); 69 SendMessageToRenderWidget(
70 rwhi, new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), point));
48 } 71 }
49 72
50 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string, 73 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string,
51 NSPoint point) { 74 NSPoint point) {
52 if (replyForPointHandler_.get()) { 75 if (replyForPointHandler_.get()) {
53 replyForPointHandler_.get()(string, point); 76 replyForPointHandler_.get()(string, point);
54 replyForPointHandler_.reset(); 77 replyForPointHandler_.reset();
55 } 78 }
56 } 79 }
57 80
58 void TextInputClientMac::GetStringFromRange( 81 void TextInputClientMac::GetStringFromRange(
59 RenderWidgetHost* rwh, 82 RenderWidgetHost* rwh,
60 NSRange range, 83 NSRange range,
61 void (^reply_handler)(NSAttributedString*, NSPoint)) { 84 void (^reply_handler)(NSAttributedString*, NSPoint)) {
62 DCHECK(replyForRangeHandler_.get() == nil); 85 DCHECK(replyForRangeHandler_.get() == nil);
63 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN); 86 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN);
64 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 87 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
65 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), 88 SendMessageToRenderWidget(rwhi, new TextInputClientMsg_StringForRange(
66 gfx::Range(range))); 89 rwhi->GetRoutingID(), gfx::Range(range)));
67 } 90 }
68 91
69 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string, 92 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string,
70 NSPoint point) { 93 NSPoint point) {
71 if (replyForRangeHandler_.get()) { 94 if (replyForRangeHandler_.get()) {
72 replyForRangeHandler_.get()(string, point); 95 replyForRangeHandler_.get()(string, point);
73 replyForRangeHandler_.reset(); 96 replyForRangeHandler_.reset();
74 } 97 }
75 } 98 }
76 99
77 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, 100 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh,
78 gfx::Point point) { 101 gfx::Point point) {
79 base::TimeTicks start = base::TimeTicks::Now(); 102 base::TimeTicks start = base::TimeTicks::Now();
80 103
81 BeforeRequest(); 104 BeforeRequest();
82 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 105 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
83 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), 106 if (!SendMessageToRenderWidget(rwhi,
84 point)); 107 new TextInputClientMsg_CharacterIndexForPoint(
108 rwhi->GetRoutingID(), point)))
109 return NSNotFound;
110
85 // http://crbug.com/121917 111 // http://crbug.com/121917
86 base::ThreadRestrictions::ScopedAllowWait allow_wait; 112 base::ThreadRestrictions::ScopedAllowWait allow_wait;
87 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); 113 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
88 AfterRequest(); 114 AfterRequest();
89 115
90 base::TimeDelta delta(base::TimeTicks::Now() - start); 116 base::TimeDelta delta(base::TimeTicks::Now() - start);
91 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.CharacterIndex", 117 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.CharacterIndex",
92 delta * base::Time::kMicrosecondsPerMillisecond); 118 delta * base::Time::kMicrosecondsPerMillisecond);
93 119
94 return character_index_; 120 return character_index_;
95 } 121 }
96 122
97 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, 123 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh,
98 NSRange range) { 124 NSRange range) {
99 base::TimeTicks start = base::TimeTicks::Now(); 125 base::TimeTicks start = base::TimeTicks::Now();
100 126
101 BeforeRequest(); 127 BeforeRequest();
102 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 128 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
103 rwhi->Send( 129 if (!SendMessageToRenderWidget(
104 new TextInputClientMsg_FirstRectForCharacterRange(rwhi->GetRoutingID(), 130 rwhi, new TextInputClientMsg_FirstRectForCharacterRange(
105 gfx::Range(range))); 131 rwhi->GetRoutingID(), gfx::Range(range))))
132 return NSRect();
133
106 // http://crbug.com/121917 134 // http://crbug.com/121917
107 base::ThreadRestrictions::ScopedAllowWait allow_wait; 135 base::ThreadRestrictions::ScopedAllowWait allow_wait;
108 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); 136 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
109 AfterRequest(); 137 AfterRequest();
110 138
111 base::TimeDelta delta(base::TimeTicks::Now() - start); 139 base::TimeDelta delta(base::TimeTicks::Now() - start);
112 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect", 140 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect",
113 delta * base::Time::kMicrosecondsPerMillisecond); 141 delta * base::Time::kMicrosecondsPerMillisecond);
114 142
115 return first_rect_; 143 return first_rect_;
(...skipping 24 matching lines...) Expand all
140 168
141 character_index_ = NSNotFound; 169 character_index_ = NSNotFound;
142 first_rect_ = NSZeroRect; 170 first_rect_ = NSZeroRect;
143 } 171 }
144 172
145 void TextInputClientMac::AfterRequest() { 173 void TextInputClientMac::AfterRequest() {
146 lock_.Release(); 174 lock_.Release();
147 } 175 }
148 176
149 } // namespace content 177 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_delegate.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698