| Index: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc
|
| diff --git a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc
|
| old mode 100644
|
| new mode 100755
|
| index 5f2148770cdc5f55840a4f769489da4c6b2ca8ce..87f621d68b1e5f724d4470e5f87fbc7c9702bd09
|
| --- a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc
|
| +++ b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc
|
| @@ -26,135 +26,219 @@ namespace {
|
| const int kRightColumnWidth = 210;
|
| const int kIconSize = 69;
|
|
|
| -class ExtensionUninstallDialogView : public views::DialogDelegateView {
|
| +class ExtensionUninstallDialogDelegateView;
|
| +
|
| +// The ExtensionUninstallDialog implementation for the views framework. This
|
| +// connects the ExtensionUninstallUI::Delegate to the actual widget, reconciling
|
| +// the two life cycles.
|
| +class ExtensionUninstallDialogViews : public ExtensionUninstallDialog {
|
| public:
|
| - ExtensionUninstallDialogView(ExtensionUninstallDialog::Delegate* delegate,
|
| - const Extension* extension,
|
| - SkBitmap* icon)
|
| - : delegate_(delegate),
|
| - icon_(NULL) {
|
| - // Scale down to icon size, but allow smaller icons (don't scale up).
|
| - gfx::Size size(icon->width(), icon->height());
|
| - if (size.width() > kIconSize || size.height() > kIconSize)
|
| - size = gfx::Size(kIconSize, kIconSize);
|
| - icon_ = new views::ImageView();
|
| - icon_->SetImageSize(size);
|
| - icon_->SetImage(*icon);
|
| - AddChildView(icon_);
|
| -
|
| - heading_ = new views::Label(UTF16ToWide(
|
| - l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
|
| - UTF8ToUTF16(extension->name()))));
|
| - heading_->SetMultiLine(true);
|
| - heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
|
| - AddChildView(heading_);
|
| - }
|
| + ExtensionUninstallDialogViews(Profile* profile,
|
| + ExtensionUninstallUI::Delegate* delegate,
|
| + const Extension* extension,
|
| + SkBitmap* icon);
|
| + virtual ~ExtensionUninstallDialogViews();
|
| +
|
| + // Forwards the accept and cancels to the delegate.
|
| + void ExtensionUninstallAccepted();
|
| + void ExtensionUninstallCanceled();
|
| +
|
| + ExtensionUninstallDialogDelegateView* view() { return view_; }
|
| +
|
| + private:
|
| + ExtensionUninstallUI::Delegate* delegate_;
|
| + ExtensionUninstallDialogDelegateView* view_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
|
| +};
|
| +
|
| +// This class display the uninstall widget and is owned by the views framework.
|
| +class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
|
| + public:
|
| + ExtensionUninstallDialogDelegateView(
|
| + ExtensionUninstallDialogViews* dialog_view,
|
| + const Extension* extension,
|
| + SkBitmap* icon);
|
| + virtual ~ExtensionUninstallDialogDelegateView();
|
| +
|
| + // Called when the dialog and delegate have been destroyed to make sure
|
| + // that we don't callback to an invalid pointer.
|
| + void DialogDestroyed() { dialog_ = NULL; }
|
|
|
| private:
|
| + ExtensionUninstallDialogViews* dialog_;
|
| +
|
| // views::DialogDelegate:
|
| virtual std::wstring GetDialogButtonLabel(
|
| - MessageBoxFlags::DialogButton button) const OVERRIDE {
|
| - switch (button) {
|
| - case MessageBoxFlags::DIALOGBUTTON_OK:
|
| - return UTF16ToWide(
|
| - l10n_util::GetStringUTF16(
|
| - IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
|
| - case MessageBoxFlags::DIALOGBUTTON_CANCEL:
|
| - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
|
| - default:
|
| - NOTREACHED();
|
| - return L"";
|
| - }
|
| - }
|
| + MessageBoxFlags::DialogButton button) const OVERRIDE;
|
|
|
| virtual int GetDefaultDialogButton() const OVERRIDE {
|
| return MessageBoxFlags::DIALOGBUTTON_CANCEL;
|
| }
|
|
|
| - virtual bool Accept() OVERRIDE {
|
| - delegate_->ExtensionDialogAccepted();
|
| - return true;
|
| - }
|
| -
|
| - virtual bool Cancel() OVERRIDE {
|
| - delegate_->ExtensionDialogCanceled();
|
| - return true;
|
| - }
|
| + virtual bool Accept() OVERRIDE;
|
| + virtual bool Cancel() OVERRIDE;
|
|
|
| // views::WindowDelegate:
|
| virtual bool IsModal() const OVERRIDE { return true; }
|
| - virtual std::wstring GetWindowTitle() const OVERRIDE {
|
| - return UTF16ToWide(
|
| - l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE));
|
| - }
|
| virtual views::View* GetContentsView() { return this; }
|
| + virtual std::wstring GetWindowTitle() const OVERRIDE;
|
|
|
| // views::View:
|
| - virtual gfx::Size GetPreferredSize() OVERRIDE {
|
| - int width = kRightColumnWidth;
|
| - width += kIconSize;
|
| - width += views::kPanelHorizMargin * 3;
|
| + virtual gfx::Size GetPreferredSize() OVERRIDE;
|
| +
|
| + virtual void Layout() OVERRIDE;
|
| +
|
| + views::ImageView* icon_;
|
| + views::Label* heading_;
|
|
|
| - int height = views::kPanelVertMargin * 2;
|
| - height += heading_->GetHeightForWidth(kRightColumnWidth);
|
| + DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
|
| +};
|
|
|
| - return gfx::Size(width,
|
| - std::max(height, kIconSize + views::kPanelVertMargin * 2));
|
| +ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
|
| + Profile* profile,
|
| + ExtensionUninstallUI::Delegate* delegate,
|
| + const Extension* extension,
|
| + SkBitmap* icon)
|
| + : delegate_(delegate),
|
| + ExtensionUninstallDialog(profile, delegate, extension, icon) {
|
| + view_ = new ExtensionUninstallDialogDelegateView(this, extension, icon);
|
| +}
|
| +
|
| +ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
|
| + // Close the widget. The views framework will delete views_.
|
| + if (view_) {
|
| + view_->DialogDestroyed();
|
| + view_->GetWidget()->CloseNow();
|
| }
|
| +}
|
| +
|
| +void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
|
| + // The widget gets destroyed when the dialog is accepted.
|
| + view_ = NULL;
|
|
|
| - virtual void Layout() OVERRIDE {
|
| - int x = views::kPanelHorizMargin;
|
| - int y = views::kPanelVertMargin;
|
| -
|
| - heading_->SizeToFit(kRightColumnWidth);
|
| -
|
| - if (heading_->height() <= kIconSize) {
|
| - icon_->SetBounds(x, y, kIconSize, kIconSize);
|
| - x += kIconSize;
|
| - x += views::kPanelHorizMargin;
|
| -
|
| - heading_->SetX(x);
|
| - heading_->SetY(y + (kIconSize - heading_->height()) / 2);
|
| - } else {
|
| - icon_->SetBounds(x,
|
| - y + (heading_->height() - kIconSize) / 2,
|
| - kIconSize,
|
| - kIconSize);
|
| - x += kIconSize;
|
| - x += views::kPanelHorizMargin;
|
| -
|
| - heading_->SetX(x);
|
| - heading_->SetY(y);
|
| - }
|
| + delegate_->ExtensionUninstallAccepted();
|
| +}
|
| +
|
| +void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
|
| + // The widget gets destroyed when the dialog is canceled.
|
| + view_ = NULL;
|
| +
|
| + delegate_->ExtensionUninstallCanceled();
|
| +}
|
| +
|
| +ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
|
| + ExtensionUninstallDialogViews* dialog_view,
|
| + const Extension* extension,
|
| + SkBitmap* icon)
|
| + : dialog_(dialog_view) {
|
| + // Scale down to icon size, but allow smaller icons (don't scale up).
|
| + gfx::Size size(icon->width(), icon->height());
|
| + if (size.width() > kIconSize || size.height() > kIconSize)
|
| + size = gfx::Size(kIconSize, kIconSize);
|
| + icon_ = new views::ImageView();
|
| + icon_->SetImageSize(size);
|
| + icon_->SetImage(*icon);
|
| + AddChildView(icon_);
|
| +
|
| + heading_ = new views::Label(UTF16ToWide(
|
| + l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
|
| + UTF8ToUTF16(extension->name()))));
|
| + heading_->SetMultiLine(true);
|
| + AddChildView(heading_);
|
| +}
|
| +
|
| +ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
|
| +}
|
| +
|
| +std::wstring ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
|
| + MessageBoxFlags::DialogButton button) const {
|
| + switch (button) {
|
| + case MessageBoxFlags::DIALOGBUTTON_OK:
|
| + return UTF16ToWide(
|
| + l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
|
| + case MessageBoxFlags::DIALOGBUTTON_CANCEL:
|
| + return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
|
| + default:
|
| + NOTREACHED();
|
| + return L"";
|
| }
|
| +}
|
|
|
| - ExtensionUninstallDialog::Delegate* delegate_;
|
| - views::ImageView* icon_;
|
| - views::Label* heading_;
|
| +bool ExtensionUninstallDialogDelegateView::Accept() {
|
| + if (dialog_)
|
| + dialog_->ExtensionUninstallAccepted();
|
| + return true;
|
| +}
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogView);
|
| -};
|
| +bool ExtensionUninstallDialogDelegateView::Cancel() {
|
| + if (dialog_)
|
| + dialog_->ExtensionUninstallCanceled();
|
| + return true;
|
| +}
|
| +
|
| +std::wstring ExtensionUninstallDialogDelegateView::GetWindowTitle() const {
|
| + return UTF16ToWide(
|
| + l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE));
|
| +}
|
| +
|
| +
|
| +gfx::Size ExtensionUninstallDialogDelegateView::GetPreferredSize() {
|
| + int width = kRightColumnWidth;
|
| + width += kIconSize;
|
| + width += views::kPanelHorizMargin * 3;
|
| +
|
| + int height = views::kPanelVertMargin * 2;
|
| + height += heading_->GetHeightForWidth(kRightColumnWidth);
|
| +
|
| + return gfx::Size(width,
|
| + std::max(height, kIconSize + views::kPanelVertMargin * 2));
|
| +}
|
| +
|
| +void ExtensionUninstallDialogDelegateView::Layout() {
|
| + int x = views::kPanelHorizMargin;
|
| + int y = views::kPanelVertMargin;
|
| +
|
| + heading_->SizeToFit(kRightColumnWidth);
|
| +
|
| + if (heading_->height() <= kIconSize) {
|
| + icon_->SetBounds(x, y, kIconSize, kIconSize);
|
| + x += kIconSize;
|
| + x += views::kPanelHorizMargin;
|
| +
|
| + heading_->SetX(x);
|
| + heading_->SetY(y + (kIconSize - heading_->height()) / 2);
|
| + } else {
|
| + icon_->SetBounds(x,
|
| + y + (heading_->height() - kIconSize) / 2,
|
| + kIconSize,
|
| + kIconSize);
|
| + x += kIconSize;
|
| + x += views::kPanelHorizMargin;
|
| +
|
| + heading_->SetX(x);
|
| + heading_->SetY(y);
|
| + }
|
| +}
|
|
|
| } // namespace
|
|
|
| // static
|
| -void ExtensionUninstallDialog::Show(
|
| - Profile* profile,
|
| - ExtensionUninstallDialog::Delegate* delegate,
|
| - const Extension* extension,
|
| - SkBitmap* icon) {
|
| - Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
|
| +void ExtensionUninstallUI::ShowDialog() {
|
| + Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
|
| if (!browser) {
|
| - delegate->ExtensionDialogCanceled();
|
| + delegate_->ExtensionUninstallCanceled();
|
| return;
|
| }
|
|
|
| BrowserWindow* window = browser->window();
|
| if (!window) {
|
| - delegate->ExtensionDialogCanceled();
|
| + delegate_->ExtensionUninstallCanceled();
|
| return;
|
| }
|
|
|
| - browser::CreateViewsWindow(window->GetNativeHandle(),
|
| - new ExtensionUninstallDialogView(delegate, extension, icon))->Show();
|
| + ExtensionUninstallDialogViews* dialog = new ExtensionUninstallDialogViews(
|
| + profile_, delegate_, extension_, &icon_);
|
| + browser::CreateViewsWindow(window->GetNativeHandle(), dialog->view())->Show();
|
| + uninstall_dialog_.reset(dialog);
|
| }
|
|
|