summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-23 22:03:11 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-23 22:03:11 +0000
commitd9828740497cdb2eeb0ebaad476299fd39933b89 (patch)
tree44453be37e1c73fe8a236691c2fb84716f9e0a75
parentb4c49e5e17495443bb8feba522b6be7b810ca277 (diff)
downloadchromium_src-d9828740497cdb2eeb0ebaad476299fd39933b89.zip
chromium_src-d9828740497cdb2eeb0ebaad476299fd39933b89.tar.gz
chromium_src-d9828740497cdb2eeb0ebaad476299fd39933b89.tar.bz2
Revert 133467 - Convert the last users of DOMView to WebView.
Remove DOMView. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/10171006 TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/10204002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133529 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/choose_mobile_network_dialog.cc11
-rw-r--r--chrome/browser/chromeos/login/html_page_screen.cc8
-rw-r--r--chrome/browser/chromeos/login/html_page_screen.h2
-rw-r--r--chrome/browser/chromeos/login/login_html_dialog.cc8
-rw-r--r--chrome/browser/chromeos/login/registration_screen.cc9
-rw-r--r--chrome/browser/chromeos/login/registration_screen.h2
-rw-r--r--chrome/browser/chromeos/login/web_page_view.cc13
-rw-r--r--chrome/browser/chromeos/login/web_page_view.h11
-rw-r--r--chrome/browser/chromeos/sim_dialog_delegate.cc11
-rw-r--r--chrome/browser/printing/print_dialog_cloud.cc37
-rw-r--r--chrome/browser/ui/views/dom_view.cc87
-rw-r--r--chrome/browser/ui/views/dom_view.h73
-rw-r--r--chrome/browser/ui/views/dom_view_browsertest.cc101
-rw-r--r--chrome/browser/ui/views/html_dialog_view.cc79
-rw-r--r--chrome/browser/ui/views/html_dialog_view.h31
-rw-r--r--chrome/browser/ui/views/html_dialog_view_browsertest.cc13
-rw-r--r--chrome/browser/ui/views/keyboard_overlay_delegate.cc3
-rw-r--r--chrome/browser/ui/views/keyboard_overlay_dialog_view.cc3
-rw-r--r--chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc29
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--chrome/chrome_tests.gypi2
21 files changed, 402 insertions, 135 deletions
diff --git a/chrome/browser/chromeos/choose_mobile_network_dialog.cc b/chrome/browser/chromeos/choose_mobile_network_dialog.cc
index acc4cf2..eb220f1 100644
--- a/chrome/browser/chromeos/choose_mobile_network_dialog.cc
+++ b/chrome/browser/chromeos/choose_mobile_network_dialog.cc
@@ -28,11 +28,14 @@ namespace chromeos {
// static
void ChooseMobileNetworkDialog::ShowDialog(gfx::NativeWindow owning_window) {
- views::Widget::CreateWindowWithParent(
- new HtmlDialogView(ProfileManager::GetDefaultProfileOrOffTheRecord(),
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+ HtmlDialogView* html_view =
+ new HtmlDialogView(profile,
BrowserList::GetLastActive(),
- new ChooseMobileNetworkDialog),
- owning_window)->Show();
+ new ChooseMobileNetworkDialog);
+ html_view->InitDialog();
+ views::Widget::CreateWindowWithParent(html_view, owning_window);
+ html_view->GetWidget()->Show();
}
ChooseMobileNetworkDialog::ChooseMobileNetworkDialog() {
diff --git a/chrome/browser/chromeos/login/html_page_screen.cc b/chrome/browser/chromeos/login/html_page_screen.cc
index d222709..7125f39 100644
--- a/chrome/browser/chromeos/login/html_page_screen.cc
+++ b/chrome/browser/chromeos/login/html_page_screen.cc
@@ -20,8 +20,8 @@ namespace chromeos {
///////////////////////////////////////////////////////////////////////////////
// HTMLPageView
-HTMLPageView::HTMLPageView(content::BrowserContext* browser_context)
- : dom_view_(new WebPageDomView(browser_context)) {
+HTMLPageView::HTMLPageView()
+ : dom_view_(new WebPageDomView()) {
}
WebPageDomView* HTMLPageView::dom_view() {
@@ -48,13 +48,13 @@ void HTMLPageScreen::Refresh() {
StartTimeoutTimer();
GURL url(url_);
Profile* profile = ProfileManager::GetDefaultProfile();
- view()->InitWebView(SiteInstance::CreateForURL(profile, url));
+ view()->InitDOM(profile, SiteInstance::CreateForURL(profile, url));
view()->SetWebContentsDelegate(this);
view()->LoadURL(url);
}
HTMLPageView* HTMLPageScreen::AllocateView() {
- return new HTMLPageView(ProfileManager::GetDefaultProfile());
+ return new HTMLPageView();
}
void HTMLPageScreen::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
diff --git a/chrome/browser/chromeos/login/html_page_screen.h b/chrome/browser/chromeos/login/html_page_screen.h
index 81ffd82..4403ffa 100644
--- a/chrome/browser/chromeos/login/html_page_screen.h
+++ b/chrome/browser/chromeos/login/html_page_screen.h
@@ -22,7 +22,7 @@ class ViewScreenDelegate;
class HTMLPageView : public WebPageView {
public:
- explicit HTMLPageView(content::BrowserContext* browser_context);
+ HTMLPageView();
protected:
virtual WebPageDomView* dom_view() OVERRIDE;
diff --git a/chrome/browser/chromeos/login/login_html_dialog.cc b/chrome/browser/chromeos/login/login_html_dialog.cc
index 845e862..bd64f0d 100644
--- a/chrome/browser/chromeos/login/login_html_dialog.cc
+++ b/chrome/browser/chromeos/login/login_html_dialog.cc
@@ -56,9 +56,11 @@ LoginHtmlDialog::~LoginHtmlDialog() {
}
void LoginHtmlDialog::Show() {
- views::Widget::CreateWindowWithParent(
- new HtmlDialogView(ProfileManager::GetDefaultProfile(), NULL, this),
- parent_window_)->Show();
+ HtmlDialogView* html_view =
+ new HtmlDialogView(ProfileManager::GetDefaultProfile(), NULL, this);
+ views::Widget::CreateWindowWithParent(html_view, parent_window_);
+ html_view->InitDialog();
+ html_view->GetWidget()->Show();
is_open_ = true;
}
diff --git a/chrome/browser/chromeos/login/registration_screen.cc b/chrome/browser/chromeos/login/registration_screen.cc
index 3273f16..3379ff9 100644
--- a/chrome/browser/chromeos/login/registration_screen.cc
+++ b/chrome/browser/chromeos/login/registration_screen.cc
@@ -42,11 +42,6 @@ const char kRegistrationSkippedUrl[] = "cros://register/skipped";
///////////////////////////////////////////////////////////////////////////////
// RegistrationView, protected:
-RegistrationView::RegistrationView(content::BrowserContext* browser_context)
- : dom_view_(new WebPageDomView(browser_context)) {
-}
-
-
WebPageDomView* RegistrationView::dom_view() {
return dom_view_;
}
@@ -76,13 +71,13 @@ void RegistrationScreen::Refresh() {
StartTimeoutTimer();
GURL url(kRegistrationHostPageUrl);
Profile* profile = ProfileManager::GetDefaultProfile();
- view()->InitWebView(SiteInstance::CreateForURL(profile, url));
+ view()->InitDOM(profile, SiteInstance::CreateForURL(profile, url));
view()->SetWebContentsDelegate(this);
view()->LoadURL(url);
}
RegistrationView* RegistrationScreen::AllocateView() {
- return new RegistrationView(ProfileManager::GetDefaultProfile());
+ return new RegistrationView();
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/login/registration_screen.h b/chrome/browser/chromeos/login/registration_screen.h
index b126db1..88d69b6 100644
--- a/chrome/browser/chromeos/login/registration_screen.h
+++ b/chrome/browser/chromeos/login/registration_screen.h
@@ -31,7 +31,7 @@ class ViewScreenDelegate;
// Class that displays screen contents: page and throbber while waiting.
class RegistrationView : public WebPageView {
public:
- explicit RegistrationView(content::BrowserContext* browser_context);
+ RegistrationView() : dom_view_(new WebPageDomView()) {}
protected:
virtual WebPageDomView* dom_view() OVERRIDE;
diff --git a/chrome/browser/chromeos/login/web_page_view.cc b/chrome/browser/chromeos/login/web_page_view.cc
index 131cca8..0ad30e7 100644
--- a/chrome/browser/chromeos/login/web_page_view.cc
+++ b/chrome/browser/chromeos/login/web_page_view.cc
@@ -51,13 +51,9 @@ const int kStopDelayMs = 500;
///////////////////////////////////////////////////////////////////////////////
// WebPageDomView, public:
-WebPageDomView::WebPageDomView(content::BrowserContext* browser_context)
- : views::WebView(browser_context) {
-}
-
void WebPageDomView::SetWebContentsDelegate(
content::WebContentsDelegate* delegate) {
- web_contents()->SetDelegate(delegate);
+ dom_contents_->web_contents()->SetDelegate(delegate);
}
///////////////////////////////////////////////////////////////////////////////
@@ -93,12 +89,13 @@ void WebPageView::Init() {
&WebPageView::ShowWaitingControls);
}
-void WebPageView::InitWebView(SiteInstance* site_instance) {
- dom_view()->CreateWebContentsWithSiteInstance(site_instance);
+void WebPageView::InitDOM(Profile* profile,
+ SiteInstance* site_instance) {
+ dom_view()->Init(profile, site_instance);
}
void WebPageView::LoadURL(const GURL& url) {
- dom_view()->LoadInitialURL(url);
+ dom_view()->LoadURL(url);
}
void WebPageView::SetWebContentsDelegate(
diff --git a/chrome/browser/chromeos/login/web_page_view.h b/chrome/browser/chromeos/login/web_page_view.h
index ebc6bf6..90b036c 100644
--- a/chrome/browser/chromeos/login/web_page_view.h
+++ b/chrome/browser/chromeos/login/web_page_view.h
@@ -10,13 +10,12 @@
#include "base/compiler_specific.h"
#include "base/timer.h"
-#include "ui/views/controls/webview/webview.h"
+#include "chrome/browser/ui/views/dom_view.h"
#include "ui/views/view.h"
class Profile;
namespace content {
-class BrowserContext;
class SiteInstance;
class WebContentsDelegate;
}
@@ -29,9 +28,9 @@ class Throbber;
namespace chromeos {
// WebPageDomView is the view that is rendering the page.
-class WebPageDomView : public views::WebView {
+class WebPageDomView : public DOMView {
public:
- explicit WebPageDomView(content::BrowserContext* browser_context);
+ WebPageDomView() {}
// Set delegate that will be notified about tab contents changes.
void SetWebContentsDelegate(content::WebContentsDelegate* delegate);
@@ -50,9 +49,9 @@ class WebPageView : public views::View {
// Initialize view layout.
void Init();
- // Initialize the WebView, creating the contents. This should be
+ // Initialize the DOM view, creating the contents. This should be
// called once the view has been added to a container.
- void InitWebView(content::SiteInstance* site_instance);
+ void InitDOM(Profile* profile, content::SiteInstance* site_instance);
// Loads the given URL into the page.
// You must have previously called Init() and SetWebContentsDelegate.
diff --git a/chrome/browser/chromeos/sim_dialog_delegate.cc b/chrome/browser/chromeos/sim_dialog_delegate.cc
index 6c607fa..6c2c15c 100644
--- a/chrome/browser/chromeos/sim_dialog_delegate.cc
+++ b/chrome/browser/chromeos/sim_dialog_delegate.cc
@@ -47,11 +47,14 @@ namespace chromeos {
// static
void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window,
SimDialogMode mode) {
- views::Widget::CreateWindowWithParent(
- new HtmlDialogView(ProfileManager::GetDefaultProfileOrOffTheRecord(),
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+ HtmlDialogView* html_view =
+ new HtmlDialogView(profile,
BrowserList::GetLastActive(),
- new SimDialogDelegate(mode)),
- owning_window)->Show();
+ new SimDialogDelegate(mode));
+ html_view->InitDialog();
+ views::Widget::CreateWindowWithParent(html_view, owning_window);
+ html_view->GetWidget()->Show();
}
SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode)
diff --git a/chrome/browser/printing/print_dialog_cloud.cc b/chrome/browser/printing/print_dialog_cloud.cc
index f23bdf0..50c466d 100644
--- a/chrome/browser/printing/print_dialog_cloud.cc
+++ b/chrome/browser/printing/print_dialog_cloud.cc
@@ -21,7 +21,6 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/dialog_style.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_switches.h"
@@ -689,17 +688,27 @@ void CreateDialogImpl(const FilePath& path_to_file,
path_to_file, width, height, std::string(), job_title, print_ticket,
file_type, modal, delete_on_close, close_after_signin,
callback);
+ if (modal) {
+ DCHECK(browser);
+#if defined(USE_AURA)
+ HtmlDialogView* html_view =
+ new HtmlDialogView(profile, browser, dialog_delegate);
+ views::Widget::CreateWindowWithParent(html_view,
+ browser->window()->GetNativeHandle());
+ html_view->InitDialog();
+ views::Widget* widget = html_view->GetWidget();
+ DCHECK(widget);
+ widget->Show();
#if defined(OS_WIN)
- gfx::NativeWindow window =
+ gfx::NativeWindow window = widget->GetNativeWindow();
+#endif
+#else
+#if defined(OS_WIN)
+ gfx::NativeWindow window =
+#endif
+ browser->BrowserShowHtmlDialog(dialog_delegate, NULL, STYLE_GENERIC);
#endif
- browser::ShowHtmlDialog(
- modal ? browser->window()->GetNativeHandle() : NULL,
- profile,
- browser,
- dialog_delegate,
- STYLE_GENERIC);
-
#if defined(OS_WIN)
HWND dialog_handle;
#if defined(USE_AURA)
@@ -707,9 +716,17 @@ void CreateDialogImpl(const FilePath& path_to_file,
#else
dialog_handle = window;
#endif
- if (::GetForegroundWindow() != dialog_handle)
+ if (::GetForegroundWindow() != dialog_handle) {
ui::ForegroundHelper::SetForeground(dialog_handle);
+ }
#endif
+ } else {
+ browser::ShowHtmlDialog(NULL,
+ profile,
+ browser,
+ dialog_delegate,
+ STYLE_GENERIC);
+ }
}
void CreateDialogSigninImpl(const base::Closure& callback) {
diff --git a/chrome/browser/ui/views/dom_view.cc b/chrome/browser/ui/views/dom_view.cc
new file mode 100644
index 0000000..fde0636
--- /dev/null
+++ b/chrome/browser/ui/views/dom_view.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2011 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/ui/views/dom_view.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/renderer_preferences_util.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/views/focus/focus_manager.h"
+
+using content::SiteInstance;
+using content::WebContents;
+
+// static
+const char DOMView::kViewClassName[] =
+ "browser/ui/views/DOMView";
+
+DOMView::DOMView() : initialized_(false) {
+ set_focusable(true);
+}
+
+DOMView::~DOMView() {
+ if (native_view())
+ Detach();
+}
+
+std::string DOMView::GetClassName() const {
+ return kViewClassName;
+}
+
+bool DOMView::Init(Profile* profile, SiteInstance* instance) {
+ if (initialized_)
+ return true;
+
+ initialized_ = true;
+ WebContents* web_contents = CreateTabContents(profile, instance);
+ dom_contents_.reset(new TabContentsWrapper(web_contents));
+
+ renderer_preferences_util::UpdateFromSystemSettings(
+ web_contents->GetMutableRendererPrefs(), profile);
+
+ // Attach the native_view now if the view is already added to Widget.
+ if (GetWidget())
+ AttachTabContents();
+
+ return true;
+}
+
+WebContents* DOMView::CreateTabContents(Profile* profile,
+ SiteInstance* instance) {
+ return WebContents::Create(profile, instance, MSG_ROUTING_NONE, NULL, NULL);
+}
+
+void DOMView::LoadURL(const GURL& url) {
+ DCHECK(initialized_);
+ dom_contents_->web_contents()->GetController().LoadURL(
+ url, content::Referrer(), content::PAGE_TRANSITION_START_PAGE,
+ std::string());
+}
+
+bool DOMView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
+ // Don't move the focus to the next view when tab is pressed, we want the
+ // key event to be propagated to the render view for doing the tab traversal
+ // there.
+ return views::FocusManager::IsTabTraversalKeyEvent(e);
+}
+
+void DOMView::OnFocus() {
+ dom_contents_->web_contents()->Focus();
+}
+
+void DOMView::ViewHierarchyChanged(bool is_add, views::View* parent,
+ views::View* child) {
+ // Attach the native_view when this is added to Widget if
+ // the native view has not been attached yet and tab_contents_ exists.
+ views::NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
+ if (is_add && GetWidget() && !native_view() && dom_contents_.get())
+ AttachTabContents();
+ else if (!is_add && child == this && native_view())
+ Detach();
+}
+
+void DOMView::AttachTabContents() {
+ Attach(dom_contents_->web_contents()->GetNativeView());
+}
diff --git a/chrome/browser/ui/views/dom_view.h b/chrome/browser/ui/views/dom_view.h
new file mode 100644
index 0000000..15f45ad
--- /dev/null
+++ b/chrome/browser/ui/views/dom_view.h
@@ -0,0 +1,73 @@
+// Copyright (c) 2011 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.
+
+// DOMView is a ChromeView that displays the content of a web DOM.
+// It should be used with data: URLs.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_DOM_VIEW_H_
+#define CHROME_BROWSER_UI_VIEWS_DOM_VIEW_H_
+#pragma once
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "googleurl/src/gurl.h"
+#include "ui/views/controls/native/native_view_host.h"
+#include "ui/views/events/event.h"
+
+class Profile;
+
+namespace content {
+class SiteInstance;
+};
+
+class DOMView : public views::NativeViewHost {
+ public:
+ // Internal class name.
+ static const char kViewClassName[];
+
+ DOMView();
+ virtual ~DOMView();
+
+ // Overridden from View.
+ virtual std::string GetClassName() const OVERRIDE;
+
+ // 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, content::SiteInstance* instance);
+
+ // Loads the given URL into the page. You must have previously called Init().
+ void LoadURL(const GURL& url);
+
+ // The TabContentsWrapper displaying the DOM contents; may be null.
+ TabContentsWrapper* dom_contents() const { return dom_contents_.get(); }
+
+ protected:
+ // Overridden from View.
+ virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) OVERRIDE;
+ virtual void OnFocus() OVERRIDE;
+ virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
+ views::View* child) OVERRIDE;
+
+ // AttachTabContents calls Attach to hook up the NativeViewHost. This is
+ // here because depending on whether this is a touch build or not the
+ // implementation varies slightly, while Detach is the same in both cases.
+ void AttachTabContents();
+
+ // Returns new allocated WebContents instance, caller is responsible deleting.
+ // Override in derived classes to replace WebContents with derivative.
+ virtual content::WebContents* CreateTabContents(
+ Profile* profile, content::SiteInstance* instance);
+
+ scoped_ptr<TabContentsWrapper> dom_contents_;
+
+ private:
+ bool initialized_;
+
+ DISALLOW_COPY_AND_ASSIGN(DOMView);
+};
+
+#endif // CHROME_BROWSER_UI_VIEWS_DOM_VIEW_H_
diff --git a/chrome/browser/ui/views/dom_view_browsertest.cc b/chrome/browser/ui/views/dom_view_browsertest.cc
new file mode 100644
index 0000000..7f3c791
--- /dev/null
+++ b/chrome/browser/ui/views/dom_view_browsertest.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 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/ui/browser.h"
+#include "chrome/browser/ui/views/dom_view.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+#include "ui/views/widget/widget.h"
+
+using views::Widget;
+
+class DOMViewTest : public InProcessBrowserTest {
+ public:
+ Widget* CreatePopupWindow() {
+ Widget* widget = new Widget;
+ Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
+ params.bounds = gfx::Rect(0, 0, 400, 400);
+ widget->Init(params);
+ return widget;
+ }
+};
+
+// Tests if creating and deleting dom_view
+// does not crash and leak memory.
+IN_PROC_BROWSER_TEST_F(DOMViewTest, TestShowAndHide) {
+ Widget* one = CreatePopupWindow();
+
+ DOMView* dom_view = new DOMView();
+ one->GetRootView()->AddChildView(dom_view);
+
+ dom_view->Init(browser()->profile(), NULL);
+ ui_test_utils::WindowedNotificationObserver load_stop_observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::NotificationService::AllSources());
+ dom_view->LoadURL(GURL("http://www.google.com"));
+ load_stop_observer.Wait();
+ one->Show();
+
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ one->Hide();
+}
+
+// Tests if removing from tree then deleting dom_view
+// does not crash and leak memory.
+IN_PROC_BROWSER_TEST_F(DOMViewTest, TestRemoveAndDelete) {
+ Widget* one = CreatePopupWindow();
+
+ DOMView* dom_view = new DOMView();
+ one->GetRootView()->AddChildView(dom_view);
+
+ dom_view->Init(browser()->profile(), NULL);
+ ui_test_utils::WindowedNotificationObserver load_stop_observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::NotificationService::AllSources());
+ dom_view->LoadURL(GURL("http://www.google.com"));
+ load_stop_observer.Wait();
+ one->Show();
+
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ one->GetRootView()->RemoveChildView(dom_view);
+
+ delete dom_view;
+
+ one->Hide();
+}
+
+// Tests if reparenting dom_view does not crash and does not leak
+// memory.
+IN_PROC_BROWSER_TEST_F(DOMViewTest, TestReparent) {
+ Widget* one = CreatePopupWindow();
+
+ DOMView* dom_view = new DOMView();
+ one->GetRootView()->AddChildView(dom_view);
+
+ dom_view->Init(browser()->profile(), NULL);
+ ui_test_utils::WindowedNotificationObserver load_stop_observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::NotificationService::AllSources());
+ dom_view->LoadURL(GURL("http://www.google.com"));
+ load_stop_observer.Wait();
+ one->Show();
+
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ one->GetRootView()->RemoveChildView(dom_view);
+ one->Hide();
+
+ // Re-attach to another Widget.
+ Widget* two = CreatePopupWindow();
+ two->GetRootView()->AddChildView(dom_view);
+ two->Show();
+
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ two->Hide();
+}
diff --git a/chrome/browser/ui/views/html_dialog_view.cc b/chrome/browser/ui/views/html_dialog_view.cc
index 3025b80..102fec7 100644
--- a/chrome/browser/ui/views/html_dialog_view.cc
+++ b/chrome/browser/ui/views/html_dialog_view.cc
@@ -6,7 +6,6 @@
#include <vector>
-#include "base/property_bag.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_dialogs.h"
@@ -17,9 +16,7 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/keycodes/keyboard_codes.h"
-#include "ui/views/controls/webview/webview.h"
#include "ui/views/events/event.h"
-#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
@@ -39,11 +36,11 @@ gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent,
Browser* browser,
HtmlDialogUIDelegate* delegate,
DialogStyle style) {
- views::Widget* widget = views::Widget::CreateWindowWithParent(
- new HtmlDialogView(profile, browser, delegate),
- parent);
- widget->Show();
- return widget->GetNativeWindow();
+ HtmlDialogView* html_view = new HtmlDialogView(profile, browser, delegate);
+ views::Widget::CreateWindowWithParent(html_view, parent);
+ html_view->InitDialog();
+ html_view->GetWidget()->Show();
+ return html_view->GetWidget()->GetNativeWindow();
}
void CloseHtmlDialog(gfx::NativeWindow window) {
@@ -58,24 +55,16 @@ void CloseHtmlDialog(gfx::NativeWindow window) {
HtmlDialogView::HtmlDialogView(Profile* profile,
Browser* browser,
HtmlDialogUIDelegate* delegate)
- : HtmlDialogTabContentsDelegate(profile),
+ : DOMView(),
+ HtmlDialogTabContentsDelegate(profile),
initialized_(false),
delegate_(delegate),
- dialog_controller_(new HtmlDialogController(this, profile, browser)),
- web_view_(new views::WebView(profile)) {
- AddChildView(web_view_);
- SetLayoutManager(new views::FillLayout);
- // Pressing the ESC key will close the dialog.
- AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false));
+ dialog_controller_(new HtmlDialogController(this, profile, browser)) {
}
HtmlDialogView::~HtmlDialogView() {
}
-content::WebContents* HtmlDialogView::web_contents() {
- return web_view_->web_contents();
-}
-
////////////////////////////////////////////////////////////////////////////////
// HtmlDialogView, views::View implementation:
@@ -93,11 +82,13 @@ bool HtmlDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) {
return true;
}
-void HtmlDialogView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (is_add && GetWidget())
- InitDialog();
+void HtmlDialogView::ViewHierarchyChanged(
+ bool is_add, View* parent, View* child) {
+ DOMView::ViewHierarchyChanged(is_add, parent, child);
+ if (is_add && GetWidget() && !initialized_) {
+ initialized_ = true;
+ RegisterDialogAccelerators();
+ }
}
////////////////////////////////////////////////////////////////////////////////
@@ -136,7 +127,7 @@ views::View* HtmlDialogView::GetContentsView() {
}
views::View* HtmlDialogView::GetInitiallyFocusedView() {
- return web_view_;
+ return this;
}
bool HtmlDialogView::ShouldShowWindowTitle() const {
@@ -290,26 +281,13 @@ void HtmlDialogView::LoadingStateChanged(content::WebContents* source) {
}
////////////////////////////////////////////////////////////////////////////////
-// HtmlDialogView, TabRenderWatcher::Delegate implementation:
-
-void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) {
-}
-
-void HtmlDialogView::OnTabMainFrameLoaded() {
-}
-
-void HtmlDialogView::OnTabMainFrameRender() {
- tab_watcher_.reset();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// HtmlDialogView, private:
+// HtmlDialogView:
void HtmlDialogView::InitDialog() {
- content::WebContents* web_contents = web_view_->GetWebContents();
- if (web_contents->GetDelegate() == this)
- return;
+ // Now Init the DOMView. This view runs in its own process to render the html.
+ DOMView::Init(profile(), NULL);
+ WebContents* web_contents = dom_contents_->web_contents();
web_contents->SetDelegate(this);
// Set the delegate. This must be done before loading the page. See
@@ -325,5 +303,20 @@ void HtmlDialogView::InitDialog() {
GetWidget()->CenterWindow(out);
}
- web_view_->LoadInitialURL(GetDialogContentURL());
+ DOMView::LoadURL(GetDialogContentURL());
+}
+
+void HtmlDialogView::RegisterDialogAccelerators() {
+ // Pressing the ESC key will close the dialog.
+ AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false));
+}
+
+void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) {
+}
+
+void HtmlDialogView::OnTabMainFrameLoaded() {
+}
+
+void HtmlDialogView::OnTabMainFrameRender() {
+ tab_watcher_.reset();
}
diff --git a/chrome/browser/ui/views/html_dialog_view.h b/chrome/browser/ui/views/html_dialog_view.h
index 44645b4..1523b36 100644
--- a/chrome/browser/ui/views/html_dialog_view.h
+++ b/chrome/browser/ui/views/html_dialog_view.h
@@ -12,20 +12,16 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/tab_render_watcher.h"
+#include "chrome/browser/ui/views/dom_view.h"
#include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h"
#include "chrome/browser/ui/webui/html_dialog_ui.h"
#include "ui/gfx/size.h"
-#include "ui/views/view.h"
#include "ui/views/widget/widget_delegate.h"
class Browser;
class HtmlDialogController;
class Profile;
-namespace views {
-class WebView;
-}
-
////////////////////////////////////////////////////////////////////////////////
//
// HtmlDialogView is a view used to display an HTML dialog to the user. The
@@ -39,10 +35,8 @@ class WebView;
// TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate
// instead of inheriting from it to avoid violating the "no multiple
// inheritance" rule.
-// TODO(beng): This class should not depend on Browser or Profile, only
-// content::BrowserContext.
class HtmlDialogView
- : public views::View,
+ : public DOMView,
public HtmlDialogTabContentsDelegate,
public HtmlDialogUIDelegate,
public views::WidgetDelegate,
@@ -53,16 +47,15 @@ class HtmlDialogView
HtmlDialogUIDelegate* delegate);
virtual ~HtmlDialogView();
- // For testing.
- content::WebContents* web_contents();
+ // Initializes the contents of the dialog (the DOMView and the callbacks).
+ void InitDialog();
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator)
OVERRIDE;
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) OVERRIDE;
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child)
+ OVERRIDE;
// Overridden from views::WidgetDelegate:
virtual bool CanResize() const OVERRIDE;
@@ -109,7 +102,10 @@ class HtmlDialogView
virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
protected:
- // Overridden from TabRenderWatcher::Delegate:
+ // Register accelerators for this dialog.
+ virtual void RegisterDialogAccelerators();
+
+ // TabRenderWatcher::Delegate implementation.
virtual void OnRenderHostCreated(content::RenderViewHost* host) OVERRIDE;
virtual void OnTabMainFrameLoaded() OVERRIDE;
virtual void OnTabMainFrameRender() OVERRIDE;
@@ -117,10 +113,7 @@ class HtmlDialogView
private:
FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered);
- // Initializes the contents of the dialog.
- void InitDialog();
-
- // Whether the view is initialized. That is, dialog accelerators is registered
+ // Whether the view is initialized. That is, dialog acceleartors is registered
// and FreezeUpdates property is set to prevent WM from showing the window
// until the property is removed.
bool initialized_;
@@ -137,8 +130,6 @@ class HtmlDialogView
// Controls lifetime of dialog.
scoped_ptr<HtmlDialogController> dialog_controller_;
- views::WebView* web_view_;
-
DISALLOW_COPY_AND_ASSIGN(HtmlDialogView);
};
diff --git a/chrome/browser/ui/views/html_dialog_view_browsertest.cc b/chrome/browser/ui/views/html_dialog_view_browsertest.cc
index 307d900..8e52edc 100644
--- a/chrome/browser/ui/views/html_dialog_view_browsertest.cc
+++ b/chrome/browser/ui/views/html_dialog_view_browsertest.cc
@@ -114,6 +114,7 @@ IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
ASSERT_TRUE(web_contents != NULL);
views::Widget::CreateWindowWithParent(
html_view, web_contents->GetView()->GetTopLevelNativeWindow());
+ html_view->InitDialog();
html_view->GetWidget()->Show();
// TestHtmlDialogView should quit current message loop on size change.
@@ -133,8 +134,8 @@ IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
EXPECT_EQ(set_bounds, actual_bounds);
- rwhv_bounds =
- html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds();
+ rwhv_bounds = html_view->dom_contents()->web_contents()->
+ GetRenderWidgetHostView()->GetViewBounds();
EXPECT_LT(0, rwhv_bounds.width());
EXPECT_LT(0, rwhv_bounds.height());
EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
@@ -149,8 +150,8 @@ IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
EXPECT_EQ(set_bounds, actual_bounds);
- rwhv_bounds =
- html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds();
+ rwhv_bounds = html_view->dom_contents()->web_contents()->
+ GetRenderWidgetHostView()->GetViewBounds();
EXPECT_LT(0, rwhv_bounds.width());
EXPECT_LT(0, rwhv_bounds.height());
EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
@@ -165,8 +166,8 @@ IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
EXPECT_EQ(set_bounds, actual_bounds);
- rwhv_bounds =
- html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds();
+ rwhv_bounds = html_view->dom_contents()->web_contents()->
+ GetRenderWidgetHostView()->GetViewBounds();
EXPECT_LT(0, rwhv_bounds.width());
EXPECT_LT(0, rwhv_bounds.height());
EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
diff --git a/chrome/browser/ui/views/keyboard_overlay_delegate.cc b/chrome/browser/ui/views/keyboard_overlay_delegate.cc
index e40749e..8e8bbae 100644
--- a/chrome/browser/ui/views/keyboard_overlay_delegate.cc
+++ b/chrome/browser/ui/views/keyboard_overlay_delegate.cc
@@ -15,7 +15,6 @@
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/screen.h"
-#include "ui/views/widget/widget.h"
using content::WebContents;
using content::WebUIMessageHandler;
@@ -58,7 +57,7 @@ void KeyboardOverlayDelegate::GetDialogSize(
using std::min;
DCHECK(view_);
gfx::Rect rect = gfx::Screen::GetMonitorAreaNearestWindow(
- view_->GetWidget()->GetNativeView());
+ view_->native_view());
const int width = min(kBaseWidth, rect.width() - kHorizontalMargin);
const int height = width * kBaseHeight / kBaseWidth;
size->SetSize(width, height);
diff --git a/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc b/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc
index 6d78a9f..d9aea68 100644
--- a/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc
+++ b/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc
@@ -92,12 +92,13 @@ void KeyboardOverlayDialogView::ShowDialog(
delegate,
parent_view);
delegate->set_view(html_view);
+ html_view->InitDialog();
browser::CreateFramelessViewsWindow(owning_window, html_view);
// Show the widget at the bottom of the work area.
gfx::Size size;
delegate->GetDialogSize(&size);
gfx::Rect rect = gfx::Screen::GetMonitorWorkAreaNearestWindow(
- html_view->GetWidget()->GetNativeView());
+ html_view->native_view());
gfx::Rect bounds((rect.width() - size.width()) / 2,
rect.height() - size.height(),
size.width(),
diff --git a/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc b/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc
index 4d125be..762ec9b 100644
--- a/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc
+++ b/chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc
@@ -154,7 +154,7 @@ class KeyboardWidget
GURL keyboard_url_;
// The WebView to host the keyboard.
- views::WebView* web_view_;
+ views::WebView* webview_;
ExtensionFunctionDispatcher extension_dispatcher_;
@@ -172,7 +172,7 @@ class KeyboardWidget
KeyboardWidget::KeyboardWidget()
: views::Widget::Widget(),
keyboard_url_(chrome::kChromeUIKeyboardURL),
- web_view_(new views::WebView(ProfileManager::GetDefaultProfile()))),
+ webview_(new DOMView(ProfileManager::GetDefaultProfile()))),
ALLOW_THIS_IN_INITIALIZER_LIST(
extension_dispatcher_(ProfileManager::GetDefaultProfile(), this)),
target_(NULL),
@@ -190,14 +190,14 @@ KeyboardWidget::KeyboardWidget()
Init(params);
// Setup the DOM view to host the keyboard.
- web_view_->CreateWebContentsWithSiteInstance(
- content::SiteInstance::CreateForURL(web_view_->browser_context(),
+ webview_->CreateWebContentsWithSiteInstance(
+ content::SiteInstance::CreateForURL(webview_->browser_context(),
keyboard_url_));
- web_view_->LoadInitialURL(keyboard_url_);
- SetContentsView(web_view_);
+ webview_->LoadInitialURL(keyboard_url_);
+ SetContentsView(webview_);
// Setup observer so the events from the keyboard can be handled.
- content::WebContentsObserver::Observe(web_view_->web_contents());
+ content::WebContentsObserver::Observe(webview_->web_contents());
// Initialize the animation.
animation_.reset(new ui::SlideAnimation(this));
@@ -342,15 +342,14 @@ bool KeyboardWidget::OnMessageReceived(const IPC::Message& message) {
void KeyboardWidget::RenderViewGone(base::TerminationStatus status) {
if (status != base::TERMINATION_STATUS_NORMAL_TERMINATION) {
// Reload the keyboard if it crashes.
- web_view_->LoadInitialURL(keyboard_url_);
- web_view_->SchedulePaint();
+ webview_->LoadInitialURL(keyboard_url_);
+ webview_->SchedulePaint();
}
}
void KeyboardWidget::OnRequest(const ExtensionHostMsg_Request_Params& request) {
- extension_dispatcher_.Dispatch(
- request,
- web_view_->web_contents()->GetRenderViewHost());
+ extension_dispatcher_.Dispatch(request,
+ webview_->web_contents()->GetRenderViewHost());
}
void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type,
@@ -400,7 +399,7 @@ void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type,
std::string json_args;
base::JSONWriter::Write(&args, &json_args);
- Profile* profile = Profile::FromBrowserContext(web_view_->browser_context());
+ Profile* profile = Profile::FromBrowserContext(webview_->browser_context());
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
kOnTextInputTypeChanged, json_args, NULL, GURL());
@@ -418,7 +417,7 @@ Browser* KeyboardWidget::GetBrowser() {
}
content::WebContents* KeyboardWidget::GetAssociatedWebContents() const {
- return web_view_->web_contents();
+ return webview_->web_contents();
}
#if defined(OS_CHROMEOS)
@@ -427,7 +426,7 @@ void KeyboardWidget::VirtualKeyboardChanged(
const chromeos::input_method::VirtualKeyboard& virtual_keyboard,
const std::string& virtual_keyboard_layout) {
const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout);
- web_view_->LoadInitialURL(url);
+ webview_->LoadInitialURL(url);
VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec();
}
#endif
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ae445eb..5899631 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3284,6 +3284,8 @@
'browser/ui/views/critical_notification_bubble_view.h',
'browser/ui/views/detachable_toolbar_view.cc',
'browser/ui/views/detachable_toolbar_view.h',
+ 'browser/ui/views/dom_view.cc',
+ 'browser/ui/views/dom_view.h',
'browser/ui/views/download/download_in_progress_dialog_view.cc',
'browser/ui/views/download/download_in_progress_dialog_view.h',
'browser/ui/views/download/download_item_view.cc',
@@ -4810,6 +4812,8 @@
['include', '^browser/ui/views/crypto_module_password_dialog_view.h'],
['include', '^browser/ui/views/detachable_toolbar_view.cc'],
['include', '^browser/ui/views/detachable_toolbar_view.h'],
+ ['include', '^browser/ui/views/dom_view.cc'],
+ ['include', '^browser/ui/views/dom_view.h'],
['include', '^browser/ui/views/download/download_in_progress_dialog_view.cc'],
['include', '^browser/ui/views/download/download_in_progress_dialog_view.h'],
['include', '^browser/ui/views/download/download_item_view.cc'],
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 241b132..94a67c4 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2937,6 +2937,7 @@
'browser/ui/views/ash/caps_lock_handler_browsertest.cc',
'browser/ui/views/ash/launcher/launcher_favicon_loader_browsertest.cc',
'browser/ui/views/browser_actions_container_browsertest.cc',
+ 'browser/ui/views/dom_view_browsertest.cc',
'browser/ui/views/html_dialog_view_browsertest.cc',
'browser/ui/views/select_file_dialog_extension_browsertest.cc',
'browser/ui/views/sync/one_click_signin_bubble_view_browsertest.cc',
@@ -3356,6 +3357,7 @@
'browser/ui/panels/panel_browser_view_browsertest.cc',
'browser/ui/views/browser_actions_container_browsertest.cc',
'browser/ui/views/crypto_module_password_dialog_view_unittest.cc',
+ 'browser/ui/views/dom_view_browsertest.cc',
'browser/ui/views/html_dialog_view_browsertest.cc',
'browser/ui/views/sync/one_click_signin_bubble_view_browsertest.cc',
],