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

Unified Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 1602663003: Framelet Prototype 2016 using Mojo IPC Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Disabled oilpan Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_plugin/browser_plugin_guest.cc
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index 33262a832e5803f3baa57fbd231f72c947cd5481..500a6682b40d5caebf2e69581419a639a9134f34 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -90,7 +90,7 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
focused_(false),
mouse_locked_(false),
pending_lock_request_(false),
- guest_visible_(false),
+ container_visible_(false),
embedder_visible_(true),
is_full_page_plugin_(false),
has_render_view_(has_render_view),
@@ -145,6 +145,36 @@ int BrowserPluginGuest::GetGuestProxyRoutingID() {
return guest_proxy_routing_id_;
}
+void BrowserPluginGuest::Attach(int element_instance_id,
+ WebContents* embedder_web_contents,
+ const GuestAttachParams& attach_params) {
+ browser_plugin_instance_id_ = element_instance_id;
+ // If a guest is detaching from one container and attaching to another
+ // container, then late arriving ACKs may be lost if the mapping from
+ // |browser_plugin_instance_id| to |guest_instance_id| changes. Thus we
+ // ensure that we always get new frames on attachment by ACKing the pending
+ // frame if it's still waiting on the ACK.
+ if (last_pending_frame_) {
+ cc::CompositorFrameAck ack;
+ RenderWidgetHostImpl::SendSwapCompositorFrameAck(
+ last_pending_frame_->producing_route_id,
+ last_pending_frame_->output_surface_id,
+ last_pending_frame_->producing_host_id, ack);
+ last_pending_frame_.reset();
+ }
+
+ // The guest is owned by the embedder. Attach is queued up so we cannot
+ // change embedders before attach completes. If the embedder goes away,
+ // so does the guest and so we will never call WillAttachComplete because
+ // we have a weak ptr.
+ delegate_->WillAttach(
+ embedder_web_contents, element_instance_id, attach_params.is_full_page,
+ base::Bind(&BrowserPluginGuest::OnWillAttachComplete,
+ weak_ptr_factory_.GetWeakPtr(),
+ static_cast<WebContentsImpl*>(embedder_web_contents),
+ attach_params));
+}
+
int BrowserPluginGuest::LoadURLWithParams(
const NavigationController::LoadURLParams& load_params) {
GetWebContents()->GetController().LoadURLWithParams(load_params);
@@ -158,10 +188,55 @@ void BrowserPluginGuest::GuestResizeDueToAutoResize(const gfx::Size& new_size) {
}
}
+void BrowserPluginGuest::SetContainerVisible(bool visible) {
+ container_visible_ = visible;
+ UpdateVisibility();
+}
+
+void BrowserPluginGuest::SetFocus(bool focused,
+ blink::WebFocusType focus_type) {
+ RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView();
+ RenderWidgetHost* rwh = rwhv ? rwhv->GetRenderWidgetHost() : nullptr;
+ SetFocusForRenderWidgetHost(rwh, focused, focus_type);
+}
+
void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
GetWebContents()->GetView()->SizeContents(new_size);
}
+void BrowserPluginGuest::ForwardInputEvent(const blink::WebInputEvent* event) {
+ RenderWidgetHostImpl* embedder_host =
+ embedder_web_contents()->GetMainFrame()->GetRenderWidgetHost();
+ RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView();
+ RenderWidgetHostImpl* host = static_cast<RenderWidgetHostImpl*>(
+ rwhv ? rwhv->GetRenderWidgetHost() : nullptr);
+ if (!host)
+ return;
+
+ if (blink::WebInputEvent::isMouseEventType(event->type)) {
+ host->ForwardMouseEvent(*static_cast<const blink::WebMouseEvent*>(event));
+ } else if (event->type == blink::WebInputEvent::MouseWheel) {
+ host->ForwardWheelEvent(
+ *static_cast<const blink::WebMouseWheelEvent*>(event));
+ } else if (blink::WebInputEvent::isGestureEventType(event->type)) {
+ host->ForwardGestureEvent(
+ *static_cast<const blink::WebGestureEvent*>(event));
+ } else if (blink::WebInputEvent::isKeyboardEventType(event->type)) {
+ if (!embedder_host->GetLastKeyboardEvent())
+ return;
+ NativeWebKeyboardEvent keyboard_event(
+ *embedder_host->GetLastKeyboardEvent());
+ host->ForwardKeyboardEvent(keyboard_event);
+ } else if (blink::WebInputEvent::isTouchEventType(event->type)) {
+ if (event->type == blink::WebInputEvent::TouchStart &&
+ !embedder_host->GetView()->HasFocus()) {
+ embedder_host->GetView()->Focus();
+ }
+ host->ForwardTouchEventWithLatencyInfo(
+ *static_cast<const blink::WebTouchEvent*>(event), ui::LatencyInfo());
+ }
+}
+
void BrowserPluginGuest::WillDestroy() {
is_in_destruction_ = true;
owner_web_contents_ = nullptr;
@@ -182,16 +257,17 @@ void BrowserPluginGuest::Init() {
WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
delegate_->GetOwnerWebContents());
owner_web_contents->CreateBrowserPluginEmbedderIfNecessary();
- InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
+ InitInternal(GuestAttachParams(), owner_web_contents);
}
base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
-void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh,
- bool focused,
- blink::WebFocusType focus_type) {
+void BrowserPluginGuest::SetFocusForRenderWidgetHost(
+ RenderWidgetHost* rwh,
+ bool focused,
+ blink::WebFocusType focus_type) {
focused_ = focused;
if (!rwh)
return;
@@ -279,18 +355,12 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
return handled;
}
-void BrowserPluginGuest::InitInternal(
- const BrowserPluginHostMsg_Attach_Params& params,
- WebContentsImpl* owner_web_contents) {
- focused_ = params.focused;
- OnSetFocus(browser_plugin::kInstanceIDNone,
- focused_,
- blink::WebFocusTypeNone);
+void BrowserPluginGuest::InitInternal(const GuestAttachParams& params,
+ WebContentsImpl* owner_web_contents) {
+ SetContainerVisible(params.visible);
+ SetFocus(params.focused, blink::WebFocusTypeNone);
- guest_visible_ = params.visible;
- UpdateVisibility();
-
- is_full_page_plugin_ = params.is_full_page_plugin;
+ is_full_page_plugin_ = params.is_full_page;
guest_window_rect_ = params.view_rect;
if (owner_web_contents_ != owner_web_contents) {
@@ -346,6 +416,8 @@ void BrowserPluginGuest::InitInternal(
WebPreferences prefs =
GetWebContents()->GetRenderViewHost()->GetWebkitPreferences();
prefs.navigate_on_drag_drop = false;
+ prefs.viewport_enabled = false;
+ prefs.viewport_meta_enabled = false;
GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
}
@@ -379,7 +451,10 @@ RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
}
void BrowserPluginGuest::UpdateVisibility() {
- OnSetVisibility(browser_plugin_instance_id(), visible());
+ if (embedder_visible_ && container_visible_)
+ GetWebContents()->WasShown();
+ else
+ GetWebContents()->WasHidden();
}
BrowserPluginGuestManager*
@@ -421,6 +496,10 @@ void BrowserPluginGuest::SetChildFrameSurface(
float scale_factor,
const cc::SurfaceSequence& sequence) {
has_attached_since_surface_set_ = false;
+ if (delegate_->SetChildFrameSurface(surface_id, frame_size, scale_factor,
+ sequence)) {
+ return;
+ }
SendMessageToEmbedder(new BrowserPluginMsg_SetChildFrameSurface(
browser_plugin_instance_id(), surface_id, frame_size, scale_factor,
sequence));
@@ -697,9 +776,8 @@ bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) {
// TODO(lazyboy): Fix this as part of http://crbug.com/330264. The required
// parts of code from this class should be extracted to a separate class for
// --site-per-process.
- if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
+ if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests())
return false;
- }
IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition,
@@ -751,36 +829,17 @@ void BrowserPluginGuest::Attach(
int browser_plugin_instance_id,
WebContentsImpl* embedder_web_contents,
const BrowserPluginHostMsg_Attach_Params& params) {
- browser_plugin_instance_id_ = browser_plugin_instance_id;
- // If a guest is detaching from one container and attaching to another
- // container, then late arriving ACKs may be lost if the mapping from
- // |browser_plugin_instance_id| to |guest_instance_id| changes. Thus we
- // ensure that we always get new frames on attachment by ACKing the pending
- // frame if it's still waiting on the ACK.
- if (last_pending_frame_) {
- cc::CompositorFrameAck ack;
- RenderWidgetHostImpl::SendSwapCompositorFrameAck(
- last_pending_frame_->producing_route_id,
- last_pending_frame_->output_surface_id,
- last_pending_frame_->producing_host_id,
- ack);
- last_pending_frame_.reset();
- }
-
- // The guest is owned by the embedder. Attach is queued up so we cannot
- // change embedders before attach completes. If the embedder goes away,
- // so does the guest and so we will never call WillAttachComplete because
- // we have a weak ptr.
- delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
- params.is_full_page_plugin,
- base::Bind(&BrowserPluginGuest::OnWillAttachComplete,
- weak_ptr_factory_.GetWeakPtr(),
- embedder_web_contents, params));
+ GuestAttachParams attach_params;
+ attach_params.focused = params.focused;
+ attach_params.visible = params.visible;
+ attach_params.view_rect = params.view_rect;
+ attach_params.is_full_page = params.is_full_page_plugin;
+ Attach(browser_plugin_instance_id, embedder_web_contents, attach_params);
}
void BrowserPluginGuest::OnWillAttachComplete(
WebContentsImpl* embedder_web_contents,
- const BrowserPluginHostMsg_Attach_Params& params) {
+ const GuestAttachParams& params) {
bool use_cross_process_frames =
BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
// If a RenderView has already been created for this new window, then we need
@@ -959,9 +1018,7 @@ void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id,
void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id,
bool focused,
blink::WebFocusType focus_type) {
- RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView();
- RenderWidgetHost* rwh = rwhv ? rwhv->GetRenderWidgetHost() : nullptr;
- SetFocus(rwh, focused, focus_type);
+ SetFocus(focused, focus_type);
}
void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent(
@@ -973,11 +1030,7 @@ void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent(
void BrowserPluginGuest::OnSetVisibility(int browser_plugin_instance_id,
bool visible) {
- guest_visible_ = visible;
- if (embedder_visible_ && guest_visible_)
- GetWebContents()->WasShown();
- else
- GetWebContents()->WasHidden();
+ SetContainerVisible(visible);
}
void BrowserPluginGuest::OnUnlockMouse() {
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/frame_host/render_widget_host_view_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698