diff options
37 files changed, 295 insertions, 237 deletions
diff --git a/build/common.gypi b/build/common.gypi index f060eb5..0134fd5 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -34,11 +34,6 @@ # Disable touch support by default. 'touchui%': 0, - # Disable webui dialog replacements for native dialogs by default. - # TODO(flackr): Change this to a runtime flag triggered by - # --pure-views so that these dialogs can be easily tested. - 'webui_dialogs%': 0, - # Whether the compositor is enabled on views. 'views_compositor%': 0, @@ -49,7 +44,6 @@ 'chromeos%': '<(chromeos)', 'use_only_pure_views%': '<(use_only_pure_views)', 'touchui%': '<(touchui)', - 'webui_dialogs%': '<(webui_dialogs)', 'views_compositor%': '<(views_compositor)', 'use_aura%': '<(use_aura)', @@ -80,11 +74,6 @@ 'use_only_pure_views%': 0, }], - # Use WebUI dialogs in TouchUI and PureView builds. - ['touchui==1 or use_only_pure_views==1 or use_aura==1', { - 'webui_dialogs%': 1, - }], - # Use the views compositor when using the Aura window manager. ['use_aura==1', { 'views_compositor%': 1, @@ -95,7 +84,6 @@ # Copy conditionally-set variables out one scope. 'chromeos%': '<(chromeos)', 'touchui%': '<(touchui)', - 'webui_dialogs%': '<(webui_dialogs)', 'host_arch%': '<(host_arch)', 'toolkit_views%': '<(toolkit_views)', 'use_only_pure_views%': '<(use_only_pure_views)', @@ -308,7 +296,6 @@ 'enable_flapper_hacks%': '<(enable_flapper_hacks)', 'chromeos%': '<(chromeos)', 'touchui%': '<(touchui)', - 'webui_dialogs%': '<(webui_dialogs)', 'file_manager_extension%': '<(file_manager_extension)', 'webui_task_manager%': '<(webui_task_manager)', 'inside_chromium_build%': '<(inside_chromium_build)', @@ -671,9 +658,6 @@ ['touchui==1', { 'grit_defines': ['-D', 'touchui'], }], - ['webui_dialogs==1', { - 'grit_defines': ['-D', 'webui_dialogs'], - }], ['file_manager_extension==1', { 'grit_defines': ['-D', 'file_manager_extension'], }], diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc index 0e92c12..97cfb92 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc +++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc @@ -139,15 +139,9 @@ void BookmarkContextMenuController::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_window_, profile_, parent_, - BookmarkEditor::EditDetails(selection_[0]), - BookmarkEditor::SHOW_TREE); -#endif + BookmarkEditor::Show(parent_window_, profile_, + BookmarkEditor::EditDetails::EditNode(selection_[0]), + BookmarkEditor::SHOW_TREE); } else { BookmarkFolderEditorController::Show(profile_, parent_window_, selection_[0], -1, @@ -172,17 +166,12 @@ void BookmarkContextMenuController::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_window_, 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/bookmarks/bookmark_editor.cc b/chrome/browser/bookmarks/bookmark_editor.cc index 2e940fc..521f441 100644 --- a/chrome/browser/bookmarks/bookmark_editor.cc +++ b/chrome/browser/bookmarks/bookmark_editor.cc @@ -1,20 +1,52 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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/bookmarks/bookmark_editor.h" +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/ui/webui/chrome_web_ui.h" -#include "googleurl/src/gurl.h" +BookmarkEditor::EditDetails::EditDetails(Type node_type) + : type(node_type) { +} + +BookmarkEditor::EditDetails BookmarkEditor::EditDetails::EditNode( + const BookmarkNode* node) { + EditDetails details(EXISTING_NODE); + details.existing_node = node; + return details; +} -BookmarkEditor::EditDetails::EditDetails() - : type(NEW_URL), - existing_node(NULL) { +BookmarkEditor::EditDetails BookmarkEditor::EditDetails::AddNodeInFolder( + const BookmarkNode* parent_node) { + EditDetails details(NEW_URL); + details.parent_node = parent_node; + return details; } -BookmarkEditor::EditDetails::EditDetails(const BookmarkNode* node) - : type(EXISTING_NODE), - existing_node(node) { +BookmarkEditor::EditDetails BookmarkEditor::EditDetails::AddFolder( + const BookmarkNode* parent_node) { + EditDetails details(NEW_FOLDER); + details.parent_node = parent_node; + return details; } BookmarkEditor::EditDetails::~EditDetails() { } + +void BookmarkEditor::Show(gfx::NativeWindow parent_window, + Profile* profile, + const EditDetails& details, + Configuration configuration) { + // TODO(flackr): Implement NEW_FOLDER type in WebUI and remove the type check. + if (ChromeWebUI::IsMoreWebUI() && ( + details.type == EditDetails::EXISTING_NODE || + details.type == EditDetails::NEW_URL)) { + ShowWebUI(profile, details); + return; + } + + // Delegate to the platform native bookmark editor code. + ShowNative(parent_window, profile, details.parent_node, details, + configuration); +} diff --git a/chrome/browser/bookmarks/bookmark_editor.h b/chrome/browser/bookmarks/bookmark_editor.h index 39e99ea..5b3a6ab 100644 --- a/chrome/browser/bookmarks/bookmark_editor.h +++ b/chrome/browser/bookmarks/bookmark_editor.h @@ -27,7 +27,19 @@ class BookmarkEditor { }; // Describes what the user is editing. - struct EditDetails { + class EditDetails { + public: + // Returns an EditDetails instance for the user editing the given bookmark. + static EditDetails EditNode(const BookmarkNode* node); + + // Returns an EditDetails instance for the user adding a bookmark within + // a given parent node. + static EditDetails AddNodeInFolder(const BookmarkNode* parent_node); + + // Returns an EditDetails instance for the user adding a folder within a + // given parent node. + static EditDetails AddFolder(const BookmarkNode* parent_node); + enum Type { // The user is editing an existing node in the model. The node the user // is editing is set in |existing_node|. @@ -43,34 +55,50 @@ class BookmarkEditor { NEW_FOLDER }; - EditDetails(); - explicit EditDetails(const BookmarkNode* node); ~EditDetails(); // See description of enum value for details. - Type type; + const Type type; // If type == EXISTING_NODE this gives the existing node. const BookmarkNode* existing_node; + // If type == NEW_URL or type == NEW_FOLDER this gives the parent node + // to place the new node in. + const BookmarkNode* parent_node; + // If type == NEW_FOLDER, this is the urls/title pairs to add to the // folder. std::vector<std::pair<GURL, string16> > urls; + + private: + explicit EditDetails(Type node_type); }; - // Shows the bookmark editor. The bookmark editor allows editing an + // Shows the bookmark editor. If --use-more-webui is enabled use the bookmark + // manager to add or edit bookmarks. The bookmark editor allows editing an // existing node or creating a new bookmark node (as determined by // |details.type|). If |configuration| is SHOW_TREE, a tree is shown allowing // the user to choose the parent of the node. // |parent| gives the initial parent to select in the tree for the node. // |parent| is only used if |details.existing_node| is null. - // TODO(flackr): Rename this to ShowNative and add cross platform Show method - // which will show a WebUI version of the dialog if --pure-views is set. static void Show(gfx::NativeWindow parent_window, Profile* profile, - const BookmarkNode* parent, const EditDetails& details, Configuration configuration); + + private: + // Shows the native bookmark editor. + // TODO(flackr): Remove parent argument. + static void ShowNative(gfx::NativeWindow parent_window, + Profile* profile, + const BookmarkNode* parent, + const EditDetails& details, + Configuration configuration); + + // Shows the WebUI bookmark editor. + static void ShowWebUI(Profile* profile, + const EditDetails& details); }; #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_ diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index d768df4..280b48c 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -30,7 +30,7 @@ <include name="IDR_ABOUT_VERSION_HTML" file="resources\about_version.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_ABOUT_VERSION_JS" file="resources\about_version.js" type="BINDATA" /> <include name="IDR_BOOKMARKS_MANIFEST" file="resources\bookmark_manager\manifest.json" type="BINDATA" /> - <if expr="pp_if('webui_dialogs')"> + <if expr="is_posix and not is_macosx"> <include name="IDR_CERTIFICATE_VIEWER_HTML" file="resources\certificate_viewer.html" type="BINDATA" /> <include name="IDR_CERTIFICATE_VIEWER_JS" file="resources\certificate_viewer.js" type="BINDATA" /> <include name="IDR_CERTIFICATE_VIEWER_CSS" file="resources\certificate_viewer.css" type="BINDATA" /> diff --git a/chrome/browser/certificate_viewer.h b/chrome/browser/certificate_viewer.h index 89b0e04..2dc9bbc 100644 --- a/chrome/browser/certificate_viewer.h +++ b/chrome/browser/certificate_viewer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -22,4 +22,9 @@ void ShowCertificateViewerByID(gfx::NativeWindow parent, int cert_id); void ShowCertificateViewer(gfx::NativeWindow parent, net::X509Certificate* cert); +// Opens a certificate viewer under |parent| to display |cert| using a native +// certificate viewer dialog. +void ShowNativeCertificateViewer(gfx::NativeWindow parent, + net::X509Certificate* cert); + #endif // CHROME_BROWSER_CERTIFICATE_VIEWER_H_ diff --git a/chrome/browser/sync/test/integration/bookmarks_helper.cc b/chrome/browser/sync/test/integration/bookmarks_helper.cc index 38edf82..d82cade 100644 --- a/chrome/browser/sync/test/integration/bookmarks_helper.cc +++ b/chrome/browser/sync/test/integration/bookmarks_helper.cc @@ -406,14 +406,14 @@ const BookmarkNode* SetURL(int profile, bookmark_utils::ApplyEditsWithNoFolderChange( GetVerifierBookmarkModel(), v_node->parent(), - BookmarkEditor::EditDetails(v_node), + BookmarkEditor::EditDetails::EditNode(v_node), v_node->GetTitle(), new_url); } return bookmark_utils::ApplyEditsWithNoFolderChange( GetBookmarkModel(profile), node->parent(), - BookmarkEditor::EditDetails(node), + BookmarkEditor::EditDetails::EditNode(node), node->GetTitle(), new_url); } diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index a234961..abf5ee1 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3114,13 +3114,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 dba32f7..06cc993 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..108d2f4 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -35,6 +35,10 @@ #include "views/layout/layout_constants.h" #include "views/window/client_view.h" +#if defined(TOOLKIT_USES_GTK) +#include "views/widget/native_widget_gtk.h" +#endif + using views::ColumnSet; using views::GridLayout; @@ -366,7 +370,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 +391,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 f7f9aa8..aa05ac8 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(); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9d85137..f48f291 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2822,7 +2822,6 @@ 'browser/ui/gtk/certificate_dialogs.cc', 'browser/ui/gtk/certificate_dialogs.h', 'browser/ui/gtk/certificate_viewer.cc', - 'browser/ui/gtk/certificate_viewer.h', 'browser/ui/gtk/chrome_gtk_frame.cc', 'browser/ui/gtk/chrome_gtk_frame.h', 'browser/ui/gtk/collected_cookies_gtk.cc', @@ -4116,14 +4115,9 @@ '../ui/aura/aura.gyp:aura', ], }], - ['webui_dialogs == 1', { - 'defines': [ - 'WEBUI_DIALOGS', - ], - }], - # Exclude WebUI certificate viewer if not POSIX, mac (these OS's have - # native certificate viewers) or WebUI dialogs are disabled. - ['webui_dialogs == 0 or os_posix == 0 or OS == "mac"', { + # Exclude WebUI certificate viewer if not POSIX or mac (these OS's have + # native certificate viewers). + ['os_posix == 0 or OS == "mac"', { 'sources/': [ ['exclude', '^browser/ui/webui/certificate_viewer.cc'], ['exclude', '^browser/ui/webui/certificate_viewer.h'], @@ -4131,23 +4125,6 @@ ['exclude', '^browser/ui/webui/certificate_viewer_ui.h'], ], }], - # Exclude other WebUI dialogs if WebUI dialogs are disabled. - ['webui_dialogs == 0', { - 'sources/': [ - ['exclude', '^browser/ui/webui/hung_renderer_dialog.cc'], - ['exclude', '^browser/ui/webui/hung_renderer_dialog.h'], - ['exclude', '^browser/ui/webui/hung_renderer_dialog_ui.cc'], - ['exclude', '^browser/ui/webui/hung_renderer_dialog_ui.h'], - ], - }], - ['webui_dialogs == 1', { - 'sources/': [ - ['exclude', '^browser/ui/gtk/certificate_viewer.cc'], - ['exclude', '^browser/ui/gtk/certificate_viewer.h'], - ['exclude', '^browser/ui/gtk/hung_renderer_dialog_gtk.cc'], - ['exclude', '^browser/ui/gtk/hung_renderer_dialog_gtk.h'], - ], - }], ['toolkit_uses_gtk == 1', { 'dependencies': [ '../build/linux/system.gyp:dbus', @@ -4472,7 +4449,6 @@ ['include', '^browser/ui/gtk/certificate_dialogs.cc'], ['include', '^browser/ui/gtk/certificate_dialogs.h'], ['include', '^browser/ui/gtk/certificate_viewer.cc'], - ['include', '^browser/ui/gtk/certificate_viewer.h'], ['include', '^browser/ui/gtk/chrome_gtk_frame.cc'], ['include', '^browser/ui/gtk/chrome_gtk_frame.h'], ['include', '^browser/ui/gtk/collected_cookies_gtk.cc'], @@ -4785,15 +4761,6 @@ ['exclude', '^browser/ui/panels/panel_mouse_watcher_gtk.cc'], ], }], - # Exclude the GTK versions of dialogs if webui_dialogs are enabled. - ['webui_dialogs==1', { - 'sources/': [ - ['exclude', '^browser/ui/gtk/certificate_viewer.cc'], - ['exclude', '^browser/ui/gtk/certificate_viewer.h'], - ['exclude', '^browser/ui/gtk/hung_renderer_dialog_gtk.cc'], - ['exclude', '^browser/ui/gtk/hung_renderer_dialog_gtk.cc.h'], - ], - }], # Exclude these toolkit_views specific files again. # (Required because of the '^browser/extensions/' include above) ['toolkit_views==0', { diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index fb7fb33..f45b0f5 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -999,6 +999,10 @@ const char kTryChromeAgain[] = "try-chrome-again"; // Runs un-installation steps that were done by chrome first-run. const char kUninstall[] = "uninstall"; +// Use WebUI versions of dialogs when available (rather than platform native +// implementations). +const char kUseMoreWebUI[] = "use-more-webui"; + // Use a pure Views implementation when available (rather rather than platform // native implementation such as GTK). const char kUsePureViews[] = "use-pure-views"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 601f642..4338e3d 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -268,6 +268,7 @@ extern const char kTestType[]; extern const char kTestingChannelID[]; extern const char kTryChromeAgain[]; extern const char kUninstall[]; +extern const char kUseMoreWebUI[]; extern const char kUsePureViews[]; extern const char kUseSpdy[]; extern const char kIgnoreCertificateErrors[]; |