| 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 #include "apps/app_shim/app_shim_host_mac.h" | 5 #include "apps/app_shim/app_shim_host_mac.h" |
| 6 | 6 |
| 7 #include "apps/app_shim/app_shim_handler_mac.h" | 7 #include "apps/app_shim/app_shim_handler_mac.h" |
| 8 #include "apps/app_shim/app_shim_messages.h" | 8 #include "apps/app_shim/app_shim_messages.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 void AppShimHost::OnChannelError() { | 56 void AppShimHost::OnChannelError() { |
| 57 Close(); | 57 Close(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool AppShimHost::Send(IPC::Message* message) { | 60 bool AppShimHost::Send(IPC::Message* message) { |
| 61 DCHECK(channel_.get()); | 61 DCHECK(channel_.get()); |
| 62 return channel_->Send(message); | 62 return channel_->Send(message); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) { | 65 void AppShimHost::OnLaunchApp(base::FilePath profile_dir, |
| 66 std::string app_id, |
| 67 bool launch_now) { |
| 66 DCHECK(CalledOnValidThread()); | 68 DCHECK(CalledOnValidThread()); |
| 67 DCHECK(!profile_); | 69 DCHECK(!profile_); |
| 68 if (profile_) { | 70 if (profile_) { |
| 69 // Only one app launch message per channel. | 71 // Only one app launch message per channel. |
| 70 Send(new AppShimMsg_LaunchApp_Done(false)); | 72 Send(new AppShimMsg_LaunchApp_Done(false)); |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 | 75 |
| 74 profile_ = FetchProfileForDirectory(profile_dir); | 76 if (!(profile_ = FetchProfileForDirectory(profile_dir))) { |
| 77 Send(new AppShimMsg_LaunchApp_Done(false)); |
| 78 return; |
| 79 } |
| 80 |
| 75 app_id_ = app_id; | 81 app_id_ = app_id; |
| 82 |
| 76 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 83 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 77 bool success = handler && handler->OnShimLaunch(this); | 84 bool success = handler && handler->OnShimLaunch(this, launch_now); |
| 78 Send(new AppShimMsg_LaunchApp_Done(success)); | 85 Send(new AppShimMsg_LaunchApp_Done(success)); |
| 79 } | 86 } |
| 80 | 87 |
| 81 void AppShimHost::OnFocus() { | 88 void AppShimHost::OnFocus() { |
| 82 DCHECK(CalledOnValidThread()); | 89 DCHECK(CalledOnValidThread()); |
| 83 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 90 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 84 if (handler) | 91 if (handler) |
| 85 handler->OnShimFocus(this); | 92 handler->OnShimFocus(this); |
| 86 } | 93 } |
| 87 | 94 |
| 88 Profile* AppShimHost::FetchProfileForDirectory(const std::string& profile_dir) { | 95 Profile* AppShimHost::FetchProfileForDirectory( |
| 96 const base::FilePath& profile_dir) { |
| 89 ProfileManager* profileManager = g_browser_process->profile_manager(); | 97 ProfileManager* profileManager = g_browser_process->profile_manager(); |
| 90 // Even though the name of this function is "unsafe", there's no security | 98 // Check for the profile name in the profile info cache to ensure that we |
| 91 // issue here -- the check for the profile name in the profile info cache | 99 // never access any directory that isn't a known profile. |
| 92 // ensures that we never access any directory that isn't a known profile. | 100 base::FilePath path = profileManager->user_data_dir().Append(profile_dir); |
| 93 base::FilePath path = base::FilePath::FromUTF8Unsafe(profile_dir); | |
| 94 path = profileManager->user_data_dir().Append(path); | |
| 95 ProfileInfoCache& cache = profileManager->GetProfileInfoCache(); | 101 ProfileInfoCache& cache = profileManager->GetProfileInfoCache(); |
| 96 // This ensures that the given profile path is acutally a profile that we | |
| 97 // already know about. | |
| 98 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) { | 102 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) { |
| 99 LOG(ERROR) << "Requested directory is not a known profile '" | 103 LOG(ERROR) << "Requested directory is not a known profile '" |
| 100 << profile_dir << "'."; | 104 << profile_dir.value() << "'."; |
| 101 return NULL; | 105 return NULL; |
| 102 } | 106 } |
| 103 Profile* profile = profileManager->GetProfile(path); | 107 Profile* profile = profileManager->GetProfile(path); |
| 104 if (!profile) { | 108 if (!profile) { |
| 105 LOG(ERROR) << "Couldn't get profile for directory '" << profile_dir << "'."; | 109 LOG(ERROR) << "Couldn't get profile for directory '" |
| 110 << profile_dir.value() << "'."; |
| 106 return NULL; | 111 return NULL; |
| 107 } | 112 } |
| 108 return profile; | 113 return profile; |
| 109 } | 114 } |
| 110 | 115 |
| 111 void AppShimHost::OnAppClosed() { | 116 void AppShimHost::OnAppClosed() { |
| 112 Close(); | 117 Close(); |
| 113 } | 118 } |
| 114 | 119 |
| 115 void AppShimHost::Close() { | 120 void AppShimHost::Close() { |
| 116 DCHECK(CalledOnValidThread()); | 121 DCHECK(CalledOnValidThread()); |
| 117 delete this; | 122 delete this; |
| 118 } | 123 } |
| OLD | NEW |