void Win32UserWindow::SetURL(std::string& url_)
{
	std::string url = URLUtils::NormalizeURL(url_);
	Win32UIBinding::SetProxyForURL(url);

	IWebMutableURLRequest* request = 0;
	std::wstring method = L"GET" ;

	HRESULT hr = WebKitCreateInstance(CLSID_WebMutableURLRequest, 0, 
		IID_IWebMutableURLRequest, (void**) &request);
	if (FAILED(hr))
		HandleHResultError("Error creating WebMutableURLRequest", hr, true);

	std::wstring wurl = UTF8ToWide(url);
	hr = request->initWithURL(SysAllocString(wurl.c_str()), 
		WebURLRequestUseProtocolCachePolicy, 60);
	if (FAILED(hr))
	{
		request->Release();
		std::string error("Error initialiazing WebMutableURLRequest for ");
		error.append(url);
		HandleHResultError(error, hr, true);
	}

	hr = request->setHTTPMethod(SysAllocString(method.c_str()));
	if (FAILED(hr))
	{
		request->Release();
		std::string error("Error setting HTTP method for ");
		error.append(url);
		HandleHResultError(error, hr, true);
	}

	hr = mainFrame->loadRequest(request);
	if (FAILED(hr))
	{
		request->Release();
		std::string error("Error starting load request for ");
		error.append(url);
		HandleHResultError(error, hr, true);
	}

	logger->Debug("set focus");
	//SetFocus(viewWindowHandle);

exit:
	if (request)
		request->Release();
}
Example #2
0
void Win32UserWindow::SetURL(std::string& url_) {
	std::string url = url_;

	this->config->SetURL(url);

	url = AppURLNormalizeURL(url, AppConfig::Instance()->GetAppID());
	std::cout << "SetURL: " << url << std::endl;

	IWebMutableURLRequest* request = 0;
	std::wstring method =L"GET" ;

	if (url.length() > 0 && (PathFileExists(url.c_str()) || PathIsUNC(url.c_str()))) {
		TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
		DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
		if (SUCCEEDED(UrlCreateFromPath(url.c_str(), fileURL, &fileURLLength, 0)))
			url = fileURL;
	}
	std::wstring wurl = UTF8ToWide(url);

	std::cout << "CoCreateInstance " << std::endl;
	HRESULT hr = CoCreateInstance(CLSID_WebMutableURLRequest, 0, CLSCTX_ALL, IID_IWebMutableURLRequest, (void**)&request);
	if (FAILED(hr))
		goto exit;

	std::cout << "initWithURL: " << url << std::endl;
	hr = request->initWithURL(SysAllocString(wurl.c_str()), WebURLRequestUseProtocolCachePolicy, 60);
	if (FAILED(hr))
		goto exit;

	std::cout << "set HTTP method" << std::endl;
	hr = request->setHTTPMethod(SysAllocString(method.c_str()));
	if (FAILED(hr))
		goto exit;

	std::cout << "load request" << std::endl;
	hr = web_frame->loadRequest(request);
	if (FAILED(hr))
		goto exit;

	std::cout << "set focus" << std::endl;
	SetFocus(view_window_handle);

exit:
	if (request)
		request->Release();
}
Example #3
0
static void loadURL(BSTR urlBStr)
{
    IWebFrame* frame = 0;
    IWebMutableURLRequest* request = 0;
    static BSTR methodBStr = 0;

    if (!methodBStr)
        methodBStr = SysAllocString(TEXT("GET"));

    if (urlBStr && urlBStr[0] && (PathFileExists(urlBStr) || PathIsUNC(urlBStr))) {
        TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
        DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
        if (SUCCEEDED(UrlCreateFromPath(urlBStr, fileURL, &fileURLLength, 0)))
            urlBStr = fileURL;
    }

    HRESULT hr = gWebView->mainFrame(&frame);
    if (FAILED(hr))
        goto exit;

    hr = CoCreateInstance(CLSID_WebMutableURLRequest, 0, CLSCTX_ALL, IID_IWebMutableURLRequest, (void**)&request);
    if (FAILED(hr))
        goto exit;

    hr = request->initWithURL(urlBStr, WebURLRequestUseProtocolCachePolicy, 0);
    if (FAILED(hr))
        goto exit;

    hr = request->setHTTPMethod(methodBStr);
    if (FAILED(hr))
        goto exit;

    hr = frame->loadRequest(request);
    if (FAILED(hr))
        goto exit;

    SetFocus(gViewWindow);

exit:
    if (frame)
        frame->Release();
    if (request)
        request->Release();
}
void Init(HWND hWnd){
	init = true;
		HWND hwnd = GetActiveWindow();
		if(FAILED(WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&tab.m_mainWebView)))){
		MessageBox(0,L"FAILED TO CreateInstance!",L"ERROR",MB_OK);
	}
	if(FAILED(tab.m_mainWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hwnd)))){
		MessageBox(0,L"FAILED TO setHostWindow!",L"ERROR",MB_OK);
	}
	if(FAILED(tab.m_mainWebView->setUIDelegate(tab.tabui))){
		MessageBox(0,L"FAILED TO setUIDelegate!",L"ERROR",MB_OK);
	}
	tab.m_mainWebView->setPolicyDelegate(tab.tabpolicy);
	tab.m_mainWebView->setFrameLoadDelegate(tab.framedelegate);
	RECT rect;
	
	GetClientRect(hwnd,&rect);

	OleInitialize(0);
	//InitWithFrame 버그있어서 Init()
	if(FAILED(tab.m_mainWebView->initWithFrame(rect,SysAllocString(L"FRAME"),SysAllocString(L"GROUPNAME")))){
		MessageBox(0,L"FAILED TO INITWithFRAME!",L"ERROR",MB_OK);
		return;
	}
	
	if(FAILED(tab.m_mainWebView->mainFrame(&tab.m_mainWebFrame))){
		MessageBox(0,L"FAILED TO set mainFRAME!",L"ERROR",MB_OK);

	}

	BSTR str = SysAllocString(L"http://newheart.kr");//localhost/php/webkittest.php");
	IWebMutableURLRequest* req = 0;
	if(FAILED(WebKitCreateInstance(CLSID_WebMutableURLRequest,0,IID_IWebMutableURLRequest,reinterpret_cast<void**>(&req))))
	{
		MessageBox(0,L"ERROR!",L"ERROR",MB_OK);
	}
	    BSTR httpMethodBSTR;

		IPropertyBag* prop;

		if(FAILED(req->allHTTPHeaderFields(&prop))){
		MessageBox(0,L"PROPERTY ERROR!",L"ERROR",MB_OK);

		}
    if (FAILED(req->HTTPMethod(&httpMethodBSTR)))
        return;
	req->initWithURL(str,WebURLRequestUseProtocolCachePolicy,60);
	
		req->allHTTPHeaderFields(&prop);
	
		BSTR user_agent = SysAllocString(L"asd");
		req->valueForHTTPHeaderField(SysAllocString(L"User-Agent"), &user_agent);
		
	

	
	tab.m_mainWebFrame->loadRequest(req);
	

	if(req)
		req->Release();

}