| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" | 8 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| 9 #include "content/browser/renderer_host/render_view_host.h" | 9 #include "content/browser/renderer_host/render_view_host.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | 10 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/browser/tab_contents/tab_contents_view.h" |
| 11 | 13 |
| 12 ExtensionViewGtk::ExtensionViewGtk(ExtensionHost* extension_host, | 14 ExtensionViewGtk::ExtensionViewGtk(ExtensionHost* extension_host, |
| 13 Browser* browser) | 15 Browser* browser) |
| 14 : browser_(browser), | 16 : browser_(browser), |
| 15 extension_host_(extension_host), | 17 extension_host_(extension_host), |
| 16 render_widget_host_view_(NULL), | |
| 17 container_(NULL) { | 18 container_(NULL) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 void ExtensionViewGtk::Init() { | 21 void ExtensionViewGtk::Init() { |
| 21 CreateWidgetHostView(); | 22 CreateWidgetHostView(); |
| 22 } | 23 } |
| 23 | 24 |
| 24 gfx::NativeView ExtensionViewGtk::native_view() { | 25 gfx::NativeView ExtensionViewGtk::native_view() { |
| 25 return render_widget_host_view_->native_view(); | 26 return extension_host_->host_contents()->view()->GetNativeView(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 RenderViewHost* ExtensionViewGtk::render_view_host() const { | 29 RenderViewHost* ExtensionViewGtk::render_view_host() const { |
| 29 return extension_host_->render_view_host(); | 30 return extension_host_->render_view_host(); |
| 30 } | 31 } |
| 31 | 32 |
| 32 void ExtensionViewGtk::SetBackground(const SkBitmap& background) { | 33 void ExtensionViewGtk::SetBackground(const SkBitmap& background) { |
| 33 if (render_view_host()->IsRenderViewLive()) { | 34 if (render_view_host()->IsRenderViewLive() && render_view_host()->view()) { |
| 34 render_widget_host_view_->SetBackground(background); | 35 render_view_host()->view()->SetBackground(background); |
| 35 } else { | 36 } else { |
| 36 pending_background_ = background; | 37 pending_background_ = background; |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 | 40 |
| 40 void ExtensionViewGtk::UpdatePreferredSize(const gfx::Size& new_size) { | 41 void ExtensionViewGtk::UpdatePreferredSize(const gfx::Size& new_size) { |
| 41 if (container_) | 42 if (container_) |
| 42 container_->OnExtensionPreferredSizeChanged(this, new_size); | 43 container_->OnExtensionPreferredSizeChanged(this, new_size); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void ExtensionViewGtk::CreateWidgetHostView() { | 46 void ExtensionViewGtk::CreateWidgetHostView() { |
| 46 DCHECK(!render_widget_host_view_); | 47 extension_host_->CreateRenderViewSoon(); |
| 47 render_widget_host_view_ = new RenderWidgetHostViewGtk(render_view_host()); | |
| 48 render_widget_host_view_->InitAsChild(); | |
| 49 | |
| 50 extension_host_->CreateRenderViewSoon(render_widget_host_view_); | |
| 51 } | 48 } |
| 52 | 49 |
| 53 void ExtensionViewGtk::RenderViewCreated() { | 50 void ExtensionViewGtk::RenderViewCreated() { |
| 54 if (!pending_background_.empty() && render_view_host()->view()) { | 51 if (!pending_background_.empty() && render_view_host()->view()) { |
| 55 render_widget_host_view_->SetBackground(pending_background_); | 52 render_view_host()->view()->SetBackground(pending_background_); |
| 56 pending_background_.reset(); | 53 pending_background_.reset(); |
| 57 } | 54 } |
| 58 | 55 |
| 59 // Tell the renderer not to draw scrollbars in popups unless the | 56 // Tell the renderer not to draw scrollbars in popups unless the |
| 60 // popups are at the maximum allowed size. | 57 // popups are at the maximum allowed size. |
| 61 gfx::Size largest_popup_size(ExtensionPopupGtk::kMaxWidth, | 58 gfx::Size largest_popup_size(ExtensionPopupGtk::kMaxWidth, |
| 62 ExtensionPopupGtk::kMaxHeight); | 59 ExtensionPopupGtk::kMaxHeight); |
| 63 extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); | 60 extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); |
| 64 } | 61 } |
| OLD | NEW |