📄 webframe.cpp
字号:
Frame* frame = core(this); if (!frame) return E_FAIL; AnimationController* controller = frame->animation(); if (!controller) return E_FAIL; COMPtr<DOMNode> domNode(Query, node); if (!domNode) return E_FAIL; *animationWasRunning = controller->pauseAnimationAtTime(domNode->node()->renderer(), String(animationName, SysStringLen(animationName)), secondsFromNow); return S_OK;}HRESULT WebFrame::pauseTransition(BSTR propertyName, IDOMNode* node, double secondsFromNow, BOOL* transitionWasRunning){ if (!node || !transitionWasRunning) return E_POINTER; *transitionWasRunning = FALSE; Frame* frame = core(this); if (!frame) return E_FAIL; AnimationController* controller = frame->animation(); if (!controller) return E_FAIL; COMPtr<DOMNode> domNode(Query, node); if (!domNode) return E_FAIL; *transitionWasRunning = controller->pauseTransitionAtTime(domNode->node()->renderer(), String(propertyName, SysStringLen(propertyName)), secondsFromNow); return S_OK;}HRESULT WebFrame::numberOfActiveAnimations(UINT* number){ if (!number) return E_POINTER; *number = 0; Frame* frame = core(this); if (!frame) return E_FAIL; AnimationController* controller = frame->animation(); if (!controller) return E_FAIL; *number = controller->numberOfActiveAnimations(); return S_OK;}HRESULT WebFrame::controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls){ if (!form) return E_INVALIDARG; HTMLFormElement *formElement = formElementFromDOMElement(form); if (!formElement) return E_FAIL; int inCount = *cControls; int count = (int) formElement->formElements.size(); *cControls = count; if (!controls) return S_OK; if (inCount < count) return E_FAIL; *cControls = 0; Vector<HTMLFormControlElement*>& elements = formElement->formElements; for (int i = 0; i < count; i++) { if (elements.at(i)->isEnumeratable()) { // Skip option elements, other duds controls[*cControls] = DOMElement::createInstance(elements.at(i)); (*cControls)++; } } return S_OK;}HRESULT WebFrame::elementIsPassword(IDOMElement *element, bool *result){ HTMLInputElement *inputElement = inputElementFromDOMElement(element); *result = inputElement != 0 && inputElement->inputType() == HTMLInputElement::PASSWORD; return S_OK;}HRESULT WebFrame::searchForLabelsBeforeElement(const BSTR* labels, int cLabels, IDOMElement* beforeElement, BSTR* result){ if (!result) { ASSERT_NOT_REACHED(); return E_POINTER; } *result = 0; if (!cLabels) return S_OK; if (cLabels < 1) return E_INVALIDARG; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; Vector<String> labelStrings(cLabels); for (int i=0; i<cLabels; i++) labelStrings[i] = String(labels[i], SysStringLen(labels[i])); Element *coreElement = elementFromDOMElement(beforeElement); if (!coreElement) return E_FAIL; String label = coreFrame->searchForLabelsBeforeElement(labelStrings, coreElement); *result = SysAllocStringLen(label.characters(), label.length()); if (label.length() && !*result) return E_OUTOFMEMORY; return S_OK;}HRESULT WebFrame::matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result){ if (!result) { ASSERT_NOT_REACHED(); return E_POINTER; } *result = 0; if (!cLabels) return S_OK; if (cLabels < 1) return E_INVALIDARG; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; Vector<String> labelStrings(cLabels); for (int i=0; i<cLabels; i++) labelStrings[i] = String(labels[i], SysStringLen(labels[i])); Element *coreElement = elementFromDOMElement(againstElement); if (!coreElement) return E_FAIL; String label = coreFrame->matchLabelsAgainstElement(labelStrings, coreElement); *result = SysAllocStringLen(label.characters(), label.length()); if (label.length() && !*result) return E_OUTOFMEMORY; return S_OK;}HRESULT WebFrame::canProvideDocumentSource(bool* result){ HRESULT hr = S_OK; *result = false; COMPtr<IWebDataSource> dataSource; hr = WebFrame::dataSource(&dataSource); if (FAILED(hr)) return hr; COMPtr<IWebURLResponse> urlResponse; hr = dataSource->response(&urlResponse); if (SUCCEEDED(hr) && urlResponse) { BSTR mimeTypeBStr; if (SUCCEEDED(urlResponse->MIMEType(&mimeTypeBStr))) { String mimeType(mimeTypeBStr, SysStringLen(mimeTypeBStr)); *result = mimeType == "text/html" || WebCore::DOMImplementation::isXMLMIMEType(mimeType); SysFreeString(mimeTypeBStr); } } return hr;}void WebFrame::frameLoaderDestroyed(){ // The FrameLoader going away is equivalent to the Frame going away, // so we now need to clear our frame pointer. d->frame = 0; this->Release();}void WebFrame::makeRepresentation(DocumentLoader*){ notImplemented();}void WebFrame::forceLayoutForNonHTML(){ notImplemented();}void WebFrame::setCopiesOnScroll(){ notImplemented();}void WebFrame::detachedFromParent2(){ notImplemented();}void WebFrame::detachedFromParent3(){ notImplemented();}void WebFrame::cancelPolicyCheck(){ if (d->m_policyListener) { d->m_policyListener->invalidate(); d->m_policyListener = 0; } d->m_policyFunction = 0;}void WebFrame::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState){ Frame* coreFrame = core(this); ASSERT(coreFrame); COMPtr<IWebFormDelegate> formDelegate; if (FAILED(d->webView->formDelegate(&formDelegate))) { (coreFrame->loader()->*function)(PolicyUse); return; } COMPtr<IDOMElement> formElement(AdoptCOM, DOMElement::createInstance(formState->form())); COMPtr<IPropertyBag> formValuesPropertyBag(AdoptCOM, COMPropertyBag<String>::createInstance(formState->values())); COMPtr<WebFrame> sourceFrame(kit(formState->sourceFrame())); if (SUCCEEDED(formDelegate->willSubmitForm(this, sourceFrame.get(), formElement.get(), formValuesPropertyBag.get(), setUpPolicyListener(function).get()))) return; // FIXME: Add a sane default implementation (coreFrame->loader()->*function)(PolicyUse);}void WebFrame::revertToProvisionalState(DocumentLoader*){ notImplemented();}void WebFrame::setMainFrameDocumentReady(bool){ notImplemented();}void WebFrame::willChangeTitle(DocumentLoader*){ notImplemented();}void WebFrame::didChangeTitle(DocumentLoader*){ notImplemented();}bool WebFrame::canHandleRequest(const ResourceRequest& request) const{ return WebView::canHandleRequest(request);}bool WebFrame::canShowMIMEType(const String& /*MIMEType*/) const{ notImplemented(); return true;}bool WebFrame::representationExistsForURLScheme(const String& /*URLScheme*/) const{ notImplemented(); return false;}String WebFrame::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const{ notImplemented(); ASSERT_NOT_REACHED(); return String();}void WebFrame::frameLoadCompleted(){}void WebFrame::restoreViewState(){}void WebFrame::provisionalLoadStarted(){ notImplemented();}bool WebFrame::shouldTreatURLAsSameAsCurrent(const KURL&) const{ notImplemented(); return false;}void WebFrame::addHistoryItemForFragmentScroll(){ notImplemented();}void WebFrame::didFinishLoad(){ notImplemented();}void WebFrame::prepareForDataSourceReplacement(){ notImplemented();}String WebFrame::userAgent(const KURL& url){ return d->webView->userAgentForKURL(url);}void WebFrame::saveViewStateToItem(HistoryItem*){}ResourceError WebFrame::cancelledError(const ResourceRequest& request){ // FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values // Alternatively, we could create our own error domain/codes. return ResourceError(String(WebURLErrorDomain), -999, request.url().string(), String());}ResourceError WebFrame::blockedError(const ResourceRequest& request){ // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotUseRestrictedPort, request.url().string(), String());}ResourceError WebFrame::cannotShowURLError(const ResourceRequest& request){ // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotShowURL, request.url().string(), String());}ResourceError WebFrame::interruptForPolicyChangeError(const ResourceRequest& request){ // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized return ResourceError(String(WebKitErrorDomain), WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(), String());}ResourceError WebFrame::cannotShowMIMETypeError(const ResourceResponse&){ notImplemented(); return ResourceError();}ResourceError WebFrame::fileDoesNotExistError(const ResourceResponse&){ notImplemented(); return ResourceError();}ResourceError WebFrame::pluginWillHandleLoadError(const ResourceResponse& response){ return ResourceError(String(WebKitErrorDomain), WebKitErrorPlugInWillHandleLoad, response.url().string(), String());}bool WebFrame::shouldFallBack(const ResourceError& error){ return error.errorCode() != WebURLErrorCancelled;}COMPtr<WebFramePolicyListener> WebFrame::setUpPolicyListener(WebCore::FramePolicyFunction function){ // FIXME: <rdar://5634381> We need to support multiple active policy listeners. if (d->m_policyListener) d->m_policyListener->invalidate(); Frame* coreFrame = core(this); ASSERT(coreFrame); d->m_policyListener.adoptRef(WebFramePolicyListener::createInstance(coreFrame)); d->m_policyFunction = function; return d->m_policyListener;}void WebFrame::receivedPolicyDecision(PolicyAction action){ ASSERT(d->m_policyListener); ASSERT(d->m_policyFunction); FramePolicyFunction function = d->m_policyFunction; d->m_policyListener = 0; d->m_policyFunction = 0; Frame* coreFrame = core(this); ASSERT(coreFrame); (coreFrame->loader()->*function)(action);}void WebFrame::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& mimeType, const ResourceRequest& request){ Frame* coreFrame = core(this); ASSERT(coreFrame); COMPtr<IWebPolicyDelegate> policyDelegate; if (FAILED(d->webView->policyDelegate(&policyDelegate))) policyDelegate = DefaultPolicyDelegate::sharedInstance(); COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request)); if (SUCCEEDED(policyDelegate->decidePolicyForMIMEType(d->webView, BString(mimeType), urlRequest.get(), this, setUpPolicyListener(function).get()))) return; (coreFrame->loader()->*function)(PolicyUse);}void WebFrame::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName){ Frame* coreFrame = core(this); ASSERT(coreFrame); COMPtr<IWebPolicyDelegate> policyDelegate; if (FAILED(d->webView->policyDelegate(&policyDelegate))) policyDelegate = DefaultPolicyDelegate::sharedInstance(); COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request)); COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame)); if (SUCCEEDED(policyDelegate->decidePolicyForNewWindowAction(d->webView, actionInformation.get(), urlRequest.get(), BString(frameName), setUpPolicyListener(function).get()))) return; (coreFrame->loader()->*function)(PolicyUse);}void WebFrame::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState){ Frame* coreFrame = core(this); ASSERT(coreFrame); COMPtr<IWebPolicyDelegate> policyDelegate; if (FAILED(d->webView->policyDelegate(&policyDelegate))) policyDelegate = DefaultPolicyDelegate::sharedInstance(); COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request)); COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame)); if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get()))) return; (coreFrame->loader()->*function)(PolicyUse);}void WebFrame::dispatchUnableToImplementPolicy(const ResourceError& error){ COMPtr<IWebPolicyDelegate> policyDelegate; if (FAILED(d->webView->policyDelegate(&policyDelegate))) policyDelegate = DefaultPolicyDelegate::sharedInstance(); COMPtr<IWebError> webError(AdoptCOM, WebError::createInstance(error)); policyDelegate->unableToImplementPolicyWithError(d->webView, webError.get(), this);}void WebFrame::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest&, const ResourceResponse& response){ COMPtr<IWebDownloadDelegate> downloadDelegate; COMPtr<IWebView> webView; if (SUCCEEDED(this->webView(&webView))) { if (FAILED(webView->downloadDelegate(&downloadDelegate))) { // If the WebView doesn't successfully provide a download delegate we'll pass a null one // into the WebDownload - which may or may not decide to use a DefaultDownloadDelegate LOG_ERROR("Failed to get downloadDelegate from WebView"); downloadDelegate = 0; } } // Its the delegate's job to ref the WebDownload to keep it alive - otherwise it will be destroyed // when this method returns COMPtr<WebDownload> download; download.adoptRef(WebDownload::createInstance(handle, request, response, downloadDelegate.get()));}bool WebFrame::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/){ notImplemented(); return false;}void WebFrame::dispatchDidFailProvisionalLoad(const ResourceError& error){ COMPtr<IWebFrameLoadDelegate> frameLoadDelegate; if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) { COMPtr<IWebError> webError; webError.adoptRef(WebError::createInstance(error)); frameLoadDelegate->didFailProvisionalLoadWithError(d->webView, webError.get(), this); }}void WebFrame::dispatchDidFailLoad(const ResourceError& error){ COMPtr<IWebFrameLoadDelegate> frameLoadDelegate; if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) { COMPtr<IWebError> webError; webError.adoptRef(WebError::createInstance(error)); frameLoadDelegate->didFailLoadWithError(d->webView, webError.get(), this); }}void WebFrame::startDownload(const ResourceRequest&){ notImplemented();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -