diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 7 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.cc | 51 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.h | 32 | ||||
-rw-r--r-- | chrome/browser/resources/extensions_ui.html | 28 |
4 files changed, 99 insertions, 19 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 96bfc63..dc6f840 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This file contains definitions of resources that will be translated for -each locale. --> +each locale. aa1 --> <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en" enc_check="möl"> @@ -2134,6 +2134,11 @@ each locale. --> <message name="IDS_EXTENSION_PROMPT_WARNING_NEW_FULL_ACCESS" desc="Warning displayed in body of extension dialog when the extension requires access the local machine."> This extension will have full access to your computer and private data. </message> + + <!-- chrome://extensions page --> + <message name="IDS_EXTENSION_LOAD_FROM_DIRECTORY" desc="Title of directory browse dialog when user wants to load an extension from a directory."> + Select the extension directory. + </message> <!-- TODO(aa): Remove these old warning messages when all the platforms are switched to the new ones, above. --> <message name="IDS_EXTENSION_PROMPT_WARNING_1" desc="Humorous warning displayed in the extension install prompt that tells users that extensions have access to their computer and private data."> diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index 126fa05..d1e8781 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -16,11 +16,14 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/extensions/user_script.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/jstemplate_builder.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "chrome/common/url_constants.h" #include "net/base/net_util.h" @@ -65,10 +68,9 @@ void ExtensionsUIHTMLSource::StartDataRequest(const std::string& path, // /////////////////////////////////////////////////////////////////////////////// -ExtensionsDOMHandler::ExtensionsDOMHandler( - ExtensionsService* extension_service) +ExtensionsDOMHandler::ExtensionsDOMHandler(ExtensionsService* extension_service) : extensions_service_(extension_service) { - } +} void ExtensionsDOMHandler::RegisterMessages() { dom_ui_->RegisterMessageCallback("requestExtensionsData", @@ -81,6 +83,8 @@ void ExtensionsDOMHandler::RegisterMessages() { NewCallback(this, &ExtensionsDOMHandler::HandleEnableMessage)); dom_ui_->RegisterMessageCallback("uninstall", NewCallback(this, &ExtensionsDOMHandler::HandleUninstallMessage)); + dom_ui_->RegisterMessageCallback("load", + NewCallback(this, &ExtensionsDOMHandler::HandleLoadMessage)); } void ExtensionsDOMHandler::HandleRequestExtensionsData(const Value* value) { @@ -109,6 +113,16 @@ void ExtensionsDOMHandler::HandleRequestExtensionsData(const Value* value) { results.Set(L"extensions", extensions_list); dom_ui_->CallJavascriptFunction(L"returnExtensionsData", results); + + // Register for notifications that we need to reload the page. + registrar_.Add(this, NotificationType::EXTENSION_LOADED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, + NotificationService::AllSources()); } void ExtensionsDOMHandler::HandleInspectMessage(const Value* value) { @@ -160,6 +174,37 @@ void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) { extensions_service_->UninstallExtension(extension_id, false); } +void ExtensionsDOMHandler::HandleLoadMessage(const Value* value) { + load_extension_dialog_ = SelectFileDialog::Create(this); + load_extension_dialog_->SelectFile( + SelectFileDialog::SELECT_FOLDER, + l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY), + FilePath(), NULL, 0, FILE_PATH_LITERAL(""), + NULL, NULL); +} + +void ExtensionsDOMHandler::FileSelected(const FilePath& path, int index, + void* params) { + extensions_service_->LoadExtension(path); +} + +void ExtensionsDOMHandler::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::EXTENSION_LOADED: + case NotificationType::EXTENSION_UNLOADED: + case NotificationType::EXTENSION_UPDATE_DISABLED: + case NotificationType::EXTENSION_UNLOADED_DISABLED: + if (dom_ui_->tab_contents()) + dom_ui_->tab_contents()->controller().Reload(false); + break; + + default: + NOTREACHED(); + } +} + static void CreateScriptFileDetailValue( const FilePath& extension_path, const UserScript::FileList& scripts, const wchar_t* key, DictionaryValue* script_data) { diff --git a/chrome/browser/extensions/extensions_ui.h b/chrome/browser/extensions/extensions_ui.h index b63b12b..ad99ac5 100644 --- a/chrome/browser/extensions/extensions_ui.h +++ b/chrome/browser/extensions/extensions_ui.h @@ -10,6 +10,9 @@ #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/shell_dialogs.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" class DictionaryValue; @@ -46,7 +49,10 @@ class ExtensionsUIHTMLSource : public ChromeURLDataManager::DataSource { }; // The handler for Javascript messages related to the "extensions" view. -class ExtensionsDOMHandler : public DOMMessageHandler { +class ExtensionsDOMHandler + : public DOMMessageHandler, + public NotificationObserver, + public SelectFileDialog::Listener { public: explicit ExtensionsDOMHandler(ExtensionsService* extension_service); virtual ~ExtensionsDOMHandler(); @@ -81,6 +87,23 @@ class ExtensionsDOMHandler : public DOMMessageHandler { // Callback for "uninstall" message. void HandleUninstallMessage(const Value* value); + // Callback for "load" message. + void HandleLoadMessage(const Value* value); + + // SelectFileDialog::Listener + virtual void FileSelected(const FilePath& path, + int index, void* params); + virtual void MultiFilesSelected( + const std::vector<FilePath>& files, void* params) { + NOTREACHED(); + }; + virtual void FileSelectionCanceled(void* params) {}; + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // Helper that lists the current active html pages for an extension. std::vector<ExtensionPage> GetActivePagesForExtension( const std::string& extension_id); @@ -88,6 +111,13 @@ class ExtensionsDOMHandler : public DOMMessageHandler { // Our model. scoped_refptr<ExtensionsService> extensions_service_; + // Used to pick the directory when loading an extension. + scoped_refptr<SelectFileDialog> load_extension_dialog_; + + // We monitor changes to the extension system so that we can reload when + // necessary. + NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(ExtensionsDOMHandler); }; diff --git a/chrome/browser/resources/extensions_ui.html b/chrome/browser/resources/extensions_ui.html index b388ea4..d0b8116 100644 --- a/chrome/browser/resources/extensions_ui.html +++ b/chrome/browser/resources/extensions_ui.html @@ -185,6 +185,13 @@ var extensionDataFormat = { * @param {Object} extensionsData Detailed info about installed extensions */ function showExtensionsData(extensionsData) { + // Sort by extension name (case-insensitive) + extensionsData.extensions.sort(function(a, b) { + a = a.name.toLowerCase(); + b = b.name.toLowerCase(); + return a < b ? -1 : (a > b ? 1 : 0); + }); + // This is the javascript code that processes the template: var input = new JsEvalContext(extensionsData); var output = document.getElementById('extensionTemplate'); @@ -249,17 +256,13 @@ function handleEnableExtension(node) { function handleUninstallExtension(node) { // Tell the C++ ExtensionDOMHandler to uninstall an extension. chrome.send('uninstall', [node.extensionId]); +} - // Find the div above us with class 'extension' and remove it. - while (node) { - if (node.className == 'extension') { - node.parentNode.removeChild(node); - return; - } - node = node.parentNode; - } - - throw new Error("Couldn't find containing extension element."); +/** + * Handles the "Load extension..." button being pressed. + */ +function loadExtension() { + chrome.send('load', []); } </script> </head> @@ -322,18 +325,15 @@ function handleUninstallExtension(node) { </div> </td> - <!-- <td style="min-width:30px"></td> <td style="min-width:30px"></td> <td valign="top"> <h2>Tools</h2> <div class="sidebar-content"> - <button>Load Extension...</button><br> - <button>Pack Extension...</button> + <button onclick="loadExtension()">Load Extension from Directory...</button> </div> </td> - --> </tr> </table> |