WebContextMenuClient.cpp [plain text]
#include "WebContextMenuClient.h"
#include "UserGestureIndicator.h"
#include "WebElementPropertyBag.h"
#include "WebLocalizableStrings.h"
#include "WebView.h"
#include <WebCore/ContextMenu.h>
#include <WebCore/ContextMenuController.h>
#include <WebCore/Editor.h>
#include <WebCore/Event.h>
#include <WebCore/FrameLoadRequest.h>
#include <WebCore/FrameLoader.h>
#include <WebCore/MainFrame.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/Page.h>
#include <WebCore/ResourceRequest.h>
using namespace WebCore;
WebContextMenuClient::WebContextMenuClient(WebView* webView)
: m_webView(webView)
{
}
void WebContextMenuClient::contextMenuDestroyed()
{
delete this;
}
std::unique_ptr<ContextMenu> WebContextMenuClient::customizeMenu(std::unique_ptr<ContextMenu> popMenu)
{
std::unique_ptr<ContextMenu> menu = WTF::move(popMenu);
COMPtr<IWebUIDelegate> uiDelegate;
if (FAILED(m_webView->uiDelegate(&uiDelegate)))
return menu;
ASSERT(uiDelegate);
HMENU nativeMenu = menu->platformContextMenu();
COMPtr<WebElementPropertyBag> propertyBag;
propertyBag.adoptRef(WebElementPropertyBag::createInstance(m_webView->page()->contextMenuController().hitTestResult()));
if (FAILED(uiDelegate->contextMenuItemsForElement(m_webView, propertyBag.get(), nativeMenu, &nativeMenu))) {
::DestroyMenu(nativeMenu);
return menu;
}
std::unique_ptr<ContextMenu> customizedMenu = std::unique_ptr<ContextMenu>(new ContextMenu(nativeMenu));
::DestroyMenu(nativeMenu);
return customizedMenu;
}
void WebContextMenuClient::contextMenuItemSelected(ContextMenuItem* item, const ContextMenu* parentMenu)
{
ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
COMPtr<IWebUIDelegate> uiDelegate;
if (FAILED(m_webView->uiDelegate(&uiDelegate)))
return;
ASSERT(uiDelegate);
COMPtr<WebElementPropertyBag> propertyBag;
propertyBag.adoptRef(WebElementPropertyBag::createInstance(m_webView->page()->contextMenuController().hitTestResult()));
ASSERT(item->type() != SubmenuType);
ASSERT(item->type() != SeparatorType);
MENUITEMINFO selectedItem = item->platformContextMenuItem();
uiDelegate->contextMenuItemSelected(m_webView, &selectedItem, propertyBag.get());
}
void WebContextMenuClient::downloadURL(const URL& url)
{
m_webView->downloadURL(url);
}
void WebContextMenuClient::searchWithGoogle(const Frame* frame)
{
String searchString = frame->editor().selectedText();
searchString.stripWhiteSpace();
String encoded = encodeWithURLEscapeSequences(searchString);
encoded.replace("%20", "+");
String url("http://www.google.com/search?q=");
url.append(encoded);
url.append("&ie=UTF-8&oe=UTF-8");
if (Page* page = frame->page()) {
UserGestureIndicator indicator(DefinitelyProcessingUserGesture);
page->mainFrame().loader().urlSelected(URL(ParsedURLString, url), String(), 0, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
}
}
void WebContextMenuClient::lookUpInDictionary(Frame*)
{
notImplemented();
}
void WebContextMenuClient::speak(const String&)
{
notImplemented();
}
void WebContextMenuClient::stopSpeaking()
{
notImplemented();
}
bool WebContextMenuClient::isSpeaking()
{
notImplemented();
return false;
}
ContextMenuItem WebContextMenuClient::shareMenuItem(const HitTestResult&)
{
notImplemented();
return ContextMenuItem();
}