Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4063)

Unified Diff: chrome/browser/ui/views/recovery_component_bubble_view.cc

Issue 325433002: Elevated install of recovery component (UI part). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/recovery_component_bubble_view.cc
diff --git a/chrome/browser/ui/views/recovery_component_bubble_view.cc b/chrome/browser/ui/views/recovery_component_bubble_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7c191354b1c1f2274f8e9c7f51f1992b3193e877
--- /dev/null
+++ b/chrome/browser/ui/views/recovery_component_bubble_view.cc
@@ -0,0 +1,186 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/recovery_component_bubble_view.h"
+
+#include "base/bind.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/component_updater/recovery_component_installer.h"
+#include "chrome/browser/ui/views/elevation_icon_setter.h"
+#include "chrome/browser/upgrade_detector.h"
+#include "content/public/browser/user_metrics.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/controls/button/label_button.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/grid_layout.h"
+#include "ui/views/layout/layout_constants.h"
+#include "ui/views/widget/widget.h"
+
+namespace {
+
+// Fixed width of the column holding the description label of the bubble.
+const int kWidthOfDescriptionText = 350;
+
+// We subtract 2 to account for the natural button padding, and
+// to bring the separation visually in line with the row separation
+// height.
+const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
+
+} // namespace
+
+// RecoveryComponentBubbleView -------------------------------------------------
+
+RecoveryComponentBubbleView*
+RecoveryComponentBubbleView::recovery_component_bubble_ = NULL;
+
+// static
+void RecoveryComponentBubbleView::ShowBubble(views::View* anchor_view) {
+ if (IsShowing())
+ return;
+ recovery_component_bubble_ = new RecoveryComponentBubbleView(anchor_view);
+ views::BubbleDelegateView::CreateBubble(recovery_component_bubble_)->Show();
+
+ content::RecordAction(
+ base::UserMetricsAction("RecoveryComponentBubble.Show"));
+}
+
+bool RecoveryComponentBubbleView::IsAvailable() {
+// Right now only Windows platform is supported.
+#if defined(OS_WIN)
+ return true;
+#else
+ return false;
+#endif
+}
+
+RecoveryComponentBubbleView::~RecoveryComponentBubbleView() {
+ // Ensure |elevation_icon_setter_| is destroyed before |accept_button_|.
+ elevation_icon_setter_.reset();
+}
+
+views::View* RecoveryComponentBubbleView::GetInitiallyFocusedView() {
+ return accept_button_;
+}
+
+void RecoveryComponentBubbleView::WindowClosing() {
+ // Reset |recovery_component_bubble_| here, not in destructor, because
+ // destruction is asynchronous and ShowBubble may be called before full
+ // destruction and would attempt to show a bubble that is closing.
+ DCHECK_EQ(recovery_component_bubble_, this);
+ recovery_component_bubble_ = NULL;
+}
+
+void RecoveryComponentBubbleView::Init() {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ accept_button_ = new views::LabelButton(
+ this, l10n_util::GetStringUTF16(IDS_RUN_RECOVERY));
+ accept_button_->SetStyle(views::Button::STYLE_BUTTON);
+ accept_button_->SetIsDefault(true);
+ accept_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont));
+ elevation_icon_setter_.reset(new ElevationIconSetter(accept_button_));
+
+ decline_button_ = new views::LabelButton(
+ this, l10n_util::GetStringUTF16(IDS_NO_THANKS));
+ decline_button_->SetStyle(views::Button::STYLE_BUTTON);
+
+ views::Label* title_label = new views::Label(
+ l10n_util::GetStringUTF16(IDS_RECOVERY_BUBBLE_TITLE));
+ title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
+ title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+ views::Label* text_label = new views::Label(
+ l10n_util::GetStringUTF16(IDS_RECOVERY_BUBBLE_TEXT));
+ text_label->SetMultiLine(true);
+ text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+ views::ImageView* image_view = new views::ImageView();
+ image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU_SEVERITY_HIGH));
+
+ views::GridLayout* layout = new views::GridLayout(this);
+ SetLayoutManager(layout);
+
+ const int kIconTitleColumnSetId = 0;
+ views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId);
+
+ // Top (icon-title) row.
+ cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
+ views::GridLayout::USE_PREF, 0, 0);
+ cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
+ cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0,
+ views::GridLayout::USE_PREF, 0, 0);
+ cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
+
+ // Middle (text) row.
+ const int kTextColumnSetId = 1;
+ cs = layout->AddColumnSet(kTextColumnSetId);
+ cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::FIXED, kWidthOfDescriptionText, 0);
+
+ // Bottom (buttons) row.
+ const int kButtonsColumnSetId = 2;
+ cs = layout->AddColumnSet(kButtonsColumnSetId);
+ cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
+ cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::TRAILING, 0,
+ views::GridLayout::USE_PREF, 0, 0);
+ cs->AddPaddingColumn(0, kButtonPadding);
+ cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::TRAILING, 0,
+ views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, kIconTitleColumnSetId);
+ layout->AddView(image_view);
+ layout->AddView(title_label);
+
+ layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
+ layout->StartRow(0, kTextColumnSetId);
+ layout->AddView(text_label);
+
+ layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
+
+ layout->StartRow(0, kButtonsColumnSetId);
+ layout->AddView(accept_button_);
+ layout->AddView(decline_button_);
+
+ AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
+}
+
+RecoveryComponentBubbleView::RecoveryComponentBubbleView(
+ views::View* anchor_view)
+ : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
+ accept_button_(NULL),
+ decline_button_(NULL) {
+ // Compensate for built-in vertical padding in the anchor view's image.
+ set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
+}
+
+void RecoveryComponentBubbleView::ButtonPressed(
+ views::Button* sender, const ui::Event& event) {
+ if (event.IsMouseEvent() &&
+ !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) {
+ return;
+ }
+ HandleButtonPressed(sender);
+}
+
+void RecoveryComponentBubbleView::HandleButtonPressed(views::Button* sender) {
+ if (sender == accept_button_ || sender == decline_button_) {
+ const bool elevation_agreed = (sender == accept_button_);
+ component_updater::StartElevatedRecoveryProcess(
+ g_browser_process->local_state(),
+ elevation_agreed,
+ base::Bind(&UpgradeDetector::CheckForUpgrade,
+ base::Unretained(UpgradeDetector::GetInstance())));
+ content::RecordAction(base::UserMetricsAction(
+ elevation_agreed ? "RecoveryComponentBubble.ElevationAgreed"
+ : "RecoveryComponentBubble.ElevationDeclined"));
+ } else {
+ content::RecordAction(base::UserMetricsAction(
+ "RecoveryComponentBubble.Ignored"));
+ }
+ GetWidget()->Close();
+}
« no previous file with comments | « chrome/browser/ui/views/recovery_component_bubble_view.h ('k') | chrome/browser/ui/views/toolbar/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698