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

Unified Diff: chrome/common/extensions/api/url_handlers/url_handlers_parser.cc

Issue 22944002: Implementation of the "Redirect URLs to Packaged Apps" feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 1) Fixed broken redirection for in-page WebKit-initiated navigations. All redirections work now. 2)… Created 7 years, 4 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/api/url_handlers/url_handlers_parser.cc
diff --git a/chrome/common/extensions/api/url_handlers/url_handlers_parser.cc b/chrome/common/extensions/api/url_handlers/url_handlers_parser.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ceb727f3ddc2f9c28a96aaf237060a751fb62baa
--- /dev/null
+++ b/chrome/common/extensions/api/url_handlers/url_handlers_parser.cc
@@ -0,0 +1,125 @@
+// Copyright (c) 2012 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/url_handlers/url_handlers_parser.h"
+
not at google - send to devlin 2013/08/19 23:32:24 consider using the same strategy that externally_c
sergeygs 2013/08/29 08:24:42 This is identical to how file_handlers code does t
not at google - send to devlin 2013/08/29 17:35:56 Sure, thanks. Make sure to file bugs on all of the
sergeygs 2013/08/30 00:39:44 Sure, I will file bugs.
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest.h"
+#include "extensions/common/error_utils.h"
+
+namespace mkeys = extension_manifest_keys;
+namespace merrors = extension_manifest_errors;
+
+namespace extensions {
+
+UrlHandlerInfo::UrlHandlerInfo() {
+}
+
+UrlHandlerInfo::~UrlHandlerInfo() {
+}
+
+UrlHandlers::UrlHandlers() {
+}
+
+UrlHandlers::~UrlHandlers() {
+}
+
+// static
+const std::vector<UrlHandlerInfo>* UrlHandlers::GetUrlHandlers(
+ const Extension* extension) {
+ UrlHandlers* info = static_cast<UrlHandlers*>(
+ extension->GetManifestData(mkeys::kUrlHandlers));
+ return info ? &info->handlers : NULL;
+}
+
+UrlHandlersParser::UrlHandlersParser() {
+}
+
+UrlHandlersParser::~UrlHandlersParser() {
+}
+
+bool ParseUrlHandler(const Extension* app,
+ const std::string& handler_id,
+ const DictionaryValue& handler_info,
+ std::vector<UrlHandlerInfo>* url_handlers,
+ string16* error) {
+ DCHECK(error);
+ UrlHandlerInfo handler;
+
+ handler.app = app;
+ handler.id = handler_id;
+
+ if (!handler_info.GetString(mkeys::kUrlHandlerTitle, &handler.title)) {
+ *error = ASCIIToUTF16(merrors::kInvalidUrlHandlerTitle);
+ return false;
+ }
+
+ const ListValue* manif_patterns = NULL;
+ if (!handler_info.GetList(mkeys::kMatches, &manif_patterns) ||
+ manif_patterns->GetSize() == 0) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ merrors::kInvalidUrlHandlerPattern, handler_id);
+ return false;
+ }
+
+ for (const auto& manif_pattern: *manif_patterns) {
+ std::string str_pattern;
+ manif_pattern->GetAsString(&str_pattern);
+ URLPattern pattern(URLPattern::SCHEME_HTTP |
+ URLPattern::SCHEME_HTTPS);
+ if (pattern.Parse(str_pattern) != URLPattern::PARSE_SUCCESS) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ merrors::kInvalidUrlHandlerPatternElement, handler_id);
+ return false;
+ }
+ handler.patterns.AddPattern(pattern);
+ }
+
+ url_handlers->push_back(handler);
+
+ return true;
+}
+
+bool UrlHandlersParser::Parse(Extension* extension, string16* error) {
+ scoped_ptr<UrlHandlers> info(new UrlHandlers);
+ const DictionaryValue* all_handlers = NULL;
+ if (!extension->manifest()->GetDictionary(
+ mkeys::kUrlHandlers, &all_handlers)) {
+ *error = ASCIIToUTF16(merrors::kInvalidUrlHandlers);
+ return false;
+ }
+
+ // TODO(sergeygs): Should be is_platform_app?
not at google - send to devlin 2013/08/19 23:32:24 yes
sergeygs 2013/08/29 08:24:42 Done.
+ DCHECK(extension->is_app());
+
+ for (DictionaryValue::Iterator iter(*all_handlers); !iter.IsAtEnd();
+ iter.Advance()) {
+ // A URL handler entry is a title and a list of URL patterns to handle.
+ const DictionaryValue* handler = NULL;
+ if (!iter.value().GetAsDictionary(&handler)) {
+ *error = ASCIIToUTF16(merrors::kInvalidUrlHandlerPatternElement);
+ return false;
+ }
+
+ if (!ParseUrlHandler(
+ extension, iter.key(), *handler, &info->handlers, error)) {
+ // Text in |error| set by LoadUrlHandler.
+ return false;
+ }
+ }
+
+ extension->SetManifestData(mkeys::kUrlHandlers, info.release());
+
+ return true;
+}
+
+const std::vector<std::string> UrlHandlersParser::Keys() const {
+ return SingleKey(mkeys::kUrlHandlers);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698