summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/api/managed_mode_private/managed_mode_private_api.cc2
-rw-r--r--chrome/browser/extensions/installed_loader.cc3
-rw-r--r--chrome/browser/managed_mode/managed_user_service.cc13
-rw-r--r--chrome/browser/managed_mode/managed_user_service_unittest.cc2
-rw-r--r--chrome/chrome_common.gypi6
-rw-r--r--chrome/common/extensions/api/managed_mode_private/managed_mode_handler.cc99
-rw-r--r--chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h52
-rw-r--r--chrome/common/extensions/extension.cc55
-rw-r--r--chrome/common/extensions/extension.h14
9 files changed, 169 insertions, 77 deletions
diff --git a/chrome/browser/extensions/api/managed_mode_private/managed_mode_private_api.cc b/chrome/browser/extensions/api/managed_mode_private/managed_mode_private_api.cc
index 0ce3a73..94a7c0f 100644
--- a/chrome/browser/extensions/api/managed_mode_private/managed_mode_private_api.cc
+++ b/chrome/browser/extensions/api/managed_mode_private/managed_mode_private_api.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/api/managed_mode_private.h"
+#include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_details.h"
@@ -130,6 +131,7 @@ ManagedModeAPI::ManagedModeAPI(Profile* profile)
: profile_(profile) {
ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
this, kChangeEventName);
+ (new ManagedModeHandler)->Register();
}
ManagedModeAPI::~ManagedModeAPI() {
diff --git a/chrome/browser/extensions/installed_loader.cc b/chrome/browser/extensions/installed_loader.cc
index ba78077..b3ff5c7 100644
--- a/chrome/browser/extensions/installed_loader.cc
+++ b/chrome/browser/extensions/installed_loader.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/extensions/management_policy.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_l10n_util.h"
@@ -335,7 +336,7 @@ void InstalledLoader::LoadAllExtensions() {
if (extension_action_manager->GetBrowserAction(**ex))
++browser_action_count;
- if ((*ex)->is_content_pack())
+ if (extensions::ManagedModeInfo::IsContentPack(*ex))
++content_pack_count;
extension_service_->RecordPermissionMessagesHistogram(
diff --git a/chrome/browser/managed_mode/managed_user_service.cc b/chrome/browser/managed_mode/managed_user_service.cc
index 2956548..765c324 100644
--- a/chrome/browser/managed_mode/managed_user_service.cc
+++ b/chrome/browser/managed_mode/managed_user_service.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h"
#include "chrome/common/extensions/extension_set.h"
#include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h"
@@ -274,17 +275,19 @@ void ManagedUserService::Observe(int type,
case chrome::NOTIFICATION_EXTENSION_LOADED: {
const extensions::Extension* extension =
content::Details<extensions::Extension>(details).ptr();
- if (!extension->GetContentPackSiteList().empty())
+ if (!extensions::ManagedModeInfo::GetContentPackSiteList(
+ extension).empty()) {
UpdateSiteLists();
-
+ }
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
const extensions::UnloadedExtensionInfo* extension_info =
content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
- if (!extension_info->extension->GetContentPackSiteList().empty())
+ if (!extensions::ManagedModeInfo::GetContentPackSiteList(
+ extension_info->extension).empty()) {
UpdateSiteLists();
-
+ }
break;
}
default:
@@ -325,7 +328,7 @@ ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() {
continue;
extensions::ExtensionResource site_list =
- extension->GetContentPackSiteList();
+ extensions::ManagedModeInfo::GetContentPackSiteList(extension);
if (!site_list.empty())
site_lists.push_back(new ManagedModeSiteList(extension->id(), site_list));
}
diff --git a/chrome/browser/managed_mode/managed_user_service_unittest.cc b/chrome/browser/managed_mode/managed_user_service_unittest.cc
index 55b23f3..9946739 100644
--- a/chrome/browser/managed_mode/managed_user_service_unittest.cc
+++ b/chrome/browser/managed_mode/managed_user_service_unittest.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h"
#include "chrome/common/extensions/manifest_handler.h"
#include "chrome/common/extensions/manifest_handlers/requirements_handler.h"
#include "chrome/common/pref_names.h"
@@ -154,6 +155,7 @@ class ManagedUserServiceExtensionTest : public ExtensionServiceTestBase {
ExtensionServiceTestBase::SetUp();
InitializeEmptyExtensionService();
(new extensions::RequirementsHandler)->Register();
+ (new extensions::ManagedModeHandler)->Register();
}
virtual void TearDown() OVERRIDE {
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index ce081a4..9400875 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -181,6 +181,8 @@
'common/extensions/api/identity/oauth2_manifest_handler.h',
'common/extensions/api/input_ime/input_components_handler.cc',
'common/extensions/api/input_ime/input_components_handler.h',
+ 'common/extensions/api/managed_mode_private/managed_mode_handler.cc',
+ 'common/extensions/api/managed_mode_private/managed_mode_handler.h',
'common/extensions/api/omnibox/omnibox_handler.cc',
'common/extensions/api/omnibox/omnibox_handler.h',
'common/extensions/api/page_launcher/page_launcher_handler.cc',
@@ -432,8 +434,8 @@
['include', 'common/extensions/api/plugins/plugins_handler.h'],
['include', 'common/extensions/api/themes/theme_handler.cc'],
['include', 'common/extensions/api/themes/theme_handler.h'],
- ['include', 'common/extensions/manifest_handlers/requirements_handler.cc'],
- ['include', 'common/extensions/manifest_handlers/requirements_handler.h'],
+ ['include', 'common/extensions/api/managed_mode_private/managed_mode_handler.cc'],
+ ['include', 'common/extensions/api/managed_mode_private/managed_mode_handler.h'],
],
}],
['OS != "ios"', {
diff --git a/chrome/common/extensions/api/managed_mode_private/managed_mode_handler.cc b/chrome/common/extensions/api/managed_mode_private/managed_mode_handler.cc
new file mode 100644
index 0000000..8aea7af
--- /dev/null
+++ b/chrome/common/extensions/api/managed_mode_private/managed_mode_handler.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h"
+
+#include "base/lazy_instance.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "extensions/common/error_utils.h"
+
+namespace keys = extension_manifest_keys;
+
+namespace extensions {
+
+ManagedModeInfo::ManagedModeInfo() {
+}
+
+ManagedModeInfo::~ManagedModeInfo() {
+}
+
+// static
+bool ManagedModeInfo::IsContentPack(const Extension* extension) {
+ ManagedModeInfo* info = static_cast<ManagedModeInfo*>(
+ extension->GetManifestData(keys::kContentPack));
+ return info ? !info->site_list.empty() : false;
+}
+
+// static
+ExtensionResource ManagedModeInfo::GetContentPackSiteList(
+ const Extension* extension) {
+ ManagedModeInfo* info = static_cast<ManagedModeInfo*>(
+ extension->GetManifestData(keys::kContentPack));
+ return info && !info->site_list.empty() ?
+ extension->GetResource(info->site_list) :
+ ExtensionResource();
+}
+
+ManagedModeHandler::ManagedModeHandler() {
+}
+
+ManagedModeHandler::~ManagedModeHandler() {
+}
+
+bool ManagedModeHandler::Parse(Extension* extension, string16* error) {
+ if (!extension->manifest()->HasKey(keys::kContentPack))
+ return true;
+
+ scoped_ptr<ManagedModeInfo> info(new ManagedModeInfo);
+ const base::DictionaryValue* content_pack_value = NULL;
+ if (!extension->manifest()->GetDictionary(keys::kContentPack,
+ &content_pack_value)) {
+ *error = ASCIIToUTF16(extension_manifest_errors::kInvalidContentPack);
+ return false;
+ }
+
+ if (!LoadSites(info.get(), content_pack_value, error) ||
+ !LoadConfigurations(info.get(), content_pack_value, error)) {
+ return false;
+ }
+
+ extension->SetManifestData(keys::kContentPack, info.release());
+ return true;
+}
+
+const std::vector<std::string> ManagedModeHandler::Keys() const {
+ return SingleKey(keys::kContentPack);
+}
+
+bool ManagedModeHandler::LoadSites(
+ ManagedModeInfo* info,
+ const base::DictionaryValue* content_pack_value,
+ string16* error) {
+ if (!content_pack_value->HasKey(keys::kContentPackSites))
+ return true;
+
+ base::FilePath::StringType site_list_string;
+ if (!content_pack_value->GetString(keys::kContentPackSites,
+ &site_list_string)) {
+ *error = ASCIIToUTF16(extension_manifest_errors::kInvalidContentPackSites);
+ return false;
+ }
+
+ info->site_list = base::FilePath(site_list_string);
+
+ return true;
+}
+
+bool ManagedModeHandler::LoadConfigurations(
+ ManagedModeInfo* info,
+ const base::DictionaryValue* content_pack_value,
+ string16* error) {
+ NOTIMPLEMENTED();
+ return true;
+}
+
+} // namespace extensions
diff --git a/chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h b/chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h
new file mode 100644
index 0000000..99b1ea6
--- /dev/null
+++ b/chrome/common/extensions/api/managed_mode_private/managed_mode_handler.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_EXTENSIONS_API_MANAGED_MODE_PRIVATE_MANAGED_MODE_HANDLER_H_
+#define CHROME_COMMON_EXTENSIONS_API_MANAGED_MODE_PRIVATE_MANAGED_MODE_HANDLER_H_
+
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/manifest.h"
+#include "chrome/common/extensions/manifest_handler.h"
+#include "extensions/common/extension_resource.h"
+
+namespace extensions {
+
+struct ManagedModeInfo : public Extension::ManifestData {
+ ManagedModeInfo();
+ virtual ~ManagedModeInfo();
+
+ static bool IsContentPack(const Extension* extension);
+ static ExtensionResource GetContentPackSiteList(const Extension* extension);
+
+ // A file containing a list of sites for Managed Mode.
+ base::FilePath site_list;
+};
+
+// Parses the "content_pack" manifest key for Managed Mode.
+class ManagedModeHandler : public ManifestHandler {
+ public:
+ ManagedModeHandler();
+ virtual ~ManagedModeHandler();
+
+ virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
+ private:
+ virtual const std::vector<std::string> Keys() const OVERRIDE;
+
+ bool LoadSites(ManagedModeInfo* info,
+ const base::DictionaryValue* content_pack_value,
+ string16* error);
+ bool LoadConfigurations(ManagedModeInfo* info,
+ const base::DictionaryValue* content_pack_value,
+ string16* error);
+
+ DISALLOW_COPY_AND_ASSIGN(ManagedModeHandler);
+};
+
+} // namespace extensions
+
+#endif // CHROME_COMMON_EXTENSIONS_API_MANAGED_MODE_PRIVATE_MANAGED_MODE_HANDLER_H_
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index c912413..7ceeac5 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1027,17 +1027,6 @@ bool Extension::is_theme() const {
return manifest()->is_theme();
}
-bool Extension::is_content_pack() const {
- return !content_pack_site_list_.empty();
-}
-
-ExtensionResource Extension::GetContentPackSiteList() const {
- if (!is_content_pack())
- return ExtensionResource();
-
- return GetResource(content_pack_site_list_);
-}
-
Extension::RuntimeData::RuntimeData() {}
Extension::RuntimeData::RuntimeData(const PermissionSet* active)
: active_permissions_(active) {}
@@ -1119,47 +1108,6 @@ bool Extension::InitExtensionID(extensions::Manifest* manifest,
}
}
-bool Extension::LoadManagedModeFeatures(string16* error) {
- if (!manifest_->HasKey(keys::kContentPack))
- return true;
- const DictionaryValue* content_pack_value = NULL;
- if (!manifest_->GetDictionary(keys::kContentPack, &content_pack_value)) {
- *error = ASCIIToUTF16(errors::kInvalidContentPack);
- return false;
- }
-
- if (!LoadManagedModeSites(content_pack_value, error))
- return false;
- if (!LoadManagedModeConfigurations(content_pack_value, error))
- return false;
-
- return true;
-}
-
-bool Extension::LoadManagedModeSites(
- const DictionaryValue* content_pack_value,
- string16* error) {
- if (!content_pack_value->HasKey(keys::kContentPackSites))
- return true;
-
- base::FilePath::StringType site_list_str;
- if (!content_pack_value->GetString(keys::kContentPackSites, &site_list_str)) {
- *error = ASCIIToUTF16(errors::kInvalidContentPackSites);
- return false;
- }
-
- content_pack_site_list_ = base::FilePath(site_list_str);
-
- return true;
-}
-
-bool Extension::LoadManagedModeConfigurations(
- const DictionaryValue* content_pack_value,
- string16* error) {
- NOTIMPLEMENTED();
- return true;
-}
-
// static
bool Extension::IsTrustedId(const std::string& id) {
// See http://b/4946060 for more details.
@@ -1277,9 +1225,6 @@ bool Extension::InitFromValue(int flags, string16* error) {
manifest_->GetBoolean(keys::kConvertedFromUserScript,
&converted_from_user_script_);
- if (!LoadManagedModeFeatures(error))
- return false;
-
if (HasMultipleUISurfaces()) {
*error = ASCIIToUTF16(errors::kOneUISurfaceOnly);
return false;
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 20f517a..718172d8 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -470,10 +470,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Theme-related.
bool is_theme() const;
- // Content pack related.
- bool is_content_pack() const;
- ExtensionResource GetContentPackSiteList() const;
-
private:
friend class base::RefCountedThreadSafe<Extension>;
@@ -551,13 +547,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
bool LoadKioskEnabled(string16* error);
bool LoadOfflineEnabled(string16* error);
bool LoadTextToSpeechVoices(string16* error);
- bool LoadManagedModeFeatures(string16* error);
- bool LoadManagedModeSites(
- const base::DictionaryValue* content_pack_value,
- string16* error);
- bool LoadManagedModeConfigurations(
- const base::DictionaryValue* content_pack_value,
- string16* error);
// Returns true if the extension has more than one "UI surface". For example,
// an extension that has a browser action and a page action.
@@ -650,9 +639,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// The public key used to sign the contents of the crx package.
std::string public_key_;
- // A file containing a list of sites for Managed Mode.
- base::FilePath content_pack_site_list_;
-
// The manifest from which this extension was created.
scoped_ptr<Manifest> manifest_;