Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: blimp/client/feature/navigation_feature.cc

Issue 1869783005: [Blimp Client] Fixes up URL before sending it to Engine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/client/DEPS ('k') | blimp/engine/session/blimp_engine_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
16 #include "url/url_canon.h"
17 #include "url/url_util.h"
15 18
16 namespace blimp { 19 namespace blimp {
17 namespace client { 20 namespace client {
18 21
19 NavigationFeature::NavigationFeature() {} 22 NavigationFeature::NavigationFeature() {}
20 23
21 NavigationFeature::~NavigationFeature() {} 24 NavigationFeature::~NavigationFeature() {}
22 25
23 void NavigationFeature::set_outgoing_message_processor( 26 void NavigationFeature::set_outgoing_message_processor(
24 scoped_ptr<BlimpMessageProcessor> processor) { 27 scoped_ptr<BlimpMessageProcessor> processor) {
25 outgoing_message_processor_ = std::move(processor); 28 outgoing_message_processor_ = std::move(processor);
26 } 29 }
27 30
28 void NavigationFeature::SetDelegate(int tab_id, 31 void NavigationFeature::SetDelegate(int tab_id,
29 NavigationFeatureDelegate* delegate) { 32 NavigationFeatureDelegate* delegate) {
30 DCHECK(!FindDelegate(tab_id)); 33 DCHECK(!FindDelegate(tab_id));
31 delegates_[tab_id] = delegate; 34 delegates_[tab_id] = delegate;
32 } 35 }
33 36
34 void NavigationFeature::RemoveDelegate(int tab_id) { 37 void NavigationFeature::RemoveDelegate(int tab_id) {
35 DelegateMap::iterator it = delegates_.find(tab_id); 38 DelegateMap::iterator it = delegates_.find(tab_id);
36 if (it != delegates_.end()) 39 if (it != delegates_.end())
37 delegates_.erase(it); 40 delegates_.erase(it);
38 } 41 }
39 42
40 void NavigationFeature::NavigateToUrlText(int tab_id, 43 void NavigationFeature::NavigateToUrlText(int tab_id,
41 const std::string& url_text) { 44 const std::string& url_text) {
45 // Fixes up url, e.g., convert "google.com" to "http://google.com".
46 // It also converts "example" to "http://example/" (a valid GURL but no
47 // website). In order to use search instead in this case, we check
48 // the host part of the URL to see if it contains '.', and use search
49 // instead if it does not. Note that this heuristic is not correct, since
50 // valid GURL such as "chrome://version/" do not have '.'. The heuristic is
51 // used only for v0.5 and useful for dev&test.
52 // TODO(haibinlu): Remove once omnibox is used.
53 GURL url = url_formatter::FixupURL(url_text, "");
54 if (!url.is_valid() || url.host().find('.') == std::string::npos) {
55 url::RawCanonOutputT<char> buffer;
56 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.
57 std::string encoded_query(buffer.data(), buffer.length());
58 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.
59 }
60
42 NavigationMessage* navigation_message; 61 NavigationMessage* navigation_message;
43 scoped_ptr<BlimpMessage> blimp_message = 62 scoped_ptr<BlimpMessage> blimp_message =
44 CreateBlimpMessage(&navigation_message, tab_id); 63 CreateBlimpMessage(&navigation_message, tab_id);
45 navigation_message->set_type(NavigationMessage::LOAD_URL); 64 navigation_message->set_type(NavigationMessage::LOAD_URL);
46 navigation_message->mutable_load_url()->set_url(url_text); 65 navigation_message->mutable_load_url()->set_url(url.spec());
47 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), 66 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
48 net::CompletionCallback()); 67 net::CompletionCallback());
49 } 68 }
50 69
51 void NavigationFeature::Reload(int tab_id) { 70 void NavigationFeature::Reload(int tab_id) {
52 NavigationMessage* navigation_message; 71 NavigationMessage* navigation_message;
53 scoped_ptr<BlimpMessage> blimp_message = 72 scoped_ptr<BlimpMessage> blimp_message =
54 CreateBlimpMessage(&navigation_message, tab_id); 73 CreateBlimpMessage(&navigation_message, tab_id);
55 navigation_message->set_type(NavigationMessage::RELOAD); 74 navigation_message->set_type(NavigationMessage::RELOAD);
56 75
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate( 147 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate(
129 const int tab_id) { 148 const int tab_id) {
130 DelegateMap::const_iterator it = delegates_.find(tab_id); 149 DelegateMap::const_iterator it = delegates_.find(tab_id);
131 if (it != delegates_.end()) 150 if (it != delegates_.end())
132 return it->second; 151 return it->second;
133 return nullptr; 152 return nullptr;
134 } 153 }
135 154
136 } // namespace client 155 } // namespace client
137 } // namespace blimp 156 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/DEPS ('k') | blimp/engine/session/blimp_engine_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698