accessible/src/mac/mozHTMLAccessible.mm

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:expandtab:shiftwidth=2:tabstop=2:
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #import "mozHTMLAccessible.h"
    10 #import "Accessible-inl.h"
    11 #import "HyperTextAccessible.h"
    13 #import "nsCocoaUtils.h"
    15 @implementation mozHeadingAccessible
    17 - (NSString*)title
    18 {
    19   nsAutoString title;
    20   // XXX use the flattening API when there are available
    21   // see bug 768298
    22   mGeckoAccessible->GetContent()->GetTextContent(title);
    24   return nsCocoaUtils::ToNSString(title);
    25 }
    27 - (id)value
    28 {
    29   if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText())
    30     return nil;
    32   uint32_t level = mGeckoAccessible->AsHyperText()->GetLevelInternal();
    33   return [NSNumber numberWithInt:level];
    34 }
    36 @end
    38 @interface mozLinkAccessible ()
    39 -(NSURL*)url;
    40 @end
    42 @implementation mozLinkAccessible
    44 - (NSArray*)accessibilityAttributeNames
    45 {
    46   // if we're expired, we don't support any attributes.
    47   if (!mGeckoAccessible)
    48     return [NSArray array];
    50   static NSMutableArray* attributes = nil;
    52   if (!attributes) {
    53     attributes = [[super accessibilityAttributeNames] mutableCopy];
    54     [attributes addObject:NSAccessibilityURLAttribute];
    55   }
    57   return attributes;
    58 }
    60 - (id)accessibilityAttributeValue:(NSString *)attribute
    61 {
    62   if ([attribute isEqualToString:NSAccessibilityURLAttribute])
    63     return [self url];
    65   return [super accessibilityAttributeValue:attribute];
    66 }
    68 - (NSArray*)accessibilityActionNames 
    69 {
    70     // if we're expired, we don't support any attributes.
    71   if (!mGeckoAccessible)
    72     return [NSArray array];
    74   static NSArray* actionNames = nil;
    76   if (!actionNames) {
    77     actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction,
    78                                    nil];
    79   }
    81   return actionNames;
    82 }
    84 - (void)accessibilityPerformAction:(NSString*)action 
    85 {
    86   if (!mGeckoAccessible)
    87     return;
    89   if ([action isEqualToString:NSAccessibilityPressAction])
    90     mGeckoAccessible->DoAction(0);
    91   else
    92     [super accessibilityPerformAction:action];
    93 }
    95 - (NSString*)customDescription
    96 {
    97   return @"";
    98 }
   100 - (NSString*)value
   101 {
   102   return @"";
   103 }
   105 - (NSURL*)url
   106 {
   107   if (!mGeckoAccessible || mGeckoAccessible->IsDefunct())
   108     return nil;
   110   nsAutoString value;
   111   mGeckoAccessible->Value(value);
   113   NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value);
   114   if (!urlString)
   115     return nil;
   117   return [NSURL URLWithString:urlString];
   118 }
   120 @end

mercurial