blob: a2ca602437441156887b70d88aa8b26803cf4374 [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]57b66d02010-09-30 11:24:5112#include "app/l10n_util.h"
[email protected]6fdd4182010-10-14 23:59:2613#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1114#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5915#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5017#include "base/compiler_specific.h"
[email protected]625332e02010-12-14 07:48:4918#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2820#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2824#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2625#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2226#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5727#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2128#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0929#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5530#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1731#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2832#include "chrome/common/chrome_paths.h"
33#include "chrome/common/chrome_switches.h"
[email protected]26a9acf2010-12-13 19:35:0534#include "chrome/common/database_messages.h"
[email protected]a0cf04a2010-06-23 03:29:5535#include "chrome/common/extensions/extension.h"
[email protected]c5a272d2010-09-27 18:37:0836#include "chrome/common/file_system/file_system_dispatcher.h"
37#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]bb461532010-11-26 21:50:2338#include "chrome/common/json_value_serializer.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2140#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1741#include "chrome/common/page_zoom.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]9b6f40e2009-06-11 15:54:2644#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5946#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4447#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1148#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2550#include "chrome/renderer/audio_message_filter.h"
[email protected]6a8ddba52010-09-05 04:38:0651#include "chrome/renderer/autofill_helper.h"
[email protected]2f979172010-09-16 21:54:0352#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4053#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5354#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1155#include "chrome/renderer/devtools_agent.h"
56#include "chrome/renderer/devtools_client.h"
[email protected]2f979172010-09-16 21:54:0357#include "chrome/renderer/dom_ui_bindings.h"
[email protected]912256b32009-09-18 09:47:3558#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0459#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3260#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3561#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]6fdd4182010-10-14 23:59:2662#include "chrome/renderer/extensions/extension_renderer_info.h"
[email protected]7120f132009-07-20 21:05:3763#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0364#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0865#include "chrome/renderer/external_popup_menu.h"
[email protected]ffd0abd2010-12-14 17:45:5066#include "chrome/renderer/geolocation_dispatcher.h"
[email protected]3bb08602010-10-07 21:47:1767#include "chrome/renderer/ggl/ggl.h"
[email protected]90109412010-12-15 17:14:2468#include "chrome/renderer/load_progress_tracker.h"
initial.commit09911bf2008-07-26 23:55:2969#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5670#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4171#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]ed3fb032009-06-16 19:50:5672#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1273#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0674#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3675#include "chrome/renderer/page_load_histograms.h"
[email protected]6a8ddba52010-09-05 04:38:0676#include "chrome/renderer/password_autocomplete_manager.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]25e18f82010-10-27 16:38:4391#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3592#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2993#include "chrome/renderer/visitedlink_slave.h"
[email protected]5aa6a312010-11-06 00:00:0794#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
[email protected]d439ba072009-10-17 22:32:2995#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2996#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4297#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5698#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1599#include "gfx/color_utils.h"
100#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:57101#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:26102#include "gfx/point.h"
103#include "gfx/rect.h"
[email protected]82afe4b2010-11-12 20:36:22104#include "gfx/skbitmap_operations.h"
[email protected]34ac8f32009-02-22 23:03:27105#include "grit/generated_resources.h"
106#include "grit/renderer_resources.h"
[email protected]f8db8132010-12-03 00:27:49107#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41108#include "media/base/media_switches.h"
[email protected]f11ca0732009-04-11 00:09:34109#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29110#include "net/base/escape.h"
111#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04112#include "net/http/http_util.h"
[email protected]1b4209f2011-01-07 00:25:40113#include "ppapi/c/private/ppb_flash.h"
[email protected]c399a8a2008-11-22 19:38:00114#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10115#include "skia/ext/image_operations.h"
[email protected]418ed5ab2009-11-12 01:14:49116#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:26117#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:07118#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:49119#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
120#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:32121#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49122#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]9b66f34bf2010-10-27 20:45:51123#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
[email protected]01178b52010-01-15 06:59:35124#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]2b06a992010-08-21 05:48:22125#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
126#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
[email protected]6fdd4182010-10-14 23:59:26127#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]b1438212010-04-03 00:30:59128#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49129#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
130#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
[email protected]3bb08602010-10-07 21:47:17131#include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
[email protected]418ed5ab2009-11-12 01:14:49132#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41133#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50134#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49135#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32136#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07137#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49138#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40139#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]24a7f3c2010-03-25 08:26:49140#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]6fdd4182010-10-14 23:59:26141#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]418ed5ab2009-11-12 01:14:49142#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
143#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
144#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
145#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
146#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
147#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40148#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49149#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34150#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49151#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
152#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
153#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
154#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
155#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
156#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26157#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11158#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26159#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
160#include "third_party/skia/include/core/SkBitmap.h"
[email protected]882b7b22010-10-05 03:34:53161#include "v8/include/v8.h"
[email protected]a6097f42011-01-10 08:50:51162#include "v8/include/v8-testing.h"
[email protected]80f584d92010-01-21 03:59:04163#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43164#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24165#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29166#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59167#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24168#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24169#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34170#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26171#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09172#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26173#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23174#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09175#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24176#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29177#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29178#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17179#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50180#include "webkit/plugins/npapi/default_plugin_shared.h"
181#include "webkit/plugins/npapi/plugin_list.h"
182#include "webkit/plugins/npapi/webplugin_delegate.h"
183#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
184#include "webkit/plugins/npapi/webplugin_impl.h"
185#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52186#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29187
[email protected]6c8afae52009-01-22 02:24:57188#if defined(OS_WIN)
189// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57190// * theming
[email protected]cd818412010-03-19 03:23:15191#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03192#elif defined(USE_X11)
[email protected]8d1b864d12010-10-10 00:04:34193#include "gfx/native_theme_linux.h"
[email protected]39cd64ed2010-02-05 02:18:46194#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33195#elif defined(OS_MACOSX)
196#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57197#endif
198
[email protected]c7287a92009-11-04 20:06:15199using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42200using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08201using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21202using WebKit::WebApplicationCacheHost;
203using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26204using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41205using WebKit::WebColor;
206using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59207using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44208using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51209using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55210using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28211using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29212using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00213using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58214using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25215using WebKit::WebDragOperation;
216using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51217using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51218using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08219using WebKit::WebExternalPopupMenu;
220using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47221using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22222using WebKit::WebFileSystem;
223using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49224using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59225using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48226using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45227using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17228using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41229using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50230using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17231using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28232using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17233using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28234using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28235using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51236using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07237using WebKit::WebPageSerializer;
238using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17239using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40240using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49241using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09242using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52243using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59244using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51245using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52246using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40247using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35248using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29249using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59250using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42251using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02252using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34253using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28254using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51255using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52256using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28257using WebKit::WebURL;
258using WebKit::WebURLError;
259using WebKit::WebURLRequest;
260using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28261using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03262using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28263using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26264using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43265using WebKit::WebWorker;
266using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26267using appcache::WebApplicationCacheHostImpl;
268using base::Time;
269using base::TimeDelta;
270using webkit_glue::AltErrorPageResourceFetcher;
271using webkit_glue::FormData;
272using webkit_glue::FormField;
273using webkit_glue::ImageResourceFetcher;
274using webkit_glue::PasswordForm;
275using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23276using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26277using webkit_glue::SiteIsolationMetrics;
278using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33279
initial.commit09911bf2008-07-26 23:55:29280//-----------------------------------------------------------------------------
281
[email protected]3354d3e2010-06-10 19:53:02282typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49283static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02284
initial.commit09911bf2008-07-26 23:55:29285// define to write the time necessary for thumbnail/DOM text retrieval,
286// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29287// #define TIME_TEXT_RETRIEVAL
288
289// maximum number of characters in the document to index, any text beyond this
290// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57291static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29292
293// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37294static const int kThumbnailWidth = 212;
295static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29296
297// Delay in milliseconds that we'll wait before capturing the page contents
298// and thumbnail.
299static const int kDelayForCaptureMs = 500;
300
301// Typically, we capture the page data once the page is loaded.
302// Sometimes, the page never finishes to load, preventing the page capture
303// To workaround this problem, we always perform a capture after the following
304// delay.
305static const int kDelayForForcedCaptureMs = 6000;
306
[email protected]882daa92009-11-05 16:31:31307// Time, in seconds, we delay before sending content state changes (such as form
308// state and scroll position) to the browser. We delay sending changes to avoid
309// spamming the browser.
310// To avoid having tab/session restore require sending a message to get the
311// current content state during tab closing we use a shorter timeout for the
312// foreground renderer. This means there is a small window of time from which
313// content state is modified and not sent to session restore, but this is
314// better than having to wake up all renderers during shutdown.
315static const int kDelaySecondsForContentStateSyncHidden = 5;
316static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29317
[email protected]0aa55312008-10-17 21:53:08318// The maximum number of popups that can be spawned from one page.
319static const int kMaximumNumberOfUnacknowledgedPopups = 25;
320
[email protected]6fdd4182010-10-14 23:59:26321static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35322
[email protected]726985e22009-06-18 21:09:28323static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
324 WebVector<WebURL> urls;
325 ds->redirectChain(urls);
326 result->reserve(urls.size());
327 for (size_t i = 0; i < urls.size(); ++i)
328 result->push_back(urls[i]);
329}
330
[email protected]30507922010-01-15 16:48:23331static bool PaintViewIntoCanvas(WebView* view,
332 skia::PlatformCanvas& canvas) {
333 view->layout();
334 const WebSize& size = view->size();
335
336 if (!canvas.initialize(size.width, size.height, true))
337 return false;
338
339 view->paint(webkit_glue::ToWebCanvas(&canvas),
340 WebRect(0, 0, size.width, size.height));
341 // TODO: Add a way to snapshot the whole page, not just the currently
342 // visible part.
343
344 return true;
345}
346
347// Calculates how "boring" a thumbnail is. The boring score is the
348// 0,1 ranged percentage of pixels that are the most common
349// luma. Higher boring scores indicate that a higher percentage of a
350// bitmap are all the same brightness.
351static double CalculateBoringScore(SkBitmap* bitmap) {
352 int histogram[256] = {0};
353 color_utils::BuildLumaHistogram(bitmap, histogram);
354
355 int color_count = *std::max_element(histogram, histogram + 256);
356 int pixel_count = bitmap->width() * bitmap->height();
357 return static_cast<double>(color_count) / pixel_count;
358}
359
[email protected]12bc8472010-04-15 07:29:40360// True if |frame| contains content that is white-listed for content settings.
361static bool IsWhitelistedForContentSettings(WebFrame* frame) {
362 WebSecurityOrigin origin = frame->securityOrigin();
363 if (origin.isEmpty())
364 return false; // Uninitialized document?
365
366 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
367 return true; // Browser UI elements should still work.
368
369 // If the scheme is ftp: or file:, an empty file name indicates a directory
370 // listing, which requires JavaScript to function properly.
371 GURL frame_url = frame->url();
372 const char* kDirProtocols[] = { "ftp", "file" };
373 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
374 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
375 return frame_url.SchemeIs(kDirProtocols[i]) &&
376 frame_url.ExtractFileName().empty();
377 }
378 }
379
380 return false;
381}
382
[email protected]3a8eecb2010-04-22 23:56:30383// Returns true if the frame is navigating to an URL either into or out of an
384// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04385// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
386// we would enter an extension app's extent from a non-app. We avoid swapping
387// processes to exit an app for now, since we do not yet restore context (such
388// as window.opener) if the window navigates back.
389static bool CrossesIntoExtensionExtent(WebFrame* frame, const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30390 // If the URL is still empty, this is a window.open navigation. Check the
391 // opener's URL.
392 GURL old_url(frame->url());
393 if (old_url.is_empty() && frame->opener())
394 old_url = frame->opener()->url();
395
[email protected]08e94b82010-12-15 22:51:04396 return !ExtensionRendererInfo::InSameExtent(old_url, new_url) &&
397 !ExtensionRendererInfo::GetByURL(old_url);
[email protected]3a8eecb2010-04-22 23:56:30398}
399
[email protected]3354d3e2010-06-10 19:53:02400// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
401// if it failed.
[email protected]e5106202010-06-11 21:12:36402static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17403 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02404 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08405 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02406 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02407 Language cld_language =
[email protected]e5106202010-06-11 21:12:36408 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08409 &num_languages, NULL, &text_bytes);
410 // We don't trust the result if the CLD reports that the detection is not
411 // reliable, or if the actual text used to detect the language was less than
412 // 100 bytes (short texts can often lead to wrong results).
413 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02414 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
415 // We should not use LanguageCode_ISO_639_1 because it does not cover all
416 // the languages CLD can detect. As a result, it'll return the invalid
417 // language code for tradtional Chinese among others.
418 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
419 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
420 // for Simplified Chinese.
421 language = LanguageCodeWithDialects(cld_language);
422 }
423 return language;
424}
425
[email protected]9b66f34bf2010-10-27 20:45:51426// Returns true if the parameter node is a textfield, text area or a content
427// editable div.
428static bool IsEditableNode(const WebNode& node) {
429 bool is_editable_node = false;
430 if (!node.isNull()) {
431 if (node.isContentEditable()) {
432 is_editable_node = true;
433 } else if (node.isElementNode()) {
434 is_editable_node =
435 node.toConst<WebElement>().isTextFormControlElement();
436 }
437 }
438 return is_editable_node;
439}
440
[email protected]54ec7f82010-10-21 22:32:51441static bool WebAccessibilityNotificationToViewHostMsg(
442 WebAccessibilityNotification notification,
443 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
444 switch (notification) {
445 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
446 *type = ViewHostMsg_AccessibilityNotification_Params::
447 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
448 break;
449 case WebKit::WebAccessibilityNotificationChildrenChanged:
450 *type = ViewHostMsg_AccessibilityNotification_Params::
451 NOTIFICATION_TYPE_CHILDREN_CHANGED;
452 break;
453 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
454 *type = ViewHostMsg_AccessibilityNotification_Params::
455 NOTIFICATION_TYPE_FOCUS_CHANGED;
456 break;
457 case WebKit::WebAccessibilityNotificationLoadComplete:
458 *type = ViewHostMsg_AccessibilityNotification_Params::
459 NOTIFICATION_TYPE_LOAD_COMPLETE;
460 break;
461 case WebKit::WebAccessibilityNotificationValueChanged:
462 *type = ViewHostMsg_AccessibilityNotification_Params::
463 NOTIFICATION_TYPE_VALUE_CHANGED;
464 break;
465 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
466 *type = ViewHostMsg_AccessibilityNotification_Params::
467 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
468 break;
469 default:
470 // TODO(ctguil): Support additional webkit notifications.
471 return false;
472 }
473 return true;
474}
475
[email protected]81f9fe0b2010-12-07 00:35:29476// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
477// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
478// being TYPE_REALs. Dates are converted to a string (which can then be parsed
479// into a base::Time), as are regexps. Arrays are converted into lists,
480// recursively. We don't deal with binary objects or functions - they become
481// null values.
482static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
483 if (v8value->IsBoolean()) {
484 return Value::CreateBooleanValue(v8value->BooleanValue());
485 } else if (v8value->IsInt32()) {
486 return Value::CreateIntegerValue(v8value->Int32Value());
487 } else if (v8value->IsNumber()) {
488 return Value::CreateRealValue(v8value->NumberValue());
489 } else if (v8value->IsString()) {
490 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
491 } else if (v8value->IsDate()) {
492 v8::Date* date = v8::Date::Cast(*v8value);
493 return Value::CreateRealValue(date->NumberValue() / 1000.0);
494 } else if (v8value->IsRegExp()) {
495 return Value::CreateStringValue(
496 *v8::String::Utf8Value(v8value->ToString()));
497 } else if (v8value->IsArray()) {
498 v8::Array* array = v8::Array::Cast(*v8value);
499 uint32_t length = array->Length();
500 scoped_ptr<ListValue> list(new ListValue);
501 for (uint32_t i = 0 ; i < length ; ++i) {
502 list->Set(i, ConvertV8Value(array->Get(i)));
503 }
504 return list.release();
505 }
506 return Value::CreateNullValue();
507}
508
initial.commit09911bf2008-07-26 23:55:29509///////////////////////////////////////////////////////////////////////////////
510
[email protected]60c42a8c72009-10-09 04:08:59511int32 RenderView::next_page_id_ = 1;
512
[email protected]cdaf8d02010-03-30 19:52:47513struct RenderView::PendingFileChooser {
514 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
515 WebFileChooserCompletion* c)
516 : params(p),
517 completion(c) {
518 }
519 ViewHostMsg_RunFileChooser_Params params;
520 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
521};
522
[email protected]2fab253a2009-08-17 23:00:59523RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51524 gfx::NativeViewId parent_hwnd,
525 int32 opener_id,
526 const RendererPreferences& renderer_prefs,
527 const WebPreferences& webkit_prefs,
528 SharedRenderViewCounter* counter,
529 int32 routing_id,
530 int64 session_storage_namespace_id,
531 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12532 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51533 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02534 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09535 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02536 send_preferred_size_changes_(false),
537 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24538 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21539 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02540 opened_by_user_gesture_(true),
541 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24542 page_id_(-1),
543 last_page_id_sent_to_browser_(-1),
544 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00545 history_list_offset_(-1),
546 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24547 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55548#if defined(OS_MACOSX)
549 has_document_tag_(false),
550#endif
[email protected]98324892009-09-09 21:16:05551 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02552 target_url_status_(TARGET_NONE),
553 spelling_panel_visible_(false),
554 view_type_(ViewType::INVALID),
555 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18556 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30557 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51558 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02559 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
560 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51561 devtools_client_(NULL),
562 geolocation_dispatcher_(NULL),
563 speech_input_dispatcher_(NULL),
564 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51565 accessibility_ack_pending_(false),
[email protected]bb461532010-11-26 21:50:23566 pending_app_icon_requests_(0),
[email protected]3354d3e2010-06-10 19:53:02567 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]6a8b86c2010-12-09 05:24:30568 custom_menu_listener_(NULL) {
[email protected]8de12d942010-11-17 20:42:44569#if defined(OS_MACOSX)
570 // On Mac, the select popups are rendered by the browser.
571 // Note that we don't do this in RenderMain otherwise this would not be called
572 // in single-process mode.
573 WebKit::WebView::setUseExternalPopupMenus(true);
574#endif
[email protected]676126f72011-01-15 00:03:51575
[email protected]71b0d5d2010-02-15 05:43:07576 ClearBlockedContentSettings();
[email protected]3ead1322010-11-19 20:01:00577 if (CommandLine::ForCurrentProcess()->HasSwitch(
578 switches::kEnableClientSidePhishingDetection)) {
579 phishing_delegate_.reset(
580 new safe_browsing::PhishingClassifierDelegate(this, NULL));
581 RenderThread* thread = RenderThread::current();
582 if (thread && thread->phishing_scorer()) {
583 phishing_delegate_->SetPhishingScorer(thread->phishing_scorer());
584 }
585 }
[email protected]676126f72011-01-15 00:03:51586
587 routing_id_ = routing_id;
588 if (opener_id != MSG_ROUTING_NONE)
589 opener_id_ = opener_id;
590
591 if (counter) {
592 shared_popup_counter_ = counter;
593 shared_popup_counter_->data++;
594 decrement_shared_popup_at_destruction_ = true;
595 } else {
596 shared_popup_counter_ = new SharedRenderViewCounter(0);
597 decrement_shared_popup_at_destruction_ = false;
598 }
599
600 notification_provider_ = new NotificationProvider(this);
601
602 devtools_agent_ = new DevToolsAgent(this);
603 PasswordAutocompleteManager* password_autocomplete_manager =
604 new PasswordAutocompleteManager(this);
605 AutoFillHelper* autofill_helper = new AutoFillHelper(
606 this, password_autocomplete_manager);
607
608 webwidget_ = WebView::create(this, devtools_agent_, autofill_helper);
609 g_view_map.Get().insert(std::make_pair(webview(), this));
610 webkit_preferences_.Apply(webview());
611 webview()->initializeMainFrame(this);
612 if (!frame_name.empty())
613 webview()->mainFrame()->setName(frame_name);
614
615 OnSetRendererPrefs(renderer_prefs);
616
617 render_thread_->AddRoute(routing_id_, this);
618 // Take a reference on behalf of the RenderThread. This will be balanced
619 // when we receive ViewMsg_Close.
620 AddRef();
621
622 // If this is a popup, we must wait for the CreatingNew_ACK message before
623 // completing initialization. Otherwise, we can finish it now.
624 if (opener_id == MSG_ROUTING_NONE) {
625 did_show_ = true;
626 CompleteInit(parent_hwnd);
627 }
628
629 host_window_ = parent_hwnd;
630
631 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
632 if (command_line.HasSwitch(switches::kDomAutomationController))
633 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
634 if (command_line.HasSwitch(switches::kEnableAccessibility))
635 WebAccessibilityCache::enableAccessibility();
636
637 audio_message_filter_ = new AudioMessageFilter(routing_id_);
638 render_thread_->AddFilter(audio_message_filter_);
639
640 PageClickTracker* page_click_tracker = new PageClickTracker(this);
641 // Note that the order of insertion of the listeners is important.
642 // The password_autocomplete_manager takes the first shot at processing the
643 // notification and can stop the propagation.
644 page_click_tracker->AddListener(password_autocomplete_manager);
645 page_click_tracker->AddListener(autofill_helper);
initial.commit09911bf2008-07-26 23:55:29646}
647
648RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08649 if (decrement_shared_popup_at_destruction_)
650 shared_popup_counter_->data--;
651
[email protected]a1128322009-10-06 18:38:46652 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47653 while (!file_chooser_completions_.empty()) {
654 if (file_chooser_completions_.front()->completion) {
655 file_chooser_completions_.front()->completion->didChooseFile(
656 WebVector<WebString>());
657 }
658 file_chooser_completions_.pop_front();
659 }
[email protected]a1128322009-10-06 18:38:46660
[email protected]83dde542009-09-11 20:59:55661#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05662 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55663 if (has_document_tag_)
664 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11665
666 // Destroy all fake plugin window handles on the browser side.
667 while (!fake_plugin_window_handles_.empty()) {
668 // Make sure no NULL plugin window handles were inserted into this list.
669 DCHECK(*fake_plugin_window_handles_.begin());
670 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
671 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
672 }
[email protected]83dde542009-09-11 20:59:55673#endif
[email protected]98324892009-09-09 21:16:05674
[email protected]5fb88962009-04-16 19:03:25675 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59676
[email protected]3ead1322010-11-19 20:01:00677 // Tell the PhishingClassifierDelegate that the view is going away.
678 if (phishing_delegate_.get())
679 phishing_delegate_->CancelPendingClassification();
680
[email protected]60c42a8c72009-10-09 04:08:59681#ifndef NDEBUG
682 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49683 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59684 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
685 DCHECK_NE(this, it->second) << "Failed to call Close?";
686#endif
[email protected]676126f72011-01-15 00:03:51687
688 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
689 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59690}
691
692/*static*/
693void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49694 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59695 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
696 if (!visitor->Visit(it->second))
697 return;
698 }
699}
700
701/*static*/
702RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49703 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59704 ViewMap::iterator it = views->find(webview);
705 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29706}
707
708/*static*/
[email protected]0aa55312008-10-17 21:53:08709RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24710 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15711 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08712 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51713 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08714 const WebPreferences& webkit_prefs,
715 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34716 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26717 int64 session_storage_namespace_id,
718 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29719 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51720 return new RenderView(
721 render_thread,
722 parent_hwnd,
723 opener_id,
724 renderer_prefs,
725 webkit_prefs,
726 counter,
727 routing_id,
728 session_storage_namespace_id,
729 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29730}
731
[email protected]bb461532010-11-26 21:50:23732// static
initial.commit09911bf2008-07-26 23:55:29733void RenderView::SetNextPageID(int32 next_page_id) {
734 // This method should only be called during process startup, and the given
735 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05736 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29737 DCHECK(next_page_id >= next_page_id_);
738 next_page_id_ = next_page_id;
739}
740
[email protected]676126f72011-01-15 00:03:51741void RenderView::AddObserver(RenderViewObserver* observer) {
742 observers_.AddObserver(observer);
743}
744
745void RenderView::RemoveObserver(RenderViewObserver* observer) {
746 observer->set_render_view(NULL);
747 observers_.RemoveObserver(observer);
748}
749
[email protected]70eee342010-11-05 01:59:37750bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
751 typedef ViewHostMsg_AccessibilityNotification_Params params;
752 if (type == params::NOTIFICATION_TYPE_CHILDREN_CHANGED ||
753 type == params::NOTIFICATION_TYPE_LOAD_COMPLETE) {
754 return true;
755 }
756 return false;
757}
758
[email protected]8a3125a712010-08-09 18:58:51759WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26760 return static_cast<WebKit::WebView*>(webwidget());
761}
762
[email protected]afe3a1672009-11-17 19:04:12763void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50764 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56765}
766
[email protected]bb461532010-11-26 21:50:23767bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
768 string16* error) {
769 // There is an issue of drive-by installs with the below implementation. A web
770 // site could force a user to install an app by timing the dialog to come up
771 // just before the user clicks.
772 //
773 // We do show a success UI that allows users to uninstall, but it seems that
774 // we might still want to put up an infobar before showing the install dialog.
775 //
776 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
777 // switch.
778 if (!CommandLine::ForCurrentProcess()->HasSwitch(
779 switches::kEnableCrxlessWebApps)) {
780 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
781 return false;
782 }
783
784 if (frame != frame->top()) {
785 *error = ASCIIToUTF16("Applications can only be installed from the top "
786 "frame.");
787 return false;
788 }
789
790 if (pending_app_info_.get()) {
791 *error = ASCIIToUTF16("An application install is already in progress.");
792 return false;
793 }
794
795 pending_app_info_.reset(new WebApplicationInfo());
796 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
797 error)) {
798 return false;
799 }
800
801 if (!pending_app_info_->manifest_url.is_valid()) {
802 *error = ASCIIToUTF16("Web application definition not found or invalid.");
803 return false;
804 }
805
806 app_definition_fetcher_.reset(new ResourceFetcher(
807 pending_app_info_->manifest_url, webview()->mainFrame(),
808 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
809 return true;
810}
811
[email protected]1a3c3cb2010-12-16 21:03:40812void RenderView::SetReportLoadProgressEnabled(bool enabled) {
813 if (!enabled) {
814 load_progress_tracker_.reset(NULL);
815 return;
816 }
817 if (load_progress_tracker_ == NULL)
818 load_progress_tracker_.reset(new LoadProgressTracker(this));
819}
820
[email protected]bb461532010-11-26 21:50:23821void RenderView::DidDownloadApplicationDefinition(
822 const WebKit::WebURLResponse& response,
823 const std::string& data) {
824 scoped_ptr<WebApplicationInfo> app_info(
825 pending_app_info_.release());
826
827 JSONStringValueSerializer serializer(data);
828 int error_code = 0;
829 std::string error_message;
830 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
831 if (!result.get()) {
832 AddErrorToRootConsole(UTF8ToUTF16(error_message));
833 return;
834 }
835
836 string16 error_message_16;
837 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
838 &error_message_16)) {
839 AddErrorToRootConsole(error_message_16);
840 return;
841 }
842
843 if (!app_info->icons.empty()) {
844 pending_app_info_.reset(app_info.release());
845 pending_app_icon_requests_ =
846 static_cast<int>(pending_app_info_->icons.size());
847 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
848 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
849 new ImageResourceFetcher(
850 pending_app_info_->icons[i].url,
851 webview()->mainFrame(),
852 static_cast<int>(i),
853 pending_app_info_->icons[i].width,
854 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
855 }
856 } else {
857 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
858 }
859}
860
861void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
862 const SkBitmap& image) {
863 pending_app_info_->icons[fetcher->id()].data = image;
864
865 // Remove the image fetcher from our pending list. We're in the callback from
866 // ImageResourceFetcher, best to delay deletion.
867 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
868 iter != app_icon_fetchers_.end(); ++iter) {
869 if (iter->get() == fetcher) {
870 iter->release();
871 app_icon_fetchers_.erase(iter);
872 break;
873 }
874 }
875
876 // We're in the callback from the ImageResourceFetcher, best to delay
877 // deletion.
878 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
879
880 if (--pending_app_icon_requests_ > 0)
881 return;
882
883 // There is a maximum size of IPC on OS X and Linux that we have run into in
884 // some situations. We're not sure what it is, but our hypothesis is in the
885 // neighborhood of 1 MB.
886 //
887 // To be on the safe side, we give ourselves 128 KB for just the image data.
888 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
889 // want to start allowing larger icons (see bug 63406), we'll have to either
890 // experiment mor ewith this and find the real limit, or else come up with
891 // some alternative way to transmit the icon data to the browser process.
892 //
893 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32894 const size_t kMaxIconSize = 1024 * 128;
895 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23896 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32897 size_t current_size = pending_app_info_->icons[i].data.getSize();
898 if (current_size > kMaxIconSize - actual_icon_size) {
899 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23900 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32901 return;
902 }
903 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23904 }
905
906 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
907 pending_app_info_.reset(NULL);
908}
909
[email protected]a3a8fb6d2009-10-22 20:12:51910void RenderView::PluginCrashed(const FilePath& plugin_path) {
911 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29912}
913
[email protected]aad51d1c2010-08-05 08:38:09914WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
915 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50916 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26917 bool found;
918 ContentSetting setting;
919 std::string mime_type;
920 Send(new ViewHostMsg_GetPluginInfo(
921 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
922 &info, &setting, &mime_type));
923 if (!found || !info.enabled)
[email protected]aad51d1c2010-08-05 08:38:09924 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45925
[email protected]0bd753682010-12-16 18:15:52926 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45927 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09928 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26929 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45930 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09931}
932
[email protected]6a8b86c2010-12-09 05:24:30933void RenderView::CustomMenuListenerInstall(CustomMenuListener* listening) {
934 custom_menu_listener_ = listening;
935}
936
937void RenderView::CustomMenuListenerDestroyed(CustomMenuListener* dead) {
938 if (custom_menu_listener_ == dead)
939 custom_menu_listener_ = NULL;
940}
941
[email protected]d8fd6fa2010-02-01 15:54:26942void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
943 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30944 // If the renderer is visible, set initial visibility and focus state.
945 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34946#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30947 delegate->SetContainerVisibility(true);
948 if (webview() && webview()->isActive())
949 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34950#endif
[email protected]49232292010-09-03 19:07:30951 }
[email protected]784ea1ab2010-09-18 00:02:34952 // Plugins start assuming the content has focus (so that they work in
953 // environments where RenderView isn't hosting them), so we always have to
954 // set the initial state. See webplugin_delegate_impl.h for details.
955 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26956}
957
958void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
959 plugin_delegates_.erase(delegate);
960}
[email protected]d8fd6fa2010-02-01 15:54:26961
[email protected]8853bc932011-01-11 16:27:02962void RenderView::RegisterBlockedPlugin(BlockedPlugin* blocked_plugin) {
963 blocked_plugins_.insert(blocked_plugin);
964}
965
966void RenderView::UnregisterBlockedPlugin(BlockedPlugin* blocked_plugin) {
967 blocked_plugins_.erase(blocked_plugin);
968}
969
[email protected]a95986a82010-12-24 06:19:28970bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27971 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27972 if (main_frame)
973 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26974
[email protected]676126f72011-01-15 00:03:51975 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
976 RenderViewObserver* observer;
977 while ((observer = it.GetNext()) != NULL)
978 if (observer->OnMessageReceived(message))
979 return true;
[email protected]b2abac72009-02-26 12:39:28980
[email protected]a95986a82010-12-24 06:19:28981 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29982 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04983 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
984 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29985 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01986 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29987 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
988 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56989 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29990 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
991 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
992 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
993 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27994#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35995 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27996#endif
initial.commit09911bf2008-07-26 23:55:29997 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
998 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05999 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
1000 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
1001 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:041002 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:291003 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
1004 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
1005 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:151006 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:291007 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491008 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1009 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171010 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541011 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1012 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171013 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541014 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1015 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291016 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181017 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1018 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281019 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:331020 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:291021 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481022 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291023 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291024 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291025 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1026 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1027 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1028 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451029 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291030 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:501031 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1032 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291033 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1034 OnDragSourceSystemDragEnded)
1035 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511036 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1037 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291038 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1039 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1040 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1041 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:211042 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:291043 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1044 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291045 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1046 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041047 IPC_MESSAGE_HANDLER(
1048 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1049 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291050 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041051 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291052 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1053 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451054 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041055 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081056 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1057 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401058 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1059 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001060 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271061 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371062 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1063 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161064 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141065 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251066 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1067 OnEnablePreferredSizeChangedMode)
[email protected]ce833282010-11-04 15:48:391068 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxChange, OnSearchBoxChange)
1069 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxSubmit, OnSearchBoxSubmit)
1070 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxCancel, OnSearchBoxCancel)
1071 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxResize, OnSearchBoxResize)
1072 IPC_MESSAGE_HANDLER(ViewMsg_DetermineIfPageSupportsInstant,
1073 OnDetermineIfPageSupportsInstant)
[email protected]cda45c02010-02-25 19:28:101074 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1075 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511076 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531077 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1078 OnUpdateBrowserWindowId)
1079 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1080 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561081 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341082 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141083#if defined(OS_MACOSX)
1084 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131085 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]935d63d2010-10-15 23:31:551086 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionConfirmed,
1087 OnPluginImeCompositionConfirmed)
[email protected]6ce7abc52010-02-02 18:40:141088#endif
[email protected]446705872009-09-10 07:22:481089 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331090 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351091 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1092 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331093 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1094 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:421095 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:021096 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]dea2d372010-09-25 06:41:141097 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361098 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1099 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1100 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421101 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1102 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241103 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]1b4209f2011-01-07 00:25:401104#if defined(ENABLE_FLAPPER_HACKS)
1105 IPC_MESSAGE_HANDLER(ViewMsg_PepperConnectTcpACK, OnConnectTcpACK)
1106#endif
[email protected]caf706f2010-10-26 17:54:081107#if defined(OS_MACOSX)
1108 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1109#endif
[email protected]212a49d2010-10-25 18:23:471110 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview)
[email protected]a6097f42011-01-10 08:50:511111 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1112 OnJavaScriptStressTestControl)
[email protected]634a6f92008-12-01 21:39:311113
initial.commit09911bf2008-07-26 23:55:291114 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281115 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291116 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281117 return handled;
initial.commit09911bf2008-07-26 23:55:291118}
1119
[email protected]9b18a84f2010-06-10 15:54:041120void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271121 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291122 if (!main_frame)
1123 return;
1124
1125 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451126 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291127 if (url.is_empty())
1128 return;
1129
1130 if (size_.IsEmpty())
1131 return; // Don't create an empty thumbnail!
1132
1133 ThumbnailScore score;
1134 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021135 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151136 &thumbnail, &score))
1137 return;
1138
initial.commit09911bf2008-07-26 23:55:291139 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461140 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291141}
1142
[email protected]9b18a84f2010-06-10 15:54:041143void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231144 SkBitmap snapshot;
1145 bool error = false;
1146
1147 WebFrame* main_frame = webview()->mainFrame();
1148 if (!main_frame)
1149 error = true;
1150
1151 if (!error && !CaptureSnapshot(webview(), &snapshot))
1152 error = true;
1153
1154 DCHECK(error == snapshot.empty()) <<
1155 "Snapshot should be empty on error, non-empty otherwise.";
1156
1157 // Send the snapshot to the browser process.
1158 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1159}
1160
[email protected]068637222009-01-29 16:58:071161void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:291162 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:581163 if (webview()) {
1164 // If the user has selected text in the currently focused frame we print
1165 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:271166 if (webview()->focusedFrame()->hasSelection())
[email protected]212a49d2010-10-25 18:23:471167 Print(webview()->focusedFrame(), false, false);
[email protected]aa82249f2009-07-16 17:23:581168 else
[email protected]212a49d2010-10-25 18:23:471169 Print(webview()->mainFrame(), false, false);
[email protected]aa82249f2009-07-16 17:23:581170 }
initial.commit09911bf2008-07-26 23:55:291171}
1172
[email protected]82270452009-06-19 15:58:011173void RenderView::OnPrintingDone(int document_cookie, bool success) {
1174 // Ignoring document cookie here since only one print job can be outstanding
1175 // per renderer and document_cookie is 0 when printing is successful.
1176 DCHECK(print_helper_.get());
1177 if (print_helper_.get() != NULL) {
1178 print_helper_->DidFinishPrinting(success);
1179 }
1180}
1181
[email protected]212a49d2010-10-25 18:23:471182void RenderView::OnPrintPreview() {
1183 DCHECK(webview());
1184 if (webview()) {
1185 // If the user has selected text in the currently focused frame we print
1186 // only that frame (this makes print selection work for multiple frames).
1187 if (webview()->focusedFrame()->hasSelection())
1188 Print(webview()->focusedFrame(), false, true);
1189 else
1190 Print(webview()->focusedFrame(), false, true);
1191 }
1192}
1193
initial.commit09911bf2008-07-26 23:55:291194void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1195 if (load_id != page_id_)
1196 return; // this capture call is no longer relevant due to navigation
1197 if (load_id == last_indexed_page_id_)
1198 return; // we already indexed this page
1199
1200 if (!webview())
1201 return;
1202
[email protected]26aa0482009-09-30 16:55:271203 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291204 if (!main_frame)
1205 return;
1206
1207 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451208 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291209 return;
1210
1211 // Don't index/capture pages that failed to load. This only checks the top
1212 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451213 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281214 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291215 return;
1216
1217 if (!preliminary_capture)
1218 last_indexed_page_id_ = load_id;
1219
[email protected]a8a81292010-01-21 00:32:451220 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451221 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291222 if (url.is_empty())
1223 return;
1224
[email protected]a8a81292010-01-21 00:32:451225 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361226 string16 contents;
initial.commit09911bf2008-07-26 23:55:291227 CaptureText(main_frame, &contents);
1228 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101229 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371230 // If the page explicitly specifies a language, use it, otherwise we'll
1231 // determine it based on the text content using the CLD.
1232 std::string language =
1233 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1234 if (language.empty()) {
1235 base::TimeTicks begin_time = base::TimeTicks::Now();
1236 language = DetermineTextLanguage(contents);
1237 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1238 base::TimeTicks::Now() - begin_time);
1239 }
[email protected]a8a81292010-01-21 00:32:451240 // Send the text to the browser for indexing (the browser might decide not
1241 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371242 Send(new ViewHostMsg_PageContents(
1243 routing_id_, url, load_id, contents, language,
1244 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271245 }
1246
[email protected]9b18a84f2010-06-10 15:54:041247 OnCaptureThumbnail();
[email protected]3ead1322010-11-19 20:01:001248
1249 if (phishing_delegate_.get())
1250 phishing_delegate_->FinishedLoad(&contents);
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]e5106202010-06-11 21:12:361253void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291254 contents->clear();
1255 if (!frame)
1256 return;
1257
1258#ifdef TIME_TEXT_RETRIEVAL
1259 double begin = time_util::GetHighResolutionTimeNow();
1260#endif
1261
1262 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361263 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291264
1265#ifdef TIME_TEXT_RETRIEVAL
1266 double end = time_util::GetHighResolutionTimeNow();
1267 char buf[128];
1268 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1269 contents.size(), (end - begin)*1000);
1270 OutputDebugStringA(buf);
1271#endif
1272
1273 // When the contents are clipped to the maximum, we don't want to have a
1274 // partial word indexed at the end that might have been clipped. Therefore,
1275 // terminate the string at the last space to ensure no words are clipped.
1276 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361277 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291278 if (last_space_index == std::wstring::npos)
1279 return; // don't index if we got a huge block of text with no spaces
1280 contents->resize(last_space_index);
1281 }
1282}
1283
[email protected]8649fb32009-06-26 17:51:021284bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291285 int w,
1286 int h,
1287 SkBitmap* thumbnail,
1288 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231289 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151290
[email protected]8649fb32009-06-26 17:51:021291 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231292
1293 // Paint |view| into |canvas|.
1294 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021295 return false;
[email protected]8649fb32009-06-26 17:51:021296
1297 skia::BitmapPlatformDevice& device =
1298 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1299
1300 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291301
[email protected]cab34d6a2009-09-24 01:14:521302 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291303 float dest_aspect = dest_rect.width() / dest_rect.height();
1304
1305 // Get the src rect so that we can preserve the aspect ratio while filling
1306 // the destination.
1307 SkIRect src_rect;
1308 if (src_bmp.width() < dest_rect.width() ||
1309 src_bmp.height() < dest_rect.height()) {
1310 // Source image is smaller: we clip the part of source image within the
1311 // dest rect, and then stretch it to fill the dest rect. We don't respect
1312 // the aspect ratio in this case.
1313 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1314 static_cast<S16CPU>(dest_rect.height()));
1315 score->good_clipping = false;
1316 } else {
1317 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1318 if (src_aspect > dest_aspect) {
1319 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1320 // the wider screen.
1321 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1322 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1323 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1324 score->good_clipping = false;
1325 } else {
1326 src_rect.set(0, 0, src_bmp.width(),
1327 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1328 score->good_clipping = true;
1329 }
1330 }
1331
[email protected]26aa0482009-09-30 16:55:271332 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291333
1334 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021335 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291336
[email protected]82afe4b2010-11-12 20:36:221337 // First do a fast downsample by powers of two to get close to the final size.
1338 SkBitmap downsampled_subset =
1339 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1340
1341 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141342 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221343 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291344
1345 score->boring_score = CalculateBoringScore(thumbnail);
1346
[email protected]30507922010-01-15 16:48:231347 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1348 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221349
[email protected]b6e4bec2008-11-12 01:17:151350 return true;
initial.commit09911bf2008-07-26 23:55:291351}
1352
[email protected]30507922010-01-15 16:48:231353bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1354 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291355
[email protected]30507922010-01-15 16:48:231356 skia::PlatformCanvas canvas;
1357 if (!PaintViewIntoCanvas(view, canvas))
1358 return false;
1359
1360 skia::BitmapPlatformDevice& device =
1361 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1362
1363 const SkBitmap& bitmap = device.accessBitmap(false);
1364 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1365 return false;
1366
1367 HISTOGRAM_TIMES("Renderer4.Snapshot",
1368 base::TimeTicks::Now() - beginning_time);
1369 return true;
initial.commit09911bf2008-07-26 23:55:291370}
1371
1372void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1373 if (!webview())
1374 return;
1375
[email protected]3cc72b12010-03-18 23:03:001376 history_list_offset_ = params.current_history_list_offset;
1377 history_list_length_ = params.current_history_list_length;
1378
[email protected]a9f607e2009-10-23 19:59:271379 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261380
initial.commit09911bf2008-07-26 23:55:291381 AboutHandler::MaybeHandle(params.url);
1382
[email protected]ecbf10d2010-02-18 13:03:291383 bool is_reload =
1384 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1385 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291386
[email protected]26aa0482009-09-30 16:55:271387 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451388 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291389 // We cannot reload if we do not have any history state. This happens, for
1390 // example, when recovering from a crash. Our workaround here is a bit of
1391 // a hack since it means that reload after a crashed tab does not cause an
1392 // end-to-end cache validation.
1393 is_reload = false;
1394 }
1395
[email protected]77f17a82009-05-21 04:42:541396 // A navigation resulting from loading a javascript URL should not be treated
1397 // as a browser initiated event. Instead, we want it to look as if the page
1398 // initiated any load resulting from JS execution.
1399 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301400 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001401 params.page_id,
1402 params.pending_history_list_offset,
1403 params.transition,
1404 params.request_time);
[email protected]5e369672009-11-03 23:48:301405 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1406 // We're doing a load of a page that was restored from the last session.
1407 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1408 // which can result in stale data for pages that are set to expire. We
1409 // explicitly override that by setting the policy here so that as
1410 // necessary we load from the network.
1411 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1412 }
1413 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541414 }
initial.commit09911bf2008-07-26 23:55:291415
[email protected]a7ccc4d2010-01-27 08:14:481416 NavigationState* navigation_state = pending_navigation_state_.get();
1417
[email protected]04d3c6e2009-05-22 17:00:131418 // If we are reloading, then WebKit will use the history state of the current
1419 // page, so we should just ignore any given history state. Otherwise, if we
1420 // have history state, then we need to navigate to it, which corresponds to a
1421 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551422 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481423 if (navigation_state)
1424 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291425 bool ignore_cache = (params.navigation_type ==
1426 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1427 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551428 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131429 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581430 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481431 if (navigation_state)
1432 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451433 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171434 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131435 } else {
1436 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281437 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291438
[email protected]e6f546c32009-07-01 17:12:551439 // A session history navigation should have been accompanied by state.
1440 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131441
[email protected]dd7daa82009-08-10 05:46:451442 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551443 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131444
[email protected]726985e22009-06-18 21:09:281445 if (params.referrer.is_valid()) {
1446 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1447 WebString::fromUTF8(params.referrer.spec()));
1448 }
[email protected]04d3c6e2009-05-22 17:00:131449
[email protected]52c68652010-12-07 17:47:041450 if (!params.extra_headers.empty()) {
1451 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1452 params.extra_headers.end(), "\n");
1453 i.GetNext(); ) {
1454 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1455 WebString::fromUTF8(i.values()));
1456 }
1457 }
1458
[email protected]a7ccc4d2010-01-27 08:14:481459 if (navigation_state)
1460 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451461 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501462 }
1463
[email protected]77f17a82009-05-21 04:42:541464 // In case LoadRequest failed before DidCreateDataSource was called.
1465 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291466}
1467
1468// Stop loading the current page
1469void RenderView::OnStop() {
1470 if (webview())
[email protected]b4bb2502009-10-01 22:35:271471 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291472}
1473
[email protected]ecbf10d2010-02-18 13:03:291474// Reload current focused frame.
1475// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561476void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291477 if (webview() && webview()->focusedFrame()) {
1478 // We always obey the cache (ignore_cache=false) here.
1479 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1480 // a cache-ignoring reload of the frame.
1481 webview()->focusedFrame()->reload(false);
1482 }
[email protected]1dda4022010-01-28 18:24:561483}
1484
initial.commit09911bf2008-07-26 23:55:291485void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271486 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291487}
1488
[email protected]68b1e922009-06-23 16:00:251489void RenderView::OnExecuteEditCommand(const std::string& name,
1490 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271491 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251492 return;
1493
[email protected]26aa0482009-09-30 16:55:271494 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451495 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251496}
1497
[email protected]b2abac72009-02-26 12:39:281498void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511499 DCHECK(!devtools_client_);
1500 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281501}
1502
initial.commit09911bf2008-07-26 23:55:291503void RenderView::OnUpdateTargetURLAck() {
1504 // Check if there is a targeturl waiting to be sent.
1505 if (target_url_status_ == TARGET_PENDING) {
1506 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1507 pending_target_url_));
1508 }
1509
1510 target_url_status_ = TARGET_NONE;
1511}
1512
1513void RenderView::OnUndo() {
1514 if (!webview())
1515 return;
1516
[email protected]26aa0482009-09-30 16:55:271517 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121518 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291519}
1520
1521void RenderView::OnRedo() {
1522 if (!webview())
1523 return;
1524
[email protected]26aa0482009-09-30 16:55:271525 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121526 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291527}
1528
1529void RenderView::OnCut() {
1530 if (!webview())
1531 return;
1532
[email protected]26aa0482009-09-30 16:55:271533 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121534 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291535}
1536
1537void RenderView::OnCopy() {
1538 if (!webview())
1539 return;
1540
[email protected]26aa0482009-09-30 16:55:271541 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121542 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291543}
1544
[email protected]c0cc3092009-09-12 08:27:271545#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351546void RenderView::OnCopyToFindPboard() {
1547 if (!webview())
1548 return;
1549
1550 // Since the find pasteboard supports only plain text, this can be simpler
1551 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271552 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351553 if (frame->hasSelection()) {
1554 string16 selection = frame->selectionAsText();
1555 RenderThread::current()->Send(
1556 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1557 }
1558
[email protected]afe3a1672009-11-17 19:04:121559 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351560}
[email protected]c0cc3092009-09-12 08:27:271561#endif
[email protected]a954bf72009-09-12 07:30:351562
initial.commit09911bf2008-07-26 23:55:291563void RenderView::OnPaste() {
1564 if (!webview())
1565 return;
1566
[email protected]26aa0482009-09-30 16:55:271567 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121568 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291569}
1570
[email protected]2a3a7762009-10-19 19:17:321571void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291572 if (!webview())
1573 return;
1574
[email protected]1ff7a032010-02-03 02:46:031575 WebFrame* frame = webview()->focusedFrame();
1576 if (!frame->hasSelection())
1577 frame->selectWordAroundCaret();
1578 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291579}
1580
[email protected]98324892009-09-09 21:16:051581void RenderView::OnAdvanceToNextMisspelling() {
1582 if (!webview())
1583 return;
[email protected]26aa0482009-09-30 16:55:271584 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051585 WebString::fromUTF8("AdvanceToNextMisspelling"));
1586}
1587
1588void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1589 if (!webview())
1590 return;
1591 // We need to tell the webView whether the spelling panel is visible or not so
1592 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261593 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271594 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051595 WebString::fromUTF8("ToggleSpellPanel"));
1596}
1597
[email protected]bbbd545c2008-12-15 20:18:041598void RenderView::OnToggleSpellCheck() {
1599 if (!webview())
1600 return;
1601
[email protected]26aa0482009-09-30 16:55:271602 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451603 frame->enableContinuousSpellChecking(
1604 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041605}
1606
initial.commit09911bf2008-07-26 23:55:291607void RenderView::OnDelete() {
1608 if (!webview())
1609 return;
1610
[email protected]26aa0482009-09-30 16:55:271611 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121612 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291613}
1614
1615void RenderView::OnSelectAll() {
1616 if (!webview())
1617 return;
1618
[email protected]26aa0482009-09-30 16:55:271619 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221620 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121621 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291622}
1623
1624void RenderView::OnSetInitialFocus(bool reverse) {
1625 if (!webview())
1626 return;
[email protected]26aa0482009-09-30 16:55:271627 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291628}
1629
[email protected]9b66f34bf2010-10-27 20:45:511630void RenderView::OnScrollFocusedEditableNodeIntoView() {
1631 if (!webview())
1632 return;
1633 WebFrame* focused_frame = webview()->focusedFrame();
1634 if (focused_frame) {
1635 WebDocument doc = focused_frame->document();
1636 if (!doc.isNull()) {
1637 WebNode node = doc.focusedNode();
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();
1642 }
1643 }
1644}
1645
initial.commit09911bf2008-07-26 23:55:291646///////////////////////////////////////////////////////////////////////////////
1647
[email protected]433819d2010-01-30 20:20:011648void RenderView::SetContentSettings(const ContentSettings& settings) {
1649 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011650}
1651
initial.commit09911bf2008-07-26 23:55:291652// Tell the embedding application that the URL of the active page has changed
1653void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451654 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291655 DCHECK(ds);
1656
[email protected]726985e22009-06-18 21:09:281657 const WebURLRequest& request = ds->request();
1658 const WebURLRequest& original_request = ds->originalRequest();
1659 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291660
[email protected]daa8c58e2009-06-15 17:21:101661 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1662 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291663
1664 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281665 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291666 params.is_post = false;
1667 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071668 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281669 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091670 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551671 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291672 // SSL state specified in the request takes precedence over the one in the
1673 // response.
1674 // So far this is only intended for error pages that are not expected to be
1675 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281676 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551677 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291678 } else {
[email protected]726985e22009-06-18 21:09:281679 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291680 }
1681
1682 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281683 if (ds->hasUnreachableURL()) {
1684 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291685 } else {
[email protected]726985e22009-06-18 21:09:281686 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291687 }
1688
[email protected]726985e22009-06-18 21:09:281689 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241690 params.should_update_history = !ds->hasUnreachableURL() &&
1691 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291692
[email protected]ce0e250d2009-10-23 21:00:351693 params.searchable_form_url = navigation_state->searchable_form_url();
1694 params.searchable_form_encoding =
1695 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291696
1697 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101698 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291699 if (password_form_data)
1700 params.password_form = *password_form_data;
1701
1702 params.gesture = navigation_gesture_;
1703 navigation_gesture_ = NavigationGestureUnknown;
1704
[email protected]dd7daa82009-08-10 05:46:451705 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291706 // Top-level navigation.
1707
[email protected]71b0d5d2010-02-15 05:43:071708 // Clear "block" flags for the new page. This needs to happen before any of
1709 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1710 // so that these functions can correctly detect that a piece of content
1711 // flipped from "not blocked" to "blocked".
1712 ClearBlockedContentSettings();
1713
[email protected]62d2a112010-04-07 00:53:021714 // Set content settings. Default them from the parent window if one exists.
1715 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011716 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541717 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011718 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011719 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011720
1721 // These content settings were merely recorded transiently for this load.
1722 // We can erase them now. If at some point we reload this page, the
1723 // browser will send us new, up-to-date content settings.
1724 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401725 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101726 // The opener's view is not guaranteed to be non-null (it could be
1727 // detached from its page but not yet destructed).
1728 if (WebView* opener_view = frame->opener()->view()) {
1729 RenderView* opener = FromWebView(opener_view);
1730 SetContentSettings(opener->current_content_settings_);
1731 }
[email protected]f85f0702010-01-30 09:31:011732 }
1733
[email protected]b75b8292010-10-01 07:28:251734 // Set zoom level, but don't do it for full-page plugin since they don't use
1735 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011736 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541737 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251738 if (webview()->mainFrame()->document().isPluginDocument()) {
1739 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251740 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251741 } else {
1742 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251743 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251744 }
1745
[email protected]f85f0702010-01-30 09:31:011746 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511747 // This zoom level was merely recorded transiently for this load. We can
1748 // erase it now. If at some point we reload this page, the browser will
1749 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011750 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511751 }
1752
[email protected]b75b8292010-10-01 07:28:251753 // Reset the zoom limits in case a plugin had changed them previously. This
1754 // will also call us back which will cause us to send a message to
1755 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251756 webview()->zoomLimitsChanged(
1757 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1758 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251759
initial.commit09911bf2008-07-26 23:55:291760 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551761 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291762
[email protected]daa8c58e2009-06-15 17:21:101763 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291764 if (!PageTransition::IsMainFrame(params.transition)) {
1765 // If the main frame does a load, it should not be reported as a subframe
1766 // navigation. This can occur in the following case:
1767 // 1. You're on a site with frames.
1768 // 2. You do a subframe navigation. This is stored with transition type
1769 // MANUAL_SUBFRAME.
1770 // 3. You navigate to some non-frame site, say, google.com.
1771 // 4. You navigate back to the page from step 2. Since it was initially
1772 // MANUAL_SUBFRAME, it will be that same transition type here.
1773 // We don't want that, because any navigation that changes the toplevel
1774 // frame should be tracked as a toplevel navigation (this allows us to
1775 // update the URL bar, etc).
1776 params.transition = PageTransition::LINK;
1777 }
1778
initial.commit09911bf2008-07-26 23:55:291779 // If we have a valid consumed client redirect source,
1780 // the page contained a client redirect (meta refresh, document.loc...),
1781 // so we set the referrer and transition to match.
1782 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041783 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291784 params.referrer = completed_client_redirect_src_;
1785 params.transition = static_cast<PageTransition::Type>(
1786 params.transition | PageTransition::CLIENT_REDIRECT);
1787 } else {
1788 // Bug 654101: the referrer will be empty on https->http transitions. It
1789 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281790 params.referrer = GURL(
1791 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291792 }
1793
[email protected]726985e22009-06-18 21:09:281794 string16 method = request.httpMethod();
1795 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291796 params.is_post = true;
1797
[email protected]c2a797d2009-09-21 16:46:321798 // Save some histogram data so we can compute the average memory used per
1799 // page load of the glyphs.
1800 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1801 webkit_glue::GetGlyphPageCount());
1802
[email protected]15cf526b2010-02-12 06:33:491803 // This message needs to be sent before any of allowScripts(),
1804 // allowImages(), allowPlugins() is called for the new page, so that when
1805 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1806 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291807 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1808 } else {
1809 // Subframe navigation: the type depends on whether this navigation
1810 // generated a new session history entry. When they do generate a session
1811 // history entry, it means the user initiated the navigation and we should
1812 // mark it as such. This test checks if this is the first time UpdateURL
1813 // has been called since WillNavigateToURL was called to initiate the load.
1814 if (page_id_ > last_page_id_sent_to_browser_)
1815 params.transition = PageTransition::MANUAL_SUBFRAME;
1816 else
1817 params.transition = PageTransition::AUTO_SUBFRAME;
1818
initial.commit09911bf2008-07-26 23:55:291819 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1820 }
1821
1822 last_page_id_sent_to_browser_ =
1823 std::max(last_page_id_sent_to_browser_, page_id_);
1824
1825 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101826 // we don't want the transition type to persist. Just clear it.
1827 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501828
[email protected]af15bed2010-08-25 21:12:091829 // Check if the navigation was within the same page, in which case we don't
1830 // want to clear the accessibility cache.
1831 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351832 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141833 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501834 }
initial.commit09911bf2008-07-26 23:55:291835}
1836
1837// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171838void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291839 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171840 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171841 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171842 routing_id_,
1843 page_id_,
1844 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1845 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171846 }
initial.commit09911bf2008-07-26 23:55:291847}
1848
1849void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401850 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291851 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271852 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291853 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301854 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291855 last_encoding_name_ = encoding_name;
1856
[email protected]e38f40152008-09-12 23:08:301857 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291858 }
1859}
1860
[email protected]e15f680732010-11-23 22:30:201861// Sends the last committed session history state to the browser so it will be
1862// saved before we navigate to a new page. This must be called *before* the
1863// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291864void RenderView::UpdateSessionHistory(WebFrame* frame) {
1865 // If we have a valid page ID at this point, then it corresponds to the page
1866 // we are navigating away from. Otherwise, this is the first navigation, so
1867 // there is no past session history to record.
1868 if (page_id_ == -1)
1869 return;
1870
[email protected]ca948a22009-06-25 19:36:171871 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271872 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171873 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291874 return;
[email protected]ca948a22009-06-25 19:36:171875
1876 Send(new ViewHostMsg_UpdateState(
1877 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291878}
1879
[email protected]3d9689372009-09-10 04:29:171880void RenderView::OpenURL(
1881 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1882 Send(new ViewHostMsg_OpenURL(
1883 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1884}
1885
[email protected]79dbc662009-09-04 05:42:511886// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291887
initial.commit09911bf2008-07-26 23:55:291888void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281889 const WebURLRequest& failed_request,
1890 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291891 const std::string& html,
1892 bool replace) {
[email protected]726985e22009-06-18 21:09:281893 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291894 std::string alt_html;
[email protected]07b493512010-08-27 15:39:291895 ExtensionRendererInfo* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291896 if (html.empty()) {
1897 // Use a local error page.
1898 int resource_id;
1899 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111900
[email protected]81654282010-10-04 17:08:061901 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]5351dbc2010-08-27 15:22:111902 extension = ExtensionRendererInfo::GetByURL(failed_url);
1903 if (extension) {
[email protected]3f853a52010-09-13 19:15:081904 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1905 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111906
1907 // TODO(erikkay): Should we use a different template for different
1908 // error messages?
1909 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291910 } else {
[email protected]3f853a52010-09-13 19:15:081911 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1912 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111913 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081914 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111915 } else {
[email protected]3f853a52010-09-13 19:15:081916 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111917 }
[email protected]75891fe2010-11-20 15:55:181918 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291919 }
initial.commit09911bf2008-07-26 23:55:291920
1921 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1922 } else {
1923 alt_html = html;
1924 }
1925
[email protected]dd7daa82009-08-10 05:46:451926 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361927 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551928 failed_url,
1929 replace);
initial.commit09911bf2008-07-26 23:55:291930}
1931
[email protected]7ccddb8c2009-08-04 17:36:551932void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031933 if (!dom_automation_controller_.get()) {
1934 dom_automation_controller_.reset(new DomAutomationController());
1935 }
1936 dom_automation_controller_->set_message_sender(this);
1937 dom_automation_controller_->set_routing_id(routing_id_);
1938 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251939 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291940}
1941
initial.commit09911bf2008-07-26 23:55:291942bool RenderView::RunJavaScriptMessage(int type,
1943 const std::wstring& message,
1944 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071945 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291946 std::wstring* result) {
1947 bool success = false;
1948 std::wstring result_temp;
1949 if (!result)
1950 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291951
[email protected]12636df2009-09-28 22:32:211952 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1953 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291954 return success;
1955}
1956
[email protected]c1f50aa2010-02-18 03:46:571957bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1958 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1959 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1960 // it is particularly important that we do not call willEnterModalLoop as
1961 // that would defer resource loads for the dialog itself.
1962 if (RenderThread::current()) // Will be NULL during unit tests.
1963 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1964
1965 message->EnableMessagePumping(); // Runs a nested message loop.
1966 return Send(message);
1967}
1968
[email protected]2de7e002010-10-11 22:58:201969void RenderView::AddGURLSearchProvider(
1970 const GURL& osd_url,
1971 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291972 if (!osd_url.is_empty())
1973 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201974 provider_type));
initial.commit09911bf2008-07-26 23:55:291975}
1976
[email protected]e8345242010-05-06 03:00:401977void RenderView::OnAllowScriptToClose(bool script_can_close) {
1978 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311979}
1980
initial.commit09911bf2008-07-26 23:55:291981uint32 RenderView::GetCPBrowsingContext() {
1982 uint32 context = 0;
1983 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1984 return context;
1985}
1986
[email protected]2de7e002010-10-11 22:58:201987void RenderView::AddSearchProvider(
1988 const std::string& url,
1989 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1990 if (provider_type.type ==
1991 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1992 !webview()->mainFrame()->isProcessingUserGesture())
1993 return;
1994
1995 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291996}
1997
[email protected]155f35e2010-07-17 00:30:181998ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251999RenderView::GetSearchProviderInstallState(WebFrame* frame,
2000 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:182001 GURL inquiry_url = GURL(url);
2002 if (inquiry_url.is_empty())
2003 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:252004
[email protected]155f35e2010-07-17 00:30:182005 ViewHostMsg_GetSearchProviderInstallState_Params install;
2006 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:252007 frame->url(),
[email protected]155f35e2010-07-17 00:30:182008 inquiry_url,
2009 &install));
2010 return install;
2011}
2012
[email protected]f103ab72009-09-02 17:10:592013void RenderView::OnMissingPluginStatus(
2014 WebPluginDelegateProxy* delegate,
2015 int status) {
[email protected]6c8afae52009-01-22 02:24:572016#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:592017 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:292018 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:502019 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:592020 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:292021 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2022 }
2023 } else {
2024 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2025 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:502026 if (status ==
2027 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:292028 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2029 }
2030 }
[email protected]6c8afae52009-01-22 02:24:572031#else
[email protected]76c3b312010-05-20 21:38:292032 // TODO(port): Implement the infobar that accompanies the default plugin.
2033 // Linux: http://crbug.com/10952
2034 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:572035 NOTIMPLEMENTED();
2036#endif
initial.commit09911bf2008-07-26 23:55:292037}
2038
[email protected]48c9cf2d2009-09-16 16:47:522039// WebKit::WebViewClient ------------------------------------------------------
2040
[email protected]844acf372011-01-14 10:49:272041// TODO(jochen): remove once WebKit side is up to date.
[email protected]8ab04652010-06-12 02:47:262042WebView* RenderView::createView(
2043 WebFrame* creator,
2044 const WebWindowFeatures& features,
2045 const WebString& frame_name) {
[email protected]844acf372011-01-14 10:49:272046 return createView(creator, WebURLRequest(), features, frame_name);
2047}
2048
2049WebView* RenderView::createView(
2050 WebFrame* creator,
2051 const WebURLRequest& request,
2052 const WebWindowFeatures& features,
2053 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522054 // Check to make sure we aren't overloading on popups.
2055 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2056 return NULL;
2057
2058 // This window can't be closed from a window.close() call until we receive a
2059 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402060 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522061
[email protected]8ab04652010-06-12 02:47:262062 ViewHostMsg_CreateWindow_Params params;
2063 params.opener_id = routing_id_;
2064 params.user_gesture = creator->isProcessingUserGesture();
2065 params.window_container_type = WindowFeaturesToContainerType(features);
2066 params.session_storage_namespace_id = session_storage_namespace_id_;
2067 params.frame_name = frame_name;
2068
[email protected]48c9cf2d2009-09-16 16:47:522069 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342070 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262071 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522072
[email protected]48c9cf2d2009-09-16 16:47:522073 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262074 new ViewHostMsg_CreateWindow(params,
2075 &routing_id,
2076 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212077 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522078 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522079
[email protected]48c9cf2d2009-09-16 16:47:522080 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73f2009-10-13 13:43:422081 0,
[email protected]12636df2009-09-28 22:32:212082 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522083 renderer_preferences_,
2084 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212085 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342086 routing_id,
[email protected]8ab04652010-06-12 02:47:262087 cloned_session_storage_namespace_id,
2088 frame_name);
2089 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522090
[email protected]007a848b2009-10-26 15:55:462091 // Record whether the creator frame is trying to suppress the opener field.
2092 view->opener_suppressed_ = opener_suppressed;
2093
[email protected]48c9cf2d2009-09-16 16:47:522094 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092095 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522096 if (!creator_url.is_valid() || !creator_url.IsStandard())
2097 creator_url = GURL();
2098 view->creator_url_ = creator_url;
2099
2100 // Copy over the alternate error page URL so we can have alt error pages in
2101 // the new render view (we don't need the browser to send the URL back down).
2102 view->alternate_error_page_url_ = alternate_error_page_url_;
2103
2104 return view->webview();
2105}
2106
[email protected]3e2b375b2010-04-07 17:03:122107WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522108 RenderWidget* widget = RenderWidget::Create(routing_id_,
2109 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122110 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522111 return widget->webwidget();
2112}
2113
2114WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442115 // TODO(jcivelli): Remove this deprecated method when its been removed from
2116 // the WebViewClient interface. It's been replaced by
2117 // createExternalPopupMenu.
2118 NOTREACHED();
2119 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522120}
2121
[email protected]caf706f2010-10-26 17:54:082122WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2123 const WebPopupMenuInfo& popup_menu_info,
2124 WebExternalPopupMenuClient* popup_menu_client) {
2125 DCHECK(!external_popup_menu_.get());
2126 external_popup_menu_.reset(
2127 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2128 return external_popup_menu_.get();
2129}
2130
[email protected]484955942010-08-19 16:13:182131WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
2132 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
2133 render_thread_,
2134 popup_type);
2135 return widget->webwidget();
2136}
2137
[email protected]0bd753682010-12-16 18:15:522138webkit::ppapi::FullscreenContainer*
2139RenderView::CreatePepperFullscreenContainer(
2140 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392141 RenderWidgetFullscreenPepper* widget =
2142 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2143 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562144 return widget;
[email protected]79c7bed2010-09-14 22:28:392145}
2146
[email protected]68c50e52010-05-12 11:14:392147WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342148 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392149 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292150 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2151 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2152 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342153}
2154
[email protected]48c9cf2d2009-09-16 16:47:522155void RenderView::didAddMessageToConsole(
2156 const WebConsoleMessage& message, const WebString& source_name,
2157 unsigned source_line) {
2158 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2159 UTF16ToWideHack(message.text),
2160 static_cast<int32>(source_line),
2161 UTF16ToWideHack(source_name)));
2162}
2163
2164void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:582165 DCHECK(frame);
[email protected]212a49d2010-10-25 18:23:472166 if (CommandLine::ForCurrentProcess()->HasSwitch(
2167 switches::kEnablePrintPreview)) {
2168 Print(frame, true, true);
2169 } else {
2170 Print(frame, true, false);
2171 }
[email protected]48c9cf2d2009-09-16 16:47:522172}
2173
[email protected]3354d3e2010-06-10 19:53:022174WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512175 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022176}
2177
[email protected]48c9cf2d2009-09-16 16:47:522178void RenderView::didStartLoading() {
2179 if (is_loading_) {
2180 DLOG(WARNING) << "didStartLoading called while loading";
2181 return;
2182 }
2183
2184 is_loading_ = true;
2185 // Clear the pointer so that we can assign it only when there is an unknown
2186 // plugin on a page.
2187 first_default_plugin_.reset();
2188
2189 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2190}
2191
2192void RenderView::didStopLoading() {
2193 if (!is_loading_) {
2194 DLOG(WARNING) << "DidStopLoading called while not loading";
2195 return;
2196 }
2197
2198 is_loading_ = false;
2199
2200 // NOTE: For now we're doing the safest thing, and sending out notification
2201 // when done loading. This currently isn't an issue as the favicon is only
2202 // displayed when done loading. Ideally we would send notification when
2203 // finished parsing the head, but webkit doesn't support that yet.
2204 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272205 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522206 if (!favicon_url.is_empty())
2207 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
2208
[email protected]26aa0482009-09-30 16:55:272209 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202210 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522211
2212 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2213
[email protected]90109412010-12-15 17:14:242214 if (load_progress_tracker_ != NULL)
2215 load_progress_tracker_->DidStopLoading();
2216
[email protected]f9f4841b2010-03-20 05:41:422217 MessageLoop::current()->PostDelayedTask(
2218 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302219 page_info_method_factory_.NewRunnableMethod(
2220 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372221 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522222}
2223
[email protected]90109412010-12-15 17:14:242224void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2225 if (load_progress_tracker_ != NULL)
2226 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2227}
2228
[email protected]f55039a2010-02-17 14:12:062229bool RenderView::isSmartInsertDeleteEnabled() {
2230#if defined(OS_MACOSX)
2231 return true;
2232#else
2233 return false;
2234#endif
2235}
2236
[email protected]04fc9482009-09-18 22:13:032237bool RenderView::isSelectTrailingWhitespaceEnabled() {
2238#if defined(OS_WIN)
2239 return true;
2240#else
2241 return false;
2242#endif
2243}
2244
[email protected]04fc9482009-09-18 22:13:032245void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422246#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032247 if (!handling_input_event_)
2248 return;
2249 // TODO(estade): investigate incremental updates to the selection so that we
2250 // don't send the entire selection over IPC every time.
2251 if (!is_empty_selection) {
2252 // Sometimes we get repeated didChangeSelection calls from webkit when
2253 // the selection hasn't actually changed. We don't want to report these
2254 // because it will cause us to continually claim the X clipboard.
2255 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272256 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032257 if (this_selection == last_selection_)
2258 return;
2259
2260 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2261 this_selection));
2262 last_selection_ = this_selection;
2263 } else {
2264 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162265 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2266 last_selection_));
[email protected]04fc9482009-09-18 22:13:032267 }
[email protected]0ff0ff32010-12-21 19:34:422268#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032269}
2270
2271void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122272 const std::string& name = UTF16ToUTF8(command_name);
2273 if (StartsWithASCII(name, "Move", true) ||
2274 StartsWithASCII(name, "Insert", true) ||
2275 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032276 return;
2277 UserMetricsRecordAction(name);
2278}
2279
[email protected]54ec7f82010-10-21 22:32:512280void RenderView::SendPendingAccessibilityNotifications() {
2281 if (!accessibility_.get())
2282 return;
2283
2284 if (pending_accessibility_notifications_.empty())
2285 return;
2286
2287 // Send all pending accessibility notifications.
2288 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2289 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2290 RendererAccessibilityNotification& notification =
2291 pending_accessibility_notifications_[i];
2292 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2293 if (!obj.isValid())
2294 continue;
2295
2296 ViewHostMsg_AccessibilityNotification_Params param;
2297 param.notification_type = pending_accessibility_notifications_[i].type;
[email protected]70eee342010-11-05 01:59:372298 param.acc_obj = WebAccessibility(
2299 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512300 notifications.push_back(param);
2301 }
2302 pending_accessibility_notifications_.clear();
2303 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2304 accessibility_ack_pending_ = true;
2305}
2306
[email protected]b2528b72009-09-24 06:57:102307bool RenderView::handleCurrentKeyboardEvent() {
2308 if (edit_commands_.empty())
2309 return false;
2310
[email protected]26aa0482009-09-30 16:55:272311 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102312 if (!frame)
2313 return false;
2314
2315 EditCommands::iterator it = edit_commands_.begin();
2316 EditCommands::iterator end = edit_commands_.end();
2317
[email protected]507b33ea2009-09-29 03:56:512318 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102319 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332320 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2321 // key (but it's the exception). Once one edit command is not executed, it
2322 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102323 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2324 WebString::fromUTF8(it->value)))
2325 break;
[email protected]507b33ea2009-09-29 03:56:512326 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102327 }
2328
[email protected]507b33ea2009-09-29 03:56:512329 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102330}
2331
[email protected]2a3a7762009-10-19 19:17:322332void RenderView::spellCheck(const WebString& text,
2333 int& misspelled_offset,
2334 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562335 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462336
[email protected]85c55dc2009-11-06 03:05:462337 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172338 RenderThread* thread = RenderThread::current();
2339 // Will be NULL during unit tests.
2340 if (thread) {
[email protected]c27324b2009-11-19 22:44:292341 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172342 word.c_str(), word.size(), document_tag_,
2343 &misspelled_offset, &misspelled_length, NULL);
2344 }
[email protected]1dbafaf72009-09-23 19:43:562345}
2346
2347WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322348 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562349 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262350 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562351 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172352 RenderThread* thread = RenderThread::current();
2353 // Will be NULL during unit tests.
2354 if (thread) {
2355 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292356 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172357 word, document_tag_);
2358 }
[email protected]1dbafaf72009-09-23 19:43:562359 }
[email protected]2a3a7762009-10-19 19:17:322360 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562361}
2362
[email protected]c49085c72009-10-02 16:28:562363void RenderView::showSpellingUI(bool show) {
2364 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2365}
2366
[email protected]8922e1f2009-10-03 05:01:262367bool RenderView::isShowingSpellingUI() {
2368 return spelling_panel_visible_;
2369}
2370
[email protected]1dbafaf72009-09-23 19:43:562371void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322372 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2373 word));
[email protected]1dbafaf72009-09-23 19:43:562374}
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) {
2399 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
2400 UTF16ToWideHack(message),
2401 std::wstring(),
2402 frame->url(),
2403 NULL);
2404}
2405
2406bool RenderView::runModalConfirmDialog(
2407 WebFrame* frame, const WebString& message) {
2408 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
2409 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;
2419 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
2420 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]6a8b86c2010-12-09 05:24:302443 custom_menu_listener_ = NULL;
[email protected]c27324b2009-11-19 22:44:292444 ContextMenuParams params = ContextMenuParams(data);
2445 if (!params.misspelled_word.empty() && RenderThread::current()) {
2446 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042447 bool spelled_right = RenderThread::current()->spellchecker()->
2448 SpellCheckWord(
2449 params.misspelled_word.c_str(), params.misspelled_word.size(),
2450 document_tag_,
2451 &misspelled_offset, &misspelled_length,
2452 &params.dictionary_suggestions);
2453 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292454 params.misspelled_word.clear();
2455 }
[email protected]216932c2010-08-26 21:44:272456 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2457 // it. We replace it with an empty GURL so the appropriate items are disabled
2458 // in the context menu.
2459 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2460 // data encoded images. We should have a way to save them.
2461 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2462 params.src_url = GURL();
[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]882daa92009-11-05 16:31:312502void RenderView::StartNavStateSyncTimerIfNecessary() {
2503 int delay;
2504 if (send_content_state_immediately_)
2505 delay = 0;
2506 else if (is_hidden())
2507 delay = kDelaySecondsForContentStateSyncHidden;
2508 else
2509 delay = kDelaySecondsForContentStateSync;
2510
2511 if (nav_state_sync_timer_.IsRunning()) {
2512 // The timer is already running. If the delay of the timer maches the amount
2513 // we want to delay by, then return. Otherwise stop the timer so that it
2514 // gets started with the right delay.
2515 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2516 return;
2517 nav_state_sync_timer_.Stop();
2518 }
2519
2520 nav_state_sync_timer_.Start(
2521 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2522}
2523
[email protected]163f8242009-10-30 20:19:552524void RenderView::setMouseOverURL(const WebURL& url) {
2525 mouse_over_url_ = GURL(url);
2526 UpdateTargetURL(mouse_over_url_, focus_url_);
2527}
2528
2529void RenderView::setKeyboardFocusURL(const WebURL& url) {
2530 focus_url_ = GURL(url);
2531 UpdateTargetURL(focus_url_, mouse_over_url_);
2532}
2533
[email protected]48c9cf2d2009-09-16 16:47:522534void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2535 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2536 hint));
2537}
2538
[email protected]c27ae592010-03-18 15:24:412539void RenderView::startDragging(const WebDragData& data,
2540 WebDragOperationsMask mask,
2541 const WebImage& image,
2542 const WebPoint& imageOffset) {
2543#if WEBKIT_USING_SKIA
2544 SkBitmap bitmap(image.getSkBitmap());
2545#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332546 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412547#endif
2548
[email protected]48c9cf2d2009-09-16 16:47:522549 Send(new ViewHostMsg_StartDragging(routing_id_,
2550 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412551 mask,
2552 bitmap,
2553 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522554}
2555
[email protected]28b92df2009-09-25 17:35:452556bool RenderView::acceptsLoadDrops() {
2557 return renderer_preferences_.can_accept_load_drops;
2558}
2559
[email protected]48c9cf2d2009-09-16 16:47:522560void RenderView::focusNext() {
2561 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2562}
2563
2564void RenderView::focusPrevious() {
2565 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2566}
2567
[email protected]08e9e132010-06-01 16:58:492568void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512569 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072570
2571 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2572 // TODO(ctguil): Make WebKit send this notification.
2573 // When focus is cleared notify accessibility that the document is focused.
2574 postAccessibilityNotification(
2575 webview()->accessibilityObject(),
2576 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2577 }
[email protected]08e9e132010-06-01 16:58:492578}
2579
[email protected]48c9cf2d2009-09-16 16:47:522580void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522581 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2582}
2583
2584int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002585 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522586}
2587
2588int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002589 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522590}
2591
[email protected]c4e98902010-06-01 10:20:142592void RenderView::didUpdateInspectorSetting(const WebString& key,
2593 const WebString& value) {
2594 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2595 key.utf8(),
2596 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262597}
2598
[email protected]79dbc662009-09-04 05:42:512599// WebKit::WebWidgetClient ----------------------------------------------------
2600
[email protected]ea42e7782010-08-23 23:58:122601void RenderView::didFocus() {
2602 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2603 // we won't have to test for user gesture anymore and we can
2604 // move that code back to render_widget.cc
2605 if (webview() && webview()->mainFrame() &&
2606 webview()->mainFrame()->isProcessingUserGesture()) {
2607 Send(new ViewHostMsg_Focus(routing_id_));
2608 }
2609}
2610
2611void RenderView::didBlur() {
2612 // TODO(jcivelli): see TODO above in didFocus().
2613 if (webview() && webview()->mainFrame() &&
2614 webview()->mainFrame()->isProcessingUserGesture()) {
2615 Send(new ViewHostMsg_Blur(routing_id_));
2616 }
2617}
2618
initial.commit09911bf2008-07-26 23:55:292619// We are supposed to get a single call to Show for a newly created RenderView
2620// that was created via RenderView::CreateWebView. So, we wait until this
2621// point to dispatch the ShowView message.
2622//
2623// This method provides us with the information about how to display the newly
2624// created RenderView (i.e., as a constrained popup or as a new tab).
2625//
[email protected]4873c7d2009-07-16 06:36:282626void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292627 DCHECK(!did_show_) << "received extraneous Show call";
2628 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2629
2630 if (did_show_)
2631 return;
2632 did_show_ = true;
2633
[email protected]4026ce1e2010-09-14 19:35:042634 // Extensions and apps always allowed to create unrequested popups. The second
2635 // check is necessary to include content scripts.
2636 if (ExtensionRendererInfo::GetByURL(creator_url_) ||
2637 bindings_utils::GetInfoForCurrentContext()) {
2638 opened_by_user_gesture_ = true;
2639 }
2640
[email protected]28295ec2009-10-16 05:34:332641 // Force new windows to a popup if they were not opened with a user gesture.
2642 if (!opened_by_user_gesture_) {
2643 // We exempt background tabs for compat with older versions of Chrome.
2644 // TODO(darin): This seems bogus. These should have a user gesture, so
2645 // we probably don't need this check.
2646 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2647 policy = WebKit::WebNavigationPolicyNewPopup;
2648 }
2649
initial.commit09911bf2008-07-26 23:55:292650 // NOTE: initial_pos_ may still have its default values at this point, but
2651 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2652 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282653 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2654 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292655 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242656 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292657}
2658
[email protected]4873c7d2009-07-16 06:36:282659void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132660 // Cancel pending translations so that the translate_helper_ does not attempt
2661 // to access the WebView.
2662 translate_helper_.CancelPendingTranslation();
2663
[email protected]3ead1322010-11-19 20:01:002664 // Same for the phishing classifier.
2665 if (phishing_delegate_.get())
2666 phishing_delegate_->CancelPendingClassification();
2667
[email protected]e8345242010-05-06 03:00:402668 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282669 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312670}
2671
[email protected]4873c7d2009-07-16 06:36:282672void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292673 DCHECK(did_show_) << "should already have shown the view";
2674
[email protected]c1f50aa2010-02-18 03:46:572675 // We must keep WebKit's shared timer running in this case in order to allow
2676 // showModalDialog to function properly.
2677 //
2678 // TODO(darin): WebKit should really be smarter about suppressing events and
2679 // timers so that we do not need to manage the shared timer in such a heavy
2680 // handed manner.
2681 //
2682 if (RenderThread::current()) // Will be NULL during unit tests.
2683 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2684
[email protected]12636df2009-09-28 22:32:212685 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292686}
2687
[email protected]3d9689372009-09-10 04:29:172688// WebKit::WebFrameClient -----------------------------------------------------
2689
[email protected]00152e92010-07-19 11:47:402690WebPlugin* RenderView::createPlugin(WebFrame* frame,
2691 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262692 bool found = false;
[email protected]414508d2010-11-02 10:45:392693 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282694 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502695 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242696 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262697 std::string actual_mime_type;
2698 Send(new ViewHostMsg_GetPluginInfo(url,
2699 frame->top()->url(),
2700 params.mimeType.utf8(),
2701 &found,
2702 &info,
[email protected]44fda5c2010-11-02 10:50:542703 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262704 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242705
[email protected]6fdd4182010-10-14 23:59:262706 if (!found)
[email protected]0cdafff2010-07-26 09:54:372707 return NULL;
[email protected]414508d2010-11-02 10:45:392708 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]4e0616e2010-05-28 14:55:532709
[email protected]191eb3f72010-12-21 06:27:502710 const webkit::npapi::PluginGroup* group =
2711 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412712 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292713
[email protected]6e74a3b2010-12-21 22:27:542714 if (group->IsVulnerable() &&
2715 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
[email protected]3c2826852010-12-16 19:09:142716 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2717 group->GetGroupName(),
2718 GURL(group->GetUpdateURL())));
2719 return CreatePluginPlaceholder(frame,
2720 params,
2721 *group,
[email protected]2e34ab3f2010-12-17 05:47:372722 IDR_BLOCKED_PLUGIN_HTML,
[email protected]3c2826852010-12-16 19:09:142723 IDS_PLUGIN_OUTDATED);
[email protected]851b1eb2010-08-09 13:32:292724 }
[email protected]6e74a3b2010-12-21 22:27:542725
[email protected]3c2826852010-12-16 19:09:142726 if (!info.enabled)
2727 return NULL;
[email protected]851b1eb2010-08-09 13:32:292728
[email protected]414508d2010-11-02 10:45:392729 ContentSetting host_setting =
2730 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]191eb3f72010-12-21 06:27:502731 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392732 plugin_setting == CONTENT_SETTING_ALLOW ||
2733 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]0bd753682010-12-16 18:15:522734 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452735 pepper_delegate_.CreatePepperPlugin(info.path));
2736 if (pepper_module)
2737 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262738 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372739 }
[email protected]fc61e222010-10-11 15:42:142740 std::string resource;
2741 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2742 resource = group->identifier();
2743 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392744 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142745 return CreatePluginPlaceholder(frame,
2746 params,
2747 *group,
[email protected]2e34ab3f2010-12-17 05:47:372748 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]3c2826852010-12-16 19:09:142749 IDS_PLUGIN_LOAD);
[email protected]fc61e222010-10-11 15:42:142750 } else {
[email protected]3c2826852010-12-16 19:09:142751 return CreatePluginPlaceholder(frame,
2752 params,
2753 *group,
[email protected]2e34ab3f2010-12-17 05:47:372754 IDR_BLOCKED_PLUGIN_HTML,
[email protected]3c2826852010-12-16 19:09:142755 IDS_PLUGIN_BLOCKED);
[email protected]fc61e222010-10-11 15:42:142756 }
[email protected]3d9689372009-09-10 04:29:172757}
2758
2759WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562760 WebApplicationCacheHostImpl* appcache_host =
2761 WebApplicationCacheHostImpl::FromFrame(frame);
2762 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2763 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2764 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172765}
2766
[email protected]9c00f002009-11-05 22:37:422767WebSharedWorker* RenderView::createSharedWorker(
2768 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372769 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422770
[email protected]30447b62009-11-13 01:13:372771 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512772 bool exists = false;
[email protected]30447b62009-11-13 01:13:372773 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512774 ViewHostMsg_CreateWorker_Params params;
2775 params.url = url;
2776 params.is_shared = true;
2777 params.name = name;
2778 params.document_id = document_id;
2779 params.render_view_route_id = routing_id_;
2780 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232781 params.parent_appcache_host_id = 0;
2782 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372783 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512784 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372785 if (url_mismatch) {
2786 return NULL;
2787 } else {
2788 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492789 document_id,
[email protected]6de0bcf2010-02-17 22:00:512790 exists,
[email protected]30447b62009-11-13 01:13:372791 route_id,
2792 routing_id_);
2793 }
[email protected]9c00f002009-11-05 22:37:422794}
2795
[email protected]3d9689372009-09-10 04:29:172796WebMediaPlayer* RenderView::createMediaPlayer(
2797 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f8db8132010-12-03 00:27:492798 scoped_ptr<media::FilterCollection> collection(
2799 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372800
[email protected]3d9689372009-09-10 04:29:172801 // Add in any custom filter factories first.
2802 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2803 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2804 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492805 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172806 }
2807
[email protected]3bb08602010-10-07 21:47:172808 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122809 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072810 WebGraphicsContext3DCommandBufferImpl* context =
2811 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2812 frame->view()->graphicsContext3D());
2813 if (!context)
2814 return NULL;
[email protected]a9a43012010-11-05 01:54:062815
[email protected]5aa6a312010-11-06 00:00:072816 // Add the hardware video decoder factory.
2817 // TODO(hclam): This will cause the renderer process to crash on context
2818 // lost.
2819 bool ret = context->makeContextCurrent();
2820 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492821 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072822 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172823 }
2824
[email protected]457d8342010-10-23 01:20:372825 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312826 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2827 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2828 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492829 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312830 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112831
[email protected]a8e24d522010-12-01 07:13:582832 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
2833 new webkit_glue::WebMediaPlayerImpl(client, collection.release()));
[email protected]79684282010-12-06 21:15:462834 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582835 cmd_line->HasSwitch(switches::kSimpleDataSource),
2836 video_renderer)) {
2837 return NULL;
2838 }
2839 return result.release();
[email protected]3d9689372009-09-10 04:29:172840}
2841
[email protected]035545f2010-04-09 13:10:212842WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2843 WebFrame* frame, WebApplicationCacheHostClient* client) {
2844 return new RendererWebApplicationCacheHostImpl(
2845 FromWebView(frame->view()), client,
2846 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2847}
2848
[email protected]8ff181072010-11-29 17:09:382849WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2850 return &cookie_jar_;
2851}
2852
[email protected]5041f982010-08-11 21:40:452853void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512854 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452855}
2856
[email protected]3d9689372009-09-10 04:29:172857void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302858 WebDataSource* ds = frame->dataSource();
2859 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522860
[email protected]a5a65ac2010-11-05 18:14:362861 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302862 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182863
[email protected]676126f72011-01-15 00:03:512864 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172865}
2866
[email protected]684e4a42010-01-30 06:44:112867bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402868 if (enabled_per_settings &&
2869 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2870 return true;
2871
2872 if (IsWhitelistedForContentSettings(frame))
2873 return true;
2874
[email protected]55126132010-08-19 14:53:282875 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402876 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112877}
2878
[email protected]d5f9e4f2010-07-28 08:31:302879bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162880 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302881}
2882
2883
[email protected]3d9689372009-09-10 04:29:172884void RenderView::loadURLExternally(
2885 WebFrame* frame, const WebURLRequest& request,
2886 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592887 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2888 if (policy == WebKit::WebNavigationPolicyDownload) {
2889 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2890 } else {
2891 OpenURL(request.url(), referrer, policy);
2892 }
[email protected]3d9689372009-09-10 04:29:172893}
2894
2895WebNavigationPolicy RenderView::decidePolicyForNavigation(
2896 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222897 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172898 // Webkit is asking whether to navigate to a new URL.
2899 // This is fine normally, except if we're showing UI from one security
2900 // context and they're trying to navigate to a different context.
2901 const GURL& url = request.url();
2902
2903 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302904 // navigations.
[email protected]8079b362010-05-07 18:37:452905 if (renderer_preferences_.browser_handles_top_level_requests &&
2906 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192907 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232908 // Reset these counters as the RenderView could be reused for the next
2909 // navigation.
2910 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232911 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192912 OpenURL(url, referrer, default_policy);
2913 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172914 }
2915
2916 // A content initiated navigation may have originated from a link-click,
2917 // script, drag-n-drop operation, etc.
2918 bool is_content_initiated =
2919 NavigationState::FromDataSource(frame->provisionalDataSource())->
2920 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582921 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172922
[email protected]6101c342010-12-16 22:44:372923 // Detect when we're crossing a permission-based boundary (e.g. into or out of
2924 // an extension or app origin, leaving a DOMUI page, etc). We only care about
2925 // top-level navigations withing the current tab (as opposed to, for example,
2926 // opening a new window). But we sometimes navigate to about:blank to clear a
2927 // tab, and we want to still allow that.
2928 //
2929 // Note: we do this only for GET requests because we our mechanism for
2930 // switching processes only issues GET requests. In particular, POST
2931 // requests don't work, because this mechanism does not preserve form POST
2932 // data. If it becomes necessary to support process switching for POST
2933 // requests, we will need to send the request's httpBody data up to the
2934 // browser process, and issue a special POST navigation in WebKit (via
2935 // FrameLoader::loadFrameRequest). See ResourceDispatcher and
2936 // WebURLLoaderImpl for examples of how to send the httpBody data.
2937 if (!frame->parent() && is_content_initiated &&
2938 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2939 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2940 bool send_referrer = false;
2941 bool should_fork =
2942 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172943 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372944 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112945
2946 // If the navigation would cross an app extent boundary, we also need
2947 // to defer to the browser to ensure process isolation.
2948 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2949 // which means that things like the back button won't trigger it. Is that
2950 // OK?
[email protected]08e94b82010-12-15 22:51:042951 // TODO(creis): For now, we only swap processes to enter an app and not
2952 // exit it, since we currently lose context (e.g., window.opener) if the
2953 // window navigates back. See crbug.com/65953.
[email protected]6101c342010-12-16 22:44:372954 if (!should_fork && CrossesIntoExtensionExtent(frame, url)) {
[email protected]5351dbc2010-08-27 15:22:112955 // Include the referrer in this case since we're going from a hosted web
2956 // page. (the packaged case is handled previously by the extension
2957 // navigation test)
[email protected]6101c342010-12-16 22:44:372958 should_fork = true;
2959 send_referrer = true;
2960 }
2961
2962 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112963 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372964 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112965 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2966 }
[email protected]3d9689372009-09-10 04:29:172967 }
2968
2969 // Detect when a page is "forking" a new tab that can be safely rendered in
2970 // its own process. This is done by sites like Gmail that try to open links
2971 // in new windows without script connections back to the original page. We
2972 // treat such cases as browser navigations (in which we will create a new
2973 // renderer for a cross-site navigation), rather than WebKit navigations.
2974 //
2975 // We use the following heuristic to decide whether to fork a new page in its
2976 // own process:
2977 // The parent page must open a new tab to about:blank, set the new tab's
2978 // window.opener to null, and then redirect the tab to a cross-site URL using
2979 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462980 //
2981 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2982 // (see below).
[email protected]3d9689372009-09-10 04:29:172983 bool is_fork =
2984 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582985 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172986 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522987 historyBackListCount() < 1 &&
2988 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172989 // The parent page must have set the child's window.opener to null before
2990 // redirecting to the desired URL.
2991 frame->opener() == NULL &&
2992 // Must be a top-level frame.
2993 frame->parent() == NULL &&
2994 // Must not have issued the request from this page.
2995 is_content_initiated &&
2996 // Must be targeted at the current tab.
2997 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2998 // Must be a JavaScript navigation, which appears as "other".
2999 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463000
3001 // Recognize if this navigation is from a link with rel=noreferrer and
3002 // target=_blank attributes, in which case the opener will be suppressed. If
3003 // so, it is safe to load cross-site pages in a separate process, so we
3004 // should let the browser handle it.
3005 bool is_noreferrer_and_blank_target =
3006 // Frame should be top level and not yet navigated.
3007 frame->parent() == NULL &&
3008 frame->url().isEmpty() &&
3009 historyBackListCount() < 1 &&
3010 historyForwardListCount() < 1 &&
3011 // Links with rel=noreferrer will have no Referer field, and their
3012 // resulting frame will have its window.opener suppressed.
3013 // TODO(creis): should add a request.httpReferrer() method to help avoid
3014 // typos on the unusual spelling of Referer.
3015 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3016 opener_suppressed_ &&
3017 frame->opener() == NULL &&
3018 // Links with target=_blank will have no name.
3019 frame->name().isNull() &&
3020 // Another frame (with a non-empty creator) should have initiated the
3021 // request, targeted at this frame.
3022 !creator_url_.is_empty() &&
3023 is_content_initiated &&
3024 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3025 type == WebKit::WebNavigationTypeOther;
3026
3027 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173028 // Open the URL via the browser, not via WebKit.
3029 OpenURL(url, GURL(), default_policy);
3030 return WebKit::WebNavigationPolicyIgnore;
3031 }
3032
3033 return default_policy;
3034}
3035
[email protected]6069da8c2009-10-20 20:33:493036bool RenderView::canHandleRequest(
3037 WebFrame* frame, const WebURLRequest& request) {
3038 // We allow WebKit to think that everything can be handled even though
3039 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343040 return true;
3041}
3042
[email protected]6069da8c2009-10-20 20:33:493043WebURLError RenderView::cannotHandleRequestError(
3044 WebFrame* frame, const WebURLRequest& request) {
3045 NOTREACHED(); // Since we said we can handle all requests.
3046 return WebURLError();
3047}
3048
3049WebURLError RenderView::cancelledError(
3050 WebFrame* frame, const WebURLRequest& request) {
3051 WebURLError error;
3052 error.domain = WebString::fromUTF8(net::kErrorDomain);
3053 error.reason = net::ERR_ABORTED;
3054 error.unreachableURL = request.url();
3055 return error;
[email protected]7b7a7dc2009-10-19 02:23:343056}
3057
3058void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493059 WebFrame*, const WebURLError&) {
3060 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343061}
3062
[email protected]90eeddb2010-05-06 21:06:433063void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3064 const WebKit::WebFormElement& form) {
3065 // Some login forms have onSubmit handlers that put a hash of the password
3066 // into a hidden field and then clear the password. (Issue 28910.)
3067 // This method gets called before any of those handlers run, so save away
3068 // a copy of the password in case it gets lost.
3069 NavigationState* navigation_state =
3070 NavigationState::FromDataSource(frame->dataSource());
3071 navigation_state->set_password_form_data(
3072 PasswordFormDomManager::CreatePasswordForm(form));
3073}
3074
[email protected]979c28b2009-11-07 01:30:483075void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173076 NavigationState* navigation_state =
3077 NavigationState::FromDataSource(frame->provisionalDataSource());
3078
3079 if (navigation_state->transition_type() == PageTransition::LINK)
3080 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3081
3082 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353083 WebSearchableFormData web_searchable_form_data(form);
3084 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3085 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213086 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433087 PasswordForm* password_form_data =
3088 PasswordFormDomManager::CreatePasswordForm(form);
3089 navigation_state->set_password_form_data(password_form_data);
3090
3091 // If the password has been cleared, recover it from the form contents already
3092 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3093 // opposed to the provisionalDataSource's, which is what we're storing into
3094 // now.)
3095 if (password_form_data && password_form_data->password_value.empty()) {
3096 NavigationState* old_navigation_state =
3097 NavigationState::FromDataSource(frame->dataSource());
3098 if (old_navigation_state) {
3099 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3100 if (old_form_data && old_form_data->action == password_form_data->action)
3101 password_form_data->password_value = old_form_data->password_value;
3102 }
3103 }
[email protected]3d9689372009-09-10 04:29:173104
[email protected]b1438212010-04-03 00:30:593105 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043106 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223107 form,
3108 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]18ecd002010-11-16 19:29:553109 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE |
3110 FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223111 &form_data)) {
[email protected]b1438212010-04-03 00:30:593112 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223113 }
[email protected]3d9689372009-09-10 04:29:173114}
3115
3116void RenderView::willPerformClientRedirect(
3117 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3118 double fire_time) {
3119 // Ignore
3120}
3121
3122void RenderView::didCancelClientRedirect(WebFrame* frame) {
3123 // Ignore
3124}
3125
3126void RenderView::didCompleteClientRedirect(
3127 WebFrame* frame, const WebURL& from) {
3128 if (!frame->parent())
3129 completed_client_redirect_src_ = from;
3130}
3131
3132void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233133 // If there are any app-related fetches in progress, they can be cancelled now
3134 // since we have navigated away from the page that created them.
3135 if (!frame->parent()) {
3136 app_icon_fetchers_.clear();
3137 app_definition_fetcher_.reset(NULL);
3138 }
3139
[email protected]3d9689372009-09-10 04:29:173140 // The rest of RenderView assumes that a WebDataSource will always have a
3141 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483142 bool content_initiated = !pending_navigation_state_.get();
3143 NavigationState* state = content_initiated ?
3144 NavigationState::CreateContentInitiated() :
3145 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513146
[email protected]8a3125a712010-08-09 18:58:513147 // NavigationState::referred_by_prefetcher_ is true if we are
3148 // navigating from a page that used prefetching using a link on that
3149 // page. We are early enough in the request process here that we
3150 // can still see the NavigationState of the previous page and set
3151 // this value appropriately.
3152 // TODO(gavinp): catch the important case of navigation in a new
3153 // renderer process.
3154 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303155 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523156 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513157 const GURL referrer(
3158 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3159 if (!referrer.is_empty() &&
3160 NavigationState::FromDataSource(
3161 old_frame->dataSource())->was_prefetcher()) {
3162 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3163 WebDataSource* old_frame_ds = old_frame->dataSource();
3164 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3165 state->set_was_referred_by_prefetcher(true);
3166 break;
3167 }
3168 }
3169 }
3170 }
3171 }
3172
[email protected]4c1b6f0b2010-02-07 16:38:183173 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523174 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513175 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183176 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3177 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3178 break;
3179 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3180 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3181 break;
3182 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3183 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3184 break;
3185 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3186 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3187 break;
3188 }
3189 }
[email protected]fa7b6b542009-11-03 05:02:303190
3191 state->set_user_script_idle_scheduler(
3192 new UserScriptIdleScheduler(this, frame));
3193 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173194}
3195
3196void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3197 WebDataSource* ds = frame->provisionalDataSource();
3198 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3199
[email protected]3d9689372009-09-10 04:29:173200 // Update the request time if WebKit has better knowledge of it.
3201 if (navigation_state->request_time().is_null()) {
3202 double event_time = ds->triggeringEventTime();
3203 if (event_time != 0.0)
3204 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3205 }
3206
[email protected]05c8e502010-08-15 15:13:523207 // Start time is only set after request time.
3208 navigation_state->set_start_load_time(Time::Now());
3209
[email protected]3d9689372009-09-10 04:29:173210 bool is_top_most = !frame->parent();
3211 if (is_top_most) {
3212 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133213 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173214
3215 // Make sure redirect tracking state is clear for the new load.
3216 completed_client_redirect_src_ = GURL();
3217 } else if (frame->parent()->isLoading()) {
3218 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003219 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173220 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3221 }
3222
3223 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073224 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173225}
3226
3227void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3228 if (frame->parent())
3229 return;
3230 // Received a redirect on the main frame.
3231 WebDataSource* data_source = frame->provisionalDataSource();
3232 if (!data_source) {
3233 // Should only be invoked when we have a data source.
3234 NOTREACHED();
3235 return;
3236 }
3237 std::vector<GURL> redirects;
3238 GetRedirectChain(data_source, &redirects);
3239 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513240 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3241 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173242 }
3243}
3244
[email protected]40bd6582009-12-04 23:49:513245void RenderView::didFailProvisionalLoad(WebFrame* frame,
3246 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173247 // Notify the browser that we failed a provisional load with an error.
3248 //
3249 // Note: It is important this notification occur before DidStopLoading so the
3250 // SSL manager can react to the provisional load failure before being
3251 // notified the load stopped.
3252 //
3253 WebDataSource* ds = frame->provisionalDataSource();
3254 DCHECK(ds);
3255
3256 const WebURLRequest& failed_request = ds->request();
3257
3258 bool show_repost_interstitial =
3259 (error.reason == net::ERR_CACHE_MISS &&
3260 EqualsASCII(failed_request.httpMethod(), "POST"));
3261 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073262 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3263 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173264
3265 // Don't display an error page if this is simply a cancelled load. Aside
3266 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3267 if (error.reason == net::ERR_ABORTED)
3268 return;
3269
3270 // Make sure we never show errors in view source mode.
3271 frame->enableViewSourceMode(false);
3272
3273 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3274
3275 // If this is a failed back/forward/reload navigation, then we need to do a
3276 // 'replace' load. This is necessary to avoid messing up session history.
3277 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3278 // as session history is concerned.
3279 //
3280 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3281 // the page id.
3282 //
3283 bool replace =
3284 navigation_state->pending_page_id() != -1 ||
3285 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3286
3287 // If we failed on a browser initiated request, then make sure that our error
3288 // page load is regarded as the same browser initiated request.
3289 if (!navigation_state->is_content_initiated()) {
3290 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3291 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003292 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173293 navigation_state->transition_type(),
3294 navigation_state->request_time()));
3295 }
3296
3297 // Provide the user with a more helpful error page?
3298 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3299 return;
3300
3301 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083302 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173303}
3304
3305void RenderView::didReceiveDocumentData(
3306 WebFrame* frame, const char* data, size_t data_len,
3307 bool& prevent_default) {
3308 NavigationState* navigation_state =
3309 NavigationState::FromDataSource(frame->dataSource());
3310 if (!navigation_state->postpone_loading_data())
3311 return;
3312
3313 // We're going to call commitDocumentData ourselves...
3314 prevent_default = true;
3315
[email protected]3f853a52010-09-13 19:15:083316 // Continue buffering the response data for the original error page. If it
3317 // grows too large, then we'll just let it through. For any error other than
3318 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173319 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083320 if (navigation_state->postponed_data().size() >= 512 ||
3321 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173322 navigation_state->set_postpone_loading_data(false);
3323 frame->commitDocumentData(navigation_state->postponed_data().data(),
3324 navigation_state->postponed_data().size());
3325 navigation_state->clear_postponed_data();
3326 }
3327}
3328
[email protected]40bd6582009-12-04 23:49:513329void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3330 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173331 NavigationState* navigation_state =
3332 NavigationState::FromDataSource(frame->dataSource());
3333
3334 navigation_state->set_commit_load_time(Time::Now());
3335 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203336 // When we perform a new navigation, we need to update the last committed
3337 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173338 UpdateSessionHistory(frame);
3339
3340 // We bump our Page ID to correspond with the new session history entry.
3341 page_id_ = next_page_id_++;
3342
[email protected]d64b07b2010-04-20 22:14:063343 // Any pending translation is now obsolete.
3344 translate_helper_.CancelPendingTranslation();
3345
[email protected]3ead1322010-11-19 20:01:003346 // Let the phishing classifier decide whether to cancel classification.
3347 if (phishing_delegate_.get())
3348 phishing_delegate_->CommittedLoadInFrame(frame);
3349
[email protected]3cc72b12010-03-18 23:03:003350 // Advance our offset in session history, applying the length limit. There
3351 // is now no forward history.
3352 history_list_offset_++;
3353 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3354 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3355 history_list_length_ = history_list_offset_ + 1;
3356
[email protected]f9f4841b2010-03-20 05:41:423357 MessageLoop::current()->PostDelayedTask(
3358 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303359 page_info_method_factory_.NewRunnableMethod(
3360 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173361 kDelayForForcedCaptureMs);
3362 } else {
3363 // Inspect the navigation_state on this frame to see if the navigation
3364 // corresponds to a session history navigation... Note: |frame| may or
3365 // may not be the toplevel frame, but for the case of capturing session
3366 // history, the first committed frame suffices. We keep track of whether
3367 // we've seen this commit before so that only capture session history once
3368 // per navigation.
3369 //
3370 // Note that we need to check if the page ID changed. In the case of a
3371 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3372 // previous URL and the current page ID, which would be wrong.
3373 if (navigation_state->pending_page_id() != -1 &&
3374 navigation_state->pending_page_id() != page_id_ &&
3375 !navigation_state->request_committed()) {
3376 // This is a successful session history navigation!
3377 UpdateSessionHistory(frame);
3378 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003379
3380 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173381 }
3382 }
3383
3384 // Remember that we've already processed this request, so we don't update
3385 // the session history again. We do this regardless of whether this is
3386 // a session history navigation, because if we attempted a session history
3387 // navigation without valid HistoryItem state, WebCore will think it is a
3388 // new navigation.
3389 navigation_state->set_request_committed(true);
3390
3391 UpdateURL(frame);
3392
3393 // If this committed load was initiated by a client redirect, we're
3394 // at the last stop now, so clear it.
3395 completed_client_redirect_src_ = GURL();
3396
3397 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273398 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173399}
3400
3401void RenderView::didClearWindowObject(WebFrame* frame) {
3402 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3403 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453404 GURL frame_url = frame->url();
3405 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253406 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]731ae512010-10-15 18:20:173407 frame_url.SchemeIs(chrome::kGearsScheme) ||
[email protected]bfa83eb82010-10-06 08:41:253408 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c091c2c2010-09-17 19:05:463409 GetDOMUIBindings()->set_message_sender(this);
3410 GetDOMUIBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253411 GetDOMUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173412 }
3413 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463414 GetExternalHostBindings()->set_message_sender(this);
3415 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253416 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173417 }
3418}
3419
3420void RenderView::didCreateDocumentElement(WebFrame* frame) {
3421 if (RenderThread::current()) { // Will be NULL during unit tests.
3422 RenderThread::current()->user_script_slave()->InjectScripts(
3423 frame, UserScript::DOCUMENT_START);
3424 }
3425
3426 // Notify the browser about non-blank documents loading in the top frame.
3427 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253428 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273429 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173430 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3431 }
3432}
3433
3434void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3435 UpdateTitle(frame, title);
3436
3437 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273438 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173439}
3440
[email protected]5019ef12010-04-27 17:26:583441void RenderView::didChangeIcons(WebFrame* frame) {
3442 if (!frame->parent()) {
3443 Send(new ViewHostMsg_UpdateFavIconURL(
3444 routing_id_,
3445 page_id_,
3446 frame->favIconURL()));
3447 }
3448}
3449
[email protected]3d9689372009-09-10 04:29:173450void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3451 WebDataSource* ds = frame->dataSource();
3452 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3453 DCHECK(navigation_state);
3454 navigation_state->set_finish_document_load_time(Time::Now());
3455
[email protected]622474d2010-11-04 09:21:083456 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173457
[email protected]676126f72011-01-15 00:03:513458 FOR_EACH_OBSERVER(
3459 RenderViewObserver, observers_, DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173460
3461 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273462 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173463
3464 if (RenderThread::current()) { // Will be NULL during unit tests.
3465 RenderThread::current()->user_script_slave()->InjectScripts(
3466 frame, UserScript::DOCUMENT_END);
3467 }
[email protected]fa7b6b542009-11-03 05:02:303468
[email protected]41f16632010-10-20 01:21:323469 // InjectScripts() can end up creating a new NavigationState if it triggers a
3470 // fragment navigation, so we need to re-fetch it here.
3471 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303472 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3473}
3474
3475void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3476 if (RenderThread::current()) { // Will be NULL during unit tests.
3477 RenderThread::current()->user_script_slave()->InjectScripts(
3478 frame, UserScript::DOCUMENT_IDLE);
3479 }
3480
3481 WebFrame* main_frame = webview()->mainFrame();
3482 if (frame == main_frame) {
3483 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203484 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303485 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203486 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303487 pending_code_execution_queue_.pop();
3488 }
3489 }
[email protected]3d9689372009-09-10 04:29:173490}
3491
3492void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083493 if (webview()->mainFrame() == frame) {
3494 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3495 page_id_));
3496 }
[email protected]3d9689372009-09-10 04:29:173497}
3498
3499void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3500 // Ignore
3501}
3502
3503void RenderView::didFinishLoad(WebFrame* frame) {
3504 WebDataSource* ds = frame->dataSource();
3505 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3506 DCHECK(navigation_state);
3507 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303508 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413509
[email protected]676126f72011-01-15 00:03:513510 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173511
3512 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173513}
3514
[email protected]ccbe04e2010-03-17 17:58:433515void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173516 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063517 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3518 // since a new one gets created by didCreateDataSource.
[email protected]af15bed2010-08-25 21:12:093519 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
[email protected]f6c2459d2010-02-24 22:34:063520 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3521
[email protected]3d9689372009-09-10 04:29:173522 // If this was a reference fragment navigation that we initiated, then we
3523 // could end up having a non-null pending navigation state. We just need to
3524 // update the ExtraData on the datasource so that others who read the
3525 // ExtraData will get the new NavigationState. Similarly, if we did not
3526 // initiate this navigation, then we need to take care to reset any pre-
3527 // existing navigation state to a content-initiated navigation state.
3528 // DidCreateDataSource conveniently takes care of this for us.
3529 didCreateDataSource(frame, frame->dataSource());
3530
[email protected]af15bed2010-08-25 21:12:093531 NavigationState* new_state =
3532 NavigationState::FromDataSource(frame->dataSource());
3533 new_state->set_was_within_same_page(true);
3534
[email protected]f6c2459d2010-02-24 22:34:063535 if (idle_scheduler_ran) {
3536 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
[email protected]f6c2459d2010-02-24 22:34:063537 new_state->user_script_idle_scheduler()->set_has_run(true);
3538 }
3539
[email protected]3d9689372009-09-10 04:29:173540 didCommitProvisionalLoad(frame, is_new_navigation);
3541
[email protected]26aa0482009-09-30 16:55:273542 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173543}
3544
[email protected]476b6f82009-09-10 21:00:593545void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313546 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593547}
3548
[email protected]3d9689372009-09-10 04:29:173549void RenderView::assignIdentifierToRequest(
3550 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3551 // Ignore
3552}
3553
3554void RenderView::willSendRequest(
3555 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3556 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303557 WebFrame* top_frame = frame->top();
3558 if (!top_frame)
3559 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513560 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3561 WebDataSource* top_data_source = top_frame->dataSource();
3562 WebDataSource* data_source =
3563 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303564 if (data_source) {
3565 NavigationState* state = NavigationState::FromDataSource(data_source);
3566 if (state && state->is_cache_policy_override_set())
3567 request.setCachePolicy(state->cache_policy_override());
3568 }
[email protected]8a3125a712010-08-09 18:58:513569
3570 if (top_data_source) {
3571 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3572 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3573 state->set_was_prefetcher(true);
3574 }
3575
[email protected]3d9689372009-09-10 04:29:173576 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133577 request.setHasUserGesture(frame->isProcessingUserGesture());
3578
[email protected]c5bbc2452010-03-08 08:33:503579 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133580 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493581
[email protected]85cc78c2010-05-04 18:30:093582 // Temporary metrics, see site_isolation_metrics.h
3583 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173584}
3585
3586void RenderView::didReceiveResponse(
3587 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493588
[email protected]85cc78c2010-05-04 18:30:093589 // Temporary metrics, see site_isolation_metrics.h
3590 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3591 identifier,
3592 response);
[email protected]fa0a3432010-03-30 16:53:493593
[email protected]3d9689372009-09-10 04:29:173594 // Only do this for responses that correspond to a provisional data source
3595 // of the top-most frame. If we have a provisional data source, then we
3596 // can't have any sub-resources yet, so we know that this response must
3597 // correspond to a frame load.
3598 if (!frame->provisionalDataSource() || frame->parent())
3599 return;
3600
3601 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083602 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173603 if (frame->isViewSourceModeEnabled())
3604 return;
3605
[email protected]65041fa2010-05-21 06:56:533606 NavigationState* navigation_state =
3607 NavigationState::FromDataSource(frame->provisionalDataSource());
3608 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083609 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533610
[email protected]972ebdff2010-06-10 22:59:073611 // Record page load flags.
3612 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3613 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573614 navigation_state->set_was_alternate_protocol_available(
3615 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073616 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083617 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533618
[email protected]f48013be2010-01-14 22:07:453619 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083620 if (http_status_code == 404) {
3621 // Can we even load an alternate error page for this URL?
3622 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3623 return;
3624 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3625 http_status_code)) {
3626 // If no corresponding error strings for a particular status code, just
3627 // render any received data, regardless of whether or not the status code
3628 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453629 return;
[email protected]3f853a52010-09-13 19:15:083630 }
[email protected]3d9689372009-09-10 04:29:173631
[email protected]3d9689372009-09-10 04:29:173632 navigation_state->set_postpone_loading_data(true);
3633 navigation_state->clear_postponed_data();
3634}
3635
3636void RenderView::didFinishResourceLoad(
3637 WebFrame* frame, unsigned identifier) {
3638 NavigationState* navigation_state =
3639 NavigationState::FromDataSource(frame->dataSource());
3640 if (!navigation_state->postpone_loading_data())
3641 return;
3642
[email protected]3f853a52010-09-13 19:15:083643 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173644 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083645 int http_status_code = navigation_state->http_status_code();
3646 if (http_status_code == 404) {
3647 // On 404s, try a remote search page as a fallback.
3648 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173649
[email protected]3f853a52010-09-13 19:15:083650 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3651 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173652
[email protected]3f853a52010-09-13 19:15:083653 WebURLError original_error;
3654 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173655
[email protected]3f853a52010-09-13 19:15:083656 navigation_state->set_alt_error_page_fetcher(
3657 new AltErrorPageResourceFetcher(
3658 error_page_url, frame, original_error,
3659 NewCallback(this, &RenderView::AltErrorPageFinished)));
3660 } else {
3661 // On other errors, use an internal error page.
3662 WebURLError error;
3663 error.unreachableURL = frame->url();
3664 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3665 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173666
[email protected]3f853a52010-09-13 19:15:083667 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3668 std::string(), true);
3669 }
[email protected]3d9689372009-09-10 04:29:173670}
3671
3672void RenderView::didFailResourceLoad(
3673 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3674 // Ignore
3675}
3676
3677void RenderView::didLoadResourceFromMemoryCache(
3678 WebFrame* frame, const WebURLRequest& request,
3679 const WebURLResponse& response) {
3680 // Let the browser know we loaded a resource from the memory cache. This
3681 // message is needed to display the correct SSL indicators.
3682 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3683 routing_id_,
3684 request.url(),
[email protected]91733b62009-09-18 06:21:093685 frame->securityOrigin().toString().utf8(),
3686 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173687 response.securityInfo()));
3688}
3689
[email protected]6069da8c2009-10-20 20:33:493690void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293691 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3692}
3693
3694void RenderView::didRunInsecureContent(
3695 WebFrame* frame, const WebSecurityOrigin& origin) {
3696 Send(new ViewHostMsg_DidRunInsecureContent(
3697 routing_id_,
3698 origin.toString().utf8()));
3699}
3700
[email protected]7ea093ba2009-11-03 05:54:593701bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403702 if (enabled_per_settings &&
3703 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3704 return true;
[email protected]7ea093ba2009-11-03 05:54:593705
[email protected]12bc8472010-04-15 07:29:403706 if (IsWhitelistedForContentSettings(frame))
3707 return true;
[email protected]7ea093ba2009-11-03 05:54:593708
3709 return false; // Other protocols fall through here.
3710}
3711
[email protected]0a1a45432010-03-31 08:09:453712bool RenderView::allowDatabase(
3713 WebFrame* frame, const WebString& name, const WebString& display_name,
3714 unsigned long estimated_size) {
3715 WebSecurityOrigin origin = frame->securityOrigin();
3716 if (origin.isEmpty())
3717 return false; // Uninitialized document?
3718
3719 bool result;
[email protected]26a9acf2010-12-13 19:35:053720 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453721 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3722 return false;
[email protected]9fb83e82010-07-02 18:24:553723 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3724 GURL(origin.toString().utf8()),
3725 name,
3726 display_name,
3727 estimated_size,
3728 !result));
[email protected]0a1a45432010-03-31 08:09:453729 return result;
3730}
[email protected]8934a3b2010-02-25 00:34:003731void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283732 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003733}
3734
[email protected]c21f1d52010-03-04 03:19:433735void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283736 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433737}
3738
[email protected]3d9689372009-09-10 04:29:173739void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3740 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3741}
3742
[email protected]0c882b282009-10-07 17:01:283743void RenderView::didCreateScriptContext(WebFrame* frame) {
3744 EventBindings::HandleContextCreated(frame, false);
3745}
3746
3747void RenderView::didDestroyScriptContext(WebFrame* frame) {
3748 EventBindings::HandleContextDestroyed(frame);
3749}
3750
3751void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3752 EventBindings::HandleContextCreated(frame, true);
3753}
3754
[email protected]af7eb3fb2010-09-23 21:31:063755bool RenderView::allowScriptExtension(WebFrame* frame,
3756 const WebString& extension_name,
3757 int extension_group) {
3758 // NULL in unit tests.
3759 if (!RenderThread::current())
3760 return true;
3761
3762 // Note: we prefer the provisional URL here instead of the document URL
3763 // because we might be currently loading an URL into a blank page.
3764 // See http://code.google.com/p/chromium/issues/detail?id=10924
3765 WebDataSource* ds = frame->provisionalDataSource();
3766 if (!ds)
3767 ds = frame->dataSource();
3768 return RenderThread::current()->AllowScriptExtension(
3769 extension_name.utf8(), ds->request().url(), extension_group);
3770}
3771
[email protected]fc86daa2010-03-30 23:52:533772void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3773 WebFrame* target,
3774 bool cross_origin,
3775 const WebString& property_name,
3776 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103777 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363778 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103779}
3780
[email protected]3d9689372009-09-10 04:29:173781void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143782 CheckPreferredSize();
3783}
3784
3785void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173786 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253787 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173788 // message.
[email protected]705243f2010-05-05 19:58:073789 if (!send_preferred_size_changes_ || !webview())
3790 return;
[email protected]dfca5acf2010-03-22 03:28:433791
[email protected]705243f2010-05-05 19:58:073792 // WebCore likes to tell us things have changed even when they haven't, so
3793 // cache the width and height and only send the IPC message when we're sure
3794 // they're different.
3795 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3796 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533797
3798 // In the presence of zoom, these sizes are still reported as if unzoomed,
3799 // so we need to adjust.
3800 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3801 size.set_width(static_cast<int>(size.width() * zoom_factor));
3802 size.set_height(static_cast<int>(size.height() * zoom_factor));
3803
[email protected]705243f2010-05-05 19:58:073804 if (size == preferred_size_)
3805 return;
[email protected]c27324b2009-11-19 22:44:293806
[email protected]705243f2010-05-05 19:58:073807 preferred_size_ = size;
3808 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3809 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173810}
3811
[email protected]143dcd592009-11-06 21:33:493812void RenderView::didChangeScrollOffset(WebFrame* frame) {
3813 StartNavStateSyncTimerIfNecessary();
3814}
3815
[email protected]8922e1f2009-10-03 05:01:263816void RenderView::reportFindInPageMatchCount(int request_id, int count,
3817 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113818 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3819 if (!count)
3820 active_match_ordinal = 0;
3821
3822 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3823 routing_id_,
3824 request_id,
3825 count,
3826 gfx::Rect(),
3827 active_match_ordinal,
3828 final_update);
3829
[email protected]8922e1f2009-10-03 05:01:263830 // If we have a message that has been queued up, then we should just replace
3831 // it. The ACK from the browser will make sure it gets sent when the browser
3832 // wants it.
3833 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263834 queued_find_reply_message_.reset(msg);
3835 } else {
3836 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113837 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263838 }
3839}
3840
3841void RenderView::reportFindInPageSelection(int request_id,
3842 int active_match_ordinal,
3843 const WebRect& selection_rect) {
3844 // Send the search result over to the browser process.
3845 Send(new ViewHostMsg_Find_Reply(routing_id_,
3846 request_id,
3847 -1,
3848 selection_rect,
3849 active_match_ordinal,
3850 false));
3851}
3852
[email protected]2b06a992010-08-21 05:48:223853void RenderView::openFileSystem(
3854 WebFrame* frame,
3855 WebFileSystem::Type type,
3856 long long size,
[email protected]d275d7a2010-11-03 01:34:493857 bool create,
[email protected]2b06a992010-08-21 05:48:223858 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083859 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223860
3861 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083862 if (origin.isEmpty()) {
3863 // Uninitialized document?
3864 callbacks->didFail(WebKit::WebFileErrorAbort);
3865 return;
3866 }
[email protected]2b06a992010-08-21 05:48:223867
[email protected]c5a272d2010-09-27 18:37:083868 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3869 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493870 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223871}
3872
[email protected]79dbc662009-09-04 05:42:513873// webkit_glue::WebPluginPageDelegate -----------------------------------------
3874
[email protected]191eb3f72010-12-21 06:27:503875webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533876 const FilePath& file_path,
3877 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593878 if (!PluginChannelHost::IsListening())
3879 return NULL;
3880
[email protected]d2139662009-12-10 03:21:143881 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283882 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143883 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163884 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533885 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143886 if (CommandLine::ForCurrentProcess()->
3887 HasSwitch(switches::kInternalPepper)) {
3888 in_process_plugin = true;
3889 use_pepper_host = true;
3890 } else {
3891 // In process Pepper plugins must be explicitly enabled.
3892 return NULL;
3893 }
[email protected]4e0616e2010-05-28 14:55:533894 } else {
3895 FilePath internal_pdf_path;
3896 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3897 if (file_path == internal_pdf_path) {
3898 in_process_plugin = true;
3899 use_pepper_host = true;
3900 }
[email protected]26e8d5e2009-10-13 02:47:163901 }
[email protected]4e0616e2010-05-28 14:55:533902
[email protected]d2139662009-12-10 03:21:143903 // Check for Native Client modules.
[email protected]5cad70a82010-09-03 22:14:113904 if (mime_type == "application/x-nacl-srpc" &&
3905 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
[email protected]8f05f7f2010-07-30 23:12:433906 // NaCl is only permitted when we're in an extension/application with the
3907 // appropriate permission, or when explicitly enabled on the command line.
3908
[email protected]8f05f7f2010-07-30 23:12:433909 GURL main_frame_url(webview()->mainFrame()->url());
[email protected]5351dbc2010-08-27 15:22:113910 ExtensionRendererInfo* extension =
3911 ExtensionRendererInfo::GetByURL(main_frame_url);
3912 bool in_ext = extension != NULL;
[email protected]8f05f7f2010-07-30 23:12:433913 bool explicit_enable =
3914 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3915
3916 if (in_ext) {
[email protected]5cad70a82010-09-03 22:14:113917 // TODO(cbiffle): NaCl is back to experimental for M7.
[email protected]5351dbc2010-08-27 15:22:113918 if (ExtensionProcessBindings::HasPermission(extension->id(),
[email protected]5cad70a82010-09-03 22:14:113919 Extension::kExperimentalPermission)) {
[email protected]8f05f7f2010-07-30 23:12:433920 in_process_plugin = true;
3921 use_pepper_host = true;
3922 } else {
3923 // Disable NaCl for apps lacking the permission, even with the flag.
3924 return NULL;
3925 }
3926 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463927 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143928 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463929 }
3930 }
[email protected]4e0616e2010-05-28 14:55:533931
[email protected]d032f492009-09-29 00:33:463932 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143933 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283934 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533935 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333936 if (!pepper_plugin)
3937 return NULL;
3938
[email protected]53900d52010-06-16 04:25:013939 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283940 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143941 } else {
[email protected]6876dff2010-01-15 19:38:093942#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]191eb3f72010-12-21 06:27:503943 return webkit::npapi::WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533944 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093945#else
[email protected]596b2c42010-01-14 20:40:433946 NOTIMPLEMENTED();
3947 return NULL;
[email protected]7b6616f2010-01-14 18:07:553948#endif
[email protected]6876dff2010-01-15 19:38:093949 }
[email protected]f103ab72009-09-02 17:10:593950 }
3951
[email protected]4e0616e2010-05-28 14:55:533952 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593953}
3954
3955void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033956#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593957 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3958 routing_id(), window));
3959#endif
3960}
3961
3962void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033963#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593964 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3965 routing_id(), window));
3966#endif
3967 CleanupWindowInPluginMoves(window);
3968}
3969
[email protected]191eb3f72010-12-21 06:27:503970void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593971 SchedulePluginMove(move);
3972}
3973
3974void RenderView::DidStartLoadingForPlugin() {
3975 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523976 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593977}
3978
3979void RenderView::DidStopLoadingForPlugin() {
3980 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523981 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593982}
3983
3984void RenderView::ShowModalHTMLDialogForPlugin(
3985 const GURL& url,
3986 const gfx::Size& size,
3987 const std::string& json_arguments,
3988 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213989 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593990 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213991 json_retval));
[email protected]f103ab72009-09-02 17:10:593992}
3993
[email protected]b921cfd22010-02-25 16:57:513994WebCookieJar* RenderView::GetCookieJar() {
3995 return &cookie_jar_;
3996}
3997
initial.commit09911bf2008-07-26 23:55:293998void RenderView::SyncNavigationState() {
3999 if (!webview())
4000 return;
4001
[email protected]26aa0482009-09-30 16:55:274002 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:174003 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:294004 return;
[email protected]ca948a22009-06-25 19:36:174005
4006 Send(new ViewHostMsg_UpdateState(
4007 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:294008}
4009
[email protected]b0950a72009-09-29 23:16:174010bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
4011 // Make sure webview was not shut down.
4012 if (!webview())
4013 return false;
4014 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:234015 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
4016 new ImageResourceFetcher(
4017 image_url, webview()->mainFrame(), id, image_size,
4018 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:174019 return true;
4020}
4021
4022void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294023 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174024 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:474025 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
4026 fetcher->id(),
4027 fetcher->image_url(),
4028 image.isNull(),
4029 image));
[email protected]bb461532010-11-26 21:50:234030
4031 // Remove the image fetcher from our pending list. We're in the callback from
4032 // ImageResourceFetcher, best to delay deletion.
4033 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4034 iter != image_fetchers_.end(); ++iter) {
4035 if (iter->get() == fetcher) {
4036 iter->release();
4037 image_fetchers_.erase(iter);
4038 break;
4039 }
4040 }
[email protected]b0950a72009-09-29 23:16:174041 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294042}
4043
[email protected]bf5c2ff392009-07-08 16:24:334044void RenderView::OnDownloadFavIcon(int id,
4045 const GURL& image_url,
4046 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344047 bool data_image_failed = false;
4048 if (image_url.SchemeIs("data")) {
4049 SkBitmap data_image = ImageFromDataUrl(image_url);
4050 data_image_failed = data_image.empty();
4051 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:334052 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
4053 data_image));
[email protected]f11ca0732009-04-11 00:09:344054 }
4055 }
4056
[email protected]bf5c2ff392009-07-08 16:24:334057 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174058 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:334059 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
4060 SkBitmap()));
4061 }
initial.commit09911bf2008-07-26 23:55:294062}
4063
[email protected]f11ca0732009-04-11 00:09:344064SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4065 std::string mime_type, char_set, data;
4066 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4067 // Decode the favicon using WebKit's image decoder.
4068 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
4069 const unsigned char* src_data =
4070 reinterpret_cast<const unsigned char*>(&data[0]);
4071
4072 return decoder.Decode(src_data, data.size());
4073 }
4074 return SkBitmap();
4075}
4076
initial.commit09911bf2008-07-26 23:55:294077void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444078 WebApplicationInfo app_info;
4079 if (page_id == page_id_) {
4080 string16 error;
4081 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4082 &error);
4083 }
initial.commit09911bf2008-07-26 23:55:294084
4085 // Prune out any data URLs in the set of icons. The browser process expects
4086 // any icon with a data URL to have originated from a favicon. We don't want
4087 // to decode arbitrary data URLs in the browser process. See
4088 // http://b/issue?id=1162972
4089 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594090 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294091 app_info.icons.erase(app_info.icons.begin() + i);
4092 --i;
4093 }
4094 }
4095
4096 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4097}
4098
[email protected]7ccddb8c2009-08-04 17:36:554099GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294100 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554101 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294102 // If the URL that failed was secure, then the embedding web page was not
4103 // expecting a network attacker to be able to manipulate its contents. As
4104 // we fetch alternate error pages over HTTP, we would be allowing a network
4105 // attacker to manipulate the contents of the response if we tried to use
4106 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154107 return GURL();
initial.commit09911bf2008-07-26 23:55:294108 }
4109
4110 // Grab the base URL from the browser process.
4111 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154112 return GURL();
initial.commit09911bf2008-07-26 23:55:294113
4114 // Strip query params from the failed URL.
4115 GURL::Replacements remove_params;
4116 remove_params.ClearUsername();
4117 remove_params.ClearPassword();
4118 remove_params.ClearQuery();
4119 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554120 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504121 std::string spec_to_send = url_to_send.spec();
4122 // Notify link doctor of the url truncation by sending of "?" at the end.
4123 if (failed_url.has_query())
4124 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294125
4126 // Construct the query params to send to link doctor.
4127 std::string params(alternate_error_page_url_.query());
4128 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504129 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294130 params.append("&sourceid=chrome");
4131 params.append("&error=");
4132 switch (error_type) {
4133 case DNS_ERROR:
4134 params.append("dnserror");
4135 break;
4136
4137 case HTTP_404:
4138 params.append("http404");
4139 break;
4140
[email protected]5df266ac2008-10-15 19:50:134141 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334142 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134143 break;
4144
initial.commit09911bf2008-07-26 23:55:294145 default:
4146 NOTREACHED() << "unknown ErrorPageType";
4147 }
4148
4149 // OK, build the final url to return.
4150 GURL::Replacements link_doctor_params;
4151 link_doctor_params.SetQueryStr(params);
4152 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4153 return url;
4154}
4155
[email protected]c091c2c2010-09-17 19:05:464156DOMUIBindings* RenderView::GetDOMUIBindings() {
4157 if (!dom_ui_bindings_.get()) {
4158 dom_ui_bindings_.reset(new DOMUIBindings());
4159 }
4160 return dom_ui_bindings_.get();
4161}
4162
4163ExternalHostBindings* RenderView::GetExternalHostBindings() {
4164 if (!external_host_bindings_.get()) {
4165 external_host_bindings_.reset(new ExternalHostBindings());
4166 }
4167 return external_host_bindings_.get();
4168}
4169
[email protected]0fdbf8c2010-07-08 20:33:014170WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4171 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494172}
4173
[email protected]6069da8c2009-10-20 20:33:494174void RenderView::OnFind(int request_id, const string16& search_text,
4175 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274176 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494177
4178 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494179 if (options.findNext) {
4180 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014181 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494182 } else {
[email protected]afdbd142010-07-10 08:01:234183 if (GetWebPluginFromPluginDocument()->startFind(
4184 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494185 } else {
[email protected]e7c58a32010-08-13 19:47:114186 // Send "no results".
4187 Send(new ViewHostMsg_Find_Reply(routing_id_,
4188 request_id,
4189 0,
4190 gfx::Rect(),
4191 0,
4192 true));
[email protected]24a7f3c2010-03-25 08:26:494193 }
4194 }
4195 return;
4196 }
4197
[email protected]b4bb2502009-10-01 22:35:274198 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274199 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294200 WebFrame* search_frame = focused_frame; // start searching focused frame.
4201
4202 bool multi_frame = (frame_after_main != main_frame);
4203
4204 // If we have multiple frames, we don't want to wrap the search within the
4205 // frame, so we check here if we only have main_frame in the chain.
4206 bool wrap_within_frame = !multi_frame;
4207
[email protected]b3f2b912009-04-09 16:18:524208 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294209 bool result = false;
4210
[email protected]7830da3e2009-11-06 16:27:264211 // If something is selected when we start searching it means we cannot just
4212 // increment the current match ordinal; we need to re-generate it.
4213 WebRange current_selection = focused_frame->selectionRange();
4214
initial.commit09911bf2008-07-26 23:55:294215 do {
[email protected]dd7daa82009-08-10 05:46:454216 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594217 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294218
4219 if (!result) {
4220 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224221 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294222
4223 // Find the next frame, but skip the invisible ones.
4224 do {
4225 // What is the next frame to search? (we might be going backwards). Note
4226 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594227 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274228 search_frame->traverseNext(true) :
4229 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454230 } while (!search_frame->hasVisibleContent() &&
4231 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294232
[email protected]884db412008-11-24 23:46:504233 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224234 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294235
4236 // If we have multiple frames and we have wrapped back around to the
4237 // focused frame, we need to search it once more allowing wrap within
4238 // the frame, otherwise it will report 'no match' if the focused frame has
4239 // reported matches, but no frames after the focused_frame contain a
4240 // match for the search word(s).
4241 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454242 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594243 request_id, search_text, options, true, // Force wrapping.
4244 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294245 }
4246 }
4247
[email protected]26aa0482009-09-30 16:55:274248 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294249 } while (!result && search_frame != focused_frame);
4250
[email protected]7830da3e2009-11-06 16:27:264251 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294252 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454253 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294254 } else {
4255 // If nothing is found, set result to "0 of 0", otherwise, set it to
4256 // "-1 of 1" to indicate that we found at least one item, but we don't know
4257 // yet what is active.
4258 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4259 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294260
[email protected]4f3dc372009-02-24 00:10:294261 // If we find no matches then this will be our last status update.
4262 // Otherwise the scoping effort will send more results.
4263 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294264
[email protected]4f3dc372009-02-24 00:10:294265 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404266 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594267 request_id,
[email protected]4f3dc372009-02-24 00:10:294268 match_count,
4269 selection_rect,
4270 ordinal,
4271 final_status_update));
initial.commit09911bf2008-07-26 23:55:294272
initial.commit09911bf2008-07-26 23:55:294273 // Scoping effort begins, starting with the mainframe.
4274 search_frame = main_frame;
4275
[email protected]dd7daa82009-08-10 05:46:454276 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294277
4278 do {
4279 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454280 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294281
4282 // We don't start another scoping effort unless at least one match has
4283 // been found.
4284 if (result) {
4285 // Start new scoping request. If the scoping function determines that it
4286 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454287 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594288 search_text,
4289 options,
initial.commit09911bf2008-07-26 23:55:294290 true); // reset the tickmarks
4291 }
4292
4293 // Iterate to the next frame. The frame will not necessarily scope, for
4294 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274295 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294296 } while (search_frame != main_frame);
4297 }
4298}
4299
[email protected]24a7f3c2010-03-25 08:26:494300void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4301 WebView* view = webview();
4302 if (!view)
4303 return;
4304
4305 WebDocument doc = view->mainFrame()->document();
4306 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014307 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494308 return;
4309 }
4310
4311 bool clear_selection =
4312 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4313 if (clear_selection)
4314 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4315
4316 WebFrame* frame = view->mainFrame();
4317 while (frame) {
4318 frame->stopFinding(clear_selection);
4319 frame = frame->traverseNext(false);
4320 }
4321
4322 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4323 WebFrame* focused_frame = view->focusedFrame();
4324 if (focused_frame) {
4325 WebDocument doc = focused_frame->document();
4326 if (!doc.isNull()) {
4327 WebNode node = doc.focusedNode();
4328 if (!node.isNull())
4329 node.simulateClick();
4330 }
4331 }
4332 }
4333}
4334
4335void RenderView::OnFindReplyAck() {
4336 // Check if there is any queued up request waiting to be sent.
4337 if (queued_find_reply_message_.get()) {
4338 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424339 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494340 }
4341}
4342
[email protected]8934a3b2010-02-25 00:34:004343bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354344 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004345 return current_content_settings_.settings[settings_type] !=
4346 CONTENT_SETTING_BLOCK;
4347}
4348
[email protected]55126132010-08-19 14:53:284349void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4350 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004351 if (!content_blocked_[settings_type]) {
4352 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284353 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4354 resource_identifier));
[email protected]0de80162010-02-03 04:52:354355 }
[email protected]0de80162010-02-03 04:52:354356}
4357
[email protected]71b0d5d2010-02-15 05:43:074358void RenderView::ClearBlockedContentSettings() {
4359 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4360 content_blocked_[i] = false;
4361}
4362
[email protected]0bd753682010-12-16 18:15:524363WebPlugin* RenderView::CreatePepperPlugin(
4364 WebFrame* frame,
4365 const WebPluginParams& params,
4366 const FilePath& path,
4367 webkit::ppapi::PluginModule* pepper_module) {
4368 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254369 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094370}
[email protected]00152e92010-07-19 11:47:404371
[email protected]191eb3f72010-12-21 06:27:504372WebPlugin* RenderView::CreateNPAPIPlugin(
4373 WebFrame* frame,
4374 const WebPluginParams& params,
4375 const FilePath& path,
4376 const std::string& mime_type) {
4377 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084378 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404379}
4380
[email protected]3c2826852010-12-16 19:09:144381WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514382 WebFrame* frame,
4383 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504384 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144385 int resource_id,
4386 int message_id) {
4387 // |blocked_plugin| will delete itself when the WebViewPlugin
4388 // is destroyed.
4389 BlockedPlugin* blocked_plugin =
4390 new BlockedPlugin(this,
4391 frame,
4392 group,
4393 params,
4394 webkit_preferences_,
4395 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374396 l10n_util::GetStringFUTF16(message_id,
4397 group.GetGroupName()));
[email protected]3c2826852010-12-16 19:09:144398 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514399}
4400
[email protected]40bd6582009-12-04 23:49:514401void RenderView::OnZoom(PageZoom::Function function) {
4402 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4403 return;
4404
[email protected]258d31122010-05-09 10:59:414405 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524406
[email protected]b75b8292010-10-01 07:28:254407 double old_zoom_level = webview()->zoomLevel();
4408 double zoom_level;
4409 if (function == PageZoom::RESET) {
4410 zoom_level = 0;
4411 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4412 // Previous zoom level is a whole number, so just increment/decrement.
4413 zoom_level = old_zoom_level + function;
4414 } else {
4415 // Either the user hit the zoom factor limit and thus the zoom level is now
4416 // not a whole number, or a plugin changed it to a custom value. We want
4417 // to go to the next whole number so that the user can always get back to
4418 // 100% with the keyboard/menu.
4419 if ((old_zoom_level > 1 && function > 0) ||
4420 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454421 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254422 } else {
4423 // We're going towards 100%, so first go to the next whole number.
4424 zoom_level = static_cast<int>(old_zoom_level);
4425 }
4426 }
[email protected]40bd6582009-12-04 23:49:514427
[email protected]b75b8292010-10-01 07:28:254428 webview()->setZoomLevel(false, zoom_level);
4429 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514430}
4431
[email protected]d0b8d092010-10-25 04:05:174432void RenderView::OnSetZoomLevel(double zoom_level) {
4433 // Don't set zoom level for full-page plugin since they don't use the same
4434 // zoom settings.
4435 if (webview()->mainFrame()->document().isPluginDocument())
4436 return;
4437
4438 webview()->hidePopups();
4439 webview()->setZoomLevel(false, zoom_level);
4440 zoomLevelChanged();
4441}
4442
[email protected]9d797f32010-04-23 07:17:544443void RenderView::OnSetContentSettingsForLoadingURL(
4444 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014445 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544446 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014447}
4448
[email protected]9d797f32010-04-23 07:17:544449void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254450 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544451 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294452}
4453
[email protected]41fc0322009-09-04 22:23:404454void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274455 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294456}
4457
[email protected]a697f4c2009-09-14 22:30:184458void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274459 WebString no_encoding;
4460 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184461}
4462
[email protected]20ad2692009-11-20 18:27:204463bool RenderView::GetAllChildFrames(
4464 WebFrame* parent_frame,
4465 std::vector<WebFrame*>* frames_vector) const {
4466 if (!parent_frame)
4467 return false;
4468 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4469 child_frame = child_frame->nextSibling()) {
4470 frames_vector->push_back(child_frame);
4471 GetAllChildFrames(child_frame, frames_vector);
4472 }
4473 return true;
4474}
4475
[email protected]dd7daa82009-08-10 05:46:454476WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4477 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274478 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454479
4480 // xpath string can represent a frame deep down the tree (across multiple
4481 // frame DOMs).
4482 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4483 // should break into 2 xpaths
4484 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4485
[email protected]26aa0482009-09-30 16:55:274486 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454487
4488 std::wstring xpath_remaining = xpath;
4489 while (!xpath_remaining.empty()) {
4490 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4491 std::wstring xpath_child;
4492 if (delim_pos != std::wstring::npos) {
4493 xpath_child = xpath_remaining.substr(0, delim_pos);
4494 xpath_remaining.erase(0, delim_pos + 1);
4495 } else {
4496 xpath_remaining.swap(xpath_child);
4497 }
4498 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294499 }
4500
[email protected]dd7daa82009-08-10 05:46:454501 return frame;
initial.commit09911bf2008-07-26 23:55:294502}
4503
[email protected]ce833282010-11-04 15:48:394504void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) {
4505 // Explicitly allow empty vector to be sent to the browser.
4506 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions));
[email protected]15d9c0c2010-09-10 22:36:264507}
4508
[email protected]882b7b22010-10-05 03:34:534509void RenderView::EvaluateScript(const string16& frame_xpath,
4510 const string16& script,
4511 int id,
4512 bool notify_result) {
4513 v8::Handle<v8::Value> result;
4514 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4515 if (web_frame)
4516 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4517 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294518 ListValue list;
4519 if (web_frame) {
4520 v8::HandleScope handle_scope;
4521 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4522 v8::Context::Scope context_scope(context);
4523 list.Set(0, ConvertV8Value(result));
4524 } else {
4525 list.Set(0, Value::CreateNullValue());
4526 }
4527 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534528 }
initial.commit09911bf2008-07-26 23:55:294529}
4530
[email protected]1810e132009-03-24 23:35:484531void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084532 const std::string& css,
4533 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484534 WebFrame* web_frame = GetChildFrame(frame_xpath);
4535 if (!web_frame)
4536 return;
4537
[email protected]ffaef0c2009-09-15 17:08:084538 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484539}
4540
[email protected]00c39612010-03-06 02:53:284541void RenderView::OnPepperPluginDestroy(
4542 WebPluginDelegatePepper* pepper_plugin) {
4543 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014544 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4545 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284546 NOTREACHED();
4547 return;
4548 }
[email protected]53900d52010-06-16 04:25:014549 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474550
4551 // The plugin could have been destroyed while it was waiting for a file
4552 // choose callback, so check all pending completion callbacks and NULL them.
4553 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4554 file_chooser_completions_.begin();
4555 i != file_chooser_completions_.end(); /* nothing */) {
4556 if ((*i)->completion == pepper_plugin) {
4557 // We NULL the first one instead of deleting it because the plugin might
4558 // be the one waiting for a file choose callback. If the callback later
4559 // comes, we don't want to send the result to the next callback in line.
4560 if (i == file_chooser_completions_.begin())
4561 (*i)->completion = NULL;
4562 else
4563 i = file_chooser_completions_.erase(i);
4564 } else {
4565 ++i;
4566 }
4567 }
[email protected]00c39612010-03-06 02:53:284568}
4569
[email protected]882b7b22010-10-05 03:34:534570void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4571 const string16& jscript,
4572 int id,
4573 bool notify_result) {
4574 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294575}
4576
[email protected]1810e132009-03-24 23:35:484577void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084578 const std::string& css,
4579 const std::string& id) {
4580 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414581
4582 // Notify RenderViewHost that css has been inserted into the frame.
4583 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484584}
4585
[email protected]7ea066a2009-04-06 20:21:594586void RenderView::OnAddMessageToConsole(
4587 const string16& frame_xpath,
4588 const string16& message,
4589 const WebConsoleMessage::Level& level) {
4590 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594591 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454592 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294593}
4594
[email protected]81e63782009-02-27 19:35:094595void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4596 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294597}
4598
4599void RenderView::OnSetDOMUIProperty(const std::string& name,
4600 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094601 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c091c2c2010-09-17 19:05:464602 GetDOMUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294603}
4604
4605void RenderView::OnReservePageIDRange(int size_of_range) {
4606 next_page_id_ += size_of_range + 1;
4607}
4608
[email protected]e80c73b2009-04-07 23:24:584609void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4610 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254611 bool ended,
4612 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034613 if (ended) {
[email protected]26aa0482009-09-30 16:55:274614 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204615 } else {
4616 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034617 }
initial.commit09911bf2008-07-26 23:55:294618}
4619
4620void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274621 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294622}
4623
initial.commit09911bf2008-07-26 23:55:294624void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584625 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254626 const gfx::Point& screen_point,
4627 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274628 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584629 drop_data.ToDragData(),
4630 drop_data.identity,
4631 client_point,
[email protected]1d9f4132009-09-08 17:29:254632 screen_point,
4633 ops);
initial.commit09911bf2008-07-26 23:55:294634
[email protected]1d9f4132009-09-08 17:29:254635 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294636}
4637
[email protected]e80c73b2009-04-07 23:24:584638void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254639 const gfx::Point& screen_point,
4640 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274641 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254642 client_point,
4643 screen_point,
4644 ops);
initial.commit09911bf2008-07-26 23:55:294645
[email protected]1d9f4132009-09-08 17:29:254646 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294647}
4648
4649void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274650 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294651}
4652
[email protected]e80c73b2009-04-07 23:24:584653void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4654 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274655 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294656}
4657
4658void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594659 webkit_preferences_ = prefs;
4660 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294661}
4662
4663void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4664 alternate_error_page_url_ = url;
4665}
4666
[email protected]a0c7153e2009-12-09 14:36:334667void RenderView::OnCustomContextMenuAction(unsigned action) {
[email protected]6a8b86c2010-12-09 05:24:304668 if (custom_menu_listener_)
4669 custom_menu_listener_->MenuItemSelected(action);
4670 else
4671 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334672}
4673
[email protected]d4a00a72010-01-29 01:44:424674void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024675 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424676 const std::string& source_lang,
4677 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024678 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4679 translate_script);
[email protected]d4a00a72010-01-29 01:44:424680}
4681
[email protected]85d252e2010-04-06 22:21:024682void RenderView::OnRevertTranslation(int page_id) {
4683 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324684}
4685
initial.commit09911bf2008-07-26 23:55:294686void RenderView::OnInstallMissingPlugin() {
4687 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594688 if (first_default_plugin_)
4689 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294690}
4691
[email protected]97c5c592010-08-03 08:22:214692void RenderView::OnLoadBlockedPlugins() {
[email protected]8853bc932011-01-11 16:27:024693 while (!blocked_plugins_.empty())
4694 (*blocked_plugins_.begin())->LoadPlugin();
[email protected]97c5c592010-08-03 08:22:214695}
4696
[email protected]cdaf8d02010-03-30 19:52:474697void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364698 // This could happen if we navigated to a different page before the user
4699 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474700 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364701 return;
4702
[email protected]cdaf8d02010-03-30 19:52:474703 WebVector<WebString> ws_file_names(paths.size());
4704 for (size_t i = 0; i < paths.size(); ++i)
4705 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464706
[email protected]cdaf8d02010-03-30 19:52:474707 if (file_chooser_completions_.front()->completion)
4708 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4709 file_chooser_completions_.pop_front();
4710
4711 // If there are more pending file chooser requests, schedule one now.
4712 if (!file_chooser_completions_.empty()) {
4713 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4714 file_chooser_completions_.front()->params));
4715 }
initial.commit09911bf2008-07-26 23:55:294716}
4717
4718void RenderView::OnEnableViewSourceMode() {
4719 if (!webview())
4720 return;
[email protected]26aa0482009-09-30 16:55:274721 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294722 if (!main_frame)
4723 return;
4724
[email protected]dd7daa82009-08-10 05:46:454725 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294726}
4727
[email protected]770dd8b2010-05-24 18:11:394728void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4729 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244730 if (send_preferred_size_changes_)
4731 return;
[email protected]9fb325e2010-05-06 18:23:244732 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394733
4734 // WebKit doesn't send a notification of the effective height of the page
4735 // changes, so poll for it.
4736 // TODO: Add a notification for this to WebKit, remove polling. After that's
4737 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4738 // http://crbug.com/44850
4739 if (flags & kPreferredSizeHeightThisIsSlow) {
4740 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4741 &RenderView::CheckPreferredSize);
4742 }
[email protected]0666aef2009-05-13 19:48:084743}
4744
[email protected]ce833282010-11-04 15:48:394745void RenderView::OnSearchBoxChange(const string16& value,
[email protected]368ef4c2010-11-08 21:58:464746 bool verbatim,
[email protected]ce833282010-11-04 15:48:394747 int selection_start,
4748 int selection_end) {
4749 search_box_.value = value;
[email protected]368ef4c2010-11-08 21:58:464750 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394751 search_box_.selection_start = selection_start;
4752 search_box_.selection_end = selection_end;
4753 if (!webview() || !webview()->mainFrame())
4754 return;
4755 extensions_v8::SearchBoxExtension::DispatchChange(webview()->mainFrame());
4756}
4757
4758void RenderView::OnSearchBoxSubmit(const string16& value, bool verbatim) {
4759 search_box_.value = value;
4760 search_box_.verbatim = verbatim;
4761 if (!webview() || !webview()->mainFrame())
4762 return;
4763 extensions_v8::SearchBoxExtension::DispatchSubmit(webview()->mainFrame());
4764}
4765
4766void RenderView::OnSearchBoxCancel() {
4767 search_box_.verbatim = false;
4768 if (!webview() || !webview()->mainFrame())
4769 return;
4770 extensions_v8::SearchBoxExtension::DispatchCancel(webview()->mainFrame());
4771}
4772
4773void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) {
4774 search_box_.x = bounds.x();
4775 search_box_.y = bounds.y();
4776 search_box_.width = bounds.width();
4777 search_box_.height = bounds.height();
4778 if (!webview() || !webview()->mainFrame())
4779 return;
4780 extensions_v8::SearchBoxExtension::DispatchResize(webview()->mainFrame());
4781}
4782
[email protected]57ad7b8c2010-11-18 19:13:494783void RenderView::OnDetermineIfPageSupportsInstant(const string16& value,
[email protected]0d5ab152011-01-14 23:09:044784 bool verbatim,
4785 int selection_start,
4786 int selection_end) {
[email protected]ce833282010-11-04 15:48:394787 search_box_.value = value;
[email protected]57ad7b8c2010-11-18 19:13:494788 search_box_.verbatim = verbatim;
[email protected]0d5ab152011-01-14 23:09:044789 search_box_.selection_start = selection_start;
4790 search_box_.selection_end = selection_end;
[email protected]ce833282010-11-04 15:48:394791 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
4792 webview()->mainFrame());
4793 Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result));
4794}
4795
[email protected]cda45c02010-02-25 19:28:104796void RenderView::OnDisableScrollbarsForSmallWindows(
4797 const gfx::Size& disable_scrollbar_size_limit) {
4798 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4799}
4800
[email protected]80d96fa2009-06-10 22:34:514801void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4802 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374803 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134804#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414805 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4806 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464807 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344808 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4809 renderer_prefs.thumb_inactive_color,
4810 renderer_prefs.thumb_active_color,
4811 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324812
[email protected]644d77e2010-01-27 01:03:104813 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324814 webview()->setScrollbarColors(
4815 renderer_prefs.thumb_inactive_color,
4816 renderer_prefs.thumb_active_color,
4817 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104818 webview()->setSelectionColors(
4819 renderer_prefs.active_selection_bg_color,
4820 renderer_prefs.active_selection_fg_color,
4821 renderer_prefs.inactive_selection_bg_color,
4822 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464823 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104824 }
[email protected]7a74e102009-09-03 00:16:564825#endif
[email protected]80d96fa2009-06-10 22:34:514826}
4827
[email protected]952cb702009-10-07 05:50:284828void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4829 const WebMediaPlayerAction& action) {
4830 if (webview())
4831 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564832}
4833
[email protected]7b291f92009-08-14 05:43:534834void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4835 view_type_ = type;
4836}
4837
4838void RenderView::OnUpdateBrowserWindowId(int window_id) {
4839 browser_window_id_ = window_id;
4840}
4841
[email protected]dea2d372010-09-25 06:41:144842void RenderView::OnEnableAccessibility() {
4843 if (WebAccessibilityCache::accessibilityEnabled())
4844 return;
[email protected]9f4db512010-05-10 20:21:414845
[email protected]dea2d372010-09-25 06:41:144846 WebAccessibilityCache::enableAccessibility();
4847
4848 if (webview()) {
4849 // It's possible that the webview has already loaded a webpage without
4850 // accessibility being enabled. Initialize the browser's cached
4851 // accessibility tree by sending it a 'load complete' notification.
4852 postAccessibilityNotification(
4853 webview()->accessibilityObject(),
4854 WebKit::WebAccessibilityNotificationLoadComplete);
4855 }
[email protected]266eb6f2008-09-30 23:56:504856}
4857
[email protected]aef92842010-05-21 16:54:364858void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4859 if (!accessibility_.get())
4860 return;
[email protected]02ea2f312010-09-27 17:03:364861
4862 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4863 WebAccessibilityObject root = webview()->accessibilityObject();
4864 if (!obj.isValid() || !root.isValid())
4865 return;
4866
4867 // By convention, calling SetFocus on the root of the tree should clear the
4868 // current focus. Otherwise set the focus to the new node.
4869 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4870 webview()->clearFocusedNode();
4871 else
4872 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364873}
4874
4875void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4876 if (!accessibility_.get())
4877 return;
[email protected]02ea2f312010-09-27 17:03:364878
4879 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4880 if (!obj.isValid())
4881 return;
4882
4883 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364884}
4885
[email protected]9892b472010-09-16 00:23:424886void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514887 DCHECK(accessibility_ack_pending_);
4888 accessibility_ack_pending_ = false;
4889 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314890}
4891
initial.commit09911bf2008-07-26 23:55:294892void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4893 const GURL& page_url) {
4894 // Prepare list to storage all savable resource links.
4895 std::vector<GURL> resources_list;
4896 std::vector<GURL> referrers_list;
4897 std::vector<GURL> frames_list;
4898 webkit_glue::SavableResourcesResult result(&resources_list,
4899 &referrers_list,
4900 &frames_list);
4901
[email protected]dbeb3952009-10-13 18:01:184902 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4903 webview(),
4904 page_url,
4905 &result,
4906 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294907 // If something is wrong when collecting all savable resource links,
4908 // send empty list to embedder(browser) to tell it failed.
4909 referrers_list.clear();
4910 resources_list.clear();
4911 frames_list.clear();
4912 }
4913
4914 // Send result of all savable resource links to embedder.
4915 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4916 resources_list,
4917 referrers_list,
4918 frames_list));
4919}
4920
4921void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324922 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314923 const std::vector<FilePath>& local_paths,
4924 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074925
4926 // Convert std::vector of GURLs to WebVector<WebURL>
4927 WebVector<WebURL> weburl_links(links);
4928
4929 // Convert std::vector of std::strings to WebVector<WebString>
4930 WebVector<WebString> webstring_paths(local_paths.size());
4931 for (size_t i = 0; i < local_paths.size(); i++)
4932 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4933
4934 WebPageSerializer::serialize(webview()->mainFrame(),
4935 true, this, weburl_links, webstring_paths,
4936 webkit_glue::FilePathToWebString(
4937 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294938}
4939
[email protected]d9ec5c0f2009-12-23 11:55:074940void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4941 const WebCString& data,
4942 WebPageSerializerClient::PageSerializationStatus status) {
4943 Send(new ViewHostMsg_SendSerializedHtmlData(
4944 routing_id_,
4945 frame_url,
4946 data.data(),
4947 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294948}
4949
[email protected]9b18a84f2010-06-10 15:54:044950void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274951 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474952 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294953}
4954
[email protected]eb6b87a2009-07-24 15:57:394955void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294956 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4957 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4958 // in the onunload handler from appearing. For now, we're bypassing that and
4959 // calling the FrameLoader's CloseURL method directly. This should be
4960 // revisited to avoid having two ways to close a page. Having a single way
4961 // to close that can run onunload is also useful for fixing
4962 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:364963 // TODO(davemoore) This code should be removed once willClose() gets
4964 // called when a page is destroyed. page_load_histograms_.Dump() is safe
4965 // to call multiple times for the same frame, but it will simplify things.
4966 page_load_histograms_.Dump(webview()->mainFrame());
4967 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:274968 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294969
[email protected]eb6b87a2009-07-24 15:57:394970 // Just echo back the params in the ACK.
4971 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294972}
4973
4974void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574975#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294976 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464977 if (webview())
4978 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574979#else // defined(OS_WIN)
4980 // TODO(port): we don't support theming on non-Windows platforms yet
4981 NOTIMPLEMENTED();
4982#endif
initial.commit09911bf2008-07-26 23:55:294983}
4984
[email protected]9b18a84f2010-06-10 15:54:044985void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4986 const std::string& origin,
4987 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154988 if (message.empty())
4989 return;
[email protected]c091c2c2010-09-17 19:05:464990 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
4991 target);
[email protected]3ac14a052008-08-15 21:22:154992}
4993
[email protected]0aa55312008-10-17 21:53:084994void RenderView::OnDisassociateFromPopupCount() {
4995 if (decrement_shared_popup_at_destruction_)
4996 shared_popup_counter_->data--;
4997 shared_popup_counter_ = new SharedRenderViewCounter(0);
4998 decrement_shared_popup_at_destruction_ = false;
4999}
5000
[email protected]15d79e12009-08-02 19:23:455001bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
5002 const WebURLError& error,
5003 bool replace) {
5004 // We only show alternate error pages in the main frame. They are
5005 // intended to assist the user when navigating, so there is not much
5006 // value in showing them for failed subframes. Ideally, we would be
5007 // able to use the TYPED transition type for this, but that flag is
5008 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455009 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455010 return false;
5011
5012 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375013 // connection failure.
[email protected]15d79e12009-08-02 19:23:455014 int ec = error.reason;
5015 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5016 ec != net::ERR_CONNECTION_FAILED &&
5017 ec != net::ERR_CONNECTION_REFUSED &&
5018 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:375019 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:455020 return false;
5021
5022 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555023 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455024 if (!error_page_url.is_valid())
5025 return false;
5026
5027 // Load an empty page first so there is an immediate response to the error,
5028 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455029 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:365030 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455031 error.unreachableURL,
5032 replace);
5033
5034 // Now, create a fetcher for the error page and associate it with the data
5035 // source we just created via the LoadHTMLString call. That way if another
5036 // navigation occurs, the fetcher will get destroyed.
5037 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455038 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:455039 navigation_state->set_alt_error_page_fetcher(
5040 new AltErrorPageResourceFetcher(
5041 error_page_url, frame, error,
5042 NewCallback(this, &RenderView::AltErrorPageFinished)));
5043 return true;
5044}
5045
initial.commit09911bf2008-07-26 23:55:295046std::string RenderView::GetAltHTMLForTemplate(
5047 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:395048 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:295049 ResourceBundle::GetSharedInstance().GetRawDataResource(
5050 template_resource_id));
5051
5052 if (template_html.empty()) {
5053 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
5054 return "";
5055 }
[email protected]7cd22a52009-07-14 00:40:255056
initial.commit09911bf2008-07-26 23:55:295057 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:255058 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:295059 template_html, &error_strings, "t");
5060}
[email protected]0e79b9e2009-02-13 04:20:485061
[email protected]15d79e12009-08-02 19:23:455062void RenderView::AltErrorPageFinished(WebFrame* frame,
5063 const WebURLError& original_error,
5064 const std::string& html) {
5065 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:555066
5067 // If we failed to download the alternate error page, fall back to the
5068 // original error page if present. Otherwise, LoadNavigationErrorPage
5069 // will simply display a default error page.
5070 const std::string* html_to_load = &html;
5071 if (html.empty()) {
5072 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455073 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:555074 html_to_load = &navigation_state->postponed_data();
5075 }
[email protected]3f853a52010-09-13 19:15:085076 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5077 true);
[email protected]15d79e12009-08-02 19:23:455078}
5079
[email protected]30f75e62009-02-25 22:01:005080void RenderView::OnMoveOrResizeStarted() {
5081 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475082 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005083}
5084
[email protected]30f75e62009-02-25 22:01:005085void RenderView::OnResize(const gfx::Size& new_size,
5086 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:105087 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475088 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105089 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205090 webview()->mainFrame()->setCanHaveScrollbars(
5091 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105092 }
5093 }
5094
[email protected]30f75e62009-02-25 22:01:005095 RenderWidget::OnResize(new_size, resizer_rect);
5096}
[email protected]0aa477bd2009-03-23 22:21:435097
[email protected]00c39612010-03-06 02:53:285098void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015099 // Notify the pepper plugins that we started painting.
5100 pepper_delegate_.ViewInitiatedPaint();
5101
5102 // Notify any "old-style" pepper plugins that we started painting. This is
5103 // used for internal bookkeeping only, so we know that the set can not change
5104 // under us.
[email protected]00c39612010-03-06 02:53:285105 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:015106 current_oldstyle_pepper_plugins_.begin();
5107 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:285108 (*i)->RenderViewInitiatedPaint();
5109}
5110
5111void RenderView::DidFlushPaint() {
5112 // Notify any pepper plugins that we painted. This will call into the plugin,
5113 // and we it may ask to close itself as a result. This will, in turn, modify
5114 // our set, possibly invalidating the iterator. So we iterate on a copy that
5115 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015116 pepper_delegate_.ViewFlushedPaint();
5117
5118 // Notify any old-style pepper plugins that we painted. This will call into
5119 // the plugin, and we it may ask to close itself as a result. This will, in
5120 // turn, modify our set, possibly invalidating the iterator. So we iterate on
5121 // a copy that won't change out from under us.
5122 // This should be deleted when we don't support old Pepper anymore.
5123 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:285124 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
5125 i != plugins.end(); ++i) {
5126 // The copy above makes sure our iterator is never invalid if some plugins
5127 // are destroyed. But some plugin may decide to close all of its views in
5128 // response to a paint in one of them, so we need to make sure each one is
5129 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:015130 if (current_oldstyle_pepper_plugins_.find(*i) !=
5131 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:285132 (*i)->RenderViewFlushedPaint();
5133 }
5134
5135 WebFrame* main_frame = webview()->mainFrame();
5136
5137 // If we have a provisional frame we are between the start and commit stages
5138 // of loading and we don't want to save stats.
5139 if (!main_frame->provisionalDataSource()) {
5140 WebDataSource* ds = main_frame->dataSource();
5141 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5142 DCHECK(navigation_state);
5143
[email protected]05c8e502010-08-15 15:13:525144 // TODO(jar): The following code should all be inside a method, probably in
5145 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285146 Time now = Time::Now();
5147 if (navigation_state->first_paint_time().is_null()) {
5148 navigation_state->set_first_paint_time(now);
5149 }
5150 if (navigation_state->first_paint_after_load_time().is_null() &&
5151 !navigation_state->finish_load_time().is_null()) {
5152 navigation_state->set_first_paint_after_load_time(now);
5153 }
5154 }
5155}
5156
[email protected]719b36f2010-12-22 20:36:465157webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155158 const gfx::Rect& paint_bounds,
5159 TransportDIB** dib,
5160 gfx::Rect* location,
5161 gfx::Rect* clip) {
5162 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5163 paint_bounds, dib, location, clip);
5164}
5165
[email protected]05d478752009-04-08 23:38:165166void RenderView::OnClearFocusedNode() {
5167 if (webview())
[email protected]26aa0482009-09-30 16:55:275168 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165169}
5170
[email protected]699ab0d2009-04-23 23:19:145171void RenderView::OnSetBackground(const SkBitmap& background) {
5172 if (webview())
[email protected]b4bb2502009-10-01 22:35:275173 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145174
5175 SetBackground(background);
5176}
5177
[email protected]8c66c5a2009-07-22 17:26:345178void RenderView::OnSetActive(bool active) {
5179 if (webview())
[email protected]b4bb2502009-10-01 22:35:275180 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265181
5182#if defined(OS_MACOSX)
5183 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5184 for (plugin_it = plugin_delegates_.begin();
5185 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5186 (*plugin_it)->SetWindowFocus(active);
5187 }
5188#endif
[email protected]8c66c5a2009-07-22 17:26:345189}
5190
[email protected]6ce7abc52010-02-02 18:40:145191#if defined(OS_MACOSX)
5192void RenderView::OnSetWindowVisibility(bool visible) {
5193 // Inform plugins that their container has changed visibility.
5194 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5195 for (plugin_it = plugin_delegates_.begin();
5196 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5197 (*plugin_it)->SetContainerVisibility(visible);
5198 }
5199}
[email protected]1e6e3c992010-02-08 15:52:135200
[email protected]4d51d5bf2010-07-26 18:48:265201void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5202 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135203 // Inform plugins that their window's frame has changed.
5204 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5205 for (plugin_it = plugin_delegates_.begin();
5206 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5207 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5208 }
5209}
[email protected]935d63d2010-10-15 23:31:555210
5211void RenderView::OnPluginImeCompositionConfirmed(const string16& text,
5212 int plugin_id) {
5213 // WebPluginDelegateProxy is responsible for figuring out if this text
5214 // applies to it or not, so inform all the delegates.
5215 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5216 for (plugin_it = plugin_delegates_.begin();
5217 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5218 (*plugin_it)->ImeCompositionConfirmed(text, plugin_id);
5219 }
5220}
[email protected]6ce7abc52010-02-02 18:40:145221#endif // OS_MACOSX
5222
[email protected]8b8e7c92010-08-19 18:05:565223void RenderView::SendExtensionRequest(
5224 const ViewHostMsg_DomMessage_Params& params) {
5225 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275226}
5227
[email protected]c6619182009-05-12 14:59:325228void RenderView::OnExtensionResponse(int request_id,
5229 bool success,
5230 const std::string& response,
5231 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355232 ExtensionProcessBindings::HandleResponse(
5233 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275234}
[email protected]c20210e62009-04-03 21:39:265235
[email protected]a7ab1b782010-10-21 23:24:165236void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5237 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495238 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195239 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495240 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165241 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375242}
5243
[email protected]9892b472010-09-16 00:23:425244void RenderView::postAccessibilityNotification(
5245 const WebAccessibilityObject& obj,
5246 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145247 if (!accessibility_.get() && webview()) {
5248 // Load complete should be our first notification sent.
5249 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5250 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5251 return;
5252
5253 // Create and initialize our accessibility cache
5254 accessibility_.reset(WebAccessibilityCache::create());
5255 accessibility_->initialize(webview());
5256 }
5257
[email protected]a3fa4f92010-09-30 22:19:335258 if (!accessibility_->isCached(obj)) {
5259 // The browser doesn't know about objects that are not in the cache. Send a
5260 // children change for the first accestor that actually is in the cache.
5261 WebAccessibilityObject parent = obj;
5262 while (parent.isValid() && !accessibility_->isCached(parent))
5263 parent = parent.parentObject();
5264
5265 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5266 if (!parent.isValid())
5267 return;
5268 postAccessibilityNotification(
5269 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5270
5271 // The parent's children change takes care of the child's children change.
5272 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5273 return;
5274 }
5275
[email protected]dea2d372010-09-25 06:41:145276 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515277 RendererAccessibilityNotification acc_notification;
5278 acc_notification.id = accessibility_->addOrGetId(obj);
5279 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485280 return;
5281
[email protected]54ec7f82010-10-21 22:32:515282 if (!WebAccessibilityNotificationToViewHostMsg(
5283 notification,
5284 &acc_notification.type)) {
5285 return;
5286 }
5287
5288 // Discard duplicate accessibility notifications.
5289 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5290 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5291 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425292 return;
[email protected]54ec7f82010-10-21 22:32:515293 }
[email protected]9892b472010-09-16 00:23:425294 }
[email protected]54ec7f82010-10-21 22:32:515295 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485296
[email protected]54ec7f82010-10-21 22:32:515297 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5298 // When no accessibility notifications are in-flight post a task to send
5299 // the notifications to the browser. We use PostTask so that we can queue
5300 // up additional notifications.
5301 MessageLoop::current()->PostTask(
5302 FROM_HERE,
5303 accessibility_method_factory_.NewRunnableMethod(
5304 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315305 }
[email protected]520cb7d72010-08-31 11:54:315306}
5307
[email protected]212a49d2010-10-25 18:23:475308void RenderView::Print(WebFrame* frame,
5309 bool script_initiated,
5310 bool is_preview) {
[email protected]0fda7272009-06-26 15:49:335311 DCHECK(frame);
5312 if (print_helper_.get() == NULL) {
5313 print_helper_.reset(new PrintWebViewHelper(this));
5314 }
[email protected]212a49d2010-10-25 18:23:475315 print_helper_->Print(frame, script_initiated, is_preview);
[email protected]0fda7272009-06-26 15:49:335316}
[email protected]446705872009-09-10 07:22:485317
5318void RenderView::OnSetEditCommandsForNextKeyEvent(
5319 const EditCommands& edit_commands) {
5320 edit_commands_ = edit_commands;
5321}
5322
[email protected]61f5a7b2009-12-22 22:21:205323void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275324 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355325 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205326 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5327 false));
[email protected]912256b32009-09-18 09:47:355328 return;
5329 }
5330
[email protected]fa7b6b542009-11-03 05:02:305331 WebDataSource* ds = main_frame->dataSource();
5332 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5333 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205334 pending_code_execution_queue_.push(
5335 linked_ptr<ViewMsg_ExecuteCode_Params>(
5336 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305337 return;
5338 }
5339
[email protected]61f5a7b2009-12-22 22:21:205340 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305341}
5342
5343void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205344 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205345 std::vector<WebFrame*> frame_vector;
5346 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205347 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205348 GetAllChildFrames(frame, &frame_vector);
5349
5350 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5351 frame_it != frame_vector.end(); ++frame_it) {
5352 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205353 if (params.is_javascript) {
[email protected]be7e5cb2010-10-04 12:53:175354 ExtensionRendererInfo* extension =
5355 ExtensionRendererInfo::GetByID(params.extension_id);
5356
[email protected]1f6228c2010-10-21 03:19:445357 // Since extension info is sent separately from user script info, they can
5358 // be out of sync. We just ignore this situation.
5359 if (!extension)
5360 continue;
5361
[email protected]be7e5cb2010-10-04 12:53:175362 const std::vector<URLPattern> host_permissions =
5363 extension->host_permissions();
5364 if (!Extension::CanExecuteScriptOnPage(
5365 frame->url(),
5366 extension->allowed_to_execute_script_everywhere(),
5367 &host_permissions,
5368 NULL,
5369 NULL)) {
[email protected]61f5a7b2009-12-22 22:21:205370 continue;
[email protected]be7e5cb2010-10-04 12:53:175371 }
[email protected]61f5a7b2009-12-22 22:21:205372
[email protected]20ad2692009-11-20 18:27:205373 std::vector<WebScriptSource> sources;
5374 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205375 WebScriptSource(WebString::fromUTF8(params.code)));
5376 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205377 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205378 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205379 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5380 } else {
[email protected]61f5a7b2009-12-22 22:21:205381 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205382 }
[email protected]912256b32009-09-18 09:47:355383 }
5384
[email protected]61f5a7b2009-12-22 22:21:205385 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355386}
5387
[email protected]60c42a8c72009-10-09 04:08:595388void RenderView::Close() {
5389 // We need to grab a pointer to the doomed WebView before we destroy it.
5390 WebView* doomed = webview();
5391 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495392 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595393}
5394
[email protected]446705872009-09-10 07:22:485395void RenderView::DidHandleKeyEvent() {
5396 edit_commands_.clear();
5397}
5398
[email protected]6a8ddba52010-09-05 04:38:065399void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515400 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065401}
5402
[email protected]941e4552010-02-01 21:23:435403#if defined(OS_MACOSX)
5404void RenderView::OnWasHidden() {
5405 RenderWidget::OnWasHidden();
5406
5407 // Inform plugins that their container is no longer visible.
5408 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5409 for (plugin_it = plugin_delegates_.begin();
5410 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5411 (*plugin_it)->SetContainerVisibility(false);
5412 }
5413}
5414
5415void RenderView::OnWasRestored(bool needs_repainting) {
5416 RenderWidget::OnWasRestored(needs_repainting);
5417
5418 // Inform plugins that their container is now visible.
5419 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5420 for (plugin_it = plugin_delegates_.begin();
5421 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5422 (*plugin_it)->SetContainerVisibility(true);
5423 }
5424}
[email protected]784ea1ab2010-09-18 00:02:345425#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135426
5427void RenderView::OnSetFocus(bool enable) {
5428 RenderWidget::OnSetFocus(enable);
5429
[email protected]7d3c02c2010-05-05 23:10:315430 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075431 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135432 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5433 for (plugin_it = plugin_delegates_.begin();
5434 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345435#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315436 // RenderWidget's call to setFocus can cause the underlying webview's
5437 // activation state to change just like a call to setIsActive.
5438 if (enable)
5439 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345440#endif
[email protected]7d3c02c2010-05-05 23:10:315441 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135442 }
[email protected]589621b2010-09-23 22:01:075443
5444 // Notify all Pepper plugins.
5445 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135446 }
5447}
[email protected]941e4552010-02-01 21:23:435448
[email protected]83dde542009-09-11 20:59:555449void RenderView::EnsureDocumentTag() {
5450 // TODO(darin): There's actually no reason for this to be here. We should
5451 // have the browser side manage the document tag.
5452#if defined(OS_MACOSX)
5453 if (!has_document_tag_) {
5454 // Make the call to get the tag.
5455 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5456 has_document_tag_ = true;
5457 }
5458#endif
5459}
[email protected]12636df2009-09-28 22:32:215460
[email protected]43f28f832010-02-03 02:28:485461#if defined(OS_MACOSX)
[email protected]935d63d2010-10-15 23:31:555462void RenderView::SetPluginImeEnabled(bool enabled, int plugin_id) {
5463 IPC::Message* msg = new ViewHostMsg_SetPluginImeEnabled(routing_id(),
5464 enabled, plugin_id);
5465 // This message can be sent during event-handling, and needs to be delivered
5466 // within that context.
5467 msg->set_unblock(true);
5468 Send(msg);
5469}
5470
[email protected]ea04a4e12010-04-15 00:58:035471gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235472 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485473 gfx::PluginWindowHandle window = NULL;
5474 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235475 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115476 if (window) {
5477 fake_plugin_window_handles_.insert(window);
5478 }
[email protected]43f28f832010-02-03 02:28:485479 return window;
5480}
5481
5482void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115483 if (window && fake_plugin_window_handles_.find(window) !=
5484 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485485 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115486 fake_plugin_window_handles_.erase(window);
5487 }
[email protected]43f28f832010-02-03 02:28:485488}
5489
[email protected]44ce0b12010-03-12 16:45:335490void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5491 int32 width,
5492 int32 height,
5493 uint64 io_surface_identifier) {
5494 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485495 routing_id(), window, width, height, io_surface_identifier));
5496}
5497
[email protected]44ce0b12010-03-12 16:45:335498void RenderView::AcceleratedSurfaceSetTransportDIB(
5499 gfx::PluginWindowHandle window,
5500 int32 width,
5501 int32 height,
5502 TransportDIB::Handle transport_dib) {
5503 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075504 routing_id(), window, width, height, transport_dib));
5505}
5506
[email protected]44ce0b12010-03-12 16:45:335507TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5508 size_t size) {
[email protected]1aef98132010-02-23 18:00:075509 TransportDIB::Handle dib_handle;
5510 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385511 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075512 return dib_handle;
5513 // Return an invalid handle if Send() fails.
5514 return TransportDIB::DefaultHandleValue();
5515}
5516
[email protected]44ce0b12010-03-12 16:45:335517void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075518 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5519}
5520
[email protected]44ce0b12010-03-12 16:45:335521void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145522 gfx::PluginWindowHandle window, uint64 surface_id) {
5523 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5524 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485525}
5526#endif
[email protected]58c321d2010-02-19 12:11:285527
[email protected]cdaf8d02010-03-30 19:52:475528bool RenderView::ScheduleFileChooser(
5529 const ViewHostMsg_RunFileChooser_Params& params,
5530 WebFileChooserCompletion* completion) {
5531 static const size_t kMaximumPendingFileChooseRequests = 4;
5532 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5533 // This sanity check prevents too many file choose requests from getting
5534 // queued which could DoS the user. Getting these is most likely a
5535 // programming error (there are many ways to DoS the user so it's not
5536 // considered a "real" security check), either in JS requesting many file
5537 // choosers to pop up, or in a plugin.
5538 //
5539 // TODO(brettw) we might possibly want to require a user gesture to open
5540 // a file picker, which will address this issue in a better way.
5541 return false;
5542 }
5543
5544 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5545 new PendingFileChooser(params, completion)));
5546 if (file_chooser_completions_.size() == 1) {
5547 // Actually show the browse dialog when this is the first request.
5548 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5549 }
5550 return true;
5551}
5552
[email protected]290838a2010-04-27 17:37:015553void RenderView::OnPageTranslated() {
5554 WebFrame* frame = webview()->mainFrame();
5555 if (!frame)
5556 return;
5557
[email protected]676126f72011-01-15 00:03:515558 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015559}
5560
[email protected]0ff0ff32010-12-21 19:34:425561WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515562 if (!geolocation_dispatcher_)
5563 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5564 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255565}
[email protected]61c9f032010-03-31 23:04:195566
[email protected]638694c2010-08-04 22:24:115567WebKit::WebSpeechInputController* RenderView::speechInputController(
5568 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515569 if (!speech_input_dispatcher_)
5570 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5571 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115572}
5573
[email protected]57ead352010-08-11 14:42:535574WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515575 if (!device_orientation_dispatcher_)
5576 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5577 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535578}
5579
[email protected]b75b8292010-10-01 07:28:255580void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5581 // For now, don't remember plugin zoom values. We don't want to mix them with
5582 // normal web content (i.e. a fixed layout plugin would usually want them
5583 // different).
5584 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5585
[email protected]b75b8292010-10-01 07:28:255586 int minimum_percent = static_cast<int>(
5587 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5588 int maximum_percent = static_cast<int>(
5589 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255590
5591 Send(new ViewHostMsg_UpdateZoomLimits(
5592 routing_id_, minimum_percent, maximum_percent, remember));
5593}
5594
5595void RenderView::zoomLevelChanged() {
5596 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5597
[email protected]b75b8292010-10-01 07:28:255598 // Tell the browser which url got zoomed so it can update the menu and the
5599 // saved values if necessary
5600 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415601 routing_id_, webview()->zoomLevel(), remember,
5602 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255603}
5604
[email protected]8079b362010-05-07 18:37:455605bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195606 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455607 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195608 if (frame->parent() != NULL)
5609 return false;
5610
[email protected]f0a3d0b2010-08-06 22:51:535611 // Navigations initiated within Webkit are not sent out to the external host
5612 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275613 // 1. The url scheme is not http/https
5614 // 2. There is no opener and this is not the first url being opened by this
5615 // RenderView.
5616 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535617 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535618 // 4. Reloads/form submits/back forward navigations
5619 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5620 return false;
5621
[email protected]2fc22d12010-12-02 23:08:165622 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325623 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015624 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165625 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015626 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325627 // The opener relationship between the new window and the parent allows the
5628 // new window to script the parent and vice versa. This is not allowed if
5629 // the origins of the two domains are different. This can be treated as a
5630 // top level navigation and routed back to the host.
5631 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275632 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475633 // Force link click navigations to always be routed to the host as they
5634 // may update session state on the server.
5635 if (type == WebKit::WebNavigationTypeLinkClicked)
5636 return true;
[email protected]900eb2f12010-08-23 22:36:275637 // If this is the first page being loaded by this RenderView instance then
5638 // it should stay here.
5639 if (page_id_ == -1) {
5640 return false;
5641 } else {
[email protected]d0ed50d2010-06-22 01:01:325642 return true;
[email protected]900eb2f12010-08-23 22:36:275643 }
[email protected]d0ed50d2010-06-22 01:01:325644 }
[email protected]900eb2f12010-08-23 22:36:275645
5646 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5647 return true;
[email protected]d0ed50d2010-06-22 01:01:325648 }
[email protected]61c9f032010-03-31 23:04:195649 return false;
5650}
[email protected]2b06a992010-08-21 05:48:225651
[email protected]27a9ef32010-09-10 04:06:245652void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5653 IPC::PlatformFileForTransit file_for_transit,
5654 int message_id) {
5655 pepper_delegate_.OnAsyncFileOpened(
5656 error_code,
5657 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5658 message_id);
5659}
[email protected]caf706f2010-10-26 17:54:085660
5661#if defined(OS_MACOSX)
5662void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155663 if (external_popup_menu_ == NULL) {
5664 // Crash reports from the field indicate that we can be notified with a
5665 // NULL external popup menu (we probably get notified twice).
5666 // If you hit this please file a bug against jcivelli and include the page
5667 // and steps to repro.
5668 NOTREACHED();
5669 return;
5670 }
[email protected]caf706f2010-10-26 17:54:085671 external_popup_menu_->DidSelectItem(selected_index);
5672 external_popup_menu_.reset();
5673}
5674#endif
[email protected]bb461532010-11-26 21:50:235675
5676void RenderView::AddErrorToRootConsole(const string16& message) {
5677 if (webview() && webview()->mainFrame()) {
5678 webview()->mainFrame()->addMessageToConsole(
5679 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5680 }
5681}
[email protected]1b4209f2011-01-07 00:25:405682
5683#if defined(ENABLE_FLAPPER_HACKS)
5684void RenderView::OnConnectTcpACK(
5685 int request_id,
5686 IPC::PlatformFileForTransit socket_for_transit,
5687 const PP_Flash_NetAddress& local_addr,
5688 const PP_Flash_NetAddress& remote_addr) {
5689 pepper_delegate_.OnConnectTcpACK(
5690 request_id,
5691 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5692 local_addr,
5693 remote_addr);
5694}
5695#endif
[email protected]a6097f42011-01-10 08:50:515696
5697void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5698 if (cmd == kJavaScriptStressTestSetStressRunType) {
5699 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5700 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5701 v8::Testing::PrepareStressRun(param);
5702 }
5703}