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

Side by Side Diff: blimp/engine/session/tab.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
« blimp/engine/session/tab.h ('K') | « blimp/engine/session/tab.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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 Tab::Tab(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 Tab::~Tab() {}
49
50 void Tab::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 Tab::LoadUrl(const GURL& url) {
62 TRACE_EVENT1("blimp", "Tab::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 Tab::GoBack() {
78 DVLOG(1) << "Back in tab " << tab_id_;
79 web_contents_->GetController().GoBack();
80 }
81
82 void Tab::GoForward() {
83 DVLOG(1) << "Forward in tab " << tab_id_;
84 web_contents_->GetController().GoForward();
85 }
86
87 void Tab::Reload() {
88 DVLOG(1) << "Reload in tab " << tab_id_;
89 web_contents_->GetController().Reload(true);
90 }
91
92 void Tab::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 Tab::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 Tab::RenderViewDeleted(content::RenderViewHost* render_view_host) {
105 render_widget_feature_->OnRenderWidgetDeleted(tab_id_,
106 render_view_host->GetWidget());
107 }
108
109 void Tab::NavigationStateChanged(content::InvalidateTypes changed_flags) {
110 DCHECK(changed_flags);
111
112 NavigationMessage* navigation_message;
113 std::unique_ptr<BlimpMessage> message =
114 CreateBlimpMessage(&navigation_message, tab_id_);
115 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED);
116 NavigationStateChangeMessage* details =
117 navigation_message->mutable_navigation_state_changed();
118
119 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_URL)
120 details->set_url(web_contents_->GetURL().spec());
121
122 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TAB) {
123 // TODO(dtrainor): Serialize the favicon? crbug.com/597094.
124 DVLOG(3) << "Tab favicon changed";
125 }
126
127 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE)
128 details->set_title(base::UTF16ToUTF8(web_contents_->GetTitle()));
129
130 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD)
131 details->set_loading(web_contents_->IsLoading());
132
133 navigation_message_sender_->ProcessMessage(std::move(message),
134 net::CompletionCallback());
135 }
136
137 void Tab::SendPageLoadStatusUpdate(PageLoadStatus load_status) {
138 NavigationMessage* navigation_message = nullptr;
139 std::unique_ptr<BlimpMessage> message =
140 CreateBlimpMessage(&navigation_message, tab_id_);
141 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED);
142 navigation_message->mutable_navigation_state_changed()
143 ->set_page_load_completed(load_status == PageLoadStatus::LOADED);
144
145 navigation_message_sender_->ProcessMessage(std::move(message),
146 net::CompletionCallback());
147 }
148
149 } // namespace engine
150 } // namespace blimp
OLDNEW
« blimp/engine/session/tab.h ('K') | « blimp/engine/session/tab.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698