WebContextMenuClient.cpp [plain text]
#include "WebContextMenuClient.h"
#include "WebView.h"
#include <WebCore/Editor.h>
#include <WebCore/Frame.h>
#include <WebCore/FrameLoader.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/Page.h>
#include <WebCore/UserGestureIndicator.h>
WebContextMenuClient::WebContextMenuClient(WebView* webView)
: m_webView(webView)
{
}
void WebContextMenuClient::contextMenuDestroyed()
{
delete this;
}
void WebContextMenuClient::downloadURL(const URL& url)
{
m_webView->downloadURL(url);
}
void WebContextMenuClient::searchWithGoogle(const WebCore::Frame* frame)
{
auto page = frame->page();
if (!page)
return;
auto searchString = frame->editor().selectedText();
searchString.stripWhiteSpace();
searchString = encodeWithURLEscapeSequences(searchString);
searchString.replace("%20"_s, "+"_s);
auto searchURL = URL { { }, "https://www.google.com/search?q=" + searchString + "&ie=UTF-8&oe=UTF-8" };
WebCore::UserGestureIndicator indicator { WebCore::ProcessingUserGesture };
page->mainFrame().loader().changeLocation(searchURL, { }, nullptr, WebCore::ReferrerPolicy::EmptyString, WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow);
}
void WebContextMenuClient::lookUpInDictionary(WebCore::Frame*)
{
notImplemented();
}
void WebContextMenuClient::speak(const String&)
{
notImplemented();
}
void WebContextMenuClient::stopSpeaking()
{
notImplemented();
}
bool WebContextMenuClient::isSpeaking()
{
notImplemented();
return false;
}