OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h" | |
6 | |
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" | |
17 | |
18 namespace extensions { | |
19 | |
20 ShowPermissionsDialogHelper::ShowPermissionsDialogHelper( | |
21 Profile* profile, | |
22 const base::Closure& on_complete) | |
23 : profile_(profile), | |
24 on_complete_(on_complete) { | |
25 } | |
26 | |
27 ShowPermissionsDialogHelper::~ShowPermissionsDialogHelper() { | |
28 } | |
29 | |
30 // static | |
31 void ShowPermissionsDialogHelper::Show(content::WebContents* web_contents, | |
32 content::BrowserContext* browser_context, | |
33 const Extension* extension, | |
34 bool from_extensions_page, | |
35 const base::Closure& on_complete) { | |
36 Profile* profile = Profile::FromBrowserContext(browser_context); | |
37 | |
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_extensions_page) { | |
42 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches", | |
43 AppInfoLaunchSource::FROM_EXTENSIONS_PAGE, | |
44 AppInfoLaunchSource::NUM_LAUNCH_SOURCES); | |
45 } | |
46 | |
47 // The Unretained() is safe here because this object's parent should never | |
not at google - send to devlin
2015/03/16 17:39:55
I don't see an Unretained()
Devlin
2015/03/16 21:10:55
Done.
| |
48 // go away before a response. | |
49 ShowAppInfoInNativeDialog( | |
50 web_contents->GetTopLevelNativeWindow(), | |
51 GetAppInfoNativeDialogSize(), | |
52 profile, | |
53 extension, | |
54 on_complete); | |
55 | |
56 return; // All done. | |
57 } | |
58 | |
59 // ShowPermissionsDialogHelper manages its own lifetime. | |
60 ShowPermissionsDialogHelper* helper = | |
61 new ShowPermissionsDialogHelper(profile, on_complete); | |
62 helper->ShowPermissionsDialog(web_contents, extension); | |
63 } | |
64 | |
65 void ShowPermissionsDialogHelper::ShowPermissionsDialog( | |
66 content::WebContents* web_contents, | |
67 const Extension* extension) { | |
68 extension_id_ = extension->id(); | |
69 prompt_.reset(new ExtensionInstallPrompt(web_contents)); | |
70 std::vector<base::FilePath> retained_file_paths; | |
71 if (extension->permissions_data()->HasAPIPermission( | |
72 APIPermission::kFileSystem)) { | |
73 std::vector<apps::SavedFileEntry> retained_file_entries = | |
74 apps::SavedFilesService::Get(profile_) | |
75 ->GetAllFileEntries(extension_id_); | |
76 for (const apps::SavedFileEntry& entry : retained_file_entries) | |
77 retained_file_paths.push_back(entry.path); | |
78 } | |
79 std::vector<base::string16> retained_device_messages; | |
80 if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) { | |
81 retained_device_messages = | |
82 DevicePermissionsManager::Get(profile_) | |
83 ->GetPermissionMessageStrings(extension_id_); | |
84 } | |
85 prompt_->ReviewPermissions( | |
86 this, extension, retained_file_paths, retained_device_messages); | |
87 } | |
88 | |
89 // This is called when the user clicks "Revoke File Access." | |
90 void ShowPermissionsDialogHelper::InstallUIProceed() { | |
91 const Extension* extension = | |
92 ExtensionRegistry::Get(profile_)->GetExtensionById( | |
93 extension_id_, ExtensionRegistry::EVERYTHING); | |
94 | |
95 if (extension) | |
96 apps::SavedFilesService::Get(profile_)->ClearQueue(extension); | |
97 apps::AppLoadService::Get(profile_) | |
98 ->RestartApplicationIfRunning(extension_id_); | |
99 | |
100 on_complete_.Run(); | |
101 | |
102 delete this; | |
103 } | |
104 | |
105 void ShowPermissionsDialogHelper::InstallUIAbort(bool user_initiated) { | |
106 on_complete_.Run(); | |
107 | |
108 delete this; | |
109 } | |
110 | |
111 } // namespace extensions | |
OLD | NEW |