WebPositive: parse "host:port" as a valid URL
* Web+ would not understand this and do a search engine query instead. * Fixes #11726 * Also add some comments to _SmartURLHandler to make it clearer how it handles URLs.
This commit is contained in:
@@ -1546,7 +1546,7 @@ BrowserWindow::MainDocumentError(const BString& failingURL,
|
|||||||
|
|
||||||
// Try delegating the URL to an external app instead.
|
// Try delegating the URL to an external app instead.
|
||||||
int32 at = failingURL.FindFirst(":");
|
int32 at = failingURL.FindFirst(":");
|
||||||
if (at != B_ERROR) {
|
if (at > 0) {
|
||||||
BString proto;
|
BString proto;
|
||||||
failingURL.CopyInto(proto, 0, at);
|
failingURL.CopyInto(proto, 0, at);
|
||||||
|
|
||||||
@@ -2461,20 +2461,27 @@ BrowserWindow::_IsValidDomainChar(char ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief "smart" parser for user-entered URLs
|
||||||
|
|
||||||
|
We try to be flexible in what we accept as a valid URL. The protocol may
|
||||||
|
be missing, or something we can't handle (in that case we run the matching
|
||||||
|
app). If all attempts to make sense of the input fail, we make a search
|
||||||
|
engine query for it.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
BrowserWindow::_SmartURLHandler(const BString& url)
|
BrowserWindow::_SmartURLHandler(const BString& url)
|
||||||
{
|
{
|
||||||
// Only process if this doesn't look like a full URL (http:// or
|
// First test if the URL has a protocol field
|
||||||
// file://, etc.)
|
|
||||||
|
|
||||||
int32 at = url.FindFirst(":");
|
int32 at = url.FindFirst(":");
|
||||||
|
|
||||||
if (at != B_ERROR) {
|
if (at != B_ERROR) {
|
||||||
|
// There is a protocol, let's see if we can handle it
|
||||||
BString proto;
|
BString proto;
|
||||||
url.CopyInto(proto, 0, at);
|
url.CopyInto(proto, 0, at);
|
||||||
|
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
|
|
||||||
|
// First try the built-in supported ones
|
||||||
for (unsigned int i = 0; i < sizeof(kHandledProtocols) / sizeof(char*);
|
for (unsigned int i = 0; i < sizeof(kHandledProtocols) / sizeof(char*);
|
||||||
i++) {
|
i++) {
|
||||||
handled = (proto == kHandledProtocols[i]);
|
handled = (proto == kHandledProtocols[i]);
|
||||||
@@ -2482,26 +2489,43 @@ BrowserWindow::_SmartURLHandler(const BString& url)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handled)
|
if (handled) {
|
||||||
|
// This is the easy case, a complete and well-formed URL, we can
|
||||||
|
// navigate to it without further efforts.
|
||||||
_VisitURL(url);
|
_VisitURL(url);
|
||||||
else {
|
return;
|
||||||
|
} else {
|
||||||
|
// There is what looks like a protocol, but one we don't know.
|
||||||
|
// Ask the BRoster if there is a matching filetype and app which
|
||||||
|
// can handle it.
|
||||||
BString temp;
|
BString temp;
|
||||||
temp = "application/x-vnd.Be.URL.";
|
temp = "application/x-vnd.Be.URL.";
|
||||||
temp += proto;
|
temp += proto;
|
||||||
|
|
||||||
char* argv[1] = { (char*)url.String() };
|
char* argv[1] = { (char*)url.String() };
|
||||||
|
|
||||||
if (be_roster->Launch(temp.String(), 1, argv) != B_OK)
|
if (be_roster->Launch(temp.String(), 1, argv) == B_OK)
|
||||||
_VisitSearchEngine(url);
|
return;
|
||||||
}
|
}
|
||||||
} else if (url == "localhost")
|
}
|
||||||
|
|
||||||
|
// There is no protocol or only an unsupported one. So let's try harder to
|
||||||
|
// guess what the request is.
|
||||||
|
|
||||||
|
// "localhost" is a special case, it is a valid domain name but has no dots.
|
||||||
|
// Handle it separately.
|
||||||
|
if (url == "localhost")
|
||||||
_VisitURL("http://localhost/");
|
_VisitURL("http://localhost/");
|
||||||
else {
|
else {
|
||||||
|
// Also handle URLs starting with "localhost" followed by a path.
|
||||||
const char* localhostPrefix = "localhost/";
|
const char* localhostPrefix = "localhost/";
|
||||||
|
|
||||||
if (url.Compare(localhostPrefix, strlen(localhostPrefix)) == 0)
|
if (url.Compare(localhostPrefix, strlen(localhostPrefix)) == 0)
|
||||||
_VisitURL(url);
|
_VisitURL(url);
|
||||||
else {
|
else {
|
||||||
|
// In all other cases we try to detect a valid domain name. There
|
||||||
|
// must be at least one dot and no spaces until the first / in the
|
||||||
|
// URL.
|
||||||
bool isURL = false;
|
bool isURL = false;
|
||||||
|
|
||||||
for (int32 i = 0; i < url.CountChars(); i++) {
|
for (int32 i = 0; i < url.CountChars(); i++) {
|
||||||
@@ -2516,10 +2540,19 @@ BrowserWindow::_SmartURLHandler(const BString& url)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isURL)
|
if (isURL) {
|
||||||
_VisitURL(url);
|
// This is apparently an URL missing the protocol part. In that
|
||||||
else
|
// case we default to http.
|
||||||
|
BString prefixed = "http://";
|
||||||
|
prefixed << url;
|
||||||
|
_VisitURL(prefixed);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// We couldn't find anything that looks like an URL. Let's
|
||||||
|
// assume what we have is a search request and go to the search
|
||||||
|
// engine.
|
||||||
_VisitSearchEngine(url);
|
_VisitSearchEngine(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user