| 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/extension_install_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 45 #include "ui/views/controls/button/image_button.h" | 45 #include "ui/views/controls/button/image_button.h" |
| 46 #include "ui/views/controls/image_view.h" | 46 #include "ui/views/controls/image_view.h" |
| 47 #include "ui/views/controls/label.h" | 47 #include "ui/views/controls/label.h" |
| 48 #include "ui/views/controls/link.h" | 48 #include "ui/views/controls/link.h" |
| 49 #include "ui/views/controls/scroll_view.h" | 49 #include "ui/views/controls/scroll_view.h" |
| 50 #include "ui/views/controls/separator.h" | 50 #include "ui/views/controls/separator.h" |
| 51 #include "ui/views/layout/box_layout.h" | 51 #include "ui/views/layout/box_layout.h" |
| 52 #include "ui/views/layout/grid_layout.h" | 52 #include "ui/views/layout/grid_layout.h" |
| 53 #include "ui/views/widget/widget.h" | 53 #include "ui/views/widget/widget.h" |
| 54 #include "ui/views/window/dialog_client_view.h" |
| 54 | 55 |
| 55 using content::OpenURLParams; | 56 using content::OpenURLParams; |
| 56 using content::Referrer; | 57 using content::Referrer; |
| 57 using extensions::ExperienceSamplingEvent; | 58 using extensions::ExperienceSamplingEvent; |
| 58 | 59 |
| 59 namespace { | 60 namespace { |
| 60 | 61 |
| 61 // Width of the bullet column in BulletedView. | 62 // Width of the bullet column in BulletedView. |
| 62 constexpr int kBulletWidth = 20; | 63 constexpr int kBulletWidth = 20; |
| 63 | 64 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 83 // points. If the parent is using bullets for its items, then a padding of one | 84 // points. If the parent is using bullets for its items, then a padding of one |
| 84 // unit will make the child item (which has no bullet) look like a sibling of | 85 // unit will make the child item (which has no bullet) look like a sibling of |
| 85 // its parent. Therefore increase the indentation by one more unit to show that | 86 // its parent. Therefore increase the indentation by one more unit to show that |
| 86 // it is in fact a child item (with no missing bullet) and not a sibling. | 87 // it is in fact a child item (with no missing bullet) and not a sibling. |
| 87 int GetLeftPaddingForBulletedItems(bool parent_bulleted) { | 88 int GetLeftPaddingForBulletedItems(bool parent_bulleted) { |
| 88 return LayoutDelegate::Get()->GetMetric( | 89 return LayoutDelegate::Get()->GetMetric( |
| 89 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING) * | 90 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING) * |
| 90 (parent_bulleted ? 2 : 1); | 91 (parent_bulleted ? 2 : 1); |
| 91 } | 92 } |
| 92 | 93 |
| 94 // Time delay before the install button is enabled after initial display. |
| 95 int g_install_delay_in_ms = 500; |
| 96 |
| 93 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { | 97 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { |
| 94 views::View* parent = static_cast<views::View*>(data); | 98 views::View* parent = static_cast<views::View*>(data); |
| 95 views::ImageView* image_view = new views::ImageView(); | 99 views::ImageView* image_view = new views::ImageView(); |
| 96 image_view->SetImage(*skia_image); | 100 image_view->SetImage(*skia_image); |
| 97 parent->AddChildView(image_view); | 101 parent->AddChildView(image_view); |
| 98 } | 102 } |
| 99 | 103 |
| 100 // Creates a string for displaying |message| to the user. If it has to look | 104 // Creates a string for displaying |message| to the user. If it has to look |
| 101 // like a entry in a bullet point list, one is added. | 105 // like a entry in a bullet point list, one is added. |
| 102 base::string16 PrepareForDisplay(const base::string16& message, | 106 base::string16 PrepareForDisplay(const base::string16& message, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 Profile* profile, | 178 Profile* profile, |
| 175 content::PageNavigator* navigator, | 179 content::PageNavigator* navigator, |
| 176 const ExtensionInstallPrompt::DoneCallback& done_callback, | 180 const ExtensionInstallPrompt::DoneCallback& done_callback, |
| 177 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) | 181 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) |
| 178 : profile_(profile), | 182 : profile_(profile), |
| 179 navigator_(navigator), | 183 navigator_(navigator), |
| 180 done_callback_(done_callback), | 184 done_callback_(done_callback), |
| 181 prompt_(std::move(prompt)), | 185 prompt_(std::move(prompt)), |
| 182 container_(NULL), | 186 container_(NULL), |
| 183 scroll_view_(NULL), | 187 scroll_view_(NULL), |
| 184 handled_result_(false) { | 188 handled_result_(false), |
| 189 install_button_enabled_(false) { |
| 185 InitView(); | 190 InitView(); |
| 186 } | 191 } |
| 187 | 192 |
| 188 ExtensionInstallDialogView::~ExtensionInstallDialogView() { | 193 ExtensionInstallDialogView::~ExtensionInstallDialogView() { |
| 189 if (!handled_result_ && !done_callback_.is_null()) { | 194 if (!handled_result_ && !done_callback_.is_null()) { |
| 190 base::ResetAndReturn(&done_callback_) | 195 base::ResetAndReturn(&done_callback_) |
| 191 .Run(ExtensionInstallPrompt::Result::USER_CANCELED); | 196 .Run(ExtensionInstallPrompt::Result::USER_CANCELED); |
| 192 } | 197 } |
| 193 } | 198 } |
| 194 | 199 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 views::View* ExtensionInstallDialogView::CreateExtraView() { | 593 views::View* ExtensionInstallDialogView::CreateExtraView() { |
| 589 if (!prompt_->has_webstore_data()) | 594 if (!prompt_->has_webstore_data()) |
| 590 return nullptr; | 595 return nullptr; |
| 591 | 596 |
| 592 views::Link* store_link = new views::Link( | 597 views::Link* store_link = new views::Link( |
| 593 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); | 598 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); |
| 594 store_link->set_listener(this); | 599 store_link->set_listener(this); |
| 595 return store_link; | 600 return store_link; |
| 596 } | 601 } |
| 597 | 602 |
| 603 bool ExtensionInstallDialogView::IsDialogButtonEnabled( |
| 604 ui::DialogButton button) const { |
| 605 if (button == ui::DIALOG_BUTTON_OK) |
| 606 return install_button_enabled_; |
| 607 return true; |
| 608 } |
| 609 |
| 610 void ExtensionInstallDialogView::SetInstallButtonDelayForTesting( |
| 611 int delay_in_ms) { |
| 612 g_install_delay_in_ms = delay_in_ms; |
| 613 } |
| 614 |
| 615 void ExtensionInstallDialogView::VisibilityChanged(views::View* starting_from, |
| 616 bool is_visible) { |
| 617 if (is_visible && !install_button_enabled_) { |
| 618 // This base::Unretained is safe because the task is owned by the timer, |
| 619 // which is in turn owned by this object. |
| 620 timer_.Start(FROM_HERE, |
| 621 base::TimeDelta::FromMilliseconds(g_install_delay_in_ms), |
| 622 base::Bind(&ExtensionInstallDialogView::EnableInstallButton, |
| 623 base::Unretained(this))); |
| 624 } |
| 625 } |
| 626 |
| 627 void ExtensionInstallDialogView::EnableInstallButton() { |
| 628 install_button_enabled_ = true; |
| 629 GetDialogClientView()->UpdateDialogButtons(); |
| 630 } |
| 631 |
| 598 void ExtensionInstallDialogView::UpdateInstallResultHistogram(bool accepted) | 632 void ExtensionInstallDialogView::UpdateInstallResultHistogram(bool accepted) |
| 599 const { | 633 const { |
| 600 if (prompt_->type() == ExtensionInstallPrompt::INSTALL_PROMPT) | 634 if (prompt_->type() == ExtensionInstallPrompt::INSTALL_PROMPT) |
| 601 UMA_HISTOGRAM_BOOLEAN("Extensions.InstallPrompt.Accepted", accepted); | 635 UMA_HISTOGRAM_BOOLEAN("Extensions.InstallPrompt.Accepted", accepted); |
| 602 } | 636 } |
| 603 | 637 |
| 604 // ExpandableContainerView::DetailsView ---------------------------------------- | 638 // ExpandableContainerView::DetailsView ---------------------------------------- |
| 605 | 639 |
| 606 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, | 640 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, |
| 607 bool parent_bulleted) | 641 bool parent_bulleted) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 gfx::ImageSkia icon = gfx::CreateVectorIcon( | 790 gfx::ImageSkia icon = gfx::CreateVectorIcon( |
| 757 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); | 791 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); |
| 758 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); | 792 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); |
| 759 } | 793 } |
| 760 | 794 |
| 761 // static | 795 // static |
| 762 ExtensionInstallPrompt::ShowDialogCallback | 796 ExtensionInstallPrompt::ShowDialogCallback |
| 763 ExtensionInstallPrompt::GetViewsShowDialogCallback() { | 797 ExtensionInstallPrompt::GetViewsShowDialogCallback() { |
| 764 return base::Bind(&ShowExtensionInstallDialogImpl); | 798 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 765 } | 799 } |
| OLD | NEW |