intent_filter.cc 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "components/arc/intent_helper/intent_filter.h"
  5. #include <algorithm>
  6. #include <utility>
  7. #include "ash/components/arc/mojom/intent_helper.mojom.h"
  8. #include "base/compiler_specific.h"
  9. #include "base/strings/string_util.h"
  10. #include "components/arc/intent_helper/intent_constants.h"
  11. #include "url/gurl.h"
  12. namespace arc {
  13. IntentFilter::IntentFilter() = default;
  14. IntentFilter::IntentFilter(IntentFilter&& other) = default;
  15. IntentFilter::IntentFilter(
  16. const std::string& package_name,
  17. std::vector<std::string> actions,
  18. std::vector<IntentFilter::AuthorityEntry> authorities,
  19. std::vector<IntentFilter::PatternMatcher> paths,
  20. std::vector<std::string> schemes,
  21. std::vector<std::string> mime_types)
  22. : package_name_(package_name),
  23. actions_(std::move(actions)),
  24. authorities_(std::move(authorities)),
  25. schemes_(std::move(schemes)),
  26. mime_types_(std::move(mime_types)) {
  27. // In order to register a path we need to have at least one authority.
  28. if (!authorities_.empty())
  29. paths_ = std::move(paths);
  30. }
  31. IntentFilter::IntentFilter(
  32. const std::string& package_name,
  33. const std::string& activity_name,
  34. const std::string& activity_label,
  35. std::vector<std::string> actions,
  36. std::vector<IntentFilter::AuthorityEntry> authorities,
  37. std::vector<IntentFilter::PatternMatcher> paths,
  38. std::vector<std::string> schemes,
  39. std::vector<std::string> mime_types)
  40. : package_name_(package_name),
  41. activity_name_(activity_name),
  42. activity_label_(activity_label),
  43. actions_(std::move(actions)),
  44. authorities_(std::move(authorities)),
  45. schemes_(std::move(schemes)),
  46. mime_types_(std::move(mime_types)) {
  47. // In order to register a path we need to have at least one authority.
  48. if (!authorities_.empty())
  49. paths_ = std::move(paths);
  50. }
  51. IntentFilter::~IntentFilter() = default;
  52. IntentFilter& IntentFilter::operator=(IntentFilter&& other) = default;
  53. IntentFilter::AuthorityEntry::AuthorityEntry() = default;
  54. IntentFilter::AuthorityEntry::AuthorityEntry(
  55. IntentFilter::AuthorityEntry&& other) = default;
  56. IntentFilter::AuthorityEntry& IntentFilter::AuthorityEntry::operator=(
  57. IntentFilter::AuthorityEntry&& other) = default;
  58. IntentFilter::AuthorityEntry::AuthorityEntry(const std::string& host, int port)
  59. : host_(host), port_(port) {
  60. // Wildcards are only allowed at the front of the host string.
  61. wild_ = !host_.empty() && host_[0] == '*';
  62. if (wild_) {
  63. host_ = host_.substr(1);
  64. }
  65. // TODO(kenobi): Not i18n-friendly. Figure out how to correctly deal with
  66. // IDNs.
  67. host_ = base::ToLowerASCII(host_);
  68. }
  69. IntentFilter::PatternMatcher::PatternMatcher() = default;
  70. IntentFilter::PatternMatcher::PatternMatcher(
  71. IntentFilter::PatternMatcher&& other) = default;
  72. IntentFilter::PatternMatcher::PatternMatcher(const std::string& pattern,
  73. mojom::PatternType match_type)
  74. : pattern_(pattern), match_type_(match_type) {}
  75. IntentFilter::PatternMatcher& IntentFilter::PatternMatcher::operator=(
  76. IntentFilter::PatternMatcher&& other) = default;
  77. } // namespace arc