| OLD | NEW |
| 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/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 #include "chrome/browser/tab_contents/retargeting_details.h" | 95 #include "chrome/browser/tab_contents/retargeting_details.h" |
| 96 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 96 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
| 97 #include "chrome/browser/tab_contents/tab_util.h" | 97 #include "chrome/browser/tab_contents/tab_util.h" |
| 98 #include "chrome/browser/themes/theme_service.h" | 98 #include "chrome/browser/themes/theme_service.h" |
| 99 #include "chrome/browser/themes/theme_service_factory.h" | 99 #include "chrome/browser/themes/theme_service_factory.h" |
| 100 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 100 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 101 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 101 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 102 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 102 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 103 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 103 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
| 104 #include "chrome/browser/ui/browser_dialogs.h" | 104 #include "chrome/browser/ui/browser_dialogs.h" |
| 105 #include "chrome/browser/ui/browser_finder.h" |
| 105 #include "chrome/browser/ui/browser_list.h" | 106 #include "chrome/browser/ui/browser_list.h" |
| 106 #include "chrome/browser/ui/browser_navigator.h" | 107 #include "chrome/browser/ui/browser_navigator.h" |
| 107 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 108 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
| 108 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" | 109 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" |
| 109 #include "chrome/browser/ui/browser_window.h" | 110 #include "chrome/browser/ui/browser_window.h" |
| 110 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 111 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 111 #include "chrome/browser/ui/extensions/shell_window.h" | 112 #include "chrome/browser/ui/extensions/shell_window.h" |
| 112 #include "chrome/browser/ui/find_bar/find_bar.h" | 113 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 113 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 114 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 114 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 115 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 SessionServiceFactory::GetForProfile(profile_); | 487 SessionServiceFactory::GetForProfile(profile_); |
| 487 if (session_service) | 488 if (session_service) |
| 488 session_service->WindowClosed(session_id_); | 489 session_service->WindowClosed(session_id_); |
| 489 | 490 |
| 490 TabRestoreService* tab_restore_service = | 491 TabRestoreService* tab_restore_service = |
| 491 TabRestoreServiceFactory::GetForProfile(profile()); | 492 TabRestoreServiceFactory::GetForProfile(profile()); |
| 492 if (tab_restore_service) | 493 if (tab_restore_service) |
| 493 tab_restore_service->BrowserClosed(tab_restore_service_delegate()); | 494 tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
| 494 | 495 |
| 495 #if !defined(OS_MACOSX) | 496 #if !defined(OS_MACOSX) |
| 496 if (!BrowserList::HasBrowserWithProfile(profile_)) { | 497 if (!browser::GetBrowserCount(profile_)) { |
| 497 // We're the last browser window with this profile. We need to nuke the | 498 // We're the last browser window with this profile. We need to nuke the |
| 498 // TabRestoreService, which will start the shutdown of the | 499 // TabRestoreService, which will start the shutdown of the |
| 499 // NavigationControllers and allow for proper shutdown. If we don't do this | 500 // NavigationControllers and allow for proper shutdown. If we don't do this |
| 500 // chrome won't shutdown cleanly, and may end up crashing when some | 501 // chrome won't shutdown cleanly, and may end up crashing when some |
| 501 // thread tries to use the IO thread (or another thread) that is no longer | 502 // thread tries to use the IO thread (or another thread) that is no longer |
| 502 // valid. | 503 // valid. |
| 503 // This isn't a valid assumption for Mac OS, as it stays running after | 504 // This isn't a valid assumption for Mac OS, as it stays running after |
| 504 // the last browser has closed. The Mac equivalent is in its app | 505 // the last browser has closed. The Mac equivalent is in its app |
| 505 // controller. | 506 // controller. |
| 506 TabRestoreServiceFactory::ResetForProfile(profile_); | 507 TabRestoreServiceFactory::ResetForProfile(profile_); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 674 |
| 674 // static | 675 // static |
| 675 void Browser::OpenWindowWithRestoredTabs(Profile* profile) { | 676 void Browser::OpenWindowWithRestoredTabs(Profile* profile) { |
| 676 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); | 677 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); |
| 677 if (service) | 678 if (service) |
| 678 service->RestoreMostRecentEntry(NULL); | 679 service->RestoreMostRecentEntry(NULL); |
| 679 } | 680 } |
| 680 | 681 |
| 681 // static | 682 // static |
| 682 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { | 683 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
| 683 Browser* browser = GetOrCreateTabbedBrowser( | 684 Browser* browser = browser::FindOrCreateTabbedBrowser( |
| 684 profile->GetOffTheRecordProfile()); | 685 profile->GetOffTheRecordProfile()); |
| 685 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); | 686 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); |
| 686 browser->window()->Show(); | 687 browser->window()->Show(); |
| 687 } | 688 } |
| 688 | 689 |
| 689 // static | 690 // static |
| 690 WebContents* Browser::OpenApplication( | 691 WebContents* Browser::OpenApplication( |
| 691 Profile* profile, | 692 Profile* profile, |
| 692 const Extension* extension, | 693 const Extension* extension, |
| 693 extension_misc::LaunchContainer container, | 694 extension_misc::LaunchContainer container, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; | 848 app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
| 848 } | 849 } |
| 849 return tab; | 850 return tab; |
| 850 } | 851 } |
| 851 | 852 |
| 852 // static | 853 // static |
| 853 WebContents* Browser::OpenApplicationTab(Profile* profile, | 854 WebContents* Browser::OpenApplicationTab(Profile* profile, |
| 854 const Extension* extension, | 855 const Extension* extension, |
| 855 const GURL& override_url, | 856 const GURL& override_url, |
| 856 WindowOpenDisposition disposition) { | 857 WindowOpenDisposition disposition) { |
| 857 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); | 858 Browser* browser = browser::FindTabbedBrowser(profile, false); |
| 858 WebContents* contents = NULL; | 859 WebContents* contents = NULL; |
| 859 if (!browser) { | 860 if (!browser) { |
| 860 // No browser for this profile, need to open a new one. | 861 // No browser for this profile, need to open a new one. |
| 861 browser = Browser::Create(profile); | 862 browser = Browser::Create(profile); |
| 862 browser->window()->Show(); | 863 browser->window()->Show(); |
| 863 // There's no current tab in this browser window, so add a new one. | 864 // There's no current tab in this browser window, so add a new one. |
| 864 disposition = NEW_FOREGROUND_TAB; | 865 disposition = NEW_FOREGROUND_TAB; |
| 865 } else { | 866 } else { |
| 866 // For existing browser, ensure its window is activated. | 867 // For existing browser, ensure its window is activated. |
| 867 browser->window()->Activate(); | 868 browser->window()->Activate(); |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 window_->Close(); | 1674 window_->Close(); |
| 1674 } | 1675 } |
| 1675 | 1676 |
| 1676 void Browser::NewTab() { | 1677 void Browser::NewTab() { |
| 1677 content::RecordAction(UserMetricsAction("NewTab")); | 1678 content::RecordAction(UserMetricsAction("NewTab")); |
| 1678 | 1679 |
| 1679 if (is_type_tabbed()) { | 1680 if (is_type_tabbed()) { |
| 1680 AddBlankTab(true); | 1681 AddBlankTab(true); |
| 1681 GetSelectedWebContents()->GetView()->RestoreFocus(); | 1682 GetSelectedWebContents()->GetView()->RestoreFocus(); |
| 1682 } else { | 1683 } else { |
| 1683 Browser* b = GetOrCreateTabbedBrowser(profile_); | 1684 Browser* b = browser::FindOrCreateTabbedBrowser(profile_); |
| 1684 b->AddBlankTab(true); | 1685 b->AddBlankTab(true); |
| 1685 b->window()->Show(); | 1686 b->window()->Show(); |
| 1686 // The call to AddBlankTab above did not set the focus to the tab as its | 1687 // The call to AddBlankTab above did not set the focus to the tab as its |
| 1687 // window was not active, so we have to do it explicitly. | 1688 // window was not active, so we have to do it explicitly. |
| 1688 // See http://crbug.com/6380. | 1689 // See http://crbug.com/6380. |
| 1689 b->GetSelectedWebContents()->GetView()->RestoreFocus(); | 1690 b->GetSelectedWebContents()->GetView()->RestoreFocus(); |
| 1690 } | 1691 } |
| 1691 } | 1692 } |
| 1692 | 1693 |
| 1693 void Browser::CloseTab() { | 1694 void Browser::CloseTab() { |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2493 // them. Once they have fired, we'll get a message back saying whether | 2494 // them. Once they have fired, we'll get a message back saying whether |
| 2494 // to proceed closing the page or not, which sends us back to this method | 2495 // to proceed closing the page or not, which sends us back to this method |
| 2495 // with the NeedToFireBeforeUnload bit cleared. | 2496 // with the NeedToFireBeforeUnload bit cleared. |
| 2496 contents->GetRenderViewHost()->FirePageBeforeUnload(false); | 2497 contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 2497 return true; | 2498 return true; |
| 2498 } | 2499 } |
| 2499 return false; | 2500 return false; |
| 2500 } | 2501 } |
| 2501 | 2502 |
| 2502 // static | 2503 // static |
| 2503 Browser* Browser::GetBrowserForController( | |
| 2504 const NavigationController* controller, int* index_result) { | |
| 2505 BrowserList::const_iterator it; | |
| 2506 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { | |
| 2507 int index = (*it)->GetIndexOfController(controller); | |
| 2508 if (index != TabStripModel::kNoTab) { | |
| 2509 if (index_result) | |
| 2510 *index_result = index; | |
| 2511 return *it; | |
| 2512 } | |
| 2513 } | |
| 2514 | |
| 2515 return NULL; | |
| 2516 } | |
| 2517 | |
| 2518 // static | |
| 2519 Browser* Browser::GetTabbedBrowser(Profile* profile, | |
| 2520 bool match_original_profiles) { | |
| 2521 return BrowserList::FindTabbedBrowser(profile, match_original_profiles); | |
| 2522 } | |
| 2523 | |
| 2524 // static | |
| 2525 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { | |
| 2526 Browser* browser = GetTabbedBrowser(profile, false); | |
| 2527 if (!browser) | |
| 2528 browser = Browser::Create(profile); | |
| 2529 return browser; | |
| 2530 } | |
| 2531 | |
| 2532 // static | |
| 2533 void Browser::RunFileChooserHelper( | 2504 void Browser::RunFileChooserHelper( |
| 2534 WebContents* tab, const content::FileChooserParams& params) { | 2505 WebContents* tab, const content::FileChooserParams& params) { |
| 2535 Profile* profile = | 2506 Profile* profile = |
| 2536 Profile::FromBrowserContext(tab->GetBrowserContext()); | 2507 Profile::FromBrowserContext(tab->GetBrowserContext()); |
| 2537 // FileSelectHelper adds a reference to itself and only releases it after | 2508 // FileSelectHelper adds a reference to itself and only releases it after |
| 2538 // sending the result message. It won't be destroyed when this reference | 2509 // sending the result message. It won't be destroyed when this reference |
| 2539 // goes out of scope. | 2510 // goes out of scope. |
| 2540 scoped_refptr<FileSelectHelper> file_select_helper( | 2511 scoped_refptr<FileSelectHelper> file_select_helper( |
| 2541 new FileSelectHelper(profile)); | 2512 new FileSelectHelper(profile)); |
| 2542 file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params); | 2513 file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params); |
| (...skipping 2920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5463 if (contents && !allow_js_access) { | 5434 if (contents && !allow_js_access) { |
| 5464 contents->web_contents()->GetController().LoadURL( | 5435 contents->web_contents()->GetController().LoadURL( |
| 5465 target_url, | 5436 target_url, |
| 5466 content::Referrer(), | 5437 content::Referrer(), |
| 5467 content::PAGE_TRANSITION_LINK, | 5438 content::PAGE_TRANSITION_LINK, |
| 5468 std::string()); // No extra headers. | 5439 std::string()); // No extra headers. |
| 5469 } | 5440 } |
| 5470 | 5441 |
| 5471 return contents != NULL; | 5442 return contents != NULL; |
| 5472 } | 5443 } |
| OLD | NEW |