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..5bac76e963903f50c7b5ee39c8a7f3ce7d48df89 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,27 @@ 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 |
| + // used only for v0.5 and useful for dev&test. |
| + // TODO(haibinlu): Remove once omnibox is used. |
| + GURL url = url_formatter::FixupURL(url_text, ""); |
| + if (!url.is_valid() || url.host().find('.') == std::string::npos) { |
| + url::RawCanonOutputT<char> buffer; |
| + url::EncodeURIComponent(url_text.data(), strlen(url_text.data()), &buffer); |
|
Kevin M
2016/04/08 00:14:33
url_text.size()
haibinlu
2016/04/08 00:51:39
Done.
|
| + std::string encoded_query(buffer.data(), buffer.length()); |
| + url = GURL("https://www.google.com/#q=" + encoded_query); |
|
Kevin M
2016/04/08 00:14:33
DCHECK for validity
haibinlu
2016/04/08 00:51:39
Done.
|
| + } |
| + |
| 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()); |
| } |