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 EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "content/public/browser/browser_plugin_guest_manager.h" | 14 #include "content/public/browser/browser_plugin_guest_manager.h" |
15 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
18 class GURL; | 18 class GURL; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class BrowserContext; | 21 class BrowserContext; |
22 class WebContents; | 22 class WebContents; |
23 } // namespace content | 23 } // namespace content |
24 | 24 |
25 namespace guestview { | |
26 class GuestViewManagerDelegate; | |
27 } // namespace guestview | |
28 | |
25 namespace extensions{ | 29 namespace extensions{ |
26 class GuestViewBase; | 30 class GuestViewBase; |
27 class GuestViewManagerFactory; | 31 class GuestViewManagerFactory; |
28 | 32 |
29 class GuestViewManager : public content::BrowserPluginGuestManager, | 33 class GuestViewManager : public content::BrowserPluginGuestManager, |
30 public base::SupportsUserData::Data { | 34 public base::SupportsUserData::Data { |
31 public: | 35 public: |
32 explicit GuestViewManager(content::BrowserContext* context); | 36 GuestViewManager(content::BrowserContext* context, |
37 scoped_ptr<guestview::GuestViewManagerDelegate> delegate); | |
33 ~GuestViewManager() override; | 38 ~GuestViewManager() override; |
34 | 39 |
35 // Returns the GuestViewManager associated with |context|. If one isn't | 40 // Returns the GuestViewManager associated with |context|. If one isn't |
36 // available, then it is created and returned. | 41 // available, then it is created and returned. |
37 static GuestViewManager* FromBrowserContext(content::BrowserContext* context); | 42 static GuestViewManager* CreateWithDelegate( |
43 content::BrowserContext* context, | |
44 scoped_ptr<guestview::GuestViewManagerDelegate> delegate); | |
38 | 45 |
39 // Returns the GuestViewManager associated with |context|. If one isn't | 46 // Returns the GuestViewManager associated with |context|. If one isn't |
40 // available, then nullptr is returned. | 47 // available, then nullptr is returned. |
41 static GuestViewManager* FromBrowserContextIfAvailable( | 48 static GuestViewManager* FromBrowserContext(content::BrowserContext* context); |
42 content::BrowserContext* context); | |
43 | 49 |
44 // Overrides factory for testing. Default (NULL) value indicates regular | 50 // Overrides factory for testing. Default (NULL) value indicates regular |
45 // (non-test) environment. | 51 // (non-test) environment. |
46 static void set_factory_for_testing(GuestViewManagerFactory* factory) { | 52 static void set_factory_for_testing(GuestViewManagerFactory* factory) { |
47 GuestViewManager::factory_ = factory; | 53 GuestViewManager::factory_ = factory; |
48 } | 54 } |
49 // Returns the guest WebContents associated with the given |guest_instance_id| | 55 // Returns the guest WebContents associated with the given |guest_instance_id| |
50 // if the provided |embedder_render_process_id| is allowed to access it. | 56 // if the provided |embedder_render_process_id| is allowed to access it. |
51 // If the embedder is not allowed access, the embedder will be killed, and | 57 // If the embedder is not allowed access, the embedder will be killed, and |
52 // this method will return NULL. If no WebContents exists with the given | 58 // this method will return NULL. If no WebContents exists with the given |
53 // instance ID, then NULL will also be returned. | 59 // instance ID, then NULL will also be returned. |
54 content::WebContents* GetGuestByInstanceIDSafely( | 60 content::WebContents* GetGuestByInstanceIDSafely( |
55 int guest_instance_id, | 61 int guest_instance_id, |
56 int embedder_render_process_id); | 62 int embedder_render_process_id); |
57 | 63 |
58 // Associates the Browser Plugin with |element_instance_id| to a | 64 // Associates the Browser Plugin with |element_instance_id| to a |
59 // guest that has ID of |guest_instance_id| and sets initialization | 65 // guest that has ID of |guest_instance_id| and sets initialization |
60 // parameters, |params| for it. | 66 // parameters, |params| for it. |
61 void AttachGuest(int embedder_process_id, | 67 void AttachGuest(int embedder_process_id, |
62 int element_instance_id, | 68 int element_instance_id, |
63 int guest_instance_id, | 69 int guest_instance_id, |
64 const base::DictionaryValue& attach_params); | 70 const base::DictionaryValue& attach_params); |
65 | 71 |
66 // Removes the association between |element_instance_id| and a guest instance | 72 // Removes the association between |element_instance_id| and a guest instance |
67 // ID if one exists. | 73 // ID if one exists. |
68 void DetachGuest(GuestViewBase* guest); | 74 void DetachGuest(GuestViewBase* guest); |
69 | 75 |
76 // Indicates whether the |guest| provided is owned by an extension or Chrome | |
lazyboy
2015/04/22 15:16:29
nit: "provided" is redundant
Fady Samuel
2015/04/22 23:09:48
Done.
| |
77 // App. | |
78 bool IsOwnedByExtension(GuestViewBase* guest); | |
79 | |
70 int GetNextInstanceID(); | 80 int GetNextInstanceID(); |
71 int GetGuestInstanceIDForElementID( | 81 int GetGuestInstanceIDForElementID( |
72 int owner_process_id, | 82 int owner_process_id, |
73 int element_instance_id); | 83 int element_instance_id); |
74 | 84 |
75 template <typename T> | 85 template <typename T> |
76 void RegisterGuestViewType() { | 86 void RegisterGuestViewType() { |
77 auto it = guest_view_registry_.find(T::Type); | 87 auto it = guest_view_registry_.find(T::Type); |
78 DCHECK(it == guest_view_registry_.end()); | 88 DCHECK(it == guest_view_registry_.end()); |
79 guest_view_registry_[T::Type] = base::Bind(&T::Create); | 89 guest_view_registry_[T::Type] = base::Bind(&T::Create); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 126 |
117 // Creates a guest of the provided |view_type|. | 127 // Creates a guest of the provided |view_type|. |
118 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, | 128 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, |
119 const std::string& view_type); | 129 const std::string& view_type); |
120 | 130 |
121 // Adds GuestView types to the GuestView registry. | 131 // Adds GuestView types to the GuestView registry. |
122 void RegisterGuestViewTypes(); | 132 void RegisterGuestViewTypes(); |
123 | 133 |
124 // Indicates whether the provided |guest| can be used in the context it has | 134 // Indicates whether the provided |guest| can be used in the context it has |
125 // been created. | 135 // been created. |
126 bool IsGuestAvailableToContext(GuestViewBase* guest, | 136 bool IsGuestAvailableToContext(GuestViewBase* guest); |
127 std::string* owner_extension_id); | |
128 | 137 |
129 content::WebContents* GetGuestByInstanceID(int guest_instance_id); | 138 content::WebContents* GetGuestByInstanceID(int guest_instance_id); |
130 | 139 |
131 bool CanEmbedderAccessInstanceIDMaybeKill( | 140 bool CanEmbedderAccessInstanceIDMaybeKill( |
132 int embedder_render_process_id, | 141 int embedder_render_process_id, |
133 int guest_instance_id); | 142 int guest_instance_id); |
134 | 143 |
135 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, | 144 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, |
136 int guest_instance_id); | 145 int guest_instance_id); |
137 | 146 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 // RemoveGuest. | 191 // RemoveGuest. |
183 // This is used so that we don't have store all removed instance IDs in | 192 // This is used so that we don't have store all removed instance IDs in |
184 // |removed_instance_ids_|. | 193 // |removed_instance_ids_|. |
185 int last_instance_id_removed_; | 194 int last_instance_id_removed_; |
186 // The remaining instance IDs that are greater than | 195 // The remaining instance IDs that are greater than |
187 // |last_instance_id_removed_| are kept here. | 196 // |last_instance_id_removed_| are kept here. |
188 std::set<int> removed_instance_ids_; | 197 std::set<int> removed_instance_ids_; |
189 | 198 |
190 content::BrowserContext* context_; | 199 content::BrowserContext* context_; |
191 | 200 |
201 scoped_ptr<guestview::GuestViewManagerDelegate> delegate_; | |
202 | |
192 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 203 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
193 }; | 204 }; |
194 | 205 |
195 } // namespace extensions | 206 } // namespace extensions |
196 | 207 |
197 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 208 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
OLD | NEW |