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.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" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE); | 186 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE); |
187 return new_tab; | 187 return new_tab; |
188 } | 188 } |
189 case NEW_WINDOW: { | 189 case NEW_WINDOW: { |
190 WebContents* new_tab = current_tab->Clone(); | 190 WebContents* new_tab = current_tab->Clone(); |
191 Browser* new_browser = new Browser(Browser::CreateParams( | 191 Browser* new_browser = new Browser(Browser::CreateParams( |
192 browser->profile(), browser->host_desktop_type())); | 192 browser->profile(), browser->host_desktop_type())); |
193 new_browser->tab_strip_model()->AddWebContents( | 193 new_browser->tab_strip_model()->AddWebContents( |
194 new_tab, -1, ui::PAGE_TRANSITION_LINK, | 194 new_tab, -1, ui::PAGE_TRANSITION_LINK, |
195 TabStripModel::ADD_ACTIVE); | 195 TabStripModel::ADD_ACTIVE); |
196 new_browser->window()->Show(); | 196 new_browser->window()->Show(true /* user_gesture */); |
197 return new_tab; | 197 return new_tab; |
198 } | 198 } |
199 default: | 199 default: |
200 browser->window()->GetLocationBar()->Revert(); | 200 browser->window()->GetLocationBar()->Revert(); |
201 return current_tab; | 201 return current_tab; |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 void ReloadInternal(Browser* browser, | 205 void ReloadInternal(Browser* browser, |
206 WindowOpenDisposition disposition, | 206 WindowOpenDisposition disposition, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 !session_service->RestoreIfNecessary(std::vector<GURL>())) { | 339 !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
340 OpenEmptyWindow(profile->GetOriginalProfile(), desktop_type); | 340 OpenEmptyWindow(profile->GetOriginalProfile(), desktop_type); |
341 } | 341 } |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 Browser* OpenEmptyWindow(Profile* profile, HostDesktopType desktop_type) { | 345 Browser* OpenEmptyWindow(Profile* profile, HostDesktopType desktop_type) { |
346 Browser* browser = new Browser( | 346 Browser* browser = new Browser( |
347 Browser::CreateParams(Browser::TYPE_TABBED, profile, desktop_type)); | 347 Browser::CreateParams(Browser::TYPE_TABBED, profile, desktop_type)); |
348 AddTabAt(browser, GURL(), -1, true); | 348 AddTabAt(browser, GURL(), -1, true); |
349 browser->window()->Show(); | 349 browser->window()->Show(true /* user_gesture */); |
350 return browser; | 350 return browser; |
351 } | 351 } |
352 | 352 |
353 void OpenWindowWithRestoredTabs(Profile* profile, | 353 void OpenWindowWithRestoredTabs(Profile* profile, |
354 HostDesktopType host_desktop_type) { | 354 HostDesktopType host_desktop_type) { |
355 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); | 355 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); |
356 if (service) | 356 if (service) |
357 service->RestoreMostRecentEntry(NULL, host_desktop_type); | 357 service->RestoreMostRecentEntry(NULL, host_desktop_type); |
358 } | 358 } |
359 | 359 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 TabStripModel::NEW_TAB_ENUM_COUNT); | 545 TabStripModel::NEW_TAB_ENUM_COUNT); |
546 | 546 |
547 if (browser->is_type_tabbed()) { | 547 if (browser->is_type_tabbed()) { |
548 AddTabAt(browser, GURL(), -1, true); | 548 AddTabAt(browser, GURL(), -1, true); |
549 browser->tab_strip_model()->GetActiveWebContents()->RestoreFocus(); | 549 browser->tab_strip_model()->GetActiveWebContents()->RestoreFocus(); |
550 } else { | 550 } else { |
551 ScopedTabbedBrowserDisplayer displayer(browser->profile(), | 551 ScopedTabbedBrowserDisplayer displayer(browser->profile(), |
552 browser->host_desktop_type()); | 552 browser->host_desktop_type()); |
553 Browser* b = displayer.browser(); | 553 Browser* b = displayer.browser(); |
554 AddTabAt(b, GURL(), -1, true); | 554 AddTabAt(b, GURL(), -1, true); |
555 b->window()->Show(); | 555 // TODO(johnme): Pass true to |Show| for user-initiated commands. |
| 556 b->window()->Show(false /* user_gesture */); |
556 // The call to AddBlankTabAt above did not set the focus to the tab as its | 557 // The call to AddBlankTabAt above did not set the focus to the tab as its |
557 // window was not active, so we have to do it explicitly. | 558 // window was not active, so we have to do it explicitly. |
558 // See http://crbug.com/6380. | 559 // See http://crbug.com/6380. |
559 b->tab_strip_model()->GetActiveWebContents()->RestoreFocus(); | 560 b->tab_strip_model()->GetActiveWebContents()->RestoreFocus(); |
560 } | 561 } |
561 } | 562 } |
562 | 563 |
563 void CloseTab(Browser* browser) { | 564 void CloseTab(Browser* browser) { |
564 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); | 565 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); |
565 browser->tab_strip_model()->CloseSelectedTabs(); | 566 browser->tab_strip_model()->CloseSelectedTabs(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 browser->host_desktop_type())); | 670 browser->host_desktop_type())); |
670 } | 671 } |
671 // Preserve the size of the original window. The new window has already | 672 // Preserve the size of the original window. The new window has already |
672 // been given an offset by the OS, so we shouldn't copy the old bounds. | 673 // been given an offset by the OS, so we shouldn't copy the old bounds. |
673 BrowserWindow* new_window = new_browser->window(); | 674 BrowserWindow* new_window = new_browser->window(); |
674 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 675 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
675 browser->window()->GetRestoredBounds().size())); | 676 browser->window()->GetRestoredBounds().size())); |
676 | 677 |
677 // We need to show the browser now. Otherwise ContainerWin assumes the | 678 // We need to show the browser now. Otherwise ContainerWin assumes the |
678 // WebContents is invisible and won't size it. | 679 // WebContents is invisible and won't size it. |
679 new_browser->window()->Show(); | 680 // TODO(johnme): Pass true to |Show| for user-initiated commands. |
| 681 new_browser->window()->Show(false /* user_gesture */); |
680 | 682 |
681 // The page transition below is only for the purpose of inserting the tab. | 683 // The page transition below is only for the purpose of inserting the tab. |
682 new_browser->tab_strip_model()->AddWebContents( | 684 new_browser->tab_strip_model()->AddWebContents( |
683 contents_dupe, -1, | 685 contents_dupe, -1, |
684 ui::PAGE_TRANSITION_LINK, | 686 ui::PAGE_TRANSITION_LINK, |
685 TabStripModel::ADD_ACTIVE); | 687 TabStripModel::ADD_ACTIVE); |
686 } | 688 } |
687 | 689 |
688 SessionService* session_service = | 690 SessionService* session_service = |
689 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 691 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
690 if (session_service) | 692 if (session_service) |
691 session_service->TabRestored(contents_dupe, pinned); | 693 session_service->TabRestored(contents_dupe, pinned); |
692 return contents_dupe; | 694 return contents_dupe; |
693 } | 695 } |
694 | 696 |
695 bool CanDuplicateTabAt(Browser* browser, int index) { | 697 bool CanDuplicateTabAt(Browser* browser, int index) { |
696 content::NavigationController& nc = | 698 content::NavigationController& nc = |
697 browser->tab_strip_model()->GetWebContentsAt(index)->GetController(); | 699 browser->tab_strip_model()->GetWebContentsAt(index)->GetController(); |
698 return nc.GetWebContents() && nc.GetLastCommittedEntry(); | 700 return nc.GetWebContents() && nc.GetLastCommittedEntry(); |
699 } | 701 } |
700 | 702 |
701 void ConvertPopupToTabbedBrowser(Browser* browser) { | 703 void ConvertPopupToTabbedBrowser(Browser* browser) { |
702 content::RecordAction(UserMetricsAction("ShowAsTab")); | 704 content::RecordAction(UserMetricsAction("ShowAsTab")); |
703 TabStripModel* tab_strip = browser->tab_strip_model(); | 705 TabStripModel* tab_strip = browser->tab_strip_model(); |
704 WebContents* contents = | 706 WebContents* contents = |
705 tab_strip->DetachWebContentsAt(tab_strip->active_index()); | 707 tab_strip->DetachWebContentsAt(tab_strip->active_index()); |
706 Browser* b = new Browser(Browser::CreateParams(browser->profile(), | 708 Browser* b = new Browser(Browser::CreateParams(browser->profile(), |
707 browser->host_desktop_type())); | 709 browser->host_desktop_type())); |
708 b->tab_strip_model()->AppendWebContents(contents, true); | 710 b->tab_strip_model()->AppendWebContents(contents, true); |
709 b->window()->Show(); | 711 b->window()->Show(true /* user_gesture */); |
710 } | 712 } |
711 | 713 |
712 void Exit() { | 714 void Exit() { |
713 content::RecordAction(UserMetricsAction("Exit")); | 715 content::RecordAction(UserMetricsAction("Exit")); |
714 chrome::AttemptUserExit(); | 716 chrome::AttemptUserExit(); |
715 } | 717 } |
716 | 718 |
717 void BookmarkCurrentPageIgnoringExtensionOverrides(Browser* browser) { | 719 void BookmarkCurrentPageIgnoringExtensionOverrides(Browser* browser) { |
718 content::RecordAction(UserMetricsAction("Star")); | 720 content::RecordAction(UserMetricsAction("Star")); |
719 | 721 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 browser->host_desktop_type())); | 1202 browser->host_desktop_type())); |
1201 | 1203 |
1202 // Preserve the size of the original window. The new window has already | 1204 // Preserve the size of the original window. The new window has already |
1203 // been given an offset by the OS, so we shouldn't copy the old bounds. | 1205 // been given an offset by the OS, so we shouldn't copy the old bounds. |
1204 BrowserWindow* new_window = b->window(); | 1206 BrowserWindow* new_window = b->window(); |
1205 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 1207 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
1206 browser->window()->GetRestoredBounds().size())); | 1208 browser->window()->GetRestoredBounds().size())); |
1207 | 1209 |
1208 // We need to show the browser now. Otherwise ContainerWin assumes the | 1210 // We need to show the browser now. Otherwise ContainerWin assumes the |
1209 // WebContents is invisible and won't size it. | 1211 // WebContents is invisible and won't size it. |
1210 b->window()->Show(); | 1212 b->window()->Show(true /* user_gesture */); |
1211 | 1213 |
1212 // The page transition below is only for the purpose of inserting the tab. | 1214 // The page transition below is only for the purpose of inserting the tab. |
1213 b->tab_strip_model()->AddWebContents(view_source_contents, -1, | 1215 b->tab_strip_model()->AddWebContents(view_source_contents, -1, |
1214 ui::PAGE_TRANSITION_LINK, | 1216 ui::PAGE_TRANSITION_LINK, |
1215 TabStripModel::ADD_ACTIVE); | 1217 TabStripModel::ADD_ACTIVE); |
1216 } | 1218 } |
1217 | 1219 |
1218 SessionService* session_service = | 1220 SessionService* session_service = |
1219 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 1221 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
1220 if (session_service) | 1222 if (session_service) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 Browser* app_browser = new Browser( | 1272 Browser* app_browser = new Browser( |
1271 Browser::CreateParams::CreateForApp(app_name, | 1273 Browser::CreateParams::CreateForApp(app_name, |
1272 true /* trusted_source */, | 1274 true /* trusted_source */, |
1273 gfx::Rect(), | 1275 gfx::Rect(), |
1274 browser->profile(), | 1276 browser->profile(), |
1275 browser->host_desktop_type())); | 1277 browser->host_desktop_type())); |
1276 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1278 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
1277 | 1279 |
1278 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1280 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1279 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1281 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1280 app_browser->window()->Show(); | 1282 app_browser->window()->Show(true /* user_gesture */); |
1281 } | 1283 } |
1282 #endif // defined(ENABLE_EXTENSIONS) | 1284 #endif // defined(ENABLE_EXTENSIONS) |
1283 | 1285 |
1284 } // namespace chrome | 1286 } // namespace chrome |
OLD | NEW |