Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / startup / bad_flags_prompt.cc
blobcfd8d7ff2dbc31bc40eb7164b8efeb14a3e6223f
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"
30 namespace chrome {
32 void ShowBadFlagsPrompt(Browser* browser) {
33 content::WebContents* web_contents =
34 browser->tab_strip_model()->GetActiveWebContents();
35 if (!web_contents)
36 return;
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,
48 #endif
49 switches::kNoSandbox,
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,
59 #endif
60 switches::kIgnoreCertificateErrors,
61 switches::kReduceSecurityForTesting,
62 invalidation::switches::kSyncAllowInsecureXmppConnection,
64 // These flags change the URLs that handle PII.
65 autofill::switches::kWalletSecureServiceUrl,
66 switches::kGaiaUrl,
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,
76 #endif
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
84 // if they are not.
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,
93 // This flag bypasses the permission UI for WebUSB as it not yet
94 // implemented. The risk is minimal because a device still needs to
95 // whitelist the requesting origin, but since this means the site can take
96 // action without the user's knowledge we need to show a warning when the
97 // flag is enabled.
98 switches::kEnableWebUsbOnAnyOrigin,
100 NULL
103 for (const char** flag = kBadFlags; *flag; ++flag) {
104 if (base::CommandLine::ForCurrentProcess()->HasSwitch(*flag)) {
105 SimpleAlertInfoBarDelegate::Create(
106 InfoBarService::FromWebContents(web_contents),
107 infobars::InfoBarDelegate::kNoIconID,
108 l10n_util::GetStringFUTF16(IDS_BAD_FLAGS_WARNING_MESSAGE,
109 base::UTF8ToUTF16(
110 std::string("--") + *flag)),
111 false);
112 return;
117 void MaybeShowInvalidUserDataDirWarningDialog() {
118 const base::FilePath& user_data_dir = GetInvalidSpecifiedUserDataDir();
119 if (user_data_dir.empty())
120 return;
122 startup_metric_utils::SetNonBrowserUIDisplayed();
124 // Ensure the ResourceBundle is initialized for string resource access.
125 bool cleanup_resource_bundle = false;
126 if (!ResourceBundle::HasSharedInstance()) {
127 cleanup_resource_bundle = true;
128 std::string locale = l10n_util::GetApplicationLocale(std::string());
129 const char kUserDataDirDialogFallbackLocale[] = "en-US";
130 if (locale.empty())
131 locale = kUserDataDirDialogFallbackLocale;
132 ui::ResourceBundle::InitSharedInstanceWithLocale(
133 locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
136 const base::string16& title =
137 l10n_util::GetStringUTF16(IDS_CANT_WRITE_USER_DIRECTORY_TITLE);
138 const base::string16& message =
139 l10n_util::GetStringFUTF16(IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY,
140 user_data_dir.LossyDisplayName());
142 if (cleanup_resource_bundle)
143 ResourceBundle::CleanupSharedInstance();
145 // More complex dialogs cannot be shown before the earliest calls here.
146 ShowMessageBox(NULL, title, message, chrome::MESSAGE_BOX_TYPE_WARNING);
149 } // namespace chrome