Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | |
| 9 | 10 |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | |
|
Devlin
2014/07/07 20:44:22
Don't need this, right?
gpdavis
2014/07/09 01:35:57
Done.
| |
| 14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/scoped_observer.h" | |
| 18 #include "base/values.h" | |
| 19 #include "chrome/browser/extensions/extension_error_reporter.h" | |
| 15 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
| 16 | 21 |
| 17 namespace base { | 22 namespace base { |
| 18 class ListValue; | 23 class ListValue; |
| 19 } | 24 } |
| 20 | 25 |
| 21 namespace content { | 26 namespace content { |
| 22 class WebUIDataSource; | 27 class WebUIDataSource; |
| 23 } | 28 } |
| 24 | 29 |
| 25 class Profile; | 30 class Profile; |
| 26 | 31 |
| 27 namespace extensions { | 32 namespace extensions { |
| 28 | 33 |
| 29 class Extension; | 34 class Extension; |
| 30 | 35 |
| 31 // The handler page for the Extension Commands UI overlay. | 36 // The handler page for the Extension Commands UI overlay. |
| 32 class ExtensionLoaderHandler : public content::WebUIMessageHandler { | 37 class ExtensionLoaderHandler : public content::WebUIMessageHandler, |
| 38 public ExtensionErrorReporter::Observer { | |
| 33 public: | 39 public: |
| 34 explicit ExtensionLoaderHandler(Profile* profile); | 40 explicit ExtensionLoaderHandler(Profile* profile); |
| 35 virtual ~ExtensionLoaderHandler(); | 41 virtual ~ExtensionLoaderHandler(); |
| 36 | 42 |
| 37 // Fetches the localized values for the page and deposits them into |source|. | 43 // Fetches the localized values for the page and deposits them into |source|. |
| 38 void GetLocalizedValues(content::WebUIDataSource* source); | 44 void GetLocalizedValues(content::WebUIDataSource* source); |
| 39 | 45 |
| 40 // WebUIMessageHandler implementation. | 46 // WebUIMessageHandler implementation. |
| 41 virtual void RegisterMessages() OVERRIDE; | 47 virtual void RegisterMessages() OVERRIDE; |
| 42 | 48 |
| 43 private: | 49 private: |
| 44 class FileHelper; | 50 class FileHelper; |
| 45 | 51 |
| 46 // Handle the 'extensionLoaderLoadUnpacked' message. | 52 // Handle the 'extensionLoaderLoadUnpacked' message. |
| 47 void HandleLoadUnpacked(const base::ListValue* args); | 53 void HandleLoadUnpacked(const base::ListValue* args); |
| 48 | 54 |
| 49 // Handle the 'extensionLoaderRetry' message. | 55 // Handle the 'extensionLoaderRetry' message. |
| 50 void HandleRetry(const base::ListValue* args); | 56 void HandleRetry(const base::ListValue* args); |
| 51 | 57 |
| 58 // Handle the 'extensionLoaderIgnoreFailure' message. | |
| 59 void HandleIgnoreFailure(const base::ListValue* args); | |
| 60 | |
| 61 // Handle the 'extensionLoaderSetDisplayLoading' message. | |
| 62 void HandleSetDisplayLoading(const base::ListValue* args); | |
| 63 | |
| 64 // Handle the 'extensionLoaderDisplayFailures' message. | |
| 65 void HandleDisplayFailures(const base::ListValue* args); | |
| 66 | |
| 52 // Try to load an unpacked extension from the given |file_path|. | 67 // Try to load an unpacked extension from the given |file_path|. |
| 53 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); | 68 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); |
| 54 | 69 |
| 55 // Called when an unpacked extension fails to load. | 70 // ExtensionErrorReporter::Observer implementation. |
| 56 void OnLoadFailure(const base::FilePath& file_path, const std::string& error); | 71 virtual void OnLoadFailure(const base::FilePath& file_path, |
| 72 const std::string& error) OVERRIDE; | |
| 57 | 73 |
| 58 // Notify the frontend of the failure. If it was a manifest error, |manifest| | 74 // Add a failure to failures_. If it was a manifest error, |manifest| will |
| 59 // will hold the manifest contents, and |line_number| will point to the line | 75 // hold the manifest contents, and |line_number| will point to the line at |
| 60 // at which the error was found. | 76 // which the error was found. |
| 61 void NotifyFrontendOfFailure(const base::FilePath& file_path, | 77 void AddFailure(const base::FilePath& file_path, |
| 62 const std::string& error, | 78 const std::string& error, |
| 63 size_t line_number, | 79 size_t line_number, |
| 64 const std::string& manifest); | 80 const std::string& manifest); |
| 81 | |
| 82 // Notify the frontend of all failures. | |
| 83 void NotifyFrontendOfFailure(); | |
| 65 | 84 |
| 66 // The profile with which this Handler is associated. | 85 // The profile with which this Handler is associated. |
| 67 Profile* profile_; | 86 Profile* profile_; |
| 68 | 87 |
| 69 // A helper to manage file picking. | 88 // A helper to manage file picking. |
| 70 scoped_ptr<FileHelper> file_helper_; | 89 scoped_ptr<FileHelper> file_helper_; |
| 71 | 90 |
| 72 // The file path to the extension that failed to load, or empty. This is | 91 // Holds information about all unpacked extension install failures that |
| 73 // loaded when the user selects "retry". | 92 // were reported while the extensions page was loading. |
| 74 base::FilePath failed_path_; | 93 base::ListValue failures_; |
| 94 | |
| 95 // Holds failed paths for load retries. | |
| 96 std::vector<base::FilePath> failed_paths_; | |
| 97 | |
| 98 ScopedObserver<ExtensionErrorReporter, ExtensionErrorReporter::Observer> | |
| 99 extension_error_reporter_observer_; | |
| 100 | |
| 101 // Set when the chrome://extensions page is fully loaded and the load | |
| 102 // failures UI is ready to receive failures. | |
| 103 bool display_ready_; | |
| 75 | 104 |
| 76 // Weak pointer factory for posting background tasks. | 105 // Weak pointer factory for posting background tasks. |
| 77 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; | 106 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; |
| 78 | 107 |
| 79 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); | 108 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); |
| 80 }; | 109 }; |
| 81 | 110 |
| 82 } // namespace extensions | 111 } // namespace extensions |
| 83 | 112 |
| 84 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ | 113 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ |
| OLD | NEW |