Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_loader_handler.h

Issue 342003005: Show alert failure for reloading unpacked extensions with bad manifest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final comment nits Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'extensionLoaderDisplayFailures' message.
60 void HandleDisplayFailures(const base::ListValue* args);
61
52 // Try to load an unpacked extension from the given |file_path|. 62 // Try to load an unpacked extension from the given |file_path|.
53 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); 63 void LoadUnpackedExtensionImpl(const base::FilePath& file_path);
54 64
55 // Called when an unpacked extension fails to load. 65 // ExtensionErrorReporter::Observer:
56 void OnLoadFailure(const base::FilePath& file_path, const std::string& error); 66 virtual void OnLoadFailure(const base::FilePath& file_path,
67 const std::string& error) OVERRIDE;
57 68
58 // Notify the frontend of the failure. If it was a manifest error, |manifest| 69 // content::WebContentsObserver:
59 // will hold the manifest contents, and |line_number| will point to the line 70 virtual void DidStartNavigationToPendingEntry(
60 // at which the error was found. 71 const GURL& url,
61 void NotifyFrontendOfFailure(const base::FilePath& file_path, 72 content::NavigationController::ReloadType reload_type) OVERRIDE;
62 const std::string& error, 73
63 size_t line_number, 74 // Add a failure to |failures_|. If it was a manifest error, |manifest| will
64 const std::string& manifest); 75 // hold the manifest contents, and |line_number| will point to the line at
76 // which the error was found.
77 void AddFailure(const base::FilePath& file_path,
78 const std::string& error,
79 size_t line_number,
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 frontend is
102 // ready to receive failure notifications. We need this because the page
103 // fails to display failures if they are sent before the Javascript is loaded.
104 bool ui_ready_;
75 105
76 // Weak pointer factory for posting background tasks. 106 // Weak pointer factory for posting background tasks.
77 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; 107 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_;
78 108
79 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); 109 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler);
80 }; 110 };
81 111
82 } // namespace extensions 112 } // namespace extensions
83 113
84 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ 114 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698