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/nacl/common/nacl_switches.h"
19 #include "components/startup_metric_utils/startup_metric_utils.h"
20 #include "components/translate/core/common/translate_switches.h"
21 #include "content/public/common/content_switches.h"
22 #include "extensions/common/switches.h"
23 #include "google_apis/gaia/gaia_switches.h"
24 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h"
31 void ShowBadFlagsPrompt(Browser
* browser
) {
32 content::WebContents
* web_contents
=
33 browser
->tab_strip_model()->GetActiveWebContents();
37 // Unsupported flags for which to display a warning that "stability and
38 // security will suffer".
39 static const char* kBadFlags
[] = {
40 // These flags disable sandbox-related security.
41 switches::kDisableGpuSandbox
,
42 switches::kDisableSeccompFilterSandbox
,
43 switches::kDisableSetuidSandbox
,
44 switches::kDisableWebSecurity
,
45 switches::kNaClDangerousNoSandboxNonSfi
,
47 switches::kSingleProcess
,
49 // These flags disable or undermine the Same Origin Policy.
50 switches::kTrustedSpdyProxy
,
51 translate::switches::kTranslateSecurityOrigin
,
53 // These flags undermine HTTPS / connection security.
54 switches::kDisableUserMediaSecurity
,
55 #if defined(ENABLE_WEBRTC)
56 switches::kDisableWebRtcEncryption
,
58 switches::kIgnoreCertificateErrors
,
59 switches::kReduceSecurityForTesting
,
60 switches::kSyncAllowInsecureXmppConnection
,
62 // These flags change the URLs that handle PII.
63 autofill::switches::kWalletSecureServiceUrl
,
65 translate::switches::kTranslateScriptURL
,
67 // This flag gives extensions more powers.
68 extensions::switches::kExtensionsOnChromeURLs
,
70 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
71 // Speech dispatcher is buggy, it can crash and it can make Chrome freeze.
72 // http://crbug.com/327295
73 switches::kEnableSpeechDispatcher
,
78 for (const char** flag
= kBadFlags
; *flag
; ++flag
) {
79 if (CommandLine::ForCurrentProcess()->HasSwitch(*flag
)) {
80 SimpleAlertInfoBarDelegate::Create(
81 InfoBarService::FromWebContents(web_contents
),
82 infobars::InfoBarDelegate::kNoIconID
,
83 l10n_util::GetStringFUTF16(IDS_BAD_FLAGS_WARNING_MESSAGE
,
85 std::string("--") + *flag
)),
92 void MaybeShowInvalidUserDataDirWarningDialog() {
93 const base::FilePath
& user_data_dir
= GetInvalidSpecifiedUserDataDir();
94 if (user_data_dir
.empty())
97 startup_metric_utils::SetNonBrowserUIDisplayed();
99 // Ensure the ResourceBundle is initialized for string resource access.
100 bool cleanup_resource_bundle
= false;
101 if (!ResourceBundle::HasSharedInstance()) {
102 cleanup_resource_bundle
= true;
103 std::string locale
= l10n_util::GetApplicationLocale(std::string());
104 const char kUserDataDirDialogFallbackLocale
[] = "en-US";
106 locale
= kUserDataDirDialogFallbackLocale
;
107 ResourceBundle::InitSharedInstanceWithLocale(locale
, NULL
);
110 const base::string16
& title
=
111 l10n_util::GetStringUTF16(IDS_CANT_WRITE_USER_DIRECTORY_TITLE
);
112 const base::string16
& message
=
113 l10n_util::GetStringFUTF16(IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY
,
114 user_data_dir
.LossyDisplayName());
116 if (cleanup_resource_bundle
)
117 ResourceBundle::CleanupSharedInstance();
119 // More complex dialogs cannot be shown before the earliest calls here.
120 ShowMessageBox(NULL
, title
, message
, chrome::MESSAGE_BOX_TYPE_WARNING
);
123 } // namespace chrome