OLD | NEW |
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 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return webview::kAPINamespace; | 179 return webview::kAPINamespace; |
180 } | 180 } |
181 | 181 |
182 int WebViewGuest::GetTaskPrefix() const { | 182 int WebViewGuest::GetTaskPrefix() const { |
183 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 183 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
184 } | 184 } |
185 | 185 |
186 void WebViewGuest::CreateWebContents( | 186 void WebViewGuest::CreateWebContents( |
187 const std::string& embedder_extension_id, | 187 const std::string& embedder_extension_id, |
188 int embedder_render_process_id, | 188 int embedder_render_process_id, |
| 189 const GURL& embedder_site_url, |
189 const base::DictionaryValue& create_params, | 190 const base::DictionaryValue& create_params, |
190 const WebContentsCreatedCallback& callback) { | 191 const WebContentsCreatedCallback& callback) { |
191 content::RenderProcessHost* embedder_render_process_host = | 192 content::RenderProcessHost* embedder_render_process_host = |
192 content::RenderProcessHost::FromID(embedder_render_process_id); | 193 content::RenderProcessHost::FromID(embedder_render_process_id); |
193 std::string storage_partition_id; | 194 std::string storage_partition_id; |
194 bool persist_storage = false; | 195 bool persist_storage = false; |
195 std::string storage_partition_string; | 196 std::string storage_partition_string; |
196 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); | 197 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); |
197 // Validate that the partition id coming from the renderer is valid UTF-8, | 198 // Validate that the partition id coming from the renderer is valid UTF-8, |
198 // since we depend on this in other parts of the code, such as FilePath | 199 // since we depend on this in other parts of the code, such as FilePath |
199 // creation. If the validation fails, treat it as a bad message and kill the | 200 // creation. If the validation fails, treat it as a bad message and kill the |
200 // renderer process. | 201 // renderer process. |
201 if (!base::IsStringUTF8(storage_partition_id)) { | 202 if (!base::IsStringUTF8(storage_partition_id)) { |
202 content::RecordAction( | 203 content::RecordAction( |
203 base::UserMetricsAction("BadMessageTerminate_BPGM")); | 204 base::UserMetricsAction("BadMessageTerminate_BPGM")); |
204 base::KillProcess( | 205 base::KillProcess( |
205 embedder_render_process_host->GetHandle(), | 206 embedder_render_process_host->GetHandle(), |
206 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 207 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
207 callback.Run(NULL); | 208 callback.Run(NULL); |
208 return; | 209 return; |
209 } | 210 } |
210 std::string url_encoded_partition = net::EscapeQueryParamValue( | 211 std::string url_encoded_partition = net::EscapeQueryParamValue( |
211 storage_partition_id, false); | 212 storage_partition_id, false); |
212 // The SiteInstance of a given webview tag is based on the fact that it's | 213 // The SiteInstance of a given webview tag is based on the fact that it's |
213 // a guest process in addition to which platform application the tag | 214 // a guest process in addition to which platform application or which WebUI |
214 // belongs to and what storage partition is in use, rather than the URL | 215 // page the tag belongs to and what storage partition is in use, rather than |
215 // that the tag is being navigated to. | 216 // the URL that the tag is being navigated to. |
| 217 std::string partition_domain; |
| 218 if (embedder_extension_id.empty()) { |
| 219 DCHECK(content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 220 embedder_render_process_id)); |
| 221 partition_domain = embedder_site_url.host(); |
| 222 } else { |
| 223 partition_domain = embedder_extension_id; |
| 224 } |
216 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 225 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
217 content::kGuestScheme, | 226 content::kGuestScheme, |
218 embedder_extension_id.c_str(), | 227 partition_domain.c_str(), |
219 persist_storage ? "persist" : "", | 228 persist_storage ? "persist" : "", |
220 url_encoded_partition.c_str())); | 229 url_encoded_partition.c_str())); |
221 | 230 |
222 // If we already have a webview tag in the same app using the same storage | 231 // If we already have a webview tag in the same app using the same storage |
223 // partition, we should use the same SiteInstance so the existing tag and | 232 // partition, we should use the same SiteInstance so the existing tag and |
224 // the new tag can script each other. | 233 // the new tag can script each other. |
225 GuestViewManager* guest_view_manager = | 234 GuestViewManager* guest_view_manager = |
226 GuestViewManager::FromBrowserContext( | 235 GuestViewManager::FromBrowserContext( |
227 embedder_render_process_host->GetBrowserContext()); | 236 embedder_render_process_host->GetBrowserContext()); |
228 content::SiteInstance* guest_site_instance = | 237 content::SiteInstance* guest_site_instance = |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 void WebViewGuest::PushWebViewStateToIOThread() { | 762 void WebViewGuest::PushWebViewStateToIOThread() { |
754 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); | 763 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
755 std::string partition_domain; | 764 std::string partition_domain; |
756 std::string partition_id; | 765 std::string partition_id; |
757 bool in_memory; | 766 bool in_memory; |
758 if (!GetGuestPartitionConfigForSite( | 767 if (!GetGuestPartitionConfigForSite( |
759 site_url, &partition_domain, &partition_id, &in_memory)) { | 768 site_url, &partition_domain, &partition_id, &in_memory)) { |
760 NOTREACHED(); | 769 NOTREACHED(); |
761 return; | 770 return; |
762 } | 771 } |
763 DCHECK(embedder_extension_id() == partition_domain); | |
764 | 772 |
765 WebViewRendererState::WebViewInfo web_view_info; | 773 WebViewRendererState::WebViewInfo web_view_info; |
766 web_view_info.embedder_process_id = embedder_render_process_id(); | 774 web_view_info.embedder_process_id = embedder_render_process_id(); |
767 web_view_info.instance_id = view_instance_id(); | 775 web_view_info.instance_id = view_instance_id(); |
768 web_view_info.partition_id = partition_id; | 776 web_view_info.partition_id = partition_id; |
769 web_view_info.embedder_extension_id = embedder_extension_id(); | 777 web_view_info.embedder_extension_id = embedder_extension_id(); |
770 | 778 |
771 content::BrowserThread::PostTask( | 779 content::BrowserThread::PostTask( |
772 content::BrowserThread::IO, | 780 content::BrowserThread::IO, |
773 FROM_HERE, | 781 FROM_HERE, |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 it != pending_new_windows.end(); ++it) { | 1114 it != pending_new_windows.end(); ++it) { |
1107 it->first->Destroy(); | 1115 it->first->Destroy(); |
1108 } | 1116 } |
1109 // All pending windows should be removed from the set after Destroy() is | 1117 // All pending windows should be removed from the set after Destroy() is |
1110 // called on all of them. | 1118 // called on all of them. |
1111 DCHECK(pending_new_windows_.empty()); | 1119 DCHECK(pending_new_windows_.empty()); |
1112 } | 1120 } |
1113 | 1121 |
1114 GURL WebViewGuest::ResolveURL(const std::string& src) { | 1122 GURL WebViewGuest::ResolveURL(const std::string& src) { |
1115 if (!in_extension()) { | 1123 if (!in_extension()) { |
1116 NOTREACHED(); | |
1117 return GURL(src); | 1124 return GURL(src); |
1118 } | 1125 } |
1119 | 1126 |
1120 GURL default_url(base::StringPrintf("%s://%s/", | 1127 GURL default_url(base::StringPrintf("%s://%s/", |
1121 kExtensionScheme, | 1128 kExtensionScheme, |
1122 embedder_extension_id().c_str())); | 1129 embedder_extension_id().c_str())); |
1123 return default_url.Resolve(src); | 1130 return default_url.Resolve(src); |
1124 } | 1131 } |
1125 | 1132 |
1126 void WebViewGuest::OnWebViewNewWindowResponse( | 1133 void WebViewGuest::OnWebViewNewWindowResponse( |
1127 int new_window_instance_id, | 1134 int new_window_instance_id, |
1128 bool allow, | 1135 bool allow, |
1129 const std::string& user_input) { | 1136 const std::string& user_input) { |
1130 WebViewGuest* guest = | 1137 WebViewGuest* guest = |
1131 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1138 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1132 if (!guest) | 1139 if (!guest) |
1133 return; | 1140 return; |
1134 | 1141 |
1135 if (!allow) | 1142 if (!allow) |
1136 guest->Destroy(); | 1143 guest->Destroy(); |
1137 } | 1144 } |
1138 | 1145 |
1139 } // namespace extensions | 1146 } // namespace extensions |
OLD | NEW |