web_document.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_DOCUMENT_H_
  31. #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_DOCUMENT_H_
  32. #include "net/cookies/site_for_cookies.h"
  33. #include "services/metrics/public/cpp/ukm_source_id.h"
  34. #include "services/network/public/mojom/referrer_policy.mojom-shared.h"
  35. #include "third_party/blink/public/platform/web_security_origin.h"
  36. #include "third_party/blink/public/platform/web_vector.h"
  37. #include "third_party/blink/public/web/web_draggable_region.h"
  38. #include "third_party/blink/public/web/web_frame.h"
  39. #include "third_party/blink/public/web/web_node.h"
  40. #include "third_party/skia/include/core/SkColor.h"
  41. namespace blink {
  42. class Document;
  43. class WebElement;
  44. class WebFormElement;
  45. class WebElementCollection;
  46. class WebString;
  47. class WebURL;
  48. struct WebDistillabilityFeatures;
  49. using WebStyleSheetKey = WebString;
  50. // Provides readonly access to some properties of a DOM document.
  51. class WebDocument : public WebNode {
  52. public:
  53. enum CSSOrigin { kAuthorOrigin, kUserOrigin };
  54. WebDocument() = default;
  55. WebDocument(const WebDocument& e) = default;
  56. WebDocument& operator=(const WebDocument& e) {
  57. WebNode::Assign(e);
  58. return *this;
  59. }
  60. void Assign(const WebDocument& e) { WebNode::Assign(e); }
  61. BLINK_EXPORT WebURL Url() const;
  62. // Note: Security checks should use the getSecurityOrigin(), not url().
  63. BLINK_EXPORT WebSecurityOrigin GetSecurityOrigin() const;
  64. BLINK_EXPORT bool IsSecureContext() const;
  65. BLINK_EXPORT WebString Encoding() const;
  66. BLINK_EXPORT WebString ContentLanguage() const;
  67. BLINK_EXPORT WebString GetReferrer() const;
  68. BLINK_EXPORT base::Optional<SkColor> ThemeColor() const;
  69. // The url of the OpenSearch Desription Document (if any).
  70. BLINK_EXPORT WebURL OpenSearchDescriptionURL() const;
  71. // Returns the frame the document belongs to or 0 if the document is
  72. // frameless.
  73. BLINK_EXPORT WebLocalFrame* GetFrame() const;
  74. BLINK_EXPORT bool IsHTMLDocument() const;
  75. BLINK_EXPORT bool IsXHTMLDocument() const;
  76. BLINK_EXPORT bool IsPluginDocument() const;
  77. BLINK_EXPORT WebURL BaseURL() const;
  78. BLINK_EXPORT ukm::SourceId GetUkmSourceId() const;
  79. // The SiteForCookies is used to compute whether this document
  80. // appears in a "third-party" context for the purpose of third-party
  81. // cookie blocking.
  82. BLINK_EXPORT net::SiteForCookies SiteForCookies() const;
  83. BLINK_EXPORT WebSecurityOrigin TopFrameOrigin() const;
  84. BLINK_EXPORT WebElement DocumentElement() const;
  85. BLINK_EXPORT WebElement Body() const;
  86. BLINK_EXPORT WebElement Head();
  87. BLINK_EXPORT WebString Title() const;
  88. BLINK_EXPORT WebString ContentAsTextForTesting() const;
  89. BLINK_EXPORT WebElementCollection All();
  90. BLINK_EXPORT WebVector<WebFormElement> Forms() const;
  91. BLINK_EXPORT WebURL CompleteURL(const WebString&) const;
  92. BLINK_EXPORT WebElement GetElementById(const WebString&) const;
  93. BLINK_EXPORT WebElement FocusedElement() const;
  94. // Inserts the given CSS source code as a style sheet in the document.
  95. BLINK_EXPORT WebStyleSheetKey InsertStyleSheet(
  96. const WebString& source_code,
  97. const WebStyleSheetKey* = nullptr,
  98. CSSOrigin = kAuthorOrigin);
  99. // Removes the CSS which was previously inserted by a call to
  100. // InsertStyleSheet().
  101. BLINK_EXPORT void RemoveInsertedStyleSheet(const WebStyleSheetKey&,
  102. CSSOrigin = kAuthorOrigin);
  103. // Arranges to call WebLocalFrameClient::didMatchCSS(frame(), ...) when one of
  104. // the selectors matches or stops matching an element in this document.
  105. // Each call to this method overrides any previous calls.
  106. BLINK_EXPORT void WatchCSSSelectors(const WebVector<WebString>& selectors);
  107. BLINK_EXPORT WebVector<WebDraggableRegion> DraggableRegions() const;
  108. BLINK_EXPORT WebURL CanonicalUrlForSharing() const;
  109. BLINK_EXPORT WebDistillabilityFeatures DistillabilityFeatures();
  110. BLINK_EXPORT void SetShowBeforeUnloadDialog(bool show_dialog);
  111. // See cc/paint/element_id.h for the definition of these id.
  112. BLINK_EXPORT uint64_t GetVisualViewportScrollingElementIdForTesting();
  113. #if INSIDE_BLINK
  114. BLINK_EXPORT WebDocument(Document*);
  115. BLINK_EXPORT WebDocument& operator=(Document*);
  116. BLINK_EXPORT operator Document*() const;
  117. #endif
  118. };
  119. DECLARE_WEB_NODE_TYPE_CASTS(WebDocument);
  120. } // namespace blink
  121. #endif