| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
| 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 // Returns the guest WebContents associated with the given |guest_instance_id| | 43 // Returns the guest WebContents associated with the given |guest_instance_id| |
| 44 // if the provided |embedder_render_process_id| is allowed to access it. | 44 // if the provided |embedder_render_process_id| is allowed to access it. |
| 45 // If the embedder is not allowed access, the embedder will be killed, and | 45 // If the embedder is not allowed access, the embedder will be killed, and |
| 46 // this method will return NULL. If no WebContents exists with the given | 46 // this method will return NULL. If no WebContents exists with the given |
| 47 // instance ID, then NULL will also be returned. | 47 // instance ID, then NULL will also be returned. |
| 48 content::WebContents* GetGuestByInstanceIDSafely( | 48 content::WebContents* GetGuestByInstanceIDSafely( |
| 49 int guest_instance_id, | 49 int guest_instance_id, |
| 50 int embedder_render_process_id); | 50 int embedder_render_process_id); |
| 51 | 51 |
| 52 int GetNextInstanceID(); |
| 53 |
| 54 content::WebContents* CreateGuest( |
| 55 const std::string& view_type, |
| 56 const std::string& embedder_extension_id, |
| 57 int embedder_render_process_id, |
| 58 const base::DictionaryValue& create_params); |
| 59 |
| 60 content::WebContents* CreateGuestWithWebContentsParams( |
| 61 const std::string& view_type, |
| 62 const std::string& embedder_extension_id, |
| 63 int embedder_render_process_id, |
| 64 const content::WebContents::CreateParams& create_params); |
| 65 |
| 66 content::SiteInstance* GetGuestSiteInstance( |
| 67 const GURL& guest_site); |
| 68 |
| 52 // BrowserPluginGuestManager implementation. | 69 // BrowserPluginGuestManager implementation. |
| 53 virtual content::WebContents* CreateGuest( | |
| 54 content::SiteInstance* embedder_site_instance, | |
| 55 int instance_id, | |
| 56 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; | |
| 57 virtual int GetNextInstanceID() OVERRIDE; | |
| 58 virtual void MaybeGetGuestByInstanceIDOrKill( | 70 virtual void MaybeGetGuestByInstanceIDOrKill( |
| 59 int guest_instance_id, | 71 int guest_instance_id, |
| 60 int embedder_render_process_id, | 72 int embedder_render_process_id, |
| 61 const GuestByInstanceIDCallback& callback) OVERRIDE; | 73 const GuestByInstanceIDCallback& callback) OVERRIDE; |
| 62 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, | 74 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, |
| 63 const GuestCallback& callback) OVERRIDE; | 75 const GuestCallback& callback) OVERRIDE; |
| 64 | 76 |
| 65 protected: | 77 protected: |
| 66 friend class GuestViewBase; | 78 friend class GuestViewBase; |
| 67 friend class GuestWebContentsObserver; | 79 friend class GuestWebContentsObserver; |
| 68 friend class guestview::TestGuestViewManager; | 80 friend class guestview::TestGuestViewManager; |
| 69 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); | 81 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); |
| 70 | 82 |
| 71 // Can be overriden in tests. | 83 // Can be overriden in tests. |
| 72 virtual void AddGuest(int guest_instance_id, | 84 virtual void AddGuest(int guest_instance_id, |
| 73 content::WebContents* guest_web_contents); | 85 content::WebContents* guest_web_contents); |
| 74 | 86 |
| 75 void RemoveGuest(int guest_instance_id); | 87 void RemoveGuest(int guest_instance_id); |
| 76 | 88 |
| 77 content::SiteInstance* GetGuestSiteInstance( | |
| 78 const GURL& guest_site); | |
| 79 | |
| 80 content::WebContents* GetGuestByInstanceID( | 89 content::WebContents* GetGuestByInstanceID( |
| 81 int guest_instance_id, | 90 int guest_instance_id, |
| 82 int embedder_render_process_id); | 91 int embedder_render_process_id); |
| 83 | 92 |
| 84 bool CanEmbedderAccessInstanceIDMaybeKill( | 93 bool CanEmbedderAccessInstanceIDMaybeKill( |
| 85 int embedder_render_process_id, | 94 int embedder_render_process_id, |
| 86 int guest_instance_id); | 95 int guest_instance_id); |
| 87 | 96 |
| 88 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, | 97 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, |
| 89 int guest_instance_id); | 98 int guest_instance_id); |
| 90 | 99 |
| 91 // Returns true if |guest_instance_id| can be used to add a new guest to this | 100 // Returns true if |guest_instance_id| can be used to add a new guest to this |
| 92 // manager. | 101 // manager. |
| 93 // We disallow adding new guest with instance IDs that were previously removed | 102 // We disallow adding new guest with instance IDs that were previously removed |
| 94 // from this manager using RemoveGuest. | 103 // from this manager using RemoveGuest. |
| 95 bool CanUseGuestInstanceID(int guest_instance_id); | 104 bool CanUseGuestInstanceID(int guest_instance_id); |
| 96 | 105 |
| 97 static bool CanEmbedderAccessGuest(int embedder_render_process_id, | |
| 98 GuestViewBase* guest); | |
| 99 | |
| 100 // Static factory instance (always NULL for non-test). | 106 // Static factory instance (always NULL for non-test). |
| 101 static GuestViewManagerFactory* factory_; | 107 static GuestViewManagerFactory* factory_; |
| 102 | 108 |
| 103 // Contains guests' WebContents, mapping from their instance ids. | 109 // Contains guests' WebContents, mapping from their instance ids. |
| 104 typedef std::map<int, content::WebContents*> GuestInstanceMap; | 110 typedef std::map<int, content::WebContents*> GuestInstanceMap; |
| 105 GuestInstanceMap guest_web_contents_by_instance_id_; | 111 GuestInstanceMap guest_web_contents_by_instance_id_; |
| 106 | 112 |
| 107 int current_instance_id_; | 113 int current_instance_id_; |
| 108 | 114 |
| 109 // Any instance ID whose number not greater than this was removed via | 115 // Any instance ID whose number not greater than this was removed via |
| 110 // RemoveGuest. | 116 // RemoveGuest. |
| 111 // This is used so that we don't have store all removed instance IDs in | 117 // This is used so that we don't have store all removed instance IDs in |
| 112 // |removed_instance_ids_|. | 118 // |removed_instance_ids_|. |
| 113 int last_instance_id_removed_; | 119 int last_instance_id_removed_; |
| 114 // The remaining instance IDs that are greater than | 120 // The remaining instance IDs that are greater than |
| 115 // |last_instance_id_removed_| are kept here. | 121 // |last_instance_id_removed_| are kept here. |
| 116 std::set<int> removed_instance_ids_; | 122 std::set<int> removed_instance_ids_; |
| 117 | 123 |
| 118 content::BrowserContext* context_; | 124 content::BrowserContext* context_; |
| 119 | 125 |
| 120 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 126 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
| 121 }; | 127 }; |
| 122 | 128 |
| 123 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 129 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
| OLD | NEW |