| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "apps/app_shim/app_shim_messages.h" | 13 #include "apps/app_shim/app_shim_messages.h" |
| 14 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/file_util.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/mac/bundle_locations.h" | 19 #include "base/mac/bundle_locations.h" |
| 19 #include "base/mac/foundation_util.h" | 20 #include "base/mac/foundation_util.h" |
| 20 #include "base/mac/launch_services_util.h" | 21 #include "base/mac/launch_services_util.h" |
| 21 #include "base/mac/mac_logging.h" | 22 #include "base/mac/mac_logging.h" |
| 22 #include "base/mac/mac_util.h" | 23 #include "base/mac/mac_util.h" |
| 23 #include "base/mac/scoped_nsautorelease_pool.h" | 24 #include "base/mac/scoped_nsautorelease_pool.h" |
| 24 #include "base/mac/scoped_nsobject.h" | 25 #include "base/mac/scoped_nsobject.h" |
| 25 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
| 26 #include "base/path_service.h" | 27 #include "base/path_service.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // was sent, or when the ping fails (if |success| is false). | 103 // was sent, or when the ping fails (if |success| is false). |
| 103 void OnPingChromeReply(bool success); | 104 void OnPingChromeReply(bool success); |
| 104 | 105 |
| 105 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the | 106 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the |
| 106 // ping event to be detected. | 107 // ping event to be detected. |
| 107 void OnPingChromeTimeout(); | 108 void OnPingChromeTimeout(); |
| 108 | 109 |
| 109 // Connects to Chrome and sends a LaunchApp message. | 110 // Connects to Chrome and sends a LaunchApp message. |
| 110 void Init(); | 111 void Init(); |
| 111 | 112 |
| 113 // Create a channel from |socket_path| and send a LaunchApp message. |
| 114 void CreateChannelAndSendLaunchApp(const base::FilePath& socket_path); |
| 115 |
| 112 // Builds main menu bar items. | 116 // Builds main menu bar items. |
| 113 void SetUpMenu(); | 117 void SetUpMenu(); |
| 114 | 118 |
| 115 void SendSetAppHidden(bool hidden); | 119 void SendSetAppHidden(bool hidden); |
| 116 | 120 |
| 117 void SendQuitApp(); | 121 void SendQuitApp(); |
| 118 | 122 |
| 119 // Called when the app is activated, e.g. by clicking on it in the dock, by | 123 // Called when the app is activated, e.g. by clicking on it in the dock, by |
| 120 // dropping a file on the dock icon, or by Cmd+Tabbing to it. | 124 // dropping a file on the dock icon, or by Cmd+Tabbing to it. |
| 121 // Returns whether the message was sent. | 125 // Returns whether the message was sent. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 133 | 137 |
| 134 // Hide this app. | 138 // Hide this app. |
| 135 void OnHide(); | 139 void OnHide(); |
| 136 | 140 |
| 137 // Requests user attention. | 141 // Requests user attention. |
| 138 void OnRequestUserAttention(); | 142 void OnRequestUserAttention(); |
| 139 | 143 |
| 140 // Terminates the app shim process. | 144 // Terminates the app shim process. |
| 141 void Close(); | 145 void Close(); |
| 142 | 146 |
| 143 IPC::ChannelProxy* channel_; | 147 base::FilePath user_data_dir_; |
| 148 scoped_ptr<IPC::ChannelProxy> channel_; |
| 144 base::scoped_nsobject<AppShimDelegate> delegate_; | 149 base::scoped_nsobject<AppShimDelegate> delegate_; |
| 145 bool launch_app_done_; | 150 bool launch_app_done_; |
| 146 bool ping_chrome_reply_received_; | 151 bool ping_chrome_reply_received_; |
| 147 | 152 |
| 148 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 153 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
| 149 }; | 154 }; |
| 150 | 155 |
| 151 AppShimController::AppShimController() | 156 AppShimController::AppShimController() |
| 152 : channel_(NULL), | 157 : delegate_([[AppShimDelegate alloc] init]), |
| 153 delegate_([[AppShimDelegate alloc] init]), | |
| 154 launch_app_done_(false), | 158 launch_app_done_(false), |
| 155 ping_chrome_reply_received_(false) { | 159 ping_chrome_reply_received_(false) { |
| 156 // Since AppShimController is created before the main message loop starts, | 160 // Since AppShimController is created before the main message loop starts, |
| 157 // NSApp will not be set, so use sharedApplication. | 161 // NSApp will not be set, so use sharedApplication. |
| 158 [[NSApplication sharedApplication] setDelegate:delegate_]; | 162 [[NSApplication sharedApplication] setDelegate:delegate_]; |
| 159 } | 163 } |
| 160 | 164 |
| 161 AppShimController::~AppShimController() { | 165 AppShimController::~AppShimController() { |
| 162 // Un-set the delegate since NSApplication does not retain it. | 166 // Un-set the delegate since NSApplication does not retain it. |
| 163 [NSApp setDelegate:nil]; | 167 [NSApp setDelegate:nil]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 DCHECK(g_io_thread); | 186 DCHECK(g_io_thread); |
| 183 | 187 |
| 184 SetUpMenu(); | 188 SetUpMenu(); |
| 185 | 189 |
| 186 // Chrome will relaunch shims when relaunching apps. | 190 // Chrome will relaunch shims when relaunching apps. |
| 187 if (base::mac::IsOSLionOrLater()) | 191 if (base::mac::IsOSLionOrLater()) |
| 188 [NSApp disableRelaunchOnLogin]; | 192 [NSApp disableRelaunchOnLogin]; |
| 189 | 193 |
| 190 // The user_data_dir for shims actually contains the app_data_path. | 194 // The user_data_dir for shims actually contains the app_data_path. |
| 191 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ | 195 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ |
| 192 base::FilePath user_data_dir = | 196 user_data_dir_ = g_info->user_data_dir.DirName().DirName().DirName(); |
| 193 g_info->user_data_dir.DirName().DirName().DirName(); | 197 CHECK(!user_data_dir_.empty()); |
| 194 CHECK(!user_data_dir.empty()); | |
| 195 | 198 |
| 196 base::FilePath socket_path = | 199 base::FilePath symlink_path = |
| 197 user_data_dir.Append(app_mode::kAppShimSocketName); | 200 user_data_dir_.Append(app_mode::kAppShimSocketName); |
| 201 |
| 202 base::FilePath socket_path; |
| 203 if (!base::ReadSymbolicLink(symlink_path, &socket_path)) { |
| 204 // The path in the user data dir is not a symlink, try connecting directly. |
| 205 CreateChannelAndSendLaunchApp(symlink_path); |
| 206 return; |
| 207 } |
| 208 |
| 209 app_mode::VerifySocketPermissions(socket_path); |
| 210 |
| 211 CreateChannelAndSendLaunchApp(socket_path); |
| 212 } |
| 213 |
| 214 void AppShimController::CreateChannelAndSendLaunchApp( |
| 215 const base::FilePath& socket_path) { |
| 198 IPC::ChannelHandle handle(socket_path.value()); | 216 IPC::ChannelHandle handle(socket_path.value()); |
| 199 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 217 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
| 200 this, g_io_thread->message_loop_proxy().get()); | 218 this, g_io_thread->message_loop_proxy().get())); |
| 201 | 219 |
| 202 bool launched_by_chrome = | 220 bool launched_by_chrome = |
| 203 CommandLine::ForCurrentProcess()->HasSwitch( | 221 CommandLine::ForCurrentProcess()->HasSwitch( |
| 204 app_mode::kLaunchedByChromeProcessId); | 222 app_mode::kLaunchedByChromeProcessId); |
| 205 apps::AppShimLaunchType launch_type = launched_by_chrome ? | 223 apps::AppShimLaunchType launch_type = launched_by_chrome ? |
| 206 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; | 224 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; |
| 207 | 225 |
| 208 [delegate_ setController:this]; | 226 [delegate_ setController:this]; |
| 209 | 227 |
| 210 std::vector<base::FilePath> files; | 228 std::vector<base::FilePath> files; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 // minute. | 655 // minute. |
| 638 main_message_loop.PostTask( | 656 main_message_loop.PostTask( |
| 639 FROM_HERE, | 657 FROM_HERE, |
| 640 base::Bind(&AppShimController::Init, | 658 base::Bind(&AppShimController::Init, |
| 641 base::Unretained(&controller))); | 659 base::Unretained(&controller))); |
| 642 } | 660 } |
| 643 | 661 |
| 644 main_message_loop.Run(); | 662 main_message_loop.Run(); |
| 645 return 0; | 663 return 0; |
| 646 } | 664 } |
| OLD | NEW |