2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WebKitDLL.h"
31 #include "CFDictionaryPropertyBag.h"
32 #include "COMPropertyBag.h"
33 #include "DOMCoreClasses.h"
34 #include "DefaultPolicyDelegate.h"
35 #include "HTMLFrameOwnerElement.h"
36 #include "MarshallingHelpers.h"
37 #include "WebActionPropertyBag.h"
38 #include "WebChromeClient.h"
39 #include "WebDataSource.h"
40 #include "WebDocumentLoader.h"
41 #include "WebDownload.h"
42 #include "WebEditorClient.h"
44 #include "WebFrameNetworkingContext.h"
45 #include "WebFramePolicyListener.h"
46 #include "WebHistory.h"
47 #include "WebHistoryItem.h"
49 #include "WebKitStatisticsPrivate.h"
50 #include "WebMutableURLRequest.h"
51 #include "WebNotificationCenter.h"
52 #include "WebScriptWorld.h"
53 #include "WebURLResponse.h"
55 #include <WebCore/BString.h>
56 #include <WebCore/COMPtr.h>
57 #include <WebCore/MemoryCache.h>
58 #include <WebCore/Document.h>
59 #include <WebCore/DocumentLoader.h>
60 #include <WebCore/DocumentMarkerController.h>
61 #include <WebCore/DOMImplementation.h>
62 #include <WebCore/DOMWindow.h>
63 #include <WebCore/Event.h>
64 #include <WebCore/EventHandler.h>
65 #include <WebCore/FormState.h>
66 #include <WebCore/FrameLoader.h>
67 #include <WebCore/FrameLoadRequest.h>
68 #include <WebCore/FrameTree.h>
69 #include <WebCore/FrameView.h>
70 #include <WebCore/FrameWin.h>
71 #include <WebCore/GDIObjectCounter.h>
72 #include <WebCore/GraphicsContext.h>
73 #include <WebCore/HistoryItem.h>
74 #include <WebCore/HTMLAppletElement.h>
75 #include <WebCore/HTMLFormElement.h>
76 #include <WebCore/HTMLFormControlElement.h>
77 #include <WebCore/HTMLInputElement.h>
78 #include <WebCore/HTMLNames.h>
79 #include <WebCore/HTMLPlugInElement.h>
80 #include <WebCore/JSDOMWindow.h>
81 #include <WebCore/KeyboardEvent.h>
82 #include <WebCore/MouseRelatedEvent.h>
83 #include <WebCore/NotImplemented.h>
84 #include <WebCore/Page.h>
85 #include <WebCore/PlatformKeyboardEvent.h>
86 #include <WebCore/PluginData.h>
87 #include <WebCore/PluginDatabase.h>
88 #include <WebCore/PluginView.h>
89 #include <WebCore/PrintContext.h>
90 #include <WebCore/ResourceHandle.h>
91 #include <WebCore/ResourceRequest.h>
92 #include <WebCore/RenderView.h>
93 #include <WebCore/RenderTreeAsText.h>
94 #include <WebCore/Settings.h>
95 #include <WebCore/SVGDocumentExtensions.h>
96 #include <WebCore/SVGSMILElement.h>
97 #include <WebCore/TextIterator.h>
98 #include <WebCore/JSDOMBinding.h>
99 #include <WebCore/ScriptController.h>
100 #include <WebCore/SecurityOrigin.h>
101 #include <JavaScriptCore/APICast.h>
102 #include <JavaScriptCore/JSLock.h>
103 #include <JavaScriptCore/JSObject.h>
104 #include <JavaScriptCore/JSValue.h>
105 #include <wtf/MathExtras.h>
108 #include <CoreGraphics/CoreGraphics.h>
110 #include "PlatformContextCairo.h"
111 #include <cairo-win32.h>
115 // CG SPI used for printing
117 CGAffineTransform CGContextGetBaseCTM(CGContextRef c);
118 void CGContextSetBaseCTM(CGContextRef c, CGAffineTransform m);
122 using namespace WebCore;
123 using namespace HTMLNames;
126 using JSC::JSGlobalObject;
129 using JSC::SilenceAssertionsOnly;
131 #define FLASH_REDRAW 0
134 // By imaging to a width a little wider than the available pixels,
135 // thin pages will be scaled down a little, matching the way they
136 // print in IE and Camino. This lets them use fewer sheets than they
137 // would otherwise, which is presumably why other browsers do this.
138 // Wide pages will be scaled down more than this.
139 const float PrintingMinimumShrinkFactor = 1.25f;
141 // This number determines how small we are willing to reduce the page content
142 // in order to accommodate the widest line. If the page would have to be
143 // reduced smaller to make the widest line fit, we just clip instead (this
144 // behavior matches MacIE and Mozilla, at least)
145 const float PrintingMaximumShrinkFactor = 2.0f;
147 //-----------------------------------------------------------------------------
148 // Helpers to convert from WebCore to WebKit type
149 WebFrame* kit(Frame* frame)
154 FrameLoaderClient* frameLoaderClient = frame->loader()->client();
155 if (frameLoaderClient)
156 return static_cast<WebFrame*>(frameLoaderClient); // eek, is there a better way than static cast?
160 Frame* core(WebFrame* webFrame)
164 return webFrame->impl();
167 // This function is not in WebFrame.h because we don't want to advertise the ability to get a non-const Frame from a const WebFrame
168 Frame* core(const WebFrame* webFrame)
172 return const_cast<WebFrame*>(webFrame)->impl();
175 //-----------------------------------------------------------------------------
177 static Element *elementFromDOMElement(IDOMElement *element)
182 COMPtr<IDOMElementPrivate> elePriv;
183 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
186 hr = elePriv->coreElement((void**)&ele);
193 static HTMLFormElement *formElementFromDOMElement(IDOMElement *element)
198 IDOMElementPrivate* elePriv;
199 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
202 hr = elePriv->coreElement((void**)&ele);
204 if (SUCCEEDED(hr) && ele && ele->hasTagName(formTag))
205 return static_cast<HTMLFormElement*>(ele);
210 static HTMLInputElement* inputElementFromDOMElement(IDOMElement* element)
215 IDOMElementPrivate* elePriv;
216 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
219 hr = elePriv->coreElement((void**)&ele);
221 if (SUCCEEDED(hr) && ele && ele->hasTagName(inputTag))
222 return static_cast<HTMLInputElement*>(ele);
227 // WebFramePrivate ------------------------------------------------------------
229 class WebFrame::WebFramePrivate {
234 , m_policyFunction(0)
238 ~WebFramePrivate() { }
239 FrameView* frameView() { return frame ? frame->view() : 0; }
243 FramePolicyFunction m_policyFunction;
244 COMPtr<WebFramePolicyListener> m_policyListener;
247 // WebFrame ----------------------------------------------------------------
250 : WebFrameLoaderClient(this)
252 , d(new WebFrame::WebFramePrivate)
253 , m_quickRedirectComing(false)
254 , m_inPrintingMode(false)
259 gClassNameCount.add("WebFrame");
262 WebFrame::~WebFrame()
267 gClassNameCount.remove("WebFrame");
270 WebFrame* WebFrame::createInstance()
272 WebFrame* instance = new WebFrame();
277 HRESULT STDMETHODCALLTYPE WebFrame::setAllowsScrolling(
278 /* [in] */ BOOL flag)
280 if (Frame* frame = core(this))
281 if (FrameView* view = frame->view())
282 view->setCanHaveScrollbars(!!flag);
287 HRESULT STDMETHODCALLTYPE WebFrame::allowsScrolling(
288 /* [retval][out] */ BOOL *flag)
291 if (Frame* frame = core(this))
292 if (FrameView* view = frame->view())
293 *flag = view->canHaveScrollbars();
298 HRESULT STDMETHODCALLTYPE WebFrame::setIsDisconnected(
299 /* [in] */ BOOL flag)
301 if (Frame* frame = core(this)) {
302 frame->setIsDisconnected(flag);
309 HRESULT STDMETHODCALLTYPE WebFrame::setExcludeFromTextSearch(
310 /* [in] */ BOOL flag)
312 if (Frame* frame = core(this)) {
313 frame->setExcludeFromTextSearch(flag);
320 HRESULT WebFrame::reloadFromOrigin()
322 Frame* coreFrame = core(this);
326 coreFrame->loader()->reload(true);
330 HRESULT STDMETHODCALLTYPE WebFrame::paintDocumentRectToContext(
331 /* [in] */ RECT rect,
332 /* [in] */ OLE_HANDLE deviceContext)
334 Frame* coreFrame = core(this);
338 FrameView* view = coreFrame->view();
342 // We can't paint with a layout still pending.
343 view->updateLayoutAndStyleIfNeededRecursive();
345 HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
346 GraphicsContext gc(dc);
347 gc.setShouldIncludeChildWindows(true);
349 LONG width = rect.right - rect.left;
350 LONG height = rect.bottom - rect.top;
352 dirtyRect.setWidth(width);
353 dirtyRect.setHeight(height);
355 gc.translate(-rect.left, -rect.top);
356 view->paintContents(&gc, rect);
362 HRESULT STDMETHODCALLTYPE WebFrame::paintScrollViewRectToContextAtPoint(
363 /* [in] */ RECT rect,
365 /* [in] */ OLE_HANDLE deviceContext)
367 Frame* coreFrame = core(this);
371 FrameView* view = coreFrame->view();
375 // We can't paint with a layout still pending.
376 view->updateLayoutAndStyleIfNeededRecursive();
378 HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
379 GraphicsContext gc(dc);
380 gc.setShouldIncludeChildWindows(true);
382 IntRect dirtyRect(rect);
383 dirtyRect.move(-pt.x, -pt.y);
384 view->paint(&gc, dirtyRect);
390 // IUnknown -------------------------------------------------------------------
392 HRESULT STDMETHODCALLTYPE WebFrame::QueryInterface(REFIID riid, void** ppvObject)
395 if (IsEqualGUID(riid, __uuidof(WebFrame)))
397 else if (IsEqualGUID(riid, IID_IUnknown))
398 *ppvObject = static_cast<IWebFrame*>(this);
399 else if (IsEqualGUID(riid, IID_IWebFrame))
400 *ppvObject = static_cast<IWebFrame*>(this);
401 else if (IsEqualGUID(riid, IID_IWebFramePrivate))
402 *ppvObject = static_cast<IWebFramePrivate*>(this);
403 else if (IsEqualGUID(riid, IID_IWebDocumentText))
404 *ppvObject = static_cast<IWebDocumentText*>(this);
406 return E_NOINTERFACE;
412 ULONG STDMETHODCALLTYPE WebFrame::AddRef(void)
417 ULONG STDMETHODCALLTYPE WebFrame::Release(void)
419 ULONG newRef = --m_refCount;
426 // IWebFrame -------------------------------------------------------------------
428 HRESULT STDMETHODCALLTYPE WebFrame::name(
429 /* [retval][out] */ BSTR* frameName)
432 ASSERT_NOT_REACHED();
438 Frame* coreFrame = core(this);
442 *frameName = BString(coreFrame->tree()->uniqueName()).release();
446 HRESULT STDMETHODCALLTYPE WebFrame::webView(
447 /* [retval][out] */ IWebView** view)
457 HRESULT STDMETHODCALLTYPE WebFrame::frameView(
458 /* [retval][out] */ IWebFrameView** /*view*/)
460 ASSERT_NOT_REACHED();
464 HRESULT STDMETHODCALLTYPE WebFrame::DOMDocument(
465 /* [retval][out] */ IDOMDocument** result)
468 ASSERT_NOT_REACHED();
474 if (Frame* coreFrame = core(this))
475 if (Document* document = coreFrame->document())
476 *result = DOMDocument::createInstance(document);
478 return *result ? S_OK : E_FAIL;
481 HRESULT STDMETHODCALLTYPE WebFrame::frameElement(
482 /* [retval][out] */ IDOMHTMLElement** frameElement)
488 Frame* coreFrame = core(this);
492 COMPtr<IDOMElement> domElement(AdoptCOM, DOMElement::createInstance(coreFrame->ownerElement()));
493 COMPtr<IDOMHTMLElement> htmlElement(Query, domElement);
496 return htmlElement.copyRefTo(frameElement);
499 HRESULT STDMETHODCALLTYPE WebFrame::currentForm(
500 /* [retval][out] */ IDOMElement **currentForm)
503 ASSERT_NOT_REACHED();
509 if (Frame* coreFrame = core(this)) {
510 if (HTMLFormElement* formElement = coreFrame->selection()->currentForm())
511 *currentForm = DOMElement::createInstance(formElement);
514 return *currentForm ? S_OK : E_FAIL;
517 JSGlobalContextRef STDMETHODCALLTYPE WebFrame::globalContext()
519 Frame* coreFrame = core(this);
523 return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
526 JSGlobalContextRef WebFrame::globalContextForScriptWorld(IWebScriptWorld* iWorld)
528 Frame* coreFrame = core(this);
532 COMPtr<WebScriptWorld> world(Query, iWorld);
536 return toGlobalRef(coreFrame->script()->globalObject(world->world())->globalExec());
539 HRESULT STDMETHODCALLTYPE WebFrame::loadRequest(
540 /* [in] */ IWebURLRequest* request)
542 COMPtr<WebMutableURLRequest> requestImpl;
544 HRESULT hr = request->QueryInterface(&requestImpl);
548 Frame* coreFrame = core(this);
552 coreFrame->loader()->load(requestImpl->resourceRequest(), false);
556 void WebFrame::loadData(PassRefPtr<WebCore::SharedBuffer> data, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL)
558 String mimeTypeString(mimeType, SysStringLen(mimeType));
560 mimeTypeString = "text/html";
562 String encodingString(textEncodingName, SysStringLen(textEncodingName));
564 // FIXME: We should really be using MarshallingHelpers::BSTRToKURL here,
565 // but that would turn a null BSTR into a null KURL, and we crash inside of
566 // WebCore if we use a null KURL in constructing the ResourceRequest.
567 KURL baseKURL = KURL(KURL(), String(baseURL ? baseURL : L"", SysStringLen(baseURL)));
569 KURL failingKURL = MarshallingHelpers::BSTRToKURL(failingURL);
571 ResourceRequest request(baseKURL);
572 SubstituteData substituteData(data, mimeTypeString, encodingString, failingKURL);
574 // This method is only called from IWebFrame methods, so don't ASSERT that the Frame pointer isn't null.
575 if (Frame* coreFrame = core(this))
576 coreFrame->loader()->load(request, substituteData, false);
580 HRESULT STDMETHODCALLTYPE WebFrame::loadData(
581 /* [in] */ IStream* data,
582 /* [in] */ BSTR mimeType,
583 /* [in] */ BSTR textEncodingName,
586 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
589 if (SUCCEEDED(data->Stat(&stat, STATFLAG_NONAME))) {
590 if (!stat.cbSize.HighPart && stat.cbSize.LowPart) {
591 Vector<char> dataBuffer(stat.cbSize.LowPart);
593 // FIXME: this does a needless copy, would be better to read right into the SharedBuffer
594 // or adopt the Vector or something.
595 if (SUCCEEDED(data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read)))
596 sharedBuffer->append(dataBuffer.data(), static_cast<int>(dataBuffer.size()));
600 loadData(sharedBuffer, mimeType, textEncodingName, url, 0);
604 HRESULT WebFrame::loadPlainTextString(
605 /* [in] */ BSTR string,
608 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
609 BString plainTextMimeType(TEXT("text/plain"), 10);
610 BString utf16Encoding(TEXT("utf-16"), 6);
611 loadData(sharedBuffer.release(), plainTextMimeType, utf16Encoding, url, 0);
615 void WebFrame::loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL)
617 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
618 BString utf16Encoding(TEXT("utf-16"), 6);
619 loadData(sharedBuffer.release(), 0, utf16Encoding, baseURL, unreachableURL);
622 HRESULT STDMETHODCALLTYPE WebFrame::loadHTMLString(
623 /* [in] */ BSTR string,
624 /* [in] */ BSTR baseURL)
626 loadHTMLString(string, baseURL, 0);
630 HRESULT STDMETHODCALLTYPE WebFrame::loadAlternateHTMLString(
632 /* [in] */ BSTR baseURL,
633 /* [in] */ BSTR unreachableURL)
635 loadHTMLString(str, baseURL, unreachableURL);
639 HRESULT STDMETHODCALLTYPE WebFrame::loadArchive(
640 /* [in] */ IWebArchive* /*archive*/)
642 ASSERT_NOT_REACHED();
646 static inline WebDataSource *getWebDataSource(DocumentLoader* loader)
648 return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;
651 HRESULT STDMETHODCALLTYPE WebFrame::dataSource(
652 /* [retval][out] */ IWebDataSource** source)
655 ASSERT_NOT_REACHED();
661 Frame* coreFrame = core(this);
665 WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->documentLoader());
667 *source = webDataSource;
670 webDataSource->AddRef();
672 return *source ? S_OK : E_FAIL;
675 HRESULT STDMETHODCALLTYPE WebFrame::provisionalDataSource(
676 /* [retval][out] */ IWebDataSource** source)
679 ASSERT_NOT_REACHED();
685 Frame* coreFrame = core(this);
689 WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->provisionalDocumentLoader());
691 *source = webDataSource;
694 webDataSource->AddRef();
696 return *source ? S_OK : E_FAIL;
699 KURL WebFrame::url() const
701 Frame* coreFrame = core(this);
705 return coreFrame->document()->url();
708 HRESULT STDMETHODCALLTYPE WebFrame::stopLoading( void)
710 if (Frame* coreFrame = core(this))
711 coreFrame->loader()->stopAllLoaders();
715 HRESULT STDMETHODCALLTYPE WebFrame::reload( void)
717 Frame* coreFrame = core(this);
721 coreFrame->loader()->reload();
725 HRESULT STDMETHODCALLTYPE WebFrame::findFrameNamed(
726 /* [in] */ BSTR name,
727 /* [retval][out] */ IWebFrame** frame)
730 ASSERT_NOT_REACHED();
736 Frame* coreFrame = core(this);
740 Frame* foundFrame = coreFrame->tree()->find(AtomicString(name, SysStringLen(name)));
744 WebFrame* foundWebFrame = kit(foundFrame);
748 return foundWebFrame->QueryInterface(IID_IWebFrame, (void**)frame);
751 HRESULT STDMETHODCALLTYPE WebFrame::parentFrame(
752 /* [retval][out] */ IWebFrame** frame)
756 if (Frame* coreFrame = core(this))
757 if (WebFrame* webFrame = kit(coreFrame->tree()->parent()))
758 hr = webFrame->QueryInterface(IID_IWebFrame, (void**) frame);
763 class EnumChildFrames : public IEnumVARIANT
766 EnumChildFrames(Frame* f) : m_refCount(1), m_frame(f), m_curChild(f ? f->tree()->firstChild() : 0) { }
768 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
771 if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
774 return E_NOINTERFACE;
780 virtual ULONG STDMETHODCALLTYPE AddRef(void)
785 virtual ULONG STDMETHODCALLTYPE Release(void)
787 ULONG newRef = --m_refCount;
793 virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
800 if (!celt || celt > 1)
802 if (!m_frame || !m_curChild)
805 WebFrame* webFrame = kit(m_curChild);
807 HRESULT hr = webFrame->QueryInterface(IID_IUnknown, (void**)&unknown);
811 V_VT(rgVar) = VT_UNKNOWN;
812 V_UNKNOWN(rgVar) = unknown;
814 m_curChild = m_curChild->tree()->nextSibling();
820 virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
824 for (unsigned i = 0; i < celt && m_curChild; i++)
825 m_curChild = m_curChild->tree()->nextSibling();
826 return m_curChild ? S_OK : S_FALSE;
829 virtual HRESULT STDMETHODCALLTYPE Reset(void)
833 m_curChild = m_frame->tree()->firstChild();
837 virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**)
848 HRESULT STDMETHODCALLTYPE WebFrame::childFrames(
849 /* [retval][out] */ IEnumVARIANT **enumFrames)
854 *enumFrames = new EnumChildFrames(core(this));
858 // IWebFramePrivate ------------------------------------------------------
860 HRESULT WebFrame::renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result)
865 Frame* coreFrame = core(this);
869 *result = BString(externalRepresentation(coreFrame, forPrinting ? RenderAsTextPrintingMode : RenderAsTextBehaviorNormal)).release();
873 HRESULT STDMETHODCALLTYPE WebFrame::counterValueForElementById(
874 /* [in] */ BSTR id, /* [retval][out] */ BSTR *result)
879 Frame* coreFrame = core(this);
883 String coreId = String(id, SysStringLen(id));
885 Element* element = coreFrame->document()->getElementById(coreId);
888 *result = BString(counterValueForElement(element)).release();
892 HRESULT STDMETHODCALLTYPE WebFrame::pageNumberForElementById(
894 /* [in] */ float pageWidthInPixels,
895 /* [in] */ float pageHeightInPixels,
896 /* [retval][out] */ int* result)
901 Frame* coreFrame = core(this);
905 String coreId = String(id, SysStringLen(id));
907 Element* element = coreFrame->document()->getElementById(coreId);
910 *result = PrintContext::pageNumberForElement(element, FloatSize(pageWidthInPixels, pageHeightInPixels));
914 HRESULT STDMETHODCALLTYPE WebFrame::numberOfPages(
915 /* [in] */ float pageWidthInPixels,
916 /* [in] */ float pageHeightInPixels,
917 /* [retval][out] */ int* result)
922 Frame* coreFrame = core(this);
926 *result = PrintContext::numberOfPages(coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
930 HRESULT STDMETHODCALLTYPE WebFrame::scrollOffset(
931 /* [retval][out] */ SIZE* offset)
934 ASSERT_NOT_REACHED();
938 Frame* coreFrame = core(this);
942 FrameView* view = coreFrame->view();
946 *offset = view->scrollOffset();
950 HRESULT STDMETHODCALLTYPE WebFrame::layout()
952 Frame* coreFrame = core(this);
956 FrameView* view = coreFrame->view();
964 HRESULT STDMETHODCALLTYPE WebFrame::firstLayoutDone(
965 /* [retval][out] */ BOOL* result)
968 ASSERT_NOT_REACHED();
974 Frame* coreFrame = core(this);
978 *result = coreFrame->loader()->stateMachine()->firstLayoutDone();
982 HRESULT STDMETHODCALLTYPE WebFrame::loadType(
983 /* [retval][out] */ WebFrameLoadType* type)
986 ASSERT_NOT_REACHED();
990 *type = (WebFrameLoadType)0;
992 Frame* coreFrame = core(this);
996 *type = (WebFrameLoadType)coreFrame->loader()->loadType();
1000 HRESULT STDMETHODCALLTYPE WebFrame::pendingFrameUnloadEventCount(
1001 /* [retval][out] */ UINT* result)
1004 ASSERT_NOT_REACHED();
1010 Frame* coreFrame = core(this);
1014 *result = coreFrame->domWindow()->pendingUnloadEventListeners();
1018 HRESULT STDMETHODCALLTYPE WebFrame::unused2()
1023 HRESULT STDMETHODCALLTYPE WebFrame::hasSpellingMarker(
1024 /* [in] */ UINT from,
1025 /* [in] */ UINT length,
1026 /* [retval][out] */ BOOL* result)
1028 Frame* coreFrame = core(this);
1031 *result = coreFrame->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1035 HRESULT STDMETHODCALLTYPE WebFrame::clearOpener()
1038 if (Frame* coreFrame = core(this))
1039 coreFrame->loader()->setOpener(0);
1044 // IWebDocumentText -----------------------------------------------------------
1046 HRESULT STDMETHODCALLTYPE WebFrame::supportsTextEncoding(
1047 /* [retval][out] */ BOOL* result)
1053 HRESULT STDMETHODCALLTYPE WebFrame::selectedString(
1054 /* [retval][out] */ BSTR* result)
1058 Frame* coreFrame = core(this);
1062 String text = coreFrame->displayStringModifiedByEncoding(coreFrame->editor()->selectedText());
1064 *result = BString(text).release();
1068 HRESULT STDMETHODCALLTYPE WebFrame::selectAll()
1070 Frame* coreFrame = core(this);
1074 if (!coreFrame->editor()->command("SelectAll").execute())
1080 HRESULT STDMETHODCALLTYPE WebFrame::deselectAll()
1085 // WebFrame ---------------------------------------------------------------
1087 PassRefPtr<Frame> WebFrame::init(IWebView* webView, Page* page, HTMLFrameOwnerElement* ownerElement)
1089 webView->QueryInterface(&d->webView);
1090 d->webView->Release(); // don't hold the extra ref
1093 d->webView->viewWindow((OLE_HANDLE*)&viewWindow);
1095 this->AddRef(); // We release this ref in frameLoaderDestroyed()
1096 RefPtr<Frame> frame = Frame::create(page, ownerElement, this);
1097 d->frame = frame.get();
1098 return frame.release();
1101 Frame* WebFrame::impl()
1106 void WebFrame::invalidate()
1108 Frame* coreFrame = core(this);
1111 if (Document* document = coreFrame->document())
1112 document->recalcStyle(Node::Force);
1115 HRESULT WebFrame::inViewSourceMode(BOOL* flag)
1118 ASSERT_NOT_REACHED();
1124 Frame* coreFrame = core(this);
1128 *flag = coreFrame->inViewSourceMode() ? TRUE : FALSE;
1132 HRESULT WebFrame::setInViewSourceMode(BOOL flag)
1134 Frame* coreFrame = core(this);
1138 coreFrame->setInViewSourceMode(!!flag);
1142 HRESULT WebFrame::elementWithName(BSTR name, IDOMElement* form, IDOMElement** element)
1145 return E_INVALIDARG;
1147 HTMLFormElement* formElement = formElementFromDOMElement(form);
1149 const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
1150 AtomicString targetName((UChar*)name, SysStringLen(name));
1151 for (unsigned int i = 0; i < elements.size(); i++) {
1152 if (!elements[i]->isFormControlElement())
1154 HTMLFormControlElement* elt = static_cast<HTMLFormControlElement*>(elements[i]);
1155 // Skip option elements, other duds
1156 if (elt->name() == targetName) {
1157 *element = DOMElement::createInstance(elt);
1165 HRESULT WebFrame::formForElement(IDOMElement* element, IDOMElement** form)
1168 return E_INVALIDARG;
1170 HTMLInputElement *inputElement = inputElementFromDOMElement(element);
1174 HTMLFormElement *formElement = inputElement->form();
1178 *form = DOMElement::createInstance(formElement);
1182 HRESULT WebFrame::elementDoesAutoComplete(IDOMElement *element, BOOL *result)
1186 return E_INVALIDARG;
1188 HTMLInputElement *inputElement = inputElementFromDOMElement(element);
1192 *result = inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->autoComplete();
1197 HRESULT WebFrame::pauseAnimation(BSTR animationName, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning)
1199 if (!node || !animationWasRunning)
1202 *animationWasRunning = FALSE;
1204 Frame* frame = core(this);
1208 AnimationController* controller = frame->animation();
1212 COMPtr<DOMNode> domNode(Query, node);
1216 *animationWasRunning = controller->pauseAnimationAtTime(domNode->node()->renderer(), String(animationName, SysStringLen(animationName)), secondsFromNow);
1220 HRESULT WebFrame::pauseTransition(BSTR propertyName, IDOMNode* node, double secondsFromNow, BOOL* transitionWasRunning)
1222 if (!node || !transitionWasRunning)
1225 *transitionWasRunning = FALSE;
1227 Frame* frame = core(this);
1231 AnimationController* controller = frame->animation();
1235 COMPtr<DOMNode> domNode(Query, node);
1239 *transitionWasRunning = controller->pauseTransitionAtTime(domNode->node()->renderer(), String(propertyName, SysStringLen(propertyName)), secondsFromNow);
1243 HRESULT WebFrame::pauseSVGAnimation(BSTR elementId, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning)
1245 if (!node || !animationWasRunning)
1248 *animationWasRunning = FALSE;
1250 Frame* frame = core(this);
1254 Document* document = frame->document();
1255 if (!document || !document->svgExtensions())
1258 COMPtr<DOMNode> domNode(Query, node);
1259 if (!domNode || !SVGSMILElement::isSMILElement(domNode->node()))
1263 *animationWasRunning = document->accessSVGExtensions()->sampleAnimationAtTime(String(elementId, SysStringLen(elementId)), static_cast<SVGSMILElement*>(domNode->node()), secondsFromNow);
1265 *animationWasRunning = FALSE;
1271 HRESULT WebFrame::visibleContentRect(RECT* rect)
1277 Frame* frame = core(this);
1281 FrameView* view = frame->view();
1285 *rect = view->visibleContentRect(false);
1289 HRESULT WebFrame::numberOfActiveAnimations(UINT* number)
1296 Frame* frame = core(this);
1300 AnimationController* controller = frame->animation();
1304 *number = controller->numberOfActiveAnimations();
1308 HRESULT WebFrame::suspendAnimations()
1310 Frame* frame = core(this);
1314 frame->animation()->suspendAnimations();
1318 HRESULT WebFrame::resumeAnimations()
1320 Frame* frame = core(this);
1324 frame->animation()->resumeAnimations();
1328 HRESULT WebFrame::isDisplayingStandaloneImage(BOOL* result)
1335 Frame* frame = core(this);
1339 Document* document = frame->document();
1340 *result = document && document->isImageDocument();
1344 HRESULT WebFrame::allowsFollowingLink(BSTR url, BOOL* result)
1351 Frame* frame = core(this);
1355 *result = frame->document()->securityOrigin()->canDisplay(MarshallingHelpers::BSTRToKURL(url));
1359 HRESULT WebFrame::controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls)
1362 return E_INVALIDARG;
1364 HTMLFormElement* formElement = formElementFromDOMElement(form);
1368 int inCount = *cControls;
1369 int count = (int) formElement->associatedElements().size();
1373 if (inCount < count)
1377 const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
1378 for (int i = 0; i < count; i++) {
1379 if (elements.at(i)->isEnumeratable()) { // Skip option elements, other duds
1380 controls[*cControls] = DOMElement::createInstance(toHTMLElement(elements.at(i)));
1387 HRESULT WebFrame::elementIsPassword(IDOMElement *element, bool *result)
1389 HTMLInputElement* inputElement = inputElementFromDOMElement(element);
1390 *result = inputElement && inputElement->isPasswordField();
1394 HRESULT WebFrame::searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* outResultDistance, BOOL* outResultIsInCellAbove, BSTR* result)
1397 ASSERT_NOT_REACHED();
1401 if (outResultDistance)
1402 *outResultDistance = 0;
1403 if (outResultIsInCellAbove)
1404 *outResultIsInCellAbove = FALSE;
1410 return E_INVALIDARG;
1412 Frame* coreFrame = core(this);
1416 Vector<String> labelStrings(cLabels);
1417 for (int i=0; i<cLabels; i++)
1418 labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
1419 Element *coreElement = elementFromDOMElement(beforeElement);
1423 size_t resultDistance;
1424 bool resultIsInCellAbove;
1425 String label = coreFrame->searchForLabelsBeforeElement(labelStrings, coreElement, &resultDistance, &resultIsInCellAbove);
1427 *result = SysAllocStringLen(label.characters(), label.length());
1428 if (label.length() && !*result)
1429 return E_OUTOFMEMORY;
1430 if (outResultDistance)
1431 *outResultDistance = resultDistance;
1432 if (outResultIsInCellAbove)
1433 *outResultIsInCellAbove = resultIsInCellAbove;
1438 HRESULT WebFrame::matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result)
1441 ASSERT_NOT_REACHED();
1450 return E_INVALIDARG;
1452 Frame* coreFrame = core(this);
1456 Vector<String> labelStrings(cLabels);
1457 for (int i=0; i<cLabels; i++)
1458 labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
1459 Element *coreElement = elementFromDOMElement(againstElement);
1463 String label = coreFrame->matchLabelsAgainstElement(labelStrings, coreElement);
1465 *result = SysAllocStringLen(label.characters(), label.length());
1466 if (label.length() && !*result)
1467 return E_OUTOFMEMORY;
1471 HRESULT WebFrame::canProvideDocumentSource(bool* result)
1476 COMPtr<IWebDataSource> dataSource;
1477 hr = WebFrame::dataSource(&dataSource);
1481 COMPtr<IWebURLResponse> urlResponse;
1482 hr = dataSource->response(&urlResponse);
1483 if (SUCCEEDED(hr) && urlResponse) {
1485 if (SUCCEEDED(urlResponse->MIMEType(&mimeTypeBStr))) {
1486 String mimeType(mimeTypeBStr, SysStringLen(mimeTypeBStr));
1487 *result = mimeType == "text/html" || WebCore::DOMImplementation::isXMLMIMEType(mimeType);
1488 SysFreeString(mimeTypeBStr);
1494 HRESULT STDMETHODCALLTYPE WebFrame::layerTreeAsText(BSTR* result)
1500 Frame* frame = core(this);
1504 String text = frame->layerTreeAsText();
1505 *result = BString(text).release();
1509 void WebFrame::frameLoaderDestroyed()
1511 // The FrameLoader going away is equivalent to the Frame going away,
1512 // so we now need to clear our frame pointer.
1518 void WebFrame::makeRepresentation(DocumentLoader*)
1523 void WebFrame::forceLayoutForNonHTML()
1528 void WebFrame::setCopiesOnScroll()
1533 void WebFrame::detachedFromParent2()
1538 void WebFrame::detachedFromParent3()
1543 void WebFrame::cancelPolicyCheck()
1545 if (d->m_policyListener) {
1546 d->m_policyListener->invalidate();
1547 d->m_policyListener = 0;
1550 d->m_policyFunction = 0;
1553 void WebFrame::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState)
1555 Frame* coreFrame = core(this);
1558 COMPtr<IWebFormDelegate> formDelegate;
1560 if (FAILED(d->webView->formDelegate(&formDelegate))) {
1561 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1565 COMPtr<IDOMElement> formElement(AdoptCOM, DOMElement::createInstance(formState->form()));
1567 HashMap<String, String> formValuesMap;
1568 const StringPairVector& textFieldValues = formState->textFieldValues();
1569 size_t size = textFieldValues.size();
1570 for (size_t i = 0; i < size; ++i)
1571 formValuesMap.add(textFieldValues[i].first, textFieldValues[i].second);
1573 COMPtr<IPropertyBag> formValuesPropertyBag(AdoptCOM, COMPropertyBag<String>::createInstance(formValuesMap));
1575 COMPtr<WebFrame> sourceFrame(kit(formState->sourceFrame()));
1576 if (SUCCEEDED(formDelegate->willSubmitForm(this, sourceFrame.get(), formElement.get(), formValuesPropertyBag.get(), setUpPolicyListener(function).get())))
1579 // FIXME: Add a sane default implementation
1580 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1583 void WebFrame::revertToProvisionalState(DocumentLoader*)
1588 void WebFrame::setMainFrameDocumentReady(bool)
1593 void WebFrame::willChangeTitle(DocumentLoader*)
1598 void WebFrame::didChangeTitle(DocumentLoader*)
1603 void WebFrame::didChangeIcons(DocumentLoader*)
1608 bool WebFrame::canHandleRequest(const ResourceRequest& request) const
1610 return WebView::canHandleRequest(request);
1613 bool WebFrame::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
1619 bool WebFrame::canShowMIMEType(const String& /*MIMEType*/) const
1625 bool WebFrame::representationExistsForURLScheme(const String& /*URLScheme*/) const
1631 String WebFrame::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const
1634 ASSERT_NOT_REACHED();
1638 void WebFrame::frameLoadCompleted()
1642 void WebFrame::restoreViewState()
1646 void WebFrame::provisionalLoadStarted()
1651 bool WebFrame::shouldTreatURLAsSameAsCurrent(const KURL&) const
1657 void WebFrame::addHistoryItemForFragmentScroll()
1662 void WebFrame::didFinishLoad()
1667 void WebFrame::prepareForDataSourceReplacement()
1672 String WebFrame::userAgent(const KURL& url)
1674 return d->webView->userAgentForKURL(url);
1677 void WebFrame::saveViewStateToItem(HistoryItem*)
1681 ResourceError WebFrame::cancelledError(const ResourceRequest& request)
1683 // FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values
1684 // Alternatively, we could create our own error domain/codes.
1685 return ResourceError(String(WebURLErrorDomain), -999, request.url().string(), String());
1688 ResourceError WebFrame::blockedError(const ResourceRequest& request)
1690 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1691 return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotUseRestrictedPort, request.url().string(), String());
1694 ResourceError WebFrame::cannotShowURLError(const ResourceRequest& request)
1696 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1697 return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotShowURL, request.url().string(), String());
1700 ResourceError WebFrame::interruptForPolicyChangeError(const ResourceRequest& request)
1702 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1703 return ResourceError(String(WebKitErrorDomain), WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(), String());
1706 ResourceError WebFrame::cannotShowMIMETypeError(const ResourceResponse&)
1709 return ResourceError();
1712 ResourceError WebFrame::fileDoesNotExistError(const ResourceResponse&)
1715 return ResourceError();
1718 ResourceError WebFrame::pluginWillHandleLoadError(const ResourceResponse& response)
1720 return ResourceError(String(WebKitErrorDomain), WebKitErrorPlugInWillHandleLoad, response.url().string(), String());
1723 bool WebFrame::shouldFallBack(const ResourceError& error)
1725 if (error.errorCode() == WebURLErrorCancelled && error.domain() == String(WebURLErrorDomain))
1728 if (error.errorCode() == WebKitErrorPlugInWillHandleLoad && error.domain() == String(WebKitErrorDomain))
1734 COMPtr<WebFramePolicyListener> WebFrame::setUpPolicyListener(WebCore::FramePolicyFunction function)
1736 // FIXME: <rdar://5634381> We need to support multiple active policy listeners.
1738 if (d->m_policyListener)
1739 d->m_policyListener->invalidate();
1741 Frame* coreFrame = core(this);
1744 d->m_policyListener.adoptRef(WebFramePolicyListener::createInstance(coreFrame));
1745 d->m_policyFunction = function;
1747 return d->m_policyListener;
1750 void WebFrame::receivedPolicyDecision(PolicyAction action)
1752 ASSERT(d->m_policyListener);
1753 ASSERT(d->m_policyFunction);
1755 FramePolicyFunction function = d->m_policyFunction;
1757 d->m_policyListener = 0;
1758 d->m_policyFunction = 0;
1760 Frame* coreFrame = core(this);
1763 (coreFrame->loader()->policyChecker()->*function)(action);
1766 void WebFrame::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& request)
1768 Frame* coreFrame = core(this);
1771 COMPtr<IWebPolicyDelegate> policyDelegate;
1772 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1773 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1775 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1777 if (SUCCEEDED(policyDelegate->decidePolicyForMIMEType(d->webView, BString(response.mimeType()), urlRequest.get(), this, setUpPolicyListener(function).get())))
1780 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1783 void WebFrame::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName)
1785 Frame* coreFrame = core(this);
1788 COMPtr<IWebPolicyDelegate> policyDelegate;
1789 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1790 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1792 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1793 COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
1795 if (SUCCEEDED(policyDelegate->decidePolicyForNewWindowAction(d->webView, actionInformation.get(), urlRequest.get(), BString(frameName), setUpPolicyListener(function).get())))
1798 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1801 void WebFrame::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState)
1803 Frame* coreFrame = core(this);
1806 COMPtr<IWebPolicyDelegate> policyDelegate;
1807 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1808 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1810 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1811 COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
1813 if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get())))
1816 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1819 void WebFrame::dispatchUnableToImplementPolicy(const ResourceError& error)
1821 COMPtr<IWebPolicyDelegate> policyDelegate;
1822 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1823 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1825 COMPtr<IWebError> webError(AdoptCOM, WebError::createInstance(error));
1826 policyDelegate->unableToImplementPolicyWithError(d->webView, webError.get(), this);
1829 void WebFrame::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest&, const ResourceResponse& response)
1831 COMPtr<IWebDownloadDelegate> downloadDelegate;
1832 COMPtr<IWebView> webView;
1833 if (SUCCEEDED(this->webView(&webView))) {
1834 if (FAILED(webView->downloadDelegate(&downloadDelegate))) {
1835 // If the WebView doesn't successfully provide a download delegate we'll pass a null one
1836 // into the WebDownload - which may or may not decide to use a DefaultDownloadDelegate
1837 LOG_ERROR("Failed to get downloadDelegate from WebView");
1838 downloadDelegate = 0;
1842 // Its the delegate's job to ref the WebDownload to keep it alive - otherwise it will be destroyed
1843 // when this method returns
1844 COMPtr<WebDownload> download;
1845 download.adoptRef(WebDownload::createInstance(handle, request, response, downloadDelegate.get()));
1848 bool WebFrame::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
1854 void WebFrame::dispatchDidFailProvisionalLoad(const ResourceError& error)
1856 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1857 if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
1858 COMPtr<IWebError> webError;
1859 webError.adoptRef(WebError::createInstance(error));
1860 frameLoadDelegate->didFailProvisionalLoadWithError(d->webView, webError.get(), this);
1864 void WebFrame::dispatchDidFailLoad(const ResourceError& error)
1866 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1867 if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
1868 COMPtr<IWebError> webError;
1869 webError.adoptRef(WebError::createInstance(error));
1870 frameLoadDelegate->didFailLoadWithError(d->webView, webError.get(), this);
1874 void WebFrame::startDownload(const ResourceRequest& request)
1876 d->webView->downloadURL(request.url());
1879 PassRefPtr<Widget> WebFrame::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* element, const KURL& /*baseURL*/, const Vector<String>& paramNames, const Vector<String>& paramValues)
1881 RefPtr<PluginView> pluginView = PluginView::create(core(this), pluginSize, element, KURL(), paramNames, paramValues, "application/x-java-applet", false);
1883 // Check if the plugin can be loaded successfully
1884 if (pluginView->plugin() && pluginView->plugin()->load())
1887 COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
1888 if (FAILED(d->webView->resourceLoadDelegate(&resourceLoadDelegate)))
1891 COMPtr<CFDictionaryPropertyBag> userInfoBag = CFDictionaryPropertyBag::createInstance();
1893 ResourceError resourceError(String(WebKitErrorDomain), WebKitErrorJavaUnavailable, String(), String());
1894 COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
1896 resourceLoadDelegate->plugInFailedWithError(d->webView, error.get(), getWebDataSource(d->frame->loader()->documentLoader()));
1901 ObjectContentType WebFrame::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
1903 return WebCore::FrameLoader::defaultObjectContentType(url, mimeType, shouldPreferPlugInsForImages);
1906 String WebFrame::overrideMediaType() const
1912 void WebFrame::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
1914 Frame* coreFrame = core(this);
1917 Settings* settings = coreFrame->settings();
1918 if (!settings || !settings->isJavaScriptEnabled())
1921 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1922 if (FAILED(d->webView->frameLoadDelegate(&frameLoadDelegate)))
1925 COMPtr<IWebFrameLoadDelegatePrivate2> delegatePrivate(Query, frameLoadDelegate);
1926 if (delegatePrivate && delegatePrivate->didClearWindowObjectForFrameInScriptWorld(d->webView, this, WebScriptWorld::findOrCreateWorld(world).get()) != E_NOTIMPL)
1929 if (world != mainThreadNormalWorld())
1932 JSContextRef context = toRef(coreFrame->script()->globalObject(world)->globalExec());
1933 JSObjectRef windowObject = toRef(coreFrame->script()->globalObject(world));
1934 ASSERT(windowObject);
1936 if (FAILED(frameLoadDelegate->didClearWindowObject(d->webView, context, windowObject, this)))
1937 frameLoadDelegate->windowScriptObjectAvailable(d->webView, context, windowObject);
1940 void WebFrame::documentElementAvailable()
1944 void WebFrame::didPerformFirstNavigation() const
1946 COMPtr<IWebPreferences> preferences;
1947 if (FAILED(d->webView->preferences(&preferences)))
1950 COMPtr<IWebPreferencesPrivate> preferencesPrivate(Query, preferences);
1951 if (!preferencesPrivate)
1953 BOOL automaticallyDetectsCacheModel;
1954 if (FAILED(preferencesPrivate->automaticallyDetectsCacheModel(&automaticallyDetectsCacheModel)))
1957 WebCacheModel cacheModel;
1958 if (FAILED(preferences->cacheModel(&cacheModel)))
1961 if (automaticallyDetectsCacheModel && cacheModel < WebCacheModelDocumentBrowser)
1962 preferences->setCacheModel(WebCacheModelDocumentBrowser);
1965 void WebFrame::registerForIconNotification(bool listen)
1967 d->webView->registerForIconNotification(listen);
1970 static IntRect printerRect(HDC printDC)
1972 return IntRect(0, 0,
1973 GetDeviceCaps(printDC, PHYSICALWIDTH) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETX),
1974 GetDeviceCaps(printDC, PHYSICALHEIGHT) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETY));
1977 void WebFrame::setPrinting(bool printing, float minPageWidth, float maxPageWidth, float minPageHeight, bool adjustViewSize)
1979 Frame* coreFrame = core(this);
1981 coreFrame->setPrinting(printing, FloatSize(minPageWidth, minPageHeight), maxPageWidth / minPageWidth, adjustViewSize ? Frame::AdjustViewSize : Frame::DoNotAdjustViewSize);
1984 HRESULT STDMETHODCALLTYPE WebFrame::setInPrintingMode(
1985 /* [in] */ BOOL value,
1986 /* [in] */ HDC printDC)
1988 if (m_inPrintingMode == !!value)
1991 Frame* coreFrame = core(this);
1992 if (!coreFrame || !coreFrame->document())
1995 m_inPrintingMode = !!value;
1997 // If we are a frameset just print with the layout we have onscreen, otherwise relayout
1998 // according to the paper size
1999 float minLayoutWidth = 0.0f;
2000 float maxLayoutWidth = 0.0f;
2001 float minLayoutHeight = 0.0f;
2002 if (m_inPrintingMode && !coreFrame->document()->isFrameSet()) {
2004 ASSERT_NOT_REACHED();
2008 const int desiredPixelsPerInch = 72;
2009 IntRect printRect = printerRect(printDC);
2010 int paperHorizontalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSX);
2011 int paperWidth = printRect.width() * desiredPixelsPerInch / paperHorizontalPixelsPerInch;
2012 int paperVerticalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSY);
2013 int paperHeight = printRect.height() * desiredPixelsPerInch / paperVerticalPixelsPerInch;
2014 minLayoutWidth = paperWidth * PrintingMinimumShrinkFactor;
2015 maxLayoutWidth = paperWidth * PrintingMaximumShrinkFactor;
2016 minLayoutHeight = paperHeight * PrintingMinimumShrinkFactor;
2019 setPrinting(m_inPrintingMode, minLayoutWidth, maxLayoutWidth, minLayoutHeight, true);
2021 if (!m_inPrintingMode)
2022 m_pageRects.clear();
2027 void WebFrame::headerAndFooterHeights(float* headerHeight, float* footerHeight)
2034 COMPtr<IWebUIDelegate> ui;
2035 if (FAILED(d->webView->uiDelegate(&ui)))
2037 if (headerHeight && SUCCEEDED(ui->webViewHeaderHeight(d->webView, &height)))
2038 *headerHeight = height;
2039 if (footerHeight && SUCCEEDED(ui->webViewFooterHeight(d->webView, &height)))
2040 *footerHeight = height;
2043 IntRect WebFrame::printerMarginRect(HDC printDC)
2045 IntRect emptyRect(0, 0, 0, 0);
2047 COMPtr<IWebUIDelegate> ui;
2048 if (FAILED(d->webView->uiDelegate(&ui)))
2052 if (FAILED(ui->webViewPrintingMarginRect(d->webView, &rect)))
2055 rect.left = MulDiv(rect.left, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
2056 rect.top = MulDiv(rect.top, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
2057 rect.right = MulDiv(rect.right, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
2058 rect.bottom = MulDiv(rect.bottom, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
2060 return IntRect(rect.left, rect.top, (rect.right - rect.left), rect.bottom - rect.top);
2063 const Vector<WebCore::IntRect>& WebFrame::computePageRects(HDC printDC)
2065 ASSERT(m_inPrintingMode);
2067 Frame* coreFrame = core(this);
2069 ASSERT(coreFrame->document());
2074 // adjust the page rect by the header and footer
2075 float headerHeight = 0, footerHeight = 0;
2076 headerAndFooterHeights(&headerHeight, &footerHeight);
2077 IntRect pageRect = printerRect(printDC);
2078 IntRect marginRect = printerMarginRect(printDC);
2079 IntRect adjustedRect = IntRect(
2080 pageRect.x() + marginRect.x(),
2081 pageRect.y() + marginRect.y(),
2082 pageRect.width() - marginRect.x() - marginRect.maxX(),
2083 pageRect.height() - marginRect.y() - marginRect.maxY());
2085 computePageRectsForFrame(coreFrame, adjustedRect, headerHeight, footerHeight, 1.0,m_pageRects, m_pageHeight);
2090 HRESULT STDMETHODCALLTYPE WebFrame::getPrintedPageCount(
2091 /* [in] */ HDC printDC,
2092 /* [retval][out] */ UINT *pageCount)
2094 if (!pageCount || !printDC) {
2095 ASSERT_NOT_REACHED();
2101 if (!m_inPrintingMode) {
2102 ASSERT_NOT_REACHED();
2106 Frame* coreFrame = core(this);
2107 if (!coreFrame || !coreFrame->document())
2110 const Vector<IntRect>& pages = computePageRects(printDC);
2111 *pageCount = (UINT) pages.size();
2117 void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
2119 int x = pageRect.x();
2121 RECT headerRect = {x, y, x+pageRect.width(), y+static_cast<int>(headerHeight)};
2122 ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)));
2125 void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
2127 int x = pageRect.x();
2128 int y = max((int)headerHeight+pageRect.height(), m_pageHeight-static_cast<int>(footerHeight));
2129 RECT footerRect = {x, y, x+pageRect.width(), y+static_cast<int>(footerHeight)};
2130 ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)), page+1, pageCount);
2133 void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
2135 Frame* coreFrame = core(this);
2137 IntRect pageRect = m_pageRects[page];
2139 CGContextSaveGState(pctx);
2141 IntRect printRect = printerRect(printDC);
2142 CGRect mediaBox = CGRectMake(CGFloat(0),
2144 CGFloat(printRect.width()),
2145 CGFloat(printRect.height()));
2147 CGContextBeginPage(pctx, &mediaBox);
2149 CGFloat scale = static_cast<float>(mediaBox.size.width)/static_cast<float>(pageRect.width());
2150 CGAffineTransform ctm = CGContextGetBaseCTM(pctx);
2151 ctm = CGAffineTransformScale(ctm, -scale, -scale);
2152 ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
2153 CGContextScaleCTM(pctx, scale, scale);
2154 CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
2155 CGContextSetBaseCTM(pctx, ctm);
2157 coreFrame->view()->paintContents(spoolCtx, pageRect);
2159 CGContextTranslateCTM(pctx, CGFloat(pageRect.x()), CGFloat(pageRect.y())-headerHeight);
2162 drawHeader(pctx, ui, pageRect, headerHeight);
2165 drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
2167 CGContextEndPage(pctx);
2168 CGContextRestoreGState(pctx);
2171 static float scaleFactor(HDC printDC, const IntRect& marginRect, const IntRect& pageRect)
2173 const IntRect& printRect = printerRect(printDC);
2175 IntRect adjustedRect = IntRect(
2176 printRect.x() + marginRect.x(),
2177 printRect.y() + marginRect.y(),
2178 printRect.width() - marginRect.x() - marginRect.maxX(),
2179 printRect.height() - marginRect.y() - marginRect.maxY());
2181 float scale = static_cast<float>(adjustedRect.width()) / static_cast<float>(pageRect.width());
2188 static HDC hdcFromContext(PlatformGraphicsContext* pctx)
2190 return cairo_win32_surface_get_dc(cairo_get_target(pctx->cr()));
2193 void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
2195 HDC hdc = hdcFromContext(pctx);
2197 int x = pageRect.x();
2199 RECT headerRect = {x, y, x + pageRect.width(), y + static_cast<int>(headerHeight)};
2201 ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)));
2204 void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
2206 HDC hdc = hdcFromContext(pctx);
2208 int x = pageRect.x();
2209 int y = max(static_cast<int>(headerHeight) + pageRect.height(), m_pageHeight -static_cast<int>(footerHeight));
2210 RECT footerRect = {x, y, x + pageRect.width(), y + static_cast<int>(footerHeight)};
2212 ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)), page+1, pageCount);
2215 static XFORM buildXFORMFromCairo(HDC targetDC, cairo_t* previewContext)
2218 GetWorldTransform(targetDC, &scaled);
2221 cairo_get_matrix(previewContext, &ctm);
2223 // Scale to the preview screen bounds
2224 scaled.eM11 = ctm.xx;
2225 scaled.eM22 = ctm.yy;
2230 void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
2232 Frame* coreFrame = core(this);
2234 const IntRect& pageRect = m_pageRects[page];
2235 const IntRect& marginRect = printerMarginRect(printDC);
2237 // In preview, the printDC is a placeholder, so just always use the HDC backing the graphics context.
2238 HDC hdc = hdcFromContext(pctx);
2242 XFORM original, scaled;
2243 GetWorldTransform(hdc, &original);
2245 cairo_t* cr = pctx->cr();
2246 bool preview = (hdc != printDC);
2248 // If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo will
2249 // draw correctly. We need to retain the correct preview scale here for use when the Cairo
2250 // drawing completes so that we can scale our GDI-based header/footer calls. This is a
2251 // workaround for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2252 scaled = buildXFORMFromCairo(hdc, cr);
2255 float scale = scaleFactor(printDC, marginRect, pageRect);
2257 IntRect cairoMarginRect(marginRect);
2258 cairoMarginRect.scale(1 / scale);
2260 // We cannot scale the display HDC because the print surface also scales fonts,
2261 // resulting in invalid printing (and print preview)
2262 cairo_scale(cr, scale, scale);
2263 cairo_translate(cr, cairoMarginRect.x(), cairoMarginRect.y() + headerHeight);
2265 // Modify Cairo (only) to account for page position.
2266 cairo_translate(cr, -pageRect.x(), -pageRect.y());
2267 coreFrame->view()->paintContents(spoolCtx, pageRect);
2268 cairo_translate(cr, pageRect.x(), pageRect.y());
2271 // If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo would
2272 // draw correctly. We need to rescale the HDC to the correct preview scale so our GDI-based
2273 // header/footer calls will draw properly. This is a workaround for a bug in Cairo.
2274 // (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2275 SetWorldTransform(hdc, &scaled);
2278 XFORM xform = TransformationMatrix().translate(marginRect.x(), marginRect.y()).scale(scale);
2279 ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
2282 drawHeader(pctx, ui, pageRect, headerHeight);
2285 drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
2287 SetWorldTransform(hdc, &original);
2289 cairo_show_page(cr);
2290 ASSERT(!cairo_status(cr));
2291 spoolCtx->restore();
2294 static void setCairoTransformToPreviewHDC(cairo_t* previewCtx, HDC previewDC)
2297 GetWorldTransform(previewDC, &passedCTM);
2299 // Reset HDC WorldTransform to unscaled state. Scaling must be
2300 // done in Cairo to avoid drawing errors.
2301 XFORM unscaledCTM = passedCTM;
2302 unscaledCTM.eM11 = 1.0;
2303 unscaledCTM.eM22 = 1.0;
2305 SetWorldTransform(previewDC, &unscaledCTM);
2307 // Make the Cairo transform match the information passed to WebKit
2308 // in the HDC's WorldTransform.
2309 cairo_matrix_t ctm = { passedCTM.eM11, passedCTM.eM12, passedCTM.eM21,
2310 passedCTM.eM22, passedCTM.eDx, passedCTM.eDy };
2312 cairo_set_matrix(previewCtx, &ctm);
2317 HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(
2318 /* [in] */ HDC printDC,
2319 /* [in] */ UINT startPage,
2320 /* [in] */ UINT endPage,
2321 /* [retval][out] */ void* ctx)
2324 if (!printDC || !ctx) {
2325 ASSERT_NOT_REACHED();
2330 ASSERT_NOT_REACHED();
2334 HDC targetDC = (ctx) ? (HDC)ctx : printDC;
2336 cairo_surface_t* printSurface = 0;
2338 printSurface = cairo_win32_surface_create(targetDC); // in-memory
2340 printSurface = cairo_win32_printing_surface_create(targetDC); // metafile
2342 cairo_t* cr = cairo_create(printSurface);
2344 cairo_surface_destroy(printSurface);
2348 PlatformContextCairo platformContext(cr);
2349 PlatformGraphicsContext* pctx = &platformContext;
2353 // If this is a preview, the Windows HDC was sent with scaling information.
2354 // Retrieve it and reset it so that it draws properly. This is a workaround
2355 // for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2356 setCairoTransformToPreviewHDC(cr, targetDC);
2359 cairo_surface_set_fallback_resolution(printSurface, 72.0, 72.0);
2362 if (!m_inPrintingMode) {
2363 ASSERT_NOT_REACHED();
2367 Frame* coreFrame = core(this);
2368 if (!coreFrame || !coreFrame->document())
2371 UINT pageCount = (UINT) m_pageRects.size();
2373 PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)ctx;
2376 if (!pageCount || startPage > pageCount) {
2377 ASSERT_NOT_REACHED();
2385 endPage = pageCount;
2387 COMPtr<IWebUIDelegate> ui;
2388 if (FAILED(d->webView->uiDelegate(&ui)))
2391 float headerHeight = 0, footerHeight = 0;
2392 headerAndFooterHeights(&headerHeight, &footerHeight);
2393 GraphicsContext spoolCtx(pctx);
2394 spoolCtx.setShouldIncludeChildWindows(true);
2396 for (UINT ii = startPage; ii < endPage; ii++)
2397 spoolPage(pctx, &spoolCtx, printDC, ui.get(), headerHeight, footerHeight, ii, pageCount);
2400 cairo_surface_finish(printSurface);
2401 ASSERT(!cairo_surface_status(printSurface));
2402 cairo_surface_destroy(printSurface);
2408 HRESULT STDMETHODCALLTYPE WebFrame::isFrameSet(
2409 /* [retval][out] */ BOOL* result)
2413 Frame* coreFrame = core(this);
2414 if (!coreFrame || !coreFrame->document())
2417 *result = coreFrame->document()->isFrameSet() ? TRUE : FALSE;
2421 HRESULT STDMETHODCALLTYPE WebFrame::string(
2422 /* [retval][out] */ BSTR *result)
2426 Frame* coreFrame = core(this);
2430 RefPtr<Range> allRange(rangeOfContents(coreFrame->document()));
2431 String allString = plainText(allRange.get());
2432 *result = BString(allString).release();
2436 HRESULT STDMETHODCALLTYPE WebFrame::size(
2437 /* [retval][out] */ SIZE *size)
2441 size->cx = size->cy = 0;
2443 Frame* coreFrame = core(this);
2446 FrameView* view = coreFrame->view();
2449 size->cx = view->width();
2450 size->cy = view->height();
2454 HRESULT STDMETHODCALLTYPE WebFrame::hasScrollBars(
2455 /* [retval][out] */ BOOL *result)
2461 Frame* coreFrame = core(this);
2465 FrameView* view = coreFrame->view();
2469 if (view->horizontalScrollbar() || view->verticalScrollbar())
2475 HRESULT STDMETHODCALLTYPE WebFrame::contentBounds(
2476 /* [retval][out] */ RECT *result)
2480 ::SetRectEmpty(result);
2482 Frame* coreFrame = core(this);
2486 FrameView* view = coreFrame->view();
2490 result->bottom = view->contentsHeight();
2491 result->right = view->contentsWidth();
2495 HRESULT STDMETHODCALLTYPE WebFrame::frameBounds(
2496 /* [retval][out] */ RECT *result)
2500 ::SetRectEmpty(result);
2502 Frame* coreFrame = core(this);
2506 FrameView* view = coreFrame->view();
2510 FloatRect bounds = view->visibleContentRect(true);
2511 result->bottom = (LONG) bounds.height();
2512 result->right = (LONG) bounds.width();
2516 HRESULT STDMETHODCALLTYPE WebFrame::isDescendantOfFrame(
2517 /* [in] */ IWebFrame *ancestor,
2518 /* [retval][out] */ BOOL *result)
2524 Frame* coreFrame = core(this);
2525 COMPtr<WebFrame> ancestorWebFrame(Query, ancestor);
2526 if (!ancestorWebFrame)
2529 *result = (coreFrame && coreFrame->tree()->isDescendantOf(core(ancestorWebFrame.get()))) ? TRUE : FALSE;
2533 HRESULT WebFrame::stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld* iWorld, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult)
2535 if (!evaluationResult)
2537 *evaluationResult = 0;
2542 COMPtr<WebScriptWorld> world(Query, iWorld);
2544 return E_INVALIDARG;
2546 Frame* coreFrame = core(this);
2547 String string = String(script, SysStringLen(script));
2549 // Start off with some guess at a frame and a global object, we'll try to do better...!
2550 JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld());
2552 // The global object is probably a shell object? - if so, we know how to use this!
2553 JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
2554 if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
2555 anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
2557 // Get the frame frome the global object we've settled on.
2558 Frame* frame = anyWorldGlobalObject->impl()->frame();
2559 ASSERT(frame->document());
2560 JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue();
2562 if (!frame) // In case the script removed our frame from the page.
2565 // This bizarre set of rules matches behavior from WebKit for Safari 2.0.
2566 // If you don't like it, use -[WebScriptObject evaluateWebScript:] or
2567 // JSEvaluateScript instead, since they have less surprising semantics.
2568 if (!result || !result.isBoolean() && !result.isString() && !result.isNumber())
2571 JSLock lock(SilenceAssertionsOnly);
2572 String resultString = ustringToString(result.toString(anyWorldGlobalObject->globalExec()));
2573 *evaluationResult = BString(resultString).release();
2578 void WebFrame::unmarkAllMisspellings()
2580 Frame* coreFrame = core(this);
2581 for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
2582 Document *doc = frame->document();
2586 doc->markers()->removeMarkers(DocumentMarker::Spelling);
2590 void WebFrame::unmarkAllBadGrammar()
2592 Frame* coreFrame = core(this);
2593 for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
2594 Document *doc = frame->document();
2598 doc->markers()->removeMarkers(DocumentMarker::Grammar);
2602 WebView* WebFrame::webView() const
2607 void WebFrame::setWebView(WebView* webView)
2609 d->webView = webView;
2612 COMPtr<IAccessible> WebFrame::accessible() const
2614 Frame* coreFrame = core(this);
2617 Document* currentDocument = coreFrame->document();
2618 if (!currentDocument)
2620 else if (!m_accessible || m_accessible->document() != currentDocument) {
2621 // Either we've never had a wrapper for this frame's top-level Document,
2622 // the Document renderer was destroyed and its wrapper was detached, or
2623 // the previous Document is in the page cache, and the current document
2624 // needs to be wrapped.
2625 m_accessible = new AccessibleDocument(currentDocument);
2627 return m_accessible.get();
2630 void WebFrame::updateBackground()
2632 Color backgroundColor = webView()->transparent() ? Color::transparent : Color::white;
2633 Frame* coreFrame = core(this);
2635 if (!coreFrame || !coreFrame->view())
2638 coreFrame->view()->updateBackgroundRecursively(backgroundColor, webView()->transparent());
2641 PassRefPtr<FrameNetworkingContext> WebFrame::createNetworkingContext()
2643 return WebFrameNetworkingContext::create(core(this), userAgent(url()));