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

Unified Diff: chrome/common/extensions/extension.cc

Issue 7917006: Extension loading extracts intents from Manifest data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index af1f538d9c90bcce2b30774aa5c26c33a8de308e..3a212634a9be9cd3e2fbb2fc850a3d287a1dcf94 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -22,6 +22,7 @@
#include "base/values.h"
#include "base/version.h"
#include "crypto/sha2.h"
+#include "chrome/browser/intents/web_intent_data.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
@@ -173,7 +174,6 @@ int GetLocationRank(Extension::Location location) {
CHECK(rank != kInvalidRank);
return rank;
}
-
James Hawkins 2011/09/19 18:51:40 Keep this blank line.
groby-ooo-7-16 2011/09/19 21:33:59 Done.
} // namespace
const FilePath::CharType Extension::kManifestFilename[] =
@@ -1162,6 +1162,76 @@ bool Extension::LoadAppIsolation(const DictionaryValue* manifest,
return true;
}
+bool Extension::LoadWebIntents(const base::DictionaryValue& manifest,
+ std::string* error) {
+ DCHECK(error);
+
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents))
+ return true;
+
+ if (!manifest.HasKey(keys::kIntents))
+ return true;
+
+ DictionaryValue* all_intents = NULL;
+ if (!manifest.GetDictionary(keys::kIntents, &all_intents)) {
+ *error = errors::kInvalidIntents;
+ return false;
+ }
+
+ std::string value;
+ DictionaryValue::key_iterator iter(all_intents->begin_keys());
James Hawkins 2011/09/19 18:51:40 iter must be defined in the scope of the for loop,
groby-ooo-7-16 2011/09/19 21:33:59 Done.
+ for (; iter != all_intents->end_keys(); ++iter) {
+ WebIntentData intent;
+
+ DictionaryValue* one_intent = NULL;
+ if (!all_intents->GetDictionaryWithoutPathExpansion(*iter, &one_intent)) {
+ *error = errors::kInvalidIntent;
+ return false;
+ }
+ intent.action = UTF8ToUTF16(*iter);
+
+ // TODO(groby): Support an array of types
James Hawkins 2011/09/19 18:51:40 Append period.
groby-ooo-7-16 2011/09/19 21:33:59 Done.
+ if (one_intent->HasKey(keys::kIntentType)) {
+ if (!one_intent->GetString(keys::kIntentType, &intent.type)) {
James Hawkins 2011/09/19 18:51:40 Save indentation: combine these two ifs. Here and
groby-ooo-7-16 2011/09/19 21:33:59 That's inconsistent with the entire rest of the fi
+ *error = errors::kInvalidIntentType;
+ return false;
+ }
+ }
+
+ if (one_intent->HasKey(keys::kIntentPath)) {
+ if (!one_intent->GetString(keys::kIntentPath, &value)) {
+ *error = errors::kInvalidIntentPath;
+ return false;
+ }
+ intent.service_url = GetResourceURL(value);
+ }
+
+ if (one_intent->HasKey(keys::kIntentTitle)) {
+ if (!one_intent->GetString(keys::kIntentTitle, &intent.title)) {
+ *error = errors::kInvalidIntentTitle;
+ return false;
+ }
+ }
+
+ if (one_intent->HasKey(keys::kIntentDisposition)) {
+ if (!one_intent->GetString(keys::kIntentDisposition, &value) ||
+ (value != values::kIntentDispositionWindow &&
+ value != values::kIntentDispositionInline)) {
+ *error = errors::kInvalidIntentDisposition;
+ return false;
+ }
+ if (value == values::kIntentDispositionInline)
+ intent.disposition = WebIntentData::DISPOSITION_INLINE;
+ else
+ intent.disposition = WebIntentData::DISPOSITION_WINDOW;
+ }
+
+ intents_.push_back(intent);
+ }
+ return true;
+}
+
+
bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest,
std::string* error) {
if (web_extent().is_empty())
@@ -2272,6 +2342,10 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags,
}
}
+ // Initialize web intents (optional).
+ if (!LoadWebIntents(source, error))
+ return false;
+
// Initialize incognito behavior. Apps default to split mode, extensions
// default to spanning.
incognito_split_mode_ = is_app();

Powered by Google App Engine
This is Rietveld 408576698