2000-11-09 00:00:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-11-09 00:00:37 +03:00
|
|
|
|
|
|
|
#include "nsNetUtil.h"
|
2002-10-01 02:38:31 +04:00
|
|
|
#include "nsCRT.h"
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-09-18 16:42:07 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_TOOLKIT_SEARCH
|
2010-08-14 20:15:21 +04:00
|
|
|
#include "nsIBrowserSearchService.h"
|
2010-09-18 16:42:07 +04:00
|
|
|
#endif
|
2000-11-09 00:00:37 +03:00
|
|
|
|
|
|
|
#include "nsIURIFixup.h"
|
|
|
|
#include "nsDefaultURIFixup.h"
|
2011-06-25 05:55:46 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-08-16 21:59:31 +04:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2012-11-06 21:14:35 +04:00
|
|
|
#include "nsIObserverService.h"
|
2013-09-24 01:30:40 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2011-06-25 05:55:46 +04:00
|
|
|
|
2014-06-19 22:22:45 +04:00
|
|
|
// Used to check if external protocol schemes are usable
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsIExternalProtocolService.h"
|
|
|
|
|
2011-06-25 05:55:46 +04:00
|
|
|
using namespace mozilla;
|
2000-11-09 00:00:37 +03:00
|
|
|
|
|
|
|
/* Implementation file */
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsDefaultURIFixup, nsIURIFixup)
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2014-06-19 22:22:45 +04:00
|
|
|
static bool sInitializedPrefCaches = false;
|
2013-11-18 00:16:45 +04:00
|
|
|
static bool sFixTypos = true;
|
2014-06-19 22:22:45 +04:00
|
|
|
static bool sFixupKeywords = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
|
2000-11-09 00:00:37 +03:00
|
|
|
nsDefaultURIFixup::nsDefaultURIFixup()
|
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsDefaultURIFixup::~nsDefaultURIFixup()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
}
|
|
|
|
|
2013-01-18 10:05:28 +04:00
|
|
|
/* nsIURI createExposableURI (in nsIURI aURI); */
|
2002-09-11 05:44:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixup::CreateExposableURI(nsIURI *aURI, nsIURI **aReturn)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isWyciwyg = false;
|
2002-09-11 05:44:13 +04:00
|
|
|
aURI->SchemeIs("wyciwyg", &isWyciwyg);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString userPass;
|
2004-09-09 18:27:52 +04:00
|
|
|
aURI->GetUserPass(userPass);
|
|
|
|
|
|
|
|
// most of the time we can just AddRef and return
|
|
|
|
if (!isWyciwyg && userPass.IsEmpty())
|
2002-09-11 05:44:13 +04:00
|
|
|
{
|
|
|
|
*aReturn = aURI;
|
|
|
|
NS_ADDREF(*aReturn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-09 18:27:52 +04:00
|
|
|
// Rats, we have to massage the URI
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (isWyciwyg)
|
2002-09-11 05:44:13 +04:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2004-09-09 18:27:52 +04:00
|
|
|
nsresult rv = aURI->GetPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t pathLength = path.Length();
|
2004-09-09 18:27:52 +04:00
|
|
|
if (pathLength <= 2)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Path is of the form "//123/http://foo/bar", with a variable number of digits.
|
|
|
|
// To figure out where the "real" URL starts, search path for a '/', starting at
|
|
|
|
// the third character.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t slashIndex = path.FindChar('/', 2);
|
2004-09-09 18:27:52 +04:00
|
|
|
if (slashIndex == kNotFound)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the charset of the original URI so we can pass it to our fixed up URI.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString charset;
|
2004-09-09 18:27:52 +04:00
|
|
|
aURI->GetOriginCharset(charset);
|
|
|
|
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri),
|
|
|
|
Substring(path, slashIndex + 1, pathLength - slashIndex - 1),
|
|
|
|
charset.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-11 05:44:13 +04:00
|
|
|
}
|
2004-09-09 18:27:52 +04:00
|
|
|
else
|
2002-09-11 05:44:13 +04:00
|
|
|
{
|
2004-09-09 18:27:52 +04:00
|
|
|
// clone the URI so zapping user:pass doesn't change the original
|
|
|
|
nsresult rv = aURI->Clone(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-11 05:44:13 +04:00
|
|
|
}
|
|
|
|
|
2004-09-09 18:27:52 +04:00
|
|
|
// hide user:pass unless overridden by pref
|
2011-09-29 10:19:26 +04:00
|
|
|
if (Preferences::GetBool("browser.fixup.hide_user_pass", true))
|
2004-09-09 18:27:52 +04:00
|
|
|
{
|
|
|
|
uri->SetUserPass(EmptyCString());
|
2011-06-25 05:55:46 +04:00
|
|
|
}
|
2002-09-11 05:44:13 +04:00
|
|
|
|
2004-09-09 18:27:52 +04:00
|
|
|
// return the fixed-up URI
|
|
|
|
*aReturn = uri;
|
|
|
|
NS_ADDREF(*aReturn);
|
2002-09-11 05:44:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2003-07-02 04:39:51 +04:00
|
|
|
/* nsIURI createFixupURI (in nsAUTF8String aURIText, in unsigned long aFixupFlags); */
|
2001-11-07 01:55:30 +03:00
|
|
|
NS_IMETHODIMP
|
2013-05-01 15:04:21 +04:00
|
|
|
nsDefaultURIFixup::CreateFixupURI(const nsACString& aStringURI, uint32_t aFixupFlags,
|
|
|
|
nsIInputStream **aPostData, nsIURI **aURI)
|
2014-04-25 02:42:00 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
|
|
|
|
nsresult rv = GetFixupURIInfo(aStringURI, aFixupFlags, aPostData,
|
|
|
|
getter_AddRefs(fixupInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
fixupInfo->GetPreferredURI(aURI);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI, uint32_t aFixupFlags,
|
|
|
|
nsIInputStream **aPostData, nsIURIFixupInfo **aInfo)
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
2002-08-07 03:51:42 +04:00
|
|
|
NS_ENSURE_ARG(!aStringURI.IsEmpty());
|
2001-11-07 01:55:30 +03:00
|
|
|
|
2002-06-28 22:47:20 +04:00
|
|
|
nsresult rv;
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString uriString(aStringURI);
|
2000-11-09 00:00:37 +03:00
|
|
|
|
|
|
|
// Eliminate embedded newlines, which single-line text fields now allow:
|
|
|
|
uriString.StripChars("\r\n");
|
2014-08-29 13:13:00 +04:00
|
|
|
// Cleanup the empty spaces that might be on each end:
|
|
|
|
uriString.Trim(" ");
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2002-09-11 05:44:13 +04:00
|
|
|
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
|
|
|
|
|
2014-08-25 17:54:00 +04:00
|
|
|
nsRefPtr<nsDefaultURIFixupInfo> info = new nsDefaultURIFixupInfo(uriString);
|
|
|
|
NS_ADDREF(*aInfo = info);
|
|
|
|
|
2003-07-02 04:39:51 +04:00
|
|
|
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2003-07-02 04:39:51 +04:00
|
|
|
ioService->ExtractScheme(aStringURI, scheme);
|
|
|
|
|
2001-11-07 01:55:30 +03:00
|
|
|
// View-source is a pseudo scheme. We're interested in fixing up the stuff
|
|
|
|
// after it. The easiest way to do that is to call this method again with the
|
|
|
|
// "view-source:" lopped off and then prepend it again afterwards.
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
if (scheme.LowerCaseEqualsLiteral("view-source"))
|
2001-05-17 23:24:42 +04:00
|
|
|
{
|
2014-04-25 02:42:00 +04:00
|
|
|
nsCOMPtr<nsIURIFixupInfo> uriInfo;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t newFixupFlags = aFixupFlags & ~FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
|
2001-11-07 22:03:39 +03:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
rv = GetFixupURIInfo(Substring(uriString,
|
2003-07-02 04:39:51 +04:00
|
|
|
sizeof("view-source:") - 1,
|
|
|
|
uriString.Length() -
|
|
|
|
(sizeof("view-source:") - 1)),
|
2014-04-25 02:42:00 +04:00
|
|
|
newFixupFlags, aPostData, getter_AddRefs(uriInfo));
|
2002-08-07 03:51:42 +04:00
|
|
|
if (NS_FAILED(rv))
|
2001-11-07 01:55:30 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2014-04-25 02:42:00 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
uriInfo->GetPreferredURI(getter_AddRefs(uri));
|
|
|
|
if (!uri)
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-03-06 10:48:55 +03:00
|
|
|
uri->GetSpec(spec);
|
2014-05-22 07:48:52 +04:00
|
|
|
uriString.AssignLiteral("view-source:");
|
|
|
|
uriString.Append(spec);
|
2001-05-17 23:24:42 +04:00
|
|
|
}
|
2001-11-07 01:55:30 +03:00
|
|
|
else {
|
|
|
|
// Check for if it is a file URL
|
2014-04-25 02:42:00 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
FileURIFixup(uriString, getter_AddRefs(uri));
|
2014-07-25 14:46:07 +04:00
|
|
|
// NB: FileURIFixup only returns a URI if it had to fix the protocol to
|
|
|
|
// do so, so passing in file:///foo/bar will not hit this path:
|
2014-04-25 02:42:00 +04:00
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
uri.swap(info->mFixedURI);
|
|
|
|
info->mPreferredURI = info->mFixedURI;
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2001-11-07 01:55:30 +03:00
|
|
|
return NS_OK;
|
2014-04-25 02:42:00 +04:00
|
|
|
}
|
2001-11-07 01:55:30 +03:00
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2001-11-07 01:55:30 +03:00
|
|
|
// Not a file URL, so translate '\' to '/' for convenience in the common protocols
|
2002-10-01 01:55:36 +04:00
|
|
|
// e.g. catch
|
|
|
|
//
|
|
|
|
// http:\\broken.com\address
|
|
|
|
// http:\\broken.com/blah
|
|
|
|
// broken.com\blah
|
|
|
|
//
|
|
|
|
// Code will also do partial fix up the following urls
|
|
|
|
//
|
|
|
|
// http:\\broken.com\address/somewhere\image.jpg (stops at first forward slash)
|
|
|
|
// http:\\broken.com\blah?arg=somearg\foo.jpg (stops at question mark)
|
|
|
|
// http:\\broken.com#odd\ref (stops at hash)
|
|
|
|
//
|
2003-07-02 04:39:51 +04:00
|
|
|
if (scheme.IsEmpty() ||
|
2004-06-17 04:13:25 +04:00
|
|
|
scheme.LowerCaseEqualsLiteral("http") ||
|
|
|
|
scheme.LowerCaseEqualsLiteral("https") ||
|
|
|
|
scheme.LowerCaseEqualsLiteral("ftp"))
|
2001-11-07 01:55:30 +03:00
|
|
|
{
|
2002-10-01 01:55:36 +04:00
|
|
|
// Walk the string replacing backslashes with forward slashes until
|
|
|
|
// the end is reached, or a question mark, or a hash, or a forward
|
|
|
|
// slash. The forward slash test is to stop before trampling over
|
|
|
|
// URIs which legitimately contain a mix of both forward and
|
|
|
|
// backward slashes.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString::iterator start;
|
|
|
|
nsAutoCString::iterator end;
|
2002-10-01 01:55:36 +04:00
|
|
|
uriString.BeginWriting(start);
|
|
|
|
uriString.EndWriting(end);
|
|
|
|
while (start != end) {
|
|
|
|
if (*start == '?' || *start == '#' || *start == '/')
|
|
|
|
break;
|
|
|
|
if (*start == '\\')
|
|
|
|
*start = '/';
|
|
|
|
++start;
|
|
|
|
}
|
2001-11-07 01:55:30 +03:00
|
|
|
}
|
2001-05-17 23:24:42 +04:00
|
|
|
#endif
|
2001-11-07 01:55:30 +03:00
|
|
|
}
|
2001-05-17 23:24:42 +04:00
|
|
|
|
2014-06-19 22:22:45 +04:00
|
|
|
if (!sInitializedPrefCaches) {
|
|
|
|
// Check if we want to fix up common scheme typos.
|
|
|
|
rv = Preferences::AddBoolVarCache(&sFixTypos,
|
|
|
|
"browser.fixup.typo.scheme",
|
|
|
|
sFixTypos);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to observe \"browser.fixup.typo.scheme\"");
|
|
|
|
|
|
|
|
rv = Preferences::AddBoolVarCache(&sFixupKeywords, "keyword.enabled",
|
|
|
|
sFixupKeywords);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed to observe \"keyword.enabled\"");
|
|
|
|
sInitializedPrefCaches = true;
|
|
|
|
}
|
2013-11-18 00:16:45 +04:00
|
|
|
|
|
|
|
// Fix up common scheme typos.
|
|
|
|
if (sFixTypos && (aFixupFlags & FIXUP_FLAG_FIX_SCHEME_TYPOS)) {
|
|
|
|
|
|
|
|
// Fast-path for common cases.
|
|
|
|
if (scheme.IsEmpty() ||
|
|
|
|
scheme.LowerCaseEqualsLiteral("http") ||
|
|
|
|
scheme.LowerCaseEqualsLiteral("https") ||
|
|
|
|
scheme.LowerCaseEqualsLiteral("ftp") ||
|
|
|
|
scheme.LowerCaseEqualsLiteral("file")) {
|
|
|
|
// Do nothing.
|
|
|
|
} else if (scheme.LowerCaseEqualsLiteral("ttp")) {
|
|
|
|
// ttp -> http.
|
|
|
|
uriString.Replace(0, 3, "http");
|
|
|
|
scheme.AssignLiteral("http");
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
} else if (scheme.LowerCaseEqualsLiteral("ttps")) {
|
|
|
|
// ttps -> https.
|
|
|
|
uriString.Replace(0, 4, "https");
|
|
|
|
scheme.AssignLiteral("https");
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
} else if (scheme.LowerCaseEqualsLiteral("tps")) {
|
|
|
|
// tps -> https.
|
|
|
|
uriString.Replace(0, 3, "https");
|
|
|
|
scheme.AssignLiteral("https");
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
} else if (scheme.LowerCaseEqualsLiteral("ps")) {
|
|
|
|
// ps -> https.
|
|
|
|
uriString.Replace(0, 2, "https");
|
|
|
|
scheme.AssignLiteral("https");
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
} else if (scheme.LowerCaseEqualsLiteral("ile")) {
|
|
|
|
// ile -> file.
|
|
|
|
uriString.Replace(0, 3, "file");
|
|
|
|
scheme.AssignLiteral("file");
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
} else if (scheme.LowerCaseEqualsLiteral("le")) {
|
|
|
|
// le -> file.
|
|
|
|
uriString.Replace(0, 2, "file");
|
|
|
|
scheme.AssignLiteral("file");
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupChangedProtocol = true;
|
2013-11-18 00:16:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-02 04:39:51 +04:00
|
|
|
// Now we need to check whether "scheme" is something we don't
|
|
|
|
// really know about.
|
2002-11-26 02:36:37 +03:00
|
|
|
nsCOMPtr<nsIProtocolHandler> ourHandler, extHandler;
|
|
|
|
|
|
|
|
ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(ourHandler));
|
|
|
|
extHandler = do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default");
|
2014-04-25 02:42:00 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2002-11-26 02:36:37 +03:00
|
|
|
if (ourHandler != extHandler || !PossiblyHostPortUrl(uriString)) {
|
|
|
|
// Just try to create an URL out of it
|
2014-04-25 02:42:00 +04:00
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), uriString, nullptr);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
info->mFixedURI = uri;
|
|
|
|
}
|
2006-04-25 05:53:06 +04:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
if (!uri && rv != NS_ERROR_MALFORMED_URI) {
|
2006-04-25 05:53:06 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2002-06-28 22:47:20 +04:00
|
|
|
}
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
if (uri && ourHandler == extHandler && sFixupKeywords &&
|
2014-06-19 22:22:45 +04:00
|
|
|
(aFixupFlags & FIXUP_FLAG_FIX_SCHEME_TYPOS)) {
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService =
|
|
|
|
do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID);
|
|
|
|
if (extProtService) {
|
|
|
|
bool handlerExists = false;
|
|
|
|
rv = extProtService->ExternalProtocolHandlerExists(scheme.get(), &handlerExists);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
// This basically means we're dealing with a theoretically valid
|
|
|
|
// URI... but we have no idea how to load it. (e.g. "christmas:humbug")
|
|
|
|
// It's more likely the user wants to search, and so we
|
|
|
|
// chuck this over to their preferred search provider instead:
|
|
|
|
if (!handlerExists) {
|
2014-04-25 02:42:00 +04:00
|
|
|
nsresult rv = KeywordToURI(uriString, aPostData, getter_AddRefs(uri));
|
|
|
|
if (NS_SUCCEEDED(rv) && uri) {
|
|
|
|
info->mFixupUsedKeyword = true;
|
|
|
|
}
|
2014-06-19 22:22:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-02 04:39:51 +04:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
if (uri) {
|
2001-12-19 18:58:58 +03:00
|
|
|
if (aFixupFlags & FIXUP_FLAGS_MAKE_ALTERNATE_URI)
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupCreatedAlternateURI = MakeAlternateURI(uri);
|
2014-04-25 02:42:00 +04:00
|
|
|
info->mPreferredURI = uri;
|
2000-11-09 00:00:37 +03:00
|
|
|
return NS_OK;
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
// Fix up protocol string before calling KeywordURIFixup, because
|
|
|
|
// it cares about the hostname of such URIs:
|
|
|
|
nsCOMPtr<nsIURI> uriWithProtocol;
|
2014-08-06 15:36:27 +04:00
|
|
|
bool inputHadDuffProtocol = false;
|
|
|
|
|
|
|
|
// Prune duff protocol schemes
|
|
|
|
//
|
|
|
|
// ://totallybroken.url.com
|
|
|
|
// //shorthand.url.com
|
|
|
|
//
|
|
|
|
if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("://")))
|
|
|
|
{
|
|
|
|
uriString = StringTail(uriString, uriString.Length() - 3);
|
|
|
|
inputHadDuffProtocol = true;
|
|
|
|
} else if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("//"))) {
|
|
|
|
uriString = StringTail(uriString, uriString.Length() - 2);
|
|
|
|
inputHadDuffProtocol = true;
|
|
|
|
}
|
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
// NB: this rv gets returned at the end of this method if we never
|
|
|
|
// do a keyword fixup after this (because the pref or the flags passed
|
|
|
|
// might not let us).
|
2014-07-25 14:46:07 +04:00
|
|
|
rv = FixupURIProtocol(uriString, info, getter_AddRefs(uriWithProtocol));
|
2014-04-25 02:42:00 +04:00
|
|
|
if (uriWithProtocol) {
|
|
|
|
info->mFixedURI = uriWithProtocol;
|
|
|
|
}
|
|
|
|
|
2000-11-09 00:00:37 +03:00
|
|
|
// See if it is a keyword
|
|
|
|
// Test whether keywords need to be fixed up
|
2014-08-06 15:36:27 +04:00
|
|
|
if (sFixupKeywords && (aFixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP) &&
|
|
|
|
!inputHadDuffProtocol) {
|
2014-04-25 02:42:00 +04:00
|
|
|
KeywordURIFixup(uriString, info, aPostData);
|
|
|
|
if (info->mPreferredURI)
|
2014-06-19 22:22:45 +04:00
|
|
|
return NS_OK;
|
2000-11-09 00:00:37 +03:00
|
|
|
}
|
|
|
|
|
2001-12-19 18:58:58 +03:00
|
|
|
// Did the caller want us to try an alternative URI?
|
|
|
|
// If so, attempt to fixup http://foo into http://www.foo.com
|
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
if (info->mFixedURI && aFixupFlags & FIXUP_FLAGS_MAKE_ALTERNATE_URI) {
|
2014-07-25 14:46:07 +04:00
|
|
|
info->mFixupCreatedAlternateURI = MakeAlternateURI(info->mFixedURI);
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
2014-08-29 07:25:02 +04:00
|
|
|
// If there is no relevent dot in the host, do we require the domain to
|
|
|
|
// be whitelisted?
|
|
|
|
if (info->mFixedURI) {
|
|
|
|
if (aFixupFlags & FIXUP_FLAG_REQUIRE_WHITELISTED_HOST) {
|
|
|
|
|
|
|
|
nsAutoCString asciiHost;
|
|
|
|
if (NS_SUCCEEDED(info->mFixedURI->GetAsciiHost(asciiHost)) &&
|
|
|
|
!asciiHost.IsEmpty()) {
|
|
|
|
|
|
|
|
uint32_t dotLoc = uint32_t(asciiHost.FindChar('.'));
|
|
|
|
|
|
|
|
if ((dotLoc == uint32_t(kNotFound) || dotLoc == asciiHost.Length() - 1)) {
|
|
|
|
if (IsDomainWhitelisted(asciiHost, dotLoc)) {
|
|
|
|
info->mPreferredURI = info->mFixedURI;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->mPreferredURI = info->mFixedURI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->mPreferredURI = info->mFixedURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-16 01:15:28 +04:00
|
|
|
// If we still haven't been able to construct a valid URI, try to force a
|
|
|
|
// keyword match. This catches search strings with '.' or ':' in them.
|
2014-08-29 07:25:02 +04:00
|
|
|
if (sFixupKeywords && (aFixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP)) {
|
2014-04-25 02:42:00 +04:00
|
|
|
rv = KeywordToURI(aStringURI, aPostData, getter_AddRefs(info->mPreferredURI));
|
|
|
|
if (NS_SUCCEEDED(rv) && info->mPreferredURI)
|
|
|
|
{
|
|
|
|
info->mFixupUsedKeyword = true;
|
2006-06-16 01:15:28 +04:00
|
|
|
return NS_OK;
|
2014-04-25 02:42:00 +04:00
|
|
|
}
|
2006-06-16 01:15:28 +04:00
|
|
|
}
|
|
|
|
|
2001-12-19 18:58:58 +03:00
|
|
|
return rv;
|
2000-11-09 00:00:37 +03:00
|
|
|
}
|
|
|
|
|
2006-05-16 07:02:28 +04:00
|
|
|
NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword,
|
2013-05-01 15:04:21 +04:00
|
|
|
nsIInputStream **aPostData,
|
2006-05-16 07:02:28 +04:00
|
|
|
nsIURI **aURI)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2013-05-01 15:04:21 +04:00
|
|
|
if (aPostData) {
|
|
|
|
*aPostData = nullptr;
|
|
|
|
}
|
2011-06-25 05:55:46 +04:00
|
|
|
NS_ENSURE_STATE(Preferences::GetRootBranch());
|
2006-05-16 07:02:28 +04:00
|
|
|
|
2010-10-31 23:01:28 +03:00
|
|
|
// Strip leading "?" and leading/trailing spaces from aKeyword
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString keyword(aKeyword);
|
2010-10-31 23:01:28 +03:00
|
|
|
if (StringBeginsWith(keyword, NS_LITERAL_CSTRING("?"))) {
|
|
|
|
keyword.Cut(0, 1);
|
|
|
|
}
|
|
|
|
keyword.Trim(" ");
|
|
|
|
|
2013-08-16 21:59:31 +04:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
|
|
|
|
if (!contentChild) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipc::OptionalInputStreamParams postData;
|
|
|
|
ipc::OptionalURIParams uri;
|
|
|
|
if (!contentChild->SendKeywordToURI(keyword, &postData, &uri)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPostData) {
|
2014-03-25 22:37:13 +04:00
|
|
|
nsTArray<ipc::FileDescriptor> fds;
|
|
|
|
nsCOMPtr<nsIInputStream> temp = DeserializeInputStream(postData, fds);
|
2013-08-16 21:59:31 +04:00
|
|
|
temp.forget(aPostData);
|
2014-03-25 22:37:13 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(fds.IsEmpty());
|
2013-08-16 21:59:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> temp = DeserializeURI(uri);
|
|
|
|
temp.forget(aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-18 16:42:07 +04:00
|
|
|
#ifdef MOZ_TOOLKIT_SEARCH
|
2010-08-14 20:15:21 +04:00
|
|
|
// Try falling back to the search service's default search engine
|
|
|
|
nsCOMPtr<nsIBrowserSearchService> searchSvc = do_GetService("@mozilla.org/browser/search-service;1");
|
|
|
|
if (searchSvc) {
|
|
|
|
nsCOMPtr<nsISearchEngine> defaultEngine;
|
2013-04-10 04:04:22 +04:00
|
|
|
searchSvc->GetDefaultEngine(getter_AddRefs(defaultEngine));
|
2010-08-14 20:15:21 +04:00
|
|
|
if (defaultEngine) {
|
|
|
|
nsCOMPtr<nsISearchSubmission> submission;
|
2014-06-19 22:22:45 +04:00
|
|
|
nsAutoString responseType;
|
2012-04-04 13:50:39 +04:00
|
|
|
// We allow default search plugins to specify alternate
|
|
|
|
// parameters that are specific to keyword searches.
|
2013-05-02 07:49:14 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(mozKeywordSearch, "application/x-moz-keywordsearch");
|
|
|
|
bool supportsResponseType = false;
|
|
|
|
defaultEngine->SupportsResponseType(mozKeywordSearch, &supportsResponseType);
|
2014-06-19 22:22:45 +04:00
|
|
|
if (supportsResponseType) {
|
|
|
|
responseType.Assign(mozKeywordSearch);
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultEngine->GetSubmission(NS_ConvertUTF8toUTF16(keyword),
|
|
|
|
responseType,
|
|
|
|
NS_LITERAL_STRING("keyword"),
|
|
|
|
getter_AddRefs(submission));
|
|
|
|
|
2010-08-14 20:15:21 +04:00
|
|
|
if (submission) {
|
|
|
|
nsCOMPtr<nsIInputStream> postData;
|
|
|
|
submission->GetPostData(getter_AddRefs(postData));
|
2013-05-01 15:04:21 +04:00
|
|
|
if (aPostData) {
|
|
|
|
postData.forget(aPostData);
|
|
|
|
} else if (postData) {
|
|
|
|
// The submission specifies POST data (i.e. the search
|
|
|
|
// engine's "method" is POST), but our caller didn't allow
|
|
|
|
// passing post data back. No point passing back a URL that
|
|
|
|
// won't load properly.
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-08-14 20:15:21 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 02:47:47 +04:00
|
|
|
// This notification is meant for Firefox Health Report so it
|
|
|
|
// can increment counts from the search engine. The assumption
|
|
|
|
// here is that this keyword/submission will eventually result
|
|
|
|
// in a search. Since we only generate a URI here, there is the
|
|
|
|
// possibility we'll increment the counter without actually
|
|
|
|
// incurring a search. A robust solution would involve currying
|
|
|
|
// the search engine's name through various function calls.
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
|
|
|
if (obsSvc) {
|
2013-09-27 20:38:25 +04:00
|
|
|
// Note that "keyword-search" refers to a search via the url
|
|
|
|
// bar, not a bookmarks keyword search.
|
|
|
|
obsSvc->NotifyObservers(defaultEngine, "keyword-search", NS_ConvertUTF8toUTF16(keyword).get());
|
2013-02-15 02:47:47 +04:00
|
|
|
}
|
|
|
|
|
2010-08-14 20:15:21 +04:00
|
|
|
return submission->GetUri(aURI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-18 16:42:07 +04:00
|
|
|
#endif
|
2006-05-16 07:02:28 +04:00
|
|
|
|
2010-08-14 20:15:21 +04:00
|
|
|
// out of options
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2006-05-16 07:02:28 +04:00
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDefaultURIFixup::MakeAlternateURI(nsIURI *aURI)
|
2001-12-19 18:58:58 +03:00
|
|
|
{
|
2011-06-25 05:55:46 +04:00
|
|
|
if (!Preferences::GetRootBranch())
|
2002-03-22 17:29:52 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-03-22 17:29:52 +03:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
if (!Preferences::GetBool("browser.fixup.alternate.enabled", true))
|
2002-03-22 17:29:52 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-03-22 17:29:52 +03:00
|
|
|
}
|
|
|
|
|
2001-12-19 18:58:58 +03:00
|
|
|
// Code only works for http. Not for any other protocol including https!
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHttp = false;
|
2001-12-19 18:58:58 +03:00
|
|
|
aURI->SchemeIs("http", &isHttp);
|
|
|
|
if (!isHttp) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Security - URLs with user / password info should NOT be fixed up
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString userpass;
|
2002-03-06 10:48:55 +03:00
|
|
|
aURI->GetUserPass(userpass);
|
2003-05-24 01:34:47 +04:00
|
|
|
if (!userpass.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString oldHost;
|
|
|
|
nsAutoCString newHost;
|
2002-03-06 10:48:55 +03:00
|
|
|
aURI->GetHost(oldHost);
|
2001-12-19 18:58:58 +03:00
|
|
|
|
|
|
|
// Count the dots
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t numDots = 0;
|
2001-12-19 18:58:58 +03:00
|
|
|
nsReadingIterator<char> iter;
|
|
|
|
nsReadingIterator<char> iterEnd;
|
|
|
|
oldHost.BeginReading(iter);
|
|
|
|
oldHost.EndReading(iterEnd);
|
|
|
|
while (iter != iterEnd) {
|
|
|
|
if (*iter == '.')
|
|
|
|
numDots++;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 17:29:52 +03:00
|
|
|
// Get the prefix and suffix to stick onto the new hostname. By default these
|
|
|
|
// are www. & .com but they could be any other value, e.g. www. & .org
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString prefix("www.");
|
2011-06-25 05:55:46 +04:00
|
|
|
nsAdoptingCString prefPrefix =
|
|
|
|
Preferences::GetCString("browser.fixup.alternate.prefix");
|
|
|
|
if (prefPrefix)
|
2002-03-22 17:29:52 +03:00
|
|
|
{
|
|
|
|
prefix.Assign(prefPrefix);
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString suffix(".com");
|
2011-06-25 05:55:46 +04:00
|
|
|
nsAdoptingCString prefSuffix =
|
|
|
|
Preferences::GetCString("browser.fixup.alternate.suffix");
|
|
|
|
if (prefSuffix)
|
2002-03-22 17:29:52 +03:00
|
|
|
{
|
|
|
|
suffix.Assign(prefSuffix);
|
|
|
|
}
|
|
|
|
|
2001-12-19 18:58:58 +03:00
|
|
|
if (numDots == 0)
|
|
|
|
{
|
|
|
|
newHost.Assign(prefix);
|
|
|
|
newHost.Append(oldHost);
|
|
|
|
newHost.Append(suffix);
|
|
|
|
}
|
|
|
|
else if (numDots == 1)
|
|
|
|
{
|
2003-05-24 01:34:47 +04:00
|
|
|
if (!prefix.IsEmpty() &&
|
2002-03-22 17:29:52 +03:00
|
|
|
oldHost.EqualsIgnoreCase(prefix.get(), prefix.Length())) {
|
2001-12-19 18:58:58 +03:00
|
|
|
newHost.Assign(oldHost);
|
|
|
|
newHost.Append(suffix);
|
|
|
|
}
|
2003-05-24 01:34:47 +04:00
|
|
|
else if (!suffix.IsEmpty()) {
|
2001-12-19 18:58:58 +03:00
|
|
|
newHost.Assign(prefix);
|
|
|
|
newHost.Append(oldHost);
|
|
|
|
}
|
2002-03-22 17:29:52 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Do nothing
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-03-22 17:29:52 +03:00
|
|
|
}
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Do nothing
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newHost.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assign the new host string over the old one
|
2002-03-06 10:48:55 +03:00
|
|
|
aURI->SetHost(newHost);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2001-12-19 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
2006-12-16 17:32:19 +03:00
|
|
|
/**
|
|
|
|
* Check if the host name starts with ftp\d*\. and it's not directly followed
|
|
|
|
* by the tld.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDefaultURIFixup::IsLikelyFTP(const nsCString &aHostSpec)
|
2006-12-16 17:32:19 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool likelyFTP = false;
|
2006-12-16 17:32:19 +03:00
|
|
|
if (aHostSpec.EqualsIgnoreCase("ftp", 3)) {
|
|
|
|
nsACString::const_iterator iter;
|
|
|
|
nsACString::const_iterator end;
|
|
|
|
aHostSpec.BeginReading(iter);
|
|
|
|
aHostSpec.EndReading(end);
|
|
|
|
iter.advance(3); // move past the "ftp" part
|
|
|
|
|
|
|
|
while (iter != end)
|
|
|
|
{
|
|
|
|
if (*iter == '.') {
|
|
|
|
// now make sure the name has at least one more dot in it
|
|
|
|
++iter;
|
|
|
|
while (iter != end)
|
|
|
|
{
|
|
|
|
if (*iter == '.') {
|
2011-10-17 18:59:28 +04:00
|
|
|
likelyFTP = true;
|
2006-12-16 17:32:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!nsCRT::IsAsciiDigit(*iter)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return likelyFTP;
|
|
|
|
}
|
|
|
|
|
2014-07-25 14:46:07 +04:00
|
|
|
nsresult nsDefaultURIFixup::FileURIFixup(const nsACString& aStringURI,
|
2000-12-20 02:01:25 +03:00
|
|
|
nsIURI** aURI)
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString uriSpecOut;
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2002-10-01 02:38:31 +04:00
|
|
|
nsresult rv = ConvertFileToStringURI(aStringURI, uriSpecOut);
|
2001-05-17 23:24:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
2001-06-22 05:28:18 +04:00
|
|
|
// if this is file url, uriSpecOut is already in FS charset
|
2012-07-30 18:20:58 +04:00
|
|
|
if(NS_SUCCEEDED(NS_NewURI(aURI, uriSpecOut.get(), nullptr)))
|
2000-11-09 00:00:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-07-02 04:39:51 +04:00
|
|
|
nsresult nsDefaultURIFixup::ConvertFileToStringURI(const nsACString& aIn,
|
2001-06-22 05:28:18 +04:00
|
|
|
nsCString& aOut)
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool attemptFixup = false;
|
2001-05-17 23:24:42 +04:00
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2000-11-09 00:00:37 +03:00
|
|
|
// Check for \ in the url-string or just a drive (PC)
|
2003-07-02 04:39:51 +04:00
|
|
|
if(kNotFound != aIn.FindChar('\\') ||
|
|
|
|
(aIn.Length() == 2 && (aIn.Last() == ':' || aIn.Last() == '|')))
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
attemptFixup = true;
|
2001-05-17 23:24:42 +04:00
|
|
|
}
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 22:10:24 +03:00
|
|
|
#elif defined(XP_UNIX)
|
2002-10-01 02:38:31 +04:00
|
|
|
// Check if it starts with / (UNIX)
|
2003-07-02 04:39:51 +04:00
|
|
|
if(aIn.First() == '/')
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
attemptFixup = true;
|
2001-05-17 23:24:42 +04:00
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
#else
|
2001-05-17 23:24:42 +04:00
|
|
|
// Do nothing (All others for now)
|
2000-11-09 00:00:37 +03:00
|
|
|
#endif
|
|
|
|
|
2001-05-17 23:24:42 +04:00
|
|
|
if (attemptFixup)
|
|
|
|
{
|
|
|
|
// Test if this is a valid path by trying to create a local file
|
|
|
|
// object. The URL of that is returned if successful.
|
|
|
|
|
|
|
|
// NOTE: Please be sure to check that the call to NS_NewLocalFile
|
|
|
|
// rejects bad file paths when using this code on a new
|
|
|
|
// platform.
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> filePath;
|
2002-04-27 09:33:09 +04:00
|
|
|
nsresult rv;
|
2001-06-22 05:28:18 +04:00
|
|
|
|
|
|
|
// this is not the real fix but a temporary fix
|
|
|
|
// in order to really fix the problem, we need to change the
|
|
|
|
// nsICmdLineService interface to use wstring to pass paramenters
|
|
|
|
// instead of string since path name and other argument could be
|
|
|
|
// in non ascii.(see bug 87127) Since it is too risky to make interface change right
|
|
|
|
// now, we decide not to do so now.
|
|
|
|
// Therefore, the aIn we receive here maybe already in damage form
|
2014-01-04 19:02:17 +04:00
|
|
|
// (e.g. treat every bytes as ISO-8859-1 and cast up to char16_t
|
2001-06-22 05:28:18 +04:00
|
|
|
// while the real data could be in file system charset )
|
|
|
|
// we choice the following logic which will work for most of the case.
|
|
|
|
// Case will still failed only if it meet ALL the following condiction:
|
|
|
|
// 1. running on CJK, Russian, or Greek system, and
|
|
|
|
// 2. user type it from URL bar
|
|
|
|
// 3. the file name contains character in the range of
|
|
|
|
// U+00A1-U+00FF but encode as different code point in file
|
|
|
|
// system charset (e.g. ACP on window)- this is very rare case
|
|
|
|
// We should remove this logic and convert to File system charset here
|
|
|
|
// once we change nsICmdLineService to use wstring and ensure
|
2003-07-02 04:39:51 +04:00
|
|
|
// all the Unicode data come in is correctly converted.
|
|
|
|
// XXXbz nsICmdLineService doesn't hand back unicode, so in some cases
|
|
|
|
// what we have is actually a "utf8" version of a "utf16" string that's
|
|
|
|
// actually byte-expanded native-encoding data. Someone upstream needs
|
|
|
|
// to stop using AssignWithConversion and do things correctly. See bug
|
|
|
|
// 58866 for what happens if we remove this
|
|
|
|
// PossiblyByteExpandedFileName check.
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF8toUTF16 in(aIn);
|
2003-07-02 04:39:51 +04:00
|
|
|
if (PossiblyByteExpandedFileName(in)) {
|
2001-06-22 05:28:18 +04:00
|
|
|
// removes high byte
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewNativeLocalFile(NS_LossyConvertUTF16toASCII(in), false, getter_AddRefs(filePath));
|
2001-06-22 05:28:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-04-27 09:33:09 +04:00
|
|
|
// input is unicode
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewLocalFile(in, false, getter_AddRefs(filePath));
|
2001-06-22 05:28:18 +04:00
|
|
|
}
|
|
|
|
|
2001-05-17 23:24:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_GetURLSpecFromFile(filePath, aOut);
|
2001-05-17 23:24:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
}
|
|
|
|
|
2001-05-17 23:24:42 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-11-09 00:00:37 +03:00
|
|
|
}
|
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDefaultURIFixup::FixupURIProtocol(const nsACString & aURIString,
|
2014-07-25 14:46:07 +04:00
|
|
|
nsDefaultURIFixupInfo* aFixupInfo,
|
|
|
|
nsIURI** aURI)
|
2014-04-25 02:42:00 +04:00
|
|
|
{
|
|
|
|
nsAutoCString uriString(aURIString);
|
|
|
|
*aURI = nullptr;
|
|
|
|
|
|
|
|
// Add ftp:// or http:// to front of url if it has no spec
|
|
|
|
//
|
|
|
|
// Should fix:
|
|
|
|
//
|
|
|
|
// no-scheme.com
|
|
|
|
// ftp.no-scheme.com
|
|
|
|
// ftp4.no-scheme.com
|
|
|
|
// no-scheme.com/query?foo=http://www.foo.com
|
|
|
|
//
|
|
|
|
int32_t schemeDelim = uriString.Find("://",0);
|
|
|
|
int32_t firstDelim = uriString.FindCharInSet("/:");
|
|
|
|
if (schemeDelim <= 0 ||
|
|
|
|
(firstDelim != -1 && schemeDelim > firstDelim)) {
|
|
|
|
// find host name
|
|
|
|
int32_t hostPos = uriString.FindCharInSet("/:?#");
|
|
|
|
if (hostPos == -1)
|
|
|
|
hostPos = uriString.Length();
|
|
|
|
|
|
|
|
// extract host name
|
|
|
|
nsAutoCString hostSpec;
|
|
|
|
uriString.Left(hostSpec, hostPos);
|
|
|
|
|
|
|
|
// insert url spec corresponding to host name
|
|
|
|
if (IsLikelyFTP(hostSpec))
|
|
|
|
uriString.InsertLiteral("ftp://", 0);
|
|
|
|
else
|
|
|
|
uriString.InsertLiteral("http://", 0);
|
2014-07-25 14:46:07 +04:00
|
|
|
aFixupInfo->mFixupChangedProtocol = true;
|
2014-04-25 02:42:00 +04:00
|
|
|
} // end if checkprotocol
|
|
|
|
|
|
|
|
return NS_NewURI(aURI, uriString, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDefaultURIFixup::PossiblyHostPortUrl(const nsACString &aUrl)
|
2001-06-22 05:28:18 +04:00
|
|
|
{
|
2002-10-01 02:38:31 +04:00
|
|
|
// Oh dear, the protocol is invalid. Test if the protocol might
|
|
|
|
// actually be a url without a protocol:
|
|
|
|
//
|
|
|
|
// http://www.faqs.org/rfcs/rfc1738.html
|
|
|
|
// http://www.faqs.org/rfcs/rfc2396.html
|
|
|
|
//
|
|
|
|
// e.g. Anything of the form:
|
|
|
|
//
|
|
|
|
// <hostname>:<port> or
|
|
|
|
// <hostname>:<port>/
|
|
|
|
//
|
|
|
|
// Where <hostname> is a string of alphanumeric characters and dashes
|
2003-03-24 07:15:34 +03:00
|
|
|
// separated by dots.
|
2002-10-01 02:38:31 +04:00
|
|
|
// and <port> is a 5 or less digits. This actually breaks the rfc2396
|
|
|
|
// definition of a scheme which allows dots in schemes.
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
// People expecting this to work with
|
|
|
|
// <user>:<password>@<host>:<port>/<url-path> will be disappointed!
|
|
|
|
//
|
|
|
|
// Note: Parser could be a lot tighter, tossing out silly hostnames
|
|
|
|
// such as those containing consecutive dots and so on.
|
|
|
|
|
|
|
|
// Read the hostname which should of the form
|
|
|
|
// [a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*:
|
|
|
|
|
2003-07-02 04:39:51 +04:00
|
|
|
nsACString::const_iterator iterBegin;
|
|
|
|
nsACString::const_iterator iterEnd;
|
2002-10-01 02:38:31 +04:00
|
|
|
aUrl.BeginReading(iterBegin);
|
|
|
|
aUrl.EndReading(iterEnd);
|
2003-07-02 04:39:51 +04:00
|
|
|
nsACString::const_iterator iter = iterBegin;
|
2002-10-01 02:38:31 +04:00
|
|
|
|
|
|
|
while (iter != iterEnd)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t chunkSize = 0;
|
2002-10-01 02:38:31 +04:00
|
|
|
// Parse a chunk of the address
|
|
|
|
while (iter != iterEnd &&
|
2003-07-02 04:39:51 +04:00
|
|
|
(*iter == '-' ||
|
2002-10-01 02:38:31 +04:00
|
|
|
nsCRT::IsAsciiAlpha(*iter) ||
|
|
|
|
nsCRT::IsAsciiDigit(*iter)))
|
|
|
|
{
|
|
|
|
++chunkSize;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
if (chunkSize == 0 || iter == iterEnd)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-10-01 02:38:31 +04:00
|
|
|
}
|
2003-07-02 04:39:51 +04:00
|
|
|
if (*iter == ':')
|
2002-10-01 02:38:31 +04:00
|
|
|
{
|
|
|
|
// Go onto checking the for the digits
|
|
|
|
break;
|
|
|
|
}
|
2003-07-02 04:39:51 +04:00
|
|
|
if (*iter != '.')
|
2002-10-01 02:38:31 +04:00
|
|
|
{
|
|
|
|
// Whatever it is, it ain't a hostname!
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-10-01 02:38:31 +04:00
|
|
|
}
|
|
|
|
++iter;
|
2001-06-22 05:28:18 +04:00
|
|
|
}
|
2002-10-01 02:38:31 +04:00
|
|
|
if (iter == iterEnd)
|
|
|
|
{
|
|
|
|
// No point continuing since there is no colon
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-10-01 02:38:31 +04:00
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// Count the number of digits after the colon and before the
|
|
|
|
// next forward slash (or end of string)
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t digitCount = 0;
|
2002-10-01 02:38:31 +04:00
|
|
|
while (iter != iterEnd && digitCount <= 5)
|
|
|
|
{
|
|
|
|
if (nsCRT::IsAsciiDigit(*iter))
|
|
|
|
{
|
|
|
|
digitCount++;
|
|
|
|
}
|
2003-07-02 04:39:51 +04:00
|
|
|
else if (*iter == '/')
|
2002-10-01 02:38:31 +04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Whatever it is, it ain't a port!
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-10-01 02:38:31 +04:00
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
if (digitCount == 0 || digitCount > 5)
|
|
|
|
{
|
|
|
|
// No digits or more digits than a port would have.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-10-01 02:38:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Yes, it's possibly a host:port url
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-10-01 02:38:31 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDefaultURIFixup::PossiblyByteExpandedFileName(const nsAString& aIn)
|
2002-10-01 02:38:31 +04:00
|
|
|
{
|
|
|
|
// XXXXX HACK XXXXX : please don't copy this code.
|
|
|
|
// There are cases where aIn contains the locale byte chars padded to short
|
|
|
|
// (thus the name "ByteExpanded"); whereas other cases
|
|
|
|
// have proper Unicode code points.
|
|
|
|
// This is a temporary fix. Please refer to 58866, 86948
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsReadingIterator<char16_t> iter;
|
|
|
|
nsReadingIterator<char16_t> iterEnd;
|
2002-10-01 02:38:31 +04:00
|
|
|
aIn.BeginReading(iter);
|
|
|
|
aIn.EndReading(iterEnd);
|
|
|
|
while (iter != iterEnd)
|
|
|
|
{
|
|
|
|
if (*iter >= 0x0080 && *iter <= 0x00FF)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-10-01 02:38:31 +04:00
|
|
|
++iter;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-06-22 05:28:18 +04:00
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2013-05-01 15:04:21 +04:00
|
|
|
void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
|
2014-04-25 02:42:00 +04:00
|
|
|
nsDefaultURIFixupInfo* aFixupInfo,
|
|
|
|
nsIInputStream **aPostData)
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
|
|
|
// These are keyword formatted strings
|
|
|
|
// "what is mozilla"
|
|
|
|
// "what is mozilla?"
|
2004-12-05 01:38:54 +03:00
|
|
|
// "docshell site:mozilla.org" - has no dot/colon in the first space-separated substring
|
|
|
|
// "?mozilla" - anything that begins with a question mark
|
|
|
|
// "?site:mozilla.org docshell"
|
2010-03-09 03:30:02 +03:00
|
|
|
// Things that have a quote before the first dot/colon
|
2014-04-25 02:42:00 +04:00
|
|
|
// "mozilla" - checked against a whitelist to see if it's a host or not
|
2014-07-25 14:46:07 +04:00
|
|
|
// ".mozilla", "mozilla." - ditto
|
2000-11-09 00:00:37 +03:00
|
|
|
|
|
|
|
// These are not keyword formatted strings
|
2004-12-05 01:38:54 +03:00
|
|
|
// "www.blah.com" - first space-separated substring contains a dot, doesn't start with "?"
|
|
|
|
// "www.blah.com stuff"
|
|
|
|
// "nonQualifiedHost:80" - first space-separated substring contains a colon, doesn't start with "?"
|
|
|
|
// "nonQualifiedHost:80 args"
|
2000-11-09 00:00:37 +03:00
|
|
|
// "nonQualifiedHost?"
|
|
|
|
// "nonQualifiedHost?args"
|
|
|
|
// "nonQualifiedHost?some args"
|
2014-07-25 14:46:07 +04:00
|
|
|
// "blah.com."
|
2000-11-09 00:00:37 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
// Note: uint32_t(kNotFound) is greater than any actual location
|
|
|
|
// in practice. So if we cast all locations to uint32_t, then a <
|
2010-03-09 03:30:02 +03:00
|
|
|
// b guarantees that either b is kNotFound and a is found, or both
|
|
|
|
// are found and a found before b.
|
2014-09-10 20:42:00 +04:00
|
|
|
|
|
|
|
uint32_t firstDotLoc = uint32_t(kNotFound);
|
|
|
|
uint32_t firstColonLoc = uint32_t(kNotFound);
|
|
|
|
uint32_t firstQuoteLoc = uint32_t(kNotFound);
|
|
|
|
uint32_t firstSpaceLoc = uint32_t(kNotFound);
|
|
|
|
uint32_t firstQMarkLoc = uint32_t(kNotFound);
|
|
|
|
uint32_t lastLSBracketLoc = uint32_t(kNotFound);
|
|
|
|
uint32_t pos = 0;
|
|
|
|
uint32_t foundDots = 0;
|
|
|
|
uint32_t foundColons = 0;
|
|
|
|
uint32_t foundDigits = 0;
|
|
|
|
uint32_t foundRSBrackets = 0;
|
|
|
|
bool looksLikeIpv6 = true;
|
|
|
|
bool hasAsciiAlpha = false;
|
|
|
|
|
|
|
|
nsACString::const_iterator iterBegin;
|
|
|
|
nsACString::const_iterator iterEnd;
|
|
|
|
aURIString.BeginReading(iterBegin);
|
|
|
|
aURIString.EndReading(iterEnd);
|
|
|
|
nsACString::const_iterator iter = iterBegin;
|
|
|
|
|
|
|
|
while (iter != iterEnd) {
|
|
|
|
if (pos >= 1 && foundRSBrackets == 0) {
|
|
|
|
if (!(lastLSBracketLoc == 0 &&
|
|
|
|
(*iter == ':' ||
|
|
|
|
*iter == '.' ||
|
|
|
|
*iter == ']' ||
|
|
|
|
(*iter >= 'a' && *iter <= 'f') ||
|
|
|
|
(*iter >= 'A' && *iter <= 'F') ||
|
|
|
|
nsCRT::IsAsciiDigit(*iter)))) {
|
|
|
|
looksLikeIpv6 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*iter == '.') {
|
|
|
|
++foundDots;
|
|
|
|
if (firstDotLoc == uint32_t(kNotFound)) {
|
|
|
|
firstDotLoc = pos;
|
|
|
|
}
|
|
|
|
} else if (*iter == ':') {
|
|
|
|
++foundColons;
|
|
|
|
if (firstColonLoc == uint32_t(kNotFound)) {
|
|
|
|
firstColonLoc = pos;
|
|
|
|
}
|
|
|
|
} else if (*iter == ' ' && firstSpaceLoc == uint32_t(kNotFound)) {
|
|
|
|
firstSpaceLoc = pos;
|
|
|
|
} else if (*iter == '?' && firstQMarkLoc == uint32_t(kNotFound)) {
|
|
|
|
firstQMarkLoc = pos;
|
|
|
|
} else if ((*iter == '\'' || *iter == '"') && firstQuoteLoc == uint32_t(kNotFound)) {
|
|
|
|
firstQuoteLoc = pos;
|
|
|
|
} else if (*iter == '[') {
|
|
|
|
lastLSBracketLoc = pos;
|
|
|
|
} else if (*iter == ']') {
|
|
|
|
foundRSBrackets++;
|
|
|
|
} else if (nsCRT::IsAsciiAlpha(*iter)) {
|
|
|
|
hasAsciiAlpha = true;
|
|
|
|
} else if (nsCRT::IsAsciiDigit(*iter)) {
|
|
|
|
++foundDigits;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastLSBracketLoc > 0 || foundRSBrackets != 1) {
|
|
|
|
looksLikeIpv6 = false;
|
|
|
|
}
|
2010-03-09 03:30:02 +03:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
nsresult rv;
|
2014-09-10 20:42:00 +04:00
|
|
|
nsAutoCString asciiHost;
|
|
|
|
nsAutoCString host;
|
|
|
|
|
|
|
|
bool isValidAsciiHost = aFixupInfo->mFixedURI &&
|
|
|
|
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetAsciiHost(asciiHost)) &&
|
|
|
|
!asciiHost.IsEmpty();
|
|
|
|
|
|
|
|
bool isValidHost = aFixupInfo->mFixedURI &&
|
|
|
|
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetHost(host)) &&
|
|
|
|
!host.IsEmpty();
|
|
|
|
|
|
|
|
// If there are 3 dots and only numbers between them, then don't do a
|
|
|
|
// keyword lookup (ipv4)
|
|
|
|
if (foundDots == 3 && (foundDots + foundDigits == pos)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are only colons and only hexadecimal characters ([a-z][0-9])
|
|
|
|
// enclosed in [], then don't do a keyword lookup
|
|
|
|
if (looksLikeIpv6) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-25 14:46:07 +04:00
|
|
|
// We do keyword lookups if a space or quote preceded the dot, colon
|
2014-09-10 20:42:00 +04:00
|
|
|
// or question mark (or if the latter were not found)
|
|
|
|
// or when the host is the same as asciiHost and there are no
|
|
|
|
// characters from [a-z][A-Z]
|
|
|
|
if (((firstSpaceLoc < firstDotLoc || firstQuoteLoc < firstDotLoc) &&
|
|
|
|
(firstSpaceLoc < firstColonLoc || firstQuoteLoc < firstColonLoc) &&
|
|
|
|
(firstSpaceLoc < firstQMarkLoc || firstQuoteLoc < firstQMarkLoc)) || firstQMarkLoc == 0 ||
|
|
|
|
(isValidAsciiHost && isValidHost && !hasAsciiAlpha &&
|
|
|
|
host.EqualsIgnoreCase(asciiHost.get()))) {
|
|
|
|
|
2014-08-29 13:13:00 +04:00
|
|
|
rv = KeywordToURI(aFixupInfo->mOriginalInput, aPostData,
|
2014-04-25 02:42:00 +04:00
|
|
|
getter_AddRefs(aFixupInfo->mPreferredURI));
|
2014-09-10 20:42:00 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && aFixupInfo->mPreferredURI) {
|
2014-04-25 02:42:00 +04:00
|
|
|
aFixupInfo->mFixupUsedKeyword = true;
|
|
|
|
}
|
|
|
|
}
|
2014-07-25 14:46:07 +04:00
|
|
|
// ... or if there is no question mark or colon, and there is either no
|
|
|
|
// dot, or exactly 1 and it is the first or last character of the input:
|
2014-09-10 20:42:00 +04:00
|
|
|
else if ((firstDotLoc == uint32_t(kNotFound) ||
|
|
|
|
(foundDots == 1 && (firstDotLoc == 0 || firstDotLoc == aURIString.Length() - 1))) &&
|
|
|
|
firstColonLoc == uint32_t(kNotFound) && firstQMarkLoc == uint32_t(kNotFound)) {
|
2014-08-29 07:25:02 +04:00
|
|
|
|
2014-09-10 20:42:00 +04:00
|
|
|
if (isValidAsciiHost && IsDomainWhitelisted(asciiHost, firstDotLoc)) {
|
|
|
|
return;
|
2014-04-25 02:42:00 +04:00
|
|
|
}
|
2014-08-29 07:25:02 +04:00
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
// If we get here, we don't have a valid URI, or we did but the
|
|
|
|
// host is not whitelisted, so we do a keyword search *anyway*:
|
2014-08-25 17:54:00 +04:00
|
|
|
rv = KeywordToURI(aFixupInfo->mOriginalInput, aPostData,
|
2014-04-25 02:42:00 +04:00
|
|
|
getter_AddRefs(aFixupInfo->mPreferredURI));
|
2014-09-10 20:42:00 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && aFixupInfo->mPreferredURI) {
|
2014-04-25 02:42:00 +04:00
|
|
|
aFixupInfo->mFixupUsedKeyword = true;
|
|
|
|
}
|
2004-12-05 01:38:54 +03:00
|
|
|
}
|
2000-11-09 00:00:37 +03:00
|
|
|
}
|
|
|
|
|
2014-08-29 07:25:02 +04:00
|
|
|
bool nsDefaultURIFixup::IsDomainWhitelisted(const nsAutoCString aAsciiHost,
|
|
|
|
const uint32_t aDotLoc)
|
|
|
|
{
|
|
|
|
// Check if this domain is whitelisted as an actual
|
|
|
|
// domain (which will prevent a keyword query)
|
|
|
|
// NB: any processing of the host here should stay in sync with
|
|
|
|
// code in the front-end(s) that set the pref.
|
|
|
|
|
|
|
|
nsAutoCString pref("browser.fixup.domainwhitelist.");
|
|
|
|
|
|
|
|
if (aDotLoc == aAsciiHost.Length() - 1) {
|
|
|
|
pref.Append(Substring(aAsciiHost, 0, aAsciiHost.Length() - 1));
|
|
|
|
} else {
|
|
|
|
pref.Append(aAsciiHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Preferences::GetBool(pref.get(), false);
|
|
|
|
}
|
|
|
|
|
2014-07-25 14:46:07 +04:00
|
|
|
|
2000-11-09 00:00:37 +03:00
|
|
|
nsresult NS_NewURIFixup(nsIURIFixup **aURIFixup)
|
|
|
|
{
|
|
|
|
nsDefaultURIFixup *fixup = new nsDefaultURIFixup;
|
2012-07-30 18:20:58 +04:00
|
|
|
if (fixup == nullptr)
|
2000-11-09 00:00:37 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return fixup->QueryInterface(NS_GET_IID(nsIURIFixup), (void **) aURIFixup);
|
|
|
|
}
|
|
|
|
|
2014-04-25 02:42:00 +04:00
|
|
|
|
|
|
|
/* Implementation of nsIURIFixupInfo */
|
|
|
|
NS_IMPL_ISUPPORTS(nsDefaultURIFixupInfo, nsIURIFixupInfo)
|
|
|
|
|
|
|
|
nsDefaultURIFixupInfo::nsDefaultURIFixupInfo(const nsACString& aOriginalInput):
|
|
|
|
mFixupUsedKeyword(false),
|
2014-07-25 14:46:07 +04:00
|
|
|
mFixupChangedProtocol(false),
|
|
|
|
mFixupCreatedAlternateURI(false)
|
2014-04-25 02:42:00 +04:00
|
|
|
{
|
|
|
|
mOriginalInput = aOriginalInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsDefaultURIFixupInfo::~nsDefaultURIFixupInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixupInfo::GetConsumer(nsISupports** aConsumer)
|
|
|
|
{
|
|
|
|
*aConsumer = mConsumer;
|
|
|
|
NS_IF_ADDREF(*aConsumer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixupInfo::SetConsumer(nsISupports* aConsumer)
|
|
|
|
{
|
|
|
|
mConsumer = aConsumer;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixupInfo::GetPreferredURI(nsIURI** aPreferredURI)
|
|
|
|
{
|
|
|
|
*aPreferredURI = mPreferredURI;
|
|
|
|
NS_IF_ADDREF(*aPreferredURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixupInfo::GetFixedURI(nsIURI** aFixedURI)
|
|
|
|
{
|
|
|
|
*aFixedURI = mFixedURI;
|
|
|
|
NS_IF_ADDREF(*aFixedURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixupInfo::GetFixupUsedKeyword(bool* aOut)
|
|
|
|
{
|
|
|
|
*aOut = mFixupUsedKeyword;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-07-25 14:46:07 +04:00
|
|
|
nsDefaultURIFixupInfo::GetFixupChangedProtocol(bool* aOut)
|
2014-04-25 02:42:00 +04:00
|
|
|
{
|
2014-07-25 14:46:07 +04:00
|
|
|
*aOut = mFixupChangedProtocol;
|
2014-04-25 02:42:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-07-25 14:46:07 +04:00
|
|
|
nsDefaultURIFixupInfo::GetFixupCreatedAlternateURI(bool* aOut)
|
2014-04-25 02:42:00 +04:00
|
|
|
{
|
2014-07-25 14:46:07 +04:00
|
|
|
*aOut = mFixupCreatedAlternateURI;
|
2014-04-25 02:42:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDefaultURIFixupInfo::GetOriginalInput(nsACString& aInput)
|
|
|
|
{
|
|
|
|
aInput = mOriginalInput;
|
|
|
|
return NS_OK;
|
|
|
|
}
|