Page* WebChromeClient::createWindow(Frame*, const FrameLoadRequest& frameLoadRequest, const WindowFeatures& features) { if (features.dialog) { COMPtr<IWebUIDelegate> delegate = uiDelegate(); if (!delegate) return 0; COMPtr<IWebMutableURLRequest> request(AdoptCOM, WebMutableURLRequest::createInstance(frameLoadRequest.resourceRequest())); COMPtr<IWebView> dialog; if (FAILED(delegate->createModalDialog(m_webView, request.get(), &dialog))) return 0; return core(dialog.get()); } Page* page = 0; IWebUIDelegate* uiDelegate = 0; IWebMutableURLRequest* request = WebMutableURLRequest::createInstance(frameLoadRequest.resourceRequest()); if (SUCCEEDED(m_webView->uiDelegate(&uiDelegate))) { IWebView* webView = 0; if (SUCCEEDED(uiDelegate->createWebViewWithRequest(m_webView, request, &webView))) { page = core(webView); webView->Release(); } uiDelegate->Release(); } request->Release(); return page; }
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(); }
HRESULT STDMETHODCALLTYPE ResourceLoadDelegate::willSendRequest( /* [in] */ IWebView* webView, /* [in] */ unsigned long identifier, /* [in] */ IWebURLRequest* request, /* [in] */ IWebURLResponse* redirectResponse, /* [in] */ IWebDataSource* dataSource, /* [retval][out] */ IWebURLRequest **newRequest) { if (!done && gTestRunner->dumpResourceLoadCallbacks()) { printf("%S - willSendRequest %S redirectResponse %S\n", descriptionSuitableForTestResult(identifier).c_str(), descriptionSuitableForTestResult(request).c_str(), descriptionSuitableForTestResult(redirectResponse).c_str()); } if (!done && !gTestRunner->deferMainResourceDataLoad()) { COMPtr<IWebDataSourcePrivate> dataSourcePrivate(Query, dataSource); if (!dataSourcePrivate) return E_FAIL; dataSourcePrivate->setDeferMainResourceDataLoad(FALSE); } if (!done && gTestRunner->willSendRequestReturnsNull()) { *newRequest = 0; return S_OK; } if (!done && gTestRunner->willSendRequestReturnsNullOnRedirect() && redirectResponse) { printf("Returning null for this redirect\n"); *newRequest = 0; return S_OK; } IWebMutableURLRequest* requestCopy = 0; request->mutableCopy(&requestCopy); const set<string>& clearHeaders = gTestRunner->willSendRequestClearHeaders(); for (set<string>::const_iterator header = clearHeaders.begin(); header != clearHeaders.end(); ++header) { BSTR bstrHeader = BSTRFromString(*header); requestCopy->setValue(0, bstrHeader); SysFreeString(bstrHeader); } *newRequest = requestCopy; return S_OK; }
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(); }
HRESULT WinLauncherWebHost::updateAddressBar(IWebView* webView) { IWebFrame* mainFrame = 0; IWebDataSource* dataSource = 0; IWebMutableURLRequest* request = 0; BSTR frameURL = 0; HRESULT hr = S_OK; hr = webView->mainFrame(&mainFrame); if (FAILED(hr)) goto exit; hr = mainFrame->dataSource(&dataSource); if (FAILED(hr) || !dataSource) hr = mainFrame->provisionalDataSource(&dataSource); if (FAILED(hr) || !dataSource) goto exit; hr = dataSource->request(&request); if (FAILED(hr) || !request) goto exit; hr = request->mainDocumentURL(&frameURL); if (FAILED(hr)) goto exit; SendMessage(hURLBarWnd, (UINT)WM_SETTEXT, 0, (LPARAM)frameURL); exit: if (mainFrame) mainFrame->Release(); if (dataSource) dataSource->Release(); if (request) request->Release(); SysFreeString(frameURL); return 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(); }
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(); }
HRESULT ResourceLoadDelegate::willSendRequest(IWebView* webView, unsigned long identifier, IWebURLRequest* request, IWebURLResponse* redirectResponse, IWebDataSource* dataSource, IWebURLRequest** newRequest) { if (!done && gTestRunner->dumpResourceLoadCallbacks()) { printf("%S - willSendRequest %S redirectResponse %S\n", descriptionSuitableForTestResult(identifier).c_str(), descriptionSuitableForTestResult(request).c_str(), descriptionSuitableForTestResult(redirectResponse).c_str()); } if (!done && !gTestRunner->deferMainResourceDataLoad()) { COMPtr<IWebDataSourcePrivate> dataSourcePrivate(Query, dataSource); if (!dataSourcePrivate) { *newRequest = nullptr; return E_FAIL; } dataSourcePrivate->setDeferMainResourceDataLoad(FALSE); } if (!done && gTestRunner->willSendRequestReturnsNull()) { *newRequest = nullptr; return S_OK; } if (!done && gTestRunner->willSendRequestReturnsNullOnRedirect() && redirectResponse) { printf("Returning null for this redirect\n"); *newRequest = nullptr; return S_OK; } _bstr_t urlBstr; if (FAILED(request->URL(&urlBstr.GetBSTR()))) { printf("Request has no URL\n"); *newRequest = nullptr; return E_FAIL; } RetainPtr<CFStringRef> str = adoptCF(CFStringCreateWithCString(0, static_cast<const char*>(urlBstr), kCFStringEncodingWindowsLatin1)); RetainPtr<CFURLRef> url = adoptCF(CFURLCreateWithString(kCFAllocatorDefault, str.get(), nullptr)); if (url) { RetainPtr<CFStringRef> host = adoptCF(CFURLCopyHostName(url.get())); RetainPtr<CFStringRef> scheme = adoptCF(CFURLCopyScheme(url.get())); if (host && ((kCFCompareEqualTo == CFStringCompare(scheme.get(), CFSTR("http"), kCFCompareCaseInsensitive)) || (kCFCompareEqualTo == CFStringCompare(scheme.get(), CFSTR("https"), kCFCompareCaseInsensitive)))) { RetainPtr<CFStringRef> testURL = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, gTestRunner->testURL().c_str(), kCFStringEncodingWindowsLatin1)); RetainPtr<CFMutableStringRef> lowercaseTestURL = adoptCF(CFStringCreateMutableCopy(kCFAllocatorDefault, CFStringGetLength(testURL.get()), testURL.get())); RetainPtr<CFLocaleRef> locale = CFLocaleCopyCurrent(); CFStringLowercase(lowercaseTestURL.get(), locale.get()); RetainPtr<CFStringRef> testHost; if (CFStringHasPrefix(lowercaseTestURL.get(), CFSTR("http:")) || CFStringHasPrefix(lowercaseTestURL.get(), CFSTR("https:"))) { RetainPtr<CFURLRef> testPathURL = adoptCF(CFURLCreateWithString(kCFAllocatorDefault, lowercaseTestURL.get(), nullptr)); testHost = adoptCF(CFURLCopyHostName(testPathURL.get())); } if (!isLocalhost(host.get()) && !hostIsUsedBySomeTestsToGenerateError(host.get()) && (!testHost || isLocalhost(testHost.get()))) { printf("Blocked access to external URL %s\n", static_cast<const char*>(urlBstr)); *newRequest = nullptr; return S_OK; } } } IWebMutableURLRequest* requestCopy = 0; request->mutableCopy(&requestCopy); const set<string>& clearHeaders = gTestRunner->willSendRequestClearHeaders(); for (set<string>::const_iterator header = clearHeaders.begin(); header != clearHeaders.end(); ++header) { _bstr_t bstrHeader(header->data()); requestCopy->setValue(0, bstrHeader); } *newRequest = requestCopy; return S_OK; }