manifest_url_handlers.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_
  5. #define EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_
  6. #include <string>
  7. #include <vector>
  8. #include "extensions/common/extension.h"
  9. #include "extensions/common/manifest_handler.h"
  10. namespace base {
  11. class DictionaryValue;
  12. }
  13. namespace extensions {
  14. // A structure to hold various URLs like devtools_page, homepage_url, etc
  15. // that may be specified in the manifest of an extension.
  16. struct ManifestURL : public Extension::ManifestData {
  17. GURL url_;
  18. // Returns the value of a URL key for an extension, or an empty URL if unset.
  19. static const GURL& Get(const Extension* extension, const std::string& key);
  20. // Returns the Homepage URL for this extension.
  21. // If homepage_url was not specified in the manifest,
  22. // this returns the Google Gallery URL. For third-party extensions,
  23. // this returns a blank GURL.
  24. // See also: GetManifestHomePageURL(), SpecifiedHomepageURL()
  25. static const GURL GetHomepageURL(const Extension* extension);
  26. // Returns true if the extension specified a valid home page url in the
  27. // manifest.
  28. static bool SpecifiedHomepageURL(const Extension* extension);
  29. // Returns the homepage specified by the extension in its manifest, if it
  30. // specifies a homepage. Otherwise, returns an empty url.
  31. // See also: GetHomepageURL()
  32. static const GURL GetManifestHomePageURL(const Extension* extension);
  33. // Returns the Chrome Web Store URL for this extension if it is hosted in the
  34. // webstore; otherwise returns an empty url.
  35. // See also: GetHomepageURL()
  36. static const GURL GetWebStoreURL(const Extension* extension);
  37. // Returns the Update URL for this extension.
  38. static const GURL& GetUpdateURL(const Extension* extension);
  39. // Returns true if this extension's update URL is the extension gallery.
  40. static bool UpdatesFromGallery(const Extension* extension);
  41. static bool UpdatesFromGallery(const base::DictionaryValue* manifest);
  42. // Returns the About Page for this extension.
  43. static const GURL& GetAboutPage(const Extension* extension);
  44. // Returns the webstore page URL for this extension.
  45. static const GURL GetDetailsURL(const Extension* extension);
  46. };
  47. // Parses the "homepage_url" manifest key.
  48. class HomepageURLHandler : public ManifestHandler {
  49. public:
  50. HomepageURLHandler();
  51. HomepageURLHandler(const HomepageURLHandler&) = delete;
  52. HomepageURLHandler& operator=(const HomepageURLHandler&) = delete;
  53. ~HomepageURLHandler() override;
  54. bool Parse(Extension* extension, std::u16string* error) override;
  55. private:
  56. base::span<const char* const> Keys() const override;
  57. };
  58. // Parses the "update_url" manifest key.
  59. class UpdateURLHandler : public ManifestHandler {
  60. public:
  61. UpdateURLHandler();
  62. UpdateURLHandler(const UpdateURLHandler&) = delete;
  63. UpdateURLHandler& operator=(const UpdateURLHandler&) = delete;
  64. ~UpdateURLHandler() override;
  65. bool Parse(Extension* extension, std::u16string* error) override;
  66. private:
  67. base::span<const char* const> Keys() const override;
  68. };
  69. // Parses the "about_page" manifest key.
  70. // TODO(sashab): Make this and any other similar handlers extend from the same
  71. // abstract class, URLManifestHandler, which has pure virtual methods for
  72. // detecting the required URL type (relative or absolute) and abstracts the
  73. // URL parsing logic away.
  74. class AboutPageHandler : public ManifestHandler {
  75. public:
  76. AboutPageHandler();
  77. AboutPageHandler(const AboutPageHandler&) = delete;
  78. AboutPageHandler& operator=(const AboutPageHandler&) = delete;
  79. ~AboutPageHandler() override;
  80. bool Parse(Extension* extension, std::u16string* error) override;
  81. bool Validate(const Extension* extension,
  82. std::string* error,
  83. std::vector<InstallWarning>* warnings) const override;
  84. private:
  85. base::span<const char* const> Keys() const override;
  86. };
  87. } // namespace extensions
  88. #endif // EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_