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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 if (guest_opaque_ != allow) | 992 if (guest_opaque_ != allow) |
993 return; | 993 return; |
994 | 994 |
995 guest_opaque_ = !allow; | 995 guest_opaque_ = !allow; |
996 if (!web_contents()->GetRenderViewHost()->GetView()) | 996 if (!web_contents()->GetRenderViewHost()->GetView()) |
997 return; | 997 return; |
998 | 998 |
999 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow); | 999 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow); |
1000 } | 1000 } |
1001 | 1001 |
1002 bool WebViewGuest::LoadDataWithBaseURL(const std::string& data_url, | |
1003 const std::string& base_url, | |
1004 const std::string& virtual_url, | |
1005 std::string* error) { | |
1006 // Make GURLs from URLs. | |
1007 const GURL data_gurl = GURL(data_url); | |
1008 const GURL base_gurl = GURL(base_url); | |
1009 const GURL virtual_gurl = GURL(virtual_url); | |
1010 | |
1011 // Check that the provided URLs are valid. | |
1012 // |data_url| must be a valid data URL. | |
1013 if (!data_gurl.is_valid() || !data_gurl.SchemeIs(url::kDataScheme)) { | |
1014 base::SStringPrintf( | |
1015 error, webview::kAPILoadDataInvalidDataURL, data_url.c_str()); | |
1016 return false; | |
1017 } | |
1018 // |base_url| must be a valid URL. | |
1019 if (!base_gurl.is_valid()) { | |
1020 base::SStringPrintf( | |
1021 error, webview::kAPILoadDataInvalidBaseURL, base_url.c_str()); | |
1022 return false; | |
1023 } | |
1024 // |virtual_url| must be a valid URL. | |
1025 if (!virtual_gurl.is_valid()) { | |
1026 base::SStringPrintf( | |
1027 error, webview::kAPILoadDataInvalidVirtualURL, virtual_url.c_str()); | |
1028 return false; | |
1029 } | |
1030 | |
1031 // Set up the parameters to load |data_url| with the specified |base_url|. | |
1032 content::NavigationController::LoadURLParams load_params(data_gurl); | |
1033 load_params.load_type = content::NavigationController::LOAD_TYPE_DATA; | |
1034 load_params.base_url_for_data_url = base_gurl; | |
1035 load_params.virtual_url_for_data_url = virtual_gurl; | |
1036 load_params.override_user_agent = | |
1037 content::NavigationController::UA_OVERRIDE_INHERIT; | |
1038 | |
1039 // Navigate to the data URL. | |
1040 web_contents()->GetController().LoadURLWithParams(load_params); | |
1041 web_contents()->Focus(); | |
Fady Samuel
2014/09/29 14:59:00
Let's avoid this? Focus should be managed separate
paulmeyer
2014/09/29 15:19:04
Done.
| |
1042 | |
1043 return true; | |
1044 } | |
1045 | |
1002 void WebViewGuest::AddNewContents(content::WebContents* source, | 1046 void WebViewGuest::AddNewContents(content::WebContents* source, |
1003 content::WebContents* new_contents, | 1047 content::WebContents* new_contents, |
1004 WindowOpenDisposition disposition, | 1048 WindowOpenDisposition disposition, |
1005 const gfx::Rect& initial_pos, | 1049 const gfx::Rect& initial_pos, |
1006 bool user_gesture, | 1050 bool user_gesture, |
1007 bool* was_blocked) { | 1051 bool* was_blocked) { |
1008 if (was_blocked) | 1052 if (was_blocked) |
1009 *was_blocked = false; | 1053 *was_blocked = false; |
1010 RequestNewWindowPermission(disposition, | 1054 RequestNewWindowPermission(disposition, |
1011 initial_pos, | 1055 initial_pos, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 WebViewGuest* guest = | 1190 WebViewGuest* guest = |
1147 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1191 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1148 if (!guest) | 1192 if (!guest) |
1149 return; | 1193 return; |
1150 | 1194 |
1151 if (!allow) | 1195 if (!allow) |
1152 guest->Destroy(); | 1196 guest->Destroy(); |
1153 } | 1197 } |
1154 | 1198 |
1155 } // namespace extensions | 1199 } // namespace extensions |
OLD | NEW |