diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-03 03:05:11 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-03 03:05:11 +0000 |
commit | 4acc19a6f31abef9608546d10f107240603ca57e (patch) | |
tree | 632c914c428e94c05c8b9cb52cb183e62ae13e56 /chrome/browser/views | |
parent | 15936cdb983239ba2347e624af19e7305e416c7b (diff) | |
download | chromium_src-4acc19a6f31abef9608546d10f107240603ca57e.zip chromium_src-4acc19a6f31abef9608546d10f107240603ca57e.tar.gz chromium_src-4acc19a6f31abef9608546d10f107240603ca57e.tar.bz2 |
Move HTML dialogs out of their own tab contents type. Moved functions to new
file html_dialog_ui.*
Move WebContents view creation into the constructor, which makes a bunch of
extra calls to CreateView unnecessary.
Remove unused CallJavascriptFunction() functions in DOMUI.
Review URL: http://codereview.chromium.org/56065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/dom_view.cc | 32 | ||||
-rw-r--r-- | chrome/browser/views/dom_view.h | 13 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/html_dialog_view.cc | 26 | ||||
-rw-r--r-- | chrome/browser/views/html_dialog_view.h | 12 |
6 files changed, 45 insertions, 43 deletions
diff --git a/chrome/browser/views/dom_view.cc b/chrome/browser/views/dom_view.cc index bd7f7df..9af3b66 100644 --- a/chrome/browser/views/dom_view.cc +++ b/chrome/browser/views/dom_view.cc @@ -6,35 +6,31 @@ #include "chrome/browser/dom_ui/dom_ui_host.h" -DOMView::DOMView(const GURL& contents) - : contents_(contents), initialized_(false), host_(NULL) { +DOMView::DOMView() : initialized_(false), web_contents_(NULL) { SetFocusable(true); } DOMView::~DOMView() { - if (host_) { + if (web_contents_) { Detach(); - host_->Destroy(); - host_ = NULL; + web_contents_->Destroy(); + web_contents_ = NULL; } } bool DOMView::Init(Profile* profile, SiteInstance* instance) { if (initialized_) return true; - initialized_ = true; - - // TODO(timsteele): This should use a separate factory method; e.g - // a DOMUIHostFactory rather than TabContentsFactory, because DOMView's - // should only be associated with instances of DOMUIHost. - TabContentsType type = TabContents::TypeForURL(&contents_); - TabContents* tab_contents = TabContents::CreateWithType(type, profile, - instance); - host_ = tab_contents->AsDOMUIHost(); - DCHECK(host_); - views::HWNDView::Attach(host_->GetNativeView()); - host_->SetupController(profile); - host_->controller()->LoadURL(contents_, GURL(), PageTransition::START_PAGE); + initialized_ = true; + web_contents_ = new WebContents(profile, instance, NULL, + MSG_ROUTING_NONE, NULL); + views::HWNDView::Attach(web_contents_->GetNativeView()); + web_contents_->SetupController(profile); return true; } + +void DOMView::LoadURL(const GURL& url) { + DCHECK(initialized_); + web_contents_->controller()->LoadURL(url, GURL(), PageTransition::START_PAGE); +} diff --git a/chrome/browser/views/dom_view.h b/chrome/browser/views/dom_view.h index 3a4e6d0..bfa6d13 100644 --- a/chrome/browser/views/dom_view.h +++ b/chrome/browser/views/dom_view.h @@ -11,29 +11,32 @@ #include "chrome/views/controls/hwnd_view.h" #include "googleurl/src/gurl.h" -class DOMUIHost; class Profile; class SiteInstance; +class WebContents; class DOMView : public views::HWNDView { public: // Construct a DOMView to display the given data: URL. - explicit DOMView(const GURL& contents); + explicit DOMView(); virtual ~DOMView(); - // Initialize the view, causing it to load its contents. This should be + // Initialize the view, creating the contents. This should be // called once the view has been added to a container. + // // If |instance| is not null, then the view will be loaded in the same // process as the given instance. bool Init(Profile* profile, SiteInstance* instance); + // Loads the given URL into the page. You must have previously called Init(). + void LoadURL(const GURL& url); + protected: virtual bool CanProcessTabKeyEvents() { return true; } - DOMUIHost* host_; + WebContents* web_contents_; private: - GURL contents_; bool initialized_; DISALLOW_COPY_AND_ASSIGN(DOMView); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index d0c3e07..f5341d6 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -822,7 +822,7 @@ void BrowserView::ShowNewProfileDialog() { NewProfileDialog::RunDialog(); } -void BrowserView::ShowHTMLDialog(HtmlDialogContentsDelegate* delegate, +void BrowserView::ShowHTMLDialog(HtmlDialogUIDelegate* delegate, void* parent_window) { HWND parent_hwnd = reinterpret_cast<HWND>(parent_window); parent_hwnd = parent_hwnd ? parent_hwnd : GetWidget()->GetNativeView(); diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 6386999..d23b76d 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -26,6 +26,7 @@ class BrowserToolbarView; class EncodingMenuControllerDelegate; class FindBarController; class FullscreenExitBubble; +class HtmlDialogUIDelegate; class InfoBarContainer; class Menu; class StatusBubbleViews; @@ -200,7 +201,7 @@ class BrowserView : public BrowserWindow, virtual void ShowPasswordManager(); virtual void ShowSelectProfileDialog(); virtual void ShowNewProfileDialog(); - virtual void ShowHTMLDialog(HtmlDialogContentsDelegate* delegate, + virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate, void* parent_window); virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) const; diff --git a/chrome/browser/views/html_dialog_view.cc b/chrome/browser/views/html_dialog_view.cc index c26bdaf..ecb459c 100644 --- a/chrome/browser/views/html_dialog_view.cc +++ b/chrome/browser/views/html_dialog_view.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/html_dialog_view.h" #include "chrome/browser/browser.h" +#include "chrome/browser/tab_contents/web_contents.h" #include "chrome/views/widget/root_view.h" #include "chrome/views/window/window.h" @@ -13,8 +14,8 @@ HtmlDialogView::HtmlDialogView(Browser* parent_browser, Profile* profile, - HtmlDialogContentsDelegate* delegate) - : DOMView(delegate->GetDialogContentURL()), + HtmlDialogUIDelegate* delegate) + : DOMView(), parent_browser_(parent_browser), profile_(profile), delegate_(delegate) { @@ -66,7 +67,7 @@ views::View* HtmlDialogView::GetInitiallyFocusedView() { } //////////////////////////////////////////////////////////////////////////////// -// HtmlDialogContentsDelegate implementation: +// HtmlDialogUIDelegate implementation: bool HtmlDialogView::IsDialogModal() const { return IsModal(); @@ -122,10 +123,10 @@ void HtmlDialogView::ReplaceContents(TabContents* source, } void HtmlDialogView::AddNewContents(TabContents* source, - TabContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) { + TabContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) { parent_browser_->AddNewContents( source, new_contents, NEW_WINDOW, initial_pos, user_gesture); } @@ -177,9 +178,10 @@ void HtmlDialogView::InitDialog() { // Now Init the DOMView. This view runs in its own process to render the html. DOMView::Init(profile_, NULL); - // Make sure this new TabContents we just created in Init() knows about us. - DCHECK(host_->type() == TAB_CONTENTS_HTML_DIALOG); - HtmlDialogContents* host = static_cast<HtmlDialogContents*>(host_); - host->Init(this); - host->set_delegate(this); + // Set the delegate. This must be done before loading the page. See + // the comment above HtmlDialogUI in its header file for why. + HtmlDialogUI::GetPropertyAccessor().SetProperty(web_contents_->property_bag(), + this); + + DOMView::LoadURL(delegate_->GetDialogContentURL()); } diff --git a/chrome/browser/views/html_dialog_view.h b/chrome/browser/views/html_dialog_view.h index 54bace6..bdff126 100644 --- a/chrome/browser/views/html_dialog_view.h +++ b/chrome/browser/views/html_dialog_view.h @@ -8,7 +8,7 @@ #include <string> #include "base/gfx/size.h" -#include "chrome/browser/dom_ui/html_dialog_contents.h" +#include "chrome/browser/dom_ui/html_dialog_ui.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/views/dom_view.h" #include "chrome/views/window/window_delegate.h" @@ -22,7 +22,7 @@ class Window; // // HtmlDialogView is a view used to display an HTML dialog to the user. The // content of the dialogs is determined by the delegate -// (HtmlDialogContentsDelegate), but is basically a file URL along with a +// (HtmlDialogUIDelegate), but is basically a file URL along with a // JSON input string. The HTML is supposed to show a UI to the user and is // expected to send back a JSON file as a return value. // @@ -30,12 +30,12 @@ class Window; class HtmlDialogView : public DOMView, public TabContentsDelegate, - public HtmlDialogContentsDelegate, + public HtmlDialogUIDelegate, public views::WindowDelegate { public: HtmlDialogView(Browser* parent_browser, Profile* profile, - HtmlDialogContentsDelegate* delegate); + HtmlDialogUIDelegate* delegate); virtual ~HtmlDialogView(); // Initializes the contents of the dialog (the DOMView and the callbacks). @@ -52,7 +52,7 @@ class HtmlDialogView virtual views::View* GetContentsView(); virtual views::View* GetInitiallyFocusedView(); - // Overridden from HtmlDialogContentsDelegate: + // Overridden from HtmlDialogUI::Delegate: virtual bool IsDialogModal() const; virtual std::wstring GetDialogTitle() const; virtual GURL GetDialogContentURL() const; @@ -95,7 +95,7 @@ class HtmlDialogView // about when the dialog is closing. For all other actions (besides dialog // closing) we delegate to the creator of this view, which we keep track of // using this variable. - HtmlDialogContentsDelegate* delegate_; + HtmlDialogUIDelegate* delegate_; DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); }; |