diff options
Diffstat (limited to 'webkit/default_plugin/install_dialog.cc')
-rw-r--r-- | webkit/default_plugin/install_dialog.cc | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/webkit/default_plugin/install_dialog.cc b/webkit/default_plugin/install_dialog.cc index 6b20939..38ab863 100644 --- a/webkit/default_plugin/install_dialog.cc +++ b/webkit/default_plugin/install_dialog.cc @@ -4,22 +4,59 @@ #include "webkit/default_plugin/install_dialog.h" +#include "base/hash_tables.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/string_util.h" #include "grit/webkit_strings.h" #include "webkit/default_plugin/plugin_impl.h" #include "webkit/glue/webkit_glue.h" -bool PluginInstallDialog::Initialize(PluginInstallerImpl* plugin_impl, - const std::wstring& plugin_name) { - if (!plugin_impl) { - NOTREACHED(); - return false; +typedef base::hash_map<const std::wstring, PluginInstallDialog*> DialogMap; +base::LazyInstance<DialogMap> s_dialogs(base::LINKER_INITIALIZED); + +PluginInstallDialog* PluginInstallDialog::AddInstaller( + PluginInstallerImpl* plugin_impl, const std::wstring& plugin_name) { + PluginInstallDialog* dialog; + if (s_dialogs.Get().count(plugin_name)) { + dialog = s_dialogs.Get()[plugin_name]; + } else { + dialog = new PluginInstallDialog(plugin_name); } - plugin_impl_ = plugin_impl; - plugin_name_ = plugin_name; - return true; + dialog->installers_.push_back(plugin_impl); + return dialog; +} + +PluginInstallDialog::PluginInstallDialog(const std::wstring& plugin_name) + : plugin_name_(plugin_name) { + s_dialogs.Get()[plugin_name] = this; +} + +PluginInstallDialog::~PluginInstallDialog() { + s_dialogs.Get().erase(plugin_name_); + if (IsWindow()) + DestroyWindow(); +} + +void PluginInstallDialog::RemoveInstaller(PluginInstallerImpl* installer) { + for (size_t i = 0; i < installers_.size(); ++i) { + if (installers_[i] == installer) { + installers_.erase(installers_.begin() + i); + if (installers_.empty()) + delete this; + return; + } + } + NOTREACHED(); +} + +void PluginInstallDialog::ShowInstallDialog() { + if (IsWindow()) + return; + + Create(NULL, NULL); + ShowWindow(SW_SHOW); } HWND PluginInstallDialog::Create(HWND parent_window, LPARAM init_param) { @@ -66,7 +103,7 @@ HWND PluginInstallDialog::Create(HWND parent_window, LPARAM init_param) { HGLOBAL rtl_layout_dialog_template = NULL; - if (IsRTLLayout()) { + if (PluginInstallerImpl::IsRTLLayout()) { rtl_layout_dialog_template = GlobalAlloc(GPTR, dialog_template_size); DCHECK(rtl_layout_dialog_template != NULL); @@ -137,33 +174,26 @@ LRESULT PluginInstallDialog::OnInitDialog(UINT message, WPARAM wparam, LRESULT PluginInstallDialog::OnGetPlugin(WORD notify_code, WORD id, HWND wnd_ctl, BOOL &handled) { - if (!plugin_impl_) { - NOTREACHED(); - return 0; - } - DestroyWindow(); - plugin_impl_->DownloadPlugin(); + if (!installers_.empty()) + installers_[0]->DownloadPlugin(); + return 0; } LRESULT PluginInstallDialog::OnCancel(WORD notify_code, WORD id, HWND wnd_ctl, BOOL &handled) { DestroyWindow(); - plugin_impl_->DownloadCancelled(); + if (!installers_.empty()) + installers_[0]->DownloadCancelled(); return 0; } - -bool PluginInstallDialog::IsRTLLayout() const { - return plugin_impl_ ? plugin_impl_->IsRTLLayout() : false; -} - // TODO(idana) bug# 1246452: use the library l10n_util once it is moved from // the Chrome module into the Base module. For now, we simply copy/paste the // same code. void PluginInstallDialog::AdjustTextDirectionality(std::wstring* text) const { - if (IsRTLLayout()) { + if (PluginInstallerImpl::IsRTLLayout()) { // Inserting an RLE (Right-To-Left Embedding) mark as the first character. text->insert(0, L"\x202B"); |