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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "content/public/browser/native_web_keyboard_event.h" | 24 #include "content/public/browser/native_web_keyboard_event.h" |
25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
29 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/render_widget_host.h" | 32 #include "content/public/browser/render_widget_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 33 #include "content/public/browser/render_widget_host_view.h" |
34 #include "content/public/browser/resource_dispatcher_host.h" | |
34 #include "content/public/browser/resource_request_details.h" | 35 #include "content/public/browser/resource_request_details.h" |
35 #include "content/public/browser/site_instance.h" | 36 #include "content/public/browser/site_instance.h" |
36 #include "content/public/browser/storage_partition.h" | 37 #include "content/public/browser/storage_partition.h" |
37 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
39 #include "content/public/browser/web_contents_delegate.h" | 40 #include "content/public/browser/web_contents_delegate.h" |
40 #include "content/public/common/media_stream_request.h" | 41 #include "content/public/common/media_stream_request.h" |
41 #include "content/public/common/page_zoom.h" | 42 #include "content/public/common/page_zoom.h" |
42 #include "content/public/common/result_codes.h" | 43 #include "content/public/common/result_codes.h" |
43 #include "content/public/common/stop_find_action.h" | 44 #include "content/public/common/stop_find_action.h" |
44 #include "content/public/common/url_constants.h" | 45 #include "content/public/common/url_constants.h" |
45 #include "extensions/browser/api/declarative/rules_registry_service.h" | 46 #include "extensions/browser/api/declarative/rules_registry_service.h" |
46 #include "extensions/browser/api/extensions_api_client.h" | 47 #include "extensions/browser/api/extensions_api_client.h" |
47 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" | 48 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" |
48 #include "extensions/browser/api/web_request/web_request_api.h" | 49 #include "extensions/browser/api/web_request/web_request_api.h" |
49 #include "extensions/browser/extension_system.h" | 50 #include "extensions/browser/extension_system.h" |
50 #include "extensions/browser/extensions_browser_client.h" | 51 #include "extensions/browser/extensions_browser_client.h" |
51 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 52 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
52 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager .h" | 53 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager .h" |
53 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 54 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
54 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 55 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
55 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | |
56 #include "extensions/common/constants.h" | 56 #include "extensions/common/constants.h" |
57 #include "extensions/common/extension.h" | |
57 #include "extensions/common/extension_messages.h" | 58 #include "extensions/common/extension_messages.h" |
58 #include "extensions/common/manifest_constants.h" | 59 #include "extensions/common/manifest_constants.h" |
59 #include "extensions/strings/grit/extensions_strings.h" | 60 #include "extensions/strings/grit/extensions_strings.h" |
60 #include "ipc/ipc_message_macros.h" | 61 #include "ipc/ipc_message_macros.h" |
61 #include "net/base/escape.h" | 62 #include "net/base/escape.h" |
62 #include "net/base/net_errors.h" | 63 #include "net/base/net_errors.h" |
63 #include "ui/base/models/simple_menu_model.h" | 64 #include "ui/base/models/simple_menu_model.h" |
64 #include "ui/events/keycodes/keyboard_codes.h" | 65 #include "ui/events/keycodes/keyboard_codes.h" |
65 #include "url/url_constants.h" | 66 #include "url/url_constants.h" |
66 | 67 |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 web_view_info.rules_registry_id = rules_registry_id_; | 926 web_view_info.rules_registry_id = rules_registry_id_; |
926 | 927 |
927 // Get content scripts IDs added by the guest. | 928 // Get content scripts IDs added by the guest. |
928 WebViewContentScriptManager* manager = | 929 WebViewContentScriptManager* manager = |
929 WebViewContentScriptManager::Get(browser_context()); | 930 WebViewContentScriptManager::Get(browser_context()); |
930 DCHECK(manager); | 931 DCHECK(manager); |
931 web_view_info.content_script_ids = manager->GetContentScriptIDSet( | 932 web_view_info.content_script_ids = manager->GetContentScriptIDSet( |
932 web_view_info.embedder_process_id, web_view_info.instance_id); | 933 web_view_info.embedder_process_id, web_view_info.instance_id); |
933 | 934 |
934 content::BrowserThread::PostTask( | 935 content::BrowserThread::PostTask( |
935 content::BrowserThread::IO, | 936 content::BrowserThread::IO, FROM_HERE, |
936 FROM_HERE, | 937 base::Bind(&WebViewGuest::AddGuestHelper, |
937 base::Bind(&WebViewRendererState::AddGuest, | |
938 base::Unretained(WebViewRendererState::GetInstance()), | 938 base::Unretained(WebViewRendererState::GetInstance()), |
939 web_contents()->GetRenderProcessHost()->GetID(), | 939 web_contents()->GetRenderProcessHost()->GetID(), |
940 web_contents()->GetRoutingID(), | 940 web_contents()->GetRoutingID(), web_view_info, |
941 web_view_info)); | 941 browser_context()->GetResourceContext())); |
942 } | 942 } |
943 | 943 |
944 // static | 944 // static |
945 void WebViewGuest::RemoveWebViewStateFromIOThread( | 945 void WebViewGuest::RemoveWebViewStateFromIOThread( |
946 WebContents* web_contents) { | 946 WebContents* web_contents) { |
947 content::BrowserThread::PostTask( | 947 content::BrowserThread::PostTask( |
948 content::BrowserThread::IO, FROM_HERE, | 948 content::BrowserThread::IO, FROM_HERE, |
949 base::Bind( | 949 base::Bind(&WebViewGuest::RemoveGuestHelper, |
950 &WebViewRendererState::RemoveGuest, | 950 base::Unretained(WebViewRendererState::GetInstance()), |
951 base::Unretained(WebViewRendererState::GetInstance()), | 951 web_contents->GetRenderProcessHost()->GetID(), |
952 web_contents->GetRenderProcessHost()->GetID(), | 952 web_contents->GetRoutingID(), |
953 web_contents->GetRoutingID())); | 953 web_contents->GetBrowserContext()->GetResourceContext())); |
954 } | 954 } |
955 | 955 |
956 void WebViewGuest::RequestMediaAccessPermission( | 956 void WebViewGuest::RequestMediaAccessPermission( |
957 WebContents* source, | 957 WebContents* source, |
958 const content::MediaStreamRequest& request, | 958 const content::MediaStreamRequest& request, |
959 const content::MediaResponseCallback& callback) { | 959 const content::MediaResponseCallback& callback) { |
960 web_view_permission_helper_->RequestMediaAccessPermission(source, | 960 web_view_permission_helper_->RequestMediaAccessPermission(source, |
961 request, | 961 request, |
962 callback); | 962 callback); |
963 } | 963 } |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1496 // on the embedder. | 1496 // on the embedder. |
1497 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1497 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1498 DispatchEventToView(base::WrapUnique( | 1498 DispatchEventToView(base::WrapUnique( |
1499 new GuestViewEvent(webview::kEventExitFullscreen, std::move(args)))); | 1499 new GuestViewEvent(webview::kEventExitFullscreen, std::move(args)))); |
1500 } | 1500 } |
1501 // Since we changed fullscreen state, sending a Resize message ensures that | 1501 // Since we changed fullscreen state, sending a Resize message ensures that |
1502 // renderer/ sees the change. | 1502 // renderer/ sees the change. |
1503 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 1503 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
1504 } | 1504 } |
1505 | 1505 |
1506 // static | |
1507 void WebViewGuest::AddGuestHelper( | |
1508 WebViewRendererState* renderer_state, | |
1509 int guest_process_id, | |
1510 int guest_routing_id, | |
1511 const WebViewRendererState::WebViewInfo& web_view_info, | |
1512 const content::ResourceContext* context) { | |
1513 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
1514 | |
1515 // Guest processes can access resources from the host (extensions). The | |
1516 // ResourceDispatcherHost object performs access checks for certain origins | |
1517 // like extensions when they are requested. We should inform the | |
1518 // ResourceDispatcherHost instance about guests so it can enforce accesses | |
1519 // correctly. This should be done only for new guest processes. | |
1520 bool new_guest = !renderer_state->IsGuest(guest_process_id); | |
1521 renderer_state->AddGuest(guest_process_id, guest_routing_id, web_view_info); | |
1522 if (new_guest) { | |
1523 DCHECK(content::ResourceDispatcherHost::Get()); | |
1524 content::ResourceDispatcherHost::Get()->AddGuestForOrigin( | |
1525 context, | |
1526 Extension::GetBaseURLFromExtensionId(web_view_info.owner_host).spec(), | |
1527 guest_process_id); | |
jam
2016/08/01 20:06:01
nit: it would be shorter to read this code if ther
ananta
2016/08/02 00:40:50
Leaving this as is. I wanted to avoid two PostTask
| |
1528 } | |
1529 } | |
1530 | |
1531 // static | |
1532 void WebViewGuest::RemoveGuestHelper(WebViewRendererState* renderer_state, | |
1533 int guest_process_id, | |
1534 int guest_routing_id, | |
1535 const content::ResourceContext* context) { | |
1536 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
1537 | |
1538 std::string owner_id; | |
1539 renderer_state->GetOwnerInfo(guest_process_id, nullptr, &owner_id); | |
1540 | |
1541 renderer_state->RemoveGuest(guest_process_id, guest_routing_id); | |
1542 // If this is no longer a guest process, then inform the | |
1543 // ResourceDispatcherHost accordingly so it can enforce accesses correctly. | |
1544 if (!renderer_state->IsGuest(guest_process_id)) { | |
1545 DCHECK(content::ResourceDispatcherHost::Get()); | |
1546 content::ResourceDispatcherHost::Get()->RemoveGuestForOrigin( | |
1547 context, | |
1548 Extension::GetBaseURLFromExtensionId(owner_id).spec(), | |
1549 guest_process_id); | |
1550 } | |
1551 } | |
1552 | |
1506 } // namespace extensions | 1553 } // namespace extensions |
OLD | NEW |