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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 has_unload_listener_(false), | 205 has_unload_listener_(false), |
206 decrement_shared_popup_at_destruction_(false), | 206 decrement_shared_popup_at_destruction_(false), |
207 form_field_autofill_request_id_(0), | 207 form_field_autofill_request_id_(0), |
208 popup_notification_visible_(false), | 208 popup_notification_visible_(false), |
209 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync), | 209 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync), |
210 preferred_width_(0), | 210 preferred_width_(0), |
211 send_preferred_width_changes_(false), | 211 send_preferred_width_changes_(false), |
212 determine_page_text_after_loading_stops_(false), | 212 determine_page_text_after_loading_stops_(false), |
213 view_type_(ViewType::INVALID), | 213 view_type_(ViewType::INVALID), |
214 browser_window_id_(-1), | 214 browser_window_id_(-1), |
215 last_top_level_navigation_page_id_(-1), | 215 last_top_level_navigation_page_id_(-1), |
| 216 has_spell_checker_document_tag_(false), |
| 217 document_tag_(0), |
216 webkit_preferences_(webkit_preferences) { | 218 webkit_preferences_(webkit_preferences) { |
217 Singleton<RenderViewSet>()->render_view_set_.insert(this); | 219 Singleton<RenderViewSet>()->render_view_set_.insert(this); |
218 } | 220 } |
219 | 221 |
220 RenderView::~RenderView() { | 222 RenderView::~RenderView() { |
221 Singleton<RenderViewSet>()->render_view_set_.erase(this); | 223 Singleton<RenderViewSet>()->render_view_set_.erase(this); |
222 if (decrement_shared_popup_at_destruction_) | 224 if (decrement_shared_popup_at_destruction_) |
223 shared_popup_counter_->data--; | 225 shared_popup_counter_->data--; |
224 | 226 |
| 227 // Tell the spellchecker that the document is closed. |
| 228 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
| 229 |
225 render_thread_->RemoveFilter(audio_message_filter_); | 230 render_thread_->RemoveFilter(audio_message_filter_); |
226 } | 231 } |
227 | 232 |
228 /*static*/ | 233 /*static*/ |
229 RenderView* RenderView::Create( | 234 RenderView* RenderView::Create( |
230 RenderThreadBase* render_thread, | 235 RenderThreadBase* render_thread, |
231 gfx::NativeViewId parent_hwnd, | 236 gfx::NativeViewId parent_hwnd, |
232 base::WaitableEvent* modal_dialog_event, | 237 base::WaitableEvent* modal_dialog_event, |
233 int32 opener_id, | 238 int32 opener_id, |
234 const RendererPreferences& renderer_prefs, | 239 const RendererPreferences& renderer_prefs, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) | 344 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
340 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) | 345 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
341 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText) | 346 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText) |
342 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) | 347 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
343 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) | 348 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
344 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) | 349 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
345 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) | 350 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
346 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) | 351 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
347 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) | 352 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
348 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) | 353 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| 354 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 355 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 356 OnAdvanceToNextMisspelling) |
349 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) | 357 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
350 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) | 358 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
351 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) | 359 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
352 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) | 360 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
353 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) | 361 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
354 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) | 362 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
355 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText) | 363 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText) |
356 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) | 364 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
357 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText) | 365 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText) |
358 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) | 366 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 UserMetricsRecordAction(L"Paste"); | 830 UserMetricsRecordAction(L"Paste"); |
823 } | 831 } |
824 | 832 |
825 void RenderView::OnReplace(const std::wstring& text) { | 833 void RenderView::OnReplace(const std::wstring& text) { |
826 if (!webview()) | 834 if (!webview()) |
827 return; | 835 return; |
828 | 836 |
829 webview()->GetFocusedFrame()->replaceSelection(WideToUTF16Hack(text)); | 837 webview()->GetFocusedFrame()->replaceSelection(WideToUTF16Hack(text)); |
830 } | 838 } |
831 | 839 |
| 840 void RenderView::OnAdvanceToNextMisspelling() { |
| 841 if (!webview()) |
| 842 return; |
| 843 webview()->GetFocusedFrame()->executeCommand( |
| 844 WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 845 } |
| 846 |
| 847 void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 848 if (!webview()) |
| 849 return; |
| 850 // We need to tell the webView whether the spelling panel is visible or not so |
| 851 // that it won't need to make ipc calls later. |
| 852 webview()->SetSpellingPanelVisibility(is_currently_visible); |
| 853 webview()->GetFocusedFrame()->executeCommand( |
| 854 WebString::fromUTF8("ToggleSpellPanel")); |
| 855 } |
| 856 |
832 void RenderView::OnToggleSpellCheck() { | 857 void RenderView::OnToggleSpellCheck() { |
833 if (!webview()) | 858 if (!webview()) |
834 return; | 859 return; |
835 | 860 |
836 WebFrame* frame = webview()->GetFocusedFrame(); | 861 WebFrame* frame = webview()->GetFocusedFrame(); |
837 frame->enableContinuousSpellChecking( | 862 frame->enableContinuousSpellChecking( |
838 !frame->isContinuousSpellCheckingEnabled()); | 863 !frame->isContinuousSpellCheckingEnabled()); |
839 } | 864 } |
840 | 865 |
841 void RenderView::OnDelete() { | 866 void RenderView::OnDelete() { |
(...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 -1, | 2541 -1, |
2517 selection_rect, | 2542 selection_rect, |
2518 active_match_ordinal, | 2543 active_match_ordinal, |
2519 false)); | 2544 false)); |
2520 } | 2545 } |
2521 | 2546 |
2522 bool RenderView::WasOpenedByUserGesture() const { | 2547 bool RenderView::WasOpenedByUserGesture() const { |
2523 return opened_by_user_gesture_; | 2548 return opened_by_user_gesture_; |
2524 } | 2549 } |
2525 | 2550 |
2526 void RenderView::SpellCheck(const std::wstring& word, int* misspell_location, | 2551 void RenderView::SpellCheck(const std::wstring& word, int tag, |
2527 int* misspell_length) { | 2552 int* misspell_location, |
2528 Send(new ViewHostMsg_SpellCheck(routing_id_, word, misspell_location, | 2553 int* misspell_length) { |
2529 misspell_length)); | 2554 Send(new ViewHostMsg_SpellCheck(routing_id_, word, tag, |
| 2555 misspell_location, misspell_length)); |
2530 } | 2556 } |
2531 | 2557 |
2532 std::wstring RenderView::GetAutoCorrectWord( | 2558 std::wstring RenderView::GetAutoCorrectWord( |
2533 const std::wstring& misspelled_word) { | 2559 const std::wstring& misspelled_word, int tag) { |
2534 std::wstring autocorrect_word; | 2560 std::wstring autocorrect_word; |
2535 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 2561 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
2536 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) { | 2562 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) { |
2537 Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word, | 2563 Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word, tag, |
2538 &autocorrect_word)); | 2564 &autocorrect_word)); |
2539 } | 2565 } |
2540 | 2566 |
2541 return autocorrect_word; | 2567 return autocorrect_word; |
2542 } | 2568 } |
2543 | 2569 |
| 2570 void RenderView::ShowSpellingUI(bool show) { |
| 2571 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 2572 } |
| 2573 |
| 2574 int RenderView::SpellCheckerDocumentTag() { |
| 2575 if (!has_spell_checker_document_tag_) { |
| 2576 // Make the call to get the tag. |
| 2577 int tag; |
| 2578 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &tag)); |
| 2579 document_tag_ = tag; |
| 2580 has_spell_checker_document_tag_ = true; |
| 2581 } |
| 2582 return document_tag_; |
| 2583 } |
| 2584 |
| 2585 void RenderView::UpdateSpellingUIWithMisspelledWord(const std::wstring& word) { |
| 2586 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord( |
| 2587 routing_id_, word)); |
| 2588 } |
| 2589 |
2544 void RenderView::ScriptedPrint(WebFrame* frame) { | 2590 void RenderView::ScriptedPrint(WebFrame* frame) { |
2545 DCHECK(webview()); | 2591 DCHECK(webview()); |
2546 if (webview()) { | 2592 if (webview()) { |
2547 // Print the full page - not just the frame the javascript is running from. | 2593 // Print the full page - not just the frame the javascript is running from. |
2548 Print(webview()->GetMainFrame(), true); | 2594 Print(webview()->GetMainFrame(), true); |
2549 } | 2595 } |
2550 } | 2596 } |
2551 | 2597 |
2552 void RenderView::UserMetricsRecordAction(const std::wstring& action) { | 2598 void RenderView::UserMetricsRecordAction(const std::wstring& action) { |
2553 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); | 2599 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3388 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms)); | 3434 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms)); |
3389 } | 3435 } |
3390 | 3436 |
3391 void RenderView::Print(WebFrame* frame, bool script_initiated) { | 3437 void RenderView::Print(WebFrame* frame, bool script_initiated) { |
3392 DCHECK(frame); | 3438 DCHECK(frame); |
3393 if (print_helper_.get() == NULL) { | 3439 if (print_helper_.get() == NULL) { |
3394 print_helper_.reset(new PrintWebViewHelper(this)); | 3440 print_helper_.reset(new PrintWebViewHelper(this)); |
3395 } | 3441 } |
3396 print_helper_->Print(frame, script_initiated); | 3442 print_helper_->Print(frame, script_initiated); |
3397 } | 3443 } |
OLD | NEW |