Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_widget_host_view_android.cc
index 79553b0..6b1c979 100644 (file)
@@ -157,7 +157,7 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
                                 !CommandLine::ForCurrentProcess()->HasSwitch(
                                     switches::kDisableDelegatedRenderer)),
       locks_on_frame_count_(0),
-      root_window_destroyed_(false) {
+      observing_root_window_(false) {
   if (!using_delegated_renderer_) {
     texture_layer_ = cc::TextureLayer::Create(NULL);
     layer_ = texture_layer_;
@@ -228,8 +228,10 @@ void RenderWidgetHostViewAndroid::WasShown() {
 
   host_->WasShown();
 
-  if (content_view_core_ && !using_synchronous_compositor_)
+  if (content_view_core_ && !using_synchronous_compositor_) {
     content_view_core_->GetWindowAndroid()->AddObserver(this);
+    observing_root_window_ = true;
+  }
 }
 
 void RenderWidgetHostViewAndroid::WasHidden() {
@@ -242,8 +244,10 @@ void RenderWidgetHostViewAndroid::WasHidden() {
   // utilization.
   host_->WasHidden();
 
-  if (content_view_core_ && !using_synchronous_compositor_)
+  if (content_view_core_ && !using_synchronous_compositor_) {
     content_view_core_->GetWindowAndroid()->RemoveObserver(this);
+    observing_root_window_ = false;
+  }
 }
 
 void RenderWidgetHostViewAndroid::WasResized() {
@@ -254,7 +258,6 @@ void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
   // Ignore the given size as only the Java code has the power to
   // resize the view on Android.
   default_size_ = size;
-  WasResized();
 }
 
 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
@@ -426,11 +429,7 @@ gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
   if (!content_view_core_)
     return gfx::Rect(default_size_);
 
-  gfx::Size size = content_view_core_->GetViewportSizeDip();
-  gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip();
-  size.Enlarge(-offset.width(), -offset.height());
-
-  return gfx::Rect(size);
+  return gfx::Rect(content_view_core_->GetViewSize());
 }
 
 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const {
@@ -611,9 +610,6 @@ void RenderWidgetHostViewAndroid::SelectionBoundsChanged(
 
 void RenderWidgetHostViewAndroid::SelectionRootBoundsChanged(
     const gfx::Rect& bounds) {
-  if (content_view_core_) {
-    content_view_core_->OnSelectionRootBoundsChanged(bounds);
-  }
 }
 
 void RenderWidgetHostViewAndroid::ScrollOffsetChanged() {
@@ -1337,17 +1333,16 @@ void RenderWidgetHostViewAndroid::DidStopFlinging() {
 void RenderWidgetHostViewAndroid::SetContentViewCore(
     ContentViewCoreImpl* content_view_core) {
   RemoveLayers();
-  // TODO: crbug.com/324341
-  // WindowAndroid and Compositor should outlive all WebContents.
-  // Allowing this here at runtime is a bandaid.
-  DCHECK(!root_window_destroyed_);
-  if (content_view_core_ && !root_window_destroyed_ &&
-      !using_synchronous_compositor_) {
+  if (observing_root_window_ && content_view_core_) {
     content_view_core_->GetWindowAndroid()->RemoveObserver(this);
+    observing_root_window_ = false;
   }
 
-  if (content_view_core != content_view_core_)
+  bool resize = false;
+  if (content_view_core != content_view_core_) {
     ReleaseLocksOnSurface();
+    resize = true;
+  }
 
   content_view_core_ = content_view_core;
 
@@ -1360,10 +1355,13 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
   }
 
   AttachLayers();
-  if (content_view_core_ && !root_window_destroyed_ &&
-      !using_synchronous_compositor_) {
+  if (content_view_core_ && !using_synchronous_compositor_) {
     content_view_core_->GetWindowAndroid()->AddObserver(this);
+    observing_root_window_ = true;
   }
+
+  if (resize && content_view_core_)
+    WasResized();
 }
 
 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
@@ -1380,10 +1378,16 @@ void RenderWidgetHostViewAndroid::OnCompositingDidCommit() {
 void RenderWidgetHostViewAndroid::OnDetachCompositor() {
   DCHECK(content_view_core_);
   DCHECK(!using_synchronous_compositor_);
-  root_window_destroyed_ = true;
   RunAckCallbacks();
 }
 
+void RenderWidgetHostViewAndroid::OnWillDestroyWindow() {
+  // crbug.com/324341
+  // WindowAndroid and Compositor should outlive all WebContents.
+  NOTREACHED();
+  observing_root_window_ = false;
+}
+
 void RenderWidgetHostViewAndroid::OnLostResources() {
   ReleaseLocksOnSurface();
   if (texture_layer_.get())