blob: d060aa8b9b545dfc592ab93b5b9aab34c3593ef9 [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
11#include "base/file_path.h"
12#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"
15
[email protected]d8c8f25f2011-11-02 18:18:0116class ExtensionService;
17
18namespace extensions {
19
[email protected]1c321ee2012-05-21 03:02:3420class Extension;
[email protected]98270432012-09-11 20:51:2421class RequirementsChecker;
[email protected]1c321ee2012-05-21 03:02:3422
[email protected]98270432012-09-11 20:51:2423// Installs and loads an unpacked extension. Because internal state needs to be
24// held about the instalation process, only one call to Load*() should be made
25// per UnpackedInstaller.
[email protected]d8c8f25f2011-11-02 18:18:0126// TODO(erikkay): It might be useful to be able to load a packed extension
27// (presumably into memory) without installing it.
28class UnpackedInstaller
29 : public base::RefCountedThreadSafe<UnpackedInstaller> {
30 public:
31 static scoped_refptr<UnpackedInstaller> Create(
32 ExtensionService* extension_service);
33
34 // Loads the extension from the directory |extension_path|, which is
35 // the top directory of a specific extension where its manifest file lives.
36 // Errors are reported through ExtensionErrorReporter. On success,
37 // ExtensionService::AddExtension() is called.
[email protected]650b2d52013-02-10 03:41:4538 void Load(const base::FilePath& extension_path);
[email protected]d8c8f25f2011-11-02 18:18:0139
40 // Loads the extension from the directory |extension_path|;
41 // for use with command line switch --load-extension=path.
42 // This is equivalent to Load, except that it runs synchronously.
[email protected]650b2d52013-02-10 03:41:4543 void LoadFromCommandLine(const base::FilePath& extension_path);
[email protected]d8c8f25f2011-11-02 18:18:0144
45 // Allows prompting for plugins to be disabled; intended for testing only.
46 bool prompt_for_plugins() { return prompt_for_plugins_; }
47 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; }
48
[email protected]b7462f32012-09-02 15:18:1249 // Allows overriding of whether modern manifest versions are required;
50 // intended for testing.
51 bool require_modern_manifest_version() const {
52 return require_modern_manifest_version_;
53 }
54 void set_require_modern_manifest_version(bool val) {
55 require_modern_manifest_version_ = val;
56 }
57
[email protected]d8c8f25f2011-11-02 18:18:0158 private:
59 friend class base::RefCountedThreadSafe<UnpackedInstaller>;
60
61 explicit UnpackedInstaller(ExtensionService* extension_service);
62 virtual ~UnpackedInstaller();
63
[email protected]98270432012-09-11 20:51:2464 // Must be called from the UI thread.
65 void CheckRequirements();
66
67 // Callback from RequirementsChecker.
68 void OnRequirementsChecked(std::vector<std::string> requirement_errors);
69
[email protected]8e7b2cf42012-04-18 14:26:5870 // Verifies if loading unpacked extensions is allowed.
71 bool IsLoadingUnpackedAllowed() const;
72
[email protected]d8c8f25f2011-11-02 18:18:0173 // We change the input extension path to an absolute path, on the file thread.
74 // Then we need to check the file access preference, which needs
75 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on
76 // the UI thread. In turn, once that gets the pref, it goes back to the
77 // file thread with LoadWithFileAccess.
78 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know
79 // what file access flags to pass to extension_file_util::LoadExtension.
80 void GetAbsolutePath();
81 void CheckExtensionFileAccess();
[email protected]b7462f32012-09-02 15:18:1282 void LoadWithFileAccess(int flags);
[email protected]d8c8f25f2011-11-02 18:18:0183
84 // Notify the frontend that there was an error loading an extension.
85 void ReportExtensionLoadError(const std::string& error);
86
87 // Called when an unpacked extension has been loaded and installed.
[email protected]98270432012-09-11 20:51:2488 void OnLoaded();
[email protected]d8c8f25f2011-11-02 18:18:0189
[email protected]b7462f32012-09-02 15:18:1290 // Helper to get the Extension::CreateFlags for the installing extension.
91 int GetFlags();
92
[email protected]d8c8f25f2011-11-02 18:18:0193 base::WeakPtr<ExtensionService> service_weak_;
94
95 // The pathname of the directory to load from, which is an absolute path
96 // after GetAbsolutePath has been called.
[email protected]650b2d52013-02-10 03:41:4597 base::FilePath extension_path_;
[email protected]d8c8f25f2011-11-02 18:18:0198
99 // If true and the extension contains plugins, we prompt the user before
100 // loading.
101 bool prompt_for_plugins_;
102
[email protected]98270432012-09-11 20:51:24103 scoped_ptr<RequirementsChecker> requirements_checker_;
104
105 scoped_refptr<const Extension> extension_;
106
[email protected]b7462f32012-09-02 15:18:12107 // Whether to require the extension installed to have a modern manifest
108 // version.
109 bool require_modern_manifest_version_;
110
[email protected]d8c8f25f2011-11-02 18:18:01111 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller);
112};
113
114} // namespace extensions
115
116#endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_