Index: blimp/engine/session/tab_blimp.cc |
diff --git a/blimp/engine/session/tab_blimp.cc b/blimp/engine/session/tab_blimp.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c8a198fd9a06363fbed6651e7578165a83868437 |
--- /dev/null |
+++ b/blimp/engine/session/tab_blimp.cc |
@@ -0,0 +1,135 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "blimp/engine/session/tab_blimp.h" |
+ |
+#include "base/trace_event/trace_event.h" |
+#include "blimp/common/create_blimp_message.h" |
+#include "blimp/common/proto/blimp_message.pb.h" |
+#include "blimp/common/proto/render_widget.pb.h" |
+#include "blimp/common/proto/tab_control.pb.h" |
+#include "blimp/engine/common/blimp_user_agent.h" |
+#include "blimp/engine/feature/engine_render_widget_feature.h" |
+#include "blimp/net/blimp_message_processor.h" |
+#include "content/public/browser/navigation_controller.h" |
+#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/render_view_host.h" |
+#include "content/public/browser/render_widget_host.h" |
+#include "content/public/browser/render_widget_host_view.h" |
+#include "content/public/browser/web_contents.h" |
+#include "ui/aura/window.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+namespace blimp { |
+namespace engine { |
+ |
+TabBlimp::TabBlimp(std::unique_ptr<content::WebContents> web_contents, |
+ const int tab_id, |
+ EngineRenderWidgetFeature* render_widget_feature, |
+ BlimpMessageProcessor* navigation_message_sender) |
+ : web_contents_(std::move(web_contents)), |
+ tab_id_(tab_id), |
+ render_widget_feature_(render_widget_feature), |
+ navigation_message_sender_(navigation_message_sender), |
+ page_load_tracker_(new PageLoadTracker(web_contents_.get(), this)) { |
+ DCHECK(render_widget_feature_); |
+ DCHECK(navigation_message_sender_); |
+ |
+ // Transfer over the user agent override. The default user agent does not |
+ // have client IO info. |
Kevin M
2016/06/02 18:38:50
Can this be rephrased to be more clear?
haibinlu
2016/06/02 20:24:37
Done.
|
+ web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); |
+ |
+ Observe(web_contents_.get()); |
+} |
+ |
+TabBlimp::~TabBlimp() {} |
+ |
+void TabBlimp::Close() { |
+ web_contents_->Close(); |
Kevin M
2016/06/02 18:38:50
Is this redundant, given that web_contents_ is abo
haibinlu
2016/06/02 20:24:37
right. we do not really need this Close method. re
|
+} |
+ |
+void TabBlimp::Resize(float device_pixel_ratio, const gfx::Size& size_in_dips) { |
Kevin M
2016/06/02 18:38:50
DVLOG this event?
haibinlu
2016/06/02 20:24:37
Done.
|
+ web_contents_->GetNativeView()->SetBounds(gfx::Rect(size_in_dips)); |
+ |
+ if (web_contents_->GetRenderViewHost() && |
+ web_contents_->GetRenderViewHost()->GetWidget()) { |
+ web_contents_->GetRenderViewHost()->GetWidget()->WasResized(); |
+ } |
+} |
+ |
+void TabBlimp::LoadUrl(const GURL& url) { |
+ TRACE_EVENT1("blimp", "TabBlimp::LoadUrl", "URL", url.spec()); |
+ DVLOG(1) << "Load URL " << url << " in tab " << tab_id_; |
+ if (!url.is_valid()) { |
+ VLOG(1) << "Dropping invalid URL " << url; |
+ return; |
+ } |
+ |
+ content::NavigationController::LoadURLParams params(url); |
+ params.transition_type = ui::PageTransitionFromInt( |
+ ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
+ params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; |
+ web_contents_->GetController().LoadURLWithParams(params); |
+ web_contents_->Focus(); |
+} |
+ |
+void TabBlimp::GoBack() { |
+ DVLOG(1) << "Back in tab " << tab_id_; |
+ web_contents_->GetController().GoBack(); |
+} |
+ |
+void TabBlimp::GoForward() { |
+ DVLOG(1) << "Forward in tab " << tab_id_; |
+ web_contents_->GetController().GoForward(); |
+} |
+ |
+void TabBlimp::Reload() { |
+ DVLOG(1) << "Reload in tab " << tab_id_; |
+ web_contents_->GetController().Reload(true); |
+} |
+ |
+void TabBlimp::RenderViewCreated(content::RenderViewHost* render_view_host) { |
Kevin M
2016/06/02 18:38:50
DCHECK(rvh)?
haibinlu
2016/06/02 20:24:37
Done.
|
+ render_widget_feature_->OnRenderWidgetCreated(tab_id_, |
+ render_view_host->GetWidget()); |
+} |
+ |
+void TabBlimp::RenderViewHostChanged(content::RenderViewHost* old_host, |
+ content::RenderViewHost* new_host) { |
+ // Informs client that WebContents swaps its visible RenderViewHost with |
Kevin M
2016/06/02 18:38:50
nit: since this is a one-liner method, this commen
haibinlu
2016/06/02 20:24:37
removed comment. OnRenderWidgetInitialized already
|
+ // another one. |
+ render_widget_feature_->OnRenderWidgetInitialized(tab_id_, |
+ new_host->GetWidget()); |
+} |
+ |
+void TabBlimp::RenderViewDeleted(content::RenderViewHost* render_view_host) { |
+ render_widget_feature_->OnRenderWidgetDeleted(tab_id_, |
+ render_view_host->GetWidget()); |
+} |
+ |
+void TabBlimp::SendPageLoadStatusUpdate(PageLoadStatus load_status) { |
+ bool page_load_completed = false; |
+ |
Kevin M
2016/06/02 18:38:50
nit: remove newline to keep these as a single sema
haibinlu
2016/06/02 20:24:37
Done.
|
+ switch (load_status) { |
+ case PageLoadStatus::LOADING: |
+ page_load_completed = false; |
+ break; |
+ case PageLoadStatus::LOADED: |
+ page_load_completed = true; |
+ break; |
+ } |
+ |
+ NavigationMessage* navigation_message = nullptr; |
+ std::unique_ptr<BlimpMessage> message = |
+ CreateBlimpMessage(&navigation_message, tab_id_); |
+ navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); |
+ NavigationStateChangeMessage* details = |
Kevin M
2016/06/02 18:38:50
No need to assign this to a named variable; just i
haibinlu
2016/06/02 20:24:37
Done.
|
+ navigation_message->mutable_navigation_state_changed(); |
+ details->set_page_load_completed(page_load_completed); |
+ |
+ navigation_message_sender_->ProcessMessage(std::move(message), |
+ net::CompletionCallback()); |
+} |
+ |
+} // namespace engine |
+} // namespace blimp |