Chromium Code Reviews| Index: blimp/client/feature/navigation_feature.cc |
| diff --git a/blimp/client/feature/navigation_feature.cc b/blimp/client/feature/navigation_feature.cc |
| index 973862d44983e27d1b7d070e4d4312d7562664ee..cacb2f19672471a3622b74b13922afe31b5b0c08 100644 |
| --- a/blimp/client/feature/navigation_feature.cc |
| +++ b/blimp/client/feature/navigation_feature.cc |
| @@ -10,8 +10,11 @@ |
| #include "blimp/common/create_blimp_message.h" |
| #include "blimp/common/proto/blimp_message.pb.h" |
| #include "blimp/common/proto/navigation.pb.h" |
| +#include "components/url_formatter/url_fixer.h" |
| #include "net/base/net_errors.h" |
| #include "url/gurl.h" |
| +#include "url/url_canon.h" |
| +#include "url/url_util.h" |
| namespace blimp { |
| namespace client { |
| @@ -39,11 +42,28 @@ void NavigationFeature::RemoveDelegate(int tab_id) { |
| void NavigationFeature::NavigateToUrlText(int tab_id, |
| const std::string& url_text) { |
| + // Fixes up url, e.g., convert "google.com" to "http://google.com". |
| + // It also converts "example" to "http://example/" (a valid GURL but no |
| + // website). In order to use search instead in this case, we check |
| + // the host part of the URL to see if it contains '.', and use search |
| + // instead if it does not. Note that this heuristic is not correct, since |
| + // valid GURL such as "chrome://version/" do not have '.'. The heuristic is |
|
brettw
2016/04/14 20:34:02
This will REALLY need to be changed since there's
haibinlu
2016/04/25 18:33:22
Yes, this is for current demo app. The next demo a
|
| + // used only for v0.5 and useful for dev&test. |
| + // TODO(haibinlu): Remove once omnibox is used. |
| + GURL url = url_formatter::FixupURL(url_text, ""); |
|
brettw
2016/04/14 20:34:02
"" -> std::string()
haibinlu
2016/04/25 18:33:22
Done.
|
| + if (!url.is_valid() || url.host().find('.') == std::string::npos) { |
|
brettw
2016/04/14 20:34:02
host() -> host_piece()
(this saves a copy)
haibinlu
2016/04/25 18:33:22
Done.
|
| + url::RawCanonOutputT<char> buffer; |
| + url::EncodeURIComponent(url_text.data(), url_text.size(), &buffer); |
| + std::string encoded_query(buffer.data(), buffer.length()); |
| + url = GURL("https://www.google.com/#q=" + encoded_query); |
| + DCHECK(url.is_valid()); |
| + } |
| + |
| NavigationMessage* navigation_message; |
| scoped_ptr<BlimpMessage> blimp_message = |
| CreateBlimpMessage(&navigation_message, tab_id); |
| navigation_message->set_type(NavigationMessage::LOAD_URL); |
| - navigation_message->mutable_load_url()->set_url(url_text); |
| + navigation_message->mutable_load_url()->set_url(url.spec()); |
| outgoing_message_processor_->ProcessMessage(std::move(blimp_message), |
| net::CompletionCallback()); |
| } |