Changeset 18678 in webkit


Ignore:
Timestamp:
Jan 8, 2007 1:32:01 PM (17 years ago)
Author:
bdakin
Message:

Reviewed by Adam.

Fix for http://bugs.webkit.org/show_bug.cgi?id=12161 REGRESSION:
Crash when control-clicking on an image for contextual menu

  • WebView/WebHTMLView.m: (-[WebHTMLView menuForEvent:]): We need to nil-check coreMenu since it will be nil if the DOM popped up a menu instead. I cleaned up the function to make all the nil checks early returns instead of nesting all of the content. Also moved the autorelease to be with the creation of the menu instead of at the return.
Location:
trunk/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/ChangeLog

    r18666 r18678  
     12007-01-08  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Adam.
     4
     5        Fix for http://bugs.webkit.org/show_bug.cgi?id=12161 REGRESSION:
     6        Crash when control-clicking on an image for contextual menu
     7
     8        * WebView/WebHTMLView.m:
     9        (-[WebHTMLView menuForEvent:]): We need to nil-check coreMenu since
     10        it will be nil if the DOM popped up a menu instead. I cleaned up
     11        the function to make all the nil checks early returns instead of
     12        nesting all of the content. Also moved the autorelease to be with
     13        the creation of the menu instead of at the return.
     14
    1152007-01-08  Sam Weinig  <sam@webkit.org>
    216
  • trunk/WebKit/WebView/WebHTMLView.m

    r18614 r18678  
    25452545    _private->handlingMouseDownEvent = YES;
    25462546    BOOL handledEvent = NO;
    2547     Frame* coreframe = core([self _frame]);
    2548     if (coreframe)
    2549         handledEvent = coreframe->eventHandler()->sendContextMenuEvent(event);
     2547    Frame* coreFrame = core([self _frame]);
     2548
     2549    if (!coreFrame) {
     2550        _private->handlingMouseDownEvent = NO;
     2551        return nil;
     2552    }
     2553
     2554    handledEvent = coreFrame->eventHandler()->sendContextMenuEvent(event);
    25502555    _private->handlingMouseDownEvent = NO;
    2551    
    2552     if (handledEvent && coreframe) {
    2553         if (Page* page = coreframe->page()) {
    2554             ContextMenu* coreMenu = page->contextMenuController()->contextMenu();
    2555             NSArray* menuItems = coreMenu->platformDescription();
    2556             NSMenu* menu = nil;
    2557             if (menuItems && [menuItems count] > 0) {
    2558                 menu = [[NSMenu alloc] init];
    2559                 [menu setAutoenablesItems:NO];
    2560                 for (unsigned i = 0; i < [menuItems count]; i++)
    2561                     [menu addItem:[menuItems objectAtIndex:i]];
    2562             }
    2563 
    2564             // Add the Inspect Element menu item if the preference is set or if this is a debug build
    2565             if ([WebView _developerExtrasEnabled]) {
    2566                 if (!menu)
    2567                     menu = [[NSMenu alloc] init];
    2568                 else if ([menu numberOfItems])
    2569                     [menu addItem:[NSMenuItem separatorItem]];
    2570                 NSMenuItem *menuItem = [[[NSMenuItem alloc] init] autorelease];
    2571                 [menuItem setAction:@selector(_inspectElement:)];
    2572                 [menuItem setTitle:UI_STRING("Inspect Element", "Inspect Element context menu item")];
    2573                 [menuItem setRepresentedObject:[[[WebElementDictionary alloc] initWithHitTestResult:
    2574                     coreMenu->hitTestResult()] autorelease]];
    2575                 [menu addItem:menuItem];
    2576             }
    2577 
    2578             return [menu autorelease];
    2579         }
    2580     }
    2581 
    2582     return nil;
     2556
     2557    if (!handledEvent)
     2558        return nil;
     2559
     2560    Page* page = coreFrame->page();
     2561    if (!page)
     2562        return nil;
     2563
     2564    ContextMenu* coreMenu = page->contextMenuController()->contextMenu();
     2565    if (!coreMenu)
     2566        return nil;
     2567
     2568    NSArray* menuItems = coreMenu->platformDescription();
     2569    NSMenu* menu = nil;
     2570    if (menuItems && [menuItems count] > 0) {
     2571        menu = [[[NSMenu alloc] init] autorelease];
     2572        [menu setAutoenablesItems:NO];
     2573        for (unsigned i = 0; i < [menuItems count]; i++)
     2574            [menu addItem:[menuItems objectAtIndex:i]];
     2575    }
     2576
     2577    // Add the Inspect Element menu item if the preference is set or if this is a debug build
     2578    if ([WebView _developerExtrasEnabled]) {
     2579        if (!menu)
     2580            menu = [[[NSMenu alloc] init] autorelease];
     2581        else if ([menu numberOfItems])
     2582            [menu addItem:[NSMenuItem separatorItem]];
     2583        NSMenuItem *inspectorItem = [[NSMenuItem alloc] init];
     2584        [inspectorItem setAction:@selector(_inspectElement:)];
     2585        [inspectorItem setTitle:UI_STRING("Inspect Element", "Inspect Element context menu item")];
     2586        [inspectorItem setRepresentedObject:[[[WebElementDictionary alloc] initWithHitTestResult:
     2587            coreMenu->hitTestResult()] autorelease]];
     2588        [menu addItem:inspectorItem];
     2589        [inspectorItem release];
     2590    }
     2591
     2592    return menu;
    25832593}
    25842594
Note: See TracChangeset for help on using the changeset viewer.