OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/render_view_host.h" | 5 #include "content/browser/renderer_host/render_view_host.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "content/browser/child_process_security_policy.h" | 21 #include "content/browser/child_process_security_policy_impl.h" |
22 #include "content/browser/cross_site_request_manager.h" | 22 #include "content/browser/cross_site_request_manager.h" |
23 #include "content/browser/gpu/gpu_surface_tracker.h" | 23 #include "content/browser/gpu/gpu_surface_tracker.h" |
24 #include "content/browser/host_zoom_map_impl.h" | 24 #include "content/browser/host_zoom_map_impl.h" |
25 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 25 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
26 #include "content/browser/power_save_blocker.h" | 26 #include "content/browser/power_save_blocker.h" |
27 #include "content/browser/renderer_host/render_process_host_impl.h" | 27 #include "content/browser/renderer_host/render_process_host_impl.h" |
28 #include "content/browser/renderer_host/render_widget_host.h" | 28 #include "content/browser/renderer_host/render_widget_host.h" |
29 #include "content/browser/renderer_host/render_widget_host_view.h" | 29 #include "content/browser/renderer_host/render_widget_host_view.h" |
30 #include "content/common/desktop_notification_messages.h" | 30 #include "content/common/desktop_notification_messages.h" |
31 #include "content/common/drag_messages.h" | 31 #include "content/common/drag_messages.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return process()->HasConnection() && renderer_initialized_; | 219 return process()->HasConnection() && renderer_initialized_; |
220 } | 220 } |
221 | 221 |
222 void RenderViewHost::SyncRendererPrefs() { | 222 void RenderViewHost::SyncRendererPrefs() { |
223 Send(new ViewMsg_SetRendererPrefs(routing_id(), | 223 Send(new ViewMsg_SetRendererPrefs(routing_id(), |
224 delegate_->GetRendererPrefs( | 224 delegate_->GetRendererPrefs( |
225 process()->GetBrowserContext()))); | 225 process()->GetBrowserContext()))); |
226 } | 226 } |
227 | 227 |
228 void RenderViewHost::Navigate(const ViewMsg_Navigate_Params& params) { | 228 void RenderViewHost::Navigate(const ViewMsg_Navigate_Params& params) { |
229 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( | 229 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( |
230 process()->GetID(), params.url); | 230 process()->GetID(), params.url); |
231 | 231 |
232 ViewMsg_Navigate* nav_message = new ViewMsg_Navigate(routing_id(), params); | 232 ViewMsg_Navigate* nav_message = new ViewMsg_Navigate(routing_id(), params); |
233 | 233 |
234 // Only send the message if we aren't suspended at the start of a cross-site | 234 // Only send the message if we aren't suspended at the start of a cross-site |
235 // request. | 235 // request. |
236 if (navigations_suspended_) { | 236 if (navigations_suspended_) { |
237 // Shouldn't be possible to have a second navigation while suspended, since | 237 // Shouldn't be possible to have a second navigation while suspended, since |
238 // navigations will only be suspended during a cross-site request. If a | 238 // navigations will only be suspended during a cross-site request. If a |
239 // second navigation occurs, TabContents will cancel this pending RVH | 239 // second navigation occurs, TabContents will cancel this pending RVH |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 int RenderViewHost::GetPendingRequestId() { | 421 int RenderViewHost::GetPendingRequestId() { |
422 return pending_request_id_; | 422 return pending_request_id_; |
423 } | 423 } |
424 | 424 |
425 void RenderViewHost::DragTargetDragEnter( | 425 void RenderViewHost::DragTargetDragEnter( |
426 const WebDropData& drop_data, | 426 const WebDropData& drop_data, |
427 const gfx::Point& client_pt, | 427 const gfx::Point& client_pt, |
428 const gfx::Point& screen_pt, | 428 const gfx::Point& screen_pt, |
429 WebDragOperationsMask operations_allowed) { | 429 WebDragOperationsMask operations_allowed) { |
430 const int renderer_id = process()->GetID(); | 430 const int renderer_id = process()->GetID(); |
431 ChildProcessSecurityPolicy* policy = | 431 ChildProcessSecurityPolicyImpl* policy = |
432 ChildProcessSecurityPolicy::GetInstance(); | 432 ChildProcessSecurityPolicyImpl::GetInstance(); |
433 | 433 |
434 // The URL could have been cobbled together from any highlighted text string, | 434 // The URL could have been cobbled together from any highlighted text string, |
435 // and can't be interpreted as a capability. | 435 // and can't be interpreted as a capability. |
436 WebDropData filtered_data(drop_data); | 436 WebDropData filtered_data(drop_data); |
437 FilterURL(policy, renderer_id, &filtered_data.url); | 437 FilterURL(policy, renderer_id, &filtered_data.url); |
438 | 438 |
439 // The filenames vector, on the other hand, does represent a capability to | 439 // The filenames vector, on the other hand, does represent a capability to |
440 // access the given files. | 440 // access the given files. |
441 std::set<FilePath> filesets; | 441 std::set<FilePath> filesets; |
442 for (std::vector<string16>::iterator iter(filtered_data.filenames.begin()); | 442 for (std::vector<string16>::iterator iter(filtered_data.filenames.begin()); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 gfx::Point(screen_x, screen_y), | 599 gfx::Point(screen_x, screen_y), |
600 false, WebDragOperationNone)); | 600 false, WebDragOperationNone)); |
601 } | 601 } |
602 | 602 |
603 void RenderViewHost::DragSourceSystemDragEnded() { | 603 void RenderViewHost::DragSourceSystemDragEnded() { |
604 Send(new DragMsg_SourceSystemDragEnded(routing_id())); | 604 Send(new DragMsg_SourceSystemDragEnded(routing_id())); |
605 } | 605 } |
606 | 606 |
607 void RenderViewHost::AllowBindings(int bindings_flags) { | 607 void RenderViewHost::AllowBindings(int bindings_flags) { |
608 if (bindings_flags & content::BINDINGS_POLICY_WEB_UI) { | 608 if (bindings_flags & content::BINDINGS_POLICY_WEB_UI) { |
609 ChildProcessSecurityPolicy::GetInstance()->GrantWebUIBindings( | 609 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( |
610 process()->GetID()); | 610 process()->GetID()); |
611 } | 611 } |
612 | 612 |
613 enabled_bindings_ |= bindings_flags; | 613 enabled_bindings_ |= bindings_flags; |
614 if (renderer_initialized_) | 614 if (renderer_initialized_) |
615 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); | 615 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); |
616 } | 616 } |
617 | 617 |
618 void RenderViewHost::SetWebUIProperty(const std::string& name, | 618 void RenderViewHost::SetWebUIProperty(const std::string& name, |
619 const std::string& value) { | 619 const std::string& value) { |
(...skipping 22 matching lines...) Expand all Loading... |
642 void RenderViewHost::SetInitialFocus(bool reverse) { | 642 void RenderViewHost::SetInitialFocus(bool reverse) { |
643 Send(new ViewMsg_SetInitialFocus(routing_id(), reverse)); | 643 Send(new ViewMsg_SetInitialFocus(routing_id(), reverse)); |
644 } | 644 } |
645 | 645 |
646 void RenderViewHost::FilesSelectedInChooser( | 646 void RenderViewHost::FilesSelectedInChooser( |
647 const std::vector<FilePath>& files, | 647 const std::vector<FilePath>& files, |
648 int permissions) { | 648 int permissions) { |
649 // Grant the security access requested to the given files. | 649 // Grant the security access requested to the given files. |
650 for (std::vector<FilePath>::const_iterator file = files.begin(); | 650 for (std::vector<FilePath>::const_iterator file = files.begin(); |
651 file != files.end(); ++file) { | 651 file != files.end(); ++file) { |
652 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 652 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( |
653 process()->GetID(), *file, permissions); | 653 process()->GetID(), *file, permissions); |
654 } | 654 } |
655 Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); | 655 Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); |
656 } | 656 } |
657 | 657 |
658 void RenderViewHost::DirectoryEnumerationFinished( | 658 void RenderViewHost::DirectoryEnumerationFinished( |
659 int request_id, | 659 int request_id, |
660 const std::vector<FilePath>& files) { | 660 const std::vector<FilePath>& files) { |
661 // Grant the security access requested to the given files. | 661 // Grant the security access requested to the given files. |
662 for (std::vector<FilePath>::const_iterator file = files.begin(); | 662 for (std::vector<FilePath>::const_iterator file = files.begin(); |
663 file != files.end(); ++file) { | 663 file != files.end(); ++file) { |
664 ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( | 664 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
665 process()->GetID(), *file); | 665 process()->GetID(), *file); |
666 } | 666 } |
667 Send(new ViewMsg_EnumerateDirectoryResponse(routing_id(), | 667 Send(new ViewMsg_EnumerateDirectoryResponse(routing_id(), |
668 request_id, | 668 request_id, |
669 files)); | 669 files)); |
670 } | 670 } |
671 | 671 |
672 void RenderViewHost::LoadStateChanged(const GURL& url, | 672 void RenderViewHost::LoadStateChanged(const GURL& url, |
673 const net::LoadStateWithParam& load_state, | 673 const net::LoadStateWithParam& load_state, |
674 uint64 upload_position, | 674 uint64 upload_position, |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 | 931 |
932 // If we're waiting for an unload ack from this renderer and we receive a | 932 // If we're waiting for an unload ack from this renderer and we receive a |
933 // Navigate message, then the renderer was navigating before it received the | 933 // Navigate message, then the renderer was navigating before it received the |
934 // unload request. It will either respond to the unload request soon or our | 934 // unload request. It will either respond to the unload request soon or our |
935 // timer will expire. Either way, we should ignore this message, because we | 935 // timer will expire. Either way, we should ignore this message, because we |
936 // have already committed to closing this renderer. | 936 // have already committed to closing this renderer. |
937 if (is_waiting_for_unload_ack_) | 937 if (is_waiting_for_unload_ack_) |
938 return; | 938 return; |
939 | 939 |
940 const int renderer_id = process()->GetID(); | 940 const int renderer_id = process()->GetID(); |
941 ChildProcessSecurityPolicy* policy = | 941 ChildProcessSecurityPolicyImpl* policy = |
942 ChildProcessSecurityPolicy::GetInstance(); | 942 ChildProcessSecurityPolicyImpl::GetInstance(); |
943 // Without this check, an evil renderer can trick the browser into creating | 943 // Without this check, an evil renderer can trick the browser into creating |
944 // a navigation entry for a banned URL. If the user clicks the back button | 944 // a navigation entry for a banned URL. If the user clicks the back button |
945 // followed by the forward button (or clicks reload, or round-trips through | 945 // followed by the forward button (or clicks reload, or round-trips through |
946 // session restore, etc), we'll think that the browser commanded the | 946 // session restore, etc), we'll think that the browser commanded the |
947 // renderer to load the URL and grant the renderer the privileges to request | 947 // renderer to load the URL and grant the renderer the privileges to request |
948 // the URL. To prevent this attack, we block the renderer from inserting | 948 // the URL. To prevent this attack, we block the renderer from inserting |
949 // banned URLs into the navigation controller in the first place. | 949 // banned URLs into the navigation controller in the first place. |
950 FilterURL(policy, renderer_id, &validated_params.url); | 950 FilterURL(policy, renderer_id, &validated_params.url); |
951 FilterURL(policy, renderer_id, &validated_params.referrer.url); | 951 FilterURL(policy, renderer_id, &validated_params.referrer.url); |
952 for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); | 952 for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 | 1033 |
1034 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { | 1034 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { |
1035 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); | 1035 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); |
1036 if (!view) | 1036 if (!view) |
1037 return; | 1037 return; |
1038 | 1038 |
1039 // Validate the URLs in |params|. If the renderer can't request the URLs | 1039 // Validate the URLs in |params|. If the renderer can't request the URLs |
1040 // directly, don't show them in the context menu. | 1040 // directly, don't show them in the context menu. |
1041 ContextMenuParams validated_params(params); | 1041 ContextMenuParams validated_params(params); |
1042 int renderer_id = process()->GetID(); | 1042 int renderer_id = process()->GetID(); |
1043 ChildProcessSecurityPolicy* policy = | 1043 ChildProcessSecurityPolicyImpl* policy = |
1044 ChildProcessSecurityPolicy::GetInstance(); | 1044 ChildProcessSecurityPolicyImpl::GetInstance(); |
1045 | 1045 |
1046 // We don't validate |unfiltered_link_url| so that this field can be used | 1046 // We don't validate |unfiltered_link_url| so that this field can be used |
1047 // when users want to copy the original link URL. | 1047 // when users want to copy the original link URL. |
1048 FilterURL(policy, renderer_id, &validated_params.link_url); | 1048 FilterURL(policy, renderer_id, &validated_params.link_url); |
1049 FilterURL(policy, renderer_id, &validated_params.src_url); | 1049 FilterURL(policy, renderer_id, &validated_params.src_url); |
1050 FilterURL(policy, renderer_id, &validated_params.page_url); | 1050 FilterURL(policy, renderer_id, &validated_params.page_url); |
1051 FilterURL(policy, renderer_id, &validated_params.frame_url); | 1051 FilterURL(policy, renderer_id, &validated_params.frame_url); |
1052 | 1052 |
1053 view->ShowContextMenu(validated_params); | 1053 view->ShowContextMenu(validated_params); |
1054 } | 1054 } |
1055 | 1055 |
1056 void RenderViewHost::OnMsgToggleFullscreen(bool enter_fullscreen) { | 1056 void RenderViewHost::OnMsgToggleFullscreen(bool enter_fullscreen) { |
1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1058 delegate_->ToggleFullscreenMode(enter_fullscreen); | 1058 delegate_->ToggleFullscreenMode(enter_fullscreen); |
1059 } | 1059 } |
1060 | 1060 |
1061 void RenderViewHost::OnMsgOpenURL(const GURL& url, | 1061 void RenderViewHost::OnMsgOpenURL(const GURL& url, |
1062 const content::Referrer& referrer, | 1062 const content::Referrer& referrer, |
1063 WindowOpenDisposition disposition, | 1063 WindowOpenDisposition disposition, |
1064 int64 source_frame_id) { | 1064 int64 source_frame_id) { |
1065 GURL validated_url(url); | 1065 GURL validated_url(url); |
1066 FilterURL(ChildProcessSecurityPolicy::GetInstance(), | 1066 FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(), |
1067 process()->GetID(), &validated_url); | 1067 process()->GetID(), &validated_url); |
1068 | 1068 |
1069 delegate_->RequestOpenURL( | 1069 delegate_->RequestOpenURL( |
1070 validated_url, referrer, disposition, source_frame_id); | 1070 validated_url, referrer, disposition, source_frame_id); |
1071 } | 1071 } |
1072 | 1072 |
1073 void RenderViewHost::OnMsgDidContentsPreferredSizeChange( | 1073 void RenderViewHost::OnMsgDidContentsPreferredSizeChange( |
1074 const gfx::Size& new_size) { | 1074 const gfx::Size& new_size) { |
1075 delegate_->UpdatePreferredSize(new_size); | 1075 delegate_->UpdatePreferredSize(new_size); |
1076 } | 1076 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 void RenderViewHost::OnMsgStartDragging( | 1136 void RenderViewHost::OnMsgStartDragging( |
1137 const WebDropData& drop_data, | 1137 const WebDropData& drop_data, |
1138 WebDragOperationsMask drag_operations_mask, | 1138 WebDragOperationsMask drag_operations_mask, |
1139 const SkBitmap& image, | 1139 const SkBitmap& image, |
1140 const gfx::Point& image_offset) { | 1140 const gfx::Point& image_offset) { |
1141 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); | 1141 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); |
1142 if (!view) | 1142 if (!view) |
1143 return; | 1143 return; |
1144 | 1144 |
1145 WebDropData filtered_data(drop_data); | 1145 WebDropData filtered_data(drop_data); |
1146 ChildProcessSecurityPolicy* policy = | 1146 ChildProcessSecurityPolicyImpl* policy = |
1147 ChildProcessSecurityPolicy::GetInstance(); | 1147 ChildProcessSecurityPolicyImpl::GetInstance(); |
1148 | 1148 |
1149 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar. | 1149 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar. |
1150 if (!filtered_data.url.SchemeIs(chrome::kJavaScriptScheme)) | 1150 if (!filtered_data.url.SchemeIs(chrome::kJavaScriptScheme)) |
1151 FilterURL(policy, process()->GetID(), &filtered_data.url); | 1151 FilterURL(policy, process()->GetID(), &filtered_data.url); |
1152 FilterURL(policy, process()->GetID(), &filtered_data.html_base_url); | 1152 FilterURL(policy, process()->GetID(), &filtered_data.html_base_url); |
1153 view->StartDragging(filtered_data, drag_operations_mask, image, image_offset); | 1153 view->StartDragging(filtered_data, drag_operations_mask, image, image_offset); |
1154 } | 1154 } |
1155 | 1155 |
1156 void RenderViewHost::OnUpdateDragCursor(WebDragOperation current_op) { | 1156 void RenderViewHost::OnUpdateDragCursor(WebDragOperation current_op) { |
1157 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); | 1157 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 | 1319 |
1320 void RenderViewHost::DidCancelPopupMenu() { | 1320 void RenderViewHost::DidCancelPopupMenu() { |
1321 Send(new ViewMsg_SelectPopupMenuItem(routing_id(), -1)); | 1321 Send(new ViewMsg_SelectPopupMenuItem(routing_id(), -1)); |
1322 } | 1322 } |
1323 #endif | 1323 #endif |
1324 | 1324 |
1325 void RenderViewHost::ToggleSpeechInput() { | 1325 void RenderViewHost::ToggleSpeechInput() { |
1326 Send(new SpeechInputMsg_ToggleSpeechInput(routing_id())); | 1326 Send(new SpeechInputMsg_ToggleSpeechInput(routing_id())); |
1327 } | 1327 } |
1328 | 1328 |
1329 void RenderViewHost::FilterURL(ChildProcessSecurityPolicy* policy, | 1329 void RenderViewHost::FilterURL(ChildProcessSecurityPolicyImpl* policy, |
1330 int renderer_id, | 1330 int renderer_id, |
1331 GURL* url) { | 1331 GURL* url) { |
1332 if (!url->is_valid()) | 1332 if (!url->is_valid()) |
1333 return; // We don't need to block invalid URLs. | 1333 return; // We don't need to block invalid URLs. |
1334 | 1334 |
1335 if (url->SchemeIs(chrome::kAboutScheme)) { | 1335 if (url->SchemeIs(chrome::kAboutScheme)) { |
1336 // The renderer treats all URLs in the about: scheme as being about:blank. | 1336 // The renderer treats all URLs in the about: scheme as being about:blank. |
1337 // Canonicalize about: URLs to about:blank. | 1337 // Canonicalize about: URLs to about:blank. |
1338 *url = GURL(chrome::kAboutBlankURL); | 1338 *url = GURL(chrome::kAboutBlankURL); |
1339 } | 1339 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 DomOperationNotificationDetails details(json_string, automation_id); | 1568 DomOperationNotificationDetails details(json_string, automation_id); |
1569 content::NotificationService::current()->Notify( | 1569 content::NotificationService::current()->Notify( |
1570 content::NOTIFICATION_DOM_OPERATION_RESPONSE, | 1570 content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
1571 content::Source<RenderViewHost>(this), | 1571 content::Source<RenderViewHost>(this), |
1572 content::Details<DomOperationNotificationDetails>(&details)); | 1572 content::Details<DomOperationNotificationDetails>(&details)); |
1573 } | 1573 } |
1574 | 1574 |
1575 void RenderViewHost::ClearPowerSaveBlockers() { | 1575 void RenderViewHost::ClearPowerSaveBlockers() { |
1576 STLDeleteValues(&power_save_blockers_); | 1576 STLDeleteValues(&power_save_blockers_); |
1577 } | 1577 } |
OLD | NEW |