| 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/extensions/extension_uninstall_dialog.h" | 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 false, base::ASCIIToUTF16(kExtensionRemovedError)); | 119 false, base::ASCIIToUTF16(kExtensionRemovedError)); |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 SetIcon(image); | 123 SetIcon(image); |
| 124 | 124 |
| 125 switch (ScopedTestDialogAutoConfirm::GetAutoConfirmValue()) { | 125 switch (ScopedTestDialogAutoConfirm::GetAutoConfirmValue()) { |
| 126 case ScopedTestDialogAutoConfirm::NONE: | 126 case ScopedTestDialogAutoConfirm::NONE: |
| 127 Show(); | 127 Show(); |
| 128 break; | 128 break; |
| 129 case ScopedTestDialogAutoConfirm::ACCEPT_AND_OPTION: |
| 130 OnDialogClosed(CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE); |
| 131 break; |
| 129 case ScopedTestDialogAutoConfirm::ACCEPT: | 132 case ScopedTestDialogAutoConfirm::ACCEPT: |
| 130 OnDialogClosed(CLOSE_ACTION_UNINSTALL); | 133 OnDialogClosed(CLOSE_ACTION_UNINSTALL); |
| 131 break; | 134 break; |
| 132 case ScopedTestDialogAutoConfirm::CANCEL: | 135 case ScopedTestDialogAutoConfirm::CANCEL: |
| 133 OnDialogClosed(CLOSE_ACTION_CANCELED); | 136 OnDialogClosed(CLOSE_ACTION_CANCELED); |
| 134 break; | 137 break; |
| 135 } | 138 } |
| 136 } | 139 } |
| 137 | 140 |
| 138 std::string ExtensionUninstallDialog::GetHeadingText() { | 141 std::string ExtensionUninstallDialog::GetHeadingText() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 156 if (ShouldShowReportAbuseCheckbox()) { | 159 if (ShouldShowReportAbuseCheckbox()) { |
| 157 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallDialogAction", | 160 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallDialogAction", |
| 158 action, | 161 action, |
| 159 CLOSE_ACTION_LAST); | 162 CLOSE_ACTION_LAST); |
| 160 } | 163 } |
| 161 | 164 |
| 162 bool success = false; | 165 bool success = false; |
| 163 base::string16 error; | 166 base::string16 error; |
| 164 switch (action) { | 167 switch (action) { |
| 165 case CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE: | 168 case CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE: |
| 169 // If the extension specifies a custom uninstall page via |
| 170 // chrome.runtime.setUninstallURL, then at uninstallation its uninstall |
| 171 // page opens. To ensure that the CWS Report Abuse page is the active tab |
| 172 // at uninstallation, HandleReportAbuse() is called after Uninstall(). |
| 173 Uninstall(&success, &error); |
| 166 HandleReportAbuse(); | 174 HandleReportAbuse(); |
| 167 // Fall through. | 175 break; |
| 168 case CLOSE_ACTION_UNINSTALL: { | 176 case CLOSE_ACTION_UNINSTALL: { |
| 169 const Extension* current_extension = | 177 Uninstall(&success, &error); |
| 170 ExtensionRegistry::Get(profile_)->GetExtensionById( | |
| 171 extension_->id(), ExtensionRegistry::EVERYTHING); | |
| 172 if (current_extension) { | |
| 173 success = | |
| 174 ExtensionSystem::Get(profile_) | |
| 175 ->extension_service() | |
| 176 ->UninstallExtension(extension_->id(), uninstall_reason_, | |
| 177 base::Bind(&base::DoNothing), &error); | |
| 178 } else { | |
| 179 error = base::ASCIIToUTF16(kExtensionRemovedError); | |
| 180 } | |
| 181 break; | 178 break; |
| 182 } | 179 } |
| 183 case CLOSE_ACTION_CANCELED: | 180 case CLOSE_ACTION_CANCELED: |
| 184 error = base::ASCIIToUTF16("User canceled uninstall dialog"); | 181 error = base::ASCIIToUTF16("User canceled uninstall dialog"); |
| 185 break; | 182 break; |
| 186 case CLOSE_ACTION_LAST: | 183 case CLOSE_ACTION_LAST: |
| 187 NOTREACHED(); | 184 NOTREACHED(); |
| 188 } | 185 } |
| 186 delegate_->OnExtensionUninstallDialogClosed(success, error); |
| 187 } |
| 189 | 188 |
| 190 delegate_->OnExtensionUninstallDialogClosed(success, error); | 189 void ExtensionUninstallDialog::Uninstall(bool* success, base::string16* error) { |
| 190 const Extension* current_extension = |
| 191 ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 192 extension_->id(), ExtensionRegistry::EVERYTHING); |
| 193 if (current_extension) { |
| 194 *success = |
| 195 ExtensionSystem::Get(profile_)->extension_service()->UninstallExtension( |
| 196 extension_->id(), uninstall_reason_, base::Bind(&base::DoNothing), |
| 197 error); |
| 198 } else { |
| 199 *error = base::ASCIIToUTF16(kExtensionRemovedError); |
| 200 } |
| 191 } | 201 } |
| 192 | 202 |
| 193 void ExtensionUninstallDialog::HandleReportAbuse() { | 203 void ExtensionUninstallDialog::HandleReportAbuse() { |
| 194 chrome::NavigateParams params( | 204 chrome::NavigateParams params( |
| 195 profile_, | 205 profile_, |
| 196 extension_urls::GetWebstoreReportAbuseUrl(extension_->id(), kReferrerId), | 206 extension_urls::GetWebstoreReportAbuseUrl(extension_->id(), kReferrerId), |
| 197 ui::PAGE_TRANSITION_LINK); | 207 ui::PAGE_TRANSITION_LINK); |
| 198 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 208 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 199 chrome::Navigate(¶ms); | 209 chrome::Navigate(¶ms); |
| 200 } | 210 } |
| 201 | 211 |
| 202 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |