blob: 9ea2b853054cc507613e04cce6159feae29cb5a4 [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]19d6e1e82011-01-26 05:08:5825#include "chrome/common/autofill_messages.h"
[email protected]035545f2010-04-09 13:10:2126#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2830#include "chrome/common/chrome_paths.h"
31#include "chrome/common/chrome_switches.h"
[email protected]26a9acf2010-12-13 19:35:0532#include "chrome/common/database_messages.h"
[email protected]a0cf04a2010-06-23 03:29:5533#include "chrome/common/extensions/extension.h"
[email protected]ec7db282011-01-29 01:11:3634#include "chrome/common/extensions/extension_set.h"
[email protected]c5a272d2010-09-27 18:37:0835#include "chrome/common/file_system/file_system_dispatcher.h"
36#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]bb461532010-11-26 21:50:2337#include "chrome/common/json_value_serializer.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2139#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1740#include "chrome/common/page_zoom.h"
[email protected]f0557932011-01-25 20:20:5141#include "chrome/common/pepper_messages.h"
[email protected]4e0616e2010-05-28 14:55:5342#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2943#include "chrome/common/render_messages.h"
[email protected]13a1e4c3c2011-02-03 21:07:0944#include "chrome/common/render_view_commands.h"
[email protected]9b6f40e2009-06-11 15:54:2645#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2946#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5947#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4448#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1149#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2551#include "chrome/renderer/audio_message_filter.h"
[email protected]78192082011-01-29 05:43:4452#include "chrome/renderer/autofill/autofill_agent.h"
53#include "chrome/renderer/autofill/form_manager.h"
54#include "chrome/renderer/autofill/password_autofill_manager.h"
[email protected]2f979172010-09-16 21:54:0355#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4056#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5357#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1158#include "chrome/renderer/devtools_agent.h"
59#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3560#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0461#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3262#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3563#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3764#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0365#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0866#include "chrome/renderer/external_popup_menu.h"
[email protected]ffd0abd2010-12-14 17:45:5067#include "chrome/renderer/geolocation_dispatcher.h"
[email protected]3bb08602010-10-07 21:47:1768#include "chrome/renderer/ggl/ggl.h"
[email protected]90109412010-12-15 17:14:2469#include "chrome/renderer/load_progress_tracker.h"
initial.commit09911bf2008-07-26 23:55:2970#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5671#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4172#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]ed3fb032009-06-16 19:50:5673#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1274#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0675#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3676#include "chrome/renderer/page_load_histograms.h"
[email protected]8beff0762009-09-29 02:18:3077#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5078#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2579#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2880#include "chrome/renderer/render_thread.h"
[email protected]676126f72011-01-15 00:03:5181#include "chrome/renderer/render_view_observer.h"
[email protected]4d51d5bf2010-07-26 18:48:2682#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1883#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3984#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2185#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3486#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]3ead1322010-11-19 20:01:0087#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]ce833282010-11-04 15:48:3988#include "chrome/renderer/searchbox_extension.h"
[email protected]638694c2010-08-04 22:24:1189#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4690#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]81273622011-02-02 03:56:1391#include "chrome/renderer/translate_helper.h"
[email protected]25e18f82010-10-27 16:38:4392#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3593#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2994#include "chrome/renderer/visitedlink_slave.h"
[email protected]c50008512011-02-03 01:17:2795#include "chrome/renderer/web_ui_bindings.h"
[email protected]5aa6a312010-11-06 00:00:0796#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
[email protected]d439ba072009-10-17 22:32:2997#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2998#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4299#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:56100#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:15101#include "gfx/color_utils.h"
102#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:57103#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:26104#include "gfx/point.h"
105#include "gfx/rect.h"
[email protected]82afe4b2010-11-12 20:36:22106#include "gfx/skbitmap_operations.h"
[email protected]34ac8f32009-02-22 23:03:27107#include "grit/generated_resources.h"
108#include "grit/renderer_resources.h"
[email protected]f8db8132010-12-03 00:27:49109#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41110#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:27111#include "media/base/message_loop_factory_impl.h"
[email protected]f11ca0732009-04-11 00:09:34112#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29113#include "net/base/escape.h"
114#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04115#include "net/http/http_util.h"
[email protected]1b4209f2011-01-07 00:25:40116#include "ppapi/c/private/ppb_flash.h"
[email protected]c399a8a2008-11-22 19:38:00117#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10118#include "skia/ext/image_operations.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
138#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"
155#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
158#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
159#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26162#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
163#include "third_party/skia/include/core/SkBitmap.h"
[email protected]9dd7e3d72011-01-20 18:27:06164#include "ui/base/message_box_flags.h"
[email protected]c051a1b2011-01-21 23:30:17165#include "ui/base/l10n/l10n_util.h"
[email protected]42ce29d2011-01-20 23:19:46166#include "ui/base/resource/resource_bundle.h"
[email protected]882b7b22010-10-05 03:34:53167#include "v8/include/v8.h"
[email protected]a6097f42011-01-10 08:50:51168#include "v8/include/v8-testing.h"
[email protected]80f584d92010-01-21 03:59:04169#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43170#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24171#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29172#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59173#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24174#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24175#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34176#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26177#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09178#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26179#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23180#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09181#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24182#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29183#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29184#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17185#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50186#include "webkit/plugins/npapi/default_plugin_shared.h"
187#include "webkit/plugins/npapi/plugin_list.h"
188#include "webkit/plugins/npapi/webplugin_delegate.h"
189#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
190#include "webkit/plugins/npapi/webplugin_impl.h"
191#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52192#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29193
[email protected]6c8afae52009-01-22 02:24:57194#if defined(OS_WIN)
195// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57196// * theming
[email protected]cd818412010-03-19 03:23:15197#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03198#elif defined(USE_X11)
[email protected]8d1b864d12010-10-10 00:04:34199#include "gfx/native_theme_linux.h"
[email protected]8bd0fe62011-01-17 06:44:37200#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33201#elif defined(OS_MACOSX)
202#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57203#endif
204
[email protected]c7287a92009-11-04 20:06:15205using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42206using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08207using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21208using WebKit::WebApplicationCacheHost;
209using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26210using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41211using WebKit::WebColor;
212using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59213using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44214using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51215using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55216using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28217using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29218using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00219using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58220using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25221using WebKit::WebDragOperation;
222using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51223using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51224using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08225using WebKit::WebExternalPopupMenu;
226using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47227using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22228using WebKit::WebFileSystem;
229using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49230using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59231using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48232using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45233using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17234using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41235using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50236using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17237using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28238using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17239using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28240using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28241using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51242using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07243using WebKit::WebPageSerializer;
244using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17245using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40246using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49247using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09248using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52249using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59250using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51251using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52252using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40253using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35254using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29255using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59256using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42257using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02258using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34259using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28260using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51261using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52262using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28263using WebKit::WebURL;
264using WebKit::WebURLError;
265using WebKit::WebURLRequest;
266using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28267using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03268using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28269using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26270using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43271using WebKit::WebWorker;
272using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26273using appcache::WebApplicationCacheHostImpl;
[email protected]78192082011-01-29 05:43:44274using autofill::AutoFillAgent;
275using autofill::FormManager;
276using autofill::PasswordAutoFillManager;
[email protected]6fdd4182010-10-14 23:59:26277using base::Time;
278using base::TimeDelta;
279using webkit_glue::AltErrorPageResourceFetcher;
280using webkit_glue::FormData;
281using webkit_glue::FormField;
282using webkit_glue::ImageResourceFetcher;
283using webkit_glue::PasswordForm;
284using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23285using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26286using webkit_glue::SiteIsolationMetrics;
287using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33288
initial.commit09911bf2008-07-26 23:55:29289//-----------------------------------------------------------------------------
290
[email protected]3354d3e2010-06-10 19:53:02291typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49292static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02293
initial.commit09911bf2008-07-26 23:55:29294// define to write the time necessary for thumbnail/DOM text retrieval,
295// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29296// #define TIME_TEXT_RETRIEVAL
297
298// maximum number of characters in the document to index, any text beyond this
299// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57300static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29301
302// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37303static const int kThumbnailWidth = 212;
304static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29305
306// Delay in milliseconds that we'll wait before capturing the page contents
307// and thumbnail.
308static const int kDelayForCaptureMs = 500;
309
310// Typically, we capture the page data once the page is loaded.
311// Sometimes, the page never finishes to load, preventing the page capture
312// To workaround this problem, we always perform a capture after the following
313// delay.
314static const int kDelayForForcedCaptureMs = 6000;
315
[email protected]882daa92009-11-05 16:31:31316// Time, in seconds, we delay before sending content state changes (such as form
317// state and scroll position) to the browser. We delay sending changes to avoid
318// spamming the browser.
319// To avoid having tab/session restore require sending a message to get the
320// current content state during tab closing we use a shorter timeout for the
321// foreground renderer. This means there is a small window of time from which
322// content state is modified and not sent to session restore, but this is
323// better than having to wake up all renderers during shutdown.
324static const int kDelaySecondsForContentStateSyncHidden = 5;
325static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29326
[email protected]0aa55312008-10-17 21:53:08327// The maximum number of popups that can be spawned from one page.
328static const int kMaximumNumberOfUnacknowledgedPopups = 25;
329
[email protected]6fdd4182010-10-14 23:59:26330static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35331
[email protected]726985e22009-06-18 21:09:28332static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
333 WebVector<WebURL> urls;
334 ds->redirectChain(urls);
335 result->reserve(urls.size());
336 for (size_t i = 0; i < urls.size(); ++i)
337 result->push_back(urls[i]);
338}
339
[email protected]30507922010-01-15 16:48:23340static bool PaintViewIntoCanvas(WebView* view,
341 skia::PlatformCanvas& canvas) {
342 view->layout();
343 const WebSize& size = view->size();
344
345 if (!canvas.initialize(size.width, size.height, true))
346 return false;
347
348 view->paint(webkit_glue::ToWebCanvas(&canvas),
349 WebRect(0, 0, size.width, size.height));
350 // TODO: Add a way to snapshot the whole page, not just the currently
351 // visible part.
352
353 return true;
354}
355
356// Calculates how "boring" a thumbnail is. The boring score is the
357// 0,1 ranged percentage of pixels that are the most common
358// luma. Higher boring scores indicate that a higher percentage of a
359// bitmap are all the same brightness.
360static double CalculateBoringScore(SkBitmap* bitmap) {
361 int histogram[256] = {0};
362 color_utils::BuildLumaHistogram(bitmap, histogram);
363
364 int color_count = *std::max_element(histogram, histogram + 256);
365 int pixel_count = bitmap->width() * bitmap->height();
366 return static_cast<double>(color_count) / pixel_count;
367}
368
[email protected]12bc8472010-04-15 07:29:40369// True if |frame| contains content that is white-listed for content settings.
370static bool IsWhitelistedForContentSettings(WebFrame* frame) {
371 WebSecurityOrigin origin = frame->securityOrigin();
372 if (origin.isEmpty())
373 return false; // Uninitialized document?
374
375 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
376 return true; // Browser UI elements should still work.
377
378 // If the scheme is ftp: or file:, an empty file name indicates a directory
379 // listing, which requires JavaScript to function properly.
380 GURL frame_url = frame->url();
381 const char* kDirProtocols[] = { "ftp", "file" };
382 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
383 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
384 return frame_url.SchemeIs(kDirProtocols[i]) &&
385 frame_url.ExtractFileName().empty();
386 }
387 }
388
389 return false;
390}
391
[email protected]3a8eecb2010-04-22 23:56:30392// Returns true if the frame is navigating to an URL either into or out of an
393// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04394// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
395// we would enter an extension app's extent from a non-app. We avoid swapping
396// processes to exit an app for now, since we do not yet restore context (such
397// as window.opener) if the window navigates back.
[email protected]ec7db282011-01-29 01:11:36398static bool CrossesIntoExtensionExtent(const ExtensionSet* extensions,
[email protected]2a521c52011-01-26 18:45:21399 WebFrame* frame,
400 const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30401 // If the URL is still empty, this is a window.open navigation. Check the
402 // opener's URL.
403 GURL old_url(frame->url());
404 if (old_url.is_empty() && frame->opener())
405 old_url = frame->opener()->url();
406
[email protected]2a521c52011-01-26 18:45:21407 return !extensions->InSameExtent(old_url, new_url) &&
408 !extensions->GetByURL(old_url);
[email protected]3a8eecb2010-04-22 23:56:30409}
410
[email protected]3354d3e2010-06-10 19:53:02411// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
412// if it failed.
[email protected]e5106202010-06-11 21:12:36413static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17414 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02415 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08416 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02417 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02418 Language cld_language =
[email protected]e5106202010-06-11 21:12:36419 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08420 &num_languages, NULL, &text_bytes);
421 // We don't trust the result if the CLD reports that the detection is not
422 // reliable, or if the actual text used to detect the language was less than
423 // 100 bytes (short texts can often lead to wrong results).
424 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02425 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
426 // We should not use LanguageCode_ISO_639_1 because it does not cover all
427 // the languages CLD can detect. As a result, it'll return the invalid
428 // language code for tradtional Chinese among others.
429 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
430 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
431 // for Simplified Chinese.
432 language = LanguageCodeWithDialects(cld_language);
433 }
434 return language;
435}
436
[email protected]9b66f34bf2010-10-27 20:45:51437// Returns true if the parameter node is a textfield, text area or a content
438// editable div.
439static bool IsEditableNode(const WebNode& node) {
440 bool is_editable_node = false;
441 if (!node.isNull()) {
442 if (node.isContentEditable()) {
443 is_editable_node = true;
444 } else if (node.isElementNode()) {
445 is_editable_node =
446 node.toConst<WebElement>().isTextFormControlElement();
447 }
448 }
449 return is_editable_node;
450}
451
[email protected]54ec7f82010-10-21 22:32:51452static bool WebAccessibilityNotificationToViewHostMsg(
453 WebAccessibilityNotification notification,
454 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
455 switch (notification) {
456 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
457 *type = ViewHostMsg_AccessibilityNotification_Params::
458 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
459 break;
460 case WebKit::WebAccessibilityNotificationChildrenChanged:
461 *type = ViewHostMsg_AccessibilityNotification_Params::
462 NOTIFICATION_TYPE_CHILDREN_CHANGED;
463 break;
464 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
465 *type = ViewHostMsg_AccessibilityNotification_Params::
466 NOTIFICATION_TYPE_FOCUS_CHANGED;
467 break;
468 case WebKit::WebAccessibilityNotificationLoadComplete:
469 *type = ViewHostMsg_AccessibilityNotification_Params::
470 NOTIFICATION_TYPE_LOAD_COMPLETE;
471 break;
472 case WebKit::WebAccessibilityNotificationValueChanged:
473 *type = ViewHostMsg_AccessibilityNotification_Params::
474 NOTIFICATION_TYPE_VALUE_CHANGED;
475 break;
476 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
477 *type = ViewHostMsg_AccessibilityNotification_Params::
478 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
479 break;
480 default:
481 // TODO(ctguil): Support additional webkit notifications.
482 return false;
483 }
484 return true;
485}
486
[email protected]81f9fe0b2010-12-07 00:35:29487// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
488// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
[email protected]fb534c92011-02-01 01:02:07489// being TYPE_DOUBLEs. Dates are converted to a string (which can then be
490// parsed into a base::Time), as are regexps. Arrays are converted into lists,
[email protected]81f9fe0b2010-12-07 00:35:29491// recursively. We don't deal with binary objects or functions - they become
492// null values.
493static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
494 if (v8value->IsBoolean()) {
495 return Value::CreateBooleanValue(v8value->BooleanValue());
496 } else if (v8value->IsInt32()) {
497 return Value::CreateIntegerValue(v8value->Int32Value());
498 } else if (v8value->IsNumber()) {
[email protected]fb534c92011-02-01 01:02:07499 return Value::CreateDoubleValue(v8value->NumberValue());
[email protected]81f9fe0b2010-12-07 00:35:29500 } else if (v8value->IsString()) {
501 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
502 } else if (v8value->IsDate()) {
503 v8::Date* date = v8::Date::Cast(*v8value);
[email protected]fb534c92011-02-01 01:02:07504 return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
[email protected]81f9fe0b2010-12-07 00:35:29505 } else if (v8value->IsRegExp()) {
506 return Value::CreateStringValue(
507 *v8::String::Utf8Value(v8value->ToString()));
508 } else if (v8value->IsArray()) {
509 v8::Array* array = v8::Array::Cast(*v8value);
510 uint32_t length = array->Length();
511 scoped_ptr<ListValue> list(new ListValue);
512 for (uint32_t i = 0 ; i < length ; ++i) {
513 list->Set(i, ConvertV8Value(array->Get(i)));
514 }
515 return list.release();
516 }
517 return Value::CreateNullValue();
518}
519
initial.commit09911bf2008-07-26 23:55:29520///////////////////////////////////////////////////////////////////////////////
521
[email protected]60c42a8c72009-10-09 04:08:59522int32 RenderView::next_page_id_ = 1;
523
[email protected]cdaf8d02010-03-30 19:52:47524struct RenderView::PendingFileChooser {
525 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
526 WebFileChooserCompletion* c)
527 : params(p),
528 completion(c) {
529 }
530 ViewHostMsg_RunFileChooser_Params params;
531 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
532};
533
[email protected]2fab253a2009-08-17 23:00:59534RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51535 gfx::NativeViewId parent_hwnd,
536 int32 opener_id,
537 const RendererPreferences& renderer_prefs,
538 const WebPreferences& webkit_prefs,
539 SharedRenderViewCounter* counter,
540 int32 routing_id,
541 int64 session_storage_namespace_id,
542 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12543 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51544 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02545 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09546 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02547 send_preferred_size_changes_(false),
548 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24549 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21550 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02551 opened_by_user_gesture_(true),
552 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24553 page_id_(-1),
554 last_page_id_sent_to_browser_(-1),
555 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00556 history_list_offset_(-1),
557 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24558 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55559#if defined(OS_MACOSX)
560 has_document_tag_(false),
561#endif
[email protected]98324892009-09-09 21:16:05562 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02563 target_url_status_(TARGET_NONE),
564 spelling_panel_visible_(false),
565 view_type_(ViewType::INVALID),
566 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18567 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30568 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51569 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02570 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51571 devtools_client_(NULL),
572 geolocation_dispatcher_(NULL),
573 speech_input_dispatcher_(NULL),
574 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51575 accessibility_ack_pending_(false),
[email protected]bb461532010-11-26 21:50:23576 pending_app_icon_requests_(0),
[email protected]5ee0cfd02011-01-18 05:42:22577 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]8de12d942010-11-17 20:42:44578#if defined(OS_MACOSX)
579 // On Mac, the select popups are rendered by the browser.
580 // Note that we don't do this in RenderMain otherwise this would not be called
581 // in single-process mode.
582 WebKit::WebView::setUseExternalPopupMenus(true);
583#endif
[email protected]676126f72011-01-15 00:03:51584
[email protected]71b0d5d2010-02-15 05:43:07585 ClearBlockedContentSettings();
[email protected]3ead1322010-11-19 20:01:00586 if (CommandLine::ForCurrentProcess()->HasSwitch(
587 switches::kEnableClientSidePhishingDetection)) {
588 phishing_delegate_.reset(
589 new safe_browsing::PhishingClassifierDelegate(this, NULL));
590 RenderThread* thread = RenderThread::current();
591 if (thread && thread->phishing_scorer()) {
592 phishing_delegate_->SetPhishingScorer(thread->phishing_scorer());
593 }
594 }
[email protected]676126f72011-01-15 00:03:51595
596 routing_id_ = routing_id;
597 if (opener_id != MSG_ROUTING_NONE)
598 opener_id_ = opener_id;
599
600 if (counter) {
601 shared_popup_counter_ = counter;
602 shared_popup_counter_->data++;
603 decrement_shared_popup_at_destruction_ = true;
604 } else {
605 shared_popup_counter_ = new SharedRenderViewCounter(0);
606 decrement_shared_popup_at_destruction_ = false;
607 }
608
609 notification_provider_ = new NotificationProvider(this);
610
611 devtools_agent_ = new DevToolsAgent(this);
[email protected]78192082011-01-29 05:43:44612 PasswordAutoFillManager* password_autofill_manager =
613 new PasswordAutoFillManager(this);
614 AutoFillAgent* autofill_agent = new AutoFillAgent(this,
615 password_autofill_manager);
[email protected]676126f72011-01-15 00:03:51616
[email protected]78192082011-01-29 05:43:44617 webwidget_ = WebView::create(this, devtools_agent_, autofill_agent);
[email protected]676126f72011-01-15 00:03:51618 g_view_map.Get().insert(std::make_pair(webview(), this));
619 webkit_preferences_.Apply(webview());
620 webview()->initializeMainFrame(this);
621 if (!frame_name.empty())
622 webview()->mainFrame()->setName(frame_name);
623
624 OnSetRendererPrefs(renderer_prefs);
625
626 render_thread_->AddRoute(routing_id_, this);
627 // Take a reference on behalf of the RenderThread. This will be balanced
628 // when we receive ViewMsg_Close.
629 AddRef();
630
631 // If this is a popup, we must wait for the CreatingNew_ACK message before
632 // completing initialization. Otherwise, we can finish it now.
633 if (opener_id == MSG_ROUTING_NONE) {
634 did_show_ = true;
635 CompleteInit(parent_hwnd);
636 }
637
638 host_window_ = parent_hwnd;
639
640 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
641 if (command_line.HasSwitch(switches::kDomAutomationController))
642 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
643 if (command_line.HasSwitch(switches::kEnableAccessibility))
644 WebAccessibilityCache::enableAccessibility();
645
646 audio_message_filter_ = new AudioMessageFilter(routing_id_);
647 render_thread_->AddFilter(audio_message_filter_);
648
649 PageClickTracker* page_click_tracker = new PageClickTracker(this);
650 // Note that the order of insertion of the listeners is important.
651 // The password_autocomplete_manager takes the first shot at processing the
652 // notification and can stop the propagation.
[email protected]78192082011-01-29 05:43:44653 page_click_tracker->AddListener(password_autofill_manager);
654 page_click_tracker->AddListener(autofill_agent);
[email protected]81273622011-02-02 03:56:13655 new TranslateHelper(this);
initial.commit09911bf2008-07-26 23:55:29656}
657
658RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08659 if (decrement_shared_popup_at_destruction_)
660 shared_popup_counter_->data--;
661
[email protected]a1128322009-10-06 18:38:46662 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47663 while (!file_chooser_completions_.empty()) {
664 if (file_chooser_completions_.front()->completion) {
665 file_chooser_completions_.front()->completion->didChooseFile(
666 WebVector<WebString>());
667 }
668 file_chooser_completions_.pop_front();
669 }
[email protected]a1128322009-10-06 18:38:46670
[email protected]83dde542009-09-11 20:59:55671#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05672 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55673 if (has_document_tag_)
674 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11675
676 // Destroy all fake plugin window handles on the browser side.
677 while (!fake_plugin_window_handles_.empty()) {
678 // Make sure no NULL plugin window handles were inserted into this list.
679 DCHECK(*fake_plugin_window_handles_.begin());
680 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
681 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
682 }
[email protected]83dde542009-09-11 20:59:55683#endif
[email protected]98324892009-09-09 21:16:05684
[email protected]5fb88962009-04-16 19:03:25685 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59686
[email protected]3ead1322010-11-19 20:01:00687 // Tell the PhishingClassifierDelegate that the view is going away.
688 if (phishing_delegate_.get())
689 phishing_delegate_->CancelPendingClassification();
690
[email protected]60c42a8c72009-10-09 04:08:59691#ifndef NDEBUG
692 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49693 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59694 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
695 DCHECK_NE(this, it->second) << "Failed to call Close?";
696#endif
[email protected]676126f72011-01-15 00:03:51697
698 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
699 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59700}
701
702/*static*/
703void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49704 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59705 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
706 if (!visitor->Visit(it->second))
707 return;
708 }
709}
710
711/*static*/
712RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49713 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59714 ViewMap::iterator it = views->find(webview);
715 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29716}
717
718/*static*/
[email protected]0aa55312008-10-17 21:53:08719RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24720 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15721 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08722 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51723 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08724 const WebPreferences& webkit_prefs,
725 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34726 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26727 int64 session_storage_namespace_id,
728 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29729 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51730 return new RenderView(
731 render_thread,
732 parent_hwnd,
733 opener_id,
734 renderer_prefs,
735 webkit_prefs,
736 counter,
737 routing_id,
738 session_storage_namespace_id,
739 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29740}
741
[email protected]bb461532010-11-26 21:50:23742// static
initial.commit09911bf2008-07-26 23:55:29743void RenderView::SetNextPageID(int32 next_page_id) {
744 // This method should only be called during process startup, and the given
745 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05746 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29747 DCHECK(next_page_id >= next_page_id_);
748 next_page_id_ = next_page_id;
749}
750
[email protected]676126f72011-01-15 00:03:51751void RenderView::AddObserver(RenderViewObserver* observer) {
752 observers_.AddObserver(observer);
753}
754
755void RenderView::RemoveObserver(RenderViewObserver* observer) {
756 observer->set_render_view(NULL);
757 observers_.RemoveObserver(observer);
758}
759
[email protected]70eee342010-11-05 01:59:37760bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
761 typedef ViewHostMsg_AccessibilityNotification_Params params;
762 if (type == params::NOTIFICATION_TYPE_CHILDREN_CHANGED ||
763 type == params::NOTIFICATION_TYPE_LOAD_COMPLETE) {
764 return true;
765 }
766 return false;
767}
768
[email protected]8a3125a712010-08-09 18:58:51769WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26770 return static_cast<WebKit::WebView*>(webwidget());
771}
772
[email protected]afe3a1672009-11-17 19:04:12773void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50774 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56775}
776
[email protected]bb461532010-11-26 21:50:23777bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
778 string16* error) {
779 // There is an issue of drive-by installs with the below implementation. A web
780 // site could force a user to install an app by timing the dialog to come up
781 // just before the user clicks.
782 //
783 // We do show a success UI that allows users to uninstall, but it seems that
784 // we might still want to put up an infobar before showing the install dialog.
785 //
786 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
787 // switch.
788 if (!CommandLine::ForCurrentProcess()->HasSwitch(
789 switches::kEnableCrxlessWebApps)) {
790 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
791 return false;
792 }
793
794 if (frame != frame->top()) {
795 *error = ASCIIToUTF16("Applications can only be installed from the top "
796 "frame.");
797 return false;
798 }
799
800 if (pending_app_info_.get()) {
801 *error = ASCIIToUTF16("An application install is already in progress.");
802 return false;
803 }
804
805 pending_app_info_.reset(new WebApplicationInfo());
806 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
807 error)) {
808 return false;
809 }
810
811 if (!pending_app_info_->manifest_url.is_valid()) {
812 *error = ASCIIToUTF16("Web application definition not found or invalid.");
813 return false;
814 }
815
816 app_definition_fetcher_.reset(new ResourceFetcher(
817 pending_app_info_->manifest_url, webview()->mainFrame(),
818 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
819 return true;
820}
821
[email protected]1a3c3cb2010-12-16 21:03:40822void RenderView::SetReportLoadProgressEnabled(bool enabled) {
823 if (!enabled) {
824 load_progress_tracker_.reset(NULL);
825 return;
826 }
827 if (load_progress_tracker_ == NULL)
828 load_progress_tracker_.reset(new LoadProgressTracker(this));
829}
830
[email protected]bb461532010-11-26 21:50:23831void RenderView::DidDownloadApplicationDefinition(
832 const WebKit::WebURLResponse& response,
833 const std::string& data) {
834 scoped_ptr<WebApplicationInfo> app_info(
835 pending_app_info_.release());
836
837 JSONStringValueSerializer serializer(data);
838 int error_code = 0;
839 std::string error_message;
840 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
841 if (!result.get()) {
842 AddErrorToRootConsole(UTF8ToUTF16(error_message));
843 return;
844 }
845
846 string16 error_message_16;
847 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
848 &error_message_16)) {
849 AddErrorToRootConsole(error_message_16);
850 return;
851 }
852
853 if (!app_info->icons.empty()) {
854 pending_app_info_.reset(app_info.release());
855 pending_app_icon_requests_ =
856 static_cast<int>(pending_app_info_->icons.size());
857 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
858 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
859 new ImageResourceFetcher(
860 pending_app_info_->icons[i].url,
861 webview()->mainFrame(),
862 static_cast<int>(i),
863 pending_app_info_->icons[i].width,
864 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
865 }
866 } else {
867 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
868 }
869}
870
871void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
872 const SkBitmap& image) {
873 pending_app_info_->icons[fetcher->id()].data = image;
874
875 // Remove the image fetcher from our pending list. We're in the callback from
876 // ImageResourceFetcher, best to delay deletion.
877 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
878 iter != app_icon_fetchers_.end(); ++iter) {
879 if (iter->get() == fetcher) {
880 iter->release();
881 app_icon_fetchers_.erase(iter);
882 break;
883 }
884 }
885
886 // We're in the callback from the ImageResourceFetcher, best to delay
887 // deletion.
888 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
889
890 if (--pending_app_icon_requests_ > 0)
891 return;
892
893 // There is a maximum size of IPC on OS X and Linux that we have run into in
894 // some situations. We're not sure what it is, but our hypothesis is in the
895 // neighborhood of 1 MB.
896 //
897 // To be on the safe side, we give ourselves 128 KB for just the image data.
898 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
899 // want to start allowing larger icons (see bug 63406), we'll have to either
900 // experiment mor ewith this and find the real limit, or else come up with
901 // some alternative way to transmit the icon data to the browser process.
902 //
903 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32904 const size_t kMaxIconSize = 1024 * 128;
905 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23906 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32907 size_t current_size = pending_app_info_->icons[i].data.getSize();
908 if (current_size > kMaxIconSize - actual_icon_size) {
909 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23910 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32911 return;
912 }
913 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23914 }
915
916 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
917 pending_app_info_.reset(NULL);
918}
919
[email protected]a3a8fb6d2009-10-22 20:12:51920void RenderView::PluginCrashed(const FilePath& plugin_path) {
921 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29922}
923
[email protected]aad51d1c2010-08-05 08:38:09924WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
925 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50926 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26927 bool found;
928 ContentSetting setting;
929 std::string mime_type;
930 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17931 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
932 &found, &info, &setting, &mime_type));
[email protected]b83ff222011-01-24 17:37:12933 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09934 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45935
[email protected]0bd753682010-12-16 18:15:52936 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45937 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09938 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26939 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45940 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09941}
942
[email protected]d8fd6fa2010-02-01 15:54:26943void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
944 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30945 // If the renderer is visible, set initial visibility and focus state.
946 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34947#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30948 delegate->SetContainerVisibility(true);
949 if (webview() && webview()->isActive())
950 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34951#endif
[email protected]49232292010-09-03 19:07:30952 }
[email protected]784ea1ab2010-09-18 00:02:34953 // Plugins start assuming the content has focus (so that they work in
954 // environments where RenderView isn't hosting them), so we always have to
955 // set the initial state. See webplugin_delegate_impl.h for details.
956 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26957}
958
959void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
960 plugin_delegates_.erase(delegate);
961}
[email protected]d8fd6fa2010-02-01 15:54:26962
[email protected]a95986a82010-12-24 06:19:28963bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27964 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27965 if (main_frame)
966 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26967
[email protected]676126f72011-01-15 00:03:51968 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
969 RenderViewObserver* observer;
970 while ((observer = it.GetNext()) != NULL)
971 if (observer->OnMessageReceived(message))
972 return true;
[email protected]b2abac72009-02-26 12:39:28973
[email protected]a95986a82010-12-24 06:19:28974 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29975 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04976 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
977 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29978 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01979 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
[email protected]521b2482011-01-15 00:10:10980 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview)
981 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu,
982 OnPrintNodeUnderContextMenu)
initial.commit09911bf2008-07-26 23:55:29983 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
984 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56985 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29986 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
987 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
988 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
989 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27990#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35991 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27992#endif
initial.commit09911bf2008-07-26 23:55:29993 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
994 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05995 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
996 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
997 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04998 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29999 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
1000 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
1001 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:151002 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:291003 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491004 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1005 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171006 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541007 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1008 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171009 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541010 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1011 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291012 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181013 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1014 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281015 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:331016 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:291017 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481018 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291019 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291020 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291021 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1022 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1023 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1024 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451025 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291026 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:501027 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1028 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291029 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1030 OnDragSourceSystemDragEnded)
1031 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511032 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1033 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291034 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1035 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1036 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1037 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]90dba072011-01-20 20:10:201038 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1039 OnDisplayPrerenderedPage)
initial.commit09911bf2008-07-26 23:55:291040 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1041 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291042 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1043 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041044 IPC_MESSAGE_HANDLER(
1045 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1046 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291047 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041048 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291049 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1050 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451051 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041052 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081053 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1054 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401055 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1056 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001057 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271058 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371059 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1060 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161061 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141062 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251063 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1064 OnEnablePreferredSizeChangedMode)
[email protected]ce833282010-11-04 15:48:391065 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxChange, OnSearchBoxChange)
1066 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxSubmit, OnSearchBoxSubmit)
1067 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxCancel, OnSearchBoxCancel)
1068 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxResize, OnSearchBoxResize)
1069 IPC_MESSAGE_HANDLER(ViewMsg_DetermineIfPageSupportsInstant,
1070 OnDetermineIfPageSupportsInstant)
[email protected]cda45c02010-02-25 19:28:101071 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1072 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511073 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531074 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1075 OnUpdateBrowserWindowId)
1076 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1077 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561078 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341079 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141080#if defined(OS_MACOSX)
1081 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131082 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131083 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1084 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141085#endif
[email protected]446705872009-09-10 07:22:481086 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331087 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351088 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1089 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331090 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1091 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:141092 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361093 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1094 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1095 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421096 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1097 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241098 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]caf706f2010-10-26 17:54:081099#if defined(OS_MACOSX)
1100 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1101#endif
[email protected]a6097f42011-01-10 08:50:511102 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1103 OnJavaScriptStressTestControl)
[email protected]521b2482011-01-15 00:10:101104 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]634a6f92008-12-01 21:39:311105
[email protected]f0557932011-01-25 20:20:511106 // TODO(viettrungluu): Move to a separate message filter.
1107#if defined(ENABLE_FLAPPER_HACKS)
1108 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
1109#endif
1110
initial.commit09911bf2008-07-26 23:55:291111 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281112 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291113 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281114 return handled;
initial.commit09911bf2008-07-26 23:55:291115}
1116
[email protected]9b18a84f2010-06-10 15:54:041117void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271118 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291119 if (!main_frame)
1120 return;
1121
1122 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451123 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291124 if (url.is_empty())
1125 return;
1126
1127 if (size_.IsEmpty())
1128 return; // Don't create an empty thumbnail!
1129
1130 ThumbnailScore score;
1131 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021132 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151133 &thumbnail, &score))
1134 return;
1135
initial.commit09911bf2008-07-26 23:55:291136 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461137 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291138}
1139
[email protected]9b18a84f2010-06-10 15:54:041140void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231141 SkBitmap snapshot;
1142 bool error = false;
1143
1144 WebFrame* main_frame = webview()->mainFrame();
1145 if (!main_frame)
1146 error = true;
1147
1148 if (!error && !CaptureSnapshot(webview(), &snapshot))
1149 error = true;
1150
1151 DCHECK(error == snapshot.empty()) <<
1152 "Snapshot should be empty on error, non-empty otherwise.";
1153
1154 // Send the snapshot to the browser process.
1155 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1156}
1157
[email protected]068637222009-01-29 16:58:071158void RenderView::OnPrintPages() {
[email protected]c7a827e2011-01-21 00:27:011159 OnPrint(false);
initial.commit09911bf2008-07-26 23:55:291160}
1161
[email protected]82270452009-06-19 15:58:011162void RenderView::OnPrintingDone(int document_cookie, bool success) {
1163 // Ignoring document cookie here since only one print job can be outstanding
1164 // per renderer and document_cookie is 0 when printing is successful.
1165 DCHECK(print_helper_.get());
1166 if (print_helper_.get() != NULL) {
1167 print_helper_->DidFinishPrinting(success);
1168 }
1169}
1170
[email protected]212a49d2010-10-25 18:23:471171void RenderView::OnPrintPreview() {
[email protected]c7a827e2011-01-21 00:27:011172 OnPrint(true);
[email protected]212a49d2010-10-25 18:23:471173}
1174
[email protected]521b2482011-01-15 00:10:101175void RenderView::OnPrintNodeUnderContextMenu() {
1176 if (context_menu_node_.isNull()) {
1177 NOTREACHED();
1178 return;
1179 }
1180
1181 // Make a copy of the node, since we will do a sync call to the browser and
1182 // during that time OnContextMenuClosed might reset context_menu_node_.
1183 WebNode context_menu_node(context_menu_node_);
1184 GetPrintWebViewHelper()->PrintNode(&context_menu_node, false, false);
1185}
1186
initial.commit09911bf2008-07-26 23:55:291187void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1188 if (load_id != page_id_)
1189 return; // this capture call is no longer relevant due to navigation
1190 if (load_id == last_indexed_page_id_)
1191 return; // we already indexed this page
1192
1193 if (!webview())
1194 return;
1195
[email protected]26aa0482009-09-30 16:55:271196 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291197 if (!main_frame)
1198 return;
1199
1200 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451201 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291202 return;
1203
1204 // Don't index/capture pages that failed to load. This only checks the top
1205 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451206 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281207 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291208 return;
1209
1210 if (!preliminary_capture)
1211 last_indexed_page_id_ = load_id;
1212
[email protected]a8a81292010-01-21 00:32:451213 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451214 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291215 if (url.is_empty())
1216 return;
1217
[email protected]a8a81292010-01-21 00:32:451218 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361219 string16 contents;
initial.commit09911bf2008-07-26 23:55:291220 CaptureText(main_frame, &contents);
1221 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101222 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371223 // If the page explicitly specifies a language, use it, otherwise we'll
1224 // determine it based on the text content using the CLD.
1225 std::string language =
1226 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1227 if (language.empty()) {
1228 base::TimeTicks begin_time = base::TimeTicks::Now();
1229 language = DetermineTextLanguage(contents);
1230 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1231 base::TimeTicks::Now() - begin_time);
1232 }
[email protected]a8a81292010-01-21 00:32:451233 // Send the text to the browser for indexing (the browser might decide not
1234 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371235 Send(new ViewHostMsg_PageContents(
1236 routing_id_, url, load_id, contents, language,
1237 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271238 }
1239
[email protected]d54169e92011-01-21 09:19:521240 // Generate the thumbnail here if the in-browser thumbnailing isn't
1241 // enabled. TODO(satorux): Remove this and related code once
1242 // crbug.com/65936 is complete.
1243 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1244 switches::kEnableInBrowserThumbnailing)) {
1245 OnCaptureThumbnail();
1246 }
[email protected]3ead1322010-11-19 20:01:001247
1248 if (phishing_delegate_.get())
1249 phishing_delegate_->FinishedLoad(&contents);
initial.commit09911bf2008-07-26 23:55:291250}
1251
[email protected]e5106202010-06-11 21:12:361252void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291253 contents->clear();
1254 if (!frame)
1255 return;
1256
1257#ifdef TIME_TEXT_RETRIEVAL
1258 double begin = time_util::GetHighResolutionTimeNow();
1259#endif
1260
1261 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361262 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291263
1264#ifdef TIME_TEXT_RETRIEVAL
1265 double end = time_util::GetHighResolutionTimeNow();
1266 char buf[128];
1267 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1268 contents.size(), (end - begin)*1000);
1269 OutputDebugStringA(buf);
1270#endif
1271
1272 // When the contents are clipped to the maximum, we don't want to have a
1273 // partial word indexed at the end that might have been clipped. Therefore,
1274 // terminate the string at the last space to ensure no words are clipped.
1275 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361276 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291277 if (last_space_index == std::wstring::npos)
1278 return; // don't index if we got a huge block of text with no spaces
1279 contents->resize(last_space_index);
1280 }
1281}
1282
[email protected]8649fb32009-06-26 17:51:021283bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291284 int w,
1285 int h,
1286 SkBitmap* thumbnail,
1287 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231288 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151289
[email protected]8649fb32009-06-26 17:51:021290 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231291
1292 // Paint |view| into |canvas|.
1293 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021294 return false;
[email protected]8649fb32009-06-26 17:51:021295
1296 skia::BitmapPlatformDevice& device =
1297 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1298
1299 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291300
[email protected]cab34d6a2009-09-24 01:14:521301 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291302 float dest_aspect = dest_rect.width() / dest_rect.height();
1303
1304 // Get the src rect so that we can preserve the aspect ratio while filling
1305 // the destination.
1306 SkIRect src_rect;
1307 if (src_bmp.width() < dest_rect.width() ||
1308 src_bmp.height() < dest_rect.height()) {
1309 // Source image is smaller: we clip the part of source image within the
1310 // dest rect, and then stretch it to fill the dest rect. We don't respect
1311 // the aspect ratio in this case.
1312 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1313 static_cast<S16CPU>(dest_rect.height()));
1314 score->good_clipping = false;
1315 } else {
1316 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1317 if (src_aspect > dest_aspect) {
1318 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1319 // the wider screen.
1320 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1321 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1322 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1323 score->good_clipping = false;
1324 } else {
1325 src_rect.set(0, 0, src_bmp.width(),
1326 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1327 score->good_clipping = true;
1328 }
1329 }
1330
[email protected]26aa0482009-09-30 16:55:271331 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291332
1333 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021334 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291335
[email protected]82afe4b2010-11-12 20:36:221336 // First do a fast downsample by powers of two to get close to the final size.
1337 SkBitmap downsampled_subset =
1338 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1339
1340 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141341 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221342 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291343
1344 score->boring_score = CalculateBoringScore(thumbnail);
1345
[email protected]30507922010-01-15 16:48:231346 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1347 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221348
[email protected]b6e4bec2008-11-12 01:17:151349 return true;
initial.commit09911bf2008-07-26 23:55:291350}
1351
[email protected]30507922010-01-15 16:48:231352bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1353 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291354
[email protected]30507922010-01-15 16:48:231355 skia::PlatformCanvas canvas;
1356 if (!PaintViewIntoCanvas(view, canvas))
1357 return false;
1358
1359 skia::BitmapPlatformDevice& device =
1360 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1361
1362 const SkBitmap& bitmap = device.accessBitmap(false);
1363 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1364 return false;
1365
1366 HISTOGRAM_TIMES("Renderer4.Snapshot",
1367 base::TimeTicks::Now() - beginning_time);
1368 return true;
initial.commit09911bf2008-07-26 23:55:291369}
1370
1371void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1372 if (!webview())
1373 return;
1374
[email protected]3cc72b12010-03-18 23:03:001375 history_list_offset_ = params.current_history_list_offset;
1376 history_list_length_ = params.current_history_list_length;
1377
[email protected]a9f607e2009-10-23 19:59:271378 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261379
initial.commit09911bf2008-07-26 23:55:291380 AboutHandler::MaybeHandle(params.url);
1381
[email protected]ecbf10d2010-02-18 13:03:291382 bool is_reload =
1383 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1384 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291385
[email protected]26aa0482009-09-30 16:55:271386 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451387 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291388 // We cannot reload if we do not have any history state. This happens, for
1389 // example, when recovering from a crash. Our workaround here is a bit of
1390 // a hack since it means that reload after a crashed tab does not cause an
1391 // end-to-end cache validation.
1392 is_reload = false;
1393 }
1394
[email protected]77f17a82009-05-21 04:42:541395 // A navigation resulting from loading a javascript URL should not be treated
1396 // as a browser initiated event. Instead, we want it to look as if the page
1397 // initiated any load resulting from JS execution.
1398 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301399 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001400 params.page_id,
1401 params.pending_history_list_offset,
1402 params.transition,
1403 params.request_time);
[email protected]5e369672009-11-03 23:48:301404 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1405 // We're doing a load of a page that was restored from the last session.
1406 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1407 // which can result in stale data for pages that are set to expire. We
1408 // explicitly override that by setting the policy here so that as
1409 // necessary we load from the network.
1410 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1411 }
1412 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541413 }
initial.commit09911bf2008-07-26 23:55:291414
[email protected]a7ccc4d2010-01-27 08:14:481415 NavigationState* navigation_state = pending_navigation_state_.get();
1416
[email protected]04d3c6e2009-05-22 17:00:131417 // If we are reloading, then WebKit will use the history state of the current
1418 // page, so we should just ignore any given history state. Otherwise, if we
1419 // have history state, then we need to navigate to it, which corresponds to a
1420 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551421 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481422 if (navigation_state)
1423 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291424 bool ignore_cache = (params.navigation_type ==
1425 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1426 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551427 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131428 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581429 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481430 if (navigation_state)
1431 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451432 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171433 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131434 } else {
1435 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281436 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291437
[email protected]e6f546c32009-07-01 17:12:551438 // A session history navigation should have been accompanied by state.
1439 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131440
[email protected]dd7daa82009-08-10 05:46:451441 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551442 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131443
[email protected]726985e22009-06-18 21:09:281444 if (params.referrer.is_valid()) {
1445 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1446 WebString::fromUTF8(params.referrer.spec()));
1447 }
[email protected]04d3c6e2009-05-22 17:00:131448
[email protected]52c68652010-12-07 17:47:041449 if (!params.extra_headers.empty()) {
1450 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1451 params.extra_headers.end(), "\n");
1452 i.GetNext(); ) {
1453 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1454 WebString::fromUTF8(i.values()));
1455 }
1456 }
1457
[email protected]90dba072011-01-20 20:10:201458 if (navigation_state) {
1459 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1460 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1461 } else {
1462 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
1463 navigation_state->set_is_prerendering(true);
1464 }
1465 }
[email protected]dd7daa82009-08-10 05:46:451466 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501467 }
1468
[email protected]77f17a82009-05-21 04:42:541469 // In case LoadRequest failed before DidCreateDataSource was called.
1470 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291471}
1472
1473// Stop loading the current page
1474void RenderView::OnStop() {
1475 if (webview())
[email protected]b4bb2502009-10-01 22:35:271476 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291477}
1478
[email protected]ecbf10d2010-02-18 13:03:291479// Reload current focused frame.
1480// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561481void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291482 if (webview() && webview()->focusedFrame()) {
1483 // We always obey the cache (ignore_cache=false) here.
1484 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1485 // a cache-ignoring reload of the frame.
1486 webview()->focusedFrame()->reload(false);
1487 }
[email protected]1dda4022010-01-28 18:24:561488}
1489
initial.commit09911bf2008-07-26 23:55:291490void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271491 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291492}
1493
[email protected]68b1e922009-06-23 16:00:251494void RenderView::OnExecuteEditCommand(const std::string& name,
1495 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271496 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251497 return;
1498
[email protected]26aa0482009-09-30 16:55:271499 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451500 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251501}
1502
[email protected]b2abac72009-02-26 12:39:281503void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511504 DCHECK(!devtools_client_);
1505 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281506}
1507
initial.commit09911bf2008-07-26 23:55:291508void RenderView::OnUpdateTargetURLAck() {
1509 // Check if there is a targeturl waiting to be sent.
1510 if (target_url_status_ == TARGET_PENDING) {
1511 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1512 pending_target_url_));
1513 }
1514
1515 target_url_status_ = TARGET_NONE;
1516}
1517
1518void RenderView::OnUndo() {
1519 if (!webview())
1520 return;
1521
[email protected]26aa0482009-09-30 16:55:271522 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121523 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291524}
1525
1526void RenderView::OnRedo() {
1527 if (!webview())
1528 return;
1529
[email protected]26aa0482009-09-30 16:55:271530 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121531 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291532}
1533
1534void RenderView::OnCut() {
1535 if (!webview())
1536 return;
1537
[email protected]26aa0482009-09-30 16:55:271538 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121539 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291540}
1541
1542void RenderView::OnCopy() {
1543 if (!webview())
1544 return;
1545
[email protected]26aa0482009-09-30 16:55:271546 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121547 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291548}
1549
[email protected]c0cc3092009-09-12 08:27:271550#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351551void RenderView::OnCopyToFindPboard() {
1552 if (!webview())
1553 return;
1554
1555 // Since the find pasteboard supports only plain text, this can be simpler
1556 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271557 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351558 if (frame->hasSelection()) {
1559 string16 selection = frame->selectionAsText();
1560 RenderThread::current()->Send(
1561 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1562 }
1563
[email protected]afe3a1672009-11-17 19:04:121564 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351565}
[email protected]c0cc3092009-09-12 08:27:271566#endif
[email protected]a954bf72009-09-12 07:30:351567
initial.commit09911bf2008-07-26 23:55:291568void RenderView::OnPaste() {
1569 if (!webview())
1570 return;
1571
[email protected]26aa0482009-09-30 16:55:271572 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121573 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]2a3a7762009-10-19 19:17:321576void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291577 if (!webview())
1578 return;
1579
[email protected]1ff7a032010-02-03 02:46:031580 WebFrame* frame = webview()->focusedFrame();
1581 if (!frame->hasSelection())
1582 frame->selectWordAroundCaret();
1583 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291584}
1585
[email protected]98324892009-09-09 21:16:051586void RenderView::OnAdvanceToNextMisspelling() {
1587 if (!webview())
1588 return;
[email protected]26aa0482009-09-30 16:55:271589 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051590 WebString::fromUTF8("AdvanceToNextMisspelling"));
1591}
1592
1593void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1594 if (!webview())
1595 return;
1596 // We need to tell the webView whether the spelling panel is visible or not so
1597 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261598 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271599 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051600 WebString::fromUTF8("ToggleSpellPanel"));
1601}
1602
[email protected]bbbd545c2008-12-15 20:18:041603void RenderView::OnToggleSpellCheck() {
1604 if (!webview())
1605 return;
1606
[email protected]26aa0482009-09-30 16:55:271607 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451608 frame->enableContinuousSpellChecking(
1609 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041610}
1611
initial.commit09911bf2008-07-26 23:55:291612void RenderView::OnDelete() {
1613 if (!webview())
1614 return;
1615
[email protected]26aa0482009-09-30 16:55:271616 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121617 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291618}
1619
1620void RenderView::OnSelectAll() {
1621 if (!webview())
1622 return;
1623
[email protected]26aa0482009-09-30 16:55:271624 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221625 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121626 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291627}
1628
1629void RenderView::OnSetInitialFocus(bool reverse) {
1630 if (!webview())
1631 return;
[email protected]26aa0482009-09-30 16:55:271632 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291633}
1634
[email protected]9b66f34bf2010-10-27 20:45:511635void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091636 WebKit::WebNode node = GetFocusedNode();
1637 if (!node.isNull()) {
1638 if (IsEditableNode(node))
1639 // TODO(varunjain): Change webkit API to scroll a particular node into
1640 // view and use that API here instead.
1641 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511642 }
1643}
1644
initial.commit09911bf2008-07-26 23:55:291645///////////////////////////////////////////////////////////////////////////////
1646
[email protected]433819d2010-01-30 20:20:011647void RenderView::SetContentSettings(const ContentSettings& settings) {
1648 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011649}
1650
initial.commit09911bf2008-07-26 23:55:291651// Tell the embedding application that the URL of the active page has changed
1652void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451653 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291654 DCHECK(ds);
1655
[email protected]726985e22009-06-18 21:09:281656 const WebURLRequest& request = ds->request();
1657 const WebURLRequest& original_request = ds->originalRequest();
1658 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291659
[email protected]daa8c58e2009-06-15 17:21:101660 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1661 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291662
1663 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281664 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291665 params.is_post = false;
1666 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071667 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281668 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091669 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551670 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291671 // SSL state specified in the request takes precedence over the one in the
1672 // response.
1673 // So far this is only intended for error pages that are not expected to be
1674 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281675 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551676 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291677 } else {
[email protected]726985e22009-06-18 21:09:281678 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291679 }
1680
1681 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281682 if (ds->hasUnreachableURL()) {
1683 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291684 } else {
[email protected]726985e22009-06-18 21:09:281685 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291686 }
1687
[email protected]726985e22009-06-18 21:09:281688 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241689 params.should_update_history = !ds->hasUnreachableURL() &&
1690 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291691
[email protected]ce0e250d2009-10-23 21:00:351692 params.searchable_form_url = navigation_state->searchable_form_url();
1693 params.searchable_form_encoding =
1694 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291695
1696 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101697 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291698 if (password_form_data)
1699 params.password_form = *password_form_data;
1700
1701 params.gesture = navigation_gesture_;
1702 navigation_gesture_ = NavigationGestureUnknown;
1703
[email protected]dd7daa82009-08-10 05:46:451704 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291705 // Top-level navigation.
1706
[email protected]71b0d5d2010-02-15 05:43:071707 // Clear "block" flags for the new page. This needs to happen before any of
1708 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1709 // so that these functions can correctly detect that a piece of content
1710 // flipped from "not blocked" to "blocked".
1711 ClearBlockedContentSettings();
1712
[email protected]62d2a112010-04-07 00:53:021713 // Set content settings. Default them from the parent window if one exists.
1714 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011715 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541716 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011717 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011718 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011719
1720 // These content settings were merely recorded transiently for this load.
1721 // We can erase them now. If at some point we reload this page, the
1722 // browser will send us new, up-to-date content settings.
1723 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401724 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101725 // The opener's view is not guaranteed to be non-null (it could be
1726 // detached from its page but not yet destructed).
1727 if (WebView* opener_view = frame->opener()->view()) {
1728 RenderView* opener = FromWebView(opener_view);
1729 SetContentSettings(opener->current_content_settings_);
1730 }
[email protected]f85f0702010-01-30 09:31:011731 }
1732
[email protected]b75b8292010-10-01 07:28:251733 // Set zoom level, but don't do it for full-page plugin since they don't use
1734 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011735 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541736 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251737 if (webview()->mainFrame()->document().isPluginDocument()) {
1738 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251739 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251740 } else {
1741 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251742 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251743 }
1744
[email protected]f85f0702010-01-30 09:31:011745 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511746 // This zoom level was merely recorded transiently for this load. We can
1747 // erase it now. If at some point we reload this page, the browser will
1748 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011749 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511750 }
1751
[email protected]b75b8292010-10-01 07:28:251752 // Reset the zoom limits in case a plugin had changed them previously. This
1753 // will also call us back which will cause us to send a message to
1754 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251755 webview()->zoomLimitsChanged(
1756 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1757 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251758
initial.commit09911bf2008-07-26 23:55:291759 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551760 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291761
[email protected]daa8c58e2009-06-15 17:21:101762 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291763 if (!PageTransition::IsMainFrame(params.transition)) {
1764 // If the main frame does a load, it should not be reported as a subframe
1765 // navigation. This can occur in the following case:
1766 // 1. You're on a site with frames.
1767 // 2. You do a subframe navigation. This is stored with transition type
1768 // MANUAL_SUBFRAME.
1769 // 3. You navigate to some non-frame site, say, google.com.
1770 // 4. You navigate back to the page from step 2. Since it was initially
1771 // MANUAL_SUBFRAME, it will be that same transition type here.
1772 // We don't want that, because any navigation that changes the toplevel
1773 // frame should be tracked as a toplevel navigation (this allows us to
1774 // update the URL bar, etc).
1775 params.transition = PageTransition::LINK;
1776 }
1777
initial.commit09911bf2008-07-26 23:55:291778 // If we have a valid consumed client redirect source,
1779 // the page contained a client redirect (meta refresh, document.loc...),
1780 // so we set the referrer and transition to match.
1781 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041782 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291783 params.referrer = completed_client_redirect_src_;
1784 params.transition = static_cast<PageTransition::Type>(
1785 params.transition | PageTransition::CLIENT_REDIRECT);
1786 } else {
1787 // Bug 654101: the referrer will be empty on https->http transitions. It
1788 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281789 params.referrer = GURL(
1790 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291791 }
1792
[email protected]726985e22009-06-18 21:09:281793 string16 method = request.httpMethod();
1794 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291795 params.is_post = true;
1796
[email protected]c2a797d2009-09-21 16:46:321797 // Save some histogram data so we can compute the average memory used per
1798 // page load of the glyphs.
1799 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1800 webkit_glue::GetGlyphPageCount());
1801
[email protected]15cf526b2010-02-12 06:33:491802 // This message needs to be sent before any of allowScripts(),
1803 // allowImages(), allowPlugins() is called for the new page, so that when
1804 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1805 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291806 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1807 } else {
1808 // Subframe navigation: the type depends on whether this navigation
1809 // generated a new session history entry. When they do generate a session
1810 // history entry, it means the user initiated the navigation and we should
1811 // mark it as such. This test checks if this is the first time UpdateURL
1812 // has been called since WillNavigateToURL was called to initiate the load.
1813 if (page_id_ > last_page_id_sent_to_browser_)
1814 params.transition = PageTransition::MANUAL_SUBFRAME;
1815 else
1816 params.transition = PageTransition::AUTO_SUBFRAME;
1817
initial.commit09911bf2008-07-26 23:55:291818 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1819 }
1820
1821 last_page_id_sent_to_browser_ =
1822 std::max(last_page_id_sent_to_browser_, page_id_);
1823
1824 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101825 // we don't want the transition type to persist. Just clear it.
1826 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501827
[email protected]af15bed2010-08-25 21:12:091828 // Check if the navigation was within the same page, in which case we don't
1829 // want to clear the accessibility cache.
1830 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351831 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141832 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501833 }
initial.commit09911bf2008-07-26 23:55:291834}
1835
1836// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171837void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291838 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171839 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171840 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171841 routing_id_,
1842 page_id_,
1843 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1844 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171845 }
initial.commit09911bf2008-07-26 23:55:291846}
1847
1848void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401849 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291850 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271851 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291852 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301853 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291854 last_encoding_name_ = encoding_name;
1855
[email protected]e38f40152008-09-12 23:08:301856 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291857 }
1858}
1859
[email protected]e15f680732010-11-23 22:30:201860// Sends the last committed session history state to the browser so it will be
1861// saved before we navigate to a new page. This must be called *before* the
1862// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291863void RenderView::UpdateSessionHistory(WebFrame* frame) {
1864 // If we have a valid page ID at this point, then it corresponds to the page
1865 // we are navigating away from. Otherwise, this is the first navigation, so
1866 // there is no past session history to record.
1867 if (page_id_ == -1)
1868 return;
1869
[email protected]ca948a22009-06-25 19:36:171870 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271871 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171872 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291873 return;
[email protected]ca948a22009-06-25 19:36:171874
1875 Send(new ViewHostMsg_UpdateState(
1876 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291877}
1878
[email protected]3d9689372009-09-10 04:29:171879void RenderView::OpenURL(
1880 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1881 Send(new ViewHostMsg_OpenURL(
1882 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1883}
1884
[email protected]79dbc662009-09-04 05:42:511885// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291886
initial.commit09911bf2008-07-26 23:55:291887void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281888 const WebURLRequest& failed_request,
1889 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291890 const std::string& html,
1891 bool replace) {
[email protected]726985e22009-06-18 21:09:281892 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291893 std::string alt_html;
[email protected]2a521c52011-01-26 18:45:211894 const Extension* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291895 if (html.empty()) {
1896 // Use a local error page.
1897 int resource_id;
1898 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111899
[email protected]81654282010-10-04 17:08:061900 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]2a521c52011-01-26 18:45:211901 extension = render_thread_->GetExtensions()->GetByURL(failed_url);
[email protected]5351dbc2010-08-27 15:22:111902 if (extension) {
[email protected]3f853a52010-09-13 19:15:081903 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1904 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111905
1906 // TODO(erikkay): Should we use a different template for different
1907 // error messages?
1908 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291909 } else {
[email protected]3f853a52010-09-13 19:15:081910 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1911 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111912 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081913 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111914 } else {
[email protected]3f853a52010-09-13 19:15:081915 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111916 }
[email protected]75891fe2010-11-20 15:55:181917 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291918 }
initial.commit09911bf2008-07-26 23:55:291919
1920 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1921 } else {
1922 alt_html = html;
1923 }
1924
[email protected]dd7daa82009-08-10 05:46:451925 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361926 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551927 failed_url,
1928 replace);
initial.commit09911bf2008-07-26 23:55:291929}
1930
[email protected]7ccddb8c2009-08-04 17:36:551931void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031932 if (!dom_automation_controller_.get()) {
1933 dom_automation_controller_.reset(new DomAutomationController());
1934 }
1935 dom_automation_controller_->set_message_sender(this);
1936 dom_automation_controller_->set_routing_id(routing_id_);
1937 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251938 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291939}
1940
initial.commit09911bf2008-07-26 23:55:291941bool RenderView::RunJavaScriptMessage(int type,
1942 const std::wstring& message,
1943 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071944 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291945 std::wstring* result) {
1946 bool success = false;
1947 std::wstring result_temp;
1948 if (!result)
1949 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291950
[email protected]12636df2009-09-28 22:32:211951 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1952 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291953 return success;
1954}
1955
[email protected]c1f50aa2010-02-18 03:46:571956bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1957 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1958 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1959 // it is particularly important that we do not call willEnterModalLoop as
1960 // that would defer resource loads for the dialog itself.
1961 if (RenderThread::current()) // Will be NULL during unit tests.
1962 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1963
1964 message->EnableMessagePumping(); // Runs a nested message loop.
1965 return Send(message);
1966}
1967
[email protected]2de7e002010-10-11 22:58:201968void RenderView::AddGURLSearchProvider(
1969 const GURL& osd_url,
1970 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291971 if (!osd_url.is_empty())
1972 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201973 provider_type));
initial.commit09911bf2008-07-26 23:55:291974}
1975
[email protected]e8345242010-05-06 03:00:401976void RenderView::OnAllowScriptToClose(bool script_can_close) {
1977 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311978}
1979
initial.commit09911bf2008-07-26 23:55:291980uint32 RenderView::GetCPBrowsingContext() {
1981 uint32 context = 0;
1982 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1983 return context;
1984}
1985
[email protected]2de7e002010-10-11 22:58:201986void RenderView::AddSearchProvider(
1987 const std::string& url,
1988 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1989 if (provider_type.type ==
1990 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1991 !webview()->mainFrame()->isProcessingUserGesture())
1992 return;
1993
1994 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291995}
1996
[email protected]155f35e2010-07-17 00:30:181997ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251998RenderView::GetSearchProviderInstallState(WebFrame* frame,
1999 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:182000 GURL inquiry_url = GURL(url);
2001 if (inquiry_url.is_empty())
2002 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:252003
[email protected]155f35e2010-07-17 00:30:182004 ViewHostMsg_GetSearchProviderInstallState_Params install;
2005 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:252006 frame->url(),
[email protected]155f35e2010-07-17 00:30:182007 inquiry_url,
2008 &install));
2009 return install;
2010}
2011
[email protected]f103ab72009-09-02 17:10:592012void RenderView::OnMissingPluginStatus(
2013 WebPluginDelegateProxy* delegate,
2014 int status) {
[email protected]6c8afae52009-01-22 02:24:572015#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:592016 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:292017 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:502018 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:592019 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:292020 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2021 }
2022 } else {
2023 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2024 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:502025 if (status ==
2026 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:292027 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2028 }
2029 }
[email protected]6c8afae52009-01-22 02:24:572030#else
[email protected]76c3b312010-05-20 21:38:292031 // TODO(port): Implement the infobar that accompanies the default plugin.
2032 // Linux: http://crbug.com/10952
2033 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:572034 NOTIMPLEMENTED();
2035#endif
initial.commit09911bf2008-07-26 23:55:292036}
2037
[email protected]48c9cf2d2009-09-16 16:47:522038// WebKit::WebViewClient ------------------------------------------------------
2039
[email protected]844acf372011-01-14 10:49:272040WebView* RenderView::createView(
2041 WebFrame* creator,
2042 const WebURLRequest& request,
2043 const WebWindowFeatures& features,
2044 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522045 // Check to make sure we aren't overloading on popups.
2046 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2047 return NULL;
2048
2049 // This window can't be closed from a window.close() call until we receive a
2050 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402051 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522052
[email protected]8ab04652010-06-12 02:47:262053 ViewHostMsg_CreateWindow_Params params;
2054 params.opener_id = routing_id_;
2055 params.user_gesture = creator->isProcessingUserGesture();
2056 params.window_container_type = WindowFeaturesToContainerType(features);
2057 params.session_storage_namespace_id = session_storage_namespace_id_;
2058 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112059 params.opener_frame_id = creator->identifier();
2060 params.opener_url = creator->url();
2061 params.opener_security_origin = creator->securityOrigin().toString().utf8();
2062 if (!request.isNull())
2063 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262064
[email protected]48c9cf2d2009-09-16 16:47:522065 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342066 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262067 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522068
[email protected]48c9cf2d2009-09-16 16:47:522069 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262070 new ViewHostMsg_CreateWindow(params,
2071 &routing_id,
2072 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212073 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522074 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522075
[email protected]48c9cf2d2009-09-16 16:47:522076 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422077 0,
[email protected]12636df2009-09-28 22:32:212078 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522079 renderer_preferences_,
2080 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212081 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342082 routing_id,
[email protected]8ab04652010-06-12 02:47:262083 cloned_session_storage_namespace_id,
2084 frame_name);
2085 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522086
[email protected]007a848b2009-10-26 15:55:462087 // Record whether the creator frame is trying to suppress the opener field.
2088 view->opener_suppressed_ = opener_suppressed;
2089
[email protected]48c9cf2d2009-09-16 16:47:522090 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092091 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522092 if (!creator_url.is_valid() || !creator_url.IsStandard())
2093 creator_url = GURL();
2094 view->creator_url_ = creator_url;
2095
2096 // Copy over the alternate error page URL so we can have alt error pages in
2097 // the new render view (we don't need the browser to send the URL back down).
2098 view->alternate_error_page_url_ = alternate_error_page_url_;
2099
2100 return view->webview();
2101}
2102
[email protected]3e2b375b2010-04-07 17:03:122103WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522104 RenderWidget* widget = RenderWidget::Create(routing_id_,
2105 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122106 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522107 return widget->webwidget();
2108}
2109
2110WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442111 // TODO(jcivelli): Remove this deprecated method when its been removed from
2112 // the WebViewClient interface. It's been replaced by
2113 // createExternalPopupMenu.
2114 NOTREACHED();
2115 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522116}
2117
[email protected]caf706f2010-10-26 17:54:082118WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2119 const WebPopupMenuInfo& popup_menu_info,
2120 WebExternalPopupMenuClient* popup_menu_client) {
2121 DCHECK(!external_popup_menu_.get());
2122 external_popup_menu_.reset(
2123 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2124 return external_popup_menu_.get();
2125}
2126
[email protected]484955942010-08-19 16:13:182127WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
2128 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
2129 render_thread_,
2130 popup_type);
2131 return widget->webwidget();
2132}
2133
[email protected]0bd753682010-12-16 18:15:522134webkit::ppapi::FullscreenContainer*
2135RenderView::CreatePepperFullscreenContainer(
2136 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392137 RenderWidgetFullscreenPepper* widget =
2138 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2139 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562140 return widget;
[email protected]79c7bed2010-09-14 22:28:392141}
2142
[email protected]68c50e52010-05-12 11:14:392143WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342144 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392145 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292146 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2147 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2148 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342149}
2150
[email protected]48c9cf2d2009-09-16 16:47:522151void RenderView::didAddMessageToConsole(
2152 const WebConsoleMessage& message, const WebString& source_name,
2153 unsigned source_line) {
2154 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2155 UTF16ToWideHack(message.text),
2156 static_cast<int32>(source_line),
2157 UTF16ToWideHack(source_name)));
2158}
2159
2160void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:582161 DCHECK(frame);
[email protected]212a49d2010-10-25 18:23:472162 if (CommandLine::ForCurrentProcess()->HasSwitch(
2163 switches::kEnablePrintPreview)) {
2164 Print(frame, true, true);
2165 } else {
2166 Print(frame, true, false);
2167 }
[email protected]48c9cf2d2009-09-16 16:47:522168}
2169
[email protected]3354d3e2010-06-10 19:53:022170WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512171 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022172}
2173
[email protected]48c9cf2d2009-09-16 16:47:522174void RenderView::didStartLoading() {
2175 if (is_loading_) {
2176 DLOG(WARNING) << "didStartLoading called while loading";
2177 return;
2178 }
2179
2180 is_loading_ = true;
2181 // Clear the pointer so that we can assign it only when there is an unknown
2182 // plugin on a page.
2183 first_default_plugin_.reset();
2184
2185 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2186}
2187
2188void RenderView::didStopLoading() {
2189 if (!is_loading_) {
2190 DLOG(WARNING) << "DidStopLoading called while not loading";
2191 return;
2192 }
2193
2194 is_loading_ = false;
2195
2196 // NOTE: For now we're doing the safest thing, and sending out notification
2197 // when done loading. This currently isn't an issue as the favicon is only
2198 // displayed when done loading. Ideally we would send notification when
2199 // finished parsing the head, but webkit doesn't support that yet.
2200 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272201 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522202 if (!favicon_url.is_empty())
2203 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
2204
[email protected]26aa0482009-09-30 16:55:272205 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202206 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522207
2208 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2209
[email protected]90109412010-12-15 17:14:242210 if (load_progress_tracker_ != NULL)
2211 load_progress_tracker_->DidStopLoading();
2212
[email protected]f9f4841b2010-03-20 05:41:422213 MessageLoop::current()->PostDelayedTask(
2214 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302215 page_info_method_factory_.NewRunnableMethod(
2216 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372217 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522218}
2219
[email protected]90109412010-12-15 17:14:242220void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2221 if (load_progress_tracker_ != NULL)
2222 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2223}
2224
[email protected]f55039a2010-02-17 14:12:062225bool RenderView::isSmartInsertDeleteEnabled() {
2226#if defined(OS_MACOSX)
2227 return true;
2228#else
2229 return false;
2230#endif
2231}
2232
[email protected]04fc9482009-09-18 22:13:032233bool RenderView::isSelectTrailingWhitespaceEnabled() {
2234#if defined(OS_WIN)
2235 return true;
2236#else
2237 return false;
2238#endif
2239}
2240
[email protected]04fc9482009-09-18 22:13:032241void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422242#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032243 if (!handling_input_event_)
2244 return;
2245 // TODO(estade): investigate incremental updates to the selection so that we
2246 // don't send the entire selection over IPC every time.
2247 if (!is_empty_selection) {
2248 // Sometimes we get repeated didChangeSelection calls from webkit when
2249 // the selection hasn't actually changed. We don't want to report these
2250 // because it will cause us to continually claim the X clipboard.
2251 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272252 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032253 if (this_selection == last_selection_)
2254 return;
2255
2256 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2257 this_selection));
2258 last_selection_ = this_selection;
2259 } else {
2260 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162261 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2262 last_selection_));
[email protected]04fc9482009-09-18 22:13:032263 }
[email protected]0ff0ff32010-12-21 19:34:422264#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032265}
2266
2267void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122268 const std::string& name = UTF16ToUTF8(command_name);
2269 if (StartsWithASCII(name, "Move", true) ||
2270 StartsWithASCII(name, "Insert", true) ||
2271 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032272 return;
2273 UserMetricsRecordAction(name);
2274}
2275
[email protected]54ec7f82010-10-21 22:32:512276void RenderView::SendPendingAccessibilityNotifications() {
2277 if (!accessibility_.get())
2278 return;
2279
2280 if (pending_accessibility_notifications_.empty())
2281 return;
2282
2283 // Send all pending accessibility notifications.
2284 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2285 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2286 RendererAccessibilityNotification& notification =
2287 pending_accessibility_notifications_[i];
2288 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2289 if (!obj.isValid())
2290 continue;
2291
2292 ViewHostMsg_AccessibilityNotification_Params param;
2293 param.notification_type = pending_accessibility_notifications_[i].type;
[email protected]70eee342010-11-05 01:59:372294 param.acc_obj = WebAccessibility(
2295 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512296 notifications.push_back(param);
2297 }
2298 pending_accessibility_notifications_.clear();
2299 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2300 accessibility_ack_pending_ = true;
2301}
2302
[email protected]b2528b72009-09-24 06:57:102303bool RenderView::handleCurrentKeyboardEvent() {
2304 if (edit_commands_.empty())
2305 return false;
2306
[email protected]26aa0482009-09-30 16:55:272307 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102308 if (!frame)
2309 return false;
2310
2311 EditCommands::iterator it = edit_commands_.begin();
2312 EditCommands::iterator end = edit_commands_.end();
2313
[email protected]507b33ea2009-09-29 03:56:512314 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102315 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332316 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2317 // key (but it's the exception). Once one edit command is not executed, it
2318 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102319 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2320 WebString::fromUTF8(it->value)))
2321 break;
[email protected]507b33ea2009-09-29 03:56:512322 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102323 }
2324
[email protected]507b33ea2009-09-29 03:56:512325 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102326}
2327
[email protected]2a3a7762009-10-19 19:17:322328void RenderView::spellCheck(const WebString& text,
2329 int& misspelled_offset,
2330 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562331 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462332
[email protected]85c55dc2009-11-06 03:05:462333 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172334 RenderThread* thread = RenderThread::current();
2335 // Will be NULL during unit tests.
2336 if (thread) {
[email protected]c27324b2009-11-19 22:44:292337 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172338 word.c_str(), word.size(), document_tag_,
2339 &misspelled_offset, &misspelled_length, NULL);
2340 }
[email protected]1dbafaf72009-09-23 19:43:562341}
2342
2343WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322344 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562345 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262346 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562347 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172348 RenderThread* thread = RenderThread::current();
2349 // Will be NULL during unit tests.
2350 if (thread) {
2351 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292352 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172353 word, document_tag_);
2354 }
[email protected]1dbafaf72009-09-23 19:43:562355 }
[email protected]2a3a7762009-10-19 19:17:322356 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562357}
2358
[email protected]c49085c72009-10-02 16:28:562359void RenderView::showSpellingUI(bool show) {
2360 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2361}
2362
[email protected]8922e1f2009-10-03 05:01:262363bool RenderView::isShowingSpellingUI() {
2364 return spelling_panel_visible_;
2365}
2366
[email protected]1dbafaf72009-09-23 19:43:562367void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322368 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2369 word));
[email protected]1dbafaf72009-09-23 19:43:562370}
2371
[email protected]13a1e4c3c2011-02-03 21:07:092372void RenderView::continuousSpellCheckingEnabledStateChanged() {
2373 UpdateToggleSpellCheckCommandState();
2374}
2375
[email protected]a1128322009-10-06 18:38:462376bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352377 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472378 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352379 // Do not open the file dialog in a hidden RenderView.
2380 if (is_hidden())
2381 return false;
[email protected]cdaf8d02010-03-30 19:52:472382 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262383 if (params.directory)
2384 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2385 else if (params.multiSelect)
2386 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2387 else
2388 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472389 ipc_params.title = params.title;
2390 ipc_params.default_file_name =
2391 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592392 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472393
2394 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462395}
2396
[email protected]48c9cf2d2009-09-16 16:47:522397void RenderView::runModalAlertDialog(
2398 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062399 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:522400 UTF16ToWideHack(message),
2401 std::wstring(),
2402 frame->url(),
2403 NULL);
2404}
2405
2406bool RenderView::runModalConfirmDialog(
2407 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062408 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:522409 UTF16ToWideHack(message),
2410 std::wstring(),
2411 frame->url(),
2412 NULL);
2413}
2414
2415bool RenderView::runModalPromptDialog(
2416 WebFrame* frame, const WebString& message, const WebString& default_value,
2417 WebString* actual_value) {
2418 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:062419 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:522420 UTF16ToWideHack(message),
2421 UTF16ToWideHack(default_value),
2422 frame->url(),
2423 &result);
2424 if (ok)
2425 actual_value->assign(WideToUTF16Hack(result));
2426 return ok;
2427}
2428
2429bool RenderView::runModalBeforeUnloadDialog(
2430 WebFrame* frame, const WebString& message) {
2431 bool success = false;
2432 // This is an ignored return value, but is included so we can accept the same
2433 // response as RunJavaScriptMessage.
2434 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212435 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522436 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212437 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522438 return success;
2439}
2440
[email protected]79e37442009-10-09 18:17:442441void RenderView::showContextMenu(
2442 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292443 ContextMenuParams params = ContextMenuParams(data);
2444 if (!params.misspelled_word.empty() && RenderThread::current()) {
2445 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042446 bool spelled_right = RenderThread::current()->spellchecker()->
2447 SpellCheckWord(
2448 params.misspelled_word.c_str(), params.misspelled_word.size(),
2449 document_tag_,
2450 &misspelled_offset, &misspelled_length,
2451 &params.dictionary_suggestions);
2452 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292453 params.misspelled_word.clear();
2454 }
[email protected]216932c2010-08-26 21:44:272455 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2456 // it. We replace it with an empty GURL so the appropriate items are disabled
2457 // in the context menu.
2458 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2459 // data encoded images. We should have a way to save them.
2460 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2461 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102462 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292463 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442464}
2465
[email protected]52f139e2c2010-06-11 16:56:092466bool RenderView::supportsFullscreen() {
2467 return CommandLine::ForCurrentProcess()->HasSwitch(
2468 switches::kEnableVideoFullscreen);
2469}
2470
2471void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2472 NOTIMPLEMENTED();
2473}
2474
2475void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2476 NOTIMPLEMENTED();
2477}
2478
[email protected]48c9cf2d2009-09-16 16:47:522479void RenderView::setStatusText(const WebString& text) {
2480}
2481
[email protected]163f8242009-10-30 20:19:552482void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582483 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522484 if (latest_url == target_url_)
2485 return;
[email protected]163f8242009-10-30 20:19:552486
[email protected]48c9cf2d2009-09-16 16:47:522487 // Tell the browser to display a destination link.
2488 if (target_url_status_ == TARGET_INFLIGHT ||
2489 target_url_status_ == TARGET_PENDING) {
2490 // If we have a request in-flight, save the URL to be sent when we
2491 // receive an ACK to the in-flight request. We can happily overwrite
2492 // any existing pending sends.
2493 pending_target_url_ = latest_url;
2494 target_url_status_ = TARGET_PENDING;
2495 } else {
2496 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2497 target_url_ = latest_url;
2498 target_url_status_ = TARGET_INFLIGHT;
2499 }
2500}
2501
[email protected]13a1e4c3c2011-02-03 21:07:092502void RenderView::UpdateToggleSpellCheckCommandState() {
2503 bool is_enabled = false;
2504 WebKit::WebNode node = GetFocusedNode();
2505 if (!node.isNull())
2506 is_enabled = IsEditableNode(node);
2507
2508 RenderViewCommandCheckedState checked_state =
2509 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
2510 if (is_enabled && webview()) {
2511 WebFrame* frame = webview()->focusedFrame();
2512 if (frame->isContinuousSpellCheckingEnabled())
2513 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED;
2514 }
2515
2516 Send(new ViewHostMsg_CommandStateChanged(
2517 routing_id_,
2518 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK,
2519 is_enabled,
2520 checked_state));
2521}
2522
[email protected]882daa92009-11-05 16:31:312523void RenderView::StartNavStateSyncTimerIfNecessary() {
2524 int delay;
2525 if (send_content_state_immediately_)
2526 delay = 0;
2527 else if (is_hidden())
2528 delay = kDelaySecondsForContentStateSyncHidden;
2529 else
2530 delay = kDelaySecondsForContentStateSync;
2531
2532 if (nav_state_sync_timer_.IsRunning()) {
2533 // The timer is already running. If the delay of the timer maches the amount
2534 // we want to delay by, then return. Otherwise stop the timer so that it
2535 // gets started with the right delay.
2536 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2537 return;
2538 nav_state_sync_timer_.Stop();
2539 }
2540
2541 nav_state_sync_timer_.Start(
2542 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2543}
2544
[email protected]163f8242009-10-30 20:19:552545void RenderView::setMouseOverURL(const WebURL& url) {
2546 mouse_over_url_ = GURL(url);
2547 UpdateTargetURL(mouse_over_url_, focus_url_);
2548}
2549
2550void RenderView::setKeyboardFocusURL(const WebURL& url) {
2551 focus_url_ = GURL(url);
2552 UpdateTargetURL(focus_url_, mouse_over_url_);
2553}
2554
[email protected]48c9cf2d2009-09-16 16:47:522555void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2556 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2557 hint));
2558}
2559
[email protected]c27ae592010-03-18 15:24:412560void RenderView::startDragging(const WebDragData& data,
2561 WebDragOperationsMask mask,
2562 const WebImage& image,
2563 const WebPoint& imageOffset) {
2564#if WEBKIT_USING_SKIA
2565 SkBitmap bitmap(image.getSkBitmap());
2566#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332567 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412568#endif
2569
[email protected]48c9cf2d2009-09-16 16:47:522570 Send(new ViewHostMsg_StartDragging(routing_id_,
2571 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412572 mask,
2573 bitmap,
2574 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522575}
2576
[email protected]28b92df2009-09-25 17:35:452577bool RenderView::acceptsLoadDrops() {
2578 return renderer_preferences_.can_accept_load_drops;
2579}
2580
[email protected]48c9cf2d2009-09-16 16:47:522581void RenderView::focusNext() {
2582 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2583}
2584
2585void RenderView::focusPrevious() {
2586 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2587}
2588
[email protected]08e9e132010-06-01 16:58:492589void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512590 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072591
2592 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2593 // TODO(ctguil): Make WebKit send this notification.
2594 // When focus is cleared notify accessibility that the document is focused.
2595 postAccessibilityNotification(
2596 webview()->accessibilityObject(),
2597 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2598 }
[email protected]13a1e4c3c2011-02-03 21:07:092599
2600 UpdateToggleSpellCheckCommandState();
[email protected]08e9e132010-06-01 16:58:492601}
2602
[email protected]48c9cf2d2009-09-16 16:47:522603void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522604 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2605}
2606
2607int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002608 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522609}
2610
2611int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002612 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522613}
2614
[email protected]c4e98902010-06-01 10:20:142615void RenderView::didUpdateInspectorSetting(const WebString& key,
2616 const WebString& value) {
2617 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2618 key.utf8(),
2619 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262620}
2621
[email protected]79dbc662009-09-04 05:42:512622// WebKit::WebWidgetClient ----------------------------------------------------
2623
[email protected]ea42e7782010-08-23 23:58:122624void RenderView::didFocus() {
2625 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2626 // we won't have to test for user gesture anymore and we can
2627 // move that code back to render_widget.cc
2628 if (webview() && webview()->mainFrame() &&
2629 webview()->mainFrame()->isProcessingUserGesture()) {
2630 Send(new ViewHostMsg_Focus(routing_id_));
2631 }
2632}
2633
2634void RenderView::didBlur() {
2635 // TODO(jcivelli): see TODO above in didFocus().
2636 if (webview() && webview()->mainFrame() &&
2637 webview()->mainFrame()->isProcessingUserGesture()) {
2638 Send(new ViewHostMsg_Blur(routing_id_));
2639 }
2640}
2641
initial.commit09911bf2008-07-26 23:55:292642// We are supposed to get a single call to Show for a newly created RenderView
2643// that was created via RenderView::CreateWebView. So, we wait until this
2644// point to dispatch the ShowView message.
2645//
2646// This method provides us with the information about how to display the newly
2647// created RenderView (i.e., as a constrained popup or as a new tab).
2648//
[email protected]4873c7d2009-07-16 06:36:282649void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292650 DCHECK(!did_show_) << "received extraneous Show call";
2651 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2652
2653 if (did_show_)
2654 return;
2655 did_show_ = true;
2656
[email protected]4026ce1e2010-09-14 19:35:042657 // Extensions and apps always allowed to create unrequested popups. The second
2658 // check is necessary to include content scripts.
[email protected]2a521c52011-01-26 18:45:212659 if (render_thread_->GetExtensions()->GetByURL(creator_url_) ||
[email protected]4026ce1e2010-09-14 19:35:042660 bindings_utils::GetInfoForCurrentContext()) {
2661 opened_by_user_gesture_ = true;
2662 }
2663
[email protected]28295ec2009-10-16 05:34:332664 // Force new windows to a popup if they were not opened with a user gesture.
2665 if (!opened_by_user_gesture_) {
2666 // We exempt background tabs for compat with older versions of Chrome.
2667 // TODO(darin): This seems bogus. These should have a user gesture, so
2668 // we probably don't need this check.
2669 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2670 policy = WebKit::WebNavigationPolicyNewPopup;
2671 }
2672
initial.commit09911bf2008-07-26 23:55:292673 // NOTE: initial_pos_ may still have its default values at this point, but
2674 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2675 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282676 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2677 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292678 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242679 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292680}
2681
[email protected]4873c7d2009-07-16 06:36:282682void RenderView::closeWidgetSoon() {
[email protected]3ead1322010-11-19 20:01:002683 // Same for the phishing classifier.
2684 if (phishing_delegate_.get())
2685 phishing_delegate_->CancelPendingClassification();
2686
[email protected]e8345242010-05-06 03:00:402687 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282688 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312689}
2690
[email protected]4873c7d2009-07-16 06:36:282691void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292692 DCHECK(did_show_) << "should already have shown the view";
2693
[email protected]c1f50aa2010-02-18 03:46:572694 // We must keep WebKit's shared timer running in this case in order to allow
2695 // showModalDialog to function properly.
2696 //
2697 // TODO(darin): WebKit should really be smarter about suppressing events and
2698 // timers so that we do not need to manage the shared timer in such a heavy
2699 // handed manner.
2700 //
2701 if (RenderThread::current()) // Will be NULL during unit tests.
2702 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2703
[email protected]12636df2009-09-28 22:32:212704 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292705}
2706
[email protected]3d9689372009-09-10 04:29:172707// WebKit::WebFrameClient -----------------------------------------------------
2708
[email protected]00152e92010-07-19 11:47:402709WebPlugin* RenderView::createPlugin(WebFrame* frame,
2710 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262711 bool found = false;
[email protected]414508d2010-11-02 10:45:392712 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282713 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502714 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242715 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262716 std::string actual_mime_type;
[email protected]c8f73ab2011-01-22 00:05:172717 Send(new ViewHostMsg_GetPluginInfo(routing_id_,
2718 url,
[email protected]6fdd4182010-10-14 23:59:262719 frame->top()->url(),
2720 params.mimeType.utf8(),
2721 &found,
2722 &info,
[email protected]44fda5c2010-11-02 10:50:542723 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262724 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242725
[email protected]6fdd4182010-10-14 23:59:262726 if (!found)
[email protected]0cdafff2010-07-26 09:54:372727 return NULL;
[email protected]414508d2010-11-02 10:45:392728 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]4e0616e2010-05-28 14:55:532729
[email protected]191eb3f72010-12-21 06:27:502730 const webkit::npapi::PluginGroup* group =
2731 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412732 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292733
[email protected]6e74a3b2010-12-21 22:27:542734 if (group->IsVulnerable() &&
2735 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
[email protected]3c2826852010-12-16 19:09:142736 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2737 group->GetGroupName(),
2738 GURL(group->GetUpdateURL())));
2739 return CreatePluginPlaceholder(frame,
2740 params,
2741 *group,
[email protected]2e34ab3f2010-12-17 05:47:372742 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202743 IDS_PLUGIN_OUTDATED,
2744 false);
[email protected]851b1eb2010-08-09 13:32:292745 }
[email protected]6e74a3b2010-12-21 22:27:542746
[email protected]b83ff222011-01-24 17:37:122747 if (!webkit::npapi::IsPluginEnabled(info))
[email protected]3c2826852010-12-16 19:09:142748 return NULL;
[email protected]851b1eb2010-08-09 13:32:292749
[email protected]414508d2010-11-02 10:45:392750 ContentSetting host_setting =
2751 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]d12dcdd62011-01-27 06:53:252752
2753 if (group->RequiresAuthorization() &&
2754 !cmd->HasSwitch(switches::kAlwaysAuthorizePlugins) &&
2755 (plugin_setting == CONTENT_SETTING_ALLOW ||
2756 plugin_setting == CONTENT_SETTING_ASK) &&
2757 host_setting == CONTENT_SETTING_DEFAULT) {
2758 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2759 group->GetGroupName(),
2760 GURL()));
2761 return CreatePluginPlaceholder(frame,
2762 params,
2763 *group,
2764 IDR_BLOCKED_PLUGIN_HTML,
2765 IDS_PLUGIN_NOT_AUTHORIZED,
2766 false);
2767 }
2768
[email protected]191eb3f72010-12-21 06:27:502769 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392770 plugin_setting == CONTENT_SETTING_ALLOW ||
2771 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]90dba072011-01-20 20:10:202772 // Delay loading plugins if prerendering.
2773 WebDataSource* ds = frame->dataSource();
2774 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2775 if (navigation_state->is_prerendering()) {
2776 return CreatePluginPlaceholder(frame,
2777 params,
2778 *group,
2779 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2780 IDS_PLUGIN_LOAD,
2781 true);
2782 }
2783
[email protected]0bd753682010-12-16 18:15:522784 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452785 pepper_delegate_.CreatePepperPlugin(info.path));
2786 if (pepper_module)
2787 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262788 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372789 }
[email protected]fc61e222010-10-11 15:42:142790 std::string resource;
2791 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2792 resource = group->identifier();
2793 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392794 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142795 return CreatePluginPlaceholder(frame,
2796 params,
2797 *group,
[email protected]2e34ab3f2010-12-17 05:47:372798 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202799 IDS_PLUGIN_LOAD,
2800 false);
[email protected]fc61e222010-10-11 15:42:142801 } else {
[email protected]3c2826852010-12-16 19:09:142802 return CreatePluginPlaceholder(frame,
2803 params,
2804 *group,
[email protected]2e34ab3f2010-12-17 05:47:372805 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202806 IDS_PLUGIN_BLOCKED,
2807 false);
[email protected]fc61e222010-10-11 15:42:142808 }
[email protected]3d9689372009-09-10 04:29:172809}
2810
2811WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562812 WebApplicationCacheHostImpl* appcache_host =
2813 WebApplicationCacheHostImpl::FromFrame(frame);
2814 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2815 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2816 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172817}
2818
[email protected]9c00f002009-11-05 22:37:422819WebSharedWorker* RenderView::createSharedWorker(
2820 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372821 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422822
[email protected]30447b62009-11-13 01:13:372823 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512824 bool exists = false;
[email protected]30447b62009-11-13 01:13:372825 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512826 ViewHostMsg_CreateWorker_Params params;
2827 params.url = url;
2828 params.is_shared = true;
2829 params.name = name;
2830 params.document_id = document_id;
2831 params.render_view_route_id = routing_id_;
2832 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232833 params.parent_appcache_host_id = 0;
2834 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372835 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512836 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372837 if (url_mismatch) {
2838 return NULL;
2839 } else {
2840 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492841 document_id,
[email protected]6de0bcf2010-02-17 22:00:512842 exists,
[email protected]30447b62009-11-13 01:13:372843 route_id,
2844 routing_id_);
2845 }
[email protected]9c00f002009-11-05 22:37:422846}
2847
[email protected]3d9689372009-09-10 04:29:172848WebMediaPlayer* RenderView::createMediaPlayer(
2849 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f78d1dfc2011-01-15 07:09:272850 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2851 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492852 scoped_ptr<media::FilterCollection> collection(
2853 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372854
[email protected]3d9689372009-09-10 04:29:172855 // Add in any custom filter factories first.
2856 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2857 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2858 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492859 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172860 }
2861
[email protected]3bb08602010-10-07 21:47:172862 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122863 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072864 WebGraphicsContext3DCommandBufferImpl* context =
2865 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2866 frame->view()->graphicsContext3D());
2867 if (!context)
2868 return NULL;
[email protected]a9a43012010-11-05 01:54:062869
[email protected]5aa6a312010-11-06 00:00:072870 // Add the hardware video decoder factory.
2871 // TODO(hclam): This will cause the renderer process to crash on context
2872 // lost.
2873 bool ret = context->makeContextCurrent();
2874 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492875 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072876 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172877 }
2878
[email protected]457d8342010-10-23 01:20:372879 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312880 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2881 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2882 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492883 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312884 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112885
[email protected]a8e24d522010-12-01 07:13:582886 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272887 new webkit_glue::WebMediaPlayerImpl(client,
2888 collection.release(),
2889 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:462890 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582891 cmd_line->HasSwitch(switches::kSimpleDataSource),
2892 video_renderer)) {
2893 return NULL;
2894 }
2895 return result.release();
[email protected]3d9689372009-09-10 04:29:172896}
2897
[email protected]035545f2010-04-09 13:10:212898WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2899 WebFrame* frame, WebApplicationCacheHostClient* client) {
2900 return new RendererWebApplicationCacheHostImpl(
2901 FromWebView(frame->view()), client,
2902 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2903}
2904
[email protected]8ff181072010-11-29 17:09:382905WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2906 return &cookie_jar_;
2907}
2908
[email protected]5041f982010-08-11 21:40:452909void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512910 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452911}
2912
[email protected]3d9689372009-09-10 04:29:172913void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302914 WebDataSource* ds = frame->dataSource();
2915 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522916
[email protected]a5a65ac2010-11-05 18:14:362917 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302918 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182919
[email protected]676126f72011-01-15 00:03:512920 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172921}
2922
[email protected]684e4a42010-01-30 06:44:112923bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402924 if (enabled_per_settings &&
2925 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2926 return true;
2927
2928 if (IsWhitelistedForContentSettings(frame))
2929 return true;
2930
[email protected]55126132010-08-19 14:53:282931 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402932 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112933}
2934
[email protected]d5f9e4f2010-07-28 08:31:302935bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162936 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302937}
2938
2939
[email protected]3d9689372009-09-10 04:29:172940void RenderView::loadURLExternally(
2941 WebFrame* frame, const WebURLRequest& request,
2942 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592943 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2944 if (policy == WebKit::WebNavigationPolicyDownload) {
2945 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2946 } else {
2947 OpenURL(request.url(), referrer, policy);
2948 }
[email protected]3d9689372009-09-10 04:29:172949}
2950
2951WebNavigationPolicy RenderView::decidePolicyForNavigation(
2952 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222953 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172954 // Webkit is asking whether to navigate to a new URL.
2955 // This is fine normally, except if we're showing UI from one security
2956 // context and they're trying to navigate to a different context.
2957 const GURL& url = request.url();
2958
2959 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302960 // navigations.
[email protected]8079b362010-05-07 18:37:452961 if (renderer_preferences_.browser_handles_top_level_requests &&
2962 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192963 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232964 // Reset these counters as the RenderView could be reused for the next
2965 // navigation.
2966 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232967 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192968 OpenURL(url, referrer, default_policy);
2969 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172970 }
2971
2972 // A content initiated navigation may have originated from a link-click,
2973 // script, drag-n-drop operation, etc.
2974 bool is_content_initiated =
2975 NavigationState::FromDataSource(frame->provisionalDataSource())->
2976 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582977 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172978
[email protected]6101c342010-12-16 22:44:372979 // Detect when we're crossing a permission-based boundary (e.g. into or out of
2980 // an extension or app origin, leaving a DOMUI page, etc). We only care about
2981 // top-level navigations withing the current tab (as opposed to, for example,
2982 // opening a new window). But we sometimes navigate to about:blank to clear a
2983 // tab, and we want to still allow that.
2984 //
2985 // Note: we do this only for GET requests because we our mechanism for
2986 // switching processes only issues GET requests. In particular, POST
2987 // requests don't work, because this mechanism does not preserve form POST
2988 // data. If it becomes necessary to support process switching for POST
2989 // requests, we will need to send the request's httpBody data up to the
2990 // browser process, and issue a special POST navigation in WebKit (via
2991 // FrameLoader::loadFrameRequest). See ResourceDispatcher and
2992 // WebURLLoaderImpl for examples of how to send the httpBody data.
2993 if (!frame->parent() && is_content_initiated &&
2994 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2995 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2996 bool send_referrer = false;
2997 bool should_fork =
2998 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172999 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:373000 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:113001
3002 // If the navigation would cross an app extent boundary, we also need
3003 // to defer to the browser to ensure process isolation.
3004 // TODO(erikkay) This is happening inside of a check to is_content_initiated
3005 // which means that things like the back button won't trigger it. Is that
3006 // OK?
[email protected]08e94b82010-12-15 22:51:043007 // TODO(creis): For now, we only swap processes to enter an app and not
3008 // exit it, since we currently lose context (e.g., window.opener) if the
3009 // window navigates back. See crbug.com/65953.
[email protected]2a521c52011-01-26 18:45:213010 if (!should_fork &&
3011 CrossesIntoExtensionExtent(
3012 render_thread_->GetExtensions(),
3013 frame,
3014 url)) {
[email protected]5351dbc2010-08-27 15:22:113015 // Include the referrer in this case since we're going from a hosted web
3016 // page. (the packaged case is handled previously by the extension
3017 // navigation test)
[email protected]6101c342010-12-16 22:44:373018 should_fork = true;
3019 send_referrer = true;
3020 }
3021
3022 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:113023 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:373024 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113025 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3026 }
[email protected]3d9689372009-09-10 04:29:173027 }
3028
3029 // Detect when a page is "forking" a new tab that can be safely rendered in
3030 // its own process. This is done by sites like Gmail that try to open links
3031 // in new windows without script connections back to the original page. We
3032 // treat such cases as browser navigations (in which we will create a new
3033 // renderer for a cross-site navigation), rather than WebKit navigations.
3034 //
3035 // We use the following heuristic to decide whether to fork a new page in its
3036 // own process:
3037 // The parent page must open a new tab to about:blank, set the new tab's
3038 // window.opener to null, and then redirect the tab to a cross-site URL using
3039 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463040 //
3041 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3042 // (see below).
[email protected]3d9689372009-09-10 04:29:173043 bool is_fork =
3044 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:583045 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173046 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523047 historyBackListCount() < 1 &&
3048 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173049 // The parent page must have set the child's window.opener to null before
3050 // redirecting to the desired URL.
3051 frame->opener() == NULL &&
3052 // Must be a top-level frame.
3053 frame->parent() == NULL &&
3054 // Must not have issued the request from this page.
3055 is_content_initiated &&
3056 // Must be targeted at the current tab.
3057 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3058 // Must be a JavaScript navigation, which appears as "other".
3059 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463060
3061 // Recognize if this navigation is from a link with rel=noreferrer and
3062 // target=_blank attributes, in which case the opener will be suppressed. If
3063 // so, it is safe to load cross-site pages in a separate process, so we
3064 // should let the browser handle it.
3065 bool is_noreferrer_and_blank_target =
3066 // Frame should be top level and not yet navigated.
3067 frame->parent() == NULL &&
3068 frame->url().isEmpty() &&
3069 historyBackListCount() < 1 &&
3070 historyForwardListCount() < 1 &&
3071 // Links with rel=noreferrer will have no Referer field, and their
3072 // resulting frame will have its window.opener suppressed.
3073 // TODO(creis): should add a request.httpReferrer() method to help avoid
3074 // typos on the unusual spelling of Referer.
3075 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3076 opener_suppressed_ &&
3077 frame->opener() == NULL &&
3078 // Links with target=_blank will have no name.
3079 frame->name().isNull() &&
3080 // Another frame (with a non-empty creator) should have initiated the
3081 // request, targeted at this frame.
3082 !creator_url_.is_empty() &&
3083 is_content_initiated &&
3084 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3085 type == WebKit::WebNavigationTypeOther;
3086
3087 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173088 // Open the URL via the browser, not via WebKit.
3089 OpenURL(url, GURL(), default_policy);
3090 return WebKit::WebNavigationPolicyIgnore;
3091 }
3092
3093 return default_policy;
3094}
3095
[email protected]6069da8c2009-10-20 20:33:493096bool RenderView::canHandleRequest(
3097 WebFrame* frame, const WebURLRequest& request) {
3098 // We allow WebKit to think that everything can be handled even though
3099 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343100 return true;
3101}
3102
[email protected]6069da8c2009-10-20 20:33:493103WebURLError RenderView::cannotHandleRequestError(
3104 WebFrame* frame, const WebURLRequest& request) {
3105 NOTREACHED(); // Since we said we can handle all requests.
3106 return WebURLError();
3107}
3108
3109WebURLError RenderView::cancelledError(
3110 WebFrame* frame, const WebURLRequest& request) {
3111 WebURLError error;
3112 error.domain = WebString::fromUTF8(net::kErrorDomain);
3113 error.reason = net::ERR_ABORTED;
3114 error.unreachableURL = request.url();
3115 return error;
[email protected]7b7a7dc2009-10-19 02:23:343116}
3117
3118void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493119 WebFrame*, const WebURLError&) {
3120 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343121}
3122
[email protected]90eeddb2010-05-06 21:06:433123void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3124 const WebKit::WebFormElement& form) {
3125 // Some login forms have onSubmit handlers that put a hash of the password
3126 // into a hidden field and then clear the password. (Issue 28910.)
3127 // This method gets called before any of those handlers run, so save away
3128 // a copy of the password in case it gets lost.
3129 NavigationState* navigation_state =
3130 NavigationState::FromDataSource(frame->dataSource());
3131 navigation_state->set_password_form_data(
3132 PasswordFormDomManager::CreatePasswordForm(form));
3133}
3134
[email protected]979c28b2009-11-07 01:30:483135void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173136 NavigationState* navigation_state =
3137 NavigationState::FromDataSource(frame->provisionalDataSource());
3138
3139 if (navigation_state->transition_type() == PageTransition::LINK)
3140 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3141
3142 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353143 WebSearchableFormData web_searchable_form_data(form);
3144 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3145 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213146 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433147 PasswordForm* password_form_data =
3148 PasswordFormDomManager::CreatePasswordForm(form);
3149 navigation_state->set_password_form_data(password_form_data);
3150
3151 // If the password has been cleared, recover it from the form contents already
3152 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3153 // opposed to the provisionalDataSource's, which is what we're storing into
3154 // now.)
3155 if (password_form_data && password_form_data->password_value.empty()) {
3156 NavigationState* old_navigation_state =
3157 NavigationState::FromDataSource(frame->dataSource());
3158 if (old_navigation_state) {
3159 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3160 if (old_form_data && old_form_data->action == password_form_data->action)
3161 password_form_data->password_value = old_form_data->password_value;
3162 }
3163 }
[email protected]3d9689372009-09-10 04:29:173164
[email protected]b1438212010-04-03 00:30:593165 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043166 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223167 form,
3168 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]78192082011-01-29 05:43:443169 static_cast<FormManager::ExtractMask>(
3170 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223171 &form_data)) {
[email protected]19d6e1e82011-01-26 05:08:583172 Send(new AutoFillHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223173 }
[email protected]3d9689372009-09-10 04:29:173174}
3175
3176void RenderView::willPerformClientRedirect(
3177 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3178 double fire_time) {
3179 // Ignore
3180}
3181
3182void RenderView::didCancelClientRedirect(WebFrame* frame) {
3183 // Ignore
3184}
3185
3186void RenderView::didCompleteClientRedirect(
3187 WebFrame* frame, const WebURL& from) {
3188 if (!frame->parent())
3189 completed_client_redirect_src_ = from;
3190}
3191
3192void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233193 // If there are any app-related fetches in progress, they can be cancelled now
3194 // since we have navigated away from the page that created them.
3195 if (!frame->parent()) {
3196 app_icon_fetchers_.clear();
3197 app_definition_fetcher_.reset(NULL);
3198 }
3199
[email protected]3d9689372009-09-10 04:29:173200 // The rest of RenderView assumes that a WebDataSource will always have a
3201 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483202 bool content_initiated = !pending_navigation_state_.get();
3203 NavigationState* state = content_initiated ?
3204 NavigationState::CreateContentInitiated() :
3205 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513206
[email protected]8a3125a712010-08-09 18:58:513207 // NavigationState::referred_by_prefetcher_ is true if we are
3208 // navigating from a page that used prefetching using a link on that
3209 // page. We are early enough in the request process here that we
3210 // can still see the NavigationState of the previous page and set
3211 // this value appropriately.
3212 // TODO(gavinp): catch the important case of navigation in a new
3213 // renderer process.
3214 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303215 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523216 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513217 const GURL referrer(
3218 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3219 if (!referrer.is_empty() &&
3220 NavigationState::FromDataSource(
3221 old_frame->dataSource())->was_prefetcher()) {
3222 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3223 WebDataSource* old_frame_ds = old_frame->dataSource();
3224 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3225 state->set_was_referred_by_prefetcher(true);
3226 break;
3227 }
3228 }
3229 }
3230 }
3231 }
3232
[email protected]4c1b6f0b2010-02-07 16:38:183233 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523234 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513235 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183236 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3237 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3238 break;
3239 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3240 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3241 break;
3242 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3243 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3244 break;
3245 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3246 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3247 break;
3248 }
3249 }
[email protected]fa7b6b542009-11-03 05:02:303250
[email protected]5792d932011-01-18 20:33:293251 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3252 // This is for navigations within a page (didNavigateWithinPage). See
3253 // http://code.google.com/p/chromium/issues/detail?id=64093
3254 NavigationState* old_state = NavigationState::FromDataSource(ds);
3255 if (old_state && old_state->user_script_idle_scheduler()) {
3256 state->swap_user_script_idle_scheduler(old_state);
3257 } else {
3258 state->set_user_script_idle_scheduler(
3259 new UserScriptIdleScheduler(this, frame));
3260 }
[email protected]fa7b6b542009-11-03 05:02:303261 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173262}
3263
3264void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3265 WebDataSource* ds = frame->provisionalDataSource();
3266 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3267
[email protected]3d9689372009-09-10 04:29:173268 // Update the request time if WebKit has better knowledge of it.
3269 if (navigation_state->request_time().is_null()) {
3270 double event_time = ds->triggeringEventTime();
3271 if (event_time != 0.0)
3272 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3273 }
3274
[email protected]05c8e502010-08-15 15:13:523275 // Start time is only set after request time.
3276 navigation_state->set_start_load_time(Time::Now());
3277
[email protected]3d9689372009-09-10 04:29:173278 bool is_top_most = !frame->parent();
3279 if (is_top_most) {
3280 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133281 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173282
3283 // Make sure redirect tracking state is clear for the new load.
3284 completed_client_redirect_src_ = GURL();
3285 } else if (frame->parent()->isLoading()) {
3286 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003287 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173288 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3289 }
3290
3291 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073292 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173293}
3294
3295void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3296 if (frame->parent())
3297 return;
3298 // Received a redirect on the main frame.
3299 WebDataSource* data_source = frame->provisionalDataSource();
3300 if (!data_source) {
3301 // Should only be invoked when we have a data source.
3302 NOTREACHED();
3303 return;
3304 }
3305 std::vector<GURL> redirects;
3306 GetRedirectChain(data_source, &redirects);
3307 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513308 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3309 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173310 }
3311}
3312
[email protected]40bd6582009-12-04 23:49:513313void RenderView::didFailProvisionalLoad(WebFrame* frame,
3314 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173315 // Notify the browser that we failed a provisional load with an error.
3316 //
3317 // Note: It is important this notification occur before DidStopLoading so the
3318 // SSL manager can react to the provisional load failure before being
3319 // notified the load stopped.
3320 //
3321 WebDataSource* ds = frame->provisionalDataSource();
3322 DCHECK(ds);
3323
3324 const WebURLRequest& failed_request = ds->request();
3325
3326 bool show_repost_interstitial =
3327 (error.reason == net::ERR_CACHE_MISS &&
3328 EqualsASCII(failed_request.httpMethod(), "POST"));
3329 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073330 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3331 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173332
3333 // Don't display an error page if this is simply a cancelled load. Aside
3334 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3335 if (error.reason == net::ERR_ABORTED)
3336 return;
3337
3338 // Make sure we never show errors in view source mode.
3339 frame->enableViewSourceMode(false);
3340
3341 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3342
3343 // If this is a failed back/forward/reload navigation, then we need to do a
3344 // 'replace' load. This is necessary to avoid messing up session history.
3345 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3346 // as session history is concerned.
3347 //
3348 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3349 // the page id.
3350 //
3351 bool replace =
3352 navigation_state->pending_page_id() != -1 ||
3353 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3354
3355 // If we failed on a browser initiated request, then make sure that our error
3356 // page load is regarded as the same browser initiated request.
3357 if (!navigation_state->is_content_initiated()) {
3358 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3359 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003360 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173361 navigation_state->transition_type(),
3362 navigation_state->request_time()));
3363 }
3364
3365 // Provide the user with a more helpful error page?
3366 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3367 return;
3368
3369 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083370 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173371}
3372
3373void RenderView::didReceiveDocumentData(
3374 WebFrame* frame, const char* data, size_t data_len,
3375 bool& prevent_default) {
3376 NavigationState* navigation_state =
3377 NavigationState::FromDataSource(frame->dataSource());
3378 if (!navigation_state->postpone_loading_data())
3379 return;
3380
3381 // We're going to call commitDocumentData ourselves...
3382 prevent_default = true;
3383
[email protected]3f853a52010-09-13 19:15:083384 // Continue buffering the response data for the original error page. If it
3385 // grows too large, then we'll just let it through. For any error other than
3386 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173387 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083388 if (navigation_state->postponed_data().size() >= 512 ||
3389 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173390 navigation_state->set_postpone_loading_data(false);
3391 frame->commitDocumentData(navigation_state->postponed_data().data(),
3392 navigation_state->postponed_data().size());
3393 navigation_state->clear_postponed_data();
3394 }
3395}
3396
[email protected]40bd6582009-12-04 23:49:513397void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3398 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173399 NavigationState* navigation_state =
3400 NavigationState::FromDataSource(frame->dataSource());
3401
3402 navigation_state->set_commit_load_time(Time::Now());
3403 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203404 // When we perform a new navigation, we need to update the last committed
3405 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173406 UpdateSessionHistory(frame);
3407
3408 // We bump our Page ID to correspond with the new session history entry.
3409 page_id_ = next_page_id_++;
3410
[email protected]3ead1322010-11-19 20:01:003411 // Let the phishing classifier decide whether to cancel classification.
3412 if (phishing_delegate_.get())
3413 phishing_delegate_->CommittedLoadInFrame(frame);
3414
[email protected]3cc72b12010-03-18 23:03:003415 // Advance our offset in session history, applying the length limit. There
3416 // is now no forward history.
3417 history_list_offset_++;
3418 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3419 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3420 history_list_length_ = history_list_offset_ + 1;
3421
[email protected]f9f4841b2010-03-20 05:41:423422 MessageLoop::current()->PostDelayedTask(
3423 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303424 page_info_method_factory_.NewRunnableMethod(
3425 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173426 kDelayForForcedCaptureMs);
3427 } else {
3428 // Inspect the navigation_state on this frame to see if the navigation
3429 // corresponds to a session history navigation... Note: |frame| may or
3430 // may not be the toplevel frame, but for the case of capturing session
3431 // history, the first committed frame suffices. We keep track of whether
3432 // we've seen this commit before so that only capture session history once
3433 // per navigation.
3434 //
3435 // Note that we need to check if the page ID changed. In the case of a
3436 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3437 // previous URL and the current page ID, which would be wrong.
3438 if (navigation_state->pending_page_id() != -1 &&
3439 navigation_state->pending_page_id() != page_id_ &&
3440 !navigation_state->request_committed()) {
3441 // This is a successful session history navigation!
3442 UpdateSessionHistory(frame);
3443 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003444
3445 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173446 }
3447 }
3448
3449 // Remember that we've already processed this request, so we don't update
3450 // the session history again. We do this regardless of whether this is
3451 // a session history navigation, because if we attempted a session history
3452 // navigation without valid HistoryItem state, WebCore will think it is a
3453 // new navigation.
3454 navigation_state->set_request_committed(true);
3455
3456 UpdateURL(frame);
3457
3458 // If this committed load was initiated by a client redirect, we're
3459 // at the last stop now, so clear it.
3460 completed_client_redirect_src_ = GURL();
3461
3462 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273463 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173464}
3465
3466void RenderView::didClearWindowObject(WebFrame* frame) {
3467 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3468 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453469 GURL frame_url = frame->url();
3470 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253471 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]731ae512010-10-15 18:20:173472 frame_url.SchemeIs(chrome::kGearsScheme) ||
[email protected]bfa83eb82010-10-06 08:41:253473 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273474 GetWebUIBindings()->set_message_sender(this);
3475 GetWebUIBindings()->set_routing_id(routing_id_);
3476 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173477 }
3478 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463479 GetExternalHostBindings()->set_message_sender(this);
3480 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253481 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173482 }
3483}
3484
3485void RenderView::didCreateDocumentElement(WebFrame* frame) {
3486 if (RenderThread::current()) { // Will be NULL during unit tests.
3487 RenderThread::current()->user_script_slave()->InjectScripts(
3488 frame, UserScript::DOCUMENT_START);
3489 }
3490
3491 // Notify the browser about non-blank documents loading in the top frame.
3492 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253493 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273494 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173495 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3496 }
3497}
3498
3499void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3500 UpdateTitle(frame, title);
3501
3502 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273503 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173504}
3505
[email protected]5019ef12010-04-27 17:26:583506void RenderView::didChangeIcons(WebFrame* frame) {
3507 if (!frame->parent()) {
3508 Send(new ViewHostMsg_UpdateFavIconURL(
3509 routing_id_,
3510 page_id_,
3511 frame->favIconURL()));
3512 }
3513}
3514
[email protected]3d9689372009-09-10 04:29:173515void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3516 WebDataSource* ds = frame->dataSource();
3517 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3518 DCHECK(navigation_state);
3519 navigation_state->set_finish_document_load_time(Time::Now());
3520
[email protected]622474d2010-11-04 09:21:083521 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173522
[email protected]676126f72011-01-15 00:03:513523 FOR_EACH_OBSERVER(
3524 RenderViewObserver, observers_, DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173525
3526 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273527 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173528
3529 if (RenderThread::current()) { // Will be NULL during unit tests.
3530 RenderThread::current()->user_script_slave()->InjectScripts(
3531 frame, UserScript::DOCUMENT_END);
3532 }
[email protected]fa7b6b542009-11-03 05:02:303533
[email protected]41f16632010-10-20 01:21:323534 // InjectScripts() can end up creating a new NavigationState if it triggers a
3535 // fragment navigation, so we need to re-fetch it here.
3536 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303537 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3538}
3539
3540void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3541 if (RenderThread::current()) { // Will be NULL during unit tests.
3542 RenderThread::current()->user_script_slave()->InjectScripts(
3543 frame, UserScript::DOCUMENT_IDLE);
3544 }
3545
3546 WebFrame* main_frame = webview()->mainFrame();
3547 if (frame == main_frame) {
3548 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203549 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303550 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203551 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303552 pending_code_execution_queue_.pop();
3553 }
3554 }
[email protected]3d9689372009-09-10 04:29:173555}
3556
3557void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083558 if (webview()->mainFrame() == frame) {
3559 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3560 page_id_));
3561 }
[email protected]3d9689372009-09-10 04:29:173562}
3563
3564void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3565 // Ignore
3566}
3567
3568void RenderView::didFinishLoad(WebFrame* frame) {
3569 WebDataSource* ds = frame->dataSource();
3570 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3571 DCHECK(navigation_state);
3572 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303573 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413574
[email protected]676126f72011-01-15 00:03:513575 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173576
3577 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173578}
3579
[email protected]ccbe04e2010-03-17 17:58:433580void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173581 WebFrame* frame, bool is_new_navigation) {
3582 // If this was a reference fragment navigation that we initiated, then we
3583 // could end up having a non-null pending navigation state. We just need to
3584 // update the ExtraData on the datasource so that others who read the
3585 // ExtraData will get the new NavigationState. Similarly, if we did not
3586 // initiate this navigation, then we need to take care to reset any pre-
3587 // existing navigation state to a content-initiated navigation state.
3588 // DidCreateDataSource conveniently takes care of this for us.
3589 didCreateDataSource(frame, frame->dataSource());
3590
[email protected]af15bed2010-08-25 21:12:093591 NavigationState* new_state =
3592 NavigationState::FromDataSource(frame->dataSource());
3593 new_state->set_was_within_same_page(true);
3594
[email protected]3d9689372009-09-10 04:29:173595 didCommitProvisionalLoad(frame, is_new_navigation);
3596
[email protected]26aa0482009-09-30 16:55:273597 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173598}
3599
[email protected]476b6f82009-09-10 21:00:593600void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313601 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593602}
3603
[email protected]3d9689372009-09-10 04:29:173604void RenderView::assignIdentifierToRequest(
3605 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3606 // Ignore
3607}
3608
3609void RenderView::willSendRequest(
3610 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3611 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303612 WebFrame* top_frame = frame->top();
3613 if (!top_frame)
3614 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513615 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3616 WebDataSource* top_data_source = top_frame->dataSource();
3617 WebDataSource* data_source =
3618 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303619 if (data_source) {
3620 NavigationState* state = NavigationState::FromDataSource(data_source);
3621 if (state && state->is_cache_policy_override_set())
3622 request.setCachePolicy(state->cache_policy_override());
3623 }
[email protected]8a3125a712010-08-09 18:58:513624
3625 if (top_data_source) {
3626 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3627 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3628 state->set_was_prefetcher(true);
3629 }
3630
[email protected]3d9689372009-09-10 04:29:173631 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133632 request.setHasUserGesture(frame->isProcessingUserGesture());
3633
[email protected]c5bbc2452010-03-08 08:33:503634 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133635 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493636
[email protected]85cc78c2010-05-04 18:30:093637 // Temporary metrics, see site_isolation_metrics.h
3638 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173639}
3640
3641void RenderView::didReceiveResponse(
3642 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493643
[email protected]85cc78c2010-05-04 18:30:093644 // Temporary metrics, see site_isolation_metrics.h
3645 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3646 identifier,
3647 response);
[email protected]fa0a3432010-03-30 16:53:493648
[email protected]3d9689372009-09-10 04:29:173649 // Only do this for responses that correspond to a provisional data source
3650 // of the top-most frame. If we have a provisional data source, then we
3651 // can't have any sub-resources yet, so we know that this response must
3652 // correspond to a frame load.
3653 if (!frame->provisionalDataSource() || frame->parent())
3654 return;
3655
3656 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083657 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173658 if (frame->isViewSourceModeEnabled())
3659 return;
3660
[email protected]65041fa2010-05-21 06:56:533661 NavigationState* navigation_state =
3662 NavigationState::FromDataSource(frame->provisionalDataSource());
3663 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083664 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533665
[email protected]972ebdff2010-06-10 22:59:073666 // Record page load flags.
3667 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3668 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573669 navigation_state->set_was_alternate_protocol_available(
3670 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073671 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083672 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533673
[email protected]f48013be2010-01-14 22:07:453674 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083675 if (http_status_code == 404) {
3676 // Can we even load an alternate error page for this URL?
3677 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3678 return;
3679 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3680 http_status_code)) {
3681 // If no corresponding error strings for a particular status code, just
3682 // render any received data, regardless of whether or not the status code
3683 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453684 return;
[email protected]3f853a52010-09-13 19:15:083685 }
[email protected]3d9689372009-09-10 04:29:173686
[email protected]3d9689372009-09-10 04:29:173687 navigation_state->set_postpone_loading_data(true);
3688 navigation_state->clear_postponed_data();
3689}
3690
3691void RenderView::didFinishResourceLoad(
3692 WebFrame* frame, unsigned identifier) {
3693 NavigationState* navigation_state =
3694 NavigationState::FromDataSource(frame->dataSource());
3695 if (!navigation_state->postpone_loading_data())
3696 return;
3697
[email protected]3f853a52010-09-13 19:15:083698 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173699 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083700 int http_status_code = navigation_state->http_status_code();
3701 if (http_status_code == 404) {
3702 // On 404s, try a remote search page as a fallback.
3703 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173704
[email protected]3f853a52010-09-13 19:15:083705 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3706 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173707
[email protected]3f853a52010-09-13 19:15:083708 WebURLError original_error;
3709 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173710
[email protected]3f853a52010-09-13 19:15:083711 navigation_state->set_alt_error_page_fetcher(
3712 new AltErrorPageResourceFetcher(
3713 error_page_url, frame, original_error,
3714 NewCallback(this, &RenderView::AltErrorPageFinished)));
3715 } else {
3716 // On other errors, use an internal error page.
3717 WebURLError error;
3718 error.unreachableURL = frame->url();
3719 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3720 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173721
[email protected]3f853a52010-09-13 19:15:083722 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3723 std::string(), true);
3724 }
[email protected]3d9689372009-09-10 04:29:173725}
3726
3727void RenderView::didFailResourceLoad(
3728 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3729 // Ignore
3730}
3731
3732void RenderView::didLoadResourceFromMemoryCache(
3733 WebFrame* frame, const WebURLRequest& request,
3734 const WebURLResponse& response) {
3735 // Let the browser know we loaded a resource from the memory cache. This
3736 // message is needed to display the correct SSL indicators.
3737 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3738 routing_id_,
3739 request.url(),
[email protected]91733b62009-09-18 06:21:093740 frame->securityOrigin().toString().utf8(),
3741 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173742 response.securityInfo()));
3743}
3744
[email protected]6069da8c2009-10-20 20:33:493745void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293746 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3747}
3748
[email protected]92771112011-01-20 00:13:023749// We have two didRunInsecureContent's with the same name. That's because
3750// we're in the process of adding an argument and one of them will be correct.
3751// Once the WebKit change is in, the first should be removed.
[email protected]e3d60e5d2009-09-25 21:08:293752void RenderView::didRunInsecureContent(
3753 WebFrame* frame, const WebSecurityOrigin& origin) {
[email protected]92771112011-01-20 00:13:023754 didRunInsecureContent(frame, origin, GURL());
3755}
3756
3757void RenderView::didRunInsecureContent(
3758 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293759 Send(new ViewHostMsg_DidRunInsecureContent(
3760 routing_id_,
[email protected]92771112011-01-20 00:13:023761 origin.toString().utf8(),
3762 target));
[email protected]e3d60e5d2009-09-25 21:08:293763}
3764
[email protected]7ea093ba2009-11-03 05:54:593765bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403766 if (enabled_per_settings &&
3767 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3768 return true;
[email protected]7ea093ba2009-11-03 05:54:593769
[email protected]12bc8472010-04-15 07:29:403770 if (IsWhitelistedForContentSettings(frame))
3771 return true;
[email protected]7ea093ba2009-11-03 05:54:593772
3773 return false; // Other protocols fall through here.
3774}
3775
[email protected]0a1a45432010-03-31 08:09:453776bool RenderView::allowDatabase(
3777 WebFrame* frame, const WebString& name, const WebString& display_name,
3778 unsigned long estimated_size) {
3779 WebSecurityOrigin origin = frame->securityOrigin();
3780 if (origin.isEmpty())
3781 return false; // Uninitialized document?
3782
3783 bool result;
[email protected]26a9acf2010-12-13 19:35:053784 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453785 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3786 return false;
[email protected]9fb83e82010-07-02 18:24:553787 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3788 GURL(origin.toString().utf8()),
3789 name,
3790 display_name,
3791 estimated_size,
3792 !result));
[email protected]0a1a45432010-03-31 08:09:453793 return result;
3794}
[email protected]8934a3b2010-02-25 00:34:003795void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283796 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003797}
3798
[email protected]c21f1d52010-03-04 03:19:433799void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283800 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433801}
3802
[email protected]3d9689372009-09-10 04:29:173803void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3804 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3805}
3806
[email protected]0c882b282009-10-07 17:01:283807void RenderView::didCreateScriptContext(WebFrame* frame) {
3808 EventBindings::HandleContextCreated(frame, false);
3809}
3810
3811void RenderView::didDestroyScriptContext(WebFrame* frame) {
3812 EventBindings::HandleContextDestroyed(frame);
3813}
3814
3815void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3816 EventBindings::HandleContextCreated(frame, true);
3817}
3818
[email protected]af7eb3fb2010-09-23 21:31:063819bool RenderView::allowScriptExtension(WebFrame* frame,
3820 const WebString& extension_name,
3821 int extension_group) {
3822 // NULL in unit tests.
3823 if (!RenderThread::current())
3824 return true;
3825
3826 // Note: we prefer the provisional URL here instead of the document URL
3827 // because we might be currently loading an URL into a blank page.
3828 // See http://code.google.com/p/chromium/issues/detail?id=10924
3829 WebDataSource* ds = frame->provisionalDataSource();
3830 if (!ds)
3831 ds = frame->dataSource();
3832 return RenderThread::current()->AllowScriptExtension(
3833 extension_name.utf8(), ds->request().url(), extension_group);
3834}
3835
[email protected]fc86daa2010-03-30 23:52:533836void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3837 WebFrame* target,
3838 bool cross_origin,
3839 const WebString& property_name,
3840 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103841 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363842 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103843}
3844
[email protected]3d9689372009-09-10 04:29:173845void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143846 CheckPreferredSize();
3847}
3848
3849void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173850 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253851 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173852 // message.
[email protected]705243f2010-05-05 19:58:073853 if (!send_preferred_size_changes_ || !webview())
3854 return;
[email protected]dfca5acf2010-03-22 03:28:433855
[email protected]705243f2010-05-05 19:58:073856 // WebCore likes to tell us things have changed even when they haven't, so
3857 // cache the width and height and only send the IPC message when we're sure
3858 // they're different.
3859 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3860 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533861
3862 // In the presence of zoom, these sizes are still reported as if unzoomed,
3863 // so we need to adjust.
3864 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3865 size.set_width(static_cast<int>(size.width() * zoom_factor));
3866 size.set_height(static_cast<int>(size.height() * zoom_factor));
3867
[email protected]705243f2010-05-05 19:58:073868 if (size == preferred_size_)
3869 return;
[email protected]c27324b2009-11-19 22:44:293870
[email protected]705243f2010-05-05 19:58:073871 preferred_size_ = size;
3872 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3873 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173874}
3875
[email protected]143dcd592009-11-06 21:33:493876void RenderView::didChangeScrollOffset(WebFrame* frame) {
3877 StartNavStateSyncTimerIfNecessary();
3878}
3879
[email protected]8922e1f2009-10-03 05:01:263880void RenderView::reportFindInPageMatchCount(int request_id, int count,
3881 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113882 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3883 if (!count)
3884 active_match_ordinal = 0;
3885
3886 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3887 routing_id_,
3888 request_id,
3889 count,
3890 gfx::Rect(),
3891 active_match_ordinal,
3892 final_update);
3893
[email protected]8922e1f2009-10-03 05:01:263894 // If we have a message that has been queued up, then we should just replace
3895 // it. The ACK from the browser will make sure it gets sent when the browser
3896 // wants it.
3897 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263898 queued_find_reply_message_.reset(msg);
3899 } else {
3900 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113901 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263902 }
3903}
3904
3905void RenderView::reportFindInPageSelection(int request_id,
3906 int active_match_ordinal,
3907 const WebRect& selection_rect) {
3908 // Send the search result over to the browser process.
3909 Send(new ViewHostMsg_Find_Reply(routing_id_,
3910 request_id,
3911 -1,
3912 selection_rect,
3913 active_match_ordinal,
3914 false));
3915}
3916
[email protected]2b06a992010-08-21 05:48:223917void RenderView::openFileSystem(
3918 WebFrame* frame,
3919 WebFileSystem::Type type,
3920 long long size,
[email protected]d275d7a2010-11-03 01:34:493921 bool create,
[email protected]2b06a992010-08-21 05:48:223922 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083923 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223924
3925 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083926 if (origin.isEmpty()) {
3927 // Uninitialized document?
3928 callbacks->didFail(WebKit::WebFileErrorAbort);
3929 return;
3930 }
[email protected]2b06a992010-08-21 05:48:223931
[email protected]c5a272d2010-09-27 18:37:083932 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3933 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493934 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223935}
3936
[email protected]79dbc662009-09-04 05:42:513937// webkit_glue::WebPluginPageDelegate -----------------------------------------
3938
[email protected]191eb3f72010-12-21 06:27:503939webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533940 const FilePath& file_path,
3941 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593942 if (!PluginChannelHost::IsListening())
3943 return NULL;
3944
[email protected]d2139662009-12-10 03:21:143945 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283946 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143947 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163948 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533949 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143950 if (CommandLine::ForCurrentProcess()->
3951 HasSwitch(switches::kInternalPepper)) {
3952 in_process_plugin = true;
3953 use_pepper_host = true;
3954 } else {
3955 // In process Pepper plugins must be explicitly enabled.
3956 return NULL;
3957 }
[email protected]4e0616e2010-05-28 14:55:533958 } else {
3959 FilePath internal_pdf_path;
3960 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3961 if (file_path == internal_pdf_path) {
3962 in_process_plugin = true;
3963 use_pepper_host = true;
3964 }
[email protected]26e8d5e2009-10-13 02:47:163965 }
[email protected]4e0616e2010-05-28 14:55:533966
[email protected]d032f492009-09-29 00:33:463967 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143968 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283969 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533970 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333971 if (!pepper_plugin)
3972 return NULL;
3973
[email protected]53900d52010-06-16 04:25:013974 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283975 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143976 } else {
[email protected]6876dff2010-01-15 19:38:093977#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]191eb3f72010-12-21 06:27:503978 return webkit::npapi::WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533979 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093980#else
[email protected]596b2c42010-01-14 20:40:433981 NOTIMPLEMENTED();
3982 return NULL;
[email protected]7b6616f2010-01-14 18:07:553983#endif
[email protected]6876dff2010-01-15 19:38:093984 }
[email protected]f103ab72009-09-02 17:10:593985 }
3986
[email protected]4e0616e2010-05-28 14:55:533987 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593988}
3989
3990void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033991#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593992 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3993 routing_id(), window));
3994#endif
3995}
3996
3997void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033998#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593999 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
4000 routing_id(), window));
4001#endif
4002 CleanupWindowInPluginMoves(window);
4003}
4004
[email protected]191eb3f72010-12-21 06:27:504005void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594006 SchedulePluginMove(move);
4007}
4008
4009void RenderView::DidStartLoadingForPlugin() {
4010 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524011 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594012}
4013
4014void RenderView::DidStopLoadingForPlugin() {
4015 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524016 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594017}
4018
4019void RenderView::ShowModalHTMLDialogForPlugin(
4020 const GURL& url,
4021 const gfx::Size& size,
4022 const std::string& json_arguments,
4023 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:214024 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:594025 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:214026 json_retval));
[email protected]f103ab72009-09-02 17:10:594027}
4028
[email protected]b921cfd22010-02-25 16:57:514029WebCookieJar* RenderView::GetCookieJar() {
4030 return &cookie_jar_;
4031}
4032
initial.commit09911bf2008-07-26 23:55:294033void RenderView::SyncNavigationState() {
4034 if (!webview())
4035 return;
4036
[email protected]26aa0482009-09-30 16:55:274037 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:174038 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:294039 return;
[email protected]ca948a22009-06-25 19:36:174040
4041 Send(new ViewHostMsg_UpdateState(
4042 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:294043}
4044
[email protected]b0950a72009-09-29 23:16:174045bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
4046 // Make sure webview was not shut down.
4047 if (!webview())
4048 return false;
4049 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:234050 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
4051 new ImageResourceFetcher(
4052 image_url, webview()->mainFrame(), id, image_size,
4053 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:174054 return true;
4055}
4056
4057void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294058 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174059 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:474060 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
4061 fetcher->id(),
4062 fetcher->image_url(),
4063 image.isNull(),
4064 image));
[email protected]bb461532010-11-26 21:50:234065
4066 // Remove the image fetcher from our pending list. We're in the callback from
4067 // ImageResourceFetcher, best to delay deletion.
4068 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4069 iter != image_fetchers_.end(); ++iter) {
4070 if (iter->get() == fetcher) {
4071 iter->release();
4072 image_fetchers_.erase(iter);
4073 break;
4074 }
4075 }
[email protected]b0950a72009-09-29 23:16:174076 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294077}
4078
[email protected]bf5c2ff392009-07-08 16:24:334079void RenderView::OnDownloadFavIcon(int id,
4080 const GURL& image_url,
4081 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344082 bool data_image_failed = false;
4083 if (image_url.SchemeIs("data")) {
4084 SkBitmap data_image = ImageFromDataUrl(image_url);
4085 data_image_failed = data_image.empty();
4086 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:334087 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
4088 data_image));
[email protected]f11ca0732009-04-11 00:09:344089 }
4090 }
4091
[email protected]bf5c2ff392009-07-08 16:24:334092 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174093 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:334094 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
4095 SkBitmap()));
4096 }
initial.commit09911bf2008-07-26 23:55:294097}
4098
[email protected]f11ca0732009-04-11 00:09:344099SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4100 std::string mime_type, char_set, data;
4101 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4102 // Decode the favicon using WebKit's image decoder.
4103 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
4104 const unsigned char* src_data =
4105 reinterpret_cast<const unsigned char*>(&data[0]);
4106
4107 return decoder.Decode(src_data, data.size());
4108 }
4109 return SkBitmap();
4110}
4111
initial.commit09911bf2008-07-26 23:55:294112void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444113 WebApplicationInfo app_info;
4114 if (page_id == page_id_) {
4115 string16 error;
4116 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4117 &error);
4118 }
initial.commit09911bf2008-07-26 23:55:294119
4120 // Prune out any data URLs in the set of icons. The browser process expects
4121 // any icon with a data URL to have originated from a favicon. We don't want
4122 // to decode arbitrary data URLs in the browser process. See
4123 // http://b/issue?id=1162972
4124 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594125 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294126 app_info.icons.erase(app_info.icons.begin() + i);
4127 --i;
4128 }
4129 }
4130
4131 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4132}
4133
[email protected]7ccddb8c2009-08-04 17:36:554134GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294135 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554136 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294137 // If the URL that failed was secure, then the embedding web page was not
4138 // expecting a network attacker to be able to manipulate its contents. As
4139 // we fetch alternate error pages over HTTP, we would be allowing a network
4140 // attacker to manipulate the contents of the response if we tried to use
4141 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154142 return GURL();
initial.commit09911bf2008-07-26 23:55:294143 }
4144
4145 // Grab the base URL from the browser process.
4146 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154147 return GURL();
initial.commit09911bf2008-07-26 23:55:294148
4149 // Strip query params from the failed URL.
4150 GURL::Replacements remove_params;
4151 remove_params.ClearUsername();
4152 remove_params.ClearPassword();
4153 remove_params.ClearQuery();
4154 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554155 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504156 std::string spec_to_send = url_to_send.spec();
4157 // Notify link doctor of the url truncation by sending of "?" at the end.
4158 if (failed_url.has_query())
4159 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294160
4161 // Construct the query params to send to link doctor.
4162 std::string params(alternate_error_page_url_.query());
4163 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504164 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294165 params.append("&sourceid=chrome");
4166 params.append("&error=");
4167 switch (error_type) {
4168 case DNS_ERROR:
4169 params.append("dnserror");
4170 break;
4171
4172 case HTTP_404:
4173 params.append("http404");
4174 break;
4175
[email protected]5df266ac2008-10-15 19:50:134176 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334177 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134178 break;
4179
initial.commit09911bf2008-07-26 23:55:294180 default:
4181 NOTREACHED() << "unknown ErrorPageType";
4182 }
4183
4184 // OK, build the final url to return.
4185 GURL::Replacements link_doctor_params;
4186 link_doctor_params.SetQueryStr(params);
4187 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4188 return url;
4189}
4190
[email protected]c50008512011-02-03 01:17:274191WebUIBindings* RenderView::GetWebUIBindings() {
4192 if (!web_ui_bindings_.get()) {
4193 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:464194 }
[email protected]c50008512011-02-03 01:17:274195 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464196}
4197
4198ExternalHostBindings* RenderView::GetExternalHostBindings() {
4199 if (!external_host_bindings_.get()) {
4200 external_host_bindings_.reset(new ExternalHostBindings());
4201 }
4202 return external_host_bindings_.get();
4203}
4204
[email protected]0fdbf8c2010-07-08 20:33:014205WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4206 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494207}
4208
[email protected]6069da8c2009-10-20 20:33:494209void RenderView::OnFind(int request_id, const string16& search_text,
4210 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274211 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494212
4213 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494214 if (options.findNext) {
4215 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014216 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494217 } else {
[email protected]afdbd142010-07-10 08:01:234218 if (GetWebPluginFromPluginDocument()->startFind(
4219 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494220 } else {
[email protected]e7c58a32010-08-13 19:47:114221 // Send "no results".
4222 Send(new ViewHostMsg_Find_Reply(routing_id_,
4223 request_id,
4224 0,
4225 gfx::Rect(),
4226 0,
4227 true));
[email protected]24a7f3c2010-03-25 08:26:494228 }
4229 }
4230 return;
4231 }
4232
[email protected]b4bb2502009-10-01 22:35:274233 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274234 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294235 WebFrame* search_frame = focused_frame; // start searching focused frame.
4236
4237 bool multi_frame = (frame_after_main != main_frame);
4238
4239 // If we have multiple frames, we don't want to wrap the search within the
4240 // frame, so we check here if we only have main_frame in the chain.
4241 bool wrap_within_frame = !multi_frame;
4242
[email protected]b3f2b912009-04-09 16:18:524243 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294244 bool result = false;
4245
[email protected]7830da3e2009-11-06 16:27:264246 // If something is selected when we start searching it means we cannot just
4247 // increment the current match ordinal; we need to re-generate it.
4248 WebRange current_selection = focused_frame->selectionRange();
4249
initial.commit09911bf2008-07-26 23:55:294250 do {
[email protected]dd7daa82009-08-10 05:46:454251 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594252 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294253
4254 if (!result) {
4255 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224256 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294257
4258 // Find the next frame, but skip the invisible ones.
4259 do {
4260 // What is the next frame to search? (we might be going backwards). Note
4261 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594262 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274263 search_frame->traverseNext(true) :
4264 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454265 } while (!search_frame->hasVisibleContent() &&
4266 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294267
[email protected]884db412008-11-24 23:46:504268 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224269 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294270
4271 // If we have multiple frames and we have wrapped back around to the
4272 // focused frame, we need to search it once more allowing wrap within
4273 // the frame, otherwise it will report 'no match' if the focused frame has
4274 // reported matches, but no frames after the focused_frame contain a
4275 // match for the search word(s).
4276 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454277 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594278 request_id, search_text, options, true, // Force wrapping.
4279 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294280 }
4281 }
4282
[email protected]26aa0482009-09-30 16:55:274283 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294284 } while (!result && search_frame != focused_frame);
4285
[email protected]7830da3e2009-11-06 16:27:264286 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294287 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454288 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294289 } else {
4290 // If nothing is found, set result to "0 of 0", otherwise, set it to
4291 // "-1 of 1" to indicate that we found at least one item, but we don't know
4292 // yet what is active.
4293 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4294 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294295
[email protected]4f3dc372009-02-24 00:10:294296 // If we find no matches then this will be our last status update.
4297 // Otherwise the scoping effort will send more results.
4298 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294299
[email protected]4f3dc372009-02-24 00:10:294300 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404301 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594302 request_id,
[email protected]4f3dc372009-02-24 00:10:294303 match_count,
4304 selection_rect,
4305 ordinal,
4306 final_status_update));
initial.commit09911bf2008-07-26 23:55:294307
initial.commit09911bf2008-07-26 23:55:294308 // Scoping effort begins, starting with the mainframe.
4309 search_frame = main_frame;
4310
[email protected]dd7daa82009-08-10 05:46:454311 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294312
4313 do {
4314 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454315 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294316
4317 // We don't start another scoping effort unless at least one match has
4318 // been found.
4319 if (result) {
4320 // Start new scoping request. If the scoping function determines that it
4321 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454322 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594323 search_text,
4324 options,
initial.commit09911bf2008-07-26 23:55:294325 true); // reset the tickmarks
4326 }
4327
4328 // Iterate to the next frame. The frame will not necessarily scope, for
4329 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274330 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294331 } while (search_frame != main_frame);
4332 }
4333}
4334
[email protected]24a7f3c2010-03-25 08:26:494335void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4336 WebView* view = webview();
4337 if (!view)
4338 return;
4339
4340 WebDocument doc = view->mainFrame()->document();
4341 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014342 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494343 return;
4344 }
4345
4346 bool clear_selection =
4347 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4348 if (clear_selection)
4349 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4350
4351 WebFrame* frame = view->mainFrame();
4352 while (frame) {
4353 frame->stopFinding(clear_selection);
4354 frame = frame->traverseNext(false);
4355 }
4356
4357 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4358 WebFrame* focused_frame = view->focusedFrame();
4359 if (focused_frame) {
4360 WebDocument doc = focused_frame->document();
4361 if (!doc.isNull()) {
4362 WebNode node = doc.focusedNode();
4363 if (!node.isNull())
4364 node.simulateClick();
4365 }
4366 }
4367 }
4368}
4369
4370void RenderView::OnFindReplyAck() {
4371 // Check if there is any queued up request waiting to be sent.
4372 if (queued_find_reply_message_.get()) {
4373 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424374 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494375 }
4376}
4377
[email protected]8934a3b2010-02-25 00:34:004378bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354379 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004380 return current_content_settings_.settings[settings_type] !=
4381 CONTENT_SETTING_BLOCK;
4382}
4383
[email protected]55126132010-08-19 14:53:284384void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4385 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004386 if (!content_blocked_[settings_type]) {
4387 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284388 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4389 resource_identifier));
[email protected]0de80162010-02-03 04:52:354390 }
[email protected]0de80162010-02-03 04:52:354391}
4392
[email protected]71b0d5d2010-02-15 05:43:074393void RenderView::ClearBlockedContentSettings() {
4394 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4395 content_blocked_[i] = false;
4396}
4397
[email protected]0bd753682010-12-16 18:15:524398WebPlugin* RenderView::CreatePepperPlugin(
4399 WebFrame* frame,
4400 const WebPluginParams& params,
4401 const FilePath& path,
4402 webkit::ppapi::PluginModule* pepper_module) {
4403 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254404 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094405}
[email protected]00152e92010-07-19 11:47:404406
[email protected]191eb3f72010-12-21 06:27:504407WebPlugin* RenderView::CreateNPAPIPlugin(
4408 WebFrame* frame,
4409 const WebPluginParams& params,
4410 const FilePath& path,
4411 const std::string& mime_type) {
4412 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084413 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404414}
4415
[email protected]3c2826852010-12-16 19:09:144416WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514417 WebFrame* frame,
4418 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504419 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144420 int resource_id,
[email protected]90dba072011-01-20 20:10:204421 int message_id,
4422 bool is_blocked_for_prerendering) {
[email protected]3c2826852010-12-16 19:09:144423 // |blocked_plugin| will delete itself when the WebViewPlugin
4424 // is destroyed.
4425 BlockedPlugin* blocked_plugin =
4426 new BlockedPlugin(this,
4427 frame,
4428 group,
4429 params,
4430 webkit_preferences_,
4431 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374432 l10n_util::GetStringFUTF16(message_id,
[email protected]90dba072011-01-20 20:10:204433 group.GetGroupName()),
4434 is_blocked_for_prerendering);
[email protected]3c2826852010-12-16 19:09:144435 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514436}
4437
[email protected]40bd6582009-12-04 23:49:514438void RenderView::OnZoom(PageZoom::Function function) {
4439 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4440 return;
4441
[email protected]258d31122010-05-09 10:59:414442 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524443
[email protected]b75b8292010-10-01 07:28:254444 double old_zoom_level = webview()->zoomLevel();
4445 double zoom_level;
4446 if (function == PageZoom::RESET) {
4447 zoom_level = 0;
4448 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4449 // Previous zoom level is a whole number, so just increment/decrement.
4450 zoom_level = old_zoom_level + function;
4451 } else {
4452 // Either the user hit the zoom factor limit and thus the zoom level is now
4453 // not a whole number, or a plugin changed it to a custom value. We want
4454 // to go to the next whole number so that the user can always get back to
4455 // 100% with the keyboard/menu.
4456 if ((old_zoom_level > 1 && function > 0) ||
4457 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454458 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254459 } else {
4460 // We're going towards 100%, so first go to the next whole number.
4461 zoom_level = static_cast<int>(old_zoom_level);
4462 }
4463 }
[email protected]40bd6582009-12-04 23:49:514464
[email protected]b75b8292010-10-01 07:28:254465 webview()->setZoomLevel(false, zoom_level);
4466 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514467}
4468
[email protected]d0b8d092010-10-25 04:05:174469void RenderView::OnSetZoomLevel(double zoom_level) {
4470 // Don't set zoom level for full-page plugin since they don't use the same
4471 // zoom settings.
4472 if (webview()->mainFrame()->document().isPluginDocument())
4473 return;
4474
4475 webview()->hidePopups();
4476 webview()->setZoomLevel(false, zoom_level);
4477 zoomLevelChanged();
4478}
4479
[email protected]9d797f32010-04-23 07:17:544480void RenderView::OnSetContentSettingsForLoadingURL(
4481 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014482 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544483 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014484}
4485
[email protected]9d797f32010-04-23 07:17:544486void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254487 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544488 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294489}
4490
[email protected]41fc0322009-09-04 22:23:404491void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274492 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294493}
4494
[email protected]a697f4c2009-09-14 22:30:184495void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274496 WebString no_encoding;
4497 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184498}
4499
[email protected]20ad2692009-11-20 18:27:204500bool RenderView::GetAllChildFrames(
4501 WebFrame* parent_frame,
4502 std::vector<WebFrame*>* frames_vector) const {
4503 if (!parent_frame)
4504 return false;
4505 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4506 child_frame = child_frame->nextSibling()) {
4507 frames_vector->push_back(child_frame);
4508 GetAllChildFrames(child_frame, frames_vector);
4509 }
4510 return true;
4511}
4512
[email protected]dd7daa82009-08-10 05:46:454513WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4514 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274515 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454516
4517 // xpath string can represent a frame deep down the tree (across multiple
4518 // frame DOMs).
4519 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4520 // should break into 2 xpaths
4521 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4522
[email protected]26aa0482009-09-30 16:55:274523 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454524
4525 std::wstring xpath_remaining = xpath;
4526 while (!xpath_remaining.empty()) {
4527 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4528 std::wstring xpath_child;
4529 if (delim_pos != std::wstring::npos) {
4530 xpath_child = xpath_remaining.substr(0, delim_pos);
4531 xpath_remaining.erase(0, delim_pos + 1);
4532 } else {
4533 xpath_remaining.swap(xpath_child);
4534 }
4535 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294536 }
4537
[email protected]dd7daa82009-08-10 05:46:454538 return frame;
initial.commit09911bf2008-07-26 23:55:294539}
4540
[email protected]13a1e4c3c2011-02-03 21:07:094541WebNode RenderView::GetFocusedNode() const {
4542 if (!webview())
4543 return WebNode();
4544 WebFrame* focused_frame = webview()->focusedFrame();
4545 if (focused_frame) {
4546 WebDocument doc = focused_frame->document();
4547 if (!doc.isNull())
4548 return doc.focusedNode();
4549 }
4550
4551 return WebNode();
4552}
4553
[email protected]ce833282010-11-04 15:48:394554void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) {
4555 // Explicitly allow empty vector to be sent to the browser.
4556 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions));
[email protected]15d9c0c2010-09-10 22:36:264557}
4558
[email protected]882b7b22010-10-05 03:34:534559void RenderView::EvaluateScript(const string16& frame_xpath,
4560 const string16& script,
4561 int id,
4562 bool notify_result) {
4563 v8::Handle<v8::Value> result;
4564 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4565 if (web_frame)
4566 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4567 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294568 ListValue list;
4569 if (web_frame) {
4570 v8::HandleScope handle_scope;
4571 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4572 v8::Context::Scope context_scope(context);
4573 list.Set(0, ConvertV8Value(result));
4574 } else {
4575 list.Set(0, Value::CreateNullValue());
4576 }
4577 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534578 }
initial.commit09911bf2008-07-26 23:55:294579}
4580
[email protected]1810e132009-03-24 23:35:484581void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084582 const std::string& css,
4583 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484584 WebFrame* web_frame = GetChildFrame(frame_xpath);
4585 if (!web_frame)
4586 return;
4587
[email protected]ffaef0c2009-09-15 17:08:084588 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484589}
4590
[email protected]00c39612010-03-06 02:53:284591void RenderView::OnPepperPluginDestroy(
4592 WebPluginDelegatePepper* pepper_plugin) {
4593 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014594 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4595 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284596 NOTREACHED();
4597 return;
4598 }
[email protected]53900d52010-06-16 04:25:014599 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474600
4601 // The plugin could have been destroyed while it was waiting for a file
4602 // choose callback, so check all pending completion callbacks and NULL them.
4603 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4604 file_chooser_completions_.begin();
4605 i != file_chooser_completions_.end(); /* nothing */) {
4606 if ((*i)->completion == pepper_plugin) {
4607 // We NULL the first one instead of deleting it because the plugin might
4608 // be the one waiting for a file choose callback. If the callback later
4609 // comes, we don't want to send the result to the next callback in line.
4610 if (i == file_chooser_completions_.begin())
4611 (*i)->completion = NULL;
4612 else
4613 i = file_chooser_completions_.erase(i);
4614 } else {
4615 ++i;
4616 }
4617 }
[email protected]00c39612010-03-06 02:53:284618}
4619
[email protected]882b7b22010-10-05 03:34:534620void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4621 const string16& jscript,
4622 int id,
4623 bool notify_result) {
4624 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294625}
4626
[email protected]1810e132009-03-24 23:35:484627void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084628 const std::string& css,
4629 const std::string& id) {
4630 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414631
4632 // Notify RenderViewHost that css has been inserted into the frame.
4633 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484634}
4635
[email protected]7ea066a2009-04-06 20:21:594636void RenderView::OnAddMessageToConsole(
4637 const string16& frame_xpath,
4638 const string16& message,
4639 const WebConsoleMessage::Level& level) {
4640 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594641 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454642 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294643}
4644
[email protected]81e63782009-02-27 19:35:094645void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4646 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294647}
4648
4649void RenderView::OnSetDOMUIProperty(const std::string& name,
4650 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094651 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:274652 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294653}
4654
4655void RenderView::OnReservePageIDRange(int size_of_range) {
4656 next_page_id_ += size_of_range + 1;
4657}
4658
[email protected]e80c73b2009-04-07 23:24:584659void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4660 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254661 bool ended,
4662 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034663 if (ended) {
[email protected]26aa0482009-09-30 16:55:274664 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204665 } else {
4666 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034667 }
initial.commit09911bf2008-07-26 23:55:294668}
4669
4670void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274671 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294672}
4673
initial.commit09911bf2008-07-26 23:55:294674void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584675 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254676 const gfx::Point& screen_point,
4677 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274678 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584679 drop_data.ToDragData(),
4680 drop_data.identity,
4681 client_point,
[email protected]1d9f4132009-09-08 17:29:254682 screen_point,
4683 ops);
initial.commit09911bf2008-07-26 23:55:294684
[email protected]1d9f4132009-09-08 17:29:254685 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294686}
4687
[email protected]e80c73b2009-04-07 23:24:584688void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254689 const gfx::Point& screen_point,
4690 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274691 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254692 client_point,
4693 screen_point,
4694 ops);
initial.commit09911bf2008-07-26 23:55:294695
[email protected]1d9f4132009-09-08 17:29:254696 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294697}
4698
4699void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274700 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294701}
4702
[email protected]e80c73b2009-04-07 23:24:584703void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4704 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274705 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294706}
4707
4708void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594709 webkit_preferences_ = prefs;
4710 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294711}
4712
4713void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4714 alternate_error_page_url_ = url;
4715}
4716
[email protected]b29aa74b2011-01-31 21:41:084717void RenderView::OnCustomContextMenuAction(
4718 const webkit_glue::CustomContextMenuContext& custom_context,
4719 unsigned action) {
4720 if (custom_context.is_pepper_menu)
4721 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4722 else
4723 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334724}
4725
initial.commit09911bf2008-07-26 23:55:294726void RenderView::OnInstallMissingPlugin() {
4727 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594728 if (first_default_plugin_)
4729 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294730}
4731
[email protected]90dba072011-01-20 20:10:204732void RenderView::OnDisplayPrerenderedPage() {
4733 NavigationState* navigation_state = pending_navigation_state_.get();
4734 if (!navigation_state) {
4735 WebDataSource* ds = webview()->mainFrame()->dataSource();
4736 navigation_state = NavigationState::FromDataSource(ds);
4737 }
4738
4739 DCHECK(navigation_state->is_prerendering());
4740 navigation_state->set_is_prerendering(false);
4741}
4742
[email protected]cdaf8d02010-03-30 19:52:474743void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364744 // This could happen if we navigated to a different page before the user
4745 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474746 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364747 return;
4748
[email protected]cdaf8d02010-03-30 19:52:474749 WebVector<WebString> ws_file_names(paths.size());
4750 for (size_t i = 0; i < paths.size(); ++i)
4751 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464752
[email protected]cdaf8d02010-03-30 19:52:474753 if (file_chooser_completions_.front()->completion)
4754 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4755 file_chooser_completions_.pop_front();
4756
4757 // If there are more pending file chooser requests, schedule one now.
4758 if (!file_chooser_completions_.empty()) {
4759 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4760 file_chooser_completions_.front()->params));
4761 }
initial.commit09911bf2008-07-26 23:55:294762}
4763
4764void RenderView::OnEnableViewSourceMode() {
4765 if (!webview())
4766 return;
[email protected]26aa0482009-09-30 16:55:274767 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294768 if (!main_frame)
4769 return;
4770
[email protected]dd7daa82009-08-10 05:46:454771 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294772}
4773
[email protected]770dd8b2010-05-24 18:11:394774void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4775 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244776 if (send_preferred_size_changes_)
4777 return;
[email protected]9fb325e2010-05-06 18:23:244778 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394779
4780 // WebKit doesn't send a notification of the effective height of the page
4781 // changes, so poll for it.
4782 // TODO: Add a notification for this to WebKit, remove polling. After that's
4783 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4784 // http://crbug.com/44850
4785 if (flags & kPreferredSizeHeightThisIsSlow) {
4786 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4787 &RenderView::CheckPreferredSize);
4788 }
[email protected]0666aef2009-05-13 19:48:084789}
4790
[email protected]ce833282010-11-04 15:48:394791void RenderView::OnSearchBoxChange(const string16& value,
[email protected]368ef4c2010-11-08 21:58:464792 bool verbatim,
[email protected]ce833282010-11-04 15:48:394793 int selection_start,
4794 int selection_end) {
4795 search_box_.value = value;
[email protected]368ef4c2010-11-08 21:58:464796 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394797 search_box_.selection_start = selection_start;
4798 search_box_.selection_end = selection_end;
4799 if (!webview() || !webview()->mainFrame())
4800 return;
4801 extensions_v8::SearchBoxExtension::DispatchChange(webview()->mainFrame());
4802}
4803
4804void RenderView::OnSearchBoxSubmit(const string16& value, bool verbatim) {
4805 search_box_.value = value;
4806 search_box_.verbatim = verbatim;
4807 if (!webview() || !webview()->mainFrame())
4808 return;
4809 extensions_v8::SearchBoxExtension::DispatchSubmit(webview()->mainFrame());
4810}
4811
4812void RenderView::OnSearchBoxCancel() {
4813 search_box_.verbatim = false;
4814 if (!webview() || !webview()->mainFrame())
4815 return;
4816 extensions_v8::SearchBoxExtension::DispatchCancel(webview()->mainFrame());
4817}
4818
4819void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) {
4820 search_box_.x = bounds.x();
4821 search_box_.y = bounds.y();
4822 search_box_.width = bounds.width();
4823 search_box_.height = bounds.height();
4824 if (!webview() || !webview()->mainFrame())
4825 return;
4826 extensions_v8::SearchBoxExtension::DispatchResize(webview()->mainFrame());
4827}
4828
[email protected]57ad7b8c2010-11-18 19:13:494829void RenderView::OnDetermineIfPageSupportsInstant(const string16& value,
[email protected]0d5ab152011-01-14 23:09:044830 bool verbatim,
4831 int selection_start,
4832 int selection_end) {
[email protected]ce833282010-11-04 15:48:394833 search_box_.value = value;
[email protected]57ad7b8c2010-11-18 19:13:494834 search_box_.verbatim = verbatim;
[email protected]0d5ab152011-01-14 23:09:044835 search_box_.selection_start = selection_start;
4836 search_box_.selection_end = selection_end;
[email protected]ce833282010-11-04 15:48:394837 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
4838 webview()->mainFrame());
4839 Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result));
4840}
4841
[email protected]cda45c02010-02-25 19:28:104842void RenderView::OnDisableScrollbarsForSmallWindows(
4843 const gfx::Size& disable_scrollbar_size_limit) {
4844 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4845}
4846
[email protected]80d96fa2009-06-10 22:34:514847void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4848 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374849 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134850#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414851 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4852 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464853 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344854 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4855 renderer_prefs.thumb_inactive_color,
4856 renderer_prefs.thumb_active_color,
4857 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324858
[email protected]644d77e2010-01-27 01:03:104859 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324860 webview()->setScrollbarColors(
4861 renderer_prefs.thumb_inactive_color,
4862 renderer_prefs.thumb_active_color,
4863 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104864 webview()->setSelectionColors(
4865 renderer_prefs.active_selection_bg_color,
4866 renderer_prefs.active_selection_fg_color,
4867 renderer_prefs.inactive_selection_bg_color,
4868 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464869 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104870 }
[email protected]7a74e102009-09-03 00:16:564871#endif
[email protected]80d96fa2009-06-10 22:34:514872}
4873
[email protected]952cb702009-10-07 05:50:284874void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4875 const WebMediaPlayerAction& action) {
4876 if (webview())
4877 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564878}
4879
[email protected]7b291f92009-08-14 05:43:534880void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4881 view_type_ = type;
4882}
4883
4884void RenderView::OnUpdateBrowserWindowId(int window_id) {
4885 browser_window_id_ = window_id;
4886}
4887
[email protected]dea2d372010-09-25 06:41:144888void RenderView::OnEnableAccessibility() {
4889 if (WebAccessibilityCache::accessibilityEnabled())
4890 return;
[email protected]9f4db512010-05-10 20:21:414891
[email protected]dea2d372010-09-25 06:41:144892 WebAccessibilityCache::enableAccessibility();
4893
4894 if (webview()) {
4895 // It's possible that the webview has already loaded a webpage without
4896 // accessibility being enabled. Initialize the browser's cached
4897 // accessibility tree by sending it a 'load complete' notification.
4898 postAccessibilityNotification(
4899 webview()->accessibilityObject(),
4900 WebKit::WebAccessibilityNotificationLoadComplete);
4901 }
[email protected]266eb6f2008-09-30 23:56:504902}
4903
[email protected]aef92842010-05-21 16:54:364904void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4905 if (!accessibility_.get())
4906 return;
[email protected]02ea2f312010-09-27 17:03:364907
4908 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4909 WebAccessibilityObject root = webview()->accessibilityObject();
4910 if (!obj.isValid() || !root.isValid())
4911 return;
4912
4913 // By convention, calling SetFocus on the root of the tree should clear the
4914 // current focus. Otherwise set the focus to the new node.
4915 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4916 webview()->clearFocusedNode();
4917 else
4918 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364919}
4920
4921void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4922 if (!accessibility_.get())
4923 return;
[email protected]02ea2f312010-09-27 17:03:364924
4925 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4926 if (!obj.isValid())
4927 return;
4928
4929 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364930}
4931
[email protected]9892b472010-09-16 00:23:424932void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514933 DCHECK(accessibility_ack_pending_);
4934 accessibility_ack_pending_ = false;
4935 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314936}
4937
initial.commit09911bf2008-07-26 23:55:294938void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4939 const GURL& page_url) {
4940 // Prepare list to storage all savable resource links.
4941 std::vector<GURL> resources_list;
4942 std::vector<GURL> referrers_list;
4943 std::vector<GURL> frames_list;
4944 webkit_glue::SavableResourcesResult result(&resources_list,
4945 &referrers_list,
4946 &frames_list);
4947
[email protected]dbeb3952009-10-13 18:01:184948 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4949 webview(),
4950 page_url,
4951 &result,
4952 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294953 // If something is wrong when collecting all savable resource links,
4954 // send empty list to embedder(browser) to tell it failed.
4955 referrers_list.clear();
4956 resources_list.clear();
4957 frames_list.clear();
4958 }
4959
4960 // Send result of all savable resource links to embedder.
4961 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4962 resources_list,
4963 referrers_list,
4964 frames_list));
4965}
4966
4967void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324968 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314969 const std::vector<FilePath>& local_paths,
4970 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074971
4972 // Convert std::vector of GURLs to WebVector<WebURL>
4973 WebVector<WebURL> weburl_links(links);
4974
4975 // Convert std::vector of std::strings to WebVector<WebString>
4976 WebVector<WebString> webstring_paths(local_paths.size());
4977 for (size_t i = 0; i < local_paths.size(); i++)
4978 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4979
4980 WebPageSerializer::serialize(webview()->mainFrame(),
4981 true, this, weburl_links, webstring_paths,
4982 webkit_glue::FilePathToWebString(
4983 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294984}
4985
[email protected]d9ec5c0f2009-12-23 11:55:074986void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4987 const WebCString& data,
4988 WebPageSerializerClient::PageSerializationStatus status) {
4989 Send(new ViewHostMsg_SendSerializedHtmlData(
4990 routing_id_,
4991 frame_url,
4992 data.data(),
4993 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294994}
4995
[email protected]9b18a84f2010-06-10 15:54:044996void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274997 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474998 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294999}
5000
[email protected]eb6b87a2009-07-24 15:57:395001void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:295002 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5003 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5004 // in the onunload handler from appearing. For now, we're bypassing that and
5005 // calling the FrameLoader's CloseURL method directly. This should be
5006 // revisited to avoid having two ways to close a page. Having a single way
5007 // to close that can run onunload is also useful for fixing
5008 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:365009 // TODO(davemoore) This code should be removed once willClose() gets
5010 // called when a page is destroyed. page_load_histograms_.Dump() is safe
5011 // to call multiple times for the same frame, but it will simplify things.
5012 page_load_histograms_.Dump(webview()->mainFrame());
5013 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:275014 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295015
[email protected]eb6b87a2009-07-24 15:57:395016 // Just echo back the params in the ACK.
5017 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:295018}
5019
5020void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:575021#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:295022 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465023 if (webview())
5024 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575025#else // defined(OS_WIN)
5026 // TODO(port): we don't support theming on non-Windows platforms yet
5027 NOTIMPLEMENTED();
5028#endif
initial.commit09911bf2008-07-26 23:55:295029}
5030
[email protected]9b18a84f2010-06-10 15:54:045031void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
5032 const std::string& origin,
5033 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:155034 if (message.empty())
5035 return;
[email protected]c091c2c2010-09-17 19:05:465036 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
5037 target);
[email protected]3ac14a052008-08-15 21:22:155038}
5039
[email protected]0aa55312008-10-17 21:53:085040void RenderView::OnDisassociateFromPopupCount() {
5041 if (decrement_shared_popup_at_destruction_)
5042 shared_popup_counter_->data--;
5043 shared_popup_counter_ = new SharedRenderViewCounter(0);
5044 decrement_shared_popup_at_destruction_ = false;
5045}
5046
[email protected]15d79e12009-08-02 19:23:455047bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
5048 const WebURLError& error,
5049 bool replace) {
5050 // We only show alternate error pages in the main frame. They are
5051 // intended to assist the user when navigating, so there is not much
5052 // value in showing them for failed subframes. Ideally, we would be
5053 // able to use the TYPED transition type for this, but that flag is
5054 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455055 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455056 return false;
5057
5058 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375059 // connection failure.
[email protected]15d79e12009-08-02 19:23:455060 int ec = error.reason;
5061 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5062 ec != net::ERR_CONNECTION_FAILED &&
5063 ec != net::ERR_CONNECTION_REFUSED &&
5064 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:375065 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:455066 return false;
5067
5068 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555069 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455070 if (!error_page_url.is_valid())
5071 return false;
5072
5073 // Load an empty page first so there is an immediate response to the error,
5074 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455075 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:365076 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455077 error.unreachableURL,
5078 replace);
5079
5080 // Now, create a fetcher for the error page and associate it with the data
5081 // source we just created via the LoadHTMLString call. That way if another
5082 // navigation occurs, the fetcher will get destroyed.
5083 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455084 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:455085 navigation_state->set_alt_error_page_fetcher(
5086 new AltErrorPageResourceFetcher(
5087 error_page_url, frame, error,
5088 NewCallback(this, &RenderView::AltErrorPageFinished)));
5089 return true;
5090}
5091
initial.commit09911bf2008-07-26 23:55:295092std::string RenderView::GetAltHTMLForTemplate(
5093 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:395094 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:295095 ResourceBundle::GetSharedInstance().GetRawDataResource(
5096 template_resource_id));
5097
5098 if (template_html.empty()) {
5099 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
5100 return "";
5101 }
[email protected]7cd22a52009-07-14 00:40:255102
initial.commit09911bf2008-07-26 23:55:295103 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:255104 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:295105 template_html, &error_strings, "t");
5106}
[email protected]0e79b9e2009-02-13 04:20:485107
[email protected]15d79e12009-08-02 19:23:455108void RenderView::AltErrorPageFinished(WebFrame* frame,
5109 const WebURLError& original_error,
5110 const std::string& html) {
5111 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:555112
5113 // If we failed to download the alternate error page, fall back to the
5114 // original error page if present. Otherwise, LoadNavigationErrorPage
5115 // will simply display a default error page.
5116 const std::string* html_to_load = &html;
5117 if (html.empty()) {
5118 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455119 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:555120 html_to_load = &navigation_state->postponed_data();
5121 }
[email protected]3f853a52010-09-13 19:15:085122 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5123 true);
[email protected]15d79e12009-08-02 19:23:455124}
5125
[email protected]30f75e62009-02-25 22:01:005126void RenderView::OnMoveOrResizeStarted() {
5127 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475128 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005129}
5130
[email protected]30f75e62009-02-25 22:01:005131void RenderView::OnResize(const gfx::Size& new_size,
5132 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:105133 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475134 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105135 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205136 webview()->mainFrame()->setCanHaveScrollbars(
5137 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105138 }
5139 }
5140
[email protected]30f75e62009-02-25 22:01:005141 RenderWidget::OnResize(new_size, resizer_rect);
5142}
[email protected]0aa477bd2009-03-23 22:21:435143
[email protected]00c39612010-03-06 02:53:285144void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015145 // Notify the pepper plugins that we started painting.
5146 pepper_delegate_.ViewInitiatedPaint();
5147
5148 // Notify any "old-style" pepper plugins that we started painting. This is
5149 // used for internal bookkeeping only, so we know that the set can not change
5150 // under us.
[email protected]00c39612010-03-06 02:53:285151 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:015152 current_oldstyle_pepper_plugins_.begin();
5153 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:285154 (*i)->RenderViewInitiatedPaint();
5155}
5156
5157void RenderView::DidFlushPaint() {
5158 // Notify any pepper plugins that we painted. This will call into the plugin,
5159 // and we it may ask to close itself as a result. This will, in turn, modify
5160 // our set, possibly invalidating the iterator. So we iterate on a copy that
5161 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015162 pepper_delegate_.ViewFlushedPaint();
5163
5164 // Notify any old-style pepper plugins that we painted. This will call into
5165 // the plugin, and we it may ask to close itself as a result. This will, in
5166 // turn, modify our set, possibly invalidating the iterator. So we iterate on
5167 // a copy that won't change out from under us.
5168 // This should be deleted when we don't support old Pepper anymore.
5169 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:285170 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
5171 i != plugins.end(); ++i) {
5172 // The copy above makes sure our iterator is never invalid if some plugins
5173 // are destroyed. But some plugin may decide to close all of its views in
5174 // response to a paint in one of them, so we need to make sure each one is
5175 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:015176 if (current_oldstyle_pepper_plugins_.find(*i) !=
5177 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:285178 (*i)->RenderViewFlushedPaint();
5179 }
5180
5181 WebFrame* main_frame = webview()->mainFrame();
5182
5183 // If we have a provisional frame we are between the start and commit stages
5184 // of loading and we don't want to save stats.
5185 if (!main_frame->provisionalDataSource()) {
5186 WebDataSource* ds = main_frame->dataSource();
5187 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5188 DCHECK(navigation_state);
5189
[email protected]05c8e502010-08-15 15:13:525190 // TODO(jar): The following code should all be inside a method, probably in
5191 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285192 Time now = Time::Now();
5193 if (navigation_state->first_paint_time().is_null()) {
5194 navigation_state->set_first_paint_time(now);
5195 }
5196 if (navigation_state->first_paint_after_load_time().is_null() &&
5197 !navigation_state->finish_load_time().is_null()) {
5198 navigation_state->set_first_paint_after_load_time(now);
5199 }
5200 }
5201}
5202
[email protected]719b36f2010-12-22 20:36:465203webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155204 const gfx::Rect& paint_bounds,
5205 TransportDIB** dib,
5206 gfx::Rect* location,
5207 gfx::Rect* clip) {
5208 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5209 paint_bounds, dib, location, clip);
5210}
5211
[email protected]d54169e92011-01-21 09:19:525212gfx::Size RenderView::GetScrollOffset() {
5213 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
5214 return gfx::Size(scroll_offset.width, scroll_offset.height);
5215}
5216
[email protected]05d478752009-04-08 23:38:165217void RenderView::OnClearFocusedNode() {
5218 if (webview())
[email protected]26aa0482009-09-30 16:55:275219 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165220}
5221
[email protected]699ab0d2009-04-23 23:19:145222void RenderView::OnSetBackground(const SkBitmap& background) {
5223 if (webview())
[email protected]b4bb2502009-10-01 22:35:275224 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145225
5226 SetBackground(background);
5227}
5228
[email protected]8c66c5a2009-07-22 17:26:345229void RenderView::OnSetActive(bool active) {
5230 if (webview())
[email protected]b4bb2502009-10-01 22:35:275231 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265232
5233#if defined(OS_MACOSX)
5234 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5235 for (plugin_it = plugin_delegates_.begin();
5236 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5237 (*plugin_it)->SetWindowFocus(active);
5238 }
5239#endif
[email protected]8c66c5a2009-07-22 17:26:345240}
5241
[email protected]6ce7abc52010-02-02 18:40:145242#if defined(OS_MACOSX)
5243void RenderView::OnSetWindowVisibility(bool visible) {
5244 // Inform plugins that their container has changed visibility.
5245 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5246 for (plugin_it = plugin_delegates_.begin();
5247 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5248 (*plugin_it)->SetContainerVisibility(visible);
5249 }
5250}
[email protected]1e6e3c992010-02-08 15:52:135251
[email protected]4d51d5bf2010-07-26 18:48:265252void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5253 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135254 // Inform plugins that their window's frame has changed.
5255 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5256 for (plugin_it = plugin_delegates_.begin();
5257 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5258 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5259 }
5260}
[email protected]935d63d2010-10-15 23:31:555261
[email protected]b7f75862011-01-21 21:15:135262void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:555263 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135264 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555265 // applies to it or not, so inform all the delegates.
5266 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5267 for (plugin_it = plugin_delegates_.begin();
5268 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135269 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555270 }
5271}
[email protected]6ce7abc52010-02-02 18:40:145272#endif // OS_MACOSX
5273
[email protected]8b8e7c92010-08-19 18:05:565274void RenderView::SendExtensionRequest(
5275 const ViewHostMsg_DomMessage_Params& params) {
5276 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275277}
5278
[email protected]c6619182009-05-12 14:59:325279void RenderView::OnExtensionResponse(int request_id,
5280 bool success,
5281 const std::string& response,
5282 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355283 ExtensionProcessBindings::HandleResponse(
5284 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275285}
[email protected]c20210e62009-04-03 21:39:265286
[email protected]a7ab1b782010-10-21 23:24:165287void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5288 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495289 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195290 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495291 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165292 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375293}
5294
[email protected]9892b472010-09-16 00:23:425295void RenderView::postAccessibilityNotification(
5296 const WebAccessibilityObject& obj,
5297 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145298 if (!accessibility_.get() && webview()) {
5299 // Load complete should be our first notification sent.
5300 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5301 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5302 return;
5303
5304 // Create and initialize our accessibility cache
5305 accessibility_.reset(WebAccessibilityCache::create());
5306 accessibility_->initialize(webview());
5307 }
5308
[email protected]a3fa4f92010-09-30 22:19:335309 if (!accessibility_->isCached(obj)) {
5310 // The browser doesn't know about objects that are not in the cache. Send a
5311 // children change for the first accestor that actually is in the cache.
5312 WebAccessibilityObject parent = obj;
5313 while (parent.isValid() && !accessibility_->isCached(parent))
5314 parent = parent.parentObject();
5315
5316 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5317 if (!parent.isValid())
5318 return;
5319 postAccessibilityNotification(
5320 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5321
5322 // The parent's children change takes care of the child's children change.
5323 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5324 return;
5325 }
5326
[email protected]dea2d372010-09-25 06:41:145327 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515328 RendererAccessibilityNotification acc_notification;
5329 acc_notification.id = accessibility_->addOrGetId(obj);
5330 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485331 return;
5332
[email protected]54ec7f82010-10-21 22:32:515333 if (!WebAccessibilityNotificationToViewHostMsg(
5334 notification,
5335 &acc_notification.type)) {
5336 return;
5337 }
5338
5339 // Discard duplicate accessibility notifications.
5340 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5341 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5342 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425343 return;
[email protected]54ec7f82010-10-21 22:32:515344 }
[email protected]9892b472010-09-16 00:23:425345 }
[email protected]54ec7f82010-10-21 22:32:515346 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485347
[email protected]54ec7f82010-10-21 22:32:515348 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5349 // When no accessibility notifications are in-flight post a task to send
5350 // the notifications to the browser. We use PostTask so that we can queue
5351 // up additional notifications.
5352 MessageLoop::current()->PostTask(
5353 FROM_HERE,
5354 accessibility_method_factory_.NewRunnableMethod(
5355 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315356 }
[email protected]520cb7d72010-08-31 11:54:315357}
5358
[email protected]c7a827e2011-01-21 00:27:015359void RenderView::OnPrint(bool is_preview) {
5360 DCHECK(webview());
5361 if (webview()) {
5362 // If the user has selected text in the currently focused frame we print
5363 // only that frame (this makes print selection work for multiple frames).
5364 if (webview()->focusedFrame()->hasSelection())
5365 Print(webview()->focusedFrame(), false, is_preview);
5366 else
5367 Print(webview()->mainFrame(), false, is_preview);
5368 }
5369}
5370
[email protected]212a49d2010-10-25 18:23:475371void RenderView::Print(WebFrame* frame,
5372 bool script_initiated,
5373 bool is_preview) {
[email protected]0fda7272009-06-26 15:49:335374 DCHECK(frame);
[email protected]521b2482011-01-15 00:10:105375 GetPrintWebViewHelper()->PrintFrame(frame, script_initiated, is_preview);
5376}
5377
5378PrintWebViewHelper* RenderView::GetPrintWebViewHelper() {
5379 if (print_helper_.get() == NULL)
[email protected]0fda7272009-06-26 15:49:335380 print_helper_.reset(new PrintWebViewHelper(this));
[email protected]521b2482011-01-15 00:10:105381 return print_helper_.get();
[email protected]0fda7272009-06-26 15:49:335382}
[email protected]446705872009-09-10 07:22:485383
5384void RenderView::OnSetEditCommandsForNextKeyEvent(
5385 const EditCommands& edit_commands) {
5386 edit_commands_ = edit_commands;
5387}
5388
[email protected]61f5a7b2009-12-22 22:21:205389void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275390 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355391 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205392 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5393 false));
[email protected]912256b32009-09-18 09:47:355394 return;
5395 }
5396
[email protected]fa7b6b542009-11-03 05:02:305397 WebDataSource* ds = main_frame->dataSource();
5398 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5399 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205400 pending_code_execution_queue_.push(
5401 linked_ptr<ViewMsg_ExecuteCode_Params>(
5402 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305403 return;
5404 }
5405
[email protected]61f5a7b2009-12-22 22:21:205406 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305407}
5408
5409void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205410 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205411 std::vector<WebFrame*> frame_vector;
5412 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205413 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205414 GetAllChildFrames(frame, &frame_vector);
5415
5416 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5417 frame_it != frame_vector.end(); ++frame_it) {
5418 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205419 if (params.is_javascript) {
[email protected]2a521c52011-01-26 18:45:215420 const Extension* extension =
5421 render_thread_->GetExtensions()->GetByID(params.extension_id);
[email protected]be7e5cb2010-10-04 12:53:175422
[email protected]1f6228c2010-10-21 03:19:445423 // Since extension info is sent separately from user script info, they can
5424 // be out of sync. We just ignore this situation.
5425 if (!extension)
5426 continue;
5427
[email protected]2a521c52011-01-26 18:45:215428 if (!extension->CanExecuteScriptOnPage(frame->url(), NULL, NULL))
[email protected]61f5a7b2009-12-22 22:21:205429 continue;
5430
[email protected]20ad2692009-11-20 18:27:205431 std::vector<WebScriptSource> sources;
5432 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205433 WebScriptSource(WebString::fromUTF8(params.code)));
5434 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205435 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205436 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205437 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5438 } else {
[email protected]61f5a7b2009-12-22 22:21:205439 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205440 }
[email protected]912256b32009-09-18 09:47:355441 }
5442
[email protected]61f5a7b2009-12-22 22:21:205443 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355444}
5445
[email protected]60c42a8c72009-10-09 04:08:595446void RenderView::Close() {
5447 // We need to grab a pointer to the doomed WebView before we destroy it.
5448 WebView* doomed = webview();
5449 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495450 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595451}
5452
[email protected]446705872009-09-10 07:22:485453void RenderView::DidHandleKeyEvent() {
5454 edit_commands_.clear();
5455}
5456
[email protected]6a8ddba52010-09-05 04:38:065457void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515458 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065459}
5460
[email protected]941e4552010-02-01 21:23:435461#if defined(OS_MACOSX)
5462void RenderView::OnWasHidden() {
5463 RenderWidget::OnWasHidden();
5464
5465 // Inform plugins that their container is no longer visible.
5466 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5467 for (plugin_it = plugin_delegates_.begin();
5468 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5469 (*plugin_it)->SetContainerVisibility(false);
5470 }
5471}
5472
5473void RenderView::OnWasRestored(bool needs_repainting) {
5474 RenderWidget::OnWasRestored(needs_repainting);
5475
5476 // Inform plugins that their container is now visible.
5477 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5478 for (plugin_it = plugin_delegates_.begin();
5479 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5480 (*plugin_it)->SetContainerVisibility(true);
5481 }
5482}
[email protected]784ea1ab2010-09-18 00:02:345483#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135484
5485void RenderView::OnSetFocus(bool enable) {
5486 RenderWidget::OnSetFocus(enable);
5487
[email protected]7d3c02c2010-05-05 23:10:315488 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075489 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135490 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5491 for (plugin_it = plugin_delegates_.begin();
5492 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345493#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315494 // RenderWidget's call to setFocus can cause the underlying webview's
5495 // activation state to change just like a call to setIsActive.
5496 if (enable)
5497 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345498#endif
[email protected]7d3c02c2010-05-05 23:10:315499 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135500 }
[email protected]589621b2010-09-23 22:01:075501
5502 // Notify all Pepper plugins.
5503 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135504 }
5505}
[email protected]941e4552010-02-01 21:23:435506
[email protected]83dde542009-09-11 20:59:555507void RenderView::EnsureDocumentTag() {
5508 // TODO(darin): There's actually no reason for this to be here. We should
5509 // have the browser side manage the document tag.
5510#if defined(OS_MACOSX)
5511 if (!has_document_tag_) {
5512 // Make the call to get the tag.
5513 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5514 has_document_tag_ = true;
5515 }
5516#endif
5517}
[email protected]12636df2009-09-28 22:32:215518
[email protected]43f28f832010-02-03 02:28:485519#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:135520void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
5521 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
5522 focused, plugin_id);
5523 Send(msg);
5524}
5525
5526void RenderView::StartPluginIme() {
5527 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555528 // This message can be sent during event-handling, and needs to be delivered
5529 // within that context.
5530 msg->set_unblock(true);
5531 Send(msg);
5532}
5533
[email protected]ea04a4e12010-04-15 00:58:035534gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235535 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485536 gfx::PluginWindowHandle window = NULL;
5537 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235538 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115539 if (window) {
5540 fake_plugin_window_handles_.insert(window);
5541 }
[email protected]43f28f832010-02-03 02:28:485542 return window;
5543}
5544
5545void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115546 if (window && fake_plugin_window_handles_.find(window) !=
5547 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485548 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115549 fake_plugin_window_handles_.erase(window);
5550 }
[email protected]43f28f832010-02-03 02:28:485551}
5552
[email protected]44ce0b12010-03-12 16:45:335553void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5554 int32 width,
5555 int32 height,
5556 uint64 io_surface_identifier) {
5557 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485558 routing_id(), window, width, height, io_surface_identifier));
5559}
5560
[email protected]44ce0b12010-03-12 16:45:335561void RenderView::AcceleratedSurfaceSetTransportDIB(
5562 gfx::PluginWindowHandle window,
5563 int32 width,
5564 int32 height,
5565 TransportDIB::Handle transport_dib) {
5566 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075567 routing_id(), window, width, height, transport_dib));
5568}
5569
[email protected]44ce0b12010-03-12 16:45:335570TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5571 size_t size) {
[email protected]1aef98132010-02-23 18:00:075572 TransportDIB::Handle dib_handle;
5573 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385574 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075575 return dib_handle;
5576 // Return an invalid handle if Send() fails.
5577 return TransportDIB::DefaultHandleValue();
5578}
5579
[email protected]44ce0b12010-03-12 16:45:335580void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075581 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5582}
5583
[email protected]44ce0b12010-03-12 16:45:335584void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145585 gfx::PluginWindowHandle window, uint64 surface_id) {
5586 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5587 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485588}
5589#endif
[email protected]58c321d2010-02-19 12:11:285590
[email protected]cdaf8d02010-03-30 19:52:475591bool RenderView::ScheduleFileChooser(
5592 const ViewHostMsg_RunFileChooser_Params& params,
5593 WebFileChooserCompletion* completion) {
5594 static const size_t kMaximumPendingFileChooseRequests = 4;
5595 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5596 // This sanity check prevents too many file choose requests from getting
5597 // queued which could DoS the user. Getting these is most likely a
5598 // programming error (there are many ways to DoS the user so it's not
5599 // considered a "real" security check), either in JS requesting many file
5600 // choosers to pop up, or in a plugin.
5601 //
5602 // TODO(brettw) we might possibly want to require a user gesture to open
5603 // a file picker, which will address this issue in a better way.
5604 return false;
5605 }
5606
5607 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5608 new PendingFileChooser(params, completion)));
5609 if (file_chooser_completions_.size() == 1) {
5610 // Actually show the browse dialog when this is the first request.
5611 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5612 }
5613 return true;
5614}
5615
[email protected]290838a2010-04-27 17:37:015616void RenderView::OnPageTranslated() {
5617 WebFrame* frame = webview()->mainFrame();
5618 if (!frame)
5619 return;
5620
[email protected]676126f72011-01-15 00:03:515621 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015622}
5623
[email protected]0ff0ff32010-12-21 19:34:425624WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515625 if (!geolocation_dispatcher_)
5626 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5627 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255628}
[email protected]61c9f032010-03-31 23:04:195629
[email protected]638694c2010-08-04 22:24:115630WebKit::WebSpeechInputController* RenderView::speechInputController(
5631 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515632 if (!speech_input_dispatcher_)
5633 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5634 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115635}
5636
[email protected]57ead352010-08-11 14:42:535637WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515638 if (!device_orientation_dispatcher_)
5639 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5640 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535641}
5642
[email protected]b75b8292010-10-01 07:28:255643void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5644 // For now, don't remember plugin zoom values. We don't want to mix them with
5645 // normal web content (i.e. a fixed layout plugin would usually want them
5646 // different).
5647 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5648
[email protected]b75b8292010-10-01 07:28:255649 int minimum_percent = static_cast<int>(
5650 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5651 int maximum_percent = static_cast<int>(
5652 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255653
5654 Send(new ViewHostMsg_UpdateZoomLimits(
5655 routing_id_, minimum_percent, maximum_percent, remember));
5656}
5657
5658void RenderView::zoomLevelChanged() {
5659 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5660
[email protected]b75b8292010-10-01 07:28:255661 // Tell the browser which url got zoomed so it can update the menu and the
5662 // saved values if necessary
5663 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415664 routing_id_, webview()->zoomLevel(), remember,
5665 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255666}
5667
[email protected]8079b362010-05-07 18:37:455668bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195669 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455670 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195671 if (frame->parent() != NULL)
5672 return false;
5673
[email protected]f0a3d0b2010-08-06 22:51:535674 // Navigations initiated within Webkit are not sent out to the external host
5675 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275676 // 1. The url scheme is not http/https
5677 // 2. There is no opener and this is not the first url being opened by this
5678 // RenderView.
5679 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535680 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535681 // 4. Reloads/form submits/back forward navigations
5682 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5683 return false;
5684
[email protected]2fc22d12010-12-02 23:08:165685 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325686 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015687 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165688 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015689 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325690 // The opener relationship between the new window and the parent allows the
5691 // new window to script the parent and vice versa. This is not allowed if
5692 // the origins of the two domains are different. This can be treated as a
5693 // top level navigation and routed back to the host.
5694 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275695 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475696 // Force link click navigations to always be routed to the host as they
5697 // may update session state on the server.
5698 if (type == WebKit::WebNavigationTypeLinkClicked)
5699 return true;
[email protected]900eb2f12010-08-23 22:36:275700 // If this is the first page being loaded by this RenderView instance then
5701 // it should stay here.
5702 if (page_id_ == -1) {
5703 return false;
5704 } else {
[email protected]d0ed50d2010-06-22 01:01:325705 return true;
[email protected]900eb2f12010-08-23 22:36:275706 }
[email protected]d0ed50d2010-06-22 01:01:325707 }
[email protected]900eb2f12010-08-23 22:36:275708
5709 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5710 return true;
[email protected]d0ed50d2010-06-22 01:01:325711 }
[email protected]61c9f032010-03-31 23:04:195712 return false;
5713}
[email protected]2b06a992010-08-21 05:48:225714
[email protected]27a9ef32010-09-10 04:06:245715void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5716 IPC::PlatformFileForTransit file_for_transit,
5717 int message_id) {
5718 pepper_delegate_.OnAsyncFileOpened(
5719 error_code,
5720 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5721 message_id);
5722}
[email protected]caf706f2010-10-26 17:54:085723
5724#if defined(OS_MACOSX)
5725void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155726 if (external_popup_menu_ == NULL) {
5727 // Crash reports from the field indicate that we can be notified with a
5728 // NULL external popup menu (we probably get notified twice).
5729 // If you hit this please file a bug against jcivelli and include the page
5730 // and steps to repro.
5731 NOTREACHED();
5732 return;
5733 }
[email protected]caf706f2010-10-26 17:54:085734 external_popup_menu_->DidSelectItem(selected_index);
5735 external_popup_menu_.reset();
5736}
5737#endif
[email protected]bb461532010-11-26 21:50:235738
5739void RenderView::AddErrorToRootConsole(const string16& message) {
5740 if (webview() && webview()->mainFrame()) {
5741 webview()->mainFrame()->addMessageToConsole(
5742 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5743 }
5744}
[email protected]1b4209f2011-01-07 00:25:405745
5746#if defined(ENABLE_FLAPPER_HACKS)
5747void RenderView::OnConnectTcpACK(
5748 int request_id,
5749 IPC::PlatformFileForTransit socket_for_transit,
5750 const PP_Flash_NetAddress& local_addr,
5751 const PP_Flash_NetAddress& remote_addr) {
5752 pepper_delegate_.OnConnectTcpACK(
5753 request_id,
5754 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5755 local_addr,
5756 remote_addr);
5757}
5758#endif
[email protected]a6097f42011-01-10 08:50:515759
5760void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5761 if (cmd == kJavaScriptStressTestSetStressRunType) {
5762 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5763 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5764 v8::Testing::PrepareStressRun(param);
5765 }
5766}
[email protected]521b2482011-01-15 00:10:105767
[email protected]b29aa74b2011-01-31 21:41:085768void RenderView::OnContextMenuClosed(
5769 const webkit_glue::CustomContextMenuContext& custom_context) {
5770 if (custom_context.is_pepper_menu)
5771 pepper_delegate_.OnContextMenuClosed(custom_context);
5772 else
5773 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105774}