예제 #1
0
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();
}
예제 #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();
}
예제 #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();
}