blob: 5d2414987efbdf4d76ae0f56cedccd55d036cad3 [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
8#include <string>
[email protected]98270432012-09-11 20:51:249#include <vector>
[email protected]d8c8f25f2011-11-02 18:18:0110
[email protected]500c7bb2014-04-26 22:44:3311#include "base/bind.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
[email protected]d8c8f25f2011-11-02 18:18:0113#include "base/memory/ref_counted.h"
[email protected]98270432012-09-11 20:51:2414#include "base/memory/scoped_ptr.h"
[email protected]d8c8f25f2011-11-02 18:18:0115#include "base/memory/weak_ptr.h"
[email protected]849749d2013-05-06 17:30:4516#include "chrome/browser/extensions/extension_installer.h"
[email protected]d8c8f25f2011-11-02 18:18:0117
[email protected]d8c8f25f2011-11-02 18:18:0118class ExtensionService;
19
20namespace extensions {
21
[email protected]1c321ee2012-05-21 03:02:3422class Extension;
[email protected]98270432012-09-11 20:51:2423class RequirementsChecker;
[email protected]1c321ee2012-05-21 03:02:3424
[email protected]98270432012-09-11 20:51:2425// Installs and loads an unpacked extension. Because internal state needs to be
26// held about the instalation process, only one call to Load*() should be made
27// per UnpackedInstaller.
[email protected]d8c8f25f2011-11-02 18:18:0128// TODO(erikkay): It might be useful to be able to load a packed extension
29// (presumably into memory) without installing it.
30class UnpackedInstaller
31 : public base::RefCountedThreadSafe<UnpackedInstaller> {
32 public:
[email protected]500c7bb2014-04-26 22:44:3333 typedef base::Callback<void(const base::FilePath&, const std::string&)>
34 OnFailureCallback;
35
[email protected]d8c8f25f2011-11-02 18:18:0136 static scoped_refptr<UnpackedInstaller> Create(
37 ExtensionService* extension_service);
38
39 // Loads the extension from the directory |extension_path|, which is
40 // the top directory of a specific extension where its manifest file lives.
41 // Errors are reported through ExtensionErrorReporter. On success,
42 // ExtensionService::AddExtension() is called.
[email protected]650b2d52013-02-10 03:41:4543 void Load(const base::FilePath& extension_path);
[email protected]d8c8f25f2011-11-02 18:18:0144
45 // Loads the extension from the directory |extension_path|;
[email protected]2a69b942013-05-31 09:37:5346 // for use with command line switch --load-extension=path or
47 // --load-and-launch-app=path.
48 // This is equivalent to Load, except that it reads the extension from
49 // |extension_path| synchronously.
50 // The return value indicates whether the installation has begun successfully.
51 // The id of the extension being loaded is returned in |extension_id|.
52 bool LoadFromCommandLine(const base::FilePath& extension_path,
53 std::string* extension_id);
[email protected]d8c8f25f2011-11-02 18:18:0154
55 // Allows prompting for plugins to be disabled; intended for testing only.
56 bool prompt_for_plugins() { return prompt_for_plugins_; }
57 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; }
58
[email protected]b7462f32012-09-02 15:18:1259 // Allows overriding of whether modern manifest versions are required;
60 // intended for testing.
61 bool require_modern_manifest_version() const {
62 return require_modern_manifest_version_;
63 }
64 void set_require_modern_manifest_version(bool val) {
65 require_modern_manifest_version_ = val;
66 }
67
[email protected]500c7bb2014-04-26 22:44:3368 void set_on_failure_callback(const OnFailureCallback& callback) {
69 on_failure_callback_ = callback;
70 }
71
[email protected]d8c8f25f2011-11-02 18:18:0172 private:
73 friend class base::RefCountedThreadSafe<UnpackedInstaller>;
74
75 explicit UnpackedInstaller(ExtensionService* extension_service);
76 virtual ~UnpackedInstaller();
77
[email protected]98270432012-09-11 20:51:2478 // Must be called from the UI thread.
[email protected]849749d2013-05-06 17:30:4579 void ShowInstallPrompt();
80
81 // Calls CheckRequirements.
82 void CallCheckRequirements();
[email protected]98270432012-09-11 20:51:2483
84 // Callback from RequirementsChecker.
85 void OnRequirementsChecked(std::vector<std::string> requirement_errors);
86
[email protected]8e7b2cf42012-04-18 14:26:5887 // Verifies if loading unpacked extensions is allowed.
88 bool IsLoadingUnpackedAllowed() const;
89
[email protected]d8c8f25f2011-11-02 18:18:0190 // We change the input extension path to an absolute path, on the file thread.
91 // Then we need to check the file access preference, which needs
92 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on
93 // the UI thread. In turn, once that gets the pref, it goes back to the
94 // file thread with LoadWithFileAccess.
95 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know
[email protected]85df9d12014-04-15 17:02:1496 // what file access flags to pass to file_util::LoadExtension.
[email protected]d8c8f25f2011-11-02 18:18:0197 void GetAbsolutePath();
98 void CheckExtensionFileAccess();
[email protected]b7462f32012-09-02 15:18:1299 void LoadWithFileAccess(int flags);
[email protected]d8c8f25f2011-11-02 18:18:01100
[email protected]add57db72014-04-01 23:25:22101 // Notify the frontend that an attempt to retry will not be necessary.
102 void UnregisterLoadRetryListener();
103
[email protected]d8c8f25f2011-11-02 18:18:01104 // Notify the frontend that there was an error loading an extension.
105 void ReportExtensionLoadError(const std::string& error);
106
107 // Called when an unpacked extension has been loaded and installed.
[email protected]849749d2013-05-06 17:30:45108 void ConfirmInstall();
[email protected]d8c8f25f2011-11-02 18:18:01109
[email protected]b7462f32012-09-02 15:18:12110 // Helper to get the Extension::CreateFlags for the installing extension.
111 int GetFlags();
112
[email protected]849749d2013-05-06 17:30:45113 // The service we will report results back to.
[email protected]d8c8f25f2011-11-02 18:18:01114 base::WeakPtr<ExtensionService> service_weak_;
115
116 // The pathname of the directory to load from, which is an absolute path
117 // after GetAbsolutePath has been called.
[email protected]650b2d52013-02-10 03:41:45118 base::FilePath extension_path_;
[email protected]d8c8f25f2011-11-02 18:18:01119
120 // If true and the extension contains plugins, we prompt the user before
121 // loading.
122 bool prompt_for_plugins_;
123
[email protected]b7462f32012-09-02 15:18:12124 // Whether to require the extension installed to have a modern manifest
125 // version.
126 bool require_modern_manifest_version_;
127
[email protected]500c7bb2014-04-26 22:44:33128 // An optional callback to set in order to be notified of failure.
129 OnFailureCallback on_failure_callback_;
130
[email protected]849749d2013-05-06 17:30:45131 // Gives access to common methods and data of an extension installer.
132 ExtensionInstaller installer_;
133
[email protected]d8c8f25f2011-11-02 18:18:01134 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller);
135};
136
137} // namespace extensions
138
139#endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_