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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 virtual void OnChannelError() OVERRIDE; | 123 virtual void OnChannelError() OVERRIDE; |
124 | 124 |
125 // If Chrome failed to launch the app, |success| will be false and the app | 125 // If Chrome failed to launch the app, |success| will be false and the app |
126 // shim process should die. | 126 // shim process should die. |
127 void OnLaunchAppDone(apps::AppShimLaunchResult result); | 127 void OnLaunchAppDone(apps::AppShimLaunchResult result); |
128 | 128 |
129 // Hide this app. | 129 // Hide this app. |
130 void OnHide(); | 130 void OnHide(); |
131 | 131 |
132 // Requests user attention. | 132 // Requests user attention. |
133 void OnRequestUserAttention(); | 133 void OnRequestUserAttention(); |
tapted
2014/08/13 06:53:15
since this shim is "always" newer, I don't think t
jackhou1
2014/08/14 04:24:51
The shim is newer, so the older Chrome might send
tapted
2014/08/14 04:38:51
ohhhhh of course..
| |
134 void OnSetUserAttention(apps::AppShimAttentionType attention_type); | |
134 | 135 |
135 // Terminates the app shim process. | 136 // Terminates the app shim process. |
136 void Close(); | 137 void Close(); |
137 | 138 |
138 base::FilePath user_data_dir_; | 139 base::FilePath user_data_dir_; |
139 scoped_ptr<IPC::ChannelProxy> channel_; | 140 scoped_ptr<IPC::ChannelProxy> channel_; |
140 base::scoped_nsobject<AppShimDelegate> delegate_; | 141 base::scoped_nsobject<AppShimDelegate> delegate_; |
141 bool launch_app_done_; | 142 bool launch_app_done_; |
142 bool ping_chrome_reply_received_; | 143 bool ping_chrome_reply_received_; |
144 NSInteger attention_request_id_; | |
143 | 145 |
144 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 146 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
145 }; | 147 }; |
146 | 148 |
147 AppShimController::AppShimController() | 149 AppShimController::AppShimController() |
148 : delegate_([[AppShimDelegate alloc] init]), | 150 : delegate_([[AppShimDelegate alloc] init]), |
149 launch_app_done_(false), | 151 launch_app_done_(false), |
150 ping_chrome_reply_received_(false) { | 152 ping_chrome_reply_received_(false), |
153 attention_request_id_(0) { | |
151 // Since AppShimController is created before the main message loop starts, | 154 // Since AppShimController is created before the main message loop starts, |
152 // NSApp will not be set, so use sharedApplication. | 155 // NSApp will not be set, so use sharedApplication. |
153 [[NSApplication sharedApplication] setDelegate:delegate_]; | 156 [[NSApplication sharedApplication] setDelegate:delegate_]; |
154 } | 157 } |
155 | 158 |
156 AppShimController::~AppShimController() { | 159 AppShimController::~AppShimController() { |
157 // Un-set the delegate since NSApplication does not retain it. | 160 // Un-set the delegate since NSApplication does not retain it. |
158 [[NSApplication sharedApplication] setDelegate:nil]; | 161 [[NSApplication sharedApplication] setDelegate:nil]; |
159 } | 162 } |
160 | 163 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 void AppShimController::SendQuitApp() { | 278 void AppShimController::SendQuitApp() { |
276 channel_->Send(new AppShimHostMsg_QuitApp); | 279 channel_->Send(new AppShimHostMsg_QuitApp); |
277 } | 280 } |
278 | 281 |
279 bool AppShimController::OnMessageReceived(const IPC::Message& message) { | 282 bool AppShimController::OnMessageReceived(const IPC::Message& message) { |
280 bool handled = true; | 283 bool handled = true; |
281 IPC_BEGIN_MESSAGE_MAP(AppShimController, message) | 284 IPC_BEGIN_MESSAGE_MAP(AppShimController, message) |
282 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) | 285 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) |
283 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide) | 286 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide) |
284 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention) | 287 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention) |
288 IPC_MESSAGE_HANDLER(AppShimMsg_SetUserAttention, OnSetUserAttention) | |
285 IPC_MESSAGE_UNHANDLED(handled = false) | 289 IPC_MESSAGE_UNHANDLED(handled = false) |
286 IPC_END_MESSAGE_MAP() | 290 IPC_END_MESSAGE_MAP() |
287 | 291 |
288 return handled; | 292 return handled; |
289 } | 293 } |
290 | 294 |
291 void AppShimController::OnChannelError() { | 295 void AppShimController::OnChannelError() { |
292 Close(); | 296 Close(); |
293 } | 297 } |
294 | 298 |
295 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { | 299 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { |
296 if (result != apps::APP_SHIM_LAUNCH_SUCCESS) { | 300 if (result != apps::APP_SHIM_LAUNCH_SUCCESS) { |
297 Close(); | 301 Close(); |
298 return; | 302 return; |
299 } | 303 } |
300 | 304 |
301 std::vector<base::FilePath> files; | 305 std::vector<base::FilePath> files; |
302 if ([delegate_ getFilesToOpenAtStartup:&files]) | 306 if ([delegate_ getFilesToOpenAtStartup:&files]) |
303 SendFocusApp(apps::APP_SHIM_FOCUS_OPEN_FILES, files); | 307 SendFocusApp(apps::APP_SHIM_FOCUS_OPEN_FILES, files); |
304 | 308 |
305 launch_app_done_ = true; | 309 launch_app_done_ = true; |
306 } | 310 } |
307 | 311 |
308 void AppShimController::OnHide() { | 312 void AppShimController::OnHide() { |
309 [NSApp hide:nil]; | 313 [NSApp hide:nil]; |
310 } | 314 } |
311 | 315 |
312 void AppShimController::OnRequestUserAttention() { | 316 void AppShimController::OnRequestUserAttention() { |
313 [NSApp requestUserAttention:NSInformationalRequest]; | 317 OnSetUserAttention(apps::APP_SHIM_ATTENTION_INFORMATIONAL); |
318 } | |
319 | |
320 void AppShimController::OnSetUserAttention( | |
321 apps::AppShimAttentionType attention_type) { | |
322 switch (attention_type) { | |
323 case apps::APP_SHIM_ATTENTION_CANCEL: | |
324 [NSApp cancelUserAttentionRequest:attention_request_id_]; | |
325 attention_request_id_ = 0; | |
326 break; | |
327 case apps::APP_SHIM_ATTENTION_CRITICAL: | |
328 attention_request_id_ = [NSApp requestUserAttention:NSCriticalRequest]; | |
329 break; | |
330 case apps::APP_SHIM_ATTENTION_INFORMATIONAL: | |
331 attention_request_id_ = | |
332 [NSApp requestUserAttention:NSInformationalRequest]; | |
333 case apps::APP_SHIM_ATTENTION_NUM_TYPES: | |
tapted
2014/08/13 06:53:15
You need a break; before this :o
jackhou1
2014/08/14 04:24:51
Done.
| |
334 NOTREACHED(); | |
335 } | |
314 } | 336 } |
315 | 337 |
316 void AppShimController::Close() { | 338 void AppShimController::Close() { |
317 [delegate_ terminateNow]; | 339 [delegate_ terminateNow]; |
318 } | 340 } |
319 | 341 |
320 bool AppShimController::SendFocusApp(apps::AppShimFocusType focus_type, | 342 bool AppShimController::SendFocusApp(apps::AppShimFocusType focus_type, |
321 const std::vector<base::FilePath>& files) { | 343 const std::vector<base::FilePath>& files) { |
322 if (launch_app_done_) { | 344 if (launch_app_done_) { |
323 channel_->Send(new AppShimHostMsg_FocusApp(focus_type, files)); | 345 channel_->Send(new AppShimHostMsg_FocusApp(focus_type, files)); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 // minute. | 682 // minute. |
661 main_message_loop.PostTask( | 683 main_message_loop.PostTask( |
662 FROM_HERE, | 684 FROM_HERE, |
663 base::Bind(&AppShimController::Init, | 685 base::Bind(&AppShimController::Init, |
664 base::Unretained(&controller))); | 686 base::Unretained(&controller))); |
665 } | 687 } |
666 | 688 |
667 main_message_loop.Run(); | 689 main_message_loop.Run(); |
668 return 0; | 690 return 0; |
669 } | 691 } |
OLD | NEW |