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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_mac.mm

Issue 548191: Merge 37438 - Fix Mac crash when page goes away while a popup menu is active.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/307/src/
Patch Set: Created 10 years, 11 months 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #import "base/scoped_nsobject.h" 8 #import "base/scoped_nsobject.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 387 }
388 388
389 // Display a popup menu for WebKit using Cocoa widgets. 389 // Display a popup menu for WebKit using Cocoa widgets.
390 void RenderWidgetHostViewMac::ShowPopupWithItems( 390 void RenderWidgetHostViewMac::ShowPopupWithItems(
391 gfx::Rect bounds, 391 gfx::Rect bounds,
392 int item_height, 392 int item_height,
393 int selected_item, 393 int selected_item,
394 const std::vector<WebMenuItem>& items) { 394 const std::vector<WebMenuItem>& items) {
395 is_popup_menu_ = true; 395 is_popup_menu_ = true;
396 396
397 // Retain the Cocoa view for the duration of the pop-up so that it can't
398 // be dealloced if my Destroy() method is called while the pop-up's up
399 // (which would in turn delete me, causing a crash once the -runMenuInView
400 // call returns. That's what was happening in <http://crbug.com/33250>).
401 scoped_nsobject<RenderWidgetHostViewCocoa> retainedCocoaView
402 ([cocoa_view_ retain]);
403
397 NSRect view_rect = [cocoa_view_ bounds]; 404 NSRect view_rect = [cocoa_view_ bounds];
398 NSRect parent_rect = [parent_view_ bounds]; 405 NSRect parent_rect = [parent_view_ bounds];
399 int y_offset = bounds.y() + bounds.height(); 406 int y_offset = bounds.y() + bounds.height();
400 NSRect position = NSMakeRect(bounds.x(), parent_rect.size.height - y_offset, 407 NSRect position = NSMakeRect(bounds.x(), parent_rect.size.height - y_offset,
401 bounds.width(), bounds.height()); 408 bounds.width(), bounds.height());
402 409
403 // Display the menu. 410 // Display the menu.
404 scoped_nsobject<WebMenuRunner> menu_runner; 411 scoped_nsobject<WebMenuRunner> menu_runner;
405 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items]); 412 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items]);
406 413
407 { 414 {
408 // Make sure events can be pumped while the menu is up. 415 // Make sure events can be pumped while the menu is up.
409 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 416 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
417 // Now run a SYNCHRONOUS NESTED EVENT LOOP until the pop-up is finished.
410 [menu_runner runMenuInView:parent_view_ 418 [menu_runner runMenuInView:parent_view_
411 withBounds:position 419 withBounds:position
412 initialIndex:selected_item]; 420 initialIndex:selected_item];
413 } 421 }
414 422
423 if (!render_widget_host_) {
424 // Bad news -- my Destroy() was called while I was off running the menu.
425 // Return ASAP, and the release of retainedCocoaView will dealloc my NSView,
426 // which will delete me (whew).
427 return;
428 }
429
415 int window_num = [[parent_view_ window] windowNumber]; 430 int window_num = [[parent_view_ window] windowNumber];
416 NSEvent* event = 431 NSEvent* event =
417 webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen], 432 webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen],
418 window_num, item_height, 433 window_num, item_height,
419 [menu_runner indexOfSelectedItem], 434 [menu_runner indexOfSelectedItem],
420 position, view_rect); 435 position, view_rect);
421 436
422 // CHECK()s inserted to diagnose the crash in http://crbug.com/31716
423 // TODO(pamg): Remove when no longer needed.
424 CHECK(render_widget_host_);
425 if ([menu_runner menuItemWasChosen]) { 437 if ([menu_runner menuItemWasChosen]) {
426 // Simulate a menu selection event. 438 // Simulate a menu selection event.
427 CHECK(cocoa_view_); 439 CHECK(cocoa_view_);
428 const WebMouseEvent& mouse_event = 440 const WebMouseEvent& mouse_event =
429 WebInputEventFactory::mouseEvent(event, cocoa_view_); 441 WebInputEventFactory::mouseEvent(event, cocoa_view_);
430 render_widget_host_->ForwardMouseEvent(mouse_event); 442 render_widget_host_->ForwardMouseEvent(mouse_event);
431 } else { 443 } else {
432 // Simulate a menu dismiss event. 444 // Simulate a menu dismiss event.
433 NativeWebKeyboardEvent keyboard_event(event); 445 NativeWebKeyboardEvent keyboard_event(event);
434 render_widget_host_->ForwardKeyboardEvent(keyboard_event); 446 render_widget_host_->ForwardKeyboardEvent(keyboard_event);
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 event.skip_in_browser = true; 1409 event.skip_in_browser = true;
1398 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); 1410 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event);
1399 } else { 1411 } else {
1400 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 1412 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition(
1401 UTF8ToUTF16([im_text UTF8String])); 1413 UTF8ToUTF16([im_text UTF8String]));
1402 } 1414 }
1403 renderWidgetHostView_->im_composing_ = false; 1415 renderWidgetHostView_->im_composing_ = false;
1404 } 1416 }
1405 1417
1406 @end 1418 @end
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