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 #import "chrome/browser/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "apps/app_shim/app_shim_mac.h" | 7 #include "apps/app_shim/app_shim_mac.h" |
8 #include "apps/app_shim/extension_app_shim_handler_mac.h" | 8 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 CFPropertyListRef plist = CFPreferencesCopyAppValue(checkInterval, app); | 674 CFPropertyListRef plist = CFPreferencesCopyAppValue(checkInterval, app); |
675 if (!plist) { | 675 if (!plist) { |
676 const float fiveHoursInSeconds = 5.0 * 60.0 * 60.0; | 676 const float fiveHoursInSeconds = 5.0 * 60.0 * 60.0; |
677 NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds]; | 677 NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds]; |
678 CFPreferencesSetAppValue(checkInterval, value, app); | 678 CFPreferencesSetAppValue(checkInterval, value, app); |
679 CFPreferencesAppSynchronize(app); | 679 CFPreferencesAppSynchronize(app); |
680 } | 680 } |
681 #endif | 681 #endif |
682 } | 682 } |
683 | 683 |
| 684 - (void)openStartupUrls { |
| 685 // On Mac, the URLs are passed in via Cocoa, not command line. The Chrome |
| 686 // NSApplication is created in MainMessageLoop, and then the shortcut urls |
| 687 // are passed in via Apple events. At this point, the first browser is |
| 688 // already loaded in PreMainMessageLoop. If we initialize NSApplication |
| 689 // before PreMainMessageLoop to capture shortcut URL events, it may cause |
| 690 // more problems because it relies on things created in PreMainMessageLoop |
| 691 // and may break existing message loop design. |
| 692 if (startupUrls_.empty()) |
| 693 return; |
| 694 |
| 695 // If there's only 1 tab and the tab is NTP, close this NTP tab and open all |
| 696 // startup urls in new tabs, because the omnibox will stay focused if we |
| 697 // load url in NTP tab. |
| 698 Browser* browser = chrome::GetLastActiveBrowser(); |
| 699 int startupIndex = TabStripModel::kNoTab; |
| 700 content::WebContents* startupContent = NULL; |
| 701 |
| 702 if (browser && browser->tab_strip_model()->count() == 1) { |
| 703 startupIndex = browser->tab_strip_model()->active_index(); |
| 704 startupContent = browser->tab_strip_model()->GetActiveWebContents(); |
| 705 } |
| 706 |
| 707 if (startupUrls_.size()) { |
| 708 [self openUrls:startupUrls_]; |
| 709 startupUrls_.clear(); |
| 710 } |
| 711 |
| 712 if (startupIndex != TabStripModel::kNoTab && |
| 713 startupContent->GetVisibleURL() == GURL(chrome::kChromeUINewTabURL)) { |
| 714 browser->tab_strip_model()->CloseWebContentsAt(startupIndex, |
| 715 TabStripModel::CLOSE_NONE); |
| 716 } |
| 717 } |
| 718 |
684 // This is called after profiles have been loaded and preferences registered. | 719 // This is called after profiles have been loaded and preferences registered. |
685 // It is safe to access the default profile here. | 720 // It is safe to access the default profile here. |
686 - (void)applicationDidFinishLaunching:(NSNotification*)notify { | 721 - (void)applicationDidFinishLaunching:(NSNotification*)notify { |
687 // Notify BrowserList to keep the application running so it doesn't go away | 722 // Notify BrowserList to keep the application running so it doesn't go away |
688 // when all the browser windows get closed. | 723 // when all the browser windows get closed. |
689 chrome::IncrementKeepAliveCount(); | 724 chrome::IncrementKeepAliveCount(); |
690 | 725 |
691 [self setUpdateCheckInterval]; | 726 [self setUpdateCheckInterval]; |
692 | 727 |
693 // Start managing the menu for app windows. This needs to be done here because | 728 // Start managing the menu for app windows. This needs to be done here because |
(...skipping 24 matching lines...) Expand all Loading... |
718 // I/O. | 753 // I/O. |
719 BrowserThread::PostTask( | 754 BrowserThread::PostTask( |
720 BrowserThread::FILE, FROM_HERE, | 755 BrowserThread::FILE, FROM_HERE, |
721 base::Bind(&RecordLastRunAppBundlePath)); | 756 base::Bind(&RecordLastRunAppBundlePath)); |
722 | 757 |
723 // Makes "Services" menu items available. | 758 // Makes "Services" menu items available. |
724 [self registerServicesMenuTypesTo:[notify object]]; | 759 [self registerServicesMenuTypesTo:[notify object]]; |
725 | 760 |
726 startupComplete_ = YES; | 761 startupComplete_ = YES; |
727 | 762 |
728 // TODO(viettrungluu): This is very temporary, since this should be done "in" | 763 [self openStartupUrls]; |
729 // |BrowserMain()|, i.e., this list of startup URLs should be appended to the | |
730 // (probably-empty) list of URLs from the command line. | |
731 if (startupUrls_.size()) { | |
732 [self openUrls:startupUrls_]; | |
733 [self clearStartupUrls]; | |
734 } | |
735 | 764 |
736 PrefService* localState = g_browser_process->local_state(); | 765 PrefService* localState = g_browser_process->local_state(); |
737 if (localState) { | 766 if (localState) { |
738 localPrefRegistrar_.Init(localState); | 767 localPrefRegistrar_.Init(localState); |
739 localPrefRegistrar_.Add( | 768 localPrefRegistrar_.Add( |
740 prefs::kAllowFileSelectionDialogs, | 769 prefs::kAllowFileSelectionDialogs, |
741 base::Bind(&chrome::BrowserCommandController::UpdateOpenFileState, | 770 base::Bind(&chrome::BrowserCommandController::UpdateOpenFileState, |
742 menuState_.get())); | 771 menuState_.get())); |
743 } | 772 } |
744 } | 773 } |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 } | 1480 } |
1452 } | 1481 } |
1453 | 1482 |
1454 return dockMenu; | 1483 return dockMenu; |
1455 } | 1484 } |
1456 | 1485 |
1457 - (const std::vector<GURL>&)startupUrls { | 1486 - (const std::vector<GURL>&)startupUrls { |
1458 return startupUrls_; | 1487 return startupUrls_; |
1459 } | 1488 } |
1460 | 1489 |
1461 - (void)clearStartupUrls { | |
1462 startupUrls_.clear(); | |
1463 } | |
1464 | |
1465 - (BookmarkMenuBridge*)bookmarkMenuBridge { | 1490 - (BookmarkMenuBridge*)bookmarkMenuBridge { |
1466 return bookmarkMenuBridge_.get(); | 1491 return bookmarkMenuBridge_.get(); |
1467 } | 1492 } |
1468 | 1493 |
1469 - (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer { | 1494 - (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer { |
1470 workAreaChangeObservers_.AddObserver(observer); | 1495 workAreaChangeObservers_.AddObserver(observer); |
1471 } | 1496 } |
1472 | 1497 |
1473 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer { | 1498 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer { |
1474 workAreaChangeObservers_.RemoveObserver(observer); | 1499 workAreaChangeObservers_.RemoveObserver(observer); |
(...skipping 20 matching lines...) Expand all Loading... |
1495 | 1520 |
1496 //--------------------------------------------------------------------------- | 1521 //--------------------------------------------------------------------------- |
1497 | 1522 |
1498 namespace app_controller_mac { | 1523 namespace app_controller_mac { |
1499 | 1524 |
1500 bool IsOpeningNewWindow() { | 1525 bool IsOpeningNewWindow() { |
1501 return g_is_opening_new_window; | 1526 return g_is_opening_new_window; |
1502 } | 1527 } |
1503 | 1528 |
1504 } // namespace app_controller_mac | 1529 } // namespace app_controller_mac |
OLD | NEW |