tor-browser

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

XRPermissionRequest.cpp (2308B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "XRPermissionRequest.h"
      8 
      9 #include "mozilla/Preferences.h"
     10 #include "mozilla/dom/Document.h"
     11 #include "nsContentUtils.h"
     12 #include "nsGlobalWindowInner.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 //-------------------------------------------------
     17 // XR Permission Requests
     18 //-------------------------------------------------
     19 
     20 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(XRPermissionRequest,
     21                                               ContentPermissionRequestBase)
     22 
     23 NS_IMPL_CYCLE_COLLECTION_INHERITED(XRPermissionRequest,
     24                                   ContentPermissionRequestBase)
     25 
     26 XRPermissionRequest::XRPermissionRequest(nsPIDOMWindowInner* aWindow,
     27                                         uint64_t aWindowId)
     28    : ContentPermissionRequestBase(aWindow->GetDoc()->NodePrincipal(), aWindow,
     29                                   "dom.vr"_ns, "xr"_ns),
     30      mWindowId(aWindowId) {
     31  MOZ_ASSERT(aWindow);
     32  MOZ_ASSERT(aWindow->GetDoc());
     33  mPrincipal = aWindow->GetDoc()->NodePrincipal();
     34  MOZ_ASSERT(mPrincipal);
     35 }
     36 
     37 NS_IMETHODIMP
     38 XRPermissionRequest::Cancel() {
     39  nsGlobalWindowInner* window =
     40      nsGlobalWindowInner::GetInnerWindowWithId(mWindowId);
     41  if (!window) {
     42    return NS_OK;
     43  }
     44  window->OnXRPermissionRequestCancel();
     45  return NS_OK;
     46 }
     47 
     48 NS_IMETHODIMP
     49 XRPermissionRequest::Allow(JS::Handle<JS::Value> aChoices) {
     50  MOZ_ASSERT(aChoices.isUndefined());
     51  nsGlobalWindowInner* window =
     52      nsGlobalWindowInner::GetInnerWindowWithId(mWindowId);
     53  if (!window) {
     54    return NS_OK;
     55  }
     56  window->OnXRPermissionRequestAllow();
     57  return NS_OK;
     58 }
     59 
     60 nsresult XRPermissionRequest::Start() {
     61  MOZ_ASSERT(NS_IsMainThread());
     62  if (!CheckPermissionDelegate()) {
     63    return Cancel();
     64  }
     65  PromptResult pr = CheckPromptPrefs();
     66  if (pr == PromptResult::Granted) {
     67    return Allow(JS::UndefinedHandleValue);
     68  }
     69  if (pr == PromptResult::Denied) {
     70    return Cancel();
     71  }
     72 
     73  return nsContentPermissionUtils::AskPermission(this, mWindow);
     74 }
     75 
     76 }  // namespace mozilla::dom