1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_DOM_DOCUMENT_IMPL_H_ 6 #define CEF_LIBCEF_DOM_DOCUMENT_IMPL_H_ 7 #pragma once 8 9 #include <map> 10 #include "include/cef_dom.h" 11 12 namespace blink { 13 class WebLocalFrame; 14 class WebNode; 15 } // namespace blink 16 17 class CefBrowserImpl; 18 19 class CefDOMDocumentImpl : public CefDOMDocument { 20 public: 21 CefDOMDocumentImpl(CefBrowserImpl* browser, blink::WebLocalFrame* frame); 22 ~CefDOMDocumentImpl() override; 23 24 // CefDOMDocument methods. 25 Type GetType() override; 26 CefRefPtr<CefDOMNode> GetDocument() override; 27 CefRefPtr<CefDOMNode> GetBody() override; 28 CefRefPtr<CefDOMNode> GetHead() override; 29 CefString GetTitle() override; 30 CefRefPtr<CefDOMNode> GetElementById(const CefString& id) override; 31 CefRefPtr<CefDOMNode> GetFocusedNode() override; 32 bool HasSelection() override; 33 int GetSelectionStartOffset() override; 34 int GetSelectionEndOffset() override; 35 CefString GetSelectionAsMarkup() override; 36 CefString GetSelectionAsText() override; 37 CefString GetBaseURL() override; 38 CefString GetCompleteURL(const CefString& partialURL) override; 39 GetBrowser()40 CefBrowserImpl* GetBrowser() { return browser_; } GetFrame()41 blink::WebLocalFrame* GetFrame() { return frame_; } 42 43 // The document maintains a map of all existing node objects. 44 CefRefPtr<CefDOMNode> GetOrCreateNode(const blink::WebNode& node); 45 void RemoveNode(const blink::WebNode& node); 46 47 // Must be called before the object is destroyed. 48 void Detach(); 49 50 // Verify that the object exists and is being accessed on the UI thread. 51 bool VerifyContext(); 52 53 protected: 54 CefBrowserImpl* browser_; 55 blink::WebLocalFrame* frame_; 56 57 using NodeMap = std::map<blink::WebNode, CefDOMNode*>; 58 NodeMap node_map_; 59 60 IMPLEMENT_REFCOUNTING(CefDOMDocumentImpl); 61 }; 62 63 #endif // CEF_LIBCEF_DOM_DOCUMENT_IMPL_H_ 64