2 * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "WebFrameLoaderClient.h"
32 #include "WebDataSource.h"
34 #include "AccessibleDocument.h"
36 #include <WebCore/AdjustViewSizeOrNot.h>
37 #include <WebCore/FrameWin.h>
38 #include <WebCore/GraphicsContext.h>
39 #include <WebCore/KURL.h>
40 #include <WebCore/PlatformString.h>
41 #include <WebCore/ResourceHandleClient.h>
43 #include <WTF/RefPtr.h>
44 #include <WTF/HashMap.h>
45 #include <WTF/OwnPtr.h>
48 class AuthenticationChallenge;
53 class GraphicsContext;
54 class HTMLFrameOwnerElement;
61 typedef const struct OpaqueJSContext* JSContextRef;
62 typedef struct OpaqueJSValue* JSObjectRef;
65 typedef struct CGContext PlatformGraphicsContext;
68 class PlatformContextCairo;
70 typedef class WebCore::PlatformContextCairo PlatformGraphicsContext;
74 class WebFramePolicyListener;
78 interface IWebHistoryItemPrivate;
80 WebFrame* kit(WebCore::Frame*);
81 WebCore::Frame* core(WebFrame*);
83 class DECLSPEC_UUID("{A3676398-4485-4a9d-87DC-CB5A40E6351D}") WebFrame : public IWebFrame, IWebFramePrivate, IWebDocumentText
84 , public WebFrameLoaderClient
87 static WebFrame* createInstance();
94 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
95 virtual ULONG STDMETHODCALLTYPE AddRef(void);
96 virtual ULONG STDMETHODCALLTYPE Release(void);
99 virtual HRESULT STDMETHODCALLTYPE name(
100 /* [retval][out] */ BSTR *frameName);
102 virtual HRESULT STDMETHODCALLTYPE webView(
103 /* [retval][out] */ IWebView **view);
105 virtual HRESULT STDMETHODCALLTYPE frameView(
106 /* [retval][out] */ IWebFrameView **view);
108 virtual HRESULT STDMETHODCALLTYPE DOMDocument(
109 /* [retval][out] */ IDOMDocument** document);
111 virtual HRESULT STDMETHODCALLTYPE DOMWindow(/* [retval][out] */ IDOMWindow**);
113 virtual HRESULT STDMETHODCALLTYPE frameElement(
114 /* [retval][out] */ IDOMHTMLElement **frameElement);
116 virtual HRESULT STDMETHODCALLTYPE loadRequest(
117 /* [in] */ IWebURLRequest *request);
119 virtual HRESULT STDMETHODCALLTYPE loadData(
120 /* [in] */ IStream *data,
121 /* [in] */ BSTR mimeType,
122 /* [in] */ BSTR textEncodingName,
123 /* [in] */ BSTR url);
125 virtual HRESULT STDMETHODCALLTYPE loadHTMLString(
126 /* [in] */ BSTR string,
127 /* [in] */ BSTR baseURL);
129 virtual HRESULT STDMETHODCALLTYPE loadAlternateHTMLString(
131 /* [in] */ BSTR baseURL,
132 /* [in] */ BSTR unreachableURL);
134 virtual HRESULT STDMETHODCALLTYPE loadArchive(
135 /* [in] */ IWebArchive *archive);
137 virtual HRESULT STDMETHODCALLTYPE dataSource(
138 /* [retval][out] */ IWebDataSource **source);
140 virtual HRESULT STDMETHODCALLTYPE provisionalDataSource(
141 /* [retval][out] */ IWebDataSource **source);
143 virtual HRESULT STDMETHODCALLTYPE stopLoading( void);
145 virtual HRESULT STDMETHODCALLTYPE reload( void);
147 virtual HRESULT STDMETHODCALLTYPE findFrameNamed(
148 /* [in] */ BSTR name,
149 /* [retval][out] */ IWebFrame **frame);
151 virtual HRESULT STDMETHODCALLTYPE parentFrame(
152 /* [retval][out] */ IWebFrame **frame);
154 virtual HRESULT STDMETHODCALLTYPE childFrames(
155 /* [retval][out] */ IEnumVARIANT **enumFrames);
157 virtual HRESULT STDMETHODCALLTYPE currentForm(
158 /* [retval][out] */ IDOMElement **formElement);
160 virtual /* [local] */ JSGlobalContextRef STDMETHODCALLTYPE globalContext();
163 virtual HRESULT STDMETHODCALLTYPE unused1(BSTR*) { return E_NOTIMPL; }
164 virtual HRESULT STDMETHODCALLTYPE renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result);
166 virtual HRESULT STDMETHODCALLTYPE pageNumberForElementById(
168 /* [in] */ float pageWidthInPixels,
169 /* [in] */ float pageHeightInPixels,
170 /* [retval][out] */ int* result);
172 virtual HRESULT STDMETHODCALLTYPE numberOfPages(
173 /* [in] */ float pageWidthInPixels,
174 /* [in] */ float pageHeightInPixels,
175 /* [retval][out] */ int* result);
177 virtual HRESULT STDMETHODCALLTYPE scrollOffset(
178 /* [retval][out] */ SIZE* offset);
180 virtual HRESULT STDMETHODCALLTYPE layout();
182 virtual HRESULT STDMETHODCALLTYPE firstLayoutDone(
183 /* [retval][out] */ BOOL* result);
185 virtual HRESULT STDMETHODCALLTYPE loadType(
186 /* [retval][out] */ WebFrameLoadType* type);
188 virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount(
189 /* [retval][out] */ UINT* result);
191 virtual HRESULT STDMETHODCALLTYPE unused2();
193 virtual HRESULT STDMETHODCALLTYPE setInPrintingMode(
194 /* [in] */ BOOL value,
195 /* [in] */ HDC printDC);
197 virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount(
198 /* [in] */ HDC printDC,
199 /* [retval][out] */ UINT *pageCount);
201 virtual HRESULT STDMETHODCALLTYPE spoolPages(
202 /* [in] */ HDC printDC,
203 /* [in] */ UINT startPage,
204 /* [in] */ UINT endPage,
205 /* [retval][out] */ void* ctx);
207 virtual HRESULT STDMETHODCALLTYPE isFrameSet(
208 /* [retval][out] */ BOOL* result);
210 virtual HRESULT STDMETHODCALLTYPE string(
211 /* [retval][out] */ BSTR* result);
213 virtual HRESULT STDMETHODCALLTYPE size(
214 /* [retval][out] */ SIZE *size);
216 virtual HRESULT STDMETHODCALLTYPE hasScrollBars(
217 /* [retval][out] */ BOOL *result);
219 virtual HRESULT STDMETHODCALLTYPE contentBounds(
220 /* [retval][out] */ RECT *result);
222 virtual HRESULT STDMETHODCALLTYPE frameBounds(
223 /* [retval][out] */ RECT *result);
225 virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame(
226 /* [in] */ IWebFrame *ancestor,
227 /* [retval][out] */ BOOL *result);
229 virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling(
230 /* [in] */ BOOL flag);
232 virtual HRESULT STDMETHODCALLTYPE allowsScrolling(
233 /* [retval][out] */ BOOL *flag);
235 virtual HRESULT STDMETHODCALLTYPE setIsDisconnected(
236 /* [in] */ BOOL flag);
238 virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch(
239 /* [in] */ BOOL flag);
241 virtual HRESULT STDMETHODCALLTYPE reloadFromOrigin();
243 virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext(
244 /* [in] */ RECT rect,
245 /* [in] */ OLE_HANDLE deviceContext);
247 virtual HRESULT STDMETHODCALLTYPE paintScrollViewRectToContextAtPoint(
248 /* [in] */ RECT rect,
250 /* [in] */ OLE_HANDLE deviceContext);
252 virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete(
253 /* [in] */ IDOMElement* element,
254 /* [retval][out] */ BOOL* result);
256 virtual HRESULT STDMETHODCALLTYPE pauseAnimation(BSTR animationName, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning);
257 virtual HRESULT STDMETHODCALLTYPE pauseTransition(BSTR propertyName, IDOMNode*, double secondsFromNow, BOOL* transitionWasRunning);
258 virtual HRESULT STDMETHODCALLTYPE numberOfActiveAnimations(UINT*);
259 virtual HRESULT STDMETHODCALLTYPE loadPlainTextString(BSTR string, BSTR url);
261 virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*);
263 virtual HRESULT STDMETHODCALLTYPE allowsFollowingLink(
265 /* [retval][out] */ BOOL* result);
267 virtual HRESULT STDMETHODCALLTYPE stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld*, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult);
268 virtual JSGlobalContextRef STDMETHODCALLTYPE globalContextForScriptWorld(IWebScriptWorld*);
270 virtual HRESULT STDMETHODCALLTYPE visibleContentRect(RECT*);
272 virtual HRESULT STDMETHODCALLTYPE layerTreeAsText(BSTR*);
274 virtual HRESULT STDMETHODCALLTYPE hasSpellingMarker(
275 /* [in] */ UINT from,
276 /* [in] */ UINT length,
277 /* [retval][out] */ BOOL *result);
279 virtual HRESULT STDMETHODCALLTYPE clearOpener();
281 virtual HRESULT STDMETHODCALLTYPE setTextDirection(BSTR);
283 virtual HRESULT STDMETHODCALLTYPE unused3(BSTR, BSTR*) { return E_NOTIMPL; }
285 virtual HRESULT STDMETHODCALLTYPE resumeAnimations();
287 virtual HRESULT STDMETHODCALLTYPE suspendAnimations();
290 virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding(
291 /* [retval][out] */ BOOL* result);
293 virtual HRESULT STDMETHODCALLTYPE selectedString(
294 /* [retval][out] */ BSTR* result);
296 virtual HRESULT STDMETHODCALLTYPE selectAll();
298 virtual HRESULT STDMETHODCALLTYPE deselectAll();
301 virtual void frameLoaderDestroyed();
302 virtual void makeRepresentation(WebCore::DocumentLoader*);
303 virtual void forceLayoutForNonHTML();
304 virtual void setCopiesOnScroll();
305 virtual void detachedFromParent2();
306 virtual void detachedFromParent3();
307 virtual void cancelPolicyCheck();
308 virtual void dispatchWillSendSubmitEvent(PassRefPtr<WebCore::FormState>);
309 virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
310 virtual void revertToProvisionalState(WebCore::DocumentLoader*);
311 virtual void setMainFrameDocumentReady(bool);
312 virtual void willChangeTitle(WebCore::DocumentLoader*);
313 virtual void didChangeTitle(WebCore::DocumentLoader*);
314 virtual void didChangeIcons(WebCore::DocumentLoader*);
315 virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
316 virtual bool canShowMIMEType(const WTF::String& MIMEType) const;
317 virtual bool canShowMIMETypeAsHTML(const WTF::String& MIMEType) const;
318 virtual bool representationExistsForURLScheme(const WTF::String& URLScheme) const;
319 virtual WTF::String generatedMIMETypeForURLScheme(const WTF::String& URLScheme) const;
320 virtual void frameLoadCompleted();
321 virtual void restoreViewState();
322 virtual void provisionalLoadStarted();
323 virtual bool shouldTreatURLAsSameAsCurrent(const WebCore::KURL&) const;
324 virtual void addHistoryItemForFragmentScroll();
325 virtual void didFinishLoad();
326 virtual void prepareForDataSourceReplacement();
327 virtual WTF::String userAgent(const WebCore::KURL&);
328 virtual void saveViewStateToItem(WebCore::HistoryItem *);
329 virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
330 virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
331 virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
332 virtual WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&);
333 virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
334 virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
335 virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&);
336 virtual bool shouldFallBack(const WebCore::ResourceError&);
337 virtual void dispatchDecidePolicyForResponse(WebCore::FramePolicyFunction, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&);
338 virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>, const WTF::String& frameName);
339 virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>);
340 virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
341 virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
343 virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length);
344 virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&);
345 virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
346 virtual void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String());
348 virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement*, const WebCore::KURL& baseURL, const Vector<WTF::String>& paramNames, const Vector<WTF::String>& paramValues);
350 virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL&, const WTF::String& mimeType, bool shouldPreferPlugInsForImages);
351 virtual WTF::String overrideMediaType() const;
353 virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*);
354 virtual void documentElementAvailable();
355 virtual void didPerformFirstNavigation() const;
357 virtual void registerForIconNotification(bool listen);
359 virtual PassRefPtr<WebCore::FrameNetworkingContext> createNetworkingContext();
362 PassRefPtr<WebCore::Frame> init(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*);
363 WebCore::Frame* impl();
365 void unmarkAllMisspellings();
366 void unmarkAllBadGrammar();
368 void updateBackground();
370 // WebFrame (matching WebCoreFrameBridge)
371 HRESULT inViewSourceMode(BOOL *flag);
372 HRESULT setInViewSourceMode(BOOL flag);
373 HRESULT elementWithName(BSTR name, IDOMElement* form, IDOMElement** element);
374 HRESULT formForElement(IDOMElement* element, IDOMElement** form);
375 HRESULT controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls);
376 HRESULT elementIsPassword(IDOMElement* element, bool* result);
377 HRESULT searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* resultDistance, BOOL* resultIsInCellAbove, BSTR* result);
378 HRESULT matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result);
379 HRESULT canProvideDocumentSource(bool* result);
381 COMPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction function);
382 void receivedPolicyDecision(WebCore::PolicyAction);
384 WebCore::KURL url() const;
386 WebView* webView() const;
387 void setWebView(WebView*);
389 COMPtr<IAccessible> accessible() const;
392 void loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL);
393 void loadData(PassRefPtr<WebCore::SharedBuffer>, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL);
394 const Vector<WebCore::IntRect>& computePageRects(HDC printDC);
395 void setPrinting(bool printing, const WebCore::FloatSize& pageSize, const WebCore::FloatSize& originalPageSize, float maximumShrinkRatio, WebCore::AdjustViewSizeOrNot);
396 void headerAndFooterHeights(float*, float*);
397 WebCore::IntRect printerMarginRect(HDC);
398 void spoolPage (PlatformGraphicsContext* pctx, WebCore::GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate*, float headerHeight, float footerHeight, UINT page, UINT pageCount);
399 void drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, float headerHeight);
400 void drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight);
404 class WebFramePrivate;
406 bool m_quickRedirectComing;
407 WebCore::KURL m_originalRequestURL;
408 bool m_inPrintingMode;
409 Vector<WebCore::IntRect> m_pageRects;
410 int m_pageHeight; // height of the page adjusted by margins
411 mutable COMPtr<AccessibleDocument> m_accessible;