OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // The next value to use for the accessibility reset token. | 76 // The next value to use for the accessibility reset token. |
77 int g_next_accessibility_reset_token = 1; | 77 int g_next_accessibility_reset_token = 1; |
78 | 78 |
79 // The (process id, routing id) pair that identifies one RenderFrame. | 79 // The (process id, routing id) pair that identifies one RenderFrame. |
80 typedef std::pair<int32, int32> RenderFrameHostID; | 80 typedef std::pair<int32, int32> RenderFrameHostID; |
81 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> | 81 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
82 RoutingIDFrameMap; | 82 RoutingIDFrameMap; |
83 base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = | 83 base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = |
84 LAZY_INSTANCE_INITIALIZER; | 84 LAZY_INSTANCE_INITIALIZER; |
85 | 85 |
86 class DesktopNotificationDelegateImpl : public DesktopNotificationDelegate { | |
87 public: | |
88 DesktopNotificationDelegateImpl(RenderFrameHost* render_frame_host, | |
89 int notification_id) | |
90 : render_process_id_(render_frame_host->GetProcess()->GetID()), | |
91 render_frame_id_(render_frame_host->GetRoutingID()), | |
92 notification_id_(notification_id) {} | |
93 | |
94 ~DesktopNotificationDelegateImpl() override {} | |
95 | |
96 void NotificationDisplayed() override { | |
97 RenderFrameHost* rfh = | |
98 RenderFrameHost::FromID(render_process_id_, render_frame_id_); | |
99 if (!rfh) | |
100 return; | |
101 | |
102 rfh->Send(new DesktopNotificationMsg_PostDisplay( | |
103 rfh->GetRoutingID(), notification_id_)); | |
104 } | |
105 | |
106 void NotificationClosed(bool by_user) override { | |
107 RenderFrameHost* rfh = | |
108 RenderFrameHost::FromID(render_process_id_, render_frame_id_); | |
109 if (!rfh) | |
110 return; | |
111 | |
112 rfh->Send(new DesktopNotificationMsg_PostClose( | |
113 rfh->GetRoutingID(), notification_id_, by_user)); | |
114 static_cast<RenderFrameHostImpl*>(rfh)->NotificationClosed( | |
115 notification_id_); | |
116 } | |
117 | |
118 void NotificationClick() override { | |
119 RenderFrameHost* rfh = | |
120 RenderFrameHost::FromID(render_process_id_, render_frame_id_); | |
121 if (!rfh) | |
122 return; | |
123 | |
124 rfh->Send(new DesktopNotificationMsg_PostClick( | |
125 rfh->GetRoutingID(), notification_id_)); | |
126 } | |
127 | |
128 private: | |
129 int render_process_id_; | |
130 int render_frame_id_; | |
131 int notification_id_; | |
132 }; | |
133 | |
134 // Translate a WebKit text direction into a base::i18n one. | 86 // Translate a WebKit text direction into a base::i18n one. |
135 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( | 87 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( |
136 blink::WebTextDirection dir) { | 88 blink::WebTextDirection dir) { |
137 switch (dir) { | 89 switch (dir) { |
138 case blink::WebTextDirectionLeftToRight: | 90 case blink::WebTextDirectionLeftToRight: |
139 return base::i18n::LEFT_TO_RIGHT; | 91 return base::i18n::LEFT_TO_RIGHT; |
140 case blink::WebTextDirectionRightToLeft: | 92 case blink::WebTextDirectionRightToLeft: |
141 return base::i18n::RIGHT_TO_LEFT; | 93 return base::i18n::RIGHT_TO_LEFT; |
142 default: | 94 default: |
143 NOTREACHED(); | 95 NOTREACHED(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, | 329 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, |
378 OnDidAccessInitialDocument) | 330 OnDidAccessInitialDocument) |
379 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) | 331 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) |
380 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) | 332 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) |
381 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 333 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
382 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 334 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
383 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 335 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
384 OnBeginNavigation) | 336 OnBeginNavigation) |
385 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_RequestPermission, | 337 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_RequestPermission, |
386 OnRequestPlatformNotificationPermission) | 338 OnRequestPlatformNotificationPermission) |
387 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, | |
388 OnShowDesktopNotification) | |
389 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, | |
390 OnCancelDesktopNotification) | |
391 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 339 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
392 OnTextSurroundingSelectionResponse) | 340 OnTextSurroundingSelectionResponse) |
393 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) | 341 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) |
394 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, | 342 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, |
395 OnAccessibilityLocationChanges) | 343 OnAccessibilityLocationChanges) |
396 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult, | 344 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult, |
397 OnAccessibilityFindInPageResult) | 345 OnAccessibilityFindInPageResult) |
398 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 346 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
399 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) | 347 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) |
400 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) | 348 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 // TODO(peter): plumb user_gesture and bridge_id. | 958 // TODO(peter): plumb user_gesture and bridge_id. |
1011 GetContentClient()->browser()->RequestPermission( | 959 GetContentClient()->browser()->RequestPermission( |
1012 content::PERMISSION_NOTIFICATIONS, | 960 content::PERMISSION_NOTIFICATIONS, |
1013 delegate()->GetAsWebContents(), | 961 delegate()->GetAsWebContents(), |
1014 routing_id_, | 962 routing_id_, |
1015 origin, | 963 origin, |
1016 true, // user_gesture, | 964 true, // user_gesture, |
1017 done_callback); | 965 done_callback); |
1018 } | 966 } |
1019 | 967 |
1020 void RenderFrameHostImpl::OnShowDesktopNotification( | |
1021 int notification_id, | |
1022 const ShowDesktopNotificationHostMsgParams& params) { | |
1023 scoped_ptr<DesktopNotificationDelegateImpl> delegate( | |
1024 new DesktopNotificationDelegateImpl(this, notification_id)); | |
1025 | |
1026 base::Closure cancel_callback; | |
1027 GetContentClient()->browser()->ShowDesktopNotification( | |
1028 params, | |
1029 GetSiteInstance()->GetBrowserContext(), | |
1030 GetProcess()->GetID(), | |
1031 delegate.Pass(), | |
1032 &cancel_callback); | |
1033 | |
1034 cancel_notification_callbacks_[notification_id] = cancel_callback; | |
1035 } | |
1036 | |
1037 void RenderFrameHostImpl::OnCancelDesktopNotification(int notification_id) { | |
1038 if (!cancel_notification_callbacks_.count(notification_id)) | |
1039 return; | |
1040 | |
1041 cancel_notification_callbacks_[notification_id].Run(); | |
1042 cancel_notification_callbacks_.erase(notification_id); | |
1043 } | |
1044 | |
1045 void RenderFrameHostImpl::OnTextSurroundingSelectionResponse( | 968 void RenderFrameHostImpl::OnTextSurroundingSelectionResponse( |
1046 const base::string16& content, | 969 const base::string16& content, |
1047 size_t start_offset, | 970 size_t start_offset, |
1048 size_t end_offset) { | 971 size_t end_offset) { |
1049 render_view_host_->OnTextSurroundingSelectionResponse( | 972 render_view_host_->OnTextSurroundingSelectionResponse( |
1050 content, start_offset, end_offset); | 973 content, start_offset, end_offset); |
1051 } | 974 } |
1052 | 975 |
1053 void RenderFrameHostImpl::OnDidAccessInitialDocument() { | 976 void RenderFrameHostImpl::OnDidAccessInitialDocument() { |
1054 delegate_->DidAccessInitialDocument(); | 977 delegate_->DidAccessInitialDocument(); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 // If we are waiting for an unload or beforeunload ack and the user has | 1369 // If we are waiting for an unload or beforeunload ack and the user has |
1447 // suppressed messages, kill the tab immediately; a page that's spamming | 1370 // suppressed messages, kill the tab immediately; a page that's spamming |
1448 // alerts in onbeforeunload is presumably malicious, so there's no point in | 1371 // alerts in onbeforeunload is presumably malicious, so there's no point in |
1449 // continuing to run its script and dragging out the process. | 1372 // continuing to run its script and dragging out the process. |
1450 // This must be done after sending the reply since RenderView can't close | 1373 // This must be done after sending the reply since RenderView can't close |
1451 // correctly while waiting for a response. | 1374 // correctly while waiting for a response. |
1452 if (is_waiting && dialog_was_suppressed) | 1375 if (is_waiting && dialog_was_suppressed) |
1453 render_view_host_->delegate_->RendererUnresponsive(render_view_host_); | 1376 render_view_host_->delegate_->RendererUnresponsive(render_view_host_); |
1454 } | 1377 } |
1455 | 1378 |
1456 void RenderFrameHostImpl::NotificationClosed(int notification_id) { | |
1457 cancel_notification_callbacks_.erase(notification_id); | |
1458 } | |
1459 | |
1460 // PlzNavigate | 1379 // PlzNavigate |
1461 void RenderFrameHostImpl::CommitNavigation( | 1380 void RenderFrameHostImpl::CommitNavigation( |
1462 ResourceResponse* response, | 1381 ResourceResponse* response, |
1463 scoped_ptr<StreamHandle> body, | 1382 scoped_ptr<StreamHandle> body, |
1464 const CommonNavigationParams& common_params, | 1383 const CommonNavigationParams& common_params, |
1465 const CommitNavigationParams& commit_params) { | 1384 const CommitNavigationParams& commit_params) { |
1466 // TODO(clamy): Check if we have to add security checks for the browser plugin | 1385 // TODO(clamy): Check if we have to add security checks for the browser plugin |
1467 // guests. | 1386 // guests. |
1468 | 1387 |
1469 Send(new FrameMsg_CommitNavigation( | 1388 Send(new FrameMsg_CommitNavigation( |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 void RenderFrameHostImpl::DidUseGeolocationPermission() { | 1603 void RenderFrameHostImpl::DidUseGeolocationPermission() { |
1685 RenderFrameHost* top_frame = frame_tree_node()->frame_tree()->GetMainFrame(); | 1604 RenderFrameHost* top_frame = frame_tree_node()->frame_tree()->GetMainFrame(); |
1686 GetContentClient()->browser()->RegisterPermissionUsage( | 1605 GetContentClient()->browser()->RegisterPermissionUsage( |
1687 PERMISSION_GEOLOCATION, | 1606 PERMISSION_GEOLOCATION, |
1688 delegate_->GetAsWebContents(), | 1607 delegate_->GetAsWebContents(), |
1689 GetLastCommittedURL().GetOrigin(), | 1608 GetLastCommittedURL().GetOrigin(), |
1690 top_frame->GetLastCommittedURL().GetOrigin()); | 1609 top_frame->GetLastCommittedURL().GetOrigin()); |
1691 } | 1610 } |
1692 | 1611 |
1693 } // namespace content | 1612 } // namespace content |
OLD | NEW |