summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorerikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 21:54:38 +0000
committererikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 21:54:38 +0000
commit581b0ad8e68976f469b2140160bbfdfe0151584b (patch)
treea50beb352caf262a37701883e505837aedd1a7cb /chrome/common
parent8a4d3c8bf1f2291c500e5948beb097d710044da1 (diff)
downloadchromium_src-581b0ad8e68976f469b2140160bbfdfe0151584b.zip
chromium_src-581b0ad8e68976f469b2140160bbfdfe0151584b.tar.gz
chromium_src-581b0ad8e68976f469b2140160bbfdfe0151584b.tar.bz2
initial manifest hooks for app experiment
BUG=none TEST=none Review URL: http://codereview.chromium.org/550016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/common/extensions/extension.cc54
-rw-r--r--chrome/common/extensions/extension.h15
-rw-r--r--chrome/common/extensions/extension_constants.cc4
-rw-r--r--chrome/common/extensions/extension_constants.h8
6 files changed, 83 insertions, 2 deletions
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 96df9be..af88125 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -188,6 +188,9 @@ const char kEnableExperimentalExtensionApis[] =
// Enable experimental WebGL support.
const char kEnableExperimentalWebGL[] = "enable-webgl";
+// Enable experimental extension apps.
+const char kEnableExtensionApps[] = "enable-extension-apps";
+
// Enable experimental timeline API.
const char kEnableExtensionTimelineApi[] = "enable-extension-timeline-api";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 11ca7c4..7e3deaf 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -69,6 +69,7 @@ extern const char kEnableApplicationCache[];
extern const char kEnableBenchmarking[];
extern const char kEnableExperimentalExtensionApis[];
extern const char kEnableExperimentalWebGL[];
+extern const char kEnableExtensionApps[];
extern const char kEnableExtensionTimelineApi[];
extern const char kEnableExtensionToolstrips[];
extern const char kEnableFastback[];
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 7f9783d..2a0f139 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -493,6 +493,44 @@ bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) {
return false;
}
+// We're likely going to want to restrict apps away from certain APIs/features.
+// TODO(erikkay) - figure out what APIs to block.
+bool Extension::ContainsNonAppKeys(const DictionaryValue& source) {
+ return false;
+}
+
+bool Extension::LoadAppHelper(const DictionaryValue* app, std::string* error) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableExtensionApps)) {
+ *error = errors::kInvalidApp;
+ return false;
+ }
+
+ ListValue* origins;
+ if (!app->GetList(keys::kAppOrigins, &origins) || origins->GetSize() == 0) {
+ *error =
+ ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidAppOrigin, "");
+ return false;
+ }
+ for (ListValue::const_iterator iter = origins->begin();
+ iter != origins->end(); ++iter) {
+ std::string url_str;
+ if (!(*iter)->GetAsString(&url_str) || url_str.empty()) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidAppOrigin, url_str);
+ return false;
+ }
+ GURL url(url_str);
+ if (!url.is_valid() || url != url.GetOrigin()) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidAppOrigin, url_str);
+ return false;
+ }
+ app_origins_.push_back(url);
+ }
+ return true;
+}
+
Extension::Extension(const FilePath& path)
: converted_from_user_script_(false), is_theme_(false),
background_page_ready_(false) {
@@ -1218,6 +1256,22 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
}
}
+ // If it's an app, load the appropriate keys, etc.
+ if (source.HasKey(keys::kApp)) {
+ if (ContainsNonAppKeys(source)) {
+ *error = errors::kInvalidApp;
+ return false;
+ }
+ DictionaryValue* app;
+ if (!source.GetDictionary(keys::kApp, &app)) {
+ *error = errors::kInvalidApp;
+ return false;
+ }
+ if (!LoadAppHelper(app, error)) {
+ return false;
+ }
+ }
+
// Although |source| is passed in as a const, it's still possible to modify
// it. This is dangerous since the utility process re-uses |source| after
// it calls InitFromValue, passing it up to the browser process which calls
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index b1e1b69..5ed2f7f 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -286,6 +286,10 @@ class Extension {
bool GetBackgroundPageReady();
void SetBackgroundPageReady();
+ // The origins that this app is registered to.
+ const std::vector<GURL>& app_origins() const { return app_origins_; }
+ bool IsApp() const { return !app_origins_.empty(); }
+
private:
// Helper method that loads a UserScript object from a
// dictionary in the content_script list of the manifest.
@@ -312,6 +316,13 @@ class Extension {
// don't want to allow scripts and such to be bundled with themes.
bool ContainsNonThemeKeys(const DictionaryValue& source);
+ // Apps don't have access to all extension features. This enforces those
+ // restrictions.
+ bool ContainsNonAppKeys(const DictionaryValue& source);
+
+ // Helper method to verify the app section of the manifest.
+ bool LoadAppHelper(const DictionaryValue* app, std::string* error);
+
// The absolute path to the directory the extension is stored in.
FilePath path_;
@@ -408,6 +419,10 @@ class Extension {
// which override the handling of those URLs.
URLOverrideMap chrome_url_overrides_;
+ // The vector of origin URLs associated with an app.
+ std::vector<GURL> app_origins_;
+
+
// Runtime data:
// True if the background page is ready.
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index 0f59e5f..f756e13 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -7,6 +7,8 @@
namespace extension_manifest_keys {
const wchar_t* kAllFrames = L"all_frames";
+const wchar_t* kApp = L"app";
+const wchar_t* kAppOrigins = L"origins";
const wchar_t* kBackground = L"background_page";
const wchar_t* kBrowserAction = L"browser_action";
const wchar_t* kChromeURLOverrides = L"chrome_url_overrides";
@@ -72,6 +74,8 @@ const char* kChromeVersionTooLow =
"This extension requires * version * or greater.";
const char* kInvalidAllFrames =
"Invalid value for 'content_scripts[*].all_frames'.";
+const char* kInvalidApp = "Invalid app.";
+const char* kInvalidAppOrigin = "Invalid app origin[*]";
const char* kInvalidBrowserAction =
"Invalid value for 'browser_action'.";
const char* kInvalidChromeURLOverrides =
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index 4d9ef84..b7d945e 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -8,6 +8,8 @@
// Keys used in JSON representation of extensions.
namespace extension_manifest_keys {
extern const wchar_t* kAllFrames;
+ extern const wchar_t* kApp;
+ extern const wchar_t* kAppOrigins;
extern const wchar_t* kBackground;
extern const wchar_t* kBrowserAction;
extern const wchar_t* kMinimumChromeVersion;
@@ -68,6 +70,10 @@ namespace extension_manifest_values {
// Error messages returned from Extension::InitFromValue().
namespace extension_manifest_errors {
extern const char* kChromeVersionTooLow;
+ extern const char* kInvalidAllFrames;
+ extern const char* kInvalidApp;
+ extern const char* kInvalidAppOrigin;
+ extern const char* kInvalidBackground;
extern const char* kInvalidBrowserAction;
extern const char* kInvalidChromeURLOverrides;
extern const char* kInvalidContentScript;
@@ -94,8 +100,6 @@ namespace extension_manifest_errors {
extern const char* kInvalidPrivacyBlacklists;
extern const char* kInvalidPrivacyBlacklistsPath;
- extern const char* kInvalidAllFrames;
- extern const char* kInvalidBackground;
extern const char* kInvalidRunAt;
extern const char* kInvalidSignature;
extern const char* kInvalidToolstrip;