Changeset 24381 in webkit


Ignore:
Timestamp:
Jul 17, 2007 2:17:25 PM (17 years ago)
Author:
aroben
Message:

Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item

WebCore:

Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item
http://bugs.webkit.org/show_bug.cgi?id=14324

Reviewed by Tim.

No regression test possible.

  • page/ContextMenuController.cpp: (WebCore::ContextMenuController::handleContextMenuEvent): Add the Inspect Element item to the menu before passing it to the ContextMenuClient so that the UI delegate has a chance to modify/remove the item.

WebKit:

Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item
http://bugs.webkit.org/show_bug.cgi?id=14324

Only clients linking against new versions of WebKit will see the item.
I've maintained our behavior for old clients of not including the
Inspect Element item in the menu items passed to the UI delegate.

Reviewed by Tim.

  • Misc/WebKitVersionChecks.h: Added a new constant.
  • WebCoreSupport/WebContextMenuClient.mm: (isPreInspectElementTagClient): Added. (fixMenusToSendToOldClients): Return an array of items that should be appended to the menu received from the delegate. (fixMenusReceivedFromOldClients): Append the saved items to the array. (WebContextMenuClient::getCustomMenuFromDefaultItems): Retain/release the saved items.

WebKit/win:

Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item
http://bugs.webkit.org/show_bug.cgi?id=14324

If we detect that we're running against the Safari 3 Beta, we add back
the Inspect Element menu item after passing it off to the delegate
because Safari's UI delegate will remove it.

Reviewed by Tim.

  • WebContextMenuClient.cpp: (isPreInspectElementTagSafari): Added. (fixMenuReceivedFromOldSafari): Added. (WebContextMenuClient::getCustomMenuFromDefaultItems): Call fixMenuReceivedFromOldSafari before returning the new menu.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r24380 r24381  
     12007-07-17  Adam Roben  <aroben@apple.com>
     2
     3        Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item
     4        http://bugs.webkit.org/show_bug.cgi?id=14324
     5
     6        Reviewed by Tim.
     7
     8        No regression test possible.
     9
     10        * page/ContextMenuController.cpp:
     11        (WebCore::ContextMenuController::handleContextMenuEvent): Add the
     12        Inspect Element item to the menu before passing it to the
     13        ContextMenuClient so that the UI delegate has a chance to
     14        modify/remove the item.
     15
    1162007-07-17  Adam Roben  <aroben@apple.com>
    217
  • trunk/WebCore/page/ContextMenuController.cpp

    r24380 r24381  
    9696    m_contextMenu.set(new ContextMenu(result));
    9797    m_contextMenu->populate();
     98    if (m_page->settings()->developerExtrasEnabled())
     99        m_contextMenu->addInspectElementItem();
     100
    98101    PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
    99102    m_contextMenu->setPlatformDescription(customMenu);
    100103
    101     if (m_page->settings()->developerExtrasEnabled())
    102         m_contextMenu->addInspectElementItem();
    103104    event->setDefaultHandled();
    104105}
  • trunk/WebKit/ChangeLog

    r24380 r24381  
     12007-07-17  Adam Roben  <aroben@apple.com>
     2
     3        Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item
     4        http://bugs.webkit.org/show_bug.cgi?id=14324
     5
     6        Only clients linking against new versions of WebKit will see the item.
     7        I've maintained our behavior for old clients of not including the
     8        Inspect Element item in the menu items passed to the UI delegate.
     9
     10        Reviewed by Tim.
     11
     12        * Misc/WebKitVersionChecks.h: Added a new constant.
     13        * WebCoreSupport/WebContextMenuClient.mm:
     14        (isPreInspectElementTagClient): Added.
     15        (fixMenusToSendToOldClients): Return an array of items that should be
     16        appended to the menu received from the delegate.
     17        (fixMenusReceivedFromOldClients): Append the saved items to the array.
     18        (WebContextMenuClient::getCustomMenuFromDefaultItems): Retain/release
     19        the saved items.
     20
    1212007-07-17  Adam Roben  <aroben@apple.com>
    222
  • trunk/WebKit/Misc/WebKitVersionChecks.h

    r24183 r24381  
    3939#define WEBKIT_FIRST_VERSION_WITH_MAIN_THREAD_EXCEPTIONS 0x020A0000 // 522.0.0
    4040#define WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK 0x020A0000 // 522.0.0
     41#define WEBKIT_FIRST_VERSION_WITH_INSPECT_ELEMENT_MENU_TAG 0x020A0C00 // 522.12.0
    4142
    4243#ifdef __cplusplus
  • trunk/WebKit/WebCoreSupport/WebContextMenuClient.mm

    r24380 r24381  
    7272}
    7373
    74 static void fixMenusToSendToOldClients(NSMutableArray *defaultMenuItems)
    75 {
     74static BOOL isPreInspectElementTagClient(void)
     75{
     76    static BOOL preInspectElementTagClient = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_INSPECT_ELEMENT_MENU_TAG);
     77    return preInspectElementTagClient;
     78}
     79
     80static NSMutableArray *fixMenusToSendToOldClients(NSMutableArray *defaultMenuItems)
     81{
     82    NSMutableArray *savedItems = nil;
     83
     84    unsigned defaultItemsCount = [defaultMenuItems count];
     85
     86    if (isPreInspectElementTagClient()) {
     87        NSMenuItem *secondToLastItem = [defaultMenuItems objectAtIndex:defaultItemsCount - 2];
     88        NSMenuItem *lastItem = [defaultMenuItems objectAtIndex:defaultItemsCount - 1];
     89
     90        if ([secondToLastItem isSeparatorItem] && [lastItem tag] == WebMenuItemTagInspectElement) {
     91            savedItems = [NSMutableArray arrayWithCapacity:2];
     92            [savedItems addObject:secondToLastItem];
     93            [savedItems addObject:lastItem];
     94
     95            [defaultMenuItems removeObject:secondToLastItem];
     96            [defaultMenuItems removeObject:lastItem];
     97        }
     98    }
     99
    76100    BOOL preVersion3Client = isPreVersion3Client();
    77101    if (!preVersion3Client)
    78         return;
     102        return savedItems;
    79103       
    80104    BOOL isMail = isAppleMail();
    81     unsigned defaultItemsCount = [defaultMenuItems count];
    82105    for (unsigned i = 0; i < defaultItemsCount; ++i) {
    83106        NSMenuItem *item = [defaultMenuItems objectAtIndex:i];
     
    124147            [item setTag:oldStyleTag];
    125148    }
    126 }
    127 
    128 static void fixMenusReceivedFromOldClients(NSMutableArray *newMenuItems)
     149
     150    return savedItems;
     151}
     152
     153static void fixMenusReceivedFromOldClients(NSMutableArray *newMenuItems, NSMutableArray *savedItems)
    129154{   
     155    if (savedItems)
     156        [newMenuItems addObjectsFromArray:savedItems];
     157
    130158    BOOL preVersion3Client = isPreVersion3Client();
    131159    if (!preVersion3Client)
     
    241269        [[defaultMenuItems objectAtIndex:i] setRepresentedObject:element];
    242270           
    243     fixMenusToSendToOldClients(defaultMenuItems);
     271    NSMutableArray *savedItems = [fixMenusToSendToOldClients(defaultMenuItems) retain];
    244272    NSMutableArray *newMenuItems = [[[delegate webView:m_webView contextMenuItemsForElement:element defaultMenuItems:defaultMenuItems] mutableCopy] autorelease];
    245     fixMenusReceivedFromOldClients(newMenuItems);
     273    fixMenusReceivedFromOldClients(newMenuItems, savedItems);
     274    [savedItems release];
    246275    return newMenuItems;
    247276}
  • trunk/WebKit/win/ChangeLog

    r24380 r24381  
     12007-07-17  Adam Roben  <aroben@apple.com>
     2
     3        Fix Bug 14324: Cannot remove/customize the "Inspect Element" contextual menu item
     4        http://bugs.webkit.org/show_bug.cgi?id=14324
     5
     6        If we detect that we're running against the Safari 3 Beta, we add back
     7        the Inspect Element menu item after passing it off to the delegate
     8        because Safari's UI delegate will remove it.
     9
     10        Reviewed by Tim.
     11
     12        * WebContextMenuClient.cpp:
     13        (isPreInspectElementTagSafari): Added.
     14        (fixMenuReceivedFromOldSafari): Added.
     15        (WebContextMenuClient::getCustomMenuFromDefaultItems): Call
     16        fixMenuReceivedFromOldSafari before returning the new menu.
     17
    1182007-07-17  Adam Roben  <aroben@apple.com>
    219
  • trunk/WebKit/win/WebContextMenuClient.cpp

    r24380 r24381  
    5555}
    5656
     57static bool isPreInspectElementTagSafari(IWebUIDelegate* uiDelegate)
     58{
     59    if (!uiDelegate)
     60        return false;
     61
     62    // We assume anyone who implements IWebUIDelegate2 also knows about the Inspect Element item.
     63    COMPtr<IWebUIDelegate2> uiDelegate2;
     64    if (SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegate2, (void**)&uiDelegate2)))
     65        return false;
     66
     67    TCHAR modulePath[MAX_PATH];
     68    DWORD length = ::GetModuleFileName(0, modulePath, _countof(modulePath));
     69    if (!length)
     70        return false;
     71
     72    return String(modulePath, length).endsWith("Safari.exe", false);
     73}
     74
     75static HMENU fixMenuReceivedFromOldSafari(IWebUIDelegate* uiDelegate, ContextMenu* originalMenu, HMENU menuFromClient)
     76{
     77    ASSERT_ARG(menu, menu);
     78    if (!isPreInspectElementTagSafari(uiDelegate))
     79        return menuFromClient;
     80
     81    int count = ::GetMenuItemCount(originalMenu->platformDescription());
     82    if (count < 1)
     83        return menuFromClient;
     84
     85    if (::GetMenuItemID(originalMenu->platformDescription(), count - 1) != WebMenuItemTagInspectElement)
     86        return menuFromClient;
     87
     88    count = ::GetMenuItemCount(menuFromClient);
     89    if (count < 1)
     90        return menuFromClient;
     91
     92    if (::GetMenuItemID(menuFromClient, count - 1) == WebMenuItemTagInspectElement)
     93        return menuFromClient;
     94
     95    originalMenu->setPlatformDescription(menuFromClient);
     96    originalMenu->addInspectElementItem();
     97    return originalMenu->platformDescription();
     98}
     99
    57100HMENU WebContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu* menu)
    58101{
     
    69112    if (FAILED(uiDelegate->contextMenuItemsForElement(m_webView, propertyBag.get(), (OLE_HANDLE)(ULONG64)menu->platformDescription(), (OLE_HANDLE*)&newMenu)))
    70113        return menu->platformDescription();
    71 
    72     return newMenu;
     114    return fixMenuReceivedFromOldSafari(uiDelegate.get(), menu, newMenu);
    73115}
    74116
Note: See TracChangeset for help on using the changeset viewer.