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

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

Issue 161293002: mac: Allows extensions to hide the bookmark page menu item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make sure changes only apply to OSX. Created 6 years, 9 months 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/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/extensions/api/commands/command_service.h" 13 #include "chrome/browser/extensions/api/commands/command_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search/search.h" 15 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/ui/app_list/app_list_util.h" 16 #include "chrome/browser/ui/app_list/app_list_util.h"
17 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" 17 #include "chrome/browser/ui/bookmarks/bookmark_editor.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_navigator.h" 19 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/simple_message_box.h" 21 #include "chrome/browser/ui/simple_message_box.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "components/user_prefs/user_prefs.h" 25 #include "components/user_prefs/user_prefs.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "extensions/browser/extension_registry.h"
28 #include "extensions/common/extension_set.h"
27 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
28 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
29 #include "net/base/net_util.h" 31 #include "net/base/net_util.h"
30 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
31 33
32 namespace chrome { 34 namespace chrome {
33 35
34 int num_bookmark_urls_before_prompting = 15; 36 int num_bookmark_urls_before_prompting = 15;
35 37
36 namespace { 38 namespace {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return chrome::IsInstantExtendedAPIEnabled() && !profile->IsOffTheRecord(); 290 return chrome::IsInstantExtendedAPIEnabled() && !profile->IsOffTheRecord();
289 } 291 }
290 292
291 bool ShouldShowAppsShortcutInBookmarkBar( 293 bool ShouldShowAppsShortcutInBookmarkBar(
292 Profile* profile, 294 Profile* profile,
293 chrome::HostDesktopType host_desktop_type) { 295 chrome::HostDesktopType host_desktop_type) {
294 return IsAppsShortcutEnabled(profile, host_desktop_type) && 296 return IsAppsShortcutEnabled(profile, host_desktop_type) &&
295 profile->GetPrefs()->GetBoolean(prefs::kShowAppsShortcutInBookmarkBar); 297 profile->GetPrefs()->GetBoolean(prefs::kShowAppsShortcutInBookmarkBar);
296 } 298 }
297 299
298 BookmarkShortcutDisposition GetBookmarkShortcutDisposition( 300 BookmarkShortcutDisposition GetBookmarkShortcutDisposition(Profile* profile) {
299 const extensions::CommandService* command_service, 301 extensions::CommandService* command_service =
300 const extensions::Extension* extension) { 302 extensions::CommandService::Get(profile);
301 if (command_service->OverridesBookmarkShortcut(extension))
302 return BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDDEN;
303 303
304 return extensions::CommandService::RemovesBookmarkShortcut(extension) ? 304 extensions::ExtensionRegistry* registry =
305 BOOKMARK_SHORTCUT_DISPOSITION_REMOVED : 305 extensions::ExtensionRegistry::Get(profile);
306 BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED; 306 if (!registry)
307 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED;
308
309 const extensions::ExtensionSet& extension_set =
310 registry->enabled_extensions();
311
312 // This flag tracks whether any extension wants the disposition to be
313 // removed.
314 bool removed = false;
315 for (extensions::ExtensionSet::const_iterator i = extension_set.begin();
316 i != extension_set.end();
317 ++i) {
318 // Use the overridden disposition if any extension wants it.
319 if (command_service->OverridesBookmarkShortcut(*i))
320 return BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDDEN;
321
322 if (!removed && extensions::CommandService::RemovesBookmarkShortcut(*i))
323 removed = true;
324 }
325
326 if (removed)
327 return BOOKMARK_SHORTCUT_DISPOSITION_REMOVED;
328 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED;
329 }
330
331 bool ShouldShowBookmarkPageMenuItem(Profile* profile) {
332 return GetBookmarkShortcutDisposition(profile) !=
333 BOOKMARK_SHORTCUT_DISPOSITION_REMOVED;
307 } 334 }
308 335
309 } // namespace chrome 336 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/bookmarks/bookmark_utils.h ('k') | chrome/browser/ui/cocoa/browser_window_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698