2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "WebContextMenu.h"
24 #include "InjectedBundleUserMessageCoders.h"
25 #include "WebCoreArgumentCoders.h"
27 #include "WebPageProxyMessages.h"
28 #include "WebProcess.h"
29 #include <WebCore/ContextMenu.h>
30 #include <WebCore/ContextMenuController.h>
31 #include <WebCore/FrameView.h>
32 #include <WebCore/Page.h>
34 using namespace WebCore;
38 WebContextMenu::WebContextMenu(WebPage* page)
43 WebContextMenu::~WebContextMenu()
47 void WebContextMenu::show()
49 ContextMenu* menu = m_page->corePage()->contextMenuController()->contextMenu();
52 Node* node = menu->hitTestResult().innerNonSharedNode();
55 Frame* frame = node->document()->frame();
58 FrameView* view = frame->view();
62 // Give the bundle client a chance to process the menu.
63 Vector<ContextMenuItem> coreItems = contextMenuItemVector(menu->platformDescription());
64 Vector<WebContextMenuItemData> proposedMenu = kitItems(coreItems, menu);
65 Vector<WebContextMenuItemData> newMenu;
66 RefPtr<APIObject> userData;
67 if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, 0, proposedMenu, newMenu, userData))
68 proposedMenu = newMenu;
70 // Notify the UIProcess.
71 m_page->send(Messages::WebPageProxy::ShowContextMenu(view->contentsToWindow(menu->hitTestResult().point()), proposedMenu, InjectedBundleUserMessageEncoder(userData.get())));
74 void WebContextMenu::itemSelected(const WebContextMenuItemData& item)
76 ContextMenuItem coreItem(ActionType, static_cast<ContextMenuAction>(item.action()), item.title());
77 m_page->corePage()->contextMenuController()->contextMenuItemSelected(&coreItem);