[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 5 | #include "apps/launcher.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 6 | |
mostynb | ecb4a22b | 2016-04-04 06:08:01 | [diff] [blame] | 7 | #include <memory> |
[email protected] | fc243fe | 2014-07-18 13:06:23 | [diff] [blame] | 8 | #include <set> |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 9 | #include <utility> |
[email protected] | fc243fe | 2014-07-18 13:06:23 | [diff] [blame] | 10 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
thestig | 9471270 | 2014-09-10 07:46:59 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 14 | #include "base/logging.h" |
| 15 | #include "base/memory/ref_counted.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 16 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 18 | #include "base/task/post_task.h" |
| 19 | #include "base/task/task_traits.h" |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 20 | #include "content/public/browser/browser_context.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 21 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 22 | #include "content/public/browser/browser_thread.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 23 | #include "content/public/browser/render_process_host.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 24 | #include "content/public/browser/web_contents.h" |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 25 | #include "content/public/common/content_switches.h" |
| 26 | #include "content/public/common/url_constants.h" |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 27 | #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
michaelpg | bc6e379f | 2017-02-13 23:17:27 | [diff] [blame] | 28 | #include "extensions/browser/api/file_handlers/app_file_handler_util.h" |
| 29 | #include "extensions/browser/api/file_handlers/directory_util.h" |
| 30 | #include "extensions/browser/api/file_handlers/mime_util.h" |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 31 | #include "extensions/browser/entry_info.h" |
[email protected] | 3442353 | 2013-11-21 18:13:10 | [diff] [blame] | 32 | #include "extensions/browser/event_router.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 33 | #include "extensions/browser/extension_host.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 34 | #include "extensions/browser/extension_prefs.h" |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 35 | #include "extensions/browser/extension_registry.h" |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 36 | #include "extensions/browser/granted_file_entry.h" |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 37 | #include "extensions/browser/lazy_background_task_queue.h" |
David Bertoni | 8269a09 | 2018-12-19 15:55:42 | [diff] [blame] | 38 | #include "extensions/browser/lazy_context_id.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 39 | #include "extensions/browser/process_manager.h" |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 40 | #include "extensions/common/api/app_runtime.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 41 | #include "extensions/common/extension.h" |
[email protected] | 70c39bb | 2013-11-26 22:59:28 | [diff] [blame] | 42 | #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
tbarzic | 8bf50fca | 2017-06-22 03:02:18 | [diff] [blame] | 43 | #include "extensions/common/permissions/api_permission.h" |
| 44 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | f7fc72c | 2014-04-22 13:01:52 | [diff] [blame] | 45 | #include "net/base/filename_util.h" |
[email protected] | 43197ea2 | 2013-09-10 15:31:56 | [diff] [blame] | 46 | #include "url/gurl.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 47 | |
[email protected] | 906ae21 | 2013-03-24 01:37:13 | [diff] [blame] | 48 | #if defined(OS_CHROMEOS) |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 49 | #include "components/user_manager/user_manager.h" |
[email protected] | 906ae21 | 2013-03-24 01:37:13 | [diff] [blame] | 50 | #endif |
| 51 | |
kalman | e58e6223 | 2015-07-23 18:27:22 | [diff] [blame] | 52 | namespace app_runtime = extensions::api::app_runtime; |
[email protected] | e054ea1 | 2013-08-20 00:41:57 | [diff] [blame] | 53 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 54 | using content::BrowserThread; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 55 | using extensions::AppRuntimeEventRouter; |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 56 | using extensions::api::app_runtime::PlayStoreStatus; |
[email protected] | fc2a40f | 2013-03-13 13:14:57 | [diff] [blame] | 57 | using extensions::app_file_handler_util::CreateFileEntry; |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 58 | using extensions::app_file_handler_util::FileHandlerCanHandleEntry; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 59 | using extensions::app_file_handler_util::FileHandlerForId; |
[email protected] | ffb8706 | 2013-08-29 10:02:25 | [diff] [blame] | 60 | using extensions::app_file_handler_util::HasFileSystemWritePermission; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 61 | using extensions::app_file_handler_util::PrepareFilesForWritableApp; |
[email protected] | 3a368a2 | 2014-03-26 19:29:19 | [diff] [blame] | 62 | using extensions::EventRouter; |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 63 | using extensions::Extension; |
| 64 | using extensions::ExtensionHost; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 65 | using extensions::GrantedFileEntry; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 66 | |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 67 | namespace apps { |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 68 | |
| 69 | namespace { |
| 70 | |
[email protected] | 9be0bad | 2013-04-18 05:51:36 | [diff] [blame] | 71 | const char kFallbackMimeType[] = "application/octet-stream"; |
| 72 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 73 | bool DoMakePathAbsolute(const base::FilePath& current_directory, |
| 74 | base::FilePath* file_path) { |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 75 | DCHECK(file_path); |
| 76 | if (file_path->IsAbsolute()) |
| 77 | return true; |
| 78 | |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 79 | if (current_directory.empty()) { |
kinaba | 6e0570b | 2014-10-21 05:43:34 | [diff] [blame] | 80 | base::FilePath absolute_path = base::MakeAbsoluteFilePath(*file_path); |
| 81 | if (absolute_path.empty()) |
| 82 | return false; |
| 83 | *file_path = absolute_path; |
| 84 | return true; |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 85 | } |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 86 | |
| 87 | if (!current_directory.IsAbsolute()) |
| 88 | return false; |
| 89 | |
| 90 | *file_path = current_directory.Append(*file_path); |
| 91 | return true; |
| 92 | } |
| 93 | |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 94 | // Class to handle launching of platform apps to open specific paths. |
[email protected] | 4e04f1e | 2012-06-20 03:20:31 | [diff] [blame] | 95 | // An instance of this class is created for each launch. The lifetime of these |
| 96 | // instances is managed by reference counted pointers. As long as an instance |
| 97 | // has outstanding tasks on a message queue it will be retained; once all |
| 98 | // outstanding tasks are completed it will be deleted. |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 99 | class PlatformAppPathLauncher |
| 100 | : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 101 | public: |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 102 | PlatformAppPathLauncher(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 103 | const Extension* app, |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 104 | const std::vector<base::FilePath>& entry_paths) |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 105 | : context_(context), |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 106 | extension_id(app->id()), |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 107 | entry_paths_(entry_paths), |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 108 | mime_type_collector_(context), |
| 109 | is_directory_collector_(context) {} |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 110 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 111 | PlatformAppPathLauncher(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 112 | const Extension* app, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 113 | const base::FilePath& file_path) |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 114 | : context_(context), |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 115 | extension_id(app->id()), |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 116 | mime_type_collector_(context), |
| 117 | is_directory_collector_(context) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 118 | if (!file_path.empty()) |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 119 | entry_paths_.push_back(file_path); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 120 | } |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 121 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 122 | void set_action_data(std::unique_ptr<app_runtime::ActionData> action_data) { |
| 123 | action_data_ = std::move(action_data); |
| 124 | } |
| 125 | |
| 126 | void set_launch_source(extensions::AppLaunchSource launch_source) { |
| 127 | launch_source_ = launch_source; |
| 128 | } |
| 129 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 130 | void Launch() { |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 131 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 132 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 133 | const Extension* app = GetExtension(); |
| 134 | if (!app) |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 135 | return; |
| 136 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 137 | if (entry_paths_.empty()) { |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 138 | LaunchWithBasicData(); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 139 | return; |
| 140 | } |
| 141 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 142 | for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 143 | DCHECK(entry_paths_[i].IsAbsolute()); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 144 | } |
[email protected] | 906ae21 | 2013-03-24 01:37:13 | [diff] [blame] | 145 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 146 | is_directory_collector_.CollectForEntriesPaths( |
| 147 | entry_paths_, |
| 148 | base::Bind(&PlatformAppPathLauncher::OnAreDirectoriesCollected, this, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 149 | HasFileSystemWritePermission(app))); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 152 | void LaunchWithHandler(const std::string& handler_id) { |
| 153 | handler_id_ = handler_id; |
| 154 | Launch(); |
| 155 | } |
| 156 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 157 | void LaunchWithRelativePath(const base::FilePath& current_directory) { |
Michael Giuffrida | fc9947e | 2017-07-26 09:37:47 | [diff] [blame] | 158 | base::PostTaskWithTraits( |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 159 | FROM_HERE, |
Michael Giuffrida | fc9947e | 2017-07-26 09:37:47 | [diff] [blame] | 160 | {base::TaskPriority::USER_VISIBLE, base::MayBlock(), |
| 161 | base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, |
| 162 | base::Bind(&PlatformAppPathLauncher::MakePathAbsolute, this, |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 163 | current_directory)); |
| 164 | } |
| 165 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 166 | private: |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 167 | friend class base::RefCountedThreadSafe<PlatformAppPathLauncher>; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 168 | |
Chris Watkins | ee8488b | 2017-11-27 04:06:56 | [diff] [blame] | 169 | virtual ~PlatformAppPathLauncher() = default; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 170 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 171 | void MakePathAbsolute(const base::FilePath& current_directory) { |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 172 | for (std::vector<base::FilePath>::iterator it = entry_paths_.begin(); |
| 173 | it != entry_paths_.end(); ++it) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 174 | if (!DoMakePathAbsolute(current_directory, &*it)) { |
| 175 | LOG(WARNING) << "Cannot make absolute path from " << it->value(); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 176 | base::PostTaskWithTraits( |
| 177 | FROM_HERE, {BrowserThread::UI}, |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 178 | base::BindOnce(&PlatformAppPathLauncher::LaunchWithBasicData, |
| 179 | this)); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 180 | return; |
| 181 | } |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 182 | } |
| 183 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 184 | base::PostTaskWithTraits( |
| 185 | FROM_HERE, {BrowserThread::UI}, |
| 186 | base::Bind(&PlatformAppPathLauncher::Launch, this)); |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 187 | } |
| 188 | |
mostynb | ecb4a22b | 2016-04-04 06:08:01 | [diff] [blame] | 189 | void OnFilesValid(std::unique_ptr<std::set<base::FilePath>> directory_paths) { |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 190 | mime_type_collector_.CollectForLocalPaths( |
| 191 | entry_paths_, |
| 192 | base::Bind( |
| 193 | &PlatformAppPathLauncher::OnAreDirectoriesAndMimeTypesCollected, |
| 194 | this, base::Passed(std::move(directory_paths)))); |
[email protected] | ffb8706 | 2013-08-29 10:02:25 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | fb6de88 | 2014-07-03 07:50:17 | [diff] [blame] | 197 | void OnFilesInvalid(const base::FilePath& /* error_path */) { |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 198 | LaunchWithBasicData(); |
[email protected] | ffb8706 | 2013-08-29 10:02:25 | [diff] [blame] | 199 | } |
| 200 | |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 201 | void LaunchWithBasicData() { |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 202 | // This method is required as an entry point on the UI thread. |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 203 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 204 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 205 | const Extension* app = GetExtension(); |
| 206 | if (!app) |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 207 | return; |
| 208 | |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 209 | std::unique_ptr<app_runtime::LaunchData> launch_data = |
Gyuyoung Kim | 637cefb | 2018-02-03 03:03:21 | [diff] [blame] | 210 | std::make_unique<app_runtime::LaunchData>(); |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 211 | launch_data->action_data = std::move(action_data_); |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 212 | if (!handler_id_.empty()) |
| 213 | launch_data->id = std::make_unique<std::string>(handler_id_); |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 214 | |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 215 | AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 216 | context_, app, launch_source_, std::move(launch_data)); |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 217 | } |
| 218 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 219 | void OnAreDirectoriesCollected( |
| 220 | bool has_file_system_write_permission, |
mostynb | ecb4a22b | 2016-04-04 06:08:01 | [diff] [blame] | 221 | std::unique_ptr<std::set<base::FilePath>> directory_paths) { |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 222 | if (has_file_system_write_permission) { |
| 223 | std::set<base::FilePath>* const directory_paths_ptr = |
| 224 | directory_paths.get(); |
| 225 | PrepareFilesForWritableApp( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 226 | entry_paths_, context_, *directory_paths_ptr, |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 227 | base::Bind(&PlatformAppPathLauncher::OnFilesValid, this, |
| 228 | base::Passed(std::move(directory_paths))), |
| 229 | base::Bind(&PlatformAppPathLauncher::OnFilesInvalid, this)); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | OnFilesValid(std::move(directory_paths)); |
| 234 | } |
| 235 | |
| 236 | void OnAreDirectoriesAndMimeTypesCollected( |
mostynb | ecb4a22b | 2016-04-04 06:08:01 | [diff] [blame] | 237 | std::unique_ptr<std::set<base::FilePath>> directory_paths, |
| 238 | std::unique_ptr<std::vector<std::string>> mime_types) { |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 239 | DCHECK(entry_paths_.size() == mime_types->size()); |
| 240 | // If fetching a mime type failed, then use a fallback one. |
| 241 | for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 242 | const std::string mime_type = |
| 243 | !(*mime_types)[i].empty() ? (*mime_types)[i] : kFallbackMimeType; |
| 244 | bool is_directory = |
| 245 | directory_paths->find(entry_paths_[i]) != directory_paths->end(); |
| 246 | entries_.push_back( |
| 247 | extensions::EntryInfo(entry_paths_[i], mime_type, is_directory)); |
| 248 | } |
[email protected] | fb6de88 | 2014-07-03 07:50:17 | [diff] [blame] | 249 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 250 | const Extension* app = GetExtension(); |
| 251 | if (!app) |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 252 | return; |
| 253 | |
[email protected] | 8427a062 | 2013-02-11 17:00:57 | [diff] [blame] | 254 | // Find file handler from the platform app for the file being opened. |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 255 | const extensions::FileHandlerInfo* handler = NULL; |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 256 | if (!handler_id_.empty()) { |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 257 | handler = FileHandlerForId(*app, handler_id_); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 258 | if (handler) { |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 259 | for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 260 | if (!FileHandlerCanHandleEntry(*handler, entries_[i])) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 261 | LOG(WARNING) |
| 262 | << "Extension does not provide a valid file handler for " |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 263 | << entry_paths_[i].value(); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 264 | handler = NULL; |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } else { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 270 | const std::vector<const extensions::FileHandlerInfo*>& handlers = |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 271 | extensions::app_file_handler_util::FindFileHandlersForEntries( |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 272 | *app, entries_); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 273 | if (!handlers.empty()) |
| 274 | handler = handlers[0]; |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 275 | } |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 276 | |
[email protected] | 8427a062 | 2013-02-11 17:00:57 | [diff] [blame] | 277 | // If this app doesn't have a file handler that supports the file, launch |
| 278 | // with no launch data. |
| 279 | if (!handler) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 280 | LOG(WARNING) << "Extension does not provide a valid file handler."; |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 281 | LaunchWithBasicData(); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
[email protected] | 56573d7 | 2013-05-09 06:36:37 | [diff] [blame] | 285 | if (handler_id_.empty()) |
| 286 | handler_id_ = handler->id; |
| 287 | |
[email protected] | 4e04f1e | 2012-06-20 03:20:31 | [diff] [blame] | 288 | // Access needs to be granted to the file for the process associated with |
| 289 | // the extension. To do this the ExtensionHost is needed. This might not be |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 290 | // available, or it might be in the process of being unloaded, in which case |
[email protected] | 4e04f1e | 2012-06-20 03:20:31 | [diff] [blame] | 291 | // the lazy background task queue is used to load the extension and then |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 292 | // call back to us. |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 293 | extensions::LazyBackgroundTaskQueue* const queue = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 294 | extensions::LazyBackgroundTaskQueue::Get(context_); |
| 295 | if (queue->ShouldEnqueueTask(context_, app)) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 296 | queue->AddPendingTask( |
David Bertoni | 8269a09 | 2018-12-19 15:55:42 | [diff] [blame] | 297 | extensions::LazyContextId(context_, extension_id), |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 298 | base::Bind(&PlatformAppPathLauncher::GrantAccessToFilesAndLaunch, |
| 299 | this)); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 300 | return; |
| 301 | } |
| 302 | |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 303 | extensions::ProcessManager* const process_manager = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 304 | extensions::ProcessManager::Get(context_); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 305 | ExtensionHost* const host = |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 306 | process_manager->GetBackgroundHostForExtension(extension_id); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 307 | DCHECK(host); |
David Bertoni | 643f6a94 | 2018-12-17 16:50:07 | [diff] [blame] | 308 | GrantAccessToFilesAndLaunch( |
| 309 | std::make_unique<extensions::LazyContextTaskQueue::ContextInfo>(host)); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 310 | } |
| 311 | |
David Bertoni | 643f6a94 | 2018-12-17 16:50:07 | [diff] [blame] | 312 | void GrantAccessToFilesAndLaunch( |
| 313 | std::unique_ptr<extensions::LazyContextTaskQueue::ContextInfo> |
| 314 | context_info) { |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 315 | const Extension* app = GetExtension(); |
| 316 | if (!app) |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 317 | return; |
| 318 | |
David Bertoni | 643f6a94 | 2018-12-17 16:50:07 | [diff] [blame] | 319 | // If there was an error loading the app page, |context_info| will be NULL. |
| 320 | if (!context_info) { |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 321 | LOG(ERROR) << "Could not load app page for " << extension_id; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 322 | return; |
| 323 | } |
| 324 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 325 | std::vector<GrantedFileEntry> granted_entries; |
| 326 | for (size_t i = 0; i < entry_paths_.size(); ++i) { |
David Bertoni | 643f6a94 | 2018-12-17 16:50:07 | [diff] [blame] | 327 | granted_entries.push_back(CreateFileEntry( |
| 328 | context_, app, context_info->render_process_host->GetID(), |
| 329 | entries_[i].path, entries_[i].is_directory)); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 332 | AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 333 | context_, app, launch_source_, handler_id_, entries_, granted_entries, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 334 | std::move(action_data_)); |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | const Extension* GetExtension() const { |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 338 | return extensions::ExtensionRegistry::Get(context_)->GetExtensionById( |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 339 | extension_id, extensions::ExtensionRegistry::EVERYTHING); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 340 | } |
| 341 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 342 | // The browser context the app should be run in. |
| 343 | content::BrowserContext* context_; |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 344 | // The id of the extension providing the app. A pointer to the extension is |
| 345 | // not kept as the extension may be unloaded and deleted during the course of |
| 346 | // the launch. |
| 347 | const std::string extension_id; |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 348 | extensions::AppLaunchSource launch_source_ = extensions::SOURCE_FILE_HANDLER; |
| 349 | std::unique_ptr<app_runtime::ActionData> action_data_; |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 350 | // A list of files and directories to be passed through to the app. |
| 351 | std::vector<base::FilePath> entry_paths_; |
| 352 | // A corresponding list with EntryInfo for every base::FilePath in |
| 353 | // entry_paths_. |
| 354 | std::vector<extensions::EntryInfo> entries_; |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 355 | // The ID of the file handler used to launch the app. |
| 356 | std::string handler_id_; |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 357 | extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; |
| 358 | extensions::app_file_handler_util::IsDirectoryCollector |
| 359 | is_directory_collector_; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 360 | |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 361 | DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); |
[email protected] | 4e04f1e | 2012-06-20 03:20:31 | [diff] [blame] | 362 | }; |
| 363 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 364 | } // namespace |
| 365 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 366 | void LaunchPlatformAppWithCommandLine(content::BrowserContext* context, |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 367 | const extensions::Extension* app, |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 368 | const base::CommandLine& command_line, |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 369 | const base::FilePath& current_directory, |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 370 | extensions::AppLaunchSource source, |
| 371 | PlayStoreStatus play_store_status) { |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 372 | LaunchPlatformAppWithCommandLineAndLaunchId(context, app, "", command_line, |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 373 | current_directory, source, |
| 374 | play_store_status); |
| 375 | } |
| 376 | |
| 377 | void LaunchPlatformAppWithCommandLineAndLaunchId( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 378 | content::BrowserContext* context, |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 379 | const extensions::Extension* app, |
| 380 | const std::string& launch_id, |
| 381 | const base::CommandLine& command_line, |
| 382 | const base::FilePath& current_directory, |
| 383 | extensions::AppLaunchSource source, |
| 384 | PlayStoreStatus play_store_status) { |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 385 | // An app with "kiosk_only" should not be installed and launched |
| 386 | // outside of ChromeOS kiosk mode in the first place. This is a defensive |
| 387 | // check in case this scenario does occur. |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 388 | if (extensions::KioskModeInfo::IsKioskOnly(app)) { |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 389 | bool in_kiosk_mode = false; |
| 390 | #if defined(OS_CHROMEOS) |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 391 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 392 | in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); |
| 393 | #endif |
| 394 | if (!in_kiosk_mode) { |
| 395 | LOG(ERROR) << "App with 'kiosk_only' attribute must be run in " |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 396 | << " ChromeOS kiosk mode."; |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 397 | NOTREACHED(); |
[email protected] | 8a01117 | 2013-08-09 04:29:23 | [diff] [blame] | 398 | return; |
| 399 | } |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 400 | } |
[email protected] | 8a01117 | 2013-08-09 04:29:23 | [diff] [blame] | 401 | |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 402 | #if defined(OS_WIN) |
| 403 | base::CommandLine::StringType about_blank_url( |
thestig | e5c64d9 | 2014-11-07 01:19:24 | [diff] [blame] | 404 | base::ASCIIToUTF16(url::kAboutBlankURL)); |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 405 | #else |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 406 | base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 407 | #endif |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 408 | base::CommandLine::StringVector args = command_line.GetArgs(); |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 409 | // Browser tests will add about:blank to the command line. This should |
| 410 | // never be interpreted as a file to open, as doing so with an app that |
| 411 | // has write access will result in a file 'about' being created, which |
| 412 | // causes problems on the bots. |
| 413 | if (args.empty() || (command_line.HasSwitch(switches::kTestType) && |
| 414 | args[0] == about_blank_url)) { |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 415 | std::unique_ptr<app_runtime::LaunchData> launch_data = |
Gyuyoung Kim | 637cefb | 2018-02-03 03:03:21 | [diff] [blame] | 416 | std::make_unique<app_runtime::LaunchData>(); |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 417 | if (play_store_status != PlayStoreStatus::PLAY_STORE_STATUS_UNKNOWN) |
| 418 | launch_data->play_store_status = play_store_status; |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 419 | if (!launch_id.empty()) |
| 420 | launch_data->id.reset(new std::string(launch_id)); |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 421 | AppRuntimeEventRouter::DispatchOnLaunchedEvent(context, app, source, |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 422 | std::move(launch_data)); |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 423 | return; |
| 424 | } |
| 425 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 426 | base::FilePath file_path(command_line.GetArgs()[0]); |
| 427 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 428 | new PlatformAppPathLauncher(context, app, file_path); |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 429 | launcher->LaunchWithRelativePath(current_directory); |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 430 | } |
| 431 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 432 | void LaunchPlatformAppWithPath(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 433 | const Extension* app, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 434 | const base::FilePath& file_path) { |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 435 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 436 | new PlatformAppPathLauncher(context, app, file_path); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 437 | launcher->Launch(); |
| 438 | } |
| 439 | |
| 440 | void LaunchPlatformAppWithAction( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 441 | content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 442 | const extensions::Extension* app, |
| 443 | std::unique_ptr<app_runtime::ActionData> action_data, |
| 444 | const base::FilePath& file_path) { |
tbarzic | 8bf50fca | 2017-06-22 03:02:18 | [diff] [blame] | 445 | CHECK(!action_data || !action_data->is_lock_screen_action || |
| 446 | !*action_data->is_lock_screen_action || |
| 447 | app->permissions_data()->HasAPIPermission( |
| 448 | extensions::APIPermission::kLockScreen)) |
| 449 | << "Launching lock screen action handler requires lockScreen permission."; |
| 450 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 451 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 452 | new PlatformAppPathLauncher(context, app, file_path); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 453 | launcher->set_action_data(std::move(action_data)); |
| 454 | launcher->set_launch_source(extensions::AppLaunchSource::SOURCE_UNTRACKED); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 455 | launcher->Launch(); |
| 456 | } |
| 457 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 458 | void LaunchPlatformApp(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 459 | const Extension* app, |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 460 | extensions::AppLaunchSource source) { |
| 461 | LaunchPlatformAppWithCommandLine( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 462 | context, app, base::CommandLine(base::CommandLine::NO_PROGRAM), |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 463 | base::FilePath(), source); |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 464 | } |
| 465 | |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 466 | void LaunchPlatformAppWithFileHandler( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 467 | content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 468 | const Extension* app, |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 469 | const std::string& handler_id, |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 470 | const std::vector<base::FilePath>& entry_paths) { |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 471 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 472 | new PlatformAppPathLauncher(context, app, entry_paths); |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 473 | launcher->LaunchWithHandler(handler_id); |
| 474 | } |
| 475 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 476 | void RestartPlatformApp(content::BrowserContext* context, |
| 477 | const Extension* app) { |
| 478 | EventRouter* event_router = EventRouter::Get(context); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 479 | bool listening_to_restart = event_router->ExtensionHasEventListener( |
| 480 | app->id(), app_runtime::OnRestarted::kEventName); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 481 | |
| 482 | if (listening_to_restart) { |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 483 | AppRuntimeEventRouter::DispatchOnRestartedEvent(context, app); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 484 | return; |
| 485 | } |
| 486 | |
[email protected] | 2d9f2a79 | 2014-01-24 12:44:09 | [diff] [blame] | 487 | extensions::ExtensionPrefs* extension_prefs = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 488 | extensions::ExtensionPrefs::Get(context); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 489 | bool had_windows = extension_prefs->IsActive(app->id()); |
| 490 | extension_prefs->SetIsActive(app->id(), false); |
| 491 | bool listening_to_launch = event_router->ExtensionHasEventListener( |
| 492 | app->id(), app_runtime::OnLaunched::kEventName); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 493 | |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 494 | if (listening_to_launch && had_windows) { |
| 495 | AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 496 | context, app, extensions::SOURCE_RESTART, nullptr); |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 497 | } |
[email protected] | fc2a40f | 2013-03-13 13:14:57 | [diff] [blame] | 498 | } |
| 499 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 500 | void LaunchPlatformAppWithUrl(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 501 | const Extension* app, |
[email protected] | 43197ea2 | 2013-09-10 15:31:56 | [diff] [blame] | 502 | const std::string& handler_id, |
| 503 | const GURL& url, |
| 504 | const GURL& referrer_url) { |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 505 | AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 506 | context, app, handler_id, url, referrer_url); |
[email protected] | 43197ea2 | 2013-09-10 15:31:56 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 509 | } // namespace apps |