Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: chrome/browser/extensions/crx_installer.h

Issue 340057: Add first-class support for user scripts (Closed)
Patch Set: newness Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 20 matching lines...) Expand all
31 // and by UtilityProcessHost. 31 // and by UtilityProcessHost.
32 // 32 //
33 // Additionally, we hold a reference to our own client so that it lives at least 33 // Additionally, we hold a reference to our own client so that it lives at least
34 // long enough to receive the result of unpacking. 34 // long enough to receive the result of unpacking.
35 // 35 //
36 // TODO(aa): Pull out a frontend interface for testing? 36 // TODO(aa): Pull out a frontend interface for testing?
37 class CrxInstaller : 37 class CrxInstaller :
38 public SandboxedExtensionUnpackerClient, 38 public SandboxedExtensionUnpackerClient,
39 public ExtensionInstallUI::Delegate { 39 public ExtensionInstallUI::Delegate {
40 public: 40 public:
41 // Starts the installation of the crx file in |crx_path| into 41 // Starts the installation of the crx file in |source_file| into
42 // |install_directory|. 42 // |install_directory|.
43 // 43 //
44 // Other params: 44 // Other params:
45 // install_source: The source of the install (external, --load-extension, etc 45 // install_source: The source of the install (external, --load-extension, etc
46 // expected_id: Optional. If the caller knows what the ID of this extension 46 // expected_id: Optional. If the caller knows what the ID of this extension
47 // should be after unpacking, it can be specified here as a 47 // should be after unpacking, it can be specified here as a
48 // sanity check. 48 // sanity check.
49 // delete_crx: Whether the crx should be deleted on completion. 49 // delete_crx: Whether the crx should be deleted on completion.
50 // frontend: The ExtensionsService to report the successfully installed 50 // frontend: The ExtensionsService to report the successfully installed
51 // extension to. 51 // extension to.
52 // client: Optional. If specified, will be used to confirm installation and 52 // client: Optional. If specified, will be used to confirm installation and
53 // also notified of success/fail. Note that we hold a reference to 53 // also notified of success/fail. Note that we hold a reference to
54 // this, so it can outlive its creator (eg the UI). 54 // this, so it can outlive its creator (eg the UI).
55 static void Start(const FilePath& crx_path, 55 static void Start(const FilePath& source_file,
56 const FilePath& install_directory, 56 const FilePath& install_directory,
57 Extension::Location install_source, 57 Extension::Location install_source,
58 const std::string& expected_id, 58 const std::string& expected_id,
59 bool delete_crx, 59 bool delete_source,
60 bool allow_privilege_increase, 60 bool allow_privilege_increase,
61 ExtensionsService* frontend, 61 ExtensionsService* frontend,
62 ExtensionInstallUI* client); 62 ExtensionInstallUI* client);
63 63
64 // Starts the installation of the user script file in |source_file| into
65 // |install_directory|. The script will be converted to an extension.
66 // See Start() for argument descriptions.
67 static void InstallUserScript(const FilePath& source_file,
68 const GURL& original_url,
69 const FilePath& install_directory,
70 bool delete_source,
71 ExtensionsService* frontend,
72 ExtensionInstallUI* client);
73
64 // Given the path to the large icon from an extension, read it if present and 74 // Given the path to the large icon from an extension, read it if present and
65 // decode it into result. 75 // decode it into result.
66 static void DecodeInstallIcon(const FilePath& large_icon_path, 76 static void DecodeInstallIcon(const FilePath& large_icon_path,
67 scoped_ptr<SkBitmap>* result); 77 scoped_ptr<SkBitmap>* result);
68 78
69 // ExtensionInstallUI::Delegate 79 // ExtensionInstallUI::Delegate
70 virtual void ContinueInstall(); 80 virtual void ContinueInstall();
71 virtual void AbortInstall(); 81 virtual void AbortInstall();
72 82
73 private: 83 private:
74 CrxInstaller(const FilePath& crx_path, 84 CrxInstaller(const FilePath& source_file,
75 const FilePath& install_directory, 85 const FilePath& install_directory,
76 Extension::Location install_source, 86 bool delete_source,
77 const std::string& expected_id,
78 bool delete_crx,
79 bool allow_privilege_increase,
80 ExtensionsService* frontend, 87 ExtensionsService* frontend,
81 ExtensionInstallUI* client); 88 ExtensionInstallUI* client);
82 ~CrxInstaller(); 89 ~CrxInstaller();
83 90
91 // Converts the source user script to an extension.
92 void ConvertUserScriptOnFileThread();
93
84 // SandboxedExtensionUnpackerClient 94 // SandboxedExtensionUnpackerClient
85 virtual void OnUnpackFailure(const std::string& error_message); 95 virtual void OnUnpackFailure(const std::string& error_message);
86 virtual void OnUnpackSuccess(const FilePath& temp_dir, 96 virtual void OnUnpackSuccess(const FilePath& temp_dir,
87 const FilePath& extension_dir, 97 const FilePath& extension_dir,
88 Extension* extension); 98 Extension* extension);
89 99
90 // Runs on the UI thread. Confirms with the user (via ExtensionInstallUI) that 100 // Runs on the UI thread. Confirms with the user (via ExtensionInstallUI) that
91 // it is OK to install this extension. 101 // it is OK to install this extension.
92 void ConfirmInstall(); 102 void ConfirmInstall();
93 103
94 // Runs on File thread. Install the unpacked extension into the profile and 104 // Runs on File thread. Install the unpacked extension into the profile and
95 // notify the frontend. 105 // notify the frontend.
96 void CompleteInstall(); 106 void CompleteInstall();
97 107
98 // Result reporting. 108 // Result reporting.
99 void ReportFailureFromFileThread(const std::string& error); 109 void ReportFailureFromFileThread(const std::string& error);
100 void ReportFailureFromUIThread(const std::string& error); 110 void ReportFailureFromUIThread(const std::string& error);
101 void ReportOverinstallFromFileThread(); 111 void ReportOverinstallFromFileThread();
102 void ReportOverinstallFromUIThread(); 112 void ReportOverinstallFromUIThread();
103 void ReportSuccessFromFileThread(); 113 void ReportSuccessFromFileThread();
104 void ReportSuccessFromUIThread(); 114 void ReportSuccessFromUIThread();
105 115
106 // The crx file we're installing. 116 // The file we're installing.
107 FilePath crx_path_; 117 FilePath source_file_;
118
119 // The URL the file was downloaded from. Only used for user scripts.
120 GURL original_url_;
108 121
109 // The directory extensions are installed to. 122 // The directory extensions are installed to.
110 FilePath install_directory_; 123 FilePath install_directory_;
111 124
112 // The location the installation came from (bundled with Chromium, registry, 125 // The location the installation came from (bundled with Chromium, registry,
113 // manual install, etc). This metadata is saved with the installation if 126 // manual install, etc). This metadata is saved with the installation if
114 // successful. 127 // successful.
115 Extension::Location install_source_; 128 Extension::Location install_source_;
116 129
117 // For updates and external installs we have an ID we're expecting the 130 // For updates and external installs we have an ID we're expecting the
118 // extension to contain. 131 // extension to contain.
119 std::string expected_id_; 132 std::string expected_id_;
120 133
121 // Whether manual extension installation is enabled. We can't just check this 134 // Whether manual extension installation is enabled. We can't just check this
122 // before trying to install because themes are special-cased to always be 135 // before trying to install because themes are special-cased to always be
123 // allowed. 136 // allowed.
124 bool extensions_enabled_; 137 bool extensions_enabled_;
125 138
126 // Whether we're supposed to delete the source crx file on destruction. 139 // Whether we're supposed to delete the source file on destruction.
127 bool delete_crx_; 140 bool delete_source_;
128 141
129 // Whether privileges should be allowed to silently increaes from any 142 // Whether privileges should be allowed to silently increaes from any
130 // previously installed version of the extension. 143 // previously installed version of the extension.
131 bool allow_privilege_increase_; 144 bool allow_privilege_increase_;
132 145
133 // The extension we're installing. We own this and either pass it off to 146 // The extension we're installing. We own this and either pass it off to
134 // ExtensionsService on success, or delete it on failure. 147 // ExtensionsService on success, or delete it on failure.
135 scoped_ptr<Extension> extension_; 148 scoped_ptr<Extension> extension_;
136 149
137 // If non-empty, contains the current version of the extension we're 150 // If non-empty, contains the current version of the extension we're
(...skipping 18 matching lines...) Expand all
156 // temp_dir_, so we don't have to delete it explicitly. 169 // temp_dir_, so we don't have to delete it explicitly.
157 FilePath unpacked_extension_root_; 170 FilePath unpacked_extension_root_;
158 171
159 // The unpacker we will use to unpack the extension. 172 // The unpacker we will use to unpack the extension.
160 SandboxedExtensionUnpacker* unpacker_; 173 SandboxedExtensionUnpacker* unpacker_;
161 174
162 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); 175 DISALLOW_COPY_AND_ASSIGN(CrxInstaller);
163 }; 176 };
164 177
165 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ 178 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698