예제 #1
0
파일: Tab.cpp 프로젝트: setanta/drowser
Tab::~Tab()
{
    WKPageClose(m_page);
    WKRelease(m_context);

    WKRelease(m_view);
}
예제 #2
0
static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
{
    TEST_ASSERT(WKFrameGetFrameLoadState(frame) == kWKFrameLoadStateFinished);

    WKURLRef url = WKFrameCopyProvisionalURL(frame);
    WKURLRef emptyURL = WKURLCreateWithUTF8CString("");
    TEST_ASSERT(WKURLIsEqual(url, emptyURL));
    WKRelease(url);
    WKRelease(emptyURL);

    testDone = true;
}
예제 #3
0
파일: Tab.cpp 프로젝트: setanta/drowser
void Tab::onCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef, const void *clientInfo)
{
    Tab* self = ((Tab*)clientInfo);

    if (page != self->m_page || !WKFrameIsMainFrame(frame))
        return;

    WKURLRef url = WKPageCopyActiveURL(page);
    WKStringRef urlString = WKURLCopyString(url);
    postToBundle(self->m_browser->ui(), "urlChanged", self->m_id, urlString);
    WKRelease(url);
    WKRelease(urlString);
}
void DOMWindowExtensionNoCache::willDestroyGlobalObjectForDOMWindowExtension(WKBundleDOMWindowExtensionRef extension)
{
    sendBundleMessage("WillDestroyDOMWindowExtensionToGlobalObject called");
    updateExtensionStateRecord(extension, Destroyed);
    m_extensionToRecordMap.remove(extension);
    WKRelease(extension);
}
예제 #5
0
TEST(WebKit2, WKStringJSString)
{
    WKStringRef wkString = WKStringCreateWithUTF8CString("hello");
    JSStringRef jsString = JSStringCreateWithUTF8CString("hello");
    
    WKStringRef convertedJSString = WKStringCreateWithJSString(jsString);
    EXPECT_TRUE(WKStringIsEqual(wkString, convertedJSString));
    
    JSStringRef convertedWKString = WKStringCopyJSString(wkString);
    EXPECT_TRUE(JSStringIsEqual(jsString, convertedWKString));

    WKRelease(wkString);
    WKRelease(convertedJSString);

    JSStringRelease(jsString);
    JSStringRelease(convertedWKString);
}
예제 #6
0
파일: Tab.cpp 프로젝트: setanta/drowser
void Tab::onFailProvisionalLoadWithErrorForFrameCallback(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void*)
{
    if (!WKFrameIsMainFrame(frame))
        return;

    WKStringRef wkErrorDescription = WKErrorCopyLocalizedDescription(error);
    WKPageLoadPlainTextString(page, wkErrorDescription);
    WKRelease(wkErrorDescription);
}
예제 #7
0
파일: Tab.cpp 프로젝트: setanta/drowser
Tab::Tab(Browser* browser)
    : m_id(nextTabId++)
    , m_browser(browser)
{
    // FIXME Find a good way to find where the injected bundle is
    WKStringRef wkStr = WKStringCreateWithUTF8CString((getApplicationPath() + "/../ContentsInjectedBundle/libPageBundle.so").c_str());
    m_context = WKContextCreateWithInjectedBundlePath(wkStr);
    WKRelease(wkStr);
    init();
}
예제 #8
0
파일: Tab.cpp 프로젝트: setanta/drowser
void Tab::onMouseDidMoveOverElement(WKPageRef, WKHitTestResultRef hitTestResult, WKEventModifiers, WKTypeRef, const void *clientInfo)
{
    Tab* self = ((Tab*)clientInfo);

    WKURLRef url = WKHitTestResultCopyAbsoluteLinkURL(hitTestResult);
    if (url) {
        self->m_browser->window()->setMouseCursor(DesktopWindow::Hand);
        WKRelease(url);
    } else {
        self->m_browser->window()->setMouseCursor(DesktopWindow::Arrow);
    }
}
예제 #9
0
void BrowserView::goToURL(const std::wstring& urlString)
{
    CFStringRef string = CFStringCreateWithCharacters(0, (const UniChar*)urlString.data(), urlString.size());
    CFURLRef cfURL = CFURLCreateWithString(0, string, 0);
    CFRelease(string);

    WKURLRef url = WKURLCreateWithCFURL(cfURL);
    CFRelease(cfURL); 

    WKPageRef page = WKViewGetPage(m_webView);
    WKPageLoadURL(page, url);
    WKRelease(url);
}
void DOMWindowExtensionBasic::willDestroyPage(WKBundleRef, WKBundlePageRef)
{
    HashMap<WKBundleDOMWindowExtensionRef, int>::iterator it = m_extensionToRecordMap.begin();
    HashMap<WKBundleDOMWindowExtensionRef, int>::iterator end = m_extensionToRecordMap.end();
    for (; it != end; ++it) {
        updateExtensionStateRecord(it->key, Removed);
        WKRelease(it->key);
    }

    m_extensionToRecordMap.clear();

    sendExtensionStateMessage();
    sendBundleMessage("TestComplete");
}
void DOMWindowExtensionBasic::willDestroyGlobalObjectForDOMWindowExtension(WKBundleDOMWindowExtensionRef extension)
{
    m_numberOfDestroyedExtensions++;

    updateExtensionStateRecord(extension, Destroyed);
    sendBundleMessage("WillDestroyGlobalObjectForDOMWindowExtension called");
    
    if (m_numberOfDestroyedExtensions == 6) {
        sendExtensionStateMessage();
        sendBundleMessage("TestComplete");
    }
    
    WKRelease(extension);
}
예제 #12
0
파일: Tab.cpp 프로젝트: setanta/drowser
void Tab::loadUrl(const std::string& url)
{
    std::string fixedUrl(url);
    if (!hasValidPrefix(fixedUrl)) {
        if (std::ifstream(fixedUrl.c_str()))
            fixedUrl.insert(0, "file:///");
        else
            fixedUrl.insert(0, "http://");
    }

    std::cout << "Load URL: " << fixedUrl << std::endl;
    WKURLRef wkUrl = WKURLCreateWithUTF8CString(fixedUrl.c_str());
    WKPageLoadURL(m_page, wkUrl);
    WKRelease(wkUrl);
}
TEST(WebKit2, WKConnectionTest)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("WKConnectionTest"));

    // Set up the context's connection client so that we can access the connection when
    // it is created.
    WKContextConnectionClient contextConnectionClient;
    memset(&contextConnectionClient, 0, sizeof(contextConnectionClient));
    contextConnectionClient.version = kWKContextConnectionClientCurrentVersion;
    contextConnectionClient.clientInfo = 0;
    contextConnectionClient.didCreateConnection = didCreateConnection;
    WKContextSetConnectionClient(context.get(), &contextConnectionClient);
 
    // Load a simple page to start the WebProcess and establish a connection.
    PlatformWebView webView(context.get());
    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
    WKPageLoadURL(webView.page(), url.get());

    // Wait until the connection is established.
    Util::run(&connectionEstablished);
    ASSERT_NOT_NULL(connectionToBundle);

    // Setup a client on the connection so we can listen for messages and
    // tear down notifications.
    WKConnectionClient connectionClient;
    memset(&connectionClient, 0, sizeof(connectionClient));
    connectionClient.version = WKConnectionClientCurrentVersion;
    connectionClient.clientInfo = 0;
    connectionClient.didReceiveMessage = connectionDidReceiveMessage;
    connectionClient.didClose = connectionDidClose;
    WKConnectionSetConnectionClient(connectionToBundle, &connectionClient);
    
    // Post a simple message to the bundle via the connection.
    WKConnectionPostMessage(connectionToBundle, Util::toWK("PingMessageName").get(), Util::toWK("PingMessageBody").get());

    // Wait for the reply.
    Util::run(&messageReceived);

    // Terminate the page to force the connection closed.
    WKPageTerminate(webView.page());
    
    // Wait for the connection to close.
    Util::run(&connectionTornDown);

    // This release is to balance the retain in didCreateConnection.
    WKRelease(connectionToBundle);
}
예제 #14
0
int main(int argc, char* argv[])
{
    const char* url = argc == 2 ? argv[1] : "http://www.google.com";

    //ProfilerStart("/home/pi/Sample.prof");

    bcm_host_init();

    memset(&g_state, 0, sizeof(struct state));
    ogl_init(&g_state);

    GMainLoop* mainLoop = g_main_loop_new(0, false);
    WKContextRef context = WKContextCreateWithInjectedBundlePath(WKStringCreateWithUTF8CString(SAMPLE_INJECTEDBUNDLE_DIR "libSampleInjectedBundle.so"));
    NIXView webView = NIXViewCreate(context, NULL);
    WKPageRef page = NIXViewGetPage(webView);

    NIXViewClient viewClient;
    memset(&viewClient, 0, sizeof(NIXViewClient));
    viewClient.version = kNIXViewClientCurrentVersion;
    viewClient.viewNeedsDisplay = viewNeedsDisplay;
    NIXViewSetViewClient(webView, &viewClient);

    NIXViewInitialize(webView);

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    loaderClient.version = kWKPageLoaderClientCurrentVersion;
    loaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
    WKPageSetPageLoaderClient(page, &loaderClient);

    NIXViewSetSize(webView, WKSizeMake(g_state.screen_width, g_state.screen_height));
    WKPageLoadURL(page, WKURLCreateWithUTF8CString(url));

    //ProfilerFlush();
    //ProfilerStop();

    g_main_loop_run(mainLoop);

    NIXViewRelease(webView);
    WKRelease(context);
    g_main_loop_unref(mainLoop);

    ogl_exit(&g_state);

    return 0;
}
예제 #15
0
파일: Tab.cpp 프로젝트: setanta/drowser
void Tab::init()
{
    m_view = WKViewCreate(m_context, m_browser->contentPageGroup());
    WKViewInitialize(m_view);
    WKViewSetIsFocused(m_view, true);
    WKViewSetIsVisible(m_view, true);
    m_page = WKViewGetPage(m_view);
    WKStringRef appName = WKStringCreateWithUTF8CString("Drowser");
    WKPageSetApplicationNameForUserAgent(m_page, appName);
    WKRelease(appName);

    WKViewClient client;
    std::memset(&client, 0, sizeof(WKViewClient));
    client.version = kWKViewClientCurrentVersion;
    client.clientInfo = this;
    client.viewNeedsDisplay = &Tab::onViewNeedsDisplayCallback;

    WKViewSetViewClient(m_view, &client);

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(WKPageLoaderClient));
    loaderClient.version = kWKPageLoaderClientCurrentVersion;
    loaderClient.clientInfo = this;
    loaderClient.didStartProgress = &Tab::onStartProgressCallback;
    loaderClient.didChangeProgress = &Tab::onChangeProgressCallback;
    loaderClient.didFinishProgress = &Tab::onFinishProgressCallback;
    loaderClient.didCommitLoadForFrame = &Tab::onCommitLoadForFrame;
    loaderClient.didReceiveTitleForFrame = &Tab::onReceiveTitleForFrame;
    loaderClient.didFailProvisionalLoadWithErrorForFrame = &Tab::onFailProvisionalLoadWithErrorForFrameCallback;

    WKPageSetPageLoaderClient(m_page, &loaderClient);

    WKPageUIClient uiClient;
    memset(&uiClient, 0, sizeof(WKPageUIClient));
    uiClient.version = kWKPageUIClientCurrentVersion;
    uiClient.clientInfo = this;
    uiClient.createNewPage = &Tab::createNewPageCallback;
    uiClient.mouseDidMoveOverElement = &Tab::onMouseDidMoveOverElement;

    WKPageSetPageUIClient(m_page, &uiClient);
}
예제 #16
0
TEST(WebKit2, WKString)
{
    WKStringRef string = WKStringCreateWithUTF8CString("hello");
    EXPECT_TRUE(!WKStringIsEmpty(string));
    EXPECT_TRUE(WKStringIsEqual(string, string));
    EXPECT_TRUE(WKStringIsEqualToUTF8CString(string, "hello"));
    EXPECT_EQ(16u, WKStringGetMaximumUTF8CStringSize(string));

    size_t maxSize = WKStringGetMaximumUTF8CStringSize(string);
    char* buffer = new char[maxSize];

    size_t actualSize = WKStringGetUTF8CString(string, buffer, maxSize);
    EXPECT_EQ(6u, actualSize);
    EXPECT_STREQ("hello", buffer);

    delete[] buffer;
    
    maxSize = WKStringGetLength(string);
    EXPECT_EQ(5u, maxSize);

    // Allocate a buffer one character larger than we need.
    WKChar* uniBuffer = new WKChar[maxSize+1];
    actualSize = WKStringGetCharacters(string, uniBuffer, maxSize);
    EXPECT_EQ(5u, actualSize);
    
    WKChar helloBuffer[] = { 'h', 'e', 'l', 'l', 'o' };
    EXPECT_TRUE(!memcmp(uniBuffer, helloBuffer, 10));
    
    // Test passing a buffer length < the string length.
    actualSize = WKStringGetCharacters(string, uniBuffer, maxSize - 1);
    EXPECT_EQ(4u, actualSize);
    
    // Test passing a buffer length > the string length.
    actualSize = WKStringGetCharacters(string, uniBuffer, maxSize + 1);
    EXPECT_EQ(5u, actualSize);
    
    delete[] uniBuffer;
    
    WKRelease(string);
}
예제 #17
0
static void WKContext_Dealloc(PyObject* self)
{
    WKContextObject* cppSelf = reinterpret_cast<WKContextObject*>(self);
    WKRelease(cppSelf->cptr);
}
예제 #18
0
void WKCollectionRelease (CFAllocatorRef allocator, const void *value)
{
    UNUSED_PARAM(allocator);
    WKRelease (value);
}
PlatformWebView::~PlatformWebView()
{
    if (::IsWindow(m_window))
        ::DestroyWindow(m_window);
    WKRelease(m_view);
}
예제 #20
0
TEST(WebKitNix, WebViewUpdateTextInputState)
{
    memset(&stateReceived, 0, sizeof(stateReceived));
    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
    WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0));

    NIXViewClient nixViewClient;
    memset(&nixViewClient, 0, sizeof(NIXViewClient));
    nixViewClient.version = kNIXViewClientCurrentVersion;
    nixViewClient.updateTextInputState = updateTextInputState;
    NIXViewSetNixViewClient(view.get(), &nixViewClient);

    WKViewInitialize(view.get());

    WKPageLoaderClient pageLoaderClient;
    memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient));
    pageLoaderClient.version = kWKPageLoaderClientCurrentVersion;
    pageLoaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(WKViewGetPage(view.get()), &pageLoaderClient);

    const WKSize size = WKSizeMake(100, 100);
    WKViewSetSize(view.get(), size);

    NIXMouseEvent nixEvent;
    memset(&nixEvent, 0, sizeof(NIXMouseEvent));
    nixEvent.type = kNIXInputEventTypeMouseDown;
    nixEvent.button = kWKEventMouseButtonLeftButton;
    nixEvent.x = 55;
    nixEvent.y = 55;
    nixEvent.globalX = 55;
    nixEvent.globalY = 55;
    nixEvent.clickCount = 1;
    nixEvent.modifiers = static_cast<NIXInputEventModifiers>(0);;
    nixEvent.timestamp = 0;

    // Simple test on content editable.
    WKRetainPtr<WKURLRef> editableContentUrl = adoptWK(Util::createURLForResource("../nix/single-tap-on-editable-content", "html"));
    WKPageLoadURL(WKViewGetPage(view.get()), editableContentUrl.get());
    Util::run(&didFinishLoad);
    NIXViewSendMouseEvent(view.get(), &nixEvent);
    nixEvent.type = kNIXInputEventTypeMouseUp;
    NIXViewSendMouseEvent(view.get(), &nixEvent);

    Util::run(&didUpdateTextInputState);

    ASSERT_TRUE(didFinishLoad);
    ASSERT_TRUE(didUpdateTextInputState);
    ASSERT_TRUE(stateReceived.isContentEditable);

    ASSERT_TRUE(WKStringIsEqualToUTF8CString(stateReceived.surroundingText, "foobar"));
    WKRelease(stateReceived.surroundingText);
    ASSERT_TRUE(WKStringIsEmpty(stateReceived.submitLabel));
    WKRelease(stateReceived.submitLabel);
    ASSERT_FALSE(stateReceived.inputMethodHints & NIXImhSensitiveData);
    ASSERT_TRUE(!WKRectIsEqual(stateReceived.cursorRect, invalidRectState));
    ASSERT_TRUE(!WKRectIsEqual(stateReceived.editorRect, invalidRectState));
    ASSERT_TRUE(!WKRectIsEqual(stateReceived.cursorRect, stateReceived.editorRect));

    // Test on a form field.
    didFinishLoad = false;
    memset(&stateReceived, 0, sizeof(stateReceived));

    editableContentUrl = adoptWK(Util::createURLForResource("../nix/single-tap-on-form-field", "html"));
    WKPageLoadURL(WKViewGetPage(view.get()), editableContentUrl.get());
    Util::run(&didFinishLoad);
    nixEvent.type = kNIXInputEventTypeMouseDown;
    NIXViewSendMouseEvent(view.get(), &nixEvent);
    nixEvent.type = kNIXInputEventTypeMouseUp;
    NIXViewSendMouseEvent(view.get(), &nixEvent);

    didUpdateTextInputState = false;
    Util::run(&didUpdateTextInputState);

    WKRelease(stateReceived.surroundingText);
    ASSERT_TRUE(didFinishLoad);
    ASSERT_TRUE(didUpdateTextInputState);
    ASSERT_TRUE(WKStringIsEqualToUTF8CString(stateReceived.submitLabel, "submitLabelValue"));
    WKRelease(stateReceived.submitLabel);
    ASSERT_TRUE(stateReceived.inputMethodHints & NIXImhSensitiveData);
}