extern "C" NS_EXPORT jobject JNICALL
GRE_NATIVE(lockProfileDirectory) (JNIEnv* env, jobject, jobject aDirectory)
{
  nsresult rv = NS_ERROR_FAILURE;

  if (aDirectory) {
    nsCOMPtr<nsIFile> profileDir;
    rv = File_to_nsILocalFile(env, aDirectory, getter_AddRefs(profileDir));

    if (NS_SUCCEEDED(rv)) {
      nsISupports* lock;
      rv = XRE_LockProfileDirectory(profileDir, &lock);

      if (NS_SUCCEEDED(rv)) {
        jclass clazz =
            env->FindClass("org/mozilla/xpcom/ProfileLock");
        if (clazz) {
          jmethodID mid = env->GetMethodID(clazz, "<init>", "(J)V");
          if (mid) {
            return env->NewObject(clazz, mid, reinterpret_cast<jlong>(lock));
          }
        }

        // if we get here, then something failed
        rv = NS_ERROR_FAILURE;
      }
    }
  }

  ThrowException(env, rv, "Failure in lockProfileDirectory");
  return nullptr;
}
extern "C" NS_EXPORT
nsISupports* LockDir(nsIFile *directory)
{
  nsISupports* lockfile = nullptr;
  XRE_LockProfileDirectory(directory, &lockfile);
  return lockfile;
}
Esempio n. 3
0
void xxxNeverCalledXUL()
{
  XRE_main(0, nsnull, nsnull);
  XRE_GetFileFromPath(nsnull, nsnull);
  XRE_GetStaticComponents(nsnull, nsnull);
  XRE_LockProfileDirectory(nsnull, nsnull);
  XRE_InitEmbedding(nsnull, nsnull, nsnull, nsnull, 0);
  XRE_NotifyProfile();
  XRE_TermEmbedding();
  XRE_CreateAppData(nsnull, nsnull);
  XRE_ParseAppData(nsnull, nsnull);
  XRE_FreeAppData(nsnull);
}
Esempio n. 4
0
/* static */
void
EmbedPrivate::PushStartup(void)
{
  // increment the number of widgets
  sWidgetCount++;

  // if this is the first widget, fire up xpcom
  if (sWidgetCount == 1) {
    nsresult rv;

    nsCOMPtr<nsILocalFile> binDir;
    if (sCompPath) {
      rv = NS_NewNativeLocalFile(nsDependentCString(sCompPath), 1, getter_AddRefs(binDir));
      if (NS_FAILED(rv))
	return;
    }

    const char *grePath = sPath;

    if (!grePath)
      grePath = getenv("MOZILLA_FIVE_HOME");

    if (!grePath)
      return;

    nsCOMPtr<nsILocalFile> greDir;
    rv = NS_NewNativeLocalFile(nsDependentCString(grePath), PR_TRUE,
                               getter_AddRefs(greDir));
    if (NS_FAILED(rv))
      return;

    if (sProfileDir && !sProfileLock) {
      rv = XRE_LockProfileDirectory(sProfileDir,
                                    &sProfileLock);
      if (NS_FAILED(rv)) return;
    }

    rv = XRE_InitEmbedding(greDir, binDir,
                           const_cast<GTKEmbedDirectoryProvider*>(&kDirectoryProvider),
                           nsnull, nsnull);
    if (NS_FAILED(rv))
      return;

    if (sProfileDir)
      XRE_NotifyProfile();

    rv = RegisterAppComponents();
    NS_ASSERTION(NS_SUCCEEDED(rv), "Warning: Failed to register app components.\n");
  }
}
Esempio n. 5
0
/* static */
void
EmbedPrivate::SetProfilePath(const char *aDir, const char *aName)
{
  if (sProfileDir) {
    if (sWidgetCount) {
      NS_ERROR("Cannot change profile directory during run.");
      return;
    }

    NS_RELEASE(sProfileDir);
    NS_RELEASE(sProfileLock);
  }

  nsresult rv =
    NS_NewNativeLocalFile(nsDependentCString(aDir), PR_TRUE, &sProfileDir);

  if (NS_SUCCEEDED(rv) && aName)
    rv = sProfileDir->AppendNative(nsDependentCString(aName));

  if (NS_SUCCEEDED(rv)) {
    PRBool exists = PR_FALSE;
    rv = sProfileDir->Exists(&exists);
    if (!exists)
      rv = sProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
    rv = XRE_LockProfileDirectory(sProfileDir, &sProfileLock);
  }

  if (NS_SUCCEEDED(rv)) {
    if (sWidgetCount)
      XRE_NotifyProfile();

    return;
  }

  NS_WARNING("Failed to lock profile.");

  // Failed
  NS_IF_RELEASE(sProfileDir);
  NS_IF_RELEASE(sProfileLock);
}