Home | History | Annotate | Download | only in web
      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 
     31 #ifndef WebDocument_h
     32 #define WebDocument_h
     33 
     34 #include "../platform/WebReferrerPolicy.h"
     35 #include "../platform/WebVector.h"
     36 #include "WebDraggableRegion.h"
     37 #include "WebExceptionCode.h"
     38 #include "WebNode.h"
     39 #include "WebSecurityOrigin.h"
     40 
     41 #if BLINK_IMPLEMENTATION
     42 namespace WebCore {
     43 class Document;
     44 class DocumentType;
     45 }
     46 namespace WTF { template <typename T> class PassRefPtr; }
     47 #endif
     48 
     49 namespace v8 {
     50 class Value;
     51 template <class T> class Handle;
     52 }
     53 
     54 namespace blink {
     55 class WebAXObject;
     56 class WebDocumentType;
     57 class WebElement;
     58 class WebFormElement;
     59 class WebFrame;
     60 class WebNodeCollection;
     61 class WebNodeList;
     62 class WebString;
     63 class WebURL;
     64 
     65 // Provides readonly access to some properties of a DOM document.
     66 class WebDocument : public WebNode {
     67 public:
     68     // FIXME: Stop using this from Chromium code and get rid of this enum.
     69     enum UserStyleLevel {
     70         UserStyleAuthorLevel
     71     };
     72 
     73     WebDocument() { }
     74     WebDocument(const WebDocument& e) : WebNode(e) { }
     75 
     76     WebDocument& operator=(const WebDocument& e)
     77     {
     78         WebNode::assign(e);
     79         return *this;
     80     }
     81     void assign(const WebDocument& e) { WebNode::assign(e); }
     82 
     83     BLINK_EXPORT WebURL url() const;
     84     // Note: Security checks should use the securityOrigin(), not url().
     85     BLINK_EXPORT WebSecurityOrigin securityOrigin() const;
     86 
     87     BLINK_EXPORT WebString encoding() const;
     88     BLINK_EXPORT WebString contentLanguage() const;
     89     BLINK_EXPORT WebString referrer() const;
     90 
     91     // The url of the OpenSearch Desription Document (if any).
     92     BLINK_EXPORT WebURL openSearchDescriptionURL() const;
     93 
     94     // Returns the frame the document belongs to or 0 if the document is frameless.
     95     BLINK_EXPORT WebFrame* frame() const;
     96     BLINK_EXPORT bool isHTMLDocument() const;
     97     BLINK_EXPORT bool isXHTMLDocument() const;
     98     BLINK_EXPORT bool isPluginDocument() const;
     99     BLINK_EXPORT WebURL baseURL() const;
    100 
    101     // The firstPartyForCookies is used to compute whether this document
    102     // appears in a "third-party" context for the purpose of third-party
    103     // cookie blocking.
    104     BLINK_EXPORT WebURL firstPartyForCookies() const;
    105 
    106     BLINK_EXPORT WebElement documentElement() const;
    107     BLINK_EXPORT WebElement body() const;
    108     BLINK_EXPORT WebElement head();
    109     BLINK_EXPORT WebString title() const;
    110     BLINK_EXPORT WebNodeCollection all();
    111     BLINK_EXPORT void forms(WebVector<WebFormElement>&) const;
    112     BLINK_EXPORT void images(WebVector<WebElement>&);
    113     BLINK_EXPORT WebURL completeURL(const WebString&) const;
    114     BLINK_EXPORT WebElement getElementById(const WebString&) const;
    115     BLINK_EXPORT WebNode focusedNode() const;
    116     BLINK_EXPORT WebDocumentType doctype() const;
    117     BLINK_EXPORT void cancelFullScreen();
    118     BLINK_EXPORT WebElement fullScreenElement() const;
    119     BLINK_EXPORT WebDOMEvent createEvent(const WebString& eventType);
    120     BLINK_EXPORT WebReferrerPolicy referrerPolicy() const;
    121     BLINK_EXPORT WebElement createElement(const WebString& tagName);
    122 
    123     // Accessibility support. These methods should only be called on the
    124     // top-level document, because one accessibility cache spans all of
    125     // the documents on the page.
    126 
    127     // Gets the accessibility object for this document.
    128     BLINK_EXPORT WebAXObject accessibilityObject() const;
    129 
    130     // Gets the accessibility object for an object on this page by ID.
    131     BLINK_EXPORT WebAXObject accessibilityObjectFromID(int axID) const;
    132     // Inserts the given CSS source code as a stylesheet in the document.
    133     // FIXME: Delete insertUserStyleSheet once Chromium code stops calling it.
    134     BLINK_EXPORT void insertUserStyleSheet(const WebString& sourceCode, UserStyleLevel);
    135     BLINK_EXPORT void insertStyleSheet(const WebString& sourceCode);
    136 
    137     // Arranges to call WebFrameClient::didMatchCSS(frame(), ...) when one of
    138     // the selectors matches or stops matching an element in this document.
    139     // Each call to this method overrides any previous calls.
    140     BLINK_EXPORT void watchCSSSelectors(const WebVector<WebString>& selectors);
    141 
    142     BLINK_EXPORT WebVector<WebDraggableRegion> draggableRegions() const;
    143 
    144     BLINK_EXPORT v8::Handle<v8::Value> registerEmbedderCustomElement(const WebString& name, v8::Handle<v8::Value> options, WebExceptionCode&);
    145 
    146 #if BLINK_IMPLEMENTATION
    147     WebDocument(const WTF::PassRefPtr<WebCore::Document>&);
    148     WebDocument& operator=(const WTF::PassRefPtr<WebCore::Document>&);
    149     operator WTF::PassRefPtr<WebCore::Document>() const;
    150 #endif
    151 };
    152 
    153 } // namespace blink
    154 
    155 #endif
    156