OLD | NEW |
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_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 #include "content/public/browser/page_navigator.h" | 76 #include "content/public/browser/page_navigator.h" |
77 #include "content/public/browser/render_view_host.h" | 77 #include "content/public/browser/render_view_host.h" |
78 #include "content/public/browser/render_widget_host_view.h" | 78 #include "content/public/browser/render_widget_host_view.h" |
79 #include "content/public/browser/user_metrics.h" | 79 #include "content/public/browser/user_metrics.h" |
80 #include "content/public/browser/web_contents.h" | 80 #include "content/public/browser/web_contents.h" |
81 #include "content/public/common/page_state.h" | 81 #include "content/public/common/page_state.h" |
82 #include "content/public/common/renderer_preferences.h" | 82 #include "content/public/common/renderer_preferences.h" |
83 #include "content/public/common/url_constants.h" | 83 #include "content/public/common/url_constants.h" |
84 #include "content/public/common/url_utils.h" | 84 #include "content/public/common/url_utils.h" |
85 #include "content/public/common/user_agent.h" | 85 #include "content/public/common/user_agent.h" |
| 86 #include "extensions/features/features.h" |
86 #include "net/base/escape.h" | 87 #include "net/base/escape.h" |
87 #include "printing/features/features.h" | 88 #include "printing/features/features.h" |
88 #include "ui/events/keycodes/keyboard_codes.h" | 89 #include "ui/events/keycodes/keyboard_codes.h" |
89 | 90 |
90 #if defined(ENABLE_EXTENSIONS) | 91 #if BUILDFLAG(ENABLE_EXTENSIONS) |
91 #include "chrome/browser/extensions/api/commands/command_service.h" | 92 #include "chrome/browser/extensions/api/commands/command_service.h" |
92 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 93 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
93 #include "chrome/browser/extensions/tab_helper.h" | 94 #include "chrome/browser/extensions/tab_helper.h" |
94 #include "chrome/browser/ui/extensions/settings_api_bubble_helpers.h" | 95 #include "chrome/browser/ui/extensions/settings_api_bubble_helpers.h" |
95 #include "chrome/browser/web_applications/web_app.h" | 96 #include "chrome/browser/web_applications/web_app.h" |
96 #include "chrome/common/extensions/extension_metrics.h" | 97 #include "chrome/common/extensions/extension_metrics.h" |
97 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 98 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
98 #include "extensions/browser/extension_registry.h" | 99 #include "extensions/browser/extension_registry.h" |
99 #include "extensions/browser/extension_system.h" | 100 #include "extensions/browser/extension_system.h" |
100 #include "extensions/common/extension.h" | 101 #include "extensions/common/extension.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 BookmarkModel* model = | 137 BookmarkModel* model = |
137 BookmarkModelFactory::GetForBrowserContext(browser->profile()); | 138 BookmarkModelFactory::GetForBrowserContext(browser->profile()); |
138 return browser_defaults::bookmarks_enabled && | 139 return browser_defaults::bookmarks_enabled && |
139 browser->profile()->GetPrefs()->GetBoolean( | 140 browser->profile()->GetPrefs()->GetBoolean( |
140 bookmarks::prefs::kEditBookmarksEnabled) && | 141 bookmarks::prefs::kEditBookmarksEnabled) && |
141 model && model->loaded() && browser->is_type_tabbed() && | 142 model && model->loaded() && browser->is_type_tabbed() && |
142 (!check_remove_bookmark_ui || | 143 (!check_remove_bookmark_ui || |
143 !chrome::ShouldRemoveBookmarkThisPageUI(browser->profile())); | 144 !chrome::ShouldRemoveBookmarkThisPageUI(browser->profile())); |
144 } | 145 } |
145 | 146 |
146 #if defined(ENABLE_EXTENSIONS) | 147 #if BUILDFLAG(ENABLE_EXTENSIONS) |
147 bool GetBookmarkOverrideCommand( | 148 bool GetBookmarkOverrideCommand( |
148 Profile* profile, | 149 Profile* profile, |
149 const extensions::Extension** extension, | 150 const extensions::Extension** extension, |
150 extensions::Command* command, | 151 extensions::Command* command, |
151 extensions::CommandService::ExtensionCommandType* command_type) { | 152 extensions::CommandService::ExtensionCommandType* command_type) { |
152 DCHECK(extension); | 153 DCHECK(extension); |
153 DCHECK(command); | 154 DCHECK(command); |
154 DCHECK(command_type); | 155 DCHECK(command_type); |
155 | 156 |
156 ui::Accelerator bookmark_page_accelerator = | 157 ui::Accelerator bookmark_page_accelerator = |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 if (google_util::IsGoogleHomePageUrl( | 451 if (google_util::IsGoogleHomePageUrl( |
451 GURL(pref_service->GetString(prefs::kHomePage)))) { | 452 GURL(pref_service->GetString(prefs::kHomePage)))) { |
452 extra_headers = rlz::RLZTracker::GetAccessPointHttpHeader( | 453 extra_headers = rlz::RLZTracker::GetAccessPointHttpHeader( |
453 rlz::RLZTracker::ChromeHomePage()); | 454 rlz::RLZTracker::ChromeHomePage()); |
454 } | 455 } |
455 } | 456 } |
456 #endif // defined(ENABLE_RLZ) | 457 #endif // defined(ENABLE_RLZ) |
457 | 458 |
458 GURL url = browser->profile()->GetHomePage(); | 459 GURL url = browser->profile()->GetHomePage(); |
459 | 460 |
460 #if defined(ENABLE_EXTENSIONS) | 461 #if BUILDFLAG(ENABLE_EXTENSIONS) |
461 // With bookmark apps enabled, hosted apps should return to their launch page | 462 // With bookmark apps enabled, hosted apps should return to their launch page |
462 // when the home button is pressed. | 463 // when the home button is pressed. |
463 if (browser->is_app()) { | 464 if (browser->is_app()) { |
464 const extensions::Extension* extension = | 465 const extensions::Extension* extension = |
465 extensions::ExtensionRegistry::Get(browser->profile()) | 466 extensions::ExtensionRegistry::Get(browser->profile()) |
466 ->GetExtensionById( | 467 ->GetExtensionById( |
467 web_app::GetExtensionIdFromApplicationName(browser->app_name()), | 468 web_app::GetExtensionIdFromApplicationName(browser->app_name()), |
468 extensions::ExtensionRegistry::EVERYTHING); | 469 extensions::ExtensionRegistry::EVERYTHING); |
469 if (!extension) | 470 if (!extension) |
470 return; | 471 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 NavigateParams params(browser, url, page_transition); | 517 NavigateParams params(browser, url, page_transition); |
517 params.disposition = open_disposition; | 518 params.disposition = open_disposition; |
518 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least | 519 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least |
519 // inherit the opener. In some cases the tabstrip will determine the group | 520 // inherit the opener. In some cases the tabstrip will determine the group |
520 // should be inherited, in which case the group is inherited instead of the | 521 // should be inherited, in which case the group is inherited instead of the |
521 // opener. | 522 // opener. |
522 params.tabstrip_add_types = | 523 params.tabstrip_add_types = |
523 TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; | 524 TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; |
524 Navigate(¶ms); | 525 Navigate(¶ms); |
525 | 526 |
526 #if defined(ENABLE_EXTENSIONS) | 527 #if BUILDFLAG(ENABLE_EXTENSIONS) |
527 DCHECK(extensions::ExtensionSystem::Get( | 528 DCHECK(extensions::ExtensionSystem::Get( |
528 browser->profile())->extension_service()); | 529 browser->profile())->extension_service()); |
529 const extensions::Extension* extension = | 530 const extensions::Extension* extension = |
530 extensions::ExtensionRegistry::Get(browser->profile()) | 531 extensions::ExtensionRegistry::Get(browser->profile()) |
531 ->enabled_extensions().GetAppByURL(url); | 532 ->enabled_extensions().GetAppByURL(url); |
532 if (extension) { | 533 if (extension) { |
533 extensions::RecordAppLaunchType(extension_misc::APP_LAUNCH_OMNIBOX_LOCATION, | 534 extensions::RecordAppLaunchType(extension_misc::APP_LAUNCH_OMNIBOX_LOCATION, |
534 extension->GetType()); | 535 extension->GetType()); |
535 } | 536 } |
536 #endif | 537 #endif |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 if (browser->window()->IsActive() && is_bookmarked_by_user) { | 756 if (browser->window()->IsActive() && is_bookmarked_by_user) { |
756 // Only show the bubble if the window is active, otherwise we may get into | 757 // Only show the bubble if the window is active, otherwise we may get into |
757 // weird situations where the bubble is deleted as soon as it is shown. | 758 // weird situations where the bubble is deleted as soon as it is shown. |
758 browser->window()->ShowBookmarkBubble(url, was_bookmarked_by_user); | 759 browser->window()->ShowBookmarkBubble(url, was_bookmarked_by_user); |
759 } | 760 } |
760 } | 761 } |
761 | 762 |
762 void BookmarkCurrentPageAllowingExtensionOverrides(Browser* browser) { | 763 void BookmarkCurrentPageAllowingExtensionOverrides(Browser* browser) { |
763 DCHECK(!chrome::ShouldRemoveBookmarkThisPageUI(browser->profile())); | 764 DCHECK(!chrome::ShouldRemoveBookmarkThisPageUI(browser->profile())); |
764 | 765 |
765 #if defined(ENABLE_EXTENSIONS) | 766 #if BUILDFLAG(ENABLE_EXTENSIONS) |
766 const extensions::Extension* extension = NULL; | 767 const extensions::Extension* extension = NULL; |
767 extensions::Command command; | 768 extensions::Command command; |
768 extensions::CommandService::ExtensionCommandType command_type; | 769 extensions::CommandService::ExtensionCommandType command_type; |
769 if (GetBookmarkOverrideCommand(browser->profile(), | 770 if (GetBookmarkOverrideCommand(browser->profile(), |
770 &extension, | 771 &extension, |
771 &command, | 772 &command, |
772 &command_type)) { | 773 &command_type)) { |
773 switch (command_type) { | 774 switch (command_type) { |
774 case extensions::CommandService::NAMED: | 775 case extensions::CommandService::NAMED: |
775 browser->window()->ExecuteExtensionCommand(extension, command); | 776 browser->window()->ExecuteExtensionCommand(extension, command); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 void ViewSelectedSource(Browser* browser) { | 1252 void ViewSelectedSource(Browser* browser) { |
1252 ViewSource(browser, browser->tab_strip_model()->GetActiveWebContents()); | 1253 ViewSource(browser, browser->tab_strip_model()->GetActiveWebContents()); |
1253 } | 1254 } |
1254 | 1255 |
1255 bool CanViewSource(const Browser* browser) { | 1256 bool CanViewSource(const Browser* browser) { |
1256 return !browser->is_devtools() && | 1257 return !browser->is_devtools() && |
1257 browser->tab_strip_model()->GetActiveWebContents()->GetController(). | 1258 browser->tab_strip_model()->GetActiveWebContents()->GetController(). |
1258 CanViewSource(); | 1259 CanViewSource(); |
1259 } | 1260 } |
1260 | 1261 |
1261 #if defined(ENABLE_EXTENSIONS) | 1262 #if BUILDFLAG(ENABLE_EXTENSIONS) |
1262 void CreateApplicationShortcuts(Browser* browser) { | 1263 void CreateApplicationShortcuts(Browser* browser) { |
1263 content::RecordAction(UserMetricsAction("CreateShortcut")); | 1264 content::RecordAction(UserMetricsAction("CreateShortcut")); |
1264 extensions::TabHelper::FromWebContents( | 1265 extensions::TabHelper::FromWebContents( |
1265 browser->tab_strip_model()->GetActiveWebContents())-> | 1266 browser->tab_strip_model()->GetActiveWebContents())-> |
1266 CreateApplicationShortcuts(); | 1267 CreateApplicationShortcuts(); |
1267 } | 1268 } |
1268 | 1269 |
1269 void CreateBookmarkAppFromCurrentWebContents(Browser* browser) { | 1270 void CreateBookmarkAppFromCurrentWebContents(Browser* browser) { |
1270 content::RecordAction(UserMetricsAction("CreateHostedApp")); | 1271 content::RecordAction(UserMetricsAction("CreateHostedApp")); |
1271 extensions::TabHelper::FromWebContents( | 1272 extensions::TabHelper::FromWebContents( |
(...skipping 23 matching lines...) Expand all Loading... |
1295 browser->tab_strip_model()->DetachWebContentsAt(index); | 1296 browser->tab_strip_model()->DetachWebContentsAt(index); |
1296 | 1297 |
1297 Browser* app_browser = new Browser(Browser::CreateParams::CreateForApp( | 1298 Browser* app_browser = new Browser(Browser::CreateParams::CreateForApp( |
1298 app_name, true /* trusted_source */, gfx::Rect(), browser->profile())); | 1299 app_name, true /* trusted_source */, gfx::Rect(), browser->profile())); |
1299 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1300 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
1300 | 1301 |
1301 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1302 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1302 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1303 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1303 app_browser->window()->Show(); | 1304 app_browser->window()->Show(); |
1304 } | 1305 } |
1305 #endif // defined(ENABLE_EXTENSIONS) | 1306 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
1306 | 1307 |
1307 } // namespace chrome | 1308 } // namespace chrome |
OLD | NEW |