WebFrame.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #ifndef WebFrame_h
  26. #define WebFrame_h
  27. #include "APIObject.h"
  28. #include "ImmutableArray.h"
  29. #include "WKBase.h"
  30. #include "WebFrameLoaderClient.h"
  31. #include <JavaScriptCore/JSBase.h>
  32. #include <WebCore/FrameLoaderClient.h>
  33. #include <WebCore/FrameLoaderTypes.h>
  34. #include <WebCore/PolicyChecker.h>
  35. #include <wtf/Forward.h>
  36. #include <wtf/PassRefPtr.h>
  37. #include <wtf/RefPtr.h>
  38. #include <wtf/RetainPtr.h>
  39. namespace WebCore {
  40. class Frame;
  41. class HTMLFrameOwnerElement;
  42. class IntPoint;
  43. class IntRect;
  44. class KURL;
  45. }
  46. namespace WebKit {
  47. class InjectedBundleHitTestResult;
  48. class InjectedBundleNodeHandle;
  49. class InjectedBundleRangeHandle;
  50. class InjectedBundleScriptWorld;
  51. class WebPage;
  52. class WebFrame : public TypedAPIObject<APIObject::TypeBundleFrame> {
  53. public:
  54. static PassRefPtr<WebFrame> createMainFrame(WebPage*);
  55. static PassRefPtr<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
  56. ~WebFrame();
  57. // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down.
  58. void invalidate();
  59. WebPage* page() const;
  60. WebCore::Frame* coreFrame() const { return m_coreFrame; }
  61. uint64_t frameID() const { return m_frameID; }
  62. uint64_t setUpPolicyListener(WebCore::FramePolicyFunction);
  63. void invalidatePolicyListener();
  64. void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyAction, uint64_t downloadID);
  65. void startDownload(const WebCore::ResourceRequest&);
  66. void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
  67. String source() const;
  68. String contentsAsString() const;
  69. String selectionAsString() const;
  70. WebCore::IntSize size() const;
  71. // WKBundleFrame API and SPI functions
  72. bool isMainFrame() const;
  73. String name() const;
  74. String url() const;
  75. String innerText() const;
  76. bool isFrameSet() const;
  77. WebFrame* parentFrame() const;
  78. PassRefPtr<ImmutableArray> childFrames();
  79. JSGlobalContextRef jsContext();
  80. JSGlobalContextRef jsContextForWorld(InjectedBundleScriptWorld*);
  81. WebCore::IntRect contentBounds() const;
  82. WebCore::IntRect visibleContentBounds() const;
  83. WebCore::IntRect visibleContentBoundsExcludingScrollbars() const;
  84. WebCore::IntSize scrollOffset() const;
  85. bool hasHorizontalScrollbar() const;
  86. bool hasVerticalScrollbar() const;
  87. PassRefPtr<InjectedBundleHitTestResult> hitTest(const WebCore::IntPoint) const;
  88. bool getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha);
  89. bool containsAnyFormElements() const;
  90. bool containsAnyFormControls() const;
  91. void stopLoading();
  92. bool handlesPageScaleGesture() const;
  93. static WebFrame* frameForContext(JSContextRef);
  94. JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*);
  95. JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*);
  96. static String counterValue(JSObjectRef element);
  97. String layerTreeAsText() const;
  98. unsigned pendingUnloadCount() const;
  99. bool allowsFollowingLink(const WebCore::KURL&) const;
  100. String provisionalURL() const;
  101. String suggestedFilenameForResourceWithURL(const WebCore::KURL&) const;
  102. String mimeTypeForResourceWithURL(const WebCore::KURL&) const;
  103. void setTextDirection(const String&);
  104. // Simple listener class used by plug-ins to know when frames finish or fail loading.
  105. class LoadListener {
  106. public:
  107. virtual ~LoadListener() { }
  108. virtual void didFinishLoad(WebFrame*) = 0;
  109. virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0;
  110. };
  111. void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
  112. LoadListener* loadListener() const { return m_loadListener; }
  113. #if PLATFORM(MAC)
  114. typedef bool (*FrameFilterFunction)(WKBundleFrameRef, WKBundleFrameRef subframe, void* context);
  115. RetainPtr<CFDataRef> webArchiveData(FrameFilterFunction, void* context);
  116. #endif
  117. private:
  118. static PassRefPtr<WebFrame> create();
  119. WebFrame();
  120. void init(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
  121. WebCore::Frame* m_coreFrame;
  122. uint64_t m_policyListenerID;
  123. WebCore::FramePolicyFunction m_policyFunction;
  124. uint64_t m_policyDownloadID;
  125. WebFrameLoaderClient m_frameLoaderClient;
  126. LoadListener* m_loadListener;
  127. uint64_t m_frameID;
  128. };
  129. } // namespace WebKit
  130. #endif // WebFrame_h