parsing_utils.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2022 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_SHARED_HIGHLIGHTING_IOS_PARSING_UTILS_H_
  5. #define COMPONENTS_SHARED_HIGHLIGHTING_IOS_PARSING_UTILS_H_
  6. #import <string>
  7. #import <CoreGraphics/CoreGraphics.h>
  8. #import "third_party/abseil-cpp/absl/types/optional.h"
  9. #import "url/gurl.h"
  10. namespace base {
  11. class Value;
  12. } // namespace base
  13. namespace web {
  14. class WebState;
  15. } // namespace web
  16. namespace shared_highlighting {
  17. // Returns whether |value| is a dictionary value, and is not empty.
  18. BOOL IsValidDictValue(const base::Value* value);
  19. // Attempts to parse the given |value| into a CGRect. If |value| does not map
  20. // into the expected structure, an empty absl::optional instance will be
  21. // returned.
  22. absl::optional<CGRect> ParseRect(const base::Value* value);
  23. // Attempts to parse the given |url_value| into a GURL instance. If |url_value|
  24. // is empty or invalid, an empty absl::optional instance will be returned.
  25. absl::optional<GURL> ParseURL(const std::string* url_value);
  26. // Converts a given |web_view_rect| into its browser coordinates counterpart.
  27. // Uses the given |web_state| to do the conversion.
  28. CGRect ConvertToBrowserRect(CGRect web_view_rect, web::WebState* web_state);
  29. } // namespace shared_highlighting
  30. #endif // COMPONENTS_SHARED_HIGHLIGHTING_IOS_PARSING_UTILS_H_