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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( | 873 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( |
874 WebContents* source) { | 874 WebContents* source) { |
875 return &javascript_dialog_helper_; | 875 return &javascript_dialog_helper_; |
876 } | 876 } |
877 | 877 |
878 void WebViewGuest::NavigateGuest(const std::string& src, | 878 void WebViewGuest::NavigateGuest(const std::string& src, |
879 bool force_navigation) { | 879 bool force_navigation) { |
880 if (src.empty()) | 880 if (src.empty()) |
881 return; | 881 return; |
882 | 882 |
883 GURL url = ResolveURL(src); | 883 // Resolve the |src| relative to the base URL of the owner. |
884 | 884 GURL owner_base_url(GetOwnerSiteURL().GetWithEmptyPath()); |
885 LoadURLWithParams(url, content::Referrer(), | 885 LoadURLWithParams(owner_base_url.Resolve(src), |
| 886 content::Referrer(), |
886 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 887 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
887 force_navigation); | 888 force_navigation); |
888 } | 889 } |
889 | 890 |
890 bool WebViewGuest::HandleKeyboardShortcuts( | 891 bool WebViewGuest::HandleKeyboardShortcuts( |
891 const content::NativeWebKeyboardEvent& event) { | 892 const content::NativeWebKeyboardEvent& event) { |
892 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. | 893 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. |
893 if (!in_extension()) | 894 if (!in_extension()) |
894 return false; | 895 return false; |
895 | 896 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 | 1245 |
1245 web_view_permission_helper_-> | 1246 web_view_permission_helper_-> |
1246 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1247 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
1247 request_info, | 1248 request_info, |
1248 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1249 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
1249 weak_ptr_factory_.GetWeakPtr(), | 1250 weak_ptr_factory_.GetWeakPtr(), |
1250 guest->guest_instance_id()), | 1251 guest->guest_instance_id()), |
1251 false /* allowed_by_default */); | 1252 false /* allowed_by_default */); |
1252 } | 1253 } |
1253 | 1254 |
1254 GURL WebViewGuest::ResolveURL(const std::string& src) { | |
1255 if (!in_extension()) | |
1256 return GURL(src); | |
1257 | |
1258 GURL default_url(base::StringPrintf("%s://%s/", | |
1259 kExtensionScheme, | |
1260 owner_extension_id().c_str())); | |
1261 return default_url.Resolve(src); | |
1262 } | |
1263 | |
1264 void WebViewGuest::OnWebViewNewWindowResponse( | 1255 void WebViewGuest::OnWebViewNewWindowResponse( |
1265 int new_window_instance_id, | 1256 int new_window_instance_id, |
1266 bool allow, | 1257 bool allow, |
1267 const std::string& user_input) { | 1258 const std::string& user_input) { |
1268 auto guest = | 1259 auto guest = |
1269 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1260 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
1270 new_window_instance_id); | 1261 new_window_instance_id); |
1271 if (!guest) | 1262 if (!guest) |
1272 return; | 1263 return; |
1273 | 1264 |
1274 if (!allow) | 1265 if (!allow) |
1275 guest->Destroy(); | 1266 guest->Destroy(); |
1276 } | 1267 } |
1277 | 1268 |
1278 } // namespace extensions | 1269 } // namespace extensions |
OLD | NEW |