Ejemplo n.º 1
0
nsresult
nsOperaProfileMigrator::CopyProxySettings(nsINIParser &aParser,
        nsIPrefBranch* aBranch)
{
    nsresult rv;

    PRInt32 networkProxyType = 0;

    const char* protocols[] = { "HTTP", "HTTPS", "FTP"  };
    const char* protocols_l[] = { "http", "https", "ftp" };
    char toggleBuf[15], serverBuf[20], serverPrefBuf[20],
         serverPortPrefBuf[25];
    PRInt32 enabled;
    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(protocols); ++i) {
        sprintf(toggleBuf, "Use %s", protocols[i]);
        GetInteger(aParser, "Proxy", toggleBuf, &enabled);
        if (enabled) {
            // Enable the "manual configuration" setting if we have at least
            // one protocol using a Proxy.
            networkProxyType = 1;
        }

        sprintf(serverBuf, "%s Server", protocols[i]);
        nsCAutoString proxyServer;
        rv = aParser.GetString("Proxy", serverBuf, proxyServer);
        if (NS_FAILED(rv))
            continue;

        sprintf(serverPrefBuf, "network.proxy.%s", protocols_l[i]);
        sprintf(serverPortPrefBuf, "network.proxy.%s_port", protocols_l[i]);
        // strings in Opera pref. file are in UTF-8
        SetProxyPref(NS_ConvertUTF8toUTF16(proxyServer),
                     serverPrefBuf, serverPortPrefBuf, aBranch);
    }

    GetInteger(aParser, "Proxy", "Use Automatic Proxy Configuration", &enabled);
    if (enabled)
        networkProxyType = 2;

    nsCAutoString configURL;
    rv = aParser.GetString("Proxy", "Automatic Proxy Configuration URL",
                           configURL);
    if (NS_SUCCEEDED(rv))
        aBranch->SetCharPref("network.proxy.autoconfig_url", configURL.get());

    GetInteger(aParser, "Proxy", "No Proxy Servers Check", &enabled);
    if (enabled) {
        nsCAutoString servers;
        rv = aParser.GetString("Proxy", "No Proxy Servers", servers);
        if (NS_SUCCEEDED(rv))
            // strings in Opera pref. file are in UTF-8
            ParseOverrideServers(NS_ConvertUTF8toUTF16(servers), aBranch);
    }

    aBranch->SetIntPref("network.proxy.type", networkProxyType);

    return NS_OK;
}
Ejemplo n.º 2
0
static void
RegisterExtensionInterpositions(nsINIParser &parser)
{
  if (!mozilla::Preferences::GetBool("extensions.interposition.enabled", false))
    return;

  nsCOMPtr<nsIAddonInterposition> interposition =
    do_GetService("@mozilla.org/addons/multiprocess-shims;1");

  nsresult rv;
  int32_t i = 0;
  do {
    nsAutoCString buf("Extension");
    buf.AppendInt(i++);

    nsAutoCString addonId;
    rv = parser.GetString("MultiprocessIncompatibleExtensions", buf.get(), addonId);
    if (NS_FAILED(rv))
      return;

    if (!xpc::SetAddonInterposition(addonId, interposition))
      continue;
  }
  while (true);
}
Ejemplo n.º 3
0
nsresult
nsOperaProfileMigrator::CopyUserContentSheet(nsINIParser &aParser)
{
    nsresult rv;

    nsCAutoString userContentCSS;
    rv = aParser.GetString("User Prefs", "Local CSS File", userContentCSS);
    if (NS_FAILED(rv) || userContentCSS.Length() == 0)
        return NS_OK;

    // Copy the file
    nsCOMPtr<nsILocalFile> userContentCSSFile;
    rv = NS_NewNativeLocalFile(userContentCSS, PR_TRUE,
                               getter_AddRefs(userContentCSSFile));
    if (NS_FAILED(rv))
        return NS_OK;

    PRBool exists;
    rv = userContentCSSFile->Exists(&exists);
    if (NS_FAILED(rv) || !exists)
        return NS_OK;

    nsCOMPtr<nsIFile> profileChromeDir;
    NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
                           getter_AddRefs(profileChromeDir));
    if (!profileChromeDir)
        return NS_OK;

    userContentCSSFile->CopyToNative(profileChromeDir,
                                     NS_LITERAL_CSTRING("userContent.css"));

    return NS_OK;
}
Ejemplo n.º 4
0
static void
LoadExtensionDirectories(nsINIParser &parser,
                         const char *aSection,
                         nsCOMArray<nsIFile> &aDirectories,
                         NSLocationType aType)
{
  nsresult rv;
  PRInt32 i = 0;
  do {
    nsCAutoString buf("Extension");
    buf.AppendInt(i++);

    nsCAutoString path;
    rv = parser.GetString(aSection, buf.get(), path);
    if (NS_FAILED(rv))
      return;

    nsCOMPtr<nsILocalFile> dir = do_CreateInstance("@mozilla.org/file/local;1", &rv);
    if (NS_FAILED(rv))
      continue;

    rv = dir->SetPersistentDescriptor(path);
    if (NS_FAILED(rv))
      continue;

    aDirectories.AppendObject(dir);

    nsCOMPtr<nsILocalFile> manifest =
      CloneAndAppend(dir, "chrome.manifest");
    XRE_AddManifestLocation(aType, manifest);
  }
  while (PR_TRUE);
}
Ejemplo n.º 5
0
NS_IMETHODIMP
nsINIParserImpl::GetString(const nsACString& aSection,
                           const nsACString& aKey,
                           nsACString& aResult)
{
  return mParser.GetString(PromiseFlatCString(aSection).get(),
                           PromiseFlatCString(aKey).get(),
                           aResult);
}
static void
ReadStrings(nsINIParser &parser, const ReadString *reads)
{
  nsresult rv;
  nsCString str;

  while (reads->section) {
    rv = parser.GetString(reads->section, reads->key, str);
    if (NS_SUCCEEDED(rv)) {
      SetAllocatedString(*reads->buffer, str);
    }

    ++reads;
  }
}
Ejemplo n.º 7
0
nsresult
nsOperaProfileMigrator::GetInteger(nsINIParser &aParser,
                                   const char* aSectionName,
                                   const char* aKeyName,
                                   PRInt32* aResult)
{
    nsCAutoString val;

    nsresult rv = aParser.GetString(aSectionName, aKeyName, val);
    if (NS_FAILED(rv))
        return rv;

    *aResult = val.ToInteger(&rv);

    return rv;
}
Ejemplo n.º 8
0
NS_IMETHODIMP
nsINIParserImpl::GetSections(nsIUTF8StringEnumerator* *aResult)
{
  nsTArray<nsCString> *strings = new nsTArray<nsCString>;
  if (!strings)
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv = mParser.GetSections(SectionCB, strings);
  if (NS_SUCCEEDED(rv))
    rv = NS_NewAdoptingUTF8StringEnumerator(aResult, strings);

  if (NS_FAILED(rv))
    delete strings;

  return rv;
}
Ejemplo n.º 9
0
static void
LoadExtensionDirectories(nsINIParser &parser,
                         const char *aSection,
                         nsCOMArray<nsIFile> &aDirectories,
                         NSLocationType aType)
{
  nsresult rv;
  PRInt32 i = 0;
  nsCOMPtr<nsIPrefServiceInternal> prefs =
    do_GetService("@mozilla.org/preferences-service;1");
  do {
    nsCAutoString buf("Extension");
    buf.AppendInt(i++);

    nsCAutoString path;
    rv = parser.GetString(aSection, buf.get(), path);
    if (NS_FAILED(rv))
      return;

    nsCOMPtr<nsILocalFile> dir = do_CreateInstance("@mozilla.org/file/local;1", &rv);
    if (NS_FAILED(rv))
      continue;

    rv = dir->SetPersistentDescriptor(path);
    if (NS_FAILED(rv))
      continue;

    if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_CSTRING(".xpi"))) {
      XRE_AddJarManifestLocation(aType, dir);
      if (!prefs)
        continue;
      prefs->ReadExtensionPrefs(dir);
    }
    else {
      aDirectories.AppendObject(dir);

      nsCOMPtr<nsILocalFile> manifest =
        CloneAndAppend(dir, "chrome.manifest");
      XRE_AddManifestLocation(aType, manifest);
    }
  }
  while (PR_TRUE);
}
Ejemplo n.º 10
0
NS_IMETHODIMP
nsINIParserImpl::GetKeys(const nsACString& aSection,
                         nsIUTF8StringEnumerator* *aResult)
{
  nsTArray<nsCString> *strings = new nsTArray<nsCString>;
  if (!strings)
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv = mParser.GetStrings(PromiseFlatCString(aSection).get(),
                                   KeyCB, strings);
  if (NS_SUCCEEDED(rv))
    rv = NS_NewAdoptingUTF8StringEnumerator(aResult, strings);

  if (NS_FAILED(rv))
    delete strings;

  return rv;

}
static void
ReadFlags(nsINIParser &parser, const ReadFlag *reads, uint32_t *buffer)
{
  nsresult rv;
  char buf[6]; // large enough to hold "false"

  while (reads->section) {
    rv = parser.GetString(reads->section, reads->key, buf, sizeof(buf));
    if (NS_SUCCEEDED(rv) || rv == NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
      if (buf[0] == '1' || buf[0] == 't' || buf[0] == 'T') {
        *buffer |= reads->flag;
      }
      if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
        *buffer &= ~reads->flag;
      }
    }

    ++reads;
  }
}
Ejemplo n.º 12
0
static void
LoadExtensionDirectories(nsINIParser &parser,
                         const char *aSection,
                         nsCOMArray<nsIFile> &aDirectories,
                         NSLocationType aType)
{
  nsresult rv;
  int32_t i = 0;
  do {
    nsAutoCString buf("Extension");
    buf.AppendInt(i++);

    nsAutoCString path;
    rv = parser.GetString(aSection, buf.get(), path);
    if (NS_FAILED(rv))
      return;

    nsCOMPtr<nsIFile> dir = do_CreateInstance("@mozilla.org/file/local;1", &rv);
    if (NS_FAILED(rv))
      continue;

    rv = dir->SetPersistentDescriptor(path);
    if (NS_FAILED(rv))
      continue;

    aDirectories.AppendObject(dir);
    if (Substring(path, path.Length() - 4).EqualsLiteral(".xpi")) {
      XRE_AddJarManifestLocation(aType, dir);
    }
    else {
      nsCOMPtr<nsIFile> manifest =
        CloneAndAppend(dir, "chrome.manifest");
      XRE_AddManifestLocation(aType, manifest);
    }
  }
  while (true);
}
Ejemplo n.º 13
0
void RemoveApplication(nsINIParser& parser, const char* curExeDir, const char* profile)  {
  if (!isProfileOverridden) {
    // Remove the desktop entry file.
    char desktopEntryFilePath[MAXPATHLEN];

    char* dataDir = getenv("XDG_DATA_HOME");

    if (dataDir && *dataDir) {
      snprintf(desktopEntryFilePath, MAXPATHLEN, "%s/applications/owa-%s.desktop", dataDir, profile);
    } else {
      char* home = getenv("HOME");
      snprintf(desktopEntryFilePath, MAXPATHLEN, "%s/.local/share/applications/owa-%s.desktop", home, profile);
    }

    unlink(desktopEntryFilePath);
  }

  // Remove the files from the installation directory.
  char webAppIniPath[MAXPATHLEN];
  snprintf(webAppIniPath, MAXPATHLEN, "%s/%s", curExeDir, kWEBAPP_INI);
  unlink(webAppIniPath);

  char curExePath[MAXPATHLEN];
  snprintf(curExePath, MAXPATHLEN, "%s/%s", curExeDir, kAPP_RT);
  unlink(curExePath);

  char webAppJsonPath[MAXPATHLEN];
  snprintf(webAppJsonPath, MAXPATHLEN, "%s/%s", curExeDir, kWEBAPP_JSON);
  unlink(webAppJsonPath);

  char iconPath[MAXPATHLEN];
  snprintf(iconPath, MAXPATHLEN, "%s/icon.png", curExeDir);
  unlink(iconPath);

  char appName[MAXPATHLEN];
  if (NS_FAILED(parser.GetString("Webapp", "Name", appName, MAXPATHLEN))) {
    strcpy(appName, profile);
  }

  char uninstallMsg[MAXPATHLEN];
  if (NS_SUCCEEDED(parser.GetString("Webapp", "UninstallMsg", uninstallMsg, MAXPATHLEN))) {
    /**
     * The only difference between libnotify.so.4 and libnotify.so.1 for these symbols
     * is that notify_notification_new takes three arguments in libnotify.so.4 and
     * four in libnotify.so.1.
     * Passing the fourth argument as NULL is binary compatible.
     */
    typedef void  (*notify_init_t)(const char*);
    typedef void* (*notify_notification_new_t)(const char*, const char*, const char*, const char*);
    typedef void  (*notify_notification_show_t)(void*, void**);

    void *handle = dlopen("libnotify.so.4", RTLD_LAZY);
    if (!handle) {
      handle = dlopen("libnotify.so.1", RTLD_LAZY);
      if (!handle)
        return;
    }

    notify_init_t nn_init = (notify_init_t)(uintptr_t)dlsym(handle, "notify_init");
    notify_notification_new_t nn_new = (notify_notification_new_t)(uintptr_t)dlsym(handle, "notify_notification_new");
    notify_notification_show_t nn_show = (notify_notification_show_t)(uintptr_t)dlsym(handle, "notify_notification_show");
    if (!nn_init || !nn_new || !nn_show) {
      dlclose(handle);
      return;
    }

    nn_init(appName);

    void* n = nn_new(uninstallMsg, NULL, "dialog-information", NULL);

    nn_show(n, NULL);

    dlclose(handle);
  }
}