web_frames_manager_impl.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2018 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 IOS_WEB_JS_MESSAGING_WEB_FRAMES_MANAGER_IMPL_H_
  5. #define IOS_WEB_JS_MESSAGING_WEB_FRAMES_MANAGER_IMPL_H_
  6. #import "ios/web/public/js_messaging/web_frames_manager.h"
  7. #include <map>
  8. #include "base/memory/weak_ptr.h"
  9. namespace web {
  10. class WebFrame;
  11. class WebFramesManagerImpl : public WebFramesManager {
  12. public:
  13. explicit WebFramesManagerImpl();
  14. WebFramesManagerImpl(const WebFramesManagerImpl&) = delete;
  15. WebFramesManagerImpl& operator=(const WebFramesManagerImpl&) = delete;
  16. ~WebFramesManagerImpl() override;
  17. // Adds |frame| to the list of web frames. A frame with the same frame ID must
  18. // not already be registered). Returns |false| and |frame| will be ignored if
  19. // |frame| is a main frame and a main frame has already been set.
  20. bool AddFrame(std::unique_ptr<WebFrame> frame);
  21. // Removes the web frame with |frame_id|, if one exists, from the list of
  22. // associated web frames. If the frame manager does not contain a frame with
  23. // |frame_id|, operation is a no-op.
  24. void RemoveFrameWithId(const std::string& frame_id);
  25. // WebFramesManager overrides.
  26. std::set<WebFrame*> GetAllWebFrames() override;
  27. WebFrame* GetMainWebFrame() override;
  28. WebFrame* GetFrameWithId(const std::string& frame_id) override;
  29. private:
  30. // List of pointers to all web frames.
  31. std::map<std::string, std::unique_ptr<WebFrame>> web_frames_;
  32. // Reference to the current main web frame.
  33. WebFrame* main_web_frame_ = nullptr;
  34. base::WeakPtrFactory<WebFramesManagerImpl> weak_factory_;
  35. };
  36. } // namespace web
  37. #endif // IOS_WEB_JS_MESSAGING_WEB_FRAMES_MANAGER_IMPL_H_