webapp,是一款基于webkit内核的简单浏览器应用,并对外提供操纵webkit内核的接口。
当前,双核浏览器逐渐风行,前有傲游3.0,后有搜狗浏览器2.0,再有QQ浏览器5.0,等等。
双核的含义,是指在IE的trident内核之外,再加上渲染及JS执行速度非常快的webkit内核。
webapp的出现,使得双核应用更简便,因为webapp提供了webkit调用接口,你的应用也可非常方便地使用webkit内核。
如果有更多的需求,可以与我联系(QQ353239635 MSN同email)。(源代码出售中)
运行
Windows: webapp.exe
注:修改webapp.ini中的start_url,可使webapp打开指定的网址
webapp acid3测试结果
// #ifndef WEBAPP_H #define WEBAPP_H #include <windows.h> namespace gfx { typedef HWND NativeWindow; }; // namespace gfx namespace webapp { class IWebView { public: virtual gfx::NativeWindow NativeWindow() = 0; virtual gfx::NativeWindow ParentWindow() = 0; virtual void LoadURL(const char* url) = 0; virtual void LoadURL(const wchar_t* url) = 0; }; class IWebViewEventListener { public: virtual gfx::NativeWindow OnGetNewWindowContainer(IWebView* webview) = 0; virtual void OnReceiveTitle(IWebView* webview, const wchar_t* title) = 0; virtual void OnStartLoad(IWebView* webview) = 0; virtual void OnFinishLoad(IWebView* webview) = 0; }; }; // namespace webapp extern "C" __declspec(dllexport) bool webapp_init(int argc, char **argv); extern "C" __declspec(dllexport) bool webapp_create_webview(webapp::IWebView** webview, gfx::NativeWindow parent); extern "C" __declspec(dllexport) bool webapp_delete_webview(webapp::IWebView** webview); extern "C" __declspec(dllexport) bool webapp_add_webview_event_listener(webapp::IWebViewEventListener* listener); extern "C" __declspec(dllexport) bool webapp_remove_webview_event_listener(webapp::IWebViewEventListener* listener); extern "C" __declspec(dllexport) void webapp_run(); extern "C" __declspec(dllexport) void webapp_shutdown(); typedef bool (__cdecl *WEBAPP_INIT)(int argc, char **argv); typedef bool (__cdecl *WEBAPP_CREATE_WEBVIEW)(webapp::IWebView** webview, gfx::NativeWindow container); typedef bool (__cdecl *WEBAPP_DELETE_WEBVIEW)(webapp::IWebView** webview); typedef bool (__cdecl *WEBAPP_ADD_WEBVIEW_EVENT_LISTENER)(webapp::IWebViewEventListener* listener); typedef bool (__cdecl *WEBAPP_REMOVE_WEBVIEW_EVENT_LISTENER)(webapp::IWebViewEventListener* listener); typedef void (__cdecl *WEBAPP_RUN)(); typedef void (__cdecl *WEBAPP_SHUTDOWN)(); #endif // WEBAPP_H
webapp测试用例(webapp_test.tar.gz - 下载完整源码)
#include "webapp_holder.h" #include <windows.h> #include <string> #include "webview_event_listener.h" #define WEBAPP_WINDOW_CLASS L"WebAppContainer_Win" using namespace webapp; WebAppHolder holder; LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { IWebView* webview = reinterpret_cast<IWebView*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)); if (webview) { switch (message) { case WM_DESTROY: holder.webapp_delete_webview(&webview); holder.webapp_shutdown(); return 0; case WM_SIZE: RECT rc; GetClientRect(hwnd, &rc); MoveWindow(webview->NativeWindow(), 0, 0, rc.right, rc.bottom, TRUE); return 0; } } return DefWindowProc(hwnd, message, wParam, lParam); } void RegisterWindowClass() { WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, ::GetModuleHandle(NULL), 0, LoadCursor(NULL, IDC_ARROW), 0, 0, WEBAPP_WINDOW_CLASS, 0, }; RegisterClassEx(&wcex); } int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { // RegisterWindowClass(); // HWND mainWnd = CreateWindow(WEBAPP_WINDOW_CLASS, L"webapp test", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, ::GetModuleHandle(NULL), NULL); // holder.webapp_init(0, NULL); // IWebView* webview = NULL; holder.webapp_create_webview(&webview, mainWnd); ShowWindow(webview->NativeWindow(), SW_SHOW); SetWindowLongPtr(mainWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(webview)); ShowWindow(mainWnd, SW_SHOW); // WebViewEventListener evt; holder.webapp_add_webview_event_listener(&evt); // wchar_t start_url[256]; DWORD num = GetPrivateProfileString(L"webapp", L"start_url", L"", start_url, sizeof(start_url), L".\\webapp.ini"); start_url[num] = 0; webview->LoadURL(start_url); holder.webapp_run(); return 0; }
#ifndef WEBVIEW_EVENT_LISTENER_H #define WEBVIEW_EVENT_LISTENER_H #include "webapp.h" class WebViewEventListener : public webapp::IWebViewEventListener { public: WebViewEventListener(); virtual gfx::NativeWindow OnGetNewWindowContainer(webapp::IWebView* webview); virtual void OnReceiveTitle(webapp::IWebView* webview, const wchar_t* title); virtual void OnStartLoad(webapp::IWebView* webview); virtual void OnFinishLoad(webapp::IWebView* webview); }; #endif // WEBVIEW_EVENT_LISTENER_H
#include "webview_event_listener.h" #include "resource.h" WebViewEventListener::WebViewEventListener() {} gfx::NativeWindow WebViewEventListener::OnGetNewWindowContainer(webapp::IWebView* webview) { wchar_t className[128]; GetClassName(webview->ParentWindow(), className, sizeof(className)); return ::CreateWindow(className, L"", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, ::GetModuleHandle(NULL), NULL); } void WebViewEventListener::OnReceiveTitle(webapp::IWebView* webview, const wchar_t* title) { ::SetWindowText(webview->ParentWindow(), title); } void WebViewEventListener::OnStartLoad(webapp::IWebView* webview) { ::SendMessage(webview->ParentWindow(), WM_SETICON,TRUE,(LPARAM)::LoadIcon(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1))); } void WebViewEventListener::OnFinishLoad(webapp::IWebView* webview) { ::SendMessage(webview->ParentWindow(), WM_SETICON,TRUE,(LPARAM)::LoadIcon(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2))); }