summaryrefslogtreecommitdiffstats
path: root/chrome/installer/util
diff options
context:
space:
mode:
authorcpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-21 22:18:53 +0000
committercpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-21 22:18:53 +0000
commit0a725742431a93b438d34789a6a1c87be7b3b617 (patch)
tree10f56f7da103ddee9ad0f5bb613d9cb88920204c /chrome/installer/util
parent1cb9d02437992810a6c887bec8bc7861e2e67d05 (diff)
downloadchromium_src-0a725742431a93b438d34789a6a1c87be7b3b617.zip
chromium_src-0a725742431a93b438d34789a6a1c87be7b3b617.tar.gz
chromium_src-0a725742431a93b438d34789a6a1c87be7b3b617.tar.bz2
Base class for setup's html dialogs
- Couple of things unimplemented to keep the review at a reasonable size - Will be used for a derived EULADialog class - Will be used for the inactive user toast annoy-a-tron - Will be used to warn user of products that conflict with chrome BUG=1468838 BUG=1484308 Review URL: http://codereview.chromium.org/11552 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/util')
-rw-r--r--chrome/installer/util/html_dialog.h63
-rw-r--r--chrome/installer/util/html_dialog_impl.cc125
-rw-r--r--chrome/installer/util/util.vcproj116
3 files changed, 291 insertions, 13 deletions
diff --git a/chrome/installer/util/html_dialog.h b/chrome/installer/util/html_dialog.h
new file mode 100644
index 0000000..3455d73
--- /dev/null
+++ b/chrome/installer/util/html_dialog.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_INSTALLER_UTIL_HTML_DIALOG_H_
+#define CHROME_INSTALLER_UTIL_HTML_DIALOG_H_
+
+#include <string>
+
+// 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
+// case of Windows it is the the Internet Explorer control.
+
+namespace installer {
+
+// Interface for implementing a native HTML dialog.
+class HTMLDialog {
+ public:
+ enum DialogResult {
+ HTML_DLG_ERROR = 0, // Dialog could not be shown.
+ HTML_DLG_ACCEPT = 1, // The user accepted (accept, ok, yes buttons).
+ HTML_DLG_DECLINE = 2, // The user declined (cancel, no, abort buttons).
+ HTML_DLG_RETRY = 3, // The user wants to retry the action.
+ HTML_DLG_IGNORE = 4, // The user wants to ignore the error and continue.
+ HTML_DLG_TIMEOUT = 5, // The dialog has timed out and defaults apply.
+ HTML_DLG_EXTRA = 6 // There is extra data as a string. See below.
+ };
+
+ // Callbacks that allow to tweak the appearance of the dialog.
+ class CustomizationCallback {
+ public:
+ // Called before the native window is created. Use it to pass arbitrary
+ // parameters in |extra| to the rendering engine.
+ virtual void OnBeforeCreation(void** extra) = 0;
+ // The native window has been created and is about to be visible. Use it
+ // to customize the native |window| appearance.
+ virtual void OnBeforeDisplay(void* window) = 0;
+ };
+
+ // Shows the HTML in a modal dialog. The buttons and other UI are also done
+ // in HTML so each native implementation needs to map the user action into
+ // one of the 6 possible results of DialogResult. Important, call this
+ // method only from the main (or UI) thread.
+ virtual DialogResult ShowModal(void* parent_window,
+ CustomizationCallback* callback) = 0;
+
+ // If the result of ShowModal() was EXTRA, the information is available
+ // as a string using this method.
+ virtual std::wstring GetExtraResult() = 0;
+
+};
+
+// Factory method for the native HTML Dialog. When done with the object use
+// regular 'delete' operator to destroy the object. It might choose a
+// different underlying implementation according to the url protocol.
+HTMLDialog* CreateNativeHTMLDialog(const std::wstring& url);
+
+
+} // namespace installer
+
+#endif // CHROME_INSTALLER_UTIL_HTML_DIALOG_H_
+
diff --git a/chrome/installer/util/html_dialog_impl.cc b/chrome/installer/util/html_dialog_impl.cc
new file mode 100644
index 0000000..2ba8974
--- /dev/null
+++ b/chrome/installer/util/html_dialog_impl.cc
@@ -0,0 +1,125 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <windows.h>
+#include <urlmon.h>
+
+#include "chrome/installer/util/html_dialog.h"
+
+#pragma comment(lib, "urlmon.lib")
+
+namespace {
+// Signature of MSHTML.DLL ShowHTMLDlg.
+typedef HRESULT (CALLBACK *ShowHTMLDlg)(HWND parent_hwnd,
+ IMoniker *moniker,
+ VARIANT *in_args,
+ TCHAR *options,
+ 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
+// 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.
+class HTMLDialogWin : public HTMLDialog {
+ public:
+ HTMLDialogWin(const std::wstring& url) : url_(url) {
+ if (!mshtml_)
+ mshtml_ = LoadLibrary(L"MSHTML.DLL");
+ }
+
+ virtual DialogResult ShowModal(void* parent_window,
+ CustomizationCallback* callback) {
+ if (!InternalDoDialog(callback))
+ 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;
+ }
+
+ // TODO(cpu): Not yet implemented.
+ virtual std::wstring GetExtraResult() {
+ return std::wstring();
+ }
+
+ private:
+ bool InternalDoDialog(CustomizationCallback* callback);
+ static LRESULT CALLBACK MsgFilter(int code, WPARAM wParam, LPARAM lParam);
+
+ std::wstring url_;
+ static HHOOK hook_;
+ static HINSTANCE mshtml_;
+ static CustomizationCallback* callback_;
+};
+
+HTMLDialog* CreateNativeHTMLDialog(const std::wstring& url) {
+ return new HTMLDialogWin(url);
+}
+
+HHOOK HTMLDialogWin::hook_ = NULL;
+HINSTANCE HTMLDialogWin::mshtml_ = NULL;
+HTMLDialogWin::CustomizationCallback* HTMLDialogWin::callback_ = NULL;
+
+// This hook function gets called for messages bound to the windows that
+// ShowHTMLDialog creates. We tell apart the top window because it has the
+// system menu style.
+LRESULT HTMLDialogWin::MsgFilter(int code, WPARAM wParam, LPARAM lParam) {
+ static bool tweak_window = true;
+ if (lParam && tweak_window) {
+ HWND target_window = reinterpret_cast<MSG*>(lParam)->hwnd;
+ if (target_window) {
+ LONG_PTR style = ::GetWindowLongPtrW(target_window, GWL_STYLE);
+ if (style & WS_SYSMENU) {
+ tweak_window = false;
+ callback_->OnBeforeDisplay(target_window);
+ }
+ }
+ }
+ // Always call the next hook in the chain.
+ return ::CallNextHookEx(hook_, code, wParam, lParam);
+}
+
+bool HTMLDialogWin::InternalDoDialog(CustomizationCallback* callback) {
+ if (!mshtml_)
+ return false;
+ ShowHTMLDlg show_html_dialog =
+ reinterpret_cast<ShowHTMLDlg>(GetProcAddress(mshtml_, "ShowHTMLDialog"));
+ if (!show_html_dialog)
+ return false;
+
+ IMoniker *url_moniker = NULL;
+ ::CreateURLMoniker(NULL, url_.c_str(), &url_moniker);
+ if (!url_moniker)
+ return false;
+
+ wchar_t* extra_args = NULL;
+ if (callback) {
+ callback->OnBeforeCreation(reinterpret_cast<void**>(&extra_args));
+ // Sets a windows hook for this thread only.
+ hook_ = ::SetWindowsHookEx(WH_GETMESSAGE, MsgFilter, NULL,
+ GetCurrentThreadId());
+ if (hook_)
+ callback_ = callback;
+ }
+
+ // Creates the window with the embedded IE control in a modal loop.
+ HRESULT hr = show_html_dialog(NULL, url_moniker, NULL, extra_args, NULL);
+ url_moniker->Release();
+
+ if (hook_) {
+ ::UnhookWindowsHookEx(hook_);
+ callback_ = NULL;
+ hook_ = NULL;
+ }
+ return SUCCEEDED(hr);
+}
+
+} // namespace installer
+
diff --git a/chrome/installer/util/util.vcproj b/chrome/installer/util/util.vcproj
index e99dde8..22700c7 100644
--- a/chrome/installer/util/util.vcproj
+++ b/chrome/installer/util/util.vcproj
@@ -20,11 +20,50 @@
InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;$(SolutionDir)common\common.vsprops;$(SolutionDir)installer\util\using_util.vsprops;$(SolutionDir)..\third_party\lzma_sdk\using_lzma_sdk.vsprops"
>
<Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
Name="VCCLCompilerTool"
/>
<Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
Name="VCLibrarianTool"
/>
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
</Configuration>
<Configuration
Name="Release|Win32"
@@ -32,13 +71,54 @@
InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;$(SolutionDir)common\common.vsprops;$(SolutionDir)installer\util\using_util.vsprops;$(SolutionDir)..\third_party\lzma_sdk\using_lzma_sdk.vsprops"
>
<Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
Name="VCCLCompilerTool"
/>
<Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
Name="VCLibrarianTool"
/>
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
</Configuration>
</Configurations>
+ <References>
+ </References>
<Files>
<File
RelativePath="browser_distribution.cc"
@@ -73,19 +153,19 @@
>
</File>
<File
- RelativePath="delete_tree_work_item.cc"
+ RelativePath="delete_reg_value_work_item.cc"
>
</File>
<File
- RelativePath="delete_tree_work_item.h"
+ RelativePath="delete_reg_value_work_item.h"
>
</File>
<File
- RelativePath="delete_reg_value_work_item.cc"
+ RelativePath="delete_tree_work_item.cc"
>
</File>
<File
- RelativePath="delete_reg_value_work_item.h"
+ RelativePath="delete_tree_work_item.h"
>
</File>
<File
@@ -97,6 +177,14 @@
>
</File>
<File
+ RelativePath=".\google_update_constants.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\google_update_constants.h"
+ >
+ </File>
+ <File
RelativePath="google_update_settings.cc"
>
</File>
@@ -113,12 +201,20 @@
>
</File>
<File
+ RelativePath=".\html_dialog.h"
+ >
+ </File>
+ <File
+ RelativePath=".\html_dialog_impl.cc"
+ >
+ </File>
+ <File
RelativePath="install_util.cc"
>
</File>
<File
RelativePath="install_util.h"
- >
+ >
</File>
<File
RelativePath="l10n_string_util.cc"
@@ -145,14 +241,6 @@
>
</File>
<File
- RelativePath=".\google_update_constants.cc"
- >
- </File>
- <File
- RelativePath=".\google_update_constants.h"
- >
- </File>
- <File
RelativePath=".\master_preferences.cc"
>
</File>
@@ -209,4 +297,6 @@
>
</File>
</Files>
+ <Globals>
+ </Globals>
</VisualStudioProject>