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

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: modify mac build failure 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 26 matching lines...) Expand all
51 base::IntToString16(child_count)), 52 base::IntToString16(child_count)),
52 MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; 53 MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES;
53 } 54 }
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,
tfarina 2012/12/19 15:55:03 ideally I think we should just blow away this func
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 // When |initial_disposition| is OFF_THE_RECORD, a node which can't be
69 // opened in incognito window, it is detected using |browser_context|, is
70 // not opened.
71 if (initial_disposition == OFF_THE_RECORD &&
72 !IsURLAllowedInIncognito(node->url(), browser_context))
73 return;
74
66 WindowOpenDisposition disposition; 75 WindowOpenDisposition disposition;
67 if (*opened_url) 76 if (*opened_url)
68 disposition = NEW_BACKGROUND_TAB; 77 disposition = NEW_BACKGROUND_TAB;
69 else 78 else
70 disposition = initial_disposition; 79 disposition = initial_disposition;
71 content::WebContents* opened_tab = (*navigator)->OpenURL( 80 content::WebContents* opened_tab = (*navigator)->OpenURL(
72 content::OpenURLParams(node->url(), content::Referrer(), disposition, 81 content::OpenURLParams(node->url(), content::Referrer(), disposition,
73 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 82 content::PAGE_TRANSITION_AUTO_BOOKMARK, false));
74 if (!*opened_url) { 83 if (!*opened_url) {
75 *opened_url = true; 84 *opened_url = true;
76 // We opened the first URL which may have opened a new window or clobbered 85 // 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 86 // the current page, reset the navigator just to be sure. |opened_tab| may
78 // be NULL in tests. 87 // be NULL in tests.
79 if (opened_tab) 88 if (opened_tab)
80 *navigator = opened_tab; 89 *navigator = opened_tab;
81 } 90 }
82 } else { 91 } else {
83 // For folders only open direct children. 92 // For folders only open direct children.
84 for (int i = 0; i < node->child_count(); ++i) { 93 for (int i = 0; i < node->child_count(); ++i) {
85 const BookmarkNode* child_node = node->GetChild(i); 94 const BookmarkNode* child_node = node->GetChild(i);
86 if (child_node->is_url()) 95 if (child_node->is_url())
87 OpenAllImpl(child_node, initial_disposition, navigator, opened_url); 96 OpenAllImpl(child_node, initial_disposition, navigator, opened_url,
97 browser_context);
88 } 98 }
89 } 99 }
90 } 100 }
91 101
92 // Returns the total number of descendants nodes. 102 // Returns the total number of descendants nodes.
93 int ChildURLCountTotal(const BookmarkNode* node) { 103 int ChildURLCountTotal(const BookmarkNode* node) {
94 int result = 0; 104 int result = 0;
95 for (int i = 0; i < node->child_count(); ++i) { 105 for (int i = 0; i < node->child_count(); ++i) {
96 const BookmarkNode* child = node->GetChild(i); 106 const BookmarkNode* child = node->GetChild(i);
97 result++; 107 result++;
(...skipping 25 matching lines...) Expand all
123 &(entry.first), &(entry.second)); 133 &(entry.first), &(entry.second));
124 urls->push_back(entry); 134 urls->push_back(entry);
125 } 135 }
126 } 136 }
127 137
128 } // namespace 138 } // namespace
129 139
130 void OpenAll(gfx::NativeWindow parent, 140 void OpenAll(gfx::NativeWindow parent,
131 content::PageNavigator* navigator, 141 content::PageNavigator* navigator,
132 const std::vector<const BookmarkNode*>& nodes, 142 const std::vector<const BookmarkNode*>& nodes,
133 WindowOpenDisposition initial_disposition) { 143 WindowOpenDisposition initial_disposition,
144 content::BrowserContext* browser_context) {
134 if (!ShouldOpenAll(parent, nodes)) 145 if (!ShouldOpenAll(parent, nodes))
135 return; 146 return;
136 147
137 bool opened_url = false; 148 bool opened_url = false;
138 for (size_t i = 0; i < nodes.size(); ++i) 149 for (size_t i = 0; i < nodes.size(); ++i)
139 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url); 150 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url,
151 browser_context);
140 } 152 }
141 153
142 void OpenAll(gfx::NativeWindow parent, 154 void OpenAll(gfx::NativeWindow parent,
143 content::PageNavigator* navigator, 155 content::PageNavigator* navigator,
144 const BookmarkNode* node, 156 const BookmarkNode* node,
145 WindowOpenDisposition initial_disposition) { 157 WindowOpenDisposition initial_disposition,
158 content::BrowserContext* browser_context) {
146 std::vector<const BookmarkNode*> nodes; 159 std::vector<const BookmarkNode*> nodes;
147 nodes.push_back(node); 160 nodes.push_back(node);
148 OpenAll(parent, navigator, nodes, initial_disposition); 161 OpenAll(parent, navigator, nodes, initial_disposition, browser_context);
149 } 162 }
150 163
151 bool ConfirmDeleteBookmarkNode(const BookmarkNode* node, 164 bool ConfirmDeleteBookmarkNode(const BookmarkNode* node,
152 gfx::NativeWindow window) { 165 gfx::NativeWindow window) {
153 DCHECK(node && node->is_folder() && !node->empty()); 166 DCHECK(node && node->is_folder() && !node->empty());
154 return ShowMessageBox(window, 167 return ShowMessageBox(window,
155 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 168 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
156 l10n_util::GetStringFUTF16Int(IDS_BOOKMARK_EDITOR_CONFIRM_DELETE, 169 l10n_util::GetStringFUTF16Int(IDS_BOOKMARK_EDITOR_CONFIRM_DELETE,
157 ChildURLCountTotal(node)), 170 ChildURLCountTotal(node)),
158 MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; 171 MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES;
(...skipping 30 matching lines...) Expand all
189 202
190 void ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) { 203 void ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) {
191 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(browser_context); 204 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(browser_context);
192 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar); 205 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar);
193 206
194 // The user changed when the bookmark bar is shown, update the preferences. 207 // The user changed when the bookmark bar is shown, update the preferences.
195 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show); 208 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show);
196 } 209 }
197 210
198 } // namespace chrome 211 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698