1 /* 2 * Copyright (C) 2010 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 INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef WebFrame_h 27 #define WebFrame_h 28 29 #include "APIObject.h" 30 #include "ImmutableArray.h" 31 #include "WebFrameLoaderClient.h" 32 #include <JavaScriptCore/JSBase.h> 33 #include <WebCore/FrameLoaderClient.h> 34 #include <WebCore/FrameLoaderTypes.h> 35 #include <WebCore/PolicyChecker.h> 36 #include <wtf/Forward.h> 37 #include <wtf/PassRefPtr.h> 38 #include <wtf/RefPtr.h> 39 40 namespace WebCore { 41 class Frame; 42 class HTMLFrameOwnerElement; 43 class KURL; 44 } 45 46 namespace WebKit { 47 48 class InjectedBundleNodeHandle; 49 class InjectedBundleRangeHandle; 50 class InjectedBundleScriptWorld; 51 class WebPage; 52 53 class WebFrame : public APIObject { 54 public: 55 static const Type APIType = TypeBundleFrame; 56 57 static PassRefPtr<WebFrame> createMainFrame(WebPage*); 58 static PassRefPtr<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*); 59 ~WebFrame(); 60 61 // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down. 62 void invalidate(); 63 64 WebPage* page() const; coreFrame()65 WebCore::Frame* coreFrame() const { return m_coreFrame; } 66 frameID()67 uint64_t frameID() const { return m_frameID; } 68 69 uint64_t setUpPolicyListener(WebCore::FramePolicyFunction); 70 void invalidatePolicyListener(); 71 void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyAction, uint64_t downloadID); 72 73 void startDownload(const WebCore::ResourceRequest&); 74 void convertHandleToDownload(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest& initialRequest, const WebCore::ResourceResponse&); 75 76 String source() const; 77 String contentsAsString() const; 78 String selectionAsString() const; 79 80 WebCore::IntSize size() const; 81 82 // WKBundleFrame API and SPI functions 83 bool isMainFrame() const; 84 String name() const; 85 String url() const; 86 String innerText() const; 87 bool isFrameSet() const; 88 PassRefPtr<ImmutableArray> childFrames(); 89 JSValueRef computedStyleIncludingVisitedInfo(JSObjectRef element); 90 JSGlobalContextRef jsContext(); 91 JSGlobalContextRef jsContextForWorld(InjectedBundleScriptWorld*); 92 WebCore::IntRect contentBounds() const; 93 WebCore::IntRect visibleContentBounds() const; 94 WebCore::IntRect visibleContentBoundsExcludingScrollbars() const; 95 WebCore::IntSize scrollOffset() const; 96 bool hasHorizontalScrollbar() const; 97 bool hasVerticalScrollbar() const; 98 bool getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha); 99 100 static WebFrame* frameForContext(JSContextRef); 101 102 JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*); 103 JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*); 104 105 static String counterValue(JSObjectRef element); 106 static String markerText(JSObjectRef element); 107 108 unsigned numberOfActiveAnimations() const; 109 bool pauseAnimationOnElementWithId(const String& animationName, const String& elementID, double time); 110 void suspendAnimations(); 111 void resumeAnimations(); 112 String layerTreeAsText() const; 113 114 unsigned pendingUnloadCount() const; 115 116 bool allowsFollowingLink(const WebCore::KURL&) const; 117 118 String provisionalURL() const; 119 String suggestedFilenameForResourceWithURL(const WebCore::KURL&) const; 120 String mimeTypeForResourceWithURL(const WebCore::KURL&) const; 121 122 // Simple listener class used by plug-ins to know when frames finish or fail loading. 123 class LoadListener { 124 public: ~LoadListener()125 virtual ~LoadListener() { } 126 127 virtual void didFinishLoad(WebFrame*) = 0; 128 virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0; 129 }; setLoadListener(LoadListener * loadListener)130 void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; } loadListener()131 LoadListener* loadListener() const { return m_loadListener; } 132 133 private: 134 static PassRefPtr<WebFrame> create(); 135 WebFrame(); 136 137 void init(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*); 138 type()139 virtual Type type() const { return APIType; } 140 141 WebCore::Frame* m_coreFrame; 142 143 uint64_t m_policyListenerID; 144 WebCore::FramePolicyFunction m_policyFunction; 145 uint64_t m_policyDownloadID; 146 147 WebFrameLoaderClient m_frameLoaderClient; 148 LoadListener* m_loadListener; 149 150 uint64_t m_frameID; 151 }; 152 153 } // namespace WebKit 154 155 #endif // WebFrame_h 156