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/ui/browser.h"
12 #include "chrome/browser/ui/simple_message_box.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/switch_utils.h"
17 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "components/infobars/core/simple_alert_infobar_delegate.h"
20 #include "components/invalidation/impl/invalidation_switches.h"
21 #include "components/nacl/common/nacl_switches.h"
22 #include "components/startup_metric_utils/startup_metric_utils.h"
23 #include "components/translate/core/common/translate_switches.h"
24 #include "content/public/common/content_switches.h"
25 #include "extensions/common/switches.h"
26 #include "google_apis/gaia/gaia_switches.h"
27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h"
32 void ShowBadFlagsPrompt(Browser
* browser
) {
33 content::WebContents
* web_contents
=
34 browser
->tab_strip_model()->GetActiveWebContents();
38 // Unsupported flags for which to display a warning that "stability and
39 // security will suffer".
40 static const char* kBadFlags
[] = {
41 // These flags disable sandbox-related security.
42 switches::kDisableGpuSandbox
,
43 switches::kDisableSeccompFilterSandbox
,
44 switches::kDisableSetuidSandbox
,
45 switches::kDisableWebSecurity
,
46 #if !defined(DISABLE_NACL)
47 switches::kNaClDangerousNoSandboxNonSfi
,
50 switches::kSingleProcess
,
52 // These flags disable or undermine the Same Origin Policy.
53 switches::kTrustedSpdyProxy
,
54 translate::switches::kTranslateSecurityOrigin
,
56 // These flags undermine HTTPS / connection security.
57 #if defined(ENABLE_WEBRTC)
58 switches::kDisableWebRtcEncryption
,
60 switches::kIgnoreCertificateErrors
,
61 switches::kReduceSecurityForTesting
,
62 invalidation::switches::kSyncAllowInsecureXmppConnection
,
64 // These flags change the URLs that handle PII.
65 autofill::switches::kWalletSecureServiceUrl
,
67 translate::switches::kTranslateScriptURL
,
69 // This flag gives extensions more powers.
70 extensions::switches::kExtensionsOnChromeURLs
,
72 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
73 // Speech dispatcher is buggy, it can crash and it can make Chrome freeze.
74 // http://crbug.com/327295
75 switches::kEnableSpeechDispatcher
,
78 // These flags control Blink feature state, which is not supported and is
79 // intended only for use by Chromium developers.
80 switches::kDisableBlinkFeatures
,
81 switches::kEnableBlinkFeatures
,
83 // This flag allows people to whitelist certain origins as secure, even
85 switches::kUnsafelyTreatInsecureOriginAsSecure
,
87 // This flag enables Web Bluetooth. Since the UI for Web Bluetooth is
88 // not yet implemented, websites could take control over paired devices
89 // without the users knowledge, so we need to show a warning for when
90 // the flag is enabled.
91 switches::kEnableWebBluetooth
,
96 for (const char** flag
= kBadFlags
; *flag
; ++flag
) {
97 if (base::CommandLine::ForCurrentProcess()->HasSwitch(*flag
)) {
98 SimpleAlertInfoBarDelegate::Create(
99 InfoBarService::FromWebContents(web_contents
),
100 infobars::InfoBarDelegate::kNoIconID
,
101 l10n_util::GetStringFUTF16(IDS_BAD_FLAGS_WARNING_MESSAGE
,
103 std::string("--") + *flag
)),
110 void MaybeShowInvalidUserDataDirWarningDialog() {
111 const base::FilePath
& user_data_dir
= GetInvalidSpecifiedUserDataDir();
112 if (user_data_dir
.empty())
115 startup_metric_utils::SetNonBrowserUIDisplayed();
117 // Ensure the ResourceBundle is initialized for string resource access.
118 bool cleanup_resource_bundle
= false;
119 if (!ResourceBundle::HasSharedInstance()) {
120 cleanup_resource_bundle
= true;
121 std::string locale
= l10n_util::GetApplicationLocale(std::string());
122 const char kUserDataDirDialogFallbackLocale
[] = "en-US";
124 locale
= kUserDataDirDialogFallbackLocale
;
125 ui::ResourceBundle::InitSharedInstanceWithLocale(
126 locale
, NULL
, ui::ResourceBundle::LOAD_COMMON_RESOURCES
);
129 const base::string16
& title
=
130 l10n_util::GetStringUTF16(IDS_CANT_WRITE_USER_DIRECTORY_TITLE
);
131 const base::string16
& message
=
132 l10n_util::GetStringFUTF16(IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY
,
133 user_data_dir
.LossyDisplayName());
135 if (cleanup_resource_bundle
)
136 ResourceBundle::CleanupSharedInstance();
138 // More complex dialogs cannot be shown before the earliest calls here.
139 ShowMessageBox(NULL
, title
, message
, chrome::MESSAGE_BOX_TYPE_WARNING
);
142 } // namespace chrome