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 // 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 private: | 45 private: |
46 // IPC::Listener implemetation. | 46 // IPC::Listener implemetation. |
47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
48 virtual void OnChannelError() OVERRIDE; | 48 virtual void OnChannelError() OVERRIDE; |
49 | 49 |
50 // If Chrome failed to launch the app, |success| will be false and the app | 50 // If Chrome failed to launch the app, |success| will be false and the app |
51 // shim process should die. | 51 // shim process should die. |
52 void OnLaunchAppDone(bool success); | 52 void OnLaunchAppDone(bool success); |
53 | 53 |
| 54 // Called when the app is activated, either by the user clicking on it in the |
| 55 // dock or by Cmd+Tabbing to it. |
| 56 void OnDidActivateApplication(); |
| 57 |
54 // Quits the app shim process. | 58 // Quits the app shim process. |
55 void Quit(); | 59 void Quit(); |
56 | 60 |
57 IPC::ChannelProxy* channel_; | 61 IPC::ChannelProxy* channel_; |
58 | 62 |
59 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 63 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
60 }; | 64 }; |
61 | 65 |
62 AppShimController::AppShimController() : channel_(NULL) { | 66 AppShimController::AppShimController() : channel_(NULL) { |
63 } | 67 } |
(...skipping 24 matching lines...) Expand all Loading... |
88 | 92 |
89 return handled; | 93 return handled; |
90 } | 94 } |
91 | 95 |
92 void AppShimController::OnChannelError() { | 96 void AppShimController::OnChannelError() { |
93 LOG(ERROR) << "App shim channel error."; | 97 LOG(ERROR) << "App shim channel error."; |
94 Quit(); | 98 Quit(); |
95 } | 99 } |
96 | 100 |
97 void AppShimController::OnLaunchAppDone(bool success) { | 101 void AppShimController::OnLaunchAppDone(bool success) { |
98 if (!success) | 102 if (!success) { |
99 Quit(); | 103 Quit(); |
| 104 return; |
| 105 } |
| 106 [[[NSWorkspace sharedWorkspace] notificationCenter] |
| 107 addObserverForName:NSWorkspaceDidActivateApplicationNotification |
| 108 object:nil |
| 109 queue:nil |
| 110 usingBlock:^(NSNotification* notification) { |
| 111 NSRunningApplication* activated_app = |
| 112 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; |
| 113 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) |
| 114 OnDidActivateApplication(); |
| 115 }]; |
100 } | 116 } |
101 | 117 |
102 void AppShimController::Quit() { | 118 void AppShimController::Quit() { |
103 [NSApp terminate:nil]; | 119 [NSApp terminate:nil]; |
104 } | 120 } |
105 | 121 |
| 122 void AppShimController::OnDidActivateApplication() { |
| 123 channel_->Send(new AppShimHostMsg_FocusApp); |
| 124 } |
| 125 |
106 //----------------------------------------------------------------------------- | 126 //----------------------------------------------------------------------------- |
107 | 127 |
108 // A ReplyEventHandler is a helper class to send an Apple Event to a process | 128 // A ReplyEventHandler is a helper class to send an Apple Event to a process |
109 // and call a callback when the reply returns. | 129 // and call a callback when the reply returns. |
110 // | 130 // |
111 // This is used to 'ping' the main Chrome process -- once Chrome has sent back | 131 // This is used to 'ping' the main Chrome process -- once Chrome has sent back |
112 // an Apple Event reply, it's guaranteed that it has opened the IPC channel | 132 // an Apple Event reply, it's guaranteed that it has opened the IPC channel |
113 // that the app shim will connect to. | 133 // that the app shim will connect to. |
114 @interface ReplyEventHandler : NSObject { | 134 @interface ReplyEventHandler : NSObject { |
115 base::Callback<void(bool)> onReply_; | 135 base::Callback<void(bool)> onReply_; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // fully initialized don't receive a reply until its run loop starts. Once | 307 // fully initialized don't receive a reply until its run loop starts. Once |
288 // the reply is received, Chrome will have opened its IPC port, guaranteed. | 308 // the reply is received, Chrome will have opened its IPC port, guaranteed. |
289 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; | 309 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; |
290 | 310 |
291 MessageLoopForUI main_message_loop; | 311 MessageLoopForUI main_message_loop; |
292 main_message_loop.set_thread_name("MainThread"); | 312 main_message_loop.set_thread_name("MainThread"); |
293 base::PlatformThread::SetName("CrAppShimMain"); | 313 base::PlatformThread::SetName("CrAppShimMain"); |
294 main_message_loop.Run(); | 314 main_message_loop.Run(); |
295 return 0; | 315 return 0; |
296 } | 316 } |
OLD | NEW |