| 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. Because internal state needs to be |
| 24 // held about the instalation process, only one call to Load*() should be made |
| 25 // per UnpackedInstaller. |
| 21 // TODO(erikkay): It might be useful to be able to load a packed extension | 26 // TODO(erikkay): It might be useful to be able to load a packed extension |
| 22 // (presumably into memory) without installing it. | 27 // (presumably into memory) without installing it. |
| 23 class UnpackedInstaller | 28 class UnpackedInstaller |
| 24 : public base::RefCountedThreadSafe<UnpackedInstaller> { | 29 : public base::RefCountedThreadSafe<UnpackedInstaller> { |
| 25 public: | 30 public: |
| 26 static scoped_refptr<UnpackedInstaller> Create( | 31 static scoped_refptr<UnpackedInstaller> Create( |
| 27 ExtensionService* extension_service); | 32 ExtensionService* extension_service); |
| 28 | 33 |
| 29 // Loads the extension from the directory |extension_path|, which is | 34 // Loads the extension from the directory |extension_path|, which is |
| 30 // the top directory of a specific extension where its manifest file lives. | 35 // the top directory of a specific extension where its manifest file lives. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 49 void set_require_modern_manifest_version(bool val) { | 54 void set_require_modern_manifest_version(bool val) { |
| 50 require_modern_manifest_version_ = val; | 55 require_modern_manifest_version_ = val; |
| 51 } | 56 } |
| 52 | 57 |
| 53 private: | 58 private: |
| 54 friend class base::RefCountedThreadSafe<UnpackedInstaller>; | 59 friend class base::RefCountedThreadSafe<UnpackedInstaller>; |
| 55 | 60 |
| 56 explicit UnpackedInstaller(ExtensionService* extension_service); | 61 explicit UnpackedInstaller(ExtensionService* extension_service); |
| 57 virtual ~UnpackedInstaller(); | 62 virtual ~UnpackedInstaller(); |
| 58 | 63 |
| 64 // 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 |
| 59 // Verifies if loading unpacked extensions is allowed. | 70 // Verifies if loading unpacked extensions is allowed. |
| 60 bool IsLoadingUnpackedAllowed() const; | 71 bool IsLoadingUnpackedAllowed() const; |
| 61 | 72 |
| 62 // We change the input extension path to an absolute path, on the file thread. | 73 // We change the input extension path to an absolute path, on the file thread. |
| 63 // Then we need to check the file access preference, which needs | 74 // Then we need to check the file access preference, which needs |
| 64 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on | 75 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on |
| 65 // the UI thread. In turn, once that gets the pref, it goes back to the | 76 // the UI thread. In turn, once that gets the pref, it goes back to the |
| 66 // file thread with LoadWithFileAccess. | 77 // file thread with LoadWithFileAccess. |
| 67 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know | 78 // TODO(yoz): It would be nice to remove this ping-pong, but we need to know |
| 68 // what file access flags to pass to extension_file_util::LoadExtension. | 79 // what file access flags to pass to extension_file_util::LoadExtension. |
| 69 void GetAbsolutePath(); | 80 void GetAbsolutePath(); |
| 70 void CheckExtensionFileAccess(); | 81 void CheckExtensionFileAccess(); |
| 71 void LoadWithFileAccess(int flags); | 82 void LoadWithFileAccess(int flags); |
| 72 | 83 |
| 73 // Notify the frontend that there was an error loading an extension. | 84 // Notify the frontend that there was an error loading an extension. |
| 74 void ReportExtensionLoadError(const std::string& error); | 85 void ReportExtensionLoadError(const std::string& error); |
| 75 | 86 |
| 76 // Called when an unpacked extension has been loaded and installed. | 87 // Called when an unpacked extension has been loaded and installed. |
| 77 void OnLoaded(const scoped_refptr<const Extension>& extension); | 88 void OnLoaded(); |
| 78 | 89 |
| 79 // Helper to get the Extension::CreateFlags for the installing extension. | 90 // Helper to get the Extension::CreateFlags for the installing extension. |
| 80 int GetFlags(); | 91 int GetFlags(); |
| 81 | 92 |
| 82 base::WeakPtr<ExtensionService> service_weak_; | 93 base::WeakPtr<ExtensionService> service_weak_; |
| 83 | 94 |
| 84 // The pathname of the directory to load from, which is an absolute path | 95 // The pathname of the directory to load from, which is an absolute path |
| 85 // after GetAbsolutePath has been called. | 96 // after GetAbsolutePath has been called. |
| 86 FilePath extension_path_; | 97 FilePath extension_path_; |
| 87 | 98 |
| 88 // If true and the extension contains plugins, we prompt the user before | 99 // If true and the extension contains plugins, we prompt the user before |
| 89 // loading. | 100 // loading. |
| 90 bool prompt_for_plugins_; | 101 bool prompt_for_plugins_; |
| 91 | 102 |
| 103 scoped_ptr<RequirementsChecker> requirements_checker_; |
| 104 |
| 105 scoped_refptr<const Extension> extension_; |
| 106 |
| 92 // Whether to require the extension installed to have a modern manifest | 107 // Whether to require the extension installed to have a modern manifest |
| 93 // version. | 108 // version. |
| 94 bool require_modern_manifest_version_; | 109 bool require_modern_manifest_version_; |
| 95 | 110 |
| 96 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller); | 111 DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller); |
| 97 }; | 112 }; |
| 98 | 113 |
| 99 } // namespace extensions | 114 } // namespace extensions |
| 100 | 115 |
| 101 #endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ | 116 #endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |
| OLD | NEW |