diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-18 19:42:22 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-18 19:42:22 +0000 |
commit | 2a30775a7ffa8558399bcc8131a39e0ae1600b60 (patch) | |
tree | 5c011ef2affaaf76a001c6f5003ab6f61e99d342 /chrome/browser | |
parent | bf6384fd33588a3cf1e7780bcb6f76c305342a13 (diff) | |
download | chromium_src-2a30775a7ffa8558399bcc8131a39e0ae1600b60.zip chromium_src-2a30775a7ffa8558399bcc8131a39e0ae1600b60.tar.gz chromium_src-2a30775a7ffa8558399bcc8131a39e0ae1600b60.tar.bz2 |
Use TabContents for Constrained HTML dialogs.
This makes constrained html windows match HtmlDialogUI more closely. The main reason for wanting to do this is that TabContents{View} has a lot of functionality that we need, but miss out on if we use RenderViewHost directly. This isn't hooked up to anything yet, but can be tested using sync setup.
BUG=58022
TEST=manual
Review URL: http://codereview.chromium.org/3846002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/dom_ui/constrained_html_ui.cc | 53 | ||||
-rw-r--r-- | chrome/browser/dom_ui/constrained_html_ui.h | 62 | ||||
-rw-r--r-- | chrome/browser/gtk/constrained_html_dialog_gtk.cc | 89 |
3 files changed, 173 insertions, 31 deletions
diff --git a/chrome/browser/dom_ui/constrained_html_ui.cc b/chrome/browser/dom_ui/constrained_html_ui.cc new file mode 100644 index 0000000..e715977 --- /dev/null +++ b/chrome/browser/dom_ui/constrained_html_ui.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/constrained_html_ui.h" + +#include "chrome/browser/dom_ui/dom_ui_util.h" +#include "chrome/browser/dom_ui/html_dialog_ui.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/common/bindings_policy.h" + +ConstrainedHtmlUI::ConstrainedHtmlUI(TabContents* contents) + : DOMUI(contents) { +} + +ConstrainedHtmlUI::~ConstrainedHtmlUI() { +} + +void ConstrainedHtmlUI::RenderViewCreated( + RenderViewHost* render_view_host) { + HtmlDialogUIDelegate* delegate = + GetConstrainedDelegate()->GetHtmlDialogUIDelegate(); + std::vector<DOMMessageHandler*> handlers; + delegate->GetDOMMessageHandlers(&handlers); + render_view_host->SetDOMUIProperty("dialogArguments", + delegate->GetDialogArgs()); + for (std::vector<DOMMessageHandler*>::iterator it = handlers.begin(); + it != handlers.end(); ++it) { + (*it)->Attach(this); + AddMessageHandler(*it); + } + + // Add a "DialogClose" callback which matches HTMLDialogUI behavior. + RegisterMessageCallback("DialogClose", + NewCallback(this, &ConstrainedHtmlUI::OnDialogClose)); +} + +void ConstrainedHtmlUI::OnDialogClose(const ListValue* args) { + GetConstrainedDelegate()->GetHtmlDialogUIDelegate()->OnDialogClosed( + dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); + GetConstrainedDelegate()->OnDialogClose(); +} + +ConstrainedHtmlUIDelegate* + ConstrainedHtmlUI::GetConstrainedDelegate() { + return *GetPropertyAccessor().GetProperty(tab_contents()->property_bag()); +} + +// static +PropertyAccessor<ConstrainedHtmlUIDelegate*>& + ConstrainedHtmlUI::GetPropertyAccessor() { + return *Singleton<PropertyAccessor<ConstrainedHtmlUIDelegate*> >::get(); +} diff --git a/chrome/browser/dom_ui/constrained_html_ui.h b/chrome/browser/dom_ui/constrained_html_ui.h new file mode 100644 index 0000000..8327c99 --- /dev/null +++ b/chrome/browser/dom_ui/constrained_html_ui.h @@ -0,0 +1,62 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOM_UI_CONSTRAINED_HTML_UI_H_ +#define CHROME_BROWSER_DOM_UI_CONSTRAINED_HTML_UI_H_ +#pragma once + +#include <vector> + +#include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/tab_contents/constrained_window.h" +#include "chrome/browser/tab_contents/tab_contents.h" + +class HtmlDialogUIDelegate; +class Profile; +class RenderViewHost; +class TabContents; + +class ConstrainedHtmlUIDelegate { + public: + virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() = 0; + + // Called when the dialog should close. + virtual void OnDialogClose() = 0; +}; + +// ConstrainedHtmlUI is a facility to show HTML DOM_UI content +// in a tab-modal constrained dialog. It is implemented as an adapter +// between an HtmlDialogUI object and a ConstrainedWindow object. +// +// Since ConstrainedWindow requires platform-specific delegate +// implementations, this class is just a factory stub. +class ConstrainedHtmlUI : public DOMUI { + public: + explicit ConstrainedHtmlUI(TabContents* contents); + virtual ~ConstrainedHtmlUI(); + + virtual void RenderViewCreated(RenderViewHost* render_view_host); + + // Create a constrained HTML dialog. The actual object that gets created + // is a ConstrainedHtmlUIDelegate, which later triggers construction of a + // ConstrainedHtmlUI object. + static void CreateConstrainedHtmlDialog(Profile* profile, + HtmlDialogUIDelegate* delegate, + TabContents* overshadowed); + + // Returns a property accessor that can be used to set the + // ConstrainedHtmlUIDelegate property on a TabContents. + static PropertyAccessor<ConstrainedHtmlUIDelegate*>& + GetPropertyAccessor(); + + private: + ConstrainedHtmlUIDelegate* GetConstrainedDelegate(); + + // JS Message Handler + void OnDialogClose(const ListValue* args); + + DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlUI); +}; + +#endif // CHROME_BROWSER_DOM_UI_CONSTRAINED_HTML_UI_H_ diff --git a/chrome/browser/gtk/constrained_html_dialog_gtk.cc b/chrome/browser/gtk/constrained_html_dialog_gtk.cc index 6fd36f1..5f65b2a 100644 --- a/chrome/browser/gtk/constrained_html_dialog_gtk.cc +++ b/chrome/browser/gtk/constrained_html_dialog_gtk.cc @@ -2,59 +2,77 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/dom_ui/constrained_html_dialog.h" +#include "chrome/browser/dom_ui/constrained_html_ui.h" #include "gfx/rect.h" #include "chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h" #include "chrome/browser/dom_ui/html_dialog_ui.h" #include "chrome/browser/gtk/constrained_window_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" +#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_source.h" #include "ipc/ipc_message.h" -class ConstrainedHtmlDialogGtk : public ConstrainedHtmlDialog, - public ConstrainedWindowGtkDelegate, - public HtmlDialogTabContentsDelegate { +class ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate, + public HtmlDialogTabContentsDelegate, + public ConstrainedHtmlUIDelegate { public: - ConstrainedHtmlDialogGtk(Profile* profile, + ConstrainedHtmlDelegateGtk(Profile* profile, HtmlDialogUIDelegate* delegate); - virtual ~ConstrainedHtmlDialogGtk(); - - // ConstrainedHtmlDialog ----------------------------------------------------- - virtual ConstrainedWindowDelegate* GetConstrainedWindowDelegate() { - return this; - } + virtual ~ConstrainedHtmlDelegateGtk(); // ConstrainedWindowGtkDelegate ---------------------------------------------- virtual GtkWidget* GetWidgetRoot() { return tab_contents_container_.widget(); } - virtual void DeleteDelegate() { delete this; } + // ConstrainedHtmlDelegate --------------------------------------------- + virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate(); + virtual void OnDialogClose(); + // HtmlDialogTabContentsDelegate --------------------------------------------- void MoveContents(TabContents* source, const gfx::Rect& pos) {} void ToolbarSizeChanged(TabContents* source, bool is_animating) {} void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} + void set_window(ConstrainedWindow* window) { + window_ = window; + } + private: + TabContents tab_contents_; TabContentsContainerGtk tab_contents_container_; + HtmlDialogUIDelegate* html_delegate_; + + // The constrained window that owns |this|. It's saved here because it needs + // to be closed in response to the DOMUI OnDialogClose callback. + ConstrainedWindow* window_; }; -ConstrainedHtmlDialogGtk::ConstrainedHtmlDialogGtk( +ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( Profile* profile, HtmlDialogUIDelegate* delegate) - : ConstrainedHtmlDialog(profile, delegate), - HtmlDialogTabContentsDelegate(profile), - tab_contents_container_(NULL) { - tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); - tab_contents_->set_delegate(this); - tab_contents_->controller().LoadURL(delegate->GetDialogContentURL(), - GURL(), PageTransition::START_PAGE); - tab_contents_container_.SetTabContents(tab_contents_); + : HtmlDialogTabContentsDelegate(profile), + tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), + tab_contents_container_(NULL), + html_delegate_(delegate), + window_(NULL) { + tab_contents_.set_delegate(this); + + // Set |this| as a property on the tab contents so that the ConstrainedHtmlUI + // can get a reference to |this|. + ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( + tab_contents_.property_bag(), this); + + tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(), + GURL(), PageTransition::START_PAGE); + tab_contents_container_.SetTabContents(&tab_contents_); gfx::Size dialog_size; delegate->GetDialogSize(&dialog_size); @@ -62,20 +80,29 @@ ConstrainedHtmlDialogGtk::ConstrainedHtmlDialogGtk( dialog_size.width(), dialog_size.height()); - InitializeDOMUI(tab_contents_->render_view_host()); - gtk_widget_show_all(GetWidgetRoot()); } -ConstrainedHtmlDialogGtk::~ConstrainedHtmlDialogGtk() { - delete tab_contents_; - // Prevent other accesses to |tab_contents_| (during superclass destruction, - // for example). - tab_contents_ = NULL; +ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { +} + +HtmlDialogUIDelegate* + ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() { + return html_delegate_; +} + +void ConstrainedHtmlDelegateGtk::OnDialogClose() { + window_->CloseConstrainedWindow(); } // static -ConstrainedHtmlDialog* ConstrainedHtmlDialog::CreateConstrainedHTMLDialog( - Profile* profile, HtmlDialogUIDelegate* delegate) { - return new ConstrainedHtmlDialogGtk(profile, delegate); +void ConstrainedHtmlUI::CreateConstrainedHtmlDialog( + Profile* profile, + HtmlDialogUIDelegate* delegate, + TabContents* overshadowed) { + ConstrainedHtmlDelegateGtk* constrained_delegate = + new ConstrainedHtmlDelegateGtk(profile, delegate); + ConstrainedWindow* constrained_window = + overshadowed->CreateConstrainedDialog(constrained_delegate); + constrained_delegate->set_window(constrained_window); } |