• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/startup/bad_flags_prompt.h"
6 
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/invalidation/invalidation_switches.h"
19 #include "components/nacl/common/nacl_switches.h"
20 #include "components/startup_metric_utils/startup_metric_utils.h"
21 #include "components/translate/core/common/translate_switches.h"
22 #include "content/public/common/content_switches.h"
23 #include "extensions/common/switches.h"
24 #include "google_apis/gaia/gaia_switches.h"
25 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h"
27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h"
29 
30 namespace chrome {
31 
ShowBadFlagsPrompt(Browser * browser)32 void ShowBadFlagsPrompt(Browser* browser) {
33   content::WebContents* web_contents =
34       browser->tab_strip_model()->GetActiveWebContents();
35   if (!web_contents)
36     return;
37 
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     switches::kNaClDangerousNoSandboxNonSfi,
47     switches::kNoSandbox,
48     switches::kSingleProcess,
49 
50     // These flags disable or undermine the Same Origin Policy.
51     switches::kTrustedSpdyProxy,
52     translate::switches::kTranslateSecurityOrigin,
53 
54     // These flags undermine HTTPS / connection security.
55 #if defined(ENABLE_WEBRTC)
56     switches::kDisableWebRtcEncryption,
57 #endif
58     switches::kIgnoreCertificateErrors,
59     switches::kReduceSecurityForTesting,
60     invalidation::switches::kSyncAllowInsecureXmppConnection,
61 
62     // These flags change the URLs that handle PII.
63     autofill::switches::kWalletSecureServiceUrl,
64     switches::kGaiaUrl,
65     translate::switches::kTranslateScriptURL,
66 
67     // This flag gives extensions more powers.
68     extensions::switches::kExtensionsOnChromeURLs,
69 
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,
74 #endif
75     NULL
76   };
77 
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,
84                                      base::UTF8ToUTF16(
85                                          std::string("--") + *flag)),
86           false);
87       return;
88     }
89   }
90 }
91 
MaybeShowInvalidUserDataDirWarningDialog()92 void MaybeShowInvalidUserDataDirWarningDialog() {
93   const base::FilePath& user_data_dir = GetInvalidSpecifiedUserDataDir();
94   if (user_data_dir.empty())
95     return;
96 
97   startup_metric_utils::SetNonBrowserUIDisplayed();
98 
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";
105     if (locale.empty())
106       locale = kUserDataDirDialogFallbackLocale;
107     ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
108   }
109 
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());
115 
116   if (cleanup_resource_bundle)
117     ResourceBundle::CleanupSharedInstance();
118 
119   // More complex dialogs cannot be shown before the earliest calls here.
120   ShowMessageBox(NULL, title, message, chrome::MESSAGE_BOX_TYPE_WARNING);
121 }
122 
123 }  // namespace chrome
124