[Extensions] Make chrome://extensions use developerPrivate for unpacked loading
[chromium-blink-merge.git] / chrome / browser / ui / webui / extensions / extension_loader_handler.h
blob02415d06c7aebb550b5b9680b6e6033a787becac
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_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"
21 #include "content/public/browser/web_ui_message_handler.h"
23 namespace content {
24 class WebUIDataSource;
27 class Profile;
29 namespace extensions {
31 class Extension;
33 // The handler page for the Extension Commands UI overlay.
34 class ExtensionLoaderHandler : public content::WebUIMessageHandler,
35 public ExtensionErrorReporter::Observer,
36 public content::WebContentsObserver {
37 public:
38 explicit ExtensionLoaderHandler(Profile* profile);
39 ~ExtensionLoaderHandler() override;
41 // Fetches the localized values for the page and deposits them into |source|.
42 void GetLocalizedValues(content::WebUIDataSource* source);
44 // WebUIMessageHandler implementation.
45 void RegisterMessages() override;
47 private:
48 // Handle the 'extensionLoaderRetry' message.
49 void HandleRetry(const base::ListValue* args);
51 // Handle the 'extensionLoaderIgnoreFailure' message.
52 void HandleIgnoreFailure(const base::ListValue* args);
54 // Handle the 'extensionLoaderDisplayFailures' message.
55 void HandleDisplayFailures(const base::ListValue* args);
57 // Try to load an unpacked extension from the given |file_path|.
58 void LoadUnpackedExtension(const base::FilePath& file_path);
60 // ExtensionErrorReporter::Observer:
61 void OnLoadFailure(content::BrowserContext* browser_context,
62 const base::FilePath& file_path,
63 const std::string& error) override;
65 // content::WebContentsObserver:
66 void DidStartNavigationToPendingEntry(
67 const GURL& url,
68 content::NavigationController::ReloadType reload_type) override;
70 // Add a failure to |failures_|. If it was a manifest error, |manifest| will
71 // hold the manifest contents, and |line_number| will point to the line at
72 // which the error was found.
73 void AddFailure(const base::FilePath& file_path,
74 const std::string& error,
75 size_t line_number,
76 const std::string& manifest);
78 // Notify the frontend of all failures.
79 void NotifyFrontendOfFailure();
81 // The profile with which this Handler is associated.
82 Profile* profile_;
84 // Holds information about all unpacked extension install failures that
85 // were reported while the extensions page was loading.
86 base::ListValue failures_;
88 // Holds failed paths for load retries.
89 std::vector<base::FilePath> failed_paths_;
91 ScopedObserver<ExtensionErrorReporter, ExtensionErrorReporter::Observer>
92 extension_error_reporter_observer_;
94 // Set when the chrome://extensions page is fully loaded and the frontend is
95 // ready to receive failure notifications. We need this because the page
96 // fails to display failures if they are sent before the Javascript is loaded.
97 bool ui_ready_;
99 // Weak pointer factory for posting background tasks.
100 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_;
102 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler);
105 } // namespace extensions
107 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_