Home | History | Annotate | Download | only in extensions
      1 // Copyright 2014 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/extension_ui_util.h"
      6 
      7 #include "base/prefs/pref_service.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/common/extensions/extension_constants.h"
     10 #include "chrome/common/pref_names.h"
     11 #include "extensions/browser/extension_util.h"
     12 #include "extensions/common/constants.h"
     13 #include "extensions/common/extension.h"
     14 
     15 namespace extensions {
     16 
     17 namespace {
     18 
     19 bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) {
     20   Profile* profile = Profile::FromBrowserContext(context);
     21   DCHECK(profile);
     22 
     23   return (app->id() == extensions::kWebStoreAppId ||
     24       app->id() == extension_misc::kEnterpriseWebStoreAppId) &&
     25       profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon);
     26 }
     27 
     28 }  // namespace
     29 
     30 namespace ui_util {
     31 
     32 bool ShouldDisplayInAppLauncher(const Extension* extension,
     33                                 content::BrowserContext* context) {
     34   return CanDisplayInAppLauncher(extension, context) &&
     35          !util::IsEphemeralApp(extension->id(), context);
     36 }
     37 
     38 bool CanDisplayInAppLauncher(const Extension* extension,
     39                              content::BrowserContext* context) {
     40   return extension->ShouldDisplayInAppLauncher() &&
     41          !IsBlockedByPolicy(extension, context);
     42 }
     43 
     44 bool ShouldDisplayInNewTabPage(const Extension* extension,
     45                                content::BrowserContext* context) {
     46   return extension->ShouldDisplayInNewTabPage() &&
     47       !IsBlockedByPolicy(extension, context) &&
     48       !util::IsEphemeralApp(extension->id(), context);
     49 }
     50 
     51 bool ShouldDisplayInExtensionSettings(const Extension* extension,
     52                                       content::BrowserContext* context) {
     53   return extension->ShouldDisplayInExtensionSettings() &&
     54       !util::IsEphemeralApp(extension->id(), context);
     55 }
     56 
     57 bool ShouldNotBeVisible(const Extension* extension,
     58                         content::BrowserContext* context) {
     59   return extension->ShouldNotBeVisible() ||
     60       util::IsEphemeralApp(extension->id(), context);
     61 }
     62 
     63 }  // namespace ui_util
     64 }  // namespace extensions
     65