void TestRunner::setSmartInsertDeleteEnabled(bool flag) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; viewEditing->setSmartInsertDeleteEnabled(flag ? TRUE : FALSE); }
void TestRunner::dispatchPendingLoadRequests() { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate2> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; viewPrivate->dispatchPendingLoadRequests(); }
void TestRunner::setTabKeyCyclesThroughElements(bool shouldCycle) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; viewPrivate->setTabKeyCyclesThroughElements(shouldCycle ? TRUE : FALSE); }
void TestRunner::setDefersLoading(bool defers) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate2> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; viewPrivate->setDefersCallbacks(defers); }
void TestRunner::setSerializeHTTPLoads(bool serializeLoads) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate2> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; viewPrivate->setLoadResourcesSerially(serializeLoads); }
void TestRunner::setWebViewEditable(bool editable) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; viewEditing->setEditable(editable); }
void LayoutTestController::setSelectTrailingWhitespaceEnabled(bool flag) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; viewEditing->setSelectTrailingWhitespaceEnabled(flag ? TRUE : FALSE); }
LayoutTestController::~LayoutTestController() { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; // reset webview-related states back to default values in preparation for next test COMPtr<IWebViewPrivate> viewPrivate; if (SUCCEEDED(webView->QueryInterface(&viewPrivate))) viewPrivate->setTabKeyCyclesThroughElements(TRUE); COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; COMPtr<IWebEditingDelegate> delegate; if (FAILED(viewEditing->editingDelegate(&delegate))) return; COMPtr<EditingDelegate> editingDelegate(Query, viewEditing.get()); if (editingDelegate) editingDelegate->setAcceptsEditing(TRUE); }
HRESULT DOMHTMLTextAreaElement::form(_COM_Outptr_opt_ IDOMHTMLElement** result) { if (!result) return E_POINTER; *result = nullptr; ASSERT(is<HTMLTextAreaElement>(m_element)); HTMLTextAreaElement& textareaElement = downcast<HTMLTextAreaElement>(*m_element); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(textareaElement.form())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) result); return E_FAIL; }
static JSValueRef textZoomOutCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return JSValueMakeUndefined(context); COMPtr<IWebIBActions> webIBActions; if (FAILED(webView->QueryInterface(IID_IWebIBActions, (void**)&webIBActions))) return JSValueMakeUndefined(context); webIBActions->makeTextSmaller(0); return JSValueMakeUndefined(context); }
bool WebChromeClient::shouldInterruptJavaScript() { COMPtr<IWebUIDelegate> uiDelegate; if (SUCCEEDED(m_webView->uiDelegate(&uiDelegate))) { COMPtr<IWebUIDelegatePrivate> uiPrivate; if (SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegatePrivate, (void**)&uiPrivate))) { BOOL result; if (SUCCEEDED(uiPrivate->webViewShouldInterruptJavaScript(m_webView, &result))) return !!result; } } return false; }
bool ReloadItem::invoke() const { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return false; COMPtr<IWebIBActions> webActions; if (FAILED(webView->QueryInterface(&webActions))) return false; webActions->reload(0); return true; }
void TestRunner::execCommand(JSStringRef name, JSStringRef value) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate2> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; _bstr_t nameBSTR(JSStringCopyBSTR(name), false); _bstr_t valueBSTR(JSStringCopyBSTR(value), false); viewPrivate->executeCoreCommandByName(nameBSTR, valueBSTR); }
HRESULT STDMETHODCALLTYPE DOMHTMLDocument::body( /* [retval][out] */ IDOMHTMLElement** bodyElement) { *bodyElement = nullptr; if (!is<HTMLDocument>(m_document)) return E_FAIL; HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc.body())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) bodyElement); return E_FAIL; }
bool LayoutTestController::callShouldCloseOnWebView() { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return false; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return false; BOOL result; viewPrivate->shouldClose(&result); return result; }
HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::form( /* [retval][out] */ IDOMHTMLElement** result) { if (!result) return E_POINTER; *result = 0; ASSERT(m_element && m_element->hasTagName(inputTag)); HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(m_element); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(inputElement->form())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) result); return E_FAIL; }
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(); BSTR groupName; if (SUCCEEDED(webView->groupName(&groupName))) { webViewPrivate->removeAllUserContentFromGroup(groupName); SysFreeString(groupName); } sharedUIDelegate->resetUndoManager(); sharedFrameLoadDelegate->resetToConsistentState(); }
HRESULT STDMETHODCALLTYPE DOMHTMLDocument::body( /* [retval][out] */ IDOMHTMLElement** bodyElement) { *bodyElement = 0; if (!m_document || !m_document->isHTMLDocument()) return E_FAIL; HTMLDocument* htmlDoc = static_cast<HTMLDocument*>(m_document); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc->body())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) bodyElement); return E_FAIL; }
HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::form( /* [retval][out] */ IDOMHTMLElement** result) { if (!result) return E_POINTER; *result = 0; ASSERT(m_element && isHTMLTextAreaElement(m_element)); HTMLTextAreaElement* textareaElement = toHTMLTextAreaElement(m_element); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(textareaElement->form())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) result); return E_FAIL; }
HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::form( /* [retval][out] */ IDOMHTMLElement** result) { if (!result) return E_POINTER; *result = nullptr; ASSERT(is<HTMLInputElement>(m_element)); HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(inputElement.form())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) result); return E_FAIL; }
HRESULT STDMETHODCALLTYPE WebActionPropertyBag::Read(LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog * /*pErrorLog*/) { if (!pszPropName) return E_POINTER; VariantClear(pVar); if (isEqual(pszPropName, WebActionNavigationTypeKey)) { V_VT(pVar) = VT_I4; V_I4(pVar) = m_action.type(); return S_OK; } else if (isEqual(pszPropName, WebActionElementKey)) { if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) { IntPoint point(mouseEvent->clientX(), mouseEvent->clientY()); COMPtr<WebElementPropertyBag> elementPropertyBag; elementPropertyBag.adoptRef(WebElementPropertyBag::createInstance(m_frame->eventHandler()->hitTestResultAtPoint(point, false))); V_VT(pVar) = VT_UNKNOWN; elementPropertyBag->QueryInterface(IID_IUnknown, (void**)V_UNKNOWNREF(pVar)); return S_OK; } } else if (isEqual(pszPropName, WebActionButtonKey)) { if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) { V_VT(pVar) = VT_I4; V_I4(pVar) = mouseEvent->button(); return S_OK; } } else if (isEqual(pszPropName, WebActionOriginalURLKey)) { V_VT(pVar) = VT_BSTR; V_BSTR(pVar) = BString(m_action.URL().url()).release(); return S_OK; } else if (isEqual(pszPropName, WebActionModifierFlagsKey)) { if (const UIEventWithKeyState* keyEvent = findEventWithKeyState(const_cast<Event*>(m_action.event()))) { int modifiers = 0; if (keyEvent->ctrlKey()) modifiers |= MK_CONTROL; if (keyEvent->shiftKey()) modifiers |= MK_SHIFT; if (keyEvent->altKey()) modifiers |= MK_ALT; V_VT(pVar) = VT_I4; V_I4(pVar) = modifiers; return S_OK; } } return E_INVALIDARG; }
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()); } } //FIXME: Ensure correct drag ops are available <rdar://problem/5015957> DWORD okEffect = DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE; DWORD effect; COMPtr<IWebUIDelegate> ui; if (SUCCEEDED(m_webView->uiDelegate(&ui))) { COMPtr<IWebUIDelegatePrivate> uiPrivate; if (SUCCEEDED(ui->QueryInterface(IID_IWebUIDelegatePrivate, (void**)&uiPrivate))) if (SUCCEEDED(uiPrivate->doDragDrop(m_webView, dataObject.get(), source.get(), okEffect, &effect))) return; } DoDragDrop(dataObject.get(), source.get(), okEffect, &effect); } }
void TestRunner::setViewSize(double width, double height) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate2> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; HWND webViewWindow; if (FAILED(viewPrivate->viewWindow(&webViewWindow))) return; ::SetWindowPos(webViewWindow, 0, 0, 0, width, height, SWP_NOMOVE); }
void LayoutTestController::setWindowIsKey(bool flag) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; HWND webViewWindow; if (FAILED(viewPrivate->viewWindow((OLE_HANDLE*)&webViewWindow))) return; ::SendMessage(webViewWindow, flag ? WM_SETFOCUS : WM_KILLFOCUS, (WPARAM)::GetDesktopWindow(), 0); }
HRESULT DOMHTMLDocument::body(_COM_Outptr_opt_ IDOMHTMLElement** bodyElement) { if (!bodyElement) return E_POINTER; *bodyElement = nullptr; if (!is<HTMLDocument>(m_document)) return E_FAIL; HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document); COMPtr<IDOMElement> domElement; domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc.bodyOrFrameset())); if (domElement) return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) bodyElement); return E_FAIL; }
void LayoutTestController::setTimelineProfilingEnabled(bool flag) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; COMPtr<IWebInspector> inspector; if (FAILED(viewPrivate->inspector(&inspector))) return; inspector->setTimelineProfilingEnabled(flag); }
void LayoutTestController::removeAllVisitedLinks() { COMPtr<IWebHistory> history; if (FAILED(WebKitCreateInstance(CLSID_WebHistory, 0, __uuidof(history), reinterpret_cast<void**>(&history)))) return; COMPtr<IWebHistory> sharedHistory; if (FAILED(history->optionalSharedHistory(&sharedHistory)) || !sharedHistory) return; COMPtr<IWebHistoryPrivate> sharedHistoryPrivate; if (FAILED(sharedHistory->QueryInterface(&sharedHistoryPrivate))) return; sharedHistoryPrivate->removeAllVisitedLinks(); }
bool TestRunner::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return false; COMPtr<IWebViewPrivate3> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return false; unsigned char options = 0; JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length")); JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), nullptr); if (!JSValueIsNumber(context, lengthValue)) return false; _bstr_t targetBSTR(JSStringCopyBSTR(target), false); size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, nullptr)); for (size_t i = 0; i < length; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, nullptr); if (!JSValueIsString(context, value)) continue; JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, nullptr)); if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive")) options |= WebFindOptionsCaseInsensitive; else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts")) options |= WebFindOptionsAtWordStarts; else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart")) options |= WebFindOptionsTreatMedialCapitalAsWordStart; else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards")) options |= WebFindOptionsBackwards; else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround")) options |= WebFindOptionsWrapAround; else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) options |= WebFindOptionsStartInSelection; } BOOL found = FALSE; if (FAILED(viewPrivate->findString(targetBSTR, static_cast<WebFindOptions>(options), &found))) return false; return found; }
bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader* loader, unsigned long identifier) { WebView* webView = m_webFrame->webView(); COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate; if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate))) return true; COMPtr<IWebResourceLoadDelegatePrivate2> resourceLoadDelegatePrivate; if (FAILED(resourceLoadDelegate->QueryInterface(IID_IWebResourceLoadDelegatePrivate2, reinterpret_cast<void**>(&resourceLoadDelegatePrivate)))) return true; BOOL shouldUse; if (SUCCEEDED(resourceLoadDelegatePrivate->shouldUseCredentialStorage(webView, identifier, getWebDataSource(loader), &shouldUse))) return shouldUse; return true; }
void LayoutTestController::setAcceptsEditing(bool acceptsEditing) { COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; COMPtr<IWebEditingDelegate> delegate; if (FAILED(viewEditing->editingDelegate(&delegate))) return; EditingDelegate* editingDelegate = (EditingDelegate*)(IWebEditingDelegate*)delegate.get(); editingDelegate->setAcceptsEditing(acceptsEditing); }