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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest_manager.cc

Issue 261013005: BrowserPlugin: Move CreateGuest to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_simplify_api
Patch Set: Removed AddGuest/RemoveGuest from content API! w00t! Created 6 years, 7 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
6 6
7 #include "content/browser/browser_plugin/browser_plugin_guest.h" 7 #include "content/browser/browser_plugin/browser_plugin_guest.h"
8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 int BrowserPluginGuestManager::GetNextInstanceID() { 64 int BrowserPluginGuestManager::GetNextInstanceID() {
65 if (!GetDelegate()) 65 if (!GetDelegate())
66 return 0; 66 return 0;
67 return GetDelegate()->GetNextInstanceID(); 67 return GetDelegate()->GetNextInstanceID();
68 } 68 }
69 69
70 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( 70 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest(
71 SiteInstance* embedder_site_instance, 71 SiteInstance* embedder_site_instance,
72 int instance_id, 72 int instance_id,
73 const BrowserPluginHostMsg_Attach_Params& params, 73 const StorageInfo& storage_info,
74 scoped_ptr<base::DictionaryValue> extra_params) { 74 scoped_ptr<base::DictionaryValue> extra_params) {
75 RenderProcessHost* embedder_process_host = 75 if (!GetDelegate())
76 embedder_site_instance->GetProcess();
77 // Validate that the partition id coming from the renderer is valid UTF-8,
78 // since we depend on this in other parts of the code, such as FilePath
79 // creation. If the validation fails, treat it as a bad message and kill the
80 // renderer process.
81 if (!IsStringUTF8(params.storage_partition_id)) {
82 content::RecordAction(
83 base::UserMetricsAction("BadMessageTerminate_BPGM"));
84 base::KillProcess(
85 embedder_process_host->GetHandle(),
86 content::RESULT_CODE_KILLED_BAD_MESSAGE, false);
87 return NULL; 76 return NULL;
88 } 77 WebContents* guest_web_contents =
78 GetDelegate()->CreateGuest(embedder_site_instance,
79 instance_id,
80 storage_info,
81 extra_params.Pass());
89 82
90 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); 83 return static_cast<WebContentsImpl*>(guest_web_contents)->
91 const std::string& host = embedder_site_url.host(); 84 GetBrowserPluginGuest();
92
93 std::string url_encoded_partition = net::EscapeQueryParamValue(
94 params.storage_partition_id, false);
95 // The SiteInstance of a given webview tag is based on the fact that it's
96 // a guest process in addition to which platform application the tag
97 // belongs to and what storage partition is in use, rather than the URL
98 // that the tag is being navigated to.
99 GURL guest_site(base::StringPrintf("%s://%s/%s?%s",
100 kGuestScheme,
101 host.c_str(),
102 params.persist_storage ? "persist" : "",
103 url_encoded_partition.c_str()));
104
105 // If we already have a webview tag in the same app using the same storage
106 // partition, we should use the same SiteInstance so the existing tag and
107 // the new tag can script each other.
108 SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site);
109 if (!guest_site_instance) {
110 // Create the SiteInstance in a new BrowsingInstance, which will ensure
111 // that webview tags are also not allowed to send messages across
112 // different partitions.
113 guest_site_instance = SiteInstance::CreateForURL(
114 embedder_site_instance->GetBrowserContext(), guest_site);
115 }
116
117 return WebContentsImpl::CreateGuest(
118 embedder_site_instance->GetBrowserContext(),
119 guest_site_instance,
120 instance_id,
121 extra_params.Pass());
122 } 85 }
123 86
124 static void BrowserPluginGuestByInstanceIDCallback( 87 static void BrowserPluginGuestByInstanceIDCallback(
125 const BrowserPluginGuestManager::GuestByInstanceIDCallback& callback, 88 const BrowserPluginGuestManager::GuestByInstanceIDCallback& callback,
126 WebContents* guest_web_contents) { 89 WebContents* guest_web_contents) {
127 if (!guest_web_contents) { 90 if (!guest_web_contents) {
128 callback.Run(NULL); 91 callback.Run(NULL);
129 return; 92 return;
130 } 93 }
131 callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)-> 94 callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)->
132 GetBrowserPluginGuest()); 95 GetBrowserPluginGuest());
133 } 96 }
134 97
135 void BrowserPluginGuestManager::MaybeGetGuestByInstanceIDOrKill( 98 void BrowserPluginGuestManager::MaybeGetGuestByInstanceIDOrKill(
136 int instance_id, 99 int instance_id,
137 int embedder_render_process_id, 100 int embedder_render_process_id,
138 const GuestByInstanceIDCallback& callback) const { 101 const GuestByInstanceIDCallback& callback) const {
139 if (!GetDelegate()) 102 if (!GetDelegate())
140 return; 103 return;
141 104
142 GetDelegate()->MaybeGetGuestByInstanceIDOrKill( 105 GetDelegate()->MaybeGetGuestByInstanceIDOrKill(
143 instance_id, 106 instance_id,
144 embedder_render_process_id, 107 embedder_render_process_id,
145 base::Bind(&BrowserPluginGuestByInstanceIDCallback, 108 base::Bind(&BrowserPluginGuestByInstanceIDCallback,
146 callback)); 109 callback));
147 } 110 }
148 111
149 void BrowserPluginGuestManager::AddGuest(int instance_id,
150 WebContents* guest_web_contents) {
151 if (!GetDelegate())
152 return;
153 GetDelegate()->AddGuest(instance_id, guest_web_contents);
154 }
155
156 void BrowserPluginGuestManager::RemoveGuest(int instance_id) {
157 if (!GetDelegate())
158 return;
159 GetDelegate()->RemoveGuest(instance_id);
160 }
161
162 static void BrowserPluginGuestMessageCallback(const IPC::Message& message, 112 static void BrowserPluginGuestMessageCallback(const IPC::Message& message,
163 BrowserPluginGuest* guest) { 113 BrowserPluginGuest* guest) {
164 if (!guest) 114 if (!guest)
165 return; 115 return;
166 guest->OnMessageReceivedFromEmbedder(message); 116 guest->OnMessageReceivedFromEmbedder(message);
167 } 117 }
168 118
169 void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message, 119 void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message,
170 int render_process_id) { 120 int render_process_id) {
171 DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)); 121 DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message));
172 int instance_id = 0; 122 int instance_id = 0;
173 // All allowed messages must have instance_id as their first parameter. 123 // All allowed messages must have instance_id as their first parameter.
174 PickleIterator iter(message); 124 PickleIterator iter(message);
175 bool success = iter.ReadInt(&instance_id); 125 bool success = iter.ReadInt(&instance_id);
176 DCHECK(success); 126 DCHECK(success);
177 MaybeGetGuestByInstanceIDOrKill(instance_id, 127 MaybeGetGuestByInstanceIDOrKill(instance_id,
178 render_process_id, 128 render_process_id,
179 base::Bind(&BrowserPluginGuestMessageCallback, 129 base::Bind(&BrowserPluginGuestMessageCallback,
180 message)); 130 message));
181 } 131 }
182 132
183 SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance(
184 const GURL& guest_site) {
185 if (!GetDelegate())
186 return NULL;
187 return GetDelegate()->GetGuestSiteInstance(guest_site);
188 }
189
190 static bool BrowserPluginGuestCallback( 133 static bool BrowserPluginGuestCallback(
191 const BrowserPluginGuestManager::GuestCallback& callback, 134 const BrowserPluginGuestManager::GuestCallback& callback,
192 WebContents* guest_web_contents) { 135 WebContents* guest_web_contents) {
193 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents) 136 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)
194 ->GetBrowserPluginGuest()); 137 ->GetBrowserPluginGuest());
195 } 138 }
196 139
197 bool BrowserPluginGuestManager::ForEachGuest( 140 bool BrowserPluginGuestManager::ForEachGuest(
198 WebContents* embedder_web_contents, const GuestCallback& callback) { 141 WebContents* embedder_web_contents, const GuestCallback& callback) {
199 if (!GetDelegate()) 142 if (!GetDelegate())
200 return false; 143 return false;
201 return GetDelegate()->ForEachGuest(embedder_web_contents, 144 return GetDelegate()->ForEachGuest(embedder_web_contents,
202 base::Bind(&BrowserPluginGuestCallback, 145 base::Bind(&BrowserPluginGuestCallback,
203 callback)); 146 callback));
204 } 147 }
205 148
206 } // namespace content 149 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698