| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Validate that the partition id coming from the renderer is valid UTF-8, | 197 // 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 | 198 // 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 | 199 // creation. If the validation fails, treat it as a bad message and kill the |
| 200 // renderer process. | 200 // renderer process. |
| 201 if (!base::IsStringUTF8(storage_partition_id)) { | 201 if (!base::IsStringUTF8(storage_partition_id)) { |
| 202 content::RecordAction( | 202 content::RecordAction( |
| 203 base::UserMetricsAction("BadMessageTerminate_BPGM")); | 203 base::UserMetricsAction("BadMessageTerminate_BPGM")); |
| 204 base::KillProcess( | 204 base::KillProcess( |
| 205 embedder_render_process_host->GetHandle(), | 205 embedder_render_process_host->GetHandle(), |
| 206 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 206 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 207 callback.Run(NULL); | 207 callback.Run(nullptr); |
| 208 return; | 208 return; |
| 209 } | 209 } |
| 210 std::string url_encoded_partition = net::EscapeQueryParamValue( | 210 std::string url_encoded_partition = net::EscapeQueryParamValue( |
| 211 storage_partition_id, false); | 211 storage_partition_id, false); |
| 212 // The SiteInstance of a given webview tag is based on the fact that it's | 212 // 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 | 213 // a guest process in addition to which platform application the tag |
| 214 // belongs to and what storage partition is in use, rather than the URL | 214 // belongs to and what storage partition is in use, rather than the URL |
| 215 // that the tag is being navigated to. | 215 // that the tag is being navigated to. |
| 216 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 216 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
| 217 content::kGuestScheme, | 217 content::kGuestScheme, |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 content::JavaScriptDialogManager* | 848 content::JavaScriptDialogManager* |
| 849 WebViewGuest::GetJavaScriptDialogManager() { | 849 WebViewGuest::GetJavaScriptDialogManager() { |
| 850 return &javascript_dialog_helper_; | 850 return &javascript_dialog_helper_; |
| 851 } | 851 } |
| 852 | 852 |
| 853 content::ColorChooser* WebViewGuest::OpenColorChooser( | 853 content::ColorChooser* WebViewGuest::OpenColorChooser( |
| 854 WebContents* web_contents, | 854 WebContents* web_contents, |
| 855 SkColor color, | 855 SkColor color, |
| 856 const std::vector<content::ColorSuggestion>& suggestions) { | 856 const std::vector<content::ColorSuggestion>& suggestions) { |
| 857 if (!attached() || !embedder_web_contents()->GetDelegate()) | 857 if (!attached() || !embedder_web_contents()->GetDelegate()) |
| 858 return NULL; | 858 return nullptr; |
| 859 return embedder_web_contents()->GetDelegate()->OpenColorChooser( | 859 return embedder_web_contents()->GetDelegate()->OpenColorChooser( |
| 860 web_contents, color, suggestions); | 860 web_contents, color, suggestions); |
| 861 } | 861 } |
| 862 | 862 |
| 863 void WebViewGuest::NavigateGuest(const std::string& src) { | 863 void WebViewGuest::NavigateGuest(const std::string& src) { |
| 864 GURL url = ResolveURL(src); | 864 GURL url = ResolveURL(src); |
| 865 | 865 |
| 866 // Do not allow navigating a guest to schemes other than known safe schemes. | 866 // Do not allow navigating a guest to schemes other than known safe schemes. |
| 867 // This will block the embedder trying to load unwanted schemes, e.g. | 867 // This will block the embedder trying to load unwanted schemes, e.g. |
| 868 // chrome://settings. | 868 // chrome://settings. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 // If the guest wishes to navigate away prior to attachment then we save the | 1002 // If the guest wishes to navigate away prior to attachment then we save the |
| 1003 // navigation to perform upon attachment. Navigation initializes a lot of | 1003 // navigation to perform upon attachment. Navigation initializes a lot of |
| 1004 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. | 1004 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. |
| 1005 // Navigation also resumes resource loading which we don't want to allow | 1005 // Navigation also resumes resource loading which we don't want to allow |
| 1006 // until attachment. | 1006 // until attachment. |
| 1007 if (!attached()) { | 1007 if (!attached()) { |
| 1008 WebViewGuest* opener = GetOpener(); | 1008 WebViewGuest* opener = GetOpener(); |
| 1009 PendingWindowMap::iterator it = | 1009 PendingWindowMap::iterator it = |
| 1010 opener->pending_new_windows_.find(this); | 1010 opener->pending_new_windows_.find(this); |
| 1011 if (it == opener->pending_new_windows_.end()) | 1011 if (it == opener->pending_new_windows_.end()) |
| 1012 return NULL; | 1012 return nullptr; |
| 1013 const NewWindowInfo& info = it->second; | 1013 const NewWindowInfo& info = it->second; |
| 1014 NewWindowInfo new_window_info(params.url, info.name); | 1014 NewWindowInfo new_window_info(params.url, info.name); |
| 1015 new_window_info.changed = new_window_info.url != info.url; | 1015 new_window_info.changed = new_window_info.url != info.url; |
| 1016 it->second = new_window_info; | 1016 it->second = new_window_info; |
| 1017 return NULL; | 1017 return nullptr; |
| 1018 } | 1018 } |
| 1019 if (params.disposition == CURRENT_TAB) { | 1019 if (params.disposition == CURRENT_TAB) { |
| 1020 // This can happen for cross-site redirects. | 1020 // This can happen for cross-site redirects. |
| 1021 LoadURLWithParams(params.url, params.referrer, params.transition, source); | 1021 LoadURLWithParams(params.url, params.referrer, params.transition, source); |
| 1022 return source; | 1022 return source; |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 CreateNewGuestWebViewWindow(params); | 1025 CreateNewGuestWebViewWindow(params); |
| 1026 return NULL; | 1026 return nullptr; |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 void WebViewGuest::WebContentsCreated(WebContents* source_contents, | 1029 void WebViewGuest::WebContentsCreated(WebContents* source_contents, |
| 1030 int opener_render_frame_id, | 1030 int opener_render_frame_id, |
| 1031 const base::string16& frame_name, | 1031 const base::string16& frame_name, |
| 1032 const GURL& target_url, | 1032 const GURL& target_url, |
| 1033 content::WebContents* new_contents) { | 1033 content::WebContents* new_contents) { |
| 1034 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); | 1034 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); |
| 1035 CHECK(guest); | 1035 CHECK(guest); |
| 1036 guest->SetOpener(this); | 1036 guest->SetOpener(this); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 WebViewGuest* guest = | 1130 WebViewGuest* guest = |
| 1131 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1131 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1132 if (!guest) | 1132 if (!guest) |
| 1133 return; | 1133 return; |
| 1134 | 1134 |
| 1135 if (!allow) | 1135 if (!allow) |
| 1136 guest->Destroy(); | 1136 guest->Destroy(); |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 } // namespace extensions | 1139 } // namespace extensions |
| OLD | NEW |