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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 // Terminates the app shim process. | 80 // Terminates the app shim process. |
81 void Close(); | 81 void Close(); |
82 | 82 |
83 IPC::ChannelProxy* channel_; | 83 IPC::ChannelProxy* channel_; |
84 scoped_nsobject<AppShimDelegate> nsapp_delegate_; | 84 scoped_nsobject<AppShimDelegate> nsapp_delegate_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 86 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
87 }; | 87 }; |
88 | 88 |
89 AppShimController::AppShimController() : channel_(NULL) { | 89 AppShimController::AppShimController() : channel_(NULL) {} |
90 } | |
91 | 90 |
92 void AppShimController::Init() { | 91 void AppShimController::Init() { |
93 DCHECK(g_io_thread); | 92 DCHECK(g_io_thread); |
94 NSString* chrome_bundle_path = | 93 NSString* chrome_bundle_path = |
95 base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); | 94 base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); |
96 NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; | 95 NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; |
97 base::FilePath user_data_dir; | 96 base::FilePath user_data_dir; |
98 if (!chrome::GetUserDataDirectoryForBrowserBundle(chrome_bundle, | 97 if (!chrome::GetUserDataDirectoryForBrowserBundle(chrome_bundle, |
99 &user_data_dir)) { | 98 &user_data_dir)) { |
100 Close(); | 99 Close(); |
101 return; | 100 return; |
102 } | 101 } |
103 | 102 |
104 base::FilePath socket_path = | 103 base::FilePath socket_path = |
105 user_data_dir.Append(app_mode::kAppShimSocketName); | 104 user_data_dir.Append(app_mode::kAppShimSocketName); |
106 IPC::ChannelHandle handle(socket_path.value()); | 105 IPC::ChannelHandle handle(socket_path.value()); |
107 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 106 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
108 this, g_io_thread->message_loop_proxy()); | 107 this, g_io_thread->message_loop_proxy()); |
109 | 108 |
110 channel_->Send(new AppShimHostMsg_LaunchApp( | 109 channel_->Send(new AppShimHostMsg_LaunchApp( |
111 g_info->profile_dir.value(), g_info->app_mode_id)); | 110 g_info->profile_dir, g_info->app_mode_id, |
| 111 CommandLine::ForCurrentProcess()->HasSwitch(app_mode::kNoLaunchApp) ? |
| 112 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL)); |
112 | 113 |
113 nsapp_delegate_.reset([[AppShimDelegate alloc] initWithController:this]); | 114 nsapp_delegate_.reset([[AppShimDelegate alloc] initWithController:this]); |
114 DCHECK(![NSApp delegate]); | 115 DCHECK(![NSApp delegate]); |
115 [NSApp setDelegate:nsapp_delegate_]; | 116 [NSApp setDelegate:nsapp_delegate_]; |
116 } | 117 } |
117 | 118 |
118 void AppShimController::QuitApp() { | 119 void AppShimController::QuitApp() { |
119 channel_->Send(new AppShimHostMsg_QuitApp); | 120 channel_->Send(new AppShimHostMsg_QuitApp); |
120 } | 121 } |
121 | 122 |
122 bool AppShimController::OnMessageReceived(const IPC::Message& message) { | 123 bool AppShimController::OnMessageReceived(const IPC::Message& message) { |
123 bool handled = true; | 124 bool handled = true; |
124 IPC_BEGIN_MESSAGE_MAP(AppShimController, message) | 125 IPC_BEGIN_MESSAGE_MAP(AppShimController, message) |
125 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) | 126 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) |
126 IPC_MESSAGE_UNHANDLED(handled = false) | 127 IPC_MESSAGE_UNHANDLED(handled = false) |
127 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
128 | 129 |
129 return handled; | 130 return handled; |
130 } | 131 } |
131 | 132 |
132 void AppShimController::OnChannelError() { | 133 void AppShimController::OnChannelError() { |
133 LOG(ERROR) << "App shim channel error."; | |
134 Close(); | 134 Close(); |
135 } | 135 } |
136 | 136 |
137 void AppShimController::OnLaunchAppDone(bool success) { | 137 void AppShimController::OnLaunchAppDone(bool success) { |
138 if (!success) { | 138 if (!success) { |
139 Close(); | 139 Close(); |
140 return; | 140 return; |
141 } | 141 } |
| 142 |
142 [[[NSWorkspace sharedWorkspace] notificationCenter] | 143 [[[NSWorkspace sharedWorkspace] notificationCenter] |
143 addObserverForName:NSWorkspaceDidActivateApplicationNotification | 144 addObserverForName:NSWorkspaceDidActivateApplicationNotification |
144 object:nil | 145 object:nil |
145 queue:nil | 146 queue:nil |
146 usingBlock:^(NSNotification* notification) { | 147 usingBlock:^(NSNotification* notification) { |
147 NSRunningApplication* activated_app = | 148 NSRunningApplication* activated_app = |
148 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; | 149 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; |
149 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) | 150 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) |
150 OnDidActivateApplication(); | 151 OnDidActivateApplication(); |
151 }]; | 152 }]; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 extern "C" { | 313 extern "C" { |
313 | 314 |
314 // |ChromeAppModeStart()| is the point of entry into the framework from the app | 315 // |ChromeAppModeStart()| is the point of entry into the framework from the app |
315 // mode loader. | 316 // mode loader. |
316 __attribute__((visibility("default"))) | 317 __attribute__((visibility("default"))) |
317 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); | 318 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); |
318 | 319 |
319 } // extern "C" | 320 } // extern "C" |
320 | 321 |
321 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { | 322 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { |
| 323 CommandLine::Init(info->argc, info->argv); |
| 324 |
322 base::mac::ScopedNSAutoreleasePool scoped_pool; | 325 base::mac::ScopedNSAutoreleasePool scoped_pool; |
323 base::AtExitManager exit_manager; | 326 base::AtExitManager exit_manager; |
324 chrome::RegisterPathProvider(); | 327 chrome::RegisterPathProvider(); |
325 | 328 |
326 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 329 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
327 RAW_LOG(ERROR, "App Mode Loader too old."); | 330 RAW_LOG(ERROR, "App Mode Loader too old."); |
328 return 1; | 331 return 1; |
329 } | 332 } |
330 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 333 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
331 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); | 334 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); |
(...skipping 26 matching lines...) Expand all Loading... |
358 // fully initialized don't receive a reply until its run loop starts. Once | 361 // fully initialized don't receive a reply until its run loop starts. Once |
359 // the reply is received, Chrome will have opened its IPC port, guaranteed. | 362 // the reply is received, Chrome will have opened its IPC port, guaranteed. |
360 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; | 363 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; |
361 | 364 |
362 base::MessageLoopForUI main_message_loop; | 365 base::MessageLoopForUI main_message_loop; |
363 main_message_loop.set_thread_name("MainThread"); | 366 main_message_loop.set_thread_name("MainThread"); |
364 base::PlatformThread::SetName("CrAppShimMain"); | 367 base::PlatformThread::SetName("CrAppShimMain"); |
365 main_message_loop.Run(); | 368 main_message_loop.Run(); |
366 return 0; | 369 return 0; |
367 } | 370 } |
OLD | NEW |