ONE发布基于Native VC++的浏览器编程接口(支持webkit/webkit2, gecko

hikari 发布于 2010/10/24 13:39
阅读 2K+
收藏 1

更详尽的详细资讯,可参考这里。

 

1. API定义

extern "C"
{
	__declspec(dllimport)
		HANDLE ONE_CreateNavigator(INT nEngine, HWND hWnd, LPCWSTR szUrl, LPRECT boundMargins);

	__declspec(dllimport)
		INT ONE_PreProcessMessage(LPMSG msg);

	__declspec(dllimport)
		HRESULT ONE_InstallFilter(LPCWSTR protocol, HANDLE filter);

	__declspec(dllimport)
		HRESULT ONE_EnableProtocolFilter(LPCWSTR protocol, PHANDLE ppv);
	
	__declspec(dllimport)
		HRESULT ONE_DisableProtocolFilter(PHANDLE ppv);

	__declspec(dllimport)
		HRESULT ONE_EnableContentFilter(LPCWSTR contentType, PHANDLE ppv);

	__declspec(dllimport)
		HRESULT ONE_DisableContentFilter(PHANDLE ppv);

	__declspec(dllimport) 
		BOOL ONE_Startup(INT engine);

	__declspec(dllimport) 
		BOOL ONE_Shutdown(INT engine);
};

2. IOneEvents定义

MIDL_INTERFACE("9049EDD4-7DFA-4b10-A6DA-AAC6596FA36B") IOneEvents
{
public:
	//navigation informations
	virtual VOID Event_NavigationTitleChanged(LPCWSTR text) = 0;
	virtual VOID Event_NavigationStatusTextChanged(LPCWSTR text) = 0;
	virtual VOID Event_NavigationUrlChanged(LPCWSTR text) = 0;
	virtual VOID Event_NavigationStateChanged(INT state) = 0;
	
	//windows
	virtual VOID Event_BeforeOpenUrl(LPCWSTR url, LPCWSTR windowName, BOOL isBackground, IOne** pOne) = 0;
	virtual VOID Event_BeforePopupUrl(LPCWSTR url, LPCWSTR windowName, LPCWSTR features, IOne** pOne) = 0;
	virtual VOID Event_BeforeCloseWindow(LPBOOL bCancel) = 0;
	
	//user input
	virtual VOID Event_BeforeClickMouse(LPBOOL bCancel, BOOL isDown, CONST LPBOOL auxKeysDown, INT key, TInputProber *info) = 0;
	virtual INT Event_BeforePressKey(LPBOOL bCancel, BOOL isDown, CONST LPBOOL auxKeysDown, INT key, TInputProber *info) = 0;
	
	//navigating actions
	virtual VOID Event_BeforeNavigate(BOOL isSubFrame, LPBOOL bCancel, LPCWSTR url) = 0;
	virtual VOID Event_StartNavigating(BOOL isSubFrame, LPCWSTR url) = 0;
	virtual VOID Event_CompleteNavigating(BOOL isSubFrame, LPCWSTR url) = 0;
	
	//script messages
	virtual VOID Event_BeforeAlertMessage(LPCWSTR title, LPCWSTR text) = 0;
	virtual VOID Event_BeforeConfirmMessage(LPBOOL isConfirm, LPCWSTR title, LPCWSTR text) = 0;
	virtual VOID Event_BeforePromptMessage(LPBOOL bAccept, LPCWSTR title, LPCWSTR text, LPWSTR value, UINT valueMaxLen) = 0;
};

3. IOne定义

MIDL_INTERFACE("1950FA71-1413-4176-A289-7DA2E6475626") IOne
{
public:
	//methods
	virtual HRESULT Initialize(LPVOID param) = 0;
	virtual HRESULT DestroyNavigator() = 0;
	virtual HRESULT Navigate(LPCWSTR url) = 0;
	virtual HRESULT Execute(INT nCmd, LPVOID lpParam) = 0;
	virtual HRESULT StopNavigating() = 0;
	virtual HRESULT Reload(BOOL isCompletely) = 0;
	virtual HRESULT SetCursorFocus() = 0;
	virtual HRESULT GoBackward(LPINT navigationState) = 0;
	virtual HRESULT GoForward(LPINT navigationState) = 0;
	virtual HRESULT GoToLogCursor(HANDLE logCursor) = 0;

	//get properties
	virtual LPCWSTR GetVersion() = 0;
	virtual BOOL GetIsAlive() = 0;
	virtual HWND GetHostWindow() = 0;
	virtual BOOL GetIsNavigationBusy() = 0;
	virtual INT GetEngine() = 0;
	virtual HRESULT GetNavigationTitle(LPWSTR title, size_t titleMaxLen) = 0;
	virtual HRESULT GetNavigationUrl(LPWSTR url, size_t urlMaxlen) = 0;
	virtual HRESULT GetLastStatusText(LPWSTR status, size_t statusMaxLen) = 0;
	virtual HRESULT GetCurrentLogCursor(PHANDLE logCursor) = 0;
	virtual HRESULT GetNavigationState(LPINT state) = 0;

	//handlers
	virtual HRESULT SetEventsHandler(CONST IOneEvents* CONST handler) = 0;//t,g,w,
	virtual HRESULT SetWindowsManager(CONST IOneCreator* CONST manager) = 0;

	//mouse control
	virtual BOOL GetMouseKeyEnable(INT key) = 0;
	virtual VOID SetMouseKeyEnable(INT key, BOOL bEnable) = 0;

	//interface
	virtual HRESULT GetInterface(INT id, PHANDLE ppv) = 0;
	virtual IOneCreator* CONST GetWindowCreator() = 0;
};

4. 使用流程

1. 启动引擎环境(每进程): ONE_Startup(引擎id)

2. 定义IOne指针变量:IOne *pOne;

3. 创建IOne实例:pOne = (IOne *)ONE_CreateNavigator(引擎id, 宿主窗口的HWND, 启动url, 宿主窗口内上下左右须保留的空白像素rectBounds)

4. 初始化前的各种设定: pOne->Execute(命令id, 命令参数)

5. 初始化前的设定事件处理器: pOne->SetEventsHandler(COneEvents *pEvents) /* 开发者自定义的class COneEvents : public IOneEvents {...}; */

6. 初始化: pOne->Initialize(NULL)

7. 释放: pOne->DestroyNavigator()/* 不能使用C++的delete方法 */

8. 关闭引擎环境(每进程): ONE_Shutdown(引擎id)

提示1: 宿主窗口收到WM_SIZE时IOne实例会自动根据rectBounds预留大小调整自己的窗口矩形。

提示2: 不设定IOneEvents处理器时仅能浏览,不能处理用户输入、打开/弹出窗口处理。

提示3: 详情可参考示范代码。
加载中
0
mallon
mallon

接口和函数定义得很“微软化”,呵呵。Windows下用用应该不错,不过我还是喜欢Qt自带的Webkit。

z
zjk2012
您好,我现在在用VC++ 引入webkit,开发。 我想知道怎么拦截网页load完成的消息,请问您知道吗? 我觉得用WKPageLoaderClient WKPageResourceLoadClient这几个结构体,添入回调函数,然后将他们和WKPage关联,就应该能在回调函数里面写下载完等事件后的代码。但是没有成功啊!
返回顶部
顶部