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; }
TEST_F(WebKit2UserMessageRoundTripTest, WKURLRequestRef) { WKRetainPtr<WKURLRef> url = adoptWK(WKURLCreateWithUTF8CString("http://webkit.org/")); WKRetainPtr<WKURLRequestRef> request = adoptWK(WKURLRequestCreateWithWKURL(url.get())); roundTrip(request.get()); WKTypeRef roundTrippedTypeRef = recievedBody.get(); WKRetainPtr<WKURLRequestRef> roundTrippedRequest = static_cast<WKURLRequestRef>(roundTrippedTypeRef); WKRetainPtr<WKURLRef> roundTrippedURL = adoptWK(WKURLRequestCopyURL(roundTrippedRequest.get())); EXPECT_TRUE(WKURLIsEqual(roundTrippedURL.get(), url.get())); }
static WKURLRef createWKURL(const char* pathOrURL) { if (strstr(pathOrURL, "http://") || strstr(pathOrURL, "https://") || strstr(pathOrURL, "file://")) return WKURLCreateWithUTF8CString(pathOrURL); // Creating from filesytem path. size_t length = strlen(pathOrURL); if (!length) return 0; #if OS(WINDOWS) const char separator = '\\'; bool isAbsolutePath = length >= 3 && pathOrURL[1] == ':' && pathOrURL[2] == separator; // FIXME: Remove the "localhost/" suffix once <http://webkit.org/b/55683> is fixed. const char* filePrefix = "file://localhost/"; #else const char separator = '/'; bool isAbsolutePath = pathOrURL[0] == separator; const char* filePrefix = "file://"; #endif static const size_t prefixLength = strlen(filePrefix); OwnArrayPtr<char> buffer; if (isAbsolutePath) { buffer = adoptArrayPtr(new char[prefixLength + length + 1]); strcpy(buffer.get(), filePrefix); strcpy(buffer.get() + prefixLength, pathOrURL); } else { buffer = adoptArrayPtr(new char[prefixLength + PATH_MAX + length + 2]); // 1 for the separator strcpy(buffer.get(), filePrefix); if (!getcwd(buffer.get() + prefixLength, PATH_MAX)) return 0; size_t numCharacters = strlen(buffer.get()); buffer[numCharacters] = separator; strcpy(buffer.get() + numCharacters + 1, pathOrURL); } return WKURLCreateWithUTF8CString(buffer.get()); }
TEST(WebKit2, AboutBlankLoad) { WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); PlatformWebView webView(context.get()); WKPageLoaderClient loaderClient; memset(&loaderClient, 0 , sizeof(loaderClient)); loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; WKPageSetPageLoaderClient(webView.page(), &loaderClient); WKPageLoadURL(webView.page(), adoptWK(WKURLCreateWithUTF8CString("about:blank")).get()); Util::run(&done); }
TEST(WebKit2, AboutBlankLoad) { WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); PlatformWebView webView(context.get()); WKPagePolicyClient policyClient; memset(&policyClient, 0, sizeof(policyClient)); policyClient.decidePolicyForResponse = decidePolicyForResponse; WKPageSetPagePolicyClient(webView.page(), &policyClient); WKPageLoadURL(webView.page(), adoptWK(WKURLCreateWithUTF8CString("about:blank")).get()); Util::run(&done); }
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); }
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; }
TEST(WebKit2, CookieManager) { wkContext.adopt(WKContextCreate()); PlatformWebView webView(wkContext.get()); WKPageLoaderClientV0 loaderClient; memset(&loaderClient, 0, sizeof(loaderClient)); loaderClient.base.version = 0; loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); WKPageLoadURL(webView.page(), adoptWK(WKURLCreateWithUTF8CString("about:blank")).get()); Util::run(&testDone); }
TEST(WebKit2, FrameHandle) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); PlatformWebView webView(context.get()); WKPageLoaderClientV0 loaderClient; memset(&loaderClient, 0, sizeof(loaderClient)); loaderClient.base.version = 0; loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); WKPageLoadURL(webView.page(), adoptWK(WKURLCreateWithUTF8CString("about:blank")).get()); Util::run(&done); auto frame = WKPageGetMainFrame(webView.page()); auto frameInfo = adoptWK(WKFrameCreateFrameInfo(frame)); auto handleFromInfo = WKFrameInfoGetFrameHandleRef(frameInfo.get()); auto handleFromFrame = adoptWK(WKFrameCreateFrameHandle(frame)); EXPECT_EQ(WKFrameHandleGetFrameID(handleFromInfo), WKFrameHandleGetFrameID(handleFromFrame.get())); }
TEST(WebKit2, ReloadPageAfterCrash) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); PlatformWebView webView(context.get()); WKPageLoaderClientV0 loaderClient; memset(&loaderClient, 0, sizeof(loaderClient)); loaderClient.base.version = 0; loaderClient.didFinishLoadForFrame = didFinishLoad; loaderClient.processDidCrash = didCrash; WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); WKRetainPtr<WKURLRef> url = adoptWK(WKURLCreateWithUTF8CString("about:blank")); // Load a blank page and next kills WebProcess. WKPageLoadURL(webView.page(), url.get()); Util::run(&loadBeforeCrash); WKPageTerminate(webView.page()); // Let's try load a page and see what happens. WKPageLoadURL(webView.page(), url.get()); Util::run(&loadAfterCrash); }
static WKURLRef blankURL() { static WKURLRef staticBlankURL = WKURLCreateWithUTF8CString("about:blank"); return staticBlankURL; }
WKURLRef URLForNonExistentResource() { return WKURLCreateWithUTF8CString("file:///does-not-exist.html"); }
WKURLRef createURLForResource(const char* resource, const char* extension) { // ### FIXME. return WKURLCreateWithUTF8CString(""); }
TEST(WebKit2, PendingAPIRequestURL) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); PlatformWebView webView(context.get()); WKPageLoaderClientV0 loaderClient; memset(&loaderClient, 0, sizeof(loaderClient)); loaderClient.base.version = 0; loaderClient.didFinishLoadForFrame = [](WKPageRef, WKFrameRef, WKTypeRef, const void*) { done = true; }; WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); WKRetainPtr<WKURLRef> activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); EXPECT_NULL(activeURL.get()); WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("simple", "html")); WKPageLoadURL(webView.page(), url.get()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKRetainPtr<WKStringRef> htmlString = Util::toWK("<body>Hello, World</body>"); WKRetainPtr<WKURLRef> blankURL = adoptWK(WKURLCreateWithUTF8CString("about:blank")); WKPageLoadHTMLString(webView.page(), htmlString.get(), nullptr); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); Util::run(&done); done = false; url = adoptWK(Util::createURLForResource("simple2", "html")); WKPageLoadHTMLString(webView.page(), htmlString.get(), url.get()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKRetainPtr<WKDataRef> data = adoptWK(WKDataCreate(nullptr, 0)); WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, nullptr); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); Util::run(&done); done = false; WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, url.get()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKPageLoadAlternateHTMLString(webView.page(), htmlString.get(), nullptr, url.get()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); Util::run(&done); done = false; WKRetainPtr<WKStringRef> plainTextString = Util::toWK("Hello, World"); WKPageLoadPlainTextString(webView.page(), plainTextString.get()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); Util::run(&done); done = false; WKPageReload(webView.page()); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); Util::run(&done); done = false; url = adoptWK(WKURLCreateWithUTF8CString("file:///tmp/index.html")); WKPageLoadFile(webView.page(), url.get(), nullptr); activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); ASSERT_NOT_NULL(activeURL.get()); EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); WKPageStopLoading(webView.page()); }
LoadItem(const String& url, const String& target) : m_url(AdoptWK, WKURLCreateWithUTF8CString(url.utf8().data())) , m_target(target) { }
void View::load(const char* url) { auto shellURL = adoptWK(WKURLCreateWithUTF8CString(url)); WKPageLoadURL(WKViewGetPage(m_view), shellURL.get()); }