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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 web_view_info.rules_registry_id = rules_registry_id_; | 928 web_view_info.rules_registry_id = rules_registry_id_; |
928 | 929 |
929 // Get content scripts IDs added by the guest. | 930 // Get content scripts IDs added by the guest. |
930 WebViewContentScriptManager* manager = | 931 WebViewContentScriptManager* manager = |
931 WebViewContentScriptManager::Get(browser_context()); | 932 WebViewContentScriptManager::Get(browser_context()); |
932 DCHECK(manager); | 933 DCHECK(manager); |
933 web_view_info.content_script_ids = manager->GetContentScriptIDSet( | 934 web_view_info.content_script_ids = manager->GetContentScriptIDSet( |
934 web_view_info.embedder_process_id, web_view_info.instance_id); | 935 web_view_info.embedder_process_id, web_view_info.instance_id); |
935 | 936 |
936 content::BrowserThread::PostTask( | 937 content::BrowserThread::PostTask( |
937 content::BrowserThread::IO, | 938 content::BrowserThread::IO, FROM_HERE, |
938 FROM_HERE, | 939 base::Bind(&WebViewGuest::AddGuestHelper, |
939 base::Bind(&WebViewRendererState::AddGuest, | |
940 base::Unretained(WebViewRendererState::GetInstance()), | 940 base::Unretained(WebViewRendererState::GetInstance()), |
941 web_contents()->GetRenderProcessHost()->GetID(), | 941 web_contents()->GetRenderProcessHost()->GetID(), |
942 web_contents()->GetRoutingID(), | 942 web_contents()->GetRoutingID(), web_view_info, |
943 web_view_info)); | 943 browser_context()->GetResourceContext())); |
944 } | 944 } |
945 | 945 |
946 // static | 946 // static |
947 void WebViewGuest::RemoveWebViewStateFromIOThread( | 947 void WebViewGuest::RemoveWebViewStateFromIOThread( |
948 WebContents* web_contents) { | 948 WebContents* web_contents) { |
949 content::BrowserThread::PostTask( | 949 content::BrowserThread::PostTask( |
950 content::BrowserThread::IO, FROM_HERE, | 950 content::BrowserThread::IO, FROM_HERE, |
951 base::Bind( | 951 base::Bind(&WebViewGuest::RemoveGuestHelper, |
952 &WebViewRendererState::RemoveGuest, | 952 base::Unretained(WebViewRendererState::GetInstance()), |
953 base::Unretained(WebViewRendererState::GetInstance()), | 953 web_contents->GetRenderProcessHost()->GetID(), |
954 web_contents->GetRenderProcessHost()->GetID(), | 954 web_contents->GetRoutingID(), |
955 web_contents->GetRoutingID())); | 955 web_contents->GetBrowserContext()->GetResourceContext())); |
956 } | 956 } |
957 | 957 |
958 void WebViewGuest::RequestMediaAccessPermission( | 958 void WebViewGuest::RequestMediaAccessPermission( |
959 WebContents* source, | 959 WebContents* source, |
960 const content::MediaStreamRequest& request, | 960 const content::MediaStreamRequest& request, |
961 const content::MediaResponseCallback& callback) { | 961 const content::MediaResponseCallback& callback) { |
962 web_view_permission_helper_->RequestMediaAccessPermission(source, | 962 web_view_permission_helper_->RequestMediaAccessPermission(source, |
963 request, | 963 request, |
964 callback); | 964 callback); |
965 } | 965 } |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 // on the embedder. | 1498 // on the embedder. |
1499 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1499 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1500 DispatchEventToView(base::WrapUnique( | 1500 DispatchEventToView(base::WrapUnique( |
1501 new GuestViewEvent(webview::kEventExitFullscreen, std::move(args)))); | 1501 new GuestViewEvent(webview::kEventExitFullscreen, std::move(args)))); |
1502 } | 1502 } |
1503 // Since we changed fullscreen state, sending a Resize message ensures that | 1503 // Since we changed fullscreen state, sending a Resize message ensures that |
1504 // renderer/ sees the change. | 1504 // renderer/ sees the change. |
1505 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 1505 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
1506 } | 1506 } |
1507 | 1507 |
| 1508 void WebViewGuest::AddGuestHelper( |
| 1509 WebViewRendererState* renderer_state, |
| 1510 int guest_process_id, |
| 1511 int guest_routing_id, |
| 1512 const WebViewRendererState::WebViewInfo& web_view_info, |
| 1513 const content::ResourceContext* context) { |
| 1514 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 1515 |
| 1516 // Guest processes can access resources from the host (extensions). The |
| 1517 // ResourceDispatcherHost object performs access checks for certain origins |
| 1518 // like extensions when they are requested. We should inform the |
| 1519 // ResourceDispatcherHost instance about guests so it can enforce accesses |
| 1520 // correctly. This should be done only for new guest processes. |
| 1521 bool new_guest = !renderer_state->IsGuest(guest_process_id); |
| 1522 renderer_state->AddGuest(guest_process_id, guest_routing_id, web_view_info); |
| 1523 if (new_guest && !web_view_info.owner_host.empty()) { |
| 1524 content::ResourceDispatcherHost::Get()->AddProcessForOrigin( |
| 1525 context, |
| 1526 Extension::GetBaseURLFromExtensionId(web_view_info.owner_host).spec(), |
| 1527 guest_process_id, |
| 1528 false); |
| 1529 } |
| 1530 } |
| 1531 |
| 1532 void WebViewGuest::RemoveGuestHelper( |
| 1533 WebViewRendererState* renderer_state, |
| 1534 int guest_process_id, |
| 1535 int guest_routing_id, |
| 1536 const content::ResourceContext* context) { |
| 1537 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 1538 |
| 1539 std::string owner_id; |
| 1540 renderer_state->GetOwnerInfo(guest_process_id, nullptr, &owner_id); |
| 1541 |
| 1542 renderer_state->RemoveGuest(guest_process_id, guest_routing_id); |
| 1543 // If this is no longer a guest process, then inform the |
| 1544 // ResourceDispatcherHost accordingly so it can enforce accesses correctly. |
| 1545 if (!owner_id.empty() && !renderer_state->IsGuest(guest_process_id)) { |
| 1546 content::ResourceDispatcherHost::Get()->RemoveProcessForOrigin( |
| 1547 context, |
| 1548 Extension::GetBaseURLFromExtensionId(owner_id).spec(), |
| 1549 guest_process_id, |
| 1550 false); |
| 1551 } |
| 1552 } |
| 1553 |
| 1554 |
1508 } // namespace extensions | 1555 } // namespace extensions |
OLD | NEW |