| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | |
| 14 #include "chrome/browser/extensions/pack_extension_job.h" | |
| 15 #include "chrome/browser/ui/shell_dialogs.h" | |
| 16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 17 #include "chrome/browser/ui/webui/chrome_web_ui.h" | |
| 18 #include "chrome/common/extensions/extension_resource.h" | |
| 19 #include "content/common/notification_observer.h" | |
| 20 #include "content/common/notification_registrar.h" | |
| 21 #include "googleurl/src/gurl.h" | |
| 22 | |
| 23 class Extension; | |
| 24 class ExtensionService; | |
| 25 class FilePath; | |
| 26 class PrefService; | |
| 27 class RenderProcessHost; | |
| 28 class UserScript; | |
| 29 | |
| 30 namespace base { | |
| 31 class DictionaryValue; | |
| 32 class ListValue; | |
| 33 } | |
| 34 | |
| 35 // Information about a page running in an extension, for example a toolstrip, | |
| 36 // a background page, or a tab contents. | |
| 37 struct ExtensionPage { | |
| 38 ExtensionPage(const GURL& url, int render_process_id, int render_view_id, | |
| 39 bool incognito) | |
| 40 : url(url), render_process_id(render_process_id), | |
| 41 render_view_id(render_view_id), incognito(incognito) {} | |
| 42 GURL url; | |
| 43 int render_process_id; | |
| 44 int render_view_id; | |
| 45 bool incognito; | |
| 46 }; | |
| 47 | |
| 48 // The handler for JavaScript messages related to the "extensions" view. | |
| 49 class ExtensionsDOMHandler : public WebUIMessageHandler, | |
| 50 public NotificationObserver, | |
| 51 public PackExtensionJob::Client, | |
| 52 public SelectFileDialog::Listener, | |
| 53 public ExtensionUninstallDialog::Delegate { | |
| 54 public: | |
| 55 explicit ExtensionsDOMHandler(ExtensionService* extension_service); | |
| 56 virtual ~ExtensionsDOMHandler(); | |
| 57 | |
| 58 // WebUIMessageHandler implementation. | |
| 59 virtual void RegisterMessages() OVERRIDE; | |
| 60 | |
| 61 // Extension Detail JSON Struct for page. (static for ease of testing). | |
| 62 // Note: service can be NULL in unit tests. | |
| 63 static base::DictionaryValue* CreateExtensionDetailValue( | |
| 64 ExtensionService* service, | |
| 65 const Extension* extension, | |
| 66 const std::vector<ExtensionPage>& pages, | |
| 67 bool enabled, | |
| 68 bool terminated); | |
| 69 | |
| 70 // ExtensionPackJob::Client | |
| 71 virtual void OnPackSuccess(const FilePath& crx_file, | |
| 72 const FilePath& key_file) OVERRIDE; | |
| 73 | |
| 74 virtual void OnPackFailure(const std::string& error) OVERRIDE; | |
| 75 | |
| 76 // ExtensionUninstallDialog::Delegate: | |
| 77 virtual void ExtensionDialogAccepted() OVERRIDE; | |
| 78 virtual void ExtensionDialogCanceled() OVERRIDE; | |
| 79 | |
| 80 private: | |
| 81 // Callback for "requestExtensionsData" message. | |
| 82 void HandleRequestExtensionsData(const base::ListValue* args); | |
| 83 | |
| 84 // Callback for "toggleDeveloperMode" message. | |
| 85 void HandleToggleDeveloperMode(const base::ListValue* args); | |
| 86 | |
| 87 // Callback for "inspect" message. | |
| 88 void HandleInspectMessage(const base::ListValue* args); | |
| 89 | |
| 90 // Callback for "reload" message. | |
| 91 void HandleReloadMessage(const base::ListValue* args); | |
| 92 | |
| 93 // Callback for "enable" message. | |
| 94 void HandleEnableMessage(const base::ListValue* args); | |
| 95 | |
| 96 // Callback for "enableIncognito" message. | |
| 97 void HandleEnableIncognitoMessage(const base::ListValue* args); | |
| 98 | |
| 99 // Callback for "allowFileAcces" message. | |
| 100 void HandleAllowFileAccessMessage(const base::ListValue* args); | |
| 101 | |
| 102 // Callback for "uninstall" message. | |
| 103 void HandleUninstallMessage(const base::ListValue* args); | |
| 104 | |
| 105 // Callback for "options" message. | |
| 106 void HandleOptionsMessage(const base::ListValue* args); | |
| 107 | |
| 108 // Callback for "showButton" message. | |
| 109 void HandleShowButtonMessage(const base::ListValue* args); | |
| 110 | |
| 111 // Callback for "load" message. | |
| 112 void HandleLoadMessage(const base::ListValue* args); | |
| 113 | |
| 114 // Callback for "pack" message. | |
| 115 void HandlePackMessage(const base::ListValue* args); | |
| 116 | |
| 117 // Callback for "autoupdate" message. | |
| 118 void HandleAutoUpdateMessage(const base::ListValue* args); | |
| 119 | |
| 120 // Utility for calling javascript window.alert in the page. | |
| 121 void ShowAlert(const std::string& message); | |
| 122 | |
| 123 // Callback for "selectFilePath" message. | |
| 124 void HandleSelectFilePathMessage(const base::ListValue* args); | |
| 125 | |
| 126 // Utility for callbacks that get an extension ID as the sole argument. | |
| 127 const Extension* GetExtension(const base::ListValue* args); | |
| 128 | |
| 129 // Forces a UI update if appropriate after a notification is received. | |
| 130 void MaybeUpdateAfterNotification(); | |
| 131 | |
| 132 // Register for notifications that we need to reload the page. | |
| 133 void RegisterForNotifications(); | |
| 134 | |
| 135 // SelectFileDialog::Listener | |
| 136 virtual void FileSelected(const FilePath& path, | |
| 137 int index, void* params) OVERRIDE; | |
| 138 virtual void MultiFilesSelected( | |
| 139 const std::vector<FilePath>& files, void* params) OVERRIDE; | |
| 140 virtual void FileSelectionCanceled(void* params) OVERRIDE {} | |
| 141 | |
| 142 // NotificationObserver | |
| 143 virtual void Observe(int type, | |
| 144 const NotificationSource& source, | |
| 145 const NotificationDetails& details) OVERRIDE; | |
| 146 | |
| 147 // Helper that lists the current active html pages for an extension. | |
| 148 std::vector<ExtensionPage> GetActivePagesForExtension( | |
| 149 const Extension* extension); | |
| 150 void GetActivePagesForExtensionProcess( | |
| 151 RenderProcessHost* process, | |
| 152 const Extension* extension, | |
| 153 std::vector<ExtensionPage> *result); | |
| 154 | |
| 155 // Returns the ExtensionUninstallDialog object for this class, creating it if | |
| 156 // needed. | |
| 157 ExtensionUninstallDialog* GetExtensionUninstallDialog(); | |
| 158 | |
| 159 // Our model. Outlives us since it's owned by our containing profile. | |
| 160 ExtensionService* const extension_service_; | |
| 161 | |
| 162 // Used to pick the directory when loading an extension. | |
| 163 scoped_refptr<SelectFileDialog> load_extension_dialog_; | |
| 164 | |
| 165 // Used to package the extension. | |
| 166 scoped_refptr<PackExtensionJob> pack_job_; | |
| 167 | |
| 168 // Used to show confirmation UI for uninstalling extensions in incognito mode. | |
| 169 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | |
| 170 | |
| 171 // The id of the extension we are prompting the user about. | |
| 172 std::string extension_id_prompting_; | |
| 173 | |
| 174 // We monitor changes to the extension system so that we can reload when | |
| 175 // necessary. | |
| 176 NotificationRegistrar registrar_; | |
| 177 | |
| 178 // If true, we will ignore notifications in ::Observe(). This is needed | |
| 179 // to prevent reloading the page when we were the cause of the | |
| 180 // notification. | |
| 181 bool ignore_notifications_; | |
| 182 | |
| 183 // The page may be refreshed in response to a RENDER_VIEW_HOST_DELETED, | |
| 184 // but the iteration over RenderViewHosts will include the host because the | |
| 185 // notification is sent when it is in the process of being deleted (and before | |
| 186 // it is removed from the process). Keep a pointer to it so we can exclude | |
| 187 // it from the active views. | |
| 188 RenderViewHost* deleting_rvh_; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(ExtensionsDOMHandler); | |
| 191 }; | |
| 192 | |
| 193 class ExtensionsUI : public ChromeWebUI { | |
| 194 public: | |
| 195 explicit ExtensionsUI(TabContents* contents); | |
| 196 | |
| 197 static RefCountedMemory* GetFaviconResourceBytes(); | |
| 198 | |
| 199 static void RegisterUserPrefs(PrefService* prefs); | |
| 200 | |
| 201 private: | |
| 202 DISALLOW_COPY_AND_ASSIGN(ExtensionsUI); | |
| 203 }; | |
| 204 | |
| 205 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ | |
| OLD | NEW |