• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #ifndef WebFrame_H
27 #define WebFrame_H
28 
29 #include "WebFrameLoaderClient.h"
30 
31 #include "WebKit.h"
32 #include "WebDataSource.h"
33 
34 #include "AccessibleDocument.h"
35 
36 #pragma warning(push, 0)
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>
42 #pragma warning(pop)
43 
44 #include <WTF/RefPtr.h>
45 #include <WTF/HashMap.h>
46 #include <WTF/OwnPtr.h>
47 
48 namespace WebCore {
49     class AuthenticationChallenge;
50     class DocumentLoader;
51     class Element;
52     class Frame;
53     class GraphicsContext;
54     class HTMLFrameOwnerElement;
55     class IntRect;
56     class Page;
57     class ResourceError;
58     class SharedBuffer;
59 }
60 
61 typedef const struct OpaqueJSContext* JSContextRef;
62 typedef struct OpaqueJSValue* JSObjectRef;
63 
64 #if PLATFORM(CG)
65 typedef struct CGContext PlatformGraphicsContext;
66 #elif PLATFORM(CAIRO)
67 typedef struct _cairo PlatformGraphicsContext;
68 #endif
69 
70 class WebFrame;
71 class WebFramePolicyListener;
72 class WebHistory;
73 class WebView;
74 
75 interface IWebHistoryItemPrivate;
76 
77 WebFrame* kit(WebCore::Frame*);
78 WebCore::Frame* core(WebFrame*);
79 
80 class DECLSPEC_UUID("{A3676398-4485-4a9d-87DC-CB5A40E6351D}") WebFrame : public IWebFrame, IWebFramePrivate, IWebDocumentText
81     , public WebFrameLoaderClient
82 {
83 public:
84     static WebFrame* createInstance();
85 protected:
86     WebFrame();
87     ~WebFrame();
88 
89 public:
90     // IUnknown
91     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
92     virtual ULONG STDMETHODCALLTYPE AddRef(void);
93     virtual ULONG STDMETHODCALLTYPE Release(void);
94 
95     //IWebFrame
96     virtual HRESULT STDMETHODCALLTYPE name(
97         /* [retval][out] */ BSTR *frameName);
98 
99     virtual HRESULT STDMETHODCALLTYPE webView(
100         /* [retval][out] */ IWebView **view);
101 
102     virtual HRESULT STDMETHODCALLTYPE frameView(
103         /* [retval][out] */ IWebFrameView **view);
104 
105     virtual HRESULT STDMETHODCALLTYPE DOMDocument(
106         /* [retval][out] */ IDOMDocument** document);
107 
108     virtual HRESULT STDMETHODCALLTYPE frameElement(
109         /* [retval][out] */ IDOMHTMLElement **frameElement);
110 
111     virtual HRESULT STDMETHODCALLTYPE loadRequest(
112         /* [in] */ IWebURLRequest *request);
113 
114     virtual HRESULT STDMETHODCALLTYPE loadData(
115         /* [in] */ IStream *data,
116         /* [in] */ BSTR mimeType,
117         /* [in] */ BSTR textEncodingName,
118         /* [in] */ BSTR url);
119 
120     virtual HRESULT STDMETHODCALLTYPE loadHTMLString(
121         /* [in] */ BSTR string,
122         /* [in] */ BSTR baseURL);
123 
124     virtual HRESULT STDMETHODCALLTYPE loadAlternateHTMLString(
125         /* [in] */ BSTR str,
126         /* [in] */ BSTR baseURL,
127         /* [in] */ BSTR unreachableURL);
128 
129     virtual HRESULT STDMETHODCALLTYPE loadArchive(
130         /* [in] */ IWebArchive *archive);
131 
132     virtual HRESULT STDMETHODCALLTYPE dataSource(
133         /* [retval][out] */ IWebDataSource **source);
134 
135     virtual HRESULT STDMETHODCALLTYPE provisionalDataSource(
136         /* [retval][out] */ IWebDataSource **source);
137 
138     virtual HRESULT STDMETHODCALLTYPE stopLoading( void);
139 
140     virtual HRESULT STDMETHODCALLTYPE reload( void);
141 
142     virtual HRESULT STDMETHODCALLTYPE findFrameNamed(
143         /* [in] */ BSTR name,
144         /* [retval][out] */ IWebFrame **frame);
145 
146     virtual HRESULT STDMETHODCALLTYPE parentFrame(
147         /* [retval][out] */ IWebFrame **frame);
148 
149     virtual HRESULT STDMETHODCALLTYPE childFrames(
150         /* [retval][out] */ IEnumVARIANT **enumFrames);
151 
152     virtual HRESULT STDMETHODCALLTYPE currentForm(
153         /* [retval][out] */ IDOMElement **formElement);
154 
155     virtual /* [local] */ JSGlobalContextRef STDMETHODCALLTYPE globalContext();
156 
157     // IWebFramePrivate
158     virtual HRESULT STDMETHODCALLTYPE renderTreeAsExternalRepresentation(
159         /* [retval][out] */ BSTR *result);
160 
161     virtual HRESULT STDMETHODCALLTYPE scrollOffset(
162         /* [retval][out] */ SIZE* offset);
163 
164     virtual HRESULT STDMETHODCALLTYPE layout();
165 
166     virtual HRESULT STDMETHODCALLTYPE firstLayoutDone(
167         /* [retval][out] */ BOOL* result);
168 
169     virtual HRESULT STDMETHODCALLTYPE loadType(
170         /* [retval][out] */ WebFrameLoadType* type);
171 
172     virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount(
173         /* [retval][out] */ UINT* result);
174 
175     virtual HRESULT STDMETHODCALLTYPE fetchApplicationIcon(
176         /* [in] */ IWebIconFetcherDelegate *delegate,
177         /* [retval][out] */ IWebIconFetcher **result);
178 
179     virtual HRESULT STDMETHODCALLTYPE setInPrintingMode(
180         /* [in] */ BOOL value,
181         /* [in] */ HDC printDC);
182 
183     virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount(
184         /* [in] */ HDC printDC,
185         /* [retval][out] */ UINT *pageCount);
186 
187     virtual HRESULT STDMETHODCALLTYPE spoolPages(
188         /* [in] */ HDC printDC,
189         /* [in] */ UINT startPage,
190         /* [in] */ UINT endPage,
191         /* [retval][out] */ void* ctx);
192 
193     virtual HRESULT STDMETHODCALLTYPE isFrameSet(
194         /* [retval][out] */ BOOL* result);
195 
196     virtual HRESULT STDMETHODCALLTYPE string(
197         /* [retval][out] */ BSTR* result);
198 
199     virtual HRESULT STDMETHODCALLTYPE size(
200         /* [retval][out] */ SIZE *size);
201 
202     virtual HRESULT STDMETHODCALLTYPE hasScrollBars(
203         /* [retval][out] */ BOOL *result);
204 
205     virtual HRESULT STDMETHODCALLTYPE contentBounds(
206         /* [retval][out] */ RECT *result);
207 
208     virtual HRESULT STDMETHODCALLTYPE frameBounds(
209         /* [retval][out] */ RECT *result);
210 
211     virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame(
212         /* [in] */ IWebFrame *ancestor,
213         /* [retval][out] */ BOOL *result);
214 
215     virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling(
216         /* [in] */ BOOL flag);
217 
218     virtual HRESULT STDMETHODCALLTYPE allowsScrolling(
219         /* [retval][out] */ BOOL *flag);
220 
221     virtual HRESULT STDMETHODCALLTYPE setIsDisconnected(
222         /* [in] */ BOOL flag);
223 
224     virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch(
225         /* [in] */ BOOL flag);
226 
227     virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext(
228         /* [in] */ RECT rect,
229         /* [in] */ OLE_HANDLE deviceContext);
230 
231     virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete(
232         /* [in] */ IDOMElement* element,
233         /* [retval][out] */ BOOL* result);
234 
235     virtual HRESULT STDMETHODCALLTYPE pauseAnimation(BSTR animationName, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning);
236     virtual HRESULT STDMETHODCALLTYPE pauseTransition(BSTR propertyName, IDOMNode*, double secondsFromNow, BOOL* transitionWasRunning);
237     virtual HRESULT STDMETHODCALLTYPE numberOfActiveAnimations(UINT*);
238 
239     virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*);
240 
241     // IWebDocumentText
242     virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding(
243         /* [retval][out] */ BOOL* result);
244 
245     virtual HRESULT STDMETHODCALLTYPE selectedString(
246         /* [retval][out] */ BSTR* result);
247 
248     virtual HRESULT STDMETHODCALLTYPE selectAll();
249 
250     virtual HRESULT STDMETHODCALLTYPE deselectAll();
251 
252     // FrameLoaderClient
253     virtual void frameLoaderDestroyed();
254     virtual void makeRepresentation(WebCore::DocumentLoader*);
255     virtual void forceLayoutForNonHTML();
256     virtual void setCopiesOnScroll();
257     virtual void detachedFromParent2();
258     virtual void detachedFromParent3();
259     virtual void cancelPolicyCheck();
260     virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
261     virtual void revertToProvisionalState(WebCore::DocumentLoader*);
262     virtual void setMainFrameDocumentReady(bool);
263     virtual void willChangeTitle(WebCore::DocumentLoader*);
264     virtual void didChangeTitle(WebCore::DocumentLoader*);
265     virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
266     virtual bool canShowMIMEType(const WebCore::String& MIMEType) const;
267     virtual bool representationExistsForURLScheme(const WebCore::String& URLScheme) const;
268     virtual WebCore::String generatedMIMETypeForURLScheme(const WebCore::String& URLScheme) const;
269     virtual void frameLoadCompleted();
270     virtual void restoreViewState();
271     virtual void provisionalLoadStarted();
272     virtual bool shouldTreatURLAsSameAsCurrent(const WebCore::KURL&) const;
273     virtual void addHistoryItemForFragmentScroll();
274     virtual void didFinishLoad();
275     virtual void prepareForDataSourceReplacement();
276     virtual WebCore::String userAgent(const WebCore::KURL&);
277     virtual void saveViewStateToItem(WebCore::HistoryItem *);
278     virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
279     virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
280     virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
281     virtual WebCore::ResourceError interruptForPolicyChangeError(const WebCore::ResourceRequest&);
282     virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
283     virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
284     virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&);
285     virtual bool shouldFallBack(const WebCore::ResourceError&);
286     virtual void dispatchDecidePolicyForMIMEType(WebCore::FramePolicyFunction, const WebCore::String& MIMEType, const WebCore::ResourceRequest&);
287     virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>, const WebCore::String& frameName);
288     virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>);
289     virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
290     virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
291 
292     virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length);
293     virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&);
294     virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
295     virtual void startDownload(const WebCore::ResourceRequest&);
296 
297     virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement*, const WebCore::KURL& baseURL, const Vector<WebCore::String>& paramNames, const Vector<WebCore::String>& paramValues);
298 
299     virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL& url, const WebCore::String& mimeType);
300     virtual WebCore::String overrideMediaType() const;
301 
302     virtual void windowObjectCleared();
303     virtual void documentElementAvailable();
304     virtual void didPerformFirstNavigation() const;
305 
306     virtual void registerForIconNotification(bool listen);
307 
308     // WebFrame
309     PassRefPtr<WebCore::Frame> init(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*);
310     WebCore::Frame* impl();
311     void invalidate();
312     void unmarkAllMisspellings();
313     void unmarkAllBadGrammar();
314 
315     void updateBackground();
316 
317     // WebFrame (matching WebCoreFrameBridge)
318     void setTextSizeMultiplier(float multiplier);
319     HRESULT inViewSourceMode(BOOL *flag);
320     HRESULT setInViewSourceMode(BOOL flag);
321     HRESULT elementWithName(BSTR name, IDOMElement* form, IDOMElement** element);
322     HRESULT formForElement(IDOMElement* element, IDOMElement** form);
323     HRESULT controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls);
324     HRESULT elementIsPassword(IDOMElement* element, bool* result);
325     HRESULT searchForLabelsBeforeElement(const BSTR* labels, int cLabels, IDOMElement* beforeElement, BSTR* result);
326     HRESULT matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result);
327     HRESULT canProvideDocumentSource(bool* result);
328 
329     COMPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction function);
330     void receivedPolicyDecision(WebCore::PolicyAction);
331 
332     WebCore::KURL url() const;
333 
334     WebView* webView() const;
335 
336     COMPtr<IAccessible> accessible() const;
337 
338 protected:
339     void loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL);
340     void loadData(PassRefPtr<WebCore::SharedBuffer>, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL);
341     const Vector<WebCore::IntRect>& computePageRects(HDC printDC);
342     void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
343     void headerAndFooterHeights(float*, float*);
344     WebCore::IntRect printerMarginRect(HDC);
345     void spoolPage (PlatformGraphicsContext* pctx, WebCore::GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate*, float headerHeight, float footerHeight, UINT page, UINT pageCount);
346     void drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, float headerHeight);
347     void drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight);
348 
349 protected:
350     ULONG               m_refCount;
351     class WebFramePrivate;
352     WebFramePrivate*    d;
353     bool                m_quickRedirectComing;
354     WebCore::KURL       m_originalRequestURL;
355     bool                m_inPrintingMode;
356     Vector<WebCore::IntRect> m_pageRects;
357     int m_pageHeight;   // height of the page adjusted by margins
358     mutable COMPtr<AccessibleDocument> m_accessible;
359 };
360 
361 #endif
362