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_
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"
24 class WebUIDataSource;
29 namespace extensions {
33 // The handler page for the Extension Commands UI overlay.
34 class ExtensionLoaderHandler : public content::WebUIMessageHandler,
35 public ExtensionErrorReporter::Observer,
36 public content::WebContentsObserver {
38 explicit ExtensionLoaderHandler(Profile* profile);
39 virtual ~ExtensionLoaderHandler();
41 // Fetches the localized values for the page and deposits them into |source|.
42 void GetLocalizedValues(content::WebUIDataSource* source);
44 // WebUIMessageHandler implementation.
45 virtual void RegisterMessages() OVERRIDE;
50 // Handle the 'extensionLoaderLoadUnpacked' message.
51 void HandleLoadUnpacked(const base::ListValue* args);
53 // Handle the 'extensionLoaderRetry' message.
54 void HandleRetry(const base::ListValue* args);
56 // Handle the 'extensionLoaderIgnoreFailure' message.
57 void HandleIgnoreFailure(const base::ListValue* args);
59 // Handle the 'extensionLoaderDisplayFailures' message.
60 void HandleDisplayFailures(const base::ListValue* args);
62 // Try to load an unpacked extension from the given |file_path|.
63 void LoadUnpackedExtensionImpl(const base::FilePath& file_path);
65 // ExtensionErrorReporter::Observer:
66 virtual void OnLoadFailure(content::BrowserContext* browser_context,
67 const base::FilePath& file_path,
68 const std::string& error) OVERRIDE;
70 // content::WebContentsObserver:
71 virtual void DidStartNavigationToPendingEntry(
73 content::NavigationController::ReloadType reload_type) OVERRIDE;
75 // Add a failure to |failures_|. If it was a manifest error, |manifest| will
76 // hold the manifest contents, and |line_number| will point to the line at
77 // which the error was found.
78 void AddFailure(const base::FilePath& file_path,
79 const std::string& error,
81 const std::string& manifest);
83 // Notify the frontend of all failures.
84 void NotifyFrontendOfFailure();
86 // The profile with which this Handler is associated.
89 // A helper to manage file picking.
90 scoped_ptr<FileHelper> file_helper_;
92 // Holds information about all unpacked extension install failures that
93 // were reported while the extensions page was loading.
94 base::ListValue failures_;
96 // Holds failed paths for load retries.
97 std::vector<base::FilePath> failed_paths_;
99 ScopedObserver<ExtensionErrorReporter, ExtensionErrorReporter::Observer>
100 extension_error_reporter_observer_;
102 // Set when the chrome://extensions page is fully loaded and the frontend is
103 // ready to receive failure notifications. We need this because the page
104 // fails to display failures if they are sent before the Javascript is loaded.
107 // Weak pointer factory for posting background tasks.
108 base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_;
110 DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler);
113 } // namespace extensions
115 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_