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