tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AnonymousContent.cpp (1842B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "AnonymousContent.h"
      8 
      9 #include "mozilla/dom/AnonymousContentBinding.h"
     10 #include "mozilla/dom/Document.h"
     11 #include "mozilla/dom/Element.h"
     12 #include "mozilla/dom/ShadowRoot.h"
     13 #include "nsCycleCollectionParticipant.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 // Ref counting and cycle collection
     18 NS_IMPL_CYCLE_COLLECTION(AnonymousContent, mHost, mRoot)
     19 
     20 already_AddRefed<AnonymousContent> AnonymousContent::Create(Document& aDoc) {
     21  RefPtr<Element> host = aDoc.CreateHTMLElement(nsGkAtoms::div);
     22  if (!host) {
     23    return nullptr;
     24  }
     25  host->SetAttr(kNameSpaceID_None, nsGkAtoms::role, u"presentation"_ns, false);
     26  host->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
     27                u"anonymous-content-host"_ns, false);
     28  RefPtr<ShadowRoot> root = host->AttachShadowWithoutNameChecks(
     29      ShadowRootMode::Closed, Element::DelegatesFocus::No);
     30  root->SetIsUAWidget();
     31  return do_AddRef(new AnonymousContent(host.forget(), root.forget()));
     32 }
     33 
     34 AnonymousContent::AnonymousContent(already_AddRefed<Element> aHost,
     35                                   already_AddRefed<ShadowRoot> aRoot)
     36    : mHost(aHost), mRoot(aRoot) {
     37  MOZ_ASSERT(mHost);
     38  MOZ_ASSERT(mRoot);
     39 }
     40 
     41 AnonymousContent::~AnonymousContent() = default;
     42 
     43 bool AnonymousContent::WrapObject(JSContext* aCx,
     44                                  JS::Handle<JSObject*> aGivenProto,
     45                                  JS::MutableHandle<JSObject*> aReflector) {
     46  return AnonymousContent_Binding::Wrap(aCx, this, aGivenProto, aReflector);
     47 }
     48 }  // namespace mozilla::dom