#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/gpu/gpu_messages.h"
-#include "content/common/host_shared_bitmap_manager.h"
#include "content/common/input/web_touch_event_traits.h"
#include "content/common/view_messages.h"
#include "content/common/webplugin_geometry.h"
#endif // defined(USE_AURA)
}
+bool RenderWidgetHostViewGuest::OnMessageReceivedFromEmbedder(
+ const IPC::Message& message,
+ RenderWidgetHostImpl* embedder) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderWidgetHostViewGuest, message,
+ embedder)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
+ OnHandleInputEvent)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
void RenderWidgetHostViewGuest::WasShown() {
// If the WebContents associated with us showed an interstitial page in the
// beginning, the teardown path might call WasShown() while |host_| is in
// |guest_| is NULL during test.
if ((guest_ && guest_->is_in_destruction()) || !host_->is_hidden())
return;
+ // Make sure the size of this view matches the size of the WebContentsView.
+ // The two sizes may fall out of sync if we switch RenderWidgetHostViews,
+ // resize, and then switch page, as is the case with interstitial pages.
+ // NOTE: |guest_| is NULL in unit tests.
+ if (guest_)
+ SetSize(guest_->web_contents()->GetViewBounds().size());
host_->WasShown(ui::LatencyInfo());
}
SetSize(rect.size());
}
+void RenderWidgetHostViewGuest::Focus() {
+ // InterstitialPageImpl focuses views directly, so we place focus logic here.
+ // InterstitialPages are not WebContents, and so BrowserPluginGuest does not
+ // have direct access to the interstitial page's RenderWidgetHost.
+ if (guest_)
+ guest_->SetFocus(host_, true);
+}
+
+bool RenderWidgetHostViewGuest::HasFocus() const {
+ if (!guest_)
+ return false;
+ return guest_->focused();
+}
+
#if defined(USE_AURA)
void RenderWidgetHostViewGuest::ProcessAckedTouchEvent(
const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
gfx::Rect embedder_bounds;
if (rwhv)
embedder_bounds = rwhv->GetViewBounds();
- gfx::Rect shifted_rect = guest_->ToGuestRect(embedder_bounds);
- shifted_rect.set_width(size_.width());
- shifted_rect.set_height(size_.height());
- return shifted_rect;
+ return gfx::Rect(
+ guest_->GetScreenCoordinates(embedder_bounds.origin()), size_);
}
void RenderWidgetHostViewGuest::RenderProcessGone(
void RenderWidgetHostViewGuest::AcceleratedSurfaceBuffersSwapped(
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
int gpu_host_id) {
- if (!guest_)
- return;
-
- FrameMsg_BuffersSwapped_Params guest_params;
- guest_params.size = params.size;
- guest_params.mailbox = params.mailbox;
- guest_params.gpu_route_id = params.route_id;
- guest_params.gpu_host_id = gpu_host_id;
- guest_->SendMessageToEmbedder(
- new BrowserPluginMsg_BuffersSwapped(guest_->instance_id(),
- guest_params));
+ NOTREACHED();
}
void RenderWidgetHostViewGuest::AcceleratedSurfacePostSubBuffer(
if (!guest_)
return;
- if (!guest_->attached()) {
- // If the guest doesn't have an embedder then there's nothing to give the
- // the frame to.
- return;
- }
- base::SharedMemoryHandle software_frame_handle =
- base::SharedMemory::NULLHandle();
- if (frame->software_frame_data) {
- cc::SoftwareFrameData* frame_data = frame->software_frame_data.get();
- scoped_ptr<cc::SharedBitmap> bitmap =
- HostSharedBitmapManager::current()->GetSharedBitmapFromId(
- frame_data->size, frame_data->bitmap_id);
- if (!bitmap)
- return;
-
- RenderWidgetHostView* embedder_rwhv =
- guest_->GetEmbedderRenderWidgetHostView();
- base::ProcessHandle embedder_pid =
- embedder_rwhv->GetRenderWidgetHost()->GetProcess()->GetHandle();
-
- bitmap->memory()->ShareToProcess(embedder_pid, &software_frame_handle);
- }
-
- FrameMsg_CompositorFrameSwapped_Params guest_params;
- frame->AssignTo(&guest_params.frame);
- guest_params.output_surface_id = output_surface_id;
- guest_params.producing_route_id = host_->GetRoutingID();
- guest_params.producing_host_id = host_->GetProcess()->GetID();
- guest_params.shared_memory_handle = software_frame_handle;
-
- guest_->SendMessageToEmbedder(
- new BrowserPluginMsg_CompositorFrameSwapped(guest_->instance_id(),
- guest_params));
+ last_scroll_offset_ = frame->metadata.root_scroll_offset;
+ guest_->SwapCompositorFrame(output_surface_id,
+ host_->GetProcess()->GetID(),
+ host_->GetRoutingID(),
+ frame.Pass());
}
bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) {
}
void RenderWidgetHostViewGuest::UpdateCursor(const WebCursor& cursor) {
- platform_view_->UpdateCursor(cursor);
+ // InterstitialPages are not WebContents so we cannot intercept
+ // ViewHostMsg_SetCursor for interstitial pages in BrowserPluginGuest.
+ // All guest RenderViewHosts have RenderWidgetHostViewGuests however,
+ // and so we will always hit this code path.
+ if (!guest_)
+ return;
+ guest_->SendMessageToEmbedder(
+ new BrowserPluginMsg_SetCursor(guest_->browser_plugin_instance_id(),
+ cursor));
+
}
void RenderWidgetHostViewGuest::SetIsLoading(bool is_loading) {
return;
std::vector<gfx::Rect> guest_character_bounds;
for (size_t i = 0; i < character_bounds.size(); ++i) {
- gfx::Rect guest_rect = guest_->ToGuestRect(character_bounds[i]);
- guest_character_bounds.push_back(guest_rect);
+ guest_character_bounds.push_back(gfx::Rect(
+ guest_->GetScreenCoordinates(character_bounds[i].origin()),
+ character_bounds[i].size()));
}
// Forward the information to embedding RWHV.
rwhv->ImeCompositionRangeChanged(range, guest_character_bounds);
if (!rwhv)
return;
ViewHostMsg_SelectionBounds_Params guest_params(params);
- guest_params.anchor_rect = guest_->ToGuestRect(params.anchor_rect);
- guest_params.focus_rect = guest_->ToGuestRect(params.focus_rect);
+ guest_params.anchor_rect.set_origin(
+ guest_->GetScreenCoordinates(params.anchor_rect.origin()));
+ guest_params.focus_rect.set_origin(
+ guest_->GetScreenCoordinates(params.focus_rect.origin()));
rwhv->SelectionBoundsChanged(guest_params);
}
void RenderWidgetHostViewGuest::CopyFromCompositingSurface(
const gfx::Rect& src_subrect,
const gfx::Size& dst_size,
- const base::Callback<void(bool, const SkBitmap&)>& callback,
+ CopyFromCompositingSurfaceCallback& callback,
const SkColorType color_type) {
CHECK(guest_);
guest_->CopyFromCompositingSurface(src_subrect, dst_size, callback);
}
void RenderWidgetHostViewGuest::SetBackgroundOpaque(bool opaque) {
- platform_view_->SetBackgroundOpaque(opaque);
+ // Content embedders can toggle opaque backgrounds through this API.
+ // We plumb the value here so that BrowserPlugin updates its compositing
+ // state in response to this change. We also want to preserve this flag
+ // after recovering from a crash so we let BrowserPluginGuest store it.
+ if (!guest_)
+ return;
+ RenderWidgetHostViewBase::SetBackgroundOpaque(opaque);
+ host_->SetBackgroundOpaque(opaque);
+ guest_->SetContentsOpaque(opaque);
}
bool RenderWidgetHostViewGuest::LockMouse() {
#endif // defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
void RenderWidgetHostViewGuest::ShowDisambiguationPopup(
- const gfx::Rect& target_rect,
+ const gfx::Rect& rect_pixels,
const SkBitmap& zoomed_bitmap) {
}
+#endif // defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
+#if defined(OS_ANDROID)
void RenderWidgetHostViewGuest::LockCompositingSurface() {
}
guest_->GetEmbedderRenderWidgetHostView());
}
+void RenderWidgetHostViewGuest::OnHandleInputEvent(
+ RenderWidgetHostImpl* embedder,
+ int browser_plugin_instance_id,
+ const gfx::Rect& guest_window_rect,
+ const blink::WebInputEvent* event) {
+ if (blink::WebInputEvent::isMouseEventType(event->type)) {
+ host_->ForwardMouseEvent(
+ *static_cast<const blink::WebMouseEvent*>(event));
+ return;
+ }
+
+ if (event->type == blink::WebInputEvent::MouseWheel) {
+ host_->ForwardWheelEvent(
+ *static_cast<const blink::WebMouseWheelEvent*>(event));
+ return;
+ }
+
+ if (blink::WebInputEvent::isKeyboardEventType(event->type)) {
+ if (!embedder->GetLastKeyboardEvent())
+ return;
+ NativeWebKeyboardEvent keyboard_event(*embedder->GetLastKeyboardEvent());
+ host_->ForwardKeyboardEvent(keyboard_event);
+ return;
+ }
+
+ if (blink::WebInputEvent::isTouchEventType(event->type)) {
+ host_->ForwardTouchEventWithLatencyInfo(
+ *static_cast<const blink::WebTouchEvent*>(event),
+ ui::LatencyInfo());
+ return;
+ }
+
+ if (blink::WebInputEvent::isGestureEventType(event->type)) {
+ host_->ForwardGestureEvent(
+ *static_cast<const blink::WebGestureEvent*>(event));
+ return;
+ }
+}
+
} // namespace content