| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/extensions/options_page_handler.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 11 #include "chrome/common/extensions/manifest_url_info.h" |
| 12 #include "extensions/common/error_utils.h" |
| 13 |
| 14 namespace keys = extension_manifest_keys; |
| 15 namespace errors = extension_manifest_errors; |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 OptionsPageHandler::OptionsPageHandler() { |
| 20 } |
| 21 |
| 22 OptionsPageHandler::~OptionsPageHandler() { |
| 23 } |
| 24 |
| 25 bool OptionsPageHandler::Parse(const base::Value* value, |
| 26 Extension* extension, |
| 27 string16* error) { |
| 28 scoped_ptr<ManifestURLInfo> info(new ManifestURLInfo); |
| 29 std::string options_str; |
| 30 if (!value->GetAsString(&options_str)) { |
| 31 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); |
| 32 return false; |
| 33 } |
| 34 |
| 35 if (extension->is_hosted_app()) { |
| 36 // hosted apps require an absolute URL. |
| 37 GURL options_url(options_str); |
| 38 if (!options_url.is_valid() || |
| 39 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) { |
| 40 *error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp); |
| 41 return false; |
| 42 } |
| 43 info->url_ = options_url; |
| 44 } else { |
| 45 GURL absolute(options_str); |
| 46 if (absolute.is_valid()) { |
| 47 *error = ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage); |
| 48 return false; |
| 49 } |
| 50 info->url_ = extension->GetResourceURL(options_str); |
| 51 if (!info->url_.is_valid()) { |
| 52 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); |
| 53 return false; |
| 54 } |
| 55 } |
| 56 |
| 57 extension->SetManifestData(keys::kOptionsPage, info.release()); |
| 58 return true; |
| 59 } |
| 60 |
| 61 } // namespace extensions |
| OLD | NEW |