| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UNPACKED_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 13 | 15 |
| 14 class ExtensionService; | 16 class ExtensionService; |
| 15 | 17 |
| 16 namespace extensions { | 18 namespace extensions { |
| 17 | 19 |
| 18 class Extension; | 20 class Extension; |
| 21 class RequirementsChecker; |
| 19 | 22 |
| 20 // Installs and loads an unpacked extension. | 23 // Installs and loads an unpacked extension. |
| 21 // TODO(erikkay): It might be useful to be able to load a packed extension | 24 // TODO(erikkay): It might be useful to be able to load a packed extension |
| 22 // (presumably into memory) without installing it. | 25 // (presumably into memory) without installing it. |
| 23 class UnpackedInstaller | 26 class UnpackedInstaller |
| 24 : public base::RefCountedThreadSafe<UnpackedInstaller> { | 27 : public base::RefCountedThreadSafe<UnpackedInstaller> { |
| 25 public: | 28 public: |
| 26 static scoped_refptr<UnpackedInstaller> Create( | 29 static scoped_refptr<UnpackedInstaller> Create( |
| 27 ExtensionService* extension_service); | 30 ExtensionService* extension_service); |
| 28 | 31 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 // Allows prompting for plugins to be disabled; intended for testing only. | 43 // Allows prompting for plugins to be disabled; intended for testing only. |
| 41 bool prompt_for_plugins() { return prompt_for_plugins_; } | 44 bool prompt_for_plugins() { return prompt_for_plugins_; } |
| 42 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; } | 45 void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; } |
| 43 | 46 |
| 44 private: | 47 private: |
| 45 friend class base::RefCountedThreadSafe<UnpackedInstaller>; | 48 friend class base::RefCountedThreadSafe<UnpackedInstaller>; |
| 46 | 49 |
| 47 explicit UnpackedInstaller(ExtensionService* extension_service); | 50 explicit UnpackedInstaller(ExtensionService* extension_service); |
| 48 virtual ~UnpackedInstaller(); | 51 virtual ~UnpackedInstaller(); |
| 49 | 52 |
| 53 // Must be called from the UI thread. |
| 54 void CheckRequirements(); |
| 55 |
| 56 // Callback from RequirementsChecker. |
| 57 void RequirementsChecked(std::vector<std::string> errors); |
| 58 |
| 50 // Verifies if loading unpacked extensions is allowed. | 59 // Verifies if loading unpacked extensions is allowed. |
| 51 bool IsLoadingUnpackedAllowed() const; | 60 bool IsLoadingUnpackedAllowed() const; |
| 52 | 61 |
| 53 // We change the input extension path to an absolute path, on the file thread. | 62 // We change the input extension path to an absolute path, on the file thread. |
| 54 // Then we need to check the file access preference, which needs | 63 // Then we need to check the file access preference, which needs |
| 55 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on | 64 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on |
| 56 // the UI thread. In turn, once that gets the pref, it goes back to the | 65 // the UI thread. In turn, once that gets the pref, it goes back to the |
| 57 // file thread with LoadWithFileAccess. | 66 // file thread with LoadWithFileAccess. |
| 58 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know | 67 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know |
| 59 // what file access flags to pass to extension_file_util::LoadExtension. | 68 // what file access flags to pass to extension_file_util::LoadExtension. |
| 60 void GetAbsolutePath(); | 69 void GetAbsolutePath(); |
| 61 void CheckExtensionFileAccess(); | 70 void CheckExtensionFileAccess(); |
| 62 void LoadWithFileAccess(bool allow_file_access); | 71 void LoadWithFileAccess(bool allow_file_access); |
| 63 | 72 |
| 64 // Notify the frontend that there was an error loading an extension. | 73 // Notify the frontend that there was an error loading an extension. |
| 65 void ReportExtensionLoadError(const std::string& error); | 74 void ReportExtensionLoadError(const std::string& error); |
| 66 | 75 |
| 67 // Called when an unpacked extension has been loaded and installed. | 76 // Called when an unpacked extension has been loaded and installed. |
| 68 void OnLoaded(const scoped_refptr<const Extension>& extension); | 77 void OnLoaded(); |
| 69 | 78 |
| 70 base::WeakPtr<ExtensionService> service_weak_; | 79 base::WeakPtr<ExtensionService> service_weak_; |
| 71 | 80 |
| 72 // The pathname of the directory to load from, which is an absolute path | 81 // The pathname of the directory to load from, which is an absolute path |
| 73 // after GetAbsolutePath has been called. | 82 // after GetAbsolutePath has been called. |
| 74 FilePath extension_path_; | 83 FilePath extension_path_; |
| 75 | 84 |
| 76 // If true and the extension contains plugins, we prompt the user before | 85 // If true and the extension contains plugins, we prompt the user before |
| 77 // loading. | 86 // loading. |
| 78 bool prompt_for_plugins_; | 87 bool prompt_for_plugins_; |
| 79 | 88 |
| 89 scoped_ptr<RequirementsChecker> requirements_checker_; |
| 90 |
| 91 scoped_refptr<const Extension> extension_; |
| 92 |
| 80 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller); | 93 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller); |
| 81 }; | 94 }; |
| 82 | 95 |
| 83 } // namespace extensions | 96 } // namespace extensions |
| 84 | 97 |
| 85 #endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ | 98 #endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |
| OLD | NEW |