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

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

Issue 8772006: Fix a possible renderer hang due to an WebAccessibilityObject becoming invalid. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address comments. Created 9 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 | Annotate | Revision Log
« 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "content/common/view_messages.h" 6 #include "content/common/view_messages.h"
7 #include "content/public/common/content_switches.h" 7 #include "content/public/common/content_switches.h"
8 #include "content/renderer/render_view_impl.h" 8 #include "content/renderer/render_view_impl.h"
9 #include "content/renderer/renderer_accessibility.h" 9 #include "content/renderer/renderer_accessibility.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 // Send all pending accessibility notifications. 207 // Send all pending accessibility notifications.
208 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications; 208 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
209 for (size_t i = 0; i < pending_notifications_.size(); ++i) { 209 for (size_t i = 0; i < pending_notifications_.size(); ++i) {
210 Notification& notification = pending_notifications_[i]; 210 Notification& notification = pending_notifications_[i];
211 211
212 bool includes_children = ShouldIncludeChildren(notification); 212 bool includes_children = ShouldIncludeChildren(notification);
213 WebAccessibilityObject obj = document.accessibilityObjectFromID( 213 WebAccessibilityObject obj = document.accessibilityObjectFromID(
214 notification.id); 214 notification.id);
215 215
216 if (!obj.isValid()) {
217 #ifndef NDEBUG
218 if (logging_)
219 LOG(WARNING) << "Got notification on invalid object id " << obj.axID();
220 #endif
221 continue;
222 }
223
224 // The browser may not have this object yet, for example if we get a 216 // The browser may not have this object yet, for example if we get a
225 // notification on an object that was recently added, or if we get a 217 // notification on an object that was recently added, or if we get a
226 // notification on a node before the page has loaded. Work our way 218 // notification on a node before the page has loaded. Work our way
227 // up the parent chain until we find a node the browser has, or until 219 // up the parent chain until we find a node the browser has, or until
228 // we reach the root. 220 // we reach the root.
229 int root_id = document.accessibilityObject().axID(); 221 int root_id = document.accessibilityObject().axID();
230 while (browser_id_map_.find(obj.axID()) == browser_id_map_.end() && 222 while (browser_id_map_.find(obj.axID()) == browser_id_map_.end() &&
223 obj.isValid() &&
231 obj.axID() != root_id) { 224 obj.axID() != root_id) {
232 obj = obj.parentObject(); 225 obj = obj.parentObject();
233 includes_children = true; 226 includes_children = true;
234 if (notification.type == 227 if (notification.type ==
235 WebKit::WebAccessibilityNotificationChildrenChanged) { 228 WebKit::WebAccessibilityNotificationChildrenChanged) {
236 notification.id = obj.axID(); 229 notification.id = obj.axID();
237 } 230 }
238 } 231 }
239 232
233 if (!obj.isValid()) {
234 #ifndef NDEBUG
235 if (logging_)
236 LOG(WARNING) << "Got notification on object that is invalid or has"
237 << " invalid ancestor. Id: " << obj.axID();
238 #endif
239 continue;
240 }
241
240 // Another potential problem is that this notification may be on an 242 // Another potential problem is that this notification may be on an
241 // object that is detached from the tree. Determine if this node is not a 243 // object that is detached from the tree. Determine if this node is not a
242 // child of its parent, and if so move the notification to the parent. 244 // child of its parent, and if so move the notification to the parent.
243 // TODO(dmazzoni): see if this can be removed after 245 // TODO(dmazzoni): see if this can be removed after
244 // https://bugs.webkit.org/show_bug.cgi?id=68466 is fixed. 246 // https://bugs.webkit.org/show_bug.cgi?id=68466 is fixed.
245 if (obj.axID() != root_id) { 247 if (obj.axID() != root_id) {
246 WebAccessibilityObject parent = obj.parentObject(); 248 WebAccessibilityObject parent = obj.parentObject();
247 while (!parent.isNull() && parent.accessibilityIsIgnored()) 249 while (!parent.isNull() &&
250 parent.isValid() &&
251 parent.accessibilityIsIgnored()) {
248 parent = parent.parentObject(); 252 parent = parent.parentObject();
249 if (parent.isNull()) { 253 }
254
255 if (parent.isNull() || !parent.isValid()) {
250 NOTREACHED(); 256 NOTREACHED();
257 continue;
251 } 258 }
252 bool is_child_of_parent = false; 259 bool is_child_of_parent = false;
253 for (unsigned int i = 0; i < parent.childCount(); ++i) { 260 for (unsigned int i = 0; i < parent.childCount(); ++i) {
254 if (parent.childAt(i).equals(obj)) { 261 if (parent.childAt(i).equals(obj)) {
255 is_child_of_parent = true; 262 is_child_of_parent = true;
256 break; 263 break;
257 } 264 }
258 } 265 }
259 if (!is_child_of_parent) { 266 if (!is_child_of_parent) {
260 obj = parent; 267 obj = parent;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 432
426 WebDocument RendererAccessibility::GetMainDocument() { 433 WebDocument RendererAccessibility::GetMainDocument() {
427 WebView* view = render_view()->GetWebView(); 434 WebView* view = render_view()->GetWebView();
428 WebFrame* main_frame = view ? view->mainFrame() : NULL; 435 WebFrame* main_frame = view ? view->mainFrame() : NULL;
429 436
430 if (main_frame) 437 if (main_frame)
431 return main_frame->document(); 438 return main_frame->document();
432 else 439 else
433 return WebDocument(); 440 return WebDocument();
434 } 441 }
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