OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | 5 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/metrics/field_trial.h" | |
8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" | 10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 11 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
12 #include "chrome/browser/extensions/install_verifier.h" | |
10 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h" | 13 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h" |
11 #include "chrome/browser/extensions/settings_api_bubble_controller.h" | 14 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
12 #include "chrome/browser/extensions/settings_api_helpers.h" | 15 #include "chrome/browser/extensions/settings_api_helpers.h" |
13 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | 16 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_switches.h" | |
19 #include "extensions/common/feature_switch.h" | |
15 | 20 |
16 namespace { | 21 namespace { |
17 | 22 |
18 // A map of all profiles evaluated, so we can tell if it's the initial check. | 23 // A map of all profiles evaluated, so we can tell if it's the initial check. |
19 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps | 24 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps |
20 // that are in the different bubble controllers. | 25 // that are in the different bubble controllers. |
21 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated = | 26 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated = |
22 LAZY_INSTANCE_INITIALIZER; | 27 LAZY_INSTANCE_INITIALIZER; |
23 | 28 |
24 // Currently, we only show these bubbles on windows platforms. This can be | 29 // This is used to turn on all bubbles for testing. |
25 // overridden for testing purposes. | 30 bool g_enabled = false; |
Devlin
2015/05/08 16:06:35
Since this is only ever used in testing now, it sh
asargent_no_longer_on_chrome
2015/05/08 16:29:48
Done. I used 'g_enabled_for_tests' because that is
| |
31 | |
32 const char kEnableDevModeWarningExperimentName[] = | |
33 "ExtensionDeveloperModeWarning"; | |
34 | |
35 const char kEnableProxyWarningExperimentName[] = | |
36 "ExtensionProxyWarning"; | |
37 | |
38 bool IsExperimentEnabled(const char* experiment_name) { | |
39 // Don't allow turning it off via command line. | |
40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
41 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | |
42 std::string forced_trials = | |
43 command_line->GetSwitchValueASCII(switches::kForceFieldTrials); | |
44 if (forced_trials.find(experiment_name)) | |
45 return true; | |
46 } | |
47 return base::FieldTrialList::FindFullName(experiment_name) == "Enabled"; | |
48 } | |
49 | |
50 bool EnableSuspiciousExtensionsBubble() { | |
51 return g_enabled || extensions::InstallVerifier::ShouldEnforce(); | |
52 } | |
53 | |
54 bool EnableSettingsApiBubble() { | |
26 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
27 bool g_enabled = true; | 56 return true; |
28 #else | |
29 bool g_enabled = false; | |
30 #endif | 57 #endif |
58 return g_enabled; | |
59 } | |
60 | |
61 bool EnableProxyOverrideBubble() { | |
62 #if defined(OS_WIN) | |
63 return true; | |
64 #endif | |
65 return g_enabled || IsExperimentEnabled(kEnableProxyWarningExperimentName); | |
66 } | |
67 | |
68 bool EnableDevModeBubble() { | |
69 if (extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) | |
70 return true; | |
71 | |
72 #if defined(OS_WIN) | |
73 if (chrome::VersionInfo::GetChannel() >= chrome::VersionInfo::CHANNEL_BETA) | |
74 return true; | |
75 #endif | |
76 | |
77 return g_enabled || IsExperimentEnabled(kEnableDevModeWarningExperimentName); | |
78 } | |
31 | 79 |
32 } // namespace | 80 } // namespace |
33 | 81 |
34 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Profile* profile) | 82 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Profile* profile) |
35 : profile_(profile) { | 83 : profile_(profile) { |
36 } | 84 } |
37 | 85 |
38 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { | 86 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { |
39 } | 87 } |
40 | 88 |
41 scoped_ptr<extensions::ExtensionMessageBubbleController> | 89 scoped_ptr<extensions::ExtensionMessageBubbleController> |
42 ExtensionMessageBubbleFactory::GetController() { | 90 ExtensionMessageBubbleFactory::GetController() { |
43 if (!g_enabled) | |
44 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); | |
45 | |
46 Profile* original_profile = profile_->GetOriginalProfile(); | 91 Profile* original_profile = profile_->GetOriginalProfile(); |
47 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get(); | 92 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get(); |
48 bool is_initial_check = profiles_evaluated.count(original_profile) == 0; | 93 bool is_initial_check = profiles_evaluated.count(original_profile) == 0; |
49 profiles_evaluated.insert(original_profile); | 94 profiles_evaluated.insert(original_profile); |
50 | 95 |
51 // The list of suspicious extensions takes priority over the dev mode bubble | 96 // The list of suspicious extensions takes priority over the dev mode bubble |
52 // and the settings API bubble, since that needs to be shown as soon as we | 97 // and the settings API bubble, since that needs to be shown as soon as we |
53 // disable something. The settings API bubble is shown on first startup after | 98 // disable something. The settings API bubble is shown on first startup after |
54 // an extension has changed the startup pages and it is acceptable if that | 99 // an extension has changed the startup pages and it is acceptable if that |
55 // waits until the next startup because of the suspicious extension bubble. | 100 // waits until the next startup because of the suspicious extension bubble. |
56 // The dev mode bubble is not time sensitive like the other two so we'll catch | 101 // The dev mode bubble is not time sensitive like the other two so we'll catch |
57 // the dev mode extensions on the next startup/next window that opens. That | 102 // the dev mode extensions on the next startup/next window that opens. That |
58 // way, we're not too spammy with the bubbles. | 103 // way, we're not too spammy with the bubbles. |
59 { | 104 if (EnableSuspiciousExtensionsBubble()) { |
60 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller( | 105 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller( |
61 new extensions::SuspiciousExtensionBubbleController(profile_)); | 106 new extensions::SuspiciousExtensionBubbleController(profile_)); |
62 if (controller->ShouldShow()) | 107 if (controller->ShouldShow()) |
63 return controller.Pass(); | 108 return controller.Pass(); |
64 } | 109 } |
65 | 110 |
66 { | 111 if (EnableSettingsApiBubble()) { |
67 // No use showing this if it's not the startup of the profile. | 112 // No use showing this if it's not the startup of the profile. |
68 if (is_initial_check) { | 113 if (is_initial_check) { |
69 scoped_ptr<extensions::SettingsApiBubbleController> controller( | 114 scoped_ptr<extensions::SettingsApiBubbleController> controller( |
70 new extensions::SettingsApiBubbleController( | 115 new extensions::SettingsApiBubbleController( |
71 profile_, extensions::BUBBLE_TYPE_STARTUP_PAGES)); | 116 profile_, extensions::BUBBLE_TYPE_STARTUP_PAGES)); |
72 if (controller->ShouldShow()) | 117 if (controller->ShouldShow()) |
73 return controller.Pass(); | 118 return controller.Pass(); |
74 } | 119 } |
75 } | 120 } |
76 | 121 |
77 { | 122 if (EnableProxyOverrideBubble()) { |
78 // TODO(devlin): Move the "GetExtensionOverridingProxy" part into the | 123 // TODO(devlin): Move the "GetExtensionOverridingProxy" part into the |
79 // proxy bubble controller. | 124 // proxy bubble controller. |
80 const extensions::Extension* extension = | 125 const extensions::Extension* extension = |
81 extensions::GetExtensionOverridingProxy(profile_); | 126 extensions::GetExtensionOverridingProxy(profile_); |
82 if (extension) { | 127 if (extension) { |
83 scoped_ptr<extensions::ProxyOverriddenBubbleController> controller( | 128 scoped_ptr<extensions::ProxyOverriddenBubbleController> controller( |
84 new extensions::ProxyOverriddenBubbleController(profile_)); | 129 new extensions::ProxyOverriddenBubbleController(profile_)); |
85 if (controller->ShouldShow(extension->id())) | 130 if (controller->ShouldShow(extension->id())) |
86 return controller.Pass(); | 131 return controller.Pass(); |
87 } | 132 } |
88 } | 133 } |
89 | 134 |
90 { | 135 if (EnableDevModeBubble()) { |
91 scoped_ptr<extensions::DevModeBubbleController> controller( | 136 scoped_ptr<extensions::DevModeBubbleController> controller( |
92 new extensions::DevModeBubbleController(profile_)); | 137 new extensions::DevModeBubbleController(profile_)); |
93 if (controller->ShouldShow()) | 138 if (controller->ShouldShow()) |
94 return controller.Pass(); | 139 return controller.Pass(); |
95 } | 140 } |
96 | 141 |
97 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); | 142 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); |
98 } | 143 } |
99 | 144 |
100 // static | 145 // static |
101 void ExtensionMessageBubbleFactory::set_enabled_for_tests(bool enabled) { | 146 void ExtensionMessageBubbleFactory::set_enabled_for_tests(bool enabled) { |
102 g_enabled = enabled; | 147 g_enabled = enabled; |
103 } | 148 } |
OLD | NEW |