OLD | NEW |
---|---|
(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 // Transfer over the user agent override. The default user agent does not | |
Kevin M
2016/06/02 21:54:05
Do we need lines 40 and 41 anymore?
haibinlu
2016/06/02 23:24:33
Done.
| |
41 // have client OS info. | |
42 // A Tab is created upon client's request, thus an updated | |
43 // user agent info (containing client OS info) is available, and we will use | |
44 // that to override user agent string from BlimpContentRendererClient. | |
45 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); | |
46 | |
47 Observe(web_contents_.get()); | |
48 } | |
49 | |
50 TabBlimp::~TabBlimp() {} | |
51 | |
52 void TabBlimp::Resize(float device_pixel_ratio, const gfx::Size& size_in_dips) { | |
53 DVLOG(1) << "Resize to " << size_in_dips.ToString() << ", " | |
54 << device_pixel_ratio; | |
55 web_contents_->GetNativeView()->SetBounds(gfx::Rect(size_in_dips)); | |
56 | |
57 if (web_contents_->GetRenderViewHost() && | |
58 web_contents_->GetRenderViewHost()->GetWidget()) { | |
59 web_contents_->GetRenderViewHost()->GetWidget()->WasResized(); | |
60 } | |
61 } | |
62 | |
63 void TabBlimp::LoadUrl(const GURL& url) { | |
64 TRACE_EVENT1("blimp", "TabBlimp::LoadUrl", "URL", url.spec()); | |
65 DVLOG(1) << "Load URL " << url << " in tab " << tab_id_; | |
66 if (!url.is_valid()) { | |
67 VLOG(1) << "Dropping invalid URL " << url; | |
68 return; | |
69 } | |
70 | |
71 content::NavigationController::LoadURLParams params(url); | |
72 params.transition_type = ui::PageTransitionFromInt( | |
73 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | |
74 params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; | |
75 web_contents_->GetController().LoadURLWithParams(params); | |
76 web_contents_->Focus(); | |
77 } | |
78 | |
79 void TabBlimp::GoBack() { | |
80 DVLOG(1) << "Back in tab " << tab_id_; | |
81 web_contents_->GetController().GoBack(); | |
82 } | |
83 | |
84 void TabBlimp::GoForward() { | |
85 DVLOG(1) << "Forward in tab " << tab_id_; | |
86 web_contents_->GetController().GoForward(); | |
87 } | |
88 | |
89 void TabBlimp::Reload() { | |
90 DVLOG(1) << "Reload in tab " << tab_id_; | |
91 web_contents_->GetController().Reload(true); | |
92 } | |
93 | |
94 void TabBlimp::RenderViewCreated(content::RenderViewHost* render_view_host) { | |
95 DCHECK(render_view_host); | |
96 render_widget_feature_->OnRenderWidgetCreated(tab_id_, | |
97 render_view_host->GetWidget()); | |
98 } | |
99 | |
100 void TabBlimp::RenderViewHostChanged(content::RenderViewHost* old_host, | |
101 content::RenderViewHost* new_host) { | |
102 render_widget_feature_->OnRenderWidgetInitialized(tab_id_, | |
103 new_host->GetWidget()); | |
104 } | |
105 | |
106 void TabBlimp::RenderViewDeleted(content::RenderViewHost* render_view_host) { | |
107 render_widget_feature_->OnRenderWidgetDeleted(tab_id_, | |
108 render_view_host->GetWidget()); | |
109 } | |
110 | |
111 void TabBlimp::NavigationStateChanged(content::InvalidateTypes changed_flags) { | |
112 if (!changed_flags) | |
113 return; | |
114 | |
115 NavigationMessage* navigation_message; | |
116 std::unique_ptr<BlimpMessage> message = | |
117 CreateBlimpMessage(&navigation_message, tab_id_); | |
118 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
119 NavigationStateChangeMessage* details = | |
120 navigation_message->mutable_navigation_state_changed(); | |
121 | |
122 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_URL) | |
123 details->set_url(web_contents_->GetURL().spec()); | |
124 | |
125 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TAB) { | |
126 // TODO(dtrainor): Serialize the favicon? crbug.com/597094. | |
127 DVLOG(3) << "Tab favicon changed"; | |
128 } | |
129 | |
130 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE) | |
131 details->set_title(base::UTF16ToUTF8(web_contents_->GetTitle())); | |
132 | |
133 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD) | |
134 details->set_loading(web_contents_->IsLoading()); | |
135 | |
136 navigation_message_sender_->ProcessMessage(std::move(message), | |
137 net::CompletionCallback()); | |
138 } | |
139 | |
140 void TabBlimp::SendPageLoadStatusUpdate(PageLoadStatus load_status) { | |
141 bool page_load_completed = false; | |
142 switch (load_status) { | |
143 case PageLoadStatus::LOADING: | |
144 page_load_completed = false; | |
145 break; | |
146 case PageLoadStatus::LOADED: | |
147 page_load_completed = true; | |
148 break; | |
149 } | |
150 | |
151 NavigationMessage* navigation_message = nullptr; | |
152 std::unique_ptr<BlimpMessage> message = | |
153 CreateBlimpMessage(&navigation_message, tab_id_); | |
154 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
155 navigation_message->mutable_navigation_state_changed() | |
156 ->set_page_load_completed(page_load_completed); | |
157 | |
158 navigation_message_sender_->ProcessMessage(std::move(message), | |
159 net::CompletionCallback()); | |
160 } | |
161 | |
162 } // namespace engine | |
163 } // namespace blimp | |
OLD | NEW |