Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/ui/bookmarks/bookmark_utils.cc

Issue 11572031: "Open All Bookmarks in Incognito Window" opens only valid URLs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: add unittest and codes for mac and gtk Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/public/pref_service_base.h" 8 #include "base/prefs/public/pref_service_base.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "chrome/browser/bookmarks/bookmark_utils.h" 12 #include "chrome/browser/bookmarks/bookmark_utils.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/browser/ui/browser_tabstrip.h" 16 #include "chrome/browser/ui/browser_tabstrip.h"
16 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/simple_message_box.h" 18 #include "chrome/browser/ui/simple_message_box.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 namespace chrome { 25 namespace chrome {
(...skipping 29 matching lines...) Expand all
54 55
55 // Implementation of OpenAll. Opens all nodes of type URL and any children of 56 // Implementation of OpenAll. Opens all nodes of type URL and any children of
56 // |node| that are of type URL. |navigator| is the PageNavigator used to open 57 // |node| that are of type URL. |navigator| is the PageNavigator used to open
57 // URLs. After the first url is opened |opened_url| is set to true and 58 // URLs. After the first url is opened |opened_url| is set to true and
58 // |navigator| is set to the PageNavigator of the last active tab. This is done 59 // |navigator| is set to the PageNavigator of the last active tab. This is done
59 // to handle a window disposition of new window, in which case we want 60 // to handle a window disposition of new window, in which case we want
60 // subsequent tabs to open in that window. 61 // subsequent tabs to open in that window.
61 void OpenAllImpl(const BookmarkNode* node, 62 void OpenAllImpl(const BookmarkNode* node,
62 WindowOpenDisposition initial_disposition, 63 WindowOpenDisposition initial_disposition,
63 content::PageNavigator** navigator, 64 content::PageNavigator** navigator,
64 bool* opened_url) { 65 bool* opened_url,
66 content::BrowserContext* browser_context) {
65 if (node->is_url()) { 67 if (node->is_url()) {
68 if (initial_disposition == OFF_THE_RECORD &&
sky 2012/12/14 17:41:12 nit: you have two spaces after ==
69 !IsURLAllowedInIncognito(node->url(), browser_context))
70 return;
71
66 WindowOpenDisposition disposition; 72 WindowOpenDisposition disposition;
67 if (*opened_url) 73 if (*opened_url)
68 disposition = NEW_BACKGROUND_TAB; 74 disposition = NEW_BACKGROUND_TAB;
69 else 75 else
70 disposition = initial_disposition; 76 disposition = initial_disposition;
71 content::WebContents* opened_tab = (*navigator)->OpenURL( 77 content::WebContents* opened_tab = (*navigator)->OpenURL(
72 content::OpenURLParams(node->url(), content::Referrer(), disposition, 78 content::OpenURLParams(node->url(), content::Referrer(), disposition,
73 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 79 content::PAGE_TRANSITION_AUTO_BOOKMARK, false));
74 if (!*opened_url) { 80 if (!*opened_url) {
75 *opened_url = true; 81 *opened_url = true;
76 // We opened the first URL which may have opened a new window or clobbered 82 // We opened the first URL which may have opened a new window or clobbered
77 // the current page, reset the navigator just to be sure. |opened_tab| may 83 // the current page, reset the navigator just to be sure. |opened_tab| may
78 // be NULL in tests. 84 // be NULL in tests.
79 if (opened_tab) 85 if (opened_tab)
80 *navigator = opened_tab; 86 *navigator = opened_tab;
81 } 87 }
82 } else { 88 } else {
83 // For folders only open direct children. 89 // For folders only open direct children.
84 for (int i = 0; i < node->child_count(); ++i) { 90 for (int i = 0; i < node->child_count(); ++i) {
85 const BookmarkNode* child_node = node->GetChild(i); 91 const BookmarkNode* child_node = node->GetChild(i);
86 if (child_node->is_url()) 92 if (child_node->is_url())
87 OpenAllImpl(child_node, initial_disposition, navigator, opened_url); 93 OpenAllImpl(child_node, initial_disposition, navigator, opened_url,
94 browser_context);
88 } 95 }
89 } 96 }
90 } 97 }
91 98
92 // Returns the total number of descendants nodes. 99 // Returns the total number of descendants nodes.
93 int ChildURLCountTotal(const BookmarkNode* node) { 100 int ChildURLCountTotal(const BookmarkNode* node) {
94 int result = 0; 101 int result = 0;
95 for (int i = 0; i < node->child_count(); ++i) { 102 for (int i = 0; i < node->child_count(); ++i) {
96 const BookmarkNode* child = node->GetChild(i); 103 const BookmarkNode* child = node->GetChild(i);
97 result++; 104 result++;
(...skipping 25 matching lines...) Expand all
123 &(entry.first), &(entry.second)); 130 &(entry.first), &(entry.second));
124 urls->push_back(entry); 131 urls->push_back(entry);
125 } 132 }
126 } 133 }
127 134
128 } // namespace 135 } // namespace
129 136
130 void OpenAll(gfx::NativeWindow parent, 137 void OpenAll(gfx::NativeWindow parent,
131 content::PageNavigator* navigator, 138 content::PageNavigator* navigator,
132 const std::vector<const BookmarkNode*>& nodes, 139 const std::vector<const BookmarkNode*>& nodes,
133 WindowOpenDisposition initial_disposition) { 140 WindowOpenDisposition initial_disposition,
141 content::BrowserContext* browser_context) {
134 if (!ShouldOpenAll(parent, nodes)) 142 if (!ShouldOpenAll(parent, nodes))
135 return; 143 return;
136 144
137 bool opened_url = false; 145 bool opened_url = false;
138 for (size_t i = 0; i < nodes.size(); ++i) 146 for (size_t i = 0; i < nodes.size(); ++i)
139 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url); 147 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url,
148 browser_context);
140 } 149 }
141 150
142 void OpenAll(gfx::NativeWindow parent, 151 void OpenAll(gfx::NativeWindow parent,
143 content::PageNavigator* navigator, 152 content::PageNavigator* navigator,
144 const BookmarkNode* node, 153 const BookmarkNode* node,
145 WindowOpenDisposition initial_disposition) { 154 WindowOpenDisposition initial_disposition,
155 content::BrowserContext* browser_context) {
146 std::vector<const BookmarkNode*> nodes; 156 std::vector<const BookmarkNode*> nodes;
147 nodes.push_back(node); 157 nodes.push_back(node);
148 OpenAll(parent, navigator, nodes, initial_disposition); 158 OpenAll(parent, navigator, nodes, initial_disposition, browser_context);
149 } 159 }
150 160
151 bool ConfirmDeleteBookmarkNode(const BookmarkNode* node, 161 bool ConfirmDeleteBookmarkNode(const BookmarkNode* node,
152 gfx::NativeWindow window) { 162 gfx::NativeWindow window) {
153 DCHECK(node && node->is_folder() && !node->empty()); 163 DCHECK(node && node->is_folder() && !node->empty());
154 return ShowMessageBox(window, 164 return ShowMessageBox(window,
155 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 165 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
156 l10n_util::GetStringFUTF16Int(IDS_BOOKMARK_EDITOR_CONFIRM_DELETE, 166 l10n_util::GetStringFUTF16Int(IDS_BOOKMARK_EDITOR_CONFIRM_DELETE,
157 ChildURLCountTotal(node)), 167 ChildURLCountTotal(node)),
158 MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; 168 MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES;
(...skipping 30 matching lines...) Expand all
189 199
190 void ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) { 200 void ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) {
191 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(browser_context); 201 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(browser_context);
192 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar); 202 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar);
193 203
194 // The user changed when the bookmark bar is shown, update the preferences. 204 // The user changed when the bookmark bar is shown, update the preferences.
195 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show); 205 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show);
196 } 206 }
197 207
198 } // namespace chrome 208 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698