IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / browser_plugin / browser_plugin_guest_manager.h
blobb1b6b095886c888305876593942bc3e7729ce3ae
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // A BrowserPluginGuestManager serves as a message router to BrowserPluginGuests
6 // for all guests within a given profile.
7 // Messages are routed to a particular guest instance based on an instance_id.
9 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_
10 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "base/supports_user_data.h"
14 #include "base/values.h"
15 #include "content/common/content_export.h"
16 #include "ipc/ipc_message.h"
18 struct BrowserPluginHostMsg_Attach_Params;
19 struct BrowserPluginHostMsg_ResizeGuest_Params;
20 struct FrameHostMsg_BuffersSwappedACK_Params;
21 class GURL;
23 namespace gfx {
24 class Point;
27 namespace IPC {
28 class Message;
29 } // namespace IPC
31 namespace content {
33 class BrowserPluginGuest;
34 class BrowserPluginHostFactory;
35 class RenderProcessHostImpl;
36 class RenderWidgetHostImpl;
37 class SiteInstance;
38 class WebContents;
39 class WebContentsImpl;
41 // WARNING: All APIs should be guarded with a process ID check like
42 // CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer
43 // processes.
44 class CONTENT_EXPORT BrowserPluginGuestManager :
45 public base::SupportsUserData::Data {
46 public:
47 virtual ~BrowserPluginGuestManager();
49 static BrowserPluginGuestManager* Create();
51 // Overrides factory for testing. Default (NULL) value indicates regular
52 // (non-test) environment.
53 static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
54 content::BrowserPluginGuestManager::factory_ = factory;
57 // Gets the next available instance id.
58 int get_next_instance_id() { return ++next_instance_id_; }
60 // Creates a guest WebContents with the provided |instance_id| and |params|.
61 // If params.src is present, the new guest will also be navigated to the
62 // provided URL. Optionally, the new guest may be attached to a
63 // |guest_opener|, and may be attached to a pre-selected |routing_id|.
64 BrowserPluginGuest* CreateGuest(
65 SiteInstance* embedder_site_instance,
66 int instance_id,
67 const BrowserPluginHostMsg_Attach_Params& params,
68 scoped_ptr<base::DictionaryValue> extra_params);
70 // Returns a BrowserPluginGuest given an |instance_id|. Returns NULL if the
71 // guest wasn't found. If the embedder is not permitted to access the given
72 // |instance_id|, the embedder is killed, and NULL is returned.
73 BrowserPluginGuest* GetGuestByInstanceID(
74 int instance_id,
75 int embedder_render_process_id) const;
77 // Adds a new |guest_web_contents| to the embedder (overridable in test).
78 virtual void AddGuest(int instance_id, WebContentsImpl* guest_web_contents);
80 // Removes the guest with the given |instance_id| from this
81 // BrowserPluginGuestManager.
82 void RemoveGuest(int instance_id);
84 // Returns whether the specified embedder is permitted to access the given
85 // |instance_id|, and kills the embedder if not.
86 bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id,
87 int instance_id) const;
89 typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback;
90 bool ForEachGuest(WebContentsImpl* embedder_web_contents,
91 const GuestCallback& callback);
93 void OnMessageReceived(const IPC::Message& message, int render_process_id);
95 private:
96 friend class TestBrowserPluginGuestManager;
98 BrowserPluginGuestManager();
100 // Returns whether the given embedder process is allowed to access the
101 // provided |guest|.
102 static bool CanEmbedderAccessGuest(int embedder_render_process_id,
103 BrowserPluginGuest* guest);
105 // Returns whether the given embedder process is allowed to use the provided
106 // |instance_id| or access the guest associated with the |instance_id|. If the
107 // embedder can, the method returns true. If the guest does not exist but the
108 // embedder can use that |instance_id|, then it returns true. If the embedder
109 // is not permitted to use that instance ID or access the associated guest,
110 // then it returns false.
111 bool CanEmbedderAccessInstanceID(int embedder_render_process_id,
112 int instance_id) const;
114 // Returns an existing SiteInstance if the current profile has a guest of the
115 // given |guest_site|.
116 SiteInstance* GetGuestSiteInstance(const GURL& guest_site);
118 // Message handlers.
119 void OnUnhandledSwapBuffersACK(
120 int instance_id,
121 const FrameHostMsg_BuffersSwappedACK_Params& params);
123 // Static factory instance (always NULL outside of tests).
124 static BrowserPluginHostFactory* factory_;
126 // Contains guests' WebContents, mapping from their instance ids.
127 typedef std::map<int, WebContentsImpl*> GuestInstanceMap;
128 GuestInstanceMap guest_web_contents_by_instance_id_;
129 int next_instance_id_;
131 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuestManager);
134 } // namespace content
136 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_