| 1 | /* |
| 2 | * Copyright (C) 2010-2016 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 | #pragma once |
| 27 | |
| 28 | #include "APIObject.h" |
| 29 | #include "DownloadID.h" |
| 30 | #include "ShareableBitmap.h" |
| 31 | #include "WKBase.h" |
| 32 | #include "WebFrameLoaderClient.h" |
| 33 | #include <JavaScriptCore/ConsoleTypes.h> |
| 34 | #include <JavaScriptCore/JSBase.h> |
| 35 | #include <WebCore/FrameLoaderClient.h> |
| 36 | #include <WebCore/FrameLoaderTypes.h> |
| 37 | #include <wtf/Forward.h> |
| 38 | #include <wtf/HashMap.h> |
| 39 | #include <wtf/RefPtr.h> |
| 40 | #include <wtf/RetainPtr.h> |
| 41 | |
| 42 | namespace API { |
| 43 | class Array; |
| 44 | } |
| 45 | |
| 46 | namespace PAL { |
| 47 | class SessionID; |
| 48 | } |
| 49 | |
| 50 | namespace WebCore { |
| 51 | class CertificateInfo; |
| 52 | class Frame; |
| 53 | class HTMLFrameOwnerElement; |
| 54 | class IntPoint; |
| 55 | class IntRect; |
| 56 | } |
| 57 | |
| 58 | namespace WebKit { |
| 59 | |
| 60 | class InjectedBundleHitTestResult; |
| 61 | class InjectedBundleNodeHandle; |
| 62 | class InjectedBundleRangeHandle; |
| 63 | class InjectedBundleScriptWorld; |
| 64 | class WebPage; |
| 65 | struct FrameInfoData; |
| 66 | struct WebsitePoliciesData; |
| 67 | |
| 68 | class WebFrame : public API::ObjectImpl<API::Object::Type::BundleFrame> { |
| 69 | public: |
| 70 | static Ref<WebFrame> createWithCoreMainFrame(WebPage*, WebCore::Frame*); |
| 71 | static Ref<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*); |
| 72 | ~WebFrame(); |
| 73 | |
| 74 | // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down. |
| 75 | void invalidate(); |
| 76 | |
| 77 | WebPage* page() const; |
| 78 | |
| 79 | static WebFrame* fromCoreFrame(WebCore::Frame&); |
| 80 | WebCore::Frame* coreFrame() const { return m_coreFrame; } |
| 81 | |
| 82 | FrameInfoData info() const; |
| 83 | uint64_t frameID() const { return m_frameID; } |
| 84 | |
| 85 | enum class ForNavigationAction { No, Yes }; |
| 86 | uint64_t setUpPolicyListener(WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&, ForNavigationAction); |
| 87 | void invalidatePolicyListener(); |
| 88 | void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyCheckIdentifier, WebCore::PolicyAction, uint64_t navigationID, DownloadID, Optional<WebsitePoliciesData>&&); |
| 89 | |
| 90 | uint64_t setUpWillSubmitFormListener(CompletionHandler<void()>&&); |
| 91 | void continueWillSubmitForm(uint64_t); |
| 92 | |
| 93 | void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = { }); |
| 94 | void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, PAL::SessionID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&); |
| 95 | |
| 96 | void addConsoleMessage(MessageSource, MessageLevel, const String&, uint64_t requestID = 0); |
| 97 | |
| 98 | String source() const; |
| 99 | String contentsAsString() const; |
| 100 | String selectionAsString() const; |
| 101 | |
| 102 | WebCore::IntSize size() const; |
| 103 | |
| 104 | // WKBundleFrame API and SPI functions |
| 105 | bool isMainFrame() const; |
| 106 | String name() const; |
| 107 | URL url() const; |
| 108 | WebCore::CertificateInfo certificateInfo() const; |
| 109 | String innerText() const; |
| 110 | bool isFrameSet() const; |
| 111 | WebFrame* parentFrame() const; |
| 112 | Ref<API::Array> childFrames(); |
| 113 | JSGlobalContextRef jsContext(); |
| 114 | JSGlobalContextRef jsContextForWorld(InjectedBundleScriptWorld*); |
| 115 | WebCore::IntRect contentBounds() const; |
| 116 | WebCore::IntRect visibleContentBounds() const; |
| 117 | WebCore::IntRect visibleContentBoundsExcludingScrollbars() const; |
| 118 | WebCore::IntSize scrollOffset() const; |
| 119 | bool hasHorizontalScrollbar() const; |
| 120 | bool hasVerticalScrollbar() const; |
| 121 | RefPtr<InjectedBundleHitTestResult> hitTest(const WebCore::IntPoint) const; |
| 122 | bool getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha); |
| 123 | bool containsAnyFormElements() const; |
| 124 | bool containsAnyFormControls() const; |
| 125 | void stopLoading(); |
| 126 | bool handlesPageScaleGesture() const; |
| 127 | bool requiresUnifiedScaleFactor() const; |
| 128 | void setAccessibleName(const String&); |
| 129 | |
| 130 | static WebFrame* frameForContext(JSContextRef); |
| 131 | |
| 132 | JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*); |
| 133 | JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*); |
| 134 | |
| 135 | static String counterValue(JSObjectRef element); |
| 136 | |
| 137 | String layerTreeAsText() const; |
| 138 | |
| 139 | unsigned pendingUnloadCount() const; |
| 140 | |
| 141 | bool allowsFollowingLink(const URL&) const; |
| 142 | |
| 143 | String provisionalURL() const; |
| 144 | String suggestedFilenameForResourceWithURL(const URL&) const; |
| 145 | String mimeTypeForResourceWithURL(const URL&) const; |
| 146 | |
| 147 | void setTextDirection(const String&); |
| 148 | |
| 149 | void documentLoaderDetached(uint64_t navigationID); |
| 150 | |
| 151 | // Simple listener class used by plug-ins to know when frames finish or fail loading. |
| 152 | class LoadListener { |
| 153 | public: |
| 154 | virtual ~LoadListener() { } |
| 155 | |
| 156 | virtual void didFinishLoad(WebFrame*) = 0; |
| 157 | virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0; |
| 158 | }; |
| 159 | void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; } |
| 160 | LoadListener* loadListener() const { return m_loadListener; } |
| 161 | |
| 162 | #if PLATFORM(COCOA) |
| 163 | typedef bool (*FrameFilterFunction)(WKBundleFrameRef, WKBundleFrameRef subframe, void* context); |
| 164 | RetainPtr<CFDataRef> webArchiveData(FrameFilterFunction, void* context); |
| 165 | #endif |
| 166 | |
| 167 | RefPtr<ShareableBitmap> createSelectionSnapshot() const; |
| 168 | |
| 169 | #if PLATFORM(IOS_FAMILY) |
| 170 | uint64_t firstLayerTreeTransactionIDAfterDidCommitLoad() const { return m_firstLayerTreeTransactionIDAfterDidCommitLoad; } |
| 171 | void setFirstLayerTreeTransactionIDAfterDidCommitLoad(uint64_t transactionID) { m_firstLayerTreeTransactionIDAfterDidCommitLoad = transactionID; } |
| 172 | #endif |
| 173 | |
| 174 | private: |
| 175 | static Ref<WebFrame> create(std::unique_ptr<WebFrameLoaderClient>); |
| 176 | explicit WebFrame(std::unique_ptr<WebFrameLoaderClient>); |
| 177 | |
| 178 | WebCore::Frame* m_coreFrame { nullptr }; |
| 179 | |
| 180 | uint64_t m_policyListenerID { 0 }; |
| 181 | Optional<WebCore::PolicyCheckIdentifier> m_policyIdentifier; |
| 182 | WebCore::FramePolicyFunction m_policyFunction; |
| 183 | ForNavigationAction m_policyFunctionForNavigationAction { ForNavigationAction::No }; |
| 184 | HashMap<uint64_t, CompletionHandler<void()>> m_willSubmitFormCompletionHandlers; |
| 185 | DownloadID m_policyDownloadID { 0 }; |
| 186 | |
| 187 | std::unique_ptr<WebFrameLoaderClient> m_frameLoaderClient; |
| 188 | LoadListener* m_loadListener { nullptr }; |
| 189 | |
| 190 | uint64_t m_frameID { 0 }; |
| 191 | |
| 192 | #if PLATFORM(IOS_FAMILY) |
| 193 | uint64_t m_firstLayerTreeTransactionIDAfterDidCommitLoad { 0 }; |
| 194 | #endif |
| 195 | }; |
| 196 | |
| 197 | } // namespace WebKit |
| 198 | |