diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-23 17:26:48 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-23 17:26:48 +0000 |
commit | a75af9f69962505ca6a4d25e30b2120dc3dfd035 (patch) | |
tree | a72ef818b29c4e58a7b1f207b3b661413f972db6 | |
parent | 01738718a8edcdb3f60f8138e4fcad7f8c5c2afd (diff) | |
download | chromium_src-a75af9f69962505ca6a4d25e30b2120dc3dfd035.zip chromium_src-a75af9f69962505ca6a4d25e30b2120dc3dfd035.tar.gz chromium_src-a75af9f69962505ca6a4d25e30b2120dc3dfd035.tar.bz2 |
Convert the last users of DOMView to WebView.
Remove DOMView.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10171006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133467 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 135 insertions, 402 deletions
diff --git a/chrome/browser/chromeos/choose_mobile_network_dialog.cc b/chrome/browser/chromeos/choose_mobile_network_dialog.cc index eb220f1..acc4cf2 100644 --- a/chrome/browser/chromeos/choose_mobile_network_dialog.cc +++ b/chrome/browser/chromeos/choose_mobile_network_dialog.cc @@ -28,14 +28,11 @@ namespace chromeos { // static void ChooseMobileNetworkDialog::ShowDialog(gfx::NativeWindow owning_window) { - Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); - HtmlDialogView* html_view = - new HtmlDialogView(profile, + views::Widget::CreateWindowWithParent( + new HtmlDialogView(ProfileManager::GetDefaultProfileOrOffTheRecord(), BrowserList::GetLastActive(), - new ChooseMobileNetworkDialog); - html_view->InitDialog(); - views::Widget::CreateWindowWithParent(html_view, owning_window); - html_view->GetWidget()->Show(); + new ChooseMobileNetworkDialog), + owning_window)->Show(); } ChooseMobileNetworkDialog::ChooseMobileNetworkDialog() { diff --git a/chrome/browser/chromeos/login/html_page_screen.cc b/chrome/browser/chromeos/login/html_page_screen.cc index 7125f39..d222709 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() - : dom_view_(new WebPageDomView()) { +HTMLPageView::HTMLPageView(content::BrowserContext* browser_context) + : dom_view_(new WebPageDomView(browser_context)) { } WebPageDomView* HTMLPageView::dom_view() { @@ -48,13 +48,13 @@ void HTMLPageScreen::Refresh() { StartTimeoutTimer(); GURL url(url_); Profile* profile = ProfileManager::GetDefaultProfile(); - view()->InitDOM(profile, SiteInstance::CreateForURL(profile, url)); + view()->InitWebView(SiteInstance::CreateForURL(profile, url)); view()->SetWebContentsDelegate(this); view()->LoadURL(url); } HTMLPageView* HTMLPageScreen::AllocateView() { - return new HTMLPageView(); + return new HTMLPageView(ProfileManager::GetDefaultProfile()); } 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 4403ffa..81ffd82 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: - HTMLPageView(); + explicit HTMLPageView(content::BrowserContext* browser_context); 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 bd64f0d..845e862 100644 --- a/chrome/browser/chromeos/login/login_html_dialog.cc +++ b/chrome/browser/chromeos/login/login_html_dialog.cc @@ -56,11 +56,9 @@ LoginHtmlDialog::~LoginHtmlDialog() { } void LoginHtmlDialog::Show() { - HtmlDialogView* html_view = - new HtmlDialogView(ProfileManager::GetDefaultProfile(), NULL, this); - views::Widget::CreateWindowWithParent(html_view, parent_window_); - html_view->InitDialog(); - html_view->GetWidget()->Show(); + views::Widget::CreateWindowWithParent( + new HtmlDialogView(ProfileManager::GetDefaultProfile(), NULL, this), + parent_window_)->Show(); is_open_ = true; } diff --git a/chrome/browser/chromeos/login/registration_screen.cc b/chrome/browser/chromeos/login/registration_screen.cc index 3379ff9..3273f16 100644 --- a/chrome/browser/chromeos/login/registration_screen.cc +++ b/chrome/browser/chromeos/login/registration_screen.cc @@ -42,6 +42,11 @@ 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_; } @@ -71,13 +76,13 @@ void RegistrationScreen::Refresh() { StartTimeoutTimer(); GURL url(kRegistrationHostPageUrl); Profile* profile = ProfileManager::GetDefaultProfile(); - view()->InitDOM(profile, SiteInstance::CreateForURL(profile, url)); + view()->InitWebView(SiteInstance::CreateForURL(profile, url)); view()->SetWebContentsDelegate(this); view()->LoadURL(url); } RegistrationView* RegistrationScreen::AllocateView() { - return new RegistrationView(); + return new RegistrationView(ProfileManager::GetDefaultProfile()); } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/login/registration_screen.h b/chrome/browser/chromeos/login/registration_screen.h index 88d69b6..b126db1 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: - RegistrationView() : dom_view_(new WebPageDomView()) {} + explicit RegistrationView(content::BrowserContext* browser_context); 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 0ad30e7..131cca8 100644 --- a/chrome/browser/chromeos/login/web_page_view.cc +++ b/chrome/browser/chromeos/login/web_page_view.cc @@ -51,9 +51,13 @@ const int kStopDelayMs = 500; /////////////////////////////////////////////////////////////////////////////// // WebPageDomView, public: +WebPageDomView::WebPageDomView(content::BrowserContext* browser_context) + : views::WebView(browser_context) { +} + void WebPageDomView::SetWebContentsDelegate( content::WebContentsDelegate* delegate) { - dom_contents_->web_contents()->SetDelegate(delegate); + web_contents()->SetDelegate(delegate); } /////////////////////////////////////////////////////////////////////////////// @@ -89,13 +93,12 @@ void WebPageView::Init() { &WebPageView::ShowWaitingControls); } -void WebPageView::InitDOM(Profile* profile, - SiteInstance* site_instance) { - dom_view()->Init(profile, site_instance); +void WebPageView::InitWebView(SiteInstance* site_instance) { + dom_view()->CreateWebContentsWithSiteInstance(site_instance); } void WebPageView::LoadURL(const GURL& url) { - dom_view()->LoadURL(url); + dom_view()->LoadInitialURL(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 90b036c..ebc6bf6 100644 --- a/chrome/browser/chromeos/login/web_page_view.h +++ b/chrome/browser/chromeos/login/web_page_view.h @@ -10,12 +10,13 @@ #include "base/compiler_specific.h" #include "base/timer.h" -#include "chrome/browser/ui/views/dom_view.h" +#include "ui/views/controls/webview/webview.h" #include "ui/views/view.h" class Profile; namespace content { +class BrowserContext; class SiteInstance; class WebContentsDelegate; } @@ -28,9 +29,9 @@ class Throbber; namespace chromeos { // WebPageDomView is the view that is rendering the page. -class WebPageDomView : public DOMView { +class WebPageDomView : public views::WebView { public: - WebPageDomView() {} + explicit WebPageDomView(content::BrowserContext* browser_context); // Set delegate that will be notified about tab contents changes. void SetWebContentsDelegate(content::WebContentsDelegate* delegate); @@ -49,9 +50,9 @@ class WebPageView : public views::View { // Initialize view layout. void Init(); - // Initialize the DOM view, creating the contents. This should be + // Initialize the WebView, creating the contents. This should be // called once the view has been added to a container. - void InitDOM(Profile* profile, content::SiteInstance* site_instance); + void InitWebView(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 6c2c15c..6c607fa 100644 --- a/chrome/browser/chromeos/sim_dialog_delegate.cc +++ b/chrome/browser/chromeos/sim_dialog_delegate.cc @@ -47,14 +47,11 @@ namespace chromeos { // static void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window, SimDialogMode mode) { - Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); - HtmlDialogView* html_view = - new HtmlDialogView(profile, + views::Widget::CreateWindowWithParent( + new HtmlDialogView(ProfileManager::GetDefaultProfileOrOffTheRecord(), BrowserList::GetLastActive(), - new SimDialogDelegate(mode)); - html_view->InitDialog(); - views::Widget::CreateWindowWithParent(html_view, owning_window); - html_view->GetWidget()->Show(); + new SimDialogDelegate(mode)), + owning_window)->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 50c466d..f23bdf0 100644 --- a/chrome/browser/printing/print_dialog_cloud.cc +++ b/chrome/browser/printing/print_dialog_cloud.cc @@ -21,6 +21,7 @@ #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" @@ -688,27 +689,17 @@ 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 = widget->GetNativeWindow(); -#endif -#else #if defined(OS_WIN) - gfx::NativeWindow window = -#endif - browser->BrowserShowHtmlDialog(dialog_delegate, NULL, STYLE_GENERIC); + gfx::NativeWindow window = #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) @@ -716,17 +707,9 @@ 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 deleted file mode 100644 index fde0636..0000000 --- a/chrome/browser/ui/views/dom_view.cc +++ /dev/null @@ -1,87 +0,0 @@ -// 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 deleted file mode 100644 index 15f45ad..0000000 --- a/chrome/browser/ui/views/dom_view.h +++ /dev/null @@ -1,73 +0,0 @@ -// 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 deleted file mode 100644 index 7f3c791..0000000 --- a/chrome/browser/ui/views/dom_view_browsertest.cc +++ /dev/null @@ -1,101 +0,0 @@ -// 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 102fec7..3025b80 100644 --- a/chrome/browser/ui/views/html_dialog_view.cc +++ b/chrome/browser/ui/views/html_dialog_view.cc @@ -6,6 +6,7 @@ #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" @@ -16,7 +17,9 @@ #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" @@ -36,11 +39,11 @@ gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent, Browser* browser, HtmlDialogUIDelegate* delegate, DialogStyle style) { - 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(); + views::Widget* widget = views::Widget::CreateWindowWithParent( + new HtmlDialogView(profile, browser, delegate), + parent); + widget->Show(); + return widget->GetNativeWindow(); } void CloseHtmlDialog(gfx::NativeWindow window) { @@ -55,16 +58,24 @@ void CloseHtmlDialog(gfx::NativeWindow window) { HtmlDialogView::HtmlDialogView(Profile* profile, Browser* browser, HtmlDialogUIDelegate* delegate) - : DOMView(), - HtmlDialogTabContentsDelegate(profile), + : HtmlDialogTabContentsDelegate(profile), initialized_(false), delegate_(delegate), - dialog_controller_(new HtmlDialogController(this, profile, browser)) { + 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)); } HtmlDialogView::~HtmlDialogView() { } +content::WebContents* HtmlDialogView::web_contents() { + return web_view_->web_contents(); +} + //////////////////////////////////////////////////////////////////////////////// // HtmlDialogView, views::View implementation: @@ -82,13 +93,11 @@ bool HtmlDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { return true; } -void HtmlDialogView::ViewHierarchyChanged( - bool is_add, View* parent, View* child) { - DOMView::ViewHierarchyChanged(is_add, parent, child); - if (is_add && GetWidget() && !initialized_) { - initialized_ = true; - RegisterDialogAccelerators(); - } +void HtmlDialogView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && GetWidget()) + InitDialog(); } //////////////////////////////////////////////////////////////////////////////// @@ -127,7 +136,7 @@ views::View* HtmlDialogView::GetContentsView() { } views::View* HtmlDialogView::GetInitiallyFocusedView() { - return this; + return web_view_; } bool HtmlDialogView::ShouldShowWindowTitle() const { @@ -281,13 +290,26 @@ void HtmlDialogView::LoadingStateChanged(content::WebContents* source) { } //////////////////////////////////////////////////////////////////////////////// -// HtmlDialogView: +// HtmlDialogView, TabRenderWatcher::Delegate implementation: + +void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) { +} + +void HtmlDialogView::OnTabMainFrameLoaded() { +} + +void HtmlDialogView::OnTabMainFrameRender() { + tab_watcher_.reset(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HtmlDialogView, private: void HtmlDialogView::InitDialog() { - // Now Init the DOMView. This view runs in its own process to render the html. - DOMView::Init(profile(), NULL); + content::WebContents* web_contents = web_view_->GetWebContents(); + if (web_contents->GetDelegate() == this) + return; - WebContents* web_contents = dom_contents_->web_contents(); web_contents->SetDelegate(this); // Set the delegate. This must be done before loading the page. See @@ -303,20 +325,5 @@ void HtmlDialogView::InitDialog() { GetWidget()->CenterWindow(out); } - 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(); + web_view_->LoadInitialURL(GetDialogContentURL()); } diff --git a/chrome/browser/ui/views/html_dialog_view.h b/chrome/browser/ui/views/html_dialog_view.h index 1523b36..44645b4 100644 --- a/chrome/browser/ui/views/html_dialog_view.h +++ b/chrome/browser/ui/views/html_dialog_view.h @@ -12,16 +12,20 @@ #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 @@ -35,8 +39,10 @@ class Profile; // 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 DOMView, + : public views::View, public HtmlDialogTabContentsDelegate, public HtmlDialogUIDelegate, public views::WidgetDelegate, @@ -47,15 +53,16 @@ class HtmlDialogView HtmlDialogUIDelegate* delegate); virtual ~HtmlDialogView(); - // Initializes the contents of the dialog (the DOMView and the callbacks). - void InitDialog(); + // For testing. + content::WebContents* web_contents(); // Overridden from views::View: virtual gfx::Size GetPreferredSize() OVERRIDE; virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; - virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child) - OVERRIDE; + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) OVERRIDE; // Overridden from views::WidgetDelegate: virtual bool CanResize() const OVERRIDE; @@ -102,10 +109,7 @@ class HtmlDialogView virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; protected: - // Register accelerators for this dialog. - virtual void RegisterDialogAccelerators(); - - // TabRenderWatcher::Delegate implementation. + // Overridden from TabRenderWatcher::Delegate: virtual void OnRenderHostCreated(content::RenderViewHost* host) OVERRIDE; virtual void OnTabMainFrameLoaded() OVERRIDE; virtual void OnTabMainFrameRender() OVERRIDE; @@ -113,7 +117,10 @@ class HtmlDialogView private: FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered); - // Whether the view is initialized. That is, dialog acceleartors is registered + // Initializes the contents of the dialog. + void InitDialog(); + + // Whether the view is initialized. That is, dialog accelerators is registered // and FreezeUpdates property is set to prevent WM from showing the window // until the property is removed. bool initialized_; @@ -130,6 +137,8 @@ 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 8e52edc..307d900 100644 --- a/chrome/browser/ui/views/html_dialog_view_browsertest.cc +++ b/chrome/browser/ui/views/html_dialog_view_browsertest.cc @@ -114,7 +114,6 @@ 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. @@ -134,8 +133,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->dom_contents()->web_contents()-> - GetRenderWidgetHostView()->GetViewBounds(); + rwhv_bounds = + html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds(); EXPECT_LT(0, rwhv_bounds.width()); EXPECT_LT(0, rwhv_bounds.height()); EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); @@ -150,8 +149,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->dom_contents()->web_contents()-> - GetRenderWidgetHostView()->GetViewBounds(); + rwhv_bounds = + html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds(); EXPECT_LT(0, rwhv_bounds.width()); EXPECT_LT(0, rwhv_bounds.height()); EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); @@ -166,8 +165,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->dom_contents()->web_contents()-> - GetRenderWidgetHostView()->GetViewBounds(); + rwhv_bounds = + html_view->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 8e8bbae..e40749e 100644 --- a/chrome/browser/ui/views/keyboard_overlay_delegate.cc +++ b/chrome/browser/ui/views/keyboard_overlay_delegate.cc @@ -15,6 +15,7 @@ #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; @@ -57,7 +58,7 @@ void KeyboardOverlayDelegate::GetDialogSize( using std::min; DCHECK(view_); gfx::Rect rect = gfx::Screen::GetMonitorAreaNearestWindow( - view_->native_view()); + view_->GetWidget()->GetNativeView()); 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 d9aea68..6d78a9f 100644 --- a/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc +++ b/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc @@ -92,13 +92,12 @@ 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->native_view()); + html_view->GetWidget()->GetNativeView()); 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 762ec9b..4d125be 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* webview_; + views::WebView* web_view_; ExtensionFunctionDispatcher extension_dispatcher_; @@ -172,7 +172,7 @@ class KeyboardWidget KeyboardWidget::KeyboardWidget() : views::Widget::Widget(), keyboard_url_(chrome::kChromeUIKeyboardURL), - webview_(new DOMView(ProfileManager::GetDefaultProfile()))), + web_view_(new views::WebView(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. - webview_->CreateWebContentsWithSiteInstance( - content::SiteInstance::CreateForURL(webview_->browser_context(), + web_view_->CreateWebContentsWithSiteInstance( + content::SiteInstance::CreateForURL(web_view_->browser_context(), keyboard_url_)); - webview_->LoadInitialURL(keyboard_url_); - SetContentsView(webview_); + web_view_->LoadInitialURL(keyboard_url_); + SetContentsView(web_view_); // Setup observer so the events from the keyboard can be handled. - content::WebContentsObserver::Observe(webview_->web_contents()); + content::WebContentsObserver::Observe(web_view_->web_contents()); // Initialize the animation. animation_.reset(new ui::SlideAnimation(this)); @@ -342,14 +342,15 @@ 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. - webview_->LoadInitialURL(keyboard_url_); - webview_->SchedulePaint(); + web_view_->LoadInitialURL(keyboard_url_); + web_view_->SchedulePaint(); } } void KeyboardWidget::OnRequest(const ExtensionHostMsg_Request_Params& request) { - extension_dispatcher_.Dispatch(request, - webview_->web_contents()->GetRenderViewHost()); + extension_dispatcher_.Dispatch( + request, + web_view_->web_contents()->GetRenderViewHost()); } void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type, @@ -399,7 +400,7 @@ void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type, std::string json_args; base::JSONWriter::Write(&args, &json_args); - Profile* profile = Profile::FromBrowserContext(webview_->browser_context()); + Profile* profile = Profile::FromBrowserContext(web_view_->browser_context()); profile->GetExtensionEventRouter()->DispatchEventToRenderers( kOnTextInputTypeChanged, json_args, NULL, GURL()); @@ -417,7 +418,7 @@ Browser* KeyboardWidget::GetBrowser() { } content::WebContents* KeyboardWidget::GetAssociatedWebContents() const { - return webview_->web_contents(); + return web_view_->web_contents(); } #if defined(OS_CHROMEOS) @@ -426,7 +427,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); - webview_->LoadInitialURL(url); + web_view_->LoadInitialURL(url); VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); } #endif diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4437b77..e7de849 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3280,8 +3280,6 @@ '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', @@ -4809,8 +4807,6 @@ ['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 e29caf3..4f9e128 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2935,7 +2935,6 @@ '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', @@ -3355,7 +3354,6 @@ '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', ], |