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/FrameWin.h>
37 #include <WebCore/GraphicsContext.h>
38 #include <WebCore/KURL.h>
39 #include <WebCore/PlatformString.h>
40 #include <WebCore/ResourceHandleClient.h>
42 #include <WTF/RefPtr.h>
43 #include <WTF/HashMap.h>
44 #include <WTF/OwnPtr.h>
47 class AuthenticationChallenge;
51 class GraphicsContext;
52 class HTMLFrameOwnerElement;
59 typedef const struct OpaqueJSContext* JSContextRef;
60 typedef struct OpaqueJSValue* JSObjectRef;
63 typedef struct CGContext PlatformGraphicsContext;
66 class PlatformContextCairo;
68 typedef class WebCore::PlatformContextCairo PlatformGraphicsContext;
72 class WebFramePolicyListener;
76 interface IWebHistoryItemPrivate;
78 WebFrame* kit(WebCore::Frame*);
79 WebCore::Frame* core(WebFrame*);
81 class DECLSPEC_UUID("{A3676398-4485-4a9d-87DC-CB5A40E6351D}") WebFrame : public IWebFrame, IWebFramePrivate, IWebDocumentText
82 , public WebFrameLoaderClient
85 static WebFrame* createInstance();
92 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
93 virtual ULONG STDMETHODCALLTYPE AddRef(void);
94 virtual ULONG STDMETHODCALLTYPE Release(void);
97 virtual HRESULT STDMETHODCALLTYPE name(
98 /* [retval][out] */ BSTR *frameName);
100 virtual HRESULT STDMETHODCALLTYPE webView(
101 /* [retval][out] */ IWebView **view);
103 virtual HRESULT STDMETHODCALLTYPE frameView(
104 /* [retval][out] */ IWebFrameView **view);
106 virtual HRESULT STDMETHODCALLTYPE DOMDocument(
107 /* [retval][out] */ IDOMDocument** document);
109 virtual HRESULT STDMETHODCALLTYPE DOMWindow(/* [retval][out] */ IDOMWindow**);
111 virtual HRESULT STDMETHODCALLTYPE frameElement(
112 /* [retval][out] */ IDOMHTMLElement **frameElement);
114 virtual HRESULT STDMETHODCALLTYPE loadRequest(
115 /* [in] */ IWebURLRequest *request);
117 virtual HRESULT STDMETHODCALLTYPE loadData(
118 /* [in] */ IStream *data,
119 /* [in] */ BSTR mimeType,
120 /* [in] */ BSTR textEncodingName,
121 /* [in] */ BSTR url);
123 virtual HRESULT STDMETHODCALLTYPE loadHTMLString(
124 /* [in] */ BSTR string,
125 /* [in] */ BSTR baseURL);
127 virtual HRESULT STDMETHODCALLTYPE loadAlternateHTMLString(
129 /* [in] */ BSTR baseURL,
130 /* [in] */ BSTR unreachableURL);
132 virtual HRESULT STDMETHODCALLTYPE loadArchive(
133 /* [in] */ IWebArchive *archive);
135 virtual HRESULT STDMETHODCALLTYPE dataSource(
136 /* [retval][out] */ IWebDataSource **source);
138 virtual HRESULT STDMETHODCALLTYPE provisionalDataSource(
139 /* [retval][out] */ IWebDataSource **source);
141 virtual HRESULT STDMETHODCALLTYPE stopLoading( void);
143 virtual HRESULT STDMETHODCALLTYPE reload( void);
145 virtual HRESULT STDMETHODCALLTYPE findFrameNamed(
146 /* [in] */ BSTR name,
147 /* [retval][out] */ IWebFrame **frame);
149 virtual HRESULT STDMETHODCALLTYPE parentFrame(
150 /* [retval][out] */ IWebFrame **frame);
152 virtual HRESULT STDMETHODCALLTYPE childFrames(
153 /* [retval][out] */ IEnumVARIANT **enumFrames);
155 virtual HRESULT STDMETHODCALLTYPE currentForm(
156 /* [retval][out] */ IDOMElement **formElement);
158 virtual /* [local] */ JSGlobalContextRef STDMETHODCALLTYPE globalContext();
161 virtual HRESULT STDMETHODCALLTYPE unused1(BSTR*) { return E_NOTIMPL; }
162 virtual HRESULT STDMETHODCALLTYPE renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result);
164 virtual HRESULT STDMETHODCALLTYPE counterValueForElementById(
166 /* [retval][out] */ BSTR *result);
168 virtual HRESULT STDMETHODCALLTYPE pageNumberForElementById(
170 /* [in] */ float pageWidthInPixels,
171 /* [in] */ float pageHeightInPixels,
172 /* [retval][out] */ int* result);
174 virtual HRESULT STDMETHODCALLTYPE numberOfPages(
175 /* [in] */ float pageWidthInPixels,
176 /* [in] */ float pageHeightInPixels,
177 /* [retval][out] */ int* result);
179 virtual HRESULT STDMETHODCALLTYPE scrollOffset(
180 /* [retval][out] */ SIZE* offset);
182 virtual HRESULT STDMETHODCALLTYPE layout();
184 virtual HRESULT STDMETHODCALLTYPE firstLayoutDone(
185 /* [retval][out] */ BOOL* result);
187 virtual HRESULT STDMETHODCALLTYPE loadType(
188 /* [retval][out] */ WebFrameLoadType* type);
190 virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount(
191 /* [retval][out] */ UINT* result);
193 virtual HRESULT STDMETHODCALLTYPE unused2();
195 virtual HRESULT STDMETHODCALLTYPE setInPrintingMode(
196 /* [in] */ BOOL value,
197 /* [in] */ HDC printDC);
199 virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount(
200 /* [in] */ HDC printDC,
201 /* [retval][out] */ UINT *pageCount);
203 virtual HRESULT STDMETHODCALLTYPE spoolPages(
204 /* [in] */ HDC printDC,
205 /* [in] */ UINT startPage,
206 /* [in] */ UINT endPage,
207 /* [retval][out] */ void* ctx);
209 virtual HRESULT STDMETHODCALLTYPE isFrameSet(
210 /* [retval][out] */ BOOL* result);
212 virtual HRESULT STDMETHODCALLTYPE string(
213 /* [retval][out] */ BSTR* result);
215 virtual HRESULT STDMETHODCALLTYPE size(
216 /* [retval][out] */ SIZE *size);
218 virtual HRESULT STDMETHODCALLTYPE hasScrollBars(
219 /* [retval][out] */ BOOL *result);
221 virtual HRESULT STDMETHODCALLTYPE contentBounds(
222 /* [retval][out] */ RECT *result);
224 virtual HRESULT STDMETHODCALLTYPE frameBounds(
225 /* [retval][out] */ RECT *result);
227 virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame(
228 /* [in] */ IWebFrame *ancestor,
229 /* [retval][out] */ BOOL *result);
231 virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling(
232 /* [in] */ BOOL flag);
234 virtual HRESULT STDMETHODCALLTYPE allowsScrolling(
235 /* [retval][out] */ BOOL *flag);
237 virtual HRESULT STDMETHODCALLTYPE setIsDisconnected(
238 /* [in] */ BOOL flag);
240 virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch(
241 /* [in] */ BOOL flag);
243 virtual HRESULT STDMETHODCALLTYPE reloadFromOrigin();
245 virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext(
246 /* [in] */ RECT rect,
247 /* [in] */ OLE_HANDLE deviceContext);
249 virtual HRESULT STDMETHODCALLTYPE paintScrollViewRectToContextAtPoint(
250 /* [in] */ RECT rect,
252 /* [in] */ OLE_HANDLE deviceContext);
254 virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete(
255 /* [in] */ IDOMElement* element,
256 /* [retval][out] */ BOOL* result);
258 virtual HRESULT STDMETHODCALLTYPE pauseAnimation(BSTR animationName, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning);
259 virtual HRESULT STDMETHODCALLTYPE pauseTransition(BSTR propertyName, IDOMNode*, double secondsFromNow, BOOL* transitionWasRunning);
260 virtual HRESULT STDMETHODCALLTYPE pauseSVGAnimation(BSTR elementId, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning);
261 virtual HRESULT STDMETHODCALLTYPE numberOfActiveAnimations(UINT*);
262 virtual HRESULT STDMETHODCALLTYPE suspendAnimations();
263 virtual HRESULT STDMETHODCALLTYPE resumeAnimations();
264 virtual HRESULT STDMETHODCALLTYPE loadPlainTextString(BSTR string, BSTR url);
266 virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*);
268 virtual HRESULT STDMETHODCALLTYPE allowsFollowingLink(
270 /* [retval][out] */ BOOL* result);
272 virtual HRESULT STDMETHODCALLTYPE stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld*, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult);
273 virtual JSGlobalContextRef STDMETHODCALLTYPE globalContextForScriptWorld(IWebScriptWorld*);
275 virtual HRESULT STDMETHODCALLTYPE visibleContentRect(RECT*);
277 virtual HRESULT STDMETHODCALLTYPE layerTreeAsText(BSTR*);
279 virtual HRESULT STDMETHODCALLTYPE hasSpellingMarker(
280 /* [in] */ UINT from,
281 /* [in] */ UINT length,
282 /* [retval][out] */ BOOL *result);
284 virtual HRESULT STDMETHODCALLTYPE clearOpener();
286 virtual HRESULT STDMETHODCALLTYPE setTextDirection(BSTR);
289 virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding(
290 /* [retval][out] */ BOOL* result);
292 virtual HRESULT STDMETHODCALLTYPE selectedString(
293 /* [retval][out] */ BSTR* result);
295 virtual HRESULT STDMETHODCALLTYPE selectAll();
297 virtual HRESULT STDMETHODCALLTYPE deselectAll();
300 virtual void frameLoaderDestroyed();
301 virtual void makeRepresentation(WebCore::DocumentLoader*);
302 virtual void forceLayoutForNonHTML();
303 virtual void setCopiesOnScroll();
304 virtual void detachedFromParent2();
305 virtual void detachedFromParent3();
306 virtual void cancelPolicyCheck();
307 virtual void dispatchWillSendSubmitEvent(WebCore::HTMLFormElement*) { }
308 virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
309 virtual void revertToProvisionalState(WebCore::DocumentLoader*);
310 virtual void setMainFrameDocumentReady(bool);
311 virtual void willChangeTitle(WebCore::DocumentLoader*);
312 virtual void didChangeTitle(WebCore::DocumentLoader*);
313 virtual void didChangeIcons(WebCore::DocumentLoader*);
314 virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
315 virtual bool canShowMIMEType(const WTF::String& MIMEType) const;
316 virtual bool canShowMIMETypeAsHTML(const WTF::String& MIMEType) const;
317 virtual bool representationExistsForURLScheme(const WTF::String& URLScheme) const;
318 virtual WTF::String generatedMIMETypeForURLScheme(const WTF::String& URLScheme) const;
319 virtual void frameLoadCompleted();
320 virtual void restoreViewState();
321 virtual void provisionalLoadStarted();
322 virtual bool shouldTreatURLAsSameAsCurrent(const WebCore::KURL&) const;
323 virtual void addHistoryItemForFragmentScroll();
324 virtual void didFinishLoad();
325 virtual void prepareForDataSourceReplacement();
326 virtual WTF::String userAgent(const WebCore::KURL&);
327 virtual void saveViewStateToItem(WebCore::HistoryItem *);
328 virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
329 virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
330 virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
331 virtual WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&);
332 virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
333 virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
334 virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&);
335 virtual bool shouldFallBack(const WebCore::ResourceError&);
336 virtual void dispatchDecidePolicyForResponse(WebCore::FramePolicyFunction, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&);
337 virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>, const WTF::String& frameName);
338 virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>);
339 virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
340 virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
342 virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length);
343 virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&);
344 virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
345 virtual void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String());
347 virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement*, const WebCore::KURL& baseURL, const Vector<WTF::String>& paramNames, const Vector<WTF::String>& paramValues);
349 virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL&, const WTF::String& mimeType, bool shouldPreferPlugInsForImages);
350 virtual WTF::String overrideMediaType() const;
352 virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*);
353 virtual void documentElementAvailable();
354 virtual void didPerformFirstNavigation() const;
356 virtual void registerForIconNotification(bool listen);
358 virtual PassRefPtr<WebCore::FrameNetworkingContext> createNetworkingContext();
361 PassRefPtr<WebCore::Frame> init(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*);
362 WebCore::Frame* impl();
364 void unmarkAllMisspellings();
365 void unmarkAllBadGrammar();
367 void updateBackground();
369 // WebFrame (matching WebCoreFrameBridge)
370 HRESULT inViewSourceMode(BOOL *flag);
371 HRESULT setInViewSourceMode(BOOL flag);
372 HRESULT elementWithName(BSTR name, IDOMElement* form, IDOMElement** element);
373 HRESULT formForElement(IDOMElement* element, IDOMElement** form);
374 HRESULT controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls);
375 HRESULT elementIsPassword(IDOMElement* element, bool* result);
376 HRESULT searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* resultDistance, BOOL* resultIsInCellAbove, BSTR* result);
377 HRESULT matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result);
378 HRESULT canProvideDocumentSource(bool* result);
380 COMPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction function);
381 void receivedPolicyDecision(WebCore::PolicyAction);
383 WebCore::KURL url() const;
385 WebView* webView() const;
386 void setWebView(WebView*);
388 COMPtr<IAccessible> accessible() const;
391 void loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL);
392 void loadData(PassRefPtr<WebCore::SharedBuffer>, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL);
393 const Vector<WebCore::IntRect>& computePageRects(HDC printDC);
394 void setPrinting(bool printing, float minPageWidth, float minPageHeight, float maximumShrinkRatio, bool adjustViewSize);
395 void headerAndFooterHeights(float*, float*);
396 WebCore::IntRect printerMarginRect(HDC);
397 void spoolPage (PlatformGraphicsContext* pctx, WebCore::GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate*, float headerHeight, float footerHeight, UINT page, UINT pageCount);
398 void drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, float headerHeight);
399 void drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight);
403 class WebFramePrivate;
405 bool m_quickRedirectComing;
406 WebCore::KURL m_originalRequestURL;
407 bool m_inPrintingMode;
408 Vector<WebCore::IntRect> m_pageRects;
409 int m_pageHeight; // height of the page adjusted by margins
410 mutable COMPtr<AccessibleDocument> m_accessible;