Chromium Code Reviews| 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/trace_event/trace_event.h" | |
| 8 #include "blimp/common/create_blimp_message.h" | |
| 9 #include "blimp/common/proto/blimp_message.pb.h" | |
| 10 #include "blimp/common/proto/render_widget.pb.h" | |
| 11 #include "blimp/common/proto/tab_control.pb.h" | |
| 12 #include "blimp/engine/common/blimp_user_agent.h" | |
| 13 #include "blimp/engine/feature/engine_render_widget_feature.h" | |
| 14 #include "blimp/net/blimp_message_processor.h" | |
| 15 #include "content/public/browser/navigation_controller.h" | |
| 16 #include "content/public/browser/navigation_entry.h" | |
| 17 #include "content/public/browser/render_view_host.h" | |
| 18 #include "content/public/browser/render_widget_host.h" | |
| 19 #include "content/public/browser/render_widget_host_view.h" | |
| 20 #include "content/public/browser/web_contents.h" | |
| 21 #include "ui/aura/window.h" | |
| 22 #include "ui/gfx/geometry/size.h" | |
| 23 | |
| 24 namespace blimp { | |
| 25 namespace engine { | |
| 26 | |
| 27 TabBlimp::TabBlimp(std::unique_ptr<content::WebContents> web_contents, | |
| 28 const int tab_id, | |
| 29 EngineRenderWidgetFeature* render_widget_feature, | |
| 30 BlimpMessageProcessor* navigation_message_sender) | |
| 31 : web_contents_(std::move(web_contents)), | |
| 32 tab_id_(tab_id), | |
| 33 render_widget_feature_(render_widget_feature), | |
| 34 navigation_message_sender_(navigation_message_sender), | |
| 35 page_load_tracker_(new PageLoadTracker(web_contents_.get(), this)) { | |
| 36 DCHECK(render_widget_feature_); | |
| 37 DCHECK(navigation_message_sender_); | |
| 38 | |
| 39 // Transfer over the user agent override. The default user agent does not | |
| 40 // 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.
| |
| 41 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); | |
| 42 | |
| 43 Observe(web_contents_.get()); | |
| 44 } | |
| 45 | |
| 46 TabBlimp::~TabBlimp() {} | |
| 47 | |
| 48 void TabBlimp::Close() { | |
| 49 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
| |
| 50 } | |
| 51 | |
| 52 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.
| |
| 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) { | |
|
Kevin M
2016/06/02 18:38:50
DCHECK(rvh)?
haibinlu
2016/06/02 20:24:37
Done.
| |
| 93 render_widget_feature_->OnRenderWidgetCreated(tab_id_, | |
| 94 render_view_host->GetWidget()); | |
| 95 } | |
| 96 | |
| 97 void TabBlimp::RenderViewHostChanged(content::RenderViewHost* old_host, | |
| 98 content::RenderViewHost* new_host) { | |
| 99 // 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
| |
| 100 // another one. | |
| 101 render_widget_feature_->OnRenderWidgetInitialized(tab_id_, | |
| 102 new_host->GetWidget()); | |
| 103 } | |
| 104 | |
| 105 void TabBlimp::RenderViewDeleted(content::RenderViewHost* render_view_host) { | |
| 106 render_widget_feature_->OnRenderWidgetDeleted(tab_id_, | |
| 107 render_view_host->GetWidget()); | |
| 108 } | |
| 109 | |
| 110 void TabBlimp::SendPageLoadStatusUpdate(PageLoadStatus load_status) { | |
| 111 bool page_load_completed = false; | |
| 112 | |
|
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.
| |
| 113 switch (load_status) { | |
| 114 case PageLoadStatus::LOADING: | |
| 115 page_load_completed = false; | |
| 116 break; | |
| 117 case PageLoadStatus::LOADED: | |
| 118 page_load_completed = true; | |
| 119 break; | |
| 120 } | |
| 121 | |
| 122 NavigationMessage* navigation_message = nullptr; | |
| 123 std::unique_ptr<BlimpMessage> message = | |
| 124 CreateBlimpMessage(&navigation_message, tab_id_); | |
| 125 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
| 126 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.
| |
| 127 navigation_message->mutable_navigation_state_changed(); | |
| 128 details->set_page_load_completed(page_load_completed); | |
| 129 | |
| 130 navigation_message_sender_->ProcessMessage(std::move(message), | |
| 131 net::CompletionCallback()); | |
| 132 } | |
| 133 | |
| 134 } // namespace engine | |
| 135 } // namespace blimp | |
| OLD | NEW |