OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/views/extensions/disabled_extensions_view.h" | 5 #include "chrome/browser/ui/views/extensions/disabled_extensions_view.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/singleton_tabs.h" | 14 #include "chrome/browser/ui/singleton_tabs.h" |
15 #include "chrome/browser/prefs/pref_service.h" | |
14 #include "chrome/common/extensions/feature_switch.h" | 16 #include "chrome/common/extensions/feature_switch.h" |
17 #include "chrome/common/pref_names.h" | |
15 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
16 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
17 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
18 #include "grit/locale_settings.h" | 21 #include "grit/locale_settings.h" |
19 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
20 #include "ui/base/accessibility/accessible_view_state.h" | 23 #include "ui/base/accessibility/accessible_view_state.h" |
21 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/views/controls/button/text_button.h" | 26 #include "ui/views/controls/button/text_button.h" |
24 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
36 const int kColumnPadding = 4; | 39 const int kColumnPadding = 4; |
37 const int kExtensionListPadding = 20; | 40 const int kExtensionListPadding = 20; |
38 const int kImagePadding = 7; | 41 const int kImagePadding = 7; |
39 const int kLeftColumnPadding = 3; | 42 const int kLeftColumnPadding = 3; |
40 const int kInsetBottomRight = 13; | 43 const int kInsetBottomRight = 13; |
41 const int kInsetTopLeft = 14; | 44 const int kInsetTopLeft = 14; |
42 const int kHeadlineMessagePadding = 4; | 45 const int kHeadlineMessagePadding = 4; |
43 const int kHeadlineRowPadding = 10; | 46 const int kHeadlineRowPadding = 10; |
44 const int kMessageBubblePadding = 11; | 47 const int kMessageBubblePadding = 11; |
45 | 48 |
49 // How often to show the disabled extension (sideload wipeout) bubble. | |
50 const int kShowSideloadWipeoutBubbleMax = 3; | |
51 | |
46 // How many extensions to show in the bubble (max). | 52 // How many extensions to show in the bubble (max). |
47 const int kMaxExtensionsToShow = 7; | 53 const int kMaxExtensionsToShow = 7; |
48 | 54 |
49 } // namespace | 55 } // namespace |
50 | 56 |
51 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
52 // DisabledExtensionsView | 58 // DisabledExtensionsView |
53 | 59 |
54 // static | 60 // static |
55 bool DisabledExtensionsView::MaybeShow(Browser* browser, | 61 void DisabledExtensionsView::MaybeShow(Browser* browser, |
56 views::View* anchor_view) { | 62 views::View* anchor_view) { |
57 #if !defined(OS_WIN) | |
58 // We are targeting registry-installed extensions, which is Windows-specific, | |
59 // and extensions marked internal and not from the web store, which are mostly | |
60 // problematic on Windows. | |
61 return false; | |
62 #endif | |
63 | |
64 if (!extensions::FeatureSwitch::sideload_wipeout()->IsEnabled()) | 63 if (!extensions::FeatureSwitch::sideload_wipeout()->IsEnabled()) |
65 return false; | 64 return; |
66 | 65 |
67 static bool done_showing_ui = false; | 66 static bool done_showing_ui = false; |
68 if (done_showing_ui) | 67 if (done_showing_ui) |
69 return false; // Only show the bubble once per launch. | 68 return; // Only show the bubble once per launch. |
69 | |
70 // A pref that counts how often the bubble has been shown. | |
71 IntegerPrefMember sideload_wipeout_bubble_shown; | |
72 | |
73 sideload_wipeout_bubble_shown.Init( | |
Aaron Boodman
2012/10/23 16:18:06
Since this is used in multiple methods and is low-
Finnur
2012/10/23 16:55:45
This function is static and this (would be) member
| |
74 prefs::kExtensionsSideloadWipeoutBubbleShown, | |
75 browser->profile()->GetPrefs(), NULL); | |
76 int bubble_shown_count = sideload_wipeout_bubble_shown.GetValue(); | |
77 if (bubble_shown_count >= kShowSideloadWipeoutBubbleMax) | |
78 return; | |
79 sideload_wipeout_bubble_shown.SetValue(++bubble_shown_count); | |
70 | 80 |
71 // Fetch all disabled extensions. | 81 // Fetch all disabled extensions. |
72 ExtensionService* extension_service = | 82 ExtensionService* extension_service = |
73 extensions::ExtensionSystem::Get( | 83 extensions::ExtensionSystem::Get( |
74 browser->profile())->extension_service(); | 84 browser->profile())->extension_service(); |
75 scoped_ptr<const ExtensionSet> wiped_out( | 85 scoped_ptr<const ExtensionSet> wiped_out( |
76 extension_service->GetWipedOutExtensions()); | 86 extension_service->GetWipedOutExtensions()); |
77 if (wiped_out->size()) { | 87 if (wiped_out->size()) { |
78 DisabledExtensionsView* bubble_delegate = | 88 DisabledExtensionsView* bubble_delegate = |
79 new DisabledExtensionsView( | 89 new DisabledExtensionsView( |
80 anchor_view, browser, wiped_out.release()); | 90 anchor_view, browser, wiped_out.release()); |
81 views::BubbleDelegateView::CreateBubble(bubble_delegate); | 91 views::BubbleDelegateView::CreateBubble(bubble_delegate); |
82 bubble_delegate->StartFade(true); | 92 bubble_delegate->StartFade(true); |
83 | 93 |
84 done_showing_ui = true; | 94 done_showing_ui = true; |
85 return true; | |
86 } | 95 } |
87 | |
88 return false; | |
89 } | 96 } |
90 | 97 |
91 DisabledExtensionsView::DisabledExtensionsView( | 98 DisabledExtensionsView::DisabledExtensionsView( |
92 views::View* anchor_view, | 99 views::View* anchor_view, |
93 Browser* browser, | 100 Browser* browser, |
94 const ExtensionSet* wiped_out) | 101 const ExtensionSet* wiped_out) |
95 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 102 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
96 browser_(browser), | 103 browser_(browser), |
97 wiped_out_(wiped_out), | 104 wiped_out_(wiped_out), |
98 headline_(NULL), | 105 headline_(NULL), |
99 learn_more_(NULL), | 106 learn_more_(NULL), |
100 settings_button_(NULL), | 107 settings_button_(NULL), |
101 dismiss_button_(NULL) { | 108 dismiss_button_(NULL) { |
102 set_close_on_deactivate(false); | 109 set_close_on_deactivate(false); |
103 set_move_with_anchor(true); | 110 set_move_with_anchor(true); |
104 | 111 |
105 UMA_HISTOGRAM_COUNTS_100("DisabledExtension.SideloadWipeoutCount", | 112 UMA_HISTOGRAM_COUNTS_100("DisabledExtension.SideloadWipeoutCount", |
106 wiped_out->size()); | 113 wiped_out->size()); |
107 } | 114 } |
108 | 115 |
109 DisabledExtensionsView::~DisabledExtensionsView() { | 116 DisabledExtensionsView::~DisabledExtensionsView() { |
110 } | 117 } |
111 | 118 |
119 void DisabledExtensionsView::DontShowBubbleAgain() { | |
120 IntegerPrefMember sideload_wipeout_bubble_shown; | |
121 sideload_wipeout_bubble_shown.Init( | |
122 prefs::kExtensionsSideloadWipeoutBubbleShown, | |
123 browser_->profile()->GetPrefs(), NULL); | |
124 sideload_wipeout_bubble_shown.SetValue(kShowSideloadWipeoutBubbleMax); | |
125 } | |
126 | |
112 void DisabledExtensionsView::ButtonPressed(views::Button* sender, | 127 void DisabledExtensionsView::ButtonPressed(views::Button* sender, |
113 const ui::Event& event) { | 128 const ui::Event& event) { |
114 if (sender == settings_button_) { | 129 if (sender == settings_button_) { |
115 content::RecordAction( | 130 content::RecordAction( |
116 UserMetricsAction("DisabledExtension_SettingsButton")); | 131 UserMetricsAction("DisabledExtension_SettingsButton")); |
117 browser_->OpenURL( | 132 browser_->OpenURL( |
118 content::OpenURLParams(GURL(chrome::kChromeUIExtensionsURL), | 133 content::OpenURLParams(GURL(chrome::kChromeUIExtensionsURL), |
119 content::Referrer(), | 134 content::Referrer(), |
120 NEW_FOREGROUND_TAB, | 135 NEW_FOREGROUND_TAB, |
121 content::PAGE_TRANSITION_LINK, | 136 content::PAGE_TRANSITION_LINK, |
122 false)); | 137 false)); |
123 | 138 |
124 } else if (sender == dismiss_button_) { | 139 } else if (sender == dismiss_button_) { |
125 content::RecordAction(UserMetricsAction("DisabledExtension_Dismiss")); | 140 content::RecordAction(UserMetricsAction("DisabledExtension_Dismiss")); |
126 // No action required. Close will happen below. | |
127 } else { | 141 } else { |
128 NOTREACHED(); | 142 NOTREACHED(); |
129 } | 143 } |
130 | 144 |
145 DontShowBubbleAgain(); | |
Aaron Boodman
2012/10/23 16:18:06
Per Peter's comment, this should go in LinkClicked
Finnur
2012/10/23 16:55:45
Done.
On 2012/10/23 16:18:06, Aaron Boodman wrote
| |
146 | |
131 GetWidget()->Close(); | 147 GetWidget()->Close(); |
132 } | 148 } |
133 | 149 |
134 void DisabledExtensionsView::LinkClicked( | 150 void DisabledExtensionsView::LinkClicked( |
135 views::Link* source, int event_flags) { | 151 views::Link* source, int event_flags) { |
136 content::RecordAction(UserMetricsAction("DisabledExtension_LearnMore")); | 152 content::RecordAction(UserMetricsAction("DisabledExtension_LearnMore")); |
137 browser_->OpenURL( | 153 browser_->OpenURL( |
138 content::OpenURLParams(GURL(chrome::kSideloadWipeoutHelpURL), | 154 content::OpenURLParams(GURL(chrome::kSideloadWipeoutHelpURL), |
139 content::Referrer(), | 155 content::Referrer(), |
140 NEW_FOREGROUND_TAB, | 156 NEW_FOREGROUND_TAB, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 layout->AddView(settings_button_); | 300 layout->AddView(settings_button_); |
285 dismiss_button_ = new views::NativeTextButton(this, | 301 dismiss_button_ = new views::NativeTextButton(this, |
286 l10n_util::GetStringUTF16(IDS_OPTIONS_SIDELOAD_WIPEOUT_DISMISS)); | 302 l10n_util::GetStringUTF16(IDS_OPTIONS_SIDELOAD_WIPEOUT_DISMISS)); |
287 dismiss_button_->SetFont( | 303 dismiss_button_->SetFont( |
288 dismiss_button_->font().DeriveFont(0, gfx::Font::BOLD)); | 304 dismiss_button_->font().DeriveFont(0, gfx::Font::BOLD)); |
289 layout->AddView(dismiss_button_); | 305 layout->AddView(dismiss_button_); |
290 | 306 |
291 content::RecordAction( | 307 content::RecordAction( |
292 UserMetricsAction("DisabledExtensionNotificationShown")); | 308 UserMetricsAction("DisabledExtensionNotificationShown")); |
293 } | 309 } |
OLD | NEW |