Index: extensions/browser/api/web_view/web_view_internal_api.cc |
diff --git a/extensions/browser/api/web_view/web_view_internal_api.cc b/extensions/browser/api/web_view/web_view_internal_api.cc |
index cbacf7e59d82c1ac7b827e5dd61c0d065416c5de..d2f6749c4b0daeb60b5fd5cf56cfba0e39ba96a7 100644 |
--- a/extensions/browser/api/web_view/web_view_internal_api.cc |
+++ b/extensions/browser/api/web_view/web_view_internal_api.cc |
@@ -300,6 +300,65 @@ bool WebViewInternalStopFindingFunction::RunAsyncSafe(WebViewGuest* guest) { |
return true; |
} |
+WebViewInternalLoadDataWithBaseUrlFunction:: |
+ WebViewInternalLoadDataWithBaseUrlFunction() { |
+} |
+ |
+WebViewInternalLoadDataWithBaseUrlFunction:: |
+ ~WebViewInternalLoadDataWithBaseUrlFunction() { |
+} |
+ |
+bool WebViewInternalLoadDataWithBaseUrlFunction::RunAsyncSafe( |
+ WebViewGuest* guest) { |
+ scoped_ptr<webview::LoadDataWithBaseUrl::Params> params( |
+ webview::LoadDataWithBaseUrl::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params.get()); |
Fady Samuel
2014/09/26 18:06:39
Could you please move the code below to WebViewGue
paulmeyer
2014/09/26 19:44:29
Done.
|
+ |
+ // If a virtual URL was provided, use it. Otherwise, the user will be shown |
+ // the data URL. |
+ std::string virtual_url = |
+ params->virtual_url ? *params->virtual_url : params->data_url; |
+ |
+ // Check that the provided URLs are valid. |
+ const GURL data_gurl = GURL(params->data_url); |
+ const GURL base_gurl = GURL(params->base_url); |
+ const GURL virtual_gurl = GURL(virtual_url); |
+ // |data_url| must be a valid data URL. |
+ if (!data_gurl.is_valid() || !data_gurl.SchemeIs(url::kDataScheme)) { |
+ error_ = "Invalid data URL \"" + params->data_url + "\"."; |
+ SendResponse(false); |
+ return false; |
+ } |
+ // |base_url| must be a valid URL. |
+ if (!base_gurl.is_valid()) { |
+ error_ = "Invalid base URL \"" + params->base_url + "\"."; |
+ SendResponse(false); |
+ return false; |
+ } |
+ // |virtual_url| must be a valid URL (if provided). |
+ if (params->virtual_url && !virtual_gurl.is_valid()) { |
+ error_ = "Invalid virtual URL \"" + *params->virtual_url + "\"."; |
+ SendResponse(false); |
+ 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_FALSE; |
Fady Samuel
2014/09/26 18:06:39
What happens if you've selected otherwise?
paulmeyer
2014/09/26 19:44:29
Done.
|
+ |
+ // Navigate to the data URL. |
+ content::WebContents* web_contents = guest->web_contents(); |
+ web_contents->GetController().LoadURLWithParams(load_params); |
+ web_contents->Focus(); |
+ |
+ SendResponse(true); |
+ return true; |
+} |
+ |
WebViewInternalGoFunction::WebViewInternalGoFunction() { |
} |