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| is owned by an extension or Chrome App. |
| 77 bool IsOwnedByExtension(GuestViewBase* guest); |
| 78 |
70 int GetNextInstanceID(); | 79 int GetNextInstanceID(); |
71 int GetGuestInstanceIDForElementID( | 80 int GetGuestInstanceIDForElementID( |
72 int owner_process_id, | 81 int owner_process_id, |
73 int element_instance_id); | 82 int element_instance_id); |
74 | 83 |
75 template <typename T> | 84 template <typename T> |
76 void RegisterGuestViewType() { | 85 void RegisterGuestViewType() { |
77 auto it = guest_view_registry_.find(T::Type); | 86 auto it = guest_view_registry_.find(T::Type); |
78 DCHECK(it == guest_view_registry_.end()); | 87 DCHECK(it == guest_view_registry_.end()); |
79 guest_view_registry_[T::Type] = base::Bind(&T::Create); | 88 guest_view_registry_[T::Type] = base::Bind(&T::Create); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 125 |
117 // Creates a guest of the provided |view_type|. | 126 // Creates a guest of the provided |view_type|. |
118 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, | 127 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, |
119 const std::string& view_type); | 128 const std::string& view_type); |
120 | 129 |
121 // Adds GuestView types to the GuestView registry. | 130 // Adds GuestView types to the GuestView registry. |
122 void RegisterGuestViewTypes(); | 131 void RegisterGuestViewTypes(); |
123 | 132 |
124 // Indicates whether the provided |guest| can be used in the context it has | 133 // Indicates whether the provided |guest| can be used in the context it has |
125 // been created. | 134 // been created. |
126 bool IsGuestAvailableToContext(GuestViewBase* guest, | 135 bool IsGuestAvailableToContext(GuestViewBase* guest); |
127 std::string* owner_extension_id); | |
128 | 136 |
129 content::WebContents* GetGuestByInstanceID(int guest_instance_id); | 137 content::WebContents* GetGuestByInstanceID(int guest_instance_id); |
130 | 138 |
131 bool CanEmbedderAccessInstanceIDMaybeKill( | 139 bool CanEmbedderAccessInstanceIDMaybeKill( |
132 int embedder_render_process_id, | 140 int embedder_render_process_id, |
133 int guest_instance_id); | 141 int guest_instance_id); |
134 | 142 |
135 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, | 143 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, |
136 int guest_instance_id); | 144 int guest_instance_id); |
137 | 145 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // RemoveGuest. | 190 // RemoveGuest. |
183 // This is used so that we don't have store all removed instance IDs in | 191 // This is used so that we don't have store all removed instance IDs in |
184 // |removed_instance_ids_|. | 192 // |removed_instance_ids_|. |
185 int last_instance_id_removed_; | 193 int last_instance_id_removed_; |
186 // The remaining instance IDs that are greater than | 194 // The remaining instance IDs that are greater than |
187 // |last_instance_id_removed_| are kept here. | 195 // |last_instance_id_removed_| are kept here. |
188 std::set<int> removed_instance_ids_; | 196 std::set<int> removed_instance_ids_; |
189 | 197 |
190 content::BrowserContext* context_; | 198 content::BrowserContext* context_; |
191 | 199 |
| 200 scoped_ptr<guestview::GuestViewManagerDelegate> delegate_; |
| 201 |
192 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 202 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
193 }; | 203 }; |
194 | 204 |
195 } // namespace extensions | 205 } // namespace extensions |
196 | 206 |
197 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 207 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
OLD | NEW |