NS_IMETHODIMP nsGIOProtocolHandler::NewURI(const nsACString &aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **aResult) { const nsCString flatSpec(aSpec); LOG(("gio: NewURI [spec=%s]\n", flatSpec.get())); if (!aBaseURI) { // XXX Is it good to support all GIO protocols? if (!IsSupportedProtocol(flatSpec)) return NS_ERROR_UNKNOWN_PROTOCOL; int32_t colon_location = flatSpec.FindChar(':'); if (colon_location <= 0) return NS_ERROR_UNKNOWN_PROTOCOL; // Verify that GIO supports this URI scheme. bool uri_scheme_supported = false; GVfs *gvfs = g_vfs_get_default(); if (!gvfs) { g_warning("Cannot get GVfs object."); return NS_ERROR_UNKNOWN_PROTOCOL; } const gchar* const * uri_schemes = g_vfs_get_supported_uri_schemes(gvfs); while (*uri_schemes != nullptr) { // While flatSpec ends with ':' the uri_scheme does not. Therefore do not // compare last character. if (StringHead(flatSpec, colon_location).Equals(*uri_schemes)) { uri_scheme_supported = true; break; } uri_schemes++; } if (!uri_scheme_supported) { return NS_ERROR_UNKNOWN_PROTOCOL; } } nsresult rv; nsCOMPtr<nsIStandardURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec, aOriginCharset, aBaseURI); if (NS_SUCCEEDED(rv)) rv = CallQueryInterface(url, aResult); return rv; }
NS_IMETHODIMP nsGIOProtocolHandler::NewURI(const nsACString &aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **aResult) { const nsCString flatSpec(aSpec); LOG(("gio: NewURI [spec=%s]\n", flatSpec.get())); if (!aBaseURI) { // XXX Is it good to support all GIO protocols? if (!IsSupportedProtocol(flatSpec)) return NS_ERROR_UNKNOWN_PROTOCOL; int32_t colon_location = flatSpec.FindChar(':'); if (colon_location <= 0) return NS_ERROR_UNKNOWN_PROTOCOL; // Verify that GIO supports this URI scheme. bool uri_scheme_supported = false; GVfs *gvfs = g_vfs_get_default(); if (!gvfs) { g_warning("Cannot get GVfs object."); return NS_ERROR_UNKNOWN_PROTOCOL; } const gchar* const * uri_schemes = g_vfs_get_supported_uri_schemes(gvfs); while (*uri_schemes != nullptr) { // While flatSpec ends with ':' the uri_scheme does not. Therefore do not // compare last character. if (StringHead(flatSpec, colon_location).Equals(*uri_schemes)) { uri_scheme_supported = true; break; } uri_schemes++; } if (!uri_scheme_supported) { return NS_ERROR_UNKNOWN_PROTOCOL; } } return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID) .Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init, nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec, aOriginCharset, aBaseURI, nullptr) .Finalize(aResult); }
NS_IMETHODIMP nsGnomeVFSProtocolHandler::NewURI(const nsACString &aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **aResult) { const nsCString flatSpec(aSpec); LOG(("gnomevfs: NewURI [spec=%s]\n", flatSpec.get())); if (!aBaseURI) { // // XXX This check is used to limit the gnome-vfs protocols we support. For // security reasons, it is best that we limit the protocols we support to // those with known characteristics. We might want to lessen this // restriction if it proves to be too heavy handed. A black list of // protocols we don't want to support might be better. For example, we // probably don't want to try to load "start-here:" inside the browser. // There are others that fall into this category, which are best handled // externally by Nautilus (or another app like it). // if (!IsSupportedProtocol(flatSpec)) return NS_ERROR_UNKNOWN_PROTOCOL; // Verify that GnomeVFS supports this URI scheme. GnomeVFSURI *uri = gnome_vfs_uri_new(flatSpec.get()); if (!uri) return NS_ERROR_UNKNOWN_PROTOCOL; } // // XXX Can we really assume that all gnome-vfs URIs can be parsed using // nsStandardURL? We probably really need to implement nsIURI/nsIURL // in terms of the gnome_vfs_uri_XXX methods, but at least this works // correctly for smb:// URLs ;-) // // Also, it might not be possible to fully implement nsIURI/nsIURL in // terms of GnomeVFSURI since some Necko methods have no GnomeVFS // equivalent. // nsresult rv; nsCOMPtr<nsIStandardURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec, aOriginCharset, aBaseURI); if (NS_SUCCEEDED(rv)) rv = CallQueryInterface(url, aResult); return rv; }