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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 std::string partition_domain = GetOwnerSiteURL().host(); | 277 std::string partition_domain = GetOwnerSiteURL().host(); |
278 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 278 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
279 content::kGuestScheme, | 279 content::kGuestScheme, |
280 partition_domain.c_str(), | 280 partition_domain.c_str(), |
281 persist_storage ? "persist" : "", | 281 persist_storage ? "persist" : "", |
282 url_encoded_partition.c_str())); | 282 url_encoded_partition.c_str())); |
283 | 283 |
284 // If we already have a webview tag in the same app using the same storage | 284 // If we already have a webview tag in the same app using the same storage |
285 // partition, we should use the same SiteInstance so the existing tag and | 285 // partition, we should use the same SiteInstance so the existing tag and |
286 // the new tag can script each other. | 286 // the new tag can script each other. |
287 auto guest_view_manager = GuestViewManager::FromBrowserContextIfAvailable( | 287 auto guest_view_manager = GuestViewManager::FromBrowserContext( |
288 owner_render_process_host->GetBrowserContext()); | 288 owner_render_process_host->GetBrowserContext()); |
289 content::SiteInstance* guest_site_instance = | 289 content::SiteInstance* guest_site_instance = |
290 guest_view_manager->GetGuestSiteInstance(guest_site); | 290 guest_view_manager->GetGuestSiteInstance(guest_site); |
291 if (!guest_site_instance) { | 291 if (!guest_site_instance) { |
292 // Create the SiteInstance in a new BrowsingInstance, which will ensure | 292 // Create the SiteInstance in a new BrowsingInstance, which will ensure |
293 // that webview tags are also not allowed to send messages across | 293 // that webview tags are also not allowed to send messages across |
294 // different partitions. | 294 // different partitions. |
295 guest_site_instance = content::SiteInstance::CreateForURL( | 295 guest_site_instance = content::SiteInstance::CreateForURL( |
296 owner_render_process_host->GetBrowserContext(), guest_site); | 296 owner_render_process_host->GetBrowserContext(), guest_site); |
297 } | 297 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(), | 388 WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(), |
389 view_instance_id()); | 389 view_instance_id()); |
390 web_view_key_to_id_map.Get().erase(key); | 390 web_view_key_to_id_map.Get().erase(key); |
391 | 391 |
392 content::BrowserThread::PostTask( | 392 content::BrowserThread::PostTask( |
393 content::BrowserThread::IO, | 393 content::BrowserThread::IO, |
394 FROM_HERE, | 394 FROM_HERE, |
395 base::Bind( | 395 base::Bind( |
396 &RemoveWebViewEventListenersOnIOThread, | 396 &RemoveWebViewEventListenersOnIOThread, |
397 browser_context(), | 397 browser_context(), |
398 owner_extension_id(), | 398 owner_host(), |
399 owner_web_contents()->GetRenderProcessHost()->GetID(), | 399 owner_web_contents()->GetRenderProcessHost()->GetID(), |
400 view_instance_id())); | 400 view_instance_id())); |
401 } | 401 } |
402 | 402 |
403 const char* WebViewGuest::GetAPINamespace() const { | 403 const char* WebViewGuest::GetAPINamespace() const { |
404 return webview::kAPINamespace; | 404 return webview::kAPINamespace; |
405 } | 405 } |
406 | 406 |
407 int WebViewGuest::GetTaskPrefix() const { | 407 int WebViewGuest::GetTaskPrefix() const { |
408 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 408 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); | 555 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
556 args->SetInteger(guestview::kCode, error_code); | 556 args->SetInteger(guestview::kCode, error_code); |
557 args->SetString(guestview::kReason, error_type); | 557 args->SetString(guestview::kReason, error_type); |
558 DispatchEventToView( | 558 DispatchEventToView( |
559 new GuestViewEvent(webview::kEventLoadAbort, args.Pass())); | 559 new GuestViewEvent(webview::kEventLoadAbort, args.Pass())); |
560 } | 560 } |
561 | 561 |
562 void WebViewGuest::CreateNewGuestWebViewWindow( | 562 void WebViewGuest::CreateNewGuestWebViewWindow( |
563 const content::OpenURLParams& params) { | 563 const content::OpenURLParams& params) { |
564 GuestViewManager* guest_manager = | 564 GuestViewManager* guest_manager = |
565 GuestViewManager::FromBrowserContextIfAvailable(browser_context()); | 565 GuestViewManager::FromBrowserContext(browser_context()); |
566 // Set the attach params to use the same partition as the opener. | 566 // Set the attach params to use the same partition as the opener. |
567 // We pull the partition information from the site's URL, which is of the | 567 // We pull the partition information from the site's URL, which is of the |
568 // form guest://site/{persist}?{partition_name}. | 568 // form guest://site/{persist}?{partition_name}. |
569 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); | 569 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
570 const std::string storage_partition_id = | 570 const std::string storage_partition_id = |
571 GetStoragePartitionIdFromSiteURL(site_url); | 571 GetStoragePartitionIdFromSiteURL(site_url); |
572 base::DictionaryValue create_params; | 572 base::DictionaryValue create_params; |
573 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); | 573 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); |
574 | 574 |
575 guest_manager->CreateGuest(WebViewGuest::Type, | 575 guest_manager->CreateGuest(WebViewGuest::Type, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 site_url, &partition_domain, &partition_id, &in_memory)) { | 864 site_url, &partition_domain, &partition_id, &in_memory)) { |
865 NOTREACHED(); | 865 NOTREACHED(); |
866 return; | 866 return; |
867 } | 867 } |
868 | 868 |
869 WebViewRendererState::WebViewInfo web_view_info; | 869 WebViewRendererState::WebViewInfo web_view_info; |
870 web_view_info.embedder_process_id = | 870 web_view_info.embedder_process_id = |
871 owner_web_contents()->GetRenderProcessHost()->GetID(); | 871 owner_web_contents()->GetRenderProcessHost()->GetID(); |
872 web_view_info.instance_id = view_instance_id(); | 872 web_view_info.instance_id = view_instance_id(); |
873 web_view_info.partition_id = partition_id; | 873 web_view_info.partition_id = partition_id; |
874 web_view_info.owner_extension_id = owner_extension_id(); | 874 web_view_info.owner_host = owner_host(); |
875 web_view_info.rules_registry_id = rules_registry_id_; | 875 web_view_info.rules_registry_id = rules_registry_id_; |
876 | 876 |
877 // Get content scripts IDs added by the guest. | 877 // Get content scripts IDs added by the guest. |
878 WebViewContentScriptManager* manager = | 878 WebViewContentScriptManager* manager = |
879 WebViewContentScriptManager::Get(browser_context()); | 879 WebViewContentScriptManager::Get(browser_context()); |
880 DCHECK(manager); | 880 DCHECK(manager); |
881 web_view_info.content_script_ids = manager->GetContentScriptIDSet( | 881 web_view_info.content_script_ids = manager->GetContentScriptIDSet( |
882 web_view_info.embedder_process_id, web_view_info.instance_id); | 882 web_view_info.embedder_process_id, web_view_info.instance_id); |
883 | 883 |
884 content::BrowserThread::PostTask( | 884 content::BrowserThread::PostTask( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 GURL url = ResolveURL(src); | 964 GURL url = ResolveURL(src); |
965 | 965 |
966 LoadURLWithParams(url, content::Referrer(), | 966 LoadURLWithParams(url, content::Referrer(), |
967 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 967 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
968 force_navigation); | 968 force_navigation); |
969 } | 969 } |
970 | 970 |
971 bool WebViewGuest::HandleKeyboardShortcuts( | 971 bool WebViewGuest::HandleKeyboardShortcuts( |
972 const content::NativeWebKeyboardEvent& event) { | 972 const content::NativeWebKeyboardEvent& event) { |
973 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. | 973 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. |
974 if (!in_extension()) | 974 if (!GuestViewManager::FromBrowserContext(browser_context())-> |
975 IsOwnedByExtension(this)) { | |
975 return false; | 976 return false; |
977 } | |
976 | 978 |
977 if (event.type != blink::WebInputEvent::RawKeyDown) | 979 if (event.type != blink::WebInputEvent::RawKeyDown) |
978 return false; | 980 return false; |
979 | 981 |
980 // If the user hits the escape key without any modifiers then unlock the | 982 // If the user hits the escape key without any modifiers then unlock the |
981 // mouse if necessary. | 983 // mouse if necessary. |
982 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && | 984 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && |
983 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { | 985 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { |
984 return web_contents()->GotResponseToLockMouseRequest(false); | 986 return web_contents()->GotResponseToLockMouseRequest(false); |
985 } | 987 } |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 // This will block the embedder trying to load unwanted schemes, e.g. | 1287 // This will block the embedder trying to load unwanted schemes, e.g. |
1286 // chrome://. | 1288 // chrome://. |
1287 bool scheme_is_blocked = | 1289 bool scheme_is_blocked = |
1288 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1290 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
1289 url.scheme()) && | 1291 url.scheme()) && |
1290 !url.SchemeIs(url::kAboutScheme)) || | 1292 !url.SchemeIs(url::kAboutScheme)) || |
1291 url.SchemeIs(url::kJavaScriptScheme); | 1293 url.SchemeIs(url::kJavaScriptScheme); |
1292 if (scheme_is_blocked || !url.is_valid()) { | 1294 if (scheme_is_blocked || !url.is_valid()) { |
1293 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, | 1295 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, |
1294 net::ErrorToShortString(net::ERR_ABORTED)); | 1296 net::ErrorToShortString(net::ERR_ABORTED)); |
1295 NavigateGuest(url::kAboutBlankURL, true /* force_navigation */); | 1297 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
lazyboy
2015/04/23 17:16:43
What is this change?
Fady Samuel
2015/04/24 00:11:31
Undone.
| |
1296 return; | 1298 return; |
1297 } | 1299 } |
1298 | 1300 |
1299 if (!force_navigation && (src_ == url)) | 1301 if (!force_navigation && (src_ == url)) |
1300 return; | 1302 return; |
1301 | 1303 |
1302 GURL validated_url(url); | 1304 GURL validated_url(url); |
1303 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 1305 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
1304 // As guests do not swap processes on navigation, only navigations to | 1306 // As guests do not swap processes on navigation, only navigations to |
1305 // normal web URLs are supported. No protocol handlers are installed for | 1307 // normal web URLs are supported. No protocol handlers are installed for |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 web_view_permission_helper_-> | 1355 web_view_permission_helper_-> |
1354 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1356 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
1355 request_info, | 1357 request_info, |
1356 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1358 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
1357 weak_ptr_factory_.GetWeakPtr(), | 1359 weak_ptr_factory_.GetWeakPtr(), |
1358 guest->guest_instance_id()), | 1360 guest->guest_instance_id()), |
1359 false /* allowed_by_default */); | 1361 false /* allowed_by_default */); |
1360 } | 1362 } |
1361 | 1363 |
1362 GURL WebViewGuest::ResolveURL(const std::string& src) { | 1364 GURL WebViewGuest::ResolveURL(const std::string& src) { |
1363 if (!in_extension()) | 1365 if (!GuestViewManager::FromBrowserContext(browser_context())-> |
1366 IsOwnedByExtension(this)) { | |
1364 return GURL(src); | 1367 return GURL(src); |
1368 } | |
1365 | 1369 |
1366 GURL default_url(base::StringPrintf("%s://%s/", | 1370 GURL default_url(base::StringPrintf("%s://%s/", |
1367 kExtensionScheme, | 1371 kExtensionScheme, |
1368 owner_extension_id().c_str())); | 1372 owner_host().c_str())); |
1369 return default_url.Resolve(src); | 1373 return default_url.Resolve(src); |
1370 } | 1374 } |
1371 | 1375 |
1372 void WebViewGuest::OnWebViewNewWindowResponse( | 1376 void WebViewGuest::OnWebViewNewWindowResponse( |
1373 int new_window_instance_id, | 1377 int new_window_instance_id, |
1374 bool allow, | 1378 bool allow, |
1375 const std::string& user_input) { | 1379 const std::string& user_input) { |
1376 auto guest = | 1380 auto guest = |
1377 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1381 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
1378 new_window_instance_id); | 1382 new_window_instance_id); |
(...skipping 30 matching lines...) Expand all Loading... | |
1409 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1413 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1410 DispatchEventToView( | 1414 DispatchEventToView( |
1411 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1415 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1412 } | 1416 } |
1413 // Since we changed fullscreen state, sending a Resize message ensures that | 1417 // Since we changed fullscreen state, sending a Resize message ensures that |
1414 // renderer/ sees the change. | 1418 // renderer/ sees the change. |
1415 web_contents()->GetRenderViewHost()->WasResized(); | 1419 web_contents()->GetRenderViewHost()->WasResized(); |
1416 } | 1420 } |
1417 | 1421 |
1418 } // namespace extensions | 1422 } // namespace extensions |
OLD | NEW |