diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_context_menu_controller.cc | 12 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_editor.h | 4 | ||||
-rw-r--r-- | chrome/browser/browser_resources.grd | 2 | ||||
-rw-r--r-- | chrome/browser/resources/bookmark_manager/js/main.js | 87 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 18 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm | 8 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_controller.mm | 5 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc | 12 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_factory.cc | 4 |
12 files changed, 148 insertions, 34 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc index ad98a03..73820d8 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc +++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc @@ -139,9 +139,15 @@ 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 } else { BookmarkFolderEditorController::Show(profile_, parent_window_, selection_[0], -1, @@ -166,11 +172,17 @@ 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 break; } diff --git a/chrome/browser/bookmarks/bookmark_editor.h b/chrome/browser/bookmarks/bookmark_editor.h index 1816420..39e99ea 100644 --- a/chrome/browser/bookmarks/bookmark_editor.h +++ b/chrome/browser/bookmarks/bookmark_editor.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. @@ -64,6 +64,8 @@ class BookmarkEditor { // 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, diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 0710cb1..1e097f8 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_certificate_viewer')"> + <if expr="pp_if('webui_dialogs')"> <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/resources/bookmark_manager/js/main.js b/chrome/browser/resources/bookmark_manager/js/main.js index cf3c7fc..86210bb 100644 --- a/chrome/browser/resources/bookmark_manager/js/main.js +++ b/chrome/browser/resources/bookmark_manager/js/main.js @@ -116,6 +116,20 @@ tree.addEventListener('change', function() { }); /** + * Add an event listener to a node that will remove itself after firing once. + * @param {!Element} node The DOM node to add the listener to. + * @param {string} name The name of the event listener to add to. + * @param {function(Event)} handler Function called when the event fires. + */ +function addOneShotEventListener(node, name, handler) { + var f = function(e) { + handler(e); + node.removeEventListener(name, f); + }; + node.addEventListener(name, f); +} + +/** * Navigates to a bookmark ID. * @param {string} id The ID to navigate to. * @param {boolean=} opt_updateHashNow Whether to immediately update the @@ -150,22 +164,61 @@ function updateParentId(id) { tree.selectedItem = bmm.treeLookup[id]; } -// We listen to hashchange so that we can update the currently shown folder when -// the user goes back and forward in the history. -window.onhashchange = function(e) { +// Process the location hash. This is called onhashchange and when the page is +// first loaded. +function processHash() { var id = window.location.hash.slice(1); + if (!id) { + // If we do not have a hash select first item in the tree. + id = tree.items[0].bookmarkId; + } var valid = false; + if (/^[ae]=/.test(id)) { + var command = id[0]; + id = id.slice(2); + if (command == 'e') { + // If hash contains e= edit the item specified. + chrome.bookmarks.get(id, function(bookmarkNodes) { + // Verify the node to edit is a valid node. + if (!bookmarkNodes || bookmarkNodes.length != 1) + return; + var bookmarkNode = bookmarkNodes[0]; + // After the list reloads edit the desired bookmark. + var editBookmark = function(e) { + var index = list.dataModel.findIndexById(bookmarkNode.id); + if (index != -1) { + var sm = list.selectionModel; + sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; + scrollIntoViewAndMakeEditable(index); + } + } - // In case we got a search hash update the text input and the bmm.treeLookup - // to use the new id. - if (/^q=/.test(id)) { + if (list.parentId == bookmarkNode.parentId) + editBookmark(); + else { + // Navigate to the parent folder, once it's loaded edit the bookmark. + addOneShotEventListener(list, 'load', editBookmark); + updateParentId(bookmarkNode.parentId); + } + }); + // We handle the two cases of navigating to the bookmark to be edited + // above, don't run the standard navigation code below. + return; + } else if (command == 'a') { + // Once the parent folder is loaded add a page bookmark. + addOneShotEventListener(list, 'load', addPage); + } + } else if (/^q=/.test(id)) { + // In case we got a search hash update the text input and the + // bmm.treeLookup to use the new id. setSearch(id.slice(2)); valid = true; } else if (id == 'recent') { valid = true; } + // Navigate to bookmark 'id' (which may be a query of the form q=query). if (valid) { updateParentId(id); } else { @@ -177,6 +230,12 @@ window.onhashchange = function(e) { } }; +// We listen to hashchange so that we can update the currently shown folder when +// the user goes back and forward in the history. +window.onhashchange = function(e) { + processHash(); +}; + // Activate is handled by the open-in-same-window-command. list.addEventListener('dblclick', function(e) { if (e.button == 0) @@ -347,21 +406,7 @@ function getFolder(parentId) { tree.addEventListener('load', function(e) { // Add hard coded tree items tree.add(recentTreeItem); - - // Now we can select a tree item. - var hash = window.location.hash.slice(1); - if (!hash) { - // If we do not have a hash select first item in the tree. - hash = tree.items[0].bookmarkId; - } - - if (/^q=/.test(hash)) { - var searchTerm = hash.slice(2); - $('term').value = searchTerm; - setSearch(searchTerm); - } else { - navigateTo(hash); - } + processHash(); }); tree.reload(); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index dc1e845..a5c727c 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1948,16 +1948,30 @@ void Browser::OpenBookmarkManager() { GetSingletonTabNavigateParams(GURL(chrome::kChromeUIBookmarksURL))); } -void Browser::OpenBookmarkManagerForNode(int64 node_id) { +void Browser::OpenBookmarkManagerWithHash(const std::string& action, + int64 node_id) { UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager")); UserMetrics::RecordAction(UserMetricsAction("ShowBookmarks")); browser::NavigateParams params(GetSingletonTabNavigateParams( GURL(chrome::kChromeUIBookmarksURL).Resolve( - StringPrintf("/#%s", base::Int64ToString(node_id).c_str())))); + StringPrintf("/#%s%s", action.c_str(), + base::Int64ToString(node_id).c_str())))); params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; ShowSingletonTabOverwritingNTP(params); } +void Browser::OpenBookmarkManagerForNode(int64 node_id) { + OpenBookmarkManagerWithHash("", node_id); +} + +void Browser::OpenBookmarkManagerEditNode(int64 node_id) { + OpenBookmarkManagerWithHash("e=", node_id); +} + +void Browser::OpenBookmarkManagerAddNodeIn(int64 node_id) { + OpenBookmarkManagerWithHash("a=", node_id); +} + void Browser::ShowAppMenu() { // We record the user metric for this event in WrenchMenu::RunMenu. window_->ShowAppMenu(); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 02f0e65..4797002 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -570,6 +570,8 @@ class Browser : public TabHandlerDelegate, void OpenBookmarkManager(); void OpenBookmarkManagerForNode(int64 node_id); + void OpenBookmarkManagerEditNode(int64 node_id); + void OpenBookmarkManagerAddNodeIn(int64 node_id); void ShowAppMenu(); void ShowHistoryTab(); void ShowDownloadsTab(); @@ -1140,6 +1142,9 @@ class Browser : public TabHandlerDelegate, // BrowserWindow if necessary. void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason); + // Open the bookmark manager with a defined hash action. + void OpenBookmarkManagerWithHash(const std::string& action, int64 node_id); + // Data members ///////////////////////////////////////////////////////////// NotificationRegistrar registrar_; diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm index b9fcf6f..32792d2 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm @@ -591,6 +591,9 @@ 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. @@ -603,6 +606,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { node->parent(), BookmarkEditor::EditDetails(node), BookmarkEditor::SHOW_TREE); +#endif } - (IBAction)cutBookmark:(id)sender { @@ -680,11 +684,15 @@ 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::SHOW_TREE); +#endif } // Might be called from the context menu over the bar OR over a diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index 3c89b2c..7f5f04e 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -1662,6 +1662,10 @@ 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] @@ -1671,6 +1675,7 @@ enum { node:node configuration:BookmarkEditor::SHOW_TREE] runAsModalSheet]; +#endif } } } diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc index e618c18..a27505b 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc @@ -17,6 +17,8 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/bookmarks/recently_used_folders_combo_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/gtk/gtk_theme_service.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/common/chrome_notification_types.h" @@ -306,17 +308,25 @@ 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_TREE); +#endif } } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index 9539a6f..53393e66 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -362,15 +362,10 @@ void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { } void BookmarkBubbleView::ShowEditor() { -#if defined(TOUCH_UI) - // TODO(saintlou): this brings up a modal window that can't be dismissed - // on touch and is tracked in chromium-os by crosbug.com/13899 - bubble_->set_fade_away_on_close(true); - Close(); -#else const BookmarkNode* node = profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); +#if !defined(WEBUI_DIALOGS) #if defined(OS_WIN) // Parent the editor to our root ancestor (not the root we're in, as that // is the info bubble and will close shortly). @@ -389,17 +384,23 @@ 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_TREE); - } #endif + } } void BookmarkBubbleView::ApplyEdits() { 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 e133bd8..2bfcdc8 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,9 +130,15 @@ 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::SHOW_TREE); +#endif } else { BookmarkFolderEditorController::Show(profile_, parent_widget_->GetNativeWindow(), selection_[0], -1, @@ -158,11 +164,17 @@ 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 break; } diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc index ef25dbb..07983b5 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc @@ -68,7 +68,7 @@ #include "chrome/browser/ui/webui/conflicts_ui.h" #endif -#if defined(WEBUI_CERTIFICATE_VIEWER) +#if defined(WEBUI_DIALOGS) && defined(OS_POSIX) && !defined(OS_MACOSX) #include "chrome/browser/ui/webui/certificate_viewer_ui.h" #endif @@ -146,7 +146,7 @@ static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, return &NewWebUI<BookmarksUI>; if (url.host() == chrome::kChromeUIBugReportHost) return &NewWebUI<BugReportUI>; -#if defined(WEBUI_CERTIFICATE_VIEWER) +#if defined(WEBUI_DIALOGS) && defined(OS_POSIX) && !defined(OS_MACOSX) if (url.host() == chrome::kChromeUICertificateViewerHost) return &NewWebUI<CertificateViewerUI>; #endif |