Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: chrome/app/chrome_main_app_mode_mac.mm

Issue 12723011: Giving focus to an app shim brings windows belonging to that app to the foreground. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 void OnDidActivateApplicationNotification(NSNotification* notification);
koz (OOO until 15th September) 2013/03/18 03:33:12 comment and newline after this
jeremya 2013/03/18 04:54:05 Done, plus changed the function to only be called
54 // Quits the app shim process. 55 // Quits the app shim process.
55 void Quit(); 56 void Quit();
56 57
57 IPC::ChannelProxy* channel_; 58 IPC::ChannelProxy* channel_;
58 59
59 DISALLOW_COPY_AND_ASSIGN(AppShimController); 60 DISALLOW_COPY_AND_ASSIGN(AppShimController);
60 }; 61 };
61 62
62 AppShimController::AppShimController() : channel_(NULL) { 63 AppShimController::AppShimController() : channel_(NULL) {
63 } 64 }
(...skipping 24 matching lines...) Expand all
88 89
89 return handled; 90 return handled;
90 } 91 }
91 92
92 void AppShimController::OnChannelError() { 93 void AppShimController::OnChannelError() {
93 LOG(ERROR) << "App shim channel error."; 94 LOG(ERROR) << "App shim channel error.";
94 Quit(); 95 Quit();
95 } 96 }
96 97
97 void AppShimController::OnLaunchAppDone(bool success) { 98 void AppShimController::OnLaunchAppDone(bool success) {
98 if (!success) 99 if (!success) {
99 Quit(); 100 Quit();
101 return;
102 }
103 [[[NSWorkspace sharedWorkspace] notificationCenter]
104 addObserverForName:NSWorkspaceDidActivateApplicationNotification
105 object:nil
106 queue:nil
107 usingBlock:^(NSNotification* notification) {
108 OnDidActivateApplicationNotification(notification);
109 }];
100 } 110 }
101 111
102 void AppShimController::Quit() { 112 void AppShimController::Quit() {
103 [NSApp terminate:nil]; 113 [NSApp terminate:nil];
104 } 114 }
105 115
116 void AppShimController::OnDidActivateApplicationNotification(
117 NSNotification* notification) {
118 NSRunningApplication* activated_app =
119 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
120 if ([activated_app isEqual:[NSRunningApplication currentApplication]])
121 channel_->Send(new AppShimHostMsg_FocusApp);
122 }
123
106 //----------------------------------------------------------------------------- 124 //-----------------------------------------------------------------------------
107 125
108 // A ReplyEventHandler is a helper class to send an Apple Event to a process 126 // A ReplyEventHandler is a helper class to send an Apple Event to a process
109 // and call a callback when the reply returns. 127 // and call a callback when the reply returns.
110 // 128 //
111 // This is used to 'ping' the main Chrome process -- once Chrome has sent back 129 // 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 130 // an Apple Event reply, it's guaranteed that it has opened the IPC channel
113 // that the app shim will connect to. 131 // that the app shim will connect to.
114 @interface ReplyEventHandler : NSObject { 132 @interface ReplyEventHandler : NSObject {
115 base::Callback<void(bool)> onReply_; 133 base::Callback<void(bool)> onReply_;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // fully initialized don't receive a reply until its run loop starts. Once 305 // 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. 306 // the reply is received, Chrome will have opened its IPC port, guaranteed.
289 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; 307 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)];
290 308
291 MessageLoopForUI main_message_loop; 309 MessageLoopForUI main_message_loop;
292 main_message_loop.set_thread_name("MainThread"); 310 main_message_loop.set_thread_name("MainThread");
293 base::PlatformThread::SetName("CrAppShimMain"); 311 base::PlatformThread::SetName("CrAppShimMain");
294 main_message_loop.Run(); 312 main_message_loop.Run();
295 return 0; 313 return 0;
296 } 314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698