| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/client/client_utils.h" | |
| 17 #include "omaha/base/debug.h" | |
| 18 #include "omaha/base/logging.h" | |
| 19 #include "omaha/base/vistautil.h" | |
| 20 #include "omaha/client/help_url_builder.h" | |
| 21 #include "omaha/common/goopdate_utils.h" | |
| 22 #include "goopdate/omaha3_idl.h" | |
| 23 #include "omaha/ui/complete_wnd.h" | |
| 24 #include "omaha/ui/yes_no_dialog.h" | |
| 25 | |
| 26 namespace omaha { | |
| 27 | |
| 28 namespace client_utils { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 // Assumes this is not a silent process. | |
| 33 // Uses bundle_name in the title if provided; otherwise displays generic title. | |
| 34 bool DisplayErrorInMessageBox(const CString& error_text, | |
| 35 const CString& bundle_name) { | |
| 36 CString msg_box_title = GetInstallerDisplayName(bundle_name); | |
| 37 return (0 != ::MessageBox(NULL, error_text, msg_box_title, MB_OK)); | |
| 38 } | |
| 39 | |
| 40 class ErrorWndEvents : public CompleteWndEvents { | |
| 41 public: | |
| 42 explicit ErrorWndEvents(bool is_machine) : is_machine_(is_machine) {} | |
| 43 | |
| 44 // TODO(omaha3): Not sure if we need to do anything for DoClose. | |
| 45 virtual void DoClose() {} | |
| 46 | |
| 47 virtual void DoExit() { | |
| 48 ::PostQuitMessage(0); | |
| 49 } | |
| 50 | |
| 51 // TODO(omaha3): Use the specified browser if available. | |
| 52 // TODO(omaha3): Need to address elevated Vista installs. We could ask the | |
| 53 // non-elevated /install instance to launch the browser for us using some | |
| 54 // type of notification pipe like we use for out-of-process crashes. | |
| 55 virtual bool DoLaunchBrowser(const CString& url) { | |
| 56 CORE_LOG(L2, (_T("[ErrorWndEvents::DoLaunchBrowser %s]"), url)); | |
| 57 return SUCCEEDED(goopdate_utils::LaunchBrowser( | |
| 58 is_machine_, BROWSER_DEFAULT, url)); | |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 bool is_machine_; | |
| 63 | |
| 64 DISALLOW_IMPLICIT_CONSTRUCTORS(ErrorWndEvents); | |
| 65 }; | |
| 66 | |
| 67 bool CanLaunchBrowser() { | |
| 68 if (!vista_util::IsElevatedWithUACMaybeOn()) { | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 CComPtr<IProcessLauncher> launcher; | |
| 73 return SUCCEEDED(launcher.CoCreateInstance(CLSID_ProcessLauncherClass, | |
| 74 NULL, | |
| 75 CLSCTX_LOCAL_SERVER)); | |
| 76 } | |
| 77 | |
| 78 } // namespace | |
| 79 | |
| 80 | |
| 81 // Assumes this is an interactive instance. | |
| 82 // If the Omaha UI fails to initialize, displays the error in a message box. | |
| 83 // Thus, some UI should always be displayed. | |
| 84 bool DisplayError(bool is_machine, | |
| 85 const CString& bundle_name, | |
| 86 HRESULT error, | |
| 87 int extra_code, | |
| 88 const CString& error_text, | |
| 89 const CString& app_id, | |
| 90 const CString& language_id, | |
| 91 const GUID& iid, | |
| 92 const CString& brand_code) { | |
| 93 CMessageLoop message_loop; | |
| 94 CompleteWnd error_wnd(&message_loop, NULL); | |
| 95 | |
| 96 error_wnd.set_is_machine(is_machine); | |
| 97 error_wnd.set_bundle_name(bundle_name); | |
| 98 CString help_url; | |
| 99 HelpUrlBuilder url_builder(is_machine, language_id, iid, brand_code); | |
| 100 std::vector<HelpUrlBuilder::AppResult> app_install_result; | |
| 101 app_install_result.push_back(HelpUrlBuilder::AppResult(app_id, | |
| 102 error, | |
| 103 extra_code)); | |
| 104 | |
| 105 // When running elevated and ProcessLauncherClass is not registered, the | |
| 106 // browser launch from the link will fail. Don't display a link that will not | |
| 107 // work. | |
| 108 if (CanLaunchBrowser()) { | |
| 109 VERIFY1(SUCCEEDED(url_builder.BuildUrl(app_install_result, &help_url))); | |
| 110 } | |
| 111 | |
| 112 HRESULT hr = error_wnd.Initialize(); | |
| 113 if (FAILED(hr)) { | |
| 114 CORE_LOG(LE, (_T("UI initialize failed][0x%08x]"), hr)); | |
| 115 bool result = DisplayErrorInMessageBox(error_text, bundle_name); | |
| 116 ASSERT1(result); | |
| 117 error_wnd.DestroyWindow(); // Window will not get to destroy itself. | |
| 118 return result; | |
| 119 } | |
| 120 | |
| 121 ErrorWndEvents error_wnd_events(is_machine); | |
| 122 // error_wnd_events must not be destroyed until CMessageLoop::Run() returns. | |
| 123 error_wnd.SetEventSink(&error_wnd_events); | |
| 124 | |
| 125 error_wnd.Show(); | |
| 126 error_wnd.DisplayCompletionDialog(false, error_text, help_url); | |
| 127 message_loop.Run(); | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 bool DisplayContinueAsNonAdmin(const CString& bundle_name, | |
| 132 bool* should_continue) { | |
| 133 ASSERT1(should_continue); | |
| 134 *should_continue = false; | |
| 135 | |
| 136 CString title(client_utils::GetInstallerDisplayName(bundle_name)); | |
| 137 CString text; | |
| 138 text.FormatMessage(IDS_CONTINUE_AS_NONADMIN, bundle_name); | |
| 139 | |
| 140 CMessageLoop message_loop; | |
| 141 YesNoDialog continue_dialog(&message_loop, NULL); | |
| 142 HRESULT hr = continue_dialog.Initialize(title, text); | |
| 143 | |
| 144 if (FAILED(hr)) { | |
| 145 int button_id = ::MessageBox(NULL, text, title, MB_YESNO); | |
| 146 *should_continue = button_id == IDYES; | |
| 147 return button_id != 0; | |
| 148 } | |
| 149 | |
| 150 VERIFY1(SUCCEEDED(continue_dialog.Show())); | |
| 151 message_loop.Run(); | |
| 152 | |
| 153 *should_continue = continue_dialog.yes_clicked(); | |
| 154 return true; | |
| 155 } | |
| 156 | |
| 157 CString GetDefaultApplicationName() { | |
| 158 CString company_name; | |
| 159 VERIFY1(company_name.LoadString(IDS_FRIENDLY_COMPANY_NAME)); | |
| 160 | |
| 161 CString default_app_name; | |
| 162 default_app_name.FormatMessage(IDS_DEFAULT_APP_DISPLAY_NAME, company_name); | |
| 163 return default_app_name; | |
| 164 } | |
| 165 | |
| 166 CString GetDefaultBundleName() { | |
| 167 return GetDefaultApplicationName(); | |
| 168 } | |
| 169 | |
| 170 CString GetUpdateAllAppsBundleName() { | |
| 171 // TODO(omaha3): If we ever productize interactive updates, we will need a | |
| 172 // different string. This may be okay for the title bar, but it looks weird | |
| 173 // in the completion strings. The current implementation uses the same string | |
| 174 // for both. | |
| 175 return GetDefaultApplicationName(); | |
| 176 } | |
| 177 | |
| 178 // If bundle_name is empty, the friendly company name is used. | |
| 179 CString GetInstallerDisplayName(const CString& bundle_name) { | |
| 180 CString display_name = bundle_name; | |
| 181 if (display_name.IsEmpty()) { | |
| 182 VERIFY1(display_name.LoadString(IDS_FRIENDLY_COMPANY_NAME)); | |
| 183 } | |
| 184 | |
| 185 CString installer_name; | |
| 186 installer_name.FormatMessage(IDS_INSTALLER_DISPLAY_NAME, display_name); | |
| 187 return installer_name; | |
| 188 } | |
| 189 | |
| 190 } // namespace client_utils | |
| 191 | |
| 192 } // namespace omaha | |
| OLD | NEW |