blob: 85d18e7c822d76148350987ad96f36ed88742268 [file] [log] [blame]
[email protected]8e7b2cf42012-04-18 14:26:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d8c8f25f2011-11-02 18:18:012// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_
6#define CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_
[email protected]d8c8f25f2011-11-02 18:18:017
dchengc963c7142016-04-08 03:55:228#include <memory>
[email protected]d8c8f25f2011-11-02 18:18:019#include <string>
[email protected]98270432012-09-11 20:51:2410#include <vector>
[email protected]d8c8f25f2011-11-02 18:18:0111
[email protected]500c7bb2014-04-26 22:44:3312#include "base/bind.h"
[email protected]57999812013-02-24 05:40:5213#include "base/files/file_path.h"
avia2f4804a2015-12-24 23:11:1314#include "base/macros.h"
[email protected]d8c8f25f2011-11-02 18:18:0115#include "base/memory/ref_counted.h"
16#include "base/memory/weak_ptr.h"
michaelpg6a4874f2017-04-13 20:41:3317#include "extensions/browser/preload_check.h"
[email protected]d8c8f25f2011-11-02 18:18:0118
[email protected]d8c8f25f2011-11-02 18:18:0119class ExtensionService;
dgozmand741d25d2017-03-23 00:35:3420class Profile;
[email protected]d8c8f25f2011-11-02 18:18:0121
22namespace extensions {
23
[email protected]1c321ee2012-05-21 03:02:3424class Extension;
michaelpg6a4874f2017-04-13 20:41:3325class PreloadCheckGroup;
[email protected]1c321ee2012-05-21 03:02:3426
[email protected]98270432012-09-11 20:51:2427// Installs and loads an unpacked extension. Because internal state needs to be
28// held about the instalation process, only one call to Load*() should be made
29// per UnpackedInstaller.
[email protected]d8c8f25f2011-11-02 18:18:0130// TODO(erikkay): It might be useful to be able to load a packed extension
31// (presumably into memory) without installing it.
32class UnpackedInstaller
33 : public base::RefCountedThreadSafe<UnpackedInstaller> {
34 public:
rdevlin.croninf6ea63a2015-03-04 17:51:0435 using CompletionCallback = base::Callback<void(const Extension* extension,
36 const base::FilePath&,
37 const std::string&)>;
[email protected]500c7bb2014-04-26 22:44:3338
[email protected]d8c8f25f2011-11-02 18:18:0139 static scoped_refptr<UnpackedInstaller> Create(
40 ExtensionService* extension_service);
41
42 // Loads the extension from the directory |extension_path|, which is
43 // the top directory of a specific extension where its manifest file lives.
44 // Errors are reported through ExtensionErrorReporter. On success,
45 // ExtensionService::AddExtension() is called.
[email protected]650b2d52013-02-10 03:41:4546 void Load(const base::FilePath& extension_path);
[email protected]d8c8f25f2011-11-02 18:18:0147
48 // Loads the extension from the directory |extension_path|;
[email protected]2a69b942013-05-31 09:37:5349 // for use with command line switch --load-extension=path or
50 // --load-and-launch-app=path.
51 // This is equivalent to Load, except that it reads the extension from
52 // |extension_path| synchronously.
53 // The return value indicates whether the installation has begun successfully.
54 // The id of the extension being loaded is returned in |extension_id|.
proberge80a37f32016-08-04 19:44:5555 // |only_allow_apps| is used to avoid side-loading of non-app extensions.
[email protected]2a69b942013-05-31 09:37:5356 bool LoadFromCommandLine(const base::FilePath& extension_path,
proberge80a37f32016-08-04 19:44:5557 std::string* extension_id,
58 bool only_allow_apps);
[email protected]d8c8f25f2011-11-02 18:18:0159
60 // Allows prompting for plugins to be disabled; intended for testing only.
61 bool prompt_for_plugins() { return prompt_for_plugins_; }
62 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; }
63
[email protected]b7462f32012-09-02 15:18:1264 // Allows overriding of whether modern manifest versions are required;
65 // intended for testing.
66 bool require_modern_manifest_version() const {
67 return require_modern_manifest_version_;
68 }
69 void set_require_modern_manifest_version(bool val) {
70 require_modern_manifest_version_ = val;
71 }
72
[email protected]1f0722442014-05-01 17:26:0273 void set_be_noisy_on_failure(bool be_noisy_on_failure) {
74 be_noisy_on_failure_ = be_noisy_on_failure;
75 }
76
rdevlin.croninf6ea63a2015-03-04 17:51:0477 void set_completion_callback(const CompletionCallback& callback) {
78 callback_ = callback;
79 }
80
[email protected]d8c8f25f2011-11-02 18:18:0181 private:
82 friend class base::RefCountedThreadSafe<UnpackedInstaller>;
83
84 explicit UnpackedInstaller(ExtensionService* extension_service);
85 virtual ~UnpackedInstaller();
86
[email protected]98270432012-09-11 20:51:2487 // Must be called from the UI thread.
[email protected]849749d2013-05-06 17:30:4588 void ShowInstallPrompt();
89
[email protected]253fc2bb2014-07-10 04:21:1890 // Begin management policy and requirements checks.
91 void StartInstallChecks();
[email protected]98270432012-09-11 20:51:2492
michaelpg6a4874f2017-04-13 20:41:3393 // Callback from PreloadCheckGroup.
94 void OnInstallChecksComplete(PreloadCheck::Errors errors);
[email protected]98270432012-09-11 20:51:2495
[email protected]8e7b2cf42012-04-18 14:26:5896 // Verifies if loading unpacked extensions is allowed.
97 bool IsLoadingUnpackedAllowed() const;
98
[email protected]d8c8f25f2011-11-02 18:18:0199 // We change the input extension path to an absolute path, on the file thread.
100 // Then we need to check the file access preference, which needs
101 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on
102 // the UI thread. In turn, once that gets the pref, it goes back to the
103 // file thread with LoadWithFileAccess.
104 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know
[email protected]85df9d12014-04-15 17:02:14105 // what file access flags to pass to file_util::LoadExtension.
[email protected]d8c8f25f2011-11-02 18:18:01106 void GetAbsolutePath();
107 void CheckExtensionFileAccess();
[email protected]b7462f32012-09-02 15:18:12108 void LoadWithFileAccess(int flags);
[email protected]d8c8f25f2011-11-02 18:18:01109
[email protected]add57db72014-04-01 23:25:22110 // Notify the frontend that an attempt to retry will not be necessary.
111 void UnregisterLoadRetryListener();
112
[email protected]d8c8f25f2011-11-02 18:18:01113 // Notify the frontend that there was an error loading an extension.
114 void ReportExtensionLoadError(const std::string& error);
115
[email protected]253fc2bb2014-07-10 04:21:18116 // Passes the extension onto extension service.
117 void InstallExtension();
[email protected]d8c8f25f2011-11-02 18:18:01118
[email protected]b7462f32012-09-02 15:18:12119 // Helper to get the Extension::CreateFlags for the installing extension.
120 int GetFlags();
121
dgozmand741d25d2017-03-23 00:35:34122 const Extension* extension() { return extension_.get(); }
[email protected]253fc2bb2014-07-10 04:21:18123
[email protected]849749d2013-05-06 17:30:45124 // The service we will report results back to.
[email protected]d8c8f25f2011-11-02 18:18:01125 base::WeakPtr<ExtensionService> service_weak_;
126
dgozmand741d25d2017-03-23 00:35:34127 // The Profile the extension is being installed in.
128 Profile* profile_;
129
[email protected]d8c8f25f2011-11-02 18:18:01130 // The pathname of the directory to load from, which is an absolute path
131 // after GetAbsolutePath has been called.
[email protected]650b2d52013-02-10 03:41:45132 base::FilePath extension_path_;
[email protected]d8c8f25f2011-11-02 18:18:01133
dgozmand741d25d2017-03-23 00:35:34134 // The extension being installed.
135 scoped_refptr<const Extension> extension_;
136
[email protected]d8c8f25f2011-11-02 18:18:01137 // If true and the extension contains plugins, we prompt the user before
138 // loading.
139 bool prompt_for_plugins_;
140
[email protected]b7462f32012-09-02 15:18:12141 // Whether to require the extension installed to have a modern manifest
142 // version.
143 bool require_modern_manifest_version_;
144
[email protected]1f0722442014-05-01 17:26:02145 // Whether or not to be noisy (show a dialog) on failure. Defaults to true.
146 bool be_noisy_on_failure_;
147
michaelpg6a4874f2017-04-13 20:41:33148 // Checks to run before the extension can be installed.
149 std::unique_ptr<PreloadCheck> policy_check_;
150 std::unique_ptr<PreloadCheck> requirements_check_;
151
152 // Runs the above checks.
153 std::unique_ptr<PreloadCheckGroup> check_group_;
[email protected]849749d2013-05-06 17:30:45154
rdevlin.croninf6ea63a2015-03-04 17:51:04155 CompletionCallback callback_;
156
[email protected]d8c8f25f2011-11-02 18:18:01157 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller);
158};
159
160} // namespace extensions
161
162#endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_