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> | |
|
Devlin
2014/07/01 22:14:17
Don't need this now, right?
gpdavis
2014/07/01 23:48:10
I will when I add in a vector of file paths since
| |
| 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" | |
| 14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/scoped_observer.h" | |
| 18 #include "chrome/browser/extensions/extension_error_reporter.h" | |
| 15 #include "content/public/browser/web_ui_message_handler.h" | 19 #include "content/public/browser/web_ui_message_handler.h" |
| 16 | 20 |
| 17 namespace base { | 21 namespace base { |
| 18 class ListValue; | 22 class ListValue; |
| 19 } | 23 } |
| 20 | 24 |
| 21 namespace content { | 25 namespace content { |
| 22 class WebUIDataSource; | 26 class WebUIDataSource; |
| 23 } | 27 } |
| 24 | 28 |
| 25 class Profile; | 29 class Profile; |
| 26 | 30 |
| 27 namespace extensions { | 31 namespace extensions { |
| 28 | 32 |
| 29 class Extension; | 33 class Extension; |
| 30 | 34 |
| 31 // The handler page for the Extension Commands UI overlay. | 35 // The handler page for the Extension Commands UI overlay. |
| 32 class ExtensionLoaderHandler : public content::WebUIMessageHandler { | 36 class ExtensionLoaderHandler : public content::WebUIMessageHandler, |
| 37 public ExtensionErrorReporter::Observer { | |
| 33 public: | 38 public: |
| 34 explicit ExtensionLoaderHandler(Profile* profile); | 39 explicit ExtensionLoaderHandler(Profile* profile); |
| 35 virtual ~ExtensionLoaderHandler(); | 40 virtual ~ExtensionLoaderHandler(); |
| 36 | 41 |
| 37 // Fetches the localized values for the page and deposits them into |source|. | 42 // Fetches the localized values for the page and deposits them into |source|. |
| 38 void GetLocalizedValues(content::WebUIDataSource* source); | 43 void GetLocalizedValues(content::WebUIDataSource* source); |
| 39 | 44 |
| 40 // WebUIMessageHandler implementation. | 45 // WebUIMessageHandler implementation. |
| 41 virtual void RegisterMessages() OVERRIDE; | 46 virtual void RegisterMessages() OVERRIDE; |
| 42 | 47 |
| 43 private: | 48 private: |
| 44 class FileHelper; | 49 class FileHelper; |
| 45 | 50 |
| 51 // Struct to hold failure data when NotifyFrontendOfFailure is called before | |
| 52 // the extensions page is fully loaded. | |
| 53 struct FailureData { | |
|
Devlin
2014/07/01 22:14:17
Can we actually move the definition to the .cc fil
gpdavis
2014/07/01 23:48:10
Yessir we can.
| |
| 54 FailureData(base::FilePath file_path, | |
| 55 std::string error, | |
| 56 size_t line_number, | |
| 57 std::string manifest); | |
| 58 | |
| 59 ~FailureData() {} | |
|
Devlin
2014/07/01 22:14:17
For a class with member data, we actually prefer t
gpdavis
2014/07/01 23:48:10
So if these are out of line, do they still go outs
Devlin
2014/07/02 17:46:49
The latter.
inline wrt classes basically means "d
| |
| 60 | |
| 61 base::FilePath file_path; | |
| 62 std::string error; | |
| 63 size_t line_number; | |
| 64 std::string manifest; | |
| 65 }; | |
| 66 | |
| 46 // Handle the 'extensionLoaderLoadUnpacked' message. | 67 // Handle the 'extensionLoaderLoadUnpacked' message. |
| 47 void HandleLoadUnpacked(const base::ListValue* args); | 68 void HandleLoadUnpacked(const base::ListValue* args); |
| 48 | 69 |
| 49 // Handle the 'extensionLoaderRetry' message. | 70 // Handle the 'extensionLoaderRetry' message. |
| 50 void HandleRetry(const base::ListValue* args); | 71 void HandleRetry(const base::ListValue* args); |
| 51 | 72 |
| 73 // Handle the 'extensionLoaderSetDisplayLoading' message. | |
| 74 void HandleSetDisplayLoading(const base::ListValue* args); | |
| 75 | |
| 76 // Handle the 'extensionLoaderDisplayFailures' message. | |
| 77 void HandleDisplayFailures(const base::ListValue* args); | |
| 78 | |
| 52 // Try to load an unpacked extension from the given |file_path|. | 79 // Try to load an unpacked extension from the given |file_path|. |
| 53 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); | 80 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); |
| 54 | 81 |
| 55 // Called when an unpacked extension fails to load. | 82 // ExtensionErrorReporter::Observer implementation. |
| 56 void OnLoadFailure(const base::FilePath& file_path, const std::string& error); | 83 virtual void OnLoadFailure(const base::FilePath& file_path, |
| 84 const std::string& error) OVERRIDE; | |
| 57 | 85 |
| 58 // Notify the frontend of the failure. If it was a manifest error, |manifest| | 86 // Notify the frontend of the failure. If it was a manifest error, |manifest| |
| 59 // will hold the manifest contents, and |line_number| will point to the line | 87 // will hold the manifest contents, and |line_number| will point to the line |
| 60 // at which the error was found. | 88 // at which the error was found. |
| 61 void NotifyFrontendOfFailure(const base::FilePath& file_path, | 89 void NotifyFrontendOfFailure(const base::FilePath& file_path, |
| 62 const std::string& error, | 90 const std::string& error, |
| 63 size_t line_number, | 91 size_t line_number, |
| 64 const std::string& manifest); | 92 const std::string& manifest); |
| 65 | 93 |
| 66 // The profile with which this Handler is associated. | 94 // The profile with which this Handler is associated. |
| 67 Profile* profile_; | 95 Profile* profile_; |
| 68 | 96 |
| 69 // A helper to manage file picking. | 97 // A helper to manage file picking. |
| 70 scoped_ptr<FileHelper> file_helper_; | 98 scoped_ptr<FileHelper> file_helper_; |
| 71 | 99 |
| 72 // The file path to the extension that failed to load, or empty. This is | 100 // Holds information about all unpacked extension install failures that |
| 73 // loaded when the user selects "retry". | 101 // were reported while the extensions page was loading. |
| 74 base::FilePath failed_path_; | 102 ScopedVector<FailureData> failures_; |
| 103 | |
| 104 ScopedObserver<ExtensionErrorReporter, ExtensionErrorReporter::Observer> | |
| 105 extension_error_reporter_observer_; | |
| 106 | |
| 107 bool display_ready_; | |
| 75 | 108 |
| 76 // Weak pointer factory for posting background tasks. | 109 // Weak pointer factory for posting background tasks. |
| 77 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; | 110 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; |
| 78 | 111 |
| 79 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); | 112 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); |
| 80 }; | 113 }; |
| 81 | 114 |
| 82 } // namespace extensions | 115 } // namespace extensions |
| 83 | 116 |
| 84 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ | 117 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ |
| OLD | NEW |