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 counterValueForElementById( 162 /* [in] */ BSTR id, 163 /* [retval][out] */ BSTR *result); 164 165 virtual HRESULT STDMETHODCALLTYPE scrollOffset( 166 /* [retval][out] */ SIZE* offset); 167 168 virtual HRESULT STDMETHODCALLTYPE layout(); 169 170 virtual HRESULT STDMETHODCALLTYPE firstLayoutDone( 171 /* [retval][out] */ BOOL* result); 172 173 virtual HRESULT STDMETHODCALLTYPE loadType( 174 /* [retval][out] */ WebFrameLoadType* type); 175 176 virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount( 177 /* [retval][out] */ UINT* result); 178 179 virtual HRESULT STDMETHODCALLTYPE fetchApplicationIcon( 180 /* [in] */ IWebIconFetcherDelegate *delegate, 181 /* [retval][out] */ IWebIconFetcher **result); 182 183 virtual HRESULT STDMETHODCALLTYPE setInPrintingMode( 184 /* [in] */ BOOL value, 185 /* [in] */ HDC printDC); 186 187 virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount( 188 /* [in] */ HDC printDC, 189 /* [retval][out] */ UINT *pageCount); 190 191 virtual HRESULT STDMETHODCALLTYPE spoolPages( 192 /* [in] */ HDC printDC, 193 /* [in] */ UINT startPage, 194 /* [in] */ UINT endPage, 195 /* [retval][out] */ void* ctx); 196 197 virtual HRESULT STDMETHODCALLTYPE isFrameSet( 198 /* [retval][out] */ BOOL* result); 199 200 virtual HRESULT STDMETHODCALLTYPE string( 201 /* [retval][out] */ BSTR* result); 202 203 virtual HRESULT STDMETHODCALLTYPE size( 204 /* [retval][out] */ SIZE *size); 205 206 virtual HRESULT STDMETHODCALLTYPE hasScrollBars( 207 /* [retval][out] */ BOOL *result); 208 209 virtual HRESULT STDMETHODCALLTYPE contentBounds( 210 /* [retval][out] */ RECT *result); 211 212 virtual HRESULT STDMETHODCALLTYPE frameBounds( 213 /* [retval][out] */ RECT *result); 214 215 virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame( 216 /* [in] */ IWebFrame *ancestor, 217 /* [retval][out] */ BOOL *result); 218 219 virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling( 220 /* [in] */ BOOL flag); 221 222 virtual HRESULT STDMETHODCALLTYPE allowsScrolling( 223 /* [retval][out] */ BOOL *flag); 224 225 virtual HRESULT STDMETHODCALLTYPE setIsDisconnected( 226 /* [in] */ BOOL flag); 227 228 virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch( 229 /* [in] */ BOOL flag); 230 231 virtual HRESULT STDMETHODCALLTYPE reloadFromOrigin(); 232 233 virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext( 234 /* [in] */ RECT rect, 235 /* [in] */ OLE_HANDLE deviceContext); 236 237 virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete( 238 /* [in] */ IDOMElement* element, 239 /* [retval][out] */ BOOL* result); 240 241 virtual HRESULT STDMETHODCALLTYPE pauseAnimation(BSTR animationName, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning); 242 virtual HRESULT STDMETHODCALLTYPE pauseTransition(BSTR propertyName, IDOMNode*, double secondsFromNow, BOOL* transitionWasRunning); 243 virtual HRESULT STDMETHODCALLTYPE pauseSVGAnimation(BSTR elementId, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning); 244 virtual HRESULT STDMETHODCALLTYPE numberOfActiveAnimations(UINT*); 245 246 virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*); 247 248 virtual HRESULT STDMETHODCALLTYPE allowsFollowingLink( 249 /* [in] */ BSTR url, 250 /* [retval][out] */ BOOL* result); 251 252 virtual HRESULT STDMETHODCALLTYPE stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld*, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult); 253 virtual JSGlobalContextRef STDMETHODCALLTYPE globalContextForScriptWorld(IWebScriptWorld*); 254 255 // IWebDocumentText 256 virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding( 257 /* [retval][out] */ BOOL* result); 258 259 virtual HRESULT STDMETHODCALLTYPE selectedString( 260 /* [retval][out] */ BSTR* result); 261 262 virtual HRESULT STDMETHODCALLTYPE selectAll(); 263 264 virtual HRESULT STDMETHODCALLTYPE deselectAll(); 265 266 // FrameLoaderClient 267 virtual void frameLoaderDestroyed(); 268 virtual void makeRepresentation(WebCore::DocumentLoader*); 269 virtual void forceLayoutForNonHTML(); 270 virtual void setCopiesOnScroll(); 271 virtual void detachedFromParent2(); 272 virtual void detachedFromParent3(); 273 virtual void cancelPolicyCheck(); 274 virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>); 275 virtual void revertToProvisionalState(WebCore::DocumentLoader*); 276 virtual void setMainFrameDocumentReady(bool); 277 virtual void willChangeTitle(WebCore::DocumentLoader*); 278 virtual void didChangeTitle(WebCore::DocumentLoader*); 279 virtual bool canHandleRequest(const WebCore::ResourceRequest&) const; 280 virtual bool canShowMIMEType(const WebCore::String& MIMEType) const; 281 virtual bool representationExistsForURLScheme(const WebCore::String& URLScheme) const; 282 virtual WebCore::String generatedMIMETypeForURLScheme(const WebCore::String& URLScheme) const; 283 virtual void frameLoadCompleted(); 284 virtual void restoreViewState(); 285 virtual void provisionalLoadStarted(); 286 virtual bool shouldTreatURLAsSameAsCurrent(const WebCore::KURL&) const; 287 virtual void addHistoryItemForFragmentScroll(); 288 virtual void didFinishLoad(); 289 virtual void prepareForDataSourceReplacement(); 290 virtual WebCore::String userAgent(const WebCore::KURL&); 291 virtual void saveViewStateToItem(WebCore::HistoryItem *); 292 virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&); 293 virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&); 294 virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&); 295 virtual WebCore::ResourceError interruptForPolicyChangeError(const WebCore::ResourceRequest&); 296 virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&); 297 virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&); 298 virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&); 299 virtual bool shouldFallBack(const WebCore::ResourceError&); 300 virtual void dispatchDecidePolicyForMIMEType(WebCore::FramePolicyFunction, const WebCore::String& MIMEType, const WebCore::ResourceRequest&); 301 virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>, const WebCore::String& frameName); 302 virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<WebCore::FormState>); 303 virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&); 304 virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&); 305 306 virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length); 307 virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&); 308 virtual void dispatchDidFailLoad(const WebCore::ResourceError&); 309 virtual void startDownload(const WebCore::ResourceRequest&); 310 311 virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement*, const WebCore::KURL& baseURL, const Vector<WebCore::String>& paramNames, const Vector<WebCore::String>& paramValues); 312 313 virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL& url, const WebCore::String& mimeType); 314 virtual WebCore::String overrideMediaType() const; 315 316 virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*); 317 virtual void documentElementAvailable(); 318 virtual void didPerformFirstNavigation() const; 319 320 virtual void registerForIconNotification(bool listen); 321 322 // WebFrame 323 PassRefPtr<WebCore::Frame> init(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*); 324 WebCore::Frame* impl(); 325 void invalidate(); 326 void unmarkAllMisspellings(); 327 void unmarkAllBadGrammar(); 328 329 void updateBackground(); 330 331 // WebFrame (matching WebCoreFrameBridge) 332 void setTextSizeMultiplier(float multiplier); 333 HRESULT inViewSourceMode(BOOL *flag); 334 HRESULT setInViewSourceMode(BOOL flag); 335 HRESULT elementWithName(BSTR name, IDOMElement* form, IDOMElement** element); 336 HRESULT formForElement(IDOMElement* element, IDOMElement** form); 337 HRESULT controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls); 338 HRESULT elementIsPassword(IDOMElement* element, bool* result); 339 HRESULT searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* resultDistance, BOOL* resultIsInCellAbove, BSTR* result); 340 HRESULT matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result); 341 HRESULT canProvideDocumentSource(bool* result); 342 343 COMPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction function); 344 void receivedPolicyDecision(WebCore::PolicyAction); 345 346 WebCore::KURL url() const; 347 348 WebView* webView() const; 349 350 COMPtr<IAccessible> accessible() const; 351 352 protected: 353 void loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL); 354 void loadData(PassRefPtr<WebCore::SharedBuffer>, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL); 355 const Vector<WebCore::IntRect>& computePageRects(HDC printDC); 356 void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize); 357 void headerAndFooterHeights(float*, float*); 358 WebCore::IntRect printerMarginRect(HDC); 359 void spoolPage (PlatformGraphicsContext* pctx, WebCore::GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate*, float headerHeight, float footerHeight, UINT page, UINT pageCount); 360 void drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, float headerHeight); 361 void drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight); 362 363 protected: 364 ULONG m_refCount; 365 class WebFramePrivate; 366 WebFramePrivate* d; 367 bool m_quickRedirectComing; 368 WebCore::KURL m_originalRequestURL; 369 bool m_inPrintingMode; 370 Vector<WebCore::IntRect> m_pageRects; 371 int m_pageHeight; // height of the page adjusted by margins 372 mutable COMPtr<AccessibleDocument> m_accessible; 373 }; 374 375 #endif 376