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" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/scoped_observer.h" | |
17 #include "base/values.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; |
Devlin
2014/07/09 19:53:17
No need to forward-declare this now.
gpdavis
2014/07/09 21:16:26
Done.
| |
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 |
46 // Handle the 'extensionLoaderLoadUnpacked' message. | 51 // Handle the 'extensionLoaderLoadUnpacked' message. |
47 void HandleLoadUnpacked(const base::ListValue* args); | 52 void HandleLoadUnpacked(const base::ListValue* args); |
48 | 53 |
49 // Handle the 'extensionLoaderRetry' message. | 54 // Handle the 'extensionLoaderRetry' message. |
50 void HandleRetry(const base::ListValue* args); | 55 void HandleRetry(const base::ListValue* args); |
51 | 56 |
57 // Handle the 'extensionLoaderIgnoreFailure' message. | |
58 void HandleIgnoreFailure(const base::ListValue* args); | |
59 | |
60 // Handle the 'extensionLoaderSetDisplayLoading' message. | |
61 void HandleSetDisplayLoading(const base::ListValue* args); | |
62 | |
63 // Handle the 'extensionLoaderDisplayFailures' message. | |
64 void HandleDisplayFailures(const base::ListValue* args); | |
65 | |
52 // Try to load an unpacked extension from the given |file_path|. | 66 // Try to load an unpacked extension from the given |file_path|. |
53 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); | 67 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); |
54 | 68 |
55 // Called when an unpacked extension fails to load. | 69 // ExtensionErrorReporter::Observer implementation. |
56 void OnLoadFailure(const base::FilePath& file_path, const std::string& error); | 70 virtual void OnLoadFailure(const base::FilePath& file_path, |
71 const std::string& error) OVERRIDE; | |
57 | 72 |
58 // Notify the frontend of the failure. If it was a manifest error, |manifest| | 73 // 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 | 74 // hold the manifest contents, and |line_number| will point to the line at |
60 // at which the error was found. | 75 // which the error was found. |
61 void NotifyFrontendOfFailure(const base::FilePath& file_path, | 76 void AddFailure(const base::FilePath& file_path, |
62 const std::string& error, | 77 const std::string& error, |
63 size_t line_number, | 78 size_t line_number, |
64 const std::string& manifest); | 79 const std::string& manifest); |
80 | |
81 // Notify the frontend of all failures. | |
82 void NotifyFrontendOfFailure(); | |
65 | 83 |
66 // The profile with which this Handler is associated. | 84 // The profile with which this Handler is associated. |
67 Profile* profile_; | 85 Profile* profile_; |
68 | 86 |
69 // A helper to manage file picking. | 87 // A helper to manage file picking. |
70 scoped_ptr<FileHelper> file_helper_; | 88 scoped_ptr<FileHelper> file_helper_; |
71 | 89 |
72 // The file path to the extension that failed to load, or empty. This is | 90 // Holds information about all unpacked extension install failures that |
73 // loaded when the user selects "retry". | 91 // were reported while the extensions page was loading. |
74 base::FilePath failed_path_; | 92 base::ListValue failures_; |
93 | |
94 // Holds failed paths for load retries. | |
95 std::vector<base::FilePath> failed_paths_; | |
96 | |
97 ScopedObserver<ExtensionErrorReporter, ExtensionErrorReporter::Observer> | |
98 extension_error_reporter_observer_; | |
99 | |
100 // Set when the chrome://extensions page is fully loaded and the load | |
101 // failures UI is ready to receive failures. | |
102 bool display_ready_; | |
75 | 103 |
76 // Weak pointer factory for posting background tasks. | 104 // Weak pointer factory for posting background tasks. |
77 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; | 105 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; |
78 | 106 |
79 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); | 107 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); |
80 }; | 108 }; |
81 | 109 |
82 } // namespace extensions | 110 } // namespace extensions |
83 | 111 |
84 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ | 112 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ |
OLD | NEW |