web_frame.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (C) 2009 Google 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 are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_FRAME_H_
  31. #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_FRAME_H_
  32. #include <memory>
  33. #include "cc/paint/paint_canvas.h"
  34. #include "third_party/blink/public/common/tokens/tokens.h"
  35. #include "third_party/blink/public/mojom/frame/tree_scope_type.mojom-shared.h"
  36. #include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-shared.h"
  37. #include "third_party/blink/public/platform/web_common.h"
  38. #include "third_party/blink/public/web/web_frame_load_type.h"
  39. #include "third_party/blink/public/web/web_node.h"
  40. #include "v8/include/v8.h"
  41. namespace blink {
  42. class Frame;
  43. class WebLocalFrame;
  44. class WebRemoteFrame;
  45. class WebSecurityOrigin;
  46. class WebView;
  47. // Frames may be rendered in process ('local') or out of process ('remote').
  48. // A remote frame is always cross-site; a local frame may be either same-site or
  49. // cross-site.
  50. // WebFrame is the base class for both WebLocalFrame and WebRemoteFrame and
  51. // contains methods that are valid on both local and remote frames, such as
  52. // getting a frame's parent or its opener.
  53. class BLINK_EXPORT WebFrame {
  54. public:
  55. // FIXME: We already have blink::TextGranularity. For now we support only
  56. // a part of blink::TextGranularity.
  57. // Ideally it seems blink::TextGranularity should be broken up into
  58. // blink::TextGranularity and perhaps blink::TextBoundary and then
  59. // TextGranularity enum could be moved somewhere to public/, and we could
  60. // just use it here directly without introducing a new enum.
  61. enum TextGranularity {
  62. kCharacterGranularity = 0,
  63. kWordGranularity,
  64. kTextGranularityLast = kWordGranularity,
  65. };
  66. // Returns the number of live WebFrame objects, used for leak checking.
  67. static int InstanceCount();
  68. // TODO(crbug.com/1096617): Remove the UnguessableToken version of this.
  69. static WebFrame* FromFrameToken(const base::UnguessableToken&);
  70. static WebFrame* FromFrameToken(const FrameToken&);
  71. virtual bool IsWebLocalFrame() const = 0;
  72. virtual WebLocalFrame* ToWebLocalFrame() = 0;
  73. virtual bool IsWebRemoteFrame() const = 0;
  74. virtual WebRemoteFrame* ToWebRemoteFrame() = 0;
  75. bool Swap(WebFrame*);
  76. // This method closes and deletes the WebFrame. This is typically called by
  77. // the embedder in response to a frame detached callback to the WebFrame
  78. // client.
  79. virtual void Close();
  80. // Called by the embedder when it needs to detach the subtree rooted at this
  81. // frame.
  82. void Detach();
  83. // Basic properties ---------------------------------------------------
  84. // The security origin of this frame.
  85. WebSecurityOrigin GetSecurityOrigin() const;
  86. // The frame's insecure request policy.
  87. mojom::InsecureRequestPolicy GetInsecureRequestPolicy() const;
  88. // The frame's upgrade insecure navigations set.
  89. WebVector<unsigned> GetInsecureRequestToUpgrade() const;
  90. // Hierarchy ----------------------------------------------------------
  91. // Returns the containing view.
  92. virtual WebView* View() const = 0;
  93. // Returns the frame that opened this frame or 0 if there is none.
  94. WebFrame* Opener() const;
  95. // Reset the frame that opened this frame to 0.
  96. // This is executed between web tests runs
  97. void ClearOpener();
  98. // Returns the parent frame or 0 if this is a top-most frame.
  99. // TODO(sashab): "Virtual" is needed here temporarily to resolve linker errors
  100. // in core/. Remove the "virtual" keyword once WebFrame and WebLocalFrameImpl
  101. // have been moved to core/.
  102. virtual WebFrame* Parent() const;
  103. // Returns the top-most frame in the hierarchy containing this frame.
  104. WebFrame* Top() const;
  105. // Returns the first child frame.
  106. WebFrame* FirstChild() const;
  107. // Returns the last child frame.
  108. WebFrame* LastChild() const;
  109. // Returns the next sibling frame.
  110. WebFrame* NextSibling() const;
  111. // Returns the previous sibling frame.
  112. WebFrame* PreviousSibling() const;
  113. // Returns the next frame in "frame traversal order".
  114. WebFrame* TraverseNext() const;
  115. // Scripting ----------------------------------------------------------
  116. // Returns the global proxy object.
  117. virtual v8::Local<v8::Object> GlobalProxy() const = 0;
  118. // Returns true if the WebFrame currently executing JavaScript has access
  119. // to the given WebFrame, or false otherwise.
  120. static bool ScriptCanAccess(WebFrame*);
  121. // Navigation ----------------------------------------------------------
  122. // Will return true if between didStartLoading and didStopLoading
  123. // notifications.
  124. virtual bool IsLoading() const;
  125. // Utility -------------------------------------------------------------
  126. // Returns the frame inside a given frame or iframe element. Returns 0 if
  127. // the given node is not a frame, iframe or if the frame is empty.
  128. static WebFrame* FromFrameOwnerElement(const WebNode&);
  129. // This identifier represents the stable identifier between a
  130. // LocalFrame <--> RenderFrameHostImpl or a
  131. // RemoteFrame <--> RenderFrameProxyHost in the browser process.
  132. // TODO(crbug.com/1096617): Make this return a FrameToken instead.
  133. const base::UnguessableToken& GetFrameToken() const { return frame_token_; }
  134. #if INSIDE_BLINK
  135. // TODO(mustaq): Should be named FromCoreFrame instead.
  136. static WebFrame* FromFrame(Frame*);
  137. static Frame* ToCoreFrame(const WebFrame&);
  138. bool InShadowTree() const { return scope_ == mojom::TreeScopeType::kShadow; }
  139. #endif
  140. protected:
  141. explicit WebFrame(mojom::TreeScopeType,
  142. const base::UnguessableToken& frame_token);
  143. virtual ~WebFrame() = default;
  144. private:
  145. const mojom::TreeScopeType scope_;
  146. // See blink::Frame::frame_token_ for comments.
  147. // TODO(dtapuska): Remove the need for this variable. This is stored here
  148. // because a WebRemote's core frame is created inside the bowels of the Swap
  149. // call.
  150. const base::UnguessableToken frame_token_;
  151. };
  152. } // namespace blink
  153. #endif