| 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)) { |
| 79 LOG(ERROR) << "Cannot get user data directory for browser bundle."; |
| 80 Quit(); | 80 Quit(); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 base::FilePath socket_path = | 84 base::FilePath socket_path = |
| 85 user_data_dir.Append(app_mode::kAppShimSocketName); | 85 user_data_dir.Append(app_mode::kAppShimSocketName); |
| 86 IPC::ChannelHandle handle(socket_path.value()); | 86 IPC::ChannelHandle handle(socket_path.value()); |
| 87 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 87 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
| 88 this, g_io_thread->message_loop_proxy()); | 88 this, g_io_thread->message_loop_proxy()); |
| 89 | 89 |
| 90 channel_->Send(new AppShimHostMsg_LaunchApp( | 90 channel_->Send(new AppShimHostMsg_LaunchApp( |
| 91 g_info->profile_dir.value(), g_info->app_mode_id)); | 91 g_info->profile_dir.value(), g_info->app_mode_id, |
| 92 !CommandLine::ForCurrentProcess()->HasSwitch(app_mode::kNoLaunchApp))); |
| 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 LOG(ERROR) << "App shim channel error."; |
| 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) { |
| 112 LOG(ERROR) << "App launch failed."; |
| 111 Quit(); | 113 Quit(); |
| 112 return; | 114 return; |
| 113 } | 115 } |
| 116 |
| 114 [[[NSWorkspace sharedWorkspace] notificationCenter] | 117 [[[NSWorkspace sharedWorkspace] notificationCenter] |
| 115 addObserverForName:NSWorkspaceDidActivateApplicationNotification | 118 addObserverForName:NSWorkspaceDidActivateApplicationNotification |
| 116 object:nil | 119 object:nil |
| 117 queue:nil | 120 queue:nil |
| 118 usingBlock:^(NSNotification* notification) { | 121 usingBlock:^(NSNotification* notification) { |
| 119 NSRunningApplication* activated_app = | 122 NSRunningApplication* activated_app = |
| 120 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; | 123 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; |
| 121 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) | 124 if ([activated_app isEqual:[NSRunningApplication currentApplication]]) |
| 122 OnDidActivateApplication(); | 125 OnDidActivateApplication(); |
| 123 }]; | 126 }]; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 extern "C" { | 255 extern "C" { |
| 253 | 256 |
| 254 // |ChromeAppModeStart()| is the point of entry into the framework from the app | 257 // |ChromeAppModeStart()| is the point of entry into the framework from the app |
| 255 // mode loader. | 258 // mode loader. |
| 256 __attribute__((visibility("default"))) | 259 __attribute__((visibility("default"))) |
| 257 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); | 260 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); |
| 258 | 261 |
| 259 } // extern "C" | 262 } // extern "C" |
| 260 | 263 |
| 261 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { | 264 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { |
| 265 CommandLine::Init(info->argc, info->argv); |
| 266 |
| 262 base::mac::ScopedNSAutoreleasePool scoped_pool; | 267 base::mac::ScopedNSAutoreleasePool scoped_pool; |
| 263 base::AtExitManager exit_manager; | 268 base::AtExitManager exit_manager; |
| 264 chrome::RegisterPathProvider(); | 269 chrome::RegisterPathProvider(); |
| 265 | 270 |
| 266 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 271 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
| 267 RAW_LOG(ERROR, "App Mode Loader too old."); | 272 RAW_LOG(ERROR, "App Mode Loader too old."); |
| 268 return 1; | 273 return 1; |
| 269 } | 274 } |
| 270 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 275 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
| 271 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); | 276 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 | 303 // 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. | 304 // the reply is received, Chrome will have opened its IPC port, guaranteed. |
| 300 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; | 305 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; |
| 301 | 306 |
| 302 base::MessageLoopForUI main_message_loop; | 307 base::MessageLoopForUI main_message_loop; |
| 303 main_message_loop.set_thread_name("MainThread"); | 308 main_message_loop.set_thread_name("MainThread"); |
| 304 base::PlatformThread::SetName("CrAppShimMain"); | 309 base::PlatformThread::SetName("CrAppShimMain"); |
| 305 main_message_loop.Run(); | 310 main_message_loop.Run(); |
| 306 return 0; | 311 return 0; |
| 307 } | 312 } |
| OLD | NEW |