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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return webview::kAPINamespace; | 177 return webview::kAPINamespace; |
178 } | 178 } |
179 | 179 |
180 int WebViewGuest::GetTaskPrefix() const { | 180 int WebViewGuest::GetTaskPrefix() const { |
181 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 181 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
182 } | 182 } |
183 | 183 |
184 void WebViewGuest::CreateWebContents( | 184 void WebViewGuest::CreateWebContents( |
185 const std::string& embedder_extension_id, | 185 const std::string& embedder_extension_id, |
186 int embedder_render_process_id, | 186 int embedder_render_process_id, |
| 187 const GURL& embedder_site_url, |
187 const base::DictionaryValue& create_params, | 188 const base::DictionaryValue& create_params, |
188 const WebContentsCreatedCallback& callback) { | 189 const WebContentsCreatedCallback& callback) { |
189 content::RenderProcessHost* embedder_render_process_host = | 190 content::RenderProcessHost* embedder_render_process_host = |
190 content::RenderProcessHost::FromID(embedder_render_process_id); | 191 content::RenderProcessHost::FromID(embedder_render_process_id); |
191 std::string storage_partition_id; | 192 std::string storage_partition_id; |
192 bool persist_storage = false; | 193 bool persist_storage = false; |
193 std::string storage_partition_string; | 194 std::string storage_partition_string; |
194 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); | 195 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); |
195 // Validate that the partition id coming from the renderer is valid UTF-8, | 196 // Validate that the partition id coming from the renderer is valid UTF-8, |
196 // since we depend on this in other parts of the code, such as FilePath | 197 // since we depend on this in other parts of the code, such as FilePath |
197 // creation. If the validation fails, treat it as a bad message and kill the | 198 // creation. If the validation fails, treat it as a bad message and kill the |
198 // renderer process. | 199 // renderer process. |
199 if (!base::IsStringUTF8(storage_partition_id)) { | 200 if (!base::IsStringUTF8(storage_partition_id)) { |
200 content::RecordAction( | 201 content::RecordAction( |
201 base::UserMetricsAction("BadMessageTerminate_BPGM")); | 202 base::UserMetricsAction("BadMessageTerminate_BPGM")); |
202 base::KillProcess( | 203 base::KillProcess( |
203 embedder_render_process_host->GetHandle(), | 204 embedder_render_process_host->GetHandle(), |
204 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 205 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
205 callback.Run(NULL); | 206 callback.Run(NULL); |
206 return; | 207 return; |
207 } | 208 } |
208 std::string url_encoded_partition = net::EscapeQueryParamValue( | 209 std::string url_encoded_partition = net::EscapeQueryParamValue( |
209 storage_partition_id, false); | 210 storage_partition_id, false); |
210 // The SiteInstance of a given webview tag is based on the fact that it's | 211 // The SiteInstance of a given webview tag is based on the fact that it's |
211 // a guest process in addition to which platform application the tag | 212 // a guest process in addition to which platform application or which WebUI |
212 // belongs to and what storage partition is in use, rather than the URL | 213 // page the tag belongs to and what storage partition is in use, rather than |
213 // that the tag is being navigated to. | 214 // the URL that the tag is being navigated to. |
| 215 std::string partition_domain; |
| 216 if (embedder_extension_id.empty()) { |
| 217 DCHECK(content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 218 embedder_render_process_id)); |
| 219 partition_domain = embedder_site_url.host(); |
| 220 } else { |
| 221 partition_domain = embedder_extension_id; |
| 222 } |
214 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 223 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
215 content::kGuestScheme, | 224 content::kGuestScheme, |
216 embedder_extension_id.c_str(), | 225 partition_domain.c_str(), |
217 persist_storage ? "persist" : "", | 226 persist_storage ? "persist" : "", |
218 url_encoded_partition.c_str())); | 227 url_encoded_partition.c_str())); |
219 | 228 |
220 // If we already have a webview tag in the same app using the same storage | 229 // If we already have a webview tag in the same app using the same storage |
221 // partition, we should use the same SiteInstance so the existing tag and | 230 // partition, we should use the same SiteInstance so the existing tag and |
222 // the new tag can script each other. | 231 // the new tag can script each other. |
223 GuestViewManager* guest_view_manager = | 232 GuestViewManager* guest_view_manager = |
224 GuestViewManager::FromBrowserContext( | 233 GuestViewManager::FromBrowserContext( |
225 embedder_render_process_host->GetBrowserContext()); | 234 embedder_render_process_host->GetBrowserContext()); |
226 content::SiteInstance* guest_site_instance = | 235 content::SiteInstance* guest_site_instance = |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 void WebViewGuest::PushWebViewStateToIOThread() { | 743 void WebViewGuest::PushWebViewStateToIOThread() { |
735 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); | 744 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
736 std::string partition_domain; | 745 std::string partition_domain; |
737 std::string partition_id; | 746 std::string partition_id; |
738 bool in_memory; | 747 bool in_memory; |
739 if (!GetGuestPartitionConfigForSite( | 748 if (!GetGuestPartitionConfigForSite( |
740 site_url, &partition_domain, &partition_id, &in_memory)) { | 749 site_url, &partition_domain, &partition_id, &in_memory)) { |
741 NOTREACHED(); | 750 NOTREACHED(); |
742 return; | 751 return; |
743 } | 752 } |
744 DCHECK(embedder_extension_id() == partition_domain); | |
745 | 753 |
746 WebViewRendererState::WebViewInfo web_view_info; | 754 WebViewRendererState::WebViewInfo web_view_info; |
747 web_view_info.embedder_process_id = embedder_render_process_id(); | 755 web_view_info.embedder_process_id = embedder_render_process_id(); |
748 web_view_info.instance_id = view_instance_id(); | 756 web_view_info.instance_id = view_instance_id(); |
749 web_view_info.partition_id = partition_id; | 757 web_view_info.partition_id = partition_id; |
750 web_view_info.embedder_extension_id = embedder_extension_id(); | 758 web_view_info.embedder_extension_id = embedder_extension_id(); |
751 | 759 |
752 content::BrowserThread::PostTask( | 760 content::BrowserThread::PostTask( |
753 content::BrowserThread::IO, | 761 content::BrowserThread::IO, |
754 FROM_HERE, | 762 FROM_HERE, |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 it != pending_new_windows.end(); ++it) { | 1077 it != pending_new_windows.end(); ++it) { |
1070 it->first->Destroy(); | 1078 it->first->Destroy(); |
1071 } | 1079 } |
1072 // All pending windows should be removed from the set after Destroy() is | 1080 // All pending windows should be removed from the set after Destroy() is |
1073 // called on all of them. | 1081 // called on all of them. |
1074 DCHECK(pending_new_windows_.empty()); | 1082 DCHECK(pending_new_windows_.empty()); |
1075 } | 1083 } |
1076 | 1084 |
1077 GURL WebViewGuest::ResolveURL(const std::string& src) { | 1085 GURL WebViewGuest::ResolveURL(const std::string& src) { |
1078 if (!in_extension()) { | 1086 if (!in_extension()) { |
1079 NOTREACHED(); | |
1080 return GURL(src); | 1087 return GURL(src); |
1081 } | 1088 } |
1082 | 1089 |
1083 GURL default_url(base::StringPrintf("%s://%s/", | 1090 GURL default_url(base::StringPrintf("%s://%s/", |
1084 kExtensionScheme, | 1091 kExtensionScheme, |
1085 embedder_extension_id().c_str())); | 1092 embedder_extension_id().c_str())); |
1086 return default_url.Resolve(src); | 1093 return default_url.Resolve(src); |
1087 } | 1094 } |
1088 | 1095 |
1089 void WebViewGuest::OnWebViewNewWindowResponse( | 1096 void WebViewGuest::OnWebViewNewWindowResponse( |
1090 int new_window_instance_id, | 1097 int new_window_instance_id, |
1091 bool allow, | 1098 bool allow, |
1092 const std::string& user_input) { | 1099 const std::string& user_input) { |
1093 WebViewGuest* guest = | 1100 WebViewGuest* guest = |
1094 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1101 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1095 if (!guest) | 1102 if (!guest) |
1096 return; | 1103 return; |
1097 | 1104 |
1098 if (!allow) | 1105 if (!allow) |
1099 guest->Destroy(); | 1106 guest->Destroy(); |
1100 } | 1107 } |
1101 | 1108 |
1102 } // namespace extensions | 1109 } // namespace extensions |
OLD | NEW |