LCOV - code coverage report
Current view: directory - src/trusted/nonnacl_util/osx - get_plugin_dirname.mm (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 21 0 0.0 %
Date: 2014-06-18 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright 2008 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can
       4                 :  * be found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #include <libgen.h>
       8                 : #include <string.h>
       9                 : #include <unistd.h>
      10                 : 
      11                 : #import <Cocoa/Cocoa.h>
      12                 : 
      13                 : #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h"
      14                 : 
      15                 : // TODO(polina): we need this to avoid hardcoding the bundle name, but it
      16                 : // causes the following error when building chrome:
      17                 : // ld: duplicate symbol nacl::PluginSelLdrLocator::GetDirectory(char*,
      18                 : // unsigned long) in
      19                 : // chrome/src/xcodebuild/Debug/libsel_ldr_launcher.a(get_plugin_dirname.o) and
      20                 : // chrome/src/xcodebuild/Debug/libnonnacl_util_chrome.a(get_plugin_dirname.o)
      21                 : //
      22                 : // Dummy class object to be used with bundleForClass below.
      23                 : //@interface Dummy: NSObject {}
      24                 : //@end
      25                 : //@implementation Dummy
      26                 : //@end
      27                 : 
      28                 : namespace nacl {
      29                 : 
      30                 : // For OSX we get the bundle pathname to the browser plugin or the main bundle.
      31                 : // The returned pointer refers to static storage, so this function is not
      32                 : // reentrant, but that's okay.
      33               0 : void PluginSelLdrLocator::GetDirectory(char* buffer, size_t len) {
      34                 :   // Guard our temporary objects below with our own autorelease pool.
      35                 :   // (We cannot guarantee this is being called from a thread with a pool.)
      36               0 :   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
      37                 : 
      38                 :   // Find the executable path for the bundle the plugin was loaded from.
      39                 :   // Expect the sel_ldr to be within the bundle directory.
      40               0 :   NSString* ident = @"com.google.npGoogleNaClPlugin";  // Id from Info.plist.
      41               0 :   NSString* nspath = [[NSBundle bundleWithIdentifier:ident]
      42                 :                       pathForResource:@"sel_ldr" ofType:nil];
      43                 :   // TODO(polina): enable this instead when the error caused by Dummy is fixed
      44                 :   // NSString* nspath = [[NSBundle bundleForClass:[Dummy class] ]
      45                 :   //                     pathForResource:@"sel_ldr" ofType:nil];
      46                 : 
      47                 :   // Convert it to a C string.
      48               0 :   char const* pathname = [nspath fileSystemRepresentation];
      49                 :   // If we were not able to find the plugin bundle, try the main bundle.
      50                 :   // This is necessary to support sel_universal, and possibly other apps
      51                 :   // using the launcher.
      52               0 :   if (NULL == pathname) {
      53               0 :     nspath = [[NSBundle mainBundle] pathForResource:@"sel_ldr" ofType:nil];
      54               0 :     pathname = [nspath fileSystemRepresentation];
      55               0 :   }
      56                 : 
      57               0 :   if (NULL == pathname) {
      58               0 :     [pool release];
      59               0 :     buffer[0] = '\0';
      60               0 :   } else {
      61                 :     // And strip off the dll name, returning only the path, or NULL if error.
      62               0 :     strncpy(buffer,  pathname, len - 1);
      63               0 :     buffer[len - 1] = '\0';
      64               0 :     [pool release];
      65               0 :     char* path_end = strrchr(buffer, '/');
      66               0 :     if (NULL != path_end) {
      67               0 :       *path_end = '\0';
      68               0 :     }
      69                 :   }
      70               0 : }
      71                 : 
      72                 : }  // namespace nacl

Generated by: LCOV version 1.7