OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // On Mac, one can't make shortcuts with command-line arguments. Instead, we | 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we |
6 // produce small app bundles which locate the Chromium framework and load it, | 6 // produce small app bundles which locate the Chromium framework and load it, |
7 // passing the appropriate data. This is the entry point into the framework for | 7 // passing the appropriate data. This is the entry point into the framework for |
8 // those app bundles. | 8 // those app bundles. |
9 | 9 |
10 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 // was sent, or when the ping fails (if |success| is false). | 102 // was sent, or when the ping fails (if |success| is false). |
103 void OnPingChromeReply(bool success); | 103 void OnPingChromeReply(bool success); |
104 | 104 |
105 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the | 105 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the |
106 // ping event to be detected. | 106 // ping event to be detected. |
107 void OnPingChromeTimeout(); | 107 void OnPingChromeTimeout(); |
108 | 108 |
109 // Connects to Chrome and sends a LaunchApp message. | 109 // Connects to Chrome and sends a LaunchApp message. |
110 void Init(); | 110 void Init(); |
111 | 111 |
112 // Create a channel from |socket_path| and send a LaunchApp message. | |
113 // This may be called multiple times at startup to try to connect to different | |
114 // paths. | |
115 void CreateChannelAndSendLaunchApp(const base::FilePath& socket_path); | |
116 | |
112 // Builds main menu bar items. | 117 // Builds main menu bar items. |
113 void SetUpMenu(); | 118 void SetUpMenu(); |
114 | 119 |
115 void SendSetAppHidden(bool hidden); | 120 void SendSetAppHidden(bool hidden); |
116 | 121 |
117 void SendQuitApp(); | 122 void SendQuitApp(); |
118 | 123 |
119 // Called when the app is activated, e.g. by clicking on it in the dock, by | 124 // Called when the app is activated, e.g. by clicking on it in the dock, by |
120 // dropping a file on the dock icon, or by Cmd+Tabbing to it. | 125 // dropping a file on the dock icon, or by Cmd+Tabbing to it. |
121 // Returns whether the message was sent. | 126 // Returns whether the message was sent. |
(...skipping 11 matching lines...) Expand all Loading... | |
133 | 138 |
134 // Hide this app. | 139 // Hide this app. |
135 void OnHide(); | 140 void OnHide(); |
136 | 141 |
137 // Requests user attention. | 142 // Requests user attention. |
138 void OnRequestUserAttention(); | 143 void OnRequestUserAttention(); |
139 | 144 |
140 // Terminates the app shim process. | 145 // Terminates the app shim process. |
141 void Close(); | 146 void Close(); |
142 | 147 |
148 base::FilePath user_data_dir_; | |
149 bool should_try_long_socket_path; | |
143 IPC::ChannelProxy* channel_; | 150 IPC::ChannelProxy* channel_; |
144 base::scoped_nsobject<AppShimDelegate> delegate_; | 151 base::scoped_nsobject<AppShimDelegate> delegate_; |
145 bool launch_app_done_; | 152 bool launch_app_done_; |
146 bool ping_chrome_reply_received_; | 153 bool ping_chrome_reply_received_; |
147 | 154 |
148 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 155 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
149 }; | 156 }; |
150 | 157 |
151 AppShimController::AppShimController() | 158 AppShimController::AppShimController() |
152 : channel_(NULL), | 159 : should_try_long_socket_path(true), |
160 channel_(NULL), | |
153 delegate_([[AppShimDelegate alloc] init]), | 161 delegate_([[AppShimDelegate alloc] init]), |
154 launch_app_done_(false), | 162 launch_app_done_(false), |
155 ping_chrome_reply_received_(false) { | 163 ping_chrome_reply_received_(false) { |
156 // Since AppShimController is created before the main message loop starts, | 164 // Since AppShimController is created before the main message loop starts, |
157 // NSApp will not be set, so use sharedApplication. | 165 // NSApp will not be set, so use sharedApplication. |
158 [[NSApplication sharedApplication] setDelegate:delegate_]; | 166 [[NSApplication sharedApplication] setDelegate:delegate_]; |
159 } | 167 } |
160 | 168 |
161 AppShimController::~AppShimController() { | 169 AppShimController::~AppShimController() { |
162 // Un-set the delegate since NSApplication does not retain it. | 170 // Un-set the delegate since NSApplication does not retain it. |
(...skipping 19 matching lines...) Expand all Loading... | |
182 DCHECK(g_io_thread); | 190 DCHECK(g_io_thread); |
183 | 191 |
184 SetUpMenu(); | 192 SetUpMenu(); |
185 | 193 |
186 // Chrome will relaunch shims when relaunching apps. | 194 // Chrome will relaunch shims when relaunching apps. |
187 if (base::mac::IsOSLionOrLater()) | 195 if (base::mac::IsOSLionOrLater()) |
188 [NSApp disableRelaunchOnLogin]; | 196 [NSApp disableRelaunchOnLogin]; |
189 | 197 |
190 // The user_data_dir for shims actually contains the app_data_path. | 198 // The user_data_dir for shims actually contains the app_data_path. |
191 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ | 199 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ |
192 base::FilePath user_data_dir = | 200 user_data_dir_ = g_info->user_data_dir.DirName().DirName().DirName(); |
193 g_info->user_data_dir.DirName().DirName().DirName(); | 201 CHECK(!user_data_dir_.empty()); |
194 CHECK(!user_data_dir.empty()); | |
195 | 202 |
196 base::FilePath socket_path = | 203 // Connect to the short socket path first. |
197 user_data_dir.Append(app_mode::kAppShimSocketName); | 204 CreateChannelAndSendLaunchApp(app_mode::GetShortSocketPath(user_data_dir_)); |
205 } | |
206 | |
207 void AppShimController::CreateChannelAndSendLaunchApp( | |
208 const base::FilePath& socket_path) { | |
tapted
2013/11/22 03:29:43
nit: indenting
jackhou1
2013/11/22 04:25:00
Done.
| |
198 IPC::ChannelHandle handle(socket_path.value()); | 209 IPC::ChannelHandle handle(socket_path.value()); |
199 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 210 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
tapted
2013/11/22 03:29:43
ooh - this is not refcounted/scoped. Should we mak
jackhou1
2013/11/22 04:25:00
Done.
| |
200 this, g_io_thread->message_loop_proxy().get()); | 211 this, g_io_thread->message_loop_proxy().get()); |
201 | 212 |
202 bool launched_by_chrome = | 213 bool launched_by_chrome = |
203 CommandLine::ForCurrentProcess()->HasSwitch( | 214 CommandLine::ForCurrentProcess()->HasSwitch( |
204 app_mode::kLaunchedByChromeProcessId); | 215 app_mode::kLaunchedByChromeProcessId); |
205 apps::AppShimLaunchType launch_type = launched_by_chrome ? | 216 apps::AppShimLaunchType launch_type = launched_by_chrome ? |
206 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; | 217 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; |
207 | 218 |
208 [delegate_ setController:this]; | 219 [delegate_ setController:this]; |
209 | 220 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) | 282 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) |
272 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide) | 283 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide) |
273 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention) | 284 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention) |
274 IPC_MESSAGE_UNHANDLED(handled = false) | 285 IPC_MESSAGE_UNHANDLED(handled = false) |
275 IPC_END_MESSAGE_MAP() | 286 IPC_END_MESSAGE_MAP() |
276 | 287 |
277 return handled; | 288 return handled; |
278 } | 289 } |
279 | 290 |
280 void AppShimController::OnChannelError() { | 291 void AppShimController::OnChannelError() { |
292 // On failure, try to connect to the long socket path. | |
tapted
2013/11/22 03:29:43
nit: maybe a TODO - remove this around m35?
jackhou1
2013/11/22 04:25:00
Done.
| |
293 if (should_try_long_socket_path) { | |
294 should_try_long_socket_path = false; | |
295 base::FilePath udd_plus_socket_name = | |
296 user_data_dir_.Append(app_mode::kAppShimSocketName); | |
297 CreateChannelAndSendLaunchApp(udd_plus_socket_name); | |
298 return; | |
299 } | |
300 | |
281 Close(); | 301 Close(); |
282 } | 302 } |
283 | 303 |
284 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { | 304 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { |
305 should_try_long_socket_path = false; | |
306 | |
285 if (result != apps::APP_SHIM_LAUNCH_SUCCESS) { | 307 if (result != apps::APP_SHIM_LAUNCH_SUCCESS) { |
286 Close(); | 308 Close(); |
287 return; | 309 return; |
288 } | 310 } |
289 | 311 |
290 std::vector<base::FilePath> files; | 312 std::vector<base::FilePath> files; |
291 if ([delegate_ getFilesToOpenAtStartup:&files]) | 313 if ([delegate_ getFilesToOpenAtStartup:&files]) |
292 SendFocusApp(apps::APP_SHIM_FOCUS_OPEN_FILES, files); | 314 SendFocusApp(apps::APP_SHIM_FOCUS_OPEN_FILES, files); |
293 | 315 |
294 launch_app_done_ = true; | 316 launch_app_done_ = true; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 // minute. | 659 // minute. |
638 main_message_loop.PostTask( | 660 main_message_loop.PostTask( |
639 FROM_HERE, | 661 FROM_HERE, |
640 base::Bind(&AppShimController::Init, | 662 base::Bind(&AppShimController::Init, |
641 base::Unretained(&controller))); | 663 base::Unretained(&controller))); |
642 } | 664 } |
643 | 665 |
644 main_message_loop.Run(); | 666 main_message_loop.Run(); |
645 return 0; | 667 return 0; |
646 } | 668 } |
OLD | NEW |