| 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/views/extensions/extension_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 8 #include "chrome/browser/ui/views/extensions/extension_popup.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.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 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
| 12 #include "views/widget/widget.h" | 14 #include "views/widget/widget.h" |
| 13 | 15 |
| 14 #if defined(USE_AURA) | |
| 15 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | |
| 16 #elif defined(TOUCH_UI) | |
| 17 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" | |
| 18 #elif defined(TOOLKIT_USES_GTK) | |
| 19 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | |
| 20 #elif defined(OS_WIN) | |
| 21 #include "content/browser/renderer_host/render_widget_host_view_win.h" | |
| 22 #endif | |
| 23 | |
| 24 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) | 16 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) |
| 25 : host_(host), | 17 : host_(host), |
| 26 browser_(browser), | 18 browser_(browser), |
| 27 initialized_(false), | 19 initialized_(false), |
| 28 container_(NULL), | 20 container_(NULL), |
| 29 is_clipped_(false) { | 21 is_clipped_(false) { |
| 30 host_->set_view(this); | 22 host_->set_view(this); |
| 31 | 23 |
| 32 // This view needs to be focusable so it can act as the focused view for the | 24 // This view needs to be focusable so it can act as the focused view for the |
| 33 // focus manager. This is required to have SkipDefaultKeyEventProcessing | 25 // focus manager. This is required to have SkipDefaultKeyEventProcessing |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 render_view_host()->view()->Show(); | 69 render_view_host()->view()->Show(); |
| 78 else | 70 else |
| 79 render_view_host()->view()->Hide(); | 71 render_view_host()->view()->Hide(); |
| 80 } | 72 } |
| 81 } | 73 } |
| 82 } | 74 } |
| 83 | 75 |
| 84 void ExtensionView::CreateWidgetHostView() { | 76 void ExtensionView::CreateWidgetHostView() { |
| 85 DCHECK(!initialized_); | 77 DCHECK(!initialized_); |
| 86 initialized_ = true; | 78 initialized_ = true; |
| 87 RenderWidgetHostView* view = | 79 Attach(host_->host_contents()->view()->GetNativeView()); |
| 88 content::GetContentClient()->browser()->CreateViewForWidget( | 80 host_->CreateRenderViewSoon(); |
| 89 render_view_host()); | |
| 90 | |
| 91 // TODO(mpcomplete): RWHV needs a cross-platform Init function. | |
| 92 #if defined(USE_AURA) | |
| 93 static_cast<RenderWidgetHostViewAura*>(view)->InitAsChild(); | |
| 94 #elif defined(TOUCH_UI) | |
| 95 static_cast<RenderWidgetHostViewViews*>(view)->InitAsChild(); | |
| 96 #elif defined(TOOLKIT_USES_GTK) | |
| 97 static_cast<RenderWidgetHostViewGtk*>(view)->InitAsChild(); | |
| 98 #elif defined(OS_WIN) | |
| 99 // Create the HWND. Note: | |
| 100 // RenderWidgetHostHWND supports windowed plugins, but if we ever also | |
| 101 // wanted to support constrained windows with this, we would need an | |
| 102 // additional HWND to parent off of because windowed plugin HWNDs cannot | |
| 103 // exist in the same z-order as constrained windows. | |
| 104 RenderWidgetHostViewWin* view_win = | |
| 105 static_cast<RenderWidgetHostViewWin*>(view); | |
| 106 view_win->Create(GetWidget()->GetNativeView()); | |
| 107 view_win->ShowWindow(SW_SHOW); | |
| 108 #else | |
| 109 NOTIMPLEMENTED(); | |
| 110 #endif | |
| 111 | |
| 112 Attach(view->GetNativeView()); | |
| 113 host_->CreateRenderViewSoon(view); | |
| 114 SetVisible(false); | 81 SetVisible(false); |
| 115 } | 82 } |
| 116 | 83 |
| 117 void ExtensionView::ShowIfCompletelyLoaded() { | 84 void ExtensionView::ShowIfCompletelyLoaded() { |
| 118 if (IsVisible() || is_clipped_) | 85 if (IsVisible() || is_clipped_) |
| 119 return; | 86 return; |
| 120 | 87 |
| 121 // We wait to show the ExtensionView until it has loaded, and the view has | 88 // We wait to show the ExtensionView until it has loaded, and the view has |
| 122 // actually been created. These can happen in different orders. | 89 // actually been created. These can happen in different orders. |
| 123 if (host_->did_stop_loading()) { | 90 if (host_->did_stop_loading()) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK); | 146 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK); |
| 180 } | 147 } |
| 181 | 148 |
| 182 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 149 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 183 // Propagate the new size to RenderWidgetHostView. | 150 // Propagate the new size to RenderWidgetHostView. |
| 184 // We can't send size zero because RenderWidget DCHECKs that. | 151 // We can't send size zero because RenderWidget DCHECKs that. |
| 185 if (render_view_host()->view() && !bounds().IsEmpty()) | 152 if (render_view_host()->view() && !bounds().IsEmpty()) |
| 186 render_view_host()->view()->SetSize(size()); | 153 render_view_host()->view()->SetSize(size()); |
| 187 } | 154 } |
| 188 | 155 |
| 189 void ExtensionView::HandleMouseMove() { | |
| 190 if (container_) | |
| 191 container_->OnExtensionMouseMove(this); | |
| 192 } | |
| 193 | |
| 194 void ExtensionView::HandleMouseLeave() { | |
| 195 if (container_) | |
| 196 container_->OnExtensionMouseLeave(this); | |
| 197 } | |
| 198 | |
| 199 void ExtensionView::RenderViewCreated() { | 156 void ExtensionView::RenderViewCreated() { |
| 200 if (!pending_background_.empty() && render_view_host()->view()) { | 157 if (!pending_background_.empty() && render_view_host()->view()) { |
| 201 render_view_host()->view()->SetBackground(pending_background_); | 158 render_view_host()->view()->SetBackground(pending_background_); |
| 202 pending_background_.reset(); | 159 pending_background_.reset(); |
| 203 } | 160 } |
| 204 | 161 |
| 205 // Tell the renderer not to draw scroll bars in popups unless the | 162 // Tell the renderer not to draw scroll bars in popups unless the |
| 206 // popups are at the maximum allowed size. | 163 // popups are at the maximum allowed size. |
| 207 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, | 164 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, |
| 208 ExtensionPopup::kMaxHeight); | 165 ExtensionPopup::kMaxHeight); |
| 209 host_->DisableScrollbarsForSmallWindows(largest_popup_size); | 166 host_->DisableScrollbarsForSmallWindows(largest_popup_size); |
| 210 } | 167 } |
| OLD | NEW |