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) { |
| 43 // Fixes up url, e.g., convert "google.com" to "http://google.com". | |
| 44 // It also converts "starwar" to "http://starwar/" (a valid GURL but no | |
|
Kevin M
2016/04/07 23:00:19
starwar => "example" (don't want trademarks in cod
haibinlu
2016/04/07 23:55:09
Done.
| |
| 45 // website). In order to use search instead in this case, we check | |
| 46 // the host part of the URL to see if it contains '.', and use search | |
| 47 // instead if it does not. Note that this heuristic is not correct, since | |
| 48 // valid GURL such as "chrome://version/" do not have '.'. The heuristic is | |
| 49 // used only for v0.5 and useful for dev&test. | |
| 50 // TODO(haibinlu): Remove once omnibox is used. | |
| 51 GURL url = url_formatter::FixupURL(url_text, ""); | |
| 52 if (!url.is_valid() || url.host().find('.') == std::string::npos) { | |
| 53 url = url_formatter::FixupURL("https://www.google.com/#q=" + url_text, ""); | |
| 54 } | |
| 55 | |
| 42 NavigationMessage* navigation_message; | 56 NavigationMessage* navigation_message; |
| 43 scoped_ptr<BlimpMessage> blimp_message = | 57 scoped_ptr<BlimpMessage> blimp_message = |
| 44 CreateBlimpMessage(&navigation_message, tab_id); | 58 CreateBlimpMessage(&navigation_message, tab_id); |
| 45 navigation_message->set_type(NavigationMessage::LOAD_URL); | 59 navigation_message->set_type(NavigationMessage::LOAD_URL); |
| 46 navigation_message->mutable_load_url()->set_url(url_text); | 60 navigation_message->mutable_load_url()->set_url(url.spec()); |
| 47 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), | 61 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), |
| 48 net::CompletionCallback()); | 62 net::CompletionCallback()); |
| 49 } | 63 } |
| 50 | 64 |
| 51 void NavigationFeature::Reload(int tab_id) { | 65 void NavigationFeature::Reload(int tab_id) { |
| 52 NavigationMessage* navigation_message; | 66 NavigationMessage* navigation_message; |
| 53 scoped_ptr<BlimpMessage> blimp_message = | 67 scoped_ptr<BlimpMessage> blimp_message = |
| 54 CreateBlimpMessage(&navigation_message, tab_id); | 68 CreateBlimpMessage(&navigation_message, tab_id); |
| 55 navigation_message->set_type(NavigationMessage::RELOAD); | 69 navigation_message->set_type(NavigationMessage::RELOAD); |
| 56 | 70 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate( | 142 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate( |
| 129 const int tab_id) { | 143 const int tab_id) { |
| 130 DelegateMap::const_iterator it = delegates_.find(tab_id); | 144 DelegateMap::const_iterator it = delegates_.find(tab_id); |
| 131 if (it != delegates_.end()) | 145 if (it != delegates_.end()) |
| 132 return it->second; | 146 return it->second; |
| 133 return nullptr; | 147 return nullptr; |
| 134 } | 148 } |
| 135 | 149 |
| 136 } // namespace client | 150 } // namespace client |
| 137 } // namespace blimp | 151 } // namespace blimp |
| OLD | NEW |