Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 610643003: Adds new webview.loadDataWithBaseUrl API to allow data URLs to be loaded with a specified base URL … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comment. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
1042 return true;
1043 }
1044
1002 void WebViewGuest::AddNewContents(content::WebContents* source, 1045 void WebViewGuest::AddNewContents(content::WebContents* source,
1003 content::WebContents* new_contents, 1046 content::WebContents* new_contents,
1004 WindowOpenDisposition disposition, 1047 WindowOpenDisposition disposition,
1005 const gfx::Rect& initial_pos, 1048 const gfx::Rect& initial_pos,
1006 bool user_gesture, 1049 bool user_gesture,
1007 bool* was_blocked) { 1050 bool* was_blocked) {
1008 if (was_blocked) 1051 if (was_blocked)
1009 *was_blocked = false; 1052 *was_blocked = false;
1010 RequestNewWindowPermission(disposition, 1053 RequestNewWindowPermission(disposition,
1011 initial_pos, 1054 initial_pos,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 WebViewGuest* guest = 1189 WebViewGuest* guest =
1147 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1190 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1148 if (!guest) 1191 if (!guest)
1149 return; 1192 return;
1150 1193
1151 if (!allow) 1194 if (!allow)
1152 guest->Destroy(); 1195 guest->Destroy();
1153 } 1196 }
1154 1197
1155 } // namespace extensions 1198 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/web_view/web_view_guest.h ('k') | extensions/common/api/web_view_internal.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698