WebPositive: Smart URL handling improvements (GCI task)
- Fixed: WebPositive now successfuly detects foreign protocols and launches their respective applications. - Improved: The decision whether to use a search engine or a DNS lookup for the text entered in the address bar, including for internationalized names (IDN) (though we do not handle them correctly later on yet). - TODO: escape the query string before passing it to webkit (for example for: "3+4")
This commit is contained in:
parent
4b84a0b5c8
commit
bafbb92901
|
@ -652,11 +652,10 @@ BrowserWindow::MessageReceived(BMessage* message)
|
|||
BString url;
|
||||
if (message->FindString("url", &url) != B_OK)
|
||||
url = fURLInputGroup->Text();
|
||||
|
||||
_SetPageIcon(CurrentWebView(), NULL);
|
||||
BString newUrl = _SmartURLHandler(url);
|
||||
if (newUrl != url)
|
||||
fURLInputGroup->TextView()->SetText(newUrl);
|
||||
CurrentWebView()->LoadURL(newUrl.String());
|
||||
_SmartURLHandler(url);
|
||||
|
||||
break;
|
||||
}
|
||||
case GO_BACK:
|
||||
|
@ -2149,18 +2148,93 @@ BrowserWindow::_NewTabURL(bool isNewWindow) const
|
|||
}
|
||||
|
||||
|
||||
BString
|
||||
BrowserWindow::_SmartURLHandler(const BString& url) const
|
||||
void
|
||||
BrowserWindow::_VisitURL(const BString& url)
|
||||
{
|
||||
BString result = url;
|
||||
//fURLInputGroup->TextView()->SetText(url);
|
||||
CurrentWebView()->LoadURL(url.String());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BrowserWindow::_VisitSearchEngine(const BString& search)
|
||||
{
|
||||
// TODO: Google Code-In Task to make default search
|
||||
// engine modifiable from Settings? :)
|
||||
|
||||
BString engine = "http://www.google.com/search?q=";
|
||||
engine += search;
|
||||
// WebKit takes care of URL encoding here.
|
||||
|
||||
_VisitURL(engine);
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
BrowserWindow::_IsValidDomainChar(char ch)
|
||||
{
|
||||
// TODO: Currenlty, only a whitespace character
|
||||
// breaks a domain name. It might be
|
||||
// a good idea (or a bad one) to make
|
||||
// character filtering based on the
|
||||
// IDNA 2008 standard.
|
||||
|
||||
return ch != ' ';
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BrowserWindow::_SmartURLHandler(const BString& url)
|
||||
{
|
||||
// Only process if this doesn't look like a full URL (http:// or
|
||||
// file://, etc.)
|
||||
if (url.FindFirst("://") == B_ERROR) {
|
||||
if (url.FindFirst(".") == B_ERROR || url.FindFirst(" ") != B_ERROR)
|
||||
result.Prepend("http://www.google.com/search?q=");
|
||||
|
||||
BString temp;
|
||||
int32 at = url.FindFirst(":");
|
||||
|
||||
if (at != B_ERROR) {
|
||||
BString proto;
|
||||
url.CopyInto(proto, 0, at);
|
||||
|
||||
if (proto == "http" || proto == "https" || proto == "file")
|
||||
_VisitURL(url);
|
||||
else {
|
||||
temp = "application/x-vnd.Be.URL.";
|
||||
temp += proto;
|
||||
|
||||
char* argv[1] = { (char*)url.String() };
|
||||
|
||||
if (be_roster->Launch(temp.String(), 1, argv) != B_OK)
|
||||
_VisitSearchEngine(url);
|
||||
}
|
||||
} else if (url == "localhost")
|
||||
_VisitURL("http://localhost/");
|
||||
else {
|
||||
const char* localhostPrefix = "localhost/";
|
||||
|
||||
if(url.Compare(localhostPrefix, strlen(localhostPrefix)) == 0)
|
||||
_VisitURL(url);
|
||||
else {
|
||||
bool isURL = false;
|
||||
|
||||
for (int32 i = 0; i < url.CountChars(); i++) {
|
||||
if (url[i] == '.')
|
||||
isURL = true;
|
||||
else if (url[i] == '/')
|
||||
break;
|
||||
else if (!_IsValidDomainChar(url[i])) {
|
||||
isURL = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isURL)
|
||||
_VisitURL(url);
|
||||
else
|
||||
_VisitSearchEngine(url);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -190,7 +190,11 @@ private:
|
|||
void _InvokeButtonVisibly(BButton* button);
|
||||
|
||||
BString _NewTabURL(bool isNewWindow) const;
|
||||
BString _SmartURLHandler(const BString& url) const;
|
||||
|
||||
void _VisitURL(const BString& url);
|
||||
void _VisitSearchEngine(const BString& search);
|
||||
inline bool _IsValidDomainChar(char ch);
|
||||
void _SmartURLHandler(const BString& url);
|
||||
|
||||
void _HandlePageSourceResult(
|
||||
const BMessage* message);
|
||||
|
|
Loading…
Reference in New Issue