toolkit/system/gnome/nsGnomeVFSService.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsGnomeVFSService.h"
     7 #include "nsStringAPI.h"
     8 #include "nsIURI.h"
     9 #include "nsTArray.h"
    10 #include "nsIStringEnumerator.h"
    11 #include "nsAutoPtr.h"
    13 extern "C" {
    14 #include <libgnomevfs/gnome-vfs.h>
    15 #include <libgnomevfs/gnome-vfs-mime.h>
    16 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
    17 }
    19 class nsGnomeVFSMimeApp MOZ_FINAL : public nsIGnomeVFSMimeApp
    20 {
    21 public:
    22   NS_DECL_ISUPPORTS
    23   NS_DECL_NSIGNOMEVFSMIMEAPP
    25   nsGnomeVFSMimeApp(GnomeVFSMimeApplication* aApp) : mApp(aApp) {}
    26   ~nsGnomeVFSMimeApp() { gnome_vfs_mime_application_free(mApp); }
    28 private:
    29   GnomeVFSMimeApplication *mApp;
    30 };
    32 NS_IMPL_ISUPPORTS(nsGnomeVFSMimeApp, nsIGnomeVFSMimeApp)
    34 NS_IMETHODIMP
    35 nsGnomeVFSMimeApp::GetId(nsACString& aId)
    36 {
    37   aId.Assign(mApp->id);
    38   return NS_OK;
    39 }
    41 NS_IMETHODIMP
    42 nsGnomeVFSMimeApp::GetName(nsACString& aName)
    43 {
    44   aName.Assign(mApp->name);
    45   return NS_OK;
    46 }
    48 NS_IMETHODIMP
    49 nsGnomeVFSMimeApp::GetCommand(nsACString& aCommand)
    50 {
    51   aCommand.Assign(mApp->command);
    52   return NS_OK;
    53 }
    55 NS_IMETHODIMP
    56 nsGnomeVFSMimeApp::GetCanOpenMultipleFiles(bool* aCanOpen)
    57 {
    58   *aCanOpen = mApp->can_open_multiple_files;
    59   return NS_OK;
    60 }
    62 NS_IMETHODIMP
    63 nsGnomeVFSMimeApp::GetExpectsURIs(int32_t* aExpects)
    64 {
    65   *aExpects = mApp->expects_uris;
    66   return NS_OK;
    67 }
    69 NS_IMETHODIMP
    70 nsGnomeVFSMimeApp::Launch(const nsACString &aUri)
    71 {
    72   char *uri = gnome_vfs_make_uri_from_input(PromiseFlatCString(aUri).get());
    74   if (! uri)
    75     return NS_ERROR_FAILURE;
    77   GList uris = { 0 };
    78   uris.data = uri;
    80   GnomeVFSResult result = gnome_vfs_mime_application_launch(mApp, &uris);
    81   g_free(uri);
    83   if (result != GNOME_VFS_OK)
    84     return NS_ERROR_FAILURE;
    86   return NS_OK;
    87 }
    89 class UTF8StringEnumerator MOZ_FINAL : public nsIUTF8StringEnumerator
    90 {
    91 public:
    92   UTF8StringEnumerator() : mIndex(0) { }
    93   ~UTF8StringEnumerator() { }
    95   NS_DECL_ISUPPORTS
    96   NS_DECL_NSIUTF8STRINGENUMERATOR
    98   nsTArray<nsCString> mStrings;
    99   uint32_t            mIndex;
   100 };
   102 NS_IMPL_ISUPPORTS(UTF8StringEnumerator, nsIUTF8StringEnumerator)
   104 NS_IMETHODIMP
   105 UTF8StringEnumerator::HasMore(bool *aResult)
   106 {
   107   *aResult = mIndex < mStrings.Length();
   108   return NS_OK;
   109 }
   111 NS_IMETHODIMP
   112 UTF8StringEnumerator::GetNext(nsACString& aResult)
   113 {
   114   if (mIndex >= mStrings.Length())
   115     return NS_ERROR_UNEXPECTED;
   117   aResult.Assign(mStrings[mIndex]);
   118   ++mIndex;
   119   return NS_OK;
   120 }
   122 NS_IMETHODIMP
   123 nsGnomeVFSMimeApp::GetSupportedURISchemes(nsIUTF8StringEnumerator** aSchemes)
   124 {
   125   *aSchemes = nullptr;
   127   nsRefPtr<UTF8StringEnumerator> array = new UTF8StringEnumerator();
   128   NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
   130   for (GList *list = mApp->supported_uri_schemes; list; list = list->next) {
   131     if (!array->mStrings.AppendElement((char*) list->data)) {
   132       return NS_ERROR_OUT_OF_MEMORY;
   133     }
   134   }
   136   NS_ADDREF(*aSchemes = array);
   137   return NS_OK;
   138 }
   140 NS_IMETHODIMP
   141 nsGnomeVFSMimeApp::GetRequiresTerminal(bool* aRequires)
   142 {
   143   *aRequires = mApp->requires_terminal;
   144   return NS_OK;
   145 }
   147 nsresult
   148 nsGnomeVFSService::Init()
   149 {
   150   return gnome_vfs_init() ? NS_OK : NS_ERROR_FAILURE;
   151 }
   153 NS_IMPL_ISUPPORTS(nsGnomeVFSService, nsIGnomeVFSService)
   155 NS_IMETHODIMP
   156 nsGnomeVFSService::GetMimeTypeFromExtension(const nsACString &aExtension,
   157                                             nsACString& aMimeType)
   158 {
   159   nsAutoCString fileExtToUse(".");
   160   fileExtToUse.Append(aExtension);
   162   const char *mimeType = gnome_vfs_mime_type_from_name(fileExtToUse.get());
   163   aMimeType.Assign(mimeType);
   165   // |mimeType| points to internal gnome-vfs data, so don't free it.
   167   return NS_OK;
   168 }
   170 NS_IMETHODIMP
   171 nsGnomeVFSService::GetAppForMimeType(const nsACString &aMimeType,
   172                                      nsIGnomeVFSMimeApp** aApp)
   173 {
   174   *aApp = nullptr;
   175   GnomeVFSMimeApplication *app =
   176    gnome_vfs_mime_get_default_application(PromiseFlatCString(aMimeType).get());
   178   if (app) {
   179     nsGnomeVFSMimeApp *mozApp = new nsGnomeVFSMimeApp(app);
   180     NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
   182     NS_ADDREF(*aApp = mozApp);
   183   }
   185   return NS_OK;
   186 }
   188 NS_IMETHODIMP
   189 nsGnomeVFSService::GetDescriptionForMimeType(const nsACString &aMimeType,
   190                                              nsACString& aDescription)
   191 {
   192   const char *desc =
   193     gnome_vfs_mime_get_description(PromiseFlatCString(aMimeType).get());
   194   aDescription.Assign(desc);
   196   // |desc| points to internal gnome-vfs data, so don't free it.
   198   return NS_OK;
   199 }
   201 NS_IMETHODIMP
   202 nsGnomeVFSService::ShowURI(nsIURI *aURI)
   203 {
   204   nsAutoCString spec;
   205   aURI->GetSpec(spec);
   207   if (gnome_vfs_url_show_with_env(spec.get(), nullptr) == GNOME_VFS_OK)
   208     return NS_OK;
   210   return NS_ERROR_FAILURE;
   211 }
   213 NS_IMETHODIMP
   214 nsGnomeVFSService::ShowURIForInput(const nsACString &aUri)
   215 {
   216   char* spec = gnome_vfs_make_uri_from_input(PromiseFlatCString(aUri).get());
   217   nsresult rv = NS_ERROR_FAILURE;
   219   if (gnome_vfs_url_show_with_env(spec, nullptr) == GNOME_VFS_OK)
   220     rv = NS_OK;
   222   g_free(spec);
   223   return rv;
   224 }

mercurial