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> |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 device_orientation_dispatcher_(NULL), | 605 device_orientation_dispatcher_(NULL), |
| 606 media_stream_dispatcher_(NULL), | 606 media_stream_dispatcher_(NULL), |
| 607 media_stream_impl_(NULL), | 607 media_stream_impl_(NULL), |
| 608 devtools_agent_(NULL), | 608 devtools_agent_(NULL), |
| 609 accessibility_mode_(AccessibilityModeOff), | 609 accessibility_mode_(AccessibilityModeOff), |
| 610 renderer_accessibility_(NULL), | 610 renderer_accessibility_(NULL), |
| 611 java_bridge_dispatcher_(NULL), | 611 java_bridge_dispatcher_(NULL), |
| 612 mouse_lock_dispatcher_(NULL), | 612 mouse_lock_dispatcher_(NULL), |
| 613 #if defined(OS_ANDROID) | 613 #if defined(OS_ANDROID) |
| 614 expected_content_intent_id_(0), | 614 expected_content_intent_id_(0), |
| 615 synchronous_find_active_match_ordinal_(-1), | |
| 615 #endif | 616 #endif |
| 616 session_storage_namespace_id_(session_storage_namespace_id), | 617 session_storage_namespace_id_(session_storage_namespace_id), |
| 617 handling_select_range_(false), | 618 handling_select_range_(false), |
| 618 #if defined(OS_WIN) | 619 #if defined(OS_WIN) |
| 619 focused_plugin_id_(-1), | 620 focused_plugin_id_(-1), |
| 620 #endif | 621 #endif |
| 621 guest_to_embedder_channel_(guest_to_embedder_channel), | 622 guest_to_embedder_channel_(guest_to_embedder_channel), |
| 622 guest_pp_instance_(0), | 623 guest_pp_instance_(0), |
| 623 guest_uninitialized_context_(NULL), | 624 guest_uninitialized_context_(NULL), |
| 624 updating_frame_tree_(false), | 625 updating_frame_tree_(false), |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 // TODO(viettrungluu): Move to a separate message filter. | 1048 // TODO(viettrungluu): Move to a separate message filter. |
| 1048 #if defined(OS_MACOSX) | 1049 #if defined(OS_MACOSX) |
| 1049 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) | 1050 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1050 #endif | 1051 #endif |
| 1051 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, | 1052 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1052 OnSetHistoryLengthAndPrune) | 1053 OnSetHistoryLengthAndPrune) |
| 1053 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 1054 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 1054 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) | 1055 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
| 1055 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) | 1056 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
| 1056 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree) | 1057 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree) |
| 1058 #if defined(OS_ANDROID) | |
| 1059 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind) | |
|
jam
2012/09/19 16:55:43
nit: put all the android if-def'd handlers togethe
Leandro Graciá Gil
2012/09/19 18:08:59
Done.
| |
| 1060 #endif | |
| 1057 | 1061 |
| 1058 // Have the super handle all other messages. | 1062 // Have the super handle all other messages. |
| 1059 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 1063 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| 1060 IPC_END_MESSAGE_MAP() | 1064 IPC_END_MESSAGE_MAP() |
| 1061 | 1065 |
| 1062 if (!msg_is_ok) { | 1066 if (!msg_is_ok) { |
| 1063 // The message had a handler, but its deserialization failed. | 1067 // The message had a handler, but its deserialization failed. |
| 1064 // Kill the renderer to avoid potential spoofing attacks. | 1068 // Kill the renderer to avoid potential spoofing attacks. |
| 1065 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; | 1069 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
| 1066 } | 1070 } |
| (...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3886 RenderViewObserver, observers_, DidChangeScrollOffset(frame)); | 3890 RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
| 3887 } | 3891 } |
| 3888 | 3892 |
| 3889 void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { | 3893 void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 3890 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); | 3894 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 3891 } | 3895 } |
| 3892 | 3896 |
| 3893 void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) { | 3897 void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) { |
| 3894 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); | 3898 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| 3895 } | 3899 } |
| 3896 | 3900 |
|
jam
2012/09/19 16:55:43
the moving of functions around made this file hard
Leandro Graciá Gil
2012/09/19 18:08:59
Done.
| |
| 3897 void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count, | 3901 void RenderViewImpl::SendFindReply(int request_id, |
| 3902 int match_count, | |
| 3903 int ordinal, | |
| 3904 const WebRect& selection_rect, | |
| 3905 bool final_status_update) { | |
| 3906 #if defined(OS_ANDROID) | |
| 3907 // Check if this is a synchronous find request. | |
| 3908 if (synchronous_find_pending_message_.get()) { | |
| 3909 if (final_status_update) { | |
| 3910 ViewMsg_SynchronousFind::WriteReplyParams( | |
| 3911 synchronous_find_pending_message_.get(), | |
| 3912 match_count, | |
| 3913 match_count ? synchronous_find_active_match_ordinal_ : 0); | |
| 3914 Send(synchronous_find_pending_message_.release()); | |
| 3915 } | |
| 3916 return; | |
| 3917 } | |
| 3918 #endif | |
| 3919 | |
| 3920 // Send the search result over to the browser process. | |
| 3921 Send(new ViewHostMsg_Find_Reply(routing_id_, | |
| 3922 request_id, | |
| 3923 match_count, | |
| 3924 selection_rect, | |
| 3925 ordinal, | |
| 3926 final_status_update)); | |
| 3927 } | |
| 3928 | |
| 3929 void RenderViewImpl::reportFindInPageMatchCount(int request_id, | |
| 3930 int count, | |
| 3898 bool final_update) { | 3931 bool final_update) { |
| 3899 int active_match_ordinal = -1; // -1 = don't update active match ordinal | 3932 int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3900 if (!count) | 3933 if (!count) |
| 3901 active_match_ordinal = 0; | 3934 active_match_ordinal = 0; |
| 3902 | 3935 |
| 3903 Send(new ViewHostMsg_Find_Reply(routing_id_, | 3936 // Send the search result over to the browser process. |
| 3904 request_id, | 3937 SendFindReply(request_id, |
| 3905 count, | 3938 count, |
| 3906 gfx::Rect(), | 3939 active_match_ordinal, |
| 3907 active_match_ordinal, | 3940 gfx::Rect(), |
| 3908 final_update)); | 3941 final_update); |
| 3909 } | 3942 } |
| 3910 | 3943 |
| 3911 void RenderViewImpl::reportFindInPageSelection(int request_id, | 3944 void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 3912 int active_match_ordinal, | 3945 int active_match_ordinal, |
| 3913 const WebRect& selection_rect) { | 3946 const WebRect& selection_rect) { |
| 3914 // Send the search result over to the browser process. | 3947 #if defined(OS_ANDROID) |
| 3915 Send(new ViewHostMsg_Find_Reply(routing_id_, | 3948 // If this was a SynchronousFind request, we need to remember the ordinal |
| 3916 request_id, | 3949 // value here for replying when reportFindInPageMatchCount is called. |
| 3917 -1, | 3950 if (synchronous_find_pending_message_.get()) { |
| 3918 selection_rect, | 3951 synchronous_find_active_match_ordinal_ = active_match_ordinal; |
| 3919 active_match_ordinal, | 3952 return; |
| 3920 false)); | 3953 } |
| 3954 #endif | |
| 3955 | |
| 3956 SendFindReply(request_id, | |
| 3957 -1, /* number_of_matches */ | |
| 3958 active_match_ordinal, | |
| 3959 selection_rect, | |
| 3960 false /* final_update */); | |
| 3921 } | 3961 } |
| 3922 | 3962 |
| 3923 void RenderViewImpl::openFileSystem( | 3963 void RenderViewImpl::openFileSystem( |
| 3924 WebFrame* frame, | 3964 WebFrame* frame, |
| 3925 WebFileSystem::Type type, | 3965 WebFileSystem::Type type, |
| 3926 long long size, | 3966 long long size, |
| 3927 bool create, | 3967 bool create, |
| 3928 WebFileSystemCallbacks* callbacks) { | 3968 WebFileSystemCallbacks* callbacks) { |
| 3929 DCHECK(callbacks); | 3969 DCHECK(callbacks); |
| 3930 | 3970 |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4369 reinterpret_cast<int64>(player), | 4409 reinterpret_cast<int64>(player), |
| 4370 player->hasVideo(), | 4410 player->hasVideo(), |
| 4371 player->hasAudio(), | 4411 player->hasAudio(), |
| 4372 false)); | 4412 false)); |
| 4373 } | 4413 } |
| 4374 | 4414 |
| 4375 void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { | 4415 void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { |
| 4376 DidPause(player); | 4416 DidPause(player); |
| 4377 } | 4417 } |
| 4378 | 4418 |
| 4419 void RenderViewImpl::StopFinding(content::StopFindAction action) { | |
| 4420 WebView* view = webview(); | |
| 4421 if (!view) | |
| 4422 return; | |
| 4423 | |
| 4424 WebDocument doc = view->mainFrame()->document(); | |
| 4425 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { | |
| 4426 GetWebPluginFromPluginDocument()->stopFind(); | |
| 4427 return; | |
| 4428 } | |
| 4429 | |
| 4430 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION; | |
| 4431 if (clear_selection) | |
| 4432 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); | |
| 4433 | |
| 4434 WebFrame* frame = view->mainFrame(); | |
| 4435 while (frame) { | |
| 4436 frame->stopFinding(clear_selection); | |
| 4437 frame = frame->traverseNext(false); | |
| 4438 } | |
| 4439 | |
| 4440 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) { | |
| 4441 WebFrame* focused_frame = view->focusedFrame(); | |
| 4442 if (focused_frame) { | |
| 4443 WebDocument doc = focused_frame->document(); | |
| 4444 if (!doc.isNull()) { | |
| 4445 WebNode node = doc.focusedNode(); | |
| 4446 if (!node.isNull()) | |
| 4447 node.simulateClick(); | |
| 4448 } | |
| 4449 } | |
| 4450 } | |
| 4451 } | |
| 4452 | |
| 4379 void RenderViewImpl::SyncNavigationState() { | 4453 void RenderViewImpl::SyncNavigationState() { |
| 4380 if (!webview()) | 4454 if (!webview()) |
| 4381 return; | 4455 return; |
| 4382 | 4456 |
| 4383 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); | 4457 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
| 4384 SendUpdateState(item); | 4458 SendUpdateState(item); |
| 4385 } | 4459 } |
| 4386 | 4460 |
| 4387 void RenderViewImpl::SyncSelectionIfRequired() { | 4461 void RenderViewImpl::SyncSelectionIfRequired() { |
| 4388 WebFrame* frame = webview()->focusedFrame(); | 4462 WebFrame* frame = webview()->focusedFrame(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4433 if (selection_text_offset_ != offset || | 4507 if (selection_text_offset_ != offset || |
| 4434 selection_range_ != range || | 4508 selection_range_ != range || |
| 4435 selection_text_ != text) { | 4509 selection_text_ != text) { |
| 4436 selection_text_ = text; | 4510 selection_text_ = text; |
| 4437 selection_text_offset_ = offset; | 4511 selection_text_offset_ = offset; |
| 4438 selection_range_ = range; | 4512 selection_range_ = range; |
| 4439 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); | 4513 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4440 } | 4514 } |
| 4441 } | 4515 } |
| 4442 | 4516 |
| 4443 GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, | 4517 void RenderViewImpl::Find(int request_id, const string16& search_text, |
| 4444 ErrorPageType error_type) { | 4518 const WebFindOptions& options) { |
| 4445 if (failed_url.SchemeIsSecure()) { | |
| 4446 // If the URL that failed was secure, then the embedding web page was not | |
| 4447 // expecting a network attacker to be able to manipulate its contents. As | |
| 4448 // we fetch alternate error pages over HTTP, we would be allowing a network | |
| 4449 // attacker to manipulate the contents of the response if we tried to use | |
| 4450 // the link doctor here. | |
| 4451 return GURL(); | |
| 4452 } | |
| 4453 | |
| 4454 // Grab the base URL from the browser process. | |
| 4455 if (!alternate_error_page_url_.is_valid()) | |
| 4456 return GURL(); | |
| 4457 | |
| 4458 // Strip query params from the failed URL. | |
| 4459 GURL::Replacements remove_params; | |
| 4460 remove_params.ClearUsername(); | |
| 4461 remove_params.ClearPassword(); | |
| 4462 remove_params.ClearQuery(); | |
| 4463 remove_params.ClearRef(); | |
| 4464 const GURL url_to_send = failed_url.ReplaceComponents(remove_params); | |
| 4465 std::string spec_to_send = url_to_send.spec(); | |
| 4466 // Notify link doctor of the url truncation by sending of "?" at the end. | |
| 4467 if (failed_url.has_query()) | |
| 4468 spec_to_send.append("?"); | |
| 4469 | |
| 4470 // Construct the query params to send to link doctor. | |
| 4471 std::string params(alternate_error_page_url_.query()); | |
| 4472 params.append("&url="); | |
| 4473 params.append(net::EscapeQueryParamValue(spec_to_send, true)); | |
| 4474 params.append("&sourceid=chrome"); | |
| 4475 params.append("&error="); | |
| 4476 switch (error_type) { | |
| 4477 case DNS_ERROR: | |
| 4478 params.append("dnserror"); | |
| 4479 break; | |
| 4480 | |
| 4481 case HTTP_404: | |
| 4482 params.append("http404"); | |
| 4483 break; | |
| 4484 | |
| 4485 case CONNECTION_ERROR: | |
| 4486 params.append("connectionfailure"); | |
| 4487 break; | |
| 4488 | |
| 4489 default: | |
| 4490 NOTREACHED() << "unknown ErrorPageType"; | |
| 4491 } | |
| 4492 | |
| 4493 // OK, build the final url to return. | |
| 4494 GURL::Replacements link_doctor_params; | |
| 4495 link_doctor_params.SetQueryStr(params); | |
| 4496 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); | |
| 4497 return url; | |
| 4498 } | |
| 4499 | |
| 4500 GURL RenderViewImpl::GetOpenerUrl() const { | |
| 4501 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_) | |
| 4502 return GURL(); | |
| 4503 else | |
| 4504 return creator_url_; | |
| 4505 } | |
| 4506 | |
| 4507 GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { | |
| 4508 WebDataSource* ds = frame->dataSource(); | |
| 4509 if (ds->hasUnreachableURL()) | |
| 4510 return ds->unreachableURL(); | |
| 4511 | |
| 4512 const WebURLRequest& request = ds->request(); | |
| 4513 return request.url(); | |
| 4514 } | |
| 4515 | |
| 4516 WebUIBindings* RenderViewImpl::GetWebUIBindings() { | |
| 4517 if (!web_ui_bindings_.get()) { | |
| 4518 web_ui_bindings_.reset(new WebUIBindings( | |
| 4519 static_cast<content::RenderView*>(this), routing_id_)); | |
| 4520 } | |
| 4521 return web_ui_bindings_.get(); | |
| 4522 } | |
| 4523 | |
| 4524 WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { | |
| 4525 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); | |
| 4526 } | |
| 4527 | |
| 4528 void RenderViewImpl::OnFind(int request_id, const string16& search_text, | |
| 4529 const WebFindOptions& options) { | |
| 4530 WebFrame* main_frame = webview()->mainFrame(); | 4519 WebFrame* main_frame = webview()->mainFrame(); |
| 4531 | 4520 |
| 4532 // Check if the plugin still exists in the document. | 4521 // Check if the plugin still exists in the document. |
| 4533 if (main_frame->document().isPluginDocument() && | 4522 if (main_frame->document().isPluginDocument() && |
| 4534 GetWebPluginFromPluginDocument()) { | 4523 GetWebPluginFromPluginDocument()) { |
| 4535 if (options.findNext) { | 4524 if (options.findNext) { |
| 4536 // Just navigate back/forward. | 4525 // Just navigate back/forward. |
| 4537 GetWebPluginFromPluginDocument()->selectFindResult(options.forward); | 4526 GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
| 4538 } else { | 4527 } else { |
| 4539 if (GetWebPluginFromPluginDocument()->startFind( | 4528 if (!GetWebPluginFromPluginDocument()->startFind( |
| 4540 search_text, options.matchCase, request_id)) { | 4529 search_text, options.matchCase, request_id)) { |
| 4541 } else { | |
| 4542 // Send "no results". | 4530 // Send "no results". |
| 4543 Send(new ViewHostMsg_Find_Reply(routing_id_, | 4531 SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
| 4544 request_id, | |
| 4545 0, | |
| 4546 gfx::Rect(), | |
| 4547 0, | |
| 4548 true)); | |
| 4549 } | 4532 } |
| 4550 } | 4533 } |
| 4551 return; | 4534 return; |
| 4552 } | 4535 } |
| 4553 | 4536 |
| 4554 WebFrame* frame_after_main = main_frame->traverseNext(true); | 4537 WebFrame* frame_after_main = main_frame->traverseNext(true); |
| 4555 WebFrame* focused_frame = webview()->focusedFrame(); | 4538 WebFrame* focused_frame = webview()->focusedFrame(); |
| 4556 WebFrame* search_frame = focused_frame; // start searching focused frame. | 4539 WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4557 | 4540 |
| 4558 bool multi_frame = (frame_after_main != main_frame); | 4541 bool multi_frame = (frame_after_main != main_frame); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4611 // If nothing is found, set result to "0 of 0", otherwise, set it to | 4594 // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4612 // "-1 of 1" to indicate that we found at least one item, but we don't know | 4595 // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4613 // yet what is active. | 4596 // yet what is active. |
| 4614 int ordinal = result ? -1 : 0; // -1 here means, we might know more later. | 4597 int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4615 int match_count = result ? 1 : 0; // 1 here means possibly more coming. | 4598 int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
| 4616 | 4599 |
| 4617 // If we find no matches then this will be our last status update. | 4600 // If we find no matches then this will be our last status update. |
| 4618 // Otherwise the scoping effort will send more results. | 4601 // Otherwise the scoping effort will send more results. |
| 4619 bool final_status_update = !result; | 4602 bool final_status_update = !result; |
| 4620 | 4603 |
| 4621 // Send the search result over to the browser process. | 4604 SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 4622 Send(new ViewHostMsg_Find_Reply(routing_id_, | 4605 final_status_update); |
| 4623 request_id, | |
| 4624 match_count, | |
| 4625 selection_rect, | |
| 4626 ordinal, | |
| 4627 final_status_update)); | |
| 4628 | 4606 |
| 4629 // Scoping effort begins, starting with the mainframe. | 4607 // Scoping effort begins, starting with the mainframe. |
| 4630 search_frame = main_frame; | 4608 search_frame = main_frame; |
| 4631 | 4609 |
| 4632 main_frame->resetMatchCount(); | 4610 main_frame->resetMatchCount(); |
| 4633 | 4611 |
| 4634 do { | 4612 do { |
| 4635 // Cancel all old scoping requests before starting a new one. | 4613 // Cancel all old scoping requests before starting a new one. |
| 4636 search_frame->cancelPendingScopingEffort(); | 4614 search_frame->cancelPendingScopingEffort(); |
| 4637 | 4615 |
| 4638 // We don't start another scoping effort unless at least one match has | 4616 // We don't start another scoping effort unless at least one match has |
| 4639 // been found. | 4617 // been found. |
| 4640 if (result) { | 4618 if (result) { |
| 4641 // Start new scoping request. If the scoping function determines that it | 4619 // Start new scoping request. If the scoping function determines that it |
| 4642 // needs to scope, it will defer until later. | 4620 // needs to scope, it will defer until later. |
| 4643 search_frame->scopeStringMatches(request_id, | 4621 search_frame->scopeStringMatches(request_id, |
| 4644 search_text, | 4622 search_text, |
| 4645 options, | 4623 options, |
| 4646 true); // reset the tickmarks | 4624 true); // reset the tickmarks |
| 4647 } | 4625 } |
| 4648 | 4626 |
| 4649 // Iterate to the next frame. The frame will not necessarily scope, for | 4627 // Iterate to the next frame. The frame will not necessarily scope, for |
| 4650 // example if it is not visible. | 4628 // example if it is not visible. |
| 4651 search_frame = search_frame->traverseNext(true); | 4629 search_frame = search_frame->traverseNext(true); |
| 4652 } while (search_frame != main_frame); | 4630 } while (search_frame != main_frame); |
| 4653 } | 4631 } |
| 4654 } | 4632 } |
| 4655 | 4633 |
| 4656 void RenderViewImpl::OnStopFinding(content::StopFindAction action) { | 4634 GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4657 WebView* view = webview(); | 4635 ErrorPageType error_type) { |
| 4658 if (!view) | 4636 if (failed_url.SchemeIsSecure()) { |
| 4659 return; | 4637 // If the URL that failed was secure, then the embedding web page was not |
| 4660 | 4638 // expecting a network attacker to be able to manipulate its contents. As |
| 4661 WebDocument doc = view->mainFrame()->document(); | 4639 // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4662 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { | 4640 // attacker to manipulate the contents of the response if we tried to use |
| 4663 GetWebPluginFromPluginDocument()->stopFind(); | 4641 // the link doctor here. |
| 4664 return; | 4642 return GURL(); |
| 4665 } | 4643 } |
| 4666 | 4644 |
| 4667 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION; | 4645 // Grab the base URL from the browser process. |
| 4668 if (clear_selection) | 4646 if (!alternate_error_page_url_.is_valid()) |
| 4669 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); | 4647 return GURL(); |
| 4670 | 4648 |
| 4671 WebFrame* frame = view->mainFrame(); | 4649 // Strip query params from the failed URL. |
| 4672 while (frame) { | 4650 GURL::Replacements remove_params; |
| 4673 frame->stopFinding(clear_selection); | 4651 remove_params.ClearUsername(); |
| 4674 frame = frame->traverseNext(false); | 4652 remove_params.ClearPassword(); |
| 4653 remove_params.ClearQuery(); | |
| 4654 remove_params.ClearRef(); | |
| 4655 const GURL url_to_send = failed_url.ReplaceComponents(remove_params); | |
| 4656 std::string spec_to_send = url_to_send.spec(); | |
| 4657 // Notify link doctor of the url truncation by sending of "?" at the end. | |
| 4658 if (failed_url.has_query()) | |
| 4659 spec_to_send.append("?"); | |
| 4660 | |
| 4661 // Construct the query params to send to link doctor. | |
| 4662 std::string params(alternate_error_page_url_.query()); | |
| 4663 params.append("&url="); | |
| 4664 params.append(net::EscapeQueryParamValue(spec_to_send, true)); | |
| 4665 params.append("&sourceid=chrome"); | |
| 4666 params.append("&error="); | |
| 4667 switch (error_type) { | |
| 4668 case DNS_ERROR: | |
| 4669 params.append("dnserror"); | |
| 4670 break; | |
| 4671 | |
| 4672 case HTTP_404: | |
| 4673 params.append("http404"); | |
| 4674 break; | |
| 4675 | |
| 4676 case CONNECTION_ERROR: | |
| 4677 params.append("connectionfailure"); | |
| 4678 break; | |
| 4679 | |
| 4680 default: | |
| 4681 NOTREACHED() << "unknown ErrorPageType"; | |
| 4675 } | 4682 } |
| 4676 | 4683 |
| 4677 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) { | 4684 // OK, build the final url to return. |
| 4678 WebFrame* focused_frame = view->focusedFrame(); | 4685 GURL::Replacements link_doctor_params; |
| 4679 if (focused_frame) { | 4686 link_doctor_params.SetQueryStr(params); |
| 4680 WebDocument doc = focused_frame->document(); | 4687 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4681 if (!doc.isNull()) { | 4688 return url; |
| 4682 WebNode node = doc.focusedNode(); | 4689 } |
| 4683 if (!node.isNull()) | 4690 |
| 4684 node.simulateClick(); | 4691 GURL RenderViewImpl::GetOpenerUrl() const { |
| 4685 } | 4692 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_) |
| 4686 } | 4693 return GURL(); |
| 4694 else | |
| 4695 return creator_url_; | |
| 4696 } | |
| 4697 | |
| 4698 GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { | |
| 4699 WebDataSource* ds = frame->dataSource(); | |
| 4700 if (ds->hasUnreachableURL()) | |
| 4701 return ds->unreachableURL(); | |
| 4702 | |
| 4703 const WebURLRequest& request = ds->request(); | |
| 4704 return request.url(); | |
| 4705 } | |
| 4706 | |
| 4707 WebUIBindings* RenderViewImpl::GetWebUIBindings() { | |
| 4708 if (!web_ui_bindings_.get()) { | |
| 4709 web_ui_bindings_.reset(new WebUIBindings( | |
| 4710 static_cast<content::RenderView*>(this), routing_id_)); | |
| 4687 } | 4711 } |
| 4712 return web_ui_bindings_.get(); | |
| 4713 } | |
| 4714 | |
| 4715 WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { | |
| 4716 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); | |
| 4717 } | |
| 4718 | |
| 4719 void RenderViewImpl::OnFind(int request_id, const string16& search_text, | |
| 4720 const WebFindOptions& options) { | |
| 4721 #if defined(OS_ANDROID) | |
| 4722 // Make sure any asynchronous messages do not disrupt an ongoing synchronous | |
| 4723 // find request as it might lead to deadlocks. Also, these should be safe to | |
| 4724 // ignore since they would belong to a previous find request. | |
| 4725 if (synchronous_find_pending_message_.get()) | |
| 4726 return; | |
| 4727 #endif | |
| 4728 Find(request_id, search_text, options); | |
| 4729 } | |
| 4730 | |
| 4731 void RenderViewImpl::OnStopFinding(content::StopFindAction action) { | |
| 4732 #if defined(OS_ANDROID) | |
| 4733 // Make sure any asynchronous messages do not disrupt an ongoing synchronous | |
| 4734 // find request as it might lead to deadlocks. Also, these should be safe to | |
| 4735 // ignore since they would belong to a previous find request. | |
| 4736 if (synchronous_find_pending_message_.get()) | |
| 4737 return; | |
| 4738 #endif | |
| 4739 | |
| 4740 StopFinding(action); | |
| 4688 } | 4741 } |
| 4689 | 4742 |
| 4690 #if defined(OS_ANDROID) | 4743 #if defined(OS_ANDROID) |
| 4744 void RenderViewImpl::OnSynchronousFind(int request_id, | |
| 4745 const string16& search_string, | |
| 4746 const WebFindOptions& options, | |
| 4747 IPC::Message* reply_msg) { | |
| 4748 // It is impossible for simultaneous blocking finds to occur. | |
| 4749 DCHECK(!synchronous_find_pending_message_.get()); | |
|
jam
2012/09/19 16:55:43
nit: make this a CHECK instead?
Leandro Graciá Gil
2012/09/19 18:08:59
Done.
| |
| 4750 synchronous_find_pending_message_.reset(reply_msg); | |
| 4751 | |
| 4752 // Find next should be asynchronous in order to minimize blocking | |
| 4753 // the UI thread as much as possible. | |
| 4754 DCHECK(!options.findNext); | |
| 4755 StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION); | |
| 4756 synchronous_find_active_match_ordinal_ = -1; | |
| 4757 | |
| 4758 Find(request_id, search_string, options); | |
| 4759 } | |
| 4760 | |
| 4691 void RenderViewImpl::OnActivateNearestFindResult(int request_id, | 4761 void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 4692 float x, float y) { | 4762 float x, float y) { |
| 4693 if (!webview()) | 4763 if (!webview()) |
| 4694 return; | 4764 return; |
| 4695 | 4765 |
| 4696 WebFrame* main_frame = webview()->mainFrame(); | 4766 WebFrame* main_frame = webview()->mainFrame(); |
| 4697 WebRect selection_rect; | 4767 WebRect selection_rect; |
| 4698 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), | 4768 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 4699 &selection_rect); | 4769 &selection_rect); |
| 4700 if (ordinal == -1) { | 4770 if (ordinal == -1) { |
| 4701 // Something went wrong, so send a no-op reply (force the main_frame to | 4771 // Something went wrong, so send a no-op reply (force the main_frame to |
| 4702 // report the current match count) in case the host is waiting for a | 4772 // report the current match count) in case the host is waiting for a |
| 4703 // response due to rate-limiting). | 4773 // response due to rate-limiting). |
| 4704 main_frame->increaseMatchCount(0, request_id); | 4774 main_frame->increaseMatchCount(0, request_id); |
| 4705 return; | 4775 return; |
| 4706 } | 4776 } |
| 4707 | 4777 |
| 4708 Send(new ViewHostMsg_Find_Reply(routing_id_, | 4778 SendFindReply(request_id, |
| 4709 request_id, | 4779 -1 /* number_of_matches */, |
| 4710 -1 /* number_of_matches */, | 4780 ordinal, |
| 4711 selection_rect, | 4781 selection_rect, |
| 4712 ordinal, | 4782 true /* final_update */); |
| 4713 true /* final_update */)); | |
| 4714 } | 4783 } |
| 4715 | 4784 |
| 4716 void RenderViewImpl::OnFindMatchRects(int current_version) { | 4785 void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 4717 if (!webview()) | 4786 if (!webview()) |
| 4718 return; | 4787 return; |
| 4719 | 4788 |
| 4720 WebFrame* main_frame = webview()->mainFrame(); | 4789 WebFrame* main_frame = webview()->mainFrame(); |
| 4721 std::vector<gfx::RectF> match_rects; | 4790 std::vector<gfx::RectF> match_rects; |
| 4722 | 4791 |
| 4723 int rects_version = main_frame->findMatchMarkersVersion(); | 4792 int rects_version = main_frame->findMatchMarkersVersion(); |
| (...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6149 | 6218 |
| 6150 updating_frame_tree_ = true; | 6219 updating_frame_tree_ = true; |
| 6151 active_frame_id_map_.clear(); | 6220 active_frame_id_map_.clear(); |
| 6152 | 6221 |
| 6153 target_process_id_ = process_id; | 6222 target_process_id_ = process_id; |
| 6154 target_routing_id_ = route_id; | 6223 target_routing_id_ = route_id; |
| 6155 CreateFrameTree(webview()->mainFrame(), frames); | 6224 CreateFrameTree(webview()->mainFrame(), frames); |
| 6156 | 6225 |
| 6157 updating_frame_tree_ = false; | 6226 updating_frame_tree_ = false; |
| 6158 } | 6227 } |
| OLD | NEW |