| 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/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
| 12 #include "base/debug/dump_without_crashing.h" | 12 #include "base/debug/dump_without_crashing.h" |
| 13 #include "base/i18n/char_iterator.h" | 13 #include "base/i18n/char_iterator.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "content/child/appcache/appcache_dispatcher.h" | 16 #include "content/child/appcache/appcache_dispatcher.h" |
| 17 #include "content/child/plugin_messages.h" | 17 #include "content/child/plugin_messages.h" |
| 18 #include "content/child/quota_dispatcher.h" | 18 #include "content/child/quota_dispatcher.h" |
| 19 #include "content/child/request_extra_data.h" | 19 #include "content/child/request_extra_data.h" |
| 20 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 20 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 21 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
| 22 #include "content/common/socket_stream_handle_data.h" | 22 #include "content/common/socket_stream_handle_data.h" |
| 23 #include "content/common/swapped_out_messages.h" | 23 #include "content/common/swapped_out_messages.h" |
| 24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
| 25 #include "content/public/common/content_constants.h" | 25 #include "content/public/common/content_constants.h" |
| 26 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/common/context_menu_params.h" |
| 27 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 29 #include "content/public/common/url_utils.h" |
| 28 #include "content/public/renderer/content_renderer_client.h" | 30 #include "content/public/renderer/content_renderer_client.h" |
| 31 #include "content/public/renderer/context_menu_client.h" |
| 29 #include "content/public/renderer/document_state.h" | 32 #include "content/public/renderer/document_state.h" |
| 30 #include "content/public/renderer/navigation_state.h" | 33 #include "content/public/renderer/navigation_state.h" |
| 31 #include "content/public/renderer/render_frame_observer.h" | 34 #include "content/public/renderer/render_frame_observer.h" |
| 32 #include "content/renderer/accessibility/renderer_accessibility.h" | 35 #include "content/renderer/accessibility/renderer_accessibility.h" |
| 33 #include "content/renderer/browser_plugin/browser_plugin.h" | 36 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 34 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 37 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 35 #include "content/renderer/child_frame_compositing_helper.h" | 38 #include "content/renderer/child_frame_compositing_helper.h" |
| 39 #include "content/renderer/context_menu_params_builder.h" |
| 36 #include "content/renderer/internal_document_state_data.h" | 40 #include "content/renderer/internal_document_state_data.h" |
| 37 #include "content/renderer/npapi/plugin_channel_host.h" | 41 #include "content/renderer/npapi/plugin_channel_host.h" |
| 38 #include "content/renderer/render_thread_impl.h" | 42 #include "content/renderer/render_thread_impl.h" |
| 39 #include "content/renderer/render_view_impl.h" | 43 #include "content/renderer/render_view_impl.h" |
| 40 #include "content/renderer/render_widget_fullscreen_pepper.h" | 44 #include "content/renderer/render_widget_fullscreen_pepper.h" |
| 41 #include "content/renderer/renderer_webapplicationcachehost_impl.h" | 45 #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
| 42 #include "content/renderer/shared_worker_repository.h" | 46 #include "content/renderer/shared_worker_repository.h" |
| 43 #include "content/renderer/websharedworker_proxy.h" | 47 #include "content/renderer/websharedworker_proxy.h" |
| 44 #include "net/base/net_errors.h" | 48 #include "net/base/net_errors.h" |
| 45 #include "net/http/http_util.h" | 49 #include "net/http/http_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 #include "content/renderer/pepper/pepper_browser_connection.h" | 69 #include "content/renderer/pepper/pepper_browser_connection.h" |
| 66 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 70 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 67 #include "content/renderer/pepper/pepper_webplugin_impl.h" | 71 #include "content/renderer/pepper/pepper_webplugin_impl.h" |
| 68 #include "content/renderer/pepper/plugin_module.h" | 72 #include "content/renderer/pepper/plugin_module.h" |
| 69 #endif | 73 #endif |
| 70 | 74 |
| 71 #if defined(ENABLE_WEBRTC) | 75 #if defined(ENABLE_WEBRTC) |
| 72 #include "content/renderer/media/rtc_peer_connection_handler.h" | 76 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 73 #endif | 77 #endif |
| 74 | 78 |
| 79 using blink::WebContextMenuData; |
| 75 using blink::WebDataSource; | 80 using blink::WebDataSource; |
| 76 using blink::WebDocument; | 81 using blink::WebDocument; |
| 77 using blink::WebFrame; | 82 using blink::WebFrame; |
| 78 using blink::WebNavigationPolicy; | 83 using blink::WebNavigationPolicy; |
| 79 using blink::WebPluginParams; | 84 using blink::WebPluginParams; |
| 80 using blink::WebReferrerPolicy; | 85 using blink::WebReferrerPolicy; |
| 81 using blink::WebSearchableFormData; | 86 using blink::WebSearchableFormData; |
| 82 using blink::WebSecurityOrigin; | 87 using blink::WebSecurityOrigin; |
| 83 using blink::WebServiceWorkerProvider; | 88 using blink::WebServiceWorkerProvider; |
| 84 using blink::WebStorageQuotaCallbacks; | 89 using blink::WebStorageQuotaCallbacks; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 return true; | 389 return true; |
| 385 } | 390 } |
| 386 | 391 |
| 387 bool handled = true; | 392 bool handled = true; |
| 388 bool msg_is_ok = true; | 393 bool msg_is_ok = true; |
| 389 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameImpl, msg, msg_is_ok) | 394 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameImpl, msg, msg_is_ok) |
| 390 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) | 395 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) |
| 391 IPC_MESSAGE_HANDLER(FrameMsg_BuffersSwapped, OnBuffersSwapped) | 396 IPC_MESSAGE_HANDLER(FrameMsg_BuffersSwapped, OnBuffersSwapped) |
| 392 IPC_MESSAGE_HANDLER_GENERIC(FrameMsg_CompositorFrameSwapped, | 397 IPC_MESSAGE_HANDLER_GENERIC(FrameMsg_CompositorFrameSwapped, |
| 393 OnCompositorFrameSwapped(msg)) | 398 OnCompositorFrameSwapped(msg)) |
| 399 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) |
| 400 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, |
| 401 OnCustomContextMenuAction) |
| 394 IPC_END_MESSAGE_MAP_EX() | 402 IPC_END_MESSAGE_MAP_EX() |
| 395 | 403 |
| 396 if (!msg_is_ok) { | 404 if (!msg_is_ok) { |
| 397 // The message had a handler, but its deserialization failed. | 405 // The message had a handler, but its deserialization failed. |
| 398 // Kill the renderer to avoid potential spoofing attacks. | 406 // Kill the renderer to avoid potential spoofing attacks. |
| 399 CHECK(false) << "Unable to deserialize message in RenderFrameImpl."; | 407 CHECK(false) << "Unable to deserialize message in RenderFrameImpl."; |
| 400 } | 408 } |
| 401 | 409 |
| 402 return handled; | 410 return handled; |
| 403 } | 411 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ChildFrameCompositingHelper::CreateCompositingHelperForRenderFrame( | 475 ChildFrameCompositingHelper::CreateCompositingHelperForRenderFrame( |
| 468 frame_, this, routing_id_); | 476 frame_, this, routing_id_); |
| 469 compositing_helper_->EnableCompositing(true); | 477 compositing_helper_->EnableCompositing(true); |
| 470 } | 478 } |
| 471 compositing_helper_->OnCompositorFrameSwapped(frame.Pass(), | 479 compositing_helper_->OnCompositorFrameSwapped(frame.Pass(), |
| 472 param.a.producing_route_id, | 480 param.a.producing_route_id, |
| 473 param.a.output_surface_id, | 481 param.a.output_surface_id, |
| 474 param.a.producing_host_id); | 482 param.a.producing_host_id); |
| 475 } | 483 } |
| 476 | 484 |
| 485 void RenderFrameImpl::OnContextMenuClosed( |
| 486 const CustomContextMenuContext& custom_context) { |
| 487 if (custom_context.request_id) { |
| 488 // External request, should be in our map. |
| 489 ContextMenuClient* client = |
| 490 pending_context_menus_.Lookup(custom_context.request_id); |
| 491 if (client) { |
| 492 client->OnMenuClosed(custom_context.request_id); |
| 493 pending_context_menus_.Remove(custom_context.request_id); |
| 494 } |
| 495 } else { |
| 496 // Internal request, forward to WebKit. |
| 497 render_view_->context_menu_node_.reset(); |
| 498 } |
| 499 } |
| 500 |
| 501 void RenderFrameImpl::OnCustomContextMenuAction( |
| 502 const CustomContextMenuContext& custom_context, |
| 503 unsigned action) { |
| 504 if (custom_context.request_id) { |
| 505 // External context menu request, look in our map. |
| 506 ContextMenuClient* client = |
| 507 pending_context_menus_.Lookup(custom_context.request_id); |
| 508 if (client) |
| 509 client->OnMenuAction(custom_context.request_id, action); |
| 510 } else { |
| 511 // Internal request, forward to WebKit. |
| 512 render_view_->webview()->performCustomContextMenuAction(action); |
| 513 } |
| 514 } |
| 515 |
| 516 bool RenderFrameImpl::ShouldUpdateSelectionTextFromContextMenuParams( |
| 517 const base::string16& selection_text, |
| 518 size_t selection_text_offset, |
| 519 const gfx::Range& selection_range, |
| 520 const ContextMenuParams& params) { |
| 521 base::string16 trimmed_selection_text; |
| 522 if (!selection_text.empty() && !selection_range.is_empty()) { |
| 523 const int start = selection_range.GetMin() - selection_text_offset; |
| 524 const size_t length = selection_range.length(); |
| 525 if (start >= 0 && start + length <= selection_text.length()) { |
| 526 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL, |
| 527 &trimmed_selection_text); |
| 528 } |
| 529 } |
| 530 base::string16 trimmed_params_text; |
| 531 TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text); |
| 532 return trimmed_params_text != trimmed_selection_text; |
| 533 } |
| 534 |
| 477 void RenderFrameImpl::DidCommitCompositorFrame() { | 535 void RenderFrameImpl::DidCommitCompositorFrame() { |
| 478 if (compositing_helper_) | 536 if (compositing_helper_) |
| 479 compositing_helper_->DidCommitCompositorFrame(); | 537 compositing_helper_->DidCommitCompositorFrame(); |
| 480 } | 538 } |
| 481 | 539 |
| 482 RenderView* RenderFrameImpl::GetRenderView() { | 540 RenderView* RenderFrameImpl::GetRenderView() { |
| 483 return render_view_.get(); | 541 return render_view_.get(); |
| 484 } | 542 } |
| 485 | 543 |
| 486 int RenderFrameImpl::GetRoutingID() { | 544 int RenderFrameImpl::GetRoutingID() { |
| 487 return routing_id_; | 545 return routing_id_; |
| 488 } | 546 } |
| 489 | 547 |
| 490 blink::WebFrame* RenderFrameImpl::GetWebFrame() { | 548 blink::WebFrame* RenderFrameImpl::GetWebFrame() { |
| 491 DCHECK(frame_); | 549 DCHECK(frame_); |
| 492 return frame_; | 550 return frame_; |
| 493 } | 551 } |
| 494 | 552 |
| 495 WebPreferences& RenderFrameImpl::GetWebkitPreferences() { | 553 WebPreferences& RenderFrameImpl::GetWebkitPreferences() { |
| 496 return render_view_->GetWebkitPreferences(); | 554 return render_view_->GetWebkitPreferences(); |
| 497 } | 555 } |
| 498 | 556 |
| 499 int RenderFrameImpl::ShowContextMenu(ContextMenuClient* client, | 557 int RenderFrameImpl::ShowContextMenu(ContextMenuClient* client, |
| 500 const ContextMenuParams& params) { | 558 const ContextMenuParams& params) { |
| 501 return render_view_->ShowContextMenu(client, params); | 559 DCHECK(client); // A null client means "internal" when we issue callbacks. |
| 560 ContextMenuParams our_params(params); |
| 561 our_params.custom_context.request_id = pending_context_menus_.Add(client); |
| 562 Send(new FrameHostMsg_ContextMenu(routing_id_, our_params)); |
| 563 return our_params.custom_context.request_id; |
| 502 } | 564 } |
| 503 | 565 |
| 504 void RenderFrameImpl::CancelContextMenu(int request_id) { | 566 void RenderFrameImpl::CancelContextMenu(int request_id) { |
| 505 return render_view_->CancelContextMenu(request_id); | 567 DCHECK(pending_context_menus_.Lookup(request_id)); |
| 568 pending_context_menus_.Remove(request_id); |
| 506 } | 569 } |
| 507 | 570 |
| 508 blink::WebPlugin* RenderFrameImpl::CreatePlugin( | 571 blink::WebPlugin* RenderFrameImpl::CreatePlugin( |
| 509 blink::WebFrame* frame, | 572 blink::WebFrame* frame, |
| 510 const WebPluginInfo& info, | 573 const WebPluginInfo& info, |
| 511 const blink::WebPluginParams& params) { | 574 const blink::WebPluginParams& params) { |
| 512 #if defined(ENABLE_PLUGINS) | 575 #if defined(ENABLE_PLUGINS) |
| 513 bool pepper_plugin_was_registered = false; | 576 bool pepper_plugin_was_registered = false; |
| 514 scoped_refptr<PluginModule> pepper_module(PluginModule::Create( | 577 scoped_refptr<PluginModule> pepper_module(PluginModule::Create( |
| 515 this, info, &pepper_plugin_was_registered)); | 578 this, info, &pepper_plugin_was_registered)); |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 } | 1558 } |
| 1496 | 1559 |
| 1497 void RenderFrameImpl::didLoseWebGLContext(blink::WebFrame* frame, | 1560 void RenderFrameImpl::didLoseWebGLContext(blink::WebFrame* frame, |
| 1498 int arb_robustness_status_code) { | 1561 int arb_robustness_status_code) { |
| 1499 render_view_->Send(new ViewHostMsg_DidLose3DContext( | 1562 render_view_->Send(new ViewHostMsg_DidLose3DContext( |
| 1500 GURL(frame->top()->document().securityOrigin().toString()), | 1563 GURL(frame->top()->document().securityOrigin().toString()), |
| 1501 THREE_D_API_TYPE_WEBGL, | 1564 THREE_D_API_TYPE_WEBGL, |
| 1502 arb_robustness_status_code)); | 1565 arb_robustness_status_code)); |
| 1503 } | 1566 } |
| 1504 | 1567 |
| 1568 void RenderFrameImpl::showContextMenu(const blink::WebContextMenuData& data) { |
| 1569 ContextMenuParams params = ContextMenuParamsBuilder::Build(data); |
| 1570 params.source_type = GetRenderWidget()->context_menu_source_type(); |
| 1571 if (params.source_type == ui::MENU_SOURCE_TOUCH_EDIT_MENU) { |
| 1572 params.x = GetRenderWidget()->touch_editing_context_menu_location().x(); |
| 1573 params.y = GetRenderWidget()->touch_editing_context_menu_location().y(); |
| 1574 } |
| 1575 GetRenderWidget()->OnShowHostContextMenu(¶ms); |
| 1576 |
| 1577 // Plugins, e.g. PDF, don't currently update the render view when their |
| 1578 // selected text changes, but the context menu params do contain the updated |
| 1579 // selection. If that's the case, update the render view's state just prior |
| 1580 // to showing the context menu. |
| 1581 // TODO(asvitkine): http://crbug.com/152432 |
| 1582 if (ShouldUpdateSelectionTextFromContextMenuParams( |
| 1583 render_view_->selection_text_, |
| 1584 render_view_->selection_text_offset_, |
| 1585 render_view_->selection_range_, |
| 1586 params)) { |
| 1587 render_view_->selection_text_ = params.selection_text; |
| 1588 // TODO(asvitkine): Text offset and range is not available in this case. |
| 1589 render_view_->selection_text_offset_ = 0; |
| 1590 render_view_->selection_range_ = |
| 1591 gfx::Range(0, render_view_->selection_text_.length()); |
| 1592 Send(new ViewHostMsg_SelectionChanged( |
| 1593 routing_id_, |
| 1594 render_view_->selection_text_, |
| 1595 render_view_->selection_text_offset_, |
| 1596 render_view_->selection_range_)); |
| 1597 } |
| 1598 |
| 1599 params.frame_id = frame_->identifier(); |
| 1600 |
| 1601 // Serializing a GURL longer than kMaxURLChars will fail, so don't do |
| 1602 // it. We replace it with an empty GURL so the appropriate items are disabled |
| 1603 // in the context menu. |
| 1604 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 1605 // data encoded images. We should have a way to save them. |
| 1606 if (params.src_url.spec().size() > GetMaxURLChars()) |
| 1607 params.src_url = GURL(); |
| 1608 render_view_->context_menu_node_ = data.node; |
| 1609 |
| 1610 #if defined(OS_ANDROID) |
| 1611 gfx::Rect start_rect; |
| 1612 gfx::Rect end_rect; |
| 1613 render_view_->GetSelectionBounds(&start_rect, &end_rect); |
| 1614 params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom()); |
| 1615 params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom()); |
| 1616 #endif |
| 1617 |
| 1618 Send(new FrameHostMsg_ContextMenu(routing_id_, params)); |
| 1619 } |
| 1620 |
| 1505 void RenderFrameImpl::AddObserver(RenderFrameObserver* observer) { | 1621 void RenderFrameImpl::AddObserver(RenderFrameObserver* observer) { |
| 1506 observers_.AddObserver(observer); | 1622 observers_.AddObserver(observer); |
| 1507 } | 1623 } |
| 1508 | 1624 |
| 1509 void RenderFrameImpl::RemoveObserver(RenderFrameObserver* observer) { | 1625 void RenderFrameImpl::RemoveObserver(RenderFrameObserver* observer) { |
| 1510 observer->RenderFrameGone(); | 1626 observer->RenderFrameGone(); |
| 1511 observers_.RemoveObserver(observer); | 1627 observers_.RemoveObserver(observer); |
| 1512 } | 1628 } |
| 1513 | 1629 |
| 1514 void RenderFrameImpl::OnStop() { | 1630 void RenderFrameImpl::OnStop() { |
| 1515 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnStop()); | 1631 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnStop()); |
| 1516 } | 1632 } |
| 1517 | 1633 |
| 1518 } // namespace content | 1634 } // namespace content |
| OLD | NEW |