blob: fea1f59cc1f4a525ec8dad5f6a143ed0c9c4ac04 [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]57999812013-02-24 05:40:5211#include "base/files/file_path.h"
[email protected]d8c8f25f2011-11-02 18:18:0112#include "base/memory/ref_counted.h"
[email protected]98270432012-09-11 20:51:2413#include "base/memory/scoped_ptr.h"
[email protected]d8c8f25f2011-11-02 18:18:0114#include "base/memory/weak_ptr.h"
[email protected]849749d2013-05-06 17:30:4515#include "chrome/browser/extensions/extension_installer.h"
[email protected]d8c8f25f2011-11-02 18:18:0116
[email protected]d8c8f25f2011-11-02 18:18:0117class ExtensionService;
18
19namespace extensions {
20
[email protected]1c321ee2012-05-21 03:02:3421class Extension;
[email protected]98270432012-09-11 20:51:2422class RequirementsChecker;
[email protected]1c321ee2012-05-21 03:02:3423
[email protected]98270432012-09-11 20:51:2424// Installs and loads an unpacked extension. Because internal state needs to be
25// held about the instalation process, only one call to Load*() should be made
26// per UnpackedInstaller.
[email protected]d8c8f25f2011-11-02 18:18:0127// TODO(erikkay): It might be useful to be able to load a packed extension
28// (presumably into memory) without installing it.
29class UnpackedInstaller
30 : public base::RefCountedThreadSafe<UnpackedInstaller> {
31 public:
32 static scoped_refptr<UnpackedInstaller> Create(
33 ExtensionService* extension_service);
34
35 // Loads the extension from the directory |extension_path|, which is
36 // the top directory of a specific extension where its manifest file lives.
37 // Errors are reported through ExtensionErrorReporter. On success,
38 // ExtensionService::AddExtension() is called.
[email protected]650b2d52013-02-10 03:41:4539 void Load(const base::FilePath& extension_path);
[email protected]d8c8f25f2011-11-02 18:18:0140
41 // Loads the extension from the directory |extension_path|;
[email protected]2a69b942013-05-31 09:37:5342 // for use with command line switch --load-extension=path or
43 // --load-and-launch-app=path.
44 // This is equivalent to Load, except that it reads the extension from
45 // |extension_path| synchronously.
46 // The return value indicates whether the installation has begun successfully.
47 // The id of the extension being loaded is returned in |extension_id|.
48 bool LoadFromCommandLine(const base::FilePath& extension_path,
49 std::string* extension_id);
[email protected]d8c8f25f2011-11-02 18:18:0150
51 // Allows prompting for plugins to be disabled; intended for testing only.
52 bool prompt_for_plugins() { return prompt_for_plugins_; }
53 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; }
54
[email protected]b7462f32012-09-02 15:18:1255 // Allows overriding of whether modern manifest versions are required;
56 // intended for testing.
57 bool require_modern_manifest_version() const {
58 return require_modern_manifest_version_;
59 }
60 void set_require_modern_manifest_version(bool val) {
61 require_modern_manifest_version_ = val;
62 }
63
[email protected]d8c8f25f2011-11-02 18:18:0164 private:
65 friend class base::RefCountedThreadSafe<UnpackedInstaller>;
66
67 explicit UnpackedInstaller(ExtensionService* extension_service);
68 virtual ~UnpackedInstaller();
69
[email protected]98270432012-09-11 20:51:2470 // Must be called from the UI thread.
[email protected]849749d2013-05-06 17:30:4571 void ShowInstallPrompt();
72
73 // Calls CheckRequirements.
74 void CallCheckRequirements();
[email protected]98270432012-09-11 20:51:2475
76 // Callback from RequirementsChecker.
77 void OnRequirementsChecked(std::vector<std::string> requirement_errors);
78
[email protected]8e7b2cf42012-04-18 14:26:5879 // Verifies if loading unpacked extensions is allowed.
80 bool IsLoadingUnpackedAllowed() const;
81
[email protected]d8c8f25f2011-11-02 18:18:0182 // We change the input extension path to an absolute path, on the file thread.
83 // Then we need to check the file access preference, which needs
84 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on
85 // the UI thread. In turn, once that gets the pref, it goes back to the
86 // file thread with LoadWithFileAccess.
87 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know
88 // what file access flags to pass to extension_file_util::LoadExtension.
89 void GetAbsolutePath();
90 void CheckExtensionFileAccess();
[email protected]b7462f32012-09-02 15:18:1291 void LoadWithFileAccess(int flags);
[email protected]d8c8f25f2011-11-02 18:18:0192
[email protected]add57db72014-04-01 23:25:2293 // Notify the frontend that an attempt to retry will not be necessary.
94 void UnregisterLoadRetryListener();
95
[email protected]d8c8f25f2011-11-02 18:18:0196 // Notify the frontend that there was an error loading an extension.
97 void ReportExtensionLoadError(const std::string& error);
98
99 // Called when an unpacked extension has been loaded and installed.
[email protected]849749d2013-05-06 17:30:45100 void ConfirmInstall();
[email protected]d8c8f25f2011-11-02 18:18:01101
[email protected]b7462f32012-09-02 15:18:12102 // Helper to get the Extension::CreateFlags for the installing extension.
103 int GetFlags();
104
[email protected]849749d2013-05-06 17:30:45105 // The service we will report results back to.
[email protected]d8c8f25f2011-11-02 18:18:01106 base::WeakPtr<ExtensionService> service_weak_;
107
108 // The pathname of the directory to load from, which is an absolute path
109 // after GetAbsolutePath has been called.
[email protected]650b2d52013-02-10 03:41:45110 base::FilePath extension_path_;
[email protected]d8c8f25f2011-11-02 18:18:01111
112 // If true and the extension contains plugins, we prompt the user before
113 // loading.
114 bool prompt_for_plugins_;
115
[email protected]b7462f32012-09-02 15:18:12116 // Whether to require the extension installed to have a modern manifest
117 // version.
118 bool require_modern_manifest_version_;
119
[email protected]849749d2013-05-06 17:30:45120 // Gives access to common methods and data of an extension installer.
121 ExtensionInstaller installer_;
122
[email protected]d8c8f25f2011-11-02 18:18:01123 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller);
124};
125
126} // namespace extensions
127
128#endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_