Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / developer_private / show_permissions_dialog_helper.cc
blobaf4364814c3e157bd3668c9d7d3967eca4e36a10
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialog_helper.h"
7 #include "apps/app_load_service.h"
8 #include "apps/saved_files_service.h"
9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/apps/app_info_dialog.h"
12 #include "content/public/browser/web_contents.h"
13 #include "extensions/browser/api/device_permissions_manager.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/common/extension.h"
16 #include "extensions/common/permissions/permissions_data.h"
18 namespace extensions {
20 ShowPermissionsDialogHelper::ShowPermissionsDialogHelper(
21 Profile* profile,
22 const base::Closure& on_complete)
23 : profile_(profile),
24 on_complete_(on_complete) {
27 ShowPermissionsDialogHelper::~ShowPermissionsDialogHelper() {
30 // static
31 void ShowPermissionsDialogHelper::Show(content::BrowserContext* browser_context,
32 content::WebContents* web_contents,
33 const Extension* extension,
34 bool from_webui,
35 const base::Closure& on_complete) {
36 Profile* profile = Profile::FromBrowserContext(browser_context);
38 // Show the new-style extensions dialog when it is available. It is currently
39 // unavailable by default on Mac.
40 if (CanShowAppInfoDialog()) {
41 if (from_webui) {
42 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches",
43 AppInfoLaunchSource::FROM_EXTENSIONS_PAGE,
44 AppInfoLaunchSource::NUM_LAUNCH_SOURCES);
47 ShowAppInfoInNativeDialog(web_contents, GetAppInfoNativeDialogSize(),
48 profile, extension, on_complete);
50 return; // All done.
53 // ShowPermissionsDialogHelper manages its own lifetime.
54 ShowPermissionsDialogHelper* helper =
55 new ShowPermissionsDialogHelper(profile, on_complete);
56 helper->ShowPermissionsDialog(web_contents, extension);
59 void ShowPermissionsDialogHelper::ShowPermissionsDialog(
60 content::WebContents* web_contents,
61 const Extension* extension) {
62 extension_id_ = extension->id();
63 prompt_.reset(new ExtensionInstallPrompt(web_contents));
64 std::vector<base::FilePath> retained_file_paths;
65 if (extension->permissions_data()->HasAPIPermission(
66 APIPermission::kFileSystem)) {
67 std::vector<apps::SavedFileEntry> retained_file_entries =
68 apps::SavedFilesService::Get(profile_)
69 ->GetAllFileEntries(extension_id_);
70 for (const apps::SavedFileEntry& entry : retained_file_entries)
71 retained_file_paths.push_back(entry.path);
73 std::vector<base::string16> retained_device_messages;
74 if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) {
75 retained_device_messages =
76 DevicePermissionsManager::Get(profile_)
77 ->GetPermissionMessageStrings(extension_id_);
79 prompt_->ReviewPermissions(
80 this, extension, retained_file_paths, retained_device_messages);
83 // This is called when the user clicks "Revoke File Access."
84 void ShowPermissionsDialogHelper::InstallUIProceed() {
85 const Extension* extension =
86 ExtensionRegistry::Get(profile_)->GetExtensionById(
87 extension_id_, ExtensionRegistry::EVERYTHING);
89 if (extension)
90 apps::SavedFilesService::Get(profile_)->ClearQueue(extension);
91 apps::AppLoadService::Get(profile_)
92 ->RestartApplicationIfRunning(extension_id_);
94 on_complete_.Run();
96 delete this;
99 void ShowPermissionsDialogHelper::InstallUIAbort(bool user_initiated) {
100 on_complete_.Run();
102 delete this;
105 } // namespace extensions