2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "BrowserView.h"
29 #include "BrowserWindow.h"
30 #include <WebKit2/WKContextPrivate.h>
31 #include <WebKit2/WKURLCF.h>
33 static const unsigned short HIGH_BIT_MASK_SHORT = 0x8000;
35 BrowserView::BrowserView()
40 // UI Client Callbacks
42 static WKPageRef createNewPage(WKPageRef page, const void* clientInfo)
44 BrowserWindow* browserWindow = BrowserWindow::create();
45 browserWindow->createWindow(0, 0, 800, 600);
47 return WKViewGetPage(browserWindow->view().webView());
50 static void showPage(WKPageRef page, const void *clientInfo)
52 static_cast<BrowserWindow*>(const_cast<void*>(clientInfo))->showWindow();
55 static void closePage(WKPageRef page, const void *clientInfo)
59 static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
63 static bool runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef frame, const void* clientInfo)
68 static WKStringRef runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void* clientInfo)
73 static void setStatusText(WKPageRef page, WKStringRef text, const void* clientInfo)
77 static void mouseDidMoveOverElement(WKPageRef page, WKEventModifiers modifiers, WKTypeRef userData, const void *clientInfo)
81 static void contentsSizeChanged(WKPageRef page, int width, int height, WKFrameRef frame, const void *clientInfo)
85 void BrowserView::create(RECT webViewRect, BrowserWindow* parentWindow)
89 bool isShiftKeyDown = ::GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT;
93 context = WKContextGetSharedThreadContext();
95 context = WKContextGetSharedProcessContext();
97 WKPageNamespaceRef pageNamespace = WKPageNamespaceCreate(context);
99 m_webView = WKViewCreate(webViewRect, pageNamespace, parentWindow->window());
101 WKPageUIClient uiClient = {
103 parentWindow, /* clientInfo */
108 runJavaScriptConfirm,
111 mouseDidMoveOverElement,
113 0 /* didNotHandleKeyEvent */
116 WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient);
119 void BrowserView::setFrame(RECT rect)
121 HWND webViewWindow = WKViewGetWindow(m_webView);
122 ::SetWindowPos(webViewWindow, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS);
125 void BrowserView::goToURL(const std::wstring& urlString)
127 CFStringRef string = CFStringCreateWithCharacters(0, (const UniChar*)urlString.data(), urlString.size());
128 CFURLRef cfURL = CFURLCreateWithString(0, string, 0);
131 WKURLRef url = WKURLCreateWithCFURL(cfURL);
134 WKPageRef page = WKViewGetPage(m_webView);
135 WKPageLoadURL(page, url);