| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/common/view_type.h" | 9 #include "chrome/common/view_type.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 14 | 14 |
| 15 ExtensionViewGtk::ExtensionViewGtk(extensions::ExtensionHost* extension_host, | 15 ExtensionViewGtk::ExtensionViewGtk(extensions::ExtensionHost* extension_host, |
| 16 Browser* browser) | 16 Browser* browser) |
| 17 : browser_(browser), | 17 : browser_(browser), |
| 18 extension_host_(extension_host), | 18 extension_host_(extension_host), |
| 19 container_(NULL) { | 19 container_(NULL) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 ExtensionViewGtk::~ExtensionViewGtk() { | |
| 23 } | |
| 24 | |
| 25 void ExtensionViewGtk::Init() { | 22 void ExtensionViewGtk::Init() { |
| 26 CreateWidgetHostView(); | 23 CreateWidgetHostView(); |
| 27 } | 24 } |
| 28 | 25 |
| 26 gfx::NativeView ExtensionViewGtk::native_view() { |
| 27 return extension_host_->host_contents()->GetView()->GetNativeView(); |
| 28 } |
| 29 |
| 30 content::RenderViewHost* ExtensionViewGtk::render_view_host() const { |
| 31 return extension_host_->render_view_host(); |
| 32 } |
| 33 |
| 29 void ExtensionViewGtk::SetBackground(const SkBitmap& background) { | 34 void ExtensionViewGtk::SetBackground(const SkBitmap& background) { |
| 30 if (GetRenderViewHost()->IsRenderViewLive() && | 35 if (render_view_host()->IsRenderViewLive() && render_view_host()->GetView()) { |
| 31 GetRenderViewHost()->GetView()) { | 36 render_view_host()->GetView()->SetBackground(background); |
| 32 GetRenderViewHost()->GetView()->SetBackground(background); | |
| 33 } else { | 37 } else { |
| 34 pending_background_ = background; | 38 pending_background_ = background; |
| 35 } | 39 } |
| 36 } | 40 } |
| 37 | 41 |
| 38 Browser* ExtensionViewGtk::GetBrowser() { | |
| 39 return browser_; | |
| 40 } | |
| 41 | |
| 42 const Browser* ExtensionViewGtk::GetBrowser() const { | |
| 43 return browser_; | |
| 44 } | |
| 45 | |
| 46 gfx::NativeView ExtensionViewGtk::GetNativeView() { | |
| 47 return extension_host_->host_contents()->GetView()->GetNativeView(); | |
| 48 } | |
| 49 | |
| 50 content::RenderViewHost* ExtensionViewGtk::GetRenderViewHost() const { | |
| 51 return extension_host_->render_view_host(); | |
| 52 } | |
| 53 | |
| 54 void ExtensionViewGtk::SetContainer(ExtensionViewContainer* container) { | |
| 55 container_ = container; | |
| 56 } | |
| 57 | |
| 58 void ExtensionViewGtk::ResizeDueToAutoResize(const gfx::Size& new_size) { | 42 void ExtensionViewGtk::ResizeDueToAutoResize(const gfx::Size& new_size) { |
| 59 if (container_) | 43 if (container_) |
| 60 container_->OnExtensionSizeChanged(this, new_size); | 44 container_->OnExtensionSizeChanged(this, new_size); |
| 61 } | 45 } |
| 62 | 46 |
| 47 void ExtensionViewGtk::CreateWidgetHostView() { |
| 48 extension_host_->CreateRenderViewSoon(); |
| 49 } |
| 50 |
| 63 void ExtensionViewGtk::RenderViewCreated() { | 51 void ExtensionViewGtk::RenderViewCreated() { |
| 64 if (!pending_background_.empty() && GetRenderViewHost()->GetView()) { | 52 if (!pending_background_.empty() && render_view_host()->GetView()) { |
| 65 GetRenderViewHost()->GetView()->SetBackground(pending_background_); | 53 render_view_host()->GetView()->SetBackground(pending_background_); |
| 66 pending_background_.reset(); | 54 pending_background_.reset(); |
| 67 } | 55 } |
| 68 | 56 |
| 69 chrome::ViewType host_type = extension_host_->extension_host_type(); | 57 chrome::ViewType host_type = extension_host_->extension_host_type(); |
| 70 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 58 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 71 gfx::Size min_size(ExtensionPopupGtk::kMinWidth, | 59 gfx::Size min_size(ExtensionPopupGtk::kMinWidth, |
| 72 ExtensionPopupGtk::kMinHeight); | 60 ExtensionPopupGtk::kMinHeight); |
| 73 gfx::Size max_size(ExtensionPopupGtk::kMaxWidth, | 61 gfx::Size max_size(ExtensionPopupGtk::kMaxWidth, |
| 74 ExtensionPopupGtk::kMaxHeight); | 62 ExtensionPopupGtk::kMaxHeight); |
| 75 GetRenderViewHost()->EnableAutoResize(min_size, max_size); | 63 render_view_host()->EnableAutoResize(min_size, max_size); |
| 76 } | 64 } |
| 77 } | 65 } |
| 78 | |
| 79 void ExtensionViewGtk::DidStopLoading() { | |
| 80 NOTIMPLEMENTED(); | |
| 81 } | |
| 82 | |
| 83 void ExtensionViewGtk::WindowFrameChanged() { | |
| 84 NOTIMPLEMENTED(); | |
| 85 } | |
| 86 | |
| 87 void ExtensionViewGtk::CreateWidgetHostView() { | |
| 88 extension_host_->CreateRenderViewSoon(); | |
| 89 } | |
| 90 | |
| 91 // static | |
| 92 ExtensionView* ExtensionView::Create(extensions::ExtensionHost* host, | |
| 93 Browser* browser) { | |
| 94 ExtensionViewGtk* extension_view = new ExtensionViewGtk(host, browser); | |
| 95 extension_view->Init(); | |
| 96 return extension_view; | |
| 97 } | |
| OLD | NEW |