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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "chrome/browser/ui/browser_window.h" | 56 #include "chrome/browser/ui/browser_window.h" |
57 #include "chrome/browser/ui/chrome_pages.h" | 57 #include "chrome/browser/ui/chrome_pages.h" |
58 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" | 58 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" |
59 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h" | 59 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h" |
60 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 60 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
61 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 61 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
62 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 62 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
63 #import "chrome/browser/ui/cocoa/confirm_quit.h" | 63 #import "chrome/browser/ui/cocoa/confirm_quit.h" |
64 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 64 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
65 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 65 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
66 #include "chrome/browser/ui/cocoa/handoff_active_url_observer.h" | |
67 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_delegate.h" | |
68 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" | 66 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
69 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 67 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
70 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" | 68 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" |
71 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 69 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
72 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 70 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
73 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 71 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
74 #include "chrome/browser/ui/extensions/application_launch.h" | 72 #include "chrome/browser/ui/extensions/application_launch.h" |
75 #include "chrome/browser/ui/host_desktop.h" | 73 #include "chrome/browser/ui/host_desktop.h" |
76 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 74 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
77 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 75 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
78 #include "chrome/browser/ui/user_manager.h" | 76 #include "chrome/browser/ui/user_manager.h" |
79 #include "chrome/common/chrome_paths_internal.h" | 77 #include "chrome/common/chrome_paths_internal.h" |
80 #include "chrome/common/chrome_switches.h" | 78 #include "chrome/common/chrome_switches.h" |
81 #include "chrome/common/cloud_print/cloud_print_class_mac.h" | 79 #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
82 #include "chrome/common/extensions/extension_constants.h" | 80 #include "chrome/common/extensions/extension_constants.h" |
83 #include "chrome/common/mac/app_mode_common.h" | 81 #include "chrome/common/mac/app_mode_common.h" |
84 #include "chrome/common/pref_names.h" | 82 #include "chrome/common/pref_names.h" |
85 #include "chrome/common/url_constants.h" | 83 #include "chrome/common/url_constants.h" |
86 #include "chrome/grit/chromium_strings.h" | 84 #include "chrome/grit/chromium_strings.h" |
87 #include "chrome/grit/generated_resources.h" | 85 #include "chrome/grit/generated_resources.h" |
88 #include "components/handoff/handoff_manager.h" | |
89 #include "components/handoff/handoff_utility.h" | 86 #include "components/handoff/handoff_utility.h" |
90 #include "components/signin/core/browser/signin_manager.h" | 87 #include "components/signin/core/browser/signin_manager.h" |
91 #include "components/signin/core/common/profile_management_switches.h" | 88 #include "components/signin/core/common/profile_management_switches.h" |
92 #include "content/public/browser/browser_thread.h" | 89 #include "content/public/browser/browser_thread.h" |
93 #include "content/public/browser/download_manager.h" | 90 #include "content/public/browser/download_manager.h" |
94 #include "content/public/browser/notification_service.h" | 91 #include "content/public/browser/notification_service.h" |
95 #include "content/public/browser/notification_types.h" | 92 #include "content/public/browser/notification_types.h" |
96 #include "content/public/browser/plugin_service.h" | 93 #include "content/public/browser/plugin_service.h" |
97 #include "content/public/browser/user_metrics.h" | 94 #include "content/public/browser/user_metrics.h" |
98 #include "extensions/browser/extension_system.h" | 95 #include "extensions/browser/extension_system.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (!switches::IsNewProfileManagement()) | 202 if (!switches::IsNewProfileManagement()) |
206 return false; | 203 return false; |
207 ProfileInfoCache& cache = | 204 ProfileInfoCache& cache = |
208 g_browser_process->profile_manager()->GetProfileInfoCache(); | 205 g_browser_process->profile_manager()->GetProfileInfoCache(); |
209 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 206 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
210 if (profile_index == std::string::npos) | 207 if (profile_index == std::string::npos) |
211 return false; | 208 return false; |
212 return cache.ProfileIsSigninRequiredAtIndex(profile_index); | 209 return cache.ProfileIsSigninRequiredAtIndex(profile_index); |
213 } | 210 } |
214 | 211 |
215 } // namespace | 212 } // anonymous namespace |
216 | 213 |
217 // A protocol that allows ObjC objects to receive delegate callbacks from | 214 @interface AppController (Private) |
218 // HandoffActiveURLObserver. | |
219 @protocol HandoffActiveURLObserverBridgeDelegate | |
220 - (void)handoffActiveURLChanged:(content::WebContents*)webContents; | |
221 @end | |
222 | |
223 namespace { | |
224 | |
225 // This class allows an ObjC object to receive the delegate callbacks from an | |
226 // HandoffActiveURLObserver. | |
227 class HandoffActiveURLObserverBridge : public HandoffActiveURLObserverDelegate { | |
228 public: | |
229 HandoffActiveURLObserverBridge( | |
230 NSObject<HandoffActiveURLObserverBridgeDelegate>* delegate) | |
231 : delegate_(delegate) { | |
232 DCHECK(delegate_); | |
233 observer_.reset(new HandoffActiveURLObserver(this)); | |
234 } | |
235 | |
236 ~HandoffActiveURLObserverBridge() override{}; | |
237 | |
238 private: | |
239 void HandoffActiveURLChanged(content::WebContents* web_contents) override { | |
240 [delegate_ handoffActiveURLChanged:web_contents]; | |
241 } | |
242 | |
243 // Instances of this class should be owned by their |delegate_|. | |
244 NSObject<HandoffActiveURLObserverBridgeDelegate>* delegate_; | |
245 | |
246 // The C++ object that this class acts as a bridge for. | |
247 scoped_ptr<HandoffActiveURLObserver> observer_; | |
248 | |
249 DISALLOW_COPY_AND_ASSIGN(HandoffActiveURLObserverBridge); | |
250 }; | |
251 | |
252 } // namespace | |
253 | |
254 @interface AppController () <HandoffActiveURLObserverBridgeDelegate> { | |
255 scoped_ptr<HandoffActiveURLObserverBridge> | |
256 active_web_contents_observer_bridge_; | |
257 } | |
258 | |
259 - (void)initMenuState; | 215 - (void)initMenuState; |
260 - (void)initProfileMenu; | 216 - (void)initProfileMenu; |
261 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; | 217 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
262 - (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; | 218 - (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; |
263 - (void)registerServicesMenuTypesTo:(NSApplication*)app; | 219 - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
264 - (void)getUrl:(NSAppleEventDescriptor*)event | 220 - (void)getUrl:(NSAppleEventDescriptor*)event |
265 withReply:(NSAppleEventDescriptor*)reply; | 221 withReply:(NSAppleEventDescriptor*)reply; |
266 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 222 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
267 - (void)activeSpaceDidChange:(NSNotification*)inNotification; | 223 - (void)activeSpaceDidChange:(NSNotification*)inNotification; |
268 - (void)checkForAnyKeyWindows; | 224 - (void)checkForAnyKeyWindows; |
269 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 225 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
270 - (BOOL)shouldQuitWithInProgressDownloads; | 226 - (BOOL)shouldQuitWithInProgressDownloads; |
271 - (void)executeApplication:(id)sender; | 227 - (void)executeApplication:(id)sender; |
272 - (void)profileWasRemoved:(const base::FilePath&)profilePath; | 228 - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
273 | 229 |
274 // Opens a tab for each GURL in |urls|. | 230 // Opens a tab for each GURL in |urls|. |
275 - (void)openUrls:(const std::vector<GURL>&)urls; | 231 - (void)openUrls:(const std::vector<GURL>&)urls; |
276 | 232 |
277 // This class cannot open urls until startup has finished. The urls that cannot | 233 // This class cannot open urls until startup has finished. The urls that cannot |
278 // be opened are cached in |startupUrls_|. This method must be called exactly | 234 // be opened are cached in |startupUrls_|. This method must be called exactly |
279 // once after startup has completed. It opens the urls in |startupUrls_|, and | 235 // once after startup has completed. It opens the urls in |startupUrls_|, and |
280 // clears |startupUrls_|. | 236 // clears |startupUrls_|. |
281 - (void)openStartupUrls; | 237 - (void)openStartupUrls; |
282 | 238 |
283 // Opens a tab for each GURL in |urls|. If there is exactly one tab open before | 239 // Opens a tab for each GURL in |urls|. If there is exactly one tab open before |
284 // this method is called, and that tab is the NTP, then this method closes the | 240 // this method is called, and that tab is the NTP, then this method closes the |
285 // NTP after all the |urls| have been opened. | 241 // NTP after all the |urls| have been opened. |
286 - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; | 242 - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; |
287 | |
288 // Whether instances of this class should use the Handoff feature. | |
289 - (BOOL)shouldUseHandoff; | |
290 | |
291 // This method passes |handoffURL| to |handoffManager_|. | |
292 - (void)passURLToHandoffManager:(const GURL&)handoffURL; | |
293 | |
294 // Lazily creates the Handoff Manager. Updates the state of the Handoff | |
295 // Manager. This method is idempotent. This should be called: | |
296 // - During initialization. | |
297 // - When the current tab navigates to a new URL. | |
298 // - When the active browser changes. | |
299 // - When the active browser's active tab switches. | |
300 // |webContents| should be the new, active WebContents. | |
301 - (void)updateHandoffManager:(content::WebContents*)webContents; | |
302 | |
303 // Given |webContents|, extracts a GURL to be used for Handoff. This may return | |
304 // the empty GURL. | |
305 - (GURL)handoffURLFromWebContents:(content::WebContents*)webContents; | |
306 @end | 243 @end |
307 | 244 |
308 class AppControllerProfileObserver : public ProfileInfoCacheObserver { | 245 class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
309 public: | 246 public: |
310 AppControllerProfileObserver( | 247 AppControllerProfileObserver( |
311 ProfileManager* profile_manager, AppController* app_controller) | 248 ProfileManager* profile_manager, AppController* app_controller) |
312 : profile_manager_(profile_manager), | 249 : profile_manager_(profile_manager), |
313 app_controller_(app_controller) { | 250 app_controller_(app_controller) { |
314 DCHECK(profile_manager_); | 251 DCHECK(profile_manager_); |
315 DCHECK(app_controller_); | 252 DCHECK(app_controller_); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 // I/O. | 769 // I/O. |
833 BrowserThread::PostTask( | 770 BrowserThread::PostTask( |
834 BrowserThread::FILE, FROM_HERE, | 771 BrowserThread::FILE, FROM_HERE, |
835 base::Bind(&RecordLastRunAppBundlePath)); | 772 base::Bind(&RecordLastRunAppBundlePath)); |
836 | 773 |
837 // Makes "Services" menu items available. | 774 // Makes "Services" menu items available. |
838 [self registerServicesMenuTypesTo:[notify object]]; | 775 [self registerServicesMenuTypesTo:[notify object]]; |
839 | 776 |
840 startupComplete_ = YES; | 777 startupComplete_ = YES; |
841 | 778 |
842 Browser* browser = | |
843 FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_NATIVE); | |
844 content::WebContents* activeWebContents = nullptr; | |
845 if (browser) | |
846 activeWebContents = browser->tab_strip_model()->GetActiveWebContents(); | |
847 [self updateHandoffManager:activeWebContents]; | |
848 [self openStartupUrls]; | 779 [self openStartupUrls]; |
849 | 780 |
850 PrefService* localState = g_browser_process->local_state(); | 781 PrefService* localState = g_browser_process->local_state(); |
851 if (localState) { | 782 if (localState) { |
852 localPrefRegistrar_.Init(localState); | 783 localPrefRegistrar_.Init(localState); |
853 localPrefRegistrar_.Add( | 784 localPrefRegistrar_.Add( |
854 prefs::kAllowFileSelectionDialogs, | 785 prefs::kAllowFileSelectionDialogs, |
855 base::Bind(&chrome::BrowserCommandController::UpdateOpenFileState, | 786 base::Bind(&chrome::BrowserCommandController::UpdateOpenFileState, |
856 menuState_.get())); | 787 menuState_.get())); |
857 } | 788 } |
858 | |
859 active_web_contents_observer_bridge_.reset( | |
860 new HandoffActiveURLObserverBridge(self)); | |
861 } | 789 } |
862 | 790 |
863 // This is called after profiles have been loaded and preferences registered. | 791 // This is called after profiles have been loaded and preferences registered. |
864 // It is safe to access the default profile here. | 792 // It is safe to access the default profile here. |
865 - (void)applicationDidBecomeActive:(NSNotification*)notify { | 793 - (void)applicationDidBecomeActive:(NSNotification*)notify { |
866 content::PluginService::GetInstance()->AppActivated(); | 794 content::PluginService::GetInstance()->AppActivated(); |
867 } | 795 } |
868 | 796 |
869 // Helper function for populating and displaying the in progress downloads at | 797 // Helper function for populating and displaying the in progress downloads at |
870 // exit alert panel. | 798 // exit alert panel. |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 | 1631 |
1704 [self openUrlsReplacingNTP:gurlVector]; | 1632 [self openUrlsReplacingNTP:gurlVector]; |
1705 return YES; | 1633 return YES; |
1706 } | 1634 } |
1707 | 1635 |
1708 - (void)application:(NSApplication*)application | 1636 - (void)application:(NSApplication*)application |
1709 didFailToContinueUserActivityWithType:(NSString*)userActivityType | 1637 didFailToContinueUserActivityWithType:(NSString*)userActivityType |
1710 error:(NSError*)error { | 1638 error:(NSError*)error { |
1711 } | 1639 } |
1712 | 1640 |
1713 #pragma mark - Handoff Manager | |
1714 | |
1715 - (BOOL)shouldUseHandoff { | |
1716 return base::mac::IsOSYosemiteOrLater(); | |
1717 } | |
1718 | |
1719 - (void)passURLToHandoffManager:(const GURL&)handoffURL { | |
1720 [handoffManager_ updateActiveURL:handoffURL]; | |
1721 } | |
1722 | |
1723 - (void)updateHandoffManager:(content::WebContents*)webContents { | |
1724 if (![self shouldUseHandoff]) | |
1725 return; | |
1726 | |
1727 if (!handoffManager_) | |
1728 handoffManager_.reset([[HandoffManager alloc] init]); | |
1729 | |
1730 GURL handoffURL = [self handoffURLFromWebContents:webContents]; | |
1731 [self passURLToHandoffManager:handoffURL]; | |
1732 } | |
1733 | |
1734 - (GURL)handoffURLFromWebContents:(content::WebContents*)webContents { | |
1735 if (!webContents) | |
1736 return GURL(); | |
1737 | |
1738 Profile* profile = | |
1739 Profile::FromBrowserContext(webContents->GetBrowserContext()); | |
1740 if (!profile) | |
1741 return GURL(); | |
1742 | |
1743 // Handoff is not allowed from an incognito profile. To err on the safe side, | |
1744 // also disallow Handoff from a guest profile. | |
1745 if (profile->GetProfileType() != Profile::REGULAR_PROFILE) | |
1746 return GURL(); | |
1747 | |
1748 if (!webContents) | |
1749 return GURL(); | |
1750 | |
1751 return webContents->GetVisibleURL(); | |
1752 } | |
1753 | |
1754 #pragma mark - HandoffActiveURLObserverBridgeDelegate | |
1755 | |
1756 - (void)handoffActiveURLChanged:(content::WebContents*)webContents { | |
1757 [self updateHandoffManager:webContents]; | |
1758 } | |
1759 | |
1760 @end // @implementation AppController | 1641 @end // @implementation AppController |
1761 | 1642 |
1762 //--------------------------------------------------------------------------- | 1643 //--------------------------------------------------------------------------- |
1763 | 1644 |
1764 namespace app_controller_mac { | 1645 namespace app_controller_mac { |
1765 | 1646 |
1766 bool IsOpeningNewWindow() { | 1647 bool IsOpeningNewWindow() { |
1767 return g_is_opening_new_window; | 1648 return g_is_opening_new_window; |
1768 } | 1649 } |
1769 | 1650 |
1770 } // namespace app_controller_mac | 1651 } // namespace app_controller_mac |
OLD | NEW |