diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:20:51 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:20:51 +0000 |
commit | f5b16fed647e941aa66933178da85db2860d639b (patch) | |
tree | f00e9856c04aad3b558a140955e7674add33f051 /webkit/default_plugin/install_dialog.cc | |
parent | 920c091ac3ee15079194c82ae8a7a18215f3f23c (diff) | |
download | chromium_src-f5b16fed647e941aa66933178da85db2860d639b.zip chromium_src-f5b16fed647e941aa66933178da85db2860d639b.tar.gz chromium_src-f5b16fed647e941aa66933178da85db2860d639b.tar.bz2 |
Add webkit to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/default_plugin/install_dialog.cc')
-rw-r--r-- | webkit/default_plugin/install_dialog.cc | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/webkit/default_plugin/install_dialog.cc b/webkit/default_plugin/install_dialog.cc new file mode 100644 index 0000000..b0f2125 --- /dev/null +++ b/webkit/default_plugin/install_dialog.cc @@ -0,0 +1,202 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "webkit/default_plugin/install_dialog.h" + +#include "base/logging.h" +#include "base/string_util.h" +#include "webkit/default_plugin/plugin_impl.h" +#include "webkit/glue/webkit_glue.h" +// This file is generated when the webkit_strings.grd file is compiled +// It is generated under chrome/webkit/<debug\release>/obj/localized_strings +// folder. This path is added to the include path in the associated vsprops +// file. +#include "webkit_strings.h" + +bool PluginInstallDialog::Initialize(PluginInstallerImpl* plugin_impl, + const std::wstring& plugin_name) { + if (!plugin_impl) { + NOTREACHED(); + return false; + } + + plugin_impl_ = plugin_impl; + plugin_name_ = plugin_name; + return true; +} + +HWND PluginInstallDialog::Create(HWND parent_window, LPARAM init_param) { + // Most of the code here is based on CDialogImpl<T>::Create. + DCHECK(m_hWnd == NULL); + + // Allocate the thunk structure here, where we can fail + // gracefully. + BOOL thunk_inited = m_thunk.Init(NULL, NULL); + if (thunk_inited == FALSE) { + SetLastError(ERROR_OUTOFMEMORY); + return NULL; + } + + _AtlWinModule.AddCreateWndData(&m_thunk.cd, this); + +#ifdef _DEBUG + m_bModal = false; +#endif // _DEBUG + + HINSTANCE instance_handle = _AtlBaseModule.GetResourceInstance(); + + HRSRC dialog_resource = FindResource(instance_handle, + MAKEINTRESOURCE(IDD), RT_DIALOG); + if (!dialog_resource) { + NOTREACHED(); + return NULL; + } + + HGLOBAL dialog_template = LoadResource(instance_handle, + dialog_resource); + if (!dialog_template) { + NOTREACHED(); + return NULL; + } + + _DialogSplitHelper::DLGTEMPLATEEX* dialog_template_struct = + reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX *>( + ::LockResource(dialog_template)); + DCHECK(dialog_template_struct != NULL); + + unsigned long dialog_template_size = + SizeofResource(instance_handle, dialog_resource); + + HGLOBAL rtl_layout_dialog_template = NULL; + + if (IsRTLLayout()) { + rtl_layout_dialog_template = GlobalAlloc(GPTR, dialog_template_size); + DCHECK(rtl_layout_dialog_template != NULL); + + _DialogSplitHelper::DLGTEMPLATEEX* rtl_layout_dialog_template_struct = + reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX*>( + ::GlobalLock(rtl_layout_dialog_template)); + DCHECK(rtl_layout_dialog_template_struct != NULL); + + memcpy(rtl_layout_dialog_template_struct, dialog_template_struct, + dialog_template_size); + + rtl_layout_dialog_template_struct->exStyle |= + (WS_EX_LAYOUTRTL | WS_EX_RTLREADING); + + dialog_template_struct = rtl_layout_dialog_template_struct; + } + + HWND dialog_window = + CreateDialogIndirectParam( + instance_handle, + reinterpret_cast<DLGTEMPLATE*>(dialog_template_struct), + parent_window, StartDialogProc, init_param); + + DCHECK(m_hWnd == dialog_window); + + if (rtl_layout_dialog_template) { + GlobalUnlock(rtl_layout_dialog_template); + GlobalFree(rtl_layout_dialog_template); + } + + return dialog_window; +} + + +LRESULT PluginInstallDialog::OnInitDialog(UINT message, WPARAM wparam, + LPARAM lparam, BOOL& handled) { + std::wstring dialog_title = + PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( + IDS_DEFAULT_PLUGIN_CONFIRMATION_DIALOG_TITLE, + IDS_DEFAULT_PLUGIN_CONFIRMATION_DIALOG_TITLE_NO_PLUGIN_NAME, + plugin_name_); + AdjustTextDirectionality(&dialog_title); + SetWindowText(dialog_title.c_str()); + + std::wstring get_the_plugin_btn_msg = + webkit_glue::GetLocalizedString( + IDS_DEFAULT_PLUGIN_GET_THE_PLUGIN_BTN_MSG); + AdjustTextDirectionality(&get_the_plugin_btn_msg); + SetDlgItemText(IDB_GET_THE_PLUGIN, get_the_plugin_btn_msg.c_str()); + + std::wstring cancel_plugin_download_msg = + webkit_glue::GetLocalizedString( + IDS_DEFAULT_PLUGIN_CANCEL_PLUGIN_DOWNLOAD_MSG); + AdjustTextDirectionality(&cancel_plugin_download_msg); + SetDlgItemText(IDCANCEL, cancel_plugin_download_msg.c_str()); + + std::wstring plugin_user_action_msg = + PluginInstallerImpl::ReplaceStringForPossibleEmptyReplacement( + IDS_DEFAULT_PLUGIN_USER_OPTION_MSG, + IDS_DEFAULT_PLUGIN_USER_OPTION_MSG_NO_PLUGIN_NAME, + plugin_name_); + AdjustTextDirectionality(&plugin_user_action_msg); + SetDlgItemText(IDC_PLUGIN_INSTALL_CONFIRMATION_LABEL, + plugin_user_action_msg.c_str()); + return 0; +} + + +LRESULT PluginInstallDialog::OnGetPlugin(WORD notify_code, WORD id, + HWND wnd_ctl, BOOL &handled) { + if (!plugin_impl_) { + NOTREACHED(); + return 0; + } + + DestroyWindow(); + plugin_impl_->DownloadPlugin(); + return 0; +} + +LRESULT PluginInstallDialog::OnCancel(WORD notify_code, WORD id, HWND wnd_ctl, + BOOL &handled) { + DestroyWindow(); + plugin_impl_->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()) { + // Inserting an RLE (Right-To-Left Embedding) mark as the first character. + text->insert(0, L"\x202B"); + + // Inserting a PDF (Pop Directional Formatting) mark as the last character. + text->append(L"\x202C"); + } +} |