summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-25 09:03:33 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-25 09:03:33 +0000
commitefae3d5f8aa9dcbce5d7f1027cef728007ce37db (patch)
treea41815c76127ee53c57ec2a1584b4228453ada14 /chrome/browser
parent1076a12a31fcd161e3e5c03f4ae88507ca9f7dbc (diff)
downloadchromium_src-efae3d5f8aa9dcbce5d7f1027cef728007ce37db.zip
chromium_src-efae3d5f8aa9dcbce5d7f1027cef728007ce37db.tar.gz
chromium_src-efae3d5f8aa9dcbce5d7f1027cef728007ce37db.tar.bz2
Bring the windows implementation of the constrained html dialog over to the new tab contents approach.
BUG=57885 TEST=none Review URL: http://codereview.chromium.org/4030002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/dom_ui/constrained_html_dialog.cc43
-rw-r--r--chrome/browser/dom_ui/constrained_html_dialog.h60
-rw-r--r--chrome/browser/views/constrained_html_delegate_win.cc111
-rw-r--r--chrome/browser/views/constrained_html_dialog_browsertest.cc93
-rw-r--r--chrome/browser/views/constrained_html_dialog_win.cc118
-rw-r--r--chrome/browser/views/constrained_html_dialog_win.h66
6 files changed, 111 insertions, 380 deletions
diff --git a/chrome/browser/dom_ui/constrained_html_dialog.cc b/chrome/browser/dom_ui/constrained_html_dialog.cc
deleted file mode 100644
index baa3cc6..0000000
--- a/chrome/browser/dom_ui/constrained_html_dialog.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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_dialog.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"
-
-ConstrainedHtmlDialog::ConstrainedHtmlDialog(Profile* profile,
- HtmlDialogUIDelegate* delegate)
- : DOMUI(NULL),
- profile_(profile),
- render_view_host_(NULL),
- html_dialog_ui_delegate_(delegate) {
-}
-
-ConstrainedHtmlDialog::~ConstrainedHtmlDialog() {
-}
-
-void ConstrainedHtmlDialog::InitializeDOMUI(RenderViewHost* render_view_host) {
- render_view_host_ = render_view_host;
-
- std::vector<DOMMessageHandler*> handlers;
- html_dialog_ui_delegate_->GetDOMMessageHandlers(&handlers);
- render_view_host->SetDOMUIProperty("dialogArguments",
- html_dialog_ui_delegate_->GetDialogArgs());
- for (std::vector<DOMMessageHandler*>::iterator it = handlers.begin();
- it != handlers.end(); ++it) {
- (*it)->Attach(this);
- AddMessageHandler(*it);
- }
-
- // Add a "DialogClosed" callback which matches HTMLDialogUI behavior.
- RegisterMessageCallback("DialogClose",
- NewCallback(this, &ConstrainedHtmlDialog::OnDialogClosed));
-}
-
-void ConstrainedHtmlDialog::OnDialogClosed(const ListValue* args) {
- html_dialog_ui_delegate()->OnDialogClosed(
- dom_ui_util::GetJsonResponseFromFirstArgumentInList(args));
-}
diff --git a/chrome/browser/dom_ui/constrained_html_dialog.h b/chrome/browser/dom_ui/constrained_html_dialog.h
deleted file mode 100644
index 9eda12a..0000000
--- a/chrome/browser/dom_ui/constrained_html_dialog.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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_DIALOG_H_
-#define CHROME_BROWSER_DOM_UI_CONSTRAINED_HTML_DIALOG_H_
-#pragma once
-
-#include <vector>
-
-#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/tab_contents/constrained_window.h"
-
-class HtmlDialogUIDelegate;
-class Profile;
-class RenderViewHost;
-
-// ConstrainedHtmlDialog 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 ConstrainedHtmlDialog : public DOMUI {
- public:
- static ConstrainedHtmlDialog* CreateConstrainedHTMLDialog(
- Profile* profile,
- HtmlDialogUIDelegate* delegate);
-
- virtual ConstrainedWindowDelegate* GetConstrainedWindowDelegate() = 0;
-
- // DOMUI override since this class does not use TabContents.
- Profile* GetProfile() const { return profile_; }
-
- protected:
- ConstrainedHtmlDialog(Profile* profile,
- HtmlDialogUIDelegate* delegate);
- virtual ~ConstrainedHtmlDialog();
-
- HtmlDialogUIDelegate* html_dialog_ui_delegate() {
- return html_dialog_ui_delegate_;
- }
-
- // DOMUI override since this class does not use TabContents.
- RenderViewHost* GetRenderViewHost() const { return render_view_host_; }
-
- void InitializeDOMUI(RenderViewHost* render_view_host);
-
- private:
- // JS Message Handler
- void OnDialogClosed(const ListValue* args);
-
- Profile* profile_;
- RenderViewHost* render_view_host_;
- HtmlDialogUIDelegate* html_dialog_ui_delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlDialog);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_CONSTRAINED_HTML_DIALOG_H_
diff --git a/chrome/browser/views/constrained_html_delegate_win.cc b/chrome/browser/views/constrained_html_delegate_win.cc
new file mode 100644
index 0000000..6a4ea77
--- /dev/null
+++ b/chrome/browser/views/constrained_html_delegate_win.cc
@@ -0,0 +1,111 @@
+// 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/html_dialog_tab_contents_delegate.h"
+#include "chrome/browser/dom_ui/html_dialog_ui.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/views/tab_contents/tab_contents_container.h"
+#include "gfx/rect.h"
+#include "ipc/ipc_message.h"
+#include "views/view.h"
+#include "views/widget/widget_win.h"
+#include "views/window/window_delegate.h"
+
+class ConstrainedHtmlDelegateWin : public TabContentsContainer,
+ public ConstrainedHtmlUIDelegate,
+ public ConstrainedWindowDelegate,
+ public HtmlDialogTabContentsDelegate {
+ public:
+ ConstrainedHtmlDelegateWin(Profile* profile,
+ HtmlDialogUIDelegate* delegate);
+ ~ConstrainedHtmlDelegateWin();
+
+ // Called when the dialog is actually being added to the views hierarchy.
+ void Init(gfx::NativeView parent_window);
+
+ // ConstrainedHtmlUIDelegate interface.
+ virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate();
+ virtual void OnDialogClose();
+
+ // ConstrainedWindowDelegate (aka views::WindowDelegate) interface.
+ virtual bool CanResize() const { return true; }
+ virtual views::View* GetContentsView() {
+ return this;
+ }
+ virtual void WindowClosing() {}
+
+ // HtmlDialogTabContentsDelegate interface.
+ void MoveContents(TabContents* source, const gfx::Rect& pos) {}
+ void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
+ void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {}
+
+ // Overridden from TabContentsContainer.
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ TabContentsContainer::ViewHierarchyChanged(is_add, parent, child);
+ if (is_add && child == this) {
+ ChangeTabContents(&html_tab_contents_);
+ gfx::Size size;
+ html_delegate_->GetDialogSize(&size);
+ SetBounds(x(), y(), size.width(), size.height());
+ }
+ }
+
+ void set_window(ConstrainedWindow* window) {
+ window_ = window;
+ }
+
+private:
+ TabContents html_tab_contents_;
+
+ HtmlDialogUIDelegate* html_delegate_;
+
+ // The constrained window that owns |this|. Saved so we can close it later.
+ ConstrainedWindow* window_;
+};
+
+ConstrainedHtmlDelegateWin::ConstrainedHtmlDelegateWin(
+ Profile* profile,
+ HtmlDialogUIDelegate* delegate)
+ : HtmlDialogTabContentsDelegate(profile),
+ html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL),
+ html_delegate_(delegate),
+ window_(NULL) {
+ CHECK(delegate);
+ html_tab_contents_.set_delegate(this);
+
+ // Set |this| as a property so the ConstrainedHtmlUI can retrieve it.
+ ConstrainedHtmlUI::GetPropertyAccessor().SetProperty(
+ html_tab_contents_.property_bag(), this);
+ html_tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(),
+ GURL(),
+ PageTransition::START_PAGE);
+}
+
+ConstrainedHtmlDelegateWin::~ConstrainedHtmlDelegateWin() {
+}
+
+HtmlDialogUIDelegate* ConstrainedHtmlDelegateWin::GetHtmlDialogUIDelegate() {
+ return html_delegate_;
+}
+
+void ConstrainedHtmlDelegateWin::OnDialogClose() {
+ window_->CloseConstrainedWindow();
+}
+
+// static
+void ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
+ Profile* profile,
+ HtmlDialogUIDelegate* delegate,
+ TabContents* container) {
+ ConstrainedHtmlDelegateWin* constrained_delegate =
+ new ConstrainedHtmlDelegateWin(profile, delegate);
+ ConstrainedWindow* constrained_window =
+ container->CreateConstrainedDialog(constrained_delegate);
+ constrained_delegate->set_window(constrained_window);
+}
diff --git a/chrome/browser/views/constrained_html_dialog_browsertest.cc b/chrome/browser/views/constrained_html_dialog_browsertest.cc
deleted file mode 100644
index c868fb8..0000000
--- a/chrome/browser/views/constrained_html_dialog_browsertest.cc
+++ /dev/null
@@ -1,93 +0,0 @@
-// 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.
-
-#if defined(OS_WIN)
-
-#include "chrome/test/ui/ui_test.h"
-
-#include "base/file_path.h"
-#include "base/message_loop.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/dom_ui/constrained_html_dialog.h"
-#include "chrome/browser/renderer_host/render_widget_host_view.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/views/constrained_html_dialog_win.h"
-#include "chrome/browser/views/html_dialog_view.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "chrome/test/ui_test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "views/widget/widget.h"
-#include "views/window/window.h"
-
-using testing::Eq;
-
-namespace {
-
-// Window non-client-area means that the minimum size for the window
-// won't be the actual minimum size - our layout and resizing code
-// makes sure the chrome is always visible.
-const int kMinimumWidthToTestFor = 20;
-const int kMinimumHeightToTestFor = 30;
-
-class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate {
- public:
- TestHtmlDialogUIDelegate() {}
- virtual ~TestHtmlDialogUIDelegate() {}
-
- // HTMLDialogUIDelegate implementation:
- virtual bool IsDialogModal() const {
- return true;
- }
- virtual std::wstring GetDialogTitle() const {
- return std::wstring(L"Test");
- }
- virtual GURL GetDialogContentURL() const {
- return GURL(chrome::kAboutAboutURL);
- }
- virtual void GetDOMMessageHandlers(
- std::vector<DOMMessageHandler*>* handlers) const {}
- virtual void GetDialogSize(gfx::Size* size) const {
- size->set_width(400);
- size->set_height(400);
- }
- virtual std::string GetDialogArgs() const {
- return std::string();
- }
- virtual void OnDialogClosed(const std::string& json_retval) { }
- virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) {
- if (out_close_dialog)
- *out_close_dialog = true;
- }
-};
-
-} // namespace
-
-class ConstrainedHtmlDialogBrowserTest : public InProcessBrowserTest {
- public:
- ConstrainedHtmlDialogBrowserTest() {}
-};
-
-IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, LoadWindow) {
- HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate();
-
- ConstrainedHtmlDialogWin* dialog =
- new ConstrainedHtmlDialogWin(browser()->profile(), delegate);
-
- TabContents* tab_contents = browser()->GetSelectedTabContents();
- ASSERT_TRUE(tab_contents != NULL);
- ConstrainedWindow* window = tab_contents->CreateConstrainedDialog(
- dialog->GetConstrainedWindowDelegate());
-
- EXPECT_EQ(1, tab_contents->constrained_window_count());
-
- gfx::Rect bounds = dialog->GetContentsView()->bounds();
- EXPECT_LT(0, bounds.width());
- EXPECT_LT(0, bounds.height());
- EXPECT_GE(400, bounds.width());
- EXPECT_GE(400, bounds.height());
-}
-
-#endif // OS_WIN
diff --git a/chrome/browser/views/constrained_html_dialog_win.cc b/chrome/browser/views/constrained_html_dialog_win.cc
deleted file mode 100644
index 2cdc81c..0000000
--- a/chrome/browser/views/constrained_html_dialog_win.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-// 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/views/constrained_html_dialog_win.h"
-
-#include "chrome/browser/dom_ui/html_dialog_ui.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
-#include "chrome/browser/renderer_host/render_view_host_delegate.h"
-#include "chrome/browser/renderer_host/render_widget_host_view_win.h"
-#include "chrome/browser/renderer_host/site_instance.h"
-#include "chrome/common/bindings_policy.h"
-#include "chrome/common/renderer_preferences.h"
-#include "views/widget/widget_win.h"
-#include "views/window/window_delegate.h"
-
-class ConstrainedHtmlDialogHostView : public views::NativeViewHost {
- public:
- explicit ConstrainedHtmlDialogHostView(ConstrainedHtmlDialogWin* dialog)
- : dialog_(dialog),
- initialized_(false) {
- }
-
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
- if (is_add && GetWidget() && !initialized_) {
- dialog_->Init(GetWidget()->GetNativeView());
- initialized_ = true;
- }
- }
-
- private:
- ConstrainedHtmlDialogWin* dialog_;
- bool initialized_;
-};
-
-ConstrainedHtmlDialogWin::ConstrainedHtmlDialogWin(
- Profile* profile,
- HtmlDialogUIDelegate* delegate)
- : ConstrainedHtmlDialog(profile, delegate) {
- CHECK(delegate);
- native_view_host_ = new ConstrainedHtmlDialogHostView(this);
-
- // Size the native view to match the delegate preferred size.
- gfx::Size size;
- delegate->GetDialogSize(&size);
- native_view_host_->SetPreferredSize(size);
-
- // Create a site instance for the correct URL.
- dialog_url_ = delegate->GetDialogContentURL();
- site_instance_ =
- SiteInstance::CreateSiteInstanceForURL(profile, dialog_url_);
-}
-
-ConstrainedHtmlDialogWin::~ConstrainedHtmlDialogWin() {
-}
-
-ConstrainedWindowDelegate*
-ConstrainedHtmlDialogWin::GetConstrainedWindowDelegate() {
- return this;
-}
-
-bool ConstrainedHtmlDialogWin::CanResize() const {
- return true;
-}
-
-views::View* ConstrainedHtmlDialogWin::GetContentsView() {
- return native_view_host_;
-}
-
-void ConstrainedHtmlDialogWin::WindowClosing() {
- html_dialog_ui_delegate()->OnDialogClosed("");
-}
-
-int ConstrainedHtmlDialogWin::GetBrowserWindowID() const {
- return 0;
-}
-
-ViewType::Type ConstrainedHtmlDialogWin::GetRenderViewType() const {
- return ViewType::HTML_DIALOG_UI;
-}
-
-RendererPreferences ConstrainedHtmlDialogWin::GetRendererPrefs(
- Profile* profile) const {
- return RendererPreferences();
-}
-
-void ConstrainedHtmlDialogWin::ProcessDOMUIMessage(
- const ViewHostMsg_DomMessage_Params& params) {
- DOMUI::ProcessDOMUIMessage(params);
-}
-
-void ConstrainedHtmlDialogWin::Init(gfx::NativeView parent_view) {
- render_view_host_.reset(new RenderViewHost(site_instance_,
- this,
- MSG_ROUTING_NONE,
- NULL));
- render_view_host_->AllowBindings(BindingsPolicy::DOM_UI);
- render_widget_host_view_ =
- new RenderWidgetHostViewWin(render_view_host_.get());
- render_view_host_->set_view(render_widget_host_view_);
- render_view_host_->CreateRenderView(string16());
- render_view_host_->NavigateToURL(dialog_url_);
- HWND hwnd = render_widget_host_view_->Create(parent_view);
- render_widget_host_view_->ShowWindow(SW_SHOW);
- native_view_host_->Attach(hwnd);
-
- InitializeDOMUI(render_view_host_.get());
-}
-
-// static
-ConstrainedHtmlDialog* ConstrainedHtmlDialog::CreateConstrainedHTMLDialog(
- Profile* profile, HtmlDialogUIDelegate* delegate) {
- return new ConstrainedHtmlDialogWin(profile, delegate);
-}
diff --git a/chrome/browser/views/constrained_html_dialog_win.h b/chrome/browser/views/constrained_html_dialog_win.h
deleted file mode 100644
index 6faa821..0000000
--- a/chrome/browser/views/constrained_html_dialog_win.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// 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_VIEWS_CONSTRAINED_HTML_DIALOG_WIN_H_
-#define CHROME_BROWSER_VIEWS_CONSTRAINED_HTML_DIALOG_WIN_H_
-#pragma once
-
-#include <string>
-
-#include "chrome/browser/dom_ui/constrained_html_dialog.h"
-#include "chrome/browser/dom_ui/html_dialog_ui.h"
-#include "chrome/browser/renderer_host/render_view_host_delegate.h"
-#include "chrome/browser/renderer_host/site_instance.h"
-#include "chrome/common/bindings_policy.h"
-#include "chrome/common/renderer_preferences.h"
-#include "views/controls/native/native_view_host.h"
-#include "views/window/window_delegate.h"
-
-class RenderViewHost;
-class RenderWidgetHostViewWin;
-
-class ConstrainedHtmlDialogWin : public ConstrainedHtmlDialog,
- public ConstrainedWindowDelegate,
- public RenderViewHostDelegate {
- public:
- ConstrainedHtmlDialogWin(Profile* profile,
- HtmlDialogUIDelegate* delegate);
- ~ConstrainedHtmlDialogWin();
-
- // Called when the dialog is actually being added to the views hierarchy.
- void Init(gfx::NativeView parent_window);
-
- // ConstrainedHtmlDialog override.
- virtual ConstrainedWindowDelegate* GetConstrainedWindowDelegate();
-
- // ConstrainedWindowDelegate (aka views::WindowDelegate) override.
- virtual bool CanResize() const;
- virtual views::View* GetContentsView();
- virtual void WindowClosing();
-
- // RenderViewHostDelegate overrides.
- virtual int GetBrowserWindowID() const;
- virtual ViewType::Type GetRenderViewType() const;
- virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
- virtual void ProcessDOMUIMessage(
- const ViewHostMsg_DomMessage_Params& params);
- virtual void UpdateInspectorSetting(const std::string& key,
- const std::string& value) {}
- virtual void ClearInspectorSettings() {}
-
- private:
- SiteInstance* site_instance_;
- scoped_ptr<RenderViewHost> render_view_host_;
-
- // URL to be displayed in the dialog.
- GURL dialog_url_;
-
- // Pointer owned by the |render_view_host_| object.
- RenderWidgetHostViewWin* render_widget_host_view_;
-
- // View pointer owned by the views hierarchy.
- views::NativeViewHost* native_view_host_;
-};
-
-#endif // CHROME_BROWSER_VIEWS_CONSTRAINED_HTML_DIALOG_WIN_H_