intent_filter.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2016 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 COMPONENTS_ARC_INTENT_HELPER_INTENT_FILTER_H_
  5. #define COMPONENTS_ARC_INTENT_HELPER_INTENT_FILTER_H_
  6. #include <string>
  7. #include <vector>
  8. class GURL;
  9. namespace arc {
  10. namespace mojom {
  11. enum class PatternType;
  12. } // namespace mojom
  13. // A chrome-side implementation of Android's IntentFilter class. This is used
  14. // to approximate the intent filtering and determine whether a given URL is
  15. // likely to be handled by any android-side apps, prior to making expensive IPC
  16. // calls.
  17. class IntentFilter {
  18. public:
  19. // A helper class for handling matching of the host part of the URL.
  20. class AuthorityEntry {
  21. public:
  22. AuthorityEntry();
  23. AuthorityEntry(AuthorityEntry&& other);
  24. AuthorityEntry(const std::string& host, int port);
  25. AuthorityEntry(const AuthorityEntry&) = delete;
  26. AuthorityEntry& operator=(const AuthorityEntry&) = delete;
  27. AuthorityEntry& operator=(AuthorityEntry&& other);
  28. const std::string& host() const { return host_; }
  29. int port() const { return port_; }
  30. bool wild() const { return wild_; }
  31. private:
  32. std::string host_;
  33. bool wild_;
  34. int port_;
  35. };
  36. // A helper class for handling matching of various patterns in the URL.
  37. class PatternMatcher {
  38. public:
  39. PatternMatcher();
  40. PatternMatcher(PatternMatcher&& other);
  41. PatternMatcher(const std::string& pattern, mojom::PatternType match_type);
  42. PatternMatcher(const PatternMatcher&) = delete;
  43. PatternMatcher& operator=(const PatternMatcher&) = delete;
  44. PatternMatcher& operator=(PatternMatcher&& other);
  45. const std::string& pattern() const { return pattern_; }
  46. mojom::PatternType match_type() const { return match_type_; }
  47. private:
  48. std::string pattern_;
  49. mojom::PatternType match_type_;
  50. };
  51. IntentFilter();
  52. IntentFilter(IntentFilter&& other);
  53. IntentFilter(const std::string& package_name,
  54. std::vector<std::string> actions,
  55. std::vector<AuthorityEntry> authorities,
  56. std::vector<PatternMatcher> paths,
  57. std::vector<std::string> schemes,
  58. std::vector<std::string> mime_types);
  59. IntentFilter(const std::string& package_name,
  60. const std::string& activity_name,
  61. const std::string& activity_label,
  62. std::vector<std::string> actions,
  63. std::vector<IntentFilter::AuthorityEntry> authorities,
  64. std::vector<IntentFilter::PatternMatcher> paths,
  65. std::vector<std::string> schemes,
  66. std::vector<std::string> mime_types);
  67. IntentFilter(const IntentFilter&) = delete;
  68. IntentFilter& operator=(const IntentFilter&) = delete;
  69. IntentFilter& operator=(IntentFilter&& other);
  70. ~IntentFilter();
  71. bool Match(const GURL& url) const;
  72. const std::string& package_name() const { return package_name_; }
  73. const std::string& activity_name() const { return activity_name_; }
  74. const std::string& activity_label() const { return activity_label_; }
  75. const std::vector<std::string>& actions() const { return actions_; }
  76. const std::vector<AuthorityEntry>& authorities() const {
  77. return authorities_;
  78. }
  79. const std::vector<PatternMatcher>& paths() const { return paths_; }
  80. const std::vector<std::string>& schemes() const { return schemes_; }
  81. const std::vector<std::string>& mime_types() const { return mime_types_; }
  82. private:
  83. std::string package_name_;
  84. std::string activity_name_;
  85. std::string activity_label_;
  86. std::vector<std::string> actions_;
  87. std::vector<AuthorityEntry> authorities_;
  88. std::vector<PatternMatcher> paths_;
  89. std::vector<std::string> schemes_;
  90. std::vector<std::string> mime_types_;
  91. };
  92. } // namespace arc
  93. #endif // COMPONENTS_ARC_INTENT_HELPER_INTENT_FILTER_H_