1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_view.h"
13 #include "extensions/common/view_type.h"
15 ExtensionViewGtk::ExtensionViewGtk(extensions::ExtensionHost
* extension_host
,
18 extension_host_(extension_host
),
22 void ExtensionViewGtk::Init() {
23 CreateWidgetHostView();
26 gfx::NativeView
ExtensionViewGtk::native_view() {
27 return extension_host_
->host_contents()->GetView()->GetNativeView();
30 content::RenderViewHost
* ExtensionViewGtk::render_view_host() const {
31 return extension_host_
->render_view_host();
34 void ExtensionViewGtk::SetBackground(const SkBitmap
& background
) {
35 if (render_view_host()->IsRenderViewLive() && render_view_host()->GetView()) {
36 render_view_host()->GetView()->SetBackground(background
);
38 pending_background_
= background
;
42 void ExtensionViewGtk::ResizeDueToAutoResize(const gfx::Size
& new_size
) {
44 container_
->OnExtensionSizeChanged(this, new_size
);
47 void ExtensionViewGtk::CreateWidgetHostView() {
48 extension_host_
->CreateRenderViewSoon();
51 void ExtensionViewGtk::RenderViewCreated() {
52 if (!pending_background_
.empty() && render_view_host()->GetView()) {
53 render_view_host()->GetView()->SetBackground(pending_background_
);
54 pending_background_
.reset();
57 extensions::ViewType host_type
= extension_host_
->extension_host_type();
58 if (host_type
== extensions::VIEW_TYPE_EXTENSION_POPUP
) {
59 gfx::Size
min_size(ExtensionPopupGtk::kMinWidth
,
60 ExtensionPopupGtk::kMinHeight
);
61 gfx::Size
max_size(ExtensionPopupGtk::kMaxWidth
,
62 ExtensionPopupGtk::kMaxHeight
);
63 render_view_host()->EnableAutoResize(min_size
, max_size
);