Page* WebChromeClient::createWindow(Frame* frame, const FrameLoadRequest&, const WindowFeatures& features, const NavigationAction& navigationAction) { COMPtr<IWebUIDelegate> delegate = uiDelegate(); if (!delegate) return 0; #if ENABLE(FULLSCREEN_API) if (frame->document() && frame->document()->webkitCurrentFullScreenElement()) frame->document()->webkitCancelFullScreen(); #endif COMPtr<WebMutableURLRequest> request = adoptCOM(WebMutableURLRequest::createInstance(ResourceRequest(navigationAction.url()))); COMPtr<IWebUIDelegatePrivate2> delegatePrivate(Query, delegate); if (delegatePrivate) { COMPtr<IWebView> newWebView; HRESULT hr = delegatePrivate->createWebViewWithRequest(m_webView, request.get(), createWindowFeaturesPropertyBag(features).get(), &newWebView); if (SUCCEEDED(hr) && newWebView) return core(newWebView.get()); // If the delegate doesn't implement the IWebUIDelegatePrivate2 version of the call, fall back // to the old versions (even if they support the IWebUIDelegatePrivate2 interface). if (hr != E_NOTIMPL) return 0; } COMPtr<IWebView> newWebView; if (features.dialog) { if (FAILED(delegate->createModalDialog(m_webView, request.get(), &newWebView))) return 0; } else if (FAILED(delegate->createWebViewWithRequest(m_webView, request.get(), &newWebView))) return 0; return newWebView ? core(newWebView.get()) : 0; }
void WebChromeClient::runJavaScriptAlert(Frame*, const String& message) { COMPtr<IWebUIDelegate> ui; if (SUCCEEDED(m_webView->uiDelegate(&ui))) ui->runJavaScriptAlertPanelWithMessage(m_webView, BString(message)); }
bool WebChromeClient::paintCustomScrollbar(GraphicsContext* context, const FloatRect& rect, ScrollbarControlSize size, ScrollbarControlState state, ScrollbarPart pressedPart, bool vertical, float value, float proportion, ScrollbarControlPartMask parts) { if (context->paintingDisabled()) return false; COMPtr<IWebUIDelegate> delegate = uiDelegate(); if (!delegate) return false; WebScrollbarControlPartMask webParts = WebNoScrollPart; if (parts & BackButtonStartPart) // FIXME: Hyatt, what about BackButtonEndPart? webParts |= WebBackButtonPart; if (parts & BackTrackPart) webParts |= WebBackTrackPart; if (parts & ThumbPart) webParts |= WebThumbPart; if (parts & ForwardTrackPart) webParts |= WebForwardTrackPart; if (parts & ForwardButtonStartPart) // FIXME: Hyatt, what about ForwardButtonEndPart? webParts |= WebForwardButtonPart; WebScrollbarControlPart webPressedPart = WebNoScrollPart; switch (pressedPart) { case BackButtonStartPart: // FIXME: Hyatt, what about BackButtonEndPart? webPressedPart = WebBackButtonPart; break; case BackTrackPart: webPressedPart = WebBackTrackPart; break; case ThumbPart: webPressedPart = WebThumbPart; break; case ForwardTrackPart: webPressedPart = WebForwardTrackPart; break; case ForwardButtonStartPart: // FIXME: Hyatt, what about ForwardButtonEndPart? webPressedPart = WebForwardButtonPart; break; default: break; } WebScrollBarControlSize webSize; switch (size) { case SmallScrollbar: webSize = WebSmallScrollbar; break; case RegularScrollbar: default: webSize = WebRegularScrollbar; } WebScrollbarControlState webState = 0; if (state & ActiveScrollbarState) webState |= WebActiveScrollbarState; if (state & EnabledScrollbarState) webState |= WebEnabledScrollbarState; if (state & PressedScrollbarState) webState |= WebPressedScrollbarState; RECT webRect = enclosingIntRect(rect); HDC hDC = context->getWindowsContext(webRect); HRESULT hr = delegate->paintCustomScrollbar(m_webView, hDC, webRect, webSize, webState, webPressedPart, vertical, value, proportion, webParts); context->releaseWindowsContext(hDC, webRect); return SUCCEEDED(hr); }
void TestRunner::clearBackForwardList() { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebBackForwardList> backForwardList; if (FAILED(webView->backForwardList(&backForwardList))) return; COMPtr<IWebHistoryItem> item; if (FAILED(backForwardList->currentItem(&item))) return; // We clear the history by setting the back/forward list's capacity to 0 // then restoring it back and adding back the current item. int capacity; if (FAILED(backForwardList->capacity(&capacity))) return; backForwardList->setCapacity(0); backForwardList->setCapacity(capacity); backForwardList->addItem(item.get()); backForwardList->goToItem(item.get()); }
// IWebHistoryDelegate HRESULT HistoryDelegate::didNavigateWithNavigationData(_In_opt_ IWebView* webView, _In_opt_ IWebNavigationData* navigationData, _In_opt_ IWebFrame* webFrame) { if (!gTestRunner->dumpHistoryDelegateCallbacks()) return S_OK; _bstr_t urlBSTR; if (FAILED(navigationData->url(&urlBSTR.GetBSTR()))) return E_FAIL; wstring url; if (urlBSTR.length()) url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR)); _bstr_t titleBSTR; if (FAILED(navigationData->title(&titleBSTR.GetBSTR()))) return E_FAIL; if (!static_cast<char*>(titleBSTR)) titleBSTR = L""; COMPtr<IWebURLRequest> request; if (FAILED(navigationData->originalRequest(&request))) return E_FAIL; _bstr_t httpMethodBSTR; if (FAILED(request->HTTPMethod(&httpMethodBSTR.GetBSTR()))) return E_FAIL; if (!static_cast<char*>(httpMethodBSTR)) httpMethodBSTR = L""; COMPtr<IWebURLResponse> response; if (FAILED(navigationData->response(&response))) return E_FAIL; COMPtr<IWebHTTPURLResponse> httpResponse; if (FAILED(response->QueryInterface(&httpResponse))) return E_FAIL; int statusCode = 0; if (FAILED(httpResponse->statusCode(&statusCode))) return E_FAIL; BOOL hasSubstituteData; if (FAILED(navigationData->hasSubstituteData(&hasSubstituteData))) return E_FAIL; _bstr_t clientRedirectSourceBSTR; if (FAILED(navigationData->clientRedirectSource(&clientRedirectSourceBSTR.GetBSTR()))) return E_FAIL; if (!static_cast<char*>(clientRedirectSourceBSTR)) clientRedirectSourceBSTR = L""; bool hasClientRedirect = clientRedirectSourceBSTR.length(); wstring redirectSource; if (clientRedirectSourceBSTR.length()) redirectSource = urlSuitableForTestResult(wstringFromBSTR(clientRedirectSourceBSTR)); bool wasFailure = hasSubstituteData || (httpResponse && statusCode >= 400); printf("WebView navigated to url \"%S\" with title \"%s\" with HTTP equivalent method \"%s\". The navigation was %s and was %s%S.\n", url.c_str(), static_cast<char*>(titleBSTR), static_cast<char*>(httpMethodBSTR), wasFailure ? "a failure" : "successful", hasClientRedirect ? "a client redirect from " : "not a client redirect", redirectSource.c_str()); return S_OK; }
static void runTest(const string& inputLine) { TestCommand command = parseInputLine(inputLine); const string& pathOrURL = command.pathOrURL; dumpPixelsForCurrentTest = command.shouldDumpPixels || dumpPixelsForAllTests; static BSTR methodBStr = SysAllocString(TEXT("GET")); BSTR urlBStr; CFStringRef str = CFStringCreateWithCString(0, pathOrURL.c_str(), kCFStringEncodingWindowsLatin1); CFURLRef url = CFURLCreateWithString(0, str, 0); if (!url) url = CFURLCreateWithFileSystemPath(0, str, kCFURLWindowsPathStyle, false); CFRelease(str); str = CFURLGetString(url); CFIndex length = CFStringGetLength(str); UniChar* buffer = new UniChar[length]; CFStringGetCharacters(str, CFRangeMake(0, length), buffer); urlBStr = SysAllocStringLen((OLECHAR*)buffer, length); delete[] buffer; CFRelease(url); ::gTestRunner = TestRunner::create(pathOrURL, command.expectedPixelHash); done = false; topLoadingFrame = 0; sizeWebViewForCurrentTest(); gTestRunner->setIconDatabaseEnabled(false); if (shouldLogFrameLoadDelegates(pathOrURL.c_str())) gTestRunner->setDumpFrameLoadCallbacks(true); COMPtr<IWebView> webView; if (SUCCEEDED(frame->webView(&webView))) { COMPtr<IWebViewPrivate> viewPrivate; if (SUCCEEDED(webView->QueryInterface(&viewPrivate))) { if (shouldLogHistoryDelegates(pathOrURL.c_str())) { gTestRunner->setDumpHistoryDelegateCallbacks(true); viewPrivate->setHistoryDelegate(sharedHistoryDelegate.get()); } else viewPrivate->setHistoryDelegate(0); } } COMPtr<IWebHistory> history; if (SUCCEEDED(WebKitCreateInstance(CLSID_WebHistory, 0, __uuidof(history), reinterpret_cast<void**>(&history)))) history->setOptionalSharedHistory(0); resetWebViewToConsistentStateBeforeTesting(); if (shouldEnableDeveloperExtras(pathOrURL.c_str())) { gTestRunner->setDeveloperExtrasEnabled(true); if (shouldOpenWebInspector(pathOrURL.c_str())) gTestRunner->showWebInspector(); } if (shouldDumpAsText(pathOrURL.c_str())) { gTestRunner->setDumpAsText(true); gTestRunner->setGeneratePixelResults(false); } prevTestBFItem = 0; if (webView) { COMPtr<IWebBackForwardList> bfList; if (SUCCEEDED(webView->backForwardList(&bfList))) bfList->currentItem(&prevTestBFItem); } WorkQueue::shared()->clear(); WorkQueue::shared()->setFrozen(false); HWND hostWindow; webView->hostWindow(reinterpret_cast<OLE_HANDLE*>(&hostWindow)); COMPtr<IWebMutableURLRequest> request; HRESULT hr = WebKitCreateInstance(CLSID_WebMutableURLRequest, 0, IID_IWebMutableURLRequest, (void**)&request); if (FAILED(hr)) goto exit; request->initWithURL(urlBStr, WebURLRequestUseProtocolCachePolicy, 60); request->setHTTPMethod(methodBStr); frame->loadRequest(request.get()); MSG msg; while (GetMessage(&msg, 0, 0, 0)) { // We get spurious WM_MOUSELEAVE events which make event handling machinery think that mouse button // is released during dragging (see e.g. fast\dynamic\layer-hit-test-crash.html). // Mouse can never leave WebView during normal DumpRenderTree operation, so we just ignore all such events. if (msg.message == WM_MOUSELEAVE) continue; TranslateMessage(&msg); DispatchMessage(&msg); } if (shouldEnableDeveloperExtras(pathOrURL.c_str())) { gTestRunner->closeWebInspector(); gTestRunner->setDeveloperExtrasEnabled(false); } resetWebViewToConsistentStateBeforeTesting(); frame->stopLoading(); if (::gTestRunner->closeRemainingWindowsWhenComplete()) { Vector<HWND> windows = openWindows(); unsigned size = windows.size(); for (unsigned i = 0; i < size; i++) { HWND window = windows[i]; // Don't try to close the main window if (window == hostWindow) continue; DestroyWindow(window); } } exit: SysFreeString(urlBStr); ::gTestRunner.clear(); return; }
void WebEventListener::handleEvent(WebCore::ScriptExecutionContext* s, WebCore::Event* e) { RefPtr<WebCore::Event> ePtr(e); COMPtr<IDOMEvent> domEvent = DOMEvent::createInstance(ePtr); m_iDOMEventListener->handleEvent(domEvent.get()); }
// deprecated - remove once a registry-free version of Safari has shipped (first major version after 3.1.1) static void registerWebKitNightly() { // look up server's file name TCHAR szFileName[MAX_PATH]; GetModuleFileName(gInstance, szFileName, MAX_PATH); typedef HRESULT (WINAPI *RegisterTypeLibForUserPtr)(ITypeLib*, OLECHAR*, OLECHAR*); COMPtr<ITypeLib> typeLib; LoadTypeLibEx(szFileName, REGKIND_NONE, &typeLib); if (RegisterTypeLibForUserPtr registerTypeLibForUser = reinterpret_cast<RegisterTypeLibForUserPtr>(GetProcAddress(GetModuleHandle(TEXT("oleaut32.dll")), "RegisterTypeLibForUser"))) registerTypeLibForUser(typeLib.get(), szFileName, 0); else RegisterTypeLib(typeLib.get(), szFileName, 0); HKEY userClasses; if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\CLASSES"), 0, KEY_WRITE, &userClasses) != ERROR_SUCCESS) userClasses = 0; // register entries from table int nEntries = ARRAYSIZE(gRegTable); HRESULT hr = S_OK; for (int i = 0; SUCCEEDED(hr) && i < nEntries; i++) { LPTSTR pszKeyName = _tcsdup(gRegTable[i][0]); LPTSTR pszValueName = gRegTable[i][1] ? _tcsdup(gRegTable[i][1]) : 0; LPTSTR allocatedValue = (gRegTable[i][2] != (LPTSTR)-1) ? _tcsdup(gRegTable[i][2]) : (LPTSTR)-1; LPTSTR pszValue = allocatedValue; if (pszKeyName && pszValue) { int clsidIndex = i/gSlotsPerEntry; substituteGUID(pszKeyName, &gRegCLSIDs[clsidIndex]); substituteGUID(pszValueName, &gRegCLSIDs[clsidIndex]); // map rogue value to module file name if (pszValue == (LPTSTR)-1) pszValue = szFileName; else substituteGUID(pszValue, &gRegCLSIDs[clsidIndex]); // create the key HKEY hkey; LONG err = RegCreateKey(HKEY_CLASSES_ROOT, pszKeyName, &hkey); if (err != ERROR_SUCCESS && userClasses) err = RegCreateKey(userClasses, pszKeyName, &hkey); if (err == ERROR_SUCCESS) { // set the value err = RegSetValueEx(hkey, pszValueName, 0, REG_SZ, (const BYTE*)pszValue, (DWORD) sizeof(pszValue[0])*(_tcslen(pszValue) + 1)); RegCloseKey(hkey); } } if (pszKeyName) free(pszKeyName); if (pszValueName) free(pszValueName); if (allocatedValue && allocatedValue != (LPTSTR)-1) free(allocatedValue); } if (userClasses) RegCloseKey(userClasses); }
static JSValueRef beginDragWithFilesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); JSObjectRef filesArray = JSValueToObject(context, arguments[0], 0); if (!filesArray) return JSValueMakeUndefined(context); JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); Vector<UChar> files; int filesCount = JSValueToNumber(context, JSObjectGetProperty(context, filesArray, lengthProperty, 0), 0); for (int i = 0; i < filesCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, filesArray, i, 0); JSStringRef file = JSValueToStringCopy(context, value, 0); files.append(JSStringGetCharactersPtr(file), JSStringGetLength(file)); files.append(0); JSStringRelease(file); } if (files.isEmpty()) return JSValueMakeUndefined(context); // We should append "0" in the end of |files| so that |DragQueryFileW| retrieved the number of files correctly from Ole Clipboard. files.append(0); STGMEDIUM hDropMedium = {0}; hDropMedium.tymed = TYMED_HGLOBAL; SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * files.size()); hDropMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, dropFilesSize); if (!hDropMedium.hGlobal) return JSValueMakeUndefined(context); DROPFILES* dropFiles = reinterpret_cast<DROPFILES*>(GlobalLock(hDropMedium.hGlobal)); memset(dropFiles, 0, sizeof(DROPFILES)); dropFiles->pFiles = sizeof(DROPFILES); dropFiles->fWide = TRUE; UChar* data = reinterpret_cast<UChar*>(reinterpret_cast<BYTE*>(dropFiles) + sizeof(DROPFILES)); for (size_t i = 0; i < files.size(); ++i) data[i] = files[i]; GlobalUnlock(hDropMedium.hGlobal); STGMEDIUM hFileNameMedium = {0}; hFileNameMedium.tymed = TYMED_HGLOBAL; SIZE_T hFileNameSize = sizeof(WCHAR) * files.size(); hFileNameMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, hFileNameSize); if (!hFileNameMedium.hGlobal) return JSValueMakeUndefined(context); WCHAR* hFileName = static_cast<WCHAR*>(GlobalLock(hFileNameMedium.hGlobal)); for (size_t i = 0; i < files.size(); i++) hFileName[i] = files[i]; GlobalUnlock(hFileNameMedium.hGlobal); if (draggingInfo) { delete draggingInfo; draggingInfo = 0; } COMPtr<DRTDataObject> dataObeject; COMPtr<IDropSource> source; if (FAILED(DRTDataObject::createInstance(&dataObeject))) dataObeject = 0; if (FAILED(DRTDropSource::createInstance(&source))) source = 0; if (dataObeject && source) { draggingInfo = new DraggingInfo(dataObeject.get(), source.get()); draggingInfo->setPerformedDropEffect(DROPEFFECT_COPY); } if (draggingInfo) { draggingInfo->dataObject()->SetData(cfHDropFormat(), &hDropMedium, FALSE); draggingInfo->dataObject()->SetData(cfFileNameWFormat(), &hFileNameMedium, FALSE); draggingInfo->dataObject()->SetData(cfUrlWFormat(), &hFileNameMedium, FALSE); OleSetClipboard(draggingInfo->dataObject()); down = true; } JSStringRelease(lengthProperty); return JSValueMakeUndefined(context); }
// IWebHistoryDelegate HRESULT HistoryDelegate::didNavigateWithNavigationData(IWebView* webView, IWebNavigationData* navigationData, IWebFrame* webFrame) { if (!gTestRunner->dumpHistoryDelegateCallbacks()) return S_OK; BSTR urlBSTR; if (FAILED(navigationData->url(&urlBSTR))) return E_FAIL; wstring url; if (urlBSTR) url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR)); SysFreeString(urlBSTR); BSTR titleBSTR; if (FAILED(navigationData->title(&titleBSTR))) return E_FAIL; wstring title; if (titleBSTR) title = wstringFromBSTR(titleBSTR); SysFreeString(titleBSTR); COMPtr<IWebURLRequest> request; if (FAILED(navigationData->originalRequest(&request))) return E_FAIL; BSTR httpMethodBSTR; if (FAILED(request->HTTPMethod(&httpMethodBSTR))) return E_FAIL; wstring httpMethod; if (httpMethodBSTR) httpMethod = wstringFromBSTR(httpMethodBSTR); SysFreeString(httpMethodBSTR); COMPtr<IWebURLResponse> response; if (FAILED(navigationData->response(&response))) return E_FAIL; COMPtr<IWebHTTPURLResponse> httpResponse; if (FAILED(response->QueryInterface(&httpResponse))) return E_FAIL; int statusCode = 0; if (FAILED(httpResponse->statusCode(&statusCode))) return E_FAIL; BOOL hasSubstituteData; if (FAILED(navigationData->hasSubstituteData(&hasSubstituteData))) return E_FAIL; BSTR clientRedirectSourceBSTR; if (FAILED(navigationData->clientRedirectSource(&clientRedirectSourceBSTR))) return E_FAIL; bool hasClientRedirect = clientRedirectSourceBSTR && SysStringLen(clientRedirectSourceBSTR); wstring redirectSource; if (clientRedirectSourceBSTR) redirectSource = urlSuitableForTestResult(wstringFromBSTR(clientRedirectSourceBSTR)); SysFreeString(clientRedirectSourceBSTR); bool wasFailure = hasSubstituteData || (httpResponse && statusCode >= 400); printf("WebView navigated to url \"%S\" with title \"%S\" with HTTP equivalent method \"%S\". The navigation was %s and was %s%S.\n", url.c_str(), title.c_str(), httpMethod.c_str(), wasFailure ? "a failure" : "successful", hasClientRedirect ? "a client redirect from " : "not a client redirect", redirectSource.c_str()); return S_OK; }
GEN_DOMNode* GEN_DOMNode::createInstance(WebCore::Node* node) { if (!node) return 0; if (GEN_DOMObject* cachedInstance = getDOMWrapper(node)) { cachedInstance->AddRef(); return static_cast<GEN_DOMNode*>(cachedInstance); } COMPtr<GEN_DOMNode> domNode; switch (node->nodeType()) { case WebCore::Node::ELEMENT_NODE: // FIXME: add support for creating subclasses of HTMLElement. // FIXME: add support for creating SVGElements and its subclasses. if (node->isHTMLElement()) domNode = new GEN_DOMHTMLElement(static_cast<WebCore::HTMLElement*>(node)); else domNode = new GEN_DOMElement(static_cast<WebCore::Element*>(node)); break; case WebCore::Node::ATTRIBUTE_NODE: domNode = new GEN_DOMAttr(static_cast<WebCore::Attr*>(node)); break; case WebCore::Node::TEXT_NODE: domNode = new GEN_DOMText(static_cast<WebCore::Text*>(node)); break; case WebCore::Node::CDATA_SECTION_NODE: domNode = new GEN_DOMCDATASection(static_cast<WebCore::CDATASection*>(node)); break; case WebCore::Node::ENTITY_REFERENCE_NODE: domNode = new GEN_DOMEntityReference(static_cast<WebCore::EntityReference*>(node)); break; case WebCore::Node::ENTITY_NODE: domNode = new GEN_DOMEntity(static_cast<WebCore::Entity*>(node)); break; case WebCore::Node::PROCESSING_INSTRUCTION_NODE: domNode = new GEN_DOMProcessingInstruction(static_cast<WebCore::ProcessingInstruction*>(node)); break; case WebCore::Node::COMMENT_NODE: domNode = new GEN_DOMComment(static_cast<WebCore::Comment*>(node)); break; case WebCore::Node::DOCUMENT_NODE: // FIXME: add support for SVGDocument. if (static_cast<WebCore::Document*>(node)->isHTMLDocument()) domNode = new GEN_DOMHTMLDocument(static_cast<WebCore::HTMLDocument*>(node)); else domNode = new GEN_DOMDocument(static_cast<WebCore::Document*>(node)); break; case WebCore::Node::DOCUMENT_TYPE_NODE: domNode = new GEN_DOMDocumentType(static_cast<WebCore::DocumentType*>(node)); break; case WebCore::Node::DOCUMENT_FRAGMENT_NODE: domNode = new GEN_DOMDocumentFragment(static_cast<WebCore::DocumentFragment*>(node)); break; case WebCore::Node::NOTATION_NODE: domNode = new GEN_DOMNotation(static_cast<WebCore::Notation*>(node)); break; default: domNode = new GEN_DOMNode(node); break; } setDOMWrapper(node, domNode.get()); return domNode.releaseRef(); }
static void resetWebViewToConsistentStateBeforeTesting() { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; webView->setPolicyDelegate(0); policyDelegate->setPermissive(false); policyDelegate->setControllerToNotifyDone(0); COMPtr<IWebIBActions> webIBActions(Query, webView); if (webIBActions) { webIBActions->makeTextStandardSize(0); webIBActions->resetPageZoom(0); } COMPtr<IWebPreferences> preferences; if (SUCCEEDED(webView->preferences(&preferences))) resetDefaultsToConsistentValues(preferences.get()); COMPtr<IWebViewEditing> viewEditing; if (SUCCEEDED(webView->QueryInterface(&viewEditing))) viewEditing->setSmartInsertDeleteEnabled(TRUE); COMPtr<IWebViewPrivate> webViewPrivate(Query, webView); if (!webViewPrivate) return; COMPtr<IWebInspector> inspector; if (SUCCEEDED(webViewPrivate->inspector(&inspector))) inspector->setJavaScriptProfilingEnabled(FALSE); HWND viewWindow; if (SUCCEEDED(webViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))) && viewWindow) SetFocus(viewWindow); webViewPrivate->clearMainFrameName(); webViewPrivate->resetOriginAccessWhiteLists(); sharedUIDelegate->resetUndoManager(); sharedFrameLoadDelegate->resetToConsistentState(); }
void dump() { invalidateAnyPreviousWaitToDumpWatchdog(); COMPtr<IWebDataSource> dataSource; if (SUCCEEDED(frame->dataSource(&dataSource))) { COMPtr<IWebURLResponse> response; if (SUCCEEDED(dataSource->response(&response)) && response) { BSTR mimeType; if (SUCCEEDED(response->MIMEType(&mimeType))) ::gLayoutTestController->setDumpAsText(::gLayoutTestController->dumpAsText() | !_tcscmp(mimeType, TEXT("text/plain"))); SysFreeString(mimeType); } } BSTR resultString = 0; if (dumpTree) { if (::gLayoutTestController->dumpAsText()) { ::InvalidateRect(webViewWindow, 0, TRUE); ::SendMessage(webViewWindow, WM_PAINT, 0, 0); wstring result = dumpFramesAsText(frame); resultString = SysAllocStringLen(result.data(), result.size()); } else { bool isSVGW3CTest = (gLayoutTestController->testPathOrURL().find("svg\\W3C-SVG-1.1") != string::npos); unsigned width; unsigned height; if (isSVGW3CTest) { width = 480; height = 360; } else { width = maxViewWidth; height = maxViewHeight; } ::SetWindowPos(webViewWindow, 0, 0, 0, width, height, SWP_NOMOVE); ::InvalidateRect(webViewWindow, 0, TRUE); ::SendMessage(webViewWindow, WM_PAINT, 0, 0); COMPtr<IWebFramePrivate> framePrivate; if (FAILED(frame->QueryInterface(&framePrivate))) goto fail; framePrivate->renderTreeAsExternalRepresentation(&resultString); } if (!resultString) printf("ERROR: nil result from %s", ::gLayoutTestController->dumpAsText() ? "IDOMElement::innerText" : "IFrameViewPrivate::renderTreeAsExternalRepresentation"); else { unsigned stringLength = SysStringLen(resultString); int bufferSize = ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, 0, 0, 0, 0); char* buffer = (char*)malloc(bufferSize + 1); ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, buffer, bufferSize + 1, 0, 0); fwrite(buffer, 1, bufferSize, stdout); free(buffer); if (!::gLayoutTestController->dumpAsText()) dumpFrameScrollPosition(frame); } if (::gLayoutTestController->dumpBackForwardList()) dumpBackForwardListForAllWindows(); } if (printSeparators) { puts("#EOF"); // terminate the content block fputs("#EOF\n", stderr); fflush(stdout); fflush(stderr); } if (dumpPixels) { if (!gLayoutTestController->dumpAsText() && !gLayoutTestController->dumpDOMAsWebArchive() && !gLayoutTestController->dumpSourceAsWebArchive()) dumpWebViewAsPixelsAndCompareWithExpected(gLayoutTestController->expectedPixelHash()); } printf("#EOF\n"); // terminate the (possibly empty) pixels block fflush(stdout); fail: SysFreeString(resultString); // This will exit from our message loop. PostQuitMessage(0); done = true; }
int main(int argc, char* argv[]) { leakChecking = false; _setmode(1, _O_BINARY); _setmode(2, _O_BINARY); initialize(); Vector<const char*> tests; for (int i = 1; i < argc; ++i) { if (!stricmp(argv[i], "--threaded")) { threaded = true; continue; } if (!stricmp(argv[i], "--dump-all-pixels")) { dumpAllPixels = true; continue; } if (!stricmp(argv[i], "--pixel-tests")) { dumpPixels = true; continue; } if (!stricmp(argv[i], "--complex-text")) { forceComplexText = true; continue; } tests.append(argv[i]); } policyDelegate = new PolicyDelegate(); sharedFrameLoadDelegate.adoptRef(new FrameLoadDelegate); sharedUIDelegate.adoptRef(new UIDelegate); sharedEditingDelegate.adoptRef(new EditingDelegate); sharedResourceLoadDelegate.adoptRef(new ResourceLoadDelegate); sharedHistoryDelegate.adoptRef(new HistoryDelegate); // FIXME - need to make DRT pass with Windows native controls <http://bugs.webkit.org/show_bug.cgi?id=25592> COMPtr<IWebPreferences> tmpPreferences; if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences)))) return -1; COMPtr<IWebPreferences> standardPreferences; if (FAILED(tmpPreferences->standardPreferences(&standardPreferences))) return -1; COMPtr<IWebPreferencesPrivate> standardPreferencesPrivate; if (FAILED(standardPreferences->QueryInterface(&standardPreferencesPrivate))) return -1; standardPreferencesPrivate->setShouldPaintNativeControls(FALSE); standardPreferences->setJavaScriptEnabled(TRUE); standardPreferences->setDefaultFontSize(16); COMPtr<IWebView> webView(AdoptCOM, createWebViewAndOffscreenWindow(&webViewWindow)); if (!webView) return -1; COMPtr<IWebIconDatabase> iconDatabase; COMPtr<IWebIconDatabase> tmpIconDatabase; if (FAILED(WebKitCreateInstance(CLSID_WebIconDatabase, 0, IID_IWebIconDatabase, (void**)&tmpIconDatabase))) return -1; if (FAILED(tmpIconDatabase->sharedIconDatabase(&iconDatabase))) return -1; if (FAILED(webView->mainFrame(&frame))) return -1; #if USE(CFNETWORK) RetainPtr<CFURLCacheRef> urlCache = sharedCFURLCache(); CFURLCacheRemoveAllCachedResponses(urlCache.get()); #endif #ifdef _DEBUG _CrtMemState entryToMainMemCheckpoint; if (leakChecking) _CrtMemCheckpoint(&entryToMainMemCheckpoint); #endif if (threaded) startJavaScriptThreads(); if (tests.size() == 1 && !strcmp(tests[0], "-")) { char filenameBuffer[2048]; printSeparators = true; while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) { char* newLineCharacter = strchr(filenameBuffer, '\n'); if (newLineCharacter) *newLineCharacter = '\0'; if (strlen(filenameBuffer) == 0) continue; runTest(filenameBuffer); } } else { printSeparators = tests.size() > 1; for (int i = 0; i < tests.size(); i++) runTest(tests[i]); } if (threaded) stopJavaScriptThreads(); delete policyDelegate; frame->Release(); #ifdef _DEBUG if (leakChecking) { // dump leaks to stderr _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtMemDumpAllObjectsSince(&entryToMainMemCheckpoint); } #endif shutDownWebKit(); return 0; }
void dump() { invalidateAnyPreviousWaitToDumpWatchdog(); COMPtr<IWebDataSource> dataSource; if (SUCCEEDED(frame->dataSource(&dataSource))) { COMPtr<IWebURLResponse> response; if (SUCCEEDED(dataSource->response(&response)) && response) { BSTR mimeType; if (SUCCEEDED(response->MIMEType(&mimeType)) && !_tcscmp(mimeType, TEXT("text/plain"))) { ::gTestRunner->setDumpAsText(true); ::gTestRunner->setGeneratePixelResults(false); } SysFreeString(mimeType); } } BSTR resultString = 0; if (dumpTree) { ::InvalidateRect(webViewWindow, 0, TRUE); ::SendMessage(webViewWindow, WM_PAINT, 0, 0); if (::gTestRunner->dumpAsText()) { wstring result = dumpFramesAsText(frame); resultString = SysAllocStringLen(result.data(), result.size()); } else { COMPtr<IWebFramePrivate> framePrivate; if (FAILED(frame->QueryInterface(&framePrivate))) goto fail; framePrivate->renderTreeAsExternalRepresentation(gTestRunner->isPrinting(), &resultString); } if (!resultString) printf("ERROR: nil result from %s", ::gTestRunner->dumpAsText() ? "IDOMElement::innerText" : "IFrameViewPrivate::renderTreeAsExternalRepresentation"); else { unsigned stringLength = SysStringLen(resultString); int bufferSize = ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, 0, 0, 0, 0); char* buffer = (char*)malloc(bufferSize + 1); ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, buffer, bufferSize + 1, 0, 0); fwrite(buffer, 1, bufferSize, stdout); free(buffer); if (!::gTestRunner->dumpAsText()) dumpFrameScrollPosition(frame); } if (::gTestRunner->dumpBackForwardList()) dumpBackForwardListForAllWindows(); } if (printSeparators) { puts("#EOF"); // terminate the content block fputs("#EOF\n", stderr); fflush(stdout); fflush(stderr); } if (dumpPixelsForCurrentTest && gTestRunner->generatePixelResults() && !gTestRunner->dumpDOMAsWebArchive() && !gTestRunner->dumpSourceAsWebArchive()) dumpWebViewAsPixelsAndCompareWithExpected(gTestRunner->expectedPixelHash()); printf("#EOF\n"); // terminate the (possibly empty) pixels block fflush(stdout); fail: SysFreeString(resultString); // This will exit from our message loop. PostQuitMessage(0); done = true; }
static COMPtr<IAccessibleComparable> comparableObject(const COMPtr<IServiceProvider>& serviceProvider) { COMPtr<IAccessibleComparable> comparable; serviceProvider->QueryService(SID_AccessibleComparable, __uuidof(IAccessibleComparable), reinterpret_cast<void**>(&comparable)); return comparable; }
static void resetWebViewToConsistentStateBeforeTesting() { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; webView->setPolicyDelegate(0); policyDelegate->setPermissive(false); policyDelegate->setControllerToNotifyDone(0); COMPtr<IWebIBActions> webIBActions(Query, webView); if (webIBActions) { webIBActions->makeTextStandardSize(0); webIBActions->resetPageZoom(0); } COMPtr<IWebPreferences> preferences; if (SUCCEEDED(webView->preferences(&preferences))) resetDefaultsToConsistentValues(preferences.get()); if (gTestRunner) { JSGlobalContextRef context = frame->globalContext(); WebCoreTestSupport::resetInternalsObject(context); } COMPtr<IWebViewEditing> viewEditing; if (SUCCEEDED(webView->QueryInterface(&viewEditing))) viewEditing->setSmartInsertDeleteEnabled(TRUE); COMPtr<IWebViewPrivate> webViewPrivate(Query, webView); if (!webViewPrivate) return; double minimumInterval = 0; if (SUCCEEDED(webViewPrivate->defaultMinimumTimerInterval(&minimumInterval))) webViewPrivate->setMinimumTimerInterval(minimumInterval); HWND viewWindow; if (SUCCEEDED(webViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))) && viewWindow) SetFocus(viewWindow); webViewPrivate->clearMainFrameName(); webViewPrivate->resetOriginAccessWhitelists(); BSTR groupName; if (SUCCEEDED(webView->groupName(&groupName))) { webViewPrivate->removeAllUserContentFromGroup(groupName); SysFreeString(groupName); } sharedUIDelegate->resetUndoManager(); sharedFrameLoadDelegate->resetToConsistentState(); COMPtr<IWebFramePrivate> framePrivate; if (SUCCEEDED(frame->QueryInterface(&framePrivate))) framePrivate->clearOpener(); }
void EmbeddedWidget::didReceiveData(const char* data, int length) { COMPtr<MemoryStream> stream = MemoryStream::createInstance(SharedBuffer::create(data, length)); m_view->didReceiveData(stream.get()); }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static const JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); COMPtr<IWebFramePrivate> framePrivate; if (SUCCEEDED(frame->QueryInterface(&framePrivate))) framePrivate->layout(); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); ASSERT(!*exception); int virtualKeyCode; int charCode = 0; int keyData = 1; bool needsShiftKeyModifier = false; if (JSStringIsEqualToUTF8CString(character, "leftArrow")) { virtualKeyCode = VK_LEFT; keyData += KF_EXTENDED << 16; // In this case, extended means "not keypad". } else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) { virtualKeyCode = VK_RIGHT; keyData += KF_EXTENDED << 16; } else if (JSStringIsEqualToUTF8CString(character, "upArrow")) { virtualKeyCode = VK_UP; keyData += KF_EXTENDED << 16; } else if (JSStringIsEqualToUTF8CString(character, "downArrow")) { virtualKeyCode = VK_DOWN; keyData += KF_EXTENDED << 16; } else if (JSStringIsEqualToUTF8CString(character, "pageUp")) virtualKeyCode = VK_PRIOR; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) virtualKeyCode = VK_NEXT; else if (JSStringIsEqualToUTF8CString(character, "home")) virtualKeyCode = VK_HOME; else if (JSStringIsEqualToUTF8CString(character, "end")) virtualKeyCode = VK_END; else if (JSStringIsEqualToUTF8CString(character, "delete")) virtualKeyCode = VK_BACK; else { charCode = JSStringGetCharactersPtr(character)[0]; virtualKeyCode = LOBYTE(VkKeyScan(charCode)); if (WTF::isASCIIUpper(charCode)) needsShiftKeyModifier = true; } JSStringRelease(character); BYTE keyState[256]; if (argumentCount > 1 || needsShiftKeyModifier) { ::GetKeyboardState(keyState); BYTE newKeyState[256]; memcpy(newKeyState, keyState, sizeof(keyState)); if (needsShiftKeyModifier) newKeyState[VK_SHIFT] = 0x80; if (argumentCount > 1) { JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], 0); if (modifiersArray) { int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); for (int i = 0; i < modifiersCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqualToUTF8CString(string, "ctrlKey")) newKeyState[VK_CONTROL] = 0x80; else if (JSStringIsEqualToUTF8CString(string, "shiftKey")) newKeyState[VK_SHIFT] = 0x80; else if (JSStringIsEqualToUTF8CString(string, "altKey")) newKeyState[VK_MENU] = 0x80; JSStringRelease(string); } } } ::SetKeyboardState(newKeyState); } MSG msg = makeMsg(webViewWindow, (::GetKeyState(VK_MENU) & 0x8000) ? WM_SYSKEYDOWN : WM_KEYDOWN, virtualKeyCode, keyData); if (virtualKeyCode != 255) dispatchMessage(&msg); else { // For characters that do not exist in the active keyboard layout, // ::Translate will not work, so we post an WM_CHAR event ourselves. ::PostMessage(webViewWindow, WM_CHAR, charCode, 0); } // Tests expect that all messages are processed by the time keyDown() returns. if (::PeekMessage(&msg, webViewWindow, WM_CHAR, WM_CHAR, PM_REMOVE) || ::PeekMessage(&msg, webViewWindow, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE)) ::DispatchMessage(&msg); MSG msgUp = makeMsg(webViewWindow, (::GetKeyState(VK_MENU) & 0x8000) ? WM_SYSKEYUP : WM_KEYUP, virtualKeyCode, keyData); ::DispatchMessage(&msgUp); if (argumentCount > 1 || needsShiftKeyModifier) ::SetKeyboardState(keyState); return JSValueMakeUndefined(context); }
IWebView* createWebViewAndOffscreenWindow(HWND* webViewWindow) { unsigned maxViewWidth = TestRunner::maxViewWidth; unsigned maxViewHeight = TestRunner::maxViewHeight; HWND hostWindow = CreateWindowEx(WS_EX_TOOLWINDOW, kDumpRenderTreeClassName, TEXT("DumpRenderTree"), WS_POPUP, -maxViewWidth, -maxViewHeight, maxViewWidth, maxViewHeight, 0, 0, GetModuleHandle(0), 0); IWebView* webView; HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, (void**)&webView); if (FAILED(hr)) { fprintf(stderr, "Failed to create CLSID_WebView instance, error 0x%x\n", hr); return 0; } if (FAILED(webView->setHostWindow((OLE_HANDLE)(ULONG64)hostWindow))) return 0; RECT clientRect; clientRect.bottom = clientRect.left = clientRect.top = clientRect.right = 0; BSTR groupName = SysAllocString(L"org.webkit.DumpRenderTree"); bool failed = FAILED(webView->initWithFrame(clientRect, 0, groupName)); SysFreeString(groupName); if (failed) return 0; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return 0; viewPrivate->setShouldApplyMacFontAscentHack(TRUE); viewPrivate->setAlwaysUsesComplexTextCodePath(forceComplexText); BSTR pluginPath = SysAllocStringLen(0, exePath().length() + _tcslen(TestPluginDir)); _tcscpy(pluginPath, exePath().c_str()); _tcscat(pluginPath, TestPluginDir); failed = FAILED(viewPrivate->addAdditionalPluginDirectory(pluginPath)); SysFreeString(pluginPath); if (failed) return 0; HWND viewWindow; if (FAILED(viewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow)))) return 0; if (webViewWindow) *webViewWindow = viewWindow; SetWindowPos(viewWindow, 0, 0, 0, maxViewWidth, maxViewHeight, 0); ShowWindow(hostWindow, SW_SHOW); if (FAILED(webView->setFrameLoadDelegate(sharedFrameLoadDelegate.get()))) return 0; if (FAILED(viewPrivate->setFrameLoadDelegatePrivate(sharedFrameLoadDelegate.get()))) return 0; if (FAILED(webView->setUIDelegate(sharedUIDelegate.get()))) return 0; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return 0; if (FAILED(viewEditing->setEditingDelegate(sharedEditingDelegate.get()))) return 0; ResourceLoadDelegate* resourceLoadDelegate = new ResourceLoadDelegate(); HRESULT result = webView->setResourceLoadDelegate(resourceLoadDelegate); resourceLoadDelegate->Release(); // The delegate is owned by the WebView, so release our reference to it. if (FAILED(result)) return 0; openWindows().append(hostWindow); windowToWebViewMap().set(hostWindow, webView); return webView; }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static JSStringRef ctrlKey = JSStringCreateWithUTF8CString("ctrlKey"); static JSStringRef shiftKey = JSStringCreateWithUTF8CString("shiftKey"); static JSStringRef altKey = JSStringCreateWithUTF8CString("altKey"); static JSStringRef metaKey = JSStringCreateWithUTF8CString("metaKey"); static JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); COMPtr<IWebFramePrivate> framePrivate; if (SUCCEEDED(frame->QueryInterface(&framePrivate))) framePrivate->layout(); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); ASSERT(!exception || !*exception); int charCode = JSStringGetCharactersPtr(character)[0]; int virtualKeyCode = toupper(LOBYTE(VkKeyScan(charCode))); JSStringRelease(character); // Hack to map option-delete to ctrl-delete // Remove this when we fix <rdar://problem/5102974> layout tests need a way to decide how to choose the appropriate modifier keys bool convertOptionToCtrl = false; if (virtualKeyCode == VK_DELETE || virtualKeyCode == VK_BACK) convertOptionToCtrl = true; BYTE keyState[256]; if (argumentCount > 1) { ::GetKeyboardState(keyState); BYTE newKeyState[256]; memcpy(newKeyState, keyState, sizeof(keyState)); JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception); if (modifiersArray) { int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); for (int i = 0; i < modifiersCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqual(string, ctrlKey)) newKeyState[VK_CONTROL] = 0x80; else if (JSStringIsEqual(string, shiftKey)) newKeyState[VK_SHIFT] = 0x80; else if (JSStringIsEqual(string, altKey)) { if (convertOptionToCtrl) newKeyState[VK_CONTROL] = 0x80; else newKeyState[VK_MENU] = 0x80; } else if (JSStringIsEqual(string, metaKey)) newKeyState[VK_MENU] = 0x80; JSStringRelease(string); } } ::SetKeyboardState(newKeyState); } MSG msg = makeMsg(webViewWindow, WM_KEYDOWN, virtualKeyCode, 0); dispatchMessage(&msg); if (argumentCount > 1) ::SetKeyboardState(keyState); return JSValueMakeUndefined(context); }
extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(int argc, const char* argv[]) { // Cygwin calls ::SetErrorMode(SEM_FAILCRITICALERRORS), which we will inherit. This is bad for // testing/debugging, as it causes the post-mortem debugger not to be invoked. We reset the // error mode here to work around Cygwin's behavior. See <http://webkit.org/b/55222>. ::SetErrorMode(0); ::SetUnhandledExceptionFilter(exceptionFilter); leakChecking = false; _setmode(1, _O_BINARY); _setmode(2, _O_BINARY); initialize(); Vector<const char*> tests; for (int i = 1; i < argc; ++i) { if (!stricmp(argv[i], "--threaded")) { threaded = true; continue; } if (!stricmp(argv[i], "--dump-all-pixels")) { dumpAllPixels = true; continue; } if (!stricmp(argv[i], "--complex-text")) { forceComplexText = true; continue; } if (!stricmp(argv[i], "--print-supported-features")) { printSupportedFeatures = true; continue; } if (!stricmp(argv[i], "--pixel-tests")) { dumpPixelsForAllTests = true; continue; } tests.append(argv[i]); } policyDelegate = new PolicyDelegate(); sharedFrameLoadDelegate.adoptRef(new FrameLoadDelegate); sharedUIDelegate.adoptRef(new UIDelegate); sharedEditingDelegate.adoptRef(new EditingDelegate); sharedHistoryDelegate.adoptRef(new HistoryDelegate); // FIXME - need to make DRT pass with Windows native controls <http://bugs.webkit.org/show_bug.cgi?id=25592> COMPtr<IWebPreferences> tmpPreferences; if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences)))) return -1; COMPtr<IWebPreferences> standardPreferences; if (FAILED(tmpPreferences->standardPreferences(&standardPreferences))) return -1; COMPtr<IWebPreferencesPrivate> standardPreferencesPrivate; if (FAILED(standardPreferences->QueryInterface(&standardPreferencesPrivate))) return -1; standardPreferencesPrivate->setShouldPaintNativeControls(FALSE); standardPreferences->setJavaScriptEnabled(TRUE); standardPreferences->setDefaultFontSize(16); standardPreferences->setAcceleratedCompositingEnabled(true); standardPreferences->setContinuousSpellCheckingEnabled(TRUE); if (printSupportedFeatures) { BOOL acceleratedCompositingAvailable; standardPreferences->acceleratedCompositingEnabled(&acceleratedCompositingAvailable); #if ENABLE(3D_RENDERING) // In theory, we could have a software-based 3D rendering implementation that we use when // hardware-acceleration is not available. But we don't have any such software // implementation, so 3D rendering is only available when hardware-acceleration is. BOOL threeDRenderingAvailable = acceleratedCompositingAvailable; #else BOOL threeDRenderingAvailable = FALSE; #endif printf("SupportedFeatures:%s %s\n", acceleratedCompositingAvailable ? "AcceleratedCompositing" : "", threeDRenderingAvailable ? "3DRendering" : ""); return 0; } COMPtr<IWebView> webView(AdoptCOM, createWebViewAndOffscreenWindow(&webViewWindow)); if (!webView) return -1; COMPtr<IWebIconDatabase> iconDatabase; COMPtr<IWebIconDatabase> tmpIconDatabase; if (FAILED(WebKitCreateInstance(CLSID_WebIconDatabase, 0, IID_IWebIconDatabase, (void**)&tmpIconDatabase))) return -1; if (FAILED(tmpIconDatabase->sharedIconDatabase(&iconDatabase))) return -1; if (FAILED(webView->mainFrame(&frame))) return -1; #if USE(CFNETWORK) RetainPtr<CFURLCacheRef> urlCache = sharedCFURLCache(); CFURLCacheRemoveAllCachedResponses(urlCache.get()); #endif #ifdef _DEBUG _CrtMemState entryToMainMemCheckpoint; if (leakChecking) _CrtMemCheckpoint(&entryToMainMemCheckpoint); #endif if (threaded) startJavaScriptThreads(); if (tests.size() == 1 && !strcmp(tests[0], "-")) { char filenameBuffer[2048]; printSeparators = true; while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) { char* newLineCharacter = strchr(filenameBuffer, '\n'); if (newLineCharacter) *newLineCharacter = '\0'; if (strlen(filenameBuffer) == 0) continue; runTest(filenameBuffer); } } else { printSeparators = tests.size() > 1; for (int i = 0; i < tests.size(); i++) runTest(tests[i]); } if (threaded) stopJavaScriptThreads(); delete policyDelegate; frame->Release(); #ifdef _DEBUG if (leakChecking) { // dump leaks to stderr _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtMemDumpAllObjectsSince(&entryToMainMemCheckpoint); } #endif shutDownWebKit(); return 0; }
void WebDragClient::startDrag(DragImageRef image, const IntPoint& imageOrigin, const IntPoint& dragPoint, Clipboard* clipboard, Frame* frame, bool isLink) { //FIXME: Allow UIDelegate to override behaviour <rdar://problem/5015953> //We liberally protect everything, to protect against a load occurring mid-drag RefPtr<Frame> frameProtector = frame; COMPtr<IDragSourceHelper> helper; COMPtr<IDataObject> dataObject; COMPtr<WebView> viewProtector = m_webView; COMPtr<IDropSource> source; if (FAILED(WebDropSource::createInstance(m_webView, &source))) return; dataObject = static_cast<ClipboardWin*>(clipboard)->dataObject(); if (source && (image || dataObject)) { if (image) { if(SUCCEEDED(CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper,(LPVOID*)&helper))) { BITMAP b; GetObject(image, sizeof(BITMAP), &b); SHDRAGIMAGE sdi; sdi.sizeDragImage.cx = b.bmWidth; sdi.sizeDragImage.cy = b.bmHeight; sdi.crColorKey = 0xffffffff; sdi.hbmpDragImage = image; sdi.ptOffset.x = dragPoint.x() - imageOrigin.x(); sdi.ptOffset.y = dragPoint.y() - imageOrigin.y(); if (isLink) sdi.ptOffset.y = b.bmHeight - sdi.ptOffset.y; helper->InitializeFromBitmap(&sdi, dataObject.get()); } } DWORD okEffect = draggingSourceOperationMaskToDragCursors(m_webView->page()->dragController()->sourceDragOperation()); DWORD effect = DROPEFFECT_NONE; COMPtr<IWebUIDelegate> ui; HRESULT hr = E_NOTIMPL; if (SUCCEEDED(m_webView->uiDelegate(&ui))) { COMPtr<IWebUIDelegatePrivate> uiPrivate; if (SUCCEEDED(ui->QueryInterface(IID_IWebUIDelegatePrivate, (void**)&uiPrivate))) hr = uiPrivate->doDragDrop(m_webView, dataObject.get(), source.get(), okEffect, &effect); } if (hr == E_NOTIMPL) hr = DoDragDrop(dataObject.get(), source.get(), okEffect, &effect); DragOperation operation = DragOperationNone; if (hr == DRAGDROP_S_DROP) { if (effect & DROPEFFECT_COPY) operation = DragOperationCopy; else if (effect & DROPEFFECT_LINK) operation = DragOperationLink; else if (effect & DROPEFFECT_MOVE) operation = DragOperationMove; } frame->eventHandler()->dragSourceEndedAt(generateMouseEvent(m_webView, false), operation); } }
static void initialize() { if (HMODULE webKitModule = LoadLibrary(WEBKITDLL)) if (FARPROC dllRegisterServer = GetProcAddress(webKitModule, "DllRegisterServer")) dllRegisterServer(); // Init COM OleInitialize(0); static LPCTSTR fontsToInstall[] = { TEXT("AHEM____.ttf"), TEXT("Apple Chancery.ttf"), TEXT("Courier Bold.ttf"), TEXT("Courier.ttf"), TEXT("Helvetica Bold Oblique.ttf"), TEXT("Helvetica Bold.ttf"), TEXT("Helvetica Oblique.ttf"), TEXT("Helvetica.ttf"), TEXT("Helvetica Neue Bold Italic.ttf"), TEXT("Helvetica Neue Bold.ttf"), TEXT("Helvetica Neue Condensed Black.ttf"), TEXT("Helvetica Neue Condensed Bold.ttf"), TEXT("Helvetica Neue Italic.ttf"), TEXT("Helvetica Neue Light Italic.ttf"), TEXT("Helvetica Neue Light.ttf"), TEXT("Helvetica Neue UltraLight Italic.ttf"), TEXT("Helvetica Neue UltraLight.ttf"), TEXT("Helvetica Neue.ttf"), TEXT("Lucida Grande.ttf"), TEXT("Lucida Grande Bold.ttf"), TEXT("Monaco.ttf"), TEXT("Papyrus.ttf"), TEXT("Times Bold Italic.ttf"), TEXT("Times Bold.ttf"), TEXT("Times Italic.ttf"), TEXT("Times Roman.ttf"), TEXT("WebKit Layout Tests 2.ttf"), TEXT("WebKit Layout Tests.ttf"), TEXT("WebKitWeightWatcher100.ttf"), TEXT("WebKitWeightWatcher200.ttf"), TEXT("WebKitWeightWatcher300.ttf"), TEXT("WebKitWeightWatcher400.ttf"), TEXT("WebKitWeightWatcher500.ttf"), TEXT("WebKitWeightWatcher600.ttf"), TEXT("WebKitWeightWatcher700.ttf"), TEXT("WebKitWeightWatcher800.ttf"), TEXT("WebKitWeightWatcher900.ttf") }; wstring resourcesPath = fontsPath(); COMPtr<IWebTextRenderer> textRenderer; if (SUCCEEDED(WebKitCreateInstance(CLSID_WebTextRenderer, 0, IID_IWebTextRenderer, (void**)&textRenderer))) for (int i = 0; i < ARRAYSIZE(fontsToInstall); ++i) textRenderer->registerPrivateFont(wstring(resourcesPath + fontsToInstall[i]).c_str()); // Add the QuickTime dll directory to PATH or QT 7.6 will fail to initialize on systems // linked with older versions of qtmlclientlib.dll. addQTDirToPATH(); // Register a host window WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = DumpRenderTreeWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = GetModuleHandle(0); wcex.hIcon = 0; wcex.hCursor = LoadCursor(0, IDC_ARROW); wcex.hbrBackground = 0; wcex.lpszMenuName = 0; wcex.lpszClassName = kDumpRenderTreeClassName; wcex.hIconSm = 0; RegisterClassEx(&wcex); }
void WebEditorClient::checkGrammarOfString(StringView text, Vector<GrammarDetail>& details, int* badGrammarLocation, int* badGrammarLength) { details.clear(); *badGrammarLocation = -1; *badGrammarLength = 0; COMPtr<IWebEditingDelegate> ed; if (FAILED(m_webView->editingDelegate(&ed)) || !ed.get()) return; initViewSpecificSpelling(m_webView); COMPtr<IEnumWebGrammarDetails> enumDetailsObj; if (FAILED(ed->checkGrammarOfString(m_webView, text.upconvertedCharacters(), text.length(), &enumDetailsObj, badGrammarLocation, badGrammarLength))) return; while (true) { ULONG fetched; COMPtr<IWebGrammarDetail> detailObj; if (enumDetailsObj->Next(1, &detailObj, &fetched) != S_OK) break; GrammarDetail detail; if (FAILED(detailObj->length(&detail.length))) continue; if (FAILED(detailObj->location(&detail.location))) continue; BString userDesc; if (FAILED(detailObj->userDescription(&userDesc))) continue; detail.userDescription = String(userDesc, SysStringLen(userDesc)); COMPtr<IEnumSpellingGuesses> enumGuessesObj; if (FAILED(detailObj->guesses(&enumGuessesObj))) continue; while (true) { BString guess; if (enumGuessesObj->Next(1, &guess, &fetched) != S_OK) break; detail.guesses.append(String(guess, SysStringLen(guess))); } details.append(detail); } }
static void dumpHistoryItem(IWebHistoryItem* item, int indent, bool current) { assert(item); int start = 0; if (current) { printf("curr->"); start = 6; } for (int i = start; i < indent; i++) putchar(' '); BSTR url; if (FAILED(item->URLString(&url))) return; if (wcsstr(url, L"file:/") == url) { static wchar_t* layoutTestsString = L"/LayoutTests/"; static wchar_t* fileTestString = L"(file test):"; wchar_t* result = wcsstr(url, layoutTestsString); if (result == NULL) return; wchar_t* start = result + wcslen(layoutTestsString); BSTR newURL = SysAllocStringLen(NULL, SysStringLen(url)); wcscpy(newURL, fileTestString); wcscpy(newURL + wcslen(fileTestString), start); SysFreeString(url); url = newURL; } printf("%S", url ? url : L""); SysFreeString(url); COMPtr<IWebHistoryItemPrivate> itemPrivate; if (FAILED(item->QueryInterface(&itemPrivate))) return; BSTR target; if (FAILED(itemPrivate->target(&target))) return; if (SysStringLen(target)) printf(" (in frame \"%S\")", target); SysFreeString(target); BOOL isTargetItem = FALSE; if (FAILED(itemPrivate->isTargetItem(&isTargetItem))) return; if (isTargetItem) printf(" **nav target**"); putchar('\n'); unsigned kidsCount; SAFEARRAY* arrPtr; if (FAILED(itemPrivate->children(&kidsCount, &arrPtr)) || !kidsCount) return; Vector<COMPtr<IUnknown> > kidsVector; LONG lowerBound; if (FAILED(::SafeArrayGetLBound(arrPtr, 1, &lowerBound))) goto exit; LONG upperBound; if (FAILED(::SafeArrayGetUBound(arrPtr, 1, &upperBound))) goto exit; LONG length = upperBound - lowerBound + 1; if (!length) goto exit; ASSERT(length == kidsCount); IUnknown** safeArrayData; if (FAILED(::SafeArrayAccessData(arrPtr, (void**)&safeArrayData))) goto exit; for (int i = 0; i < length; ++i) kidsVector.append(safeArrayData[i]); ::SafeArrayUnaccessData(arrPtr); // must sort to eliminate arbitrary result ordering which defeats reproducible testing qsort(kidsVector.data(), kidsCount, sizeof(kidsVector[0]), compareHistoryItems); for (unsigned i = 0; i < kidsCount; ++i) { COMPtr<IWebHistoryItem> item; kidsVector[i]->QueryInterface(&item); dumpHistoryItem(item.get(), indent + 4, false); } exit: if (arrPtr && SUCCEEDED(::SafeArrayUnlock(arrPtr))) ::SafeArrayDestroy(arrPtr); }
void WebChromeClient::print(Frame* frame) { COMPtr<IWebUIDelegate> uiDelegate; if (SUCCEEDED(m_webView->uiDelegate(&uiDelegate))) uiDelegate->printFrame(m_webView, kit(frame)); }
static void dumpBackForwardList(IWebView* webView) { ASSERT(webView); printf("\n============== Back Forward List ==============\n"); COMPtr<IWebBackForwardList> bfList; if (FAILED(webView->backForwardList(&bfList))) return; // Print out all items in the list after prevTestBFItem, which was from the previous test // Gather items from the end of the list, the print them out from oldest to newest Vector<COMPtr<IUnknown> > itemsToPrint; int forwardListCount; if (FAILED(bfList->forwardListCount(&forwardListCount))) return; for (int i = forwardListCount; i > 0; --i) { COMPtr<IWebHistoryItem> item; if (FAILED(bfList->itemAtIndex(i, &item))) return; // something is wrong if the item from the last test is in the forward part of the b/f list assert(item != prevTestBFItem); COMPtr<IUnknown> itemUnknown; item->QueryInterface(&itemUnknown); itemsToPrint.append(itemUnknown); } COMPtr<IWebHistoryItem> currentItem; if (FAILED(bfList->currentItem(¤tItem))) return; assert(currentItem != prevTestBFItem); COMPtr<IUnknown> currentItemUnknown; currentItem->QueryInterface(¤tItemUnknown); itemsToPrint.append(currentItemUnknown); int currentItemIndex = itemsToPrint.size() - 1; int backListCount; if (FAILED(bfList->backListCount(&backListCount))) return; for (int i = -1; i >= -backListCount; --i) { COMPtr<IWebHistoryItem> item; if (FAILED(bfList->itemAtIndex(i, &item))) return; if (item == prevTestBFItem) break; COMPtr<IUnknown> itemUnknown; item->QueryInterface(&itemUnknown); itemsToPrint.append(itemUnknown); } for (int i = itemsToPrint.size() - 1; i >= 0; --i) { COMPtr<IWebHistoryItem> historyItemToPrint; itemsToPrint[i]->QueryInterface(&historyItemToPrint); dumpHistoryItem(historyItemToPrint.get(), 8, i == currentItemIndex); } printf("===============================================\n"); }
bool WKCACFLayerRenderer::createRenderer() { if (m_d3dDevice || !m_mightBeAbleToCreateDeviceLater) return m_d3dDevice; m_mightBeAbleToCreateDeviceLater = false; D3DPRESENT_PARAMETERS parameters = initialPresentationParameters(); if (!d3d() || !::IsWindow(m_hostWindow)) return false; // D3D doesn't like to make back buffers for 0 size windows. We skirt this problem if we make the // passed backbuffer width and height non-zero. The window will necessarily get set to a non-zero // size eventually, and then the backbuffer size will get reset. RECT rect; GetClientRect(m_hostWindow, &rect); if (rect.left-rect.right == 0 || rect.bottom-rect.top == 0) { parameters.BackBufferWidth = 1; parameters.BackBufferHeight = 1; } D3DCAPS9 d3dCaps; if (FAILED(d3d()->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) return false; DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE; if ((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && d3dCaps.VertexProcessingCaps) behaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; else behaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; COMPtr<IDirect3DDevice9> device; if (FAILED(d3d()->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hostWindow, behaviorFlags, ¶meters, &device))) { // In certain situations (e.g., shortly after waking from sleep), Direct3DCreate9() will // return an IDirect3D9 for which IDirect3D9::CreateDevice will always fail. In case we // have one of these bad IDirect3D9s, get rid of it so we'll fetch a new one the next time // we want to call CreateDevice. s_d3d->Release(); s_d3d = 0; // Even if we don't have a bad IDirect3D9, in certain situations (e.g., shortly after // waking from sleep), CreateDevice will fail, but will later succeed if called again. m_mightBeAbleToCreateDeviceLater = true; return false; } // Now that we've created the IDirect3DDevice9 based on the capabilities we // got from the IDirect3D9 global object, we requery the device for its // actual capabilities. The capabilities returned by the device can // sometimes be more complete, for example when using software vertex // processing. D3DCAPS9 deviceCaps; if (FAILED(device->GetDeviceCaps(&deviceCaps))) return false; if (!hardwareCapabilitiesIndicateCoreAnimationSupport(deviceCaps)) return false; m_d3dDevice = device; initD3DGeometry(); wkCACFContextInitializeD3DDevice(m_context, m_d3dDevice.get()); if (IsWindow(m_hostWindow)) m_rootLayer->setBounds(bounds()); return true; }
HRESULT STDMETHODCALLTYPE WebCache::statistics( /* [in][out] */ int* count, /* [retval][out] */ IPropertyBag ** s) { if (!count || (s && *count < 4)) return E_FAIL; *count = 4; if (!s) return S_OK; WebCore::Cache::Statistics stat = WebCore::cache()->getStatistics(); static CFStringRef imagesKey = CFSTR("images"); static CFStringRef stylesheetsKey = CFSTR("style sheets"); static CFStringRef xslKey = CFSTR("xsl"); static CFStringRef scriptsKey = CFSTR("scripts"); #if !ENABLE(XSLT) const int zero = 0; #endif RetainPtr<CFMutableDictionaryRef> dictionary(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); RetainPtr<CFNumberRef> value(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &stat.images.count)); CFDictionaryAddValue(dictionary.get(), imagesKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.count)); CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get()); #if ENABLE(XSLT) value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.count)); #else value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero)); #endif CFDictionaryAddValue(dictionary.get(), xslKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.count)); CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get()); COMPtr<CFDictionaryPropertyBag> propBag = CFDictionaryPropertyBag::createInstance(); propBag->setDictionary(dictionary.get()); s[0] = propBag.releaseRef(); dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.size)); CFDictionaryAddValue(dictionary.get(), imagesKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.size)); CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get()); #if ENABLE(XSLT) value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.size)); #else value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero)); #endif CFDictionaryAddValue(dictionary.get(), xslKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.size)); CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get()); propBag = CFDictionaryPropertyBag::createInstance(); propBag->setDictionary(dictionary.get()); s[1] = propBag.releaseRef(); dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.liveSize)); CFDictionaryAddValue(dictionary.get(), imagesKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.liveSize)); CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get()); #if ENABLE(XSLT) value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.liveSize)); #else value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero)); #endif CFDictionaryAddValue(dictionary.get(), xslKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.liveSize)); CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get()); propBag = CFDictionaryPropertyBag::createInstance(); propBag->setDictionary(dictionary.get()); s[2] = propBag.releaseRef(); dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.decodedSize)); CFDictionaryAddValue(dictionary.get(), imagesKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.decodedSize)); CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get()); #if ENABLE(XSLT) value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.decodedSize)); #else value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero)); #endif CFDictionaryAddValue(dictionary.get(), xslKey, value.get()); value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.decodedSize)); CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get()); propBag = CFDictionaryPropertyBag::createInstance(); propBag->setDictionary(dictionary.get()); s[3] = propBag.releaseRef(); return S_OK; }