Chromium Code Reviews| 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/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/json/json_reader.h" | |
| 16 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
| 17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 18 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
| 19 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 21 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
| 23 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
| 24 #include "base/string_split.h" | 25 #include "base/string_split.h" |
| 25 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 26 #include "base/sys_string_conversions.h" | 27 #include "base/sys_string_conversions.h" |
| 27 #include "base/time.h" | 28 #include "base/time.h" |
| 28 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
| 29 #include "content/common/appcache/appcache_dispatcher.h" | 30 #include "content/common/appcache/appcache_dispatcher.h" |
| 30 #include "content/common/child_thread.h" | 31 #include "content/common/child_thread.h" |
| 31 #include "content/common/clipboard_messages.h" | 32 #include "content/common/clipboard_messages.h" |
| 32 #include "content/common/database_messages.h" | 33 #include "content/common/database_messages.h" |
| 33 #include "content/common/drag_messages.h" | 34 #include "content/common/drag_messages.h" |
| 34 #include "content/common/fileapi/file_system_dispatcher.h" | 35 #include "content/common/fileapi/file_system_dispatcher.h" |
| 35 #include "content/common/fileapi/webfilesystem_callback_dispatcher.h" | 36 #include "content/common/fileapi/webfilesystem_callback_dispatcher.h" |
| 36 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 37 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 37 #include "content/common/intents_messages.h" | 38 #include "content/common/intents_messages.h" |
| 38 #include "content/common/java_bridge_messages.h" | 39 #include "content/common/java_bridge_messages.h" |
| 39 #include "content/common/old_browser_plugin_messages.h" | 40 #include "content/common/old_browser_plugin_messages.h" |
| 40 #include "content/common/pepper_messages.h" | 41 #include "content/common/pepper_messages.h" |
| 41 #include "content/common/pepper_plugin_registry.h" | 42 #include "content/common/pepper_plugin_registry.h" |
| 42 #include "content/common/quota_dispatcher.h" | 43 #include "content/common/quota_dispatcher.h" |
| 43 #include "content/common/request_extra_data.h" | 44 #include "content/common/request_extra_data.h" |
| 44 #include "content/common/socket_stream_handle_data.h" | 45 #include "content/common/socket_stream_handle_data.h" |
| 46 #include "content/common/renderer_constants.h" | |
| 45 #include "content/common/view_messages.h" | 47 #include "content/common/view_messages.h" |
| 46 #include "content/common/webmessageportchannel_impl.h" | 48 #include "content/common/webmessageportchannel_impl.h" |
| 47 #include "content/public/common/bindings_policy.h" | 49 #include "content/public/common/bindings_policy.h" |
| 48 #include "content/public/common/content_client.h" | 50 #include "content/public/common/content_client.h" |
| 49 #include "content/public/common/content_constants.h" | 51 #include "content/public/common/content_constants.h" |
| 50 #include "content/public/common/content_switches.h" | 52 #include "content/public/common/content_switches.h" |
| 51 #include "content/public/common/context_menu_params.h" | 53 #include "content/public/common/context_menu_params.h" |
| 52 #include "content/public/common/file_chooser_params.h" | 54 #include "content/public/common/file_chooser_params.h" |
| 53 #include "content/public/common/url_constants.h" | 55 #include "content/public/common/url_constants.h" |
| 54 #include "content/public/renderer/content_renderer_client.h" | 56 #include "content/public/renderer/content_renderer_client.h" |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 | 340 |
| 339 static const float kScalingIncrement = 0.1f; | 341 static const float kScalingIncrement = 0.1f; |
| 340 | 342 |
| 341 static const float kScalingIncrementForGesture = 0.01f; | 343 static const float kScalingIncrementForGesture = 0.01f; |
| 342 | 344 |
| 343 static RenderViewImpl* FromRoutingID(int32 routing_id) { | 345 static RenderViewImpl* FromRoutingID(int32 routing_id) { |
| 344 return static_cast<RenderViewImpl*>( | 346 return static_cast<RenderViewImpl*>( |
| 345 ChildThread::current()->ResolveRoute(routing_id)); | 347 ChildThread::current()->ResolveRoute(routing_id)); |
| 346 } | 348 } |
| 347 | 349 |
| 350 static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { | |
| 351 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) | |
|
Charlie Reis
2012/08/22 22:08:34
nit: This for loop needs braces.
nasko
2012/08/23 21:55:53
Done.
| |
| 352 if (frame->identifier() == frame_id) | |
| 353 return frame; | |
| 354 return NULL; | |
| 355 } | |
| 356 | |
| 348 static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { | 357 static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 349 WebVector<WebURL> urls; | 358 WebVector<WebURL> urls; |
| 350 ds->redirectChain(urls); | 359 ds->redirectChain(urls); |
| 351 result->reserve(urls.size()); | 360 result->reserve(urls.size()); |
| 352 for (size_t i = 0; i < urls.size(); ++i) | 361 for (size_t i = 0; i < urls.size(); ++i) |
| 353 result->push_back(urls[i]); | 362 result->push_back(urls[i]); |
| 354 } | 363 } |
| 355 | 364 |
| 356 // If |data_source| is non-null and has a DocumentState associated with it, | 365 // If |data_source| is non-null and has a DocumentState associated with it, |
| 357 // the AltErrorPageResourceFetcher is reset. | 366 // the AltErrorPageResourceFetcher is reset. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 if (!opener) { | 451 if (!opener) { |
| 443 return true; | 452 return true; |
| 444 } | 453 } |
| 445 | 454 |
| 446 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) | 455 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 447 return true; | 456 return true; |
| 448 } | 457 } |
| 449 return false; | 458 return false; |
| 450 } | 459 } |
| 451 | 460 |
| 461 // Recursively walks the frame tree and serializes it to JSON as described in | |
| 462 // the comment for ViewMsg_UpdateFrameTree. | |
| 463 static void ConstructFrameTree(WebKit::WebFrame* frame, | |
| 464 WebKit::WebFrame* exclude_subtree, | |
|
Charlie Reis
2012/08/22 22:08:34
nit: Wrong indent.
Also, what is this parameter f
nasko
2012/08/23 21:55:53
Done.
| |
| 465 base::DictionaryValue* dict) { | |
| 466 dict->SetString(content::kFrameTreeNodeNameKey, | |
| 467 UTF16ToUTF8(frame->assignedName()).c_str()); | |
| 468 dict->SetInteger(content::kFrameTreeNodeIdKey, frame->identifier()); | |
| 469 | |
| 470 WebFrame* child = frame->firstChild(); | |
| 471 ListValue* children = new ListValue(); | |
| 472 for (; child; child = child->nextSibling()) { | |
| 473 if (child == exclude_subtree) | |
| 474 continue; | |
| 475 | |
| 476 base::DictionaryValue* d = new base::DictionaryValue(); | |
| 477 ConstructFrameTree(child, exclude_subtree, d); | |
| 478 children->Append(d); | |
| 479 } | |
| 480 if (children->GetSize() > 0) { | |
|
Charlie Reis
2012/08/22 22:08:34
nit: No braces on one-line if.
nasko
2012/08/23 21:55:53
Done.
| |
| 481 dict->Set(content::kFrameTreeNodeSubtreeKey, children); | |
| 482 } | |
| 483 } | |
| 484 | |
| 452 /////////////////////////////////////////////////////////////////////////////// | 485 /////////////////////////////////////////////////////////////////////////////// |
| 453 | 486 |
| 454 struct RenderViewImpl::PendingFileChooser { | 487 struct RenderViewImpl::PendingFileChooser { |
| 455 PendingFileChooser(const content::FileChooserParams& p, | 488 PendingFileChooser(const content::FileChooserParams& p, |
| 456 WebFileChooserCompletion* c) | 489 WebFileChooserCompletion* c) |
| 457 : params(p), | 490 : params(p), |
| 458 completion(c) { | 491 completion(c) { |
| 459 } | 492 } |
| 460 content::FileChooserParams params; | 493 content::FileChooserParams params; |
| 461 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. | 494 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 java_bridge_dispatcher_(NULL), | 584 java_bridge_dispatcher_(NULL), |
| 552 mouse_lock_dispatcher_(NULL), | 585 mouse_lock_dispatcher_(NULL), |
| 553 session_storage_namespace_id_(session_storage_namespace_id), | 586 session_storage_namespace_id_(session_storage_namespace_id), |
| 554 handling_select_range_(false), | 587 handling_select_range_(false), |
| 555 #if defined(OS_WIN) | 588 #if defined(OS_WIN) |
| 556 focused_plugin_id_(-1), | 589 focused_plugin_id_(-1), |
| 557 #endif | 590 #endif |
| 558 guest_to_embedder_channel_(guest_to_embedder_channel), | 591 guest_to_embedder_channel_(guest_to_embedder_channel), |
| 559 guest_pp_instance_(0), | 592 guest_pp_instance_(0), |
| 560 guest_uninitialized_context_(NULL), | 593 guest_uninitialized_context_(NULL), |
| 594 updating_frame_tree_(false), | |
| 595 pending_frame_tree_update_(false), | |
| 596 target_process_id_(0), | |
| 597 target_routing_id_(0), | |
| 561 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { | 598 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
| 562 set_throttle_input_events(renderer_prefs.throttle_input_events); | 599 set_throttle_input_events(renderer_prefs.throttle_input_events); |
| 563 routing_id_ = routing_id; | 600 routing_id_ = routing_id; |
| 564 surface_id_ = surface_id; | 601 surface_id_ = surface_id; |
| 565 if (opener_id != MSG_ROUTING_NONE && is_renderer_created) | 602 if (opener_id != MSG_ROUTING_NONE && is_renderer_created) |
| 566 opener_id_ = opener_id; | 603 opener_id_ = opener_id; |
| 567 | 604 |
| 568 // Ensure we start with a valid next_page_id_ from the browser. | 605 // Ensure we start with a valid next_page_id_ from the browser. |
| 569 DCHECK_GE(next_page_id_, 0); | 606 DCHECK_GE(next_page_id_, 0); |
| 570 | 607 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 682 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 646 if (command_line.HasSwitch(switches::kDomAutomationController)) | 683 if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 647 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION; | 684 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION; |
| 648 | 685 |
| 649 ProcessViewLayoutFlags(command_line); | 686 ProcessViewLayoutFlags(command_line); |
| 650 | 687 |
| 651 content::GetContentClient()->renderer()->RenderViewCreated(this); | 688 content::GetContentClient()->renderer()->RenderViewCreated(this); |
| 652 | 689 |
| 653 // If we have an opener_id but we weren't created by a renderer, then | 690 // If we have an opener_id but we weren't created by a renderer, then |
| 654 // it's the browser asking us to set our opener to another RenderView. | 691 // it's the browser asking us to set our opener to another RenderView. |
| 655 // TODO(creis): This doesn't yet handle openers that are subframes. | |
| 656 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) { | 692 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) { |
| 657 RenderViewImpl* opener_view = FromRoutingID(opener_id); | 693 RenderViewImpl* opener_view = FromRoutingID(opener_id); |
| 658 if (opener_view) | 694 if (opener_view) |
| 659 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); | 695 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
| 660 } | 696 } |
| 661 | 697 |
| 662 // If we are initially swapped out, navigate to kSwappedOutURL. | 698 // If we are initially swapped out, navigate to kSwappedOutURL. |
| 663 // This ensures we are in a unique origin that others cannot script. | 699 // This ensures we are in a unique origin that others cannot script. |
| 664 if (is_swapped_out_) | 700 if (is_swapped_out_) |
| 665 NavigateToSwappedOutURL(); | 701 NavigateToSwappedOutURL(webview()->mainFrame(), NULL); |
| 666 } | 702 } |
| 667 | 703 |
| 668 RenderViewImpl::~RenderViewImpl() { | 704 RenderViewImpl::~RenderViewImpl() { |
| 669 history_page_ids_.clear(); | 705 history_page_ids_.clear(); |
| 670 | 706 |
| 671 if (decrement_shared_popup_at_destruction_) | 707 if (decrement_shared_popup_at_destruction_) |
| 672 shared_popup_counter_->data--; | 708 shared_popup_counter_->data--; |
| 673 | 709 |
| 674 // If file chooser is still waiting for answer, dispatch empty answer. | 710 // If file chooser is still waiting for answer, dispatch empty answer. |
| 675 while (!file_chooser_completions_.empty()) { | 711 while (!file_chooser_completions_.empty()) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) | 994 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
| 959 // TODO(viettrungluu): Move to a separate message filter. | 995 // TODO(viettrungluu): Move to a separate message filter. |
| 960 #if defined(OS_MACOSX) | 996 #if defined(OS_MACOSX) |
| 961 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) | 997 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 962 #endif | 998 #endif |
| 963 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, | 999 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 964 OnSetHistoryLengthAndPrune) | 1000 OnSetHistoryLengthAndPrune) |
| 965 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 1001 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 966 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) | 1002 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
| 967 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) | 1003 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
| 1004 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree) | |
| 968 | 1005 |
| 969 // Have the super handle all other messages. | 1006 // Have the super handle all other messages. |
| 970 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 1007 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| 971 IPC_END_MESSAGE_MAP() | 1008 IPC_END_MESSAGE_MAP() |
| 972 | 1009 |
| 973 if (!msg_is_ok) { | 1010 if (!msg_is_ok) { |
| 974 // The message had a handler, but its deserialization failed. | 1011 // The message had a handler, but its deserialization failed. |
| 975 // Kill the renderer to avoid potential spoofing attacks. | 1012 // Kill the renderer to avoid potential spoofing attacks. |
| 976 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; | 1013 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
| 977 } | 1014 } |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1861 // NOTE: For now we're doing the safest thing, and sending out notification | 1898 // NOTE: For now we're doing the safest thing, and sending out notification |
| 1862 // when done loading. This currently isn't an issue as the favicon is only | 1899 // when done loading. This currently isn't an issue as the favicon is only |
| 1863 // displayed when done loading. Ideally we would send notification when | 1900 // displayed when done loading. Ideally we would send notification when |
| 1864 // finished parsing the head, but webkit doesn't support that yet. | 1901 // finished parsing the head, but webkit doesn't support that yet. |
| 1865 // The feed discovery code would also benefit from access to the head. | 1902 // The feed discovery code would also benefit from access to the head. |
| 1866 Send(new ViewHostMsg_DidStopLoading(routing_id_)); | 1903 Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1867 | 1904 |
| 1868 if (load_progress_tracker_ != NULL) | 1905 if (load_progress_tracker_ != NULL) |
| 1869 load_progress_tracker_->DidStopLoading(); | 1906 load_progress_tracker_->DidStopLoading(); |
| 1870 | 1907 |
| 1908 if (pending_frame_tree_update_) { | |
| 1909 pending_frame_tree_update_ = false; | |
| 1910 SendUpdatedFrameTree(webview()->mainFrame(), false); | |
| 1911 } | |
| 1912 | |
| 1871 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); | 1913 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
| 1872 } | 1914 } |
| 1873 | 1915 |
| 1874 void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, | 1916 void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 1875 double load_progress) { | 1917 double load_progress) { |
| 1876 if (load_progress_tracker_ != NULL) | 1918 if (load_progress_tracker_ != NULL) |
| 1877 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); | 1919 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 1878 } | 1920 } |
| 1879 | 1921 |
| 1880 bool RenderViewImpl::isSmartInsertDeleteEnabled() { | 1922 bool RenderViewImpl::isSmartInsertDeleteEnabled() { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2445 return NULL; | 2487 return NULL; |
| 2446 return new RendererWebApplicationCacheHostImpl( | 2488 return new RendererWebApplicationCacheHostImpl( |
| 2447 FromWebView(frame->view()), client, | 2489 FromWebView(frame->view()), client, |
| 2448 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); | 2490 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); |
| 2449 } | 2491 } |
| 2450 | 2492 |
| 2451 WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { | 2493 WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
| 2452 return &cookie_jar_; | 2494 return &cookie_jar_; |
| 2453 } | 2495 } |
| 2454 | 2496 |
| 2497 void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) { | |
| 2498 if (is_loading_) { | |
| 2499 pending_frame_tree_update_ = true; | |
| 2500 return; | |
| 2501 } | |
| 2502 if (!updating_frame_tree_) { | |
|
Charlie Reis
2012/08/22 22:08:34
nit: No braces.
nasko
2012/08/23 21:55:53
Done.
| |
| 2503 SendUpdatedFrameTree(child, false); | |
| 2504 } | |
| 2505 } | |
| 2506 | |
| 2455 void RenderViewImpl::frameDetached(WebFrame* frame) { | 2507 void RenderViewImpl::frameDetached(WebFrame* frame) { |
| 2508 if (is_loading_) { | |
| 2509 pending_frame_tree_update_ = true; | |
| 2510 return; | |
| 2511 } | |
| 2512 if (!updating_frame_tree_) { | |
| 2513 SendUpdatedFrameTree(frame, true); | |
| 2514 } | |
| 2456 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); | 2515 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
| 2457 } | 2516 } |
| 2458 | 2517 |
| 2459 void RenderViewImpl::willClose(WebFrame* frame) { | 2518 void RenderViewImpl::willClose(WebFrame* frame) { |
| 2460 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); | 2519 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
| 2461 } | 2520 } |
| 2462 | 2521 |
| 2463 void RenderViewImpl::loadURLExternally( | 2522 void RenderViewImpl::loadURLExternally( |
| 2464 WebFrame* frame, const WebURLRequest& request, | 2523 WebFrame* frame, const WebURLRequest& request, |
| 2465 WebNavigationPolicy policy) { | 2524 WebNavigationPolicy policy) { |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3598 | 3657 |
| 3599 if (!context->Initialize( | 3658 if (!context->Initialize( |
| 3600 attributes, | 3659 attributes, |
| 3601 false /* bind generates resources */, | 3660 false /* bind generates resources */, |
| 3602 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_ INITIALIZE)) | 3661 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_ INITIALIZE)) |
| 3603 return NULL; | 3662 return NULL; |
| 3604 return context.release(); | 3663 return context.release(); |
| 3605 } | 3664 } |
| 3606 } | 3665 } |
| 3607 | 3666 |
| 3667 // The browser process needs to know the shape of the tree, as well as the names | |
| 3668 // and ids of all frames. This allows it to properly route JavaScript messages | |
| 3669 // across processes and frames. The serialization format is described in the | |
| 3670 // comments of the ViewMsg_FrameTreeUpdated message. | |
| 3671 // This function sends a those updates to the browser and updates the RVH | |
|
Charlie Reis
2012/08/22 22:08:34
nit: sends those
nasko
2012/08/23 21:55:53
Done.
| |
| 3672 // corresponding to this object. It must be called on any events that modify | |
| 3673 // the tree structure or the names of any frames. | |
| 3674 void RenderViewImpl::SendUpdatedFrameTree( | |
| 3675 WebKit::WebFrame* frame, bool exclude_subtree) { | |
| 3676 std::string json; | |
| 3677 WebFrame* f = frame->top(); | |
| 3678 base::DictionaryValue tree; | |
| 3679 | |
| 3680 ConstructFrameTree(f, exclude_subtree ? frame : NULL, &tree); | |
| 3681 base::JSONWriter::Write(&tree, &json); | |
| 3682 | |
| 3683 Send(new ViewHostMsg_FrameTreeUpdated(routing_id_, json)); | |
| 3684 } | |
| 3685 | |
| 3608 void RenderViewImpl::EnsureMediaStreamImpl() { | 3686 void RenderViewImpl::EnsureMediaStreamImpl() { |
| 3609 if (!RenderThreadImpl::current()) // Will be NULL during unit tests. | 3687 if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 3610 return; | 3688 return; |
| 3611 | 3689 |
| 3612 #if defined(ENABLE_WEBRTC) | 3690 #if defined(ENABLE_WEBRTC) |
| 3613 if (!p2p_socket_dispatcher_) | 3691 if (!p2p_socket_dispatcher_) |
| 3614 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); | 3692 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); |
| 3615 | 3693 |
| 3616 if (!media_stream_dispatcher_) | 3694 if (!media_stream_dispatcher_) |
| 3617 media_stream_dispatcher_ = new MediaStreamDispatcher(this); | 3695 media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3813 } | 3891 } |
| 3814 delete channels; | 3892 delete channels; |
| 3815 } | 3893 } |
| 3816 | 3894 |
| 3817 int id = intents_host_->RegisterWebIntent(intentRequest); | 3895 int id = intents_host_->RegisterWebIntent(intentRequest); |
| 3818 Send(new IntentsHostMsg_WebIntentDispatch( | 3896 Send(new IntentsHostMsg_WebIntentDispatch( |
| 3819 routing_id_, intent_data, id)); | 3897 routing_id_, intent_data, id)); |
| 3820 } | 3898 } |
| 3821 | 3899 |
| 3822 bool RenderViewImpl::willCheckAndDispatchMessageEvent( | 3900 bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
| 3823 WebKit::WebFrame* source, | 3901 WebKit::WebFrame* sourceFrame, |
| 3902 WebKit::WebFrame* targetFrame, | |
| 3824 WebKit::WebSecurityOrigin target_origin, | 3903 WebKit::WebSecurityOrigin target_origin, |
| 3825 WebKit::WebDOMMessageEvent event) { | 3904 WebKit::WebDOMMessageEvent event) { |
| 3826 if (!is_swapped_out_) | 3905 if (!is_swapped_out_) |
| 3827 return false; | 3906 return false; |
| 3828 | 3907 |
| 3829 ViewMsg_PostMessage_Params params; | 3908 ViewMsg_PostMessage_Params params; |
| 3830 params.data = event.data().toString(); | 3909 params.data = event.data().toString(); |
| 3831 params.source_origin = event.origin(); | 3910 params.source_origin = event.origin(); |
| 3832 if (!target_origin.isNull()) | 3911 if (!target_origin.isNull()) |
| 3833 params.target_origin = target_origin.toString(); | 3912 params.target_origin = target_origin.toString(); |
| 3834 | 3913 |
| 3835 // Include the routing ID for the source frame, which the browser process | 3914 // Include the routing ID for the source frame, which the browser process |
| 3836 // will translate into the routing ID for the equivalent frame in the target | 3915 // will translate into the routing ID for the equivalent frame in the target |
| 3837 // process. | 3916 // process. |
| 3838 // TODO(creis): Support source subframes. | |
| 3839 params.source_routing_id = MSG_ROUTING_NONE; | 3917 params.source_routing_id = MSG_ROUTING_NONE; |
| 3840 RenderViewImpl* source_view = FromWebView(source->view()); | 3918 RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
| 3841 if (source_view) | 3919 if (source_view) |
| 3842 params.source_routing_id = source_view->routing_id(); | 3920 params.source_routing_id = source_view->routing_id(); |
| 3921 params.source_frame_id = sourceFrame->identifier(); | |
| 3922 | |
| 3923 // Include the process, route, and frame IDs of the target frame. This allows | |
| 3924 // the browser to detect races between this message being sent and the target | |
| 3925 // frame no longer being valid. | |
| 3926 params.target_process_id = target_process_id_; | |
| 3927 params.target_routing_id = target_routing_id_; | |
| 3928 | |
| 3929 std::map<int,int>::iterator it = frames_map_.find(targetFrame->identifier()); | |
| 3930 if (it != frames_map_.end()) { | |
|
Charlie Reis
2012/08/22 22:08:34
nit: no braces
nasko
2012/08/23 21:55:53
Done.
| |
| 3931 params.target_frame_id = it->second; | |
| 3932 } else { | |
| 3933 params.target_frame_id = 0; | |
| 3934 } | |
| 3843 | 3935 |
| 3844 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); | 3936 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 3845 return true; | 3937 return true; |
| 3846 } | 3938 } |
| 3847 | 3939 |
| 3848 void RenderViewImpl::willOpenSocketStream( | 3940 void RenderViewImpl::willOpenSocketStream( |
| 3849 WebSocketStreamHandle* handle) { | 3941 WebSocketStreamHandle* handle) { |
| 3850 SocketStreamHandleData::AddToHandle(handle, routing_id_); | 3942 SocketStreamHandleData::AddToHandle(handle, routing_id_); |
| 3851 } | 3943 } |
| 3852 | 3944 |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4562 | 4654 |
| 4563 void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, | 4655 void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 4564 const string16& jscript, | 4656 const string16& jscript, |
| 4565 int id, | 4657 int id, |
| 4566 bool notify_result) { | 4658 bool notify_result) { |
| 4567 EvaluateScript(frame_xpath, jscript, id, notify_result); | 4659 EvaluateScript(frame_xpath, jscript, id, notify_result); |
| 4568 } | 4660 } |
| 4569 | 4661 |
| 4570 void RenderViewImpl::OnPostMessageEvent( | 4662 void RenderViewImpl::OnPostMessageEvent( |
| 4571 const ViewMsg_PostMessage_Params& params) { | 4663 const ViewMsg_PostMessage_Params& params) { |
| 4572 // TODO(creis): Support sending to subframes. | 4664 // Find the frame, which is a target of this message. The source tags the |
|
Charlie Reis
2012/08/22 22:08:34
nit: Find the target frame of this message.
nasko
2012/08/23 21:55:53
Done.
| |
| 4573 WebFrame* frame = webview()->mainFrame(); | 4665 // message with |remote_frame_id|, so use it to locate the frame. |
| 4666 WebFrame* frame = FindFrameByID(webview()->mainFrame(), | |
| 4667 params.target_frame_id); | |
| 4668 if (!frame) | |
| 4669 return; | |
| 4574 | 4670 |
| 4575 // Find the source frame if it exists. | 4671 // Find the source frame if it exists. |
| 4576 // TODO(creis): Support source subframes. | |
| 4577 WebFrame* source_frame = NULL; | 4672 WebFrame* source_frame = NULL; |
| 4578 if (params.source_routing_id != MSG_ROUTING_NONE) { | 4673 if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 4579 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); | 4674 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 4580 if (source_view) | 4675 if (source_view) |
| 4581 source_frame = source_view->webview()->mainFrame(); | 4676 source_frame = source_view->GetFrameByRemoteID(params.source_frame_id); |
| 4582 } | 4677 } |
| 4583 | 4678 |
| 4584 // Create an event with the message. The final parameter to initMessageEvent | 4679 // Create an event with the message. The final parameter to initMessageEvent |
| 4585 // is the last event ID, which is not used with postMessage. | 4680 // is the last event ID, which is not used with postMessage. |
| 4586 WebDOMEvent event = frame->document().createEvent("MessageEvent"); | 4681 WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 4587 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); | 4682 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 4588 msg_event.initMessageEvent("message", | 4683 msg_event.initMessageEvent("message", |
| 4589 // |canBubble| and |cancellable| are always false | 4684 // |canBubble| and |cancellable| are always false |
| 4590 false, false, | 4685 false, false, |
| 4591 WebSerializedScriptValue::fromString(params.data), | 4686 WebSerializedScriptValue::fromString(params.data), |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4920 // Synchronously run the unload handler before sending the ACK. | 5015 // Synchronously run the unload handler before sending the ACK. |
| 4921 webview()->dispatchUnloadEvent(); | 5016 webview()->dispatchUnloadEvent(); |
| 4922 | 5017 |
| 4923 // Swap out and stop sending any IPC messages that are not ACKs. | 5018 // Swap out and stop sending any IPC messages that are not ACKs. |
| 4924 SetSwappedOut(true); | 5019 SetSwappedOut(true); |
| 4925 | 5020 |
| 4926 // Replace the page with a blank dummy URL. The unload handler will not be | 5021 // Replace the page with a blank dummy URL. The unload handler will not be |
| 4927 // run a second time, thanks to a check in FrameLoader::stopLoading. | 5022 // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 4928 // TODO(creis): Need to add a better way to do this that avoids running the | 5023 // TODO(creis): Need to add a better way to do this that avoids running the |
| 4929 // beforeunload handler. For now, we just run it a second time silently. | 5024 // beforeunload handler. For now, we just run it a second time silently. |
| 4930 NavigateToSwappedOutURL(); | 5025 NavigateToSwappedOutURL(webview()->mainFrame(), NULL); |
| 4931 | 5026 |
| 4932 // Let WebKit know that this view is hidden so it can drop resources and | 5027 // Let WebKit know that this view is hidden so it can drop resources and |
| 4933 // stop compositing. | 5028 // stop compositing. |
| 4934 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); | 5029 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
| 4935 } | 5030 } |
| 4936 | 5031 |
| 4937 // Just echo back the params in the ACK. | 5032 // Just echo back the params in the ACK. |
| 4938 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); | 5033 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 4939 } | 5034 } |
| 4940 | 5035 |
| 4941 void RenderViewImpl::NavigateToSwappedOutURL() { | 5036 void RenderViewImpl::NavigateToSwappedOutURL( |
| 5037 WebKit::WebFrame* frame, | |
| 5038 base::DictionaryValue* frame_tree) { | |
| 4942 // We use loadRequest instead of loadHTMLString because the former commits | 5039 // We use loadRequest instead of loadHTMLString because the former commits |
| 4943 // synchronously. Otherwise a new navigation can interrupt the navigation | 5040 // synchronously. Otherwise a new navigation can interrupt the navigation |
| 4944 // to content::kSwappedOutURL. If that happens to be to the page we had been | 5041 // to content::kSwappedOutURL. If that happens to be to the page we had been |
| 4945 // showing, then WebKit will never send a commit and we'll be left spinning. | 5042 // showing, then WebKit will never send a commit and we'll be left spinning. |
| 4946 GURL swappedOutURL(content::kSwappedOutURL); | 5043 GURL swappedOutURL(content::kSwappedOutURL); |
| 4947 WebURLRequest request(swappedOutURL); | 5044 WebURLRequest request(swappedOutURL); |
| 4948 webview()->mainFrame()->loadRequest(request); | 5045 frame->loadRequest(request); |
| 5046 | |
| 5047 // If a frame tree is specified, recursively recreate it using the data | |
|
Charlie Reis
2012/08/22 22:08:34
I feel weird about putting this logic in this func
nasko
2012/08/23 21:55:53
Separated it into a separate function. Fits much b
| |
| 5048 // in the current DictionaryValue. | |
| 5049 if (frame_tree == NULL) | |
| 5050 return; | |
| 5051 | |
| 5052 string16 name; | |
| 5053 if (frame_tree->GetString(content::kFrameTreeNodeNameKey, &name) && | |
| 5054 name != string16()) | |
|
Charlie Reis
2012/08/22 22:08:34
nit: Needs braces.
nasko
2012/08/23 21:55:53
Done.
| |
| 5055 frame->setName(name); | |
| 5056 | |
| 5057 int remote_id; | |
| 5058 if (frame_tree->GetInteger(content::kFrameTreeNodeIdKey, &remote_id)) | |
| 5059 frames_map_.insert(std::pair<int, int>(frame->identifier(), remote_id)); | |
| 5060 | |
| 5061 ListValue* children; | |
| 5062 if (!frame_tree->GetList(content::kFrameTreeNodeSubtreeKey, &children)) | |
| 5063 return; | |
| 5064 | |
| 5065 base::DictionaryValue* child; | |
| 5066 for (size_t i = 0; i < children->GetSize(); ++i) { | |
| 5067 if (!children->GetDictionary(i, &child)) | |
| 5068 continue; | |
| 5069 WebElement element = frame->document().createElement("iframe"); | |
| 5070 if (frame->document().body().appendChild(element)) { | |
| 5071 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element); | |
| 5072 if (subframe) { | |
|
Charlie Reis
2012/08/22 22:08:34
nit: No braces.
nasko
2012/08/23 21:55:53
Done.
| |
| 5073 NavigateToSwappedOutURL(subframe, child); | |
| 5074 } | |
| 5075 } | |
| 5076 } | |
| 4949 } | 5077 } |
| 4950 | 5078 |
| 4951 void RenderViewImpl::OnClosePage() { | 5079 void RenderViewImpl::OnClosePage() { |
| 4952 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); | 5080 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
| 4953 // TODO(creis): We'd rather use webview()->Close() here, but that currently | 5081 // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4954 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs | 5082 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4955 // in the onunload handler from appearing. For now, we're bypassing that and | 5083 // in the onunload handler from appearing. For now, we're bypassing that and |
| 4956 // calling the FrameLoader's CloseURL method directly. This should be | 5084 // calling the FrameLoader's CloseURL method directly. This should be |
| 4957 // revisited to avoid having two ways to close a page. Having a single way | 5085 // revisited to avoid having two ways to close a page. Having a single way |
| 4958 // to close that can run onunload is also useful for fixing | 5086 // to close that can run onunload is also useful for fixing |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5798 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 5926 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
| 5799 return !!RenderThreadImpl::current()->compositor_thread(); | 5927 return !!RenderThreadImpl::current()->compositor_thread(); |
| 5800 } | 5928 } |
| 5801 | 5929 |
| 5802 void RenderViewImpl::OnJavaBridgeInit() { | 5930 void RenderViewImpl::OnJavaBridgeInit() { |
| 5803 DCHECK(!java_bridge_dispatcher_); | 5931 DCHECK(!java_bridge_dispatcher_); |
| 5804 #if defined(ENABLE_JAVA_BRIDGE) | 5932 #if defined(ENABLE_JAVA_BRIDGE) |
| 5805 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); | 5933 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
| 5806 #endif | 5934 #endif |
| 5807 } | 5935 } |
| 5936 | |
| 5937 void RenderViewImpl::OnUpdatedFrameTree( | |
| 5938 int process_id, | |
| 5939 int route_id, | |
| 5940 const std::string& frame_tree) { | |
| 5941 base::DictionaryValue* frames = NULL; | |
| 5942 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree)); | |
| 5943 if (tree.get() != NULL && tree->IsType(base::Value::TYPE_DICTIONARY)) | |
|
Charlie Reis
2012/08/22 22:08:34
nit: You don't need "!= NULL"
nasko
2012/08/23 21:55:53
Done.
| |
| 5944 tree->GetAsDictionary(&frames); | |
| 5945 | |
| 5946 updating_frame_tree_ = true; | |
| 5947 frames_map_.clear(); | |
| 5948 | |
| 5949 target_process_id_ = process_id; | |
| 5950 target_routing_id_ = route_id; | |
| 5951 NavigateToSwappedOutURL(webview()->mainFrame(), frames); | |
| 5952 | |
| 5953 updating_frame_tree_ = false; | |
| 5954 } | |
| 5955 | |
| 5956 WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) { | |
| 5957 WebKit::WebFrame* frame = NULL; | |
| 5958 | |
| 5959 std::map<int, int>::iterator it = frames_map_.find(remote_frame_id); | |
| 5960 if (it == frames_map_.end()) | |
| 5961 return NULL; | |
| 5962 | |
| 5963 for (WebFrame* f = webview()->mainFrame(); f; f = f->traverseNext(false)) | |
|
Charlie Reis
2012/08/22 22:08:34
This part is just FindFrameByID, right? No sense
nasko
2012/08/23 21:55:53
Yes, indeed.
| |
| 5964 if (f->identifier() == it->second) | |
| 5965 frame = f; | |
| 5966 | |
| 5967 return frame; | |
| 5968 } | |
| OLD | NEW |