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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/guest_view/web_view/web_view_guest.cc
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc
index bb24c5db3c99ef51ad23e50ed925d8201a6b2475..b3dda987a080982e9fcc984ca330266b3ccf5556 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.cc
+++ b/extensions/browser/guest_view/web_view/web_view_guest.cc
@@ -999,6 +999,49 @@ void WebViewGuest::SetAllowTransparency(bool allow) {
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow);
}
+bool WebViewGuest::LoadDataWithBaseURL(const std::string& data_url,
+ const std::string& base_url,
+ const std::string& virtual_url,
+ std::string* error) {
+ // Make GURLs from URLs.
+ const GURL data_gurl = GURL(data_url);
+ const GURL base_gurl = GURL(base_url);
+ const GURL virtual_gurl = GURL(virtual_url);
+
+ // Check that the provided URLs are valid.
+ // |data_url| must be a valid data URL.
+ if (!data_gurl.is_valid() || !data_gurl.SchemeIs(url::kDataScheme)) {
+ base::SStringPrintf(
+ error, webview::kAPILoadDataInvalidDataURL, data_url.c_str());
+ return false;
+ }
+ // |base_url| must be a valid URL.
+ if (!base_gurl.is_valid()) {
+ base::SStringPrintf(
+ error, webview::kAPILoadDataInvalidBaseURL, base_url.c_str());
+ return false;
+ }
+ // |virtual_url| must be a valid URL.
+ if (!virtual_gurl.is_valid()) {
+ base::SStringPrintf(
+ error, webview::kAPILoadDataInvalidVirtualURL, virtual_url.c_str());
+ return false;
+ }
+
+ // Set up the parameters to load |data_url| with the specified |base_url|.
+ content::NavigationController::LoadURLParams load_params(data_gurl);
+ load_params.load_type = content::NavigationController::LOAD_TYPE_DATA;
+ load_params.base_url_for_data_url = base_gurl;
+ load_params.virtual_url_for_data_url = virtual_gurl;
+ load_params.override_user_agent =
+ content::NavigationController::UA_OVERRIDE_INHERIT;
+
+ // Navigate to the data URL.
+ web_contents()->GetController().LoadURLWithParams(load_params);
+
+ return true;
+}
+
void WebViewGuest::AddNewContents(content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
« 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