Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/feature/navigation_feature.h" | 5 #include "blimp/client/feature/navigation_feature.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "blimp/common/create_blimp_message.h" | 10 #include "blimp/common/create_blimp_message.h" |
| 11 #include "blimp/common/proto/blimp_message.pb.h" | 11 #include "blimp/common/proto/blimp_message.pb.h" |
| 12 #include "blimp/common/proto/navigation.pb.h" | 12 #include "blimp/common/proto/navigation.pb.h" |
| 13 #include "components/url_formatter/url_fixer.h" | |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace blimp { | 17 namespace blimp { |
| 17 namespace client { | 18 namespace client { |
| 18 | 19 |
| 19 NavigationFeature::NavigationFeature() {} | 20 NavigationFeature::NavigationFeature() {} |
| 20 | 21 |
| 21 NavigationFeature::~NavigationFeature() {} | 22 NavigationFeature::~NavigationFeature() {} |
| 22 | 23 |
| 23 void NavigationFeature::set_outgoing_message_processor( | 24 void NavigationFeature::set_outgoing_message_processor( |
| 24 scoped_ptr<BlimpMessageProcessor> processor) { | 25 scoped_ptr<BlimpMessageProcessor> processor) { |
| 25 outgoing_message_processor_ = std::move(processor); | 26 outgoing_message_processor_ = std::move(processor); |
| 26 } | 27 } |
| 27 | 28 |
| 28 void NavigationFeature::SetDelegate(int tab_id, | 29 void NavigationFeature::SetDelegate(int tab_id, |
| 29 NavigationFeatureDelegate* delegate) { | 30 NavigationFeatureDelegate* delegate) { |
| 30 DCHECK(!FindDelegate(tab_id)); | 31 DCHECK(!FindDelegate(tab_id)); |
| 31 delegates_[tab_id] = delegate; | 32 delegates_[tab_id] = delegate; |
| 32 } | 33 } |
| 33 | 34 |
| 34 void NavigationFeature::RemoveDelegate(int tab_id) { | 35 void NavigationFeature::RemoveDelegate(int tab_id) { |
| 35 DelegateMap::iterator it = delegates_.find(tab_id); | 36 DelegateMap::iterator it = delegates_.find(tab_id); |
| 36 if (it != delegates_.end()) | 37 if (it != delegates_.end()) |
| 37 delegates_.erase(it); | 38 delegates_.erase(it); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void NavigationFeature::NavigateToUrlText(int tab_id, | 41 void NavigationFeature::NavigateToUrlText(int tab_id, |
| 41 const std::string& url_text) { | 42 const std::string& url_text) { |
|
Kevin M
2016/04/07 20:17:00
Add unit tests for fixing up the URL.
haibinlu
2016/04/07 22:28:59
This is a temp (and wrong) fix for v0.5. not sure
| |
| 43 // Simplified heuristic for v0.5 only. | |
|
Kevin M
2016/04/07 20:12:30
Add explanation as to *what* this is doing.
haibinlu
2016/04/07 22:28:59
Done.
| |
| 44 // TODO(haibinlu): Remove once omnibox is used. | |
| 45 GURL url = url_formatter::FixupURL(url_text, ""); | |
| 46 if (!url.is_valid() || url.host().find('.') == std::string::npos) { | |
|
Kevin M
2016/04/07 20:12:30
Add comment on the reason and behavior of this heu
haibinlu
2016/04/07 22:28:59
Done.
| |
| 47 url = url_formatter::FixupURL("https://www.google.com/#q=" + url_text, ""); | |
|
Kevin M
2016/04/07 20:12:30
url_text needs to be querystring encoded in this c
haibinlu
2016/04/07 22:28:59
FixupURL will do that.
Kevin M
2016/04/07 23:00:19
What if the searched text was "1+2"? Would FixupUR
haibinlu
2016/04/07 23:55:09
you are right. it needs encoding.
| |
| 48 } | |
| 49 | |
| 50 DCHECK(url.is_valid()); | |
|
Kevin M
2016/04/07 20:12:30
DCHECK is a poor fit here ("url" is built from use
haibinlu
2016/04/07 22:28:59
removed the DCHECK. with FixupURL on google search
| |
| 42 NavigationMessage* navigation_message; | 51 NavigationMessage* navigation_message; |
| 43 scoped_ptr<BlimpMessage> blimp_message = | 52 scoped_ptr<BlimpMessage> blimp_message = |
| 44 CreateBlimpMessage(&navigation_message, tab_id); | 53 CreateBlimpMessage(&navigation_message, tab_id); |
| 45 navigation_message->set_type(NavigationMessage::LOAD_URL); | 54 navigation_message->set_type(NavigationMessage::LOAD_URL); |
| 46 navigation_message->mutable_load_url()->set_url(url_text); | 55 navigation_message->mutable_load_url()->set_url(url.spec()); |
| 47 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), | 56 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), |
| 48 net::CompletionCallback()); | 57 net::CompletionCallback()); |
| 49 } | 58 } |
| 50 | 59 |
| 51 void NavigationFeature::Reload(int tab_id) { | 60 void NavigationFeature::Reload(int tab_id) { |
| 52 NavigationMessage* navigation_message; | 61 NavigationMessage* navigation_message; |
| 53 scoped_ptr<BlimpMessage> blimp_message = | 62 scoped_ptr<BlimpMessage> blimp_message = |
| 54 CreateBlimpMessage(&navigation_message, tab_id); | 63 CreateBlimpMessage(&navigation_message, tab_id); |
| 55 navigation_message->set_type(NavigationMessage::RELOAD); | 64 navigation_message->set_type(NavigationMessage::RELOAD); |
| 56 | 65 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate( | 137 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate( |
| 129 const int tab_id) { | 138 const int tab_id) { |
| 130 DelegateMap::const_iterator it = delegates_.find(tab_id); | 139 DelegateMap::const_iterator it = delegates_.find(tab_id); |
| 131 if (it != delegates_.end()) | 140 if (it != delegates_.end()) |
| 132 return it->second; | 141 return it->second; |
| 133 return nullptr; | 142 return nullptr; |
| 134 } | 143 } |
| 135 | 144 |
| 136 } // namespace client | 145 } // namespace client |
| 137 } // namespace blimp | 146 } // namespace blimp |
| OLD | NEW |