| OLD | NEW |
| 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_navigator.h" | 16 #include "chrome/browser/ui/browser_navigator.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/simple_message_box.h" | 18 #include "chrome/browser/ui/simple_message_box.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "components/user_prefs/user_prefs.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 24 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 | 27 |
| 27 namespace chrome { | 28 namespace chrome { |
| 28 | 29 |
| 29 int num_bookmark_urls_before_prompting = 15; | 30 int num_bookmark_urls_before_prompting = 15; |
| 30 | 31 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 234 } |
| 234 | 235 |
| 235 void GetURLAndTitleToBookmark(content::WebContents* web_contents, | 236 void GetURLAndTitleToBookmark(content::WebContents* web_contents, |
| 236 GURL* url, | 237 GURL* url, |
| 237 string16* title) { | 238 string16* title) { |
| 238 *url = web_contents->GetURL(); | 239 *url = web_contents->GetURL(); |
| 239 *title = web_contents->GetTitle(); | 240 *title = web_contents->GetTitle(); |
| 240 } | 241 } |
| 241 | 242 |
| 242 void ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) { | 243 void ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) { |
| 243 PrefService* prefs = PrefServiceFromBrowserContext(browser_context); | 244 PrefService* prefs = |
| 245 components::UserPrefs::GetInstance()->Lookup(browser_context); |
| 244 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar); | 246 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar); |
| 245 | 247 |
| 246 // The user changed when the bookmark bar is shown, update the preferences. | 248 // The user changed when the bookmark bar is shown, update the preferences. |
| 247 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show); | 249 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show); |
| 248 } | 250 } |
| 249 | 251 |
| 250 string16 FormatBookmarkURLForDisplay(const GURL& url, | 252 string16 FormatBookmarkURLForDisplay(const GURL& url, |
| 251 const PrefService* prefs) { | 253 const PrefService* prefs) { |
| 252 std::string languages; | 254 std::string languages; |
| 253 if (prefs) | 255 if (prefs) |
| 254 languages = prefs->GetString(prefs::kAcceptLanguages); | 256 languages = prefs->GetString(prefs::kAcceptLanguages); |
| 255 | 257 |
| 256 // Because this gets re-parsed by FixupURL(), it's safe to omit the scheme | 258 // Because this gets re-parsed by FixupURL(), it's safe to omit the scheme |
| 257 // and trailing slash, and unescape most characters. However, it's | 259 // and trailing slash, and unescape most characters. However, it's |
| 258 // important not to drop any username/password, or unescape anything that | 260 // important not to drop any username/password, or unescape anything that |
| 259 // changes the URL's meaning. | 261 // changes the URL's meaning. |
| 260 return net::FormatUrl( | 262 return net::FormatUrl( |
| 261 url, languages, | 263 url, languages, |
| 262 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, | 264 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, |
| 263 net::UnescapeRule::SPACES, NULL, NULL, NULL); | 265 net::UnescapeRule::SPACES, NULL, NULL, NULL); |
| 264 } | 266 } |
| 265 | 267 |
| 266 } // namespace chrome | 268 } // namespace chrome |
| OLD | NEW |