1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/startup/bad_flags_prompt.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/simple_message_box.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/switch_utils.h"
18 #include "components/startup_metric_utils/startup_metric_utils.h"
19 #include "components/translate/core/common/translate_switches.h"
20 #include "extensions/common/switches.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h"
28 void ShowBadFlagsPrompt(Browser* browser) {
29 content::WebContents* web_contents =
30 browser->tab_strip_model()->GetActiveWebContents();
34 // Unsupported flags for which to display a warning that "stability and
35 // security will suffer".
36 static const char* kBadFlags[] = {
37 // These imply disabling the sandbox.
38 switches::kSingleProcess,
40 switches::kDisableWebSecurity,
41 // Browser plugin is dangerous on regular pages because it breaks the Same
43 switches::kEnableBrowserPluginForAllViewTypes,
44 extensions::switches::kExtensionsOnChromeURLs,
45 // This parameter should be used only for server side developments.
46 translate::switches::kTranslateScriptURL,
47 translate::switches::kTranslateSecurityOrigin,
48 #if defined(ENABLE_WEBRTC)
49 // This flag disables security of media packets in WebRTC.
50 switches::kDisableWebRtcEncryption,
55 for (const char** flag = kBadFlags; *flag; ++flag) {
56 if (CommandLine::ForCurrentProcess()->HasSwitch(*flag)) {
57 SimpleAlertInfoBarDelegate::Create(
58 InfoBarService::FromWebContents(web_contents),
59 InfoBarDelegate::kNoIconID,
60 l10n_util::GetStringFUTF16(IDS_BAD_FLAGS_WARNING_MESSAGE,
62 std::string("--") + *flag)),
69 void MaybeShowInvalidUserDataDirWarningDialog() {
70 const base::FilePath& user_data_dir = GetInvalidSpecifiedUserDataDir();
71 if (user_data_dir.empty())
74 startup_metric_utils::SetNonBrowserUIDisplayed();
76 // Ensure the ResourceBundle is initialized for string resource access.
77 bool cleanup_resource_bundle = false;
78 if (!ResourceBundle::HasSharedInstance()) {
79 cleanup_resource_bundle = true;
80 std::string locale = l10n_util::GetApplicationLocale(std::string());
81 const char kUserDataDirDialogFallbackLocale[] = "en-US";
83 locale = kUserDataDirDialogFallbackLocale;
84 ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
87 const base::string16& title =
88 l10n_util::GetStringUTF16(IDS_CANT_WRITE_USER_DIRECTORY_TITLE);
89 const base::string16& message =
90 l10n_util::GetStringFUTF16(IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY,
91 user_data_dir.LossyDisplayName());
93 if (cleanup_resource_bundle)
94 ResourceBundle::CleanupSharedInstance();
96 // More complex dialogs cannot be shown before the earliest calls here.
97 ShowMessageBox(NULL, title, message, chrome::MESSAGE_BOX_TYPE_WARNING);
100 } // namespace chrome