mozilla-gio.patch
changeset 210 f4f4388b26a8
equal deleted inserted replaced
209:46868b4f4bfd 210:f4f4388b26a8
       
     1 # HG changeset patch
       
     2 # User Chris Coulson
       
     3 # Parent 0ebe30f9eacfe67fa0b699457e524d5a9c96359e
       
     4 Bug 611953 - GNOME 3.0 readiness (patch 2 + 3)
       
     5 
       
     6 diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp
       
     7 --- a/toolkit/system/gnome/nsGIOService.cpp
       
     8 +++ b/toolkit/system/gnome/nsGIOService.cpp
       
     9 @@ -101,25 +101,25 @@ nsGIOMimeApp::GetName(nsACString& aName)
       
    10    return NS_OK;
       
    11  }
       
    12  
       
    13  NS_IMETHODIMP
       
    14  nsGIOMimeApp::GetCommand(nsACString& aCommand)
       
    15  {
       
    16    get_commandline_t g_app_info_get_commandline_ptr;
       
    17  
       
    18 -  void *libHandle = dlopen("libgio-2.0.so", RTLD_LAZY);
       
    19 +  void *libHandle = dlopen("libgio-2.0.so.0", RTLD_LAZY);
       
    20    if (!libHandle) {
       
    21      return NS_ERROR_FAILURE;
       
    22    }
       
    23    dlerror(); /* clear any existing error */
       
    24    g_app_info_get_commandline_ptr =
       
    25      (get_commandline_t) dlsym(libHandle, "g_app_info_get_commandline");
       
    26 -  if (dlerror() != NULL) {
       
    27 -    const char cmd = *g_app_info_get_commandline_ptr(mApp);
       
    28 +  if (dlerror() == NULL) {
       
    29 +    const char *cmd = g_app_info_get_commandline_ptr(mApp);
       
    30      if (!cmd) {
       
    31        dlclose(libHandle);
       
    32        return NS_ERROR_FAILURE;
       
    33      }
       
    34      aCommand.Assign(cmd);
       
    35    }
       
    36    dlclose(libHandle);
       
    37    return NS_OK;
       
    38 @@ -277,16 +277,43 @@ nsGIOMimeApp::SetAsDefaultForFileExtensi
       
    39      } else {
       
    40        *ext_pos = '\0';
       
    41      }
       
    42    }
       
    43    g_free(extensions);
       
    44    return NS_OK;
       
    45  }
       
    46  
       
    47 +/**
       
    48 + * Set default application for URI's of a particular scheme
       
    49 + * @param aURIScheme string containing the URI scheme
       
    50 + * @return NS_OK when application was set as default for URI scheme,
       
    51 + * NS_ERROR_FAILURE otherwise
       
    52 + */
       
    53 +NS_IMETHODIMP
       
    54 +nsGIOMimeApp::SetAsDefaultForURIScheme(nsACString const& aURIScheme)
       
    55 +{
       
    56 +  GError *error = NULL;
       
    57 +  nsCAutoString contentType("x-scheme-handler/");
       
    58 +  contentType.Append(aURIScheme);
       
    59 +
       
    60 +  g_app_info_set_as_default_for_type(mApp,
       
    61 +                                     contentType.get(),
       
    62 +                                     &error);
       
    63 +  if (error) {
       
    64 +    g_warning("Cannot set application as default for URI scheme (%s): %s",
       
    65 +              PromiseFlatCString(aURIScheme).get(),
       
    66 +              error->message);
       
    67 +    g_error_free(error);
       
    68 +    return NS_ERROR_FAILURE;
       
    69 +  }
       
    70 +
       
    71 +  return NS_OK;
       
    72 +}
       
    73 +
       
    74  nsresult
       
    75  nsGIOService::Init()
       
    76  {
       
    77    // do nothing, gvfs/gio does not init.
       
    78    return NS_OK;
       
    79  }
       
    80  
       
    81  NS_IMPL_ISUPPORTS1(nsGIOService, nsIGIOService)
       
    82 @@ -317,29 +344,45 @@ nsGIOService::GetMimeTypeFromExtension(c
       
    83    g_free(mime_type);
       
    84    g_free(content_type);
       
    85  
       
    86    return NS_OK;
       
    87  }
       
    88  // used in nsGNOMERegistry
       
    89  // -----------------------------------------------------------------------------
       
    90  NS_IMETHODIMP
       
    91 +nsGIOService::GetAppForURIScheme(const nsACString& aURIScheme,
       
    92 +                                 nsIGIOMimeApp** aApp)
       
    93 +{
       
    94 +  *aApp = nsnull;
       
    95 +
       
    96 +  GAppInfo *app_info = g_app_info_get_default_for_uri_scheme(
       
    97 +                         PromiseFlatCString(aURIScheme).get());
       
    98 +  if (app_info) {
       
    99 +    nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
       
   100 +    NS_ADDREF(*aApp = mozApp);
       
   101 +  } else {
       
   102 +    return NS_ERROR_FAILURE;
       
   103 +  }
       
   104 +  return NS_OK;
       
   105 +}
       
   106 +
       
   107 +NS_IMETHODIMP
       
   108  nsGIOService::GetAppForMimeType(const nsACString& aMimeType,
       
   109                                  nsIGIOMimeApp**   aApp)
       
   110  {
       
   111    *aApp = nsnull;
       
   112    char *content_type =
       
   113      get_content_type_from_mime_type(PromiseFlatCString(aMimeType).get());
       
   114    if (!content_type)
       
   115      return NS_ERROR_FAILURE;
       
   116  
       
   117    GAppInfo *app_info = g_app_info_get_default_for_type(content_type, false);
       
   118    if (app_info) {
       
   119      nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
       
   120 -    NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
       
   121      NS_ADDREF(*aApp = mozApp);
       
   122    } else {
       
   123      g_free(content_type);
       
   124      return NS_ERROR_FAILURE;
       
   125    }
       
   126    g_free(content_type);
       
   127    return NS_OK;
       
   128  }
       
   129 @@ -414,75 +457,46 @@ nsGIOService::CreateAppFromCommand(nsACS
       
   130                                     nsIGIOMimeApp**   appInfo)
       
   131  {
       
   132    GError *error = NULL;
       
   133    *appInfo = nsnull;
       
   134  
       
   135    GAppInfo *app_info = NULL, *app_info_from_list = NULL;
       
   136    GList *apps = g_app_info_get_all();
       
   137    GList *apps_p = apps;
       
   138 -  get_commandline_t g_app_info_get_commandline_ptr;
       
   139 -
       
   140 -  void *libHandle = dlopen("libgio-2.0.so", RTLD_LAZY);
       
   141 -  if (!libHandle) {
       
   142 -    return NS_ERROR_FAILURE;
       
   143 -  }
       
   144 -  dlerror(); /* clear any existing error */
       
   145 -  g_app_info_get_commandline_ptr =
       
   146 -    (get_commandline_t) dlsym(libHandle, "g_app_info_get_commandline");
       
   147 -  if (dlerror() != NULL) {
       
   148 -    g_app_info_get_commandline_ptr = NULL;
       
   149 -  }
       
   150  
       
   151    // Try to find relevant and existing GAppInfo in all installed application
       
   152 +  // We do this by comparing each GAppInfo's executable with out own
       
   153    while (apps_p) {
       
   154      app_info_from_list = (GAppInfo*) apps_p->data;
       
   155 -    /* This is  a silly test. It just compares app names but not
       
   156 -     * commands. This is due to old version of Glib/Gio. The required
       
   157 -     * function which allows to do a regular check of existence of desktop file
       
   158 -     * is possible by using function g_app_info_get_commandline. This function
       
   159 -     * has been introduced in Glib 2.20. */
       
   160 -    if (app_info_from_list && strcmp(g_app_info_get_name(app_info_from_list),
       
   161 -                                     PromiseFlatCString(appName).get()) == 0 )
       
   162 -    {
       
   163 -      if (g_app_info_get_commandline_ptr)
       
   164 -      {
       
   165 -        /* Following test is only possible with Glib >= 2.20.
       
   166 -         * Compare path only by using strncmp */
       
   167 -        if (strncmp(g_app_info_get_commandline_ptr(app_info_from_list),
       
   168 -                    PromiseFlatCString(cmd).get(),
       
   169 -                    strlen(PromiseFlatCString(cmd).get())) == 0)
       
   170 -        {
       
   171 -          app_info = app_info_from_list;
       
   172 -          break;
       
   173 -        } else {
       
   174 -          g_object_unref(app_info_from_list);
       
   175 -        }
       
   176 -      } else {
       
   177 +    if (!app_info) {
       
   178 +      // If the executable is not absolute, get it's full path
       
   179 +      char *executable = g_find_program_in_path(g_app_info_get_executable(app_info_from_list));
       
   180 +
       
   181 +      if (executable && strcmp(executable, PromiseFlatCString(cmd).get()) == 0) {
       
   182 +        g_object_ref (app_info_from_list);
       
   183          app_info = app_info_from_list;
       
   184 -        break;
       
   185        }
       
   186 -    } else {
       
   187 -      g_object_unref(app_info_from_list);
       
   188 +      g_free(executable);
       
   189      }
       
   190 +
       
   191 +    g_object_unref(app_info_from_list);
       
   192      apps_p = apps_p->next;
       
   193    }
       
   194    g_list_free(apps);
       
   195  
       
   196    if (!app_info) {
       
   197      app_info = g_app_info_create_from_commandline(PromiseFlatCString(cmd).get(),
       
   198                                                    PromiseFlatCString(appName).get(),
       
   199                                                    G_APP_INFO_CREATE_SUPPORTS_URIS,
       
   200                                                    &error);
       
   201    }
       
   202  
       
   203    if (!app_info) {
       
   204      g_warning("Cannot create application info from command: %s", error->message);
       
   205      g_error_free(error);
       
   206 -    dlclose(libHandle);
       
   207      return NS_ERROR_FAILURE;
       
   208    }
       
   209    nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
       
   210    NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
       
   211    NS_ADDREF(*appInfo = mozApp);
       
   212 -  dlclose(libHandle);
       
   213    return NS_OK;
       
   214  }
       
   215 diff --git a/xpcom/system/nsIGIOService.idl b/xpcom/system/nsIGIOService.idl
       
   216 --- a/xpcom/system/nsIGIOService.idl
       
   217 +++ b/xpcom/system/nsIGIOService.idl
       
   218 @@ -39,17 +39,17 @@
       
   219  
       
   220  #include "nsISupports.idl"
       
   221  
       
   222  interface nsIUTF8StringEnumerator;
       
   223  interface nsIURI;
       
   224  
       
   225  /* nsIGIOMimeApp holds information about an application that is looked up
       
   226     with nsIGIOService::GetAppForMimeType. */
       
   227 -// 66009894-9877-405b-9321-bf30420e34e6 prev uuid
       
   228 +// e77021b4-4012-407d-b686-7a1f18050109 prev uuid
       
   229  
       
   230  [scriptable, uuid(e77021b4-4012-407d-b686-7a1f18050109)] 
       
   231  interface nsIGIOMimeApp : nsISupports
       
   232  {
       
   233    const long EXPECTS_URIS  = 0;
       
   234    const long EXPECTS_PATHS = 1;
       
   235    const long EXPECTS_URIS_FOR_NON_FILES = 2;
       
   236  
       
   237 @@ -57,41 +57,45 @@ interface nsIGIOMimeApp : nsISupports
       
   238    readonly attribute AUTF8String         name;
       
   239    readonly attribute AUTF8String         command;
       
   240    readonly attribute long                expectsURIs;  // see constants above
       
   241    readonly attribute nsIUTF8StringEnumerator supportedURISchemes;
       
   242  
       
   243    void launch(in AUTF8String uri);
       
   244    void setAsDefaultForMimeType(in AUTF8String mimeType);
       
   245    void setAsDefaultForFileExtensions(in AUTF8String extensions);
       
   246 +  void setAsDefaultForURIScheme(in AUTF8String uriScheme);
       
   247  };
       
   248  
       
   249  /*
       
   250   * The VFS service makes use of two distinct registries.
       
   251   *
       
   252   * The application registry holds information about applications (uniquely
       
   253   * identified by id), such as which MIME types and URI schemes they are
       
   254   * capable of handling, whether they run in a terminal, etc.
       
   255   *
       
   256   * The MIME registry holds information about MIME types, such as which
       
   257   * extensions map to a given MIME type.  The MIME registry also stores the
       
   258   * id of the application selected to handle each MIME type.
       
   259   */
       
   260  
       
   261 -// prev id dea20bf0-4e4d-48c5-b932-dc3e116dc64b
       
   262 -[scriptable, uuid(47e372c2-78bb-4899-8114-56aa7d9cdac5)]
       
   263 +// prev id 47e372c2-78bb-4899-8114-56aa7d9cdac5
       
   264 +[scriptable, uuid(74ca8791-330d-4786-9569-2a2a19f0b486)]
       
   265  interface nsIGIOService : nsISupports
       
   266  {
       
   267  
       
   268    /*** MIME registry methods ***/
       
   269  
       
   270    /* Obtain the MIME type registered for an extension.  The extension
       
   271       should not include a leading dot. */
       
   272    AUTF8String        getMimeTypeFromExtension(in AUTF8String extension);
       
   273  
       
   274 +  /* Obtain the preferred application for opening a given URI scheme */
       
   275 +  nsIGIOMimeApp      getAppForURIScheme(in AUTF8String aURIScheme);
       
   276 +
       
   277    /* Obtain the preferred application for opening a given MIME type */
       
   278    nsIGIOMimeApp      getAppForMimeType(in AUTF8String mimeType);
       
   279  
       
   280    /* Obtain the preferred application for opening a given MIME type */
       
   281    nsIGIOMimeApp      createAppFromCommand(in AUTF8String cmd, 
       
   282                                            in AUTF8String appName);
       
   283  
       
   284    /* Obtain a description for the given MIME type */