 Chromium Code Reviews
 Chromium Code Reviews Issue 258373002:
  Towards moving guest management to chrome: Introduce GuestViewManager  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 258373002:
  Towards moving guest management to chrome: Introduce GuestViewManager  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 // A BrowserPluginGuestManager serves as a message router to BrowserPluginGuests | 5 // A BrowserPluginGuestManager serves as a message router to BrowserPluginGuests | 
| 6 // for all guests within a given profile. | 6 // for all guests within a given profile. | 
| 7 // Messages are routed to a particular guest instance based on an instance_id. | 7 // Messages are routed to a particular guest instance based on an instance_id. | 
| 8 | 8 | 
| 9 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | 9 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | 
| 10 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | 10 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | 
| 11 | 11 | 
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" | 
| 13 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" | 
| 14 #include "base/values.h" | 14 #include "base/values.h" | 
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" | 
| 16 #include "content/public/browser/browser_plugin_guest_manager_delegate.h" | |
| 16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" | 
| 17 | 18 | 
| 18 struct BrowserPluginHostMsg_Attach_Params; | 19 struct BrowserPluginHostMsg_Attach_Params; | 
| 19 struct BrowserPluginHostMsg_ResizeGuest_Params; | 20 struct BrowserPluginHostMsg_ResizeGuest_Params; | 
| 20 class GURL; | 21 class GURL; | 
| 21 | 22 | 
| 22 namespace gfx { | 23 namespace gfx { | 
| 23 class Point; | 24 class Point; | 
| 24 } | 25 } | 
| 25 | 26 | 
| 26 namespace IPC { | 27 namespace IPC { | 
| 27 class Message; | 28 class Message; | 
| 28 } // namespace IPC | 29 } // namespace IPC | 
| 29 | 30 | 
| 30 namespace content { | 31 namespace content { | 
| 31 | 32 | 
| 33 class BrowserContext; | |
| 32 class BrowserPluginGuest; | 34 class BrowserPluginGuest; | 
| 33 class BrowserPluginHostFactory; | 35 class BrowserPluginHostFactory; | 
| 34 class RenderWidgetHostImpl; | 36 class RenderWidgetHostImpl; | 
| 35 class SiteInstance; | 37 class SiteInstance; | 
| 36 class WebContents; | 38 class WebContents; | 
| 37 class WebContentsImpl; | |
| 38 | 39 | 
| 39 // WARNING: All APIs should be guarded with a process ID check like | 40 // WARNING: All APIs should be guarded with a process ID check like | 
| 40 // CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer | 41 // CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer | 
| 41 // processes. | 42 // processes. | 
| 42 class CONTENT_EXPORT BrowserPluginGuestManager : | 43 class CONTENT_EXPORT BrowserPluginGuestManager : | 
| 43 public base::SupportsUserData::Data { | 44 public base::SupportsUserData::Data { | 
| 44 public: | 45 public: | 
| 45 virtual ~BrowserPluginGuestManager(); | 46 virtual ~BrowserPluginGuestManager(); | 
| 46 | 47 | 
| 47 static BrowserPluginGuestManager* Create(); | 48 static BrowserPluginGuestManager* FromBrowserContext(BrowserContext* context); | 
| 49 | |
| 50 BrowserPluginGuestManagerDelegate* GetDelegate() const; | |
| 51 | |
| 52 static BrowserPluginGuestManager* Create(BrowserContext* context); | |
| 48 | 53 | 
| 49 // Overrides factory for testing. Default (NULL) value indicates regular | 54 // Overrides factory for testing. Default (NULL) value indicates regular | 
| 50 // (non-test) environment. | 55 // (non-test) environment. | 
| 51 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | 56 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | 
| 52 content::BrowserPluginGuestManager::factory_ = factory; | 57 content::BrowserPluginGuestManager::factory_ = factory; | 
| 53 } | 58 } | 
| 54 | 59 | 
| 55 // Gets the next available instance id. | 60 // Gets the next available instance id. | 
| 
lazyboy
2014/05/01 20:06:59
Can you also add a comment saying 0 is an invalid
 
Fady Samuel
2014/05/01 21:05:28
Done.
 | |
| 56 int get_next_instance_id() { return ++next_instance_id_; } | 61 int GetNextInstanceID(); | 
| 57 | 62 | 
| 58 // Creates a guest WebContents with the provided |instance_id| and |params|. | 63 // Creates a guest WebContents with the provided |instance_id| and |params|. | 
| 59 // If params.src is present, the new guest will also be navigated to the | 64 // If params.src is present, the new guest will also be navigated to the | 
| 60 // provided URL. Optionally, the new guest may be attached to a | 65 // provided URL. Optionally, the new guest may be attached to a | 
| 61 // |guest_opener|, and may be attached to a pre-selected |routing_id|. | 66 // |guest_opener|, and may be attached to a pre-selected |routing_id|. | 
| 62 BrowserPluginGuest* CreateGuest( | 67 BrowserPluginGuest* CreateGuest( | 
| 63 SiteInstance* embedder_site_instance, | 68 SiteInstance* embedder_site_instance, | 
| 64 int instance_id, | 69 int instance_id, | 
| 65 const BrowserPluginHostMsg_Attach_Params& params, | 70 const BrowserPluginHostMsg_Attach_Params& params, | 
| 66 scoped_ptr<base::DictionaryValue> extra_params); | 71 scoped_ptr<base::DictionaryValue> extra_params); | 
| 67 | 72 | 
| 68 // Returns a BrowserPluginGuest given an |instance_id|. Returns NULL if the | 73 // Returns a BrowserPluginGuest given an |instance_id|. Returns NULL if the | 
| 69 // guest wasn't found. If the embedder is not permitted to access the given | 74 // guest wasn't found. If the embedder is not permitted to access the given | 
| 70 // |instance_id|, the embedder is killed, and NULL is returned. | 75 // |instance_id|, the embedder is killed, and NULL is returned. | 
| 71 BrowserPluginGuest* GetGuestByInstanceID( | 76 BrowserPluginGuest* GetGuestByInstanceID( | 
| 72 int instance_id, | 77 int instance_id, | 
| 73 int embedder_render_process_id) const; | 78 int embedder_render_process_id) const; | 
| 74 | 79 | 
| 75 // Adds a new |guest_web_contents| to the embedder (overridable in test). | 80 // Adds a new |guest_web_contents| to the embedder (overridable in test). | 
| 76 virtual void AddGuest(int instance_id, WebContentsImpl* guest_web_contents); | 81 virtual void AddGuest(int instance_id, WebContents* guest_web_contents); | 
| 77 | 82 | 
| 78 // Removes the guest with the given |instance_id| from this | 83 // Removes the guest with the given |instance_id| from this | 
| 79 // BrowserPluginGuestManager. | 84 // BrowserPluginGuestManager. | 
| 80 void RemoveGuest(int instance_id); | 85 void RemoveGuest(int instance_id); | 
| 81 | 86 | 
| 82 // Returns whether the specified embedder is permitted to access the given | 87 // Returns whether the specified embedder is permitted to access the given | 
| 83 // |instance_id|, and kills the embedder if not. | 88 // |instance_id|, and kills the embedder if not. | 
| 84 bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id, | 89 bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id, | 
| 85 int instance_id) const; | 90 int instance_id) const; | 
| 86 | 91 | 
| 87 typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback; | 92 typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback; | 
| 88 bool ForEachGuest(WebContentsImpl* embedder_web_contents, | 93 bool ForEachGuest(WebContents* embedder_web_contents, | 
| 89 const GuestCallback& callback); | 94 const GuestCallback& callback); | 
| 90 | 95 | 
| 96 typedef BrowserPluginGuestManagerDelegate::InstanceIDResponseCallback | |
| 97 InstanceIDResponseCallback; | |
| 98 void RequestInstanceID(const std::string& src, | |
| 99 const InstanceIDResponseCallback& callback); | |
| 100 | |
| 91 void OnMessageReceived(const IPC::Message& message, int render_process_id); | 101 void OnMessageReceived(const IPC::Message& message, int render_process_id); | 
| 92 | 102 | 
| 93 private: | 103 private: | 
| 94 friend class TestBrowserPluginGuestManager; | 104 friend class TestBrowserPluginGuestManager; | 
| 95 | 105 | 
| 96 BrowserPluginGuestManager(); | 106 explicit BrowserPluginGuestManager(BrowserContext* context); | 
| 97 | |
| 98 // Returns whether the given embedder process is allowed to access the | |
| 99 // provided |guest|. | |
| 100 static bool CanEmbedderAccessGuest(int embedder_render_process_id, | |
| 101 BrowserPluginGuest* guest); | |
| 102 | |
| 103 // Returns whether the given embedder process is allowed to use the provided | |
| 104 // |instance_id| or access the guest associated with the |instance_id|. If the | |
| 105 // embedder can, the method returns true. If the guest does not exist but the | |
| 106 // embedder can use that |instance_id|, then it returns true. If the embedder | |
| 107 // is not permitted to use that instance ID or access the associated guest, | |
| 108 // then it returns false. | |
| 109 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, | |
| 110 int instance_id) const; | |
| 111 | 107 | 
| 112 // Returns an existing SiteInstance if the current profile has a guest of the | 108 // Returns an existing SiteInstance if the current profile has a guest of the | 
| 113 // given |guest_site|. | 109 // given |guest_site|. | 
| 114 SiteInstance* GetGuestSiteInstance(const GURL& guest_site); | 110 SiteInstance* GetGuestSiteInstance(const GURL& guest_site); | 
| 115 | 111 | 
| 116 // Static factory instance (always NULL outside of tests). | 112 // Static factory instance (always NULL outside of tests). | 
| 117 static BrowserPluginHostFactory* factory_; | 113 static BrowserPluginHostFactory* factory_; | 
| 118 | 114 | 
| 119 // Contains guests' WebContents, mapping from their instance ids. | 115 // The BrowserContext in which this manager this stored. | 
| 120 typedef std::map<int, WebContentsImpl*> GuestInstanceMap; | 116 BrowserContext* context_; | 
| 121 GuestInstanceMap guest_web_contents_by_instance_id_; | |
| 122 int next_instance_id_; | |
| 123 | 117 | 
| 124 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuestManager); | 118 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuestManager); | 
| 125 }; | 119 }; | 
| 126 | 120 | 
| 127 } // namespace content | 121 } // namespace content | 
| 128 | 122 | 
| 129 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | 123 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_ | 
| 130 | |
| OLD | NEW |