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

Side by Side Diff: blimp/client/core/contents/navigation_feature.cc

Issue 2624903006: Remove all blimp client code. (Closed)
Patch Set: Update buildbot configuration Created 3 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "blimp/client/core/contents/navigation_feature.h"
6
7 #include <map>
8 #include <string>
9
10 #include "blimp/common/create_blimp_message.h"
11 #include "blimp/common/proto/blimp_message.pb.h"
12 #include "blimp/common/proto/navigation.pb.h"
13 #include "components/url_formatter/url_fixer.h"
14 #include "net/base/net_errors.h"
15 #include "url/gurl.h"
16 #include "url/url_canon.h"
17 #include "url/url_util.h"
18
19 namespace blimp {
20 namespace client {
21
22 NavigationFeature::NavigationFeature() {}
23
24 NavigationFeature::~NavigationFeature() {}
25
26 void NavigationFeature::set_outgoing_message_processor(
27 std::unique_ptr<BlimpMessageProcessor> processor) {
28 outgoing_message_processor_ = std::move(processor);
29 }
30
31 void NavigationFeature::SetDelegate(int tab_id,
32 NavigationFeatureDelegate* delegate) {
33 DCHECK(!FindDelegate(tab_id));
34 delegates_[tab_id] = delegate;
35 }
36
37 void NavigationFeature::RemoveDelegate(int tab_id) {
38 auto it = delegates_.find(tab_id);
39 if (it != delegates_.end())
40 delegates_.erase(it);
41 }
42
43 void NavigationFeature::NavigateToUrlText(int tab_id,
44 const std::string& url_text) {
45 GURL url = url_formatter::FixupURL(url_text, std::string());
46 NavigationMessage* navigation_message;
47 std::unique_ptr<BlimpMessage> blimp_message =
48 CreateBlimpMessage(&navigation_message, tab_id);
49 navigation_message->set_type(NavigationMessage::LOAD_URL);
50 // Use the possibly invalid spec here. Just load what we're getting from the
51 // embedder.
52 navigation_message->mutable_load_url()->set_url(url.possibly_invalid_spec());
53 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
54 net::CompletionCallback());
55 }
56
57 void NavigationFeature::Reload(int tab_id) {
58 NavigationMessage* navigation_message;
59 std::unique_ptr<BlimpMessage> blimp_message =
60 CreateBlimpMessage(&navigation_message, tab_id);
61 navigation_message->set_type(NavigationMessage::RELOAD);
62
63 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
64 net::CompletionCallback());
65 }
66
67 void NavigationFeature::GoForward(int tab_id) {
68 NavigationMessage* navigation_message;
69 std::unique_ptr<BlimpMessage> blimp_message =
70 CreateBlimpMessage(&navigation_message, tab_id);
71 navigation_message->set_type(NavigationMessage::GO_FORWARD);
72
73 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
74 net::CompletionCallback());
75 }
76
77 void NavigationFeature::GoBack(int tab_id) {
78 NavigationMessage* navigation_message;
79 std::unique_ptr<BlimpMessage> blimp_message =
80 CreateBlimpMessage(&navigation_message, tab_id);
81 navigation_message->set_type(NavigationMessage::GO_BACK);
82
83 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
84 net::CompletionCallback());
85 }
86
87 void NavigationFeature::ProcessMessage(
88 std::unique_ptr<BlimpMessage> message,
89 const net::CompletionCallback& callback) {
90 DCHECK(!callback.is_null());
91 DCHECK_EQ(BlimpMessage::kNavigation, message->feature_case());
92
93 int tab_id = message->target_tab_id();
94 const NavigationMessage& navigation_message = message->navigation();
95
96 NavigationFeatureDelegate* delegate = FindDelegate(tab_id);
97 if (!delegate) {
98 VLOG(1) << "NavigationFeatureDelegate not found for " << tab_id
99 << ". Ignoring.";
100 callback.Run(net::OK);
101 return;
102 }
103
104 switch (navigation_message.type()) {
105 case NavigationMessage::NAVIGATION_STATE_CHANGED: {
106 const NavigationStateChangeMessage& details =
107 navigation_message.navigation_state_changed();
108 if (details.has_url())
109 delegate->OnUrlChanged(tab_id, GURL(details.url()));
110
111 if (details.has_title())
112 delegate->OnTitleChanged(tab_id, details.title());
113
114 if (details.has_loading())
115 delegate->OnLoadingChanged(tab_id, details.loading());
116
117 if (details.has_favicon()) {
118 NOTIMPLEMENTED();
119 }
120
121 if (details.has_page_load_completed()) {
122 delegate->OnPageLoadStatusUpdate(tab_id, details.page_load_completed());
123 }
124 } break;
125 case NavigationMessage::LOAD_URL:
126 case NavigationMessage::GO_BACK:
127 case NavigationMessage::GO_FORWARD:
128 case NavigationMessage::RELOAD:
129 NOTREACHED() << "Client received unexpected navigation type.";
130 break;
131 case NavigationMessage::UNKNOWN:
132 NOTREACHED();
133 }
134
135 callback.Run(net::OK);
136 }
137
138 NavigationFeature::NavigationFeatureDelegate* NavigationFeature::FindDelegate(
139 const int tab_id) {
140 base::SmallMap<std::map<int, NavigationFeatureDelegate*>>::const_iterator it =
141 delegates_.find(tab_id);
142 if (it != delegates_.end())
143 return it->second;
144 return nullptr;
145 }
146
147 } // namespace client
148 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/contents/navigation_feature.h ('k') | blimp/client/core/contents/navigation_feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698