web_view_manager.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 SHELL_BROWSER_WEB_VIEW_MANAGER_H_
  5. #define SHELL_BROWSER_WEB_VIEW_MANAGER_H_
  6. #include <map>
  7. #include "content/public/browser/browser_plugin_guest_manager.h"
  8. namespace electron {
  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. bool ForEachGuest(content::WebContents* embedder,
  23. const GuestCallback& callback) override;
  24. private:
  25. struct WebContentsWithEmbedder {
  26. content::WebContents* web_contents;
  27. content::WebContents* embedder;
  28. };
  29. // guest_instance_id => (web_contents, embedder)
  30. std::map<int, WebContentsWithEmbedder> web_contents_embedder_map_;
  31. struct ElementInstanceKey {
  32. int embedder_process_id;
  33. int element_instance_id;
  34. ElementInstanceKey(int embedder_process_id, int element_instance_id)
  35. : embedder_process_id(embedder_process_id),
  36. element_instance_id(element_instance_id) {}
  37. bool operator<(const ElementInstanceKey& other) const {
  38. if (embedder_process_id != other.embedder_process_id)
  39. return embedder_process_id < other.embedder_process_id;
  40. return element_instance_id < other.element_instance_id;
  41. }
  42. bool operator==(const ElementInstanceKey& other) const {
  43. return (embedder_process_id == other.embedder_process_id) &&
  44. (element_instance_id == other.element_instance_id);
  45. }
  46. };
  47. // (embedder_process_id, element_instance_id) => guest_instance_id
  48. std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
  49. DISALLOW_COPY_AND_ASSIGN(WebViewManager);
  50. };
  51. } // namespace electron
  52. #endif // SHELL_BROWSER_WEB_VIEW_MANAGER_H_