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

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

Issue 11726002: Move the parsing of 'update_url' & 'options_page' URLs out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url_parse
Patch Set: Created 8 years 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/options_page_handler.cc
diff --git a/chrome/common/extensions/options_page_handler.cc b/chrome/common/extensions/options_page_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8eb7a6fccf2169c2bd92d4ef2608b542edaaa9d9
--- /dev/null
+++ b/chrome/common/extensions/options_page_handler.cc
@@ -0,0 +1,61 @@
+// 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/options_page_handler.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 "chrome/common/extensions/manifest_url_info.h"
+#include "extensions/common/error_utils.h"
+
+namespace keys = extension_manifest_keys;
+namespace errors = extension_manifest_errors;
+
+namespace extensions {
+
+OptionsPageHandler::OptionsPageHandler() {
+}
+
+OptionsPageHandler::~OptionsPageHandler() {
+}
+
+bool OptionsPageHandler::Parse(const base::Value* value,
+ Extension* extension,
+ string16* error) {
+ scoped_ptr<ManifestURLInfo> info(new ManifestURLInfo);
+ std::string options_str;
+ if (!value->GetAsString(&options_str)) {
+ *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
+ return false;
+ }
+
+ if (extension->is_hosted_app()) {
+ // hosted apps require an absolute URL.
+ GURL options_url(options_str);
+ if (!options_url.is_valid() ||
+ !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) {
+ *error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp);
+ return false;
+ }
+ info->url_ = options_url;
+ } else {
+ GURL absolute(options_str);
+ if (absolute.is_valid()) {
+ *error = ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage);
+ return false;
+ }
+ info->url_ = extension->GetResourceURL(options_str);
+ if (!info->url_.is_valid()) {
+ *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
+ return false;
+ }
+ }
+
+ extension->SetManifestData(keys::kOptionsPage, info.release());
+ return true;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698