initial import
[vuplus_webkit] / Source / WebKit / win / WebFrame.h
1 /*
2  * Copyright (C) 2006, 2007, 2011 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 #include <WebCore/FrameWin.h>
37 #include <WebCore/GraphicsContext.h>
38 #include <WebCore/KURL.h>
39 #include <WebCore/PlatformString.h>
40 #include <WebCore/ResourceHandleClient.h>
41
42 #include <WTF/RefPtr.h>
43 #include <WTF/HashMap.h>
44 #include <WTF/OwnPtr.h>
45
46 namespace WebCore {
47     class AuthenticationChallenge;
48     class DocumentLoader;
49     class Element;
50     class Frame;
51     class GraphicsContext;
52     class HTMLFrameOwnerElement;
53     class IntRect;
54     class Page;
55     class ResourceError;
56     class SharedBuffer;
57 }
58
59 typedef const struct OpaqueJSContext* JSContextRef;
60 typedef struct OpaqueJSValue* JSObjectRef;
61
62 #if USE(CG)
63 typedef struct CGContext PlatformGraphicsContext;
64 #elif USE(CAIRO)
65 namespace WebCore {
66 class PlatformContextCairo;
67 }
68 typedef class WebCore::PlatformContextCairo PlatformGraphicsContext;
69 #endif
70
71 class WebFrame;
72 class WebFramePolicyListener;
73 class WebHistory;
74 class WebView;
75
76 interface IWebHistoryItemPrivate;
77
78 WebFrame* kit(WebCore::Frame*);
79 WebCore::Frame* core(WebFrame*);
80
81 class DECLSPEC_UUID("{A3676398-4485-4a9d-87DC-CB5A40E6351D}") WebFrame : public IWebFrame, IWebFramePrivate, IWebDocumentText
82     , public WebFrameLoaderClient
83 {
84 public:
85     static WebFrame* createInstance();
86 protected:
87     WebFrame();
88     ~WebFrame();
89
90 public:
91     // IUnknown
92     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
93     virtual ULONG STDMETHODCALLTYPE AddRef(void);
94     virtual ULONG STDMETHODCALLTYPE Release(void);
95
96     //IWebFrame
97     virtual HRESULT STDMETHODCALLTYPE name( 
98         /* [retval][out] */ BSTR *frameName);
99     
100     virtual HRESULT STDMETHODCALLTYPE webView( 
101         /* [retval][out] */ IWebView **view);
102
103     virtual HRESULT STDMETHODCALLTYPE frameView(
104         /* [retval][out] */ IWebFrameView **view);
105
106     virtual HRESULT STDMETHODCALLTYPE DOMDocument( 
107         /* [retval][out] */ IDOMDocument** document);
108
109     virtual HRESULT STDMETHODCALLTYPE DOMWindow(/* [retval][out] */ IDOMWindow**);
110     
111     virtual HRESULT STDMETHODCALLTYPE frameElement( 
112         /* [retval][out] */ IDOMHTMLElement **frameElement);
113     
114     virtual HRESULT STDMETHODCALLTYPE loadRequest( 
115         /* [in] */ IWebURLRequest *request);
116     
117     virtual HRESULT STDMETHODCALLTYPE loadData( 
118         /* [in] */ IStream *data,
119         /* [in] */ BSTR mimeType,
120         /* [in] */ BSTR textEncodingName,
121         /* [in] */ BSTR url);
122     
123     virtual HRESULT STDMETHODCALLTYPE loadHTMLString( 
124         /* [in] */ BSTR string,
125         /* [in] */ BSTR baseURL);
126     
127     virtual HRESULT STDMETHODCALLTYPE loadAlternateHTMLString( 
128         /* [in] */ BSTR str,
129         /* [in] */ BSTR baseURL,
130         /* [in] */ BSTR unreachableURL);
131     
132     virtual HRESULT STDMETHODCALLTYPE loadArchive( 
133         /* [in] */ IWebArchive *archive);
134     
135     virtual HRESULT STDMETHODCALLTYPE dataSource( 
136         /* [retval][out] */ IWebDataSource **source);
137     
138     virtual HRESULT STDMETHODCALLTYPE provisionalDataSource( 
139         /* [retval][out] */ IWebDataSource **source);
140     
141     virtual HRESULT STDMETHODCALLTYPE stopLoading( void);
142     
143     virtual HRESULT STDMETHODCALLTYPE reload( void);
144     
145     virtual HRESULT STDMETHODCALLTYPE findFrameNamed( 
146         /* [in] */ BSTR name,
147         /* [retval][out] */ IWebFrame **frame);
148     
149     virtual HRESULT STDMETHODCALLTYPE parentFrame( 
150         /* [retval][out] */ IWebFrame **frame);
151     
152     virtual HRESULT STDMETHODCALLTYPE childFrames( 
153         /* [retval][out] */ IEnumVARIANT **enumFrames);
154
155     virtual HRESULT STDMETHODCALLTYPE currentForm( 
156         /* [retval][out] */ IDOMElement **formElement);
157
158     virtual /* [local] */ JSGlobalContextRef STDMETHODCALLTYPE globalContext();
159
160     // IWebFramePrivate
161     virtual HRESULT STDMETHODCALLTYPE unused1(BSTR*) { return E_NOTIMPL; }
162     virtual HRESULT STDMETHODCALLTYPE renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result);
163
164     virtual HRESULT STDMETHODCALLTYPE counterValueForElementById(
165         /* [in] */ BSTR id,
166         /* [retval][out] */ BSTR *result);
167
168     virtual HRESULT STDMETHODCALLTYPE pageNumberForElementById(
169         /* [in] */ BSTR id,
170         /* [in] */ float pageWidthInPixels,
171         /* [in] */ float pageHeightInPixels,
172         /* [retval][out] */ int* result);
173
174     virtual HRESULT STDMETHODCALLTYPE numberOfPages(
175         /* [in] */ float pageWidthInPixels,
176         /* [in] */ float pageHeightInPixels,
177         /* [retval][out] */ int* result);
178
179     virtual HRESULT STDMETHODCALLTYPE scrollOffset(
180         /* [retval][out] */ SIZE* offset);
181
182     virtual HRESULT STDMETHODCALLTYPE layout();
183
184     virtual HRESULT STDMETHODCALLTYPE firstLayoutDone(
185         /* [retval][out] */ BOOL* result);
186
187     virtual HRESULT STDMETHODCALLTYPE loadType( 
188         /* [retval][out] */ WebFrameLoadType* type);
189
190     virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount( 
191         /* [retval][out] */ UINT* result);
192
193     virtual HRESULT STDMETHODCALLTYPE unused2();
194     
195     virtual HRESULT STDMETHODCALLTYPE setInPrintingMode( 
196         /* [in] */ BOOL value,
197         /* [in] */ HDC printDC);
198         
199     virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount( 
200         /* [in] */ HDC printDC,
201         /* [retval][out] */ UINT *pageCount);
202     
203     virtual HRESULT STDMETHODCALLTYPE spoolPages( 
204         /* [in] */ HDC printDC,
205         /* [in] */ UINT startPage,
206         /* [in] */ UINT endPage,
207         /* [retval][out] */ void* ctx);
208
209     virtual HRESULT STDMETHODCALLTYPE isFrameSet( 
210         /* [retval][out] */ BOOL* result);
211
212     virtual HRESULT STDMETHODCALLTYPE string( 
213         /* [retval][out] */ BSTR* result);
214
215     virtual HRESULT STDMETHODCALLTYPE size( 
216         /* [retval][out] */ SIZE *size);
217
218     virtual HRESULT STDMETHODCALLTYPE hasScrollBars( 
219         /* [retval][out] */ BOOL *result);
220     
221     virtual HRESULT STDMETHODCALLTYPE contentBounds( 
222         /* [retval][out] */ RECT *result);
223     
224     virtual HRESULT STDMETHODCALLTYPE frameBounds( 
225         /* [retval][out] */ RECT *result);
226
227     virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame( 
228         /* [in] */ IWebFrame *ancestor,
229         /* [retval][out] */ BOOL *result);
230
231     virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling(
232         /* [in] */ BOOL flag);
233
234     virtual HRESULT STDMETHODCALLTYPE allowsScrolling(
235         /* [retval][out] */ BOOL *flag);
236
237     virtual HRESULT STDMETHODCALLTYPE setIsDisconnected(
238         /* [in] */ BOOL flag);
239
240     virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch(
241         /* [in] */ BOOL flag);
242
243     virtual HRESULT STDMETHODCALLTYPE reloadFromOrigin();
244
245     virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext(
246         /* [in] */ RECT rect,
247         /* [in] */ OLE_HANDLE deviceContext);
248
249     virtual HRESULT STDMETHODCALLTYPE paintScrollViewRectToContextAtPoint(
250         /* [in] */ RECT rect,
251         /* [in] */ POINT pt,
252         /* [in] */ OLE_HANDLE deviceContext);
253
254     virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete(
255         /* [in] */ IDOMElement* element, 
256         /* [retval][out] */ BOOL* result);
257
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);
265
266     virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*);
267
268     virtual HRESULT STDMETHODCALLTYPE allowsFollowingLink(
269         /* [in] */ BSTR url,
270         /* [retval][out] */ BOOL* result);
271
272     virtual HRESULT STDMETHODCALLTYPE stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld*, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult);
273     virtual JSGlobalContextRef STDMETHODCALLTYPE globalContextForScriptWorld(IWebScriptWorld*);
274
275     virtual HRESULT STDMETHODCALLTYPE visibleContentRect(RECT*);
276
277     virtual HRESULT STDMETHODCALLTYPE layerTreeAsText(BSTR*);
278
279     virtual HRESULT STDMETHODCALLTYPE hasSpellingMarker(
280         /* [in] */ UINT from,
281         /* [in] */ UINT length,
282         /* [retval][out] */ BOOL *result);
283
284     virtual HRESULT STDMETHODCALLTYPE clearOpener();
285
286     virtual HRESULT STDMETHODCALLTYPE setTextDirection(BSTR);
287
288     // IWebDocumentText
289     virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding( 
290         /* [retval][out] */ BOOL* result);
291     
292     virtual HRESULT STDMETHODCALLTYPE selectedString( 
293         /* [retval][out] */ BSTR* result);
294     
295     virtual HRESULT STDMETHODCALLTYPE selectAll();
296     
297     virtual HRESULT STDMETHODCALLTYPE deselectAll();
298     
299     // FrameLoaderClient
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&);
341
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());
346         
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);
348
349     virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL&, const WTF::String& mimeType, bool shouldPreferPlugInsForImages);
350     virtual WTF::String overrideMediaType() const;
351
352     virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*);
353     virtual void documentElementAvailable();
354     virtual void didPerformFirstNavigation() const;
355
356     virtual void registerForIconNotification(bool listen);
357
358     virtual PassRefPtr<WebCore::FrameNetworkingContext> createNetworkingContext();
359
360     // WebFrame
361     PassRefPtr<WebCore::Frame> init(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*);
362     WebCore::Frame* impl();
363     void invalidate();
364     void unmarkAllMisspellings();
365     void unmarkAllBadGrammar();
366
367     void updateBackground();
368
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);
379
380     COMPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction function);
381     void receivedPolicyDecision(WebCore::PolicyAction);
382
383     WebCore::KURL url() const;
384
385     WebView* webView() const;
386     void setWebView(WebView*);
387
388     COMPtr<IAccessible> accessible() const;
389
390 protected:
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);
400
401 protected:
402     ULONG               m_refCount;
403     class WebFramePrivate;
404     WebFramePrivate*    d;
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;
411 };
412
413 #endif