Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: apps/launcher.cc

Issue 2212303003: Implement app launch changes for app runtime extension proposal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tool-screenshot
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 const Extension* extension, 107 const Extension* extension,
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(extension->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(const extensions::ActionData& action_data) {
118 action_data_ = 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* extension = GetExtension();
121 if (!extension) 129 if (!extension)
122 return; 130 return;
123 131
124 if (entry_paths_.empty()) { 132 if (entry_paths_.empty()) {
125 LaunchWithNoLaunchData(); 133 LaunchWithNoLaunchData();
126 return; 134 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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* extension = GetExtension();
195 if (!extension) 203 if (!extension)
196 return; 204 return;
197 205
198 AppRuntimeEventRouter::DispatchOnLaunchedEvent( 206 AppRuntimeEventRouter::DispatchOnLaunchedEvent(
199 profile_, extension, extensions::SOURCE_FILE_HANDLER); 207 profile_, extension, launch_source_, 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(CreateFileEntry(
308 profile_, extension, host->render_process_host()->GetID(), 316 profile_, extension, 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_, extension, launch_source_, handler_id_, entries_,
322 granted_entries, 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 base::Optional<extensions::ActionData> action_data_;
Devlin 2016/08/11 20:51:20 Why an optional instead of a unique_ptr here?
jdufault 2016/08/12 18:56:54 It conveyed intent more clearly. With the removal
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_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, extension, source, base::Optional<extensions::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, extension, 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* extension,
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, extension, file_path);
393 launcher->Launch(); 405 launcher->Launch();
394 } 406 }
395 407
408 void LaunchPlatformAppWithAction(Profile* profile,
409 const extensions::Extension* extension,
410 const extensions::ActionData& action_data,
411 const base::FilePath& file_path) {
412 scoped_refptr<PlatformAppPathLauncher> launcher =
413 new PlatformAppPathLauncher(profile, extension, file_path);
414 launcher->set_action_data(action_data);
415 launcher->set_launch_source(extensions::AppLaunchSource::SOURCE_UNTRACKED);
416 launcher->Launch();
417 }
418
396 void LaunchPlatformApp(Profile* profile, 419 void LaunchPlatformApp(Profile* profile,
397 const Extension* extension, 420 const Extension* extension,
398 extensions::AppLaunchSource source) { 421 extensions::AppLaunchSource source) {
399 LaunchPlatformAppWithCommandLine( 422 LaunchPlatformAppWithCommandLine(
400 profile, 423 profile,
401 extension, 424 extension,
402 base::CommandLine(base::CommandLine::NO_PROGRAM), 425 base::CommandLine(base::CommandLine::NO_PROGRAM),
403 base::FilePath(), 426 base::FilePath(),
404 source); 427 source);
405 } 428 }
(...skipping 22 matching lines...) Expand all
428 extensions::ExtensionPrefs* extension_prefs = 451 extensions::ExtensionPrefs* extension_prefs =
429 extensions::ExtensionPrefs::Get(profile); 452 extensions::ExtensionPrefs::Get(profile);
430 bool had_windows = extension_prefs->IsActive(extension->id()); 453 bool had_windows = extension_prefs->IsActive(extension->id());
431 extension_prefs->SetIsActive(extension->id(), false); 454 extension_prefs->SetIsActive(extension->id(), false);
432 bool listening_to_launch = event_router-> 455 bool listening_to_launch = event_router->
433 ExtensionHasEventListener(extension->id(), 456 ExtensionHasEventListener(extension->id(),
434 app_runtime::OnLaunched::kEventName); 457 app_runtime::OnLaunched::kEventName);
435 458
436 if (listening_to_launch && had_windows) { 459 if (listening_to_launch && had_windows) {
437 AppRuntimeEventRouter::DispatchOnLaunchedEvent( 460 AppRuntimeEventRouter::DispatchOnLaunchedEvent(
438 profile, extension, extensions::SOURCE_RESTART); 461 profile, extension, extensions::SOURCE_RESTART,
462 base::Optional<extensions::ActionData>());
439 } 463 }
440 } 464 }
441 465
442 void LaunchPlatformAppWithUrl(Profile* profile, 466 void LaunchPlatformAppWithUrl(Profile* profile,
443 const Extension* extension, 467 const Extension* extension,
444 const std::string& handler_id, 468 const std::string& handler_id,
445 const GURL& url, 469 const GURL& url,
446 const GURL& referrer_url) { 470 const GURL& referrer_url) {
447 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( 471 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl(
448 profile, extension, handler_id, url, referrer_url); 472 profile, extension, handler_id, url, referrer_url);
449 } 473 }
450 474
451 } // namespace apps 475 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698