| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 // A BrowserPluginGuestManager serves as a message router to BrowserPluginGuests | |
| 6 // for all guests within a given profile. | |
| 7 // Messages are routed to a particular guest instance based on an instance_id. | |
| 8 | |
| 9 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | |
| 10 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/supports_user_data.h" | |
| 14 #include "base/values.h" | |
| 15 #include "content/common/content_export.h" | |
| 16 #include "content/public/browser/browser_plugin_guest_manager_delegate.h" | |
| 17 #include "ipc/ipc_message.h" | |
| 18 | |
| 19 struct BrowserPluginHostMsg_Attach_Params; | |
| 20 struct BrowserPluginHostMsg_ResizeGuest_Params; | |
| 21 class GURL; | |
| 22 | |
| 23 namespace gfx { | |
| 24 class Point; | |
| 25 } | |
| 26 | |
| 27 namespace IPC { | |
| 28 class Message; | |
| 29 } // namespace IPC | |
| 30 | |
| 31 namespace content { | |
| 32 | |
| 33 class BrowserContext; | |
| 34 class BrowserPluginGuest; | |
| 35 class BrowserPluginHostFactory; | |
| 36 class RenderWidgetHostImpl; | |
| 37 class SiteInstance; | |
| 38 class WebContents; | |
| 39 | |
| 40 // WARNING: All APIs should be guarded with a process ID check like | |
| 41 // CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer | |
| 42 // processes. | |
| 43 class CONTENT_EXPORT BrowserPluginGuestManager : | |
| 44 public base::SupportsUserData::Data { | |
| 45 public: | |
| 46 virtual ~BrowserPluginGuestManager(); | |
| 47 | |
| 48 static BrowserPluginGuestManager* FromBrowserContext(BrowserContext* context); | |
| 49 | |
| 50 BrowserPluginGuestManagerDelegate* GetDelegate() const; | |
| 51 | |
| 52 static BrowserPluginGuestManager* Create(BrowserContext* context); | |
| 53 | |
| 54 // Overrides factory for testing. Default (NULL) value indicates regular | |
| 55 // (non-test) environment. | |
| 56 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | |
| 57 content::BrowserPluginGuestManager::factory_ = factory; | |
| 58 } | |
| 59 | |
| 60 // Gets the next available instance id. 0 is considered an invalid instance | |
| 61 // ID. | |
| 62 int GetNextInstanceID(); | |
| 63 | |
| 64 // Creates a guest WebContents with the provided |instance_id| and |params|. | |
| 65 // If params.src is present, the new guest will also be navigated to the | |
| 66 // provided URL. Optionally, the new guest may be attached to a | |
| 67 // |guest_opener|, and may be attached to a pre-selected |routing_id|. | |
| 68 virtual BrowserPluginGuest* CreateGuest( | |
| 69 SiteInstance* embedder_site_instance, | |
| 70 int instance_id, | |
| 71 const StorageInfo& storage_info, | |
| 72 scoped_ptr<base::DictionaryValue> extra_params); | |
| 73 | |
| 74 typedef base::Callback<void(BrowserPluginGuest*)> GuestByInstanceIDCallback; | |
| 75 void MaybeGetGuestByInstanceIDOrKill( | |
| 76 int instance_id, | |
| 77 int embedder_render_process_id, | |
| 78 const GuestByInstanceIDCallback& callback) const; | |
| 79 | |
| 80 typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback; | |
| 81 bool ForEachGuest(WebContents* embedder_web_contents, | |
| 82 const GuestCallback& callback); | |
| 83 | |
| 84 void OnMessageReceived(const IPC::Message& message, int render_process_id); | |
| 85 | |
| 86 private: | |
| 87 friend class TestBrowserPluginGuestManager; | |
| 88 | |
| 89 explicit BrowserPluginGuestManager(BrowserContext* context); | |
| 90 | |
| 91 // Static factory instance (always NULL outside of tests). | |
| 92 static BrowserPluginHostFactory* factory_; | |
| 93 | |
| 94 // The BrowserContext in which this manager this stored. | |
| 95 BrowserContext* context_; | |
| 96 | |
| 97 // Contains guests' WebContents, mapping from their instance ids. | |
| 98 typedef std::map<int, WebContents*> GuestInstanceMap; | |
| 99 GuestInstanceMap guest_web_contents_by_instance_id_; | |
| 100 int next_instance_id_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuestManager); | |
| 103 }; | |
| 104 | |
| 105 } // namespace content | |
| 106 | |
| 107 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | |
| OLD | NEW |