widget/windows/winrt/UIAAccessibilityBridge.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #pragma once
     8 #if defined(ACCESSIBILITY)
    10 #include "nsCOMPtr.h"
    11 #include "nsIObserver.h"
    12 #include "nsIObserverService.h"
    13 #include "nsServiceManagerUtils.h"
    14 #include "mozilla/a11y/Accessible.h"
    16 #include "mozwrlbase.h"
    18 namespace mozilla {
    19 namespace widget {
    20 namespace winrt {
    22 // Connects to our accessibility framework to receive
    23 // events and query the dom.
    24 class AccessibilityBridge : public nsIObserver
    25 {
    26 public:
    27   NS_DECL_ISUPPORTS
    28   NS_DECL_NSIOBSERVER
    30   AccessibilityBridge() {}
    32   ~AccessibilityBridge() {
    33     Disconnect();
    34   }
    36   bool Init(IUnknown* aBridge, mozilla::a11y::Accessible* aPtr) {
    37     mAccess = aPtr;
    38     mBridge = aBridge;
    39     return Connect();
    40   }
    42   bool Connect() {
    43     nsresult rv;
    45     nsCOMPtr<nsIObserverService> observerService = 
    46       do_GetService("@mozilla.org/observer-service;1", &rv);
    47     if (NS_FAILED(rv)) {
    48       return false;
    49     }
    50     rv = observerService->AddObserver(this, "accessible-event", false);
    51     if (NS_FAILED(rv)) {
    52       return false;
    53     }
    54     return true;
    55   }
    57   bool Connected() {
    58     return mAccess ? true : false;
    59   }
    61   void Disconnect() {
    62     nsresult rv;
    63     nsCOMPtr<nsIObserverService> observerService = 
    64       do_GetService("@mozilla.org/observer-service;1", &rv);
    65     if (NS_FAILED(rv)) {
    66       NS_WARNING("failed to get observersvc on shutdown.");
    67       return;
    68     }
    69     observerService->RemoveObserver(this, "accessible-event");
    70     mAccess = nullptr;
    71   }
    73 private:
    74   nsRefPtr<mozilla::a11y::Accessible> mAccess;
    75   Microsoft::WRL::ComPtr<IUnknown> mBridge;
    76 };
    78 } } }
    80 #endif // ACCESSIBILITY

mercurial