diff options
author | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-08 20:30:53 +0000 |
---|---|---|
committer | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-08 20:30:53 +0000 |
commit | b3d565264e6073bd00e4dfd81c8f887ea01fb58c (patch) | |
tree | b37f2589de3352d27f2bbcca2a579780f8c0b168 /chrome/installer | |
parent | e292fca9e47cba237bb5b2d885f900eddecd70c5 (diff) | |
download | chromium_src-b3d565264e6073bd00e4dfd81c8f887ea01fb58c.zip chromium_src-b3d565264e6073bd00e4dfd81c8f887ea01fb58c.tar.gz chromium_src-b3d565264e6073bd00e4dfd81c8f887ea01fb58c.tar.bz2 |
More addions to the installer html dialog class
- EulaDialog subclass
- Wired the output parameter
BUG=1468838
Review URL: http://codereview.chromium.org/13601
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6533 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rwxr-xr-x | chrome/installer/setup/main.cc | 17 | ||||
-rw-r--r-- | chrome/installer/util/html_dialog.h | 24 | ||||
-rw-r--r-- | chrome/installer/util/html_dialog_impl.cc | 76 |
3 files changed, 106 insertions, 11 deletions
diff --git a/chrome/installer/setup/main.cc b/chrome/installer/setup/main.cc index 4aa4f37..5307c1c 100755 --- a/chrome/installer/setup/main.cc +++ b/chrome/installer/setup/main.cc @@ -21,6 +21,7 @@ #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/delete_tree_work_item.h" #include "chrome/installer/util/helper.h" +#include "chrome/installer/util/html_dialog.h" #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/logging_installer.h" #include "chrome/installer/util/lzma_util.h" @@ -430,8 +431,19 @@ installer_util::InstallStatus UninstallChrome(const CommandLine& cmd_line, *version, remove_all, force); } -} // namespace +// This function is temporary and meant to live while we get our eula dialogs +// looking sharp. If the cmd line has --eula-test=path then the eula dialog +// will be shown and no matter what the selection is the installer will exit. +bool HandleEULADialog(const CommandLine& cmdline) { + std:: wstring eula_path(cmdline.GetSwitchValue(L"eula-test")); + if (eula_path.empty()) + return true; + installer::EulaHTMLDialog dlg(eula_path); + dlg.ShowModal(); + return false; +} +} // namespace int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, wchar_t* command_line, int show_command) { @@ -446,6 +458,9 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; LOG(INFO) << "system install is " << system_install; + if (!HandleEULADialog(parsed_command_line)) + return 0; + // Check to make sure current system is WinXP or later. If not, log // error message and get out. if (!InstallUtil::IsOSSupported()) { diff --git a/chrome/installer/util/html_dialog.h b/chrome/installer/util/html_dialog.h index 3455d73..91ace2d 100644 --- a/chrome/installer/util/html_dialog.h +++ b/chrome/installer/util/html_dialog.h @@ -7,6 +7,8 @@ #include <string> +#include "base/basictypes.h" + // This is the interface for creating HTML-based Dialogs *before* Chrome has // been installed or when there is a suspicion chrome is not working. In // other words, the dialogs use another native html rendering engine. In the @@ -56,6 +58,28 @@ class HTMLDialog { // different underlying implementation according to the url protocol. HTMLDialog* CreateNativeHTMLDialog(const std::wstring& url); +// This class leverages HTMLDialog to create a dialog that is suitable +// for a end-user-agreement modal dialog. +class EulaHTMLDialog { + public: + // |file| points to an html file on disk. + explicit EulaHTMLDialog(const std::wstring& file); + ~EulaHTMLDialog(); + + // Shows the dialog and blocks for user input. The return value is true if + // the user accepted and false otherwise. + bool ShowModal(); + + private: + class Customizer : public HTMLDialog::CustomizationCallback { + public: + virtual void OnBeforeCreation(void** extra); + virtual void OnBeforeDisplay(void* window); + }; + + HTMLDialog* dialog_; + DISALLOW_COPY_AND_ASSIGN(EulaHTMLDialog); +}; } // namespace installer diff --git a/chrome/installer/util/html_dialog_impl.cc b/chrome/installer/util/html_dialog_impl.cc index 2ba8974..197cebb 100644 --- a/chrome/installer/util/html_dialog_impl.cc +++ b/chrome/installer/util/html_dialog_impl.cc @@ -18,16 +18,33 @@ typedef HRESULT (CALLBACK *ShowHTMLDlg)(HWND parent_hwnd, VARIANT *out_args); } // namespace. - namespace installer { // Windows implementation of the HTML dialog class. The main danger with // using the IE embedded control as a child window of a custom window is that // it still contains too much browser functionality, allowing the user to do -// things that are not expected of a plain dialog. ShowHTMLDialog api solves +// things that are not expected of a plain dialog. ShowHTMLDialog API solves // that problem but gives us a not very customizable frame. We solve that // using hooks to end up with a robust dialog at the expense of having to do -// the buttons in html itself. +// the buttons in html itself, like so: +// +// <form onsubmit="submit_it(this); return false;"> +// <input name="accept" type="checkbox" /> My cool option +// <input name="submit" type="submit" value="[accept]" /> +// </form> +// +// function submit_it(f) { +// if (f.accept.checked) { +// window.returnValue = 1; <-- this matches HTML_DLG_ACCEPT +// } else { +// window.returnValue = 2; <-- this matches HTML_DLG_DECLINE +// } +// window.close(); +// } +// +// Note that on the submit handler you need to set window.returnValue to one of +// the values of DialogResult and call window.close(). + class HTMLDialogWin : public HTMLDialog { public: HTMLDialogWin(const std::wstring& url) : url_(url) { @@ -37,11 +54,10 @@ class HTMLDialogWin : public HTMLDialog { virtual DialogResult ShowModal(void* parent_window, CustomizationCallback* callback) { - if (!InternalDoDialog(callback)) + int result = HTML_DLG_DECLINE; + if (!InternalDoDialog(callback, &result)) return HTML_DLG_ERROR; - // TODO(cpu): Remove the HTML_DLG_ACCEPT and read the real return - // value from the ShowHTMLDialog call. - return HTML_DLG_ACCEPT; + return static_cast<DialogResult>(result); } // TODO(cpu): Not yet implemented. @@ -50,7 +66,7 @@ class HTMLDialogWin : public HTMLDialog { } private: - bool InternalDoDialog(CustomizationCallback* callback); + bool InternalDoDialog(CustomizationCallback* callback, int* result); static LRESULT CALLBACK MsgFilter(int code, WPARAM wParam, LPARAM lParam); std::wstring url_; @@ -86,7 +102,8 @@ LRESULT HTMLDialogWin::MsgFilter(int code, WPARAM wParam, LPARAM lParam) { return ::CallNextHookEx(hook_, code, wParam, lParam); } -bool HTMLDialogWin::InternalDoDialog(CustomizationCallback* callback) { +bool HTMLDialogWin::InternalDoDialog(CustomizationCallback* callback, + int* result) { if (!mshtml_) return false; ShowHTMLDlg show_html_dialog = @@ -109,10 +126,17 @@ bool HTMLDialogWin::InternalDoDialog(CustomizationCallback* callback) { callback_ = callback; } + VARIANT v_result; + ::VariantInit(&v_result); + // Creates the window with the embedded IE control in a modal loop. - HRESULT hr = show_html_dialog(NULL, url_moniker, NULL, extra_args, NULL); + HRESULT hr = show_html_dialog(NULL, url_moniker, NULL, extra_args, &v_result); url_moniker->Release(); + if (v_result.vt == VT_I4) + *result = v_result.intVal; + ::VariantClear(&v_result); + if (hook_) { ::UnhookWindowsHookEx(hook_); callback_ = NULL; @@ -121,5 +145,37 @@ bool HTMLDialogWin::InternalDoDialog(CustomizationCallback* callback) { return SUCCEEDED(hr); } +// EulaHTMLDialog implementation --------------------------------------------- + +void EulaHTMLDialog::Customizer::OnBeforeCreation(void** extra) { +} + +// The customization of the window consists in removing the close button and +// replacing the existing 'e' icon with the standard informational icon. +void EulaHTMLDialog::Customizer::OnBeforeDisplay(void* window) { + if (!window) + return; + HWND top_window = static_cast<HWND>(window); + LONG_PTR style = ::GetWindowLongPtrW(top_window, GWL_STYLE); + ::SetWindowLongPtrW(top_window, GWL_STYLE, style & ~WS_SYSMENU); + HICON ico = ::LoadIcon(NULL, IDI_INFORMATION); + ::SendMessageW(top_window, WM_SETICON, ICON_SMALL, + reinterpret_cast<LPARAM>(ico)); +} + +EulaHTMLDialog::EulaHTMLDialog(const std::wstring& file) { + dialog_ = CreateNativeHTMLDialog(file); +} + +EulaHTMLDialog::~EulaHTMLDialog() { + delete dialog_; +} + +bool EulaHTMLDialog::ShowModal() { + Customizer customizer; + dialog_->ShowModal(NULL, &customizer); + return false; +} + } // namespace installer |