Commit f3af70d5 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Add support for reporting abuse on extension uninstallation

Add capability for having a "Report abuse" checkbox on the extension uninstall
dialog. Currently, don't show this until we have the field trial specifications
worked out.

BUG=441377

Review URL: https://codereview.chromium.org/1010953002

Cr-Commit-Position: refs/heads/master@{#321512}
parent 2a83ad3c
......@@ -5237,6 +5237,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON" desc="Text for the uninstall button on the extension uninstall prompt">
Remove
</message>
<message name="IDS_EXTENSION_PROMPT_UNINSTALL_REPORT_ABUSE" desc="Message to indicate the user can report abuse for the extension about to be uninstalled.">
Report abuse
</message>
<message name="IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON" desc="Text for the enable button on the extension re-enable prompt">
Re-enable
</message>
......
......@@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/grit/generated_resources.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/image_loader.h"
......@@ -17,8 +18,11 @@
#include "extensions/common/extension.h"
#include "extensions/common/extension_icon_set.h"
#include "extensions/common/extension_resource.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
......@@ -123,4 +127,19 @@ std::string ExtensionUninstallDialog::GetHeadingText() {
base::UTF8ToUTF16(extension_->name()));
}
bool ExtensionUninstallDialog::ShouldShowReportAbuseCheckbox() const {
// TODO(devlin): Add a field trial for reporting abuse on uninstallation.
// See crbug.com/441377.
return false;
}
void ExtensionUninstallDialog::HandleReportAbuse() {
chrome::NavigateParams params(
profile_,
extension_urls::GetWebstoreReportAbuseUrl(extension_->id()),
ui::PAGE_TRANSITION_LINK);
params.disposition = NEW_FOREGROUND_TAB;
chrome::Navigate(&params);
}
} // namespace extensions
......@@ -61,10 +61,17 @@ class ExtensionUninstallDialog
std::string GetHeadingText();
// Returns true if a checkbox for reporting abuse should be shown.
bool ShouldShowReportAbuseCheckbox() const;
protected:
// Constructor used by the derived classes.
ExtensionUninstallDialog(Profile* profile, Delegate* delegate);
// Handles the "report abuse" checkbox being checked at the close of the
// dialog.
void HandleReportAbuse();
// TODO(sashab): Remove protected members: crbug.com/397395
Profile* const profile_;
......
......@@ -8,7 +8,8 @@
#include <string>
#include "base/strings/sys_string_conversions.h"
#import "base/mac/scoped_nsobject.h"
#import "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/grit/generated_resources.h"
#include "extensions/common/extension.h"
......@@ -57,10 +58,23 @@ void ExtensionUninstallDialogCocoa::Show() {
[alert setAlertStyle:NSWarningAlertStyle];
[alert setIcon:gfx::NSImageFromImageSkia(icon_)];
if ([alert runModal] == NSAlertFirstButtonReturn)
base::scoped_nsobject<NSButton> reportAbuseCheckbox;
if (ShouldShowReportAbuseCheckbox()) {
reportAbuseCheckbox.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
[reportAbuseCheckbox setButtonType:NSSwitchButton];
[reportAbuseCheckbox setTitle:l10n_util::GetNSString(
IDS_EXTENSION_PROMPT_UNINSTALL_REPORT_ABUSE)];
[reportAbuseCheckbox sizeToFit];
[alert setAccessoryView:reportAbuseCheckbox];
}
if ([alert runModal] == NSAlertFirstButtonReturn) {
if (reportAbuseCheckbox.get() && [reportAbuseCheckbox state] == NSOnState)
HandleReportAbuse();
delegate_->ExtensionUninstallAccepted();
else
} else {
delegate_->ExtensionUninstallCanceled();
}
}
} // namespace
......
......@@ -17,6 +17,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/layout_constants.h"
......@@ -46,7 +47,7 @@ class ExtensionUninstallDialogViews
void DialogDelegateDestroyed() { view_ = NULL; }
// Forwards the accept and cancels to the delegate.
void ExtensionUninstallAccepted();
void ExtensionUninstallAccepted(bool handle_report_abuse);
void ExtensionUninstallCanceled();
private:
......@@ -79,6 +80,7 @@ class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
private:
// views::DialogDelegate:
views::View* CreateExtraView() override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
int GetDefaultDialogButton() const override {
// Default to accept when triggered via chrome://extensions page.
......@@ -102,6 +104,7 @@ class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
views::ImageView* icon_;
views::Label* heading_;
bool triggered_by_extension_;
views::Checkbox* report_abuse_checkbox_;
DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
};
......@@ -136,10 +139,13 @@ void ExtensionUninstallDialogViews::Show() {
constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show();
}
void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
void ExtensionUninstallDialogViews::ExtensionUninstallAccepted(
bool report_abuse_checked) {
// The widget gets destroyed when the dialog is accepted.
view_->DialogDestroyed();
view_ = NULL;
if (report_abuse_checked)
HandleReportAbuse();
delegate_->ExtensionUninstallAccepted();
}
......@@ -156,7 +162,8 @@ ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
const extensions::Extension* triggering_extension,
gfx::ImageSkia* image)
: dialog_(dialog_view),
triggered_by_extension_(triggering_extension != NULL) {
triggered_by_extension_(triggering_extension != NULL),
report_abuse_checkbox_(nullptr) {
// Scale down to icon size, but allow smaller icons (don't scale up).
gfx::Size size(image->width(), image->height());
if (size.width() > kIconSize || size.height() > kIconSize)
......@@ -184,6 +191,14 @@ ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
dialog_->DialogDelegateDestroyed();
}
views::View* ExtensionUninstallDialogDelegateView::CreateExtraView() {
if (dialog_->ShouldShowReportAbuseCheckbox()) {
report_abuse_checkbox_ = new views::Checkbox(
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_REPORT_ABUSE));
}
return report_abuse_checkbox_;
}
base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
......@@ -191,8 +206,10 @@ base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
}
bool ExtensionUninstallDialogDelegateView::Accept() {
if (dialog_)
dialog_->ExtensionUninstallAccepted();
if (dialog_) {
dialog_->ExtensionUninstallAccepted(
report_abuse_checkbox_ && report_abuse_checkbox_->checked());
}
return true;
}
......
......@@ -72,6 +72,10 @@ GURL GetWebstoreUpdateUrl() {
return GURL(kChromeWebstoreUpdateURL);
}
GURL GetWebstoreReportAbuseUrl(const std::string& extension_id) {
return GURL(GetWebstoreLaunchURL() + "/report/" + extension_id);
}
bool IsWebstoreUpdateUrl(const GURL& update_url) {
GURL store_url = GetWebstoreUpdateUrl();
if (update_url == store_url) {
......
......@@ -70,6 +70,9 @@ GURL GetWebstoreSearchPageUrl(const std::string& query);
// have been overridden by a command line flag for testing purposes.
GURL GetWebstoreUpdateUrl();
// Returns the url to visit to report abuse for the given |extension_id|.
GURL GetWebstoreReportAbuseUrl(const std::string& extension_id);
// Returns whether the URL is the webstore update URL (just considering host
// and path, not scheme, query, etc.)
bool IsWebstoreUpdateUrl(const GURL& update_url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment