Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Side by Side Diff: chrome/browser/apps/ephemeral_app_launcher.cc

Issue 384423002: [Canceled] Extensions: Add install_flags parameter to ManagementPolicy::UserMayLoad (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/apps/ephemeral_app_launcher_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/apps/ephemeral_app_launcher.h" 5 #include "chrome/browser/apps/ephemeral_app_launcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_install_checker.h" 9 #include "chrome/browser/extensions/extension_install_checker.h"
10 #include "chrome/browser/extensions/extension_install_prompt.h" 10 #include "chrome/browser/extensions/extension_install_prompt.h"
11 #include "chrome/browser/extensions/extension_util.h" 11 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser_navigator.h" 13 #include "chrome/browser/ui/browser_navigator.h"
14 #include "chrome/browser/ui/extensions/application_launch.h" 14 #include "chrome/browser/ui/extensions/application_launch.h"
15 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 15 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 18 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "extensions/browser/extension_prefs.h" 20 #include "extensions/browser/extension_prefs.h"
21 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/install_flag.h"
23 #include "extensions/browser/management_policy.h" 24 #include "extensions/browser/management_policy.h"
24 #include "extensions/common/permissions/permissions_data.h" 25 #include "extensions/common/permissions/permissions_data.h"
25 26
26 using content::WebContents; 27 using content::WebContents;
27 using extensions::Extension; 28 using extensions::Extension;
28 using extensions::ExtensionInstallChecker; 29 using extensions::ExtensionInstallChecker;
29 using extensions::ExtensionPrefs; 30 using extensions::ExtensionPrefs;
30 using extensions::ExtensionRegistry; 31 using extensions::ExtensionRegistry;
31 using extensions::ExtensionSystem; 32 using extensions::ExtensionSystem;
32 using extensions::ManagementPolicy; 33 using extensions::ManagementPolicy;
33 using extensions::WebstoreInstaller; 34 using extensions::WebstoreInstaller;
34 namespace webstore_install = extensions::webstore_install; 35 namespace webstore_install = extensions::webstore_install;
35 36
36 namespace { 37 namespace {
37 38
38 const char kInvalidManifestError[] = "Invalid manifest"; 39 const char kInvalidManifestError[] = "Invalid manifest";
39 const char kExtensionTypeError[] = "Not an app"; 40 const char kExtensionTypeError[] = "Not an app";
40 const char kAppTypeError[] = "Ephemeral legacy packaged apps not supported"; 41 const char kAppTypeError[] = "Ephemeral legacy packaged apps not supported";
41 const char kUserCancelledError[] = "Launch cancelled by the user"; 42 const char kUserCancelledError[] = "Launch cancelled by the user";
42 const char kBlacklistedError[] = "App is blacklisted for malware"; 43 const char kBlacklistedError[] = "App is blacklisted for malware";
43 const char kRequirementsError[] = "App has missing requirements"; 44 const char kRequirementsError[] = "App has missing requirements";
44 const char kFeatureDisabledError[] = "Launching ephemeral apps is not enabled"; 45 const char kFeatureDisabledError[] = "Launching ephemeral apps is not enabled";
45 const char kMissingAppError[] = "App is not installed"; 46 const char kMissingAppError[] = "App is not installed";
46 const char kAppDisabledError[] = "App is disabled"; 47 const char kAppDisabledError[] = "App is disabled";
47 48
49 const int kInstallFlags = extensions::kInstallFlagIsEphemeral;
50
48 Profile* ProfileForWebContents(content::WebContents* contents) { 51 Profile* ProfileForWebContents(content::WebContents* contents) {
49 if (!contents) 52 if (!contents)
50 return NULL; 53 return NULL;
51 54
52 return Profile::FromBrowserContext(contents->GetBrowserContext()); 55 return Profile::FromBrowserContext(contents->GetBrowserContext());
53 } 56 }
54 57
55 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { 58 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) {
56 if (!contents) 59 if (!contents)
57 return NULL; 60 return NULL;
58 61
59 return contents->GetTopLevelNativeWindow(); 62 return contents->GetTopLevelNativeWindow();
60 } 63 }
61 64
62 // Check whether an extension can be launched. The extension does not need to 65 // Check whether an extension can be launched. The extension does not need to
63 // be currently installed. 66 // be currently installed.
64 bool CheckCommonLaunchCriteria(Profile* profile, 67 bool CheckCommonLaunchCriteria(Profile* profile,
65 const Extension* extension, 68 const Extension* extension,
69 int install_flags,
66 webstore_install::Result* reason, 70 webstore_install::Result* reason,
67 std::string* error) { 71 std::string* error) {
68 // Only apps can be launched. 72 // Only apps can be launched.
69 if (!extension->is_app()) { 73 if (!extension->is_app()) {
70 *reason = webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE; 74 *reason = webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE;
71 *error = kExtensionTypeError; 75 *error = kExtensionTypeError;
72 return false; 76 return false;
73 } 77 }
74 78
75 // Do not launch apps blocked by management policies. 79 // Do not launch apps blocked by management policies.
76 ManagementPolicy* management_policy = 80 ManagementPolicy* management_policy =
77 ExtensionSystem::Get(profile)->management_policy(); 81 ExtensionSystem::Get(profile)->management_policy();
78 base::string16 policy_error; 82 base::string16 policy_error;
79 if (!management_policy->UserMayLoad(extension, &policy_error)) { 83 if (!management_policy->UserMayLoad(
84 extension, install_flags, &policy_error)) {
80 *reason = webstore_install::BLOCKED_BY_POLICY; 85 *reason = webstore_install::BLOCKED_BY_POLICY;
81 *error = base::UTF16ToUTF8(policy_error); 86 *error = base::UTF16ToUTF8(policy_error);
82 return false; 87 return false;
83 } 88 }
84 89
85 return true; 90 return true;
86 } 91 }
87 92
88 } // namespace 93 } // namespace
89 94
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 scoped_ptr<WebstoreInstaller::Approval> approval = 201 scoped_ptr<WebstoreInstaller::Approval> approval =
197 WebstoreStandaloneInstaller::CreateApproval(); 202 WebstoreStandaloneInstaller::CreateApproval();
198 approval->is_ephemeral = true; 203 approval->is_ephemeral = true;
199 return approval.Pass(); 204 return approval.Pass();
200 } 205 }
201 206
202 bool EphemeralAppLauncher::CanLaunchInstalledApp( 207 bool EphemeralAppLauncher::CanLaunchInstalledApp(
203 const extensions::Extension* extension, 208 const extensions::Extension* extension,
204 webstore_install::Result* reason, 209 webstore_install::Result* reason,
205 std::string* error) { 210 std::string* error) {
206 if (!CheckCommonLaunchCriteria(profile(), extension, reason, error)) 211 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile());
212 int install_flags = extension_prefs->GetInstallFlags(extension->id());
213 if (!CheckCommonLaunchCriteria(
214 profile(), extension, install_flags, reason, error))
207 return false; 215 return false;
208 216
209 // Do not launch blacklisted apps. 217 // Do not launch blacklisted apps.
210 if (ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(extension->id())) { 218 if (extension_prefs->IsExtensionBlacklisted(extension->id())) {
211 *reason = webstore_install::BLACKLISTED; 219 *reason = webstore_install::BLACKLISTED;
212 *error = kBlacklistedError; 220 *error = kBlacklistedError;
213 return false; 221 return false;
214 } 222 }
215 223
216 // If the app has missing requirements, it cannot be launched. 224 // If the app has missing requirements, it cannot be launched.
217 if (!extensions::util::IsAppLaunchable(extension->id(), profile())) { 225 if (!extensions::util::IsAppLaunchable(extension->id(), profile())) {
218 *reason = webstore_install::REQUIREMENT_VIOLATIONS; 226 *reason = webstore_install::REQUIREMENT_VIOLATIONS;
219 *error = kRequirementsError; 227 *error = kRequirementsError;
220 return false; 228 return false;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 WebstoreStandaloneInstaller::CompleteInstall(result, error); 311 WebstoreStandaloneInstaller::CompleteInstall(result, error);
304 } 312 }
305 313
306 void EphemeralAppLauncher::CheckEphemeralInstallPermitted() { 314 void EphemeralAppLauncher::CheckEphemeralInstallPermitted() {
307 scoped_refptr<const Extension> extension = GetLocalizedExtensionForDisplay(); 315 scoped_refptr<const Extension> extension = GetLocalizedExtensionForDisplay();
308 DCHECK(extension.get()); // Checked in OnManifestParsed(). 316 DCHECK(extension.get()); // Checked in OnManifestParsed().
309 317
310 install_checker_ = CreateInstallChecker(); 318 install_checker_ = CreateInstallChecker();
311 DCHECK(install_checker_.get()); 319 DCHECK(install_checker_.get());
312 320
313 install_checker_->set_extension(extension); 321 install_checker_->set_extension(extension, kInstallFlags);
314 install_checker_->Start(ExtensionInstallChecker::CHECK_BLACKLIST | 322 install_checker_->Start(ExtensionInstallChecker::CHECK_BLACKLIST |
315 ExtensionInstallChecker::CHECK_REQUIREMENTS, 323 ExtensionInstallChecker::CHECK_REQUIREMENTS,
316 true, 324 true,
317 base::Bind(&EphemeralAppLauncher::OnInstallChecked, 325 base::Bind(&EphemeralAppLauncher::OnInstallChecked,
318 base::Unretained(this))); 326 base::Unretained(this)));
319 } 327 }
320 328
321 void EphemeralAppLauncher::OnInstallChecked(int check_failures) { 329 void EphemeralAppLauncher::OnInstallChecked(int check_failures) {
322 if (!CheckRequestorAlive()) { 330 if (!CheckRequestorAlive()) {
323 AbortLaunch(webstore_install::UNKNOWN_ERROR, std::string()); 331 AbortLaunch(webstore_install::UNKNOWN_ERROR, std::string());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 399
392 void EphemeralAppLauncher::OnManifestParsed() { 400 void EphemeralAppLauncher::OnManifestParsed() {
393 const Extension* extension = GetLocalizedExtensionForDisplay(); 401 const Extension* extension = GetLocalizedExtensionForDisplay();
394 if (!extension) { 402 if (!extension) {
395 AbortLaunch(webstore_install::INVALID_MANIFEST, kInvalidManifestError); 403 AbortLaunch(webstore_install::INVALID_MANIFEST, kInvalidManifestError);
396 return; 404 return;
397 } 405 }
398 406
399 webstore_install::Result result = webstore_install::UNKNOWN_ERROR; 407 webstore_install::Result result = webstore_install::UNKNOWN_ERROR;
400 std::string error; 408 std::string error;
401 if (!CheckCommonLaunchCriteria(profile(), extension, &result, &error)) { 409 if (!CheckCommonLaunchCriteria(
410 profile(), extension, kInstallFlags, &result, &error)) {
402 AbortLaunch(result, error); 411 AbortLaunch(result, error);
403 return; 412 return;
404 } 413 }
405 414
406 if (extension->is_legacy_packaged_app()) { 415 if (extension->is_legacy_packaged_app()) {
407 AbortLaunch(webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE, 416 AbortLaunch(webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE,
408 kAppTypeError); 417 kAppTypeError);
409 return; 418 return;
410 } 419 }
411 420
(...skipping 27 matching lines...) Expand all
439 448
440 void EphemeralAppLauncher::ExtensionEnableFlowFinished() { 449 void EphemeralAppLauncher::ExtensionEnableFlowFinished() {
441 MaybeLaunchApp(); 450 MaybeLaunchApp();
442 Release(); // Matches the AddRef in EnableInstalledApp(). 451 Release(); // Matches the AddRef in EnableInstalledApp().
443 } 452 }
444 453
445 void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) { 454 void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) {
446 InvokeCallback(webstore_install::USER_CANCELLED, kUserCancelledError); 455 InvokeCallback(webstore_install::USER_CANCELLED, kUserCancelledError);
447 Release(); // Matches the AddRef in EnableInstalledApp(). 456 Release(); // Matches the AddRef in EnableInstalledApp().
448 } 457 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/apps/ephemeral_app_launcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698