Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / webui / extensions / extension_settings_handler.h
blobe12947ed3853236d873c0dfa9fa42108bf32a19d
1 // Copyright (c) 2012 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_SETTINGS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_HANDLER_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "chrome/browser/extensions/error_console/error_console.h"
13 #include "chrome/browser/extensions/extension_management.h"
14 #include "chrome/common/extensions/webstore_install_result.h"
15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/browser/web_ui_message_handler.h"
20 #include "extensions/browser/extension_prefs_observer.h"
21 #include "extensions/browser/extension_registry_observer.h"
22 #include "extensions/browser/warning_service.h"
24 class ExtensionService;
25 class GURL;
27 namespace base {
28 class FilePath;
29 class ListValue;
32 namespace content {
33 class WebUIDataSource;
36 namespace user_prefs {
37 class PrefRegistrySyncable;
40 namespace extensions {
41 class Extension;
42 class ExtensionPrefs;
43 class ExtensionRegistry;
45 // Extension Settings UI handler.
46 class ExtensionSettingsHandler
47 : public content::WebUIMessageHandler,
48 public content::NotificationObserver,
49 public content::WebContentsObserver,
50 public ErrorConsole::Observer,
51 public ExtensionManagement::Observer,
52 public ExtensionPrefsObserver,
53 public ExtensionRegistryObserver,
54 public WarningService::Observer,
55 public base::SupportsWeakPtr<ExtensionSettingsHandler> {
56 public:
57 ExtensionSettingsHandler();
58 ~ExtensionSettingsHandler() override;
60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
62 void GetLocalizedValues(content::WebUIDataSource* source);
64 private:
65 // content::WebContentsObserver implementation.
66 void RenderViewDeleted(content::RenderViewHost* render_view_host) override;
67 void DidStartNavigationToPendingEntry(
68 const GURL& url,
69 content::NavigationController::ReloadType reload_type) override;
71 // WebUIMessageHandler implementation.
72 void RegisterMessages() override;
74 // ErrorConsole::Observer implementation.
75 void OnErrorAdded(const ExtensionError* error) override;
77 // content::NotificationObserver implementation.
78 void Observe(int type,
79 const content::NotificationSource& source,
80 const content::NotificationDetails& details) override;
82 // ExtensionRegistryObserver implementation.
83 void OnExtensionLoaded(content::BrowserContext* browser_context,
84 const Extension* extension) override;
85 void OnExtensionUnloaded(content::BrowserContext* browser_context,
86 const Extension* extension,
87 UnloadedExtensionInfo::Reason reason) override;
88 void OnExtensionUninstalled(content::BrowserContext* browser_context,
89 const Extension* extension,
90 extensions::UninstallReason reason) override;
92 // ExtensionPrefsObserver implementation.
93 void OnExtensionDisableReasonsChanged(const std::string& extension_id,
94 int disable_reasons) override;
96 // ExtensionManagement::Observer implementation.
97 void OnExtensionManagementSettingsChanged() override;
99 // WarningService::Observer implementation.
100 void ExtensionWarningsChanged() override;
102 // Helper method that reloads all unpacked extensions.
103 void ReloadUnpackedExtensions();
105 // Callback for "requestExtensionsData" message.
106 void HandleRequestExtensionsData(const base::ListValue* args);
108 // Callback for "toggleDeveloperMode" message.
109 void HandleToggleDeveloperMode(const base::ListValue* args);
111 // Callback for "launch" message.
112 void HandleLaunchMessage(const base::ListValue* args);
114 // Callback for "repair" message.
115 void HandleRepairMessage(const base::ListValue* args);
117 // Callback for "options" message.
118 void HandleOptionsMessage(const base::ListValue* args);
120 // Callback for "permissions" message.
121 void HandlePermissionsMessage(const base::ListValue* args);
123 // Callback for "autoupdate" message.
124 void HandleAutoUpdateMessage(const base::ListValue* args);
126 // Callback for the "dismissADTPromo" message.
127 void HandleDismissADTPromoMessage(const base::ListValue* args);
129 // Callback for the "showPath" message.
130 void HandleShowPath(const base::ListValue* args);
132 // Utility for callbacks that get an extension ID as the sole argument.
133 // Returns NULL if the extension isn't active.
134 const Extension* GetActiveExtension(const base::ListValue* args);
136 // Forces a UI update if appropriate after a notification is received.
137 void MaybeUpdateAfterNotification();
139 // Register for notifications that we need to reload the page.
140 void MaybeRegisterForNotifications();
142 // Called when the reinstallation is complete.
143 void OnReinstallComplete(bool success,
144 const std::string& error,
145 webstore_install::Result result);
147 // Our model. Outlives us since it's owned by our containing profile.
148 ExtensionService* extension_service_;
150 // If true, we will ignore notifications in ::Observe(). This is needed
151 // to prevent reloading the page when we were the cause of the
152 // notification.
153 bool ignore_notifications_;
155 // The page may be refreshed in response to a RenderViewHost being destroyed,
156 // but the iteration over RenderViewHosts will include the host because the
157 // notification is sent when it is in the process of being deleted (and before
158 // it is removed from the process). Keep a pointer to it so we can exclude
159 // it from the active views.
160 content::RenderViewHost* deleting_rvh_;
161 // Do the same for a deleting RenderWidgetHost ID and RenderProcessHost ID.
162 int deleting_rwh_id_;
163 int deleting_rph_id_;
165 // We want to register for notifications only after we've responded at least
166 // once to the page, otherwise we'd be calling JavaScript functions on objects
167 // that don't exist yet when notifications come in. This variable makes sure
168 // we do so only once.
169 bool registered_for_notifications_;
171 content::NotificationRegistrar registrar_;
173 ScopedObserver<WarningService, WarningService::Observer>
174 warning_service_observer_;
176 // An observer to listen for when Extension errors are reported.
177 ScopedObserver<ErrorConsole, ErrorConsole::Observer> error_console_observer_;
179 // An observer to listen for notable changes in the ExtensionPrefs, like
180 // a change in Disable Reasons.
181 ScopedObserver<ExtensionPrefs, ExtensionPrefsObserver>
182 extension_prefs_observer_;
184 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
185 extension_registry_observer_;
187 ScopedObserver<ExtensionManagement, ExtensionManagement::Observer>
188 extension_management_observer_;
190 // Whether we found any DISABLE_NOT_VERIFIED extensions and want to kick off
191 // a verification check to try and rescue them.
192 bool should_do_verification_check_;
194 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsHandler);
197 } // namespace extensions
199 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_HANDLER_H_