| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/default_plugin/install_dialog.h" | 5 #include "webkit/default_plugin/install_dialog.h" |
| 6 | 6 |
| 7 #include "base/hash_tables.h" |
| 8 #include "base/lazy_instance.h" |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 9 #include "grit/webkit_strings.h" | 11 #include "grit/webkit_strings.h" |
| 10 #include "webkit/default_plugin/plugin_impl.h" | 12 #include "webkit/default_plugin/plugin_impl.h" |
| 11 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
| 12 | 14 |
| 13 bool PluginInstallDialog::Initialize(PluginInstallerImpl* plugin_impl, | 15 typedef base::hash_map<const std::wstring, PluginInstallDialog*> DialogMap; |
| 14 const std::wstring& plugin_name) { | 16 base::LazyInstance<DialogMap> s_dialogs(base::LINKER_INITIALIZED); |
| 15 if (!plugin_impl) { | 17 |
| 16 NOTREACHED(); | 18 PluginInstallDialog* PluginInstallDialog::AddInstaller( |
| 17 return false; | 19 PluginInstallerImpl* plugin_impl, const std::wstring& plugin_name) { |
| 20 PluginInstallDialog* dialog; |
| 21 if (s_dialogs.Get().count(plugin_name)) { |
| 22 dialog = s_dialogs.Get()[plugin_name]; |
| 23 } else { |
| 24 dialog = new PluginInstallDialog(plugin_name); |
| 18 } | 25 } |
| 19 | 26 |
| 20 plugin_impl_ = plugin_impl; | 27 dialog->installers_.push_back(plugin_impl); |
| 21 plugin_name_ = plugin_name; | 28 return dialog; |
| 22 return true; | 29 } |
| 30 |
| 31 PluginInstallDialog::PluginInstallDialog(const std::wstring& plugin_name) |
| 32 : plugin_name_(plugin_name) { |
| 33 s_dialogs.Get()[plugin_name] = this; |
| 34 } |
| 35 |
| 36 PluginInstallDialog::~PluginInstallDialog() { |
| 37 s_dialogs.Get().erase(plugin_name_); |
| 38 if (IsWindow()) |
| 39 DestroyWindow(); |
| 40 } |
| 41 |
| 42 void PluginInstallDialog::RemoveInstaller(PluginInstallerImpl* installer) { |
| 43 for (size_t i = 0; i < installers_.size(); ++i) { |
| 44 if (installers_[i] == installer) { |
| 45 installers_.erase(installers_.begin() + i); |
| 46 if (installers_.empty()) |
| 47 delete this; |
| 48 return; |
| 49 } |
| 50 } |
| 51 NOTREACHED(); |
| 52 } |
| 53 |
| 54 void PluginInstallDialog::ShowInstallDialog() { |
| 55 if (IsWindow()) |
| 56 return; |
| 57 |
| 58 Create(NULL, NULL); |
| 59 ShowWindow(SW_SHOW); |
| 23 } | 60 } |
| 24 | 61 |
| 25 HWND PluginInstallDialog::Create(HWND parent_window, LPARAM init_param) { | 62 HWND PluginInstallDialog::Create(HWND parent_window, LPARAM init_param) { |
| 26 // Most of the code here is based on CDialogImpl<T>::Create. | 63 // Most of the code here is based on CDialogImpl<T>::Create. |
| 27 DCHECK(m_hWnd == NULL); | 64 DCHECK(m_hWnd == NULL); |
| 28 | 65 |
| 29 // Allocate the thunk structure here, where we can fail | 66 // Allocate the thunk structure here, where we can fail |
| 30 // gracefully. | 67 // gracefully. |
| 31 BOOL thunk_inited = m_thunk.Init(NULL, NULL); | 68 BOOL thunk_inited = m_thunk.Init(NULL, NULL); |
| 32 if (thunk_inited == FALSE) { | 69 if (thunk_inited == FALSE) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 _DialogSplitHelper::DLGTEMPLATEEX* dialog_template_struct = | 96 _DialogSplitHelper::DLGTEMPLATEEX* dialog_template_struct = |
| 60 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX *>( | 97 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX *>( |
| 61 ::LockResource(dialog_template)); | 98 ::LockResource(dialog_template)); |
| 62 DCHECK(dialog_template_struct != NULL); | 99 DCHECK(dialog_template_struct != NULL); |
| 63 | 100 |
| 64 unsigned long dialog_template_size = | 101 unsigned long dialog_template_size = |
| 65 SizeofResource(instance_handle, dialog_resource); | 102 SizeofResource(instance_handle, dialog_resource); |
| 66 | 103 |
| 67 HGLOBAL rtl_layout_dialog_template = NULL; | 104 HGLOBAL rtl_layout_dialog_template = NULL; |
| 68 | 105 |
| 69 if (IsRTLLayout()) { | 106 if (PluginInstallerImpl::IsRTLLayout()) { |
| 70 rtl_layout_dialog_template = GlobalAlloc(GPTR, dialog_template_size); | 107 rtl_layout_dialog_template = GlobalAlloc(GPTR, dialog_template_size); |
| 71 DCHECK(rtl_layout_dialog_template != NULL); | 108 DCHECK(rtl_layout_dialog_template != NULL); |
| 72 | 109 |
| 73 _DialogSplitHelper::DLGTEMPLATEEX* rtl_layout_dialog_template_struct = | 110 _DialogSplitHelper::DLGTEMPLATEEX* rtl_layout_dialog_template_struct = |
| 74 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX*>( | 111 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX*>( |
| 75 ::GlobalLock(rtl_layout_dialog_template)); | 112 ::GlobalLock(rtl_layout_dialog_template)); |
| 76 DCHECK(rtl_layout_dialog_template_struct != NULL); | 113 DCHECK(rtl_layout_dialog_template_struct != NULL); |
| 77 | 114 |
| 78 memcpy(rtl_layout_dialog_template_struct, dialog_template_struct, | 115 memcpy(rtl_layout_dialog_template_struct, dialog_template_struct, |
| 79 dialog_template_size); | 116 dialog_template_size); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 plugin_name_); | 167 plugin_name_); |
| 131 AdjustTextDirectionality(&plugin_user_action_msg); | 168 AdjustTextDirectionality(&plugin_user_action_msg); |
| 132 SetDlgItemText(IDC_PLUGIN_INSTALL_CONFIRMATION_LABEL, | 169 SetDlgItemText(IDC_PLUGIN_INSTALL_CONFIRMATION_LABEL, |
| 133 plugin_user_action_msg.c_str()); | 170 plugin_user_action_msg.c_str()); |
| 134 return 0; | 171 return 0; |
| 135 } | 172 } |
| 136 | 173 |
| 137 | 174 |
| 138 LRESULT PluginInstallDialog::OnGetPlugin(WORD notify_code, WORD id, | 175 LRESULT PluginInstallDialog::OnGetPlugin(WORD notify_code, WORD id, |
| 139 HWND wnd_ctl, BOOL &handled) { | 176 HWND wnd_ctl, BOOL &handled) { |
| 140 if (!plugin_impl_) { | 177 DestroyWindow(); |
| 141 NOTREACHED(); | 178 if (!installers_.empty()) |
| 142 return 0; | 179 installers_[0]->DownloadPlugin(); |
| 143 } | |
| 144 | 180 |
| 145 DestroyWindow(); | |
| 146 plugin_impl_->DownloadPlugin(); | |
| 147 return 0; | 181 return 0; |
| 148 } | 182 } |
| 149 | 183 |
| 150 LRESULT PluginInstallDialog::OnCancel(WORD notify_code, WORD id, HWND wnd_ctl, | 184 LRESULT PluginInstallDialog::OnCancel(WORD notify_code, WORD id, HWND wnd_ctl, |
| 151 BOOL &handled) { | 185 BOOL &handled) { |
| 152 DestroyWindow(); | 186 DestroyWindow(); |
| 153 plugin_impl_->DownloadCancelled(); | 187 if (!installers_.empty()) |
| 188 installers_[0]->DownloadCancelled(); |
| 154 return 0; | 189 return 0; |
| 155 } | 190 } |
| 156 | 191 |
| 157 | |
| 158 bool PluginInstallDialog::IsRTLLayout() const { | |
| 159 return plugin_impl_ ? plugin_impl_->IsRTLLayout() : false; | |
| 160 } | |
| 161 | |
| 162 // TODO(idana) bug# 1246452: use the library l10n_util once it is moved from | 192 // TODO(idana) bug# 1246452: use the library l10n_util once it is moved from |
| 163 // the Chrome module into the Base module. For now, we simply copy/paste the | 193 // the Chrome module into the Base module. For now, we simply copy/paste the |
| 164 // same code. | 194 // same code. |
| 165 void PluginInstallDialog::AdjustTextDirectionality(std::wstring* text) const { | 195 void PluginInstallDialog::AdjustTextDirectionality(std::wstring* text) const { |
| 166 if (IsRTLLayout()) { | 196 if (PluginInstallerImpl::IsRTLLayout()) { |
| 167 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. | 197 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. |
| 168 text->insert(0, L"\x202B"); | 198 text->insert(0, L"\x202B"); |
| 169 | 199 |
| 170 // Inserting a PDF (Pop Directional Formatting) mark as the last character. | 200 // Inserting a PDF (Pop Directional Formatting) mark as the last character. |
| 171 text->append(L"\x202C"); | 201 text->append(L"\x202C"); |
| 172 } | 202 } |
| 173 } | 203 } |
| OLD | NEW |