[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 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
thestig | 9471270 | 2014-09-10 07:46:59 | [diff] [blame] | 14 | #include "base/files/file_util.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 15 | #include "base/logging.h" |
| 16 | #include "base/memory/ref_counted.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 17 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 18 | #include "base/strings/utf_string_conversions.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 19 | #include "base/task/post_task.h" |
| 20 | #include "base/task/task_traits.h" |
Jay Harris | d3191c0 | 2019-08-16 01:23:39 | [diff] [blame] | 21 | #include "components/services/app_service/public/cpp/file_handler_info.h" |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 22 | #include "content/public/browser/browser_context.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 23 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 24 | #include "content/public/browser/browser_thread.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 25 | #include "content/public/browser/render_process_host.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 26 | #include "content/public/browser/web_contents.h" |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 27 | #include "content/public/common/content_switches.h" |
| 28 | #include "content/public/common/url_constants.h" |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 29 | #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
michaelpg | bc6e379f | 2017-02-13 23:17:27 | [diff] [blame] | 30 | #include "extensions/browser/api/file_handlers/app_file_handler_util.h" |
| 31 | #include "extensions/browser/api/file_handlers/directory_util.h" |
| 32 | #include "extensions/browser/api/file_handlers/mime_util.h" |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 33 | #include "extensions/browser/entry_info.h" |
[email protected] | 3442353 | 2013-11-21 18:13:10 | [diff] [blame] | 34 | #include "extensions/browser/event_router.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 35 | #include "extensions/browser/extension_host.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 36 | #include "extensions/browser/extension_prefs.h" |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 37 | #include "extensions/browser/extension_registry.h" |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 38 | #include "extensions/browser/granted_file_entry.h" |
David Bertoni | 8269a09 | 2018-12-19 15:55:42 | [diff] [blame] | 39 | #include "extensions/browser/lazy_context_id.h" |
David Bertoni | 641e3ce0 | 2019-01-11 20:35:12 | [diff] [blame] | 40 | #include "extensions/browser/lazy_context_task_queue.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 41 | #include "extensions/browser/process_manager.h" |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 42 | #include "extensions/common/api/app_runtime.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 43 | #include "extensions/common/extension.h" |
[email protected] | 70c39bb | 2013-11-26 22:59:28 | [diff] [blame] | 44 | #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
tbarzic | 8bf50fca | 2017-06-22 03:02:18 | [diff] [blame] | 45 | #include "extensions/common/permissions/api_permission.h" |
| 46 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | f7fc72c | 2014-04-22 13:01:52 | [diff] [blame] | 47 | #include "net/base/filename_util.h" |
[email protected] | 43197ea2 | 2013-09-10 15:31:56 | [diff] [blame] | 48 | #include "url/gurl.h" |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 49 | |
[email protected] | 906ae21 | 2013-03-24 01:37:13 | [diff] [blame] | 50 | #if defined(OS_CHROMEOS) |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 51 | #include "components/user_manager/user_manager.h" |
[email protected] | 906ae21 | 2013-03-24 01:37:13 | [diff] [blame] | 52 | #endif |
| 53 | |
kalman | e58e6223 | 2015-07-23 18:27:22 | [diff] [blame] | 54 | namespace app_runtime = extensions::api::app_runtime; |
[email protected] | e054ea1 | 2013-08-20 00:41:57 | [diff] [blame] | 55 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 56 | using content::BrowserThread; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 57 | using extensions::AppRuntimeEventRouter; |
[email protected] | fc2a40f | 2013-03-13 13:14:57 | [diff] [blame] | 58 | using extensions::app_file_handler_util::CreateFileEntry; |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 59 | using extensions::app_file_handler_util::FileHandlerCanHandleEntry; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 60 | using extensions::app_file_handler_util::FileHandlerForId; |
[email protected] | ffb8706 | 2013-08-29 10:02:25 | [diff] [blame] | 61 | using extensions::app_file_handler_util::HasFileSystemWritePermission; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 62 | using extensions::app_file_handler_util::PrepareFilesForWritableApp; |
[email protected] | 3a368a2 | 2014-03-26 19:29:19 | [diff] [blame] | 63 | using extensions::EventRouter; |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 64 | using extensions::Extension; |
| 65 | using extensions::ExtensionHost; |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 66 | using extensions::GrantedFileEntry; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 67 | |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 68 | namespace apps { |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 69 | |
| 70 | namespace { |
| 71 | |
[email protected] | 9be0bad | 2013-04-18 05:51:36 | [diff] [blame] | 72 | const char kFallbackMimeType[] = "application/octet-stream"; |
| 73 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 74 | bool DoMakePathAbsolute(const base::FilePath& current_directory, |
| 75 | base::FilePath* file_path) { |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 76 | DCHECK(file_path); |
| 77 | if (file_path->IsAbsolute()) |
| 78 | return true; |
| 79 | |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 80 | if (current_directory.empty()) { |
kinaba | 6e0570b | 2014-10-21 05:43:34 | [diff] [blame] | 81 | base::FilePath absolute_path = base::MakeAbsoluteFilePath(*file_path); |
| 82 | if (absolute_path.empty()) |
| 83 | return false; |
| 84 | *file_path = absolute_path; |
| 85 | return true; |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 86 | } |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 87 | |
| 88 | if (!current_directory.IsAbsolute()) |
| 89 | return false; |
| 90 | |
| 91 | *file_path = current_directory.Append(*file_path); |
| 92 | return true; |
| 93 | } |
| 94 | |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 95 | // Class to handle launching of platform apps to open specific paths. |
[email protected] | 4e04f1e | 2012-06-20 03:20:31 | [diff] [blame] | 96 | // An instance of this class is created for each launch. The lifetime of these |
| 97 | // instances is managed by reference counted pointers. As long as an instance |
| 98 | // has outstanding tasks on a message queue it will be retained; once all |
| 99 | // outstanding tasks are completed it will be deleted. |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 100 | class PlatformAppPathLauncher |
| 101 | : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 102 | public: |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 103 | PlatformAppPathLauncher(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 104 | const Extension* app, |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 105 | const std::vector<base::FilePath>& entry_paths) |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 106 | : context_(context), |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 107 | extension_id(app->id()), |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 108 | entry_paths_(entry_paths), |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 109 | mime_type_collector_(context), |
| 110 | is_directory_collector_(context) {} |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 111 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 112 | PlatformAppPathLauncher(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 113 | const Extension* app, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 114 | const base::FilePath& file_path) |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 115 | : context_(context), |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 116 | extension_id(app->id()), |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 117 | mime_type_collector_(context), |
| 118 | is_directory_collector_(context) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 119 | if (!file_path.empty()) |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 120 | entry_paths_.push_back(file_path); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 121 | } |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 122 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 123 | void set_action_data(std::unique_ptr<app_runtime::ActionData> action_data) { |
| 124 | action_data_ = std::move(action_data); |
| 125 | } |
| 126 | |
| 127 | void set_launch_source(extensions::AppLaunchSource launch_source) { |
| 128 | launch_source_ = launch_source; |
| 129 | } |
| 130 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 131 | void Launch() { |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 132 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 133 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 134 | const Extension* app = GetExtension(); |
| 135 | if (!app) |
benwells | 8af3948 | 2014-11-20 08:32:31 | [diff] [blame] | 136 | return; |
| 137 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 138 | if (entry_paths_.empty()) { |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 139 | LaunchWithBasicData(); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 143 | for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 144 | DCHECK(entry_paths_[i].IsAbsolute()); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 145 | } |
[email protected] | 906ae21 | 2013-03-24 01:37:13 | [diff] [blame] | 146 | |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 147 | is_directory_collector_.CollectForEntriesPaths( |
| 148 | entry_paths_, |
Reilly Grant | e78baea1 | 2019-11-26 23:33:11 | [diff] [blame] | 149 | base::BindOnce(&PlatformAppPathLauncher::OnAreDirectoriesCollected, |
| 150 | this, HasFileSystemWritePermission(app))); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 153 | void LaunchWithHandler(const std::string& handler_id) { |
| 154 | handler_id_ = handler_id; |
| 155 | Launch(); |
| 156 | } |
| 157 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 158 | void LaunchWithRelativePath(const base::FilePath& current_directory) { |
Sami Kyostila | 13e85b3 | 2019-08-09 07:20:57 | [diff] [blame] | 159 | base::PostTask( |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 160 | FROM_HERE, |
Sami Kyostila | 13e85b3 | 2019-08-09 07:20:57 | [diff] [blame] | 161 | {base::ThreadPool(), base::TaskPriority::USER_VISIBLE, base::MayBlock(), |
Michael Giuffrida | fc9947e | 2017-07-26 09:37:47 | [diff] [blame] | 162 | base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, |
kylechar | 6de6f02 | 2019-02-26 00:14:59 | [diff] [blame] | 163 | base::BindOnce(&PlatformAppPathLauncher::MakePathAbsolute, this, |
| 164 | current_directory)); |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 167 | private: |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 168 | friend class base::RefCountedThreadSafe<PlatformAppPathLauncher>; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 169 | |
Chris Watkins | ee8488b | 2017-11-27 04:06:56 | [diff] [blame] | 170 | virtual ~PlatformAppPathLauncher() = default; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 171 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 172 | void MakePathAbsolute(const base::FilePath& current_directory) { |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 173 | for (std::vector<base::FilePath>::iterator it = entry_paths_.begin(); |
| 174 | it != entry_paths_.end(); ++it) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 175 | if (!DoMakePathAbsolute(current_directory, &*it)) { |
| 176 | LOG(WARNING) << "Cannot make absolute path from " << it->value(); |
Sami Kyostila | 13e85b3 | 2019-08-09 07:20:57 | [diff] [blame] | 177 | base::PostTask( |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 178 | FROM_HERE, {BrowserThread::UI}, |
Sam McNally | e11acd7 | 2018-11-02 04:54:34 | [diff] [blame] | 179 | base::BindOnce(&PlatformAppPathLauncher::LaunchWithBasicData, |
| 180 | this)); |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 181 | return; |
| 182 | } |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 183 | } |
| 184 | |
Sami Kyostila | 13e85b3 | 2019-08-09 07:20:57 | [diff] [blame] | 185 | base::PostTask(FROM_HERE, {BrowserThread::UI}, |
| 186 | base::BindOnce(&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_, |
Reilly Grant | e78baea1 | 2019-11-26 23:33:11 | [diff] [blame] | 192 | base::BindOnce( |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 193 | &PlatformAppPathLauncher::OnAreDirectoriesAndMimeTypesCollected, |
Reilly Grant | e78baea1 | 2019-11-26 23:33:11 | [diff] [blame] | 194 | this, 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, |
Reilly Grant | e78baea1 | 2019-11-26 23:33:11 | [diff] [blame] | 227 | base::BindOnce(&PlatformAppPathLauncher::OnFilesValid, this, |
| 228 | std::move(directory_paths)), |
| 229 | base::BindOnce(&PlatformAppPathLauncher::OnFilesInvalid, this)); |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 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. |
Jay Harris | d3191c0 | 2019-08-16 01:23:39 | [diff] [blame] | 255 | const FileHandlerInfo* handler = nullptr; |
[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(); |
Jay Harris | d3191c0 | 2019-08-16 01:23:39 | [diff] [blame] | 264 | handler = nullptr; |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } else { |
Alex Danilo | 1ef3e57 | 2019-02-27 08:48:12 | [diff] [blame] | 270 | const std::vector<extensions::FileHandlerMatch> handlers = |
| 271 | extensions::app_file_handler_util::FindFileHandlerMatchesForEntries( |
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()) |
Alex Danilo | 1ef3e57 | 2019-02-27 08:48:12 | [diff] [blame] | 274 | handler = handlers[0].handler; |
[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. |
David Bertoni | 641e3ce0 | 2019-01-11 20:35:12 | [diff] [blame] | 293 | const extensions::LazyContextId context_id(context_, extension_id); |
| 294 | extensions::LazyContextTaskQueue* const queue = context_id.GetTaskQueue(); |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 295 | if (queue->ShouldEnqueueTask(context_, app)) { |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 296 | queue->AddPendingTask( |
David Bertoni | 641e3ce0 | 2019-01-11 20:35:12 | [diff] [blame] | 297 | context_id, |
Reilly Grant | e78baea1 | 2019-11-26 23:33:11 | [diff] [blame] | 298 | base::BindOnce(&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; |
Eric Willigers | 618e130 | 2019-06-23 23:03:47 | [diff] [blame] | 348 | extensions::AppLaunchSource launch_source_ = |
| 349 | extensions::AppLaunchSource::kSourceFileHandler; |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 350 | std::unique_ptr<app_runtime::ActionData> action_data_; |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 351 | // A list of files and directories to be passed through to the app. |
| 352 | std::vector<base::FilePath> entry_paths_; |
| 353 | // A corresponding list with EntryInfo for every base::FilePath in |
| 354 | // entry_paths_. |
| 355 | std::vector<extensions::EntryInfo> entries_; |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 356 | // The ID of the file handler used to launch the app. |
| 357 | std::string handler_id_; |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 358 | extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; |
| 359 | extensions::app_file_handler_util::IsDirectoryCollector |
| 360 | is_directory_collector_; |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 361 | |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 362 | DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); |
[email protected] | 4e04f1e | 2012-06-20 03:20:31 | [diff] [blame] | 363 | }; |
| 364 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 365 | } // namespace |
| 366 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 367 | void LaunchPlatformAppWithCommandLine(content::BrowserContext* context, |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 368 | const extensions::Extension* app, |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 369 | const base::CommandLine& command_line, |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 370 | const base::FilePath& current_directory, |
Eric Willigers | 24c3228 | 2019-06-11 05:59:14 | [diff] [blame] | 371 | extensions::AppLaunchSource source) { |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 372 | LaunchPlatformAppWithCommandLineAndLaunchId(context, app, "", command_line, |
Eric Willigers | 24c3228 | 2019-06-11 05:59:14 | [diff] [blame] | 373 | current_directory, source); |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void LaunchPlatformAppWithCommandLineAndLaunchId( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 377 | content::BrowserContext* context, |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 378 | const extensions::Extension* app, |
| 379 | const std::string& launch_id, |
| 380 | const base::CommandLine& command_line, |
| 381 | const base::FilePath& current_directory, |
Eric Willigers | 24c3228 | 2019-06-11 05:59:14 | [diff] [blame] | 382 | extensions::AppLaunchSource source) { |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 383 | // An app with "kiosk_only" should not be installed and launched |
| 384 | // outside of ChromeOS kiosk mode in the first place. This is a defensive |
| 385 | // check in case this scenario does occur. |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 386 | if (extensions::KioskModeInfo::IsKioskOnly(app)) { |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 387 | bool in_kiosk_mode = false; |
| 388 | #if defined(OS_CHROMEOS) |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 389 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 390 | in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); |
| 391 | #endif |
| 392 | if (!in_kiosk_mode) { |
| 393 | LOG(ERROR) << "App with 'kiosk_only' attribute must be run in " |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 394 | << " ChromeOS kiosk mode."; |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 395 | NOTREACHED(); |
[email protected] | 8a01117 | 2013-08-09 04:29:23 | [diff] [blame] | 396 | return; |
| 397 | } |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 398 | } |
[email protected] | 8a01117 | 2013-08-09 04:29:23 | [diff] [blame] | 399 | |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 400 | #if defined(OS_WIN) |
| 401 | base::CommandLine::StringType about_blank_url( |
thestig | e5c64d9 | 2014-11-07 01:19:24 | [diff] [blame] | 402 | base::ASCIIToUTF16(url::kAboutBlankURL)); |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 403 | #else |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 404 | base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 405 | #endif |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 406 | base::CommandLine::StringVector args = command_line.GetArgs(); |
[email protected] | 4c35abc | 2014-05-14 02:13:58 | [diff] [blame] | 407 | // Browser tests will add about:blank to the command line. This should |
| 408 | // never be interpreted as a file to open, as doing so with an app that |
| 409 | // has write access will result in a file 'about' being created, which |
| 410 | // causes problems on the bots. |
| 411 | if (args.empty() || (command_line.HasSwitch(switches::kTestType) && |
| 412 | args[0] == about_blank_url)) { |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 413 | std::unique_ptr<app_runtime::LaunchData> launch_data = |
Gyuyoung Kim | 637cefb | 2018-02-03 03:03:21 | [diff] [blame] | 414 | std::make_unique<app_runtime::LaunchData>(); |
andra.paraschiv | 4e4fb8bb | 2016-12-15 11:13:54 | [diff] [blame] | 415 | if (!launch_id.empty()) |
| 416 | launch_data->id.reset(new std::string(launch_id)); |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 417 | AppRuntimeEventRouter::DispatchOnLaunchedEvent(context, app, source, |
rkc | 79bf63c | 2016-08-25 21:07:23 | [diff] [blame] | 418 | std::move(launch_data)); |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 422 | base::FilePath file_path(command_line.GetArgs()[0]); |
| 423 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 424 | new PlatformAppPathLauncher(context, app, file_path); |
[email protected] | 3567d14 | 2014-05-12 11:49:43 | [diff] [blame] | 425 | launcher->LaunchWithRelativePath(current_directory); |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 426 | } |
| 427 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 428 | void LaunchPlatformAppWithPath(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 429 | const Extension* app, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 430 | const base::FilePath& file_path) { |
[email protected] | a228c84 | 2012-09-04 10:07:05 | [diff] [blame] | 431 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 432 | new PlatformAppPathLauncher(context, app, file_path); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 433 | launcher->Launch(); |
| 434 | } |
| 435 | |
| 436 | void LaunchPlatformAppWithAction( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 437 | content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 438 | const extensions::Extension* app, |
| 439 | std::unique_ptr<app_runtime::ActionData> action_data, |
| 440 | const base::FilePath& file_path) { |
tbarzic | 8bf50fca | 2017-06-22 03:02:18 | [diff] [blame] | 441 | CHECK(!action_data || !action_data->is_lock_screen_action || |
| 442 | !*action_data->is_lock_screen_action || |
| 443 | app->permissions_data()->HasAPIPermission( |
| 444 | extensions::APIPermission::kLockScreen)) |
| 445 | << "Launching lock screen action handler requires lockScreen permission."; |
| 446 | |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 447 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 448 | new PlatformAppPathLauncher(context, app, file_path); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 449 | launcher->set_action_data(std::move(action_data)); |
Eric Willigers | 618e130 | 2019-06-23 23:03:47 | [diff] [blame] | 450 | launcher->set_launch_source(extensions::AppLaunchSource::kSourceUntracked); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 451 | launcher->Launch(); |
| 452 | } |
| 453 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 454 | void LaunchPlatformApp(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 455 | const Extension* app, |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 456 | extensions::AppLaunchSource source) { |
| 457 | LaunchPlatformAppWithCommandLine( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 458 | context, app, base::CommandLine(base::CommandLine::NO_PROGRAM), |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 459 | base::FilePath(), source); |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 460 | } |
| 461 | |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 462 | void LaunchPlatformAppWithFileHandler( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 463 | content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 464 | const Extension* app, |
[email protected] | 3113a23 | 2014-06-04 09:40:29 | [diff] [blame] | 465 | const std::string& handler_id, |
cmihail | 20232c2 | 2016-02-25 02:15:21 | [diff] [blame] | 466 | const std::vector<base::FilePath>& entry_paths) { |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 467 | scoped_refptr<PlatformAppPathLauncher> launcher = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 468 | new PlatformAppPathLauncher(context, app, entry_paths); |
[email protected] | af8dc08e | 2012-11-22 01:58:42 | [diff] [blame] | 469 | launcher->LaunchWithHandler(handler_id); |
| 470 | } |
| 471 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 472 | void RestartPlatformApp(content::BrowserContext* context, |
| 473 | const Extension* app) { |
| 474 | EventRouter* event_router = EventRouter::Get(context); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 475 | bool listening_to_restart = event_router->ExtensionHasEventListener( |
| 476 | app->id(), app_runtime::OnRestarted::kEventName); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 477 | |
| 478 | if (listening_to_restart) { |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 479 | AppRuntimeEventRouter::DispatchOnRestartedEvent(context, app); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | |
[email protected] | 2d9f2a79 | 2014-01-24 12:44:09 | [diff] [blame] | 483 | extensions::ExtensionPrefs* extension_prefs = |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 484 | extensions::ExtensionPrefs::Get(context); |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 485 | bool had_windows = extension_prefs->IsActive(app->id()); |
| 486 | extension_prefs->SetIsActive(app->id(), false); |
| 487 | bool listening_to_launch = event_router->ExtensionHasEventListener( |
| 488 | app->id(), app_runtime::OnLaunched::kEventName); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 489 | |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 490 | if (listening_to_launch && had_windows) { |
| 491 | AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
Eric Willigers | 618e130 | 2019-06-23 23:03:47 | [diff] [blame] | 492 | context, app, extensions::AppLaunchSource::kSourceRestart, nullptr); |
cylee | 988a9bb5 | 2014-11-04 16:39:16 | [diff] [blame] | 493 | } |
[email protected] | fc2a40f | 2013-03-13 13:14:57 | [diff] [blame] | 494 | } |
| 495 | |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 496 | void LaunchPlatformAppWithUrl(content::BrowserContext* context, |
jdufault | 9d3e955f | 2016-08-16 22:19:11 | [diff] [blame] | 497 | const Extension* app, |
[email protected] | 43197ea2 | 2013-09-10 15:31:56 | [diff] [blame] | 498 | const std::string& handler_id, |
| 499 | const GURL& url, |
| 500 | const GURL& referrer_url) { |
[email protected] | ce5f1b3 | 2014-06-22 01:46:45 | [diff] [blame] | 501 | AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 502 | context, app, handler_id, url, referrer_url); |
[email protected] | 43197ea2 | 2013-09-10 15:31:56 | [diff] [blame] | 503 | } |
| 504 | |
[email protected] | 24c81d69 | 2013-08-07 14:09:48 | [diff] [blame] | 505 | } // namespace apps |