blob: 3ed2c34ca95ec267e8dde225842d826fb0e1ebac [file] [log] [blame]
[email protected]1b4209f2011-01-07 00:25:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]2041cf342010-02-19 03:15:5912#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]625332e02010-12-14 07:48:4915#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2817#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5118#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_piece.h"
20#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2821#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2622#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2223#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]c4a9e932011-03-05 04:05:5525#include "chrome/common/autofill_messages.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2829#include "chrome/common/chrome_paths.h"
30#include "chrome/common/chrome_switches.h"
[email protected]a0cf04a2010-06-23 03:29:5531#include "chrome/common/extensions/extension.h"
[email protected]46fd1ea42011-02-16 15:59:3332#include "chrome/common/extensions/extension_constants.h"
[email protected]ec7db282011-01-29 01:11:3633#include "chrome/common/extensions/extension_set.h"
[email protected]bb461532010-11-26 21:50:2334#include "chrome/common/json_value_serializer.h"
[email protected]4e0616e2010-05-28 14:55:5335#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]a527a022011-02-10 02:32:3637#include "chrome/common/render_messages_params.h"
[email protected]13a1e4c3c2011-02-03 21:07:0938#include "chrome/common/render_view_commands.h"
[email protected]9b6f40e2009-06-11 15:54:2639#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5941#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4442#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1143#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2944#include "chrome/renderer/about_handler.h"
[email protected]78192082011-01-29 05:43:4445#include "chrome/renderer/autofill/autofill_agent.h"
46#include "chrome/renderer/autofill/form_manager.h"
47#include "chrome/renderer/autofill/password_autofill_manager.h"
[email protected]2f979172010-09-16 21:54:0348#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]e4ac5df2009-03-17 15:33:1149#include "chrome/renderer/devtools_agent.h"
50#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3551#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0452#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3253#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3554#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]78d5cfe2011-02-04 08:43:2255#include "chrome/renderer/extensions/extension_resource_request_policy.h"
[email protected]7120f132009-07-20 21:05:3756#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0357#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0858#include "chrome/renderer/external_popup_menu.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/localized_error.h"
[email protected]6a8ddba52010-09-05 04:38:0660#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3661#include "chrome/renderer/page_load_histograms.h"
[email protected]d81c1e52009-06-03 22:09:5062#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2563#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2864#include "chrome/renderer/render_thread.h"
[email protected]676126f72011-01-15 00:03:5165#include "chrome/renderer/render_view_observer.h"
[email protected]4d51d5bf2010-07-26 18:48:2666#include "chrome/renderer/render_view_visitor.h"
[email protected]32ca14682011-02-16 19:05:1067#include "chrome/renderer/safe_browsing/malware_dom_details.h"
[email protected]3ead1322010-11-19 20:01:0068#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]6c2f73202011-02-14 20:21:5469#include "chrome/renderer/searchbox.h"
[email protected]85c55dc2009-11-06 03:05:4670#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]c4a9e932011-03-05 04:05:5571#include "chrome/renderer/spellchecker/spellcheck_provider.h"
[email protected]81273622011-02-02 03:56:1372#include "chrome/renderer/translate_helper.h"
[email protected]25e18f82010-10-27 16:38:4373#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3574#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2975#include "chrome/renderer/visitedlink_slave.h"
[email protected]e93e04e2011-03-14 00:27:1076#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1077#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4278#include "content/common/content_constants.h"
[email protected]37666cf2011-03-13 21:51:4279#include "content/common/database_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2880#include "content/common/file_system/file_system_dispatcher.h"
81#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]7f070d42011-03-09 20:25:3282#include "content/common/notification_service.h"
[email protected]4dd57932011-03-17 06:06:1283#include "content/common/page_zoom.h"
[email protected]127dd582011-03-16 21:32:1084#include "content/common/pepper_messages.h"
[email protected]230b7ef2011-03-16 22:30:1985#include "content/renderer/audio_message_filter.h"
[email protected]21d61e52011-03-18 19:08:2586#include "content/renderer/content_renderer_client.h"
[email protected]230b7ef2011-03-16 22:30:1987#include "content/renderer/device_orientation_dispatcher.h"
88#include "content/renderer/geolocation_dispatcher.h"
[email protected]ccc70d8e2011-03-16 20:40:3789#include "content/renderer/ggl.h"
[email protected]921f1592011-03-18 00:41:0290#include "content/renderer/load_progress_tracker.h"
[email protected]ccc70d8e2011-03-16 20:40:3791#include "content/renderer/media/audio_renderer_impl.h"
92#include "content/renderer/media/ipc_video_decoder.h"
[email protected]921f1592011-03-18 00:41:0293#include "content/renderer/navigation_state.h"
[email protected]230b7ef2011-03-16 22:30:1994#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3795#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3596#include "content/renderer/plugin_channel_host.h"
[email protected]acb94722011-03-18 01:33:3497#include "content/renderer/renderer_webapplicationcachehost_impl.h"
98#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]2cff0052011-03-18 16:51:4499#include "content/renderer/render_widget_fullscreen.h"
100#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]230b7ef2011-03-16 22:30:19101#include "content/renderer/speech_input_dispatcher.h"
[email protected]6f516082011-03-17 19:15:35102#include "content/renderer/webgraphicscontext3d_command_buffer_impl.h"
103#include "content/renderer/webplugin_delegate_proxy.h"
104#include "content/renderer/websharedworker_proxy.h"
105#include "content/renderer/webworker_proxy.h"
[email protected]921f1592011-03-18 00:41:02106#include "content/renderer/web_ui_bindings.h"
[email protected]f8db8132010-12-03 00:27:49107#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41108#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:27109#include "media/base/message_loop_factory_impl.h"
[email protected]f11ca0732009-04-11 00:09:34110#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29111#include "net/base/escape.h"
112#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04113#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:57114#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]c399a8a2008-11-22 19:38:00115#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10116#include "skia/ext/image_operations.h"
[email protected]8bd0fe62011-01-17 06:44:37117#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]69f110d62011-03-17 19:01:14136#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]232a5812011-03-04 22:42:08137#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]8bd0fe62011-01-17 06:44:37138#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
[email protected]5efcef62011-02-22 09:00:13155#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingCompletion.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h"
[email protected]8bd0fe62011-01-17 06:44:37157#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
158#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
159#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
163#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26164#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
165#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55166#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38167#include "ui/gfx/color_utils.h"
168#include "ui/gfx/favicon_size.h"
169#include "ui/gfx/native_widget_types.h"
170#include "ui/gfx/point.h"
171#include "ui/gfx/rect.h"
172#include "ui/gfx/skbitmap_operations.h"
[email protected]a6097f42011-01-10 08:50:51173#include "v8/include/v8-testing.h"
[email protected]c4a9e932011-03-05 04:05:55174#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04175#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43176#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24177#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29178#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59179#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24180#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24181#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34182#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26183#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09184#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26185#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23186#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09187#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24188#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29189#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07190#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29191#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17192#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50193#include "webkit/plugins/npapi/default_plugin_shared.h"
194#include "webkit/plugins/npapi/plugin_list.h"
195#include "webkit/plugins/npapi/webplugin_delegate.h"
196#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
197#include "webkit/plugins/npapi/webplugin_impl.h"
198#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52199#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29200
[email protected]6c8afae52009-01-22 02:24:57201#if defined(OS_WIN)
202// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57203// * theming
[email protected]08397d52011-02-05 01:53:38204#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03205#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37206#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]08397d52011-02-05 01:53:38207#include "ui/gfx/native_theme_linux.h"
[email protected]78043bdd2010-04-05 18:45:33208#elif defined(OS_MACOSX)
209#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57210#endif
211
[email protected]c7287a92009-11-04 20:06:15212using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42213using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08214using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21215using WebKit::WebApplicationCacheHost;
216using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26217using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41218using WebKit::WebColor;
219using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59220using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44221using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51222using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55223using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28224using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29225using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00226using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58227using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25228using WebKit::WebDragOperation;
229using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51230using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51231using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08232using WebKit::WebExternalPopupMenu;
233using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47234using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22235using WebKit::WebFileSystem;
236using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49237using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59238using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48239using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45240using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17241using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41242using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50243using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17244using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28245using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17246using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28247using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28248using WebKit::WebNavigationType;
[email protected]232a5812011-03-04 22:42:08249using WebKit::WebNetworkStateNotifier;
[email protected]79dbc662009-09-04 05:42:51250using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07251using WebKit::WebPageSerializer;
252using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17253using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40254using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49255using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09256using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52257using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59258using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51259using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52260using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40261using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35262using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29263using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59264using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42265using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02266using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34267using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28268using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51269using WebKit::WebTextAffinity;
[email protected]5efcef62011-02-22 09:00:13270using WebKit::WebTextCheckingResult;
[email protected]de570ef2009-07-29 18:27:52271using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28272using WebKit::WebURL;
273using WebKit::WebURLError;
274using WebKit::WebURLRequest;
275using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28276using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03277using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28278using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26279using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43280using WebKit::WebWorker;
281using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26282using appcache::WebApplicationCacheHostImpl;
[email protected]78192082011-01-29 05:43:44283using autofill::AutoFillAgent;
284using autofill::FormManager;
[email protected]c4a9e932011-03-05 04:05:55285using autofill::PasswordAutofillManager;
[email protected]6fdd4182010-10-14 23:59:26286using base::Time;
287using base::TimeDelta;
288using webkit_glue::AltErrorPageResourceFetcher;
289using webkit_glue::FormData;
290using webkit_glue::FormField;
291using webkit_glue::ImageResourceFetcher;
292using webkit_glue::PasswordForm;
293using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23294using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26295using webkit_glue::SiteIsolationMetrics;
296using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33297
initial.commit09911bf2008-07-26 23:55:29298//-----------------------------------------------------------------------------
299
[email protected]3354d3e2010-06-10 19:53:02300typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49301static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02302
initial.commit09911bf2008-07-26 23:55:29303// define to write the time necessary for thumbnail/DOM text retrieval,
304// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29305// #define TIME_TEXT_RETRIEVAL
306
307// maximum number of characters in the document to index, any text beyond this
308// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57309static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29310
311// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37312static const int kThumbnailWidth = 212;
313static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29314
315// Delay in milliseconds that we'll wait before capturing the page contents
316// and thumbnail.
317static const int kDelayForCaptureMs = 500;
318
319// Typically, we capture the page data once the page is loaded.
320// Sometimes, the page never finishes to load, preventing the page capture
321// To workaround this problem, we always perform a capture after the following
322// delay.
323static const int kDelayForForcedCaptureMs = 6000;
324
[email protected]882daa92009-11-05 16:31:31325// Time, in seconds, we delay before sending content state changes (such as form
326// state and scroll position) to the browser. We delay sending changes to avoid
327// spamming the browser.
328// To avoid having tab/session restore require sending a message to get the
329// current content state during tab closing we use a shorter timeout for the
330// foreground renderer. This means there is a small window of time from which
331// content state is modified and not sent to session restore, but this is
332// better than having to wake up all renderers during shutdown.
333static const int kDelaySecondsForContentStateSyncHidden = 5;
334static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29335
[email protected]0aa55312008-10-17 21:53:08336// The maximum number of popups that can be spawned from one page.
337static const int kMaximumNumberOfUnacknowledgedPopups = 25;
338
[email protected]6fdd4182010-10-14 23:59:26339static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35340
[email protected]726985e22009-06-18 21:09:28341static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
342 WebVector<WebURL> urls;
343 ds->redirectChain(urls);
344 result->reserve(urls.size());
345 for (size_t i = 0; i < urls.size(); ++i)
346 result->push_back(urls[i]);
347}
348
[email protected]30507922010-01-15 16:48:23349static bool PaintViewIntoCanvas(WebView* view,
350 skia::PlatformCanvas& canvas) {
351 view->layout();
352 const WebSize& size = view->size();
353
354 if (!canvas.initialize(size.width, size.height, true))
355 return false;
356
357 view->paint(webkit_glue::ToWebCanvas(&canvas),
358 WebRect(0, 0, size.width, size.height));
359 // TODO: Add a way to snapshot the whole page, not just the currently
360 // visible part.
361
362 return true;
363}
364
365// Calculates how "boring" a thumbnail is. The boring score is the
366// 0,1 ranged percentage of pixels that are the most common
367// luma. Higher boring scores indicate that a higher percentage of a
368// bitmap are all the same brightness.
369static double CalculateBoringScore(SkBitmap* bitmap) {
370 int histogram[256] = {0};
371 color_utils::BuildLumaHistogram(bitmap, histogram);
372
373 int color_count = *std::max_element(histogram, histogram + 256);
374 int pixel_count = bitmap->width() * bitmap->height();
375 return static_cast<double>(color_count) / pixel_count;
376}
377
[email protected]12bc8472010-04-15 07:29:40378// True if |frame| contains content that is white-listed for content settings.
379static bool IsWhitelistedForContentSettings(WebFrame* frame) {
380 WebSecurityOrigin origin = frame->securityOrigin();
381 if (origin.isEmpty())
382 return false; // Uninitialized document?
383
384 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
385 return true; // Browser UI elements should still work.
386
387 // If the scheme is ftp: or file:, an empty file name indicates a directory
388 // listing, which requires JavaScript to function properly.
389 GURL frame_url = frame->url();
390 const char* kDirProtocols[] = { "ftp", "file" };
391 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
392 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
393 return frame_url.SchemeIs(kDirProtocols[i]) &&
394 frame_url.ExtractFileName().empty();
395 }
396 }
397
398 return false;
399}
400
[email protected]3a8eecb2010-04-22 23:56:30401// Returns true if the frame is navigating to an URL either into or out of an
402// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04403// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
[email protected]88c15e972011-02-05 04:19:53404// we would enter an extension app's extent from a non-app, or if we leave an
405// extension with no web extent. We avoid swapping processes to exit a hosted
406// app with a web extent for now, since we do not yet restore context (such
[email protected]08e94b82010-12-15 22:51:04407// as window.opener) if the window navigates back.
[email protected]88c15e972011-02-05 04:19:53408static bool CrossesExtensionExtents(const ExtensionSet* extensions,
409 WebFrame* frame,
410 const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30411 // If the URL is still empty, this is a window.open navigation. Check the
412 // opener's URL.
413 GURL old_url(frame->url());
414 if (old_url.is_empty() && frame->opener())
415 old_url = frame->opener()->url();
416
[email protected]88c15e972011-02-05 04:19:53417 bool old_url_is_hosted_app = extensions->GetByURL(old_url) &&
418 !extensions->GetByURL(old_url)->web_extent().is_empty();
[email protected]2a521c52011-01-26 18:45:21419 return !extensions->InSameExtent(old_url, new_url) &&
[email protected]88c15e972011-02-05 04:19:53420 !old_url_is_hosted_app;
[email protected]3a8eecb2010-04-22 23:56:30421}
422
[email protected]3354d3e2010-06-10 19:53:02423// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
424// if it failed.
[email protected]e5106202010-06-11 21:12:36425static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17426 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02427 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08428 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02429 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02430 Language cld_language =
[email protected]e5106202010-06-11 21:12:36431 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08432 &num_languages, NULL, &text_bytes);
433 // We don't trust the result if the CLD reports that the detection is not
434 // reliable, or if the actual text used to detect the language was less than
435 // 100 bytes (short texts can often lead to wrong results).
436 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02437 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
438 // We should not use LanguageCode_ISO_639_1 because it does not cover all
439 // the languages CLD can detect. As a result, it'll return the invalid
440 // language code for tradtional Chinese among others.
441 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
442 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
443 // for Simplified Chinese.
444 language = LanguageCodeWithDialects(cld_language);
445 }
446 return language;
447}
448
[email protected]9b66f34bf2010-10-27 20:45:51449// Returns true if the parameter node is a textfield, text area or a content
450// editable div.
451static bool IsEditableNode(const WebNode& node) {
452 bool is_editable_node = false;
453 if (!node.isNull()) {
454 if (node.isContentEditable()) {
455 is_editable_node = true;
456 } else if (node.isElementNode()) {
457 is_editable_node =
458 node.toConst<WebElement>().isTextFormControlElement();
459 }
460 }
461 return is_editable_node;
462}
463
[email protected]54ec7f82010-10-21 22:32:51464static bool WebAccessibilityNotificationToViewHostMsg(
465 WebAccessibilityNotification notification,
466 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
467 switch (notification) {
468 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
469 *type = ViewHostMsg_AccessibilityNotification_Params::
470 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
471 break;
472 case WebKit::WebAccessibilityNotificationChildrenChanged:
473 *type = ViewHostMsg_AccessibilityNotification_Params::
474 NOTIFICATION_TYPE_CHILDREN_CHANGED;
475 break;
476 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
477 *type = ViewHostMsg_AccessibilityNotification_Params::
478 NOTIFICATION_TYPE_FOCUS_CHANGED;
479 break;
480 case WebKit::WebAccessibilityNotificationLoadComplete:
481 *type = ViewHostMsg_AccessibilityNotification_Params::
482 NOTIFICATION_TYPE_LOAD_COMPLETE;
483 break;
484 case WebKit::WebAccessibilityNotificationValueChanged:
485 *type = ViewHostMsg_AccessibilityNotification_Params::
486 NOTIFICATION_TYPE_VALUE_CHANGED;
487 break;
488 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
489 *type = ViewHostMsg_AccessibilityNotification_Params::
490 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
491 break;
492 default:
493 // TODO(ctguil): Support additional webkit notifications.
494 return false;
495 }
496 return true;
497}
498
[email protected]81f9fe0b2010-12-07 00:35:29499// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
500// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
[email protected]fb534c92011-02-01 01:02:07501// being TYPE_DOUBLEs. Dates are converted to a string (which can then be
502// parsed into a base::Time), as are regexps. Arrays are converted into lists,
[email protected]81f9fe0b2010-12-07 00:35:29503// recursively. We don't deal with binary objects or functions - they become
504// null values.
505static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
506 if (v8value->IsBoolean()) {
507 return Value::CreateBooleanValue(v8value->BooleanValue());
508 } else if (v8value->IsInt32()) {
509 return Value::CreateIntegerValue(v8value->Int32Value());
510 } else if (v8value->IsNumber()) {
[email protected]fb534c92011-02-01 01:02:07511 return Value::CreateDoubleValue(v8value->NumberValue());
[email protected]81f9fe0b2010-12-07 00:35:29512 } else if (v8value->IsString()) {
513 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
514 } else if (v8value->IsDate()) {
515 v8::Date* date = v8::Date::Cast(*v8value);
[email protected]fb534c92011-02-01 01:02:07516 return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
[email protected]81f9fe0b2010-12-07 00:35:29517 } else if (v8value->IsRegExp()) {
518 return Value::CreateStringValue(
519 *v8::String::Utf8Value(v8value->ToString()));
520 } else if (v8value->IsArray()) {
521 v8::Array* array = v8::Array::Cast(*v8value);
522 uint32_t length = array->Length();
523 scoped_ptr<ListValue> list(new ListValue);
524 for (uint32_t i = 0 ; i < length ; ++i) {
525 list->Set(i, ConvertV8Value(array->Get(i)));
526 }
527 return list.release();
528 }
529 return Value::CreateNullValue();
530}
531
initial.commit09911bf2008-07-26 23:55:29532///////////////////////////////////////////////////////////////////////////////
533
[email protected]60c42a8c72009-10-09 04:08:59534int32 RenderView::next_page_id_ = 1;
535
[email protected]cdaf8d02010-03-30 19:52:47536struct RenderView::PendingFileChooser {
537 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
538 WebFileChooserCompletion* c)
539 : params(p),
540 completion(c) {
541 }
542 ViewHostMsg_RunFileChooser_Params params;
543 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
544};
545
[email protected]2fab253a2009-08-17 23:00:59546RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51547 gfx::NativeViewId parent_hwnd,
548 int32 opener_id,
549 const RendererPreferences& renderer_prefs,
550 const WebPreferences& webkit_prefs,
551 SharedRenderViewCounter* counter,
552 int32 routing_id,
553 int64 session_storage_namespace_id,
554 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12555 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51556 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02557 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09558 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02559 send_preferred_size_changes_(false),
560 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24561 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21562 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02563 opened_by_user_gesture_(true),
564 opener_suppressed_(false),
[email protected]987d51af2011-02-24 17:50:18565 is_prerendering_(false),
[email protected]81a34412009-01-05 19:17:24566 page_id_(-1),
567 last_page_id_sent_to_browser_(-1),
568 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00569 history_list_offset_(-1),
570 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24571 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55572#if defined(OS_MACOSX)
573 has_document_tag_(false),
574#endif
[email protected]98324892009-09-09 21:16:05575 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02576 target_url_status_(TARGET_NONE),
577 spelling_panel_visible_(false),
578 view_type_(ViewType::INVALID),
579 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18580 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30581 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51582 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02583 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51584 devtools_client_(NULL),
585 geolocation_dispatcher_(NULL),
586 speech_input_dispatcher_(NULL),
587 device_orientation_dispatcher_(NULL),
[email protected]dec1f292011-02-11 20:20:20588 print_helper_(NULL),
[email protected]6c2f73202011-02-14 20:21:54589 searchbox_(NULL),
[email protected]5efcef62011-02-22 09:00:13590 spellcheck_provider_(NULL),
[email protected]54ec7f82010-10-21 22:32:51591 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18592 p2p_socket_dispatcher_(NULL),
[email protected]bb461532010-11-26 21:50:23593 pending_app_icon_requests_(0),
[email protected]5ee0cfd02011-01-18 05:42:22594 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]8de12d942010-11-17 20:42:44595#if defined(OS_MACOSX)
596 // On Mac, the select popups are rendered by the browser.
597 // Note that we don't do this in RenderMain otherwise this would not be called
598 // in single-process mode.
599 WebKit::WebView::setUseExternalPopupMenus(true);
600#endif
[email protected]676126f72011-01-15 00:03:51601
[email protected]71b0d5d2010-02-15 05:43:07602 ClearBlockedContentSettings();
[email protected]676126f72011-01-15 00:03:51603
604 routing_id_ = routing_id;
605 if (opener_id != MSG_ROUTING_NONE)
606 opener_id_ = opener_id;
607
608 if (counter) {
609 shared_popup_counter_ = counter;
610 shared_popup_counter_->data++;
611 decrement_shared_popup_at_destruction_ = true;
612 } else {
613 shared_popup_counter_ = new SharedRenderViewCounter(0);
614 decrement_shared_popup_at_destruction_ = false;
615 }
616
617 notification_provider_ = new NotificationProvider(this);
618
619 devtools_agent_ = new DevToolsAgent(this);
[email protected]c4a9e932011-03-05 04:05:55620 PasswordAutofillManager* password_autofill_manager =
621 new PasswordAutofillManager(this);
[email protected]78192082011-01-29 05:43:44622 AutoFillAgent* autofill_agent = new AutoFillAgent(this,
623 password_autofill_manager);
[email protected]676126f72011-01-15 00:03:51624
[email protected]78192082011-01-29 05:43:44625 webwidget_ = WebView::create(this, devtools_agent_, autofill_agent);
[email protected]676126f72011-01-15 00:03:51626 g_view_map.Get().insert(std::make_pair(webview(), this));
627 webkit_preferences_.Apply(webview());
628 webview()->initializeMainFrame(this);
629 if (!frame_name.empty())
630 webview()->mainFrame()->setName(frame_name);
[email protected]1ee59cb2011-02-23 02:45:51631 webview()->settings()->setMinimumTimerInterval(
632 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
633 webkit_glue::kForegroundTabTimerInterval);
[email protected]676126f72011-01-15 00:03:51634
635 OnSetRendererPrefs(renderer_prefs);
636
637 render_thread_->AddRoute(routing_id_, this);
638 // Take a reference on behalf of the RenderThread. This will be balanced
639 // when we receive ViewMsg_Close.
640 AddRef();
641
642 // If this is a popup, we must wait for the CreatingNew_ACK message before
643 // completing initialization. Otherwise, we can finish it now.
644 if (opener_id == MSG_ROUTING_NONE) {
645 did_show_ = true;
646 CompleteInit(parent_hwnd);
647 }
648
649 host_window_ = parent_hwnd;
650
651 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
652 if (command_line.HasSwitch(switches::kDomAutomationController))
653 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
654 if (command_line.HasSwitch(switches::kEnableAccessibility))
655 WebAccessibilityCache::enableAccessibility();
656
657 audio_message_filter_ = new AudioMessageFilter(routing_id_);
658 render_thread_->AddFilter(audio_message_filter_);
659
660 PageClickTracker* page_click_tracker = new PageClickTracker(this);
661 // Note that the order of insertion of the listeners is important.
662 // The password_autocomplete_manager takes the first shot at processing the
663 // notification and can stop the propagation.
[email protected]78192082011-01-29 05:43:44664 page_click_tracker->AddListener(password_autofill_manager);
665 page_click_tracker->AddListener(autofill_agent);
[email protected]81273622011-02-02 03:56:13666 new TranslateHelper(this);
[email protected]dec1f292011-02-11 20:20:20667 print_helper_ = new PrintWebViewHelper(this);
[email protected]6c2f73202011-02-14 20:21:54668 searchbox_ = new SearchBox(this);
[email protected]28685da92011-02-07 21:49:17669
[email protected]5efcef62011-02-22 09:00:13670 RenderThread* current_thread = RenderThread::current();
671 SpellCheck* spellcheck = current_thread ? current_thread->spellchecker() : 0;
672 spellcheck_provider_ = new SpellCheckProvider(this, spellcheck);
673
[email protected]28685da92011-02-07 21:49:17674 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]cae8c8492011-03-03 11:12:18675 switches::kEnableP2PApi)) {
676 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
677 }
678
679 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]28685da92011-02-07 21:49:17680 switches::kEnableClientSidePhishingDetection)) {
681 new safe_browsing::PhishingClassifierDelegate(this, NULL);
682 }
[email protected]32ca14682011-02-16 19:05:10683
684 // Observer for Malware DOM details messages.
685 new safe_browsing::MalwareDOMDetails(this);
initial.commit09911bf2008-07-26 23:55:29686}
687
688RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08689 if (decrement_shared_popup_at_destruction_)
690 shared_popup_counter_->data--;
691
[email protected]a1128322009-10-06 18:38:46692 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47693 while (!file_chooser_completions_.empty()) {
694 if (file_chooser_completions_.front()->completion) {
695 file_chooser_completions_.front()->completion->didChooseFile(
696 WebVector<WebString>());
697 }
698 file_chooser_completions_.pop_front();
699 }
[email protected]a1128322009-10-06 18:38:46700
[email protected]83dde542009-09-11 20:59:55701#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05702 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55703 if (has_document_tag_)
704 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11705
706 // Destroy all fake plugin window handles on the browser side.
707 while (!fake_plugin_window_handles_.empty()) {
708 // Make sure no NULL plugin window handles were inserted into this list.
709 DCHECK(*fake_plugin_window_handles_.begin());
710 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
711 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
712 }
[email protected]83dde542009-09-11 20:59:55713#endif
[email protected]98324892009-09-09 21:16:05714
[email protected]5fb88962009-04-16 19:03:25715 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59716
717#ifndef NDEBUG
718 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49719 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59720 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
721 DCHECK_NE(this, it->second) << "Failed to call Close?";
722#endif
[email protected]676126f72011-01-15 00:03:51723
724 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
725 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59726}
727
728/*static*/
729void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49730 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59731 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
732 if (!visitor->Visit(it->second))
733 return;
734 }
735}
736
737/*static*/
738RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49739 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59740 ViewMap::iterator it = views->find(webview);
741 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29742}
743
744/*static*/
[email protected]0aa55312008-10-17 21:53:08745RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24746 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15747 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08748 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51749 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08750 const WebPreferences& webkit_prefs,
751 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34752 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26753 int64 session_storage_namespace_id,
754 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29755 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51756 return new RenderView(
757 render_thread,
758 parent_hwnd,
759 opener_id,
760 renderer_prefs,
761 webkit_prefs,
762 counter,
763 routing_id,
764 session_storage_namespace_id,
765 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29766}
767
[email protected]bb461532010-11-26 21:50:23768// static
initial.commit09911bf2008-07-26 23:55:29769void RenderView::SetNextPageID(int32 next_page_id) {
770 // This method should only be called during process startup, and the given
771 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05772 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29773 DCHECK(next_page_id >= next_page_id_);
774 next_page_id_ = next_page_id;
775}
776
[email protected]676126f72011-01-15 00:03:51777void RenderView::AddObserver(RenderViewObserver* observer) {
778 observers_.AddObserver(observer);
779}
780
781void RenderView::RemoveObserver(RenderViewObserver* observer) {
782 observer->set_render_view(NULL);
783 observers_.RemoveObserver(observer);
784}
785
[email protected]70eee342010-11-05 01:59:37786bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
787 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36788 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
789 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37790 return true;
791 }
792 return false;
793}
794
[email protected]8a3125a712010-08-09 18:58:51795WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26796 return static_cast<WebKit::WebView*>(webwidget());
797}
798
[email protected]afe3a1672009-11-17 19:04:12799void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50800 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56801}
802
[email protected]bb461532010-11-26 21:50:23803bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
804 string16* error) {
805 // There is an issue of drive-by installs with the below implementation. A web
806 // site could force a user to install an app by timing the dialog to come up
807 // just before the user clicks.
808 //
809 // We do show a success UI that allows users to uninstall, but it seems that
810 // we might still want to put up an infobar before showing the install dialog.
811 //
812 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
813 // switch.
814 if (!CommandLine::ForCurrentProcess()->HasSwitch(
815 switches::kEnableCrxlessWebApps)) {
816 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
817 return false;
818 }
819
820 if (frame != frame->top()) {
821 *error = ASCIIToUTF16("Applications can only be installed from the top "
822 "frame.");
823 return false;
824 }
825
826 if (pending_app_info_.get()) {
827 *error = ASCIIToUTF16("An application install is already in progress.");
828 return false;
829 }
830
831 pending_app_info_.reset(new WebApplicationInfo());
832 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
833 error)) {
834 return false;
835 }
836
837 if (!pending_app_info_->manifest_url.is_valid()) {
838 *error = ASCIIToUTF16("Web application definition not found or invalid.");
839 return false;
840 }
841
842 app_definition_fetcher_.reset(new ResourceFetcher(
843 pending_app_info_->manifest_url, webview()->mainFrame(),
844 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
845 return true;
846}
847
[email protected]1a3c3cb2010-12-16 21:03:40848void RenderView::SetReportLoadProgressEnabled(bool enabled) {
849 if (!enabled) {
850 load_progress_tracker_.reset(NULL);
851 return;
852 }
853 if (load_progress_tracker_ == NULL)
854 load_progress_tracker_.reset(new LoadProgressTracker(this));
855}
856
[email protected]bb461532010-11-26 21:50:23857void RenderView::DidDownloadApplicationDefinition(
858 const WebKit::WebURLResponse& response,
859 const std::string& data) {
860 scoped_ptr<WebApplicationInfo> app_info(
861 pending_app_info_.release());
862
863 JSONStringValueSerializer serializer(data);
864 int error_code = 0;
865 std::string error_message;
866 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
867 if (!result.get()) {
868 AddErrorToRootConsole(UTF8ToUTF16(error_message));
869 return;
870 }
871
872 string16 error_message_16;
873 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
874 &error_message_16)) {
875 AddErrorToRootConsole(error_message_16);
876 return;
877 }
878
879 if (!app_info->icons.empty()) {
880 pending_app_info_.reset(app_info.release());
881 pending_app_icon_requests_ =
882 static_cast<int>(pending_app_info_->icons.size());
883 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
884 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
885 new ImageResourceFetcher(
886 pending_app_info_->icons[i].url,
887 webview()->mainFrame(),
888 static_cast<int>(i),
889 pending_app_info_->icons[i].width,
890 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
891 }
892 } else {
893 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
894 }
895}
896
897void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
898 const SkBitmap& image) {
899 pending_app_info_->icons[fetcher->id()].data = image;
900
901 // Remove the image fetcher from our pending list. We're in the callback from
902 // ImageResourceFetcher, best to delay deletion.
903 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
904 iter != app_icon_fetchers_.end(); ++iter) {
905 if (iter->get() == fetcher) {
906 iter->release();
907 app_icon_fetchers_.erase(iter);
908 break;
909 }
910 }
911
912 // We're in the callback from the ImageResourceFetcher, best to delay
913 // deletion.
914 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
915
916 if (--pending_app_icon_requests_ > 0)
917 return;
918
919 // There is a maximum size of IPC on OS X and Linux that we have run into in
920 // some situations. We're not sure what it is, but our hypothesis is in the
921 // neighborhood of 1 MB.
922 //
923 // To be on the safe side, we give ourselves 128 KB for just the image data.
924 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
925 // want to start allowing larger icons (see bug 63406), we'll have to either
926 // experiment mor ewith this and find the real limit, or else come up with
927 // some alternative way to transmit the icon data to the browser process.
928 //
929 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32930 const size_t kMaxIconSize = 1024 * 128;
931 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23932 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32933 size_t current_size = pending_app_info_->icons[i].data.getSize();
934 if (current_size > kMaxIconSize - actual_icon_size) {
935 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23936 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32937 return;
938 }
939 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23940 }
941
942 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
943 pending_app_info_.reset(NULL);
944}
945
[email protected]a3a8fb6d2009-10-22 20:12:51946void RenderView::PluginCrashed(const FilePath& plugin_path) {
947 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29948}
949
[email protected]aad51d1c2010-08-05 08:38:09950WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
951 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50952 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26953 bool found;
954 ContentSetting setting;
955 std::string mime_type;
956 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17957 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
958 &found, &info, &setting, &mime_type));
[email protected]b83ff222011-01-24 17:37:12959 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09960 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45961
[email protected]0bd753682010-12-16 18:15:52962 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45963 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09964 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26965 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45966 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09967}
968
[email protected]d8fd6fa2010-02-01 15:54:26969void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
970 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30971 // If the renderer is visible, set initial visibility and focus state.
972 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34973#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30974 delegate->SetContainerVisibility(true);
975 if (webview() && webview()->isActive())
976 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34977#endif
[email protected]49232292010-09-03 19:07:30978 }
[email protected]784ea1ab2010-09-18 00:02:34979 // Plugins start assuming the content has focus (so that they work in
980 // environments where RenderView isn't hosting them), so we always have to
981 // set the initial state. See webplugin_delegate_impl.h for details.
982 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26983}
984
985void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
986 plugin_delegates_.erase(delegate);
987}
[email protected]d8fd6fa2010-02-01 15:54:26988
[email protected]a95986a82010-12-24 06:19:28989bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27990 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27991 if (main_frame)
992 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26993
[email protected]676126f72011-01-15 00:03:51994 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
995 RenderViewObserver* observer;
996 while ((observer = it.GetNext()) != NULL)
997 if (observer->OnMessageReceived(message))
998 return true;
[email protected]b2abac72009-02-26 12:39:28999
[email protected]a95986a82010-12-24 06:19:281000 bool handled = true;
initial.commit09911bf2008-07-26 23:55:291001 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:041002 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
1003 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:291004 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
1005 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:561006 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:291007 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
1008 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
1009 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
1010 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:271011#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351012 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:271013#endif
initial.commit09911bf2008-07-26 23:55:291014 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
1015 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:051016 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
1017 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
1018 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:041019 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:291020 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
1021 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
1022 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:151023 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:291024 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491025 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1026 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171027 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541028 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1029 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171030 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541031 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1032 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291033 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181034 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1035 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281036 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]d8e74e82011-03-15 19:38:481037 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavicon, OnDownloadFavicon)
initial.commit09911bf2008-07-26 23:55:291038 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481039 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291040 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291041 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291042 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1043 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1044 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1045 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451046 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:401047 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
[email protected]266eb6f2008-09-30 23:56:501048 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1049 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291050 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1051 OnDragSourceSystemDragEnded)
1052 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511053 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1054 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291055 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1056 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1057 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1058 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]90dba072011-01-20 20:10:201059 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1060 OnDisplayPrerenderedPage)
initial.commit09911bf2008-07-26 23:55:291061 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1062 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291063 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1064 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041065 IPC_MESSAGE_HANDLER(
1066 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1067 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291068 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041069 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291070 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1071 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451072 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041073 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081074 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1075 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401076 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1077 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001078 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271079 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371080 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1081 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161082 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141083 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251084 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1085 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:101086 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1087 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511088 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531089 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1090 OnUpdateBrowserWindowId)
1091 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1092 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561093 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341094 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141095#if defined(OS_MACOSX)
1096 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131097 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131098 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1099 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141100#endif
[email protected]446705872009-09-10 07:22:481101 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331102 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351103 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1104 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331105 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1106 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:141107 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361108 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1109 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1110 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421111 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1112 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241113 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]caf706f2010-10-26 17:54:081114#if defined(OS_MACOSX)
1115 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1116#endif
[email protected]a6097f42011-01-10 08:50:511117 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1118 OnJavaScriptStressTestControl)
[email protected]521b2482011-01-15 00:10:101119 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]232a5812011-03-04 22:42:081120 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]634a6f92008-12-01 21:39:311121
[email protected]f0557932011-01-25 20:20:511122 // TODO(viettrungluu): Move to a separate message filter.
1123#if defined(ENABLE_FLAPPER_HACKS)
1124 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
1125#endif
1126
initial.commit09911bf2008-07-26 23:55:291127 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281128 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291129 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281130 return handled;
initial.commit09911bf2008-07-26 23:55:291131}
1132
[email protected]9b18a84f2010-06-10 15:54:041133void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271134 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291135 if (!main_frame)
1136 return;
1137
1138 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451139 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291140 if (url.is_empty())
1141 return;
1142
1143 if (size_.IsEmpty())
1144 return; // Don't create an empty thumbnail!
1145
1146 ThumbnailScore score;
1147 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021148 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151149 &thumbnail, &score))
1150 return;
1151
initial.commit09911bf2008-07-26 23:55:291152 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461153 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291154}
1155
[email protected]9b18a84f2010-06-10 15:54:041156void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231157 SkBitmap snapshot;
1158 bool error = false;
1159
1160 WebFrame* main_frame = webview()->mainFrame();
1161 if (!main_frame)
1162 error = true;
1163
1164 if (!error && !CaptureSnapshot(webview(), &snapshot))
1165 error = true;
1166
1167 DCHECK(error == snapshot.empty()) <<
1168 "Snapshot should be empty on error, non-empty otherwise.";
1169
1170 // Send the snapshot to the browser process.
1171 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1172}
1173
initial.commit09911bf2008-07-26 23:55:291174void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1175 if (load_id != page_id_)
1176 return; // this capture call is no longer relevant due to navigation
1177 if (load_id == last_indexed_page_id_)
1178 return; // we already indexed this page
1179
1180 if (!webview())
1181 return;
1182
[email protected]26aa0482009-09-30 16:55:271183 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291184 if (!main_frame)
1185 return;
1186
1187 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451188 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291189 return;
1190
1191 // Don't index/capture pages that failed to load. This only checks the top
1192 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451193 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281194 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291195 return;
1196
1197 if (!preliminary_capture)
1198 last_indexed_page_id_ = load_id;
1199
[email protected]a8a81292010-01-21 00:32:451200 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451201 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291202 if (url.is_empty())
1203 return;
1204
[email protected]a8a81292010-01-21 00:32:451205 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361206 string16 contents;
initial.commit09911bf2008-07-26 23:55:291207 CaptureText(main_frame, &contents);
1208 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101209 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371210 // If the page explicitly specifies a language, use it, otherwise we'll
1211 // determine it based on the text content using the CLD.
1212 std::string language =
1213 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1214 if (language.empty()) {
1215 base::TimeTicks begin_time = base::TimeTicks::Now();
1216 language = DetermineTextLanguage(contents);
1217 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1218 base::TimeTicks::Now() - begin_time);
1219 }
[email protected]a8a81292010-01-21 00:32:451220 // Send the text to the browser for indexing (the browser might decide not
1221 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371222 Send(new ViewHostMsg_PageContents(
1223 routing_id_, url, load_id, contents, language,
1224 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271225 }
1226
[email protected]d54169e92011-01-21 09:19:521227 // Generate the thumbnail here if the in-browser thumbnailing isn't
1228 // enabled. TODO(satorux): Remove this and related code once
1229 // crbug.com/65936 is complete.
1230 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1231 switches::kEnableInBrowserThumbnailing)) {
1232 OnCaptureThumbnail();
1233 }
[email protected]3ead1322010-11-19 20:01:001234
[email protected]28685da92011-02-07 21:49:171235 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PageCaptured(contents));
initial.commit09911bf2008-07-26 23:55:291236}
1237
[email protected]e5106202010-06-11 21:12:361238void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291239 contents->clear();
1240 if (!frame)
1241 return;
1242
1243#ifdef TIME_TEXT_RETRIEVAL
1244 double begin = time_util::GetHighResolutionTimeNow();
1245#endif
1246
1247 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361248 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291249
1250#ifdef TIME_TEXT_RETRIEVAL
1251 double end = time_util::GetHighResolutionTimeNow();
1252 char buf[128];
1253 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1254 contents.size(), (end - begin)*1000);
1255 OutputDebugStringA(buf);
1256#endif
1257
1258 // When the contents are clipped to the maximum, we don't want to have a
1259 // partial word indexed at the end that might have been clipped. Therefore,
1260 // terminate the string at the last space to ensure no words are clipped.
1261 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361262 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291263 if (last_space_index == std::wstring::npos)
1264 return; // don't index if we got a huge block of text with no spaces
1265 contents->resize(last_space_index);
1266 }
1267}
1268
[email protected]8649fb32009-06-26 17:51:021269bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291270 int w,
1271 int h,
1272 SkBitmap* thumbnail,
1273 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231274 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151275
[email protected]8649fb32009-06-26 17:51:021276 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231277
1278 // Paint |view| into |canvas|.
1279 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021280 return false;
[email protected]8649fb32009-06-26 17:51:021281
1282 skia::BitmapPlatformDevice& device =
1283 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1284
1285 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291286
[email protected]cab34d6a2009-09-24 01:14:521287 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291288 float dest_aspect = dest_rect.width() / dest_rect.height();
1289
1290 // Get the src rect so that we can preserve the aspect ratio while filling
1291 // the destination.
1292 SkIRect src_rect;
1293 if (src_bmp.width() < dest_rect.width() ||
1294 src_bmp.height() < dest_rect.height()) {
1295 // Source image is smaller: we clip the part of source image within the
1296 // dest rect, and then stretch it to fill the dest rect. We don't respect
1297 // the aspect ratio in this case.
1298 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1299 static_cast<S16CPU>(dest_rect.height()));
1300 score->good_clipping = false;
1301 } else {
1302 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1303 if (src_aspect > dest_aspect) {
1304 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1305 // the wider screen.
1306 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1307 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1308 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1309 score->good_clipping = false;
1310 } else {
1311 src_rect.set(0, 0, src_bmp.width(),
1312 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1313 score->good_clipping = true;
1314 }
1315 }
1316
[email protected]26aa0482009-09-30 16:55:271317 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291318
1319 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021320 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291321
[email protected]82afe4b2010-11-12 20:36:221322 // First do a fast downsample by powers of two to get close to the final size.
1323 SkBitmap downsampled_subset =
1324 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1325
1326 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141327 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221328 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291329
1330 score->boring_score = CalculateBoringScore(thumbnail);
1331
[email protected]30507922010-01-15 16:48:231332 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1333 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221334
[email protected]b6e4bec2008-11-12 01:17:151335 return true;
initial.commit09911bf2008-07-26 23:55:291336}
1337
[email protected]30507922010-01-15 16:48:231338bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1339 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291340
[email protected]30507922010-01-15 16:48:231341 skia::PlatformCanvas canvas;
1342 if (!PaintViewIntoCanvas(view, canvas))
1343 return false;
1344
1345 skia::BitmapPlatformDevice& device =
1346 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1347
1348 const SkBitmap& bitmap = device.accessBitmap(false);
1349 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1350 return false;
1351
1352 HISTOGRAM_TIMES("Renderer4.Snapshot",
1353 base::TimeTicks::Now() - beginning_time);
1354 return true;
initial.commit09911bf2008-07-26 23:55:291355}
1356
1357void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1358 if (!webview())
1359 return;
1360
[email protected]3cc72b12010-03-18 23:03:001361 history_list_offset_ = params.current_history_list_offset;
1362 history_list_length_ = params.current_history_list_length;
1363
[email protected]a9f607e2009-10-23 19:59:271364 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261365
initial.commit09911bf2008-07-26 23:55:291366 AboutHandler::MaybeHandle(params.url);
1367
[email protected]ecbf10d2010-02-18 13:03:291368 bool is_reload =
1369 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1370 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291371
[email protected]26aa0482009-09-30 16:55:271372 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451373 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291374 // We cannot reload if we do not have any history state. This happens, for
1375 // example, when recovering from a crash. Our workaround here is a bit of
1376 // a hack since it means that reload after a crashed tab does not cause an
1377 // end-to-end cache validation.
1378 is_reload = false;
1379 }
1380
[email protected]77f17a82009-05-21 04:42:541381 // A navigation resulting from loading a javascript URL should not be treated
1382 // as a browser initiated event. Instead, we want it to look as if the page
1383 // initiated any load resulting from JS execution.
1384 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301385 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001386 params.page_id,
1387 params.pending_history_list_offset,
1388 params.transition,
1389 params.request_time);
[email protected]5e369672009-11-03 23:48:301390 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1391 // We're doing a load of a page that was restored from the last session.
1392 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1393 // which can result in stale data for pages that are set to expire. We
1394 // explicitly override that by setting the policy here so that as
1395 // necessary we load from the network.
1396 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1397 }
1398 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541399 }
initial.commit09911bf2008-07-26 23:55:291400
[email protected]a7ccc4d2010-01-27 08:14:481401 NavigationState* navigation_state = pending_navigation_state_.get();
1402
[email protected]04d3c6e2009-05-22 17:00:131403 // If we are reloading, then WebKit will use the history state of the current
1404 // page, so we should just ignore any given history state. Otherwise, if we
1405 // have history state, then we need to navigate to it, which corresponds to a
1406 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551407 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481408 if (navigation_state)
1409 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291410 bool ignore_cache = (params.navigation_type ==
1411 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1412 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551413 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131414 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581415 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481416 if (navigation_state)
1417 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451418 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171419 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131420 } else {
1421 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281422 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291423
[email protected]e6f546c32009-07-01 17:12:551424 // A session history navigation should have been accompanied by state.
1425 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131426
[email protected]dd7daa82009-08-10 05:46:451427 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551428 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131429
[email protected]726985e22009-06-18 21:09:281430 if (params.referrer.is_valid()) {
1431 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1432 WebString::fromUTF8(params.referrer.spec()));
1433 }
[email protected]04d3c6e2009-05-22 17:00:131434
[email protected]52c68652010-12-07 17:47:041435 if (!params.extra_headers.empty()) {
1436 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1437 params.extra_headers.end(), "\n");
1438 i.GetNext(); ) {
1439 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1440 WebString::fromUTF8(i.values()));
1441 }
1442 }
1443
[email protected]90dba072011-01-20 20:10:201444 if (navigation_state) {
1445 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1446 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1447 } else {
1448 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
[email protected]987d51af2011-02-24 17:50:181449 is_prerendering_ = true;
[email protected]90dba072011-01-20 20:10:201450 }
1451 }
[email protected]dd7daa82009-08-10 05:46:451452 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501453 }
1454
[email protected]77f17a82009-05-21 04:42:541455 // In case LoadRequest failed before DidCreateDataSource was called.
1456 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291457}
1458
1459// Stop loading the current page
1460void RenderView::OnStop() {
1461 if (webview())
[email protected]b4bb2502009-10-01 22:35:271462 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291463}
1464
[email protected]ecbf10d2010-02-18 13:03:291465// Reload current focused frame.
1466// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561467void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291468 if (webview() && webview()->focusedFrame()) {
1469 // We always obey the cache (ignore_cache=false) here.
1470 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1471 // a cache-ignoring reload of the frame.
1472 webview()->focusedFrame()->reload(false);
1473 }
[email protected]1dda4022010-01-28 18:24:561474}
1475
initial.commit09911bf2008-07-26 23:55:291476void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271477 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291478}
1479
[email protected]68b1e922009-06-23 16:00:251480void RenderView::OnExecuteEditCommand(const std::string& name,
1481 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271482 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251483 return;
1484
[email protected]26aa0482009-09-30 16:55:271485 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451486 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251487}
1488
[email protected]b2abac72009-02-26 12:39:281489void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511490 DCHECK(!devtools_client_);
1491 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281492}
1493
initial.commit09911bf2008-07-26 23:55:291494void RenderView::OnUpdateTargetURLAck() {
1495 // Check if there is a targeturl waiting to be sent.
1496 if (target_url_status_ == TARGET_PENDING) {
1497 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1498 pending_target_url_));
1499 }
1500
1501 target_url_status_ = TARGET_NONE;
1502}
1503
1504void RenderView::OnUndo() {
1505 if (!webview())
1506 return;
1507
[email protected]26aa0482009-09-30 16:55:271508 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121509 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291510}
1511
1512void RenderView::OnRedo() {
1513 if (!webview())
1514 return;
1515
[email protected]26aa0482009-09-30 16:55:271516 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121517 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291518}
1519
1520void RenderView::OnCut() {
1521 if (!webview())
1522 return;
1523
[email protected]26aa0482009-09-30 16:55:271524 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121525 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291526}
1527
1528void RenderView::OnCopy() {
1529 if (!webview())
1530 return;
1531
[email protected]26aa0482009-09-30 16:55:271532 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121533 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291534}
1535
[email protected]c0cc3092009-09-12 08:27:271536#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351537void RenderView::OnCopyToFindPboard() {
1538 if (!webview())
1539 return;
1540
1541 // Since the find pasteboard supports only plain text, this can be simpler
1542 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271543 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351544 if (frame->hasSelection()) {
1545 string16 selection = frame->selectionAsText();
1546 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:171547 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351548 }
1549
[email protected]afe3a1672009-11-17 19:04:121550 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351551}
[email protected]c0cc3092009-09-12 08:27:271552#endif
[email protected]a954bf72009-09-12 07:30:351553
initial.commit09911bf2008-07-26 23:55:291554void RenderView::OnPaste() {
1555 if (!webview())
1556 return;
1557
[email protected]26aa0482009-09-30 16:55:271558 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121559 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291560}
1561
[email protected]2a3a7762009-10-19 19:17:321562void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291563 if (!webview())
1564 return;
1565
[email protected]1ff7a032010-02-03 02:46:031566 WebFrame* frame = webview()->focusedFrame();
1567 if (!frame->hasSelection())
1568 frame->selectWordAroundCaret();
1569 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291570}
1571
[email protected]98324892009-09-09 21:16:051572void RenderView::OnAdvanceToNextMisspelling() {
1573 if (!webview())
1574 return;
[email protected]26aa0482009-09-30 16:55:271575 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051576 WebString::fromUTF8("AdvanceToNextMisspelling"));
1577}
1578
1579void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1580 if (!webview())
1581 return;
1582 // We need to tell the webView whether the spelling panel is visible or not so
1583 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261584 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271585 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051586 WebString::fromUTF8("ToggleSpellPanel"));
1587}
1588
[email protected]bbbd545c2008-12-15 20:18:041589void RenderView::OnToggleSpellCheck() {
1590 if (!webview())
1591 return;
1592
[email protected]26aa0482009-09-30 16:55:271593 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451594 frame->enableContinuousSpellChecking(
1595 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041596}
1597
initial.commit09911bf2008-07-26 23:55:291598void RenderView::OnDelete() {
1599 if (!webview())
1600 return;
1601
[email protected]26aa0482009-09-30 16:55:271602 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121603 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291604}
1605
1606void RenderView::OnSelectAll() {
1607 if (!webview())
1608 return;
1609
[email protected]26aa0482009-09-30 16:55:271610 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221611 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121612 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291613}
1614
1615void RenderView::OnSetInitialFocus(bool reverse) {
1616 if (!webview())
1617 return;
[email protected]26aa0482009-09-30 16:55:271618 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291619}
1620
[email protected]9b66f34bf2010-10-27 20:45:511621void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091622 WebKit::WebNode node = GetFocusedNode();
1623 if (!node.isNull()) {
1624 if (IsEditableNode(node))
1625 // TODO(varunjain): Change webkit API to scroll a particular node into
1626 // view and use that API here instead.
1627 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511628 }
1629}
1630
initial.commit09911bf2008-07-26 23:55:291631///////////////////////////////////////////////////////////////////////////////
1632
[email protected]433819d2010-01-30 20:20:011633void RenderView::SetContentSettings(const ContentSettings& settings) {
1634 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011635}
1636
initial.commit09911bf2008-07-26 23:55:291637// Tell the embedding application that the URL of the active page has changed
1638void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451639 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291640 DCHECK(ds);
1641
[email protected]726985e22009-06-18 21:09:281642 const WebURLRequest& request = ds->request();
1643 const WebURLRequest& original_request = ds->originalRequest();
1644 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291645
[email protected]daa8c58e2009-06-15 17:21:101646 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1647 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291648
1649 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281650 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291651 params.is_post = false;
1652 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071653 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191654 params.socket_address.set_host(response.remoteIPAddress().utf8());
1655 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031656 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091657 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551658 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291659 // SSL state specified in the request takes precedence over the one in the
1660 // response.
1661 // So far this is only intended for error pages that are not expected to be
1662 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281663 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551664 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291665 } else {
[email protected]726985e22009-06-18 21:09:281666 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291667 }
1668
1669 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281670 if (ds->hasUnreachableURL()) {
1671 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291672 } else {
[email protected]726985e22009-06-18 21:09:281673 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291674 }
1675
[email protected]726985e22009-06-18 21:09:281676 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241677 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041678 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291679
[email protected]ce0e250d2009-10-23 21:00:351680 params.searchable_form_url = navigation_state->searchable_form_url();
1681 params.searchable_form_encoding =
1682 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291683
1684 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101685 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291686 if (password_form_data)
1687 params.password_form = *password_form_data;
1688
1689 params.gesture = navigation_gesture_;
1690 navigation_gesture_ = NavigationGestureUnknown;
1691
[email protected]0f38dc4552011-02-25 11:24:001692 // Make navigation state a part of the FrameNavigate message so that commited
1693 // entry had it at all times.
1694 const WebHistoryItem& item = frame->currentHistoryItem();
1695 if (!item.isNull()) {
1696 params.content_state = webkit_glue::HistoryItemToString(item);
1697 } else {
1698 params.content_state =
1699 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1700 }
1701
[email protected]dd7daa82009-08-10 05:46:451702 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291703 // Top-level navigation.
1704
[email protected]71b0d5d2010-02-15 05:43:071705 // Clear "block" flags for the new page. This needs to happen before any of
1706 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1707 // so that these functions can correctly detect that a piece of content
1708 // flipped from "not blocked" to "blocked".
1709 ClearBlockedContentSettings();
1710
[email protected]62d2a112010-04-07 00:53:021711 // Set content settings. Default them from the parent window if one exists.
1712 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011713 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541714 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011715 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011716 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011717
1718 // These content settings were merely recorded transiently for this load.
1719 // We can erase them now. If at some point we reload this page, the
1720 // browser will send us new, up-to-date content settings.
1721 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401722 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101723 // The opener's view is not guaranteed to be non-null (it could be
1724 // detached from its page but not yet destructed).
1725 if (WebView* opener_view = frame->opener()->view()) {
1726 RenderView* opener = FromWebView(opener_view);
1727 SetContentSettings(opener->current_content_settings_);
1728 }
[email protected]f85f0702010-01-30 09:31:011729 }
1730
[email protected]b75b8292010-10-01 07:28:251731 // Set zoom level, but don't do it for full-page plugin since they don't use
1732 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011733 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541734 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251735 if (webview()->mainFrame()->document().isPluginDocument()) {
1736 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251737 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251738 } else {
1739 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251740 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251741 }
1742
[email protected]f85f0702010-01-30 09:31:011743 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511744 // This zoom level was merely recorded transiently for this load. We can
1745 // erase it now. If at some point we reload this page, the browser will
1746 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011747 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511748 }
1749
[email protected]b75b8292010-10-01 07:28:251750 // Reset the zoom limits in case a plugin had changed them previously. This
1751 // will also call us back which will cause us to send a message to
1752 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251753 webview()->zoomLimitsChanged(
1754 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1755 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251756
initial.commit09911bf2008-07-26 23:55:291757 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551758 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291759
[email protected]daa8c58e2009-06-15 17:21:101760 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291761 if (!PageTransition::IsMainFrame(params.transition)) {
1762 // If the main frame does a load, it should not be reported as a subframe
1763 // navigation. This can occur in the following case:
1764 // 1. You're on a site with frames.
1765 // 2. You do a subframe navigation. This is stored with transition type
1766 // MANUAL_SUBFRAME.
1767 // 3. You navigate to some non-frame site, say, google.com.
1768 // 4. You navigate back to the page from step 2. Since it was initially
1769 // MANUAL_SUBFRAME, it will be that same transition type here.
1770 // We don't want that, because any navigation that changes the toplevel
1771 // frame should be tracked as a toplevel navigation (this allows us to
1772 // update the URL bar, etc).
1773 params.transition = PageTransition::LINK;
1774 }
1775
initial.commit09911bf2008-07-26 23:55:291776 // If we have a valid consumed client redirect source,
1777 // the page contained a client redirect (meta refresh, document.loc...),
1778 // so we set the referrer and transition to match.
1779 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041780 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291781 params.referrer = completed_client_redirect_src_;
1782 params.transition = static_cast<PageTransition::Type>(
1783 params.transition | PageTransition::CLIENT_REDIRECT);
1784 } else {
1785 // Bug 654101: the referrer will be empty on https->http transitions. It
1786 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281787 params.referrer = GURL(
1788 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291789 }
1790
[email protected]726985e22009-06-18 21:09:281791 string16 method = request.httpMethod();
1792 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291793 params.is_post = true;
1794
[email protected]c2a797d2009-09-21 16:46:321795 // Save some histogram data so we can compute the average memory used per
1796 // page load of the glyphs.
1797 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1798 webkit_glue::GetGlyphPageCount());
1799
[email protected]15cf526b2010-02-12 06:33:491800 // This message needs to be sent before any of allowScripts(),
1801 // allowImages(), allowPlugins() is called for the new page, so that when
1802 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1803 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291804 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1805 } else {
1806 // Subframe navigation: the type depends on whether this navigation
1807 // generated a new session history entry. When they do generate a session
1808 // history entry, it means the user initiated the navigation and we should
1809 // mark it as such. This test checks if this is the first time UpdateURL
1810 // has been called since WillNavigateToURL was called to initiate the load.
1811 if (page_id_ > last_page_id_sent_to_browser_)
1812 params.transition = PageTransition::MANUAL_SUBFRAME;
1813 else
1814 params.transition = PageTransition::AUTO_SUBFRAME;
1815
initial.commit09911bf2008-07-26 23:55:291816 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1817 }
1818
1819 last_page_id_sent_to_browser_ =
1820 std::max(last_page_id_sent_to_browser_, page_id_);
1821
1822 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101823 // we don't want the transition type to persist. Just clear it.
1824 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501825
[email protected]af15bed2010-08-25 21:12:091826 // Check if the navigation was within the same page, in which case we don't
1827 // want to clear the accessibility cache.
1828 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351829 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141830 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501831 }
initial.commit09911bf2008-07-26 23:55:291832}
1833
1834// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171835void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291836 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171837 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171838 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171839 routing_id_,
1840 page_id_,
1841 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1842 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171843 }
initial.commit09911bf2008-07-26 23:55:291844}
1845
1846void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401847 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291848 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271849 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291850 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301851 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291852 last_encoding_name_ = encoding_name;
1853
[email protected]e38f40152008-09-12 23:08:301854 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291855 }
1856}
1857
[email protected]e15f680732010-11-23 22:30:201858// Sends the last committed session history state to the browser so it will be
1859// saved before we navigate to a new page. This must be called *before* the
1860// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291861void RenderView::UpdateSessionHistory(WebFrame* frame) {
1862 // If we have a valid page ID at this point, then it corresponds to the page
1863 // we are navigating away from. Otherwise, this is the first navigation, so
1864 // there is no past session history to record.
1865 if (page_id_ == -1)
1866 return;
1867
[email protected]ca948a22009-06-25 19:36:171868 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271869 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171870 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291871 return;
[email protected]ca948a22009-06-25 19:36:171872
1873 Send(new ViewHostMsg_UpdateState(
1874 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291875}
1876
[email protected]3d9689372009-09-10 04:29:171877void RenderView::OpenURL(
1878 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1879 Send(new ViewHostMsg_OpenURL(
1880 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1881}
1882
[email protected]79dbc662009-09-04 05:42:511883// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291884
initial.commit09911bf2008-07-26 23:55:291885void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281886 const WebURLRequest& failed_request,
1887 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291888 const std::string& html,
1889 bool replace) {
[email protected]21d61e52011-03-18 19:08:251890 std::string alt_html = !html.empty() ? html :
1891 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1892 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451893 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361894 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251895 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551896 replace);
initial.commit09911bf2008-07-26 23:55:291897}
1898
[email protected]7ccddb8c2009-08-04 17:36:551899void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031900 if (!dom_automation_controller_.get()) {
1901 dom_automation_controller_.reset(new DomAutomationController());
1902 }
1903 dom_automation_controller_->set_message_sender(this);
1904 dom_automation_controller_->set_routing_id(routing_id_);
1905 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251906 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291907}
1908
initial.commit09911bf2008-07-26 23:55:291909bool RenderView::RunJavaScriptMessage(int type,
1910 const std::wstring& message,
1911 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071912 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291913 std::wstring* result) {
1914 bool success = false;
1915 std::wstring result_temp;
1916 if (!result)
1917 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291918
[email protected]12636df2009-09-28 22:32:211919 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1920 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291921 return success;
1922}
1923
[email protected]c1f50aa2010-02-18 03:46:571924bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1925 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1926 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1927 // it is particularly important that we do not call willEnterModalLoop as
1928 // that would defer resource loads for the dialog itself.
1929 if (RenderThread::current()) // Will be NULL during unit tests.
1930 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1931
1932 message->EnableMessagePumping(); // Runs a nested message loop.
1933 return Send(message);
1934}
1935
[email protected]2de7e002010-10-11 22:58:201936void RenderView::AddGURLSearchProvider(
1937 const GURL& osd_url,
1938 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291939 if (!osd_url.is_empty())
1940 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201941 provider_type));
initial.commit09911bf2008-07-26 23:55:291942}
1943
[email protected]e8345242010-05-06 03:00:401944void RenderView::OnAllowScriptToClose(bool script_can_close) {
1945 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311946}
1947
[email protected]2de7e002010-10-11 22:58:201948void RenderView::AddSearchProvider(
1949 const std::string& url,
1950 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1951 if (provider_type.type ==
1952 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1953 !webview()->mainFrame()->isProcessingUserGesture())
1954 return;
1955
1956 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291957}
1958
[email protected]155f35e2010-07-17 00:30:181959ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251960RenderView::GetSearchProviderInstallState(WebFrame* frame,
1961 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181962 GURL inquiry_url = GURL(url);
1963 if (inquiry_url.is_empty())
1964 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251965
[email protected]155f35e2010-07-17 00:30:181966 ViewHostMsg_GetSearchProviderInstallState_Params install;
1967 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:251968 frame->url(),
[email protected]155f35e2010-07-17 00:30:181969 inquiry_url,
1970 &install));
1971 return install;
1972}
1973
[email protected]f103ab72009-09-02 17:10:591974void RenderView::OnMissingPluginStatus(
1975 WebPluginDelegateProxy* delegate,
1976 int status) {
[email protected]6c8afae52009-01-22 02:24:571977#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591978 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291979 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501980 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591981 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291982 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1983 }
1984 } else {
1985 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1986 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501987 if (status ==
1988 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291989 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1990 }
1991 }
[email protected]6c8afae52009-01-22 02:24:571992#else
[email protected]76c3b312010-05-20 21:38:291993 // TODO(port): Implement the infobar that accompanies the default plugin.
1994 // Linux: http://crbug.com/10952
1995 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571996 NOTIMPLEMENTED();
1997#endif
initial.commit09911bf2008-07-26 23:55:291998}
1999
[email protected]48c9cf2d2009-09-16 16:47:522000// WebKit::WebViewClient ------------------------------------------------------
2001
[email protected]844acf372011-01-14 10:49:272002WebView* RenderView::createView(
2003 WebFrame* creator,
2004 const WebURLRequest& request,
2005 const WebWindowFeatures& features,
2006 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522007 // Check to make sure we aren't overloading on popups.
2008 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2009 return NULL;
2010
2011 // This window can't be closed from a window.close() call until we receive a
2012 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402013 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522014
[email protected]8ab04652010-06-12 02:47:262015 ViewHostMsg_CreateWindow_Params params;
2016 params.opener_id = routing_id_;
2017 params.user_gesture = creator->isProcessingUserGesture();
2018 params.window_container_type = WindowFeaturesToContainerType(features);
2019 params.session_storage_namespace_id = session_storage_namespace_id_;
2020 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112021 params.opener_frame_id = creator->identifier();
2022 params.opener_url = creator->url();
2023 params.opener_security_origin = creator->securityOrigin().toString().utf8();
2024 if (!request.isNull())
2025 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262026
[email protected]48c9cf2d2009-09-16 16:47:522027 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342028 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262029 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522030
[email protected]48c9cf2d2009-09-16 16:47:522031 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262032 new ViewHostMsg_CreateWindow(params,
2033 &routing_id,
2034 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212035 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522036 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522037
[email protected]48c9cf2d2009-09-16 16:47:522038 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422039 0,
[email protected]12636df2009-09-28 22:32:212040 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522041 renderer_preferences_,
2042 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212043 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342044 routing_id,
[email protected]8ab04652010-06-12 02:47:262045 cloned_session_storage_namespace_id,
2046 frame_name);
2047 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522048
[email protected]007a848b2009-10-26 15:55:462049 // Record whether the creator frame is trying to suppress the opener field.
2050 view->opener_suppressed_ = opener_suppressed;
2051
[email protected]48c9cf2d2009-09-16 16:47:522052 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092053 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522054 if (!creator_url.is_valid() || !creator_url.IsStandard())
2055 creator_url = GURL();
2056 view->creator_url_ = creator_url;
2057
2058 // Copy over the alternate error page URL so we can have alt error pages in
2059 // the new render view (we don't need the browser to send the URL back down).
2060 view->alternate_error_page_url_ = alternate_error_page_url_;
2061
2062 return view->webview();
2063}
2064
[email protected]3e2b375b2010-04-07 17:03:122065WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522066 RenderWidget* widget = RenderWidget::Create(routing_id_,
2067 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122068 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522069 return widget->webwidget();
2070}
2071
2072WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442073 // TODO(jcivelli): Remove this deprecated method when its been removed from
2074 // the WebViewClient interface. It's been replaced by
2075 // createExternalPopupMenu.
2076 NOTREACHED();
2077 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522078}
2079
[email protected]caf706f2010-10-26 17:54:082080WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2081 const WebPopupMenuInfo& popup_menu_info,
2082 WebExternalPopupMenuClient* popup_menu_client) {
2083 DCHECK(!external_popup_menu_.get());
2084 external_popup_menu_.reset(
2085 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2086 return external_popup_menu_.get();
2087}
2088
[email protected]0bd753682010-12-16 18:15:522089webkit::ppapi::FullscreenContainer*
2090RenderView::CreatePepperFullscreenContainer(
2091 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392092 RenderWidgetFullscreenPepper* widget =
2093 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2094 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562095 return widget;
[email protected]79c7bed2010-09-14 22:28:392096}
2097
[email protected]68c50e52010-05-12 11:14:392098WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342099 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392100 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292101 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2102 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2103 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342104}
2105
[email protected]48c9cf2d2009-09-16 16:47:522106void RenderView::didAddMessageToConsole(
2107 const WebConsoleMessage& message, const WebString& source_name,
2108 unsigned source_line) {
2109 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2110 UTF16ToWideHack(message.text),
2111 static_cast<int32>(source_line),
2112 UTF16ToWideHack(source_name)));
2113}
2114
2115void RenderView::printPage(WebFrame* frame) {
[email protected]09285ec2011-03-11 21:04:342116 print_helper_->ScriptInitiatedPrint(frame);
[email protected]48c9cf2d2009-09-16 16:47:522117}
2118
[email protected]3354d3e2010-06-10 19:53:022119WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512120 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022121}
2122
[email protected]48c9cf2d2009-09-16 16:47:522123void RenderView::didStartLoading() {
2124 if (is_loading_) {
2125 DLOG(WARNING) << "didStartLoading called while loading";
2126 return;
2127 }
2128
2129 is_loading_ = true;
2130 // Clear the pointer so that we can assign it only when there is an unknown
2131 // plugin on a page.
2132 first_default_plugin_.reset();
2133
2134 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2135}
2136
2137void RenderView::didStopLoading() {
2138 if (!is_loading_) {
2139 DLOG(WARNING) << "DidStopLoading called while not loading";
2140 return;
2141 }
2142
2143 is_loading_ = false;
2144
2145 // NOTE: For now we're doing the safest thing, and sending out notification
2146 // when done loading. This currently isn't an issue as the favicon is only
2147 // displayed when done loading. Ideally we would send notification when
2148 // finished parsing the head, but webkit doesn't support that yet.
2149 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272150 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522151 if (!favicon_url.is_empty())
[email protected]d8e74e82011-03-15 19:38:482152 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, favicon_url));
[email protected]48c9cf2d2009-09-16 16:47:522153
[email protected]26aa0482009-09-30 16:55:272154 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202155 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522156
2157 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2158
[email protected]90109412010-12-15 17:14:242159 if (load_progress_tracker_ != NULL)
2160 load_progress_tracker_->DidStopLoading();
2161
[email protected]f9f4841b2010-03-20 05:41:422162 MessageLoop::current()->PostDelayedTask(
2163 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302164 page_info_method_factory_.NewRunnableMethod(
2165 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372166 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522167}
2168
[email protected]90109412010-12-15 17:14:242169void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2170 if (load_progress_tracker_ != NULL)
2171 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2172}
2173
[email protected]f55039a2010-02-17 14:12:062174bool RenderView::isSmartInsertDeleteEnabled() {
2175#if defined(OS_MACOSX)
2176 return true;
2177#else
2178 return false;
2179#endif
2180}
2181
[email protected]04fc9482009-09-18 22:13:032182bool RenderView::isSelectTrailingWhitespaceEnabled() {
2183#if defined(OS_WIN)
2184 return true;
2185#else
2186 return false;
2187#endif
2188}
2189
[email protected]04fc9482009-09-18 22:13:032190void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422191#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032192 if (!handling_input_event_)
2193 return;
2194 // TODO(estade): investigate incremental updates to the selection so that we
2195 // don't send the entire selection over IPC every time.
2196 if (!is_empty_selection) {
2197 // Sometimes we get repeated didChangeSelection calls from webkit when
2198 // the selection hasn't actually changed. We don't want to report these
2199 // because it will cause us to continually claim the X clipboard.
2200 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272201 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032202 if (this_selection == last_selection_)
2203 return;
2204
2205 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2206 this_selection));
2207 last_selection_ = this_selection;
2208 } else {
2209 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162210 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2211 last_selection_));
[email protected]04fc9482009-09-18 22:13:032212 }
[email protected]0ff0ff32010-12-21 19:34:422213#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032214}
2215
2216void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122217 const std::string& name = UTF16ToUTF8(command_name);
2218 if (StartsWithASCII(name, "Move", true) ||
2219 StartsWithASCII(name, "Insert", true) ||
2220 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032221 return;
2222 UserMetricsRecordAction(name);
2223}
2224
[email protected]54ec7f82010-10-21 22:32:512225void RenderView::SendPendingAccessibilityNotifications() {
2226 if (!accessibility_.get())
2227 return;
2228
2229 if (pending_accessibility_notifications_.empty())
2230 return;
2231
2232 // Send all pending accessibility notifications.
2233 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2234 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2235 RendererAccessibilityNotification& notification =
2236 pending_accessibility_notifications_[i];
2237 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2238 if (!obj.isValid())
2239 continue;
2240
2241 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:362242 WebAccessibilityNotificationToViewHostMsg(
2243 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:372244 param.acc_obj = WebAccessibility(
2245 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512246 notifications.push_back(param);
2247 }
2248 pending_accessibility_notifications_.clear();
2249 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2250 accessibility_ack_pending_ = true;
2251}
2252
[email protected]b2528b72009-09-24 06:57:102253bool RenderView::handleCurrentKeyboardEvent() {
2254 if (edit_commands_.empty())
2255 return false;
2256
[email protected]26aa0482009-09-30 16:55:272257 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102258 if (!frame)
2259 return false;
2260
2261 EditCommands::iterator it = edit_commands_.begin();
2262 EditCommands::iterator end = edit_commands_.end();
2263
[email protected]507b33ea2009-09-29 03:56:512264 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102265 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332266 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2267 // key (but it's the exception). Once one edit command is not executed, it
2268 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102269 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2270 WebString::fromUTF8(it->value)))
2271 break;
[email protected]507b33ea2009-09-29 03:56:512272 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102273 }
2274
[email protected]507b33ea2009-09-29 03:56:512275 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102276}
2277
[email protected]2a3a7762009-10-19 19:17:322278void RenderView::spellCheck(const WebString& text,
2279 int& misspelled_offset,
2280 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562281 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462282
[email protected]85c55dc2009-11-06 03:05:462283 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172284 RenderThread* thread = RenderThread::current();
2285 // Will be NULL during unit tests.
2286 if (thread) {
[email protected]c27324b2009-11-19 22:44:292287 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172288 word.c_str(), word.size(), document_tag_,
2289 &misspelled_offset, &misspelled_length, NULL);
2290 }
[email protected]1dbafaf72009-09-23 19:43:562291}
2292
[email protected]5efcef62011-02-22 09:00:132293void RenderView::requestCheckingOfText(
2294 const WebString& text,
2295 WebKit::WebTextCheckingCompletion* completion) {
2296 spellcheck_provider_->RequestTextChecking(text, document_tag_, completion);
2297}
2298
[email protected]1dbafaf72009-09-23 19:43:562299WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322300 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562301 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262302 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562303 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172304 RenderThread* thread = RenderThread::current();
2305 // Will be NULL during unit tests.
2306 if (thread) {
2307 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292308 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172309 word, document_tag_);
2310 }
[email protected]1dbafaf72009-09-23 19:43:562311 }
[email protected]2a3a7762009-10-19 19:17:322312 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562313}
2314
[email protected]c49085c72009-10-02 16:28:562315void RenderView::showSpellingUI(bool show) {
2316 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2317}
2318
[email protected]8922e1f2009-10-03 05:01:262319bool RenderView::isShowingSpellingUI() {
2320 return spelling_panel_visible_;
2321}
2322
[email protected]1dbafaf72009-09-23 19:43:562323void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322324 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2325 word));
[email protected]1dbafaf72009-09-23 19:43:562326}
2327
[email protected]13a1e4c3c2011-02-03 21:07:092328void RenderView::continuousSpellCheckingEnabledStateChanged() {
2329 UpdateToggleSpellCheckCommandState();
2330}
2331
[email protected]a1128322009-10-06 18:38:462332bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352333 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472334 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352335 // Do not open the file dialog in a hidden RenderView.
2336 if (is_hidden())
2337 return false;
[email protected]cdaf8d02010-03-30 19:52:472338 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262339 if (params.directory)
2340 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2341 else if (params.multiSelect)
2342 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2343 else
2344 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472345 ipc_params.title = params.title;
2346 ipc_params.default_file_name =
2347 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592348 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472349
2350 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462351}
2352
[email protected]48c9cf2d2009-09-16 16:47:522353void RenderView::runModalAlertDialog(
2354 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062355 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:522356 UTF16ToWideHack(message),
2357 std::wstring(),
2358 frame->url(),
2359 NULL);
2360}
2361
2362bool RenderView::runModalConfirmDialog(
2363 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062364 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:522365 UTF16ToWideHack(message),
2366 std::wstring(),
2367 frame->url(),
2368 NULL);
2369}
2370
2371bool RenderView::runModalPromptDialog(
2372 WebFrame* frame, const WebString& message, const WebString& default_value,
2373 WebString* actual_value) {
2374 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:062375 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:522376 UTF16ToWideHack(message),
2377 UTF16ToWideHack(default_value),
2378 frame->url(),
2379 &result);
2380 if (ok)
2381 actual_value->assign(WideToUTF16Hack(result));
2382 return ok;
2383}
2384
2385bool RenderView::runModalBeforeUnloadDialog(
2386 WebFrame* frame, const WebString& message) {
2387 bool success = false;
2388 // This is an ignored return value, but is included so we can accept the same
2389 // response as RunJavaScriptMessage.
2390 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212391 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522392 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212393 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522394 return success;
2395}
2396
[email protected]79e37442009-10-09 18:17:442397void RenderView::showContextMenu(
2398 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292399 ContextMenuParams params = ContextMenuParams(data);
2400 if (!params.misspelled_word.empty() && RenderThread::current()) {
2401 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042402 bool spelled_right = RenderThread::current()->spellchecker()->
2403 SpellCheckWord(
2404 params.misspelled_word.c_str(), params.misspelled_word.size(),
2405 document_tag_,
2406 &misspelled_offset, &misspelled_length,
2407 &params.dictionary_suggestions);
2408 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292409 params.misspelled_word.clear();
2410 }
[email protected]db803aae2011-03-05 02:00:422411 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272412 // it. We replace it with an empty GURL so the appropriate items are disabled
2413 // in the context menu.
2414 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2415 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:422416 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272417 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102418 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292419 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442420}
2421
[email protected]52f139e2c2010-06-11 16:56:092422bool RenderView::supportsFullscreen() {
2423 return CommandLine::ForCurrentProcess()->HasSwitch(
2424 switches::kEnableVideoFullscreen);
2425}
2426
2427void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2428 NOTIMPLEMENTED();
2429}
2430
2431void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2432 NOTIMPLEMENTED();
2433}
2434
[email protected]48c9cf2d2009-09-16 16:47:522435void RenderView::setStatusText(const WebString& text) {
2436}
2437
[email protected]163f8242009-10-30 20:19:552438void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582439 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522440 if (latest_url == target_url_)
2441 return;
[email protected]163f8242009-10-30 20:19:552442
[email protected]48c9cf2d2009-09-16 16:47:522443 // Tell the browser to display a destination link.
2444 if (target_url_status_ == TARGET_INFLIGHT ||
2445 target_url_status_ == TARGET_PENDING) {
2446 // If we have a request in-flight, save the URL to be sent when we
2447 // receive an ACK to the in-flight request. We can happily overwrite
2448 // any existing pending sends.
2449 pending_target_url_ = latest_url;
2450 target_url_status_ = TARGET_PENDING;
2451 } else {
2452 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2453 target_url_ = latest_url;
2454 target_url_status_ = TARGET_INFLIGHT;
2455 }
2456}
2457
[email protected]13a1e4c3c2011-02-03 21:07:092458void RenderView::UpdateToggleSpellCheckCommandState() {
2459 bool is_enabled = false;
2460 WebKit::WebNode node = GetFocusedNode();
2461 if (!node.isNull())
2462 is_enabled = IsEditableNode(node);
2463
2464 RenderViewCommandCheckedState checked_state =
2465 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
2466 if (is_enabled && webview()) {
2467 WebFrame* frame = webview()->focusedFrame();
2468 if (frame->isContinuousSpellCheckingEnabled())
2469 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED;
2470 }
2471
2472 Send(new ViewHostMsg_CommandStateChanged(
2473 routing_id_,
2474 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK,
2475 is_enabled,
2476 checked_state));
2477}
2478
[email protected]882daa92009-11-05 16:31:312479void RenderView::StartNavStateSyncTimerIfNecessary() {
2480 int delay;
2481 if (send_content_state_immediately_)
2482 delay = 0;
2483 else if (is_hidden())
2484 delay = kDelaySecondsForContentStateSyncHidden;
2485 else
2486 delay = kDelaySecondsForContentStateSync;
2487
2488 if (nav_state_sync_timer_.IsRunning()) {
2489 // The timer is already running. If the delay of the timer maches the amount
2490 // we want to delay by, then return. Otherwise stop the timer so that it
2491 // gets started with the right delay.
2492 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2493 return;
2494 nav_state_sync_timer_.Stop();
2495 }
2496
2497 nav_state_sync_timer_.Start(
2498 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2499}
2500
[email protected]163f8242009-10-30 20:19:552501void RenderView::setMouseOverURL(const WebURL& url) {
2502 mouse_over_url_ = GURL(url);
2503 UpdateTargetURL(mouse_over_url_, focus_url_);
2504}
2505
2506void RenderView::setKeyboardFocusURL(const WebURL& url) {
2507 focus_url_ = GURL(url);
2508 UpdateTargetURL(focus_url_, mouse_over_url_);
2509}
2510
[email protected]48c9cf2d2009-09-16 16:47:522511void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2512 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2513 hint));
2514}
2515
[email protected]c27ae592010-03-18 15:24:412516void RenderView::startDragging(const WebDragData& data,
2517 WebDragOperationsMask mask,
2518 const WebImage& image,
2519 const WebPoint& imageOffset) {
2520#if WEBKIT_USING_SKIA
2521 SkBitmap bitmap(image.getSkBitmap());
2522#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332523 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412524#endif
2525
[email protected]48c9cf2d2009-09-16 16:47:522526 Send(new ViewHostMsg_StartDragging(routing_id_,
2527 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412528 mask,
2529 bitmap,
2530 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522531}
2532
[email protected]28b92df2009-09-25 17:35:452533bool RenderView::acceptsLoadDrops() {
2534 return renderer_preferences_.can_accept_load_drops;
2535}
2536
[email protected]48c9cf2d2009-09-16 16:47:522537void RenderView::focusNext() {
2538 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2539}
2540
2541void RenderView::focusPrevious() {
2542 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2543}
2544
[email protected]08e9e132010-06-01 16:58:492545void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512546 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072547
2548 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2549 // TODO(ctguil): Make WebKit send this notification.
2550 // When focus is cleared notify accessibility that the document is focused.
2551 postAccessibilityNotification(
2552 webview()->accessibilityObject(),
2553 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2554 }
[email protected]13a1e4c3c2011-02-03 21:07:092555
2556 UpdateToggleSpellCheckCommandState();
[email protected]08e9e132010-06-01 16:58:492557}
2558
[email protected]48c9cf2d2009-09-16 16:47:522559void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522560 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2561}
2562
2563int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002564 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522565}
2566
2567int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002568 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522569}
2570
[email protected]c4e98902010-06-01 10:20:142571void RenderView::didUpdateInspectorSetting(const WebString& key,
2572 const WebString& value) {
2573 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2574 key.utf8(),
2575 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262576}
2577
[email protected]79dbc662009-09-04 05:42:512578// WebKit::WebWidgetClient ----------------------------------------------------
2579
[email protected]ea42e7782010-08-23 23:58:122580void RenderView::didFocus() {
2581 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2582 // we won't have to test for user gesture anymore and we can
2583 // move that code back to render_widget.cc
2584 if (webview() && webview()->mainFrame() &&
2585 webview()->mainFrame()->isProcessingUserGesture()) {
2586 Send(new ViewHostMsg_Focus(routing_id_));
2587 }
2588}
2589
2590void RenderView::didBlur() {
2591 // TODO(jcivelli): see TODO above in didFocus().
2592 if (webview() && webview()->mainFrame() &&
2593 webview()->mainFrame()->isProcessingUserGesture()) {
2594 Send(new ViewHostMsg_Blur(routing_id_));
2595 }
2596}
2597
initial.commit09911bf2008-07-26 23:55:292598// We are supposed to get a single call to Show for a newly created RenderView
2599// that was created via RenderView::CreateWebView. So, we wait until this
2600// point to dispatch the ShowView message.
2601//
2602// This method provides us with the information about how to display the newly
2603// created RenderView (i.e., as a constrained popup or as a new tab).
2604//
[email protected]4873c7d2009-07-16 06:36:282605void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292606 DCHECK(!did_show_) << "received extraneous Show call";
2607 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2608
2609 if (did_show_)
2610 return;
2611 did_show_ = true;
2612
[email protected]4026ce1e2010-09-14 19:35:042613 // Extensions and apps always allowed to create unrequested popups. The second
2614 // check is necessary to include content scripts.
[email protected]2a521c52011-01-26 18:45:212615 if (render_thread_->GetExtensions()->GetByURL(creator_url_) ||
[email protected]4026ce1e2010-09-14 19:35:042616 bindings_utils::GetInfoForCurrentContext()) {
2617 opened_by_user_gesture_ = true;
2618 }
2619
[email protected]28295ec2009-10-16 05:34:332620 // Force new windows to a popup if they were not opened with a user gesture.
2621 if (!opened_by_user_gesture_) {
2622 // We exempt background tabs for compat with older versions of Chrome.
2623 // TODO(darin): This seems bogus. These should have a user gesture, so
2624 // we probably don't need this check.
2625 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2626 policy = WebKit::WebNavigationPolicyNewPopup;
2627 }
2628
initial.commit09911bf2008-07-26 23:55:292629 // NOTE: initial_pos_ may still have its default values at this point, but
2630 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2631 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282632 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2633 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292634 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242635 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292636}
2637
[email protected]4873c7d2009-07-16 06:36:282638void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292639 DCHECK(did_show_) << "should already have shown the view";
2640
[email protected]c1f50aa2010-02-18 03:46:572641 // We must keep WebKit's shared timer running in this case in order to allow
2642 // showModalDialog to function properly.
2643 //
2644 // TODO(darin): WebKit should really be smarter about suppressing events and
2645 // timers so that we do not need to manage the shared timer in such a heavy
2646 // handed manner.
2647 //
2648 if (RenderThread::current()) // Will be NULL during unit tests.
2649 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2650
[email protected]12636df2009-09-28 22:32:212651 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292652}
2653
[email protected]3d9689372009-09-10 04:29:172654// WebKit::WebFrameClient -----------------------------------------------------
2655
[email protected]00152e92010-07-19 11:47:402656WebPlugin* RenderView::createPlugin(WebFrame* frame,
2657 const WebPluginParams& params) {
[email protected]21d61e52011-03-18 19:08:252658 WebPlugin* plugin = content::GetContentClient()->renderer()->CreatePlugin(
2659 this, frame, params);
2660 if (!plugin)
2661 plugin = CreatePluginNoCheck(frame, params);
2662 return plugin;
[email protected]3d9689372009-09-10 04:29:172663}
2664
2665WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562666 WebApplicationCacheHostImpl* appcache_host =
2667 WebApplicationCacheHostImpl::FromFrame(frame);
2668 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2669 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2670 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172671}
2672
[email protected]9c00f002009-11-05 22:37:422673WebSharedWorker* RenderView::createSharedWorker(
2674 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372675 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422676
[email protected]30447b62009-11-13 01:13:372677 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512678 bool exists = false;
[email protected]30447b62009-11-13 01:13:372679 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512680 ViewHostMsg_CreateWorker_Params params;
2681 params.url = url;
2682 params.is_shared = true;
2683 params.name = name;
2684 params.document_id = document_id;
2685 params.render_view_route_id = routing_id_;
2686 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232687 params.parent_appcache_host_id = 0;
2688 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372689 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512690 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372691 if (url_mismatch) {
2692 return NULL;
2693 } else {
2694 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492695 document_id,
[email protected]6de0bcf2010-02-17 22:00:512696 exists,
[email protected]30447b62009-11-13 01:13:372697 route_id,
2698 routing_id_);
2699 }
[email protected]9c00f002009-11-05 22:37:422700}
2701
[email protected]3d9689372009-09-10 04:29:172702WebMediaPlayer* RenderView::createMediaPlayer(
2703 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f78d1dfc2011-01-15 07:09:272704 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2705 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492706 scoped_ptr<media::FilterCollection> collection(
2707 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372708
[email protected]3d9689372009-09-10 04:29:172709 // Add in any custom filter factories first.
2710 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2711 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2712 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492713 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172714 }
2715
[email protected]3bb08602010-10-07 21:47:172716 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122717 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072718 WebGraphicsContext3DCommandBufferImpl* context =
2719 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2720 frame->view()->graphicsContext3D());
2721 if (!context)
2722 return NULL;
[email protected]a9a43012010-11-05 01:54:062723
[email protected]5aa6a312010-11-06 00:00:072724 // Add the hardware video decoder factory.
2725 // TODO(hclam): This will cause the renderer process to crash on context
2726 // lost.
2727 bool ret = context->makeContextCurrent();
2728 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492729 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072730 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172731 }
2732
[email protected]457d8342010-10-23 01:20:372733 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312734 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2735 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2736 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492737 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312738 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112739
[email protected]a8e24d522010-12-01 07:13:582740 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272741 new webkit_glue::WebMediaPlayerImpl(client,
2742 collection.release(),
2743 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:462744 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582745 cmd_line->HasSwitch(switches::kSimpleDataSource),
2746 video_renderer)) {
2747 return NULL;
2748 }
2749 return result.release();
[email protected]3d9689372009-09-10 04:29:172750}
2751
[email protected]035545f2010-04-09 13:10:212752WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2753 WebFrame* frame, WebApplicationCacheHostClient* client) {
2754 return new RendererWebApplicationCacheHostImpl(
2755 FromWebView(frame->view()), client,
2756 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2757}
2758
[email protected]8ff181072010-11-29 17:09:382759WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2760 return &cookie_jar_;
2761}
2762
[email protected]5041f982010-08-11 21:40:452763void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512764 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452765}
2766
[email protected]3d9689372009-09-10 04:29:172767void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302768 WebDataSource* ds = frame->dataSource();
2769 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522770
[email protected]a5a65ac2010-11-05 18:14:362771 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302772 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182773
[email protected]676126f72011-01-15 00:03:512774 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172775}
2776
[email protected]684e4a42010-01-30 06:44:112777bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402778 if (enabled_per_settings &&
2779 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2780 return true;
2781
2782 if (IsWhitelistedForContentSettings(frame))
2783 return true;
2784
[email protected]55126132010-08-19 14:53:282785 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402786 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112787}
2788
[email protected]d5f9e4f2010-07-28 08:31:302789bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162790 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302791}
2792
2793
[email protected]3d9689372009-09-10 04:29:172794void RenderView::loadURLExternally(
2795 WebFrame* frame, const WebURLRequest& request,
2796 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592797 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2798 if (policy == WebKit::WebNavigationPolicyDownload) {
2799 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2800 } else {
2801 OpenURL(request.url(), referrer, policy);
2802 }
[email protected]3d9689372009-09-10 04:29:172803}
2804
2805WebNavigationPolicy RenderView::decidePolicyForNavigation(
2806 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222807 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172808 // Webkit is asking whether to navigate to a new URL.
2809 // This is fine normally, except if we're showing UI from one security
2810 // context and they're trying to navigate to a different context.
2811 const GURL& url = request.url();
2812
2813 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302814 // navigations.
[email protected]8079b362010-05-07 18:37:452815 if (renderer_preferences_.browser_handles_top_level_requests &&
2816 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192817 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232818 // Reset these counters as the RenderView could be reused for the next
2819 // navigation.
2820 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232821 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192822 OpenURL(url, referrer, default_policy);
2823 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172824 }
2825
2826 // A content initiated navigation may have originated from a link-click,
2827 // script, drag-n-drop operation, etc.
2828 bool is_content_initiated =
2829 NavigationState::FromDataSource(frame->provisionalDataSource())->
2830 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582831 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172832
[email protected]6101c342010-12-16 22:44:372833 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552834 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572835 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372836 // opening a new window). But we sometimes navigate to about:blank to clear a
2837 // tab, and we want to still allow that.
2838 //
[email protected]8f4da8c2011-02-09 19:49:572839 // Note: we do this only for GET requests because our mechanism for switching
2840 // processes only issues GET requests. In particular, POST requests don't
2841 // work, because this mechanism does not preserve form POST data. If it
2842 // becomes necessary to support process switching for POST requests, we will
2843 // need to send the request's httpBody data up to the browser process, and
2844 // issue a special POST navigation in WebKit (via
2845 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2846 // for examples of how to send the httpBody data.
2847 // Note2: We normally don't do this for browser-initiated navigations, since
2848 // it's pointless to tell the browser about navigations it gave us. But
2849 // we do potentially ask the browser to handle a redirect that was originally
2850 // initiated by the browser. See http://crbug.com/70943
2851 //
2852 // TODO(creis): Move this redirect check to the browser process to avoid
2853 // ping-ponging. See http://crbug.com/72380.
2854 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372855 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2856 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2857 bool send_referrer = false;
2858 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552859 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172860 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372861 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112862
2863 // If the navigation would cross an app extent boundary, we also need
2864 // to defer to the browser to ensure process isolation.
2865 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2866 // which means that things like the back button won't trigger it. Is that
2867 // OK?
[email protected]88c15e972011-02-05 04:19:532868 // TODO(creis): For hosted apps, we currently only swap processes to enter
2869 // the app and not exit it, since we currently lose context (e.g.,
2870 // window.opener) if the window navigates back. See crbug.com/65953.
[email protected]2a521c52011-01-26 18:45:212871 if (!should_fork &&
[email protected]88c15e972011-02-05 04:19:532872 CrossesExtensionExtents(
[email protected]2a521c52011-01-26 18:45:212873 render_thread_->GetExtensions(),
2874 frame,
2875 url)) {
[email protected]5351dbc2010-08-27 15:22:112876 // Include the referrer in this case since we're going from a hosted web
2877 // page. (the packaged case is handled previously by the extension
2878 // navigation test)
[email protected]6101c342010-12-16 22:44:372879 should_fork = true;
2880 send_referrer = true;
[email protected]46fd1ea42011-02-16 15:59:332881
2882 if (is_content_initiated) {
2883 const Extension* extension =
2884 render_thread_->GetExtensions()->GetByURL(url);
2885 if (extension && extension->is_app()) {
2886 UMA_HISTOGRAM_ENUMERATION(
2887 extension_misc::kAppLaunchHistogram,
2888 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION,
2889 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
2890 }
2891 }
[email protected]6101c342010-12-16 22:44:372892 }
2893
2894 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112895 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372896 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112897 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2898 }
[email protected]3d9689372009-09-10 04:29:172899 }
2900
2901 // Detect when a page is "forking" a new tab that can be safely rendered in
2902 // its own process. This is done by sites like Gmail that try to open links
2903 // in new windows without script connections back to the original page. We
2904 // treat such cases as browser navigations (in which we will create a new
2905 // renderer for a cross-site navigation), rather than WebKit navigations.
2906 //
2907 // We use the following heuristic to decide whether to fork a new page in its
2908 // own process:
2909 // The parent page must open a new tab to about:blank, set the new tab's
2910 // window.opener to null, and then redirect the tab to a cross-site URL using
2911 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462912 //
2913 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2914 // (see below).
[email protected]3d9689372009-09-10 04:29:172915 bool is_fork =
2916 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582917 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172918 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522919 historyBackListCount() < 1 &&
2920 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172921 // The parent page must have set the child's window.opener to null before
2922 // redirecting to the desired URL.
2923 frame->opener() == NULL &&
2924 // Must be a top-level frame.
2925 frame->parent() == NULL &&
2926 // Must not have issued the request from this page.
2927 is_content_initiated &&
2928 // Must be targeted at the current tab.
2929 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2930 // Must be a JavaScript navigation, which appears as "other".
2931 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462932
2933 // Recognize if this navigation is from a link with rel=noreferrer and
2934 // target=_blank attributes, in which case the opener will be suppressed. If
2935 // so, it is safe to load cross-site pages in a separate process, so we
2936 // should let the browser handle it.
2937 bool is_noreferrer_and_blank_target =
2938 // Frame should be top level and not yet navigated.
2939 frame->parent() == NULL &&
2940 frame->url().isEmpty() &&
2941 historyBackListCount() < 1 &&
2942 historyForwardListCount() < 1 &&
2943 // Links with rel=noreferrer will have no Referer field, and their
2944 // resulting frame will have its window.opener suppressed.
2945 // TODO(creis): should add a request.httpReferrer() method to help avoid
2946 // typos on the unusual spelling of Referer.
2947 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2948 opener_suppressed_ &&
2949 frame->opener() == NULL &&
2950 // Links with target=_blank will have no name.
2951 frame->name().isNull() &&
2952 // Another frame (with a non-empty creator) should have initiated the
2953 // request, targeted at this frame.
2954 !creator_url_.is_empty() &&
2955 is_content_initiated &&
2956 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2957 type == WebKit::WebNavigationTypeOther;
2958
2959 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172960 // Open the URL via the browser, not via WebKit.
2961 OpenURL(url, GURL(), default_policy);
2962 return WebKit::WebNavigationPolicyIgnore;
2963 }
2964
2965 return default_policy;
2966}
2967
[email protected]6069da8c2009-10-20 20:33:492968bool RenderView::canHandleRequest(
2969 WebFrame* frame, const WebURLRequest& request) {
2970 // We allow WebKit to think that everything can be handled even though
2971 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342972 return true;
2973}
2974
[email protected]6069da8c2009-10-20 20:33:492975WebURLError RenderView::cannotHandleRequestError(
2976 WebFrame* frame, const WebURLRequest& request) {
2977 NOTREACHED(); // Since we said we can handle all requests.
2978 return WebURLError();
2979}
2980
2981WebURLError RenderView::cancelledError(
2982 WebFrame* frame, const WebURLRequest& request) {
2983 WebURLError error;
2984 error.domain = WebString::fromUTF8(net::kErrorDomain);
2985 error.reason = net::ERR_ABORTED;
2986 error.unreachableURL = request.url();
2987 return error;
[email protected]7b7a7dc2009-10-19 02:23:342988}
2989
2990void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492991 WebFrame*, const WebURLError&) {
2992 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342993}
2994
[email protected]90eeddb2010-05-06 21:06:432995void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2996 const WebKit::WebFormElement& form) {
2997 // Some login forms have onSubmit handlers that put a hash of the password
2998 // into a hidden field and then clear the password. (Issue 28910.)
2999 // This method gets called before any of those handlers run, so save away
3000 // a copy of the password in case it gets lost.
3001 NavigationState* navigation_state =
3002 NavigationState::FromDataSource(frame->dataSource());
3003 navigation_state->set_password_form_data(
3004 PasswordFormDomManager::CreatePasswordForm(form));
3005}
3006
[email protected]979c28b2009-11-07 01:30:483007void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173008 NavigationState* navigation_state =
3009 NavigationState::FromDataSource(frame->provisionalDataSource());
3010
3011 if (navigation_state->transition_type() == PageTransition::LINK)
3012 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3013
3014 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353015 WebSearchableFormData web_searchable_form_data(form);
3016 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3017 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213018 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433019 PasswordForm* password_form_data =
3020 PasswordFormDomManager::CreatePasswordForm(form);
3021 navigation_state->set_password_form_data(password_form_data);
3022
3023 // If the password has been cleared, recover it from the form contents already
3024 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3025 // opposed to the provisionalDataSource's, which is what we're storing into
3026 // now.)
3027 if (password_form_data && password_form_data->password_value.empty()) {
3028 NavigationState* old_navigation_state =
3029 NavigationState::FromDataSource(frame->dataSource());
3030 if (old_navigation_state) {
3031 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3032 if (old_form_data && old_form_data->action == password_form_data->action)
3033 password_form_data->password_value = old_form_data->password_value;
3034 }
3035 }
[email protected]3d9689372009-09-10 04:29:173036
[email protected]b1438212010-04-03 00:30:593037 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043038 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223039 form,
3040 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]78192082011-01-29 05:43:443041 static_cast<FormManager::ExtractMask>(
3042 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223043 &form_data)) {
[email protected]19d6e1e82011-01-26 05:08:583044 Send(new AutoFillHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223045 }
[email protected]3d9689372009-09-10 04:29:173046}
3047
3048void RenderView::willPerformClientRedirect(
3049 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3050 double fire_time) {
3051 // Ignore
3052}
3053
3054void RenderView::didCancelClientRedirect(WebFrame* frame) {
3055 // Ignore
3056}
3057
3058void RenderView::didCompleteClientRedirect(
3059 WebFrame* frame, const WebURL& from) {
3060 if (!frame->parent())
3061 completed_client_redirect_src_ = from;
3062}
3063
3064void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233065 // If there are any app-related fetches in progress, they can be cancelled now
3066 // since we have navigated away from the page that created them.
3067 if (!frame->parent()) {
3068 app_icon_fetchers_.clear();
3069 app_definition_fetcher_.reset(NULL);
3070 }
3071
[email protected]3d9689372009-09-10 04:29:173072 // The rest of RenderView assumes that a WebDataSource will always have a
3073 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483074 bool content_initiated = !pending_navigation_state_.get();
3075 NavigationState* state = content_initiated ?
3076 NavigationState::CreateContentInitiated() :
3077 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513078
[email protected]8a3125a712010-08-09 18:58:513079 // NavigationState::referred_by_prefetcher_ is true if we are
3080 // navigating from a page that used prefetching using a link on that
3081 // page. We are early enough in the request process here that we
3082 // can still see the NavigationState of the previous page and set
3083 // this value appropriately.
3084 // TODO(gavinp): catch the important case of navigation in a new
3085 // renderer process.
3086 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303087 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523088 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513089 const GURL referrer(
3090 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3091 if (!referrer.is_empty() &&
3092 NavigationState::FromDataSource(
3093 old_frame->dataSource())->was_prefetcher()) {
3094 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3095 WebDataSource* old_frame_ds = old_frame->dataSource();
3096 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3097 state->set_was_referred_by_prefetcher(true);
3098 break;
3099 }
3100 }
3101 }
3102 }
3103 }
3104
[email protected]4c1b6f0b2010-02-07 16:38:183105 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523106 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513107 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183108 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3109 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3110 break;
3111 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3112 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3113 break;
3114 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3115 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3116 break;
3117 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3118 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3119 break;
3120 }
3121 }
[email protected]fa7b6b542009-11-03 05:02:303122
[email protected]5792d932011-01-18 20:33:293123 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3124 // This is for navigations within a page (didNavigateWithinPage). See
3125 // http://code.google.com/p/chromium/issues/detail?id=64093
3126 NavigationState* old_state = NavigationState::FromDataSource(ds);
3127 if (old_state && old_state->user_script_idle_scheduler()) {
3128 state->swap_user_script_idle_scheduler(old_state);
3129 } else {
3130 state->set_user_script_idle_scheduler(
3131 new UserScriptIdleScheduler(this, frame));
3132 }
[email protected]375e8bd2011-02-07 19:15:353133
[email protected]987d51af2011-02-24 17:50:183134 state->set_was_started_as_prerender(is_prerendering_);
[email protected]375e8bd2011-02-07 19:15:353135
[email protected]fa7b6b542009-11-03 05:02:303136 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173137}
3138
3139void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3140 WebDataSource* ds = frame->provisionalDataSource();
3141 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3142
[email protected]3d9689372009-09-10 04:29:173143 // Update the request time if WebKit has better knowledge of it.
3144 if (navigation_state->request_time().is_null()) {
3145 double event_time = ds->triggeringEventTime();
3146 if (event_time != 0.0)
3147 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3148 }
3149
[email protected]05c8e502010-08-15 15:13:523150 // Start time is only set after request time.
3151 navigation_state->set_start_load_time(Time::Now());
3152
[email protected]3d9689372009-09-10 04:29:173153 bool is_top_most = !frame->parent();
3154 if (is_top_most) {
3155 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133156 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173157
3158 // Make sure redirect tracking state is clear for the new load.
3159 completed_client_redirect_src_ = GURL();
3160 } else if (frame->parent()->isLoading()) {
3161 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003162 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173163 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3164 }
3165
[email protected]28685da92011-02-07 21:49:173166 FOR_EACH_OBSERVER(
3167 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3168
[email protected]3d9689372009-09-10 04:29:173169 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073170 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173171}
3172
3173void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3174 if (frame->parent())
3175 return;
3176 // Received a redirect on the main frame.
3177 WebDataSource* data_source = frame->provisionalDataSource();
3178 if (!data_source) {
3179 // Should only be invoked when we have a data source.
3180 NOTREACHED();
3181 return;
3182 }
3183 std::vector<GURL> redirects;
3184 GetRedirectChain(data_source, &redirects);
3185 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513186 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3187 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173188 }
3189}
3190
[email protected]40bd6582009-12-04 23:49:513191void RenderView::didFailProvisionalLoad(WebFrame* frame,
3192 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173193 // Notify the browser that we failed a provisional load with an error.
3194 //
3195 // Note: It is important this notification occur before DidStopLoading so the
3196 // SSL manager can react to the provisional load failure before being
3197 // notified the load stopped.
3198 //
3199 WebDataSource* ds = frame->provisionalDataSource();
3200 DCHECK(ds);
3201
3202 const WebURLRequest& failed_request = ds->request();
3203
[email protected]28685da92011-02-07 21:49:173204 FOR_EACH_OBSERVER(
3205 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3206
[email protected]3d9689372009-09-10 04:29:173207 bool show_repost_interstitial =
3208 (error.reason == net::ERR_CACHE_MISS &&
3209 EqualsASCII(failed_request.httpMethod(), "POST"));
3210 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073211 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3212 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173213
3214 // Don't display an error page if this is simply a cancelled load. Aside
3215 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3216 if (error.reason == net::ERR_ABORTED)
3217 return;
3218
3219 // Make sure we never show errors in view source mode.
3220 frame->enableViewSourceMode(false);
3221
3222 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3223
3224 // If this is a failed back/forward/reload navigation, then we need to do a
3225 // 'replace' load. This is necessary to avoid messing up session history.
3226 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3227 // as session history is concerned.
3228 //
3229 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3230 // the page id.
3231 //
3232 bool replace =
3233 navigation_state->pending_page_id() != -1 ||
3234 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3235
3236 // If we failed on a browser initiated request, then make sure that our error
3237 // page load is regarded as the same browser initiated request.
3238 if (!navigation_state->is_content_initiated()) {
3239 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3240 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003241 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173242 navigation_state->transition_type(),
3243 navigation_state->request_time()));
3244 }
3245
3246 // Provide the user with a more helpful error page?
3247 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3248 return;
3249
3250 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083251 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173252}
3253
3254void RenderView::didReceiveDocumentData(
3255 WebFrame* frame, const char* data, size_t data_len,
3256 bool& prevent_default) {
3257 NavigationState* navigation_state =
3258 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:093259 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173260}
3261
[email protected]40bd6582009-12-04 23:49:513262void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3263 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173264 NavigationState* navigation_state =
3265 NavigationState::FromDataSource(frame->dataSource());
3266
3267 navigation_state->set_commit_load_time(Time::Now());
3268 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203269 // When we perform a new navigation, we need to update the last committed
3270 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173271 UpdateSessionHistory(frame);
3272
3273 // We bump our Page ID to correspond with the new session history entry.
3274 page_id_ = next_page_id_++;
3275
[email protected]3cc72b12010-03-18 23:03:003276 // Advance our offset in session history, applying the length limit. There
3277 // is now no forward history.
3278 history_list_offset_++;
3279 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3280 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3281 history_list_length_ = history_list_offset_ + 1;
3282
[email protected]f9f4841b2010-03-20 05:41:423283 MessageLoop::current()->PostDelayedTask(
3284 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303285 page_info_method_factory_.NewRunnableMethod(
3286 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173287 kDelayForForcedCaptureMs);
3288 } else {
3289 // Inspect the navigation_state on this frame to see if the navigation
3290 // corresponds to a session history navigation... Note: |frame| may or
3291 // may not be the toplevel frame, but for the case of capturing session
3292 // history, the first committed frame suffices. We keep track of whether
3293 // we've seen this commit before so that only capture session history once
3294 // per navigation.
3295 //
3296 // Note that we need to check if the page ID changed. In the case of a
3297 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3298 // previous URL and the current page ID, which would be wrong.
3299 if (navigation_state->pending_page_id() != -1 &&
3300 navigation_state->pending_page_id() != page_id_ &&
3301 !navigation_state->request_committed()) {
3302 // This is a successful session history navigation!
3303 UpdateSessionHistory(frame);
3304 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003305
3306 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173307 }
3308 }
3309
[email protected]28685da92011-02-07 21:49:173310 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3311 DidCommitProvisionalLoad(frame, is_new_navigation));
3312
[email protected]3d9689372009-09-10 04:29:173313 // Remember that we've already processed this request, so we don't update
3314 // the session history again. We do this regardless of whether this is
3315 // a session history navigation, because if we attempted a session history
3316 // navigation without valid HistoryItem state, WebCore will think it is a
3317 // new navigation.
3318 navigation_state->set_request_committed(true);
3319
3320 UpdateURL(frame);
3321
3322 // If this committed load was initiated by a client redirect, we're
3323 // at the last stop now, so clear it.
3324 completed_client_redirect_src_ = GURL();
3325
3326 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273327 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173328}
3329
3330void RenderView::didClearWindowObject(WebFrame* frame) {
3331 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3332 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453333 GURL frame_url = frame->url();
[email protected]c09163a2011-02-15 00:05:553334 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253335 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3336 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273337 GetWebUIBindings()->set_message_sender(this);
3338 GetWebUIBindings()->set_routing_id(routing_id_);
3339 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173340 }
3341 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463342 GetExternalHostBindings()->set_message_sender(this);
3343 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253344 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173345 }
3346}
3347
3348void RenderView::didCreateDocumentElement(WebFrame* frame) {
3349 if (RenderThread::current()) { // Will be NULL during unit tests.
3350 RenderThread::current()->user_script_slave()->InjectScripts(
3351 frame, UserScript::DOCUMENT_START);
3352 }
3353
3354 // Notify the browser about non-blank documents loading in the top frame.
3355 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253356 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273357 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173358 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3359 }
3360}
3361
3362void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3363 UpdateTitle(frame, title);
3364
3365 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273366 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173367}
3368
[email protected]5019ef12010-04-27 17:26:583369void RenderView::didChangeIcons(WebFrame* frame) {
3370 if (!frame->parent()) {
[email protected]d8e74e82011-03-15 19:38:483371 Send(new ViewHostMsg_UpdateFaviconURL(
[email protected]5019ef12010-04-27 17:26:583372 routing_id_,
3373 page_id_,
3374 frame->favIconURL()));
3375 }
3376}
3377
[email protected]3d9689372009-09-10 04:29:173378void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3379 WebDataSource* ds = frame->dataSource();
3380 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3381 DCHECK(navigation_state);
3382 navigation_state->set_finish_document_load_time(Time::Now());
3383
[email protected]622474d2010-11-04 09:21:083384 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173385
[email protected]28685da92011-02-07 21:49:173386 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3387 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173388
3389 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273390 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173391
3392 if (RenderThread::current()) { // Will be NULL during unit tests.
3393 RenderThread::current()->user_script_slave()->InjectScripts(
3394 frame, UserScript::DOCUMENT_END);
3395 }
[email protected]fa7b6b542009-11-03 05:02:303396
[email protected]41f16632010-10-20 01:21:323397 // InjectScripts() can end up creating a new NavigationState if it triggers a
3398 // fragment navigation, so we need to re-fetch it here.
3399 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303400 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3401}
3402
3403void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3404 if (RenderThread::current()) { // Will be NULL during unit tests.
3405 RenderThread::current()->user_script_slave()->InjectScripts(
3406 frame, UserScript::DOCUMENT_IDLE);
3407 }
3408
3409 WebFrame* main_frame = webview()->mainFrame();
3410 if (frame == main_frame) {
3411 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203412 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303413 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203414 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303415 pending_code_execution_queue_.pop();
3416 }
3417 }
[email protected]3d9689372009-09-10 04:29:173418}
3419
3420void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083421 if (webview()->mainFrame() == frame) {
3422 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3423 page_id_));
3424 }
[email protected]3d9689372009-09-10 04:29:173425}
3426
3427void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:173428 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:173429}
3430
3431void RenderView::didFinishLoad(WebFrame* frame) {
3432 WebDataSource* ds = frame->dataSource();
3433 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3434 DCHECK(navigation_state);
3435 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303436 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413437
[email protected]676126f72011-01-15 00:03:513438 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173439
3440 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173441}
3442
[email protected]ccbe04e2010-03-17 17:58:433443void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173444 WebFrame* frame, bool is_new_navigation) {
3445 // If this was a reference fragment navigation that we initiated, then we
3446 // could end up having a non-null pending navigation state. We just need to
3447 // update the ExtraData on the datasource so that others who read the
3448 // ExtraData will get the new NavigationState. Similarly, if we did not
3449 // initiate this navigation, then we need to take care to reset any pre-
3450 // existing navigation state to a content-initiated navigation state.
3451 // DidCreateDataSource conveniently takes care of this for us.
3452 didCreateDataSource(frame, frame->dataSource());
3453
[email protected]af15bed2010-08-25 21:12:093454 NavigationState* new_state =
3455 NavigationState::FromDataSource(frame->dataSource());
3456 new_state->set_was_within_same_page(true);
3457
[email protected]3d9689372009-09-10 04:29:173458 didCommitProvisionalLoad(frame, is_new_navigation);
3459
[email protected]26aa0482009-09-30 16:55:273460 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173461}
3462
[email protected]476b6f82009-09-10 21:00:593463void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313464 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593465}
3466
[email protected]3d9689372009-09-10 04:29:173467void RenderView::assignIdentifierToRequest(
3468 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3469 // Ignore
3470}
3471
3472void RenderView::willSendRequest(
3473 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3474 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303475 WebFrame* top_frame = frame->top();
3476 if (!top_frame)
3477 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513478 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3479 WebDataSource* top_data_source = top_frame->dataSource();
3480 WebDataSource* data_source =
3481 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223482
3483 // If the request is for an extension resource, check whether it should be
3484 // allowed. If not allowed, we reset the URL to something invalid to prevent
3485 // the request and cause an error.
3486 GURL request_url(request.url());
3487 if (request_url.SchemeIs(chrome::kExtensionScheme) &&
3488 !ExtensionResourceRequestPolicy::CanRequestResource(
3489 request_url,
3490 GURL(frame->url()),
3491 render_thread_->GetExtensions())) {
3492 request.setURL(WebURL(GURL("chrome-extension://invalid/")));
3493 }
3494
[email protected]5e369672009-11-03 23:48:303495 if (data_source) {
3496 NavigationState* state = NavigationState::FromDataSource(data_source);
3497 if (state && state->is_cache_policy_override_set())
3498 request.setCachePolicy(state->cache_policy_override());
3499 }
[email protected]8a3125a712010-08-09 18:58:513500
3501 if (top_data_source) {
3502 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3503 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3504 state->set_was_prefetcher(true);
3505 }
3506
[email protected]3d9689372009-09-10 04:29:173507 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133508 request.setHasUserGesture(frame->isProcessingUserGesture());
3509
[email protected]c5bbc2452010-03-08 08:33:503510 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133511 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493512
[email protected]85cc78c2010-05-04 18:30:093513 // Temporary metrics, see site_isolation_metrics.h
3514 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173515}
3516
3517void RenderView::didReceiveResponse(
3518 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493519
[email protected]85cc78c2010-05-04 18:30:093520 // Temporary metrics, see site_isolation_metrics.h
3521 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3522 identifier,
3523 response);
[email protected]fa0a3432010-03-30 16:53:493524
[email protected]3d9689372009-09-10 04:29:173525 // Only do this for responses that correspond to a provisional data source
3526 // of the top-most frame. If we have a provisional data source, then we
3527 // can't have any sub-resources yet, so we know that this response must
3528 // correspond to a frame load.
3529 if (!frame->provisionalDataSource() || frame->parent())
3530 return;
3531
3532 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083533 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173534 if (frame->isViewSourceModeEnabled())
3535 return;
3536
[email protected]65041fa2010-05-21 06:56:533537 NavigationState* navigation_state =
3538 NavigationState::FromDataSource(frame->provisionalDataSource());
3539 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083540 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533541
[email protected]972ebdff2010-06-10 22:59:073542 // Record page load flags.
3543 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3544 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573545 navigation_state->set_was_alternate_protocol_available(
3546 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073547 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083548 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093549 // Whether or not the http status code actually corresponds to an error is
3550 // only checked when the page is done loading, if |use_error_page| is
3551 // still true.
3552 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173553}
3554
3555void RenderView::didFinishResourceLoad(
3556 WebFrame* frame, unsigned identifier) {
3557 NavigationState* navigation_state =
3558 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:093559 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173560 return;
3561
[email protected]06333afe2011-02-24 14:55:093562 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:083563 int http_status_code = navigation_state->http_status_code();
3564 if (http_status_code == 404) {
3565 // On 404s, try a remote search page as a fallback.
3566 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173567
[email protected]3f853a52010-09-13 19:15:083568 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093569 if (error_page_url.is_valid()) {
3570 WebURLError original_error;
3571 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173572
[email protected]06333afe2011-02-24 14:55:093573 navigation_state->set_alt_error_page_fetcher(
3574 new AltErrorPageResourceFetcher(
3575 error_page_url, frame, original_error,
3576 NewCallback(this, &RenderView::AltErrorPageFinished)));
3577 return;
3578 }
3579 }
[email protected]3d9689372009-09-10 04:29:173580
[email protected]06333afe2011-02-24 14:55:093581 // Use an internal error page, if we have one for the status code.
3582 if (LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3583 http_status_code)) {
[email protected]3f853a52010-09-13 19:15:083584 WebURLError error;
3585 error.unreachableURL = frame->url();
3586 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3587 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173588
[email protected]3f853a52010-09-13 19:15:083589 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3590 std::string(), true);
3591 }
[email protected]3d9689372009-09-10 04:29:173592}
3593
3594void RenderView::didFailResourceLoad(
3595 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3596 // Ignore
3597}
3598
3599void RenderView::didLoadResourceFromMemoryCache(
3600 WebFrame* frame, const WebURLRequest& request,
3601 const WebURLResponse& response) {
3602 // Let the browser know we loaded a resource from the memory cache. This
3603 // message is needed to display the correct SSL indicators.
3604 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3605 routing_id_,
3606 request.url(),
[email protected]3d9689372009-09-10 04:29:173607 response.securityInfo()));
3608}
3609
[email protected]6069da8c2009-10-20 20:33:493610void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293611 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3612}
3613
[email protected]92771112011-01-20 00:13:023614void RenderView::didRunInsecureContent(
3615 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293616 Send(new ViewHostMsg_DidRunInsecureContent(
3617 routing_id_,
[email protected]92771112011-01-20 00:13:023618 origin.toString().utf8(),
3619 target));
[email protected]e3d60e5d2009-09-25 21:08:293620}
3621
[email protected]7ea093ba2009-11-03 05:54:593622bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403623 if (enabled_per_settings &&
3624 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3625 return true;
[email protected]7ea093ba2009-11-03 05:54:593626
[email protected]12bc8472010-04-15 07:29:403627 if (IsWhitelistedForContentSettings(frame))
3628 return true;
[email protected]7ea093ba2009-11-03 05:54:593629
3630 return false; // Other protocols fall through here.
3631}
3632
[email protected]0a1a45432010-03-31 08:09:453633bool RenderView::allowDatabase(
3634 WebFrame* frame, const WebString& name, const WebString& display_name,
3635 unsigned long estimated_size) {
3636 WebSecurityOrigin origin = frame->securityOrigin();
3637 if (origin.isEmpty())
3638 return false; // Uninitialized document?
3639
3640 bool result;
[email protected]26a9acf2010-12-13 19:35:053641 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453642 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3643 return false;
[email protected]9fb83e82010-07-02 18:24:553644 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3645 GURL(origin.toString().utf8()),
3646 name,
3647 display_name,
3648 estimated_size,
3649 !result));
[email protected]0a1a45432010-03-31 08:09:453650 return result;
3651}
[email protected]8934a3b2010-02-25 00:34:003652void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283653 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003654}
3655
[email protected]c21f1d52010-03-04 03:19:433656void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283657 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433658}
3659
[email protected]3d9689372009-09-10 04:29:173660void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3661 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3662}
3663
[email protected]0c882b282009-10-07 17:01:283664void RenderView::didCreateScriptContext(WebFrame* frame) {
3665 EventBindings::HandleContextCreated(frame, false);
3666}
3667
3668void RenderView::didDestroyScriptContext(WebFrame* frame) {
3669 EventBindings::HandleContextDestroyed(frame);
3670}
3671
3672void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3673 EventBindings::HandleContextCreated(frame, true);
3674}
3675
[email protected]af7eb3fb2010-09-23 21:31:063676bool RenderView::allowScriptExtension(WebFrame* frame,
3677 const WebString& extension_name,
3678 int extension_group) {
3679 // NULL in unit tests.
3680 if (!RenderThread::current())
3681 return true;
3682
3683 // Note: we prefer the provisional URL here instead of the document URL
3684 // because we might be currently loading an URL into a blank page.
3685 // See http://code.google.com/p/chromium/issues/detail?id=10924
3686 WebDataSource* ds = frame->provisionalDataSource();
3687 if (!ds)
3688 ds = frame->dataSource();
3689 return RenderThread::current()->AllowScriptExtension(
3690 extension_name.utf8(), ds->request().url(), extension_group);
3691}
3692
[email protected]fc86daa2010-03-30 23:52:533693void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3694 WebFrame* target,
3695 bool cross_origin,
3696 const WebString& property_name,
3697 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103698 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363699 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103700}
3701
[email protected]3d9689372009-09-10 04:29:173702void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143703 CheckPreferredSize();
3704}
3705
3706void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173707 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253708 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173709 // message.
[email protected]705243f2010-05-05 19:58:073710 if (!send_preferred_size_changes_ || !webview())
3711 return;
[email protected]dfca5acf2010-03-22 03:28:433712
[email protected]705243f2010-05-05 19:58:073713 // WebCore likes to tell us things have changed even when they haven't, so
3714 // cache the width and height and only send the IPC message when we're sure
3715 // they're different.
3716 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3717 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533718
3719 // In the presence of zoom, these sizes are still reported as if unzoomed,
3720 // so we need to adjust.
3721 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3722 size.set_width(static_cast<int>(size.width() * zoom_factor));
3723 size.set_height(static_cast<int>(size.height() * zoom_factor));
3724
[email protected]705243f2010-05-05 19:58:073725 if (size == preferred_size_)
3726 return;
[email protected]c27324b2009-11-19 22:44:293727
[email protected]705243f2010-05-05 19:58:073728 preferred_size_ = size;
3729 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3730 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173731}
3732
[email protected]143dcd592009-11-06 21:33:493733void RenderView::didChangeScrollOffset(WebFrame* frame) {
3734 StartNavStateSyncTimerIfNecessary();
3735}
3736
[email protected]8922e1f2009-10-03 05:01:263737void RenderView::reportFindInPageMatchCount(int request_id, int count,
3738 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113739 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3740 if (!count)
3741 active_match_ordinal = 0;
3742
3743 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3744 routing_id_,
3745 request_id,
3746 count,
3747 gfx::Rect(),
3748 active_match_ordinal,
3749 final_update);
3750
[email protected]8922e1f2009-10-03 05:01:263751 // If we have a message that has been queued up, then we should just replace
3752 // it. The ACK from the browser will make sure it gets sent when the browser
3753 // wants it.
3754 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263755 queued_find_reply_message_.reset(msg);
3756 } else {
3757 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113758 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263759 }
3760}
3761
3762void RenderView::reportFindInPageSelection(int request_id,
3763 int active_match_ordinal,
3764 const WebRect& selection_rect) {
3765 // Send the search result over to the browser process.
3766 Send(new ViewHostMsg_Find_Reply(routing_id_,
3767 request_id,
3768 -1,
3769 selection_rect,
3770 active_match_ordinal,
3771 false));
3772}
3773
[email protected]2b06a992010-08-21 05:48:223774void RenderView::openFileSystem(
3775 WebFrame* frame,
3776 WebFileSystem::Type type,
3777 long long size,
[email protected]d275d7a2010-11-03 01:34:493778 bool create,
[email protected]2b06a992010-08-21 05:48:223779 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083780 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223781
3782 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083783 if (origin.isEmpty()) {
3784 // Uninitialized document?
3785 callbacks->didFail(WebKit::WebFileErrorAbort);
3786 return;
3787 }
[email protected]2b06a992010-08-21 05:48:223788
[email protected]c5a272d2010-09-27 18:37:083789 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3790 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493791 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223792}
3793
[email protected]79dbc662009-09-04 05:42:513794// webkit_glue::WebPluginPageDelegate -----------------------------------------
3795
[email protected]191eb3f72010-12-21 06:27:503796webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533797 const FilePath& file_path,
3798 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593799 if (!PluginChannelHost::IsListening())
3800 return NULL;
3801
[email protected]00c39612010-03-06 02:53:283802 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463803 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:093804#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:223805 return webkit::npapi::WebPluginDelegateImpl::Create(
3806 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093807#else
[email protected]e8f7a182011-03-10 00:50:223808 NOTIMPLEMENTED();
3809 return NULL;
[email protected]7b6616f2010-01-14 18:07:553810#endif
[email protected]f103ab72009-09-02 17:10:593811 }
3812
[email protected]4e0616e2010-05-28 14:55:533813 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593814}
3815
3816void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033817#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593818 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3819 routing_id(), window));
3820#endif
3821}
3822
3823void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033824#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593825 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3826 routing_id(), window));
3827#endif
3828 CleanupWindowInPluginMoves(window);
3829}
3830
[email protected]191eb3f72010-12-21 06:27:503831void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593832 SchedulePluginMove(move);
3833}
3834
3835void RenderView::DidStartLoadingForPlugin() {
3836 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523837 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593838}
3839
3840void RenderView::DidStopLoadingForPlugin() {
3841 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523842 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593843}
3844
[email protected]b921cfd22010-02-25 16:57:513845WebCookieJar* RenderView::GetCookieJar() {
3846 return &cookie_jar_;
3847}
3848
initial.commit09911bf2008-07-26 23:55:293849void RenderView::SyncNavigationState() {
3850 if (!webview())
3851 return;
3852
[email protected]26aa0482009-09-30 16:55:273853 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173854 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293855 return;
[email protected]ca948a22009-06-25 19:36:173856
3857 Send(new ViewHostMsg_UpdateState(
3858 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293859}
3860
[email protected]b0950a72009-09-29 23:16:173861bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3862 // Make sure webview was not shut down.
3863 if (!webview())
3864 return false;
3865 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:233866 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
3867 new ImageResourceFetcher(
3868 image_url, webview()->mainFrame(), id, image_size,
3869 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:173870 return true;
3871}
3872
3873void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293874 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173875 // Notify requester of image download status.
[email protected]d8e74e82011-03-15 19:38:483876 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_,
[email protected]51bd36612009-10-20 22:49:473877 fetcher->id(),
3878 fetcher->image_url(),
3879 image.isNull(),
3880 image));
[email protected]bb461532010-11-26 21:50:233881
3882 // Remove the image fetcher from our pending list. We're in the callback from
3883 // ImageResourceFetcher, best to delay deletion.
3884 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
3885 iter != image_fetchers_.end(); ++iter) {
3886 if (iter->get() == fetcher) {
3887 iter->release();
3888 image_fetchers_.erase(iter);
3889 break;
3890 }
3891 }
[email protected]b0950a72009-09-29 23:16:173892 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293893}
3894
[email protected]d8e74e82011-03-15 19:38:483895void RenderView::OnDownloadFavicon(int id,
[email protected]bf5c2ff392009-07-08 16:24:333896 const GURL& image_url,
3897 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343898 bool data_image_failed = false;
3899 if (image_url.SchemeIs("data")) {
3900 SkBitmap data_image = ImageFromDataUrl(image_url);
3901 data_image_failed = data_image.empty();
3902 if (!data_image_failed) {
[email protected]d8e74e82011-03-15 19:38:483903 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, id, image_url, false,
[email protected]bf5c2ff392009-07-08 16:24:333904 data_image));
[email protected]f11ca0732009-04-11 00:09:343905 }
3906 }
3907
[email protected]bf5c2ff392009-07-08 16:24:333908 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173909 !DownloadImage(id, image_url, image_size)) {
[email protected]d8e74e82011-03-15 19:38:483910 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, id, image_url, true,
[email protected]bf5c2ff392009-07-08 16:24:333911 SkBitmap()));
3912 }
initial.commit09911bf2008-07-26 23:55:293913}
3914
[email protected]f11ca0732009-04-11 00:09:343915SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3916 std::string mime_type, char_set, data;
3917 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3918 // Decode the favicon using WebKit's image decoder.
[email protected]f23a8c12011-03-15 14:43:433919 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize));
[email protected]f11ca0732009-04-11 00:09:343920 const unsigned char* src_data =
3921 reinterpret_cast<const unsigned char*>(&data[0]);
3922
3923 return decoder.Decode(src_data, data.size());
3924 }
3925 return SkBitmap();
3926}
3927
initial.commit09911bf2008-07-26 23:55:293928void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:443929 WebApplicationInfo app_info;
3930 if (page_id == page_id_) {
3931 string16 error;
3932 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
3933 &error);
3934 }
initial.commit09911bf2008-07-26 23:55:293935
3936 // Prune out any data URLs in the set of icons. The browser process expects
3937 // any icon with a data URL to have originated from a favicon. We don't want
3938 // to decode arbitrary data URLs in the browser process. See
3939 // http://b/issue?id=1162972
3940 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593941 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293942 app_info.icons.erase(app_info.icons.begin() + i);
3943 --i;
3944 }
3945 }
3946
3947 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3948}
3949
[email protected]7ccddb8c2009-08-04 17:36:553950GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293951 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553952 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293953 // If the URL that failed was secure, then the embedding web page was not
3954 // expecting a network attacker to be able to manipulate its contents. As
3955 // we fetch alternate error pages over HTTP, we would be allowing a network
3956 // attacker to manipulate the contents of the response if we tried to use
3957 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153958 return GURL();
initial.commit09911bf2008-07-26 23:55:293959 }
3960
3961 // Grab the base URL from the browser process.
3962 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153963 return GURL();
initial.commit09911bf2008-07-26 23:55:293964
3965 // Strip query params from the failed URL.
3966 GURL::Replacements remove_params;
3967 remove_params.ClearUsername();
3968 remove_params.ClearPassword();
3969 remove_params.ClearQuery();
3970 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553971 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503972 std::string spec_to_send = url_to_send.spec();
3973 // Notify link doctor of the url truncation by sending of "?" at the end.
3974 if (failed_url.has_query())
3975 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293976
3977 // Construct the query params to send to link doctor.
3978 std::string params(alternate_error_page_url_.query());
3979 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503980 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293981 params.append("&sourceid=chrome");
3982 params.append("&error=");
3983 switch (error_type) {
3984 case DNS_ERROR:
3985 params.append("dnserror");
3986 break;
3987
3988 case HTTP_404:
3989 params.append("http404");
3990 break;
3991
[email protected]5df266ac2008-10-15 19:50:133992 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333993 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133994 break;
3995
initial.commit09911bf2008-07-26 23:55:293996 default:
3997 NOTREACHED() << "unknown ErrorPageType";
3998 }
3999
4000 // OK, build the final url to return.
4001 GURL::Replacements link_doctor_params;
4002 link_doctor_params.SetQueryStr(params);
4003 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4004 return url;
4005}
4006
[email protected]c50008512011-02-03 01:17:274007WebUIBindings* RenderView::GetWebUIBindings() {
4008 if (!web_ui_bindings_.get()) {
4009 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:464010 }
[email protected]c50008512011-02-03 01:17:274011 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464012}
4013
4014ExternalHostBindings* RenderView::GetExternalHostBindings() {
4015 if (!external_host_bindings_.get()) {
4016 external_host_bindings_.reset(new ExternalHostBindings());
4017 }
4018 return external_host_bindings_.get();
4019}
4020
[email protected]0fdbf8c2010-07-08 20:33:014021WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4022 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494023}
4024
[email protected]6069da8c2009-10-20 20:33:494025void RenderView::OnFind(int request_id, const string16& search_text,
4026 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274027 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494028
4029 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494030 if (options.findNext) {
4031 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014032 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494033 } else {
[email protected]afdbd142010-07-10 08:01:234034 if (GetWebPluginFromPluginDocument()->startFind(
4035 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494036 } else {
[email protected]e7c58a32010-08-13 19:47:114037 // Send "no results".
4038 Send(new ViewHostMsg_Find_Reply(routing_id_,
4039 request_id,
4040 0,
4041 gfx::Rect(),
4042 0,
4043 true));
[email protected]24a7f3c2010-03-25 08:26:494044 }
4045 }
4046 return;
4047 }
4048
[email protected]b4bb2502009-10-01 22:35:274049 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274050 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294051 WebFrame* search_frame = focused_frame; // start searching focused frame.
4052
4053 bool multi_frame = (frame_after_main != main_frame);
4054
4055 // If we have multiple frames, we don't want to wrap the search within the
4056 // frame, so we check here if we only have main_frame in the chain.
4057 bool wrap_within_frame = !multi_frame;
4058
[email protected]b3f2b912009-04-09 16:18:524059 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294060 bool result = false;
4061
[email protected]7830da3e2009-11-06 16:27:264062 // If something is selected when we start searching it means we cannot just
4063 // increment the current match ordinal; we need to re-generate it.
4064 WebRange current_selection = focused_frame->selectionRange();
4065
initial.commit09911bf2008-07-26 23:55:294066 do {
[email protected]dd7daa82009-08-10 05:46:454067 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594068 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294069
4070 if (!result) {
4071 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224072 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294073
4074 // Find the next frame, but skip the invisible ones.
4075 do {
4076 // What is the next frame to search? (we might be going backwards). Note
4077 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594078 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274079 search_frame->traverseNext(true) :
4080 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454081 } while (!search_frame->hasVisibleContent() &&
4082 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294083
[email protected]884db412008-11-24 23:46:504084 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224085 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294086
4087 // If we have multiple frames and we have wrapped back around to the
4088 // focused frame, we need to search it once more allowing wrap within
4089 // the frame, otherwise it will report 'no match' if the focused frame has
4090 // reported matches, but no frames after the focused_frame contain a
4091 // match for the search word(s).
4092 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454093 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594094 request_id, search_text, options, true, // Force wrapping.
4095 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294096 }
4097 }
4098
[email protected]26aa0482009-09-30 16:55:274099 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294100 } while (!result && search_frame != focused_frame);
4101
[email protected]7830da3e2009-11-06 16:27:264102 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294103 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454104 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294105 } else {
4106 // If nothing is found, set result to "0 of 0", otherwise, set it to
4107 // "-1 of 1" to indicate that we found at least one item, but we don't know
4108 // yet what is active.
4109 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4110 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294111
[email protected]4f3dc372009-02-24 00:10:294112 // If we find no matches then this will be our last status update.
4113 // Otherwise the scoping effort will send more results.
4114 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294115
[email protected]4f3dc372009-02-24 00:10:294116 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404117 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594118 request_id,
[email protected]4f3dc372009-02-24 00:10:294119 match_count,
4120 selection_rect,
4121 ordinal,
4122 final_status_update));
initial.commit09911bf2008-07-26 23:55:294123
initial.commit09911bf2008-07-26 23:55:294124 // Scoping effort begins, starting with the mainframe.
4125 search_frame = main_frame;
4126
[email protected]dd7daa82009-08-10 05:46:454127 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294128
4129 do {
4130 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454131 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294132
4133 // We don't start another scoping effort unless at least one match has
4134 // been found.
4135 if (result) {
4136 // Start new scoping request. If the scoping function determines that it
4137 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454138 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594139 search_text,
4140 options,
initial.commit09911bf2008-07-26 23:55:294141 true); // reset the tickmarks
4142 }
4143
4144 // Iterate to the next frame. The frame will not necessarily scope, for
4145 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274146 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294147 } while (search_frame != main_frame);
4148 }
4149}
4150
[email protected]24a7f3c2010-03-25 08:26:494151void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4152 WebView* view = webview();
4153 if (!view)
4154 return;
4155
4156 WebDocument doc = view->mainFrame()->document();
4157 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014158 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494159 return;
4160 }
4161
4162 bool clear_selection =
4163 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4164 if (clear_selection)
4165 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4166
4167 WebFrame* frame = view->mainFrame();
4168 while (frame) {
4169 frame->stopFinding(clear_selection);
4170 frame = frame->traverseNext(false);
4171 }
4172
4173 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4174 WebFrame* focused_frame = view->focusedFrame();
4175 if (focused_frame) {
4176 WebDocument doc = focused_frame->document();
4177 if (!doc.isNull()) {
4178 WebNode node = doc.focusedNode();
4179 if (!node.isNull())
4180 node.simulateClick();
4181 }
4182 }
4183 }
4184}
4185
4186void RenderView::OnFindReplyAck() {
4187 // Check if there is any queued up request waiting to be sent.
4188 if (queued_find_reply_message_.get()) {
4189 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424190 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494191 }
4192}
4193
[email protected]8934a3b2010-02-25 00:34:004194bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354195 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004196 return current_content_settings_.settings[settings_type] !=
4197 CONTENT_SETTING_BLOCK;
4198}
4199
[email protected]55126132010-08-19 14:53:284200void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4201 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004202 if (!content_blocked_[settings_type]) {
4203 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284204 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4205 resource_identifier));
[email protected]0de80162010-02-03 04:52:354206 }
[email protected]0de80162010-02-03 04:52:354207}
4208
[email protected]71b0d5d2010-02-15 05:43:074209void RenderView::ClearBlockedContentSettings() {
4210 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4211 content_blocked_[i] = false;
4212}
4213
[email protected]0bd753682010-12-16 18:15:524214WebPlugin* RenderView::CreatePepperPlugin(
4215 WebFrame* frame,
4216 const WebPluginParams& params,
4217 const FilePath& path,
4218 webkit::ppapi::PluginModule* pepper_module) {
4219 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254220 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094221}
[email protected]00152e92010-07-19 11:47:404222
[email protected]191eb3f72010-12-21 06:27:504223WebPlugin* RenderView::CreateNPAPIPlugin(
4224 WebFrame* frame,
4225 const WebPluginParams& params,
4226 const FilePath& path,
4227 const std::string& mime_type) {
4228 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084229 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404230}
4231
[email protected]40bd6582009-12-04 23:49:514232void RenderView::OnZoom(PageZoom::Function function) {
4233 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4234 return;
4235
[email protected]258d31122010-05-09 10:59:414236 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524237
[email protected]b75b8292010-10-01 07:28:254238 double old_zoom_level = webview()->zoomLevel();
4239 double zoom_level;
4240 if (function == PageZoom::RESET) {
4241 zoom_level = 0;
4242 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4243 // Previous zoom level is a whole number, so just increment/decrement.
4244 zoom_level = old_zoom_level + function;
4245 } else {
4246 // Either the user hit the zoom factor limit and thus the zoom level is now
4247 // not a whole number, or a plugin changed it to a custom value. We want
4248 // to go to the next whole number so that the user can always get back to
4249 // 100% with the keyboard/menu.
4250 if ((old_zoom_level > 1 && function > 0) ||
4251 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454252 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254253 } else {
4254 // We're going towards 100%, so first go to the next whole number.
4255 zoom_level = static_cast<int>(old_zoom_level);
4256 }
4257 }
[email protected]40bd6582009-12-04 23:49:514258
[email protected]b75b8292010-10-01 07:28:254259 webview()->setZoomLevel(false, zoom_level);
4260 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514261}
4262
[email protected]d0b8d092010-10-25 04:05:174263void RenderView::OnSetZoomLevel(double zoom_level) {
4264 // Don't set zoom level for full-page plugin since they don't use the same
4265 // zoom settings.
4266 if (webview()->mainFrame()->document().isPluginDocument())
4267 return;
4268
4269 webview()->hidePopups();
4270 webview()->setZoomLevel(false, zoom_level);
4271 zoomLevelChanged();
4272}
4273
[email protected]9d797f32010-04-23 07:17:544274void RenderView::OnSetContentSettingsForLoadingURL(
4275 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014276 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544277 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014278}
4279
[email protected]9d797f32010-04-23 07:17:544280void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254281 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544282 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294283}
4284
[email protected]41fc0322009-09-04 22:23:404285void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274286 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294287}
4288
[email protected]a697f4c2009-09-14 22:30:184289void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274290 WebString no_encoding;
4291 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184292}
4293
[email protected]20ad2692009-11-20 18:27:204294bool RenderView::GetAllChildFrames(
4295 WebFrame* parent_frame,
4296 std::vector<WebFrame*>* frames_vector) const {
4297 if (!parent_frame)
4298 return false;
4299 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4300 child_frame = child_frame->nextSibling()) {
4301 frames_vector->push_back(child_frame);
4302 GetAllChildFrames(child_frame, frames_vector);
4303 }
4304 return true;
4305}
4306
[email protected]dd7daa82009-08-10 05:46:454307WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4308 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274309 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454310
4311 // xpath string can represent a frame deep down the tree (across multiple
4312 // frame DOMs).
4313 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4314 // should break into 2 xpaths
4315 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4316
[email protected]26aa0482009-09-30 16:55:274317 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454318
4319 std::wstring xpath_remaining = xpath;
4320 while (!xpath_remaining.empty()) {
4321 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4322 std::wstring xpath_child;
4323 if (delim_pos != std::wstring::npos) {
4324 xpath_child = xpath_remaining.substr(0, delim_pos);
4325 xpath_remaining.erase(0, delim_pos + 1);
4326 } else {
4327 xpath_remaining.swap(xpath_child);
4328 }
4329 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294330 }
4331
[email protected]dd7daa82009-08-10 05:46:454332 return frame;
initial.commit09911bf2008-07-26 23:55:294333}
4334
[email protected]13a1e4c3c2011-02-03 21:07:094335WebNode RenderView::GetFocusedNode() const {
4336 if (!webview())
4337 return WebNode();
4338 WebFrame* focused_frame = webview()->focusedFrame();
4339 if (focused_frame) {
4340 WebDocument doc = focused_frame->document();
4341 if (!doc.isNull())
4342 return doc.focusedNode();
4343 }
4344
4345 return WebNode();
4346}
4347
[email protected]882b7b22010-10-05 03:34:534348void RenderView::EvaluateScript(const string16& frame_xpath,
4349 const string16& script,
4350 int id,
4351 bool notify_result) {
4352 v8::Handle<v8::Value> result;
4353 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4354 if (web_frame)
4355 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4356 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294357 ListValue list;
4358 if (web_frame) {
4359 v8::HandleScope handle_scope;
4360 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4361 v8::Context::Scope context_scope(context);
4362 list.Set(0, ConvertV8Value(result));
4363 } else {
4364 list.Set(0, Value::CreateNullValue());
4365 }
4366 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534367 }
initial.commit09911bf2008-07-26 23:55:294368}
4369
[email protected]1810e132009-03-24 23:35:484370void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084371 const std::string& css,
4372 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484373 WebFrame* web_frame = GetChildFrame(frame_xpath);
4374 if (!web_frame)
4375 return;
4376
[email protected]ffaef0c2009-09-15 17:08:084377 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484378}
4379
[email protected]882b7b22010-10-05 03:34:534380void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4381 const string16& jscript,
4382 int id,
4383 bool notify_result) {
4384 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294385}
4386
[email protected]1810e132009-03-24 23:35:484387void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084388 const std::string& css,
4389 const std::string& id) {
4390 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414391
4392 // Notify RenderViewHost that css has been inserted into the frame.
4393 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484394}
4395
[email protected]7ea066a2009-04-06 20:21:594396void RenderView::OnAddMessageToConsole(
4397 const string16& frame_xpath,
4398 const string16& message,
4399 const WebConsoleMessage::Level& level) {
4400 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594401 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454402 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294403}
4404
[email protected]81e63782009-02-27 19:35:094405void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4406 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294407}
4408
[email protected]d0980792011-02-13 19:41:404409void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:294410 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:554411 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:274412 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294413}
4414
4415void RenderView::OnReservePageIDRange(int size_of_range) {
4416 next_page_id_ += size_of_range + 1;
4417}
4418
[email protected]e80c73b2009-04-07 23:24:584419void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4420 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254421 bool ended,
4422 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034423 if (ended) {
[email protected]26aa0482009-09-30 16:55:274424 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204425 } else {
4426 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034427 }
initial.commit09911bf2008-07-26 23:55:294428}
4429
4430void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274431 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294432}
4433
initial.commit09911bf2008-07-26 23:55:294434void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584435 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254436 const gfx::Point& screen_point,
4437 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274438 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584439 drop_data.ToDragData(),
[email protected]50285ff2011-03-11 23:10:564440 0, // drag identity, unused
[email protected]e80c73b2009-04-07 23:24:584441 client_point,
[email protected]1d9f4132009-09-08 17:29:254442 screen_point,
4443 ops);
initial.commit09911bf2008-07-26 23:55:294444
[email protected]1d9f4132009-09-08 17:29:254445 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294446}
4447
[email protected]e80c73b2009-04-07 23:24:584448void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254449 const gfx::Point& screen_point,
4450 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274451 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254452 client_point,
4453 screen_point,
4454 ops);
initial.commit09911bf2008-07-26 23:55:294455
[email protected]1d9f4132009-09-08 17:29:254456 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294457}
4458
4459void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274460 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294461}
4462
[email protected]e80c73b2009-04-07 23:24:584463void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4464 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274465 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294466}
4467
4468void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594469 webkit_preferences_ = prefs;
4470 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294471}
4472
4473void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4474 alternate_error_page_url_ = url;
4475}
4476
[email protected]b29aa74b2011-01-31 21:41:084477void RenderView::OnCustomContextMenuAction(
4478 const webkit_glue::CustomContextMenuContext& custom_context,
4479 unsigned action) {
4480 if (custom_context.is_pepper_menu)
4481 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4482 else
4483 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334484}
4485
initial.commit09911bf2008-07-26 23:55:294486void RenderView::OnInstallMissingPlugin() {
4487 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594488 if (first_default_plugin_)
4489 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294490}
4491
[email protected]90dba072011-01-20 20:10:204492void RenderView::OnDisplayPrerenderedPage() {
[email protected]987d51af2011-02-24 17:50:184493 DCHECK(is_prerendering_);
4494 is_prerendering_ = false;
[email protected]90dba072011-01-20 20:10:204495
[email protected]987d51af2011-02-24 17:50:184496 // Update NavigationState for histograms.
4497 WebDataSource* ds = webview()->mainFrame()->dataSource();
4498 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]e0b181752011-02-13 23:56:434499 navigation_state->set_prerendered_page_display_time(Time::Now());
[email protected]987d51af2011-02-24 17:50:184500
4501 // If there is a provisional data source, update its NavigationState, too.
4502 WebDataSource* provisional_ds =
4503 webview()->mainFrame()->provisionalDataSource();
4504 if (provisional_ds) {
4505 NavigationState* provisional_navigation_state =
4506 NavigationState::FromDataSource(provisional_ds);
4507 if (provisional_navigation_state) {
4508 provisional_navigation_state->set_prerendered_page_display_time(
4509 Time::Now());
4510 }
4511 }
[email protected]90dba072011-01-20 20:10:204512}
4513
[email protected]cdaf8d02010-03-30 19:52:474514void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364515 // This could happen if we navigated to a different page before the user
4516 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474517 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364518 return;
4519
[email protected]cdaf8d02010-03-30 19:52:474520 WebVector<WebString> ws_file_names(paths.size());
4521 for (size_t i = 0; i < paths.size(); ++i)
4522 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464523
[email protected]cdaf8d02010-03-30 19:52:474524 if (file_chooser_completions_.front()->completion)
4525 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4526 file_chooser_completions_.pop_front();
4527
4528 // If there are more pending file chooser requests, schedule one now.
4529 if (!file_chooser_completions_.empty()) {
4530 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4531 file_chooser_completions_.front()->params));
4532 }
initial.commit09911bf2008-07-26 23:55:294533}
4534
4535void RenderView::OnEnableViewSourceMode() {
4536 if (!webview())
4537 return;
[email protected]26aa0482009-09-30 16:55:274538 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294539 if (!main_frame)
4540 return;
4541
[email protected]dd7daa82009-08-10 05:46:454542 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294543}
4544
[email protected]770dd8b2010-05-24 18:11:394545void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4546 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244547 if (send_preferred_size_changes_)
4548 return;
[email protected]9fb325e2010-05-06 18:23:244549 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394550
4551 // WebKit doesn't send a notification of the effective height of the page
4552 // changes, so poll for it.
4553 // TODO: Add a notification for this to WebKit, remove polling. After that's
4554 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4555 // http://crbug.com/44850
4556 if (flags & kPreferredSizeHeightThisIsSlow) {
4557 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4558 &RenderView::CheckPreferredSize);
4559 }
[email protected]0666aef2009-05-13 19:48:084560}
4561
[email protected]cda45c02010-02-25 19:28:104562void RenderView::OnDisableScrollbarsForSmallWindows(
4563 const gfx::Size& disable_scrollbar_size_limit) {
4564 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4565}
4566
[email protected]80d96fa2009-06-10 22:34:514567void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4568 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374569 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134570#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414571 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4572 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464573 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344574 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4575 renderer_prefs.thumb_inactive_color,
4576 renderer_prefs.thumb_active_color,
4577 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324578
[email protected]644d77e2010-01-27 01:03:104579 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324580 webview()->setScrollbarColors(
4581 renderer_prefs.thumb_inactive_color,
4582 renderer_prefs.thumb_active_color,
4583 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104584 webview()->setSelectionColors(
4585 renderer_prefs.active_selection_bg_color,
4586 renderer_prefs.active_selection_fg_color,
4587 renderer_prefs.inactive_selection_bg_color,
4588 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464589 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104590 }
[email protected]7a74e102009-09-03 00:16:564591#endif
[email protected]80d96fa2009-06-10 22:34:514592}
4593
[email protected]952cb702009-10-07 05:50:284594void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4595 const WebMediaPlayerAction& action) {
4596 if (webview())
4597 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564598}
4599
[email protected]7b291f92009-08-14 05:43:534600void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4601 view_type_ = type;
4602}
4603
4604void RenderView::OnUpdateBrowserWindowId(int window_id) {
4605 browser_window_id_ = window_id;
4606}
4607
[email protected]dea2d372010-09-25 06:41:144608void RenderView::OnEnableAccessibility() {
4609 if (WebAccessibilityCache::accessibilityEnabled())
4610 return;
[email protected]9f4db512010-05-10 20:21:414611
[email protected]dea2d372010-09-25 06:41:144612 WebAccessibilityCache::enableAccessibility();
4613
4614 if (webview()) {
4615 // It's possible that the webview has already loaded a webpage without
4616 // accessibility being enabled. Initialize the browser's cached
4617 // accessibility tree by sending it a 'load complete' notification.
4618 postAccessibilityNotification(
4619 webview()->accessibilityObject(),
4620 WebKit::WebAccessibilityNotificationLoadComplete);
4621 }
[email protected]266eb6f2008-09-30 23:56:504622}
4623
[email protected]aef92842010-05-21 16:54:364624void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4625 if (!accessibility_.get())
4626 return;
[email protected]02ea2f312010-09-27 17:03:364627
4628 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4629 WebAccessibilityObject root = webview()->accessibilityObject();
4630 if (!obj.isValid() || !root.isValid())
4631 return;
4632
4633 // By convention, calling SetFocus on the root of the tree should clear the
4634 // current focus. Otherwise set the focus to the new node.
4635 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4636 webview()->clearFocusedNode();
4637 else
4638 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364639}
4640
4641void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4642 if (!accessibility_.get())
4643 return;
[email protected]02ea2f312010-09-27 17:03:364644
4645 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4646 if (!obj.isValid())
4647 return;
4648
4649 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364650}
4651
[email protected]9892b472010-09-16 00:23:424652void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514653 DCHECK(accessibility_ack_pending_);
4654 accessibility_ack_pending_ = false;
4655 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314656}
4657
initial.commit09911bf2008-07-26 23:55:294658void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4659 const GURL& page_url) {
4660 // Prepare list to storage all savable resource links.
4661 std::vector<GURL> resources_list;
4662 std::vector<GURL> referrers_list;
4663 std::vector<GURL> frames_list;
4664 webkit_glue::SavableResourcesResult result(&resources_list,
4665 &referrers_list,
4666 &frames_list);
4667
[email protected]dbeb3952009-10-13 18:01:184668 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4669 webview(),
4670 page_url,
4671 &result,
4672 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294673 // If something is wrong when collecting all savable resource links,
4674 // send empty list to embedder(browser) to tell it failed.
4675 referrers_list.clear();
4676 resources_list.clear();
4677 frames_list.clear();
4678 }
4679
4680 // Send result of all savable resource links to embedder.
4681 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4682 resources_list,
4683 referrers_list,
4684 frames_list));
4685}
4686
4687void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324688 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314689 const std::vector<FilePath>& local_paths,
4690 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074691
4692 // Convert std::vector of GURLs to WebVector<WebURL>
4693 WebVector<WebURL> weburl_links(links);
4694
4695 // Convert std::vector of std::strings to WebVector<WebString>
4696 WebVector<WebString> webstring_paths(local_paths.size());
4697 for (size_t i = 0; i < local_paths.size(); i++)
4698 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4699
4700 WebPageSerializer::serialize(webview()->mainFrame(),
4701 true, this, weburl_links, webstring_paths,
4702 webkit_glue::FilePathToWebString(
4703 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294704}
4705
[email protected]d9ec5c0f2009-12-23 11:55:074706void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4707 const WebCString& data,
4708 WebPageSerializerClient::PageSerializationStatus status) {
4709 Send(new ViewHostMsg_SendSerializedHtmlData(
4710 routing_id_,
4711 frame_url,
4712 data.data(),
4713 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294714}
4715
[email protected]9b18a84f2010-06-10 15:54:044716void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274717 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474718 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294719}
4720
[email protected]eb6b87a2009-07-24 15:57:394721void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294722 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4723 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4724 // in the onunload handler from appearing. For now, we're bypassing that and
4725 // calling the FrameLoader's CloseURL method directly. This should be
4726 // revisited to avoid having two ways to close a page. Having a single way
4727 // to close that can run onunload is also useful for fixing
4728 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:364729 // TODO(davemoore) This code should be removed once willClose() gets
4730 // called when a page is destroyed. page_load_histograms_.Dump() is safe
4731 // to call multiple times for the same frame, but it will simplify things.
4732 page_load_histograms_.Dump(webview()->mainFrame());
4733 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:274734 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294735
[email protected]eb6b87a2009-07-24 15:57:394736 // Just echo back the params in the ACK.
4737 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294738}
4739
4740void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574741#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294742 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464743 if (webview())
4744 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574745#else // defined(OS_WIN)
4746 // TODO(port): we don't support theming on non-Windows platforms yet
4747 NOTIMPLEMENTED();
4748#endif
initial.commit09911bf2008-07-26 23:55:294749}
4750
[email protected]9b18a84f2010-06-10 15:54:044751void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4752 const std::string& origin,
4753 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154754 if (message.empty())
4755 return;
[email protected]c091c2c2010-09-17 19:05:464756 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
4757 target);
[email protected]3ac14a052008-08-15 21:22:154758}
4759
[email protected]0aa55312008-10-17 21:53:084760void RenderView::OnDisassociateFromPopupCount() {
4761 if (decrement_shared_popup_at_destruction_)
4762 shared_popup_counter_->data--;
4763 shared_popup_counter_ = new SharedRenderViewCounter(0);
4764 decrement_shared_popup_at_destruction_ = false;
4765}
4766
[email protected]15d79e12009-08-02 19:23:454767bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4768 const WebURLError& error,
4769 bool replace) {
4770 // We only show alternate error pages in the main frame. They are
4771 // intended to assist the user when navigating, so there is not much
4772 // value in showing them for failed subframes. Ideally, we would be
4773 // able to use the TYPED transition type for this, but that flag is
4774 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454775 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454776 return false;
4777
4778 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374779 // connection failure.
[email protected]15d79e12009-08-02 19:23:454780 int ec = error.reason;
4781 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4782 ec != net::ERR_CONNECTION_FAILED &&
4783 ec != net::ERR_CONNECTION_REFUSED &&
4784 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374785 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454786 return false;
4787
4788 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554789 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454790 if (!error_page_url.is_valid())
4791 return false;
4792
4793 // Load an empty page first so there is an immediate response to the error,
4794 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454795 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364796 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454797 error.unreachableURL,
4798 replace);
4799
4800 // Now, create a fetcher for the error page and associate it with the data
4801 // source we just created via the LoadHTMLString call. That way if another
4802 // navigation occurs, the fetcher will get destroyed.
4803 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454804 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454805 navigation_state->set_alt_error_page_fetcher(
4806 new AltErrorPageResourceFetcher(
4807 error_page_url, frame, error,
4808 NewCallback(this, &RenderView::AltErrorPageFinished)));
4809 return true;
4810}
4811
[email protected]15d79e12009-08-02 19:23:454812void RenderView::AltErrorPageFinished(WebFrame* frame,
4813 const WebURLError& original_error,
4814 const std::string& html) {
4815 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094816 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554817 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094818 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454819}
4820
[email protected]30f75e62009-02-25 22:01:004821void RenderView::OnMoveOrResizeStarted() {
4822 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474823 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004824}
4825
[email protected]30f75e62009-02-25 22:01:004826void RenderView::OnResize(const gfx::Size& new_size,
4827 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104828 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474829 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104830 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204831 webview()->mainFrame()->setCanHaveScrollbars(
4832 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104833 }
4834 }
4835
[email protected]30f75e62009-02-25 22:01:004836 RenderWidget::OnResize(new_size, resizer_rect);
4837}
[email protected]0aa477bd2009-03-23 22:21:434838
[email protected]00c39612010-03-06 02:53:284839void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014840 // Notify the pepper plugins that we started painting.
4841 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284842}
4843
4844void RenderView::DidFlushPaint() {
4845 // Notify any pepper plugins that we painted. This will call into the plugin,
4846 // and we it may ask to close itself as a result. This will, in turn, modify
4847 // our set, possibly invalidating the iterator. So we iterate on a copy that
4848 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014849 pepper_delegate_.ViewFlushedPaint();
4850
[email protected]00c39612010-03-06 02:53:284851 WebFrame* main_frame = webview()->mainFrame();
4852
4853 // If we have a provisional frame we are between the start and commit stages
4854 // of loading and we don't want to save stats.
4855 if (!main_frame->provisionalDataSource()) {
4856 WebDataSource* ds = main_frame->dataSource();
4857 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4858 DCHECK(navigation_state);
4859
[email protected]05c8e502010-08-15 15:13:524860 // TODO(jar): The following code should all be inside a method, probably in
4861 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284862 Time now = Time::Now();
4863 if (navigation_state->first_paint_time().is_null()) {
4864 navigation_state->set_first_paint_time(now);
4865 }
4866 if (navigation_state->first_paint_after_load_time().is_null() &&
4867 !navigation_state->finish_load_time().is_null()) {
4868 navigation_state->set_first_paint_after_load_time(now);
4869 }
4870 }
4871}
4872
[email protected]719b36f2010-12-22 20:36:464873webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154874 const gfx::Rect& paint_bounds,
4875 TransportDIB** dib,
4876 gfx::Rect* location,
4877 gfx::Rect* clip) {
4878 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4879 paint_bounds, dib, location, clip);
4880}
4881
[email protected]bcaf2272011-02-15 15:29:434882gfx::Point RenderView::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:524883 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434884 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524885}
4886
[email protected]05d478752009-04-08 23:38:164887void RenderView::OnClearFocusedNode() {
4888 if (webview())
[email protected]26aa0482009-09-30 16:55:274889 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164890}
4891
[email protected]699ab0d2009-04-23 23:19:144892void RenderView::OnSetBackground(const SkBitmap& background) {
4893 if (webview())
[email protected]b4bb2502009-10-01 22:35:274894 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144895
4896 SetBackground(background);
4897}
4898
[email protected]8c66c5a2009-07-22 17:26:344899void RenderView::OnSetActive(bool active) {
4900 if (webview())
[email protected]b4bb2502009-10-01 22:35:274901 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264902
4903#if defined(OS_MACOSX)
4904 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4905 for (plugin_it = plugin_delegates_.begin();
4906 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4907 (*plugin_it)->SetWindowFocus(active);
4908 }
4909#endif
[email protected]8c66c5a2009-07-22 17:26:344910}
4911
[email protected]6ce7abc52010-02-02 18:40:144912#if defined(OS_MACOSX)
4913void RenderView::OnSetWindowVisibility(bool visible) {
4914 // Inform plugins that their container has changed visibility.
4915 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4916 for (plugin_it = plugin_delegates_.begin();
4917 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4918 (*plugin_it)->SetContainerVisibility(visible);
4919 }
4920}
[email protected]1e6e3c992010-02-08 15:52:134921
[email protected]4d51d5bf2010-07-26 18:48:264922void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4923 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134924 // Inform plugins that their window's frame has changed.
4925 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4926 for (plugin_it = plugin_delegates_.begin();
4927 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4928 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4929 }
4930}
[email protected]935d63d2010-10-15 23:31:554931
[email protected]b7f75862011-01-21 21:15:134932void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:554933 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134934 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554935 // applies to it or not, so inform all the delegates.
4936 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4937 for (plugin_it = plugin_delegates_.begin();
4938 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134939 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554940 }
4941}
[email protected]6ce7abc52010-02-02 18:40:144942#endif // OS_MACOSX
4943
[email protected]8b8e7c92010-08-19 18:05:564944void RenderView::SendExtensionRequest(
4945 const ViewHostMsg_DomMessage_Params& params) {
4946 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:274947}
4948
[email protected]c6619182009-05-12 14:59:324949void RenderView::OnExtensionResponse(int request_id,
4950 bool success,
4951 const std::string& response,
4952 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354953 ExtensionProcessBindings::HandleResponse(
4954 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274955}
[email protected]c20210e62009-04-03 21:39:264956
[email protected]a7ab1b782010-10-21 23:24:164957void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
4958 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494959 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194960 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494961 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:164962 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:374963}
4964
[email protected]9892b472010-09-16 00:23:424965void RenderView::postAccessibilityNotification(
4966 const WebAccessibilityObject& obj,
4967 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:144968 if (!accessibility_.get() && webview()) {
4969 // Load complete should be our first notification sent.
4970 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
4971 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
4972 return;
4973
4974 // Create and initialize our accessibility cache
4975 accessibility_.reset(WebAccessibilityCache::create());
4976 accessibility_->initialize(webview());
4977 }
4978
[email protected]a3fa4f92010-09-30 22:19:334979 if (!accessibility_->isCached(obj)) {
4980 // The browser doesn't know about objects that are not in the cache. Send a
4981 // children change for the first accestor that actually is in the cache.
4982 WebAccessibilityObject parent = obj;
4983 while (parent.isValid() && !accessibility_->isCached(parent))
4984 parent = parent.parentObject();
4985
4986 DCHECK(parent.isValid() && accessibility_->isCached(parent));
4987 if (!parent.isValid())
4988 return;
4989 postAccessibilityNotification(
4990 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
4991
4992 // The parent's children change takes care of the child's children change.
4993 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
4994 return;
4995 }
4996
[email protected]dea2d372010-09-25 06:41:144997 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:514998 RendererAccessibilityNotification acc_notification;
4999 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:365000 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:515001 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485002 return;
5003
[email protected]a527a022011-02-10 02:32:365004 ViewHostMsg_AccessibilityNotification_Params::NotificationType temp;
5005 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:515006 return;
[email protected]54ec7f82010-10-21 22:32:515007
5008 // Discard duplicate accessibility notifications.
5009 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5010 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5011 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425012 return;
[email protected]54ec7f82010-10-21 22:32:515013 }
[email protected]9892b472010-09-16 00:23:425014 }
[email protected]54ec7f82010-10-21 22:32:515015 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485016
[email protected]54ec7f82010-10-21 22:32:515017 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5018 // When no accessibility notifications are in-flight post a task to send
5019 // the notifications to the browser. We use PostTask so that we can queue
5020 // up additional notifications.
5021 MessageLoop::current()->PostTask(
5022 FROM_HERE,
5023 accessibility_method_factory_.NewRunnableMethod(
5024 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315025 }
[email protected]520cb7d72010-08-31 11:54:315026}
5027
[email protected]446705872009-09-10 07:22:485028void RenderView::OnSetEditCommandsForNextKeyEvent(
5029 const EditCommands& edit_commands) {
5030 edit_commands_ = edit_commands;
5031}
5032
[email protected]61f5a7b2009-12-22 22:21:205033void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275034 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355035 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205036 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5037 false));
[email protected]912256b32009-09-18 09:47:355038 return;
5039 }
5040
[email protected]fa7b6b542009-11-03 05:02:305041 WebDataSource* ds = main_frame->dataSource();
5042 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5043 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205044 pending_code_execution_queue_.push(
5045 linked_ptr<ViewMsg_ExecuteCode_Params>(
5046 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305047 return;
5048 }
5049
[email protected]61f5a7b2009-12-22 22:21:205050 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305051}
5052
5053void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205054 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205055 std::vector<WebFrame*> frame_vector;
5056 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205057 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205058 GetAllChildFrames(frame, &frame_vector);
5059
5060 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5061 frame_it != frame_vector.end(); ++frame_it) {
5062 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205063 if (params.is_javascript) {
[email protected]2a521c52011-01-26 18:45:215064 const Extension* extension =
5065 render_thread_->GetExtensions()->GetByID(params.extension_id);
[email protected]be7e5cb2010-10-04 12:53:175066
[email protected]1f6228c2010-10-21 03:19:445067 // Since extension info is sent separately from user script info, they can
5068 // be out of sync. We just ignore this situation.
5069 if (!extension)
5070 continue;
5071
[email protected]2a521c52011-01-26 18:45:215072 if (!extension->CanExecuteScriptOnPage(frame->url(), NULL, NULL))
[email protected]61f5a7b2009-12-22 22:21:205073 continue;
5074
[email protected]20ad2692009-11-20 18:27:205075 std::vector<WebScriptSource> sources;
5076 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205077 WebScriptSource(WebString::fromUTF8(params.code)));
5078 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205079 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205080 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205081 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5082 } else {
[email protected]61f5a7b2009-12-22 22:21:205083 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205084 }
[email protected]912256b32009-09-18 09:47:355085 }
5086
[email protected]61f5a7b2009-12-22 22:21:205087 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355088}
5089
[email protected]60c42a8c72009-10-09 04:08:595090void RenderView::Close() {
5091 // We need to grab a pointer to the doomed WebView before we destroy it.
5092 WebView* doomed = webview();
5093 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495094 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595095}
5096
[email protected]446705872009-09-10 07:22:485097void RenderView::DidHandleKeyEvent() {
5098 edit_commands_.clear();
5099}
5100
[email protected]6a8ddba52010-09-05 04:38:065101void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515102 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065103}
5104
[email protected]941e4552010-02-01 21:23:435105void RenderView::OnWasHidden() {
5106 RenderWidget::OnWasHidden();
5107
[email protected]a6939ca42011-02-18 17:58:075108 if (webview()) {
5109 webview()->settings()->setMinimumTimerInterval(
5110 webkit_glue::kBackgroundTabTimerInterval);
5111 }
5112
5113#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:435114 // Inform plugins that their container is no longer visible.
5115 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5116 for (plugin_it = plugin_delegates_.begin();
5117 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5118 (*plugin_it)->SetContainerVisibility(false);
5119 }
[email protected]a6939ca42011-02-18 17:58:075120#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435121}
5122
5123void RenderView::OnWasRestored(bool needs_repainting) {
5124 RenderWidget::OnWasRestored(needs_repainting);
5125
[email protected]a6939ca42011-02-18 17:58:075126 if (webview()) {
5127 webview()->settings()->setMinimumTimerInterval(
5128 webkit_glue::kForegroundTabTimerInterval);
5129 }
5130
5131#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:435132 // Inform plugins that their container is now visible.
5133 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5134 for (plugin_it = plugin_delegates_.begin();
5135 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5136 (*plugin_it)->SetContainerVisibility(true);
5137 }
[email protected]784ea1ab2010-09-18 00:02:345138#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075139}
[email protected]1e6e3c992010-02-08 15:52:135140
5141void RenderView::OnSetFocus(bool enable) {
5142 RenderWidget::OnSetFocus(enable);
5143
[email protected]7d3c02c2010-05-05 23:10:315144 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075145 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135146 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5147 for (plugin_it = plugin_delegates_.begin();
5148 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345149#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315150 // RenderWidget's call to setFocus can cause the underlying webview's
5151 // activation state to change just like a call to setIsActive.
5152 if (enable)
5153 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345154#endif
[email protected]7d3c02c2010-05-05 23:10:315155 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135156 }
[email protected]589621b2010-09-23 22:01:075157
5158 // Notify all Pepper plugins.
5159 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135160 }
5161}
[email protected]941e4552010-02-01 21:23:435162
[email protected]83dde542009-09-11 20:59:555163void RenderView::EnsureDocumentTag() {
5164 // TODO(darin): There's actually no reason for this to be here. We should
5165 // have the browser side manage the document tag.
5166#if defined(OS_MACOSX)
5167 if (!has_document_tag_) {
5168 // Make the call to get the tag.
5169 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5170 has_document_tag_ = true;
5171 }
5172#endif
5173}
[email protected]12636df2009-09-28 22:32:215174
[email protected]43f28f832010-02-03 02:28:485175#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:135176void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
5177 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
5178 focused, plugin_id);
5179 Send(msg);
5180}
5181
5182void RenderView::StartPluginIme() {
5183 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555184 // This message can be sent during event-handling, and needs to be delivered
5185 // within that context.
5186 msg->set_unblock(true);
5187 Send(msg);
5188}
5189
[email protected]ea04a4e12010-04-15 00:58:035190gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235191 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485192 gfx::PluginWindowHandle window = NULL;
5193 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235194 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115195 if (window) {
5196 fake_plugin_window_handles_.insert(window);
5197 }
[email protected]43f28f832010-02-03 02:28:485198 return window;
5199}
5200
5201void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115202 if (window && fake_plugin_window_handles_.find(window) !=
5203 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485204 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115205 fake_plugin_window_handles_.erase(window);
5206 }
[email protected]43f28f832010-02-03 02:28:485207}
5208
[email protected]44ce0b12010-03-12 16:45:335209void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5210 int32 width,
5211 int32 height,
5212 uint64 io_surface_identifier) {
5213 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485214 routing_id(), window, width, height, io_surface_identifier));
5215}
5216
[email protected]44ce0b12010-03-12 16:45:335217void RenderView::AcceleratedSurfaceSetTransportDIB(
5218 gfx::PluginWindowHandle window,
5219 int32 width,
5220 int32 height,
5221 TransportDIB::Handle transport_dib) {
5222 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075223 routing_id(), window, width, height, transport_dib));
5224}
5225
[email protected]44ce0b12010-03-12 16:45:335226TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5227 size_t size) {
[email protected]1aef98132010-02-23 18:00:075228 TransportDIB::Handle dib_handle;
5229 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385230 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075231 return dib_handle;
5232 // Return an invalid handle if Send() fails.
5233 return TransportDIB::DefaultHandleValue();
5234}
5235
[email protected]44ce0b12010-03-12 16:45:335236void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075237 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5238}
5239
[email protected]44ce0b12010-03-12 16:45:335240void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145241 gfx::PluginWindowHandle window, uint64 surface_id) {
5242 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5243 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485244}
5245#endif
[email protected]58c321d2010-02-19 12:11:285246
[email protected]cdaf8d02010-03-30 19:52:475247bool RenderView::ScheduleFileChooser(
5248 const ViewHostMsg_RunFileChooser_Params& params,
5249 WebFileChooserCompletion* completion) {
5250 static const size_t kMaximumPendingFileChooseRequests = 4;
5251 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5252 // This sanity check prevents too many file choose requests from getting
5253 // queued which could DoS the user. Getting these is most likely a
5254 // programming error (there are many ways to DoS the user so it's not
5255 // considered a "real" security check), either in JS requesting many file
5256 // choosers to pop up, or in a plugin.
5257 //
5258 // TODO(brettw) we might possibly want to require a user gesture to open
5259 // a file picker, which will address this issue in a better way.
5260 return false;
5261 }
5262
5263 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5264 new PendingFileChooser(params, completion)));
5265 if (file_chooser_completions_.size() == 1) {
5266 // Actually show the browse dialog when this is the first request.
5267 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5268 }
5269 return true;
5270}
5271
[email protected]290838a2010-04-27 17:37:015272void RenderView::OnPageTranslated() {
5273 WebFrame* frame = webview()->mainFrame();
5274 if (!frame)
5275 return;
5276
[email protected]676126f72011-01-15 00:03:515277 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015278}
5279
[email protected]0ff0ff32010-12-21 19:34:425280WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515281 if (!geolocation_dispatcher_)
5282 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5283 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255284}
[email protected]61c9f032010-03-31 23:04:195285
[email protected]638694c2010-08-04 22:24:115286WebKit::WebSpeechInputController* RenderView::speechInputController(
5287 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515288 if (!speech_input_dispatcher_)
5289 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5290 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115291}
5292
[email protected]57ead352010-08-11 14:42:535293WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515294 if (!device_orientation_dispatcher_)
5295 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5296 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535297}
5298
[email protected]b75b8292010-10-01 07:28:255299void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5300 // For now, don't remember plugin zoom values. We don't want to mix them with
5301 // normal web content (i.e. a fixed layout plugin would usually want them
5302 // different).
5303 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5304
[email protected]b75b8292010-10-01 07:28:255305 int minimum_percent = static_cast<int>(
5306 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5307 int maximum_percent = static_cast<int>(
5308 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255309
5310 Send(new ViewHostMsg_UpdateZoomLimits(
5311 routing_id_, minimum_percent, maximum_percent, remember));
5312}
5313
5314void RenderView::zoomLevelChanged() {
5315 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5316
[email protected]b75b8292010-10-01 07:28:255317 // Tell the browser which url got zoomed so it can update the menu and the
5318 // saved values if necessary
5319 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415320 routing_id_, webview()->zoomLevel(), remember,
5321 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255322}
5323
[email protected]a6d36cc2011-02-23 00:39:485324void RenderView::registerProtocolHandler(const WebString& scheme,
5325 const WebString& base_url,
5326 const WebString& url,
5327 const WebString& title) {
5328 GURL base(base_url);
5329 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5330 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5331 return;
5332 }
5333 RenderThread::current()->Send(
5334 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5335 UTF16ToUTF8(scheme),
5336 absolute_url,
5337 title));
5338}
5339
[email protected]8079b362010-05-07 18:37:455340bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195341 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455342 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195343 if (frame->parent() != NULL)
5344 return false;
5345
[email protected]f0a3d0b2010-08-06 22:51:535346 // Navigations initiated within Webkit are not sent out to the external host
5347 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275348 // 1. The url scheme is not http/https
5349 // 2. There is no opener and this is not the first url being opened by this
5350 // RenderView.
5351 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535352 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535353 // 4. Reloads/form submits/back forward navigations
5354 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5355 return false;
5356
[email protected]2fc22d12010-12-02 23:08:165357 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325358 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015359 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165360 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015361 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325362 // The opener relationship between the new window and the parent allows the
5363 // new window to script the parent and vice versa. This is not allowed if
5364 // the origins of the two domains are different. This can be treated as a
5365 // top level navigation and routed back to the host.
5366 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275367 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475368 // Force link click navigations to always be routed to the host as they
5369 // may update session state on the server.
5370 if (type == WebKit::WebNavigationTypeLinkClicked)
5371 return true;
[email protected]900eb2f12010-08-23 22:36:275372 // If this is the first page being loaded by this RenderView instance then
5373 // it should stay here.
5374 if (page_id_ == -1) {
5375 return false;
5376 } else {
[email protected]d0ed50d2010-06-22 01:01:325377 return true;
[email protected]900eb2f12010-08-23 22:36:275378 }
[email protected]d0ed50d2010-06-22 01:01:325379 }
[email protected]900eb2f12010-08-23 22:36:275380
5381 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5382 return true;
[email protected]d0ed50d2010-06-22 01:01:325383 }
[email protected]61c9f032010-03-31 23:04:195384 return false;
5385}
[email protected]2b06a992010-08-21 05:48:225386
[email protected]27a9ef32010-09-10 04:06:245387void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5388 IPC::PlatformFileForTransit file_for_transit,
5389 int message_id) {
5390 pepper_delegate_.OnAsyncFileOpened(
5391 error_code,
5392 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5393 message_id);
5394}
[email protected]caf706f2010-10-26 17:54:085395
5396#if defined(OS_MACOSX)
5397void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155398 if (external_popup_menu_ == NULL) {
5399 // Crash reports from the field indicate that we can be notified with a
5400 // NULL external popup menu (we probably get notified twice).
5401 // If you hit this please file a bug against jcivelli and include the page
5402 // and steps to repro.
5403 NOTREACHED();
5404 return;
5405 }
[email protected]caf706f2010-10-26 17:54:085406 external_popup_menu_->DidSelectItem(selected_index);
5407 external_popup_menu_.reset();
5408}
5409#endif
[email protected]bb461532010-11-26 21:50:235410
5411void RenderView::AddErrorToRootConsole(const string16& message) {
5412 if (webview() && webview()->mainFrame()) {
5413 webview()->mainFrame()->addMessageToConsole(
5414 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5415 }
5416}
[email protected]1b4209f2011-01-07 00:25:405417
5418#if defined(ENABLE_FLAPPER_HACKS)
5419void RenderView::OnConnectTcpACK(
5420 int request_id,
5421 IPC::PlatformFileForTransit socket_for_transit,
5422 const PP_Flash_NetAddress& local_addr,
5423 const PP_Flash_NetAddress& remote_addr) {
5424 pepper_delegate_.OnConnectTcpACK(
5425 request_id,
5426 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5427 local_addr,
5428 remote_addr);
5429}
5430#endif
[email protected]a6097f42011-01-10 08:50:515431
5432void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5433 if (cmd == kJavaScriptStressTestSetStressRunType) {
5434 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5435 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5436 v8::Testing::PrepareStressRun(param);
5437 }
5438}
[email protected]521b2482011-01-15 00:10:105439
[email protected]b29aa74b2011-01-31 21:41:085440void RenderView::OnContextMenuClosed(
5441 const webkit_glue::CustomContextMenuContext& custom_context) {
5442 if (custom_context.is_pepper_menu)
5443 pepper_delegate_.OnContextMenuClosed(custom_context);
5444 else
5445 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105446}
[email protected]232a5812011-03-04 22:42:085447
5448void RenderView::OnNetworkStateChanged(bool online) {
5449 WebNetworkStateNotifier::setOnLine(online);
5450}