Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/show_permissions_dialog_helper.cc |
| diff --git a/chrome/browser/extensions/api/developer_private/show_permissions_dialog_helper.cc b/chrome/browser/extensions/api/developer_private/show_permissions_dialog_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..50bfaafe81cfe97866ef8b7e243a126252dbbd71 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/developer_private/show_permissions_dialog_helper.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/developer_private/show_permissions_dialog_helper.h" |
| + |
| +#include "apps/app_load_service.h" |
| +#include "apps/saved_files_service.h" |
| +#include "base/metrics/histogram.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/apps/app_info_dialog.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "extensions/browser/api/device_permissions_manager.h" |
| +#include "extensions/browser/extension_registry.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/permissions/permissions_data.h" |
| + |
| +namespace extensions { |
| + |
| +ShowPermissionsDialogHelper::ShowPermissionsDialogHelper() : profile_(nullptr) { |
| +} |
| + |
| +ShowPermissionsDialogHelper::~ShowPermissionsDialogHelper() { |
| +} |
| + |
| +void ShowPermissionsDialogHelper::Show(content::WebContents* web_contents, |
| + content::BrowserContext* browser_context, |
| + const Extension* extension, |
| + bool from_extensions_page, |
| + const base::Closure& on_complete) { |
| + profile_ = Profile::FromBrowserContext(browser_context); |
| + extension_id_ = extension->id(); |
| + on_complete_callback_ = on_complete; |
| + |
| + // Show the new-style extensions dialog when it is available. It is currently |
| + // unavailable by default on Mac. |
| + if (CanShowAppInfoDialog()) { |
| + if (from_extensions_page) { |
| + UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches", |
| + AppInfoLaunchSource::FROM_EXTENSIONS_PAGE, |
| + AppInfoLaunchSource::NUM_LAUNCH_SOURCES); |
| + } |
| + |
| + // The Unretained() is safe here because this object's parent should never |
| + // go away before a response. |
| + ShowAppInfoInNativeDialog( |
| + web_contents->GetTopLevelNativeWindow(), |
| + GetAppInfoNativeDialogSize(), |
| + profile_, |
| + extension, |
| + base::Bind(&ShowPermissionsDialogHelper::AppInfoDialogClosed, |
| + base::Unretained(this))); |
|
not at google - send to devlin
2015/03/13 23:52:31
Would it be too neat to just pass |on_complete| in
Devlin
2015/03/16 16:42:17
Nope, just neat enough. :) Done.
|
| + } else { |
| + prompt_.reset(new ExtensionInstallPrompt(web_contents)); |
| + std::vector<base::FilePath> retained_file_paths; |
| + if (extension->permissions_data()->HasAPIPermission( |
| + APIPermission::kFileSystem)) { |
| + std::vector<apps::SavedFileEntry> retained_file_entries = |
| + apps::SavedFilesService::Get(profile_) |
| + ->GetAllFileEntries(extension_id_); |
| + for (const apps::SavedFileEntry& entry : retained_file_entries) |
| + retained_file_paths.push_back(entry.path); |
| + } |
| + std::vector<base::string16> retained_device_messages; |
| + if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) { |
| + retained_device_messages = |
| + DevicePermissionsManager::Get(profile_) |
| + ->GetPermissionMessageStrings(extension_id_); |
| + } |
| + prompt_->ReviewPermissions( |
| + this, extension, retained_file_paths, retained_device_messages); |
| + } |
| +} |
| + |
| +// This is called when the user clicks "Revoke File Access." |
| +void ShowPermissionsDialogHelper::InstallUIProceed() { |
| + const Extension* extension = |
| + ExtensionRegistry::Get(profile_)->GetExtensionById( |
| + extension_id_, ExtensionRegistry::EVERYTHING); |
| + |
| + if (extension) |
| + apps::SavedFilesService::Get(profile_)->ClearQueue(extension); |
| + apps::AppLoadService::Get(profile_) |
| + ->RestartApplicationIfRunning(extension_id_); |
| + |
| + on_complete_callback_.Run(); |
| +} |
| + |
| +void ShowPermissionsDialogHelper::InstallUIAbort(bool user_initiated) { |
| + on_complete_callback_.Run(); |
| +} |
| + |
| +void ShowPermissionsDialogHelper::AppInfoDialogClosed() { |
| + on_complete_callback_.Run(); |
| +} |
| + |
| +} // namespace extensions |