diff options
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extensions_ui.cc | 51 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.h | 32 |
2 files changed, 79 insertions, 4 deletions
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); }; |