| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/lazy_instance.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "content/public/browser/browser_plugin_guest_manager.h" | |
| 14 #include "content/public/browser/site_instance.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 | |
| 17 class GuestViewBase; | |
| 18 class GuestViewManagerFactory; | |
| 19 class GURL; | |
| 20 | |
| 21 namespace content { | |
| 22 class BrowserContext; | |
| 23 class WebContents; | |
| 24 } // namespace content | |
| 25 | |
| 26 class GuestViewManager : public content::BrowserPluginGuestManager, | |
| 27 public base::SupportsUserData::Data { | |
| 28 public: | |
| 29 explicit GuestViewManager(content::BrowserContext* context); | |
| 30 virtual ~GuestViewManager(); | |
| 31 | |
| 32 static GuestViewManager* FromBrowserContext(content::BrowserContext* context); | |
| 33 | |
| 34 // Overrides factory for testing. Default (NULL) value indicates regular | |
| 35 // (non-test) environment. | |
| 36 static void set_factory_for_testing(GuestViewManagerFactory* factory) { | |
| 37 GuestViewManager::factory_ = factory; | |
| 38 } | |
| 39 // Returns the guest WebContents associated with the given |guest_instance_id| | |
| 40 // if the provided |embedder_render_process_id| is allowed to access it. | |
| 41 // If the embedder is not allowed access, the embedder will be killed, and | |
| 42 // this method will return NULL. If no WebContents exists with the given | |
| 43 // instance ID, then NULL will also be returned. | |
| 44 content::WebContents* GetGuestByInstanceIDSafely( | |
| 45 int guest_instance_id, | |
| 46 int embedder_render_process_id); | |
| 47 | |
| 48 int GetNextInstanceID(); | |
| 49 | |
| 50 typedef base::Callback<void(content::WebContents*)> | |
| 51 WebContentsCreatedCallback; | |
| 52 void CreateGuest(const std::string& view_type, | |
| 53 const std::string& embedder_extension_id, | |
| 54 content::WebContents* embedder_web_contents, | |
| 55 const base::DictionaryValue& create_params, | |
| 56 const WebContentsCreatedCallback& callback); | |
| 57 | |
| 58 content::WebContents* CreateGuestWithWebContentsParams( | |
| 59 const std::string& view_type, | |
| 60 const std::string& embedder_extension_id, | |
| 61 int embedder_render_process_id, | |
| 62 const content::WebContents::CreateParams& create_params); | |
| 63 | |
| 64 content::SiteInstance* GetGuestSiteInstance( | |
| 65 const GURL& guest_site); | |
| 66 | |
| 67 // BrowserPluginGuestManager implementation. | |
| 68 virtual void MaybeGetGuestByInstanceIDOrKill( | |
| 69 int guest_instance_id, | |
| 70 int embedder_render_process_id, | |
| 71 const GuestByInstanceIDCallback& callback) OVERRIDE; | |
| 72 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, | |
| 73 const GuestCallback& callback) OVERRIDE; | |
| 74 | |
| 75 protected: | |
| 76 friend class GuestViewBase; | |
| 77 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); | |
| 78 | |
| 79 // Can be overriden in tests. | |
| 80 virtual void AddGuest(int guest_instance_id, | |
| 81 content::WebContents* guest_web_contents); | |
| 82 | |
| 83 void RemoveGuest(int guest_instance_id); | |
| 84 | |
| 85 content::WebContents* GetGuestByInstanceID(int guest_instance_id); | |
| 86 | |
| 87 bool CanEmbedderAccessInstanceIDMaybeKill( | |
| 88 int embedder_render_process_id, | |
| 89 int guest_instance_id); | |
| 90 | |
| 91 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, | |
| 92 int guest_instance_id); | |
| 93 | |
| 94 // Returns true if |guest_instance_id| can be used to add a new guest to this | |
| 95 // manager. | |
| 96 // We disallow adding new guest with instance IDs that were previously removed | |
| 97 // from this manager using RemoveGuest. | |
| 98 bool CanUseGuestInstanceID(int guest_instance_id); | |
| 99 | |
| 100 // Static factory instance (always NULL for non-test). | |
| 101 static GuestViewManagerFactory* factory_; | |
| 102 | |
| 103 // Contains guests' WebContents, mapping from their instance ids. | |
| 104 typedef std::map<int, content::WebContents*> GuestInstanceMap; | |
| 105 GuestInstanceMap guest_web_contents_by_instance_id_; | |
| 106 | |
| 107 int current_instance_id_; | |
| 108 | |
| 109 // Any instance ID whose number not greater than this was removed via | |
| 110 // RemoveGuest. | |
| 111 // This is used so that we don't have store all removed instance IDs in | |
| 112 // |removed_instance_ids_|. | |
| 113 int last_instance_id_removed_; | |
| 114 // The remaining instance IDs that are greater than | |
| 115 // |last_instance_id_removed_| are kept here. | |
| 116 std::set<int> removed_instance_ids_; | |
| 117 | |
| 118 content::BrowserContext* context_; | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | |
| 121 }; | |
| 122 | |
| 123 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | |
| OLD | NEW |