| Index: chrome/browser/extensions/extension_view.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_view.cc (revision 14851)
|
| +++ chrome/browser/extensions/extension_view.cc (working copy)
|
| @@ -4,68 +4,68 @@
|
|
|
| #include "chrome/browser/extensions/extension_view.h"
|
|
|
| -#include "base/command_line.h"
|
| -#include "chrome/browser/browser.h"
|
| -#include "chrome/browser/character_encoding.h"
|
| -#include "chrome/browser/extensions/extension.h"
|
| -#include "chrome/browser/extensions/extension_message_service.h"
|
| -#include "chrome/browser/jsmessage_box_handler.h"
|
| -#include "chrome/browser/profile.h"
|
| +#include "chrome/browser/extensions/extension_host.h"
|
| #include "chrome/browser/renderer_host/render_view_host.h"
|
| -#include "chrome/browser/renderer_host/render_process_host.h"
|
| -#include "chrome/browser/renderer_host/render_widget_host.h"
|
| #include "chrome/browser/renderer_host/render_widget_host_view.h"
|
| -#include "chrome/browser/tab_contents/site_instance.h"
|
| -#include "chrome/browser/tab_contents/web_contents.h"
|
| -#include "chrome/browser/tab_contents/tab_contents_view.h"
|
| -#include "chrome/common/chrome_switches.h"
|
| -#include "chrome/common/pref_names.h"
|
| -#include "chrome/common/pref_service.h"
|
| -#include "chrome/common/resource_bundle.h"
|
| +#include "chrome/views/widget/widget.h"
|
|
|
| -#include "grit/browser_resources.h"
|
| -#include "grit/generated_resources.h"
|
| +#if defined(OS_WIN)
|
| +#include "chrome/browser/renderer_host/render_widget_host_view_win.h"
|
| +#endif
|
|
|
| -#include "webkit/glue/context_menu.h"
|
| +ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser,
|
| + const GURL& content_url)
|
| + : host_(host), browser_(browser), content_url_(content_url),
|
| + initialized_(false) {
|
| + host_->set_view(this);
|
| +}
|
|
|
| -ExtensionView::ExtensionView(Extension* extension,
|
| - const GURL& url,
|
| - SiteInstance* instance,
|
| - Browser* browser)
|
| - : HWNDHtmlView(url, this, false, instance),
|
| - extension_(extension),
|
| - browser_(browser),
|
| - did_stop_loading_(false),
|
| - pending_preferred_width_(0) {
|
| +ExtensionView::~ExtensionView() {
|
| + if (GetHWND())
|
| + Detach();
|
| }
|
|
|
| -ExtensionFunctionDispatcher* ExtensionView::
|
| - CreateExtensionFunctionDispatcher(RenderViewHost *render_view_host,
|
| - const std::string& extension_id) {
|
| - return new ExtensionFunctionDispatcher(render_view_host, browser_,
|
| - extension_id);
|
| +void ExtensionView::SetVisible(bool is_visible) {
|
| + HWNDView::SetVisible(is_visible);
|
| +
|
| + // Also tell RenderWidgetHostView the new visibility. Despite its name, it is
|
| + // not part of the View heirarchy and does not know about the change unless we
|
| + // tell it.
|
| + if (render_view_host()->view()) {
|
| + if (is_visible)
|
| + render_view_host()->view()->Show();
|
| + else
|
| + render_view_host()->view()->Hide();
|
| + }
|
| }
|
|
|
| +void ExtensionView::DidChangeBounds(const gfx::Rect& previous,
|
| + const gfx::Rect& current) {
|
| + // Propagate the new size to RenderWidgetHostView.
|
| + // We can't send size zero because RenderWidget DCHECKs that.
|
| + if (render_view_host()->view() && !current.IsEmpty())
|
| + render_view_host()->view()->SetSize(gfx::Size(width(), height()));
|
| +}
|
| +
|
| void ExtensionView::ShowIfCompletelyLoaded() {
|
| // We wait to show the ExtensionView until it has loaded and our parent has
|
| // given us a background. These can happen in different orders.
|
| - if (did_stop_loading_ && !render_view_host()->view()->background().empty()) {
|
| + if (host_->did_stop_loading() && render_view_host()->view() &&
|
| + !render_view_host()->view()->background().empty()) {
|
| SetVisible(true);
|
| DidContentsPreferredWidthChange(pending_preferred_width_);
|
| }
|
| }
|
|
|
| void ExtensionView::SetBackground(const SkBitmap& background) {
|
| - HWNDHtmlView::SetBackground(background);
|
| + if (initialized_ && render_view_host()->view()) {
|
| + render_view_host()->view()->SetBackground(background);
|
| + } else {
|
| + pending_background_ = background;
|
| + }
|
| ShowIfCompletelyLoaded();
|
| }
|
|
|
| -void ExtensionView::DidStopLoading(RenderViewHost* render_view_host) {
|
| - render_view_host->WasResized();
|
| - did_stop_loading_ = true;
|
| - ShowIfCompletelyLoaded();
|
| -}
|
| -
|
| void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) {
|
| // Don't actually do anything with this information until we have been shown.
|
| // Size changes will not be honored by lower layers while we are hidden.
|
| @@ -87,97 +87,37 @@
|
| }
|
| }
|
|
|
| -void ExtensionView::CreatingRenderer() {
|
| - render_view_host()->AllowExtensionBindings();
|
| - SetVisible(false);
|
| -}
|
| +void ExtensionView::ViewHierarchyChanged(bool is_add,
|
| + views::View *parent,
|
| + views::View *child) {
|
| + if (is_add && GetWidget() && !initialized_) {
|
| + initialized_ = true;
|
|
|
| -void ExtensionView::RenderViewCreated(RenderViewHost* rvh) {
|
| - URLRequestContext* context = rvh->process()->profile()->GetRequestContext();
|
| - ExtensionMessageService::GetInstance(context)->RegisterExtension(
|
| - extension_->id(), render_view_host()->process()->pid());
|
| -}
|
| + RenderWidgetHostView* view = RenderWidgetHostView::CreateViewForWidget(
|
| + render_view_host());
|
|
|
| -WebPreferences ExtensionView::GetWebkitPrefs() {
|
| - PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
|
| - bool isDomUI = true;
|
| - return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI);
|
| -}
|
| + // TODO(mpcomplete): RWHV needs a cross-platform Init function.
|
| +#if defined(OS_WIN)
|
| + // Create the HWND. Note:
|
| + // RenderWidgetHostHWND supports windowed plugins, but if we ever also
|
| + // wanted to support constrained windows with this, we would need an
|
| + // additional HWND to parent off of because windowed plugin HWNDs cannot
|
| + // exist in the same z-order as constrained windows.
|
| + RenderWidgetHostViewWin* view_win =
|
| + static_cast<RenderWidgetHostViewWin*>(view);
|
| + HWND hwnd = view_win->Create(GetWidget()->GetNativeView());
|
| + view_win->ShowWindow(SW_SHOW);
|
| + Attach(hwnd);
|
| +#else
|
| + NOTIMPLEMENTED();
|
| +#endif
|
|
|
| -void ExtensionView::RunJavaScriptMessage(
|
| - const std::wstring& message,
|
| - const std::wstring& default_prompt,
|
| - const GURL& frame_url,
|
| - const int flags,
|
| - IPC::Message* reply_msg,
|
| - bool* did_suppress_message) {
|
| - // Automatically cancel the javascript alert (otherwise the renderer hangs
|
| - // indefinitely).
|
| - *did_suppress_message = true;
|
| - render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L"");
|
| -}
|
| + host_->CreateRenderView(content_url_, view);
|
| + SetVisible(false);
|
|
|
| -void ExtensionView::DidStartLoading(RenderViewHost* render_view_host) {
|
| - static const StringPiece toolstrip_css(
|
| - ResourceBundle::GetSharedInstance().GetRawDataResource(
|
| - IDR_EXTENSIONS_TOOLSTRIP_CSS));
|
| - render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string());
|
| -}
|
| -
|
| -RenderViewHostDelegate::View* ExtensionView::GetViewDelegate() const {
|
| - // TODO(erikkay) this is unfortunate. The interface declares that this method
|
| - // must be const (no good reason for it as far as I can tell) which means you
|
| - // can't return self without doing this const_cast. Either we need to change
|
| - // the interface, or we need to split out the view delegate into another
|
| - // object (which is how WebContents works).
|
| - return const_cast<ExtensionView*>(this);
|
| -}
|
| -
|
| -void ExtensionView::CreateNewWindow(int route_id,
|
| - base::WaitableEvent* modal_dialog_event) {
|
| - delegate_view_helper_.CreateNewWindow(route_id, modal_dialog_event,
|
| - browser_->profile(), site_instance());
|
| -}
|
| -
|
| -void ExtensionView::CreateNewWidget(int route_id, bool activatable) {
|
| - delegate_view_helper_.CreateNewWidget(route_id, activatable,
|
| - site_instance()->GetProcess());
|
| -}
|
| -
|
| -void ExtensionView::ShowCreatedWindow(int route_id,
|
| - WindowOpenDisposition disposition,
|
| - const gfx::Rect& initial_pos,
|
| - bool user_gesture) {
|
| - WebContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
|
| - if (contents) {
|
| - browser_->AddTabContents(contents, disposition, initial_pos, user_gesture);
|
| + if (!pending_background_.empty()) {
|
| + render_view_host()->view()->SetBackground(pending_background_);
|
| + pending_background_.reset();
|
| + }
|
| }
|
| }
|
| -
|
| -void ExtensionView::ShowCreatedWidget(int route_id,
|
| - const gfx::Rect& initial_pos) {
|
| - RenderWidgetHostView* widget_host_view =
|
| - delegate_view_helper_.GetCreatedWidget(route_id);
|
| - browser_->BrowserRenderWidgetShowing();
|
| - // TODO(erikkay): These two lines could be refactored with TabContentsView.
|
| - widget_host_view->InitAsPopup(render_view_host()->view(),
|
| - initial_pos);
|
| - widget_host_view->GetRenderWidgetHost()->Init();
|
| -}
|
| -
|
| -void ExtensionView::ShowContextMenu(const ContextMenuParams& params) {
|
| - // TODO(erikkay) - This is a temporary hack. Show a menu here instead.
|
| - render_view_host()->InspectElementAt(params.x, params.y);
|
| -}
|
| -
|
| -void ExtensionView::StartDragging(const WebDropData& drop_data) {
|
| -}
|
| -
|
| -void ExtensionView::UpdateDragCursor(bool is_drop_target) {
|
| -}
|
| -
|
| -void ExtensionView::TakeFocus(bool reverse) {
|
| -}
|
| -
|
| -void ExtensionView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
|
| -}
|
|
|