| 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/launcher.h" | 5 #include "apps/launcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 // Class to handle launching of platform apps to open specific paths. | 89 // Class to handle launching of platform apps to open specific paths. |
| 90 // An instance of this class is created for each launch. The lifetime of these | 90 // An instance of this class is created for each launch. The lifetime of these |
| 91 // instances is managed by reference counted pointers. As long as an instance | 91 // instances is managed by reference counted pointers. As long as an instance |
| 92 // has outstanding tasks on a message queue it will be retained; once all | 92 // has outstanding tasks on a message queue it will be retained; once all |
| 93 // outstanding tasks are completed it will be deleted. | 93 // outstanding tasks are completed it will be deleted. |
| 94 class PlatformAppPathLauncher | 94 class PlatformAppPathLauncher |
| 95 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { | 95 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { |
| 96 public: | 96 public: |
| 97 PlatformAppPathLauncher(Profile* profile, | 97 PlatformAppPathLauncher(Profile* profile, |
| 98 const Extension* extension, | 98 const Extension* app, |
| 99 const std::vector<base::FilePath>& entry_paths) | 99 const std::vector<base::FilePath>& entry_paths) |
| 100 : profile_(profile), | 100 : profile_(profile), |
| 101 extension_id(extension->id()), | 101 extension_id(app->id()), |
| 102 entry_paths_(entry_paths), | 102 entry_paths_(entry_paths), |
| 103 mime_type_collector_(profile), | 103 mime_type_collector_(profile), |
| 104 is_directory_collector_(profile) {} | 104 is_directory_collector_(profile) {} |
| 105 | 105 |
| 106 PlatformAppPathLauncher(Profile* profile, | 106 PlatformAppPathLauncher(Profile* profile, |
| 107 const Extension* extension, | 107 const Extension* app, |
| 108 const base::FilePath& file_path) | 108 const base::FilePath& file_path) |
| 109 : profile_(profile), | 109 : profile_(profile), |
| 110 extension_id(extension->id()), | 110 extension_id(app->id()), |
| 111 mime_type_collector_(profile), | 111 mime_type_collector_(profile), |
| 112 is_directory_collector_(profile) { | 112 is_directory_collector_(profile) { |
| 113 if (!file_path.empty()) | 113 if (!file_path.empty()) |
| 114 entry_paths_.push_back(file_path); | 114 entry_paths_.push_back(file_path); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void set_action_data(std::unique_ptr<app_runtime::ActionData> action_data) { |
| 118 action_data_ = std::move(action_data); |
| 119 } |
| 120 |
| 121 void set_launch_source(extensions::AppLaunchSource launch_source) { |
| 122 launch_source_ = launch_source; |
| 123 } |
| 124 |
| 117 void Launch() { | 125 void Launch() { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 126 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 | 127 |
| 120 const Extension* extension = GetExtension(); | 128 const Extension* app = GetExtension(); |
| 121 if (!extension) | 129 if (!app) |
| 122 return; | 130 return; |
| 123 | 131 |
| 124 if (entry_paths_.empty()) { | 132 if (entry_paths_.empty()) { |
| 125 LaunchWithNoLaunchData(); | 133 LaunchWithNoLaunchData(); |
| 126 return; | 134 return; |
| 127 } | 135 } |
| 128 | 136 |
| 129 for (size_t i = 0; i < entry_paths_.size(); ++i) { | 137 for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 130 DCHECK(entry_paths_[i].IsAbsolute()); | 138 DCHECK(entry_paths_[i].IsAbsolute()); |
| 131 } | 139 } |
| 132 | 140 |
| 133 is_directory_collector_.CollectForEntriesPaths( | 141 is_directory_collector_.CollectForEntriesPaths( |
| 134 entry_paths_, | 142 entry_paths_, |
| 135 base::Bind(&PlatformAppPathLauncher::OnAreDirectoriesCollected, this, | 143 base::Bind(&PlatformAppPathLauncher::OnAreDirectoriesCollected, this, |
| 136 HasFileSystemWritePermission(extension))); | 144 HasFileSystemWritePermission(app))); |
| 137 } | 145 } |
| 138 | 146 |
| 139 void LaunchWithHandler(const std::string& handler_id) { | 147 void LaunchWithHandler(const std::string& handler_id) { |
| 140 handler_id_ = handler_id; | 148 handler_id_ = handler_id; |
| 141 Launch(); | 149 Launch(); |
| 142 } | 150 } |
| 143 | 151 |
| 144 void LaunchWithRelativePath(const base::FilePath& current_directory) { | 152 void LaunchWithRelativePath(const base::FilePath& current_directory) { |
| 145 BrowserThread::PostTask( | 153 BrowserThread::PostTask( |
| 146 BrowserThread::FILE, | 154 BrowserThread::FILE, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 192 } |
| 185 | 193 |
| 186 void OnFilesInvalid(const base::FilePath& /* error_path */) { | 194 void OnFilesInvalid(const base::FilePath& /* error_path */) { |
| 187 LaunchWithNoLaunchData(); | 195 LaunchWithNoLaunchData(); |
| 188 } | 196 } |
| 189 | 197 |
| 190 void LaunchWithNoLaunchData() { | 198 void LaunchWithNoLaunchData() { |
| 191 // This method is required as an entry point on the UI thread. | 199 // This method is required as an entry point on the UI thread. |
| 192 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 200 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 193 | 201 |
| 194 const Extension* extension = GetExtension(); | 202 const Extension* app = GetExtension(); |
| 195 if (!extension) | 203 if (!app) |
| 196 return; | 204 return; |
| 197 | 205 |
| 198 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 206 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 199 profile_, extension, extensions::SOURCE_FILE_HANDLER); | 207 profile_, app, launch_source_, std::move(action_data_)); |
| 200 } | 208 } |
| 201 | 209 |
| 202 void OnAreDirectoriesCollected( | 210 void OnAreDirectoriesCollected( |
| 203 bool has_file_system_write_permission, | 211 bool has_file_system_write_permission, |
| 204 std::unique_ptr<std::set<base::FilePath>> directory_paths) { | 212 std::unique_ptr<std::set<base::FilePath>> directory_paths) { |
| 205 if (has_file_system_write_permission) { | 213 if (has_file_system_write_permission) { |
| 206 std::set<base::FilePath>* const directory_paths_ptr = | 214 std::set<base::FilePath>* const directory_paths_ptr = |
| 207 directory_paths.get(); | 215 directory_paths.get(); |
| 208 PrepareFilesForWritableApp( | 216 PrepareFilesForWritableApp( |
| 209 entry_paths_, profile_, *directory_paths_ptr, | 217 entry_paths_, profile_, *directory_paths_ptr, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 223 // If fetching a mime type failed, then use a fallback one. | 231 // If fetching a mime type failed, then use a fallback one. |
| 224 for (size_t i = 0; i < entry_paths_.size(); ++i) { | 232 for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 225 const std::string mime_type = | 233 const std::string mime_type = |
| 226 !(*mime_types)[i].empty() ? (*mime_types)[i] : kFallbackMimeType; | 234 !(*mime_types)[i].empty() ? (*mime_types)[i] : kFallbackMimeType; |
| 227 bool is_directory = | 235 bool is_directory = |
| 228 directory_paths->find(entry_paths_[i]) != directory_paths->end(); | 236 directory_paths->find(entry_paths_[i]) != directory_paths->end(); |
| 229 entries_.push_back( | 237 entries_.push_back( |
| 230 extensions::EntryInfo(entry_paths_[i], mime_type, is_directory)); | 238 extensions::EntryInfo(entry_paths_[i], mime_type, is_directory)); |
| 231 } | 239 } |
| 232 | 240 |
| 233 const Extension* extension = GetExtension(); | 241 const Extension* app = GetExtension(); |
| 234 if (!extension) | 242 if (!app) |
| 235 return; | 243 return; |
| 236 | 244 |
| 237 // Find file handler from the platform app for the file being opened. | 245 // Find file handler from the platform app for the file being opened. |
| 238 const extensions::FileHandlerInfo* handler = NULL; | 246 const extensions::FileHandlerInfo* handler = NULL; |
| 239 if (!handler_id_.empty()) { | 247 if (!handler_id_.empty()) { |
| 240 handler = FileHandlerForId(*extension, handler_id_); | 248 handler = FileHandlerForId(*app, handler_id_); |
| 241 if (handler) { | 249 if (handler) { |
| 242 for (size_t i = 0; i < entry_paths_.size(); ++i) { | 250 for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 243 if (!FileHandlerCanHandleEntry(*handler, entries_[i])) { | 251 if (!FileHandlerCanHandleEntry(*handler, entries_[i])) { |
| 244 LOG(WARNING) | 252 LOG(WARNING) |
| 245 << "Extension does not provide a valid file handler for " | 253 << "Extension does not provide a valid file handler for " |
| 246 << entry_paths_[i].value(); | 254 << entry_paths_[i].value(); |
| 247 handler = NULL; | 255 handler = NULL; |
| 248 break; | 256 break; |
| 249 } | 257 } |
| 250 } | 258 } |
| 251 } | 259 } |
| 252 } else { | 260 } else { |
| 253 const std::vector<const extensions::FileHandlerInfo*>& handlers = | 261 const std::vector<const extensions::FileHandlerInfo*>& handlers = |
| 254 extensions::app_file_handler_util::FindFileHandlersForEntries( | 262 extensions::app_file_handler_util::FindFileHandlersForEntries( |
| 255 *extension, entries_); | 263 *app, entries_); |
| 256 if (!handlers.empty()) | 264 if (!handlers.empty()) |
| 257 handler = handlers[0]; | 265 handler = handlers[0]; |
| 258 } | 266 } |
| 259 | 267 |
| 260 // If this app doesn't have a file handler that supports the file, launch | 268 // If this app doesn't have a file handler that supports the file, launch |
| 261 // with no launch data. | 269 // with no launch data. |
| 262 if (!handler) { | 270 if (!handler) { |
| 263 LOG(WARNING) << "Extension does not provide a valid file handler."; | 271 LOG(WARNING) << "Extension does not provide a valid file handler."; |
| 264 LaunchWithNoLaunchData(); | 272 LaunchWithNoLaunchData(); |
| 265 return; | 273 return; |
| 266 } | 274 } |
| 267 | 275 |
| 268 if (handler_id_.empty()) | 276 if (handler_id_.empty()) |
| 269 handler_id_ = handler->id; | 277 handler_id_ = handler->id; |
| 270 | 278 |
| 271 // Access needs to be granted to the file for the process associated with | 279 // Access needs to be granted to the file for the process associated with |
| 272 // the extension. To do this the ExtensionHost is needed. This might not be | 280 // the extension. To do this the ExtensionHost is needed. This might not be |
| 273 // available, or it might be in the process of being unloaded, in which case | 281 // available, or it might be in the process of being unloaded, in which case |
| 274 // the lazy background task queue is used to load the extension and then | 282 // the lazy background task queue is used to load the extension and then |
| 275 // call back to us. | 283 // call back to us. |
| 276 extensions::LazyBackgroundTaskQueue* const queue = | 284 extensions::LazyBackgroundTaskQueue* const queue = |
| 277 extensions::LazyBackgroundTaskQueue::Get(profile_); | 285 extensions::LazyBackgroundTaskQueue::Get(profile_); |
| 278 if (queue->ShouldEnqueueTask(profile_, extension)) { | 286 if (queue->ShouldEnqueueTask(profile_, app)) { |
| 279 queue->AddPendingTask( | 287 queue->AddPendingTask( |
| 280 profile_, extension_id, | 288 profile_, extension_id, |
| 281 base::Bind(&PlatformAppPathLauncher::GrantAccessToFilesAndLaunch, | 289 base::Bind(&PlatformAppPathLauncher::GrantAccessToFilesAndLaunch, |
| 282 this)); | 290 this)); |
| 283 return; | 291 return; |
| 284 } | 292 } |
| 285 | 293 |
| 286 extensions::ProcessManager* const process_manager = | 294 extensions::ProcessManager* const process_manager = |
| 287 extensions::ProcessManager::Get(profile_); | 295 extensions::ProcessManager::Get(profile_); |
| 288 ExtensionHost* const host = | 296 ExtensionHost* const host = |
| 289 process_manager->GetBackgroundHostForExtension(extension_id); | 297 process_manager->GetBackgroundHostForExtension(extension_id); |
| 290 DCHECK(host); | 298 DCHECK(host); |
| 291 GrantAccessToFilesAndLaunch(host); | 299 GrantAccessToFilesAndLaunch(host); |
| 292 } | 300 } |
| 293 | 301 |
| 294 void GrantAccessToFilesAndLaunch(ExtensionHost* host) { | 302 void GrantAccessToFilesAndLaunch(ExtensionHost* host) { |
| 295 const Extension* extension = GetExtension(); | 303 const Extension* app = GetExtension(); |
| 296 if (!extension) | 304 if (!app) |
| 297 return; | 305 return; |
| 298 | 306 |
| 299 // If there was an error loading the app page, |host| will be NULL. | 307 // If there was an error loading the app page, |host| will be NULL. |
| 300 if (!host) { | 308 if (!host) { |
| 301 LOG(ERROR) << "Could not load app page for " << extension_id; | 309 LOG(ERROR) << "Could not load app page for " << extension_id; |
| 302 return; | 310 return; |
| 303 } | 311 } |
| 304 | 312 |
| 305 std::vector<GrantedFileEntry> granted_entries; | 313 std::vector<GrantedFileEntry> granted_entries; |
| 306 for (size_t i = 0; i < entry_paths_.size(); ++i) { | 314 for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 307 granted_entries.push_back(CreateFileEntry( | 315 granted_entries.push_back( |
| 308 profile_, extension, host->render_process_host()->GetID(), | 316 CreateFileEntry(profile_, app, host->render_process_host()->GetID(), |
| 309 entries_[i].path, entries_[i].is_directory)); | 317 entries_[i].path, entries_[i].is_directory)); |
| 310 } | 318 } |
| 311 | 319 |
| 312 AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( | 320 AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
| 313 profile_, extension, handler_id_, entries_, granted_entries); | 321 profile_, app, launch_source_, handler_id_, entries_, granted_entries, |
| 322 std::move(action_data_)); |
| 314 } | 323 } |
| 315 | 324 |
| 316 const Extension* GetExtension() const { | 325 const Extension* GetExtension() const { |
| 317 return extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( | 326 return extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 318 extension_id, extensions::ExtensionRegistry::EVERYTHING); | 327 extension_id, extensions::ExtensionRegistry::EVERYTHING); |
| 319 } | 328 } |
| 320 | 329 |
| 321 // The profile the app should be run in. | 330 // The profile the app should be run in. |
| 322 Profile* profile_; | 331 Profile* profile_; |
| 323 // The id of the extension providing the app. A pointer to the extension is | 332 // The id of the extension providing the app. A pointer to the extension is |
| 324 // not kept as the extension may be unloaded and deleted during the course of | 333 // not kept as the extension may be unloaded and deleted during the course of |
| 325 // the launch. | 334 // the launch. |
| 326 const std::string extension_id; | 335 const std::string extension_id; |
| 336 extensions::AppLaunchSource launch_source_ = extensions::SOURCE_FILE_HANDLER; |
| 337 std::unique_ptr<app_runtime::ActionData> action_data_; |
| 327 // A list of files and directories to be passed through to the app. | 338 // A list of files and directories to be passed through to the app. |
| 328 std::vector<base::FilePath> entry_paths_; | 339 std::vector<base::FilePath> entry_paths_; |
| 329 // A corresponding list with EntryInfo for every base::FilePath in | 340 // A corresponding list with EntryInfo for every base::FilePath in |
| 330 // entry_paths_. | 341 // entry_paths_. |
| 331 std::vector<extensions::EntryInfo> entries_; | 342 std::vector<extensions::EntryInfo> entries_; |
| 332 // The ID of the file handler used to launch the app. | 343 // The ID of the file handler used to launch the app. |
| 333 std::string handler_id_; | 344 std::string handler_id_; |
| 334 extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; | 345 extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; |
| 335 extensions::app_file_handler_util::IsDirectoryCollector | 346 extensions::app_file_handler_util::IsDirectoryCollector |
| 336 is_directory_collector_; | 347 is_directory_collector_; |
| 337 | 348 |
| 338 DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); | 349 DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); |
| 339 }; | 350 }; |
| 340 | 351 |
| 341 } // namespace | 352 } // namespace |
| 342 | 353 |
| 343 void LaunchPlatformAppWithCommandLine(Profile* profile, | 354 void LaunchPlatformAppWithCommandLine(Profile* profile, |
| 344 const Extension* extension, | 355 const Extension* app, |
| 345 const base::CommandLine& command_line, | 356 const base::CommandLine& command_line, |
| 346 const base::FilePath& current_directory, | 357 const base::FilePath& current_directory, |
| 347 extensions::AppLaunchSource source) { | 358 extensions::AppLaunchSource source) { |
| 348 // An app with "kiosk_only" should not be installed and launched | 359 // An app with "kiosk_only" should not be installed and launched |
| 349 // outside of ChromeOS kiosk mode in the first place. This is a defensive | 360 // outside of ChromeOS kiosk mode in the first place. This is a defensive |
| 350 // check in case this scenario does occur. | 361 // check in case this scenario does occur. |
| 351 if (extensions::KioskModeInfo::IsKioskOnly(extension)) { | 362 if (extensions::KioskModeInfo::IsKioskOnly(app)) { |
| 352 bool in_kiosk_mode = false; | 363 bool in_kiosk_mode = false; |
| 353 #if defined(OS_CHROMEOS) | 364 #if defined(OS_CHROMEOS) |
| 354 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 365 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 355 in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); | 366 in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); |
| 356 #endif | 367 #endif |
| 357 if (!in_kiosk_mode) { | 368 if (!in_kiosk_mode) { |
| 358 LOG(ERROR) << "App with 'kiosk_only' attribute must be run in " | 369 LOG(ERROR) << "App with 'kiosk_only' attribute must be run in " |
| 359 << " ChromeOS kiosk mode."; | 370 << " ChromeOS kiosk mode."; |
| 360 NOTREACHED(); | 371 NOTREACHED(); |
| 361 return; | 372 return; |
| 362 } | 373 } |
| 363 } | 374 } |
| 364 | 375 |
| 365 #if defined(OS_WIN) | 376 #if defined(OS_WIN) |
| 366 base::CommandLine::StringType about_blank_url( | 377 base::CommandLine::StringType about_blank_url( |
| 367 base::ASCIIToUTF16(url::kAboutBlankURL)); | 378 base::ASCIIToUTF16(url::kAboutBlankURL)); |
| 368 #else | 379 #else |
| 369 base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); | 380 base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); |
| 370 #endif | 381 #endif |
| 371 base::CommandLine::StringVector args = command_line.GetArgs(); | 382 base::CommandLine::StringVector args = command_line.GetArgs(); |
| 372 // Browser tests will add about:blank to the command line. This should | 383 // Browser tests will add about:blank to the command line. This should |
| 373 // never be interpreted as a file to open, as doing so with an app that | 384 // never be interpreted as a file to open, as doing so with an app that |
| 374 // has write access will result in a file 'about' being created, which | 385 // has write access will result in a file 'about' being created, which |
| 375 // causes problems on the bots. | 386 // causes problems on the bots. |
| 376 if (args.empty() || (command_line.HasSwitch(switches::kTestType) && | 387 if (args.empty() || (command_line.HasSwitch(switches::kTestType) && |
| 377 args[0] == about_blank_url)) { | 388 args[0] == about_blank_url)) { |
| 378 AppRuntimeEventRouter::DispatchOnLaunchedEvent(profile, extension, source); | 389 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 390 profile, app, source, std::unique_ptr<app_runtime::ActionData>()); |
| 379 return; | 391 return; |
| 380 } | 392 } |
| 381 | 393 |
| 382 base::FilePath file_path(command_line.GetArgs()[0]); | 394 base::FilePath file_path(command_line.GetArgs()[0]); |
| 383 scoped_refptr<PlatformAppPathLauncher> launcher = | 395 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 384 new PlatformAppPathLauncher(profile, extension, file_path); | 396 new PlatformAppPathLauncher(profile, app, file_path); |
| 385 launcher->LaunchWithRelativePath(current_directory); | 397 launcher->LaunchWithRelativePath(current_directory); |
| 386 } | 398 } |
| 387 | 399 |
| 388 void LaunchPlatformAppWithPath(Profile* profile, | 400 void LaunchPlatformAppWithPath(Profile* profile, |
| 389 const Extension* extension, | 401 const Extension* app, |
| 390 const base::FilePath& file_path) { | 402 const base::FilePath& file_path) { |
| 391 scoped_refptr<PlatformAppPathLauncher> launcher = | 403 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 392 new PlatformAppPathLauncher(profile, extension, file_path); | 404 new PlatformAppPathLauncher(profile, app, file_path); |
| 405 launcher->Launch(); |
| 406 } |
| 407 |
| 408 void LaunchPlatformAppWithAction( |
| 409 Profile* profile, |
| 410 const extensions::Extension* app, |
| 411 std::unique_ptr<app_runtime::ActionData> action_data, |
| 412 const base::FilePath& file_path) { |
| 413 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 414 new PlatformAppPathLauncher(profile, app, file_path); |
| 415 launcher->set_action_data(std::move(action_data)); |
| 416 launcher->set_launch_source(extensions::AppLaunchSource::SOURCE_UNTRACKED); |
| 393 launcher->Launch(); | 417 launcher->Launch(); |
| 394 } | 418 } |
| 395 | 419 |
| 396 void LaunchPlatformApp(Profile* profile, | 420 void LaunchPlatformApp(Profile* profile, |
| 397 const Extension* extension, | 421 const Extension* app, |
| 398 extensions::AppLaunchSource source) { | 422 extensions::AppLaunchSource source) { |
| 399 LaunchPlatformAppWithCommandLine( | 423 LaunchPlatformAppWithCommandLine( |
| 400 profile, | 424 profile, app, base::CommandLine(base::CommandLine::NO_PROGRAM), |
| 401 extension, | 425 base::FilePath(), source); |
| 402 base::CommandLine(base::CommandLine::NO_PROGRAM), | |
| 403 base::FilePath(), | |
| 404 source); | |
| 405 } | 426 } |
| 406 | 427 |
| 407 void LaunchPlatformAppWithFileHandler( | 428 void LaunchPlatformAppWithFileHandler( |
| 408 Profile* profile, | 429 Profile* profile, |
| 409 const Extension* extension, | 430 const Extension* app, |
| 410 const std::string& handler_id, | 431 const std::string& handler_id, |
| 411 const std::vector<base::FilePath>& entry_paths) { | 432 const std::vector<base::FilePath>& entry_paths) { |
| 412 scoped_refptr<PlatformAppPathLauncher> launcher = | 433 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 413 new PlatformAppPathLauncher(profile, extension, entry_paths); | 434 new PlatformAppPathLauncher(profile, app, entry_paths); |
| 414 launcher->LaunchWithHandler(handler_id); | 435 launcher->LaunchWithHandler(handler_id); |
| 415 } | 436 } |
| 416 | 437 |
| 417 void RestartPlatformApp(Profile* profile, const Extension* extension) { | 438 void RestartPlatformApp(Profile* profile, const Extension* app) { |
| 418 EventRouter* event_router = EventRouter::Get(profile); | 439 EventRouter* event_router = EventRouter::Get(profile); |
| 419 bool listening_to_restart = event_router-> | 440 bool listening_to_restart = event_router->ExtensionHasEventListener( |
| 420 ExtensionHasEventListener(extension->id(), | 441 app->id(), app_runtime::OnRestarted::kEventName); |
| 421 app_runtime::OnRestarted::kEventName); | |
| 422 | 442 |
| 423 if (listening_to_restart) { | 443 if (listening_to_restart) { |
| 424 AppRuntimeEventRouter::DispatchOnRestartedEvent(profile, extension); | 444 AppRuntimeEventRouter::DispatchOnRestartedEvent(profile, app); |
| 425 return; | 445 return; |
| 426 } | 446 } |
| 427 | 447 |
| 428 extensions::ExtensionPrefs* extension_prefs = | 448 extensions::ExtensionPrefs* extension_prefs = |
| 429 extensions::ExtensionPrefs::Get(profile); | 449 extensions::ExtensionPrefs::Get(profile); |
| 430 bool had_windows = extension_prefs->IsActive(extension->id()); | 450 bool had_windows = extension_prefs->IsActive(app->id()); |
| 431 extension_prefs->SetIsActive(extension->id(), false); | 451 extension_prefs->SetIsActive(app->id(), false); |
| 432 bool listening_to_launch = event_router-> | 452 bool listening_to_launch = event_router->ExtensionHasEventListener( |
| 433 ExtensionHasEventListener(extension->id(), | 453 app->id(), app_runtime::OnLaunched::kEventName); |
| 434 app_runtime::OnLaunched::kEventName); | |
| 435 | 454 |
| 436 if (listening_to_launch && had_windows) { | 455 if (listening_to_launch && had_windows) { |
| 437 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 456 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 438 profile, extension, extensions::SOURCE_RESTART); | 457 profile, app, extensions::SOURCE_RESTART, |
| 458 std::unique_ptr<app_runtime::ActionData>()); |
| 439 } | 459 } |
| 440 } | 460 } |
| 441 | 461 |
| 442 void LaunchPlatformAppWithUrl(Profile* profile, | 462 void LaunchPlatformAppWithUrl(Profile* profile, |
| 443 const Extension* extension, | 463 const Extension* app, |
| 444 const std::string& handler_id, | 464 const std::string& handler_id, |
| 445 const GURL& url, | 465 const GURL& url, |
| 446 const GURL& referrer_url) { | 466 const GURL& referrer_url) { |
| 447 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( | 467 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( |
| 448 profile, extension, handler_id, url, referrer_url); | 468 profile, app, handler_id, url, referrer_url); |
| 449 } | 469 } |
| 450 | 470 |
| 451 } // namespace apps | 471 } // namespace apps |
| OLD | NEW |