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

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: Addressed patch set 4 comments 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"
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 {
54 explicit FailureData(base::FilePath file_path,
Devlin 2014/06/30 21:06:42 no need for explicit with multiple parameters to t
gpdavis 2014/06/30 21:41:19 Done.
55 std::string error,
Devlin 2014/06/30 21:06:42 nit: indentation error.
gpdavis 2014/06/30 21:41:19 Done.
56 size_t line_number,
57 std::string manifest)
58 : file_path(file_path),
59 error(error),
60 line_number(line_number),
61 manifest(manifest) {}
gpdavis 2014/06/30 19:42:52 There should probably be a newline here, right? H
Devlin 2014/06/30 21:06:42 Make an out-of-line constructor, and an explicit d
gpdavis 2014/06/30 21:41:19 An "out-of-line" constructor? I've never heard th
Devlin 2014/06/30 22:32:36 out-of-line is the (slang) opposite of inline. Me
gpdavis 2014/06/30 23:35:11 Ah, gotcha. Can do.
62 base::FilePath file_path;
63 std::string error;
64 size_t line_number;
65 std::string manifest;
66
67 DISALLOW_COPY_AND_ASSIGN(FailureData);
Devlin 2014/06/30 21:06:42 One note and one problem: note - we don't actually
gpdavis 2014/06/30 21:41:19 C++ is a pretty new language to me-- I'm pretty we
Devlin 2014/06/30 22:32:36 So, what DISALLOW_COPY_AND_ASSIGN does is just dec
gpdavis 2014/06/30 23:35:11 Ahh, I see. So by creating private dummies for tho
68 };
69
46 // Handle the 'extensionLoaderLoadUnpacked' message. 70 // Handle the 'extensionLoaderLoadUnpacked' message.
47 void HandleLoadUnpacked(const base::ListValue* args); 71 void HandleLoadUnpacked(const base::ListValue* args);
48 72
49 // Handle the 'extensionLoaderRetry' message. 73 // Handle the 'extensionLoaderRetry' message.
50 void HandleRetry(const base::ListValue* args); 74 void HandleRetry(const base::ListValue* args);
51 75
76 // Handle the 'extensionLoaderSetDisplayLoading' message.
77 void HandleSetDisplayLoading(const base::ListValue* args);
78
79 // Handle the 'extensionLoaderDisplayFailures' message.
80 void HandleDisplayFailures(const base::ListValue* args);
81
52 // Try to load an unpacked extension from the given |file_path|. 82 // Try to load an unpacked extension from the given |file_path|.
53 void LoadUnpackedExtensionImpl(const base::FilePath& file_path); 83 void LoadUnpackedExtensionImpl(const base::FilePath& file_path);
54 84
55 // Called when an unpacked extension fails to load. 85 // ExtensionErrorReporter::Observer implementation.
56 void OnLoadFailure(const base::FilePath& file_path, const std::string& error); 86 virtual void OnLoadFailure(const base::FilePath& file_path,
87 const std::string& error) OVERRIDE;
57 88
58 // Notify the frontend of the failure. If it was a manifest error, |manifest| 89 // 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 90 // will hold the manifest contents, and |line_number| will point to the line
60 // at which the error was found. 91 // at which the error was found.
61 void NotifyFrontendOfFailure(const base::FilePath& file_path, 92 void NotifyFrontendOfFailure(const base::FilePath& file_path,
62 const std::string& error, 93 const std::string& error,
63 size_t line_number, 94 size_t line_number,
64 const std::string& manifest); 95 const std::string& manifest);
65 96
66 // The profile with which this Handler is associated. 97 // The profile with which this Handler is associated.
67 Profile* profile_; 98 Profile* profile_;
68 99
69 // A helper to manage file picking. 100 // A helper to manage file picking.
70 scoped_ptr<FileHelper> file_helper_; 101 scoped_ptr<FileHelper> file_helper_;
71 102
72 // The file path to the extension that failed to load, or empty. This is 103 // The file path to the extension that failed to load, or empty. This is
73 // loaded when the user selects "retry". 104 // loaded when the user selects "retry".
74 base::FilePath failed_path_; 105 base::FilePath failed_path_;
75 106
107 // Holds information about all unpacked extension install failures that
108 // were reported while the extensions page was loading.
109 ScopedVector<FailureData> failures_;
110
111 ScopedObserver<ExtensionErrorReporter, ExtensionErrorReporter::Observer>
112 extension_error_reporter_observer_;
113
114 bool display_ready_;
115
76 // Weak pointer factory for posting background tasks. 116 // Weak pointer factory for posting background tasks.
77 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_; 117 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_;
78 118
79 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler); 119 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler);
80 }; 120 };
81 121
82 } // namespace extensions 122 } // namespace extensions
83 123
84 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_ 124 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698