Extensions: Move IsIncognitoEnabled to extensions/ from chrome/.

This CL moves extensions::util::IsIncognitoEnabled from
chrome/browser/extension_util.h(cc) to extensions/browser/extension_util.h(cc).
This is possible since IsIncognitoEnabled does not have any chrome/
dependencies. This is required to prevent a dependency violation for a
subsequent CL where we need to use IsIncognitoEnabled from code in
src/extensions.

BUG=527548

Review-Url: https://codereview.chromium.org/2758103003
Cr-Commit-Position: refs/heads/master@{#462274}
diff --git a/extensions/browser/extension_util.cc b/extensions/browser/extension_util.cc
index 142e1e4..0961f42 100644
--- a/extensions/browser/extension_util.cc
+++ b/extensions/browser/extension_util.cc
@@ -8,12 +8,27 @@
 #include "content/public/browser/site_instance.h"
 #include "extensions/browser/extension_prefs.h"
 #include "extensions/browser/extension_registry.h"
+#include "extensions/common/features/behavior_feature.h"
+#include "extensions/common/features/feature.h"
+#include "extensions/common/features/feature_provider.h"
+#include "extensions/common/manifest.h"
 #include "extensions/common/manifest_handlers/app_isolation_info.h"
 #include "extensions/common/manifest_handlers/incognito_info.h"
 
 namespace extensions {
 namespace util {
 
+namespace {
+
+// Returns true if |extension| should always be enabled in incognito mode.
+bool IsWhitelistedForIncognito(const Extension* extension) {
+  const Feature* feature = FeatureProvider::GetBehaviorFeature(
+      behavior_feature::kWhitelistedForIncognito);
+  return feature && feature->IsAvailableToExtension(extension).is_available();
+}
+
+}  // namespace
+
 bool HasIsolatedStorage(const ExtensionInfo& info) {
   if (!info.extension_manifest.get())
     return false;
@@ -45,6 +60,24 @@
           extension->location() == Manifest::COMPONENT);
 }
 
+bool IsIncognitoEnabled(const std::string& extension_id,
+                        content::BrowserContext* context) {
+  const Extension* extension =
+      ExtensionRegistry::Get(context)->GetExtensionById(
+          extension_id, ExtensionRegistry::ENABLED);
+  if (extension) {
+    if (!CanBeIncognitoEnabled(extension))
+      return false;
+    // If this is an existing component extension we always allow it to
+    // work in incognito mode.
+    if (Manifest::IsComponentLocation(extension->location()))
+      return true;
+    if (IsWhitelistedForIncognito(extension))
+      return true;
+  }
+  return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id);
+}
+
 content::StoragePartition* GetStoragePartitionForExtensionId(
     const std::string& extension_id,
     content::BrowserContext* browser_context) {