Exemplo n.º 1
0
static PRBool
CopyUpdaterIntoUpdateDir(nsIFile *greDir, nsIFile *appDir, nsIFile *updateDir,
                         nsCOMPtr<nsIFile> &updater)
{
    // Copy the updater application from the GRE and the updater ini from the app
#if defined(XP_MACOSX)
    if (!CopyFileIntoUpdateDir(greDir, kUpdaterApp, updateDir))
        return PR_FALSE;
#else
    if (!CopyFileIntoUpdateDir(greDir, kUpdaterBin, updateDir))
        return PR_FALSE;
#endif
    CopyFileIntoUpdateDir(appDir, kUpdaterINI, updateDir);
#if defined(XP_UNIX) && !defined(XP_MACOSX)
    nsCOMPtr<nsIFile> iconDir;
    appDir->Clone(getter_AddRefs(iconDir));
    iconDir->AppendNative(NS_LITERAL_CSTRING("icons"));
    if (!CopyFileIntoUpdateDir(iconDir, kUpdaterPNG, updateDir))
        return PR_FALSE;
#endif
    // Finally, return the location of the updater binary.
    nsresult rv = updateDir->Clone(getter_AddRefs(updater));
    if (NS_FAILED(rv))
        return PR_FALSE;
#if defined(XP_MACOSX)
    rv  = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterApp));
    rv |= updater->AppendNative(NS_LITERAL_CSTRING("Contents"));
    rv |= updater->AppendNative(NS_LITERAL_CSTRING("MacOS"));
    if (NS_FAILED(rv))
        return PR_FALSE;
#endif
    rv = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterBin));
    return NS_SUCCEEDED(rv);
}
Exemplo n.º 2
0
// (static) Obtains the ICO file for the favicon at page aFaviconPageURI
// If successful, the file path on disk is in the format:
// <ProfLDS>\jumpListCache\<hash(aFaviconPageURI)>.ico
nsresult FaviconHelper::GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
  nsCOMPtr<nsIFile> &aICOFile,
  bool aURLShortcut)
{
  // Hash the input URI and replace any / with _
  nsAutoCString inputURIHash;
  nsCOMPtr<nsICryptoHash> cryptoHash;
  nsresult rv = HashURI(cryptoHash, aFaviconPageURI,
                        inputURIHash);
  NS_ENSURE_SUCCESS(rv, rv);
  char* cur = inputURIHash.BeginWriting();
  char* end = inputURIHash.EndWriting();
  for (; cur < end; ++cur) {
    if ('/' == *cur) {
      *cur = '_';
    }
  }

  // Obtain the local profile directory and construct the output icon file path
  rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(aICOFile));
  NS_ENSURE_SUCCESS(rv, rv);
  if (!aURLShortcut)
    rv = aICOFile->AppendNative(nsDependentCString(kJumpListCacheDir));
  else
    rv = aICOFile->AppendNative(nsDependentCString(kShortcutCacheDir));
  NS_ENSURE_SUCCESS(rv, rv);

  // Append the icon extension
  inputURIHash.AppendLiteral(".ico");
  rv = aICOFile->AppendNative(inputURIHash);

  return rv;
}
Exemplo n.º 3
0
// (static) Obtains the ICO file for the favicon at page aFaviconPageURI
// If successful, the file path on disk is in the format:
// <ProfLDS>\jumpListCache\<hash(aFaviconPageURI)>.ico
nsresult JumpListShortcut::GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
        nsCOMPtr<nsIFile> &aICOFile)
{
    // Hash the input URI and replace any / with _
    nsCAutoString inputURIHash;
    nsCOMPtr<nsICryptoHash> cryptoHash;
    nsresult rv = JumpListItem::HashURI(cryptoHash, aFaviconPageURI,
                                        inputURIHash);
    NS_ENSURE_SUCCESS(rv, rv);
    char* cur = inputURIHash.BeginWriting();
    char* end = inputURIHash.EndWriting();
    for (; cur < end; ++cur) {
        if ('/' == *cur) {
            *cur = '_';
        }
    }

    // Obtain the local profile directory and construct the output icon file path
    rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(aICOFile));
    NS_ENSURE_SUCCESS(rv, rv);
    rv = aICOFile->AppendNative(nsDependentCString(JumpListItem::kJumpListCacheDir));
    NS_ENSURE_SUCCESS(rv, rv);

    // Try to create the directory if it's not there yet
    rv = aICOFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
    if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS) {
        return rv;
    }

    // Append the icon extension
    inputURIHash.Append(".ico");
    rv = aICOFile->AppendNative(inputURIHash);

    return rv;
}
Exemplo n.º 4
0
static PRBool
CopyUpdaterIntoUpdateDir(nsIFile *greDir, nsIFile *appDir, nsIFile *updateDir,
                         nsCOMPtr<nsIFile> &updater)
{
  // We have to move the updater binary and its resource file.
  const char *filesToMove[] = {
#if defined(XP_MACOSX)
    kUpdaterApp,
#else
    kUpdaterINI,
    kUpdaterBin,
#endif
    nsnull
  };

  nsresult rv;

  for (const char **leafName = filesToMove; *leafName; ++leafName) {
    nsDependentCString leaf(*leafName);
    nsCOMPtr<nsIFile> file;

    // Make sure there is not an existing file in the target location.
    rv = updateDir->Clone(getter_AddRefs(file));
    if (NS_FAILED(rv))
      return PR_FALSE;
    rv = file->AppendNative(leaf);
    if (NS_FAILED(rv))
      return PR_FALSE;
    file->Remove(PR_FALSE);

    // Now, copy into the target location.
    rv = greDir->Clone(getter_AddRefs(file));
    if (NS_FAILED(rv))
      return PR_FALSE;
    rv = file->AppendNative(leaf);
    if (NS_FAILED(rv))
      return PR_FALSE;
    rv = file->CopyToNative(updateDir, EmptyCString());
    if (*leafName != kUpdaterINI && NS_FAILED(rv))
      return PR_FALSE;
  }
  
  // Finally, return the location of the updater binary.
  rv = updateDir->Clone(getter_AddRefs(updater));
  if (NS_FAILED(rv))
    return PR_FALSE;
#if defined(XP_MACOSX)
  rv  = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterApp));
  rv |= updater->AppendNative(NS_LITERAL_CSTRING("Contents"));
  rv |= updater->AppendNative(NS_LITERAL_CSTRING("MacOS"));
  if (NS_FAILED(rv))
    return PR_FALSE;
#endif
  rv = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterBin));
  return NS_SUCCEEDED(rv); 
}
Exemplo n.º 5
0
nsresult InitEmbedding(const char* aProfilePath, const char* aEmbedPath)
{
    nsresult rv;

    ++gInitCount;
    if (gInitCount > 1)
        return NS_OK;

    // Find the GRE (xul shared lib). We are only using frozen interfaces, so we
    // should be compatible all the way up to (but not including) mozilla 2.0
    static const GREVersionRange vr = {
        "1.9a1",
        PR_TRUE,
        "2.0",
        PR_FALSE
    };
    // find xpcom shared lib (uses GRE_HOME env var if set)
    char temp[MAX_PATH];
    rv = GRE_GetGREPathWithProperties(&vr, 1, nsnull, 0, temp, sizeof(temp));
    string xpcomPath(temp);
    cout << "xpcom: " << xpcomPath << endl;

    if (NS_FAILED(rv)) {
        cerr << "Unable to find GRE, try setting GRE_HOME." << endl;
        //return 1;
	xpcomPath = aEmbedPath;
    }

    // start the glue, i.e. load and link against xpcom shared lib
    rv = XPCOMGlueStartup(xpcomPath.c_str());
    if (NS_FAILED(rv)) {
        cerr << "Could not start XPCOM glue." << endl;
        return 2;
    }

    // get rid of the bogus TLS warnings
    NS_LogInit();

    // load XUL functions
    nsDynamicFunctionLoad nsFuncs[] = {
            {"XRE_InitEmbedding2", (NSFuncPtr*)&XRE_InitEmbedding2},
            {"XRE_TermEmbedding", (NSFuncPtr*)&XRE_TermEmbedding},
            {"XRE_NotifyProfile", (NSFuncPtr*)&XRE_NotifyProfile},
            {"XRE_LockProfileDirectory", (NSFuncPtr*)&XRE_LockProfileDirectory},
            {0, 0}
    };

    rv = XPCOMGlueLoadXULFunctions(nsFuncs);
    if (NS_FAILED(rv)) {
        cerr << "Could not load XUL functions." << endl;
        return 4;
    }

    // strip the filename from xpcom so we have the dir instead
    size_t lastslash = xpcomPath.find_last_of("/\\");
    if (lastslash == string::npos) {
        cerr << "Invalid path to xpcom:" << xpcomPath << "." << endl;
        return 3;
    }
    string xpcomDir = xpcomPath.substr(0, lastslash);

    // create nsILocalFile pointing to xpcomDir
    nsCOMPtr<nsILocalFile> xuldir;
    rv = NS_NewNativeLocalFile(nsCString(xpcomDir.c_str()), PR_FALSE,
                               getter_AddRefs(xuldir));
    if (NS_FAILED(rv)) {
        cerr << "Unable to create nsILocalFile for xuldir " << xpcomDir
             << "." << endl;
        return 6;
    }

    // create nsILocalFile pointing to appdir
    char self[MAX_PATH];
#ifdef WIN32
    GetModuleFileNameA(GetModuleHandle(NULL), self, sizeof(self));
#else
    // TODO: works on linux, need solution for unices which do not support this
    ssize_t len;
    if ((len = readlink("/proc/self/exe", self, sizeof(self)-1)) != -1)
        self[len] = '\0';
#endif
    string selfPath(self);
    lastslash = selfPath.find_last_of("/\\");
    if (lastslash == string::npos) {
        cerr << "Invalid module filename: " << self << "." << endl;
        return 7;
    }

    selfPath = selfPath.substr(0, lastslash);

    nsCOMPtr<nsILocalFile> appdir;
    rv = NS_NewNativeLocalFile(nsCString(selfPath.c_str()), PR_FALSE,
                               getter_AddRefs(appdir));
    if (NS_FAILED(rv)) {
        cerr << "Unable to create nsILocalFile for appdir." << endl;
        return 8;
    }

    // setup profile dir
    nsCString pr(aProfilePath);
    if (!pr.IsEmpty()) {
        rv = NS_NewNativeLocalFile(pr, PR_FALSE,
                                   getter_AddRefs(sProfileDir));
        NS_ENSURE_SUCCESS(rv, rv);
    } else {
        // for now use a subdir under appdir
        nsCOMPtr<nsIFile> profFile;
        rv = appdir->Clone(getter_AddRefs(profFile));
        NS_ENSURE_SUCCESS(rv, rv);
        sProfileDir = do_QueryInterface(profFile);
        sProfileDir->AppendNative(NS_LITERAL_CSTRING("mozembed"));
    }

    // create dir if needed
    PRBool dirExists;
    rv = sProfileDir->Exists(&dirExists);
    NS_ENSURE_SUCCESS(rv, rv);
    if (!dirExists) {
        sProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
    }

    // Lock profile directory
    if (sProfileDir && !sProfileLock) {
        rv = XRE_LockProfileDirectory(sProfileDir, &sProfileLock);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    // init embedding
    rv = XRE_InitEmbedding2(xuldir, appdir,
                           const_cast<MozEmbedDirectoryProvider*>(&kDirectoryProvider));
    if (NS_FAILED(rv)) {
        cerr << "XRE_InitEmbedding2 failed." << endl;
        return 9;
    }

    // initialize profile:
    XRE_NotifyProfile();

    NS_LogTerm();

    return NS_OK;
}