diff options
author | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 22:09:29 +0000 |
---|---|---|
committer | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 22:09:29 +0000 |
commit | 5fdc1f1f719d861693f9c6107202ac9b0287c09b (patch) | |
tree | 5a621bbc99fcb2b444f7040e58b214d1bb190275 /chrome/browser/ui | |
parent | c182124ee6da66fd40ae91c31bc42a6ff56ecece (diff) | |
download | chromium_src-5fdc1f1f719d861693f9c6107202ac9b0287c09b.zip chromium_src-5fdc1f1f719d861693f9c6107202ac9b0287c09b.tar.gz chromium_src-5fdc1f1f719d861693f9c6107202ac9b0287c09b.tar.bz2 |
Add --use-more-webui runtime flag to toggle WebUI replacements for native dialogs.
This adds the flag --use-more-webui to allow turning on WebUI replacements for native dialogs. This flag is automatically set when --use-pure-views is specified. Modifies replaced native dialogs to be toggled based on flag value. BookmarkEditor has also been refactored to use static constructors to EditDetails to describe what is being edited to make the code more readable.
BUG=None
TEST=Tested that webui dialogs can be turned on or left off with --use-more-webui.
Review URL: http://codereview.chromium.org/7670041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
27 files changed, 192 insertions, 148 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index e408ab9..20afc98 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3113,13 +3113,12 @@ void Browser::BookmarkAllTabs() { BookmarkModel* model = profile()->GetBookmarkModel(); DCHECK(model && model->IsLoaded()); - BookmarkEditor::EditDetails details; - details.type = BookmarkEditor::EditDetails::NEW_FOLDER; + BookmarkEditor::EditDetails details = + BookmarkEditor::EditDetails::AddFolder(model->GetParentForNewNodes()); bookmark_utils::GetURLsForOpenTabs(this, &(details.urls)); DCHECK(!details.urls.empty()); - BookmarkEditor::Show(window()->GetNativeHandle(), profile_, - model->GetParentForNewNodes(), details, + BookmarkEditor::Show(window()->GetNativeHandle(), profile_, details, BookmarkEditor::SHOW_TREE); } diff --git a/chrome/browser/ui/browser_dialogs.h b/chrome/browser/ui/browser_dialogs.h index 1981941..4a8e64c 100644 --- a/chrome/browser/ui/browser_dialogs.h +++ b/chrome/browser/ui/browser_dialogs.h @@ -51,6 +51,10 @@ void ShowExtensionInstalledBubble(const Extension* extension, void ShowHungRendererDialog(TabContents* contents); void HideHungRendererDialog(TabContents* contents); +// Native implementations of hung renderer dialogs. +void ShowNativeHungRendererDialog(TabContents* contents); +void HideNativeHungRendererDialog(TabContents* contents); + } // namespace browser #endif // CHROME_BROWSER_UI_BROWSER_DIALOGS_H_ diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm index 2bd43da..3569a61 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm @@ -588,22 +588,16 @@ void RecordAppLaunch(Profile* profile, GURL url) { return; } -#if defined(WEBUI_DIALOGS) - browser_->OpenBookmarkManagerEditNode(node->id()); -#else - // There is no real need to jump to a platform-common routine at - // this point (which just jumps back to objc) other than consistency - // across platforms. + // This jumps to a platform-common routine at this point (which may just + // jump back to objc or may use the WebUI dialog). // // TODO(jrg): identify when we NO_TREE. I can see it in the code // for the other platforms but can't find a way to trigger it in the // UI. BookmarkEditor::Show([[self view] window], browser_->profile(), - node->parent(), - BookmarkEditor::EditDetails(node), + BookmarkEditor::EditDetails::EditNode(node), BookmarkEditor::SHOW_TREE); -#endif } - (IBAction)cutBookmark:(id)sender { @@ -681,15 +675,10 @@ void RecordAppLaunch(Profile* profile, GURL url) { const BookmarkNode* parent = [self nodeFromMenuItem:sender]; if (!parent) parent = bookmarkModel_->bookmark_bar_node(); -#if defined(WEBUI_DIALOGS) - browser_->OpenBookmarkManagerAddNodeIn(parent->id()); -#else BookmarkEditor::Show([[self view] window], browser_->profile(), - parent, - BookmarkEditor::EditDetails(), + BookmarkEditor::EditDetails::AddNodeInFolder(parent), BookmarkEditor::SHOW_TREE); -#endif } // Might be called from the context menu over the bar OR over a diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.mm index 6d37efd..340115a 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.mm @@ -60,11 +60,11 @@ // static; implemented for each platform. Update this function for new // classes derived from BookmarkEditorBaseController. -void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd, - Profile* profile, - const BookmarkNode* parent, - const EditDetails& details, - Configuration configuration) { +void BookmarkEditor::ShowNative(gfx::NativeWindow parent_hwnd, + Profile* profile, + const BookmarkNode* parent, + const EditDetails& details, + Configuration configuration) { BookmarkEditorBaseController* controller = nil; if (details.type == EditDetails::NEW_FOLDER) { controller = [[BookmarkAllTabsController alloc] diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index 3508698..5ca9378 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -1629,10 +1629,6 @@ enum { if (responds) { const BookmarkNode* node = [sender node]; if (node) { -#if defined(WEBUI_DIALOGS) - DCHECK(browser_); - browser_->OpenBookmarkManagerEditNode(node->id()); -#else // A BookmarkEditorController is a sheet that owns itself, and // deallocates itself when closed. [[[BookmarkEditorController alloc] @@ -1642,7 +1638,6 @@ enum { node:node configuration:BookmarkEditor::SHOW_TREE] runAsModalSheet]; -#endif } } } diff --git a/chrome/browser/ui/cocoa/hung_renderer_controller.mm b/chrome/browser/ui/cocoa/hung_renderer_controller.mm index bab2472..397146d 100644 --- a/chrome/browser/ui/cocoa/hung_renderer_controller.mm +++ b/chrome/browser/ui/cocoa/hung_renderer_controller.mm @@ -215,7 +215,7 @@ class TabContentsObserverBridge : public TabContentsObserver { namespace browser { -void ShowHungRendererDialog(TabContents* contents) { +void ShowNativeHungRendererDialog(TabContents* contents) { if (!logging::DialogsAreSuppressed()) { if (!g_instance) g_instance = [[HungRendererController alloc] @@ -224,7 +224,7 @@ void ShowHungRendererDialog(TabContents* contents) { } } -void HideHungRendererDialog(TabContents* contents) { +void HideNativeHungRendererDialog(TabContents* contents) { if (!logging::DialogsAreSuppressed() && g_instance) [g_instance endForTabContents:contents]; } diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc index f0b57ab..4ace196 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc @@ -309,25 +309,17 @@ void BookmarkBubbleGtk::ShowEditor() { // Commit any edits now. ApplyEdits(); -#if !defined(WEBUI_DIALOGS) // Closing might delete us, so we'll cache what we need on the stack. Profile* profile = profile_; GtkWindow* toplevel = GTK_WINDOW(gtk_widget_get_toplevel(anchor_)); -#endif // Close the bubble, deleting the C++ objects, etc. bubble_->Close(); if (node) { -#if defined(WEBUI_DIALOGS) - Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); - DCHECK(browser); - browser->OpenBookmarkManagerEditNode(node->id()); -#else - BookmarkEditor::Show(toplevel, profile, NULL, - BookmarkEditor::EditDetails(node), + BookmarkEditor::Show(toplevel, profile, + BookmarkEditor::EditDetails::EditNode(node), BookmarkEditor::SHOW_TREE); -#endif } } diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.cc index 1dd66f0..9d54c96 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.cc +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.cc @@ -258,11 +258,11 @@ class BookmarkEditorGtk::ContextMenuController }; // static -void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd, - Profile* profile, - const BookmarkNode* parent, - const EditDetails& details, - Configuration configuration) { +void BookmarkEditor::ShowNative(gfx::NativeWindow parent_hwnd, + Profile* profile, + const BookmarkNode* parent, + const EditDetails& details, + Configuration configuration) { DCHECK(profile); BookmarkEditorGtk* editor = new BookmarkEditorGtk(parent_hwnd, profile, parent, details, diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk_unittest.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk_unittest.cc index c8a0a0a..7563edd 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk_unittest.cc +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk_unittest.cc @@ -101,7 +101,7 @@ class BookmarkEditorGtkTest : public testing::Test { // Makes sure the tree model matches that of the bookmark bar model. TEST_F(BookmarkEditorGtkTest, ModelsMatch) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(), + BookmarkEditor::EditDetails::AddNodeInFolder(NULL), BookmarkEditor::SHOW_TREE); // The root should have two or three children, one for the bookmark bar node, @@ -148,7 +148,7 @@ TEST_F(BookmarkEditorGtkTest, ModelsMatch) { // Changes the title and makes sure parent/visual order doesn't change. TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(GetNode("a")), + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditor::SHOW_TREE); gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); @@ -168,7 +168,7 @@ TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { Time node_time = GetNode("a")->date_added(); BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(GetNode("a")), + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditor::SHOW_TREE); gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), GURL(base_path() + "new_a").spec().c_str()); @@ -189,7 +189,7 @@ TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { // Moves 'a' to be a child of the other node. TEST_F(BookmarkEditorGtkTest, ChangeParent) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(GetNode("a")), + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditor::SHOW_TREE); GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); @@ -208,7 +208,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParent) { TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { Time node_time = GetNode("a")->date_added(); BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(GetNode("a")), + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditor::SHOW_TREE); gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), @@ -229,7 +229,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { // Creates a new folder and moves a node to it. TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(GetNode("a")), + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditor::SHOW_TREE); GtkTreeIter bookmark_bar_node; @@ -277,7 +277,7 @@ TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { // Brings up the editor, creating a new URL on the bookmark bar. TEST_F(BookmarkEditorGtkTest, NewURL) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails(), + BookmarkEditor::EditDetails::AddNodeInFolder(NULL), BookmarkEditor::SHOW_TREE); gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), @@ -301,7 +301,7 @@ TEST_F(BookmarkEditorGtkTest, NewURL) { // Brings up the editor with no tree and modifies the url. TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails( + BookmarkEditor::EditDetails::EditNode( model_->other_node()->GetChild(0)), BookmarkEditor::NO_TREE); @@ -323,7 +323,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) { // Brings up the editor with no tree and modifies only the title. TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) { BookmarkEditorGtk editor(NULL, profile_.get(), NULL, - BookmarkEditor::EditDetails( + BookmarkEditor::EditDetails::EditNode( model_->other_node()->GetChild(0)), BookmarkEditor::NO_TREE); gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); diff --git a/chrome/browser/ui/gtk/certificate_viewer.cc b/chrome/browser/ui/gtk/certificate_viewer.cc index 7a07793..609514c 100644 --- a/chrome/browser/ui/gtk/certificate_viewer.cc +++ b/chrome/browser/ui/gtk/certificate_viewer.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/gtk/certificate_viewer.h" - #include <gtk/gtk.h> #include <algorithm> @@ -14,6 +12,7 @@ #include "base/string_number_conversions.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/certificate_viewer.h" #include "chrome/browser/ui/gtk/certificate_dialogs.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/common/net/x509_certificate_model.h" @@ -22,6 +21,7 @@ #include "ui/base/gtk/gtk_hig_constants.h" #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/gtk_util.h" +#include "ui/gfx/native_widget_types.h" namespace { @@ -708,14 +708,14 @@ void CertificateViewer::Show() { } // namespace -void ShowCertificateViewer(gfx::NativeWindow parent, - net::X509Certificate::OSCertHandle cert) { +void ShowNativeCertificateViewer(gfx::NativeWindow parent, + net::X509Certificate::OSCertHandle cert) { net::X509Certificate::OSCertHandles cert_chain; x509_certificate_model::GetCertChainFromCert(cert, &cert_chain); (new CertificateViewer(parent, cert_chain))->Show(); } -void ShowCertificateViewer(gfx::NativeWindow parent, - net::X509Certificate* cert) { - ShowCertificateViewer(parent, cert->os_cert_handle()); +void ShowNativeCertificateViewer(gfx::NativeWindow parent, + net::X509Certificate* cert) { + ShowNativeCertificateViewer(parent, cert->os_cert_handle()); } diff --git a/chrome/browser/ui/gtk/certificate_viewer.h b/chrome/browser/ui/gtk/certificate_viewer.h deleted file mode 100644 index c31477c..0000000 --- a/chrome/browser/ui/gtk/certificate_viewer.h +++ /dev/null @@ -1,16 +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. - -#ifndef CHROME_BROWSER_UI_GTK_CERTIFICATE_VIEWER_H_ -#define CHROME_BROWSER_UI_GTK_CERTIFICATE_VIEWER_H_ -#pragma once - -#include "chrome/browser/certificate_viewer.h" -#include "net/base/x509_certificate.h" -#include "ui/gfx/native_widget_types.h" - -void ShowCertificateViewer(gfx::NativeWindow parent, - net::X509Certificate::OSCertHandle); - -#endif // CHROME_BROWSER_UI_GTK_CERTIFICATE_VIEWER_H_ diff --git a/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc b/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc index 890166d..a4cae17 100644 --- a/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc @@ -249,7 +249,7 @@ void HungRendererDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { namespace browser { -void ShowHungRendererDialog(TabContents* contents) { +void ShowNativeHungRendererDialog(TabContents* contents) { if (!logging::DialogsAreSuppressed()) { if (!g_instance) g_instance = new HungRendererDialogGtk(); @@ -257,7 +257,7 @@ void ShowHungRendererDialog(TabContents* contents) { } } -void HideHungRendererDialog(TabContents* contents) { +void HideNativeHungRendererDialog(TabContents* contents) { if (!logging::DialogsAreSuppressed() && g_instance) g_instance->EndForTabContents(contents); } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index 529a13e..ee4ba58 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -366,7 +366,6 @@ void BookmarkBubbleView::ShowEditor() { const BookmarkNode* node = profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); -#if !defined(WEBUI_DIALOGS) #if defined(USE_AURA) NOTIMPLEMENTED(); gfx::NativeView parent = NULL; @@ -388,22 +387,15 @@ void BookmarkBubbleView::ShowEditor() { static_cast<views::NativeWidgetGtk*>(GetWidget()->native_widget())-> GetTransientParent()); #endif -#endif // Even though we just hid the window, we need to invoke Close to schedule // the delete and all that. Close(); if (node) { -#if defined(WEBUI_DIALOGS) - Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); - DCHECK(browser); - browser->OpenBookmarkManagerEditNode(node->id()); -#else - BookmarkEditor::Show(parent, profile_, NULL, - BookmarkEditor::EditDetails(node), + BookmarkEditor::Show(parent, profile_, + BookmarkEditor::EditDetails::EditNode(node), BookmarkEditor::SHOW_TREE); -#endif } } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc index 94dd345..ab7480c 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc @@ -130,15 +130,9 @@ void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { } if (selection_[0]->is_url()) { -#if defined(WEBUI_DIALOGS) - Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); - DCHECK(browser); - browser->OpenBookmarkManagerEditNode(selection_[0]->id()); -#else BookmarkEditor::Show(parent_widget_->GetNativeWindow(), profile_, - parent_, BookmarkEditor::EditDetails(selection_[0]), + BookmarkEditor::EditDetails::EditNode(selection_[0]), BookmarkEditor::SHOW_TREE); -#endif } else { BookmarkFolderEditorController::Show(profile_, parent_widget_->GetNativeWindow(), selection_[0], -1, @@ -164,17 +158,12 @@ void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { UserMetrics::RecordAction( UserMetricsAction("BookmarkBar_ContextMenu_Add")); -#if defined(WEBUI_DIALOGS) - Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); - DCHECK(browser); - browser->OpenBookmarkManagerAddNodeIn(selection_[0]->id()); -#else // TODO: this should honor the index from GetParentForNewNodes. BookmarkEditor::Show( parent_widget_->GetNativeWindow(), profile_, - bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL), - BookmarkEditor::EditDetails(), BookmarkEditor::SHOW_TREE); -#endif + BookmarkEditor::EditDetails::AddNodeInFolder( + bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL)), + BookmarkEditor::SHOW_TREE); break; } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc index aed2f47..fd3fead 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc @@ -47,11 +47,11 @@ const int kNewFolderButtonID = 1002; } // namespace // static -void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd, - Profile* profile, - const BookmarkNode* parent, - const EditDetails& details, - Configuration configuration) { +void BookmarkEditor::ShowNative(gfx::NativeWindow parent_hwnd, + Profile* profile, + const BookmarkNode* parent, + const EditDetails& details, + Configuration configuration) { DCHECK(profile); BookmarkEditorView* editor = new BookmarkEditorView(profile, parent, details, configuration); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view_unittest.cc index 3b37cc5..9bf17a7 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view_unittest.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view_unittest.cc @@ -130,7 +130,8 @@ class BookmarkEditorViewTest : public testing::Test { // Makes sure the tree model matches that of the bookmark bar model. TEST_F(BookmarkEditorViewTest, ModelsMatch) { - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::AddNodeInFolder(NULL), BookmarkEditorView::SHOW_TREE); BookmarkEditorView::EditorNode* editor_root = editor_tree_model()->GetRoot(); // The root should have two or three children: bookmark bar, other bookmarks @@ -159,7 +160,8 @@ TEST_F(BookmarkEditorViewTest, ModelsMatch) { // Changes the title and makes sure parent/visual order doesn't change. TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditorView::SHOW_TREE); SetTitleText(L"new_a"); @@ -176,7 +178,8 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { Time node_time = Time::Now() + TimeDelta::FromDays(2); GetMutableNode("a")->set_date_added(node_time); - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditorView::SHOW_TREE); SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec())); @@ -193,7 +196,8 @@ TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { // Moves 'a' to be a child of the other node. TEST_F(BookmarkEditorViewTest, ChangeParent) { - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditorView::SHOW_TREE); ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); @@ -207,7 +211,8 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) { TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) { Time node_time = Time::Now() + TimeDelta::FromDays(2); GetMutableNode("a")->set_date_added(node_time); - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditorView::SHOW_TREE); SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec())); @@ -222,7 +227,8 @@ TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) { // Creates a new folder and moves a node to it. TEST_F(BookmarkEditorViewTest, MoveToNewParent) { - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::EditNode(GetNode("a")), BookmarkEditorView::SHOW_TREE); // Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21". @@ -255,7 +261,8 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) { // Brings up the editor, creating a new URL on the bookmark bar. TEST_F(BookmarkEditorViewTest, NewURL) { - CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(), + CreateEditor(profile_.get(), NULL, + BookmarkEditor::EditDetails::AddNodeInFolder(NULL), BookmarkEditorView::SHOW_TREE); SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); @@ -276,7 +283,8 @@ TEST_F(BookmarkEditorViewTest, NewURL) { // Brings up the editor with no tree and modifies the url. TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) { CreateEditor(profile_.get(), NULL, - BookmarkEditor::EditDetails(model_->other_node()->GetChild(0)), + BookmarkEditor::EditDetails::EditNode( + model_->other_node()->GetChild(0)), BookmarkEditorView::NO_TREE); SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); @@ -296,7 +304,8 @@ TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) { // Brings up the editor with no tree and modifies only the title. TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) { CreateEditor(profile_.get(), NULL, - BookmarkEditor::EditDetails(model_->other_node()->GetChild(0)), + BookmarkEditor::EditDetails::EditNode( + model_->other_node()->GetChild(0)), BookmarkEditorView::NO_TREE); SetTitleText(L"new_a"); @@ -314,10 +323,10 @@ TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) { // Creates a new folder. TEST_F(BookmarkEditorViewTest, NewFolder) { const BookmarkNode* bb_node = model_->bookmark_bar_node(); - BookmarkEditor::EditDetails details; + BookmarkEditor::EditDetails details = + BookmarkEditor::EditDetails::AddFolder(bb_node); details.urls.push_back(std::make_pair(GURL(base_path() + "x"), ASCIIToUTF16("z"))); - details.type = BookmarkEditor::EditDetails::NEW_FOLDER; CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); // The url field shouldn't be visible. @@ -343,10 +352,10 @@ TEST_F(BookmarkEditorViewTest, NewFolder) { // Creates a new folder and selects a different folder for the folder to appear // in then the editor is initially created showing. TEST_F(BookmarkEditorViewTest, MoveFolder) { - BookmarkEditor::EditDetails details; + BookmarkEditor::EditDetails details = BookmarkEditor::EditDetails::AddFolder( + model_->bookmark_bar_node()); details.urls.push_back(std::make_pair(GURL(base_path() + "x"), ASCIIToUTF16("z"))); - details.type = BookmarkEditor::EditDetails::NEW_FOLDER; CreateEditor(profile_.get(), model_->bookmark_bar_node(), details, BookmarkEditorView::SHOW_TREE); diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index a6eee7a..b589d4e 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -554,7 +554,7 @@ static HungRendererDialogView* CreateHungRendererDialogView() { namespace browser { -void ShowHungRendererDialog(TabContents* contents) { +void ShowNativeHungRendererDialog(TabContents* contents) { if (!logging::DialogsAreSuppressed()) { if (!g_instance) g_instance = CreateHungRendererDialogView(); @@ -562,7 +562,7 @@ void ShowHungRendererDialog(TabContents* contents) { } } -void HideHungRendererDialog(TabContents* contents) { +void HideNativeHungRendererDialog(TabContents* contents) { if (!logging::DialogsAreSuppressed() && g_instance) g_instance->EndForTabContents(contents); } diff --git a/chrome/browser/ui/webui/bookmarks_ui.cc b/chrome/browser/ui/webui/bookmarks_ui.cc index 6c78bcc..d5ec1a4 100644 --- a/chrome/browser/ui/webui/bookmarks_ui.cc +++ b/chrome/browser/ui/webui/bookmarks_ui.cc @@ -7,7 +7,13 @@ #include "base/memory/ref_counted_memory.h" #include "base/memory/singleton.h" #include "base/message_loop.h" +#include "base/string_number_conversions.h" +#include "base/stringprintf.h" +#include "chrome/browser/bookmarks/bookmark_editor.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_thread.h" @@ -15,6 +21,8 @@ #include "grit/theme_resources.h" #include "grit/theme_resources_standard.h" #include "ui/base/resource/resource_bundle.h" +#include "googleurl/src/gurl.h" + //////////////////////////////////////////////////////////////////////////////// // @@ -60,3 +68,33 @@ RefCountedMemory* BookmarksUI::GetFaviconResourceBytes() { return ResourceBundle::GetSharedInstance(). LoadDataResourceBytes(IDR_BOOKMARKS_FAVICON); } + +//////////////////////////////////////////////////////////////////////////////// +// +// BookmarkEditor +// +//////////////////////////////////////////////////////////////////////////////// + +// static +void BookmarkEditor::ShowWebUI(Profile* profile, + const EditDetails& details) { + GURL url(chrome::kChromeUIBookmarksURL); + if (details.type == EditDetails::EXISTING_NODE) { + DCHECK(details.existing_node); + url = url.Resolve(StringPrintf("/#e=%s", + base::Int64ToString(details.existing_node->id()).c_str())); + } else if (details.type == EditDetails::NEW_URL) { + DCHECK(details.parent_node); + url = url.Resolve(StringPrintf("/#a=%s", + base::Int64ToString(details.parent_node->id()).c_str())); + } else { + NOTREACHED() << "Unhandled bookmark edit details type"; + } + // Get parent browser object. + Browser* browser = BrowserList::GetLastActiveWithProfile(profile); + DCHECK(browser); + browser::NavigateParams params( + browser->GetSingletonTabNavigateParams(url)); + params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; + browser->ShowSingletonTabOverwritingNTP(params); +} diff --git a/chrome/browser/ui/webui/certificate_viewer.cc b/chrome/browser/ui/webui/certificate_viewer.cc index e7a0f7c..4d50cb5db 100644 --- a/chrome/browser/ui/webui/certificate_viewer.cc +++ b/chrome/browser/ui/webui/certificate_viewer.cc @@ -5,13 +5,15 @@ #include "base/i18n/time_formatting.h" #include "base/utf_string_conversions.h" #include "base/string_number_conversions.h" -#include "chrome/browser/ui/webui/certificate_viewer.h" -#include "chrome/common/url_constants.h" +#include "chrome/browser/certificate_viewer.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/gtk/certificate_dialogs.h" -#include "chrome/browser/ui/browser_dialogs.h" +#include "chrome/browser/ui/webui/certificate_viewer.h" +#include "chrome/browser/ui/webui/chrome_web_ui.h" #include "chrome/common/net/x509_certificate_model.h" +#include "chrome/common/url_constants.h" #include "content/browser/tab_contents/tab_contents.h" #include "ui/base/l10n/l10n_util.h" #include "grit/generated_resources.h" @@ -24,10 +26,14 @@ const int kDefaultHeight = 450; } // namespace -// Shows a certificate using the WebUI certificate viewer. +// Shows a certificate using the native or WebUI certificate viewer. void ShowCertificateViewer(gfx::NativeWindow parent, net::X509Certificate* cert) { - CertificateViewerDialog::ShowDialog(parent, cert); + if (ChromeWebUI::IsMoreWebUI()) { + CertificateViewerDialog::ShowDialog(parent, cert); + } else { + ShowNativeCertificateViewer(parent, cert); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/webui/certificate_viewer.h b/chrome/browser/ui/webui/certificate_viewer.h index 1ebda6a..0b621d0 100644 --- a/chrome/browser/ui/webui/certificate_viewer.h +++ b/chrome/browser/ui/webui/certificate_viewer.h @@ -11,7 +11,8 @@ #include "net/base/x509_certificate.h" #include "ui/gfx/native_widget_types.h" -// Displays the WebUI certificate viewer dialog for the passed in certificate. +// Displays the native or WebUI certificate viewer dialog for the given +// certificate. void ShowCertificateViewer(gfx::NativeWindow parent, net::X509Certificate*); diff --git a/chrome/browser/ui/webui/chrome_web_ui.cc b/chrome/browser/ui/webui/chrome_web_ui.cc index 885711c..cd9b0ee 100644 --- a/chrome/browser/ui/webui/chrome_web_ui.cc +++ b/chrome/browser/ui/webui/chrome_web_ui.cc @@ -4,9 +4,15 @@ #include "chrome/browser/ui/webui/chrome_web_ui.h" +#include "base/command_line.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/chrome_switches.h" #include "content/browser/tab_contents/tab_contents.h" +#if defined(TOOLKIT_VIEWS) +#include "views/widget/widget.h" +#endif + ChromeWebUI::ChromeWebUI(TabContents* contents) : WebUI(contents), force_bookmark_bar_visible_(false) { @@ -18,3 +24,13 @@ ChromeWebUI::~ChromeWebUI() { Profile* ChromeWebUI::GetProfile() const { return Profile::FromBrowserContext(tab_contents()->browser_context()); } + +// static +bool ChromeWebUI::IsMoreWebUI() { + bool more_webui = CommandLine::ForCurrentProcess()->HasSwitch( + switches::kUseMoreWebUI); +#if defined(TOOLKIT_VIEWS) + more_webui |= views::Widget::IsPureViews(); +#endif + return more_webui; +} diff --git a/chrome/browser/ui/webui/chrome_web_ui.h b/chrome/browser/ui/webui/chrome_web_ui.h index 4b9ed85..489e519 100644 --- a/chrome/browser/ui/webui/chrome_web_ui.h +++ b/chrome/browser/ui/webui/chrome_web_ui.h @@ -24,6 +24,10 @@ class ChromeWebUI : public WebUI { return force_bookmark_bar_visible_; } + // IsMoreWebUI returns a command line flag that tracks whether to use + // available WebUI implementations of native dialogs. + static bool IsMoreWebUI(); + protected: void set_force_bookmark_bar_visible(bool value) { force_bookmark_bar_visible_ = value; diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc index 813e153..09aec3f 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc @@ -25,6 +25,7 @@ #include "chrome/browser/ui/webui/history2_ui.h" #include "chrome/browser/ui/webui/history_ui.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" +#include "chrome/browser/ui/webui/hung_renderer_dialog_ui.h" #include "chrome/browser/ui/webui/media/media_internals_ui.h" #include "chrome/browser/ui/webui/net_internals_ui.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" @@ -69,14 +70,10 @@ #include "chrome/browser/ui/webui/conflicts_ui.h" #endif -#if defined(WEBUI_DIALOGS) && defined(OS_POSIX) && !defined(OS_MACOSX) +#if defined(OS_POSIX) && !defined(OS_MACOSX) #include "chrome/browser/ui/webui/certificate_viewer_ui.h" #endif -#if defined(WEBUI_DIALOGS) -#include "chrome/browser/ui/webui/hung_renderer_dialog_ui.h" -#endif - namespace { // A function for creating a new WebUI. The caller owns the return value, which @@ -151,15 +148,13 @@ static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, return &NewWebUI<BookmarksUI>; if (url.host() == chrome::kChromeUIBugReportHost) return &NewWebUI<BugReportUI>; -#if defined(WEBUI_DIALOGS) && defined(OS_POSIX) && !defined(OS_MACOSX) +#if defined(OS_POSIX) && !defined(OS_MACOSX) if (url.host() == chrome::kChromeUICertificateViewerHost) return &NewWebUI<CertificateViewerUI>; #endif -#if defined(WEBUI_DIALOGS) if (url.host() == chrome::kChromeUIHungRendererDialogHost) { return &NewWebUI<HungRendererDialogUI>; } -#endif if (url.host() == chrome::kChromeUICrashesHost) return &NewWebUI<CrashesUI>; if (url.host() == chrome::kChromeUIDevToolsHost) diff --git a/chrome/browser/ui/webui/html_dialog_ui.cc b/chrome/browser/ui/webui/html_dialog_ui.cc index fd3341a..9f01d15 100644 --- a/chrome/browser/ui/webui/html_dialog_ui.cc +++ b/chrome/browser/ui/webui/html_dialog_ui.cc @@ -29,6 +29,10 @@ HtmlDialogUI::~HtmlDialogUI() { // and the HTML dialogs won't swap WebUIs anyway since they don't navigate. } +void HtmlDialogUI::CloseDialog(const base::ListValue* args) { + OnDialogClosed(args); +} + // static PropertyAccessor<HtmlDialogUIDelegate*>& HtmlDialogUI::GetPropertyAccessor() { return g_html_dialog_ui_property_accessor.Get(); @@ -67,8 +71,8 @@ void HtmlDialogUI::OnDialogClosed(const ListValue* args) { tab_contents()->property_bag()); if (delegate) { std::string json_retval; - if (!args->GetString(0, &json_retval)) - NOTREACHED() << "Could not read JSON arguments"; + if (args && !args->empty() && !args->GetString(0, &json_retval)) + NOTREACHED() << "Could not read JSON argument"; (*delegate)->OnDialogClosed(json_retval); } diff --git a/chrome/browser/ui/webui/html_dialog_ui.h b/chrome/browser/ui/webui/html_dialog_ui.h index 264daa1..9e26f85 100644 --- a/chrome/browser/ui/webui/html_dialog_ui.h +++ b/chrome/browser/ui/webui/html_dialog_ui.h @@ -100,6 +100,9 @@ class HtmlDialogUI : public ChromeWebUI { explicit HtmlDialogUI(TabContents* tab_contents); virtual ~HtmlDialogUI(); + // Close the dialog, passing the specified arguments to the close handler. + void CloseDialog(const base::ListValue* args); + // Returns the PropertyBag accessor object used to write the delegate pointer // into the TabContents (see class-level comment above). static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor(); diff --git a/chrome/browser/ui/webui/hung_renderer_dialog.cc b/chrome/browser/ui/webui/hung_renderer_dialog.cc index 590c79a..13379cd 100644 --- a/chrome/browser/ui/webui/hung_renderer_dialog.cc +++ b/chrome/browser/ui/webui/hung_renderer_dialog.cc @@ -8,10 +8,13 @@ #include <vector> #include "base/json/json_reader.h" +#include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/browser/ui/webui/html_dialog_ui.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" @@ -19,7 +22,6 @@ #include "content/common/result_codes.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -#include "views/widget/widget.h" namespace { HungRendererDialog* g_instance = NULL; @@ -30,11 +32,21 @@ const int kHungRendererDialogHeight = 200; namespace browser { void ShowHungRendererDialog(TabContents* contents) { - HungRendererDialog::ShowHungRendererDialog(contents); + if (ChromeWebUI::IsMoreWebUI()) { + HungRendererDialog::ShowHungRendererDialog(contents); + return; + } + + ShowNativeHungRendererDialog(contents); } void HideHungRendererDialog(TabContents* contents) { - HungRendererDialog::HideHungRendererDialog(contents); + if (ChromeWebUI::IsMoreWebUI()) { + HungRendererDialog::HideHungRendererDialog(contents); + return; + } + + HideNativeHungRendererDialog(contents); } } // namespace browser @@ -62,6 +74,7 @@ void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { HungRendererDialog::HungRendererDialog() : contents_(NULL), + handler_(NULL), window_(NULL) { } @@ -70,6 +83,7 @@ void HungRendererDialog::ShowDialog(TabContents* contents) { contents_ = contents; Browser* browser = BrowserList::GetLastActive(); DCHECK(browser); + handler_ = new HungRendererDialogHandler(contents_); window_ = browser->BrowserShowHtmlDialog(this, NULL); } @@ -83,9 +97,8 @@ void HungRendererDialog::HideDialog(TabContents* contents) { // We do this because the close dialog handler runs whether it is trigged by // the user closing the box, or by being closed externally with widget->Close. contents_ = NULL; - views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); - DCHECK(widget); - widget->Close(); + DCHECK(handler_); + handler_->CloseDialog(); } bool HungRendererDialog::IsDialogModal() const { @@ -102,7 +115,7 @@ GURL HungRendererDialog::GetDialogContentURL() const { void HungRendererDialog::GetWebUIMessageHandlers( std::vector<WebUIMessageHandler*>* handlers) const { - handlers->push_back(new HungRendererDialogHandler(contents_)); + handlers->push_back(handler_); } void HungRendererDialog::GetDialogSize(gfx::Size* size) const { @@ -155,6 +168,11 @@ HungRendererDialogHandler::HungRendererDialogHandler( : contents_(contents) { } +void HungRendererDialogHandler::CloseDialog() { + DCHECK(web_ui_); + static_cast<HtmlDialogUI*>(web_ui_)->CloseDialog(NULL); +} + void HungRendererDialogHandler::RegisterMessages() { web_ui_->RegisterMessageCallback("requestTabContentsList", NewCallback(this, diff --git a/chrome/browser/ui/webui/hung_renderer_dialog.h b/chrome/browser/ui/webui/hung_renderer_dialog.h index aa9eebc..e26a8a1 100644 --- a/chrome/browser/ui/webui/hung_renderer_dialog.h +++ b/chrome/browser/ui/webui/hung_renderer_dialog.h @@ -15,6 +15,7 @@ #include "ui/gfx/native_widget_types.h" class TabContents; +class HungRendererDialogHandler; class HungRendererDialog : private HtmlDialogUIDelegate { public: @@ -49,6 +50,9 @@ class HungRendererDialog : private HtmlDialogUIDelegate { // The tab contents. TabContents* contents_; + // The dialog handler. + HungRendererDialogHandler* handler_; + // The dialog window. gfx::NativeWindow window_; @@ -61,6 +65,8 @@ class HungRendererDialogHandler : public WebUIMessageHandler { public: explicit HungRendererDialogHandler(TabContents* contents); + void CloseDialog(); + // Overridden from WebUIMessageHandler virtual void RegisterMessages(); |