summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 20:53:19 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 20:53:19 +0000
commit10f27fb06b2d231f8ab3bb0177439760d9a3b654 (patch)
tree7cce1bb2c90dc61e2228ea2e25edd88ef346d986
parent72dc92dc4f37783ba4aedae7d2d9c1750fac999e (diff)
downloadchromium_src-10f27fb06b2d231f8ab3bb0177439760d9a3b654.zip
chromium_src-10f27fb06b2d231f8ab3bb0177439760d9a3b654.tar.gz
chromium_src-10f27fb06b2d231f8ab3bb0177439760d9a3b654.tar.bz2
Undo part of brettw's WebContents refactor that removed TabContentsDelegate
code from HtmlDialogView. BUG=http://code.google.com/p/chromium/issues/detail?id=9884 Review URL: http://codereview.chromium.org/99305 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15238 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/frame/browser_view.cc3
-rw-r--r--chrome/browser/views/html_dialog_view.cc83
-rw-r--r--chrome/browser/views/html_dialog_view.h33
3 files changed, 112 insertions, 7 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index b4f68f6..8581d43 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -847,8 +847,7 @@ void BrowserView::ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
void* parent_window) {
HWND parent_hwnd = reinterpret_cast<HWND>(parent_window);
parent_hwnd = parent_hwnd ? parent_hwnd : GetWidget()->GetNativeView();
- HtmlDialogView* html_view = new HtmlDialogView(browser_->profile(),
- delegate);
+ HtmlDialogView* html_view = new HtmlDialogView(browser_.get(), delegate);
views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), html_view);
html_view->InitDialog();
html_view->window()->Show();
diff --git a/chrome/browser/views/html_dialog_view.cc b/chrome/browser/views/html_dialog_view.cc
index 28f7bb1..4a30c10 100644
--- a/chrome/browser/views/html_dialog_view.cc
+++ b/chrome/browser/views/html_dialog_view.cc
@@ -12,12 +12,13 @@
////////////////////////////////////////////////////////////////////////////////
// HtmlDialogView, public:
-HtmlDialogView::HtmlDialogView(Profile* profile,
+HtmlDialogView::HtmlDialogView(Browser* parent_browser,
HtmlDialogUIDelegate* delegate)
: DOMView(),
- profile_(profile),
+ parent_browser_(parent_browser),
+ profile_(parent_browser->profile()),
delegate_(delegate) {
- DCHECK(profile);
+ DCHECK(profile_);
}
HtmlDialogView::~HtmlDialogView() {
@@ -93,12 +94,88 @@ void HtmlDialogView::OnDialogClosed(const std::string& json_retval) {
}
////////////////////////////////////////////////////////////////////////////////
+// TabContentsDelegate implementation:
+
+void HtmlDialogView::OpenURLFromTab(TabContents* source,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition) {
+ // Force all links to open in a new window, ignoring the incoming
+ // disposition. This is a tabless, modal dialog so we can't just
+ // open it in the current frame.
+ static_cast<TabContentsDelegate*>(parent_browser_)->OpenURLFromTab(
+ source, url, referrer, NEW_WINDOW, transition);
+}
+
+void HtmlDialogView::NavigationStateChanged(const TabContents* source,
+ unsigned changed_flags) {
+ // We shouldn't receive any NavigationStateChanged except the first
+ // one, which we ignore because we're a dialog box.
+}
+
+void HtmlDialogView::ReplaceContents(TabContents* source,
+ TabContents* new_contents) {
+}
+
+void HtmlDialogView::AddNewContents(TabContents* source,
+ TabContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture) {
+ static_cast<TabContentsDelegate*>(parent_browser_)->AddNewContents(
+ source, new_contents, NEW_WINDOW, initial_pos, user_gesture);
+}
+
+void HtmlDialogView::ActivateContents(TabContents* contents) {
+ // We don't do anything here because there's only one TabContents in
+ // this frame and we don't have a TabStripModel.
+}
+
+void HtmlDialogView::LoadingStateChanged(TabContents* source) {
+ // We don't care about this notification.
+}
+
+void HtmlDialogView::CloseContents(TabContents* source) {
+ // We receive this message but don't handle it because we really do the
+ // cleanup in OnDialogClosed().
+}
+
+void HtmlDialogView::MoveContents(TabContents* source, const gfx::Rect& pos) {
+ // The contained web page wishes to resize itself. We let it do this because
+ // if it's a dialog we know about, we trust it not to be mean to the user.
+ window()->SetBounds(pos);
+}
+
+bool HtmlDialogView::IsPopup(TabContents* source) {
+ // This needs to return true so that we are allowed to be resized by our
+ // contents.
+ return true;
+}
+
+void HtmlDialogView::ToolbarSizeChanged(TabContents* source,
+ bool is_animating) {
+ Layout();
+}
+
+void HtmlDialogView::URLStarredChanged(TabContents* source, bool starred) {
+ // We don't have a visible star to click in the window.
+ NOTREACHED();
+}
+
+void HtmlDialogView::UpdateTargetURL(TabContents* source, const GURL& url) {
+ // Ignored.
+}
+
+////////////////////////////////////////////////////////////////////////////////
// HtmlDialogView:
void HtmlDialogView::InitDialog() {
// Now Init the DOMView. This view runs in its own process to render the html.
DOMView::Init(profile_, NULL);
+ tab_contents_->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(tab_contents_->property_bag(),
diff --git a/chrome/browser/views/html_dialog_view.h b/chrome/browser/views/html_dialog_view.h
index b886d1e..0043252 100644
--- a/chrome/browser/views/html_dialog_view.h
+++ b/chrome/browser/views/html_dialog_view.h
@@ -29,11 +29,11 @@ class Window;
////////////////////////////////////////////////////////////////////////////////
class HtmlDialogView
: public DOMView,
+ public TabContentsDelegate,
public HtmlDialogUIDelegate,
public views::WindowDelegate {
public:
- HtmlDialogView(Profile* profile,
- HtmlDialogUIDelegate* delegate);
+ HtmlDialogView(Browser* parent_browser, HtmlDialogUIDelegate* delegate);
virtual ~HtmlDialogView();
// Initializes the contents of the dialog (the DOMView and the callbacks).
@@ -57,7 +57,36 @@ class HtmlDialogView
virtual void GetDialogSize(gfx::Size* size) const;
virtual std::string GetDialogArgs() const;
virtual void OnDialogClosed(const std::string& json_retval);
+
+ // Overridden from TabContentsDelegate:
+ virtual void OpenURLFromTab(TabContents* source,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition);
+ virtual void NavigationStateChanged(const TabContents* source,
+ unsigned changed_flags);
+ virtual void ReplaceContents(TabContents* source,
+ TabContents* new_contents);
+ virtual void AddNewContents(TabContents* source,
+ TabContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture);
+ virtual void ActivateContents(TabContents* contents);
+ virtual void LoadingStateChanged(TabContents* source);
+ virtual void CloseContents(TabContents* source);
+ virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
+ virtual bool IsPopup(TabContents* source);
+ virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
+ virtual void URLStarredChanged(TabContents* source, bool starred);
+ virtual void UpdateTargetURL(TabContents* source, const GURL& url);
+
private:
+ // The Browser object which created this html dialog; we send all
+ // window opening/navigations to this object.
+ Browser* parent_browser_;
+
Profile* profile_;
// This view is a delegate to the HTML content since it needs to get notified