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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 void OnDidActivateApplication(); | 59 void OnDidActivateApplication(); |
60 | 60 |
61 // Quits the app shim process. | 61 // Quits the app shim process. |
62 void Quit(); | 62 void Quit(); |
63 | 63 |
64 IPC::ChannelProxy* channel_; | 64 IPC::ChannelProxy* channel_; |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 66 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
67 }; | 67 }; |
68 | 68 |
69 AppShimController::AppShimController() : channel_(NULL) { | 69 AppShimController::AppShimController() : channel_(NULL) {} |
70 } | |
71 | 70 |
72 void AppShimController::Init() { | 71 void AppShimController::Init() { |
73 DCHECK(g_io_thread); | 72 DCHECK(g_io_thread); |
74 NSString* chrome_bundle_path = | 73 NSString* chrome_bundle_path = |
75 base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); | 74 base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); |
76 NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; | 75 NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; |
77 base::FilePath user_data_dir; | 76 base::FilePath user_data_dir; |
78 if (!chrome::GetUserDataDirectoryForBrowserBundle(chrome_bundle, | 77 if (!chrome::GetUserDataDirectoryForBrowserBundle(chrome_bundle, |
79 &user_data_dir)) { | 78 &user_data_dir)) { |
80 Quit(); | 79 Quit(); |
81 return; | 80 return; |
82 } | 81 } |
83 | 82 |
84 base::FilePath socket_path = | 83 base::FilePath socket_path = |
85 user_data_dir.Append(app_mode::kAppShimSocketName); | 84 user_data_dir.Append(app_mode::kAppShimSocketName); |
86 IPC::ChannelHandle handle(socket_path.value()); | 85 IPC::ChannelHandle handle(socket_path.value()); |
87 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 86 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
88 this, g_io_thread->message_loop_proxy()); | 87 this, g_io_thread->message_loop_proxy()); |
89 | 88 |
90 channel_->Send(new AppShimHostMsg_LaunchApp( | 89 channel_->Send(new AppShimHostMsg_LaunchApp( |
91 g_info->profile_dir.value(), g_info->app_mode_id)); | 90 g_info->profile_dir, g_info->app_mode_id, |
91 CommandLine::ForCurrentProcess()->HasSwitch(app_mode::kNoLaunchApp) ? | |
92 apps::REGISTER_WITHOUT_LAUNCH : apps::LAUNCH_NOW)); | |
92 } | 93 } |
93 | 94 |
94 bool AppShimController::OnMessageReceived(const IPC::Message& message) { | 95 bool AppShimController::OnMessageReceived(const IPC::Message& message) { |
95 bool handled = true; | 96 bool handled = true; |
96 IPC_BEGIN_MESSAGE_MAP(AppShimController, message) | 97 IPC_BEGIN_MESSAGE_MAP(AppShimController, message) |
97 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) | 98 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) |
98 IPC_MESSAGE_UNHANDLED(handled = false) | 99 IPC_MESSAGE_UNHANDLED(handled = false) |
99 IPC_END_MESSAGE_MAP() | 100 IPC_END_MESSAGE_MAP() |
100 | 101 |
101 return handled; | 102 return handled; |
102 } | 103 } |
103 | 104 |
104 void AppShimController::OnChannelError() { | 105 void AppShimController::OnChannelError() { |
105 LOG(ERROR) << "App shim channel error."; | 106 DLOG(ERROR) << "App shim channel error."; |
tapted
2013/05/30 03:25:06
Let's just remove this. It's usually a lie, since
jackhou1
2013/05/30 05:10:05
Done.
| |
106 Quit(); | 107 Quit(); |
107 } | 108 } |
108 | 109 |
109 void AppShimController::OnLaunchAppDone(bool success) { | 110 void AppShimController::OnLaunchAppDone(bool success) { |
110 if (!success) { | 111 if (!success) { |
111 Quit(); | 112 Quit(); |
112 return; | 113 return; |
113 } | 114 } |
115 | |
114 [[[NSWorkspace sharedWorkspace] notificationCenter] | 116 [[[NSWorkspace sharedWorkspace] notificationCenter] |
115 addObserverForName:NSWorkspaceDidActivateApplicationNotification | 117 addObserverForName:NSWorkspaceDidActivateApplicationNotification |
116 object:nil | 118 object:nil |
117 queue:nil | 119 queue:nil |
118 usingBlock:^(NSNotification* notification) { | 120 usingBlock:^(NSNotification* notification) { |
119 NSRunningApplication* activated_app = | 121 NSRunningApplication* activated_app = |
120 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; | 122 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; |
121 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) | 123 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) |
122 OnDidActivateApplication(); | 124 OnDidActivateApplication(); |
123 }]; | 125 }]; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 extern "C" { | 254 extern "C" { |
253 | 255 |
254 // |ChromeAppModeStart()| is the point of entry into the framework from the app | 256 // |ChromeAppModeStart()| is the point of entry into the framework from the app |
255 // mode loader. | 257 // mode loader. |
256 __attribute__((visibility("default"))) | 258 __attribute__((visibility("default"))) |
257 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); | 259 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); |
258 | 260 |
259 } // extern "C" | 261 } // extern "C" |
260 | 262 |
261 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { | 263 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { |
264 CommandLine::Init(info->argc, info->argv); | |
265 | |
262 base::mac::ScopedNSAutoreleasePool scoped_pool; | 266 base::mac::ScopedNSAutoreleasePool scoped_pool; |
263 base::AtExitManager exit_manager; | 267 base::AtExitManager exit_manager; |
264 chrome::RegisterPathProvider(); | 268 chrome::RegisterPathProvider(); |
265 | 269 |
266 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 270 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
267 RAW_LOG(ERROR, "App Mode Loader too old."); | 271 RAW_LOG(ERROR, "App Mode Loader too old."); |
268 return 1; | 272 return 1; |
269 } | 273 } |
270 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 274 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
271 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); | 275 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); |
(...skipping 26 matching lines...) Expand all Loading... | |
298 // fully initialized don't receive a reply until its run loop starts. Once | 302 // fully initialized don't receive a reply until its run loop starts. Once |
299 // the reply is received, Chrome will have opened its IPC port, guaranteed. | 303 // the reply is received, Chrome will have opened its IPC port, guaranteed. |
300 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; | 304 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; |
301 | 305 |
302 base::MessageLoopForUI main_message_loop; | 306 base::MessageLoopForUI main_message_loop; |
303 main_message_loop.set_thread_name("MainThread"); | 307 main_message_loop.set_thread_name("MainThread"); |
304 base::PlatformThread::SetName("CrAppShimMain"); | 308 base::PlatformThread::SetName("CrAppShimMain"); |
305 main_message_loop.Run(); | 309 main_message_loop.Run(); |
306 return 0; | 310 return 0; |
307 } | 311 } |
OLD | NEW |