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

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: Added missing file 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
25 class GuestViewManager : public content::BrowserPluginGuestManager, 26 class GuestViewManager : public content::BrowserPluginGuestManager,
26 public base::SupportsUserData::Data { 27 public base::SupportsUserData::Data {
27 public: 28 public:
28 explicit GuestViewManager(content::BrowserContext* context); 29 explicit GuestViewManager(content::BrowserContext* context);
29 virtual ~GuestViewManager(); 30 virtual ~GuestViewManager();
30 31
31 static GuestViewManager* FromBrowserContext(content::BrowserContext* context); 32 static GuestViewManager* FromBrowserContext(content::BrowserContext* context);
32 33
34 // Overrides factory for testing. Default (NULL) value indicates regular
35 // (non-test) environment.
36 static void set_factory_for_testing(GuestViewManagerFactory* factory) {
37 GuestViewManager::factory_ = factory;
38 }
33 // Returns the guest WebContents associated with the given |guest_instance_id| 39 // Returns the guest WebContents associated with the given |guest_instance_id|
34 // if the provided |embedder_render_process_id| is allowed to access it. 40 // 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 41 // 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 42 // this method will return NULL. If no WebContents exists with the given
37 // instance ID, then NULL will also be returned. 43 // instance ID, then NULL will also be returned.
38 content::WebContents* GetGuestByInstanceIDSafely( 44 content::WebContents* GetGuestByInstanceIDSafely(
39 int guest_instance_id, 45 int guest_instance_id,
40 int embedder_render_process_id); 46 int embedder_render_process_id);
41 47
42 // BrowserPluginGuestManager implementation. 48 // BrowserPluginGuestManager implementation.
43 virtual content::WebContents* CreateGuest( 49 virtual content::WebContents* CreateGuest(
44 content::SiteInstance* embedder_site_instance, 50 content::SiteInstance* embedder_site_instance,
45 int instance_id, 51 int instance_id,
46 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; 52 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE;
47 virtual int GetNextInstanceID() OVERRIDE; 53 virtual int GetNextInstanceID() OVERRIDE;
48 virtual void MaybeGetGuestByInstanceIDOrKill( 54 virtual void MaybeGetGuestByInstanceIDOrKill(
49 int guest_instance_id, 55 int guest_instance_id,
50 int embedder_render_process_id, 56 int embedder_render_process_id,
51 const GuestByInstanceIDCallback& callback) OVERRIDE; 57 const GuestByInstanceIDCallback& callback) OVERRIDE;
52 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, 58 virtual bool ForEachGuest(content::WebContents* embedder_web_contents,
53 const GuestCallback& callback) OVERRIDE; 59 const GuestCallback& callback) OVERRIDE;
54 60
55 private: 61 protected:
56 friend class GuestViewBase; 62 friend class GuestViewBase;
57 friend class GuestWebContentsObserver; 63 friend class GuestWebContentsObserver;
58 friend class TestGuestViewManager; 64 friend class TestGuestViewManager;
59 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); 65 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove);
60 66
61 void AddGuest(int guest_instance_id, 67 // Can be overriden in tests.
62 content::WebContents* guest_web_contents); 68 virtual void AddGuest(int guest_instance_id,
69 content::WebContents* guest_web_contents);
63 70
64 void RemoveGuest(int guest_instance_id); 71 void RemoveGuest(int guest_instance_id);
65 72
66 content::SiteInstance* GetGuestSiteInstance( 73 content::SiteInstance* GetGuestSiteInstance(
67 const GURL& guest_site); 74 const GURL& guest_site);
68 75
69 content::WebContents* GetGuestByInstanceID( 76 content::WebContents* GetGuestByInstanceID(
70 int guest_instance_id, 77 int guest_instance_id,
71 int embedder_render_process_id); 78 int embedder_render_process_id);
72 79
73 bool CanEmbedderAccessInstanceIDMaybeKill( 80 bool CanEmbedderAccessInstanceIDMaybeKill(
74 int embedder_render_process_id, 81 int embedder_render_process_id,
75 int guest_instance_id); 82 int guest_instance_id);
76 83
77 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, 84 bool CanEmbedderAccessInstanceID(int embedder_render_process_id,
78 int guest_instance_id); 85 int guest_instance_id);
79 86
80 // Returns true if |guest_instance_id| can be used to add a new guest to this 87 // Returns true if |guest_instance_id| can be used to add a new guest to this
81 // manager. 88 // manager.
82 // We disallow adding new guest with instance IDs that were previously removed 89 // We disallow adding new guest with instance IDs that were previously removed
83 // from this manager using RemoveGuest. 90 // from this manager using RemoveGuest.
84 bool CanUseGuestInstanceID(int guest_instance_id); 91 bool CanUseGuestInstanceID(int guest_instance_id);
85 92
86 static bool CanEmbedderAccessGuest(int embedder_render_process_id, 93 static bool CanEmbedderAccessGuest(int embedder_render_process_id,
87 GuestViewBase* guest); 94 GuestViewBase* guest);
88 95
96 // Static factory instance (always NULL for non-test).
97 static GuestViewManagerFactory* factory_;
98
89 // Contains guests' WebContents, mapping from their instance ids. 99 // Contains guests' WebContents, mapping from their instance ids.
90 typedef std::map<int, content::WebContents*> GuestInstanceMap; 100 typedef std::map<int, content::WebContents*> GuestInstanceMap;
91 GuestInstanceMap guest_web_contents_by_instance_id_; 101 GuestInstanceMap guest_web_contents_by_instance_id_;
92 102
93 int current_instance_id_; 103 int current_instance_id_;
94 104
95 // Any instance ID whose number not greater than this was removed via 105 // Any instance ID whose number not greater than this was removed via
96 // RemoveGuest. 106 // RemoveGuest.
97 // This is used so that we don't have store all removed instance IDs in 107 // This is used so that we don't have store all removed instance IDs in
98 // |removed_instance_ids_|. 108 // |removed_instance_ids_|.
99 int last_instance_id_removed_; 109 int last_instance_id_removed_;
100 // The remaining instance IDs that are greater than 110 // The remaining instance IDs that are greater than
101 // |last_instance_id_removed_| are kept here. 111 // |last_instance_id_removed_| are kept here.
102 std::set<int> removed_instance_ids_; 112 std::set<int> removed_instance_ids_;
103 113
104 content::BrowserContext* context_; 114 content::BrowserContext* context_;
105 115
106 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); 116 DISALLOW_COPY_AND_ASSIGN(GuestViewManager);
107 }; 117 };
108 118
109 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 119 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698