Chromium Code Reviews| 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 // This may be called multiple times at startup to try to connect to different | |
|
tapted
2014/01/06 07:31:28
nit: I don't think this second sentence is true an
jackhou1
2014/01/07 05:24:36
Done.
| |
| 115 // paths. | |
| 116 void CreateChannelAndSendLaunchApp(const base::FilePath& socket_path); | |
| 117 | |
| 112 // Builds main menu bar items. | 118 // Builds main menu bar items. |
| 113 void SetUpMenu(); | 119 void SetUpMenu(); |
| 114 | 120 |
| 115 void SendSetAppHidden(bool hidden); | 121 void SendSetAppHidden(bool hidden); |
| 116 | 122 |
| 117 void SendQuitApp(); | 123 void SendQuitApp(); |
| 118 | 124 |
| 119 // Called when the app is activated, e.g. by clicking on it in the dock, by | 125 // 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. | 126 // dropping a file on the dock icon, or by Cmd+Tabbing to it. |
| 121 // Returns whether the message was sent. | 127 // Returns whether the message was sent. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 133 | 139 |
| 134 // Hide this app. | 140 // Hide this app. |
| 135 void OnHide(); | 141 void OnHide(); |
| 136 | 142 |
| 137 // Requests user attention. | 143 // Requests user attention. |
| 138 void OnRequestUserAttention(); | 144 void OnRequestUserAttention(); |
| 139 | 145 |
| 140 // Terminates the app shim process. | 146 // Terminates the app shim process. |
| 141 void Close(); | 147 void Close(); |
| 142 | 148 |
| 143 IPC::ChannelProxy* channel_; | 149 base::FilePath user_data_dir_; |
| 150 scoped_ptr<IPC::ChannelProxy> channel_; | |
| 144 base::scoped_nsobject<AppShimDelegate> delegate_; | 151 base::scoped_nsobject<AppShimDelegate> delegate_; |
| 145 bool launch_app_done_; | 152 bool launch_app_done_; |
| 146 bool ping_chrome_reply_received_; | 153 bool ping_chrome_reply_received_; |
| 147 | 154 |
| 148 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 155 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
| 149 }; | 156 }; |
| 150 | 157 |
| 151 AppShimController::AppShimController() | 158 AppShimController::AppShimController() |
| 152 : channel_(NULL), | 159 : delegate_([[AppShimDelegate alloc] init]), |
| 153 delegate_([[AppShimDelegate alloc] init]), | |
| 154 launch_app_done_(false), | 160 launch_app_done_(false), |
| 155 ping_chrome_reply_received_(false) { | 161 ping_chrome_reply_received_(false) { |
| 156 // Since AppShimController is created before the main message loop starts, | 162 // Since AppShimController is created before the main message loop starts, |
| 157 // NSApp will not be set, so use sharedApplication. | 163 // NSApp will not be set, so use sharedApplication. |
| 158 [[NSApplication sharedApplication] setDelegate:delegate_]; | 164 [[NSApplication sharedApplication] setDelegate:delegate_]; |
| 159 } | 165 } |
| 160 | 166 |
| 161 AppShimController::~AppShimController() { | 167 AppShimController::~AppShimController() { |
| 162 // Un-set the delegate since NSApplication does not retain it. | 168 // Un-set the delegate since NSApplication does not retain it. |
| 163 [NSApp setDelegate:nil]; | 169 [NSApp setDelegate:nil]; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 182 DCHECK(g_io_thread); | 188 DCHECK(g_io_thread); |
| 183 | 189 |
| 184 SetUpMenu(); | 190 SetUpMenu(); |
| 185 | 191 |
| 186 // Chrome will relaunch shims when relaunching apps. | 192 // Chrome will relaunch shims when relaunching apps. |
| 187 if (base::mac::IsOSLionOrLater()) | 193 if (base::mac::IsOSLionOrLater()) |
| 188 [NSApp disableRelaunchOnLogin]; | 194 [NSApp disableRelaunchOnLogin]; |
| 189 | 195 |
| 190 // The user_data_dir for shims actually contains the app_data_path. | 196 // The user_data_dir for shims actually contains the app_data_path. |
| 191 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ | 197 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ |
| 192 base::FilePath user_data_dir = | 198 user_data_dir_ = g_info->user_data_dir.DirName().DirName().DirName(); |
| 193 g_info->user_data_dir.DirName().DirName().DirName(); | 199 CHECK(!user_data_dir_.empty()); |
| 194 CHECK(!user_data_dir.empty()); | |
| 195 | 200 |
| 196 base::FilePath socket_path = | 201 base::FilePath symlink_path = |
| 197 user_data_dir.Append(app_mode::kAppShimSocketName); | 202 user_data_dir_.Append(app_mode::kAppShimSocketName); |
| 203 | |
| 204 base::FilePath socket_path; | |
| 205 if (!base::ReadSymbolicLink(symlink_path, &socket_path)) { | |
| 206 // The path in the user data dir is not a symlink, try connecting directly. | |
| 207 CreateChannelAndSendLaunchApp(symlink_path); | |
| 208 return; | |
| 209 } | |
| 210 | |
| 211 app_mode::VerifySocketPermissions(socket_path); | |
| 212 | |
| 213 CreateChannelAndSendLaunchApp(socket_path); | |
| 214 } | |
| 215 | |
| 216 void AppShimController::CreateChannelAndSendLaunchApp( | |
| 217 const base::FilePath& socket_path) { | |
| 198 IPC::ChannelHandle handle(socket_path.value()); | 218 IPC::ChannelHandle handle(socket_path.value()); |
| 199 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 219 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
| 200 this, g_io_thread->message_loop_proxy().get()); | 220 this, g_io_thread->message_loop_proxy().get())); |
| 201 | 221 |
| 202 bool launched_by_chrome = | 222 bool launched_by_chrome = |
| 203 CommandLine::ForCurrentProcess()->HasSwitch( | 223 CommandLine::ForCurrentProcess()->HasSwitch( |
| 204 app_mode::kLaunchedByChromeProcessId); | 224 app_mode::kLaunchedByChromeProcessId); |
| 205 apps::AppShimLaunchType launch_type = launched_by_chrome ? | 225 apps::AppShimLaunchType launch_type = launched_by_chrome ? |
| 206 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; | 226 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; |
| 207 | 227 |
| 208 [delegate_ setController:this]; | 228 [delegate_ setController:this]; |
| 209 | 229 |
| 210 std::vector<base::FilePath> files; | 230 std::vector<base::FilePath> files; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 // minute. | 657 // minute. |
| 638 main_message_loop.PostTask( | 658 main_message_loop.PostTask( |
| 639 FROM_HERE, | 659 FROM_HERE, |
| 640 base::Bind(&AppShimController::Init, | 660 base::Bind(&AppShimController::Init, |
| 641 base::Unretained(&controller))); | 661 base::Unretained(&controller))); |
| 642 } | 662 } |
| 643 | 663 |
| 644 main_message_loop.Run(); | 664 main_message_loop.Run(); |
| 645 return 0; | 665 return 0; |
| 646 } | 666 } |
| OLD | NEW |