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

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: Respond to remaining rsesek/wittman comments. 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/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search/search.h" 16 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/ui/app_list/app_list_util.h" 17 #include "chrome/browser/ui/app_list/app_list_util.h"
17 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" 18 #include "chrome/browser/ui/bookmarks/bookmark_editor.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_navigator.h" 20 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/simple_message_box.h" 22 #include "chrome/browser/ui/simple_message_box.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
25 #include "components/user_prefs/user_prefs.h" 26 #include "components/user_prefs/user_prefs.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "extensions/browser/extension_system.h"
29 #include "extensions/common/extension_set.h"
27 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
28 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
29 #include "net/base/net_util.h" 32 #include "net/base/net_util.h"
30 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
31 34
32 namespace chrome { 35 namespace chrome {
33 36
34 int num_bookmark_urls_before_prompting = 15; 37 int num_bookmark_urls_before_prompting = 15;
35 38
36 namespace { 39 namespace {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return chrome::IsInstantExtendedAPIEnabled() && !profile->IsOffTheRecord(); 291 return chrome::IsInstantExtendedAPIEnabled() && !profile->IsOffTheRecord();
289 } 292 }
290 293
291 bool ShouldShowAppsShortcutInBookmarkBar( 294 bool ShouldShowAppsShortcutInBookmarkBar(
292 Profile* profile, 295 Profile* profile,
293 chrome::HostDesktopType host_desktop_type) { 296 chrome::HostDesktopType host_desktop_type) {
294 return IsAppsShortcutEnabled(profile, host_desktop_type) && 297 return IsAppsShortcutEnabled(profile, host_desktop_type) &&
295 profile->GetPrefs()->GetBoolean(prefs::kShowAppsShortcutInBookmarkBar); 298 profile->GetPrefs()->GetBoolean(prefs::kShowAppsShortcutInBookmarkBar);
296 } 299 }
297 300
298 BookmarkShortcutDisposition GetBookmarkShortcutDisposition( 301 BookmarkShortcutDisposition GetBookmarkShortcutDisposition(Profile* profile) {
299 const extensions::CommandService* command_service, 302 extensions::CommandService* command_service =
300 const extensions::Extension* extension) { 303 extensions::CommandService::Get(profile);
301 if (command_service->OverridesBookmarkShortcut(extension))
302 return BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDDEN;
303 304
304 return extensions::CommandService::RemovesBookmarkShortcut(extension) ? 305 const extensions::ExtensionSet* extension_set =
305 BOOKMARK_SHORTCUT_DISPOSITION_REMOVED : 306 extensions::ExtensionSystem::Get(profile)->
306 BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED; 307 extension_service()->extensions();
308 // This flag tracks whether any extension wants the disposition to be
309 // removed.
310 bool removed = false;
311 for (extensions::ExtensionSet::const_iterator i = extension_set->begin();
312 i != extension_set->end();
313 ++i) {
314 // Use the overridden disposition if any extension wants it.
315 if (command_service->OverridesBookmarkShortcut(*i))
316 return BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDDEN;
317
318 if (!removed && extensions::CommandService::RemovesBookmarkShortcut(*i))
319 removed = true;
320 }
321
322 if (removed)
erikchen 2014/02/26 19:58:23 I consider this form to be slightly clearer than t
323 return BOOKMARK_SHORTCUT_DISPOSITION_REMOVED;
324 return BOOKMARK_SHORTCUT_DISPOSITION_UNCHANGED;
325 }
326
327 bool ShouldShowBookmarkPageMenuItem(Profile* profile) {
328 return GetBookmarkShortcutDisposition(profile) !=
329 BOOKMARK_SHORTCUT_DISPOSITION_REMOVED;
307 } 330 }
308 331
309 } // namespace chrome 332 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698