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

Side by Side Diff: chrome/browser/ui/browser_commands.cc

Issue 664553007: Cleanup: Put more chrome/ code behind ENABLE_EXTENSIONS ifdefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: fix android Created 6 years, 2 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
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_navigator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/browser_commands.h" 5 #include "chrome/browser/ui/browser_commands.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browsing_data/browsing_data_helper.h" 14 #include "chrome/browser/browsing_data/browsing_data_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover.h" 15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chrome_page_zoom.h" 17 #include "chrome/browser/chrome_page_zoom.h"
18 #include "chrome/browser/devtools/devtools_window.h" 18 #include "chrome/browser/devtools/devtools_window.h"
19 #include "chrome/browser/dom_distiller/tab_utils.h" 19 #include "chrome/browser/dom_distiller/tab_utils.h"
20 #include "chrome/browser/extensions/api/commands/command_service.h"
21 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
22 #include "chrome/browser/extensions/tab_helper.h"
23 #include "chrome/browser/favicon/favicon_tab_helper.h" 20 #include "chrome/browser/favicon/favicon_tab_helper.h"
24 #include "chrome/browser/lifetime/application_lifetime.h" 21 #include "chrome/browser/lifetime/application_lifetime.h"
25 #include "chrome/browser/platform_util.h" 22 #include "chrome/browser/platform_util.h"
26 #include "chrome/browser/prefs/incognito_mode_prefs.h" 23 #include "chrome/browser/prefs/incognito_mode_prefs.h"
27 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/rlz/rlz.h" 25 #include "chrome/browser/rlz/rlz.h"
29 #include "chrome/browser/search/search.h" 26 #include "chrome/browser/search/search.h"
30 #include "chrome/browser/sessions/session_service_factory.h" 27 #include "chrome/browser/sessions/session_service_factory.h"
31 #include "chrome/browser/sessions/tab_restore_service.h" 28 #include "chrome/browser/sessions/tab_restore_service.h"
32 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 29 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
(...skipping 13 matching lines...) Expand all
46 #include "chrome/browser/ui/find_bar/find_bar.h" 43 #include "chrome/browser/ui/find_bar/find_bar.h"
47 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 44 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
48 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 45 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
49 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 46 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
50 #include "chrome/browser/ui/location_bar/location_bar.h" 47 #include "chrome/browser/ui/location_bar/location_bar.h"
51 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 48 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
52 #include "chrome/browser/ui/search/search_tab_helper.h" 49 #include "chrome/browser/ui/search/search_tab_helper.h"
53 #include "chrome/browser/ui/status_bubble.h" 50 #include "chrome/browser/ui/status_bubble.h"
54 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 51 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
55 #include "chrome/browser/ui/tabs/tab_strip_model.h" 52 #include "chrome/browser/ui/tabs/tab_strip_model.h"
56 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
57 #include "chrome/browser/ui/zoom/zoom_controller.h" 53 #include "chrome/browser/ui/zoom/zoom_controller.h"
58 #include "chrome/browser/upgrade_detector.h" 54 #include "chrome/browser/upgrade_detector.h"
59 #include "chrome/browser/web_applications/web_app.h"
60 #include "chrome/common/chrome_switches.h" 55 #include "chrome/common/chrome_switches.h"
61 #include "chrome/common/chrome_version_info.h" 56 #include "chrome/common/chrome_version_info.h"
62 #include "chrome/common/content_restriction.h" 57 #include "chrome/common/content_restriction.h"
63 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
64 #include "chrome/common/pref_names.h" 58 #include "chrome/common/pref_names.h"
65 #include "components/bookmarks/browser/bookmark_model.h" 59 #include "components/bookmarks/browser/bookmark_model.h"
66 #include "components/bookmarks/browser/bookmark_utils.h" 60 #include "components/bookmarks/browser/bookmark_utils.h"
67 #include "components/google/core/browser/google_util.h" 61 #include "components/google/core/browser/google_util.h"
68 #include "components/translate/core/browser/language_state.h" 62 #include "components/translate/core/browser/language_state.h"
69 #include "components/web_modal/popup_manager.h" 63 #include "components/web_modal/popup_manager.h"
70 #include "content/public/browser/devtools_agent_host.h" 64 #include "content/public/browser/devtools_agent_host.h"
71 #include "content/public/browser/navigation_controller.h" 65 #include "content/public/browser/navigation_controller.h"
72 #include "content/public/browser/navigation_entry.h" 66 #include "content/public/browser/navigation_entry.h"
73 #include "content/public/browser/notification_service.h" 67 #include "content/public/browser/notification_service.h"
74 #include "content/public/browser/page_navigator.h" 68 #include "content/public/browser/page_navigator.h"
75 #include "content/public/browser/render_view_host.h" 69 #include "content/public/browser/render_view_host.h"
76 #include "content/public/browser/render_widget_host_view.h" 70 #include "content/public/browser/render_widget_host_view.h"
77 #include "content/public/browser/user_metrics.h" 71 #include "content/public/browser/user_metrics.h"
78 #include "content/public/browser/web_contents.h" 72 #include "content/public/browser/web_contents.h"
79 #include "content/public/common/renderer_preferences.h" 73 #include "content/public/common/renderer_preferences.h"
80 #include "content/public/common/url_constants.h" 74 #include "content/public/common/url_constants.h"
81 #include "content/public/common/url_utils.h" 75 #include "content/public/common/url_utils.h"
82 #include "content/public/common/user_agent.h" 76 #include "content/public/common/user_agent.h"
83 #include "net/base/escape.h" 77 #include "net/base/escape.h"
84 #include "ui/events/keycodes/keyboard_codes.h" 78 #include "ui/events/keycodes/keyboard_codes.h"
85 79
86 #if defined(OS_WIN) 80 #if defined(OS_WIN)
87 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" 81 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
88 #endif 82 #endif
89 83
90 #if defined(ENABLE_EXTENSIONS) 84 #if defined(ENABLE_EXTENSIONS)
85 #include "chrome/browser/extensions/api/commands/command_service.h"
86 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
87 #include "chrome/browser/extensions/tab_helper.h"
88 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
89 #include "chrome/browser/web_applications/web_app.h"
90 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
91 #include "extensions/browser/extension_registry.h" 91 #include "extensions/browser/extension_registry.h"
92 #include "extensions/browser/extension_system.h" 92 #include "extensions/browser/extension_system.h"
93 #include "extensions/common/extension.h" 93 #include "extensions/common/extension.h"
94 #include "extensions/common/extension_set.h" 94 #include "extensions/common/extension_set.h"
95 #endif 95 #endif
96 96
97 #if defined(ENABLE_PRINTING) 97 #if defined(ENABLE_PRINTING)
98 #if defined(ENABLE_FULL_PRINTING) 98 #if defined(ENABLE_FULL_PRINTING)
99 #include "chrome/browser/printing/print_preview_dialog_controller.h" 99 #include "chrome/browser/printing/print_preview_dialog_controller.h"
100 #include "chrome/browser/printing/print_view_manager.h" 100 #include "chrome/browser/printing/print_view_manager.h"
(...skipping 22 matching lines...) Expand all
123 BookmarkModel* model = 123 BookmarkModel* model =
124 BookmarkModelFactory::GetForProfile(browser->profile()); 124 BookmarkModelFactory::GetForProfile(browser->profile());
125 return browser_defaults::bookmarks_enabled && 125 return browser_defaults::bookmarks_enabled &&
126 browser->profile()->GetPrefs()->GetBoolean( 126 browser->profile()->GetPrefs()->GetBoolean(
127 bookmarks::prefs::kEditBookmarksEnabled) && 127 bookmarks::prefs::kEditBookmarksEnabled) &&
128 model && model->loaded() && browser->is_type_tabbed() && 128 model && model->loaded() && browser->is_type_tabbed() &&
129 (!check_remove_bookmark_ui || 129 (!check_remove_bookmark_ui ||
130 !chrome::ShouldRemoveBookmarkThisPageUI(browser->profile())); 130 !chrome::ShouldRemoveBookmarkThisPageUI(browser->profile()));
131 } 131 }
132 132
133 #if defined(ENABLE_EXTENSIONS)
133 bool GetBookmarkOverrideCommand( 134 bool GetBookmarkOverrideCommand(
134 Profile* profile, 135 Profile* profile,
135 const extensions::Extension** extension, 136 const extensions::Extension** extension,
136 extensions::Command* command, 137 extensions::Command* command,
137 extensions::CommandService::ExtensionCommandType* command_type) { 138 extensions::CommandService::ExtensionCommandType* command_type) {
138 #if defined(ENABLE_EXTENSIONS)
139 DCHECK(extension); 139 DCHECK(extension);
140 DCHECK(command); 140 DCHECK(command);
141 DCHECK(command_type); 141 DCHECK(command_type);
142 142
143 ui::Accelerator bookmark_page_accelerator = 143 ui::Accelerator bookmark_page_accelerator =
144 chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE); 144 chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE);
145 if (bookmark_page_accelerator.key_code() == ui::VKEY_UNKNOWN) 145 if (bookmark_page_accelerator.key_code() == ui::VKEY_UNKNOWN)
146 return false; 146 return false;
147 147
148 extensions::CommandService* command_service = 148 extensions::CommandService* command_service =
149 extensions::CommandService::Get(profile); 149 extensions::CommandService::Get(profile);
150 const extensions::ExtensionSet& extension_set = 150 const extensions::ExtensionSet& extension_set =
151 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 151 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
152 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); 152 for (extensions::ExtensionSet::const_iterator i = extension_set.begin();
153 i != extension_set.end(); 153 i != extension_set.end();
154 ++i) { 154 ++i) {
155 extensions::Command prospective_command; 155 extensions::Command prospective_command;
156 extensions::CommandService::ExtensionCommandType prospective_command_type; 156 extensions::CommandService::ExtensionCommandType prospective_command_type;
157 if (command_service->GetBoundExtensionCommand((*i)->id(), 157 if (command_service->GetBoundExtensionCommand((*i)->id(),
158 bookmark_page_accelerator, 158 bookmark_page_accelerator,
159 &prospective_command, 159 &prospective_command,
160 &prospective_command_type)) { 160 &prospective_command_type)) {
161 *extension = i->get(); 161 *extension = i->get();
162 *command = prospective_command; 162 *command = prospective_command;
163 *command_type = prospective_command_type; 163 *command_type = prospective_command_type;
164 return true; 164 return true;
165 } 165 }
166 } 166 }
167 #endif
168
169 return false; 167 return false;
170 } 168 }
169 #endif
171 170
172 void BookmarkCurrentPageInternal(Browser* browser) { 171 void BookmarkCurrentPageInternal(Browser* browser) {
173 content::RecordAction(UserMetricsAction("Star")); 172 content::RecordAction(UserMetricsAction("Star"));
174 173
175 BookmarkModel* model = 174 BookmarkModel* model =
176 BookmarkModelFactory::GetForProfile(browser->profile()); 175 BookmarkModelFactory::GetForProfile(browser->profile());
177 if (!model || !model->loaded()) 176 if (!model || !model->loaded())
178 return; // Ignore requests until bookmarks are loaded. 177 return; // Ignore requests until bookmarks are loaded.
179 178
180 GURL url; 179 GURL url;
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 737 }
739 738
740 void Exit() { 739 void Exit() {
741 content::RecordAction(UserMetricsAction("Exit")); 740 content::RecordAction(UserMetricsAction("Exit"));
742 chrome::AttemptUserExit(); 741 chrome::AttemptUserExit();
743 } 742 }
744 743
745 void BookmarkCurrentPage(Browser* browser) { 744 void BookmarkCurrentPage(Browser* browser) {
746 DCHECK(!chrome::ShouldRemoveBookmarkThisPageUI(browser->profile())); 745 DCHECK(!chrome::ShouldRemoveBookmarkThisPageUI(browser->profile()));
747 746
747 #if defined(ENABLE_EXTENSIONS)
748 const extensions::Extension* extension = NULL; 748 const extensions::Extension* extension = NULL;
749 extensions::Command command; 749 extensions::Command command;
750 extensions::CommandService::ExtensionCommandType command_type; 750 extensions::CommandService::ExtensionCommandType command_type;
751 if (GetBookmarkOverrideCommand(browser->profile(), 751 if (GetBookmarkOverrideCommand(browser->profile(),
752 &extension, 752 &extension,
753 &command, 753 &command,
754 &command_type)) { 754 &command_type)) {
755 switch (command_type) { 755 switch (command_type) {
756 case extensions::CommandService::NAMED: 756 case extensions::CommandService::NAMED:
757 browser->window()->ExecuteExtensionCommand(extension, command); 757 browser->window()->ExecuteExtensionCommand(extension, command);
758 break; 758 break;
759 case extensions::CommandService::BROWSER_ACTION: 759 case extensions::CommandService::BROWSER_ACTION:
760 case extensions::CommandService::PAGE_ACTION: 760 case extensions::CommandService::PAGE_ACTION:
761 // BookmarkCurrentPage is called through a user gesture, so it is safe 761 // BookmarkCurrentPage is called through a user gesture, so it is safe
762 // to grant the active tab permission. 762 // to grant the active tab permission.
763 extensions::ExtensionActionAPI::Get(browser->profile())-> 763 extensions::ExtensionActionAPI::Get(browser->profile())->
764 ShowExtensionActionPopup(extension, browser, true); 764 ShowExtensionActionPopup(extension, browser, true);
765 break; 765 break;
766 } 766 }
767 return; 767 return;
768 } 768 }
769 #endif
769 770
770 BookmarkCurrentPageInternal(browser); 771 BookmarkCurrentPageInternal(browser);
771 } 772 }
772 773
773 bool CanBookmarkCurrentPage(const Browser* browser) { 774 bool CanBookmarkCurrentPage(const Browser* browser) {
774 return CanBookmarkCurrentPageInternal(browser, true); 775 return CanBookmarkCurrentPageInternal(browser, true);
775 } 776 }
776 777
777 void BookmarkAllTabs(Browser* browser) { 778 void BookmarkAllTabs(Browser* browser) {
778 chrome::ShowBookmarkAllTabsDialog(browser); 779 chrome::ShowBookmarkAllTabsDialog(browser);
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 void ViewSelectedSource(Browser* browser) { 1236 void ViewSelectedSource(Browser* browser) {
1236 ViewSource(browser, browser->tab_strip_model()->GetActiveWebContents()); 1237 ViewSource(browser, browser->tab_strip_model()->GetActiveWebContents());
1237 } 1238 }
1238 1239
1239 bool CanViewSource(const Browser* browser) { 1240 bool CanViewSource(const Browser* browser) {
1240 return !browser->is_devtools() && 1241 return !browser->is_devtools() &&
1241 browser->tab_strip_model()->GetActiveWebContents()->GetController(). 1242 browser->tab_strip_model()->GetActiveWebContents()->GetController().
1242 CanViewSource(); 1243 CanViewSource();
1243 } 1244 }
1244 1245
1246 #if defined(ENABLE_EXTENSIONS)
1245 void CreateApplicationShortcuts(Browser* browser) { 1247 void CreateApplicationShortcuts(Browser* browser) {
1246 content::RecordAction(UserMetricsAction("CreateShortcut")); 1248 content::RecordAction(UserMetricsAction("CreateShortcut"));
1247 extensions::TabHelper::FromWebContents( 1249 extensions::TabHelper::FromWebContents(
1248 browser->tab_strip_model()->GetActiveWebContents())-> 1250 browser->tab_strip_model()->GetActiveWebContents())->
1249 CreateApplicationShortcuts(); 1251 CreateApplicationShortcuts();
1250 } 1252 }
1251 1253
1252 void CreateBookmarkAppFromCurrentWebContents(Browser* browser) { 1254 void CreateBookmarkAppFromCurrentWebContents(Browser* browser) {
1253 content::RecordAction(UserMetricsAction("CreateHostedApp")); 1255 content::RecordAction(UserMetricsAction("CreateHostedApp"));
1254 extensions::TabHelper::FromWebContents( 1256 extensions::TabHelper::FromWebContents(
(...skipping 27 matching lines...) Expand all
1282 true /* trusted_source */, 1284 true /* trusted_source */,
1283 gfx::Rect(), 1285 gfx::Rect(),
1284 browser->profile(), 1286 browser->profile(),
1285 browser->host_desktop_type())); 1287 browser->host_desktop_type()));
1286 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1288 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1287 1289
1288 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1290 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1289 contents->GetRenderViewHost()->SyncRendererPrefs(); 1291 contents->GetRenderViewHost()->SyncRendererPrefs();
1290 app_browser->window()->Show(); 1292 app_browser->window()->Show();
1291 } 1293 }
1294 #endif // defined(ENABLE_EXTENSIONS)
1292 1295
1293 } // namespace chrome 1296 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_navigator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698