Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: extensions/browser/guest_view/guest_view_manager.h

Issue 1066563006: GuestView: Move GuestViewManager extension dependencies to ExtensionsGuestViewManagerDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extensions_guest_view_message_filter
Patch Set: Fixed NavigateGuest Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
98 content::WebContents* GetGuestByInstanceID( 107 content::WebContents* GetGuestByInstanceID(
99 int owner_process_id, 108 int owner_process_id,
100 int element_instance_id) override; 109 int element_instance_id) override;
101 bool ForEachGuest(content::WebContents* owner_web_contents, 110 bool ForEachGuest(content::WebContents* owner_web_contents,
102 const GuestCallback& callback) override; 111 const GuestCallback& callback) override;
103 content::WebContents* GetFullPageGuest( 112 content::WebContents* GetFullPageGuest(
104 content::WebContents* embedder_web_contents) override; 113 content::WebContents* embedder_web_contents) override;
105 114
106 protected: 115 protected:
107 friend class GuestViewBase; 116 friend class GuestViewBase;
108 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); 117 friend class GuestViewEvent;
109 118
110 // Can be overriden in tests. 119 // Can be overriden in tests.
111 virtual void AddGuest(int guest_instance_id, 120 virtual void AddGuest(int guest_instance_id,
112 content::WebContents* guest_web_contents); 121 content::WebContents* guest_web_contents);
113 122
114 // Can be overriden in tests. 123 // Can be overriden in tests.
115 virtual void RemoveGuest(int guest_instance_id); 124 virtual void RemoveGuest(int guest_instance_id);
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); 136
137 // Dispatches the event with |name| with the provided |args| to the embedder
138 // of the given |guest| with |instance_id| for routing.
139 void DispatchEvent(const std::string& event_name,
140 scoped_ptr<base::DictionaryValue> args,
141 GuestViewBase* guest,
142 int instance_id);
128 143
129 content::WebContents* GetGuestByInstanceID(int guest_instance_id); 144 content::WebContents* GetGuestByInstanceID(int guest_instance_id);
130 145
131 bool CanEmbedderAccessInstanceIDMaybeKill( 146 bool CanEmbedderAccessInstanceIDMaybeKill(
132 int embedder_render_process_id, 147 int embedder_render_process_id,
133 int guest_instance_id); 148 int guest_instance_id);
134 149
135 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, 150 bool CanEmbedderAccessInstanceID(int embedder_render_process_id,
136 int guest_instance_id); 151 int guest_instance_id);
137 152
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // RemoveGuest. 197 // RemoveGuest.
183 // This is used so that we don't have store all removed instance IDs in 198 // This is used so that we don't have store all removed instance IDs in
184 // |removed_instance_ids_|. 199 // |removed_instance_ids_|.
185 int last_instance_id_removed_; 200 int last_instance_id_removed_;
186 // The remaining instance IDs that are greater than 201 // The remaining instance IDs that are greater than
187 // |last_instance_id_removed_| are kept here. 202 // |last_instance_id_removed_| are kept here.
188 std::set<int> removed_instance_ids_; 203 std::set<int> removed_instance_ids_;
189 204
190 content::BrowserContext* context_; 205 content::BrowserContext* context_;
191 206
207 scoped_ptr<guestview::GuestViewManagerDelegate> delegate_;
208
192 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); 209 DISALLOW_COPY_AND_ASSIGN(GuestViewManager);
193 }; 210 };
194 211
195 } // namespace extensions 212 } // namespace extensions
196 213
197 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 214 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_event.cc ('k') | extensions/browser/guest_view/guest_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698