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

Side by Side Diff: blimp/engine/session/tab_blimp.cc

Issue 2035543002: [Blimp] Creates engine tab class to handle tab related operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2016 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/engine/session/tab_blimp.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/trace_event/trace_event.h"
9 #include "blimp/common/create_blimp_message.h"
10 #include "blimp/common/proto/blimp_message.pb.h"
11 #include "blimp/common/proto/render_widget.pb.h"
12 #include "blimp/common/proto/tab_control.pb.h"
13 #include "blimp/engine/common/blimp_user_agent.h"
14 #include "blimp/engine/feature/engine_render_widget_feature.h"
15 #include "blimp/net/blimp_message_processor.h"
16 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/render_widget_host.h"
20 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/web_contents.h"
22 #include "ui/aura/window.h"
23 #include "ui/gfx/geometry/size.h"
24
25 namespace blimp {
26 namespace engine {
27
28 TabBlimp::TabBlimp(std::unique_ptr<content::WebContents> web_contents,
29 const int tab_id,
30 EngineRenderWidgetFeature* render_widget_feature,
31 BlimpMessageProcessor* navigation_message_sender)
32 : web_contents_(std::move(web_contents)),
33 tab_id_(tab_id),
34 render_widget_feature_(render_widget_feature),
35 navigation_message_sender_(navigation_message_sender),
36 page_load_tracker_(new PageLoadTracker(web_contents_.get(), this)) {
37 DCHECK(render_widget_feature_);
38 DCHECK(navigation_message_sender_);
39
40 // A Tab is created upon client's request, thus an updated
41 // user agent info (containing client OS info) is available, and we will use
42 // that to override user agent string from BlimpContentRendererClient.
43 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent());
44
45 Observe(web_contents_.get());
46 }
47
48 TabBlimp::~TabBlimp() {}
49
50 void TabBlimp::Resize(float device_pixel_ratio, const gfx::Size& size_in_dips) {
51 DVLOG(1) << "Resize to " << size_in_dips.ToString() << ", "
52 << device_pixel_ratio;
53 web_contents_->GetNativeView()->SetBounds(gfx::Rect(size_in_dips));
54
55 if (web_contents_->GetRenderViewHost() &&
56 web_contents_->GetRenderViewHost()->GetWidget()) {
57 web_contents_->GetRenderViewHost()->GetWidget()->WasResized();
58 }
59 }
60
61 void TabBlimp::LoadUrl(const GURL& url) {
62 TRACE_EVENT1("blimp", "TabBlimp::LoadUrl", "URL", url.spec());
63 DVLOG(1) << "Load URL " << url << " in tab " << tab_id_;
64 if (!url.is_valid()) {
65 VLOG(1) << "Dropping invalid URL " << url;
66 return;
67 }
68
69 content::NavigationController::LoadURLParams params(url);
70 params.transition_type = ui::PageTransitionFromInt(
71 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
72 params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
73 web_contents_->GetController().LoadURLWithParams(params);
74 web_contents_->Focus();
75 }
76
77 void TabBlimp::GoBack() {
78 DVLOG(1) << "Back in tab " << tab_id_;
79 web_contents_->GetController().GoBack();
80 }
81
82 void TabBlimp::GoForward() {
83 DVLOG(1) << "Forward in tab " << tab_id_;
84 web_contents_->GetController().GoForward();
85 }
86
87 void TabBlimp::Reload() {
88 DVLOG(1) << "Reload in tab " << tab_id_;
89 web_contents_->GetController().Reload(true);
90 }
91
92 void TabBlimp::RenderViewCreated(content::RenderViewHost* render_view_host) {
93 DCHECK(render_view_host);
94 render_widget_feature_->OnRenderWidgetCreated(tab_id_,
95 render_view_host->GetWidget());
96 }
97
98 void TabBlimp::RenderViewHostChanged(content::RenderViewHost* old_host,
99 content::RenderViewHost* new_host) {
100 render_widget_feature_->OnRenderWidgetInitialized(tab_id_,
101 new_host->GetWidget());
102 }
103
104 void TabBlimp::RenderViewDeleted(content::RenderViewHost* render_view_host) {
105 render_widget_feature_->OnRenderWidgetDeleted(tab_id_,
106 render_view_host->GetWidget());
107 }
108
109 void TabBlimp::NavigationStateChanged(content::InvalidateTypes changed_flags) {
110 if (!changed_flags)
Kevin M 2016/06/06 21:44:39 Should this ever happen? Shall we DCHECK it?
haibinlu 2016/06/06 22:32:28 InvalidateTypes has no type at value 0. but chrom
111 return;
112
113 NavigationMessage* navigation_message;
114 std::unique_ptr<BlimpMessage> message =
115 CreateBlimpMessage(&navigation_message, tab_id_);
116 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED);
117 NavigationStateChangeMessage* details =
118 navigation_message->mutable_navigation_state_changed();
119
120 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_URL)
121 details->set_url(web_contents_->GetURL().spec());
122
123 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TAB) {
124 // TODO(dtrainor): Serialize the favicon? crbug.com/597094.
125 DVLOG(3) << "Tab favicon changed";
126 }
127
128 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE)
129 details->set_title(base::UTF16ToUTF8(web_contents_->GetTitle()));
130
131 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD)
132 details->set_loading(web_contents_->IsLoading());
133
134 navigation_message_sender_->ProcessMessage(std::move(message),
135 net::CompletionCallback());
136 }
137
138 void TabBlimp::SendPageLoadStatusUpdate(PageLoadStatus load_status) {
139 bool page_load_completed = false;
Kevin M 2016/06/06 21:44:38 Replace switch with bool page_load_completed = lo
haibinlu 2016/06/06 22:32:28 Done.
140 switch (load_status) {
141 case PageLoadStatus::LOADING:
142 page_load_completed = false;
143 break;
144 case PageLoadStatus::LOADED:
145 page_load_completed = true;
146 break;
147 }
148
149 NavigationMessage* navigation_message = nullptr;
150 std::unique_ptr<BlimpMessage> message =
151 CreateBlimpMessage(&navigation_message, tab_id_);
152 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED);
153 navigation_message->mutable_navigation_state_changed()
154 ->set_page_load_completed(page_load_completed);
155
156 navigation_message_sender_->ProcessMessage(std::move(message),
157 net::CompletionCallback());
158 }
159
160 } // namespace engine
161 } // namespace blimp
OLDNEW
« blimp/engine/session/tab_blimp.h ('K') | « blimp/engine/session/tab_blimp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698