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/SVGDocumentExtensions.h>
97 #include <WebCore/SVGSMILElement.h>
98 #include <WebCore/TextIterator.h>
99 #include <WebCore/JSDOMBinding.h>
100 #include <WebCore/ScriptController.h>
101 #include <WebCore/ScriptValue.h>
102 #include <WebCore/SecurityOrigin.h>
103 #include <JavaScriptCore/APICast.h>
104 #include <JavaScriptCore/JSLock.h>
105 #include <JavaScriptCore/JSObject.h>
106 #include <JavaScriptCore/JSValue.h>
107 #include <wtf/MathExtras.h>
110 #include <CoreGraphics/CoreGraphics.h>
112 #include "PlatformContextCairo.h"
113 #include <cairo-win32.h>
117 // CG SPI used for printing
119 CGAffineTransform CGContextGetBaseCTM(CGContextRef c);
120 void CGContextSetBaseCTM(CGContextRef c, CGAffineTransform m);
124 using namespace WebCore;
125 using namespace HTMLNames;
128 using JSC::JSGlobalObject;
131 using JSC::SilenceAssertionsOnly;
133 #define FLASH_REDRAW 0
136 // By imaging to a width a little wider than the available pixels,
137 // thin pages will be scaled down a little, matching the way they
138 // print in IE and Camino. This lets them use fewer sheets than they
139 // would otherwise, which is presumably why other browsers do this.
140 // Wide pages will be scaled down more than this.
141 const float PrintingMinimumShrinkFactor = 1.25f;
143 // This number determines how small we are willing to reduce the page content
144 // in order to accommodate the widest line. If the page would have to be
145 // reduced smaller to make the widest line fit, we just clip instead (this
146 // behavior matches MacIE and Mozilla, at least)
147 const float PrintingMaximumShrinkFactor = 2.0f;
149 //-----------------------------------------------------------------------------
150 // Helpers to convert from WebCore to WebKit type
151 WebFrame* kit(Frame* frame)
156 FrameLoaderClient* frameLoaderClient = frame->loader()->client();
157 if (frameLoaderClient)
158 return static_cast<WebFrame*>(frameLoaderClient); // eek, is there a better way than static cast?
162 Frame* core(WebFrame* webFrame)
166 return webFrame->impl();
169 // 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
170 Frame* core(const WebFrame* webFrame)
174 return const_cast<WebFrame*>(webFrame)->impl();
177 //-----------------------------------------------------------------------------
179 static Element *elementFromDOMElement(IDOMElement *element)
184 COMPtr<IDOMElementPrivate> elePriv;
185 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
188 hr = elePriv->coreElement((void**)&ele);
195 static HTMLFormElement *formElementFromDOMElement(IDOMElement *element)
200 IDOMElementPrivate* elePriv;
201 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
204 hr = elePriv->coreElement((void**)&ele);
206 if (SUCCEEDED(hr) && ele && ele->hasTagName(formTag))
207 return static_cast<HTMLFormElement*>(ele);
212 static HTMLInputElement* inputElementFromDOMElement(IDOMElement* element)
217 IDOMElementPrivate* elePriv;
218 HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
221 hr = elePriv->coreElement((void**)&ele);
223 if (SUCCEEDED(hr) && ele && ele->hasTagName(inputTag))
224 return static_cast<HTMLInputElement*>(ele);
229 // WebFramePrivate ------------------------------------------------------------
231 class WebFrame::WebFramePrivate {
236 , m_policyFunction(0)
240 ~WebFramePrivate() { }
241 FrameView* frameView() { return frame ? frame->view() : 0; }
245 FramePolicyFunction m_policyFunction;
246 COMPtr<WebFramePolicyListener> m_policyListener;
249 // WebFrame ----------------------------------------------------------------
252 : WebFrameLoaderClient(this)
254 , d(new WebFrame::WebFramePrivate)
255 , m_quickRedirectComing(false)
256 , m_inPrintingMode(false)
261 gClassNameCount.add("WebFrame");
264 WebFrame::~WebFrame()
269 gClassNameCount.remove("WebFrame");
272 WebFrame* WebFrame::createInstance()
274 WebFrame* instance = new WebFrame();
279 HRESULT STDMETHODCALLTYPE WebFrame::setAllowsScrolling(
280 /* [in] */ BOOL flag)
282 if (Frame* frame = core(this))
283 if (FrameView* view = frame->view())
284 view->setCanHaveScrollbars(!!flag);
289 HRESULT STDMETHODCALLTYPE WebFrame::allowsScrolling(
290 /* [retval][out] */ BOOL *flag)
293 if (Frame* frame = core(this))
294 if (FrameView* view = frame->view())
295 *flag = view->canHaveScrollbars();
300 HRESULT STDMETHODCALLTYPE WebFrame::setIsDisconnected(
301 /* [in] */ BOOL flag)
303 if (Frame* frame = core(this)) {
304 frame->setIsDisconnected(flag);
311 HRESULT STDMETHODCALLTYPE WebFrame::setExcludeFromTextSearch(
312 /* [in] */ BOOL flag)
314 if (Frame* frame = core(this)) {
315 frame->setExcludeFromTextSearch(flag);
322 HRESULT WebFrame::reloadFromOrigin()
324 Frame* coreFrame = core(this);
328 coreFrame->loader()->reload(true);
332 HRESULT STDMETHODCALLTYPE WebFrame::paintDocumentRectToContext(
333 /* [in] */ RECT rect,
334 /* [in] */ OLE_HANDLE deviceContext)
336 Frame* coreFrame = core(this);
340 FrameView* view = coreFrame->view();
344 // We can't paint with a layout still pending.
345 view->updateLayoutAndStyleIfNeededRecursive();
347 HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
348 GraphicsContext gc(dc);
349 gc.setShouldIncludeChildWindows(true);
351 LONG width = rect.right - rect.left;
352 LONG height = rect.bottom - rect.top;
354 dirtyRect.setWidth(width);
355 dirtyRect.setHeight(height);
357 gc.translate(-rect.left, -rect.top);
358 view->paintContents(&gc, rect);
364 HRESULT STDMETHODCALLTYPE WebFrame::paintScrollViewRectToContextAtPoint(
365 /* [in] */ RECT rect,
367 /* [in] */ OLE_HANDLE deviceContext)
369 Frame* coreFrame = core(this);
373 FrameView* view = coreFrame->view();
377 // We can't paint with a layout still pending.
378 view->updateLayoutAndStyleIfNeededRecursive();
380 HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
381 GraphicsContext gc(dc);
382 gc.setShouldIncludeChildWindows(true);
384 IntRect dirtyRect(rect);
385 dirtyRect.move(-pt.x, -pt.y);
386 view->paint(&gc, dirtyRect);
392 // IUnknown -------------------------------------------------------------------
394 HRESULT STDMETHODCALLTYPE WebFrame::QueryInterface(REFIID riid, void** ppvObject)
397 if (IsEqualGUID(riid, __uuidof(WebFrame)))
399 else if (IsEqualGUID(riid, IID_IUnknown))
400 *ppvObject = static_cast<IWebFrame*>(this);
401 else if (IsEqualGUID(riid, IID_IWebFrame))
402 *ppvObject = static_cast<IWebFrame*>(this);
403 else if (IsEqualGUID(riid, IID_IWebFramePrivate))
404 *ppvObject = static_cast<IWebFramePrivate*>(this);
405 else if (IsEqualGUID(riid, IID_IWebDocumentText))
406 *ppvObject = static_cast<IWebDocumentText*>(this);
408 return E_NOINTERFACE;
414 ULONG STDMETHODCALLTYPE WebFrame::AddRef(void)
419 ULONG STDMETHODCALLTYPE WebFrame::Release(void)
421 ULONG newRef = --m_refCount;
428 // IWebFrame -------------------------------------------------------------------
430 HRESULT STDMETHODCALLTYPE WebFrame::name(
431 /* [retval][out] */ BSTR* frameName)
434 ASSERT_NOT_REACHED();
440 Frame* coreFrame = core(this);
444 *frameName = BString(coreFrame->tree()->uniqueName()).release();
448 HRESULT STDMETHODCALLTYPE WebFrame::webView(
449 /* [retval][out] */ IWebView** view)
459 HRESULT STDMETHODCALLTYPE WebFrame::frameView(
460 /* [retval][out] */ IWebFrameView** /*view*/)
462 ASSERT_NOT_REACHED();
466 HRESULT STDMETHODCALLTYPE WebFrame::DOMDocument(
467 /* [retval][out] */ IDOMDocument** result)
470 ASSERT_NOT_REACHED();
476 if (Frame* coreFrame = core(this))
477 if (Document* document = coreFrame->document())
478 *result = DOMDocument::createInstance(document);
480 return *result ? S_OK : E_FAIL;
484 HRESULT WebFrame::DOMWindow(/* [retval][out] */ IDOMWindow** window)
487 ASSERT_NOT_REACHED();
493 if (Frame* coreFrame = core(this)) {
494 if (WebCore::DOMWindow* coreWindow = coreFrame->domWindow())
495 *window = ::DOMWindow::createInstance(coreWindow);
498 return *window ? S_OK : E_FAIL;
501 HRESULT STDMETHODCALLTYPE WebFrame::frameElement(
502 /* [retval][out] */ IDOMHTMLElement** frameElement)
508 Frame* coreFrame = core(this);
512 COMPtr<IDOMElement> domElement(AdoptCOM, DOMElement::createInstance(coreFrame->ownerElement()));
513 COMPtr<IDOMHTMLElement> htmlElement(Query, domElement);
516 return htmlElement.copyRefTo(frameElement);
519 HRESULT STDMETHODCALLTYPE WebFrame::currentForm(
520 /* [retval][out] */ IDOMElement **currentForm)
523 ASSERT_NOT_REACHED();
529 if (Frame* coreFrame = core(this)) {
530 if (HTMLFormElement* formElement = coreFrame->selection()->currentForm())
531 *currentForm = DOMElement::createInstance(formElement);
534 return *currentForm ? S_OK : E_FAIL;
537 JSGlobalContextRef STDMETHODCALLTYPE WebFrame::globalContext()
539 Frame* coreFrame = core(this);
543 return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
546 JSGlobalContextRef WebFrame::globalContextForScriptWorld(IWebScriptWorld* iWorld)
548 Frame* coreFrame = core(this);
552 COMPtr<WebScriptWorld> world(Query, iWorld);
556 return toGlobalRef(coreFrame->script()->globalObject(world->world())->globalExec());
559 HRESULT STDMETHODCALLTYPE WebFrame::loadRequest(
560 /* [in] */ IWebURLRequest* request)
562 COMPtr<WebMutableURLRequest> requestImpl;
564 HRESULT hr = request->QueryInterface(&requestImpl);
568 Frame* coreFrame = core(this);
572 coreFrame->loader()->load(requestImpl->resourceRequest(), false);
576 void WebFrame::loadData(PassRefPtr<WebCore::SharedBuffer> data, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL)
578 String mimeTypeString(mimeType, SysStringLen(mimeType));
580 mimeTypeString = "text/html";
582 String encodingString(textEncodingName, SysStringLen(textEncodingName));
584 // FIXME: We should really be using MarshallingHelpers::BSTRToKURL here,
585 // but that would turn a null BSTR into a null KURL, and we crash inside of
586 // WebCore if we use a null KURL in constructing the ResourceRequest.
587 KURL baseKURL = KURL(KURL(), String(baseURL ? baseURL : L"", SysStringLen(baseURL)));
589 KURL failingKURL = MarshallingHelpers::BSTRToKURL(failingURL);
591 ResourceRequest request(baseKURL);
592 SubstituteData substituteData(data, mimeTypeString, encodingString, failingKURL);
594 // This method is only called from IWebFrame methods, so don't ASSERT that the Frame pointer isn't null.
595 if (Frame* coreFrame = core(this))
596 coreFrame->loader()->load(request, substituteData, false);
600 HRESULT STDMETHODCALLTYPE WebFrame::loadData(
601 /* [in] */ IStream* data,
602 /* [in] */ BSTR mimeType,
603 /* [in] */ BSTR textEncodingName,
606 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
609 if (SUCCEEDED(data->Stat(&stat, STATFLAG_NONAME))) {
610 if (!stat.cbSize.HighPart && stat.cbSize.LowPart) {
611 Vector<char> dataBuffer(stat.cbSize.LowPart);
613 // FIXME: this does a needless copy, would be better to read right into the SharedBuffer
614 // or adopt the Vector or something.
615 if (SUCCEEDED(data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read)))
616 sharedBuffer->append(dataBuffer.data(), static_cast<int>(dataBuffer.size()));
620 loadData(sharedBuffer, mimeType, textEncodingName, url, 0);
624 HRESULT WebFrame::loadPlainTextString(
625 /* [in] */ BSTR string,
628 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
629 BString plainTextMimeType(TEXT("text/plain"), 10);
630 BString utf16Encoding(TEXT("utf-16"), 6);
631 loadData(sharedBuffer.release(), plainTextMimeType, utf16Encoding, url, 0);
635 void WebFrame::loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL)
637 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
638 BString utf16Encoding(TEXT("utf-16"), 6);
639 loadData(sharedBuffer.release(), 0, utf16Encoding, baseURL, unreachableURL);
642 HRESULT STDMETHODCALLTYPE WebFrame::loadHTMLString(
643 /* [in] */ BSTR string,
644 /* [in] */ BSTR baseURL)
646 loadHTMLString(string, baseURL, 0);
650 HRESULT STDMETHODCALLTYPE WebFrame::loadAlternateHTMLString(
652 /* [in] */ BSTR baseURL,
653 /* [in] */ BSTR unreachableURL)
655 loadHTMLString(str, baseURL, unreachableURL);
659 HRESULT STDMETHODCALLTYPE WebFrame::loadArchive(
660 /* [in] */ IWebArchive* /*archive*/)
662 ASSERT_NOT_REACHED();
666 static inline WebDataSource *getWebDataSource(DocumentLoader* loader)
668 return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;
671 HRESULT STDMETHODCALLTYPE WebFrame::dataSource(
672 /* [retval][out] */ IWebDataSource** source)
675 ASSERT_NOT_REACHED();
681 Frame* coreFrame = core(this);
685 WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->documentLoader());
687 *source = webDataSource;
690 webDataSource->AddRef();
692 return *source ? S_OK : E_FAIL;
695 HRESULT STDMETHODCALLTYPE WebFrame::provisionalDataSource(
696 /* [retval][out] */ IWebDataSource** source)
699 ASSERT_NOT_REACHED();
705 Frame* coreFrame = core(this);
709 WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->provisionalDocumentLoader());
711 *source = webDataSource;
714 webDataSource->AddRef();
716 return *source ? S_OK : E_FAIL;
719 KURL WebFrame::url() const
721 Frame* coreFrame = core(this);
725 return coreFrame->document()->url();
728 HRESULT STDMETHODCALLTYPE WebFrame::stopLoading( void)
730 if (Frame* coreFrame = core(this))
731 coreFrame->loader()->stopAllLoaders();
735 HRESULT STDMETHODCALLTYPE WebFrame::reload( void)
737 Frame* coreFrame = core(this);
741 coreFrame->loader()->reload();
745 HRESULT STDMETHODCALLTYPE WebFrame::findFrameNamed(
746 /* [in] */ BSTR name,
747 /* [retval][out] */ IWebFrame** frame)
750 ASSERT_NOT_REACHED();
756 Frame* coreFrame = core(this);
760 Frame* foundFrame = coreFrame->tree()->find(AtomicString(name, SysStringLen(name)));
764 WebFrame* foundWebFrame = kit(foundFrame);
768 return foundWebFrame->QueryInterface(IID_IWebFrame, (void**)frame);
771 HRESULT STDMETHODCALLTYPE WebFrame::parentFrame(
772 /* [retval][out] */ IWebFrame** frame)
776 if (Frame* coreFrame = core(this))
777 if (WebFrame* webFrame = kit(coreFrame->tree()->parent()))
778 hr = webFrame->QueryInterface(IID_IWebFrame, (void**) frame);
783 class EnumChildFrames : public IEnumVARIANT
786 EnumChildFrames(Frame* f) : m_refCount(1), m_frame(f), m_curChild(f ? f->tree()->firstChild() : 0) { }
788 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
791 if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
794 return E_NOINTERFACE;
800 virtual ULONG STDMETHODCALLTYPE AddRef(void)
805 virtual ULONG STDMETHODCALLTYPE Release(void)
807 ULONG newRef = --m_refCount;
813 virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
820 if (!celt || celt > 1)
822 if (!m_frame || !m_curChild)
825 WebFrame* webFrame = kit(m_curChild);
827 HRESULT hr = webFrame->QueryInterface(IID_IUnknown, (void**)&unknown);
831 V_VT(rgVar) = VT_UNKNOWN;
832 V_UNKNOWN(rgVar) = unknown;
834 m_curChild = m_curChild->tree()->nextSibling();
840 virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
844 for (unsigned i = 0; i < celt && m_curChild; i++)
845 m_curChild = m_curChild->tree()->nextSibling();
846 return m_curChild ? S_OK : S_FALSE;
849 virtual HRESULT STDMETHODCALLTYPE Reset(void)
853 m_curChild = m_frame->tree()->firstChild();
857 virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**)
868 HRESULT STDMETHODCALLTYPE WebFrame::childFrames(
869 /* [retval][out] */ IEnumVARIANT **enumFrames)
874 *enumFrames = new EnumChildFrames(core(this));
878 // IWebFramePrivate ------------------------------------------------------
880 HRESULT WebFrame::renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result)
885 Frame* coreFrame = core(this);
889 *result = BString(externalRepresentation(coreFrame, forPrinting ? RenderAsTextPrintingMode : RenderAsTextBehaviorNormal)).release();
893 HRESULT STDMETHODCALLTYPE WebFrame::counterValueForElementById(
894 /* [in] */ BSTR id, /* [retval][out] */ BSTR *result)
899 Frame* coreFrame = core(this);
903 String coreId = String(id, SysStringLen(id));
905 Element* element = coreFrame->document()->getElementById(coreId);
908 *result = BString(counterValueForElement(element)).release();
912 HRESULT STDMETHODCALLTYPE WebFrame::pageNumberForElementById(
914 /* [in] */ float pageWidthInPixels,
915 /* [in] */ float pageHeightInPixels,
916 /* [retval][out] */ int* result)
921 Frame* coreFrame = core(this);
925 String coreId = String(id, SysStringLen(id));
927 Element* element = coreFrame->document()->getElementById(coreId);
930 *result = PrintContext::pageNumberForElement(element, FloatSize(pageWidthInPixels, pageHeightInPixels));
934 HRESULT STDMETHODCALLTYPE WebFrame::numberOfPages(
935 /* [in] */ float pageWidthInPixels,
936 /* [in] */ float pageHeightInPixels,
937 /* [retval][out] */ int* result)
942 Frame* coreFrame = core(this);
946 *result = PrintContext::numberOfPages(coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
950 HRESULT STDMETHODCALLTYPE WebFrame::scrollOffset(
951 /* [retval][out] */ SIZE* offset)
954 ASSERT_NOT_REACHED();
958 Frame* coreFrame = core(this);
962 FrameView* view = coreFrame->view();
966 *offset = view->scrollOffset();
970 HRESULT STDMETHODCALLTYPE WebFrame::layout()
972 Frame* coreFrame = core(this);
976 FrameView* view = coreFrame->view();
984 HRESULT STDMETHODCALLTYPE WebFrame::firstLayoutDone(
985 /* [retval][out] */ BOOL* result)
988 ASSERT_NOT_REACHED();
994 Frame* coreFrame = core(this);
998 *result = coreFrame->loader()->stateMachine()->firstLayoutDone();
1002 HRESULT STDMETHODCALLTYPE WebFrame::loadType(
1003 /* [retval][out] */ WebFrameLoadType* type)
1006 ASSERT_NOT_REACHED();
1010 *type = (WebFrameLoadType)0;
1012 Frame* coreFrame = core(this);
1016 *type = (WebFrameLoadType)coreFrame->loader()->loadType();
1020 HRESULT STDMETHODCALLTYPE WebFrame::pendingFrameUnloadEventCount(
1021 /* [retval][out] */ UINT* result)
1024 ASSERT_NOT_REACHED();
1030 Frame* coreFrame = core(this);
1034 *result = coreFrame->domWindow()->pendingUnloadEventListeners();
1038 HRESULT STDMETHODCALLTYPE WebFrame::unused2()
1043 HRESULT STDMETHODCALLTYPE WebFrame::hasSpellingMarker(
1044 /* [in] */ UINT from,
1045 /* [in] */ UINT length,
1046 /* [retval][out] */ BOOL* result)
1048 Frame* coreFrame = core(this);
1051 *result = coreFrame->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1055 HRESULT STDMETHODCALLTYPE WebFrame::clearOpener()
1058 if (Frame* coreFrame = core(this))
1059 coreFrame->loader()->setOpener(0);
1064 HRESULT WebFrame::setTextDirection(BSTR direction)
1066 Frame* coreFrame = core(this);
1067 if (!coreFrame || !coreFrame->editor())
1070 String directionString(direction, SysStringLen(direction));
1071 if (directionString == "auto")
1072 coreFrame->editor()->setBaseWritingDirection(NaturalWritingDirection);
1073 else if (directionString == "ltr")
1074 coreFrame->editor()->setBaseWritingDirection(LeftToRightWritingDirection);
1075 else if (directionString == "rtl")
1076 coreFrame->editor()->setBaseWritingDirection(RightToLeftWritingDirection);
1080 // IWebDocumentText -----------------------------------------------------------
1082 HRESULT STDMETHODCALLTYPE WebFrame::supportsTextEncoding(
1083 /* [retval][out] */ BOOL* result)
1089 HRESULT STDMETHODCALLTYPE WebFrame::selectedString(
1090 /* [retval][out] */ BSTR* result)
1094 Frame* coreFrame = core(this);
1098 String text = coreFrame->displayStringModifiedByEncoding(coreFrame->editor()->selectedText());
1100 *result = BString(text).release();
1104 HRESULT STDMETHODCALLTYPE WebFrame::selectAll()
1106 Frame* coreFrame = core(this);
1110 if (!coreFrame->editor()->command("SelectAll").execute())
1116 HRESULT STDMETHODCALLTYPE WebFrame::deselectAll()
1121 // WebFrame ---------------------------------------------------------------
1123 PassRefPtr<Frame> WebFrame::init(IWebView* webView, Page* page, HTMLFrameOwnerElement* ownerElement)
1125 webView->QueryInterface(&d->webView);
1126 d->webView->Release(); // don't hold the extra ref
1129 d->webView->viewWindow((OLE_HANDLE*)&viewWindow);
1131 this->AddRef(); // We release this ref in frameLoaderDestroyed()
1132 RefPtr<Frame> frame = Frame::create(page, ownerElement, this);
1133 d->frame = frame.get();
1134 return frame.release();
1137 Frame* WebFrame::impl()
1142 void WebFrame::invalidate()
1144 Frame* coreFrame = core(this);
1147 if (Document* document = coreFrame->document())
1148 document->recalcStyle(Node::Force);
1151 HRESULT WebFrame::inViewSourceMode(BOOL* flag)
1154 ASSERT_NOT_REACHED();
1160 Frame* coreFrame = core(this);
1164 *flag = coreFrame->inViewSourceMode() ? TRUE : FALSE;
1168 HRESULT WebFrame::setInViewSourceMode(BOOL flag)
1170 Frame* coreFrame = core(this);
1174 coreFrame->setInViewSourceMode(!!flag);
1178 HRESULT WebFrame::elementWithName(BSTR name, IDOMElement* form, IDOMElement** element)
1181 return E_INVALIDARG;
1183 HTMLFormElement* formElement = formElementFromDOMElement(form);
1185 const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
1186 AtomicString targetName((UChar*)name, SysStringLen(name));
1187 for (unsigned int i = 0; i < elements.size(); i++) {
1188 if (!elements[i]->isFormControlElement())
1190 HTMLFormControlElement* elt = static_cast<HTMLFormControlElement*>(elements[i]);
1191 // Skip option elements, other duds
1192 if (elt->name() == targetName) {
1193 *element = DOMElement::createInstance(elt);
1201 HRESULT WebFrame::formForElement(IDOMElement* element, IDOMElement** form)
1204 return E_INVALIDARG;
1206 HTMLInputElement *inputElement = inputElementFromDOMElement(element);
1210 HTMLFormElement *formElement = inputElement->form();
1214 *form = DOMElement::createInstance(formElement);
1218 HRESULT WebFrame::elementDoesAutoComplete(IDOMElement *element, BOOL *result)
1222 return E_INVALIDARG;
1224 HTMLInputElement *inputElement = inputElementFromDOMElement(element);
1228 *result = inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->shouldAutocomplete();
1233 HRESULT WebFrame::pauseAnimation(BSTR animationName, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning)
1235 if (!node || !animationWasRunning)
1238 *animationWasRunning = FALSE;
1240 Frame* frame = core(this);
1244 AnimationController* controller = frame->animation();
1248 COMPtr<DOMNode> domNode(Query, node);
1252 *animationWasRunning = controller->pauseAnimationAtTime(domNode->node()->renderer(), String(animationName, SysStringLen(animationName)), secondsFromNow);
1256 HRESULT WebFrame::pauseTransition(BSTR propertyName, IDOMNode* node, double secondsFromNow, BOOL* transitionWasRunning)
1258 if (!node || !transitionWasRunning)
1261 *transitionWasRunning = FALSE;
1263 Frame* frame = core(this);
1267 AnimationController* controller = frame->animation();
1271 COMPtr<DOMNode> domNode(Query, node);
1275 *transitionWasRunning = controller->pauseTransitionAtTime(domNode->node()->renderer(), String(propertyName, SysStringLen(propertyName)), secondsFromNow);
1279 HRESULT WebFrame::pauseSVGAnimation(BSTR elementId, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning)
1281 if (!node || !animationWasRunning)
1284 *animationWasRunning = FALSE;
1286 Frame* frame = core(this);
1290 Document* document = frame->document();
1291 if (!document || !document->svgExtensions())
1294 COMPtr<DOMNode> domNode(Query, node);
1295 if (!domNode || !SVGSMILElement::isSMILElement(domNode->node()))
1299 *animationWasRunning = document->accessSVGExtensions()->sampleAnimationAtTime(String(elementId, SysStringLen(elementId)), static_cast<SVGSMILElement*>(domNode->node()), secondsFromNow);
1301 *animationWasRunning = FALSE;
1307 HRESULT WebFrame::visibleContentRect(RECT* rect)
1313 Frame* frame = core(this);
1317 FrameView* view = frame->view();
1321 *rect = view->visibleContentRect(false);
1325 HRESULT WebFrame::numberOfActiveAnimations(UINT* number)
1332 Frame* frame = core(this);
1336 AnimationController* controller = frame->animation();
1340 *number = controller->numberOfActiveAnimations(frame->document());
1344 HRESULT WebFrame::suspendAnimations()
1346 Frame* frame = core(this);
1350 frame->animation()->suspendAnimations();
1354 HRESULT WebFrame::resumeAnimations()
1356 Frame* frame = core(this);
1360 frame->animation()->resumeAnimations();
1364 HRESULT WebFrame::isDisplayingStandaloneImage(BOOL* result)
1371 Frame* frame = core(this);
1375 Document* document = frame->document();
1376 *result = document && document->isImageDocument();
1380 HRESULT WebFrame::allowsFollowingLink(BSTR url, BOOL* result)
1387 Frame* frame = core(this);
1391 *result = frame->document()->securityOrigin()->canDisplay(MarshallingHelpers::BSTRToKURL(url));
1395 HRESULT WebFrame::controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls)
1398 return E_INVALIDARG;
1400 HTMLFormElement* formElement = formElementFromDOMElement(form);
1404 int inCount = *cControls;
1405 int count = (int) formElement->associatedElements().size();
1409 if (inCount < count)
1413 const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
1414 for (int i = 0; i < count; i++) {
1415 if (elements.at(i)->isEnumeratable()) { // Skip option elements, other duds
1416 controls[*cControls] = DOMElement::createInstance(toHTMLElement(elements.at(i)));
1423 HRESULT WebFrame::elementIsPassword(IDOMElement *element, bool *result)
1425 HTMLInputElement* inputElement = inputElementFromDOMElement(element);
1426 *result = inputElement && inputElement->isPasswordField();
1430 HRESULT WebFrame::searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* outResultDistance, BOOL* outResultIsInCellAbove, BSTR* result)
1433 ASSERT_NOT_REACHED();
1437 if (outResultDistance)
1438 *outResultDistance = 0;
1439 if (outResultIsInCellAbove)
1440 *outResultIsInCellAbove = FALSE;
1446 return E_INVALIDARG;
1448 Frame* coreFrame = core(this);
1452 Vector<String> labelStrings(cLabels);
1453 for (int i=0; i<cLabels; i++)
1454 labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
1455 Element *coreElement = elementFromDOMElement(beforeElement);
1459 size_t resultDistance;
1460 bool resultIsInCellAbove;
1461 String label = coreFrame->searchForLabelsBeforeElement(labelStrings, coreElement, &resultDistance, &resultIsInCellAbove);
1463 *result = SysAllocStringLen(label.characters(), label.length());
1464 if (label.length() && !*result)
1465 return E_OUTOFMEMORY;
1466 if (outResultDistance)
1467 *outResultDistance = resultDistance;
1468 if (outResultIsInCellAbove)
1469 *outResultIsInCellAbove = resultIsInCellAbove;
1474 HRESULT WebFrame::matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result)
1477 ASSERT_NOT_REACHED();
1486 return E_INVALIDARG;
1488 Frame* coreFrame = core(this);
1492 Vector<String> labelStrings(cLabels);
1493 for (int i=0; i<cLabels; i++)
1494 labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
1495 Element *coreElement = elementFromDOMElement(againstElement);
1499 String label = coreFrame->matchLabelsAgainstElement(labelStrings, coreElement);
1501 *result = SysAllocStringLen(label.characters(), label.length());
1502 if (label.length() && !*result)
1503 return E_OUTOFMEMORY;
1507 HRESULT WebFrame::canProvideDocumentSource(bool* result)
1512 COMPtr<IWebDataSource> dataSource;
1513 hr = WebFrame::dataSource(&dataSource);
1517 COMPtr<IWebURLResponse> urlResponse;
1518 hr = dataSource->response(&urlResponse);
1519 if (SUCCEEDED(hr) && urlResponse) {
1521 if (SUCCEEDED(urlResponse->MIMEType(&mimeTypeBStr))) {
1522 String mimeType(mimeTypeBStr, SysStringLen(mimeTypeBStr));
1523 *result = mimeType == "text/html" || WebCore::DOMImplementation::isXMLMIMEType(mimeType);
1524 SysFreeString(mimeTypeBStr);
1530 HRESULT STDMETHODCALLTYPE WebFrame::layerTreeAsText(BSTR* result)
1536 Frame* frame = core(this);
1540 String text = frame->layerTreeAsText();
1541 *result = BString(text).release();
1545 void WebFrame::frameLoaderDestroyed()
1547 // The FrameLoader going away is equivalent to the Frame going away,
1548 // so we now need to clear our frame pointer.
1554 void WebFrame::makeRepresentation(DocumentLoader*)
1559 void WebFrame::forceLayoutForNonHTML()
1564 void WebFrame::setCopiesOnScroll()
1569 void WebFrame::detachedFromParent2()
1574 void WebFrame::detachedFromParent3()
1579 void WebFrame::cancelPolicyCheck()
1581 if (d->m_policyListener) {
1582 d->m_policyListener->invalidate();
1583 d->m_policyListener = 0;
1586 d->m_policyFunction = 0;
1589 void WebFrame::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState)
1591 Frame* coreFrame = core(this);
1594 COMPtr<IWebFormDelegate> formDelegate;
1596 if (FAILED(d->webView->formDelegate(&formDelegate))) {
1597 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1601 COMPtr<IDOMElement> formElement(AdoptCOM, DOMElement::createInstance(formState->form()));
1603 HashMap<String, String> formValuesMap;
1604 const StringPairVector& textFieldValues = formState->textFieldValues();
1605 size_t size = textFieldValues.size();
1606 for (size_t i = 0; i < size; ++i)
1607 formValuesMap.add(textFieldValues[i].first, textFieldValues[i].second);
1609 COMPtr<IPropertyBag> formValuesPropertyBag(AdoptCOM, COMPropertyBag<String>::createInstance(formValuesMap));
1611 COMPtr<WebFrame> sourceFrame(kit(formState->sourceFrame()));
1612 if (SUCCEEDED(formDelegate->willSubmitForm(this, sourceFrame.get(), formElement.get(), formValuesPropertyBag.get(), setUpPolicyListener(function).get())))
1615 // FIXME: Add a sane default implementation
1616 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1619 void WebFrame::revertToProvisionalState(DocumentLoader*)
1624 void WebFrame::setMainFrameDocumentReady(bool)
1629 void WebFrame::willChangeTitle(DocumentLoader*)
1634 void WebFrame::didChangeTitle(DocumentLoader*)
1639 void WebFrame::didChangeIcons(DocumentLoader*)
1644 bool WebFrame::canHandleRequest(const ResourceRequest& request) const
1646 return WebView::canHandleRequest(request);
1649 bool WebFrame::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
1655 bool WebFrame::canShowMIMEType(const String& /*MIMEType*/) const
1661 bool WebFrame::representationExistsForURLScheme(const String& /*URLScheme*/) const
1667 String WebFrame::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const
1670 ASSERT_NOT_REACHED();
1674 void WebFrame::frameLoadCompleted()
1678 void WebFrame::restoreViewState()
1682 void WebFrame::provisionalLoadStarted()
1687 bool WebFrame::shouldTreatURLAsSameAsCurrent(const KURL&) const
1693 void WebFrame::addHistoryItemForFragmentScroll()
1698 void WebFrame::didFinishLoad()
1703 void WebFrame::prepareForDataSourceReplacement()
1708 String WebFrame::userAgent(const KURL& url)
1710 return d->webView->userAgentForKURL(url);
1713 void WebFrame::saveViewStateToItem(HistoryItem*)
1717 ResourceError WebFrame::cancelledError(const ResourceRequest& request)
1719 // FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values
1720 // Alternatively, we could create our own error domain/codes.
1721 return ResourceError(String(WebURLErrorDomain), -999, request.url().string(), String());
1724 ResourceError WebFrame::blockedError(const ResourceRequest& request)
1726 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1727 return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotUseRestrictedPort, request.url().string(), String());
1730 ResourceError WebFrame::cannotShowURLError(const ResourceRequest& request)
1732 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1733 return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotShowURL, request.url().string(), String());
1736 ResourceError WebFrame::interruptedForPolicyChangeError(const ResourceRequest& request)
1738 // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
1739 return ResourceError(String(WebKitErrorDomain), WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(), String());
1742 ResourceError WebFrame::cannotShowMIMETypeError(const ResourceResponse&)
1745 return ResourceError();
1748 ResourceError WebFrame::fileDoesNotExistError(const ResourceResponse&)
1751 return ResourceError();
1754 ResourceError WebFrame::pluginWillHandleLoadError(const ResourceResponse& response)
1756 return ResourceError(String(WebKitErrorDomain), WebKitErrorPlugInWillHandleLoad, response.url().string(), String());
1759 bool WebFrame::shouldFallBack(const ResourceError& error)
1761 if (error.errorCode() == WebURLErrorCancelled && error.domain() == String(WebURLErrorDomain))
1764 if (error.errorCode() == WebKitErrorPlugInWillHandleLoad && error.domain() == String(WebKitErrorDomain))
1770 COMPtr<WebFramePolicyListener> WebFrame::setUpPolicyListener(WebCore::FramePolicyFunction function)
1772 // FIXME: <rdar://5634381> We need to support multiple active policy listeners.
1774 if (d->m_policyListener)
1775 d->m_policyListener->invalidate();
1777 Frame* coreFrame = core(this);
1780 d->m_policyListener.adoptRef(WebFramePolicyListener::createInstance(coreFrame));
1781 d->m_policyFunction = function;
1783 return d->m_policyListener;
1786 void WebFrame::receivedPolicyDecision(PolicyAction action)
1788 ASSERT(d->m_policyListener);
1789 ASSERT(d->m_policyFunction);
1791 FramePolicyFunction function = d->m_policyFunction;
1793 d->m_policyListener = 0;
1794 d->m_policyFunction = 0;
1796 Frame* coreFrame = core(this);
1799 (coreFrame->loader()->policyChecker()->*function)(action);
1802 void WebFrame::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& request)
1804 Frame* coreFrame = core(this);
1807 COMPtr<IWebPolicyDelegate> policyDelegate;
1808 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1809 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1811 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1813 if (SUCCEEDED(policyDelegate->decidePolicyForMIMEType(d->webView, BString(response.mimeType()), urlRequest.get(), this, setUpPolicyListener(function).get())))
1816 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1819 void WebFrame::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName)
1821 Frame* coreFrame = core(this);
1824 COMPtr<IWebPolicyDelegate> policyDelegate;
1825 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1826 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1828 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1829 COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
1831 if (SUCCEEDED(policyDelegate->decidePolicyForNewWindowAction(d->webView, actionInformation.get(), urlRequest.get(), BString(frameName), setUpPolicyListener(function).get())))
1834 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1837 void WebFrame::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState)
1839 Frame* coreFrame = core(this);
1842 COMPtr<IWebPolicyDelegate> policyDelegate;
1843 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1844 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1846 COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
1847 COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
1849 if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get())))
1852 (coreFrame->loader()->policyChecker()->*function)(PolicyUse);
1855 void WebFrame::dispatchUnableToImplementPolicy(const ResourceError& error)
1857 COMPtr<IWebPolicyDelegate> policyDelegate;
1858 if (FAILED(d->webView->policyDelegate(&policyDelegate)))
1859 policyDelegate = DefaultPolicyDelegate::sharedInstance();
1861 COMPtr<IWebError> webError(AdoptCOM, WebError::createInstance(error));
1862 policyDelegate->unableToImplementPolicyWithError(d->webView, webError.get(), this);
1865 void WebFrame::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest&, const ResourceResponse& response)
1867 COMPtr<IWebDownloadDelegate> downloadDelegate;
1868 COMPtr<IWebView> webView;
1869 if (SUCCEEDED(this->webView(&webView))) {
1870 if (FAILED(webView->downloadDelegate(&downloadDelegate))) {
1871 // If the WebView doesn't successfully provide a download delegate we'll pass a null one
1872 // into the WebDownload - which may or may not decide to use a DefaultDownloadDelegate
1873 LOG_ERROR("Failed to get downloadDelegate from WebView");
1874 downloadDelegate = 0;
1878 // Its the delegate's job to ref the WebDownload to keep it alive - otherwise it will be destroyed
1879 // when this method returns
1880 COMPtr<WebDownload> download;
1881 download.adoptRef(WebDownload::createInstance(handle, request, response, downloadDelegate.get()));
1884 bool WebFrame::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
1890 void WebFrame::dispatchDidFailProvisionalLoad(const ResourceError& error)
1892 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1893 if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
1894 COMPtr<IWebError> webError;
1895 webError.adoptRef(WebError::createInstance(error));
1896 frameLoadDelegate->didFailProvisionalLoadWithError(d->webView, webError.get(), this);
1900 void WebFrame::dispatchDidFailLoad(const ResourceError& error)
1902 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1903 if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
1904 COMPtr<IWebError> webError;
1905 webError.adoptRef(WebError::createInstance(error));
1906 frameLoadDelegate->didFailLoadWithError(d->webView, webError.get(), this);
1910 void WebFrame::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
1912 d->webView->downloadURL(request.url());
1915 PassRefPtr<Widget> WebFrame::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* element, const KURL& /*baseURL*/, const Vector<String>& paramNames, const Vector<String>& paramValues)
1917 RefPtr<PluginView> pluginView = PluginView::create(core(this), pluginSize, element, KURL(), paramNames, paramValues, "application/x-java-applet", false);
1919 // Check if the plugin can be loaded successfully
1920 if (pluginView->plugin() && pluginView->plugin()->load())
1923 COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
1924 if (FAILED(d->webView->resourceLoadDelegate(&resourceLoadDelegate)))
1927 COMPtr<CFDictionaryPropertyBag> userInfoBag = CFDictionaryPropertyBag::createInstance();
1929 ResourceError resourceError(String(WebKitErrorDomain), WebKitErrorJavaUnavailable, String(), String());
1930 COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
1932 resourceLoadDelegate->plugInFailedWithError(d->webView, error.get(), getWebDataSource(d->frame->loader()->documentLoader()));
1937 ObjectContentType WebFrame::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
1939 return WebCore::FrameLoader::defaultObjectContentType(url, mimeType, shouldPreferPlugInsForImages);
1942 String WebFrame::overrideMediaType() const
1948 void WebFrame::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
1950 Frame* coreFrame = core(this);
1953 Settings* settings = coreFrame->settings();
1954 if (!settings || !settings->isJavaScriptEnabled())
1957 COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
1958 if (FAILED(d->webView->frameLoadDelegate(&frameLoadDelegate)))
1961 COMPtr<IWebFrameLoadDelegatePrivate2> delegatePrivate(Query, frameLoadDelegate);
1962 if (delegatePrivate && delegatePrivate->didClearWindowObjectForFrameInScriptWorld(d->webView, this, WebScriptWorld::findOrCreateWorld(world).get()) != E_NOTIMPL)
1965 if (world != mainThreadNormalWorld())
1968 JSContextRef context = toRef(coreFrame->script()->globalObject(world)->globalExec());
1969 JSObjectRef windowObject = toRef(coreFrame->script()->globalObject(world));
1970 ASSERT(windowObject);
1972 if (FAILED(frameLoadDelegate->didClearWindowObject(d->webView, context, windowObject, this)))
1973 frameLoadDelegate->windowScriptObjectAvailable(d->webView, context, windowObject);
1976 void WebFrame::documentElementAvailable()
1980 void WebFrame::didPerformFirstNavigation() const
1982 COMPtr<IWebPreferences> preferences;
1983 if (FAILED(d->webView->preferences(&preferences)))
1986 COMPtr<IWebPreferencesPrivate> preferencesPrivate(Query, preferences);
1987 if (!preferencesPrivate)
1989 BOOL automaticallyDetectsCacheModel;
1990 if (FAILED(preferencesPrivate->automaticallyDetectsCacheModel(&automaticallyDetectsCacheModel)))
1993 WebCacheModel cacheModel;
1994 if (FAILED(preferences->cacheModel(&cacheModel)))
1997 if (automaticallyDetectsCacheModel && cacheModel < WebCacheModelDocumentBrowser)
1998 preferences->setCacheModel(WebCacheModelDocumentBrowser);
2001 void WebFrame::registerForIconNotification(bool listen)
2003 d->webView->registerForIconNotification(listen);
2006 static IntRect printerRect(HDC printDC)
2008 return IntRect(0, 0,
2009 GetDeviceCaps(printDC, PHYSICALWIDTH) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETX),
2010 GetDeviceCaps(printDC, PHYSICALHEIGHT) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETY));
2013 void WebFrame::setPrinting(bool printing, float minPageWidth, float minPageHeight, float maximumShrinkRatio, bool adjustViewSize)
2015 Frame* coreFrame = core(this);
2017 coreFrame->setPrinting(printing, FloatSize(minPageWidth, minPageHeight), maximumShrinkRatio, adjustViewSize ? AdjustViewSize : DoNotAdjustViewSize);
2020 HRESULT STDMETHODCALLTYPE WebFrame::setInPrintingMode(
2021 /* [in] */ BOOL value,
2022 /* [in] */ HDC printDC)
2024 if (m_inPrintingMode == !!value)
2027 Frame* coreFrame = core(this);
2028 if (!coreFrame || !coreFrame->document())
2031 m_inPrintingMode = !!value;
2033 // If we are a frameset just print with the layout we have onscreen, otherwise relayout
2034 // according to the paper size
2035 FloatSize minLayoutSize(0.0, 0.0);
2036 if (m_inPrintingMode && !coreFrame->document()->isFrameSet()) {
2038 ASSERT_NOT_REACHED();
2042 const int desiredPixelsPerInch = 72;
2043 IntRect printRect = printerRect(printDC);
2044 int paperHorizontalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSX);
2045 int paperWidth = printRect.width() * desiredPixelsPerInch / paperHorizontalPixelsPerInch;
2046 int paperVerticalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSY);
2047 int paperHeight = printRect.height() * desiredPixelsPerInch / paperVerticalPixelsPerInch;
2048 Frame* coreFrame = core(this);
2049 minLayoutSize = coreFrame->resizePageRectsKeepingRatio(FloatSize(paperWidth, paperHeight), FloatSize(paperWidth * PrintingMinimumShrinkFactor, paperHeight * PrintingMinimumShrinkFactor));
2052 setPrinting(m_inPrintingMode, minLayoutSize.width(), minLayoutSize.height(), PrintingMaximumShrinkFactor / PrintingMinimumShrinkFactor, true);
2054 if (!m_inPrintingMode)
2055 m_pageRects.clear();
2060 void WebFrame::headerAndFooterHeights(float* headerHeight, float* footerHeight)
2067 COMPtr<IWebUIDelegate> ui;
2068 if (FAILED(d->webView->uiDelegate(&ui)))
2070 if (headerHeight && SUCCEEDED(ui->webViewHeaderHeight(d->webView, &height)))
2071 *headerHeight = height;
2072 if (footerHeight && SUCCEEDED(ui->webViewFooterHeight(d->webView, &height)))
2073 *footerHeight = height;
2076 IntRect WebFrame::printerMarginRect(HDC printDC)
2078 IntRect emptyRect(0, 0, 0, 0);
2080 COMPtr<IWebUIDelegate> ui;
2081 if (FAILED(d->webView->uiDelegate(&ui)))
2085 if (FAILED(ui->webViewPrintingMarginRect(d->webView, &rect)))
2088 rect.left = MulDiv(rect.left, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
2089 rect.top = MulDiv(rect.top, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
2090 rect.right = MulDiv(rect.right, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
2091 rect.bottom = MulDiv(rect.bottom, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
2093 return IntRect(rect.left, rect.top, (rect.right - rect.left), rect.bottom - rect.top);
2096 const Vector<WebCore::IntRect>& WebFrame::computePageRects(HDC printDC)
2098 ASSERT(m_inPrintingMode);
2100 Frame* coreFrame = core(this);
2102 ASSERT(coreFrame->document());
2107 // adjust the page rect by the header and footer
2108 float headerHeight = 0, footerHeight = 0;
2109 headerAndFooterHeights(&headerHeight, &footerHeight);
2110 IntRect pageRect = printerRect(printDC);
2111 IntRect marginRect = printerMarginRect(printDC);
2112 IntRect adjustedRect = IntRect(
2113 pageRect.x() + marginRect.x(),
2114 pageRect.y() + marginRect.y(),
2115 pageRect.width() - marginRect.x() - marginRect.maxX(),
2116 pageRect.height() - marginRect.y() - marginRect.maxY());
2118 computePageRectsForFrame(coreFrame, adjustedRect, headerHeight, footerHeight, 1.0,m_pageRects, m_pageHeight);
2123 HRESULT STDMETHODCALLTYPE WebFrame::getPrintedPageCount(
2124 /* [in] */ HDC printDC,
2125 /* [retval][out] */ UINT *pageCount)
2127 if (!pageCount || !printDC) {
2128 ASSERT_NOT_REACHED();
2134 if (!m_inPrintingMode) {
2135 ASSERT_NOT_REACHED();
2139 Frame* coreFrame = core(this);
2140 if (!coreFrame || !coreFrame->document())
2143 const Vector<IntRect>& pages = computePageRects(printDC);
2144 *pageCount = (UINT) pages.size();
2150 void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
2152 int x = pageRect.x();
2154 RECT headerRect = {x, y, x+pageRect.width(), y+static_cast<int>(headerHeight)};
2155 ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)));
2158 void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
2160 int x = pageRect.x();
2161 int y = max((int)headerHeight+pageRect.height(), m_pageHeight-static_cast<int>(footerHeight));
2162 RECT footerRect = {x, y, x+pageRect.width(), y+static_cast<int>(footerHeight)};
2163 ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)), page+1, pageCount);
2166 void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
2168 Frame* coreFrame = core(this);
2170 IntRect pageRect = m_pageRects[page];
2172 CGContextSaveGState(pctx);
2174 IntRect printRect = printerRect(printDC);
2175 CGRect mediaBox = CGRectMake(CGFloat(0),
2177 CGFloat(printRect.width()),
2178 CGFloat(printRect.height()));
2180 CGContextBeginPage(pctx, &mediaBox);
2182 CGFloat scale = static_cast<float>(mediaBox.size.width)/static_cast<float>(pageRect.width());
2183 CGAffineTransform ctm = CGContextGetBaseCTM(pctx);
2184 ctm = CGAffineTransformScale(ctm, -scale, -scale);
2185 ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
2186 CGContextScaleCTM(pctx, scale, scale);
2187 CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
2188 CGContextSetBaseCTM(pctx, ctm);
2190 coreFrame->view()->paintContents(spoolCtx, pageRect);
2192 CGContextTranslateCTM(pctx, CGFloat(pageRect.x()), CGFloat(pageRect.y())-headerHeight);
2195 drawHeader(pctx, ui, pageRect, headerHeight);
2198 drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
2200 CGContextEndPage(pctx);
2201 CGContextRestoreGState(pctx);
2204 static float scaleFactor(HDC printDC, const IntRect& marginRect, const IntRect& pageRect)
2206 const IntRect& printRect = printerRect(printDC);
2208 IntRect adjustedRect = IntRect(
2209 printRect.x() + marginRect.x(),
2210 printRect.y() + marginRect.y(),
2211 printRect.width() - marginRect.x() - marginRect.maxX(),
2212 printRect.height() - marginRect.y() - marginRect.maxY());
2214 float scale = static_cast<float>(adjustedRect.width()) / static_cast<float>(pageRect.width());
2221 static HDC hdcFromContext(PlatformGraphicsContext* pctx)
2223 return cairo_win32_surface_get_dc(cairo_get_target(pctx->cr()));
2226 void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
2228 HDC hdc = hdcFromContext(pctx);
2230 int x = pageRect.x();
2232 RECT headerRect = {x, y, x + pageRect.width(), y + static_cast<int>(headerHeight)};
2234 ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)));
2237 void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
2239 HDC hdc = hdcFromContext(pctx);
2241 int x = pageRect.x();
2242 int y = max(static_cast<int>(headerHeight) + pageRect.height(), m_pageHeight -static_cast<int>(footerHeight));
2243 RECT footerRect = {x, y, x + pageRect.width(), y + static_cast<int>(footerHeight)};
2245 ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)), page+1, pageCount);
2248 static XFORM buildXFORMFromCairo(HDC targetDC, cairo_t* previewContext)
2251 GetWorldTransform(targetDC, &scaled);
2254 cairo_get_matrix(previewContext, &ctm);
2256 // Scale to the preview screen bounds
2257 scaled.eM11 = ctm.xx;
2258 scaled.eM22 = ctm.yy;
2263 void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
2265 Frame* coreFrame = core(this);
2267 const IntRect& pageRect = m_pageRects[page];
2268 const IntRect& marginRect = printerMarginRect(printDC);
2270 // In preview, the printDC is a placeholder, so just always use the HDC backing the graphics context.
2271 HDC hdc = hdcFromContext(pctx);
2275 XFORM original, scaled;
2276 GetWorldTransform(hdc, &original);
2278 cairo_t* cr = pctx->cr();
2279 bool preview = (hdc != printDC);
2281 // If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo will
2282 // draw correctly. We need to retain the correct preview scale here for use when the Cairo
2283 // drawing completes so that we can scale our GDI-based header/footer calls. This is a
2284 // workaround for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2285 scaled = buildXFORMFromCairo(hdc, cr);
2288 float scale = scaleFactor(printDC, marginRect, pageRect);
2290 IntRect cairoMarginRect(marginRect);
2291 cairoMarginRect.scale(1 / scale);
2293 // We cannot scale the display HDC because the print surface also scales fonts,
2294 // resulting in invalid printing (and print preview)
2295 cairo_scale(cr, scale, scale);
2296 cairo_translate(cr, cairoMarginRect.x(), cairoMarginRect.y() + headerHeight);
2298 // Modify Cairo (only) to account for page position.
2299 cairo_translate(cr, -pageRect.x(), -pageRect.y());
2300 coreFrame->view()->paintContents(spoolCtx, pageRect);
2301 cairo_translate(cr, pageRect.x(), pageRect.y());
2304 // If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo would
2305 // draw correctly. We need to rescale the HDC to the correct preview scale so our GDI-based
2306 // header/footer calls will draw properly. This is a workaround for a bug in Cairo.
2307 // (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2308 SetWorldTransform(hdc, &scaled);
2311 XFORM xform = TransformationMatrix().translate(marginRect.x(), marginRect.y()).scale(scale);
2312 ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
2315 drawHeader(pctx, ui, pageRect, headerHeight);
2318 drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
2320 SetWorldTransform(hdc, &original);
2322 cairo_show_page(cr);
2323 ASSERT(!cairo_status(cr));
2324 spoolCtx->restore();
2327 static void setCairoTransformToPreviewHDC(cairo_t* previewCtx, HDC previewDC)
2330 GetWorldTransform(previewDC, &passedCTM);
2332 // Reset HDC WorldTransform to unscaled state. Scaling must be
2333 // done in Cairo to avoid drawing errors.
2334 XFORM unscaledCTM = passedCTM;
2335 unscaledCTM.eM11 = 1.0;
2336 unscaledCTM.eM22 = 1.0;
2338 SetWorldTransform(previewDC, &unscaledCTM);
2340 // Make the Cairo transform match the information passed to WebKit
2341 // in the HDC's WorldTransform.
2342 cairo_matrix_t ctm = { passedCTM.eM11, passedCTM.eM12, passedCTM.eM21,
2343 passedCTM.eM22, passedCTM.eDx, passedCTM.eDy };
2345 cairo_set_matrix(previewCtx, &ctm);
2350 HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(
2351 /* [in] */ HDC printDC,
2352 /* [in] */ UINT startPage,
2353 /* [in] */ UINT endPage,
2354 /* [retval][out] */ void* ctx)
2357 if (!printDC || !ctx) {
2358 ASSERT_NOT_REACHED();
2363 ASSERT_NOT_REACHED();
2367 HDC targetDC = (ctx) ? (HDC)ctx : printDC;
2369 cairo_surface_t* printSurface = 0;
2371 printSurface = cairo_win32_surface_create(targetDC); // in-memory
2373 printSurface = cairo_win32_printing_surface_create(targetDC); // metafile
2375 cairo_t* cr = cairo_create(printSurface);
2377 cairo_surface_destroy(printSurface);
2381 PlatformContextCairo platformContext(cr);
2382 PlatformGraphicsContext* pctx = &platformContext;
2386 // If this is a preview, the Windows HDC was sent with scaling information.
2387 // Retrieve it and reset it so that it draws properly. This is a workaround
2388 // for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
2389 setCairoTransformToPreviewHDC(cr, targetDC);
2392 cairo_surface_set_fallback_resolution(printSurface, 72.0, 72.0);
2395 if (!m_inPrintingMode) {
2396 ASSERT_NOT_REACHED();
2400 Frame* coreFrame = core(this);
2401 if (!coreFrame || !coreFrame->document())
2404 UINT pageCount = (UINT) m_pageRects.size();
2406 PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)ctx;
2409 if (!pageCount || startPage > pageCount) {
2410 ASSERT_NOT_REACHED();
2418 endPage = pageCount;
2420 COMPtr<IWebUIDelegate> ui;
2421 if (FAILED(d->webView->uiDelegate(&ui)))
2424 float headerHeight = 0, footerHeight = 0;
2425 headerAndFooterHeights(&headerHeight, &footerHeight);
2426 GraphicsContext spoolCtx(pctx);
2427 spoolCtx.setShouldIncludeChildWindows(true);
2429 for (UINT ii = startPage; ii < endPage; ii++)
2430 spoolPage(pctx, &spoolCtx, printDC, ui.get(), headerHeight, footerHeight, ii, pageCount);
2433 cairo_surface_finish(printSurface);
2434 ASSERT(!cairo_surface_status(printSurface));
2435 cairo_surface_destroy(printSurface);
2441 HRESULT STDMETHODCALLTYPE WebFrame::isFrameSet(
2442 /* [retval][out] */ BOOL* result)
2446 Frame* coreFrame = core(this);
2447 if (!coreFrame || !coreFrame->document())
2450 *result = coreFrame->document()->isFrameSet() ? TRUE : FALSE;
2454 HRESULT STDMETHODCALLTYPE WebFrame::string(
2455 /* [retval][out] */ BSTR *result)
2459 Frame* coreFrame = core(this);
2463 RefPtr<Range> allRange(rangeOfContents(coreFrame->document()));
2464 String allString = plainText(allRange.get());
2465 *result = BString(allString).release();
2469 HRESULT STDMETHODCALLTYPE WebFrame::size(
2470 /* [retval][out] */ SIZE *size)
2474 size->cx = size->cy = 0;
2476 Frame* coreFrame = core(this);
2479 FrameView* view = coreFrame->view();
2482 size->cx = view->width();
2483 size->cy = view->height();
2487 HRESULT STDMETHODCALLTYPE WebFrame::hasScrollBars(
2488 /* [retval][out] */ BOOL *result)
2494 Frame* coreFrame = core(this);
2498 FrameView* view = coreFrame->view();
2502 if (view->horizontalScrollbar() || view->verticalScrollbar())
2508 HRESULT STDMETHODCALLTYPE WebFrame::contentBounds(
2509 /* [retval][out] */ RECT *result)
2513 ::SetRectEmpty(result);
2515 Frame* coreFrame = core(this);
2519 FrameView* view = coreFrame->view();
2523 result->bottom = view->contentsHeight();
2524 result->right = view->contentsWidth();
2528 HRESULT STDMETHODCALLTYPE WebFrame::frameBounds(
2529 /* [retval][out] */ RECT *result)
2533 ::SetRectEmpty(result);
2535 Frame* coreFrame = core(this);
2539 FrameView* view = coreFrame->view();
2543 FloatRect bounds = view->visibleContentRect(true);
2544 result->bottom = (LONG) bounds.height();
2545 result->right = (LONG) bounds.width();
2549 HRESULT STDMETHODCALLTYPE WebFrame::isDescendantOfFrame(
2550 /* [in] */ IWebFrame *ancestor,
2551 /* [retval][out] */ BOOL *result)
2557 Frame* coreFrame = core(this);
2558 COMPtr<WebFrame> ancestorWebFrame(Query, ancestor);
2559 if (!ancestorWebFrame)
2562 *result = (coreFrame && coreFrame->tree()->isDescendantOf(core(ancestorWebFrame.get()))) ? TRUE : FALSE;
2566 HRESULT WebFrame::stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld* iWorld, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult)
2568 if (!evaluationResult)
2570 *evaluationResult = 0;
2575 COMPtr<WebScriptWorld> world(Query, iWorld);
2577 return E_INVALIDARG;
2579 Frame* coreFrame = core(this);
2580 String string = String(script, SysStringLen(script));
2582 // Start off with some guess at a frame and a global object, we'll try to do better...!
2583 JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld());
2585 // The global object is probably a shell object? - if so, we know how to use this!
2586 JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
2587 if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
2588 anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
2590 // Get the frame frome the global object we've settled on.
2591 Frame* frame = anyWorldGlobalObject->impl()->frame();
2592 ASSERT(frame->document());
2593 JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue();
2595 if (!frame) // In case the script removed our frame from the page.
2598 // This bizarre set of rules matches behavior from WebKit for Safari 2.0.
2599 // If you don't like it, use -[WebScriptObject evaluateWebScript:] or
2600 // JSEvaluateScript instead, since they have less surprising semantics.
2601 if (!result || !result.isBoolean() && !result.isString() && !result.isNumber())
2604 JSLock lock(SilenceAssertionsOnly);
2605 String resultString = ustringToString(result.toString(anyWorldGlobalObject->globalExec()));
2606 *evaluationResult = BString(resultString).release();
2611 void WebFrame::unmarkAllMisspellings()
2613 Frame* coreFrame = core(this);
2614 for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
2615 Document *doc = frame->document();
2619 doc->markers()->removeMarkers(DocumentMarker::Spelling);
2623 void WebFrame::unmarkAllBadGrammar()
2625 Frame* coreFrame = core(this);
2626 for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
2627 Document *doc = frame->document();
2631 doc->markers()->removeMarkers(DocumentMarker::Grammar);
2635 WebView* WebFrame::webView() const
2640 void WebFrame::setWebView(WebView* webView)
2642 d->webView = webView;
2645 COMPtr<IAccessible> WebFrame::accessible() const
2647 Frame* coreFrame = core(this);
2650 Document* currentDocument = coreFrame->document();
2651 if (!currentDocument)
2653 else if (!m_accessible || m_accessible->document() != currentDocument) {
2654 // Either we've never had a wrapper for this frame's top-level Document,
2655 // the Document renderer was destroyed and its wrapper was detached, or
2656 // the previous Document is in the page cache, and the current document
2657 // needs to be wrapped.
2658 m_accessible = new AccessibleDocument(currentDocument);
2660 return m_accessible.get();
2663 void WebFrame::updateBackground()
2665 Color backgroundColor = webView()->transparent() ? Color::transparent : Color::white;
2666 Frame* coreFrame = core(this);
2668 if (!coreFrame || !coreFrame->view())
2671 coreFrame->view()->updateBackgroundRecursively(backgroundColor, webView()->transparent());
2674 PassRefPtr<FrameNetworkingContext> WebFrame::createNetworkingContext()
2676 return WebFrameNetworkingContext::create(core(this), userAgent(url()));