Chromium Code Reviews| 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/controls/button/image_button.h" | 44 #include "ui/views/controls/button/image_button.h" |
| 45 #include "ui/views/controls/image_view.h" | 45 #include "ui/views/controls/image_view.h" |
| 46 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
| 47 #include "ui/views/controls/link.h" | 47 #include "ui/views/controls/link.h" |
| 48 #include "ui/views/controls/scroll_view.h" | 48 #include "ui/views/controls/scroll_view.h" |
| 49 #include "ui/views/controls/separator.h" | 49 #include "ui/views/controls/separator.h" |
| 50 #include "ui/views/layout/box_layout.h" | 50 #include "ui/views/layout/box_layout.h" |
| 51 #include "ui/views/layout/grid_layout.h" | 51 #include "ui/views/layout/grid_layout.h" |
| 52 #include "ui/views/layout/layout_constants.h" | 52 #include "ui/views/layout/layout_constants.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 const int kBulletWidth = 20; | 63 const int kBulletWidth = 20; |
| 63 | 64 |
| 64 // Size of extension icon in top left of dialog. | 65 // Size of extension icon in top left of dialog. |
| 65 const int kIconSize = 64; | 66 const int kIconSize = 64; |
| 66 | 67 |
| 67 // The maximum height of the scroll view before it will show a scrollbar. | 68 // The maximum height of the scroll view before it will show a scrollbar. |
| 68 const int kScrollViewMaxHeight = 250; | 69 const int kScrollViewMaxHeight = 250; |
| 69 | 70 |
| 70 // Width of the left column of the dialog when the extension requests | 71 // Width of the left column of the dialog when the extension requests |
| 71 // permissions. | 72 // permissions. |
| 72 const int kPermissionsLeftColumnWidth = 250; | 73 const int kPermissionsLeftColumnWidth = 250; |
| 73 | 74 |
| 74 // Width of the left column of the dialog when the extension requests no | 75 // Width of the left column of the dialog when the extension requests no |
| 75 // permissions. | 76 // permissions. |
| 76 const int kNoPermissionsLeftColumnWidth = 200; | 77 const int kNoPermissionsLeftColumnWidth = 200; |
| 77 | 78 |
| 78 // Width of the left column for external install prompts. The text is long in | 79 // Width of the left column for external install prompts. The text is long in |
| 79 // this case, so make it wider than normal. | 80 // this case, so make it wider than normal. |
| 80 const int kExternalInstallLeftColumnWidth = 350; | 81 const int kExternalInstallLeftColumnWidth = 350; |
| 81 | 82 |
| 83 // Time delay to enable the install button after initial display. | |
| 84 int g_install_delay_in_ms = 500; | |
| 85 | |
| 82 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { | 86 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { |
| 83 views::View* parent = static_cast<views::View*>(data); | 87 views::View* parent = static_cast<views::View*>(data); |
| 84 views::ImageView* image_view = new views::ImageView(); | 88 views::ImageView* image_view = new views::ImageView(); |
| 85 image_view->SetImage(*skia_image); | 89 image_view->SetImage(*skia_image); |
| 86 parent->AddChildView(image_view); | 90 parent->AddChildView(image_view); |
| 87 } | 91 } |
| 88 | 92 |
| 89 // Creates a string for displaying |message| to the user. If it has to look | 93 // Creates a string for displaying |message| to the user. If it has to look |
| 90 // like a entry in a bullet point list, one is added. | 94 // like a entry in a bullet point list, one is added. |
| 91 base::string16 PrepareForDisplay(const base::string16& message, | 95 base::string16 PrepareForDisplay(const base::string16& message, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 const ExtensionInstallPrompt::DoneCallback& done_callback, | 169 const ExtensionInstallPrompt::DoneCallback& done_callback, |
| 166 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) | 170 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) |
| 167 : profile_(profile), | 171 : profile_(profile), |
| 168 navigator_(navigator), | 172 navigator_(navigator), |
| 169 done_callback_(done_callback), | 173 done_callback_(done_callback), |
| 170 prompt_(std::move(prompt)), | 174 prompt_(std::move(prompt)), |
| 171 container_(NULL), | 175 container_(NULL), |
| 172 scroll_view_(NULL), | 176 scroll_view_(NULL), |
| 173 handled_result_(false) { | 177 handled_result_(false) { |
| 174 InitView(); | 178 InitView(); |
| 179 StartTimerToEnableInstall(); | |
|
Devlin
2017/03/23 01:25:30
Here, too, just because the dialog is constructed
Ackerman
2017/03/31 22:03:22
Done.
| |
| 175 } | 180 } |
| 176 | 181 |
| 177 ExtensionInstallDialogView::~ExtensionInstallDialogView() { | 182 ExtensionInstallDialogView::~ExtensionInstallDialogView() { |
| 178 if (!handled_result_ && !done_callback_.is_null()) { | 183 if (!handled_result_ && !done_callback_.is_null()) { |
| 179 base::ResetAndReturn(&done_callback_) | 184 base::ResetAndReturn(&done_callback_) |
| 180 .Run(ExtensionInstallPrompt::Result::USER_CANCELED); | 185 .Run(ExtensionInstallPrompt::Result::USER_CANCELED); |
| 181 } | 186 } |
| 182 } | 187 } |
| 183 | 188 |
| 184 void ExtensionInstallDialogView::InitView() { | 189 void ExtensionInstallDialogView::InitView() { |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 views::View* ExtensionInstallDialogView::CreateExtraView() { | 566 views::View* ExtensionInstallDialogView::CreateExtraView() { |
| 562 if (!prompt_->has_webstore_data()) | 567 if (!prompt_->has_webstore_data()) |
| 563 return nullptr; | 568 return nullptr; |
| 564 | 569 |
| 565 views::Link* store_link = new views::Link( | 570 views::Link* store_link = new views::Link( |
| 566 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); | 571 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); |
| 567 store_link->set_listener(this); | 572 store_link->set_listener(this); |
| 568 return store_link; | 573 return store_link; |
| 569 } | 574 } |
| 570 | 575 |
| 576 bool ExtensionInstallDialogView::IsDialogButtonEnabled( | |
| 577 ui::DialogButton button) const { | |
| 578 if (button == ui::DIALOG_BUTTON_OK) | |
| 579 return install_enabled_; | |
| 580 return true; | |
| 581 } | |
| 582 | |
| 583 void ExtensionInstallDialogView::StartTimerToEnableInstall() { | |
| 584 timer_.Start(FROM_HERE, | |
|
Devlin
2017/03/23 01:25:30
Here too, let's just inline this at the call site.
Ackerman
2017/03/31 22:03:21
Done.
| |
| 585 base::TimeDelta::FromMilliseconds(g_install_delay_in_ms), | |
| 586 base::Bind(&ExtensionInstallDialogView::EnableInstall, | |
| 587 base::Unretained(this))); | |
| 588 } | |
| 589 | |
| 590 void ExtensionInstallDialogView::SetInstallDelayForTesting(int delay_in_ms) { | |
| 591 g_install_delay_in_ms = delay_in_ms; | |
| 592 } | |
| 593 | |
| 594 void ExtensionInstallDialogView::EnableInstall() { | |
| 595 install_enabled_ = true; | |
| 596 GetDialogClientView()->UpdateDialogButtons(); | |
| 597 } | |
| 598 | |
| 571 void ExtensionInstallDialogView::UpdateInstallResultHistogram(bool accepted) | 599 void ExtensionInstallDialogView::UpdateInstallResultHistogram(bool accepted) |
| 572 const { | 600 const { |
| 573 if (prompt_->type() == ExtensionInstallPrompt::INSTALL_PROMPT) | 601 if (prompt_->type() == ExtensionInstallPrompt::INSTALL_PROMPT) |
| 574 UMA_HISTOGRAM_BOOLEAN("Extensions.InstallPrompt.Accepted", accepted); | 602 UMA_HISTOGRAM_BOOLEAN("Extensions.InstallPrompt.Accepted", accepted); |
| 575 } | 603 } |
| 576 | 604 |
| 577 // ExpandableContainerView::DetailsView ---------------------------------------- | 605 // ExpandableContainerView::DetailsView ---------------------------------------- |
| 578 | 606 |
| 579 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, | 607 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, |
| 580 bool parent_bulleted) | 608 bool parent_bulleted) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 gfx::ImageSkia icon = gfx::CreateVectorIcon( | 768 gfx::ImageSkia icon = gfx::CreateVectorIcon( |
| 741 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); | 769 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); |
| 742 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); | 770 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); |
| 743 } | 771 } |
| 744 | 772 |
| 745 // static | 773 // static |
| 746 ExtensionInstallPrompt::ShowDialogCallback | 774 ExtensionInstallPrompt::ShowDialogCallback |
| 747 ExtensionInstallPrompt::GetViewsShowDialogCallback() { | 775 ExtensionInstallPrompt::GetViewsShowDialogCallback() { |
| 748 return base::Bind(&ShowExtensionInstallDialogImpl); | 776 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 749 } | 777 } |
| OLD | NEW |