blob: d5964c5d4f22b82dbc91752b5f083d692148b85d [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|;
42 // for use with command line switch --load-extension=path.
[email protected]9d02fa12013-02-19 05:12:5743 // This is equivalent to Load, except that it runs synchronously and
44 // optionally launches the extension once it's loaded.
45 void LoadFromCommandLine(const base::FilePath& extension_path,
46 bool launch_on_load);
[email protected]d8c8f25f2011-11-02 18:18:0147
48 // Allows prompting for plugins to be disabled; intended for testing only.
49 bool prompt_for_plugins() { return prompt_for_plugins_; }
50 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; }
51
[email protected]b7462f32012-09-02 15:18:1252 // Allows overriding of whether modern manifest versions are required;
53 // intended for testing.
54 bool require_modern_manifest_version() const {
55 return require_modern_manifest_version_;
56 }
57 void set_require_modern_manifest_version(bool val) {
58 require_modern_manifest_version_ = val;
59 }
60
[email protected]d8c8f25f2011-11-02 18:18:0161 private:
62 friend class base::RefCountedThreadSafe<UnpackedInstaller>;
63
64 explicit UnpackedInstaller(ExtensionService* extension_service);
65 virtual ~UnpackedInstaller();
66
[email protected]98270432012-09-11 20:51:2467 // Must be called from the UI thread.
[email protected]849749d2013-05-06 17:30:4568 void ShowInstallPrompt();
69
70 // Calls CheckRequirements.
71 void CallCheckRequirements();
[email protected]98270432012-09-11 20:51:2472
73 // Callback from RequirementsChecker.
74 void OnRequirementsChecked(std::vector<std::string> requirement_errors);
75
[email protected]8e7b2cf42012-04-18 14:26:5876 // Verifies if loading unpacked extensions is allowed.
77 bool IsLoadingUnpackedAllowed() const;
78
[email protected]d8c8f25f2011-11-02 18:18:0179 // We change the input extension path to an absolute path, on the file thread.
80 // Then we need to check the file access preference, which needs
81 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on
82 // the UI thread. In turn, once that gets the pref, it goes back to the
83 // file thread with LoadWithFileAccess.
84 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know
85 // what file access flags to pass to extension_file_util::LoadExtension.
86 void GetAbsolutePath();
87 void CheckExtensionFileAccess();
[email protected]b7462f32012-09-02 15:18:1288 void LoadWithFileAccess(int flags);
[email protected]d8c8f25f2011-11-02 18:18:0189
90 // Notify the frontend that there was an error loading an extension.
91 void ReportExtensionLoadError(const std::string& error);
92
93 // Called when an unpacked extension has been loaded and installed.
[email protected]849749d2013-05-06 17:30:4594 void ConfirmInstall();
[email protected]d8c8f25f2011-11-02 18:18:0195
[email protected]b7462f32012-09-02 15:18:1296 // Helper to get the Extension::CreateFlags for the installing extension.
97 int GetFlags();
98
[email protected]849749d2013-05-06 17:30:4599 // The service we will report results back to.
[email protected]d8c8f25f2011-11-02 18:18:01100 base::WeakPtr<ExtensionService> service_weak_;
101
102 // The pathname of the directory to load from, which is an absolute path
103 // after GetAbsolutePath has been called.
[email protected]650b2d52013-02-10 03:41:45104 base::FilePath extension_path_;
[email protected]d8c8f25f2011-11-02 18:18:01105
106 // If true and the extension contains plugins, we prompt the user before
107 // loading.
108 bool prompt_for_plugins_;
109
[email protected]b7462f32012-09-02 15:18:12110 // Whether to require the extension installed to have a modern manifest
111 // version.
112 bool require_modern_manifest_version_;
113
[email protected]9d02fa12013-02-19 05:12:57114 // Whether to launch the extension once it's loaded.
115 bool launch_on_load_;
116
[email protected]849749d2013-05-06 17:30:45117 // Gives access to common methods and data of an extension installer.
118 ExtensionInstaller installer_;
119
[email protected]d8c8f25f2011-11-02 18:18:01120 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller);
121};
122
123} // namespace extensions
124
125#endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_