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/Frame.h>
67 #include <WebCore/FrameLoader.h>
68 #include <WebCore/FrameLoadRequest.h>
69 #include <WebCore/FrameTree.h>
70 #include <WebCore/FrameView.h>
71 #include <WebCore/FrameWin.h>
72 #include <WebCore/GDIObjectCounter.h>
73 #include <WebCore/GraphicsContext.h>
74 #include <WebCore/HistoryItem.h>
75 #include <WebCore/HTMLAppletElement.h>
76 #include <WebCore/HTMLFormElement.h>
77 #include <WebCore/HTMLFormControlElement.h>
78 #include <WebCore/HTMLInputElement.h>
79 #include <WebCore/HTMLNames.h>
80 #include <WebCore/HTMLPlugInElement.h>
81 #include <WebCore/JSDOMWindow.h>
82 #include <WebCore/KeyboardEvent.h>
83 #include <WebCore/MouseRelatedEvent.h>
84 #include <WebCore/NotImplemented.h>
85 #include <WebCore/Page.h>
86 #include <WebCore/PlatformKeyboardEvent.h>
87 #include <WebCore/PluginData.h>
88 #include <WebCore/PluginDatabase.h>
89 #include <WebCore/PluginView.h>
90 #include <WebCore/PrintContext.h>
91 #include <WebCore/ResourceHandle.h>
92 #include <WebCore/ResourceRequest.h>
93 #include <WebCore/RenderView.h>
94 #include <WebCore/RenderTreeAsText.h>
95 #include <WebCore/Settings.h>
96 #include <WebCore/TextIterator.h>
97 #include <WebCore/JSDOMBinding.h>
98 #include <WebCore/ScriptController.h>
99 #include <WebCore/ScriptValue.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;
130 #define FLASH_REDRAW 0
133 // By imaging to a width a little wider than the available pixels,
134 // thin pages will be scaled down a little, matching the way they
135 // print in IE and Camino. This lets them use fewer sheets than they
136 // would otherwise, which is presumably why other browsers do this.
137 // Wide pages will be scaled down more than this.
138 const float PrintingMinimumShrinkFactor = 1.25f;
140 // This number determines how small we are willing to reduce the page content
141 // in order to accommodate the widest line. If the page would have to be
142 // reduced smaller to make the widest line fit, we just clip instead (this
143 // behavior matches MacIE and Mozilla, at least)
144 const float PrintingMaximumShrinkFactor = 2.0f;
146 //-----------------------------------------------------------------------------
147 // Helpers to convert from WebCore to WebKit type
148 WebFrame* kit(Frame* frame)
153 FrameLoaderClient* frameLoaderClient = frame->loader()->client();
154 if (frameLoaderClient)
155 return static_cast<WebFrame*>(frameLoaderClient); // eek, is there a better way than static cast?
159 Frame* core(WebFrame* webFrame)
163 return webFrame->impl();
166 // 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
167 Frame* core(const WebFrame* webFrame)
171 return const_cast<WebFrame*>(webFrame)->impl();
174 //-----------------------------------------------------------------------------
176 static Element *elementFromDOMElement(IDOMElement *element)
181 COMPtr<IDOMElementPrivate> elePriv;
182 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
185 hr = elePriv->coreElement((void**)&ele);
192 static HTMLFormElement *formElementFromDOMElement(IDOMElement *element)
197 IDOMElementPrivate* elePriv;
198 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
201 hr = elePriv->coreElement((void**)&ele);
203 if (SUCCEEDED(hr) && ele && ele->hasTagName(formTag))
204 return static_cast<HTMLFormElement*>(ele);
209 static HTMLInputElement* inputElementFromDOMElement(IDOMElement* element)
214 IDOMElementPrivate* elePriv;
215 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
218 hr = elePriv->coreElement((void**)&ele);
220 if (SUCCEEDED(hr) && ele && ele->hasTagName(inputTag))
221 return static_cast<HTMLInputElement*>(ele);
226 // WebFramePrivate ------------------------------------------------------------
228 class WebFrame::WebFramePrivate {
233 , m_policyFunction(0)
237 ~WebFramePrivate() { }
238 FrameView* frameView() { return frame ? frame->view() : 0; }
242 FramePolicyFunction m_policyFunction;
243 COMPtr<WebFramePolicyListener> m_policyListener;
246 // WebFrame ----------------------------------------------------------------
249 : WebFrameLoaderClient(this)
251 , d(new WebFrame::WebFramePrivate)
252 , m_quickRedirectComing(false)
253 , m_inPrintingMode(false)
258 gClassNameCount.add("WebFrame");
261 WebFrame::~WebFrame()
266 gClassNameCount.remove("WebFrame");
269 WebFrame* WebFrame::createInstance()
271 WebFrame* instance = new WebFrame();
276 HRESULT STDMETHODCALLTYPE WebFrame::setAllowsScrolling(
277 /* [in] */ BOOL flag)
279 if (Frame* frame = core(this))
280 if (FrameView* view = frame->view())
281 view->setCanHaveScrollbars(!!flag);
286 HRESULT STDMETHODCALLTYPE WebFrame::allowsScrolling(
287 /* [retval][out] */ BOOL *flag)
290 if (Frame* frame = core(this))
291 if (FrameView* view = frame->view())
292 *flag = view->canHaveScrollbars();
297 HRESULT STDMETHODCALLTYPE WebFrame::setIsDisconnected(
298 /* [in] */ BOOL flag)
303 HRESULT STDMETHODCALLTYPE WebFrame::setExcludeFromTextSearch(
304 /* [in] */ BOOL flag)
309 HRESULT WebFrame::reloadFromOrigin()
311 Frame* coreFrame = core(this);
315 coreFrame->loader()->reload(true);
319 HRESULT STDMETHODCALLTYPE WebFrame::paintDocumentRectToContext(
320 /* [in] */ RECT rect,
321 /* [in] */ OLE_HANDLE deviceContext)
323 Frame* coreFrame = core(this);
327 FrameView* view = coreFrame->view();
331 // We can't paint with a layout still pending.
332 view->updateLayoutAndStyleIfNeededRecursive();
334 HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
335 GraphicsContext gc(dc);
336 gc.setShouldIncludeChildWindows(true);
338 LONG width = rect.right - rect.left;
339 LONG height = rect.bottom - rect.top;
341 dirtyRect.setWidth(width);
342 dirtyRect.setHeight(height);
344 gc.translate(-rect.left, -rect.top);
345 view->paintContents(&gc, rect);
351 HRESULT STDMETHODCALLTYPE WebFrame::paintScrollViewRectToContextAtPoint(
352 /* [in] */ RECT rect,
354 /* [in] */ OLE_HANDLE deviceContext)
356 Frame* coreFrame = core(this);
360 FrameView* view = coreFrame->view();
364 // We can't paint with a layout still pending.
365 view->updateLayoutAndStyleIfNeededRecursive();
367 HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
368 GraphicsContext gc(dc);
369 gc.setShouldIncludeChildWindows(true);
371 IntRect dirtyRect(rect);
372 dirtyRect.move(-pt.x, -pt.y);
373 view->paint(&gc, dirtyRect);
379 // IUnknown -------------------------------------------------------------------
381 HRESULT STDMETHODCALLTYPE WebFrame::QueryInterface(REFIID riid, void** ppvObject)
384 if (IsEqualGUID(riid, __uuidof(WebFrame)))
386 else if (IsEqualGUID(riid, IID_IUnknown))
387 *ppvObject = static_cast<IWebFrame*>(this);
388 else if (IsEqualGUID(riid, IID_IWebFrame))
389 *ppvObject = static_cast<IWebFrame*>(this);
390 else if (IsEqualGUID(riid, IID_IWebFramePrivate))
391 *ppvObject = static_cast<IWebFramePrivate*>(this);
392 else if (IsEqualGUID(riid, IID_IWebDocumentText))
393 *ppvObject = static_cast<IWebDocumentText*>(this);
395 return E_NOINTERFACE;
401 ULONG STDMETHODCALLTYPE WebFrame::AddRef(void)
406 ULONG STDMETHODCALLTYPE WebFrame::Release(void)
408 ULONG newRef = --m_refCount;
415 // IWebFrame -------------------------------------------------------------------
417 HRESULT STDMETHODCALLTYPE WebFrame::name(
418 /* [retval][out] */ BSTR* frameName)
421 ASSERT_NOT_REACHED();
427 Frame* coreFrame = core(this);
431 *frameName = BString(coreFrame->tree()->uniqueName()).release();
435 HRESULT STDMETHODCALLTYPE WebFrame::webView(
436 /* [retval][out] */ IWebView** view)
446 HRESULT STDMETHODCALLTYPE WebFrame::frameView(
447 /* [retval][out] */ IWebFrameView** /*view*/)
449 ASSERT_NOT_REACHED();
453 HRESULT STDMETHODCALLTYPE WebFrame::DOMDocument(
454 /* [retval][out] */ IDOMDocument** result)
457 ASSERT_NOT_REACHED();
463 if (Frame* coreFrame = core(this))
464 if (Document* document = coreFrame->document())
465 *result = DOMDocument::createInstance(document);
467 return *result ? S_OK : E_FAIL;
471 HRESULT WebFrame::DOMWindow(/* [retval][out] */ IDOMWindow** window)
474 ASSERT_NOT_REACHED();
480 if (Frame* coreFrame = core(this)) {
481 if (WebCore::DOMWindow* coreWindow = coreFrame->domWindow())
482 *window = ::DOMWindow::createInstance(coreWindow);
485 return *window ? S_OK : E_FAIL;
488 HRESULT STDMETHODCALLTYPE WebFrame::frameElement(
489 /* [retval][out] */ IDOMHTMLElement** frameElement)
495 Frame* coreFrame = core(this);
499 COMPtr<IDOMElement> domElement(AdoptCOM, DOMElement::createInstance(coreFrame->ownerElement()));
500 COMPtr<IDOMHTMLElement> htmlElement(Query, domElement);
503 return htmlElement.copyRefTo(frameElement);
506 HRESULT STDMETHODCALLTYPE WebFrame::currentForm(
507 /* [retval][out] */ IDOMElement **currentForm)
510 ASSERT_NOT_REACHED();
516 if (Frame* coreFrame = core(this)) {
517 if (HTMLFormElement* formElement = coreFrame->selection()->currentForm())
518 *currentForm = DOMElement::createInstance(formElement);
521 return *currentForm ? S_OK : E_FAIL;
524 JSGlobalContextRef STDMETHODCALLTYPE WebFrame::globalContext()
526 Frame* coreFrame = core(this);
530 return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
533 JSGlobalContextRef WebFrame::globalContextForScriptWorld(IWebScriptWorld* iWorld)
535 Frame* coreFrame = core(this);
539 COMPtr<WebScriptWorld> world(Query, iWorld);
543 return toGlobalRef(coreFrame->script()->globalObject(world->world())->globalExec());
546 HRESULT STDMETHODCALLTYPE WebFrame::loadRequest(
547 /* [in] */ IWebURLRequest* request)
549 COMPtr<WebMutableURLRequest> requestImpl;
551 HRESULT hr = request->QueryInterface(&requestImpl);
555 Frame* coreFrame = core(this);
559 coreFrame->loader()->load(requestImpl->resourceRequest(), false);
563 void WebFrame::loadData(PassRefPtr<WebCore::SharedBuffer> data, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL)
565 String mimeTypeString(mimeType, SysStringLen(mimeType));
567 mimeTypeString = "text/html";
569 String encodingString(textEncodingName, SysStringLen(textEncodingName));
571 // FIXME: We should really be using MarshallingHelpers::BSTRToKURL here,
572 // but that would turn a null BSTR into a null KURL, and we crash inside of
573 // WebCore if we use a null KURL in constructing the ResourceRequest.
574 KURL baseKURL = KURL(KURL(), String(baseURL ? baseURL : L"", SysStringLen(baseURL)));
576 KURL failingKURL = MarshallingHelpers::BSTRToKURL(failingURL);
578 ResourceRequest request(baseKURL);
579 SubstituteData substituteData(data, mimeTypeString, encodingString, failingKURL);
581 // This method is only called from IWebFrame methods, so don't ASSERT that the Frame pointer isn't null.
582 if (Frame* coreFrame = core(this))
583 coreFrame->loader()->load(request, substituteData, false);
587 HRESULT STDMETHODCALLTYPE WebFrame::loadData(
588 /* [in] */ IStream* data,
589 /* [in] */ BSTR mimeType,
590 /* [in] */ BSTR textEncodingName,
593 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
596 if (SUCCEEDED(data->Stat(&stat, STATFLAG_NONAME))) {
597 if (!stat.cbSize.HighPart && stat.cbSize.LowPart) {
598 Vector<char> dataBuffer(stat.cbSize.LowPart);
600 // FIXME: this does a needless copy, would be better to read right into the SharedBuffer
601 // or adopt the Vector or something.
602 if (SUCCEEDED(data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read)))
603 sharedBuffer->append(dataBuffer.data(), static_cast<int>(dataBuffer.size()));
607 loadData(sharedBuffer, mimeType, textEncodingName, url, 0);
611 HRESULT WebFrame::loadPlainTextString(
612 /* [in] */ BSTR string,
615 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
616 BString plainTextMimeType(TEXT("text/plain"), 10);
617 BString utf16Encoding(TEXT("utf-16"), 6);
618 loadData(sharedBuffer.release(), plainTextMimeType, utf16Encoding, url, 0);
622 void WebFrame::loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL)
624 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
625 BString utf16Encoding(TEXT("utf-16"), 6);
626 loadData(sharedBuffer.release(), 0, utf16Encoding, baseURL, unreachableURL);
629 HRESULT STDMETHODCALLTYPE WebFrame::loadHTMLString(
630 /* [in] */ BSTR string,
631 /* [in] */ BSTR baseURL)
633 loadHTMLString(string, baseURL, 0);
637 HRESULT STDMETHODCALLTYPE WebFrame::loadAlternateHTMLString(
639 /* [in] */ BSTR baseURL,
640 /* [in] */ BSTR unreachableURL)
642 loadHTMLString(str, baseURL, unreachableURL);
646 HRESULT STDMETHODCALLTYPE WebFrame::loadArchive(
647 /* [in] */ IWebArchive* /*archive*/)
649 ASSERT_NOT_REACHED();
653 static inline WebDataSource *getWebDataSource(DocumentLoader* loader)
655 return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;
658 HRESULT STDMETHODCALLTYPE WebFrame::dataSource(
659 /* [retval][out] */ IWebDataSource** source)
662 ASSERT_NOT_REACHED();
668 Frame* coreFrame = core(this);
672 WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->documentLoader());
674 *source = webDataSource;
677 webDataSource->AddRef();
679 return *source ? S_OK : E_FAIL;
682 HRESULT STDMETHODCALLTYPE WebFrame::provisionalDataSource(
683 /* [retval][out] */ IWebDataSource** source)
686 ASSERT_NOT_REACHED();
692 Frame* coreFrame = core(this);
696 WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->provisionalDocumentLoader());
698 *source = webDataSource;
701 webDataSource->AddRef();
703 return *source ? S_OK : E_FAIL;
706 KURL WebFrame::url() const
708 Frame* coreFrame = core(this);
712 return coreFrame->document()->url();
715 HRESULT STDMETHODCALLTYPE WebFrame::stopLoading( void)
717 if (Frame* coreFrame = core(this))
718 coreFrame->loader()->stopAllLoaders();
722 HRESULT STDMETHODCALLTYPE WebFrame::reload( void)
724 Frame* coreFrame = core(this);
728 coreFrame->loader()->reload();
732 HRESULT STDMETHODCALLTYPE WebFrame::findFrameNamed(
733 /* [in] */ BSTR name,
734 /* [retval][out] */ IWebFrame** frame)
737 ASSERT_NOT_REACHED();
743 Frame* coreFrame = core(this);
747 Frame* foundFrame = coreFrame->tree()->find(AtomicString(name, SysStringLen(name)));
751 WebFrame* foundWebFrame = kit(foundFrame);
755 return foundWebFrame->QueryInterface(IID_IWebFrame, (void**)frame);
758 HRESULT STDMETHODCALLTYPE WebFrame::parentFrame(
759 /* [retval][out] */ IWebFrame** frame)
763 if (Frame* coreFrame = core(this))
764 if (WebFrame* webFrame = kit(coreFrame->tree()->parent()))
765 hr = webFrame->QueryInterface(IID_IWebFrame, (void**) frame);
770 class EnumChildFrames : public IEnumVARIANT
773 EnumChildFrames(Frame* f) : m_refCount(1), m_frame(f), m_curChild(f ? f->tree()->firstChild() : 0) { }
775 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
778 if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
781 return E_NOINTERFACE;
787 virtual ULONG STDMETHODCALLTYPE AddRef(void)
792 virtual ULONG STDMETHODCALLTYPE Release(void)
794 ULONG newRef = --m_refCount;
800 virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
807 if (!celt || celt > 1)
809 if (!m_frame || !m_curChild)
812 WebFrame* webFrame = kit(m_curChild);
814 HRESULT hr = webFrame->QueryInterface(IID_IUnknown, (void**)&unknown);
818 V_VT(rgVar) = VT_UNKNOWN;
819 V_UNKNOWN(rgVar) = unknown;
821 m_curChild = m_curChild->tree()->nextSibling();
827 virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
831 for (unsigned i = 0; i < celt && m_curChild; i++)
832 m_curChild = m_curChild->tree()->nextSibling();
833 return m_curChild ? S_OK : S_FALSE;
836 virtual HRESULT STDMETHODCALLTYPE Reset(void)
840 m_curChild = m_frame->tree()->firstChild();
844 virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**)
855 HRESULT STDMETHODCALLTYPE WebFrame::childFrames(
856 /* [retval][out] */ IEnumVARIANT **enumFrames)
861 *enumFrames = new EnumChildFrames(core(this));
865 // IWebFramePrivate ------------------------------------------------------
867 HRESULT WebFrame::renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result)
872 Frame* coreFrame = core(this);
876 *result = BString(externalRepresentation(coreFrame, forPrinting ? RenderAsTextPrintingMode : RenderAsTextBehaviorNormal)).release();
880 HRESULT STDMETHODCALLTYPE WebFrame::pageNumberForElementById(
882 /* [in] */ float pageWidthInPixels,
883 /* [in] */ float pageHeightInPixels,
884 /* [retval][out] */ int* result)
886 // TODO: Please remove this function if not needed as this is LTC specific function
887 // and has been moved to Internals.
892 HRESULT STDMETHODCALLTYPE WebFrame::numberOfPages(
893 /* [in] */ float pageWidthInPixels,
894 /* [in] */ float pageHeightInPixels,
895 /* [retval][out] */ int* result)
900 Frame* coreFrame = core(this);
904 *result = PrintContext::numberOfPages(coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
908 HRESULT STDMETHODCALLTYPE WebFrame::scrollOffset(
909 /* [retval][out] */ SIZE* offset)
912 ASSERT_NOT_REACHED();
916 Frame* coreFrame = core(this);
920 FrameView* view = coreFrame->view();
924 *offset = view->scrollOffset();
928 HRESULT STDMETHODCALLTYPE WebFrame::layout()
930 Frame* coreFrame = core(this);
934 FrameView* view = coreFrame->view();
942 HRESULT STDMETHODCALLTYPE WebFrame::firstLayoutDone(
943 /* [retval][out] */ BOOL* result)
946 ASSERT_NOT_REACHED();
952 Frame* coreFrame = core(this);
956 *result = coreFrame->loader()->stateMachine()->firstLayoutDone();
960 HRESULT STDMETHODCALLTYPE WebFrame::loadType(
961 /* [retval][out] */ WebFrameLoadType* type)
964 ASSERT_NOT_REACHED();
968 *type = (WebFrameLoadType)0;
970 Frame* coreFrame = core(this);
974 *type = (WebFrameLoadType)coreFrame->loader()->loadType();
978 HRESULT STDMETHODCALLTYPE WebFrame::pendingFrameUnloadEventCount(
979 /* [retval][out] */ UINT* result)
982 ASSERT_NOT_REACHED();
988 Frame* coreFrame = core(this);
992 *result = coreFrame->domWindow()->pendingUnloadEventListeners();
996 HRESULT STDMETHODCALLTYPE WebFrame::unused2()
1001 HRESULT STDMETHODCALLTYPE WebFrame::hasSpellingMarker(
1002 /* [in] */ UINT from,
1003 /* [in] */ UINT length,
1004 /* [retval][out] */ BOOL* result)
1006 Frame* coreFrame = core(this);
1009 *result = coreFrame->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1013 HRESULT STDMETHODCALLTYPE WebFrame::clearOpener()
1016 if (Frame* coreFrame = core(this))
1017 coreFrame->loader()->setOpener(0);
1022 HRESULT WebFrame::setTextDirection(BSTR direction)
1024 Frame* coreFrame = core(this);
1025 if (!coreFrame || !coreFrame->editor())
1028 String directionString(direction, SysStringLen(direction));
1029 if (directionString == "auto")
1030 coreFrame->editor()->setBaseWritingDirection(NaturalWritingDirection);
1031 else if (directionString == "ltr")
1032 coreFrame->editor()->setBaseWritingDirection(LeftToRightWritingDirection);
1033 else if (directionString == "rtl")
1034 coreFrame->editor()->setBaseWritingDirection(RightToLeftWritingDirection);
1038 // IWebDocumentText -----------------------------------------------------------
1040 HRESULT STDMETHODCALLTYPE WebFrame::supportsTextEncoding(
1041 /* [retval][out] */ BOOL* result)
1047 HRESULT STDMETHODCALLTYPE WebFrame::selectedString(
1048 /* [retval][out] */ BSTR* result)
1052 Frame* coreFrame = core(this);
1056 String text = coreFrame->displayStringModifiedByEncoding(coreFrame->editor()->selectedText());
1058 *result = BString(text).release();
1062 HRESULT STDMETHODCALLTYPE WebFrame::selectAll()
1064 Frame* coreFrame = core(this);
1068 if (!coreFrame->editor()->command("SelectAll").execute())
1074 HRESULT STDMETHODCALLTYPE WebFrame::deselectAll()
1079 // WebFrame ---------------------------------------------------------------
1081 PassRefPtr<Frame> WebFrame::init(IWebView* webView, Page* page, HTMLFrameOwnerElement* ownerElement)
1083 webView->QueryInterface(&d->webView);
1084 d->webView->Release(); // don't hold the extra ref
1087 d->webView->viewWindow((OLE_HANDLE*)&viewWindow);
1089 this->AddRef(); // We release this ref in frameLoaderDestroyed()
1090 RefPtr<Frame> frame = Frame::create(page, ownerElement, this);
1091 d->frame = frame.get();
1092 return frame.release();
1095 Frame* WebFrame::impl()
1100 void WebFrame::invalidate()
1102 Frame* coreFrame = core(this);
1105 if (Document* document = coreFrame->document())
1106 document->recalcStyle(Node::Force);
1109 HRESULT WebFrame::inViewSourceMode(BOOL* flag)
1112 ASSERT_NOT_REACHED();
1118 Frame* coreFrame = core(this);
1122 *flag = coreFrame->inViewSourceMode() ? TRUE : FALSE;
1126 HRESULT WebFrame::setInViewSourceMode(BOOL flag)
1128 Frame* coreFrame = core(this);
1132 coreFrame->setInViewSourceMode(!!flag);
1136 HRESULT WebFrame::elementWithName(BSTR name, IDOMElement* form, IDOMElement** element)
1139 return E_INVALIDARG;
1141 HTMLFormElement* formElement = formElementFromDOMElement(form);
1143 const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
1144 AtomicString targetName((UChar*)name, SysStringLen(name));
1145 for (unsigned int i = 0; i < elements.size(); i++) {
1146 if (!elements[i]->isFormControlElement())
1148 HTMLFormControlElement* elt = static_cast<HTMLFormControlElement*>(elements[i]);
1149 // Skip option elements, other duds
1150 if (elt->name() == targetName) {
1151 *element = DOMElement::createInstance(elt);
1159 HRESULT WebFrame::formForElement(IDOMElement* element, IDOMElement** form)
1162 return E_INVALIDARG;
1164 HTMLInputElement *inputElement = inputElementFromDOMElement(element);
1168 HTMLFormElement *formElement = inputElement->form();
1172 *form = DOMElement::createInstance(formElement);
1176 HRESULT WebFrame::elementDoesAutoComplete(IDOMElement *element, BOOL *result)
1180 return E_INVALIDARG;
1182 HTMLInputElement *inputElement = inputElementFromDOMElement(element);
1186 *result = inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->shouldAutocomplete();
1191 HRESULT STDMETHODCALLTYPE WebFrame::resumeAnimations()
1193 Frame* frame = core(this);
1197 frame->animation()->resumeAnimations();
1201 HRESULT STDMETHODCALLTYPE WebFrame::suspendAnimations()
1203 Frame* frame = core(this);
1207 frame->animation()->suspendAnimations();
1211 HRESULT WebFrame::pauseAnimation(BSTR animationName, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning)
1213 if (!node || !animationWasRunning)
1216 *animationWasRunning = FALSE;
1218 Frame* frame = core(this);
1222 AnimationController* controller = frame->animation();
1226 COMPtr<DOMNode> domNode(Query, node);
1230 *animationWasRunning = controller->pauseAnimationAtTime(domNode->node()->renderer(), String(animationName, SysStringLen(animationName)), secondsFromNow);
1234 HRESULT WebFrame::pauseTransition(BSTR propertyName, IDOMNode* node, double secondsFromNow, BOOL* transitionWasRunning)
1236 if (!node || !transitionWasRunning)
1239 *transitionWasRunning = FALSE;
1241 Frame* frame = core(this);
1245 AnimationController* controller = frame->animation();
1249 COMPtr<DOMNode> domNode(Query, node);
1253 *transitionWasRunning = controller->pauseTransitionAtTime(domNode->node()->renderer(), String(propertyName, SysStringLen(propertyName)), secondsFromNow);
1257 HRESULT WebFrame::visibleContentRect(RECT* rect)
1263 Frame* frame = core(this);
1267 FrameView* view = frame->view();
1271 *rect = view->visibleContentRect(false);
1275 HRESULT WebFrame::numberOfActiveAnimations(UINT* number)
1282 Frame* frame = core(this);
1286 AnimationController* controller = frame->animation();
1290 *number = controller->numberOfActiveAnimations(frame->document());
1294 HRESULT WebFrame::isDisplayingStandaloneImage(BOOL* result)
1301 Frame* frame = core(this);
1305 Document* document = frame->document();
1306 *result = document && document->isImageDocument();
1310 HRESULT WebFrame::allowsFollowingLink(BSTR url, BOOL* result)
1317 Frame* frame = core(this);
1321 *result = frame->document()->securityOrigin()->canDisplay(MarshallingHelpers::BSTRToKURL(url));
1325 HRESULT WebFrame::controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls)
1328 return E_INVALIDARG;
1330 HTMLFormElement* formElement = formElementFromDOMElement(form);
1334 int inCount = *cControls;
1335 int count = (int) formElement->associatedElements().size();
1339 if (inCount < count)
1343 const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
1344 for (int i = 0; i < count; i++) {
1345 if (elements.at(i)->isEnumeratable()) { // Skip option elements, other duds
1346 controls[*cControls] = DOMElement::createInstance(toHTMLElement(elements.at(i)));
1353 HRESULT WebFrame::elementIsPassword(IDOMElement *element, bool *result)
1355 HTMLInputElement* inputElement = inputElementFromDOMElement(element);
1356 *result = inputElement && inputElement->isPasswordField();
1360 HRESULT WebFrame::searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* outResultDistance, BOOL* outResultIsInCellAbove, BSTR* result)
1363 ASSERT_NOT_REACHED();
1367 if (outResultDistance)
1368 *outResultDistance = 0;
1369 if (outResultIsInCellAbove)
1370 *outResultIsInCellAbove = FALSE;
1376 return E_INVALIDARG;
1378 Frame* coreFrame = core(this);
1382 Vector<String> labelStrings(cLabels);
1383 for (int i=0; i<cLabels; i++)
1384 labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
1385 Element *coreElement = elementFromDOMElement(beforeElement);
1389 size_t resultDistance;
1390 bool resultIsInCellAbove;
1391 String label = coreFrame->searchForLabelsBeforeElement(labelStrings, coreElement, &resultDistance, &resultIsInCellAbove);
1393 *result = SysAllocStringLen(label.characters(), label.length());
1394 if (label.length() && !*result)
1395 return E_OUTOFMEMORY;
1396 if (outResultDistance)
1397 *outResultDistance = resultDistance;
1398 if (outResultIsInCellAbove)
1399 *outResultIsInCellAbove = resultIsInCellAbove;
1404 HRESULT WebFrame::matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result)
1407 ASSERT_NOT_REACHED();
1416 return E_INVALIDARG;
1418 Frame* coreFrame = core(this);
1422 Vector<String> labelStrings(cLabels);
1423 for (int i=0; i<cLabels; i++)
1424 labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
1425 Element *coreElement = elementFromDOMElement(againstElement);
1429 String label = coreFrame->matchLabelsAgainstElement(labelStrings, coreElement);
1431 *result = SysAllocStringLen(label.characters(), label.length());
1432 if (label.length() && !*result)
1433 return E_OUTOFMEMORY;
1437 HRESULT WebFrame::canProvideDocumentSource(bool* result)
1442 COMPtr<IWebDataSource> dataSource;
1443 hr = WebFrame::dataSource(&dataSource);
1447 COMPtr<IWebURLResponse> urlResponse;
1448 hr = dataSource->response(&urlResponse);
1449 if (SUCCEEDED(hr) && urlResponse) {
1451 if (SUCCEEDED(urlResponse->MIMEType(&mimeTypeBStr))) {
1452 String mimeType(mimeTypeBStr, SysStringLen(mimeTypeBStr));
1453 *result = mimeType == "text/html" || WebCore::DOMImplementation::isXMLMIMEType(mimeType);
1454 SysFreeString(mimeTypeBStr);
1460 HRESULT STDMETHODCALLTYPE WebFrame::layerTreeAsText(BSTR* result)
1466 Frame* frame = core(this);
1470 String text = frame->layerTreeAsText();
1471 *result = BString(text).release();
1475 void WebFrame::frameLoaderDestroyed()
1477 // The FrameLoader going away is equivalent to the Frame going away,
1478 // so we now need to clear our frame pointer.
1484 void WebFrame::makeRepresentation(DocumentLoader*)
1489 void WebFrame::forceLayoutForNonHTML()
1494 void WebFrame::setCopiesOnScroll()
1499 void WebFrame::detachedFromParent2()
1504 void WebFrame::detachedFromParent3()
1509 void WebFrame::cancelPolicyCheck()
1511 if (d->m_policyListener) {
1512 d->m_policyListener->invalidate();
1513 d->m_policyListener = 0;
1516 d->m_policyFunction = 0;
1519 void WebFrame::dispatchWillSendSubmitEvent(PassRefPtr<WebCore::FormState>)
1523 void WebFrame::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState)
1525 Frame* coreFrame = core(this);
1528 COMPtr<IWebFormDelegate> formDelegate;
1530 if (FAILED(d->webView->formDelegate(&formDelegate))) {
1531 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1535 COMPtr<IDOMElement> formElement(AdoptCOM, DOMElement::createInstance(formState->form()));
1537 HashMap<String, String> formValuesMap;
1538 const StringPairVector& textFieldValues = formState->textFieldValues();
1539 size_t size = textFieldValues.size();
1540 for (size_t i = 0; i < size; ++i)
1541 formValuesMap.add(textFieldValues[i].first, textFieldValues[i].second);
1543 COMPtr<IPropertyBag> formValuesPropertyBag(AdoptCOM, COMPropertyBag<String>::createInstance(formValuesMap));
1545 COMPtr<WebFrame> sourceFrame(kit(formState->sourceDocument()->frame()));
1546 if (SUCCEEDED(formDelegate->willSubmitForm(this, sourceFrame.get(), formElement.get(), formValuesPropertyBag.get(), setUpPolicyListener(function).get())))
1549 // FIXME: Add a sane default implementation
1550 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1553 void WebFrame::revertToProvisionalState(DocumentLoader*)
1558 void WebFrame::setMainFrameDocumentReady(bool)
1563 void WebFrame::willChangeTitle(DocumentLoader*)
1568 void WebFrame::didChangeTitle(DocumentLoader*)
1573 void WebFrame::didChangeIcons(DocumentLoader*)
1578 bool WebFrame::canHandleRequest(const ResourceRequest& request) const
1580 return WebView::canHandleRequest(request);
1583 bool WebFrame::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
1589 bool WebFrame::canShowMIMEType(const String& /*MIMEType*/) const
1595 bool WebFrame::representationExistsForURLScheme(const String& /*URLScheme*/) const
1601 String WebFrame::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const
1604 ASSERT_NOT_REACHED();
1608 void WebFrame::frameLoadCompleted()
1612 void WebFrame::restoreViewState()
1616 void WebFrame::provisionalLoadStarted()
1621 bool WebFrame::shouldTreatURLAsSameAsCurrent(const KURL&) const
1627 void WebFrame::addHistoryItemForFragmentScroll()
1632 void WebFrame::didFinishLoad()
1637 void WebFrame::prepareForDataSourceReplacement()
1642 String WebFrame::userAgent(const KURL& url)
1644 return d->webView->userAgentForKURL(url);
1647 void WebFrame::saveViewStateToItem(HistoryItem*)
1651 ResourceError WebFrame::cancelledError(const ResourceRequest& request)
1653 // FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values
1654 // Alternatively, we could create our own error domain/codes.
1655 return ResourceError(String(WebURLErrorDomain), -999, request.url().string(), String());
1658 ResourceError WebFrame::blockedError(const ResourceRequest& request)
1660 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1661 return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotUseRestrictedPort, request.url().string(), String());
1664 ResourceError WebFrame::cannotShowURLError(const ResourceRequest& request)
1666 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1667 return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotShowURL, request.url().string(), String());
1670 ResourceError WebFrame::interruptedForPolicyChangeError(const ResourceRequest& request)
1672 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1673 return ResourceError(String(WebKitErrorDomain), WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(), String());
1676 ResourceError WebFrame::cannotShowMIMETypeError(const ResourceResponse&)
1679 return ResourceError();
1682 ResourceError WebFrame::fileDoesNotExistError(const ResourceResponse&)
1685 return ResourceError();
1688 ResourceError WebFrame::pluginWillHandleLoadError(const ResourceResponse& response)
1690 return ResourceError(String(WebKitErrorDomain), WebKitErrorPlugInWillHandleLoad, response.url().string(), String());
1693 bool WebFrame::shouldFallBack(const ResourceError& error)
1695 if (error.errorCode() == WebURLErrorCancelled && error.domain() == String(WebURLErrorDomain))
1698 if (error.errorCode() == WebKitErrorPlugInWillHandleLoad && error.domain() == String(WebKitErrorDomain))
1704 COMPtr<WebFramePolicyListener> WebFrame::setUpPolicyListener(WebCore::FramePolicyFunction function)
1706 // FIXME: <rdar://5634381> We need to support multiple active policy listeners.
1708 if (d->m_policyListener)
1709 d->m_policyListener->invalidate();
1711 Frame* coreFrame = core(this);
1714 d->m_policyListener.adoptRef(WebFramePolicyListener::createInstance(coreFrame));
1715 d->m_policyFunction = function;
1717 return d->m_policyListener;
1720 void WebFrame::receivedPolicyDecision(PolicyAction action)
1722 ASSERT(d->m_policyListener);
1723 ASSERT(d->m_policyFunction);
1725 FramePolicyFunction function = d->m_policyFunction;
1727 d->m_policyListener = 0;
1728 d->m_policyFunction = 0;
1730 Frame* coreFrame = core(this);
1733 (coreFrame->loader()->policyChecker()->*function)(action);
1736 void WebFrame::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& request)
1738 Frame* coreFrame = core(this);
1741 COMPtr<IWebPolicyDelegate> policyDelegate;
1742 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1743 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1745 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1747 if (SUCCEEDED(policyDelegate->decidePolicyForMIMEType(d->webView, BString(response.mimeType()), urlRequest.get(), this, setUpPolicyListener(function).get())))
1750 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1753 void WebFrame::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName)
1755 Frame* coreFrame = core(this);
1758 COMPtr<IWebPolicyDelegate> policyDelegate;
1759 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1760 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1762 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1763 COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
1765 if (SUCCEEDED(policyDelegate->decidePolicyForNewWindowAction(d->webView, actionInformation.get(), urlRequest.get(), BString(frameName), setUpPolicyListener(function).get())))
1768 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1771 void WebFrame::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState)
1773 Frame* coreFrame = core(this);
1776 COMPtr<IWebPolicyDelegate> policyDelegate;
1777 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1778 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1780 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1781 COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
1783 if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get())))
1786 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1789 void WebFrame::dispatchUnableToImplementPolicy(const ResourceError& error)
1791 COMPtr<IWebPolicyDelegate> policyDelegate;
1792 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1793 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1795 COMPtr<IWebError> webError(AdoptCOM, WebError::createInstance(error));
1796 policyDelegate->unableToImplementPolicyWithError(d->webView, webError.get(), this);
1799 void WebFrame::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response)
1801 COMPtr<IWebDownloadDelegate> downloadDelegate;
1802 COMPtr<IWebView> webView;
1803 if (SUCCEEDED(this->webView(&webView))) {
1804 if (FAILED(webView->downloadDelegate(&downloadDelegate))) {
1805 // If the WebView doesn't successfully provide a download delegate we'll pass a null one
1806 // into the WebDownload - which may or may not decide to use a DefaultDownloadDelegate
1807 LOG_ERROR("Failed to get downloadDelegate from WebView");
1808 downloadDelegate = 0;
1812 // Its the delegate's job to ref the WebDownload to keep it alive - otherwise it will be destroyed
1813 // when this method returns
1814 COMPtr<WebDownload> download;
1815 download.adoptRef(WebDownload::createInstance(handle, request, response, downloadDelegate.get()));
1818 bool WebFrame::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
1824 void WebFrame::dispatchDidFailProvisionalLoad(const ResourceError& error)
1826 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1827 if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
1828 COMPtr<IWebError> webError;
1829 webError.adoptRef(WebError::createInstance(error));
1830 frameLoadDelegate->didFailProvisionalLoadWithError(d->webView, webError.get(), this);
1834 void WebFrame::dispatchDidFailLoad(const ResourceError& error)
1836 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1837 if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
1838 COMPtr<IWebError> webError;
1839 webError.adoptRef(WebError::createInstance(error));
1840 frameLoadDelegate->didFailLoadWithError(d->webView, webError.get(), this);
1844 void WebFrame::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
1846 d->webView->downloadURL(request.url());
1849 PassRefPtr<Widget> WebFrame::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* element, const KURL& /*baseURL*/, const Vector<String>& paramNames, const Vector<String>& paramValues)
1851 RefPtr<PluginView> pluginView = PluginView::create(core(this), pluginSize, element, KURL(), paramNames, paramValues, "application/x-java-applet", false);
1853 // Check if the plugin can be loaded successfully
1854 if (pluginView->plugin() && pluginView->plugin()->load())
1857 COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
1858 if (FAILED(d->webView->resourceLoadDelegate(&resourceLoadDelegate)))
1861 COMPtr<CFDictionaryPropertyBag> userInfoBag = CFDictionaryPropertyBag::createInstance();
1863 ResourceError resourceError(String(WebKitErrorDomain), WebKitErrorJavaUnavailable, String(), String());
1864 COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
1866 resourceLoadDelegate->plugInFailedWithError(d->webView, error.get(), getWebDataSource(d->frame->loader()->documentLoader()));
1871 ObjectContentType WebFrame::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
1873 return WebCore::FrameLoader::defaultObjectContentType(url, mimeType, shouldPreferPlugInsForImages);
1876 String WebFrame::overrideMediaType() const
1882 void WebFrame::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
1884 Frame* coreFrame = core(this);
1887 Settings* settings = coreFrame->settings();
1888 if (!settings || !settings->isScriptEnabled())
1891 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1892 if (FAILED(d->webView->frameLoadDelegate(&frameLoadDelegate)))
1895 COMPtr<IWebFrameLoadDelegatePrivate2> delegatePrivate(Query, frameLoadDelegate);
1896 if (delegatePrivate && delegatePrivate->didClearWindowObjectForFrameInScriptWorld(d->webView, this, WebScriptWorld::findOrCreateWorld(world).get()) != E_NOTIMPL)
1899 if (world != mainThreadNormalWorld())
1902 JSContextRef context = toRef(coreFrame->script()->globalObject(world)->globalExec());
1903 JSObjectRef windowObject = toRef(coreFrame->script()->globalObject(world));
1904 ASSERT(windowObject);
1906 if (FAILED(frameLoadDelegate->didClearWindowObject(d->webView, context, windowObject, this)))
1907 frameLoadDelegate->windowScriptObjectAvailable(d->webView, context, windowObject);
1910 void WebFrame::documentElementAvailable()
1914 void WebFrame::didPerformFirstNavigation() const
1916 COMPtr<IWebPreferences> preferences;
1917 if (FAILED(d->webView->preferences(&preferences)))
1920 COMPtr<IWebPreferencesPrivate> preferencesPrivate(Query, preferences);
1921 if (!preferencesPrivate)
1923 BOOL automaticallyDetectsCacheModel;
1924 if (FAILED(preferencesPrivate->automaticallyDetectsCacheModel(&automaticallyDetectsCacheModel)))
1927 WebCacheModel cacheModel;
1928 if (FAILED(preferences->cacheModel(&cacheModel)))
1931 if (automaticallyDetectsCacheModel && cacheModel < WebCacheModelDocumentBrowser)
1932 preferences->setCacheModel(WebCacheModelDocumentBrowser);
1935 void WebFrame::registerForIconNotification(bool listen)
1937 d->webView->registerForIconNotification(listen);
1940 static IntRect printerRect(HDC printDC)
1942 return IntRect(0, 0,
1943 GetDeviceCaps(printDC, PHYSICALWIDTH) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETX),
1944 GetDeviceCaps(printDC, PHYSICALHEIGHT) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETY));
1947 void WebFrame::setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot adjustViewSize)
1949 Frame* coreFrame = core(this);
1951 coreFrame->setPrinting(printing, pageSize, originalPageSize, maximumShrinkRatio, adjustViewSize ? AdjustViewSize : DoNotAdjustViewSize);
1954 HRESULT STDMETHODCALLTYPE WebFrame::setInPrintingMode(
1955 /* [in] */ BOOL value,
1956 /* [in] */ HDC printDC)
1958 if (m_inPrintingMode == !!value)
1961 Frame* coreFrame = core(this);
1962 if (!coreFrame || !coreFrame->document())
1965 m_inPrintingMode = !!value;
1967 // If we are a frameset just print with the layout we have onscreen, otherwise relayout
1968 // according to the paper size
1969 FloatSize minLayoutSize(0.0, 0.0);
1970 FloatSize originalPageSize(0.0, 0.0);
1971 if (m_inPrintingMode && !coreFrame->document()->isFrameSet()) {
1973 ASSERT_NOT_REACHED();
1977 const int desiredPixelsPerInch = 72;
1978 IntRect printRect = printerRect(printDC);
1979 int paperHorizontalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSX);
1980 int paperVerticalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSY);
1981 int paperWidth = printRect.width() * desiredPixelsPerInch / paperHorizontalPixelsPerInch;
1982 int paperHeight = printRect.height() * desiredPixelsPerInch / paperVerticalPixelsPerInch;
1983 originalPageSize = FloatSize(paperWidth, paperHeight);
1984 Frame* coreFrame = core(this);
1985 minLayoutSize = coreFrame->resizePageRectsKeepingRatio(originalPageSize, FloatSize(paperWidth * PrintingMinimumShrinkFactor, paperHeight * PrintingMinimumShrinkFactor));
1988 setPrinting(m_inPrintingMode, minLayoutSize, originalPageSize, PrintingMaximumShrinkFactor / PrintingMinimumShrinkFactor, AdjustViewSize);
1990 if (!m_inPrintingMode)
1991 m_pageRects.clear();
1996 void WebFrame::headerAndFooterHeights(float* headerHeight, float* footerHeight)
2003 COMPtr<IWebUIDelegate> ui;
2004 if (FAILED(d->webView->uiDelegate(&ui)))
2006 if (headerHeight && SUCCEEDED(ui->webViewHeaderHeight(d->webView, &height)))
2007 *headerHeight = height;
2008 if (footerHeight && SUCCEEDED(ui->webViewFooterHeight(d->webView, &height)))
2009 *footerHeight = height;
2012 IntRect WebFrame::printerMarginRect(HDC printDC)
2014 IntRect emptyRect(0, 0, 0, 0);
2016 COMPtr<IWebUIDelegate> ui;
2017 if (FAILED(d->webView->uiDelegate(&ui)))
2021 if (FAILED(ui->webViewPrintingMarginRect(d->webView, &rect)))
2024 rect.left = MulDiv(rect.left, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
2025 rect.top = MulDiv(rect.top, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
2026 rect.right = MulDiv(rect.right, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
2027 rect.bottom = MulDiv(rect.bottom, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
2029 return IntRect(rect.left, rect.top, (rect.right - rect.left), rect.bottom - rect.top);
2032 const Vector<WebCore::IntRect>& WebFrame::computePageRects(HDC printDC)
2034 ASSERT(m_inPrintingMode);
2036 Frame* coreFrame = core(this);
2038 ASSERT(coreFrame->document());
2043 // adjust the page rect by the header and footer
2044 float headerHeight = 0, footerHeight = 0;
2045 headerAndFooterHeights(&headerHeight, &footerHeight);
2046 IntRect pageRect = printerRect(printDC);
2047 IntRect marginRect = printerMarginRect(printDC);
2048 IntRect adjustedRect = IntRect(
2049 pageRect.x() + marginRect.x(),
2050 pageRect.y() + marginRect.y(),
2051 pageRect.width() - marginRect.x() - marginRect.maxX(),
2052 pageRect.height() - marginRect.y() - marginRect.maxY());
2054 computePageRectsForFrame(coreFrame, adjustedRect, headerHeight, footerHeight, 1.0,m_pageRects, m_pageHeight);
2059 HRESULT STDMETHODCALLTYPE WebFrame::getPrintedPageCount(
2060 /* [in] */ HDC printDC,
2061 /* [retval][out] */ UINT *pageCount)
2063 if (!pageCount || !printDC) {
2064 ASSERT_NOT_REACHED();
2070 if (!m_inPrintingMode) {
2071 ASSERT_NOT_REACHED();
2075 Frame* coreFrame = core(this);
2076 if (!coreFrame || !coreFrame->document())
2079 const Vector<IntRect>& pages = computePageRects(printDC);
2080 *pageCount = (UINT) pages.size();
2086 void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
2088 int x = pageRect.x();
2090 RECT headerRect = {x, y, x+pageRect.width(), y+static_cast<int>(headerHeight)};
2091 ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)));
2094 void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
2096 int x = pageRect.x();
2097 int y = max((int)headerHeight+pageRect.height(), m_pageHeight-static_cast<int>(footerHeight));
2098 RECT footerRect = {x, y, x+pageRect.width(), y+static_cast<int>(footerHeight)};
2099 ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)), page+1, pageCount);
2102 void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
2104 Frame* coreFrame = core(this);
2106 IntRect pageRect = m_pageRects[page];
2108 CGContextSaveGState(pctx);
2110 IntRect printRect = printerRect(printDC);
2111 CGRect mediaBox = CGRectMake(CGFloat(0),
2113 CGFloat(printRect.width()),
2114 CGFloat(printRect.height()));
2116 CGContextBeginPage(pctx, &mediaBox);
2118 CGFloat scale = static_cast<float>(mediaBox.size.width)/static_cast<float>(pageRect.width());
2119 CGAffineTransform ctm = CGContextGetBaseCTM(pctx);
2120 ctm = CGAffineTransformScale(ctm, -scale, -scale);
2121 ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
2122 CGContextScaleCTM(pctx, scale, scale);
2123 CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
2124 CGContextSetBaseCTM(pctx, ctm);
2126 coreFrame->view()->paintContents(spoolCtx, pageRect);
2128 CGContextTranslateCTM(pctx, CGFloat(pageRect.x()), CGFloat(pageRect.y())-headerHeight);
2131 drawHeader(pctx, ui, pageRect, headerHeight);
2134 drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
2136 CGContextEndPage(pctx);
2137 CGContextRestoreGState(pctx);
2140 static float scaleFactor(HDC printDC, const IntRect& marginRect, const IntRect& pageRect)
2142 const IntRect& printRect = printerRect(printDC);
2144 IntRect adjustedRect = IntRect(
2145 printRect.x() + marginRect.x(),
2146 printRect.y() + marginRect.y(),
2147 printRect.width() - marginRect.x() - marginRect.maxX(),
2148 printRect.height() - marginRect.y() - marginRect.maxY());
2150 float scale = static_cast<float>(adjustedRect.width()) / static_cast<float>(pageRect.width());
2157 static HDC hdcFromContext(PlatformGraphicsContext* pctx)
2159 return cairo_win32_surface_get_dc(cairo_get_target(pctx->cr()));
2162 void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
2164 HDC hdc = hdcFromContext(pctx);
2166 int x = pageRect.x();
2168 RECT headerRect = {x, y, x + pageRect.width(), y + static_cast<int>(headerHeight)};
2170 ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)));
2173 void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
2175 HDC hdc = hdcFromContext(pctx);
2177 int x = pageRect.x();
2178 int y = max(static_cast<int>(headerHeight) + pageRect.height(), m_pageHeight -static_cast<int>(footerHeight));
2179 RECT footerRect = {x, y, x + pageRect.width(), y + static_cast<int>(footerHeight)};
2181 ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)), page+1, pageCount);
2184 static XFORM buildXFORMFromCairo(HDC targetDC, cairo_t* previewContext)
2187 GetWorldTransform(targetDC, &scaled);
2190 cairo_get_matrix(previewContext, &ctm);
2192 // Scale to the preview screen bounds
2193 scaled.eM11 = ctm.xx;
2194 scaled.eM22 = ctm.yy;
2199 void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
2201 Frame* coreFrame = core(this);
2203 const IntRect& pageRect = m_pageRects[page];
2204 const IntRect& marginRect = printerMarginRect(printDC);
2206 // In preview, the printDC is a placeholder, so just always use the HDC backing the graphics context.
2207 HDC hdc = hdcFromContext(pctx);
2211 XFORM original, scaled;
2212 GetWorldTransform(hdc, &original);
2214 cairo_t* cr = pctx->cr();
2215 bool preview = (hdc != printDC);
2217 // If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo will
2218 // draw correctly. We need to retain the correct preview scale here for use when the Cairo
2219 // drawing completes so that we can scale our GDI-based header/footer calls. This is a
2220 // workaround for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2221 scaled = buildXFORMFromCairo(hdc, cr);
2224 float scale = scaleFactor(printDC, marginRect, pageRect);
2226 IntRect cairoMarginRect(marginRect);
2227 cairoMarginRect.scale(1 / scale);
2229 // We cannot scale the display HDC because the print surface also scales fonts,
2230 // resulting in invalid printing (and print preview)
2231 cairo_scale(cr, scale, scale);
2232 cairo_translate(cr, cairoMarginRect.x(), cairoMarginRect.y() + headerHeight);
2234 // Modify Cairo (only) to account for page position.
2235 cairo_translate(cr, -pageRect.x(), -pageRect.y());
2236 coreFrame->view()->paintContents(spoolCtx, pageRect);
2237 cairo_translate(cr, pageRect.x(), pageRect.y());
2240 // If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo would
2241 // draw correctly. We need to rescale the HDC to the correct preview scale so our GDI-based
2242 // header/footer calls will draw properly. This is a workaround for a bug in Cairo.
2243 // (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2244 SetWorldTransform(hdc, &scaled);
2247 XFORM xform = TransformationMatrix().translate(marginRect.x(), marginRect.y()).scale(scale);
2248 ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
2251 drawHeader(pctx, ui, pageRect, headerHeight);
2254 drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
2256 SetWorldTransform(hdc, &original);
2258 cairo_show_page(cr);
2259 ASSERT(!cairo_status(cr));
2260 spoolCtx->restore();
2263 static void setCairoTransformToPreviewHDC(cairo_t* previewCtx, HDC previewDC)
2266 GetWorldTransform(previewDC, &passedCTM);
2268 // Reset HDC WorldTransform to unscaled state. Scaling must be
2269 // done in Cairo to avoid drawing errors.
2270 XFORM unscaledCTM = passedCTM;
2271 unscaledCTM.eM11 = 1.0;
2272 unscaledCTM.eM22 = 1.0;
2274 SetWorldTransform(previewDC, &unscaledCTM);
2276 // Make the Cairo transform match the information passed to WebKit
2277 // in the HDC's WorldTransform.
2278 cairo_matrix_t ctm = { passedCTM.eM11, passedCTM.eM12, passedCTM.eM21,
2279 passedCTM.eM22, passedCTM.eDx, passedCTM.eDy };
2281 cairo_set_matrix(previewCtx, &ctm);
2286 HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(
2287 /* [in] */ HDC printDC,
2288 /* [in] */ UINT startPage,
2289 /* [in] */ UINT endPage,
2290 /* [retval][out] */ void* ctx)
2293 if (!printDC || !ctx) {
2294 ASSERT_NOT_REACHED();
2299 ASSERT_NOT_REACHED();
2303 HDC targetDC = (ctx) ? (HDC)ctx : printDC;
2305 cairo_surface_t* printSurface = 0;
2307 printSurface = cairo_win32_surface_create(targetDC); // in-memory
2309 printSurface = cairo_win32_printing_surface_create(targetDC); // metafile
2311 cairo_t* cr = cairo_create(printSurface);
2313 cairo_surface_destroy(printSurface);
2317 PlatformContextCairo platformContext(cr);
2318 PlatformGraphicsContext* pctx = &platformContext;
2322 // If this is a preview, the Windows HDC was sent with scaling information.
2323 // Retrieve it and reset it so that it draws properly. This is a workaround
2324 // for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2325 setCairoTransformToPreviewHDC(cr, targetDC);
2328 cairo_surface_set_fallback_resolution(printSurface, 72.0, 72.0);
2331 if (!m_inPrintingMode) {
2332 ASSERT_NOT_REACHED();
2336 Frame* coreFrame = core(this);
2337 if (!coreFrame || !coreFrame->document())
2340 UINT pageCount = (UINT) m_pageRects.size();
2342 PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)ctx;
2345 if (!pageCount || startPage > pageCount) {
2346 ASSERT_NOT_REACHED();
2354 endPage = pageCount;
2356 COMPtr<IWebUIDelegate> ui;
2357 if (FAILED(d->webView->uiDelegate(&ui)))
2360 float headerHeight = 0, footerHeight = 0;
2361 headerAndFooterHeights(&headerHeight, &footerHeight);
2362 GraphicsContext spoolCtx(pctx);
2363 spoolCtx.setShouldIncludeChildWindows(true);
2365 for (UINT ii = startPage; ii < endPage; ii++)
2366 spoolPage(pctx, &spoolCtx, printDC, ui.get(), headerHeight, footerHeight, ii, pageCount);
2369 cairo_surface_finish(printSurface);
2370 ASSERT(!cairo_surface_status(printSurface));
2371 cairo_surface_destroy(printSurface);
2377 HRESULT STDMETHODCALLTYPE WebFrame::isFrameSet(
2378 /* [retval][out] */ BOOL* result)
2382 Frame* coreFrame = core(this);
2383 if (!coreFrame || !coreFrame->document())
2386 *result = coreFrame->document()->isFrameSet() ? TRUE : FALSE;
2390 HRESULT STDMETHODCALLTYPE WebFrame::string(
2391 /* [retval][out] */ BSTR *result)
2395 Frame* coreFrame = core(this);
2399 RefPtr<Range> allRange(rangeOfContents(coreFrame->document()));
2400 String allString = plainText(allRange.get());
2401 *result = BString(allString).release();
2405 HRESULT STDMETHODCALLTYPE WebFrame::size(
2406 /* [retval][out] */ SIZE *size)
2410 size->cx = size->cy = 0;
2412 Frame* coreFrame = core(this);
2415 FrameView* view = coreFrame->view();
2418 size->cx = view->width();
2419 size->cy = view->height();
2423 HRESULT STDMETHODCALLTYPE WebFrame::hasScrollBars(
2424 /* [retval][out] */ BOOL *result)
2430 Frame* coreFrame = core(this);
2434 FrameView* view = coreFrame->view();
2438 if (view->horizontalScrollbar() || view->verticalScrollbar())
2444 HRESULT STDMETHODCALLTYPE WebFrame::contentBounds(
2445 /* [retval][out] */ RECT *result)
2449 ::SetRectEmpty(result);
2451 Frame* coreFrame = core(this);
2455 FrameView* view = coreFrame->view();
2459 result->bottom = view->contentsHeight();
2460 result->right = view->contentsWidth();
2464 HRESULT STDMETHODCALLTYPE WebFrame::frameBounds(
2465 /* [retval][out] */ RECT *result)
2469 ::SetRectEmpty(result);
2471 Frame* coreFrame = core(this);
2475 FrameView* view = coreFrame->view();
2479 FloatRect bounds = view->visibleContentRect(true);
2480 result->bottom = (LONG) bounds.height();
2481 result->right = (LONG) bounds.width();
2485 HRESULT STDMETHODCALLTYPE WebFrame::isDescendantOfFrame(
2486 /* [in] */ IWebFrame *ancestor,
2487 /* [retval][out] */ BOOL *result)
2493 Frame* coreFrame = core(this);
2494 COMPtr<WebFrame> ancestorWebFrame(Query, ancestor);
2495 if (!ancestorWebFrame)
2498 *result = (coreFrame && coreFrame->tree()->isDescendantOf(core(ancestorWebFrame.get()))) ? TRUE : FALSE;
2502 HRESULT WebFrame::stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld* iWorld, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult)
2504 if (!evaluationResult)
2506 *evaluationResult = 0;
2511 COMPtr<WebScriptWorld> world(Query, iWorld);
2513 return E_INVALIDARG;
2515 Frame* coreFrame = core(this);
2516 String string = String(script, SysStringLen(script));
2518 // Start off with some guess at a frame and a global object, we'll try to do better...!
2519 JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld());
2521 // The global object is probably a shell object? - if so, we know how to use this!
2522 JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
2523 if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
2524 anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
2526 // Get the frame frome the global object we've settled on.
2527 Frame* frame = anyWorldGlobalObject->impl()->frame();
2528 ASSERT(frame->document());
2529 JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue();
2531 if (!frame) // In case the script removed our frame from the page.
2534 // This bizarre set of rules matches behavior from WebKit for Safari 2.0.
2535 // If you don't like it, use -[WebScriptObject evaluateWebScript:] or
2536 // JSEvaluateScript instead, since they have less surprising semantics.
2537 if (!result || !result.isBoolean() && !result.isString() && !result.isNumber())
2540 JSC::ExecState* exec = anyWorldGlobalObject->globalExec();
2541 JSC::JSLockHolder lock(exec);
2542 String resultString = ustringToString(result.toString(exec)->value(exec));
2543 *evaluationResult = BString(resultString).release();
2548 void WebFrame::unmarkAllMisspellings()
2550 Frame* coreFrame = core(this);
2551 for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
2552 Document *doc = frame->document();
2556 doc->markers()->removeMarkers(DocumentMarker::Spelling);
2560 void WebFrame::unmarkAllBadGrammar()
2562 Frame* coreFrame = core(this);
2563 for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
2564 Document *doc = frame->document();
2568 doc->markers()->removeMarkers(DocumentMarker::Grammar);
2572 WebView* WebFrame::webView() const
2577 void WebFrame::setWebView(WebView* webView)
2579 d->webView = webView;
2582 COMPtr<IAccessible> WebFrame::accessible() const
2584 Frame* coreFrame = core(this);
2587 Document* currentDocument = coreFrame->document();
2588 if (!currentDocument)
2590 else if (!m_accessible || m_accessible->document() != currentDocument) {
2591 // Either we've never had a wrapper for this frame's top-level Document,
2592 // the Document renderer was destroyed and its wrapper was detached, or
2593 // the previous Document is in the page cache, and the current document
2594 // needs to be wrapped.
2595 m_accessible = new AccessibleDocument(currentDocument);
2597 return m_accessible.get();
2600 void WebFrame::updateBackground()
2602 Color backgroundColor = webView()->transparent() ? Color::transparent : Color::white;
2603 Frame* coreFrame = core(this);
2605 if (!coreFrame || !coreFrame->view())
2608 coreFrame->view()->updateBackgroundRecursively(backgroundColor, webView()->transparent());
2611 PassRefPtr<FrameNetworkingContext> WebFrame::createNetworkingContext()
2613 return WebFrameNetworkingContext::create(core(this), userAgent(url()));