| 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_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/extensions/api/commands/command_service.h" | 12 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/ui/app_list/app_list_util.h" | 15 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 16 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" | 16 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/simple_message_box.h" | 20 #include "chrome/browser/ui/simple_message_box.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
| 25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 26 #include "components/bookmarks/browser/bookmark_model.h" | 26 #include "components/bookmarks/browser/bookmark_model.h" |
| 27 #include "components/search/search.h" | 27 #include "components/search/search.h" |
| 28 #include "components/user_prefs/user_prefs.h" | 28 #include "components/user_prefs/user_prefs.h" |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #include "net/base/net_util.h" |
| 31 #include "ui/base/l10n/l10n_util.h" |
| 32 |
| 33 #if defined(ENABLE_EXTENSIONS) |
| 30 #include "extensions/browser/extension_registry.h" | 34 #include "extensions/browser/extension_registry.h" |
| 31 #include "extensions/common/extension_set.h" | 35 #include "extensions/common/extension_set.h" |
| 32 #include "net/base/net_util.h" | 36 #endif |
| 33 #include "ui/base/l10n/l10n_util.h" | |
| 34 | 37 |
| 35 namespace chrome { | 38 namespace chrome { |
| 36 | 39 |
| 37 int num_bookmark_urls_before_prompting = 15; | 40 int num_bookmark_urls_before_prompting = 15; |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 | 43 |
| 41 // The ways in which extensions may customize the bookmark shortcut. | 44 // The ways in which extensions may customize the bookmark shortcut. |
| 42 enum BookmarkShortcutDisposition { | 45 enum BookmarkShortcutDisposition { |
| 43 BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED, | 46 BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 std::pair<GURL, base::string16> entry; | 150 std::pair<GURL, base::string16> entry; |
| 148 GetURLAndTitleToBookmark(browser->tab_strip_model()->GetWebContentsAt(i), | 151 GetURLAndTitleToBookmark(browser->tab_strip_model()->GetWebContentsAt(i), |
| 149 &(entry.first), &(entry.second)); | 152 &(entry.first), &(entry.second)); |
| 150 urls->push_back(entry); | 153 urls->push_back(entry); |
| 151 } | 154 } |
| 152 } | 155 } |
| 153 | 156 |
| 154 // Indicates how the bookmark shortcut has been changed by extensions associated | 157 // Indicates how the bookmark shortcut has been changed by extensions associated |
| 155 // with |profile|, if at all. | 158 // with |profile|, if at all. |
| 156 BookmarkShortcutDisposition GetBookmarkShortcutDisposition(Profile* profile) { | 159 BookmarkShortcutDisposition GetBookmarkShortcutDisposition(Profile* profile) { |
| 160 #if defined(ENABLE_EXTENSIONS) |
| 157 extensions::CommandService* command_service = | 161 extensions::CommandService* command_service = |
| 158 extensions::CommandService::Get(profile); | 162 extensions::CommandService::Get(profile); |
| 159 | 163 |
| 160 extensions::ExtensionRegistry* registry = | 164 extensions::ExtensionRegistry* registry = |
| 161 extensions::ExtensionRegistry::Get(profile); | 165 extensions::ExtensionRegistry::Get(profile); |
| 162 if (!registry) | 166 if (!registry) |
| 163 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED; | 167 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED; |
| 164 | 168 |
| 165 const extensions::ExtensionSet& extension_set = | 169 const extensions::ExtensionSet& extension_set = |
| 166 registry->enabled_extensions(); | 170 registry->enabled_extensions(); |
| 167 | 171 |
| 168 // This flag tracks whether any extension wants the disposition to be | 172 // This flag tracks whether any extension wants the disposition to be |
| 169 // removed. | 173 // removed. |
| 170 bool removed = false; | 174 bool removed = false; |
| 171 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); | 175 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); |
| 172 i != extension_set.end(); | 176 i != extension_set.end(); |
| 173 ++i) { | 177 ++i) { |
| 174 // Use the overridden disposition if any extension wants it. | 178 // Use the overridden disposition if any extension wants it. |
| 175 if (command_service->OverridesBookmarkShortcut(i->get())) | 179 if (command_service->OverridesBookmarkShortcut(i->get())) |
| 176 return BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDDEN; | 180 return BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDDEN; |
| 177 | 181 |
| 178 if (!removed && | 182 if (!removed && |
| 179 extensions::CommandService::RemovesBookmarkShortcut(i->get())) { | 183 extensions::CommandService::RemovesBookmarkShortcut(i->get())) { |
| 180 removed = true; | 184 removed = true; |
| 181 } | 185 } |
| 182 } | 186 } |
| 183 | 187 |
| 184 if (removed) | 188 if (removed) |
| 185 return BOOKMARK_SHORTCUT_DISPOSITION_REMOVED; | 189 return BOOKMARK_SHORTCUT_DISPOSITION_REMOVED; |
| 190 #endif |
| 186 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED; | 191 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED; |
| 187 } | 192 } |
| 188 | 193 |
| 189 } // namespace | 194 } // namespace |
| 190 | 195 |
| 191 void OpenAll(gfx::NativeWindow parent, | 196 void OpenAll(gfx::NativeWindow parent, |
| 192 content::PageNavigator* navigator, | 197 content::PageNavigator* navigator, |
| 193 const std::vector<const BookmarkNode*>& nodes, | 198 const std::vector<const BookmarkNode*>& nodes, |
| 194 WindowOpenDisposition initial_disposition, | 199 WindowOpenDisposition initial_disposition, |
| 195 content::BrowserContext* browser_context) { | 200 content::BrowserContext* browser_context) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 profile->GetPrefs()->GetBoolean( | 346 profile->GetPrefs()->GetBoolean( |
| 342 bookmarks::prefs::kShowAppsShortcutInBookmarkBar); | 347 bookmarks::prefs::kShowAppsShortcutInBookmarkBar); |
| 343 } | 348 } |
| 344 | 349 |
| 345 bool ShouldRemoveBookmarkThisPageUI(Profile* profile) { | 350 bool ShouldRemoveBookmarkThisPageUI(Profile* profile) { |
| 346 return GetBookmarkShortcutDisposition(profile) == | 351 return GetBookmarkShortcutDisposition(profile) == |
| 347 BOOKMARK_SHORTCUT_DISPOSITION_REMOVED; | 352 BOOKMARK_SHORTCUT_DISPOSITION_REMOVED; |
| 348 } | 353 } |
| 349 | 354 |
| 350 bool ShouldRemoveBookmarkOpenPagesUI(Profile* profile) { | 355 bool ShouldRemoveBookmarkOpenPagesUI(Profile* profile) { |
| 356 #if defined(ENABLE_EXTENSIONS) |
| 351 extensions::ExtensionRegistry* registry = | 357 extensions::ExtensionRegistry* registry = |
| 352 extensions::ExtensionRegistry::Get(profile); | 358 extensions::ExtensionRegistry::Get(profile); |
| 353 if (!registry) | 359 if (!registry) |
| 354 return false; | 360 return false; |
| 355 | 361 |
| 356 const extensions::ExtensionSet& extension_set = | 362 const extensions::ExtensionSet& extension_set = |
| 357 registry->enabled_extensions(); | 363 registry->enabled_extensions(); |
| 358 | 364 |
| 359 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); | 365 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); |
| 360 i != extension_set.end(); | 366 i != extension_set.end(); |
| 361 ++i) { | 367 ++i) { |
| 362 if (extensions::CommandService::RemovesBookmarkOpenPagesShortcut(i->get())) | 368 if (extensions::CommandService::RemovesBookmarkOpenPagesShortcut(i->get())) |
| 363 return true; | 369 return true; |
| 364 } | 370 } |
| 371 #endif |
| 365 | 372 |
| 366 return false; | 373 return false; |
| 367 } | 374 } |
| 368 | 375 |
| 369 } // namespace chrome | 376 } // namespace chrome |
| OLD | NEW |