| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 history_forward_list_count_(0), | 254 history_forward_list_count_(0), |
| 255 has_unload_listener_(false), | 255 has_unload_listener_(false), |
| 256 decrement_shared_popup_at_destruction_(false), | 256 decrement_shared_popup_at_destruction_(false), |
| 257 autofill_query_id_(0), | 257 autofill_query_id_(0), |
| 258 popup_notification_visible_(false), | 258 popup_notification_visible_(false), |
| 259 spelling_panel_visible_(false), | 259 spelling_panel_visible_(false), |
| 260 send_content_state_immediately_(false), | 260 send_content_state_immediately_(false), |
| 261 send_preferred_size_changes_(false), | 261 send_preferred_size_changes_(false), |
| 262 ALLOW_THIS_IN_INITIALIZER_LIST( | 262 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 263 notification_provider_(new NotificationProvider(this))), | 263 notification_provider_(new NotificationProvider(this))), |
| 264 determine_page_text_after_loading_stops_(false), |
| 264 view_type_(ViewType::INVALID), | 265 view_type_(ViewType::INVALID), |
| 265 browser_window_id_(-1), | 266 browser_window_id_(-1), |
| 266 last_top_level_navigation_page_id_(-1), | 267 last_top_level_navigation_page_id_(-1), |
| 267 #if defined(OS_MACOSX) | 268 #if defined(OS_MACOSX) |
| 268 has_document_tag_(false), | 269 has_document_tag_(false), |
| 269 #endif | 270 #endif |
| 270 document_tag_(0), | 271 document_tag_(0), |
| 271 webkit_preferences_(webkit_preferences) { | 272 webkit_preferences_(webkit_preferences) { |
| 272 } | 273 } |
| 273 | 274 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) | 439 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| 439 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) | 440 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 440 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, | 441 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 441 OnAdvanceToNextMisspelling) | 442 OnAdvanceToNextMisspelling) |
| 442 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) | 443 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
| 443 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) | 444 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 444 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) | 445 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 445 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) | 446 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
| 446 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) | 447 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 447 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) | 448 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
| 449 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText) |
| 448 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) | 450 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
| 449 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost, | 451 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost, |
| 450 OnSetZoomLevelForLoadingHost) | 452 OnSetZoomLevelForLoadingHost) |
| 451 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) | 453 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
| 452 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, | 454 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 453 OnResetPageEncodingToDefault) | 455 OnResetPageEncodingToDefault) |
| 454 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) | 456 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
| 455 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) | 457 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
| 456 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) | 458 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
| 457 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) | 459 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 591 |
| 590 // Don't index/capture pages that failed to load. This only checks the top | 592 // Don't index/capture pages that failed to load. This only checks the top |
| 591 // level frame so the thumbnail may contain a frame that failed to load. | 593 // level frame so the thumbnail may contain a frame that failed to load. |
| 592 WebDataSource* ds = main_frame->dataSource(); | 594 WebDataSource* ds = main_frame->dataSource(); |
| 593 if (ds && ds->hasUnreachableURL()) | 595 if (ds && ds->hasUnreachableURL()) |
| 594 return; | 596 return; |
| 595 | 597 |
| 596 if (!preliminary_capture) | 598 if (!preliminary_capture) |
| 597 last_indexed_page_id_ = load_id; | 599 last_indexed_page_id_ = load_id; |
| 598 | 600 |
| 599 // Get the URL for this page. | 601 // get the URL for this page |
| 600 GURL url(main_frame->url()); | 602 GURL url(main_frame->url()); |
| 601 if (url.is_empty()) | 603 if (url.is_empty()) |
| 602 return; | 604 return; |
| 603 | 605 |
| 604 // Retrieve the frame's full text. | 606 // full text |
| 605 std::wstring contents; | 607 std::wstring contents; |
| 606 CaptureText(main_frame, &contents); | 608 CaptureText(main_frame, &contents); |
| 607 if (contents.size()) { | 609 if (contents.size()) { |
| 608 // Send the text to the browser for indexing (the browser might decide not | 610 // Send the text to the browser for indexing. |
| 609 // to index, if the URL is HTTPS for instance) and language discovery. | 611 Send(new ViewHostMsg_PageContents(url, load_id, contents)); |
| 610 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents)); | 612 } |
| 613 |
| 614 // Send over text content of this page to the browser. |
| 615 if (determine_page_text_after_loading_stops_) { |
| 616 determine_page_text_after_loading_stops_ = false; |
| 617 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents)); |
| 611 } | 618 } |
| 612 | 619 |
| 613 // thumbnail | 620 // thumbnail |
| 614 SendThumbnail(); | 621 SendThumbnail(); |
| 615 } | 622 } |
| 616 | 623 |
| 617 void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { | 624 void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { |
| 618 contents->clear(); | 625 contents->clear(); |
| 619 if (!frame) | 626 if (!frame) |
| 620 return; | 627 return; |
| 621 | 628 |
| 629 // Don't index any https pages. People generally don't want their bank |
| 630 // accounts, etc. indexed on their computer, especially since some of these |
| 631 // things are not marked cachable. |
| 632 // TODO(brettw) we may want to consider more elaborate heuristics such as |
| 633 // the cachability of the page. We may also want to consider subframes (this |
| 634 // test will still index subframes if the subframe is SSL). |
| 635 if (GURL(frame->url()).SchemeIsSecure()) |
| 636 return; |
| 637 |
| 622 #ifdef TIME_TEXT_RETRIEVAL | 638 #ifdef TIME_TEXT_RETRIEVAL |
| 623 double begin = time_util::GetHighResolutionTimeNow(); | 639 double begin = time_util::GetHighResolutionTimeNow(); |
| 624 #endif | 640 #endif |
| 625 | 641 |
| 626 // get the contents of the frame | 642 // get the contents of the frame |
| 627 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars)); | 643 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars)); |
| 628 | 644 |
| 629 #ifdef TIME_TEXT_RETRIEVAL | 645 #ifdef TIME_TEXT_RETRIEVAL |
| 630 double end = time_util::GetHighResolutionTimeNow(); | 646 double end = time_util::GetHighResolutionTimeNow(); |
| 631 char buf[128]; | 647 char buf[128]; |
| (...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2959 true); // reset the tickmarks | 2975 true); // reset the tickmarks |
| 2960 } | 2976 } |
| 2961 | 2977 |
| 2962 // Iterate to the next frame. The frame will not necessarily scope, for | 2978 // Iterate to the next frame. The frame will not necessarily scope, for |
| 2963 // example if it is not visible. | 2979 // example if it is not visible. |
| 2964 search_frame = search_frame->traverseNext(true); | 2980 search_frame = search_frame->traverseNext(true); |
| 2965 } while (search_frame != main_frame); | 2981 } while (search_frame != main_frame); |
| 2966 } | 2982 } |
| 2967 } | 2983 } |
| 2968 | 2984 |
| 2985 void RenderView::OnDeterminePageText() { |
| 2986 if (!is_loading_) { |
| 2987 if (!webview()) |
| 2988 return; |
| 2989 WebFrame* main_frame = webview()->mainFrame(); |
| 2990 std::wstring contents; |
| 2991 CaptureText(main_frame, &contents); |
| 2992 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents)); |
| 2993 determine_page_text_after_loading_stops_ = false; |
| 2994 return; |
| 2995 } |
| 2996 |
| 2997 // We set |determine_page_text_after_loading_stops_| true here so that, |
| 2998 // after page has been loaded completely, the text in the page is captured. |
| 2999 determine_page_text_after_loading_stops_ = true; |
| 3000 } |
| 3001 |
| 2969 void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { | 3002 void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { |
| 2970 Send(new ViewHostMsg_DnsPrefetch(host_names)); | 3003 Send(new ViewHostMsg_DnsPrefetch(host_names)); |
| 2971 } | 3004 } |
| 2972 | 3005 |
| 2973 void RenderView::OnZoom(PageZoom::Function function) { | 3006 void RenderView::OnZoom(PageZoom::Function function) { |
| 2974 if (!webview()) // Not sure if this can happen, but no harm in being safe. | 3007 if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 2975 return; | 3008 return; |
| 2976 | 3009 |
| 2977 int zoom_level = webview()->zoomLevel(); | 3010 int zoom_level = webview()->zoomLevel(); |
| 2978 int new_zoom_level = webview()->setZoomLevel(false, | 3011 int new_zoom_level = webview()->setZoomLevel(false, |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3896 new PluginMsg_SignalModalDialogEvent(host_window_)); | 3929 new PluginMsg_SignalModalDialogEvent(host_window_)); |
| 3897 | 3930 |
| 3898 message->EnableMessagePumping(); // Runs a nested message loop. | 3931 message->EnableMessagePumping(); // Runs a nested message loop. |
| 3899 bool rv = Send(message); | 3932 bool rv = Send(message); |
| 3900 | 3933 |
| 3901 PluginChannelHost::Broadcast( | 3934 PluginChannelHost::Broadcast( |
| 3902 new PluginMsg_ResetModalDialogEvent(host_window_)); | 3935 new PluginMsg_ResetModalDialogEvent(host_window_)); |
| 3903 | 3936 |
| 3904 return rv; | 3937 return rv; |
| 3905 } | 3938 } |
| OLD | NEW |