web_view_manager.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_WEB_VIEW_MANAGER_H_
  5. #define ATOM_BROWSER_WEB_VIEW_MANAGER_H_
  6. #include <map>
  7. #include "content/public/browser/browser_plugin_guest_manager.h"
  8. namespace atom {
  9. class WebViewManager : public content::BrowserPluginGuestManager {
  10. public:
  11. WebViewManager();
  12. ~WebViewManager() override;
  13. void AddGuest(int guest_instance_id,
  14. int element_instance_id,
  15. content::WebContents* embedder,
  16. content::WebContents* web_contents);
  17. void RemoveGuest(int guest_instance_id);
  18. content::WebContents* GetEmbedder(int guest_instance_id);
  19. static WebViewManager* GetWebViewManager(content::WebContents* web_contents);
  20. protected:
  21. // content::BrowserPluginGuestManager:
  22. content::WebContents* GetGuestByInstanceID(int owner_process_id,
  23. int element_instance_id) override;
  24. bool ForEachGuest(content::WebContents* embedder,
  25. const GuestCallback& callback) override;
  26. private:
  27. struct WebContentsWithEmbedder {
  28. content::WebContents* web_contents;
  29. content::WebContents* embedder;
  30. };
  31. // guest_instance_id => (web_contents, embedder)
  32. std::map<int, WebContentsWithEmbedder> web_contents_embedder_map_;
  33. struct ElementInstanceKey {
  34. int embedder_process_id;
  35. int element_instance_id;
  36. ElementInstanceKey(int embedder_process_id, int element_instance_id)
  37. : embedder_process_id(embedder_process_id),
  38. element_instance_id(element_instance_id) {}
  39. bool operator<(const ElementInstanceKey& other) const {
  40. if (embedder_process_id != other.embedder_process_id)
  41. return embedder_process_id < other.embedder_process_id;
  42. return element_instance_id < other.element_instance_id;
  43. }
  44. bool operator==(const ElementInstanceKey& other) const {
  45. return (embedder_process_id == other.embedder_process_id) &&
  46. (element_instance_id == other.element_instance_id);
  47. }
  48. };
  49. // (embedder_process_id, element_instance_id) => guest_instance_id
  50. std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
  51. DISALLOW_COPY_AND_ASSIGN(WebViewManager);
  52. };
  53. } // namespace atom
  54. #endif // ATOM_BROWSER_WEB_VIEW_MANAGER_H_