/* static */ already_AddRefed<Promise>
FileCreatorHelper::CreateFile(nsIGlobalObject* aGlobalObject,
                              nsIFile* aFile,
                              const ChromeFilePropertyBag& aBag,
                              bool aIsFromNsIFile,
                              ErrorResult& aRv)
{
  MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());

  RefPtr<Promise> promise = Promise::Create(aGlobalObject, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return nullptr;
  }

  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobalObject);

  // Parent process

  if (XRE_IsParentProcess()) {
    RefPtr<File> file =
      CreateFileInternal(window, aFile, aBag, aIsFromNsIFile, aRv);
    if (aRv.Failed()) {
      return nullptr;
    }
    promise->MaybeResolve(file);
    return promise.forget();
  }

  // Content process.

  ContentChild* cc = ContentChild::GetSingleton();
  if (!cc) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
    return promise.forget();
  }

  if (!cc->GetRemoteType().EqualsLiteral(FILE_REMOTE_TYPE) &&
      !Preferences::GetBool("dom.file.createInChild", false)) {
    // If this pref is not set and the request is received by the parent
    // process, this child is killed for security reason.
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
    return promise.forget();
  }

  RefPtr<FileCreatorHelper> helper = new FileCreatorHelper(promise, window);

  // The request is sent to the parent process and it's kept alive by
  // ContentChild.
  helper->SendRequest(aFile, aBag, aIsFromNsIFile, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return nullptr;
  }

  return promise.forget();
}
Esempio n. 2
0
IResFile* gkResFileManager::loadResFileExec( const TCHAR* pszFilename, bool searchDir /*= false*/, bool loadheader )
{
	TCHAR szFullPath[MAX_PATH] = _T("");
	if (searchDir && gEnv->pSystem->IsEditor())
	{

		HRESULT hr = gkFindFileRelativeExec(szFullPath, MAX_PATH, pszFilename);
		if ( hr == S_OK)
		{
			_tcscpy( szFullPath, gkGetExecRelativePath( szFullPath ).c_str() );
		}
		else
		{
			_tcscpy( szFullPath, pszFilename );
		}		
	}
	else
	{
		_tcscat( szFullPath, pszFilename );
	}

	return CreateFileInternal(szFullPath, loadheader);

}