Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_widget_host_view_aura.cc
index 24e30fd..b07e9c3 100644 (file)
@@ -37,7 +37,6 @@
 #include "content/common/view_messages.h"
 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
 #include "content/port/browser/render_widget_host_view_port.h"
-#include "content/public/browser/browser_thread.h"
 #include "content/public/browser/content_browser_client.h"
 #include "content/public/browser/render_process_host.h"
 #include "content/public/browser/render_view_host.h"
@@ -67,6 +66,7 @@
 #include "ui/base/hit_test.h"
 #include "ui/base/ime/input_method.h"
 #include "ui/base/ui_base_types.h"
+#include "ui/compositor/compositor_vsync_manager.h"
 #include "ui/compositor/layer.h"
 #include "ui/events/event.h"
 #include "ui/events/event_utils.h"
@@ -80,9 +80,9 @@
 #include "ui/wm/public/window_types.h"
 
 #if defined(OS_WIN)
-#include "base/win/windows_version.h"
 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
 #include "content/browser/accessibility/browser_accessibility_win.h"
+#include "content/browser/renderer_host/legacy_render_widget_host_win.h"
 #include "content/common/plugin_constants_win.h"
 #include "ui/base/win/hidden_window.h"
 #include "ui/gfx/gdi_util.h"
@@ -100,7 +100,8 @@ namespace content {
 namespace {
 
 void MailboxReleaseCallback(scoped_ptr<base::SharedMemory> shared_memory,
-                            unsigned sync_point, bool lost_resource) {
+                            uint32 sync_point,
+                            bool lost_resource) {
   // NOTE: shared_memory will get released when we go out of scope.
 }
 
@@ -204,7 +205,10 @@ BOOL CALLBACK SetCutoutRectsCallback(HWND window, LPARAM param) {
       cutout_rects.push_back(offset_cutout);
     }
     gfx::SubtractRectanglesFromRegion(hrgn, cutout_rects);
-    SetWindowRgn(window, hrgn, TRUE);
+    // If we don't have any cutout rects then no point in messing with the
+    // window region.
+    if (cutout_rects.size())
+      SetWindowRgn(window, hrgn, TRUE);
   }
   return TRUE;
 }
@@ -295,17 +299,6 @@ void GetScreenInfoForWindow(WebScreenInfo* results, aura::Window* window) {
   results->deviceScaleFactor = display.device_scale_factor();
 }
 
-bool ShouldSendPinchGesture() {
-#if defined(OS_WIN)
-  if (base::win::GetVersion() >= base::win::VERSION_WIN8)
-    return true;
-#endif
-  static bool pinch_allowed =
-      CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableViewport) ||
-      CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePinch);
-  return pinch_allowed;
-}
-
 bool PointerEventActivates(const ui::Event& event) {
   if (event.type() == ui::ET_MOUSE_PRESSED)
     return true;
@@ -333,10 +326,7 @@ void SendCompositorFrameAck(
   DCHECK(!texture_to_produce.get() || !skip_frame);
   if (texture_to_produce.get()) {
     GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
-    std::string mailbox_name = texture_to_produce->Produce();
-    std::copy(mailbox_name.data(),
-              mailbox_name.data() + mailbox_name.length(),
-              reinterpret_cast<char*>(ack.gl_frame_data->mailbox.name));
+    ack.gl_frame_data->mailbox = texture_to_produce->Produce();
     ack.gl_frame_data->size = texture_to_produce->size();
     ack.gl_frame_data->sync_point =
         gl_helper ? gl_helper->InsertSyncPoint() : 0;
@@ -354,7 +344,7 @@ void SendCompositorFrameAck(
 void AcknowledgeBufferForGpu(
     int32 route_id,
     int gpu_host_id,
-    const std::string& received_mailbox,
+    const gpu::Mailbox& received_mailbox,
     bool skip_frame,
     const scoped_refptr<ui::Texture>& texture_to_produce) {
   AcceleratedSurfaceMsg_BufferPresented_Params ack;
@@ -362,10 +352,10 @@ void AcknowledgeBufferForGpu(
   DCHECK(!texture_to_produce.get() || !skip_frame);
   if (texture_to_produce.get()) {
     GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
-    ack.mailbox_name = texture_to_produce->Produce();
+    ack.mailbox = texture_to_produce->Produce();
     sync_point = gl_helper ? gl_helper->InsertSyncPoint() : 0;
   } else if (skip_frame) {
-    ack.mailbox_name = received_mailbox;
+    ack.mailbox = received_mailbox;
     ack.sync_point = 0;
   }
 
@@ -378,8 +368,8 @@ void AcknowledgeBufferForGpu(
 
 // We need to watch for mouse events outside a Web Popup or its parent
 // and dismiss the popup for certain events.
-class RenderWidgetHostViewAura::EventFilterForPopupExit :
-    public ui::EventHandler {
+class RenderWidgetHostViewAura::EventFilterForPopupExit
+    public ui::EventHandler {
  public:
   explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
       : rwhva_(rwhva) {
@@ -396,6 +386,10 @@ class RenderWidgetHostViewAura::EventFilterForPopupExit :
     rwhva_->ApplyEventFilterForPopupExit(event);
   }
 
+  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+    rwhva_->ApplyEventFilterForPopupExit(event);
+  }
+
  private:
   RenderWidgetHostViewAura* rwhva_;
 
@@ -403,12 +397,14 @@ class RenderWidgetHostViewAura::EventFilterForPopupExit :
 };
 
 void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit(
-    ui::MouseEvent* event) {
-  if (in_shutdown_ || is_fullscreen_)
+    ui::LocatedEvent* event) {
+  if (in_shutdown_ || is_fullscreen_ || !event->target())
     return;
 
-  if (event->type() != ui::ET_MOUSE_PRESSED || !event->target())
+  if (event->type() != ui::ET_MOUSE_PRESSED &&
+      event->type() != ui::ET_TOUCH_PRESSED) {
     return;
+  }
 
   aura::Window* target = static_cast<aura::Window*>(event->target());
   if (target != window_ &&
@@ -479,7 +475,6 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
       accelerated_compositing_state_changed_(false),
       can_lock_compositor_(YES),
       cursor_visibility_state_in_renderer_(UNKNOWN),
-      paint_observer_(NULL),
       touch_editing_client_(NULL),
       delegated_frame_evictor_(new DelegatedFrameEvictor(this)),
       weak_ptr_factory_(this) {
@@ -492,9 +487,6 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
   gfx::Screen::GetScreenFor(window_)->AddObserver(this);
   software_frame_manager_.reset(new SoftwareFrameManager(
       weak_ptr_factory_.GetWeakPtr()));
-#if defined(OS_WIN)
-  plugin_parent_window_ = NULL;
-#endif
   ImageTransportFactory::GetInstance()->AddObserver(this);
 }
 
@@ -624,15 +616,18 @@ void RenderWidgetHostViewAura::WasShown() {
   }
 
 #if defined(OS_WIN)
+  if (legacy_render_widget_host_HWND_) {
+    // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent
+    // window before reparenting any plugins. This ensures that the plugin
+    // windows stay on top of the child Zorder in the parent and receive
+    // mouse events, etc.
+    legacy_render_widget_host_HWND_->UpdateParent(
+        GetNativeView()->GetDispatcher()->host()->GetAcceleratedWidget());
+    legacy_render_widget_host_HWND_->SetBounds(
+        window_->GetBoundsInRootWindow());
+  }
   LPARAM lparam = reinterpret_cast<LPARAM>(this);
   EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam);
-
-  if (::IsWindow(plugin_parent_window_)) {
-    gfx::Rect window_bounds = window_->GetBoundsInRootWindow();
-    ::SetWindowPos(plugin_parent_window_, NULL, window_bounds.x(),
-                   window_bounds.y(), window_bounds.width(),
-                   window_bounds.height(), 0);
-  }
 #endif
 }
 
@@ -650,11 +645,12 @@ void RenderWidgetHostViewAura::WasHidden() {
   if (dispatcher) {
     HWND parent = dispatcher->host()->GetAcceleratedWidget();
     LPARAM lparam = reinterpret_cast<LPARAM>(this);
-
     EnumChildWindows(parent, HideWindowsCallback, lparam);
+    // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
+    // hidden window on the same lines as Windowed plugin windows.
+    if (legacy_render_widget_host_HWND_)
+      legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
   }
-  if (::IsWindow(plugin_parent_window_))
-    ::SetWindowPos(plugin_parent_window_, NULL, 0, 0, 0, 0, 0);
 #endif
 }
 
@@ -873,11 +869,19 @@ bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
 void RenderWidgetHostViewAura::Show() {
   window_->Show();
   WasShown();
+#if defined(OS_WIN)
+  if (legacy_render_widget_host_HWND_)
+    legacy_render_widget_host_HWND_->Show();
+#endif
 }
 
 void RenderWidgetHostViewAura::Hide() {
   window_->Hide();
   WasHidden();
+#if defined(OS_WIN)
+  if (legacy_render_widget_host_HWND_)
+    legacy_render_widget_host_HWND_->Hide();
+#endif
 }
 
 bool RenderWidgetHostViewAura::IsShowing() {
@@ -910,8 +914,6 @@ void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) {
 }
 
 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
-  if (is_loading_ && !is_loading && paint_observer_)
-    paint_observer_->OnPageLoadComplete();
   is_loading_ = is_loading;
   UpdateCursorIfOverSelf();
 }
@@ -1149,8 +1151,10 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame(
       ConvertRectToPixel(current_device_scale_factor_, src_subrect);
   request->set_area(src_subrect_in_pixel);
   if (subscriber_texture.get()) {
-    request->SetTextureMailbox(cc::TextureMailbox(
-        subscriber_texture->mailbox(), subscriber_texture->sync_point()));
+    request->SetTextureMailbox(
+        cc::TextureMailbox(subscriber_texture->mailbox(),
+                           subscriber_texture->target(),
+                           subscriber_texture->sync_point()));
   }
   RequestCopyOfOutput(request.Pass());
 }
@@ -1219,26 +1223,25 @@ void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
       selection_focus_rect_);
   }
 #if defined(OS_WIN)
-  // Create the dummy plugin parent window which will be passed as the
-  // container window to windowless plugins.
+  // Create the legacy dummy window which corresponds to the bounds of the
+  // webcontents. This will be passed as the container window for windowless
+  // plugins.
   // Plugins like Flash assume the container window which is returned via the
   // NPNVnetscapeWindow property corresponds to the bounds of the webpage.
   // This is not true in Aura where we have only HWND which is the main Aura
   // window. If we return this window to plugins like Flash then it causes the
   // coordinate translations done by these plugins to break.
-  if (!plugin_parent_window_ && GetNativeViewId()) {
-    plugin_parent_window_ = ::CreateWindowEx(
-        0, L"Static", NULL, WS_CHILDWINDOW, 0, 0, 0, 0,
-        reinterpret_cast<HWND>(GetNativeViewId()), NULL, NULL, NULL);
-    if (::IsWindow(plugin_parent_window_))
-      ::SetProp(plugin_parent_window_, content::kPluginDummyParentProperty,
-                reinterpret_cast<HANDLE>(true));
-  }
-  if (::IsWindow(plugin_parent_window_)) {
-    gfx::Rect window_bounds = window_->GetBoundsInRootWindow();
-    ::SetWindowPos(plugin_parent_window_, NULL, window_bounds.x(),
-                   window_bounds.y(), window_bounds.width(),
-                   window_bounds.height(), 0);
+  // Additonally the legacy dummy window is needed for accessibility and for
+  // scrolling to work in legacy drivers for trackpoints/trackpads, etc.
+  if (GetNativeViewId()) {
+    if (!legacy_render_widget_host_HWND_) {
+      legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create(
+          reinterpret_cast<HWND>(GetNativeViewId()));
+    }
+    if (legacy_render_widget_host_HWND_) {
+      legacy_render_widget_host_HWND_->SetBounds(
+          window_->GetBoundsInRootWindow());
+    }
   }
 #endif
 }
@@ -1295,7 +1298,7 @@ bool RenderWidgetHostViewAura::SwapBuffersPrepare(
     const gfx::Rect& surface_rect,
     float surface_scale_factor,
     const gfx::Rect& damage_rect,
-    const std::string& mailbox_name,
+    const gpu::Mailbox& mailbox,
     const BufferPresentedCallback& ack_callback) {
   if (last_swapped_surface_size_ != surface_rect.size()) {
     // The surface could have shrunk since we skipped an update, in which
@@ -1308,7 +1311,7 @@ bool RenderWidgetHostViewAura::SwapBuffersPrepare(
 
   if (ShouldSkipFrame(ConvertSizeToDIP(surface_scale_factor,
                                        surface_rect.size())) ||
-      mailbox_name.empty()) {
+      mailbox.IsZero()) {
     skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op);
     ack_callback.Run(true, scoped_refptr<ui::Texture>());
     return false;
@@ -1323,7 +1326,7 @@ bool RenderWidgetHostViewAura::SwapBuffersPrepare(
     return false;
   }
 
-  current_surface_->Consume(mailbox_name, surface_rect.size());
+  current_surface_->Consume(mailbox, surface_rect.size());
   released_front_lock_ = NULL;
   UpdateExternalTexture();
 
@@ -1362,15 +1365,16 @@ void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() {
 #if defined(OS_WIN)
 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
     const std::vector<gfx::Rect>& rects) {
+  // Check this before setting constrained_rects_, so that next time they're set
+  // and we have a root window we don't early return.
+  if (!window_->GetDispatcher())
+    return;
+
   if (rects == constrained_rects_)
     return;
+
   constrained_rects_ = rects;
-  UpdateCutoutRects();
-}
 
-void RenderWidgetHostViewAura::UpdateCutoutRects() {
-  if (!window_->GetRootWindow())
-    return;
   HWND parent = window_->GetDispatcher()->host()->GetAcceleratedWidget();
   CutoutRectsParams params;
   params.widget = this;
@@ -1388,11 +1392,11 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
       &AcknowledgeBufferForGpu,
       params_in_pixel.route_id,
       gpu_host_id,
-      params_in_pixel.mailbox_name);
+      params_in_pixel.mailbox);
   BuffersSwapped(params_in_pixel.size,
                  gfx::Rect(params_in_pixel.size),
                  params_in_pixel.scale_factor,
-                 params_in_pixel.mailbox_name,
+                 params_in_pixel.mailbox,
                  params_in_pixel.latency_info,
                  ack_callback);
 }
@@ -1487,8 +1491,6 @@ void RenderWidgetHostViewAura::SwapDelegatedFrame(
   current_frame_size_ = frame_size_in_dip;
   CheckResizeLock();
 
-  if (paint_observer_)
-    paint_observer_->OnUpdateCompositorContent();
   window_->SchedulePaintInRect(damage_rect_in_dip);
 
   pending_delegated_ack_count_++;
@@ -1531,10 +1533,12 @@ void RenderWidgetHostViewAura::UnusedResourcesAreAvailable() {
 
 void RenderWidgetHostViewAura::SendReturnedDelegatedResources(
     uint32 output_surface_id) {
+  DCHECK(resource_collection_);
+
   cc::CompositorFrameAck ack;
-  if (resource_collection_)
-    resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources);
+  resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources);
   DCHECK(!ack.resources.empty());
+
   RenderWidgetHostImpl::SendReclaimCompositorResources(
       host_->GetRoutingID(),
       output_surface_id,
@@ -1602,9 +1606,9 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame(
         base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck,
                    AsWeakPtr(),
                    output_surface_id));
+  } else {
+    SendSoftwareFrameAck(output_surface_id);
   }
-  if (paint_observer_)
-    paint_observer_->OnUpdateCompositorContent();
   DidReceiveFrameFromRenderer();
 
   software_frame_manager_->SwapToNewFrameComplete(!host_->is_hidden());
@@ -1685,13 +1689,10 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame(
   GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
   gl_helper->WaitSyncPoint(frame->gl_frame_data->sync_point);
 
-  std::string mailbox_name(
-      reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name),
-      sizeof(frame->gl_frame_data->mailbox.name));
   BuffersSwapped(frame->gl_frame_data->size,
                  frame->gl_frame_data->sub_buffer_rect,
                  frame->metadata.device_scale_factor,
-                 mailbox_name,
+                 frame->gl_frame_data->mailbox,
                  frame->metadata.latency_info,
                  ack_callback);
 }
@@ -1707,7 +1708,11 @@ void RenderWidgetHostViewAura::SetParentNativeViewAccessible(
 
 gfx::NativeViewId RenderWidgetHostViewAura::GetParentForWindowlessPlugin()
     const {
-  return reinterpret_cast<gfx::NativeViewId>(plugin_parent_window_);
+  if (legacy_render_widget_host_HWND_) {
+    return reinterpret_cast<gfx::NativeViewId>(
+        legacy_render_widget_host_HWND_->hwnd());
+  }
+  return NULL;
 }
 #endif
 
@@ -1715,7 +1720,7 @@ void RenderWidgetHostViewAura::BuffersSwapped(
     const gfx::Size& surface_size,
     const gfx::Rect& damage_rect,
     float surface_scale_factor,
-    const std::string& mailbox_name,
+    const gpu::Mailbox& mailbox,
     const std::vector<ui::LatencyInfo>& latency_info,
     const BufferPresentedCallback& ack_callback) {
   scoped_refptr<ui::Texture> previous_texture(current_surface_);
@@ -1725,7 +1730,7 @@ void RenderWidgetHostViewAura::BuffersSwapped(
   if (!SwapBuffersPrepare(surface_rect,
                           surface_scale_factor,
                           damage_rect,
-                          mailbox_name,
+                          mailbox,
                           ack_callback)) {
     return;
   }
@@ -1773,8 +1778,6 @@ void RenderWidgetHostViewAura::BuffersSwapped(
     rect_to_paint.Inset(-1, -1);
     rect_to_paint.Intersect(window_->bounds());
 
-    if (paint_observer_)
-      paint_observer_->OnUpdateCompositorContent();
     window_->SchedulePaintInRect(rect_to_paint);
     for (size_t i = 0; i < latency_info.size(); i++)
       compositor->SetLatencyInfo(latency_info[i]);
@@ -1794,11 +1797,11 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
       base::Bind(&AcknowledgeBufferForGpu,
                  params_in_pixel.route_id,
                  gpu_host_id,
-                 params_in_pixel.mailbox_name);
+                 params_in_pixel.mailbox);
   BuffersSwapped(params_in_pixel.surface_size,
                  damage_rect,
                  params_in_pixel.surface_scale_factor,
-                 params_in_pixel.mailbox_name,
+                 params_in_pixel.mailbox,
                  params_in_pixel.latency_info,
                  ack_callback);
 }
@@ -1855,7 +1858,8 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResult(
   }
 
   DCHECK(result->HasBitmap());
-  PrepareBitmapCopyOutputResult(dst_size_in_pixel, callback, result.Pass());
+  PrepareBitmapCopyOutputResult(dst_size_in_pixel, config, callback,
+                                result.Pass());
 }
 
 static void CopyFromCompositingSurfaceFinished(
@@ -1865,7 +1869,15 @@ static void CopyFromCompositingSurfaceFinished(
     scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock,
     bool result) {
   bitmap_pixels_lock.reset();
-  release_callback->Run(0, false);
+
+  uint32 sync_point = 0;
+  if (result) {
+    GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
+    sync_point = gl_helper->InsertSyncPoint();
+  }
+  bool lost_resource = sync_point == 0;
+  release_callback->Run(sync_point, lost_resource);
+
   callback.Run(result, *bitmap);
 }
 
@@ -1875,15 +1887,12 @@ void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult(
     const SkBitmap::Config config,
     const base::Callback<void(bool, const SkBitmap&)>& callback,
     scoped_ptr<cc::CopyOutputResult> result) {
+  DCHECK(result->HasTexture());
   base::ScopedClosureRunner scoped_callback_runner(
       base::Bind(callback, false, SkBitmap()));
 
-  DCHECK(result->HasTexture());
-  if (!result->HasTexture())
-    return;
-
   scoped_ptr<SkBitmap> bitmap(new SkBitmap);
-  bitmap->setConfig(SkBitmap::kARGB_8888_Config,
+  bitmap->setConfig(config,
                     dst_size_in_pixel.width(), dst_size_in_pixel.height(),
                     0, kOpaque_SkAlphaType);
   if (!bitmap->allocPixels())
@@ -1908,7 +1917,7 @@ void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult(
   ignore_result(scoped_callback_runner.Release());
 
   gl_helper->CropScaleReadbackAndCleanMailbox(
-      texture_mailbox.name(),
+      texture_mailbox.mailbox(),
       texture_mailbox.sync_point(),
       result->size(),
       gfx::Rect(result->size()),
@@ -1925,14 +1934,17 @@ void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult(
 // static
 void RenderWidgetHostViewAura::PrepareBitmapCopyOutputResult(
     const gfx::Size& dst_size_in_pixel,
+    const SkBitmap::Config config,
     const base::Callback<void(bool, const SkBitmap&)>& callback,
     scoped_ptr<cc::CopyOutputResult> result) {
+  if (config != SkBitmap::kARGB_8888_Config) {
+    NOTIMPLEMENTED();
+    callback.Run(false, SkBitmap());
+    return;
+  }
   DCHECK(result->HasBitmap());
-
   base::ScopedClosureRunner scoped_callback_runner(
       base::Bind(callback, false, SkBitmap()));
-  if (!result->HasBitmap())
-    return;
 
   scoped_ptr<SkBitmap> source = result->TakeBitmap();
   DCHECK(source);
@@ -1977,13 +1989,17 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinishedForVideo(
     bool result) {
   callback.Run(result);
 
-  GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
-  uint32 sync_point = gl_helper ? gl_helper->InsertSyncPoint() : 0;
+  uint32 sync_point = 0;
+  if (result) {
+    GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
+    sync_point = gl_helper->InsertSyncPoint();
+  }
   if (release_callback) {
     // A release callback means the texture came from the compositor, so there
     // should be no |subscriber_texture|.
     DCHECK(!subscriber_texture);
-    release_callback->Run(sync_point, false);
+    bool lost_resource = sync_point == 0;
+    release_callback->Run(sync_point, lost_resource);
   }
   ReturnSubscriberTexture(rwhva, subscriber_texture, sync_point);
 }
@@ -2109,11 +2125,10 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResultForVideo(
       callback,
       subscriber_texture,
       base::Passed(&release_callback));
-  yuv_readback_pipeline->ReadbackYUV(
-      texture_mailbox.name(),
-      texture_mailbox.sync_point(),
-      video_frame.get(),
-      finished_callback);
+  yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(),
+                                     texture_mailbox.sync_point(),
+                                     video_frame.get(),
+                                     finished_callback);
 }
 
 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) {
@@ -2149,10 +2164,11 @@ gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() {
 #endif
 }
 
-void RenderWidgetHostViewAura::GestureEventAck(int gesture_event_type,
-                                               InputEventAckState ack_result) {
+void RenderWidgetHostViewAura::GestureEventAck(
+    const blink::WebGestureEvent& event,
+    InputEventAckState ack_result) {
   if (touch_editing_client_)
-    touch_editing_client_->GestureEventAck(gesture_event_type);
+    touch_editing_client_->GestureEventAck(event.type);
 }
 
 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
@@ -2195,6 +2211,7 @@ void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() {
   if (GetBrowserAccessibilityManager())
     return;
 
+  BrowserAccessibilityManager* manager = NULL;
 #if defined(OS_WIN)
   aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher();
   if (!dispatcher)
@@ -2208,14 +2225,15 @@ void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() {
   gfx::NativeViewAccessible accessible_parent =
       host_->GetParentNativeViewAccessible();
 
-  BrowserAccessibilityManager* manager = new BrowserAccessibilityManagerWin(
-      hwnd, accessible_parent,
-      BrowserAccessibilityManagerWin::GetEmptyDocument(), this);
+  if (legacy_render_widget_host_HWND_) {
+    manager = new BrowserAccessibilityManagerWin(
+        legacy_render_widget_host_HWND_.get(), accessible_parent,
+        BrowserAccessibilityManagerWin::GetEmptyDocument(), this);
+  }
 #else
-  BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
+  manager = BrowserAccessibilityManager::Create(
       BrowserAccessibilityManager::GetEmptyDocument(), this);
 #endif
-
   SetBrowserAccessibilityManager(manager);
 }
 
@@ -2559,11 +2577,12 @@ gfx::Size RenderWidgetHostViewAura::GetMaximumSize() const {
 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
                                                const gfx::Rect& new_bounds) {
   base::AutoReset<bool> in_bounds_changed(&in_bounds_changed_, true);
-  // We care about this only in fullscreen mode, where there is no
-  // WebContentsViewAura. We are sized via SetSize() or SetBounds() by
-  // WebContentsViewAura in other cases.
-  if (is_fullscreen_)
-    SetSize(new_bounds.size());
+  // We care about this whenever RenderWidgetHostViewAura is not owned by a
+  // WebContentsViewAura since changes to the Window's bounds need to be
+  // messaged to the renderer.  WebContentsViewAura invokes SetSize() or
+  // SetBounds() itself.  No matter how we got here, any redundant calls are
+  // harmless.
+  SetSize(new_bounds.size());
 }
 
 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
@@ -2602,8 +2621,6 @@ void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
     paint_canvas_ = NULL;
     backing_store->SkiaShowRect(gfx::Point(), canvas);
 
-    if (paint_observer_)
-      paint_observer_->OnPaintComplete();
     ui::Compositor* compositor = GetCompositor();
     if (compositor) {
       for (size_t i = 0; i < software_latency_info_.size(); i++)
@@ -2910,14 +2927,17 @@ void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
       break;
   }
 
-  // Needed to propagate mouse event to native_tab_contents_view_aura.
+  // Needed to propagate mouse event to |window_->parent()->delegate()|, but
+  // note that it might be something other than a WebContentsViewAura instance.
   // TODO(pkotwicz): Find a better way of doing this.
   // In fullscreen mode which is typically used by flash, don't forward
   // the mouse events to the parent. The renderer and the plugin process
   // handle these events.
   if (!is_fullscreen_ && window_->parent()->delegate() &&
-      !(event->flags() & ui::EF_FROM_TOUCH))
+      !(event->flags() & ui::EF_FROM_TOUCH)) {
+    event->ConvertLocationToTarget(window_, window_->parent());
     window_->parent()->delegate()->OnMouseEvent(event);
+  }
 
   if (!IsXButtonUpEvent(event))
     event->SetHandled();
@@ -2981,10 +3001,9 @@ void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
 
 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
   TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent");
-  // Pinch gestures are currently disabled by default. See crbug.com/128477.
   if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
       event->type() == ui::ET_GESTURE_PINCH_UPDATE ||
-      event->type() == ui::ET_GESTURE_PINCH_END) && !ShouldSendPinchGesture()) {
+      event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) {
     event->SetHandled();
     return;
   }
@@ -3190,8 +3209,6 @@ void RenderWidgetHostViewAura::OnCompositingStarted(
 
 void RenderWidgetHostViewAura::OnCompositingEnded(
     ui::Compositor* compositor) {
-  if (paint_observer_)
-    paint_observer_->OnCompositingComplete();
 }
 
 void RenderWidgetHostViewAura::OnCompositingAborted(
@@ -3208,7 +3225,6 @@ void RenderWidgetHostViewAura::OnCompositingLockStateChanged(
 }
 
 void RenderWidgetHostViewAura::OnUpdateVSyncParameters(
-    ui::Compositor* compositor,
     base::TimeTicks timebase,
     base::TimeDelta interval) {
   if (IsShowing()) {
@@ -3297,8 +3313,6 @@ void RenderWidgetHostViewAura::OnLostResources() {
 // RenderWidgetHostViewAura, private:
 
 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
-  if (paint_observer_)
-    paint_observer_->OnViewDestroyed();
   if (touch_editing_client_)
     touch_editing_client_->OnViewDestroyed();
 
@@ -3341,9 +3355,10 @@ RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
   active_frame_subscriber_textures_.clear();
 
 #if defined(OS_WIN)
-  if (::IsWindow(plugin_parent_window_))
-    ::DestroyWindow(plugin_parent_window_);
+  legacy_render_widget_host_HWND_.reset(NULL);
 #endif
+
+  DCHECK(!vsync_manager_);
 }
 
 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
@@ -3489,7 +3504,6 @@ void RenderWidgetHostViewAura::AddOnCommitCallbackAndDisableLocks(
 
 void RenderWidgetHostViewAura::AddedToRootWindow() {
   window_->GetDispatcher()->AddRootWindowObserver(this);
-  host_->ParentChanged(GetNativeViewId());
   UpdateScreenInfo(window_);
 
   aura::client::CursorClient* cursor_client =
@@ -3505,6 +3519,21 @@ void RenderWidgetHostViewAura::AddedToRootWindow() {
     if (input_method)
       input_method->SetFocusedTextInputClient(this);
   }
+
+#if defined(OS_WIN)
+  // The parent may have changed here. Ensure that the legacy window is
+  // reparented accordingly.
+  if (legacy_render_widget_host_HWND_)
+    legacy_render_widget_host_HWND_->UpdateParent(
+        reinterpret_cast<HWND>(GetNativeViewId()));
+#endif
+
+  ui::Compositor* compositor = GetCompositor();
+  if (compositor) {
+    DCHECK(!vsync_manager_);
+    vsync_manager_ = compositor->vsync_manager();
+    vsync_manager_->AddObserver(this);
+  }
 }
 
 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
@@ -3516,7 +3545,6 @@ void RenderWidgetHostViewAura::RemovingFromRootWindow() {
   DetachFromInputMethod();
 
   window_->GetDispatcher()->RemoveRootWindowObserver(this);
-  host_->ParentChanged(0);
   ui::Compositor* compositor = GetCompositor();
   if (current_surface_.get()) {
     // We can't get notification for commits after this point, which would
@@ -3529,8 +3557,21 @@ void RenderWidgetHostViewAura::RemovingFromRootWindow() {
   RunOnCommitCallbacks();
   resize_lock_.reset();
   host_->WasResized();
+
   if (compositor && compositor->HasObserver(this))
     compositor->RemoveObserver(this);
+
+#if defined(OS_WIN)
+  // Update the legacy window's parent temporarily to the desktop window. It
+  // will eventually get reparented to the right root.
+  if (legacy_render_widget_host_HWND_)
+    legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow());
+#endif
+
+  if (vsync_manager_) {
+    vsync_manager_->RemoveObserver(this);
+    vsync_manager_ = NULL;
+  }
 }
 
 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const {