WebFrame.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. #ifndef WebFrame_H
  26. #define WebFrame_H
  27. #include "WebFrameLoaderClient.h"
  28. #include "WebKit.h"
  29. #include "WebDataSource.h"
  30. #include "AccessibleDocument.h"
  31. #include <WebCore/AdjustViewSizeOrNot.h>
  32. #include <WebCore/FrameWin.h>
  33. #include <WebCore/GraphicsContext.h>
  34. #include <WebCore/KURL.h>
  35. #include <WebCore/ResourceHandleClient.h>
  36. #include <WTF/RefPtr.h>
  37. #include <WTF/HashMap.h>
  38. #include <WTF/OwnPtr.h>
  39. #include <wtf/text/WTFString.h>
  40. namespace WebCore {
  41. class AuthenticationChallenge;
  42. class DocumentLoader;
  43. class Element;
  44. class FloatSize;
  45. class Frame;
  46. class GraphicsContext;
  47. class HTMLFrameOwnerElement;
  48. class IntRect;
  49. class Page;
  50. class ResourceError;
  51. class SharedBuffer;
  52. }
  53. typedef const struct OpaqueJSContext* JSContextRef;
  54. typedef struct OpaqueJSValue* JSObjectRef;
  55. #if USE(CG)
  56. typedef struct CGContext PlatformGraphicsContext;
  57. #elif USE(CAIRO)
  58. namespace WebCore {
  59. class PlatformContextCairo;
  60. }
  61. typedef class WebCore::PlatformContextCairo PlatformGraphicsContext;
  62. #endif
  63. class WebFrame;
  64. class WebFramePolicyListener;
  65. class WebHistory;
  66. class WebView;
  67. interface IWebHistoryItemPrivate;
  68. WebFrame* kit(WebCore::Frame*);
  69. WebCore::Frame* core(WebFrame*);
  70. class DECLSPEC_UUID("{A3676398-4485-4a9d-87DC-CB5A40E6351D}") WebFrame : public IWebFrame, IWebFramePrivate, IWebDocumentText
  71. , public WebFrameLoaderClient
  72. {
  73. public:
  74. static WebFrame* createInstance();
  75. protected:
  76. WebFrame();
  77. ~WebFrame();
  78. public:
  79. // IUnknown
  80. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
  81. virtual ULONG STDMETHODCALLTYPE AddRef(void);
  82. virtual ULONG STDMETHODCALLTYPE Release(void);
  83. //IWebFrame
  84. virtual HRESULT STDMETHODCALLTYPE name(
  85. /* [retval][out] */ BSTR *frameName);
  86. virtual HRESULT STDMETHODCALLTYPE webView(
  87. /* [retval][out] */ IWebView **view);
  88. virtual HRESULT STDMETHODCALLTYPE frameView(
  89. /* [retval][out] */ IWebFrameView **view);
  90. virtual HRESULT STDMETHODCALLTYPE DOMDocument(
  91. /* [retval][out] */ IDOMDocument** document);
  92. virtual HRESULT STDMETHODCALLTYPE DOMWindow(/* [retval][out] */ IDOMWindow**);
  93. virtual HRESULT STDMETHODCALLTYPE frameElement(
  94. /* [retval][out] */ IDOMHTMLElement **frameElement);
  95. virtual HRESULT STDMETHODCALLTYPE loadRequest(
  96. /* [in] */ IWebURLRequest *request);
  97. virtual HRESULT STDMETHODCALLTYPE loadData(
  98. /* [in] */ IStream *data,
  99. /* [in] */ BSTR mimeType,
  100. /* [in] */ BSTR textEncodingName,
  101. /* [in] */ BSTR url);
  102. virtual HRESULT STDMETHODCALLTYPE loadHTMLString(
  103. /* [in] */ BSTR string,
  104. /* [in] */ BSTR baseURL);
  105. virtual HRESULT STDMETHODCALLTYPE loadAlternateHTMLString(
  106. /* [in] */ BSTR str,
  107. /* [in] */ BSTR baseURL,
  108. /* [in] */ BSTR unreachableURL);
  109. virtual HRESULT STDMETHODCALLTYPE loadArchive(
  110. /* [in] */ IWebArchive *archive);
  111. virtual HRESULT STDMETHODCALLTYPE dataSource(
  112. /* [retval][out] */ IWebDataSource **source);
  113. virtual HRESULT STDMETHODCALLTYPE provisionalDataSource(
  114. /* [retval][out] */ IWebDataSource **source);
  115. virtual HRESULT STDMETHODCALLTYPE stopLoading( void);
  116. virtual HRESULT STDMETHODCALLTYPE reload( void);
  117. virtual HRESULT STDMETHODCALLTYPE findFrameNamed(
  118. /* [in] */ BSTR name,
  119. /* [retval][out] */ IWebFrame **frame);
  120. virtual HRESULT STDMETHODCALLTYPE parentFrame(
  121. /* [retval][out] */ IWebFrame **frame);
  122. virtual HRESULT STDMETHODCALLTYPE childFrames(
  123. /* [retval][out] */ IEnumVARIANT **enumFrames);
  124. virtual HRESULT STDMETHODCALLTYPE currentForm(
  125. /* [retval][out] */ IDOMElement **formElement);
  126. virtual /* [local] */ JSGlobalContextRef STDMETHODCALLTYPE globalContext();
  127. // IWebFramePrivate
  128. virtual HRESULT STDMETHODCALLTYPE unused1(BSTR*) { return E_NOTIMPL; }
  129. virtual HRESULT STDMETHODCALLTYPE renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result);
  130. virtual HRESULT STDMETHODCALLTYPE pageNumberForElementById(
  131. /* [in] */ BSTR id,
  132. /* [in] */ float pageWidthInPixels,
  133. /* [in] */ float pageHeightInPixels,
  134. /* [retval][out] */ int* result);
  135. virtual HRESULT STDMETHODCALLTYPE numberOfPages(
  136. /* [in] */ float pageWidthInPixels,
  137. /* [in] */ float pageHeightInPixels,
  138. /* [retval][out] */ int* result);
  139. virtual HRESULT STDMETHODCALLTYPE scrollOffset(
  140. /* [retval][out] */ SIZE* offset);
  141. virtual HRESULT STDMETHODCALLTYPE layout();
  142. virtual HRESULT STDMETHODCALLTYPE firstLayoutDone(
  143. /* [retval][out] */ BOOL* result);
  144. virtual HRESULT STDMETHODCALLTYPE loadType(
  145. /* [retval][out] */ WebFrameLoadType* type);
  146. virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount(
  147. /* [retval][out] */ UINT* result);
  148. virtual HRESULT STDMETHODCALLTYPE unused2();
  149. virtual HRESULT STDMETHODCALLTYPE setInPrintingMode(
  150. /* [in] */ BOOL value,
  151. /* [in] */ HDC printDC);
  152. virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount(
  153. /* [in] */ HDC printDC,
  154. /* [retval][out] */ UINT *pageCount);
  155. virtual HRESULT STDMETHODCALLTYPE spoolPages(
  156. /* [in] */ HDC printDC,
  157. /* [in] */ UINT startPage,
  158. /* [in] */ UINT endPage,
  159. /* [retval][out] */ void* ctx);
  160. virtual HRESULT STDMETHODCALLTYPE isFrameSet(
  161. /* [retval][out] */ BOOL* result);
  162. virtual HRESULT STDMETHODCALLTYPE string(
  163. /* [retval][out] */ BSTR* result);
  164. virtual HRESULT STDMETHODCALLTYPE size(
  165. /* [retval][out] */ SIZE *size);
  166. virtual HRESULT STDMETHODCALLTYPE hasScrollBars(
  167. /* [retval][out] */ BOOL *result);
  168. virtual HRESULT STDMETHODCALLTYPE contentBounds(
  169. /* [retval][out] */ RECT *result);
  170. virtual HRESULT STDMETHODCALLTYPE frameBounds(
  171. /* [retval][out] */ RECT *result);
  172. virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame(
  173. /* [in] */ IWebFrame *ancestor,
  174. /* [retval][out] */ BOOL *result);
  175. virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling(
  176. /* [in] */ BOOL flag);
  177. virtual HRESULT STDMETHODCALLTYPE allowsScrolling(
  178. /* [retval][out] */ BOOL *flag);
  179. virtual HRESULT STDMETHODCALLTYPE setIsDisconnected(
  180. /* [in] */ BOOL flag);
  181. virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch(
  182. /* [in] */ BOOL flag);
  183. virtual HRESULT STDMETHODCALLTYPE reloadFromOrigin();
  184. virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext(
  185. /* [in] */ RECT rect,
  186. /* [in] */ OLE_HANDLE deviceContext);
  187. virtual HRESULT STDMETHODCALLTYPE paintScrollViewRectToContextAtPoint(
  188. /* [in] */ RECT rect,
  189. /* [in] */ POINT pt,
  190. /* [in] */ OLE_HANDLE deviceContext);
  191. virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete(
  192. /* [in] */ IDOMElement* element,
  193. /* [retval][out] */ BOOL* result);
  194. virtual HRESULT STDMETHODCALLTYPE pauseAnimation(BSTR animationName, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning);
  195. virtual HRESULT STDMETHODCALLTYPE pauseTransition(BSTR propertyName, IDOMNode*, double secondsFromNow, BOOL* transitionWasRunning);
  196. virtual HRESULT STDMETHODCALLTYPE numberOfActiveAnimations(UINT*);
  197. virtual HRESULT STDMETHODCALLTYPE loadPlainTextString(BSTR string, BSTR url);
  198. virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*);
  199. virtual HRESULT STDMETHODCALLTYPE allowsFollowingLink(
  200. /* [in] */ BSTR url,
  201. /* [retval][out] */ BOOL* result);
  202. virtual HRESULT STDMETHODCALLTYPE stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld*, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult);
  203. virtual JSGlobalContextRef STDMETHODCALLTYPE globalContextForScriptWorld(IWebScriptWorld*);
  204. virtual HRESULT STDMETHODCALLTYPE visibleContentRect(RECT*);
  205. virtual HRESULT STDMETHODCALLTYPE layerTreeAsText(BSTR*);
  206. virtual HRESULT STDMETHODCALLTYPE hasSpellingMarker(
  207. /* [in] */ UINT from,
  208. /* [in] */ UINT length,
  209. /* [retval][out] */ BOOL *result);
  210. virtual HRESULT STDMETHODCALLTYPE clearOpener();
  211. virtual HRESULT STDMETHODCALLTYPE setTextDirection(BSTR);
  212. virtual HRESULT STDMETHODCALLTYPE unused3(BSTR, BSTR*) { return E_NOTIMPL; }
  213. virtual HRESULT STDMETHODCALLTYPE resumeAnimations();
  214. virtual HRESULT STDMETHODCALLTYPE suspendAnimations();
  215. // IWebDocumentText
  216. virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding(
  217. /* [retval][out] */ BOOL* result);
  218. virtual HRESULT STDMETHODCALLTYPE selectedString(
  219. /* [retval][out] */ BSTR* result);
  220. virtual HRESULT STDMETHODCALLTYPE selectAll();
  221. virtual HRESULT STDMETHODCALLTYPE deselectAll();
  222. // FrameLoaderClient
  223. virtual void frameLoaderDestroyed();
  224. virtual void makeRepresentation(WebCore::DocumentLoader*);
  225. virtual void forceLayoutForNonHTML();
  226. virtual void setCopiesOnScroll();
  227. virtual void detachedFromParent2();
  228. virtual void detachedFromParent3();
  229. virtual void cancelPolicyCheck();
  230. virtual void dispatchWillSendSubmitEvent(PassRefPtr<WebCore::FormState>);
  231. virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
  232. virtual void revertToProvisionalState(WebCore::DocumentLoader*);
  233. virtual void setMainFrameDocumentReady(bool);
  234. virtual void willChangeTitle(WebCore::DocumentLoader*);
  235. virtual void didChangeTitle(WebCore::DocumentLoader*);
  236. virtual void didChangeIcons(WebCore::DocumentLoader*);
  237. virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
  238. virtual bool canShowMIMEType(const WTF::String& MIMEType) const;
  239. virtual bool canShowMIMETypeAsHTML(const WTF::String& MIMEType) const;
  240. virtual bool representationExistsForURLScheme(const WTF::String& URLScheme) const;
  241. virtual WTF::String generatedMIMETypeForURLScheme(const WTF::String& URLScheme) const;
  242. virtual void frameLoadCompleted();
  243. virtual void restoreViewState();
  244. virtual void provisionalLoadStarted();
  245. virtual bool shouldTreatURLAsSameAsCurrent(const WebCore::KURL&) const;
  246. virtual void addHistoryItemForFragmentScroll();
  247. virtual void didFinishLoad();
  248. virtual void prepareForDataSourceReplacement();
  249. virtual WTF::String userAgent(const WebCore::KURL&);
  250. virtual void saveViewStateToItem(WebCore::HistoryItem *);
  251. virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
  252. virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
  253. virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
  254. virtual WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&);
  255. virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
  256. virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
  257. virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&);
  258. virtual bool shouldFallBack(const WebCore::ResourceError&);
  259. virtual void dispatchDecidePolicyForResponse(WebCore::FramePolicyFunction, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&);
  260. virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>, const WTF::String& frameName);
  261. virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>);
  262. virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
  263. virtual void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
  264. virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length);
  265. virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&);
  266. virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
  267. virtual void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String());
  268. virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement*, const WebCore::KURL& baseURL, const Vector<WTF::String>& paramNames, const Vector<WTF::String>& paramValues);
  269. virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL&, const WTF::String& mimeType, bool shouldPreferPlugInsForImages);
  270. virtual WTF::String overrideMediaType() const;
  271. virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*);
  272. virtual void documentElementAvailable();
  273. virtual void didPerformFirstNavigation() const;
  274. virtual void registerForIconNotification(bool listen);
  275. virtual PassRefPtr<WebCore::FrameNetworkingContext> createNetworkingContext();
  276. // WebFrame
  277. PassRefPtr<WebCore::Frame> init(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*);
  278. WebCore::Frame* impl();
  279. void invalidate();
  280. void unmarkAllMisspellings();
  281. void unmarkAllBadGrammar();
  282. void updateBackground();
  283. // WebFrame (matching WebCoreFrameBridge)
  284. HRESULT inViewSourceMode(BOOL *flag);
  285. HRESULT setInViewSourceMode(BOOL flag);
  286. HRESULT elementWithName(BSTR name, IDOMElement* form, IDOMElement** element);
  287. HRESULT formForElement(IDOMElement* element, IDOMElement** form);
  288. HRESULT controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls);
  289. HRESULT elementIsPassword(IDOMElement* element, bool* result);
  290. HRESULT searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* resultDistance, BOOL* resultIsInCellAbove, BSTR* result);
  291. HRESULT matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result);
  292. HRESULT canProvideDocumentSource(bool* result);
  293. COMPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction function);
  294. void receivedPolicyDecision(WebCore::PolicyAction);
  295. WebCore::KURL url() const;
  296. WebView* webView() const;
  297. void setWebView(WebView*);
  298. COMPtr<IAccessible> accessible() const;
  299. protected:
  300. void loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL);
  301. void loadData(PassRefPtr<WebCore::SharedBuffer>, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL);
  302. const Vector<WebCore::IntRect>& computePageRects(HDC printDC);
  303. void setPrinting(bool printing, const WebCore::FloatSize& pageSize, const WebCore::FloatSize& originalPageSize, float maximumShrinkRatio, WebCore::AdjustViewSizeOrNot);
  304. void headerAndFooterHeights(float*, float*);
  305. WebCore::IntRect printerMarginRect(HDC);
  306. void spoolPage (PlatformGraphicsContext* pctx, WebCore::GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate*, float headerHeight, float footerHeight, UINT page, UINT pageCount);
  307. void drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, float headerHeight);
  308. void drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight);
  309. protected:
  310. ULONG m_refCount;
  311. class WebFramePrivate;
  312. WebFramePrivate* d;
  313. bool m_quickRedirectComing;
  314. WebCore::KURL m_originalRequestURL;
  315. bool m_inPrintingMode;
  316. Vector<WebCore::IntRect> m_pageRects;
  317. int m_pageHeight; // height of the page adjusted by margins
  318. mutable COMPtr<AccessibleDocument> m_accessible;
  319. };
  320. #endif