| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/engine/session/tab.h" | 5 #include "blimp/engine/session/tab.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "blimp/common/create_blimp_message.h" | 9 #include "blimp/common/create_blimp_message.h" |
| 10 #include "blimp/common/proto/blimp_message.pb.h" | 10 #include "blimp/common/proto/blimp_message.pb.h" |
| 11 #include "blimp/common/proto/render_widget.pb.h" | 11 #include "blimp/common/proto/render_widget.pb.h" |
| 12 #include "blimp/common/proto/tab_control.pb.h" | 12 #include "blimp/common/proto/tab_control.pb.h" |
| 13 #include "blimp/engine/common/blimp_user_agent.h" | 13 #include "blimp/engine/common/blimp_user_agent.h" |
| 14 #include "blimp/engine/feature/engine_render_widget_feature.h" | 14 #include "blimp/engine/feature/engine_render_widget_feature.h" |
| 15 #include "blimp/net/blimp_message_processor.h" | 15 #include "blimp/net/blimp_message_processor.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/render_widget_host.h" | 19 #include "content/public/browser/render_widget_host.h" |
| 20 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/form_field_data.h" |
| 22 #include "content/public/common/renderer_preferences.h" | 23 #include "content/public/common/renderer_preferences.h" |
| 23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 24 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 25 | 26 |
| 26 namespace blimp { | 27 namespace blimp { |
| 27 namespace engine { | 28 namespace engine { |
| 28 | 29 |
| 29 Tab::Tab(std::unique_ptr<content::WebContents> web_contents, | 30 Tab::Tab(std::unique_ptr<content::WebContents> web_contents, |
| 30 const int tab_id, | 31 const int tab_id, |
| 31 EngineRenderWidgetFeature* render_widget_feature, | 32 EngineRenderWidgetFeature* render_widget_feature, |
| 32 BlimpMessageProcessor* navigation_message_sender) | 33 BlimpMessageProcessor* navigation_message_sender) |
| 33 : web_contents_(std::move(web_contents)), | 34 : web_contents_(std::move(web_contents)), |
| 34 tab_id_(tab_id), | 35 tab_id_(tab_id), |
| 35 render_widget_feature_(render_widget_feature), | 36 render_widget_feature_(render_widget_feature), |
| 36 navigation_message_sender_(navigation_message_sender), | 37 navigation_message_sender_(navigation_message_sender), |
| 37 page_load_tracker_(web_contents_.get(), this) { | 38 page_load_tracker_(web_contents_.get(), this), |
| 39 current_form_request_id_(0), |
| 40 weak_factory_(this) { |
| 38 DCHECK(render_widget_feature_); | 41 DCHECK(render_widget_feature_); |
| 39 DCHECK(navigation_message_sender_); | 42 DCHECK(navigation_message_sender_); |
| 40 | 43 |
| 41 // A Tab is created upon client's request, thus an updated | 44 // A Tab is created upon client's request, thus an updated |
| 42 // user agent info (containing client OS info) is available, and we will use | 45 // user agent info (containing client OS info) is available, and we will use |
| 43 // that to override user agent string from BlimpContentRendererClient. | 46 // that to override user agent string from BlimpContentRendererClient. |
| 44 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); | 47 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); |
| 45 | 48 |
| 46 render_widget_feature_->SetDelegate(tab_id_, this); | 49 render_widget_feature_->SetDelegate(tab_id_, this); |
| 47 | 50 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 navigation_message_sender_->ProcessMessage(std::move(message), | 164 navigation_message_sender_->ProcessMessage(std::move(message), |
| 162 net::CompletionCallback()); | 165 net::CompletionCallback()); |
| 163 } | 166 } |
| 164 | 167 |
| 165 void Tab::OnWebGestureEvent(content::RenderWidgetHost* render_widget_host, | 168 void Tab::OnWebGestureEvent(content::RenderWidgetHost* render_widget_host, |
| 166 std::unique_ptr<blink::WebGestureEvent> event) { | 169 std::unique_ptr<blink::WebGestureEvent> event) { |
| 167 TRACE_EVENT1("blimp", "Tab::OnWebGestureEvent", "type", event->type); | 170 TRACE_EVENT1("blimp", "Tab::OnWebGestureEvent", "type", event->type); |
| 168 render_widget_host->ForwardGestureEvent(*event); | 171 render_widget_host->ForwardGestureEvent(*event); |
| 169 } | 172 } |
| 170 | 173 |
| 174 void Tab::ShowTextInputUI() { |
| 175 current_form_request_id_++; |
| 176 content::FormFieldDataCallback callback = |
| 177 base::Bind(&Tab::ProcessTextInputInfo, weak_factory_.GetWeakPtr(), |
| 178 current_form_request_id_); |
| 179 |
| 180 content::RenderFrameHost* focused_frame = web_contents()->GetFocusedFrame(); |
| 181 if (focused_frame) { |
| 182 focused_frame->RequestFocusedFormFieldData(callback); |
| 183 } |
| 184 } |
| 185 |
| 186 void Tab::HideTextInputUI() { |
| 187 current_form_request_id_++; |
| 188 render_widget_feature_->SendHideImeRequest( |
| 189 tab_id(), |
| 190 web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost()); |
| 191 } |
| 192 |
| 193 void Tab::ProcessTextInputInfo(int request_id, |
| 194 const content::FormFieldData& field) { |
| 195 if (field.text_input_type == ui::TEXT_INPUT_TYPE_NONE) |
| 196 return; |
| 197 |
| 198 // Discard the results for old requests. |
| 199 if (request_id < current_form_request_id_) { |
| 200 return; |
| 201 } |
| 202 |
| 203 // TODO(shaktisahu): Remove adding RenderWidgetHost info to the proto. |
| 204 render_widget_feature_->SendShowImeRequest( |
| 205 tab_id(), |
| 206 web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), field); |
| 207 } |
| 208 |
| 171 void Tab::OnCompositorMessageReceived( | 209 void Tab::OnCompositorMessageReceived( |
| 172 content::RenderWidgetHost* render_widget_host, | 210 content::RenderWidgetHost* render_widget_host, |
| 173 const std::vector<uint8_t>& message) { | 211 const std::vector<uint8_t>& message) { |
| 174 TRACE_EVENT0("blimp", "Tab::OnCompositorMessageReceived"); | 212 TRACE_EVENT0("blimp", "Tab::OnCompositorMessageReceived"); |
| 175 | 213 |
| 176 render_widget_host->HandleCompositorProto(message); | 214 render_widget_host->HandleCompositorProto(message); |
| 177 } | 215 } |
| 178 | 216 |
| 179 } // namespace engine | 217 } // namespace engine |
| 180 } // namespace blimp | 218 } // namespace blimp |
| OLD | NEW |