summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer/firefox_importer_utils_mac.mm
blob: bea6b71e7a38bef72d80e8136e06917dc0676685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <Cocoa/Cocoa.h>

#include "chrome/browser/importer/firefox_importer_utils.h"

#include "base/file_util.h"

FilePath GetProfilesINI() {
  FilePath ini_file;
  NSArray* dirs =
      NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
                                          NSUserDomainMask, YES);
  if ([dirs count]) {
    NSString* app_support_dir = [dirs objectAtIndex:0];
    NSString* firefox_dir = [app_support_dir
        stringByAppendingPathComponent:@"Firefox"];
    NSString* profiles_ini = [firefox_dir
        stringByAppendingPathComponent:@"profiles.ini"];
    if (profiles_ini) {
      ini_file = FilePath([profiles_ini fileSystemRepresentation]);
    }
  }

  if (file_util::PathExists(ini_file))
    return ini_file;

  return FilePath();
}

FilePath GetFirefoxDylibPath() {
  CFURLRef appURL = nil;
  if (LSFindApplicationForInfo(kLSUnknownCreator,
                              CFSTR("org.mozilla.firefox"),
                              NULL,
                              NULL,
                              &appURL) != noErr) {
    return FilePath();
  }
  NSBundle *ff_bundle = [NSBundle
      bundleWithPath:[reinterpret_cast<const NSURL*>(appURL) path]];
  CFRelease(appURL);
  NSString *ff_library_path = [[ff_bundle executablePath]
                                  stringByDeletingLastPathComponent];

  return FilePath([ff_library_path fileSystemRepresentation]);
}