OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)), | 558 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)), |
559 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), | 559 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), |
560 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), | 560 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
561 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), | 561 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
562 devtools_client_(NULL), | 562 devtools_client_(NULL), |
563 geolocation_dispatcher_(NULL), | 563 geolocation_dispatcher_(NULL), |
564 speech_input_dispatcher_(NULL), | 564 speech_input_dispatcher_(NULL), |
565 device_orientation_dispatcher_(NULL), | 565 device_orientation_dispatcher_(NULL), |
566 accessibility_ack_pending_(false), | 566 accessibility_ack_pending_(false), |
567 pending_app_icon_requests_(0), | 567 pending_app_icon_requests_(0), |
568 session_storage_namespace_id_(session_storage_namespace_id), | 568 session_storage_namespace_id_(session_storage_namespace_id) { |
569 custom_menu_listener_(NULL) { | |
570 #if defined(OS_MACOSX) | 569 #if defined(OS_MACOSX) |
571 // On Mac, the select popups are rendered by the browser. | 570 // On Mac, the select popups are rendered by the browser. |
572 // Note that we don't do this in RenderMain otherwise this would not be called | 571 // Note that we don't do this in RenderMain otherwise this would not be called |
573 // in single-process mode. | 572 // in single-process mode. |
574 WebKit::WebView::setUseExternalPopupMenus(true); | 573 WebKit::WebView::setUseExternalPopupMenus(true); |
575 #endif | 574 #endif |
576 | 575 |
577 ClearBlockedContentSettings(); | 576 ClearBlockedContentSettings(); |
578 if (CommandLine::ForCurrentProcess()->HasSwitch( | 577 if (CommandLine::ForCurrentProcess()->HasSwitch( |
579 switches::kEnableClientSidePhishingDetection)) { | 578 switches::kEnableClientSidePhishingDetection)) { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 if (!found || !info.enabled) | 923 if (!found || !info.enabled) |
925 return NULL; | 924 return NULL; |
926 | 925 |
927 scoped_refptr<webkit::ppapi::PluginModule> pepper_module( | 926 scoped_refptr<webkit::ppapi::PluginModule> pepper_module( |
928 pepper_delegate_.CreatePepperPlugin(info.path)); | 927 pepper_delegate_.CreatePepperPlugin(info.path)); |
929 if (pepper_module) | 928 if (pepper_module) |
930 return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); | 929 return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); |
931 return CreateNPAPIPlugin(frame, params, info.path, mime_type); | 930 return CreateNPAPIPlugin(frame, params, info.path, mime_type); |
932 } | 931 } |
933 | 932 |
934 void RenderView::CustomMenuListenerInstall(CustomMenuListener* listening) { | |
935 custom_menu_listener_ = listening; | |
936 } | |
937 | |
938 void RenderView::CustomMenuListenerDestroyed(CustomMenuListener* dead) { | |
939 if (custom_menu_listener_ == dead) | |
940 custom_menu_listener_ = NULL; | |
941 } | |
942 | |
943 void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { | 933 void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
944 plugin_delegates_.insert(delegate); | 934 plugin_delegates_.insert(delegate); |
945 // If the renderer is visible, set initial visibility and focus state. | 935 // If the renderer is visible, set initial visibility and focus state. |
946 if (!is_hidden()) { | 936 if (!is_hidden()) { |
947 #if defined(OS_MACOSX) | 937 #if defined(OS_MACOSX) |
948 delegate->SetContainerVisibility(true); | 938 delegate->SetContainerVisibility(true); |
949 if (webview() && webview()->isActive()) | 939 if (webview() && webview()->isActive()) |
950 delegate->SetWindowFocus(true); | 940 delegate->SetWindowFocus(true); |
951 #endif | 941 #endif |
952 } | 942 } |
953 // Plugins start assuming the content has focus (so that they work in | 943 // Plugins start assuming the content has focus (so that they work in |
954 // environments where RenderView isn't hosting them), so we always have to | 944 // environments where RenderView isn't hosting them), so we always have to |
955 // set the initial state. See webplugin_delegate_impl.h for details. | 945 // set the initial state. See webplugin_delegate_impl.h for details. |
956 delegate->SetContentAreaFocus(has_focus()); | 946 delegate->SetContentAreaFocus(has_focus()); |
957 } | 947 } |
958 | 948 |
959 void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { | 949 void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
960 plugin_delegates_.erase(delegate); | 950 plugin_delegates_.erase(delegate); |
961 } | 951 } |
962 | 952 |
963 void RenderView::RegisterBlockedPlugin(BlockedPlugin* blocked_plugin) { | |
964 blocked_plugins_.insert(blocked_plugin); | |
965 } | |
966 | |
967 void RenderView::UnregisterBlockedPlugin(BlockedPlugin* blocked_plugin) { | |
968 blocked_plugins_.erase(blocked_plugin); | |
969 } | |
970 | |
971 bool RenderView::OnMessageReceived(const IPC::Message& message) { | 953 bool RenderView::OnMessageReceived(const IPC::Message& message) { |
972 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; | 954 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
973 if (main_frame) | 955 if (main_frame) |
974 child_process_logging::SetActiveURL(main_frame->url()); | 956 child_process_logging::SetActiveURL(main_frame->url()); |
975 | 957 |
976 ObserverListBase<RenderViewObserver>::Iterator it(observers_); | 958 ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
977 RenderViewObserver* observer; | 959 RenderViewObserver* observer; |
978 while ((observer = it.GetNext()) != NULL) | 960 while ((observer = it.GetNext()) != NULL) |
979 if (observer->OnMessageReceived(message)) | 961 if (observer->OnMessageReceived(message)) |
980 return true; | 962 return true; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 OnDragSourceEndedOrMoved) | 1018 OnDragSourceEndedOrMoved) |
1037 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, | 1019 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
1038 OnDragSourceSystemDragEnded) | 1020 OnDragSourceSystemDragEnded) |
1039 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) | 1021 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
1040 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView, | 1022 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView, |
1041 OnScrollFocusedEditableNodeIntoView) | 1023 OnScrollFocusedEditableNodeIntoView) |
1042 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 1024 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
1043 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) | 1025 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
1044 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) | 1026 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
1045 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) | 1027 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
1046 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) | |
1047 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) | 1028 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
1048 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 1029 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
1049 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, | 1030 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
1050 OnGetAllSavableResourceLinksForCurrentPage) | 1031 OnGetAllSavableResourceLinksForCurrentPage) |
1051 IPC_MESSAGE_HANDLER( | 1032 IPC_MESSAGE_HANDLER( |
1052 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, | 1033 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
1053 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) | 1034 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
1054 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) | 1035 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
1055 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) | 1036 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
1056 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 1037 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2441 // response as RunJavaScriptMessage. | 2422 // response as RunJavaScriptMessage. |
2442 std::wstring ignored_result; | 2423 std::wstring ignored_result; |
2443 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( | 2424 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
2444 routing_id_, frame->url(), UTF16ToWideHack(message), &success, | 2425 routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
2445 &ignored_result)); | 2426 &ignored_result)); |
2446 return success; | 2427 return success; |
2447 } | 2428 } |
2448 | 2429 |
2449 void RenderView::showContextMenu( | 2430 void RenderView::showContextMenu( |
2450 WebFrame* frame, const WebContextMenuData& data) { | 2431 WebFrame* frame, const WebContextMenuData& data) { |
2451 custom_menu_listener_ = NULL; | |
2452 ContextMenuParams params = ContextMenuParams(data); | 2432 ContextMenuParams params = ContextMenuParams(data); |
2453 if (!params.misspelled_word.empty() && RenderThread::current()) { | 2433 if (!params.misspelled_word.empty() && RenderThread::current()) { |
2454 int misspelled_offset, misspelled_length; | 2434 int misspelled_offset, misspelled_length; |
2455 bool spelled_right = RenderThread::current()->spellchecker()-> | 2435 bool spelled_right = RenderThread::current()->spellchecker()-> |
2456 SpellCheckWord( | 2436 SpellCheckWord( |
2457 params.misspelled_word.c_str(), params.misspelled_word.size(), | 2437 params.misspelled_word.c_str(), params.misspelled_word.size(), |
2458 document_tag_, | 2438 document_tag_, |
2459 &misspelled_offset, &misspelled_length, | 2439 &misspelled_offset, &misspelled_length, |
2460 ¶ms.dictionary_suggestions); | 2440 ¶ms.dictionary_suggestions); |
2461 if (spelled_right) | 2441 if (spelled_right) |
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4671 void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { | 4651 void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
4672 webkit_preferences_ = prefs; | 4652 webkit_preferences_ = prefs; |
4673 webkit_preferences_.Apply(webview()); | 4653 webkit_preferences_.Apply(webview()); |
4674 } | 4654 } |
4675 | 4655 |
4676 void RenderView::OnSetAltErrorPageURL(const GURL& url) { | 4656 void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
4677 alternate_error_page_url_ = url; | 4657 alternate_error_page_url_ = url; |
4678 } | 4658 } |
4679 | 4659 |
4680 void RenderView::OnCustomContextMenuAction(unsigned action) { | 4660 void RenderView::OnCustomContextMenuAction(unsigned action) { |
4681 if (custom_menu_listener_) | 4661 webview()->performCustomContextMenuAction(action); |
4682 custom_menu_listener_->MenuItemSelected(action); | |
4683 else | |
4684 webview()->performCustomContextMenuAction(action); | |
4685 } | 4662 } |
4686 | 4663 |
4687 void RenderView::OnTranslatePage(int page_id, | 4664 void RenderView::OnTranslatePage(int page_id, |
4688 const std::string& translate_script, | 4665 const std::string& translate_script, |
4689 const std::string& source_lang, | 4666 const std::string& source_lang, |
4690 const std::string& target_lang) { | 4667 const std::string& target_lang) { |
4691 translate_helper_.TranslatePage(page_id, source_lang, target_lang, | 4668 translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
4692 translate_script); | 4669 translate_script); |
4693 } | 4670 } |
4694 | 4671 |
4695 void RenderView::OnRevertTranslation(int page_id) { | 4672 void RenderView::OnRevertTranslation(int page_id) { |
4696 translate_helper_.RevertTranslation(page_id); | 4673 translate_helper_.RevertTranslation(page_id); |
4697 } | 4674 } |
4698 | 4675 |
4699 void RenderView::OnInstallMissingPlugin() { | 4676 void RenderView::OnInstallMissingPlugin() { |
4700 // This could happen when the first default plugin is deleted. | 4677 // This could happen when the first default plugin is deleted. |
4701 if (first_default_plugin_) | 4678 if (first_default_plugin_) |
4702 first_default_plugin_->InstallMissingPlugin(); | 4679 first_default_plugin_->InstallMissingPlugin(); |
4703 } | 4680 } |
4704 | 4681 |
4705 void RenderView::OnLoadBlockedPlugins() { | |
4706 while (!blocked_plugins_.empty()) | |
4707 (*blocked_plugins_.begin())->LoadPlugin(); | |
4708 } | |
4709 | |
4710 void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { | 4682 void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
4711 // This could happen if we navigated to a different page before the user | 4683 // This could happen if we navigated to a different page before the user |
4712 // closed the chooser. | 4684 // closed the chooser. |
4713 if (file_chooser_completions_.empty()) | 4685 if (file_chooser_completions_.empty()) |
4714 return; | 4686 return; |
4715 | 4687 |
4716 WebVector<WebString> ws_file_names(paths.size()); | 4688 WebVector<WebString> ws_file_names(paths.size()); |
4717 for (size_t i = 0; i < paths.size(); ++i) | 4689 for (size_t i = 0; i < paths.size(); ++i) |
4718 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); | 4690 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
4719 | 4691 |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5714 if (cmd == kJavaScriptStressTestSetStressRunType) { | 5686 if (cmd == kJavaScriptStressTestSetStressRunType) { |
5715 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); | 5687 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); |
5716 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { | 5688 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { |
5717 v8::Testing::PrepareStressRun(param); | 5689 v8::Testing::PrepareStressRun(param); |
5718 } | 5690 } |
5719 } | 5691 } |
5720 | 5692 |
5721 void RenderView::OnContextMenuClosed() { | 5693 void RenderView::OnContextMenuClosed() { |
5722 context_menu_node_.reset(); | 5694 context_menu_node_.reset(); |
5723 } | 5695 } |
OLD | NEW |