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

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

Issue 334923002: Remove ContentBrowserClient::GuestWebContentsAttached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_adview
Patch Set: Hopefully fixed tests Created 6 years, 6 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 CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_
6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "content/public/browser/browser_plugin_guest_manager.h" 13 #include "content/public/browser/browser_plugin_guest_manager.h"
14 #include "content/public/browser/site_instance.h" 14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 16
17 class GuestViewBase; 17 class GuestViewBase;
18 class GuestViewManagerFactory;
18 class GuestWebContentsObserver; 19 class GuestWebContentsObserver;
19 class GURL; 20 class GURL;
20 21
21 namespace content { 22 namespace content {
22 class BrowserContext; 23 class BrowserContext;
23 } // namespace content 24 } // namespace content
24 25
26 namespace guestview {
27 class TestGuestViewManager;
28 } // namespace guestview
29
25 class GuestViewManager : public content::BrowserPluginGuestManager, 30 class GuestViewManager : public content::BrowserPluginGuestManager,
26 public base::SupportsUserData::Data { 31 public base::SupportsUserData::Data {
27 public: 32 public:
28 explicit GuestViewManager(content::BrowserContext* context); 33 explicit GuestViewManager(content::BrowserContext* context);
29 virtual ~GuestViewManager(); 34 virtual ~GuestViewManager();
30 35
31 static GuestViewManager* FromBrowserContext(content::BrowserContext* context); 36 static GuestViewManager* FromBrowserContext(content::BrowserContext* context);
32 37
38 // Overrides factory for testing. Default (NULL) value indicates regular
39 // (non-test) environment.
40 static void set_factory_for_testing(GuestViewManagerFactory* factory) {
41 GuestViewManager::factory_ = factory;
42 }
33 // Returns the guest WebContents associated with the given |guest_instance_id| 43 // Returns the guest WebContents associated with the given |guest_instance_id|
34 // if the provided |embedder_render_process_id| is allowed to access it. 44 // if the provided |embedder_render_process_id| is allowed to access it.
35 // If the embedder is not allowed access, the embedder will be killed, and 45 // If the embedder is not allowed access, the embedder will be killed, and
36 // this method will return NULL. If no WebContents exists with the given 46 // this method will return NULL. If no WebContents exists with the given
37 // instance ID, then NULL will also be returned. 47 // instance ID, then NULL will also be returned.
38 content::WebContents* GetGuestByInstanceIDSafely( 48 content::WebContents* GetGuestByInstanceIDSafely(
39 int guest_instance_id, 49 int guest_instance_id,
40 int embedder_render_process_id); 50 int embedder_render_process_id);
41 51
42 // BrowserPluginGuestManager implementation. 52 // BrowserPluginGuestManager implementation.
43 virtual content::WebContents* CreateGuest( 53 virtual content::WebContents* CreateGuest(
44 content::SiteInstance* embedder_site_instance, 54 content::SiteInstance* embedder_site_instance,
45 int instance_id, 55 int instance_id,
46 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; 56 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE;
47 virtual int GetNextInstanceID() OVERRIDE; 57 virtual int GetNextInstanceID() OVERRIDE;
48 virtual void MaybeGetGuestByInstanceIDOrKill( 58 virtual void MaybeGetGuestByInstanceIDOrKill(
49 int guest_instance_id, 59 int guest_instance_id,
50 int embedder_render_process_id, 60 int embedder_render_process_id,
51 const GuestByInstanceIDCallback& callback) OVERRIDE; 61 const GuestByInstanceIDCallback& callback) OVERRIDE;
52 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, 62 virtual bool ForEachGuest(content::WebContents* embedder_web_contents,
53 const GuestCallback& callback) OVERRIDE; 63 const GuestCallback& callback) OVERRIDE;
54 64
55 private: 65 protected:
56 friend class GuestViewBase; 66 friend class GuestViewBase;
57 friend class GuestWebContentsObserver; 67 friend class GuestWebContentsObserver;
58 friend class TestGuestViewManager; 68 friend class guestview::TestGuestViewManager;
59 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); 69 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove);
60 70
61 void AddGuest(int guest_instance_id, 71 // Can be overriden in tests.
62 content::WebContents* guest_web_contents); 72 virtual void AddGuest(int guest_instance_id,
73 content::WebContents* guest_web_contents);
63 74
64 void RemoveGuest(int guest_instance_id); 75 void RemoveGuest(int guest_instance_id);
65 76
66 content::SiteInstance* GetGuestSiteInstance( 77 content::SiteInstance* GetGuestSiteInstance(
67 const GURL& guest_site); 78 const GURL& guest_site);
68 79
69 content::WebContents* GetGuestByInstanceID( 80 content::WebContents* GetGuestByInstanceID(
70 int guest_instance_id, 81 int guest_instance_id,
71 int embedder_render_process_id); 82 int embedder_render_process_id);
72 83
73 bool CanEmbedderAccessInstanceIDMaybeKill( 84 bool CanEmbedderAccessInstanceIDMaybeKill(
74 int embedder_render_process_id, 85 int embedder_render_process_id,
75 int guest_instance_id); 86 int guest_instance_id);
76 87
77 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, 88 bool CanEmbedderAccessInstanceID(int embedder_render_process_id,
78 int guest_instance_id); 89 int guest_instance_id);
79 90
80 // Returns true if |guest_instance_id| can be used to add a new guest to this 91 // Returns true if |guest_instance_id| can be used to add a new guest to this
81 // manager. 92 // manager.
82 // We disallow adding new guest with instance IDs that were previously removed 93 // We disallow adding new guest with instance IDs that were previously removed
83 // from this manager using RemoveGuest. 94 // from this manager using RemoveGuest.
84 bool CanUseGuestInstanceID(int guest_instance_id); 95 bool CanUseGuestInstanceID(int guest_instance_id);
85 96
86 static bool CanEmbedderAccessGuest(int embedder_render_process_id, 97 static bool CanEmbedderAccessGuest(int embedder_render_process_id,
87 GuestViewBase* guest); 98 GuestViewBase* guest);
88 99
100 // Static factory instance (always NULL for non-test).
101 static GuestViewManagerFactory* factory_;
102
89 // Contains guests' WebContents, mapping from their instance ids. 103 // Contains guests' WebContents, mapping from their instance ids.
90 typedef std::map<int, content::WebContents*> GuestInstanceMap; 104 typedef std::map<int, content::WebContents*> GuestInstanceMap;
91 GuestInstanceMap guest_web_contents_by_instance_id_; 105 GuestInstanceMap guest_web_contents_by_instance_id_;
92 106
93 int current_instance_id_; 107 int current_instance_id_;
94 108
95 // Any instance ID whose number not greater than this was removed via 109 // Any instance ID whose number not greater than this was removed via
96 // RemoveGuest. 110 // RemoveGuest.
97 // This is used so that we don't have store all removed instance IDs in 111 // This is used so that we don't have store all removed instance IDs in
98 // |removed_instance_ids_|. 112 // |removed_instance_ids_|.
99 int last_instance_id_removed_; 113 int last_instance_id_removed_;
100 // The remaining instance IDs that are greater than 114 // The remaining instance IDs that are greater than
101 // |last_instance_id_removed_| are kept here. 115 // |last_instance_id_removed_| are kept here.
102 std::set<int> removed_instance_ids_; 116 std::set<int> removed_instance_ids_;
103 117
104 content::BrowserContext* context_; 118 content::BrowserContext* context_;
105 119
106 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); 120 DISALLOW_COPY_AND_ASSIGN(GuestViewManager);
107 }; 121 };
108 122
109 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 123 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/guest_view_base.cc ('k') | chrome/browser/guest_view/guest_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698