blob: 0b17633e88d299e6dc6a971344c3aba2da686b12 [file] [log] [blame]
[email protected]810a52ef2010-01-08 01:22:151// Copyright (c) 2010 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]37126212009-05-06 02:23:3112#include "app/message_box_flags.h"
[email protected]57b66d02010-09-30 11:24:5113#include "app/l10n_util.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]835d7c82010-10-14 04:38:3818#include "base/metrics/field_trial.h"
19#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"
[email protected]7b291f92009-08-14 05:43:5322#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_piece.h"
24#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2325#include "base/time.h"
[email protected]55126132010-08-19 14:53:2826#include "base/sys_string_conversions.h"
[email protected]be1ce6a72010-08-03 14:35:2227#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5728#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2129#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0930#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5531#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1732#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2833#include "chrome/common/chrome_paths.h"
34#include "chrome/common/chrome_switches.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"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2139#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1740#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5341#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2942#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0243#include "chrome/common/render_messages_params.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]534c66c2010-04-28 22:53:1147#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2549#include "chrome/renderer/audio_message_filter.h"
[email protected]6a8ddba52010-09-05 04:38:0650#include "chrome/renderer/autofill_helper.h"
[email protected]2f979172010-09-16 21:54:0351#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4052#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5353#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1154#include "chrome/renderer/devtools_agent.h"
55#include "chrome/renderer/devtools_client.h"
[email protected]2f979172010-09-16 21:54:0356#include "chrome/renderer/dom_ui_bindings.h"
[email protected]912256b32009-09-18 09:47:3557#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0458#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]5351dbc2010-08-27 15:22:1159#include "chrome/renderer/extensions/extension_renderer_info.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]7120f132009-07-20 21:05:3762#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0363#include "chrome/renderer/external_host_bindings.h"
[email protected]58c321d2010-02-19 12:11:2864#include "chrome/renderer/geolocation_dispatcher.h"
[email protected]3bb08602010-10-07 21:47:1765#include "chrome/renderer/ggl/ggl.h"
initial.commit09911bf2008-07-26 23:55:2966#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5667#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4168#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]8400e032010-02-26 18:50:1169#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5670#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1271#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0672#include "chrome/renderer/page_click_tracker.h"
73#include "chrome/renderer/password_autocomplete_manager.h"
[email protected]8beff0762009-09-29 02:18:3074#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5075#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2576#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2877#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2678#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1879#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3980#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2181#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3482#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]638694c2010-08-04 22:24:1183#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4684#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3585#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2986#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2987#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2988#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4289#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5690#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1591#include "gfx/color_utils.h"
92#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5793#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2694#include "gfx/point.h"
95#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2796#include "grit/generated_resources.h"
97#include "grit/renderer_resources.h"
[email protected]ee68378a2010-08-10 01:05:4198#include "media/base/media_switches.h"
[email protected]f11ca0732009-04-11 00:09:3499#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29100#include "net/base/escape.h"
101#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:00102#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10103#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:30104#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:06105#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:49106#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:26107#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:07108#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:49109#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
110#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:32111#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49112#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:35113#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]7a4de7a62010-08-17 18:38:24114#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]2b06a992010-08-21 05:48:22115#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
116#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
[email protected]b1438212010-04-03 00:30:59117#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49118#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
119#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
[email protected]3bb08602010-10-07 21:47:17120#include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
[email protected]418ed5ab2009-11-12 01:14:49121#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41122#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50123#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49124#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32125#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07126#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49127#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40128#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17129#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49130#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49131#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
132#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
133#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
134#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
135#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
136#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40137#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49138#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34139#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49140#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
141#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
142#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
143#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
144#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
145#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26146#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11147#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]882b7b22010-10-05 03:34:53148#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04149#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]7a4de7a62010-08-17 18:38:24150#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29151#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59152#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24153#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24154#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34155#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26156#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17157#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51158#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09159#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26160#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38161#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17162#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29163#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30164#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23165#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30166#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40167#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09168#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24169#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29170#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29171#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17172#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29173
[email protected]6c8afae52009-01-22 02:24:57174#if defined(OS_WIN)
175// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57176// * theming
[email protected]cd818412010-03-19 03:23:15177#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03178#elif defined(USE_X11)
[email protected]8d1b864d12010-10-10 00:04:34179#include "gfx/native_theme_linux.h"
[email protected]39cd64ed2010-02-05 02:18:46180#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33181#elif defined(OS_MACOSX)
182#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57183#endif
184
[email protected]80f584d92010-01-21 03:59:04185using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26186using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33187using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45188using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59189using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24190using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17191using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56192using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10193using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09194using webkit_glue::SiteIsolationMetrics;
[email protected]416ac2e2010-09-01 17:15:16195using webkit_glue::WebAccessibility;
[email protected]c7287a92009-11-04 20:06:15196using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42197using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08198using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21199using WebKit::WebApplicationCacheHost;
200using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41201using WebKit::WebColor;
202using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59203using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44204using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51205using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07206using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55207using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28208using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29209using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00210using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58211using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25212using WebKit::WebDragOperation;
213using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51214using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47215using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22216using WebKit::WebFileSystem;
217using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49218using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59219using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48220using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45221using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17222using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41223using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50224using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17225using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28226using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17227using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28228using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28229using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51230using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07231using WebKit::WebPageSerializer;
232using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17233using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40234using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49235using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09236using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52237using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59238using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51239using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52240using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40241using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35242using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29243using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59244using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42245using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02246using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34247using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28248using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51249using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52250using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28251using WebKit::WebURL;
252using WebKit::WebURLError;
253using WebKit::WebURLRequest;
254using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28255using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03256using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28257using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43258using WebKit::WebWorker;
259using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11260using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33261
initial.commit09911bf2008-07-26 23:55:29262//-----------------------------------------------------------------------------
263
[email protected]3354d3e2010-06-10 19:53:02264typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
265
initial.commit09911bf2008-07-26 23:55:29266// define to write the time necessary for thumbnail/DOM text retrieval,
267// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29268// #define TIME_TEXT_RETRIEVAL
269
270// maximum number of characters in the document to index, any text beyond this
271// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57272static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29273
274// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37275static const int kThumbnailWidth = 212;
276static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29277
278// Delay in milliseconds that we'll wait before capturing the page contents
279// and thumbnail.
280static const int kDelayForCaptureMs = 500;
281
282// Typically, we capture the page data once the page is loaded.
283// Sometimes, the page never finishes to load, preventing the page capture
284// To workaround this problem, we always perform a capture after the following
285// delay.
286static const int kDelayForForcedCaptureMs = 6000;
287
[email protected]882daa92009-11-05 16:31:31288// Time, in seconds, we delay before sending content state changes (such as form
289// state and scroll position) to the browser. We delay sending changes to avoid
290// spamming the browser.
291// To avoid having tab/session restore require sending a message to get the
292// current content state during tab closing we use a shorter timeout for the
293// foreground renderer. This means there is a small window of time from which
294// content state is modified and not sent to session restore, but this is
295// better than having to wake up all renderers during shutdown.
296static const int kDelaySecondsForContentStateSyncHidden = 5;
297static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29298
[email protected]0aa55312008-10-17 21:53:08299// The maximum number of popups that can be spawned from one page.
300static const int kMaximumNumberOfUnacknowledgedPopups = 25;
301
initial.commit09911bf2008-07-26 23:55:29302static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16303 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29304
[email protected]50b691c2008-10-31 19:08:35305static const char* const kBackForwardNavigationScheme = "history";
306
[email protected]726985e22009-06-18 21:09:28307static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
308 WebVector<WebURL> urls;
309 ds->redirectChain(urls);
310 result->reserve(urls.size());
311 for (size_t i = 0; i < urls.size(); ++i)
312 result->push_back(urls[i]);
313}
314
[email protected]30507922010-01-15 16:48:23315static bool PaintViewIntoCanvas(WebView* view,
316 skia::PlatformCanvas& canvas) {
317 view->layout();
318 const WebSize& size = view->size();
319
320 if (!canvas.initialize(size.width, size.height, true))
321 return false;
322
323 view->paint(webkit_glue::ToWebCanvas(&canvas),
324 WebRect(0, 0, size.width, size.height));
325 // TODO: Add a way to snapshot the whole page, not just the currently
326 // visible part.
327
328 return true;
329}
330
331// Calculates how "boring" a thumbnail is. The boring score is the
332// 0,1 ranged percentage of pixels that are the most common
333// luma. Higher boring scores indicate that a higher percentage of a
334// bitmap are all the same brightness.
335static double CalculateBoringScore(SkBitmap* bitmap) {
336 int histogram[256] = {0};
337 color_utils::BuildLumaHistogram(bitmap, histogram);
338
339 int color_count = *std::max_element(histogram, histogram + 256);
340 int pixel_count = bitmap->width() * bitmap->height();
341 return static_cast<double>(color_count) / pixel_count;
342}
343
[email protected]12bc8472010-04-15 07:29:40344// True if |frame| contains content that is white-listed for content settings.
345static bool IsWhitelistedForContentSettings(WebFrame* frame) {
346 WebSecurityOrigin origin = frame->securityOrigin();
347 if (origin.isEmpty())
348 return false; // Uninitialized document?
349
350 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
351 return true; // Browser UI elements should still work.
352
353 // If the scheme is ftp: or file:, an empty file name indicates a directory
354 // listing, which requires JavaScript to function properly.
355 GURL frame_url = frame->url();
356 const char* kDirProtocols[] = { "ftp", "file" };
357 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
358 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
359 return frame_url.SchemeIs(kDirProtocols[i]) &&
360 frame_url.ExtractFileName().empty();
361 }
362 }
363
364 return false;
365}
366
[email protected]3a8eecb2010-04-22 23:56:30367// Returns true if the frame is navigating to an URL either into or out of an
368// extension app's extent.
369static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
370 if (!RenderThread::current())
371 return false;
372
373 // If the URL is still empty, this is a window.open navigation. Check the
374 // opener's URL.
375 GURL old_url(frame->url());
376 if (old_url.is_empty() && frame->opener())
377 old_url = frame->opener()->url();
378
[email protected]5351dbc2010-08-27 15:22:11379 return !ExtensionRendererInfo::InSameExtent(old_url, new_url);
[email protected]3a8eecb2010-04-22 23:56:30380}
381
[email protected]3354d3e2010-06-10 19:53:02382// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
383// if it failed.
[email protected]e5106202010-06-11 21:12:36384static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17385 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02386 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08387 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02388 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02389 Language cld_language =
[email protected]e5106202010-06-11 21:12:36390 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08391 &num_languages, NULL, &text_bytes);
392 // We don't trust the result if the CLD reports that the detection is not
393 // reliable, or if the actual text used to detect the language was less than
394 // 100 bytes (short texts can often lead to wrong results).
395 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02396 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
397 // We should not use LanguageCode_ISO_639_1 because it does not cover all
398 // the languages CLD can detect. As a result, it'll return the invalid
399 // language code for tradtional Chinese among others.
400 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
401 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
402 // for Simplified Chinese.
403 language = LanguageCodeWithDialects(cld_language);
404 }
405 return language;
406}
407
initial.commit09911bf2008-07-26 23:55:29408///////////////////////////////////////////////////////////////////////////////
409
[email protected]60c42a8c72009-10-09 04:08:59410int32 RenderView::next_page_id_ = 1;
411
[email protected]cdaf8d02010-03-30 19:52:47412struct RenderView::PendingFileChooser {
413 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
414 WebFileChooserCompletion* c)
415 : params(p),
416 completion(c) {
417 }
418 ViewHostMsg_RunFileChooser_Params params;
419 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
420};
421
[email protected]2fab253a2009-08-17 23:00:59422RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34423 const WebPreferences& webkit_preferences,
424 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12425 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02426 webkit_preferences_(webkit_preferences),
427 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09428 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02429 send_preferred_size_changes_(false),
430 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24431 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21432 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02433 opened_by_user_gesture_(true),
434 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24435 page_id_(-1),
436 last_page_id_sent_to_browser_(-1),
437 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00438 history_list_offset_(-1),
439 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24440 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55441#if defined(OS_MACOSX)
442 has_document_tag_(false),
443#endif
[email protected]98324892009-09-09 21:16:05444 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10445 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17446 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02447 target_url_status_(TARGET_NONE),
448 spelling_panel_visible_(false),
449 view_type_(ViewType::INVALID),
450 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18451 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30452 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
453 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02454 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
455 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
456 ALLOW_THIS_IN_INITIALIZER_LIST(
457 notification_provider_(new NotificationProvider(this))),
458 session_storage_namespace_id_(session_storage_namespace_id),
459 decrement_shared_popup_at_destruction_(false) {
[email protected]6a8ddba52010-09-05 04:38:06460 password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this));
461 autofill_helper_.reset(new AutoFillHelper(this));
462 page_click_tracker_.reset(new PageClickTracker(this));
463 // Note that the order of insertion of the listeners is important.
464 // The password_autocomplete_manager_ takes the first shot at processing the
465 // notification and can stop the propagation.
466 page_click_tracker_->AddListener(password_autocomplete_manager_.get());
467 page_click_tracker_->AddListener(autofill_helper_.get());
[email protected]71b0d5d2010-02-15 05:43:07468 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29469}
470
471RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08472 if (decrement_shared_popup_at_destruction_)
473 shared_popup_counter_->data--;
474
[email protected]b0950a72009-09-29 23:16:17475 // Dispose of un-disposed image fetchers.
476 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
477 i != image_fetchers_.end(); ++i) {
478 delete *i;
479 }
480
[email protected]a1128322009-10-06 18:38:46481 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47482 while (!file_chooser_completions_.empty()) {
483 if (file_chooser_completions_.front()->completion) {
484 file_chooser_completions_.front()->completion->didChooseFile(
485 WebVector<WebString>());
486 }
487 file_chooser_completions_.pop_front();
488 }
[email protected]a1128322009-10-06 18:38:46489
[email protected]83dde542009-09-11 20:59:55490#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05491 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55492 if (has_document_tag_)
493 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11494
495 // Destroy all fake plugin window handles on the browser side.
496 while (!fake_plugin_window_handles_.empty()) {
497 // Make sure no NULL plugin window handles were inserted into this list.
498 DCHECK(*fake_plugin_window_handles_.begin());
499 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
500 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
501 }
[email protected]83dde542009-09-11 20:59:55502#endif
[email protected]98324892009-09-09 21:16:05503
[email protected]5fb88962009-04-16 19:03:25504 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59505
506#ifndef NDEBUG
507 // Make sure we are no longer referenced by the ViewMap.
508 ViewMap* views = Singleton<ViewMap>::get();
509 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
510 DCHECK_NE(this, it->second) << "Failed to call Close?";
511#endif
512}
513
514/*static*/
515void RenderView::ForEach(RenderViewVisitor* visitor) {
516 ViewMap* views = Singleton<ViewMap>::get();
517 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
518 if (!visitor->Visit(it->second))
519 return;
520 }
521}
522
523/*static*/
524RenderView* RenderView::FromWebView(WebView* webview) {
525 ViewMap* views = Singleton<ViewMap>::get();
526 ViewMap::iterator it = views->find(webview);
527 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29528}
529
530/*static*/
[email protected]0aa55312008-10-17 21:53:08531RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24532 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15533 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08534 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51535 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08536 const WebPreferences& webkit_prefs,
537 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34538 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26539 int64 session_storage_namespace_id,
540 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29541 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34542 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
543 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29544 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29545 opener_id,
[email protected]80d96fa2009-06-10 22:34:51546 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08547 counter,
[email protected]8ab04652010-06-12 02:47:26548 routing_id,
549 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29550 return view;
551}
552
553/*static*/
554void RenderView::SetNextPageID(int32 next_page_id) {
555 // This method should only be called during process startup, and the given
556 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05557 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29558 DCHECK(next_page_id >= next_page_id_);
559 next_page_id_ = next_page_id;
560}
561
[email protected]8a3125a712010-08-09 18:58:51562WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26563 return static_cast<WebKit::WebView*>(webwidget());
564}
565
[email protected]afe3a1672009-11-17 19:04:12566void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56567 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
568}
569
[email protected]a3a8fb6d2009-10-22 20:12:51570void RenderView::PluginCrashed(const FilePath& plugin_path) {
571 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29572}
573
[email protected]aad51d1c2010-08-05 08:38:09574WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
575 const WebPluginParams& params) {
[email protected]20a793e2010-10-12 06:50:08576 std::vector<WebPluginInfo> info;
577 std::vector<ContentSetting> settings;
578 std::vector<std::string> mime_types;
579 Send(new ViewHostMsg_GetPluginInfoArray(
580 params.url, frame->top()->url(), params.mimeType.utf8(),
581 &info, &settings, &mime_types));
582
583 // Select the first plugin returned, but only if it's enabled.
584 if (info.empty() || !info[0].enabled)
[email protected]aad51d1c2010-08-05 08:38:09585 return NULL;
586 scoped_refptr<pepper::PluginModule> pepper_module =
[email protected]20a793e2010-10-12 06:50:08587 PepperPluginRegistry::GetInstance()->GetModule(info[0].path);
[email protected]aad51d1c2010-08-05 08:38:09588 if (pepper_module)
[email protected]20a793e2010-10-12 06:50:08589 return CreatePepperPlugin(frame, params, info[0].path, pepper_module.get());
[email protected]aad51d1c2010-08-05 08:38:09590 else
[email protected]20a793e2010-10-12 06:50:08591 return CreateNPAPIPlugin(frame, params, info[0].path, mime_types[0]);
[email protected]aad51d1c2010-08-05 08:38:09592}
593
[email protected]d8fd6fa2010-02-01 15:54:26594void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
595 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30596 // If the renderer is visible, set initial visibility and focus state.
597 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34598#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30599 delegate->SetContainerVisibility(true);
600 if (webview() && webview()->isActive())
601 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34602#endif
[email protected]49232292010-09-03 19:07:30603 }
[email protected]784ea1ab2010-09-18 00:02:34604 // Plugins start assuming the content has focus (so that they work in
605 // environments where RenderView isn't hosting them), so we always have to
606 // set the initial state. See webplugin_delegate_impl.h for details.
607 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26608}
609
610void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
611 plugin_delegates_.erase(delegate);
612}
[email protected]d8fd6fa2010-02-01 15:54:26613
[email protected]18bcc3c2009-01-27 21:39:15614void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29615 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51616 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08617 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26618 int32 routing_id,
619 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29620 DCHECK(!webview());
621
622 if (opener_id != MSG_ROUTING_NONE)
623 opener_id_ = opener_id;
624
[email protected]0aa55312008-10-17 21:53:08625 if (counter) {
626 shared_popup_counter_ = counter;
627 shared_popup_counter_->data++;
628 decrement_shared_popup_at_destruction_ = true;
629 } else {
630 shared_popup_counter_ = new SharedRenderViewCounter(0);
631 decrement_shared_popup_at_destruction_ = false;
632 }
633
[email protected]58bfc6b2009-06-24 09:45:02634 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04635
[email protected]9a6c6232010-06-25 11:46:49636 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59637 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59638 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27639 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23640 if (!frame_name.empty())
641 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29642
[email protected]d3ba77272009-09-03 00:06:09643 OnSetRendererPrefs(renderer_prefs);
644
initial.commit09911bf2008-07-26 23:55:29645 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24646 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29647 // Take a reference on behalf of the RenderThread. This will be balanced
648 // when we receive ViewMsg_Close.
649 AddRef();
650
651 // If this is a popup, we must wait for the CreatingNew_ACK message before
652 // completing initialization. Otherwise, we can finish it now.
653 if (opener_id == MSG_ROUTING_NONE) {
654 did_show_ = true;
655 CompleteInit(parent_hwnd);
656 }
657
658 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29659
[email protected]58bfc6b2009-06-24 09:45:02660 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09661 if (command_line.HasSwitch(switches::kDomAutomationController))
662 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
[email protected]dea2d372010-09-25 06:41:14663 if (command_line.HasSwitch(switches::kEnableAccessibility))
664 WebAccessibilityCache::enableAccessibility();
initial.commit09911bf2008-07-26 23:55:29665
[email protected]5fb88962009-04-16 19:03:25666 audio_message_filter_ = new AudioMessageFilter(routing_id_);
667 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29668}
669
670void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27671 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27672 if (main_frame)
673 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26674
[email protected]b2abac72009-02-26 12:39:28675 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11676 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28677 return;
[email protected]b4b967e2009-04-22 11:33:05678 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
679 return;
[email protected]b6849bda2009-10-14 23:59:26680 if (notification_provider_->OnMessageReceived(message))
681 return;
[email protected]58c321d2010-02-19 12:11:28682 if (geolocation_dispatcher_.get() &&
683 geolocation_dispatcher_->OnMessageReceived(message)) {
684 return;
685 }
[email protected]638694c2010-08-04 22:24:11686 if (speech_input_dispatcher_.get() &&
687 speech_input_dispatcher_->OnMessageReceived(message)) {
688 return;
689 }
[email protected]57ead352010-08-11 14:42:53690 if (device_orientation_dispatcher_.get() &&
691 device_orientation_dispatcher_->OnMessageReceived(message)) {
692 return;
693 }
[email protected]b2abac72009-02-26 12:39:28694
initial.commit09911bf2008-07-26 23:55:29695 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04696 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
697 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29698 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01699 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29700 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
701 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56702 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29703 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
704 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
705 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
706 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27707#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35708 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27709#endif
initial.commit09911bf2008-07-26 23:55:29710 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
711 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05712 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
713 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
714 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04715 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29716 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
717 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
718 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15719 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29720 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49721 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
722 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17723 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54724 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
725 OnSetContentSettingsForLoadingURL)
726 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
727 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29728 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18729 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
730 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28731 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33732 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29733 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48734 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29735 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29736 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29737 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
738 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
739 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
740 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
741 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45742 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29743 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50744 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
745 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29746 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
747 OnDragSourceSystemDragEnded)
748 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29749 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
750 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
751 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
752 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:21753 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:29754 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
755 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29756 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
757 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04758 IPC_MESSAGE_HANDLER(
759 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
760 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29761 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04762 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29763 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
764 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45765 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04766 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08767 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
768 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24769 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
770 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48771 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
772 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40773 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
774 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00775 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27776 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37777 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
778 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16779 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14780 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25781 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
782 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10783 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
784 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51785 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53786 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
787 OnUpdateBrowserWindowId)
788 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
789 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56790 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34791 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14792#if defined(OS_MACOSX)
793 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13794 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14795#endif
[email protected]446705872009-09-10 07:22:48796 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33797 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35798 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
799 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33800 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
801 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42802 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02803 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]dea2d372010-09-25 06:41:14804 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:36805 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
806 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
807 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42808 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
809 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:24810 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]634a6f92008-12-01 21:39:31811
initial.commit09911bf2008-07-26 23:55:29812 // Have the super handle all other messages.
813 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
814 IPC_END_MESSAGE_MAP()
815}
816
[email protected]9b18a84f2010-06-10 15:54:04817void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27818 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29819 if (!main_frame)
820 return;
821
822 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45823 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29824 if (url.is_empty())
825 return;
826
827 if (size_.IsEmpty())
828 return; // Don't create an empty thumbnail!
829
830 ThumbnailScore score;
831 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02832 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15833 &thumbnail, &score))
834 return;
835
initial.commit09911bf2008-07-26 23:55:29836 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46837 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29838}
839
[email protected]9b18a84f2010-06-10 15:54:04840void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23841 SkBitmap snapshot;
842 bool error = false;
843
844 WebFrame* main_frame = webview()->mainFrame();
845 if (!main_frame)
846 error = true;
847
848 if (!error && !CaptureSnapshot(webview(), &snapshot))
849 error = true;
850
851 DCHECK(error == snapshot.empty()) <<
852 "Snapshot should be empty on error, non-empty otherwise.";
853
854 // Send the snapshot to the browser process.
855 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
856}
857
[email protected]068637222009-01-29 16:58:07858void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29859 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58860 if (webview()) {
861 // If the user has selected text in the currently focused frame we print
862 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27863 if (webview()->focusedFrame()->hasSelection())
864 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58865 else
[email protected]26aa0482009-09-30 16:55:27866 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58867 }
initial.commit09911bf2008-07-26 23:55:29868}
869
[email protected]82270452009-06-19 15:58:01870void RenderView::OnPrintingDone(int document_cookie, bool success) {
871 // Ignoring document cookie here since only one print job can be outstanding
872 // per renderer and document_cookie is 0 when printing is successful.
873 DCHECK(print_helper_.get());
874 if (print_helper_.get() != NULL) {
875 print_helper_->DidFinishPrinting(success);
876 }
877}
878
initial.commit09911bf2008-07-26 23:55:29879void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
880 if (load_id != page_id_)
881 return; // this capture call is no longer relevant due to navigation
882 if (load_id == last_indexed_page_id_)
883 return; // we already indexed this page
884
885 if (!webview())
886 return;
887
[email protected]26aa0482009-09-30 16:55:27888 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29889 if (!main_frame)
890 return;
891
892 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45893 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29894 return;
895
896 // Don't index/capture pages that failed to load. This only checks the top
897 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45898 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28899 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29900 return;
901
902 if (!preliminary_capture)
903 last_indexed_page_id_ = load_id;
904
[email protected]a8a81292010-01-21 00:32:45905 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45906 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29907 if (url.is_empty())
908 return;
909
[email protected]a8a81292010-01-21 00:32:45910 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36911 string16 contents;
initial.commit09911bf2008-07-26 23:55:29912 CaptureText(main_frame, &contents);
913 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:10914 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:37915 // If the page explicitly specifies a language, use it, otherwise we'll
916 // determine it based on the text content using the CLD.
917 std::string language =
918 TranslateHelper::GetPageLanguageFromMetaTag(&document);
919 if (language.empty()) {
920 base::TimeTicks begin_time = base::TimeTicks::Now();
921 language = DetermineTextLanguage(contents);
922 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
923 base::TimeTicks::Now() - begin_time);
924 }
[email protected]a8a81292010-01-21 00:32:45925 // Send the text to the browser for indexing (the browser might decide not
926 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:37927 Send(new ViewHostMsg_PageContents(
928 routing_id_, url, load_id, contents, language,
929 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27930 }
931
[email protected]9b18a84f2010-06-10 15:54:04932 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29933}
934
[email protected]e5106202010-06-11 21:12:36935void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29936 contents->clear();
937 if (!frame)
938 return;
939
940#ifdef TIME_TEXT_RETRIEVAL
941 double begin = time_util::GetHighResolutionTimeNow();
942#endif
943
944 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36945 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29946
947#ifdef TIME_TEXT_RETRIEVAL
948 double end = time_util::GetHighResolutionTimeNow();
949 char buf[128];
950 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
951 contents.size(), (end - begin)*1000);
952 OutputDebugStringA(buf);
953#endif
954
955 // When the contents are clipped to the maximum, we don't want to have a
956 // partial word indexed at the end that might have been clipped. Therefore,
957 // terminate the string at the last space to ensure no words are clipped.
958 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36959 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29960 if (last_space_index == std::wstring::npos)
961 return; // don't index if we got a huge block of text with no spaces
962 contents->resize(last_space_index);
963 }
964}
965
[email protected]8649fb32009-06-26 17:51:02966bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29967 int w,
968 int h,
969 SkBitmap* thumbnail,
970 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23971 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15972
[email protected]8649fb32009-06-26 17:51:02973 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23974
975 // Paint |view| into |canvas|.
976 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02977 return false;
[email protected]8649fb32009-06-26 17:51:02978
979 skia::BitmapPlatformDevice& device =
980 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
981
982 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29983
[email protected]cab34d6a2009-09-24 01:14:52984 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29985 float dest_aspect = dest_rect.width() / dest_rect.height();
986
987 // Get the src rect so that we can preserve the aspect ratio while filling
988 // the destination.
989 SkIRect src_rect;
990 if (src_bmp.width() < dest_rect.width() ||
991 src_bmp.height() < dest_rect.height()) {
992 // Source image is smaller: we clip the part of source image within the
993 // dest rect, and then stretch it to fill the dest rect. We don't respect
994 // the aspect ratio in this case.
995 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
996 static_cast<S16CPU>(dest_rect.height()));
997 score->good_clipping = false;
998 } else {
999 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1000 if (src_aspect > dest_aspect) {
1001 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1002 // the wider screen.
1003 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1004 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1005 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1006 score->good_clipping = false;
1007 } else {
1008 src_rect.set(0, 0, src_bmp.width(),
1009 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1010 score->good_clipping = true;
1011 }
1012 }
1013
[email protected]26aa0482009-09-30 16:55:271014 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291015
1016 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021017 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291018
1019 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:141020 *thumbnail = skia::ImageOperations::Resize(
1021 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291022
1023 score->boring_score = CalculateBoringScore(thumbnail);
1024
[email protected]30507922010-01-15 16:48:231025 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1026 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:151027 return true;
initial.commit09911bf2008-07-26 23:55:291028}
1029
[email protected]30507922010-01-15 16:48:231030bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1031 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291032
[email protected]30507922010-01-15 16:48:231033 skia::PlatformCanvas canvas;
1034 if (!PaintViewIntoCanvas(view, canvas))
1035 return false;
1036
1037 skia::BitmapPlatformDevice& device =
1038 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1039
1040 const SkBitmap& bitmap = device.accessBitmap(false);
1041 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1042 return false;
1043
1044 HISTOGRAM_TIMES("Renderer4.Snapshot",
1045 base::TimeTicks::Now() - beginning_time);
1046 return true;
initial.commit09911bf2008-07-26 23:55:291047}
1048
1049void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1050 if (!webview())
1051 return;
1052
[email protected]3cc72b12010-03-18 23:03:001053 history_list_offset_ = params.current_history_list_offset;
1054 history_list_length_ = params.current_history_list_length;
1055
[email protected]8c785c62009-07-13 14:20:151056 if (devtools_agent_.get())
1057 devtools_agent_->OnNavigate();
1058
[email protected]422197532010-01-25 17:38:231059 if (notification_provider_.get())
1060 notification_provider_->OnNavigate();
1061
[email protected]a9f607e2009-10-23 19:59:271062 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261063
initial.commit09911bf2008-07-26 23:55:291064 AboutHandler::MaybeHandle(params.url);
1065
[email protected]ecbf10d2010-02-18 13:03:291066 bool is_reload =
1067 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1068 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291069
[email protected]26aa0482009-09-30 16:55:271070 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451071 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291072 // We cannot reload if we do not have any history state. This happens, for
1073 // example, when recovering from a crash. Our workaround here is a bit of
1074 // a hack since it means that reload after a crashed tab does not cause an
1075 // end-to-end cache validation.
1076 is_reload = false;
1077 }
1078
[email protected]77f17a82009-05-21 04:42:541079 // A navigation resulting from loading a javascript URL should not be treated
1080 // as a browser initiated event. Instead, we want it to look as if the page
1081 // initiated any load resulting from JS execution.
1082 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301083 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001084 params.page_id,
1085 params.pending_history_list_offset,
1086 params.transition,
1087 params.request_time);
[email protected]5e369672009-11-03 23:48:301088 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1089 // We're doing a load of a page that was restored from the last session.
1090 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1091 // which can result in stale data for pages that are set to expire. We
1092 // explicitly override that by setting the policy here so that as
1093 // necessary we load from the network.
1094 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1095 }
1096 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541097 }
initial.commit09911bf2008-07-26 23:55:291098
[email protected]a7ccc4d2010-01-27 08:14:481099 NavigationState* navigation_state = pending_navigation_state_.get();
1100
[email protected]04d3c6e2009-05-22 17:00:131101 // If we are reloading, then WebKit will use the history state of the current
1102 // page, so we should just ignore any given history state. Otherwise, if we
1103 // have history state, then we need to navigate to it, which corresponds to a
1104 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551105 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481106 if (navigation_state)
1107 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291108 bool ignore_cache = (params.navigation_type ==
1109 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1110 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551111 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131112 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581113 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481114 if (navigation_state)
1115 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451116 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171117 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131118 } else {
1119 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281120 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291121
[email protected]e6f546c32009-07-01 17:12:551122 // A session history navigation should have been accompanied by state.
1123 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131124
[email protected]dd7daa82009-08-10 05:46:451125 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551126 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131127
[email protected]726985e22009-06-18 21:09:281128 if (params.referrer.is_valid()) {
1129 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1130 WebString::fromUTF8(params.referrer.spec()));
1131 }
[email protected]04d3c6e2009-05-22 17:00:131132
[email protected]a7ccc4d2010-01-27 08:14:481133 if (navigation_state)
1134 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451135 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501136 }
1137
[email protected]77f17a82009-05-21 04:42:541138 // In case LoadRequest failed before DidCreateDataSource was called.
1139 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291140}
1141
1142// Stop loading the current page
1143void RenderView::OnStop() {
1144 if (webview())
[email protected]b4bb2502009-10-01 22:35:271145 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291146}
1147
[email protected]ecbf10d2010-02-18 13:03:291148// Reload current focused frame.
1149// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561150void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291151 if (webview() && webview()->focusedFrame()) {
1152 // We always obey the cache (ignore_cache=false) here.
1153 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1154 // a cache-ignoring reload of the frame.
1155 webview()->focusedFrame()->reload(false);
1156 }
[email protected]1dda4022010-01-28 18:24:561157}
1158
initial.commit09911bf2008-07-26 23:55:291159void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271160 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291161}
1162
[email protected]68b1e922009-06-23 16:00:251163void RenderView::OnExecuteEditCommand(const std::string& name,
1164 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271165 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251166 return;
1167
[email protected]26aa0482009-09-30 16:55:271168 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451169 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251170}
1171
[email protected]b2abac72009-02-26 12:39:281172void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111173 DCHECK(!devtools_client_.get());
1174 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281175}
1176
initial.commit09911bf2008-07-26 23:55:291177void RenderView::OnUpdateTargetURLAck() {
1178 // Check if there is a targeturl waiting to be sent.
1179 if (target_url_status_ == TARGET_PENDING) {
1180 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1181 pending_target_url_));
1182 }
1183
1184 target_url_status_ = TARGET_NONE;
1185}
1186
1187void RenderView::OnUndo() {
1188 if (!webview())
1189 return;
1190
[email protected]26aa0482009-09-30 16:55:271191 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121192 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291193}
1194
1195void RenderView::OnRedo() {
1196 if (!webview())
1197 return;
1198
[email protected]26aa0482009-09-30 16:55:271199 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121200 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291201}
1202
1203void RenderView::OnCut() {
1204 if (!webview())
1205 return;
1206
[email protected]26aa0482009-09-30 16:55:271207 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121208 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291209}
1210
1211void RenderView::OnCopy() {
1212 if (!webview())
1213 return;
1214
[email protected]26aa0482009-09-30 16:55:271215 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121216 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291217}
1218
[email protected]c0cc3092009-09-12 08:27:271219#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351220void RenderView::OnCopyToFindPboard() {
1221 if (!webview())
1222 return;
1223
1224 // Since the find pasteboard supports only plain text, this can be simpler
1225 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271226 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351227 if (frame->hasSelection()) {
1228 string16 selection = frame->selectionAsText();
1229 RenderThread::current()->Send(
1230 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1231 }
1232
[email protected]afe3a1672009-11-17 19:04:121233 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351234}
[email protected]c0cc3092009-09-12 08:27:271235#endif
[email protected]a954bf72009-09-12 07:30:351236
initial.commit09911bf2008-07-26 23:55:291237void RenderView::OnPaste() {
1238 if (!webview())
1239 return;
1240
[email protected]26aa0482009-09-30 16:55:271241 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121242 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291243}
1244
[email protected]2a3a7762009-10-19 19:17:321245void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291246 if (!webview())
1247 return;
1248
[email protected]1ff7a032010-02-03 02:46:031249 WebFrame* frame = webview()->focusedFrame();
1250 if (!frame->hasSelection())
1251 frame->selectWordAroundCaret();
1252 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291253}
1254
[email protected]98324892009-09-09 21:16:051255void RenderView::OnAdvanceToNextMisspelling() {
1256 if (!webview())
1257 return;
[email protected]26aa0482009-09-30 16:55:271258 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051259 WebString::fromUTF8("AdvanceToNextMisspelling"));
1260}
1261
1262void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1263 if (!webview())
1264 return;
1265 // We need to tell the webView whether the spelling panel is visible or not so
1266 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261267 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271268 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051269 WebString::fromUTF8("ToggleSpellPanel"));
1270}
1271
[email protected]bbbd545c2008-12-15 20:18:041272void RenderView::OnToggleSpellCheck() {
1273 if (!webview())
1274 return;
1275
[email protected]26aa0482009-09-30 16:55:271276 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451277 frame->enableContinuousSpellChecking(
1278 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041279}
1280
initial.commit09911bf2008-07-26 23:55:291281void RenderView::OnDelete() {
1282 if (!webview())
1283 return;
1284
[email protected]26aa0482009-09-30 16:55:271285 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121286 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291287}
1288
1289void RenderView::OnSelectAll() {
1290 if (!webview())
1291 return;
1292
[email protected]26aa0482009-09-30 16:55:271293 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221294 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121295 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291296}
1297
1298void RenderView::OnSetInitialFocus(bool reverse) {
1299 if (!webview())
1300 return;
[email protected]26aa0482009-09-30 16:55:271301 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291302}
1303
1304///////////////////////////////////////////////////////////////////////////////
1305
[email protected]433819d2010-01-30 20:20:011306void RenderView::SetContentSettings(const ContentSettings& settings) {
1307 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011308}
1309
initial.commit09911bf2008-07-26 23:55:291310// Tell the embedding application that the URL of the active page has changed
1311void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451312 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291313 DCHECK(ds);
1314
[email protected]726985e22009-06-18 21:09:281315 const WebURLRequest& request = ds->request();
1316 const WebURLRequest& original_request = ds->originalRequest();
1317 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291318
[email protected]daa8c58e2009-06-15 17:21:101319 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1320 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291321
1322 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281323 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291324 params.is_post = false;
1325 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071326 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281327 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091328 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551329 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291330 // SSL state specified in the request takes precedence over the one in the
1331 // response.
1332 // So far this is only intended for error pages that are not expected to be
1333 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281334 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551335 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291336 } else {
[email protected]726985e22009-06-18 21:09:281337 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291338 }
1339
1340 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281341 if (ds->hasUnreachableURL()) {
1342 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291343 } else {
[email protected]726985e22009-06-18 21:09:281344 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291345 }
1346
[email protected]726985e22009-06-18 21:09:281347 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241348 params.should_update_history = !ds->hasUnreachableURL() &&
1349 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291350
[email protected]ce0e250d2009-10-23 21:00:351351 params.searchable_form_url = navigation_state->searchable_form_url();
1352 params.searchable_form_encoding =
1353 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291354
1355 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101356 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291357 if (password_form_data)
1358 params.password_form = *password_form_data;
1359
1360 params.gesture = navigation_gesture_;
1361 navigation_gesture_ = NavigationGestureUnknown;
1362
[email protected]dd7daa82009-08-10 05:46:451363 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291364 // Top-level navigation.
1365
[email protected]71b0d5d2010-02-15 05:43:071366 // Clear "block" flags for the new page. This needs to happen before any of
1367 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1368 // so that these functions can correctly detect that a piece of content
1369 // flipped from "not blocked" to "blocked".
1370 ClearBlockedContentSettings();
1371
[email protected]62d2a112010-04-07 00:53:021372 // Set content settings. Default them from the parent window if one exists.
1373 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011374 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541375 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011376 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011377 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011378
1379 // These content settings were merely recorded transiently for this load.
1380 // We can erase them now. If at some point we reload this page, the
1381 // browser will send us new, up-to-date content settings.
1382 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401383 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101384 // The opener's view is not guaranteed to be non-null (it could be
1385 // detached from its page but not yet destructed).
1386 if (WebView* opener_view = frame->opener()->view()) {
1387 RenderView* opener = FromWebView(opener_view);
1388 SetContentSettings(opener->current_content_settings_);
1389 }
[email protected]f85f0702010-01-30 09:31:011390 }
1391
[email protected]b75b8292010-10-01 07:28:251392 // Set zoom level, but don't do it for full-page plugin since they don't use
1393 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011394 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541395 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251396 if (webview()->mainFrame()->document().isPluginDocument()) {
1397 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251398 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251399 } else {
1400 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251401 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251402 }
1403
[email protected]f85f0702010-01-30 09:31:011404 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511405 // This zoom level was merely recorded transiently for this load. We can
1406 // erase it now. If at some point we reload this page, the browser will
1407 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011408 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511409 }
1410
[email protected]b75b8292010-10-01 07:28:251411 // Reset the zoom limits in case a plugin had changed them previously. This
1412 // will also call us back which will cause us to send a message to
1413 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251414 webview()->zoomLimitsChanged(
1415 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1416 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251417
initial.commit09911bf2008-07-26 23:55:291418 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551419 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291420
[email protected]daa8c58e2009-06-15 17:21:101421 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291422 if (!PageTransition::IsMainFrame(params.transition)) {
1423 // If the main frame does a load, it should not be reported as a subframe
1424 // navigation. This can occur in the following case:
1425 // 1. You're on a site with frames.
1426 // 2. You do a subframe navigation. This is stored with transition type
1427 // MANUAL_SUBFRAME.
1428 // 3. You navigate to some non-frame site, say, google.com.
1429 // 4. You navigate back to the page from step 2. Since it was initially
1430 // MANUAL_SUBFRAME, it will be that same transition type here.
1431 // We don't want that, because any navigation that changes the toplevel
1432 // frame should be tracked as a toplevel navigation (this allows us to
1433 // update the URL bar, etc).
1434 params.transition = PageTransition::LINK;
1435 }
1436
initial.commit09911bf2008-07-26 23:55:291437 // If we have a valid consumed client redirect source,
1438 // the page contained a client redirect (meta refresh, document.loc...),
1439 // so we set the referrer and transition to match.
1440 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041441 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291442 params.referrer = completed_client_redirect_src_;
1443 params.transition = static_cast<PageTransition::Type>(
1444 params.transition | PageTransition::CLIENT_REDIRECT);
1445 } else {
1446 // Bug 654101: the referrer will be empty on https->http transitions. It
1447 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281448 params.referrer = GURL(
1449 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291450 }
1451
[email protected]726985e22009-06-18 21:09:281452 string16 method = request.httpMethod();
1453 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291454 params.is_post = true;
1455
[email protected]c2a797d2009-09-21 16:46:321456 // Save some histogram data so we can compute the average memory used per
1457 // page load of the glyphs.
1458 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1459 webkit_glue::GetGlyphPageCount());
1460
[email protected]15cf526b2010-02-12 06:33:491461 // This message needs to be sent before any of allowScripts(),
1462 // allowImages(), allowPlugins() is called for the new page, so that when
1463 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1464 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291465 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1466 } else {
1467 // Subframe navigation: the type depends on whether this navigation
1468 // generated a new session history entry. When they do generate a session
1469 // history entry, it means the user initiated the navigation and we should
1470 // mark it as such. This test checks if this is the first time UpdateURL
1471 // has been called since WillNavigateToURL was called to initiate the load.
1472 if (page_id_ > last_page_id_sent_to_browser_)
1473 params.transition = PageTransition::MANUAL_SUBFRAME;
1474 else
1475 params.transition = PageTransition::AUTO_SUBFRAME;
1476
initial.commit09911bf2008-07-26 23:55:291477 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1478 }
1479
1480 last_page_id_sent_to_browser_ =
1481 std::max(last_page_id_sent_to_browser_, page_id_);
1482
1483 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101484 // we don't want the transition type to persist. Just clear it.
1485 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501486
[email protected]af15bed2010-08-25 21:12:091487 // Check if the navigation was within the same page, in which case we don't
1488 // want to clear the accessibility cache.
1489 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351490 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141491 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501492 }
initial.commit09911bf2008-07-26 23:55:291493}
1494
1495// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171496void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291497 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171498 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171499 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171500 routing_id_,
1501 page_id_,
1502 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1503 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171504 }
initial.commit09911bf2008-07-26 23:55:291505}
1506
1507void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401508 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291509 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271510 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291511 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301512 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291513 last_encoding_name_ = encoding_name;
1514
[email protected]e38f40152008-09-12 23:08:301515 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291516 }
1517}
1518
[email protected]f4d34b52008-11-24 23:05:011519// Sends the previous session history state to the browser so it will be saved
1520// before we navigate to a new page. This must be called *before* the page ID
1521// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291522void RenderView::UpdateSessionHistory(WebFrame* frame) {
1523 // If we have a valid page ID at this point, then it corresponds to the page
1524 // we are navigating away from. Otherwise, this is the first navigation, so
1525 // there is no past session history to record.
1526 if (page_id_ == -1)
1527 return;
1528
[email protected]ca948a22009-06-25 19:36:171529 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271530 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171531 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291532 return;
[email protected]ca948a22009-06-25 19:36:171533
1534 Send(new ViewHostMsg_UpdateState(
1535 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291536}
1537
[email protected]3d9689372009-09-10 04:29:171538void RenderView::OpenURL(
1539 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1540 Send(new ViewHostMsg_OpenURL(
1541 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1542}
1543
[email protected]79dbc662009-09-04 05:42:511544// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291545
initial.commit09911bf2008-07-26 23:55:291546void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281547 const WebURLRequest& failed_request,
1548 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291549 const std::string& html,
1550 bool replace) {
[email protected]726985e22009-06-18 21:09:281551 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291552 std::string alt_html;
[email protected]07b493512010-08-27 15:39:291553 ExtensionRendererInfo* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291554 if (html.empty()) {
1555 // Use a local error page.
1556 int resource_id;
1557 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111558
[email protected]81654282010-10-04 17:08:061559 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]5351dbc2010-08-27 15:22:111560 extension = ExtensionRendererInfo::GetByURL(failed_url);
1561 if (extension) {
[email protected]3f853a52010-09-13 19:15:081562 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1563 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111564
1565 // TODO(erikkay): Should we use a different template for different
1566 // error messages?
1567 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291568 } else {
[email protected]3f853a52010-09-13 19:15:081569 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1570 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111571 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081572 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111573 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1574 } else {
[email protected]3f853a52010-09-13 19:15:081575 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111576 resource_id = IDR_NET_ERROR_HTML;
1577 }
initial.commit09911bf2008-07-26 23:55:291578 }
initial.commit09911bf2008-07-26 23:55:291579
1580 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1581 } else {
1582 alt_html = html;
1583 }
1584
[email protected]dd7daa82009-08-10 05:46:451585 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551586 GURL(kUnreachableWebDataURL),
1587 failed_url,
1588 replace);
initial.commit09911bf2008-07-26 23:55:291589}
1590
[email protected]7ccddb8c2009-08-04 17:36:551591void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031592 if (!dom_automation_controller_.get()) {
1593 dom_automation_controller_.reset(new DomAutomationController());
1594 }
1595 dom_automation_controller_->set_message_sender(this);
1596 dom_automation_controller_->set_routing_id(routing_id_);
1597 dom_automation_controller_->BindToJavascript(frame,
1598 L"domAutomationController");
initial.commit09911bf2008-07-26 23:55:291599}
1600
initial.commit09911bf2008-07-26 23:55:291601bool RenderView::RunJavaScriptMessage(int type,
1602 const std::wstring& message,
1603 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071604 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291605 std::wstring* result) {
1606 bool success = false;
1607 std::wstring result_temp;
1608 if (!result)
1609 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291610
[email protected]12636df2009-09-28 22:32:211611 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1612 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291613 return success;
1614}
1615
[email protected]c1f50aa2010-02-18 03:46:571616bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1617 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1618 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1619 // it is particularly important that we do not call willEnterModalLoop as
1620 // that would defer resource loads for the dialog itself.
1621 if (RenderThread::current()) // Will be NULL during unit tests.
1622 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1623
1624 message->EnableMessagePumping(); // Runs a nested message loop.
1625 return Send(message);
1626}
1627
[email protected]2de7e002010-10-11 22:58:201628void RenderView::AddGURLSearchProvider(
1629 const GURL& osd_url,
1630 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291631 if (!osd_url.is_empty())
1632 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201633 provider_type));
initial.commit09911bf2008-07-26 23:55:291634}
1635
[email protected]95056b582010-02-18 01:29:241636void RenderView::OnAutoFillSuggestionsReturned(
1637 int query_id,
[email protected]8f6e6582010-04-09 02:03:071638 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391639 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411640 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391641 const std::vector<int>& unique_ids) {
[email protected]6a8ddba52010-09-05 04:38:061642 autofill_helper_->SuggestionsReceived(
[email protected]a53e06832010-07-28 22:46:411643 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031644}
1645
[email protected]45c6e532010-03-15 23:51:241646void RenderView::OnAutoFillFormDataFilled(int query_id,
1647 const webkit_glue::FormData& form) {
[email protected]6a8ddba52010-09-05 04:38:061648 autofill_helper_->FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481649}
1650
[email protected]e8345242010-05-06 03:00:401651void RenderView::OnAllowScriptToClose(bool script_can_close) {
1652 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311653}
1654
initial.commit09911bf2008-07-26 23:55:291655uint32 RenderView::GetCPBrowsingContext() {
1656 uint32 context = 0;
1657 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1658 return context;
1659}
1660
[email protected]2de7e002010-10-11 22:58:201661void RenderView::AddSearchProvider(
1662 const std::string& url,
1663 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1664 if (provider_type.type ==
1665 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1666 !webview()->mainFrame()->isProcessingUserGesture())
1667 return;
1668
1669 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291670}
1671
[email protected]155f35e2010-07-17 00:30:181672ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251673RenderView::GetSearchProviderInstallState(WebFrame* frame,
1674 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181675 GURL inquiry_url = GURL(url);
1676 if (inquiry_url.is_empty())
1677 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251678
[email protected]155f35e2010-07-17 00:30:181679 ViewHostMsg_GetSearchProviderInstallState_Params install;
1680 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:251681 frame->url(),
[email protected]155f35e2010-07-17 00:30:181682 inquiry_url,
1683 &install));
1684 return install;
1685}
1686
[email protected]f103ab72009-09-02 17:10:591687void RenderView::OnMissingPluginStatus(
1688 WebPluginDelegateProxy* delegate,
1689 int status) {
[email protected]6c8afae52009-01-22 02:24:571690#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591691 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291692 // Show the InfoBar for the first available plugin.
1693 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591694 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291695 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1696 }
1697 } else {
1698 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1699 // to start the download/install.
1700 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1701 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1702 }
1703 }
[email protected]6c8afae52009-01-22 02:24:571704#else
[email protected]76c3b312010-05-20 21:38:291705 // TODO(port): Implement the infobar that accompanies the default plugin.
1706 // Linux: http://crbug.com/10952
1707 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571708 NOTIMPLEMENTED();
1709#endif
initial.commit09911bf2008-07-26 23:55:291710}
1711
[email protected]48c9cf2d2009-09-16 16:47:521712// WebKit::WebViewClient ------------------------------------------------------
1713
[email protected]8ab04652010-06-12 02:47:261714WebView* RenderView::createView(
1715 WebFrame* creator,
1716 const WebWindowFeatures& features,
1717 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521718 // Check to make sure we aren't overloading on popups.
1719 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1720 return NULL;
1721
1722 // This window can't be closed from a window.close() call until we receive a
1723 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401724 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521725
[email protected]8ab04652010-06-12 02:47:261726 ViewHostMsg_CreateWindow_Params params;
1727 params.opener_id = routing_id_;
1728 params.user_gesture = creator->isProcessingUserGesture();
1729 params.window_container_type = WindowFeaturesToContainerType(features);
1730 params.session_storage_namespace_id = session_storage_namespace_id_;
1731 params.frame_name = frame_name;
1732
[email protected]48c9cf2d2009-09-16 16:47:521733 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341734 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261735 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521736
[email protected]48c9cf2d2009-09-16 16:47:521737 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261738 new ViewHostMsg_CreateWindow(params,
1739 &routing_id,
1740 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211741 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521742 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521743
[email protected]48c9cf2d2009-09-16 16:47:521744 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421745 0,
[email protected]12636df2009-09-28 22:32:211746 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521747 renderer_preferences_,
1748 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211749 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341750 routing_id,
[email protected]8ab04652010-06-12 02:47:261751 cloned_session_storage_namespace_id,
1752 frame_name);
1753 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521754
[email protected]007a848b2009-10-26 15:55:461755 // Record whether the creator frame is trying to suppress the opener field.
1756 view->opener_suppressed_ = opener_suppressed;
1757
[email protected]48c9cf2d2009-09-16 16:47:521758 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091759 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521760 if (!creator_url.is_valid() || !creator_url.IsStandard())
1761 creator_url = GURL();
1762 view->creator_url_ = creator_url;
1763
1764 // Copy over the alternate error page URL so we can have alt error pages in
1765 // the new render view (we don't need the browser to send the URL back down).
1766 view->alternate_error_page_url_ = alternate_error_page_url_;
1767
1768 return view->webview();
1769}
1770
[email protected]3e2b375b2010-04-07 17:03:121771WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521772 RenderWidget* widget = RenderWidget::Create(routing_id_,
1773 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121774 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521775 return widget->webwidget();
1776}
1777
1778WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1779 RenderWidget* widget = RenderWidget::Create(routing_id_,
1780 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121781 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521782 widget->ConfigureAsExternalPopupMenu(info);
1783 return widget->webwidget();
1784}
1785
[email protected]484955942010-08-19 16:13:181786WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
1787 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
1788 render_thread_,
1789 popup_type);
1790 return widget->webwidget();
1791}
1792
[email protected]79c7bed2010-09-14 22:28:391793pepper::FullscreenContainer* RenderView::CreatePepperFullscreenContainer(
1794 pepper::PluginInstance* plugin) {
1795 RenderWidgetFullscreenPepper* widget =
1796 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
1797 widget->show(WebKit::WebNavigationPolicyIgnore);
1798 return widget->container();
1799}
1800
[email protected]68c50e52010-05-12 11:14:391801WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341802 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391803 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291804 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1805 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1806 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341807}
1808
[email protected]48c9cf2d2009-09-16 16:47:521809void RenderView::didAddMessageToConsole(
1810 const WebConsoleMessage& message, const WebString& source_name,
1811 unsigned source_line) {
1812 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1813 UTF16ToWideHack(message.text),
1814 static_cast<int32>(source_line),
1815 UTF16ToWideHack(source_name)));
1816}
1817
1818void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581819 DCHECK(frame);
1820 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521821}
1822
[email protected]3354d3e2010-06-10 19:53:021823WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1824 return notification_provider_.get();
1825}
1826
[email protected]48c9cf2d2009-09-16 16:47:521827void RenderView::didStartLoading() {
1828 if (is_loading_) {
1829 DLOG(WARNING) << "didStartLoading called while loading";
1830 return;
1831 }
1832
1833 is_loading_ = true;
1834 // Clear the pointer so that we can assign it only when there is an unknown
1835 // plugin on a page.
1836 first_default_plugin_.reset();
1837
1838 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1839}
1840
1841void RenderView::didStopLoading() {
1842 if (!is_loading_) {
1843 DLOG(WARNING) << "DidStopLoading called while not loading";
1844 return;
1845 }
1846
1847 is_loading_ = false;
1848
1849 // NOTE: For now we're doing the safest thing, and sending out notification
1850 // when done loading. This currently isn't an issue as the favicon is only
1851 // displayed when done loading. Ideally we would send notification when
1852 // finished parsing the head, but webkit doesn't support that yet.
1853 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271854 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521855 if (!favicon_url.is_empty())
1856 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1857
[email protected]26aa0482009-09-30 16:55:271858 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:201859 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:521860
1861 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1862
[email protected]f9f4841b2010-03-20 05:41:421863 MessageLoop::current()->PostDelayedTask(
1864 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:301865 page_info_method_factory_.NewRunnableMethod(
1866 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:371867 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521868}
1869
[email protected]f55039a2010-02-17 14:12:061870bool RenderView::isSmartInsertDeleteEnabled() {
1871#if defined(OS_MACOSX)
1872 return true;
1873#else
1874 return false;
1875#endif
1876}
1877
[email protected]04fc9482009-09-18 22:13:031878bool RenderView::isSelectTrailingWhitespaceEnabled() {
1879#if defined(OS_WIN)
1880 return true;
1881#else
1882 return false;
1883#endif
1884}
1885
[email protected]04fc9482009-09-18 22:13:031886void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]eef99c22010-08-17 05:55:161887#if defined(USE_X11) || defined(OS_MACOSX)
[email protected]04fc9482009-09-18 22:13:031888 if (!handling_input_event_)
1889 return;
1890 // TODO(estade): investigate incremental updates to the selection so that we
1891 // don't send the entire selection over IPC every time.
1892 if (!is_empty_selection) {
1893 // Sometimes we get repeated didChangeSelection calls from webkit when
1894 // the selection hasn't actually changed. We don't want to report these
1895 // because it will cause us to continually claim the X clipboard.
1896 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271897 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031898 if (this_selection == last_selection_)
1899 return;
1900
1901 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1902 this_selection));
1903 last_selection_ = this_selection;
1904 } else {
1905 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:161906 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1907 last_selection_));
[email protected]04fc9482009-09-18 22:13:031908 }
1909#endif
1910}
1911
1912void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121913 const std::string& name = UTF16ToUTF8(command_name);
1914 if (StartsWithASCII(name, "Move", true) ||
1915 StartsWithASCII(name, "Insert", true) ||
1916 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031917 return;
1918 UserMetricsRecordAction(name);
1919}
1920
[email protected]03f57072010-07-14 17:36:081921void RenderView::textFieldDidEndEditing(
1922 const WebKit::WebInputElement& element) {
1923#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061924 password_autocomplete_manager_->TextFieldDidEndEditing(element);
[email protected]03f57072010-07-14 17:36:081925#endif
1926}
1927
1928void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1929#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]e47aec52010-08-12 00:50:301930 // We post a task for doing the AutoFill as the caret position is not set
1931 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
1932 // it is needed to trigger autofill.
1933 autofill_method_factory_.RevokeAll();
1934 MessageLoop::current()->PostTask(
1935 FROM_HERE,
1936 autofill_method_factory_.NewRunnableMethod(
1937 &RenderView::TextFieldDidChangeImpl, element));
[email protected]03f57072010-07-14 17:36:081938#endif
1939}
1940
[email protected]e47aec52010-08-12 00:50:301941void RenderView::TextFieldDidChangeImpl(
1942 const WebKit::WebInputElement& element) {
[email protected]6a8ddba52010-09-05 04:38:061943 if (password_autocomplete_manager_->TextDidChangeInTextField(element))
[email protected]e47aec52010-08-12 00:50:301944 return;
[email protected]6a8ddba52010-09-05 04:38:061945 autofill_helper_->TextDidChangeInTextField(element);
[email protected]e47aec52010-08-12 00:50:301946}
1947
[email protected]03f57072010-07-14 17:36:081948void RenderView::textFieldDidReceiveKeyDown(
1949 const WebKit::WebInputElement& element,
1950 const WebKit::WebKeyboardEvent& event) {
1951#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061952 password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event);
[email protected]03f57072010-07-14 17:36:081953#endif
1954}
1955
[email protected]b2528b72009-09-24 06:57:101956bool RenderView::handleCurrentKeyboardEvent() {
1957 if (edit_commands_.empty())
1958 return false;
1959
[email protected]26aa0482009-09-30 16:55:271960 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101961 if (!frame)
1962 return false;
1963
1964 EditCommands::iterator it = edit_commands_.begin();
1965 EditCommands::iterator end = edit_commands_.end();
1966
[email protected]507b33ea2009-09-29 03:56:511967 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101968 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331969 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1970 // key (but it's the exception). Once one edit command is not executed, it
1971 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101972 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1973 WebString::fromUTF8(it->value)))
1974 break;
[email protected]507b33ea2009-09-29 03:56:511975 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101976 }
1977
[email protected]507b33ea2009-09-29 03:56:511978 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101979}
1980
[email protected]e47aec52010-08-12 00:50:301981void RenderView::inputElementClicked(const WebKit::WebInputElement& element,
1982 bool already_focused) {
1983#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061984 if (password_autocomplete_manager_->InputElementClicked(element,
1985 already_focused)) {
[email protected]e47aec52010-08-12 00:50:301986 return;
1987 }
[email protected]6a8ddba52010-09-05 04:38:061988 autofill_helper_->InputElementClicked(element, already_focused);
[email protected]e47aec52010-08-12 00:50:301989#endif
1990}
1991
[email protected]2a3a7762009-10-19 19:17:321992void RenderView::spellCheck(const WebString& text,
1993 int& misspelled_offset,
1994 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561995 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461996
[email protected]85c55dc2009-11-06 03:05:461997 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171998 RenderThread* thread = RenderThread::current();
1999 // Will be NULL during unit tests.
2000 if (thread) {
[email protected]c27324b2009-11-19 22:44:292001 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172002 word.c_str(), word.size(), document_tag_,
2003 &misspelled_offset, &misspelled_length, NULL);
2004 }
[email protected]1dbafaf72009-09-23 19:43:562005}
2006
2007WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322008 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562009 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262010 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562011 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172012 RenderThread* thread = RenderThread::current();
2013 // Will be NULL during unit tests.
2014 if (thread) {
2015 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292016 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172017 word, document_tag_);
2018 }
[email protected]1dbafaf72009-09-23 19:43:562019 }
[email protected]2a3a7762009-10-19 19:17:322020 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562021}
2022
[email protected]c49085c72009-10-02 16:28:562023void RenderView::showSpellingUI(bool show) {
2024 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2025}
2026
[email protected]8922e1f2009-10-03 05:01:262027bool RenderView::isShowingSpellingUI() {
2028 return spelling_panel_visible_;
2029}
2030
[email protected]1dbafaf72009-09-23 19:43:562031void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322032 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2033 word));
[email protected]1dbafaf72009-09-23 19:43:562034}
2035
[email protected]a1128322009-10-06 18:38:462036bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352037 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472038 WebFileChooserCompletion* chooser_completion) {
2039 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262040 if (params.directory)
2041 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2042 else if (params.multiSelect)
2043 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2044 else
2045 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472046 ipc_params.title = params.title;
2047 ipc_params.default_file_name =
2048 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592049 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472050
2051 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462052}
2053
[email protected]48c9cf2d2009-09-16 16:47:522054void RenderView::runModalAlertDialog(
2055 WebFrame* frame, const WebString& message) {
2056 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
2057 UTF16ToWideHack(message),
2058 std::wstring(),
2059 frame->url(),
2060 NULL);
2061}
2062
2063bool RenderView::runModalConfirmDialog(
2064 WebFrame* frame, const WebString& message) {
2065 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
2066 UTF16ToWideHack(message),
2067 std::wstring(),
2068 frame->url(),
2069 NULL);
2070}
2071
2072bool RenderView::runModalPromptDialog(
2073 WebFrame* frame, const WebString& message, const WebString& default_value,
2074 WebString* actual_value) {
2075 std::wstring result;
2076 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
2077 UTF16ToWideHack(message),
2078 UTF16ToWideHack(default_value),
2079 frame->url(),
2080 &result);
2081 if (ok)
2082 actual_value->assign(WideToUTF16Hack(result));
2083 return ok;
2084}
2085
2086bool RenderView::runModalBeforeUnloadDialog(
2087 WebFrame* frame, const WebString& message) {
2088 bool success = false;
2089 // This is an ignored return value, but is included so we can accept the same
2090 // response as RunJavaScriptMessage.
2091 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212092 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522093 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212094 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522095 return success;
2096}
2097
[email protected]79e37442009-10-09 18:17:442098void RenderView::showContextMenu(
2099 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292100 ContextMenuParams params = ContextMenuParams(data);
2101 if (!params.misspelled_word.empty() && RenderThread::current()) {
2102 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042103 bool spelled_right = RenderThread::current()->spellchecker()->
2104 SpellCheckWord(
2105 params.misspelled_word.c_str(), params.misspelled_word.size(),
2106 document_tag_,
2107 &misspelled_offset, &misspelled_length,
2108 &params.dictionary_suggestions);
2109 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292110 params.misspelled_word.clear();
2111 }
[email protected]216932c2010-08-26 21:44:272112 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2113 // it. We replace it with an empty GURL so the appropriate items are disabled
2114 // in the context menu.
2115 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2116 // data encoded images. We should have a way to save them.
2117 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2118 params.src_url = GURL();
[email protected]c27324b2009-11-19 22:44:292119 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442120}
2121
[email protected]52f139e2c2010-06-11 16:56:092122bool RenderView::supportsFullscreen() {
2123 return CommandLine::ForCurrentProcess()->HasSwitch(
2124 switches::kEnableVideoFullscreen);
2125}
2126
2127void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2128 NOTIMPLEMENTED();
2129}
2130
2131void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2132 NOTIMPLEMENTED();
2133}
2134
[email protected]48c9cf2d2009-09-16 16:47:522135void RenderView::setStatusText(const WebString& text) {
2136}
2137
[email protected]163f8242009-10-30 20:19:552138void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582139 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522140 if (latest_url == target_url_)
2141 return;
[email protected]163f8242009-10-30 20:19:552142
[email protected]48c9cf2d2009-09-16 16:47:522143 // Tell the browser to display a destination link.
2144 if (target_url_status_ == TARGET_INFLIGHT ||
2145 target_url_status_ == TARGET_PENDING) {
2146 // If we have a request in-flight, save the URL to be sent when we
2147 // receive an ACK to the in-flight request. We can happily overwrite
2148 // any existing pending sends.
2149 pending_target_url_ = latest_url;
2150 target_url_status_ = TARGET_PENDING;
2151 } else {
2152 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2153 target_url_ = latest_url;
2154 target_url_status_ = TARGET_INFLIGHT;
2155 }
2156}
2157
[email protected]882daa92009-11-05 16:31:312158void RenderView::StartNavStateSyncTimerIfNecessary() {
2159 int delay;
2160 if (send_content_state_immediately_)
2161 delay = 0;
2162 else if (is_hidden())
2163 delay = kDelaySecondsForContentStateSyncHidden;
2164 else
2165 delay = kDelaySecondsForContentStateSync;
2166
2167 if (nav_state_sync_timer_.IsRunning()) {
2168 // The timer is already running. If the delay of the timer maches the amount
2169 // we want to delay by, then return. Otherwise stop the timer so that it
2170 // gets started with the right delay.
2171 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2172 return;
2173 nav_state_sync_timer_.Stop();
2174 }
2175
2176 nav_state_sync_timer_.Start(
2177 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2178}
2179
[email protected]163f8242009-10-30 20:19:552180void RenderView::setMouseOverURL(const WebURL& url) {
2181 mouse_over_url_ = GURL(url);
2182 UpdateTargetURL(mouse_over_url_, focus_url_);
2183}
2184
2185void RenderView::setKeyboardFocusURL(const WebURL& url) {
2186 focus_url_ = GURL(url);
2187 UpdateTargetURL(focus_url_, mouse_over_url_);
2188}
2189
[email protected]48c9cf2d2009-09-16 16:47:522190void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2191 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2192 hint));
2193}
2194
[email protected]c27ae592010-03-18 15:24:412195void RenderView::startDragging(const WebDragData& data,
2196 WebDragOperationsMask mask,
2197 const WebImage& image,
2198 const WebPoint& imageOffset) {
2199#if WEBKIT_USING_SKIA
2200 SkBitmap bitmap(image.getSkBitmap());
2201#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332202 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412203#endif
2204
[email protected]48c9cf2d2009-09-16 16:47:522205 Send(new ViewHostMsg_StartDragging(routing_id_,
2206 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412207 mask,
2208 bitmap,
2209 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522210}
2211
[email protected]28b92df2009-09-25 17:35:452212bool RenderView::acceptsLoadDrops() {
2213 return renderer_preferences_.can_accept_load_drops;
2214}
2215
[email protected]48c9cf2d2009-09-16 16:47:522216void RenderView::focusNext() {
2217 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2218}
2219
2220void RenderView::focusPrevious() {
2221 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2222}
2223
[email protected]08e9e132010-06-01 16:58:492224void RenderView::focusedNodeChanged(const WebNode& node) {
2225 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
[email protected]a4b103b2010-10-05 18:46:072226
2227 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2228 // TODO(ctguil): Make WebKit send this notification.
2229 // When focus is cleared notify accessibility that the document is focused.
2230 postAccessibilityNotification(
2231 webview()->accessibilityObject(),
2232 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2233 }
[email protected]08e9e132010-06-01 16:58:492234}
2235
[email protected]48c9cf2d2009-09-16 16:47:522236void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522237 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2238}
2239
2240int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002241 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522242}
2243
2244int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002245 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522246}
2247
[email protected]c4e98902010-06-01 10:20:142248void RenderView::didUpdateInspectorSetting(const WebString& key,
2249 const WebString& value) {
2250 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2251 key.utf8(),
2252 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262253}
2254
[email protected]acca2a1f2009-10-16 03:53:392255void RenderView::queryAutofillSuggestions(const WebNode& node,
2256 const WebString& name,
2257 const WebString& value) {
[email protected]a5e84bd2010-09-14 22:23:362258 autofill_helper_->QueryAutoFillSuggestions(node);
[email protected]acca2a1f2009-10-16 03:53:392259}
2260
2261void RenderView::removeAutofillSuggestions(const WebString& name,
2262 const WebString& value) {
[email protected]6a8ddba52010-09-05 04:38:062263 autofill_helper_->RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a1f2009-10-16 03:53:392264}
2265
[email protected]18ca9a6b2010-06-02 19:05:182266void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2267 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202268 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392269 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202270 unsigned index) {
[email protected]a5e84bd2010-09-14 22:23:362271 autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index);
[email protected]18ca9a6b2010-06-02 19:05:182272}
[email protected]c83641732010-02-20 01:04:482273
[email protected]18ca9a6b2010-06-02 19:05:182274void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2275 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392276 const WebKit::WebString& label,
2277 int unique_id) {
[email protected]a5e84bd2010-09-14 22:23:362278 autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182279}
2280
2281void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]6a8ddba52010-09-05 04:38:062282 autofill_helper_->DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482283}
2284
[email protected]03f57072010-07-14 17:36:082285void RenderView::didAcceptAutocompleteSuggestion(
2286 const WebKit::WebInputElement& user_element) {
2287#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:062288 bool result = password_autocomplete_manager_->FillPassword(user_element);
[email protected]03f57072010-07-14 17:36:082289 // Since this user name was selected from a suggestion list, we should always
2290 // have password for it.
2291 DCHECK(result);
2292#endif
2293}
2294
[email protected]79dbc662009-09-04 05:42:512295// WebKit::WebWidgetClient ----------------------------------------------------
2296
[email protected]ea42e7782010-08-23 23:58:122297void RenderView::didFocus() {
2298 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2299 // we won't have to test for user gesture anymore and we can
2300 // move that code back to render_widget.cc
2301 if (webview() && webview()->mainFrame() &&
2302 webview()->mainFrame()->isProcessingUserGesture()) {
2303 Send(new ViewHostMsg_Focus(routing_id_));
2304 }
2305}
2306
2307void RenderView::didBlur() {
2308 // TODO(jcivelli): see TODO above in didFocus().
2309 if (webview() && webview()->mainFrame() &&
2310 webview()->mainFrame()->isProcessingUserGesture()) {
2311 Send(new ViewHostMsg_Blur(routing_id_));
2312 }
2313}
2314
initial.commit09911bf2008-07-26 23:55:292315// We are supposed to get a single call to Show for a newly created RenderView
2316// that was created via RenderView::CreateWebView. So, we wait until this
2317// point to dispatch the ShowView message.
2318//
2319// This method provides us with the information about how to display the newly
2320// created RenderView (i.e., as a constrained popup or as a new tab).
2321//
[email protected]4873c7d2009-07-16 06:36:282322void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292323 DCHECK(!did_show_) << "received extraneous Show call";
2324 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2325
2326 if (did_show_)
2327 return;
2328 did_show_ = true;
2329
[email protected]4026ce1e2010-09-14 19:35:042330 // Extensions and apps always allowed to create unrequested popups. The second
2331 // check is necessary to include content scripts.
2332 if (ExtensionRendererInfo::GetByURL(creator_url_) ||
2333 bindings_utils::GetInfoForCurrentContext()) {
2334 opened_by_user_gesture_ = true;
2335 }
2336
[email protected]28295ec2009-10-16 05:34:332337 // Force new windows to a popup if they were not opened with a user gesture.
2338 if (!opened_by_user_gesture_) {
2339 // We exempt background tabs for compat with older versions of Chrome.
2340 // TODO(darin): This seems bogus. These should have a user gesture, so
2341 // we probably don't need this check.
2342 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2343 policy = WebKit::WebNavigationPolicyNewPopup;
2344 }
2345
initial.commit09911bf2008-07-26 23:55:292346 // NOTE: initial_pos_ may still have its default values at this point, but
2347 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2348 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282349 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2350 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292351 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242352 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292353}
2354
[email protected]4873c7d2009-07-16 06:36:282355void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132356 // Cancel pending translations so that the translate_helper_ does not attempt
2357 // to access the WebView.
2358 translate_helper_.CancelPendingTranslation();
2359
[email protected]e8345242010-05-06 03:00:402360 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282361 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312362}
2363
[email protected]4873c7d2009-07-16 06:36:282364void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292365 DCHECK(did_show_) << "should already have shown the view";
2366
[email protected]c1f50aa2010-02-18 03:46:572367 // We must keep WebKit's shared timer running in this case in order to allow
2368 // showModalDialog to function properly.
2369 //
2370 // TODO(darin): WebKit should really be smarter about suppressing events and
2371 // timers so that we do not need to manage the shared timer in such a heavy
2372 // handed manner.
2373 //
2374 if (RenderThread::current()) // Will be NULL during unit tests.
2375 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2376
[email protected]12636df2009-09-28 22:32:212377 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292378}
2379
[email protected]3d9689372009-09-10 04:29:172380// WebKit::WebFrameClient -----------------------------------------------------
2381
[email protected]00152e92010-07-19 11:47:402382WebPlugin* RenderView::createPlugin(WebFrame* frame,
2383 const WebPluginParams& params) {
[email protected]20a793e2010-10-12 06:50:082384 std::vector<ContentSetting> settings;
[email protected]55126132010-08-19 14:53:282385 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]20a793e2010-10-12 06:50:082386 std::vector<WebPluginInfo> info;
[email protected]7a13e792010-08-03 08:18:242387 GURL url(params.url);
[email protected]20a793e2010-10-12 06:50:082388 std::vector<std::string> actual_mime_types;
2389 Send(new ViewHostMsg_GetPluginInfoArray(url,
2390 frame->top()->url(),
2391 params.mimeType.utf8(),
2392 &info,
2393 &settings,
2394 &actual_mime_types));
[email protected]7a13e792010-08-03 08:18:242395
[email protected]20a793e2010-10-12 06:50:082396 if (info.empty())
[email protected]0cdafff2010-07-26 09:54:372397 return NULL;
[email protected]4e0616e2010-05-28 14:55:532398
[email protected]20a793e2010-10-12 06:50:082399 DCHECK(settings[0] != CONTENT_SETTING_DEFAULT);
[email protected]851b1eb2010-08-09 13:32:292400
[email protected]20a793e2010-10-12 06:50:082401 scoped_ptr<PluginGroup> group(PluginGroup::CopyOrCreatePluginGroup(info[0]));
2402 group->AddPlugin(info[0], 0);
2403
2404 if (!info[0].enabled) {
[email protected]55126132010-08-19 14:53:282405 if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) &&
[email protected]851b1eb2010-08-09 13:32:292406 group->IsVulnerable()) {
2407 Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_,
2408 group->GetGroupName(),
2409 GURL(group->GetUpdateURL())));
[email protected]57b66d02010-09-30 11:24:512410 return CreateOutdatedPluginPlaceholder(frame, params, group.get());
[email protected]851b1eb2010-08-09 13:32:292411 }
2412 return NULL;
2413 }
2414
[email protected]20a793e2010-10-12 06:50:082415 if (info[0].path.value() == kDefaultPluginLibraryName ||
2416 settings[0] == CONTENT_SETTING_ALLOW) {
[email protected]aad51d1c2010-08-05 08:38:092417 scoped_refptr<pepper::PluginModule> pepper_module =
[email protected]20a793e2010-10-12 06:50:082418 PepperPluginRegistry::GetInstance()->GetModule(info[0].path);
[email protected]fc61e222010-10-11 15:42:142419 if (pepper_module) {
2420 return CreatePepperPlugin(frame,
2421 params,
[email protected]20a793e2010-10-12 06:50:082422 info[0].path,
[email protected]fc61e222010-10-11 15:42:142423 pepper_module.get());
[email protected]aad51d1c2010-08-05 08:38:092424 }
[email protected]20a793e2010-10-12 06:50:082425 return CreateNPAPIPlugin(frame, params, info[0].path, actual_mime_types[0]);
[email protected]0cdafff2010-07-26 09:54:372426 }
[email protected]fc61e222010-10-11 15:42:142427 std::string resource;
2428 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2429 resource = group->identifier();
2430 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
2431 int resource_id;
2432 int message_id;
[email protected]20a793e2010-10-12 06:50:082433 if (settings[0] == CONTENT_SETTING_ASK) {
[email protected]fc61e222010-10-11 15:42:142434 resource_id = IDR_BLOCKED_PLUGIN_HTML;
2435 message_id = IDS_PLUGIN_LOAD;
2436 } else {
2437 resource_id = IDR_OUTDATED_PLUGIN_HTML;
2438 message_id = IDS_PLUGIN_BLOCKED;
2439 }
[email protected]20a793e2010-10-12 06:50:082440
[email protected]fc61e222010-10-11 15:42:142441 // |blocked_plugin| will delete itself when the WebViewPlugin
2442 // is destroyed.
2443 BlockedPlugin* blocked_plugin =
2444 new BlockedPlugin(this,
2445 frame,
2446 params,
2447 webkit_preferences_,
2448 resource_id,
2449 l10n_util::GetStringUTF16(message_id));
2450 return blocked_plugin->plugin();
[email protected]3d9689372009-09-10 04:29:172451}
2452
2453WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562454 WebApplicationCacheHostImpl* appcache_host =
2455 WebApplicationCacheHostImpl::FromFrame(frame);
2456 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2457 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2458 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172459}
2460
[email protected]9c00f002009-11-05 22:37:422461WebSharedWorker* RenderView::createSharedWorker(
2462 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372463 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422464
[email protected]30447b62009-11-13 01:13:372465 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512466 bool exists = false;
[email protected]30447b62009-11-13 01:13:372467 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512468 ViewHostMsg_CreateWorker_Params params;
2469 params.url = url;
2470 params.is_shared = true;
2471 params.name = name;
2472 params.document_id = document_id;
2473 params.render_view_route_id = routing_id_;
2474 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232475 params.parent_appcache_host_id = 0;
2476 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372477 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512478 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372479 if (url_mismatch) {
2480 return NULL;
2481 } else {
2482 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492483 document_id,
[email protected]6de0bcf2010-02-17 22:00:512484 exists,
[email protected]30447b62009-11-13 01:13:372485 route_id,
2486 routing_id_);
2487 }
[email protected]9c00f002009-11-05 22:37:422488}
2489
[email protected]3d9689372009-09-10 04:29:172490WebMediaPlayer* RenderView::createMediaPlayer(
2491 WebFrame* frame, WebMediaPlayerClient* client) {
2492 scoped_refptr<media::FilterFactoryCollection> factory =
2493 new media::FilterFactoryCollection();
2494 // Add in any custom filter factories first.
2495 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2496 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2497 // Add the chrome specific audio renderer.
2498 factory->AddFactory(
2499 AudioRendererImpl::CreateFactory(audio_message_filter()));
2500 }
2501
[email protected]3bb08602010-10-07 21:47:172502 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
2503 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
2504 // Add the hardware video decoder factory.
2505 // TODO(hclam): This assumes that ggl::Context is set to current
2506 // internally. I need to make it more explicit to get the context.
2507 bool ret = frame->view()->graphicsContext3D()->makeContextCurrent();
2508 CHECK(ret) << "Failed to switch context";
2509
2510 factory->AddFactory(IpcVideoDecoder::CreateFactory(
[email protected]885ff1df2010-10-07 21:47:582511 MessageLoop::current(), ggl::GetCurrentContext()));
[email protected]3bb08602010-10-07 21:47:172512 }
2513
[email protected]80f584d92010-01-21 03:59:042514 WebApplicationCacheHostImpl* appcache_host =
2515 WebApplicationCacheHostImpl::FromFrame(frame);
2516
[email protected]3d9689372009-09-10 04:29:172517 // TODO(hclam): obtain the following parameters from |client|.
2518 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2519 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]7509760e32010-10-08 21:54:252520 GURL(frame->url()), // referrer
[email protected]810a52ef2010-01-08 01:22:152521 "null", // frame origin
2522 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172523 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042524 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172525 routing_id());
2526
[email protected]0436b9a2009-10-23 00:23:052527 // A simple data source that keeps all data in memory.
2528 media::FilterFactory* simple_data_source_factory =
2529 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2530 bridge_factory);
2531 // A sophisticated data source that does memory caching.
2532 media::FilterFactory* buffered_data_source_factory =
2533 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2534 bridge_factory);
2535 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2536 factory->AddFactory(simple_data_source_factory);
2537 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172538 } else {
[email protected]0436b9a2009-10-23 00:23:052539 factory->AddFactory(buffered_data_source_factory);
2540 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172541 }
[email protected]8400e032010-02-26 18:50:112542
2543 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2544 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2545 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2546 } else {
[email protected]b57509eb2010-03-30 01:26:282547 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2548 factory_factory =
2549 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112550 }
2551
2552 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172553}
2554
[email protected]035545f2010-04-09 13:10:212555WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2556 WebFrame* frame, WebApplicationCacheHostClient* client) {
2557 return new RendererWebApplicationCacheHostImpl(
2558 FromWebView(frame->view()), client,
2559 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2560}
2561
[email protected]b921cfd22010-02-25 16:57:512562WebCookieJar* RenderView::cookieJar() {
2563 return &cookie_jar_;
2564}
2565
[email protected]5041f982010-08-11 21:40:452566void RenderView::frameDetached(WebFrame* frame) {
[email protected]6a8ddba52010-09-05 04:38:062567 autofill_helper_->FrameDetached(frame);
2568 page_click_tracker_->StopTrackingFrame(frame, true);
[email protected]5041f982010-08-11 21:40:452569}
2570
[email protected]3d9689372009-09-10 04:29:172571void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302572 WebDataSource* ds = frame->dataSource();
2573 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522574
2575 if (!frame->parent()) {
2576 const GURL& url = frame->url();
2577 // Ensure state contains scheme.
2578 if (url.SchemeIs("http"))
2579 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
2580 else if (url.SchemeIs("https"))
2581 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
2582
2583 // Dump will only be provided when scheme is http or https.
2584 DumpLoadHistograms();
2585 }
2586
[email protected]fa7b6b542009-11-03 05:02:302587 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162588
[email protected]5041f982010-08-11 21:40:452589 // TODO(jhawkins): Remove once frameDetached is called by WebKit.
[email protected]6a8ddba52010-09-05 04:38:062590 autofill_helper_->FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172591}
2592
[email protected]684e4a42010-01-30 06:44:112593bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402594 if (enabled_per_settings &&
2595 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2596 return true;
2597
2598 if (IsWhitelistedForContentSettings(frame))
2599 return true;
2600
[email protected]55126132010-08-19 14:53:282601 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402602 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112603}
2604
[email protected]d5f9e4f2010-07-28 08:31:302605bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]a16a4212010-09-01 08:07:462606 if (!CommandLine::ForCurrentProcess()->HasSwitch(
2607 switches::kDisableClickToPlay)) {
[email protected]d5f9e4f2010-07-28 08:31:302608 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
2609 }
[email protected]a16a4212010-09-01 08:07:462610 return enabled_per_settings &&
2611 AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]d5f9e4f2010-07-28 08:31:302612}
2613
2614
[email protected]3d9689372009-09-10 04:29:172615void RenderView::loadURLExternally(
2616 WebFrame* frame, const WebURLRequest& request,
2617 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592618 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2619 if (policy == WebKit::WebNavigationPolicyDownload) {
2620 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2621 } else {
2622 OpenURL(request.url(), referrer, policy);
2623 }
[email protected]3d9689372009-09-10 04:29:172624}
2625
2626WebNavigationPolicy RenderView::decidePolicyForNavigation(
2627 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222628 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172629 // Webkit is asking whether to navigate to a new URL.
2630 // This is fine normally, except if we're showing UI from one security
2631 // context and they're trying to navigate to a different context.
2632 const GURL& url = request.url();
2633
2634 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302635 // navigations.
[email protected]8079b362010-05-07 18:37:452636 if (renderer_preferences_.browser_handles_top_level_requests &&
2637 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192638 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232639 // Reset these counters as the RenderView could be reused for the next
2640 // navigation.
2641 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232642 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192643 OpenURL(url, referrer, default_policy);
2644 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172645 }
2646
2647 // A content initiated navigation may have originated from a link-click,
2648 // script, drag-n-drop operation, etc.
2649 bool is_content_initiated =
2650 NavigationState::FromDataSource(frame->provisionalDataSource())->
2651 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582652 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172653
2654 // We only care about navigations that are within the current tab (as opposed
2655 // to, for example, opening a new window).
2656 // But we sometimes navigate to about:blank to clear a tab, and we want to
2657 // still allow that.
2658 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2659 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532660 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172661 !url.SchemeIs(chrome::kAboutScheme)) {
2662 // When we received such unsolicited navigations, we sometimes want to
2663 // punt them up to the browser to handle.
[email protected]5351dbc2010-08-27 15:22:112664 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172665 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422666 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]5351dbc2010-08-27 15:22:112667 // We don't send referrer from these special pages.
[email protected]3d9689372009-09-10 04:29:172668 OpenURL(url, GURL(), default_policy);
2669 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2670 }
[email protected]8079b362010-05-07 18:37:452671
[email protected]5351dbc2010-08-27 15:22:112672 // We forward non-local navigations from extensions to the browser if they
2673 // are top-level events, even if the browser hasn't expressed interest.
[email protected]a6b960ad972010-09-01 19:53:582674 // TODO(erikkay) crbug.com/54118 - combine this clause and the next into
2675 // some shared logic.
[email protected]8079b362010-05-07 18:37:452676 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]a6b960ad972010-09-01 19:53:582677 old_url.SchemeIs(chrome::kExtensionScheme) &&
[email protected]c240ace2010-06-16 18:31:532678 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]5351dbc2010-08-27 15:22:112679 // We don't send referrer from extensions.
[email protected]8079b362010-05-07 18:37:452680 OpenURL(url, GURL(), default_policy);
2681 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2682 }
[email protected]5351dbc2010-08-27 15:22:112683
2684 // If the navigation would cross an app extent boundary, we also need
2685 // to defer to the browser to ensure process isolation.
2686 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2687 // which means that things like the back button won't trigger it. Is that
2688 // OK?
2689 if (CrossesExtensionExtents(frame, url)) {
2690 // Include the referrer in this case since we're going from a hosted web
2691 // page. (the packaged case is handled previously by the extension
2692 // navigation test)
2693 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2694 OpenURL(url, referrer, default_policy);
2695 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2696 }
[email protected]3d9689372009-09-10 04:29:172697 }
2698
2699 // Detect when a page is "forking" a new tab that can be safely rendered in
2700 // its own process. This is done by sites like Gmail that try to open links
2701 // in new windows without script connections back to the original page. We
2702 // treat such cases as browser navigations (in which we will create a new
2703 // renderer for a cross-site navigation), rather than WebKit navigations.
2704 //
2705 // We use the following heuristic to decide whether to fork a new page in its
2706 // own process:
2707 // The parent page must open a new tab to about:blank, set the new tab's
2708 // window.opener to null, and then redirect the tab to a cross-site URL using
2709 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462710 //
2711 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2712 // (see below).
[email protected]3d9689372009-09-10 04:29:172713 bool is_fork =
2714 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582715 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172716 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522717 historyBackListCount() < 1 &&
2718 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172719 // The parent page must have set the child's window.opener to null before
2720 // redirecting to the desired URL.
2721 frame->opener() == NULL &&
2722 // Must be a top-level frame.
2723 frame->parent() == NULL &&
2724 // Must not have issued the request from this page.
2725 is_content_initiated &&
2726 // Must be targeted at the current tab.
2727 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2728 // Must be a JavaScript navigation, which appears as "other".
2729 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462730
2731 // Recognize if this navigation is from a link with rel=noreferrer and
2732 // target=_blank attributes, in which case the opener will be suppressed. If
2733 // so, it is safe to load cross-site pages in a separate process, so we
2734 // should let the browser handle it.
2735 bool is_noreferrer_and_blank_target =
2736 // Frame should be top level and not yet navigated.
2737 frame->parent() == NULL &&
2738 frame->url().isEmpty() &&
2739 historyBackListCount() < 1 &&
2740 historyForwardListCount() < 1 &&
2741 // Links with rel=noreferrer will have no Referer field, and their
2742 // resulting frame will have its window.opener suppressed.
2743 // TODO(creis): should add a request.httpReferrer() method to help avoid
2744 // typos on the unusual spelling of Referer.
2745 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2746 opener_suppressed_ &&
2747 frame->opener() == NULL &&
2748 // Links with target=_blank will have no name.
2749 frame->name().isNull() &&
2750 // Another frame (with a non-empty creator) should have initiated the
2751 // request, targeted at this frame.
2752 !creator_url_.is_empty() &&
2753 is_content_initiated &&
2754 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2755 type == WebKit::WebNavigationTypeOther;
2756
2757 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172758 // Open the URL via the browser, not via WebKit.
2759 OpenURL(url, GURL(), default_policy);
2760 return WebKit::WebNavigationPolicyIgnore;
2761 }
2762
2763 return default_policy;
2764}
2765
[email protected]6069da8c2009-10-20 20:33:492766bool RenderView::canHandleRequest(
2767 WebFrame* frame, const WebURLRequest& request) {
2768 // We allow WebKit to think that everything can be handled even though
2769 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342770 return true;
2771}
2772
[email protected]6069da8c2009-10-20 20:33:492773WebURLError RenderView::cannotHandleRequestError(
2774 WebFrame* frame, const WebURLRequest& request) {
2775 NOTREACHED(); // Since we said we can handle all requests.
2776 return WebURLError();
2777}
2778
2779WebURLError RenderView::cancelledError(
2780 WebFrame* frame, const WebURLRequest& request) {
2781 WebURLError error;
2782 error.domain = WebString::fromUTF8(net::kErrorDomain);
2783 error.reason = net::ERR_ABORTED;
2784 error.unreachableURL = request.url();
2785 return error;
[email protected]7b7a7dc2009-10-19 02:23:342786}
2787
2788void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492789 WebFrame*, const WebURLError&) {
2790 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342791}
2792
[email protected]90eeddb2010-05-06 21:06:432793void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2794 const WebKit::WebFormElement& form) {
2795 // Some login forms have onSubmit handlers that put a hash of the password
2796 // into a hidden field and then clear the password. (Issue 28910.)
2797 // This method gets called before any of those handlers run, so save away
2798 // a copy of the password in case it gets lost.
2799 NavigationState* navigation_state =
2800 NavigationState::FromDataSource(frame->dataSource());
2801 navigation_state->set_password_form_data(
2802 PasswordFormDomManager::CreatePasswordForm(form));
2803}
2804
[email protected]979c28b2009-11-07 01:30:482805void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172806 NavigationState* navigation_state =
2807 NavigationState::FromDataSource(frame->provisionalDataSource());
2808
2809 if (navigation_state->transition_type() == PageTransition::LINK)
2810 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2811
2812 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352813 WebSearchableFormData web_searchable_form_data(form);
2814 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2815 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212816 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432817 PasswordForm* password_form_data =
2818 PasswordFormDomManager::CreatePasswordForm(form);
2819 navigation_state->set_password_form_data(password_form_data);
2820
2821 // If the password has been cleared, recover it from the form contents already
2822 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2823 // opposed to the provisionalDataSource's, which is what we're storing into
2824 // now.)
2825 if (password_form_data && password_form_data->password_value.empty()) {
2826 NavigationState* old_navigation_state =
2827 NavigationState::FromDataSource(frame->dataSource());
2828 if (old_navigation_state) {
2829 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2830 if (old_form_data && old_form_data->action == password_form_data->action)
2831 password_form_data->password_value = old_form_data->password_value;
2832 }
2833 }
[email protected]3d9689372009-09-10 04:29:172834
[email protected]b1438212010-04-03 00:30:592835 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042836 if (FormManager::WebFormElementToFormData(
[email protected]1fa7b482010-10-01 18:28:582837 form, FormManager::REQUIRE_AUTOCOMPLETE, true, false, &form_data))
[email protected]b1438212010-04-03 00:30:592838 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172839}
2840
2841void RenderView::willPerformClientRedirect(
2842 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2843 double fire_time) {
2844 // Ignore
2845}
2846
2847void RenderView::didCancelClientRedirect(WebFrame* frame) {
2848 // Ignore
2849}
2850
2851void RenderView::didCompleteClientRedirect(
2852 WebFrame* frame, const WebURL& from) {
2853 if (!frame->parent())
2854 completed_client_redirect_src_ = from;
2855}
2856
2857void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2858 // The rest of RenderView assumes that a WebDataSource will always have a
2859 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482860 bool content_initiated = !pending_navigation_state_.get();
2861 NavigationState* state = content_initiated ?
2862 NavigationState::CreateContentInitiated() :
2863 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512864
[email protected]8a3125a712010-08-09 18:58:512865 // NavigationState::referred_by_prefetcher_ is true if we are
2866 // navigating from a page that used prefetching using a link on that
2867 // page. We are early enough in the request process here that we
2868 // can still see the NavigationState of the previous page and set
2869 // this value appropriately.
2870 // TODO(gavinp): catch the important case of navigation in a new
2871 // renderer process.
2872 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302873 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522874 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512875 const GURL referrer(
2876 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2877 if (!referrer.is_empty() &&
2878 NavigationState::FromDataSource(
2879 old_frame->dataSource())->was_prefetcher()) {
2880 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2881 WebDataSource* old_frame_ds = old_frame->dataSource();
2882 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2883 state->set_was_referred_by_prefetcher(true);
2884 break;
2885 }
2886 }
2887 }
2888 }
2889 }
2890
[email protected]4c1b6f0b2010-02-07 16:38:182891 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522892 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512893 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182894 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2895 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2896 break;
2897 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2898 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2899 break;
2900 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2901 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2902 break;
2903 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2904 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2905 break;
2906 }
2907 }
[email protected]fa7b6b542009-11-03 05:02:302908
2909 state->set_user_script_idle_scheduler(
2910 new UserScriptIdleScheduler(this, frame));
2911 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172912}
2913
2914void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2915 WebDataSource* ds = frame->provisionalDataSource();
2916 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2917
[email protected]3d9689372009-09-10 04:29:172918 // Update the request time if WebKit has better knowledge of it.
2919 if (navigation_state->request_time().is_null()) {
2920 double event_time = ds->triggeringEventTime();
2921 if (event_time != 0.0)
2922 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2923 }
2924
[email protected]05c8e502010-08-15 15:13:522925 // Start time is only set after request time.
2926 navigation_state->set_start_load_time(Time::Now());
2927
[email protected]3d9689372009-09-10 04:29:172928 bool is_top_most = !frame->parent();
2929 if (is_top_most) {
2930 navigation_gesture_ = frame->isProcessingUserGesture() ?
2931 NavigationGestureUnknown : NavigationGestureAuto;
2932
2933 // Make sure redirect tracking state is clear for the new load.
2934 completed_client_redirect_src_ = GURL();
2935 } else if (frame->parent()->isLoading()) {
2936 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002937 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172938 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2939 }
2940
2941 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:072942 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172943}
2944
2945void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2946 if (frame->parent())
2947 return;
2948 // Received a redirect on the main frame.
2949 WebDataSource* data_source = frame->provisionalDataSource();
2950 if (!data_source) {
2951 // Should only be invoked when we have a data source.
2952 NOTREACHED();
2953 return;
2954 }
2955 std::vector<GURL> redirects;
2956 GetRedirectChain(data_source, &redirects);
2957 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512958 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2959 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172960 }
2961}
2962
[email protected]40bd6582009-12-04 23:49:512963void RenderView::didFailProvisionalLoad(WebFrame* frame,
2964 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172965 // Notify the browser that we failed a provisional load with an error.
2966 //
2967 // Note: It is important this notification occur before DidStopLoading so the
2968 // SSL manager can react to the provisional load failure before being
2969 // notified the load stopped.
2970 //
2971 WebDataSource* ds = frame->provisionalDataSource();
2972 DCHECK(ds);
2973
2974 const WebURLRequest& failed_request = ds->request();
2975
2976 bool show_repost_interstitial =
2977 (error.reason == net::ERR_CACHE_MISS &&
2978 EqualsASCII(failed_request.httpMethod(), "POST"));
2979 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072980 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2981 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172982
2983 // Don't display an error page if this is simply a cancelled load. Aside
2984 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2985 if (error.reason == net::ERR_ABORTED)
2986 return;
2987
2988 // Make sure we never show errors in view source mode.
2989 frame->enableViewSourceMode(false);
2990
2991 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2992
2993 // If this is a failed back/forward/reload navigation, then we need to do a
2994 // 'replace' load. This is necessary to avoid messing up session history.
2995 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2996 // as session history is concerned.
2997 //
2998 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2999 // the page id.
3000 //
3001 bool replace =
3002 navigation_state->pending_page_id() != -1 ||
3003 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3004
3005 // If we failed on a browser initiated request, then make sure that our error
3006 // page load is regarded as the same browser initiated request.
3007 if (!navigation_state->is_content_initiated()) {
3008 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3009 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003010 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173011 navigation_state->transition_type(),
3012 navigation_state->request_time()));
3013 }
3014
3015 // Provide the user with a more helpful error page?
3016 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3017 return;
3018
3019 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083020 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173021}
3022
3023void RenderView::didReceiveDocumentData(
3024 WebFrame* frame, const char* data, size_t data_len,
3025 bool& prevent_default) {
3026 NavigationState* navigation_state =
3027 NavigationState::FromDataSource(frame->dataSource());
3028 if (!navigation_state->postpone_loading_data())
3029 return;
3030
3031 // We're going to call commitDocumentData ourselves...
3032 prevent_default = true;
3033
[email protected]3f853a52010-09-13 19:15:083034 // Continue buffering the response data for the original error page. If it
3035 // grows too large, then we'll just let it through. For any error other than
3036 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173037 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083038 if (navigation_state->postponed_data().size() >= 512 ||
3039 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173040 navigation_state->set_postpone_loading_data(false);
3041 frame->commitDocumentData(navigation_state->postponed_data().data(),
3042 navigation_state->postponed_data().size());
3043 navigation_state->clear_postponed_data();
3044 }
3045}
3046
[email protected]40bd6582009-12-04 23:49:513047void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3048 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173049 NavigationState* navigation_state =
3050 NavigationState::FromDataSource(frame->dataSource());
3051
3052 navigation_state->set_commit_load_time(Time::Now());
3053 if (is_new_navigation) {
3054 // When we perform a new navigation, we need to update the previous session
3055 // history entry with state for the page we are leaving.
3056 UpdateSessionHistory(frame);
3057
3058 // We bump our Page ID to correspond with the new session history entry.
3059 page_id_ = next_page_id_++;
3060
[email protected]d64b07b2010-04-20 22:14:063061 // Any pending translation is now obsolete.
3062 translate_helper_.CancelPendingTranslation();
3063
[email protected]3cc72b12010-03-18 23:03:003064 // Advance our offset in session history, applying the length limit. There
3065 // is now no forward history.
3066 history_list_offset_++;
3067 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3068 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3069 history_list_length_ = history_list_offset_ + 1;
3070
[email protected]f9f4841b2010-03-20 05:41:423071 MessageLoop::current()->PostDelayedTask(
3072 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303073 page_info_method_factory_.NewRunnableMethod(
3074 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173075 kDelayForForcedCaptureMs);
3076 } else {
3077 // Inspect the navigation_state on this frame to see if the navigation
3078 // corresponds to a session history navigation... Note: |frame| may or
3079 // may not be the toplevel frame, but for the case of capturing session
3080 // history, the first committed frame suffices. We keep track of whether
3081 // we've seen this commit before so that only capture session history once
3082 // per navigation.
3083 //
3084 // Note that we need to check if the page ID changed. In the case of a
3085 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3086 // previous URL and the current page ID, which would be wrong.
3087 if (navigation_state->pending_page_id() != -1 &&
3088 navigation_state->pending_page_id() != page_id_ &&
3089 !navigation_state->request_committed()) {
3090 // This is a successful session history navigation!
3091 UpdateSessionHistory(frame);
3092 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003093
3094 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173095 }
3096 }
3097
3098 // Remember that we've already processed this request, so we don't update
3099 // the session history again. We do this regardless of whether this is
3100 // a session history navigation, because if we attempted a session history
3101 // navigation without valid HistoryItem state, WebCore will think it is a
3102 // new navigation.
3103 navigation_state->set_request_committed(true);
3104
3105 UpdateURL(frame);
3106
3107 // If this committed load was initiated by a client redirect, we're
3108 // at the last stop now, so clear it.
3109 completed_client_redirect_src_ = GURL();
3110
3111 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273112 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173113}
3114
3115void RenderView::didClearWindowObject(WebFrame* frame) {
3116 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3117 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453118 GURL frame_url = frame->url();
3119 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253120 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3121 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c091c2c2010-09-17 19:05:463122 GetDOMUIBindings()->set_message_sender(this);
3123 GetDOMUIBindings()->set_routing_id(routing_id_);
3124 GetDOMUIBindings()->BindToJavascript(frame, L"chrome");
[email protected]3d9689372009-09-10 04:29:173125 }
3126 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463127 GetExternalHostBindings()->set_message_sender(this);
3128 GetExternalHostBindings()->set_routing_id(routing_id_);
3129 GetExternalHostBindings()->BindToJavascript(frame, L"externalHost");
[email protected]3d9689372009-09-10 04:29:173130 }
3131}
3132
3133void RenderView::didCreateDocumentElement(WebFrame* frame) {
3134 if (RenderThread::current()) { // Will be NULL during unit tests.
3135 RenderThread::current()->user_script_slave()->InjectScripts(
3136 frame, UserScript::DOCUMENT_START);
3137 }
3138
3139 // Notify the browser about non-blank documents loading in the top frame.
3140 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253141 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273142 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173143 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3144 }
3145}
3146
3147void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3148 UpdateTitle(frame, title);
3149
3150 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273151 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173152}
3153
[email protected]5019ef12010-04-27 17:26:583154void RenderView::didChangeIcons(WebFrame* frame) {
3155 if (!frame->parent()) {
3156 Send(new ViewHostMsg_UpdateFavIconURL(
3157 routing_id_,
3158 page_id_,
3159 frame->favIconURL()));
3160 }
3161}
3162
[email protected]3d9689372009-09-10 04:29:173163void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3164 WebDataSource* ds = frame->dataSource();
3165 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3166 DCHECK(navigation_state);
3167 navigation_state->set_finish_document_load_time(Time::Now());
3168
3169 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
3170
[email protected]6a8ddba52010-09-05 04:38:063171 page_click_tracker_->StartTrackingFrame(frame);
[email protected]e9e07992010-02-17 21:04:363172 // The document has now been fully loaded. Scan for forms to be sent up to
3173 // the browser.
[email protected]6a8ddba52010-09-05 04:38:063174 autofill_helper_->FrameContentsAvailable(frame);
3175 password_autocomplete_manager_->SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:173176
3177 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273178 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173179
3180 if (RenderThread::current()) { // Will be NULL during unit tests.
3181 RenderThread::current()->user_script_slave()->InjectScripts(
3182 frame, UserScript::DOCUMENT_END);
3183 }
[email protected]fa7b6b542009-11-03 05:02:303184
3185 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3186}
3187
3188void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3189 if (RenderThread::current()) { // Will be NULL during unit tests.
3190 RenderThread::current()->user_script_slave()->InjectScripts(
3191 frame, UserScript::DOCUMENT_IDLE);
3192 }
3193
3194 WebFrame* main_frame = webview()->mainFrame();
3195 if (frame == main_frame) {
3196 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203197 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303198 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203199 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303200 pending_code_execution_queue_.pop();
3201 }
3202 }
[email protected]3d9689372009-09-10 04:29:173203}
3204
3205void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083206 if (webview()->mainFrame() == frame) {
3207 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3208 page_id_));
3209 }
[email protected]3d9689372009-09-10 04:29:173210}
3211
3212void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3213 // Ignore
3214}
3215
3216void RenderView::didFinishLoad(WebFrame* frame) {
3217 WebDataSource* ds = frame->dataSource();
3218 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3219 DCHECK(navigation_state);
3220 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303221 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413222
3223 // Let the password manager know which password forms are actually visible.
[email protected]6a8ddba52010-09-05 04:38:063224 password_autocomplete_manager_->SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:173225}
3226
[email protected]ccbe04e2010-03-17 17:58:433227void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173228 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063229 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3230 // since a new one gets created by didCreateDataSource.
[email protected]af15bed2010-08-25 21:12:093231 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
[email protected]f6c2459d2010-02-24 22:34:063232 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3233
[email protected]3d9689372009-09-10 04:29:173234 // If this was a reference fragment navigation that we initiated, then we
3235 // could end up having a non-null pending navigation state. We just need to
3236 // update the ExtraData on the datasource so that others who read the
3237 // ExtraData will get the new NavigationState. Similarly, if we did not
3238 // initiate this navigation, then we need to take care to reset any pre-
3239 // existing navigation state to a content-initiated navigation state.
3240 // DidCreateDataSource conveniently takes care of this for us.
3241 didCreateDataSource(frame, frame->dataSource());
3242
[email protected]af15bed2010-08-25 21:12:093243 NavigationState* new_state =
3244 NavigationState::FromDataSource(frame->dataSource());
3245 new_state->set_was_within_same_page(true);
3246
[email protected]f6c2459d2010-02-24 22:34:063247 if (idle_scheduler_ran) {
3248 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
[email protected]f6c2459d2010-02-24 22:34:063249 new_state->user_script_idle_scheduler()->set_has_run(true);
3250 }
3251
[email protected]3d9689372009-09-10 04:29:173252 didCommitProvisionalLoad(frame, is_new_navigation);
3253
[email protected]26aa0482009-09-30 16:55:273254 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173255}
3256
[email protected]476b6f82009-09-10 21:00:593257void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313258 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593259}
3260
[email protected]3d9689372009-09-10 04:29:173261void RenderView::assignIdentifierToRequest(
3262 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3263 // Ignore
3264}
3265
3266void RenderView::willSendRequest(
3267 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3268 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303269 WebFrame* top_frame = frame->top();
3270 if (!top_frame)
3271 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513272 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3273 WebDataSource* top_data_source = top_frame->dataSource();
3274 WebDataSource* data_source =
3275 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303276 if (data_source) {
3277 NavigationState* state = NavigationState::FromDataSource(data_source);
3278 if (state && state->is_cache_policy_override_set())
3279 request.setCachePolicy(state->cache_policy_override());
3280 }
[email protected]8a3125a712010-08-09 18:58:513281
3282 if (top_data_source) {
3283 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3284 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3285 state->set_was_prefetcher(true);
3286 }
3287
[email protected]3d9689372009-09-10 04:29:173288 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503289 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133290 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493291
[email protected]85cc78c2010-05-04 18:30:093292 // Temporary metrics, see site_isolation_metrics.h
3293 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173294}
3295
3296void RenderView::didReceiveResponse(
3297 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493298
[email protected]85cc78c2010-05-04 18:30:093299 // Temporary metrics, see site_isolation_metrics.h
3300 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3301 identifier,
3302 response);
[email protected]fa0a3432010-03-30 16:53:493303
[email protected]3d9689372009-09-10 04:29:173304 // Only do this for responses that correspond to a provisional data source
3305 // of the top-most frame. If we have a provisional data source, then we
3306 // can't have any sub-resources yet, so we know that this response must
3307 // correspond to a frame load.
3308 if (!frame->provisionalDataSource() || frame->parent())
3309 return;
3310
3311 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083312 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173313 if (frame->isViewSourceModeEnabled())
3314 return;
3315
[email protected]65041fa2010-05-21 06:56:533316 NavigationState* navigation_state =
3317 NavigationState::FromDataSource(frame->provisionalDataSource());
3318 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083319 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533320
[email protected]972ebdff2010-06-10 22:59:073321 // Record page load flags.
3322 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3323 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573324 navigation_state->set_was_alternate_protocol_available(
3325 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073326 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083327 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533328
[email protected]f48013be2010-01-14 22:07:453329 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083330 if (http_status_code == 404) {
3331 // Can we even load an alternate error page for this URL?
3332 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3333 return;
3334 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3335 http_status_code)) {
3336 // If no corresponding error strings for a particular status code, just
3337 // render any received data, regardless of whether or not the status code
3338 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453339 return;
[email protected]3f853a52010-09-13 19:15:083340 }
[email protected]3d9689372009-09-10 04:29:173341
[email protected]3d9689372009-09-10 04:29:173342 navigation_state->set_postpone_loading_data(true);
3343 navigation_state->clear_postponed_data();
3344}
3345
3346void RenderView::didFinishResourceLoad(
3347 WebFrame* frame, unsigned identifier) {
3348 NavigationState* navigation_state =
3349 NavigationState::FromDataSource(frame->dataSource());
3350 if (!navigation_state->postpone_loading_data())
3351 return;
3352
[email protected]3f853a52010-09-13 19:15:083353 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173354 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083355 int http_status_code = navigation_state->http_status_code();
3356 if (http_status_code == 404) {
3357 // On 404s, try a remote search page as a fallback.
3358 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173359
[email protected]3f853a52010-09-13 19:15:083360 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3361 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173362
[email protected]3f853a52010-09-13 19:15:083363 WebURLError original_error;
3364 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173365
[email protected]3f853a52010-09-13 19:15:083366 navigation_state->set_alt_error_page_fetcher(
3367 new AltErrorPageResourceFetcher(
3368 error_page_url, frame, original_error,
3369 NewCallback(this, &RenderView::AltErrorPageFinished)));
3370 } else {
3371 // On other errors, use an internal error page.
3372 WebURLError error;
3373 error.unreachableURL = frame->url();
3374 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3375 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173376
[email protected]3f853a52010-09-13 19:15:083377 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3378 std::string(), true);
3379 }
[email protected]3d9689372009-09-10 04:29:173380}
3381
3382void RenderView::didFailResourceLoad(
3383 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3384 // Ignore
3385}
3386
3387void RenderView::didLoadResourceFromMemoryCache(
3388 WebFrame* frame, const WebURLRequest& request,
3389 const WebURLResponse& response) {
3390 // Let the browser know we loaded a resource from the memory cache. This
3391 // message is needed to display the correct SSL indicators.
3392 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3393 routing_id_,
3394 request.url(),
[email protected]91733b62009-09-18 06:21:093395 frame->securityOrigin().toString().utf8(),
3396 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173397 response.securityInfo()));
3398}
3399
[email protected]6069da8c2009-10-20 20:33:493400void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293401 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3402}
3403
3404void RenderView::didRunInsecureContent(
3405 WebFrame* frame, const WebSecurityOrigin& origin) {
3406 Send(new ViewHostMsg_DidRunInsecureContent(
3407 routing_id_,
3408 origin.toString().utf8()));
3409}
3410
[email protected]7ea093ba2009-11-03 05:54:593411bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403412 if (enabled_per_settings &&
3413 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3414 return true;
[email protected]7ea093ba2009-11-03 05:54:593415
[email protected]12bc8472010-04-15 07:29:403416 if (IsWhitelistedForContentSettings(frame))
3417 return true;
[email protected]7ea093ba2009-11-03 05:54:593418
3419 return false; // Other protocols fall through here.
3420}
3421
[email protected]0a1a45432010-03-31 08:09:453422bool RenderView::allowDatabase(
3423 WebFrame* frame, const WebString& name, const WebString& display_name,
3424 unsigned long estimated_size) {
3425 WebSecurityOrigin origin = frame->securityOrigin();
3426 if (origin.isEmpty())
3427 return false; // Uninitialized document?
3428
3429 bool result;
3430 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3431 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3432 return false;
[email protected]9fb83e82010-07-02 18:24:553433 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3434 GURL(origin.toString().utf8()),
3435 name,
3436 display_name,
3437 estimated_size,
3438 !result));
[email protected]0a1a45432010-03-31 08:09:453439 return result;
3440}
[email protected]8934a3b2010-02-25 00:34:003441void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283442 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003443}
3444
[email protected]c21f1d52010-03-04 03:19:433445void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283446 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433447}
3448
[email protected]3d9689372009-09-10 04:29:173449void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3450 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3451}
3452
[email protected]0c882b282009-10-07 17:01:283453void RenderView::didCreateScriptContext(WebFrame* frame) {
3454 EventBindings::HandleContextCreated(frame, false);
3455}
3456
3457void RenderView::didDestroyScriptContext(WebFrame* frame) {
3458 EventBindings::HandleContextDestroyed(frame);
3459}
3460
3461void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3462 EventBindings::HandleContextCreated(frame, true);
3463}
3464
[email protected]af7eb3fb2010-09-23 21:31:063465bool RenderView::allowScriptExtension(WebFrame* frame,
3466 const WebString& extension_name,
3467 int extension_group) {
3468 // NULL in unit tests.
3469 if (!RenderThread::current())
3470 return true;
3471
3472 // Note: we prefer the provisional URL here instead of the document URL
3473 // because we might be currently loading an URL into a blank page.
3474 // See http://code.google.com/p/chromium/issues/detail?id=10924
3475 WebDataSource* ds = frame->provisionalDataSource();
3476 if (!ds)
3477 ds = frame->dataSource();
3478 return RenderThread::current()->AllowScriptExtension(
3479 extension_name.utf8(), ds->request().url(), extension_group);
3480}
3481
[email protected]fc86daa2010-03-30 23:52:533482void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3483 WebFrame* target,
3484 bool cross_origin,
3485 const WebString& property_name,
3486 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103487 // TODO(johnnyg): track the individual properties and repeat event_ids.
3488 if (cross_origin)
3489 cross_origin_access_count_++;
3490 else
3491 same_origin_access_count_++;
3492}
3493
[email protected]3d9689372009-09-10 04:29:173494void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143495 CheckPreferredSize();
3496}
3497
3498void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173499 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253500 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173501 // message.
[email protected]705243f2010-05-05 19:58:073502 if (!send_preferred_size_changes_ || !webview())
3503 return;
[email protected]dfca5acf2010-03-22 03:28:433504
[email protected]705243f2010-05-05 19:58:073505 // WebCore likes to tell us things have changed even when they haven't, so
3506 // cache the width and height and only send the IPC message when we're sure
3507 // they're different.
3508 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3509 webview()->mainFrame()->documentElementScrollHeight());
3510 if (size == preferred_size_)
3511 return;
[email protected]c27324b2009-11-19 22:44:293512
[email protected]705243f2010-05-05 19:58:073513 preferred_size_ = size;
3514 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3515 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173516}
3517
[email protected]143dcd592009-11-06 21:33:493518void RenderView::didChangeScrollOffset(WebFrame* frame) {
3519 StartNavStateSyncTimerIfNecessary();
3520}
3521
[email protected]8922e1f2009-10-03 05:01:263522void RenderView::reportFindInPageMatchCount(int request_id, int count,
3523 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113524 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3525 if (!count)
3526 active_match_ordinal = 0;
3527
3528 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3529 routing_id_,
3530 request_id,
3531 count,
3532 gfx::Rect(),
3533 active_match_ordinal,
3534 final_update);
3535
[email protected]8922e1f2009-10-03 05:01:263536 // If we have a message that has been queued up, then we should just replace
3537 // it. The ACK from the browser will make sure it gets sent when the browser
3538 // wants it.
3539 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263540 queued_find_reply_message_.reset(msg);
3541 } else {
3542 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113543 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263544 }
3545}
3546
3547void RenderView::reportFindInPageSelection(int request_id,
3548 int active_match_ordinal,
3549 const WebRect& selection_rect) {
3550 // Send the search result over to the browser process.
3551 Send(new ViewHostMsg_Find_Reply(routing_id_,
3552 request_id,
3553 -1,
3554 selection_rect,
3555 active_match_ordinal,
3556 false));
3557}
3558
[email protected]2b06a992010-08-21 05:48:223559void RenderView::openFileSystem(
3560 WebFrame* frame,
3561 WebFileSystem::Type type,
3562 long long size,
3563 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083564 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223565
3566 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083567 if (origin.isEmpty()) {
3568 // Uninitialized document?
3569 callbacks->didFail(WebKit::WebFileErrorAbort);
3570 return;
3571 }
[email protected]2b06a992010-08-21 05:48:223572
[email protected]c5a272d2010-09-27 18:37:083573 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3574 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
3575 size, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223576}
3577
[email protected]79dbc662009-09-04 05:42:513578// webkit_glue::WebPluginPageDelegate -----------------------------------------
3579
[email protected]f103ab72009-09-02 17:10:593580webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533581 const FilePath& file_path,
3582 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593583 if (!PluginChannelHost::IsListening())
3584 return NULL;
3585
[email protected]d2139662009-12-10 03:21:143586 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283587 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143588 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163589 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533590 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143591 if (CommandLine::ForCurrentProcess()->
3592 HasSwitch(switches::kInternalPepper)) {
3593 in_process_plugin = true;
3594 use_pepper_host = true;
3595 } else {
3596 // In process Pepper plugins must be explicitly enabled.
3597 return NULL;
3598 }
[email protected]4e0616e2010-05-28 14:55:533599 } else {
3600 FilePath internal_pdf_path;
3601 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3602 if (file_path == internal_pdf_path) {
3603 in_process_plugin = true;
3604 use_pepper_host = true;
3605 }
[email protected]26e8d5e2009-10-13 02:47:163606 }
[email protected]4e0616e2010-05-28 14:55:533607
[email protected]d2139662009-12-10 03:21:143608 // Check for Native Client modules.
[email protected]5cad70a82010-09-03 22:14:113609 if (mime_type == "application/x-nacl-srpc" &&
3610 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
[email protected]8f05f7f2010-07-30 23:12:433611 // NaCl is only permitted when we're in an extension/application with the
3612 // appropriate permission, or when explicitly enabled on the command line.
3613
[email protected]8f05f7f2010-07-30 23:12:433614 GURL main_frame_url(webview()->mainFrame()->url());
[email protected]5351dbc2010-08-27 15:22:113615 ExtensionRendererInfo* extension =
3616 ExtensionRendererInfo::GetByURL(main_frame_url);
3617 bool in_ext = extension != NULL;
[email protected]8f05f7f2010-07-30 23:12:433618 bool explicit_enable =
3619 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3620
3621 if (in_ext) {
[email protected]5cad70a82010-09-03 22:14:113622 // TODO(cbiffle): NaCl is back to experimental for M7.
[email protected]5351dbc2010-08-27 15:22:113623 if (ExtensionProcessBindings::HasPermission(extension->id(),
[email protected]5cad70a82010-09-03 22:14:113624 Extension::kExperimentalPermission)) {
[email protected]8f05f7f2010-07-30 23:12:433625 in_process_plugin = true;
3626 use_pepper_host = true;
3627 } else {
3628 // Disable NaCl for apps lacking the permission, even with the flag.
3629 return NULL;
3630 }
3631 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463632 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143633 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463634 }
3635 }
[email protected]4e0616e2010-05-28 14:55:533636
[email protected]d032f492009-09-29 00:33:463637 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143638 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283639 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533640 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333641 if (!pepper_plugin)
3642 return NULL;
3643
[email protected]53900d52010-06-16 04:25:013644 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283645 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143646 } else {
[email protected]6876dff2010-01-15 19:38:093647#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143648 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533649 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093650#else
[email protected]596b2c42010-01-14 20:40:433651 NOTIMPLEMENTED();
3652 return NULL;
[email protected]7b6616f2010-01-14 18:07:553653#endif
[email protected]6876dff2010-01-15 19:38:093654 }
[email protected]f103ab72009-09-02 17:10:593655 }
3656
[email protected]4e0616e2010-05-28 14:55:533657 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593658}
3659
3660void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033661#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593662 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3663 routing_id(), window));
3664#endif
3665}
3666
3667void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033668#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593669 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3670 routing_id(), window));
3671#endif
3672 CleanupWindowInPluginMoves(window);
3673}
3674
3675void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3676 SchedulePluginMove(move);
3677}
3678
3679void RenderView::DidStartLoadingForPlugin() {
3680 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523681 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593682}
3683
3684void RenderView::DidStopLoadingForPlugin() {
3685 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523686 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593687}
3688
3689void RenderView::ShowModalHTMLDialogForPlugin(
3690 const GURL& url,
3691 const gfx::Size& size,
3692 const std::string& json_arguments,
3693 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213694 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593695 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213696 json_retval));
[email protected]f103ab72009-09-02 17:10:593697}
3698
[email protected]b921cfd22010-02-25 16:57:513699WebCookieJar* RenderView::GetCookieJar() {
3700 return &cookie_jar_;
3701}
3702
initial.commit09911bf2008-07-26 23:55:293703void RenderView::SyncNavigationState() {
3704 if (!webview())
3705 return;
3706
[email protected]26aa0482009-09-30 16:55:273707 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173708 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293709 return;
[email protected]ca948a22009-06-25 19:36:173710
3711 Send(new ViewHostMsg_UpdateState(
3712 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293713}
3714
[email protected]b0950a72009-09-29 23:16:173715bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3716 // Make sure webview was not shut down.
3717 if (!webview())
3718 return false;
3719 // Create an image resource fetcher and assign it with a call back object.
3720 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273721 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173722 NewCallback(this, &RenderView::DidDownloadImage)));
3723 return true;
3724}
3725
3726void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293727 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173728 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473729 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3730 fetcher->id(),
3731 fetcher->image_url(),
3732 image.isNull(),
3733 image));
[email protected]b0950a72009-09-29 23:16:173734 // Dispose of the image fetcher.
3735 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3736 image_fetchers_.erase(fetcher);
3737 // We're in the callback from the ImageResourceFetcher, best to delay
3738 // deletion.
3739 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293740}
3741
[email protected]bf5c2ff392009-07-08 16:24:333742void RenderView::OnDownloadFavIcon(int id,
3743 const GURL& image_url,
3744 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343745 bool data_image_failed = false;
3746 if (image_url.SchemeIs("data")) {
3747 SkBitmap data_image = ImageFromDataUrl(image_url);
3748 data_image_failed = data_image.empty();
3749 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333750 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3751 data_image));
[email protected]f11ca0732009-04-11 00:09:343752 }
3753 }
3754
[email protected]bf5c2ff392009-07-08 16:24:333755 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173756 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333757 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3758 SkBitmap()));
3759 }
initial.commit09911bf2008-07-26 23:55:293760}
3761
[email protected]f11ca0732009-04-11 00:09:343762SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3763 std::string mime_type, char_set, data;
3764 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3765 // Decode the favicon using WebKit's image decoder.
3766 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3767 const unsigned char* src_data =
3768 reinterpret_cast<const unsigned char*>(&data[0]);
3769
3770 return decoder.Decode(src_data, data.size());
3771 }
3772 return SkBitmap();
3773}
3774
initial.commit09911bf2008-07-26 23:55:293775void RenderView::OnGetApplicationInfo(int page_id) {
3776 webkit_glue::WebApplicationInfo app_info;
3777 if (page_id == page_id_)
3778 webkit_glue::GetApplicationInfo(webview(), &app_info);
3779
3780 // Prune out any data URLs in the set of icons. The browser process expects
3781 // any icon with a data URL to have originated from a favicon. We don't want
3782 // to decode arbitrary data URLs in the browser process. See
3783 // http://b/issue?id=1162972
3784 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593785 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293786 app_info.icons.erase(app_info.icons.begin() + i);
3787 --i;
3788 }
3789 }
3790
3791 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3792}
3793
[email protected]7ccddb8c2009-08-04 17:36:553794GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293795 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553796 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293797 // If the URL that failed was secure, then the embedding web page was not
3798 // expecting a network attacker to be able to manipulate its contents. As
3799 // we fetch alternate error pages over HTTP, we would be allowing a network
3800 // attacker to manipulate the contents of the response if we tried to use
3801 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153802 return GURL();
initial.commit09911bf2008-07-26 23:55:293803 }
3804
3805 // Grab the base URL from the browser process.
3806 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153807 return GURL();
initial.commit09911bf2008-07-26 23:55:293808
3809 // Strip query params from the failed URL.
3810 GURL::Replacements remove_params;
3811 remove_params.ClearUsername();
3812 remove_params.ClearPassword();
3813 remove_params.ClearQuery();
3814 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553815 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503816 std::string spec_to_send = url_to_send.spec();
3817 // Notify link doctor of the url truncation by sending of "?" at the end.
3818 if (failed_url.has_query())
3819 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293820
3821 // Construct the query params to send to link doctor.
3822 std::string params(alternate_error_page_url_.query());
3823 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503824 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293825 params.append("&sourceid=chrome");
3826 params.append("&error=");
3827 switch (error_type) {
3828 case DNS_ERROR:
3829 params.append("dnserror");
3830 break;
3831
3832 case HTTP_404:
3833 params.append("http404");
3834 break;
3835
[email protected]5df266ac2008-10-15 19:50:133836 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333837 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133838 break;
3839
initial.commit09911bf2008-07-26 23:55:293840 default:
3841 NOTREACHED() << "unknown ErrorPageType";
3842 }
3843
3844 // OK, build the final url to return.
3845 GURL::Replacements link_doctor_params;
3846 link_doctor_params.SetQueryStr(params);
3847 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3848 return url;
3849}
3850
[email protected]c091c2c2010-09-17 19:05:463851DOMUIBindings* RenderView::GetDOMUIBindings() {
3852 if (!dom_ui_bindings_.get()) {
3853 dom_ui_bindings_.reset(new DOMUIBindings());
3854 }
3855 return dom_ui_bindings_.get();
3856}
3857
3858ExternalHostBindings* RenderView::GetExternalHostBindings() {
3859 if (!external_host_bindings_.get()) {
3860 external_host_bindings_.reset(new ExternalHostBindings());
3861 }
3862 return external_host_bindings_.get();
3863}
3864
[email protected]0fdbf8c2010-07-08 20:33:013865WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3866 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493867}
3868
[email protected]6069da8c2009-10-20 20:33:493869void RenderView::OnFind(int request_id, const string16& search_text,
3870 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273871 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493872
3873 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493874 if (options.findNext) {
3875 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013876 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493877 } else {
[email protected]afdbd142010-07-10 08:01:233878 if (GetWebPluginFromPluginDocument()->startFind(
3879 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493880 } else {
[email protected]e7c58a32010-08-13 19:47:113881 // Send "no results".
3882 Send(new ViewHostMsg_Find_Reply(routing_id_,
3883 request_id,
3884 0,
3885 gfx::Rect(),
3886 0,
3887 true));
[email protected]24a7f3c2010-03-25 08:26:493888 }
3889 }
3890 return;
3891 }
3892
[email protected]b4bb2502009-10-01 22:35:273893 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273894 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293895 WebFrame* search_frame = focused_frame; // start searching focused frame.
3896
3897 bool multi_frame = (frame_after_main != main_frame);
3898
3899 // If we have multiple frames, we don't want to wrap the search within the
3900 // frame, so we check here if we only have main_frame in the chain.
3901 bool wrap_within_frame = !multi_frame;
3902
[email protected]b3f2b912009-04-09 16:18:523903 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293904 bool result = false;
3905
[email protected]7830da3e2009-11-06 16:27:263906 // If something is selected when we start searching it means we cannot just
3907 // increment the current match ordinal; we need to re-generate it.
3908 WebRange current_selection = focused_frame->selectionRange();
3909
initial.commit09911bf2008-07-26 23:55:293910 do {
[email protected]dd7daa82009-08-10 05:46:453911 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593912 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293913
3914 if (!result) {
3915 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223916 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293917
3918 // Find the next frame, but skip the invisible ones.
3919 do {
3920 // What is the next frame to search? (we might be going backwards). Note
3921 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593922 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273923 search_frame->traverseNext(true) :
3924 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453925 } while (!search_frame->hasVisibleContent() &&
3926 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293927
[email protected]884db412008-11-24 23:46:503928 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223929 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293930
3931 // If we have multiple frames and we have wrapped back around to the
3932 // focused frame, we need to search it once more allowing wrap within
3933 // the frame, otherwise it will report 'no match' if the focused frame has
3934 // reported matches, but no frames after the focused_frame contain a
3935 // match for the search word(s).
3936 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453937 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593938 request_id, search_text, options, true, // Force wrapping.
3939 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293940 }
3941 }
3942
[email protected]26aa0482009-09-30 16:55:273943 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293944 } while (!result && search_frame != focused_frame);
3945
[email protected]7830da3e2009-11-06 16:27:263946 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293947 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453948 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293949 } else {
3950 // If nothing is found, set result to "0 of 0", otherwise, set it to
3951 // "-1 of 1" to indicate that we found at least one item, but we don't know
3952 // yet what is active.
3953 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3954 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293955
[email protected]4f3dc372009-02-24 00:10:293956 // If we find no matches then this will be our last status update.
3957 // Otherwise the scoping effort will send more results.
3958 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293959
[email protected]4f3dc372009-02-24 00:10:293960 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403961 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593962 request_id,
[email protected]4f3dc372009-02-24 00:10:293963 match_count,
3964 selection_rect,
3965 ordinal,
3966 final_status_update));
initial.commit09911bf2008-07-26 23:55:293967
initial.commit09911bf2008-07-26 23:55:293968 // Scoping effort begins, starting with the mainframe.
3969 search_frame = main_frame;
3970
[email protected]dd7daa82009-08-10 05:46:453971 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293972
3973 do {
3974 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453975 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293976
3977 // We don't start another scoping effort unless at least one match has
3978 // been found.
3979 if (result) {
3980 // Start new scoping request. If the scoping function determines that it
3981 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453982 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593983 search_text,
3984 options,
initial.commit09911bf2008-07-26 23:55:293985 true); // reset the tickmarks
3986 }
3987
3988 // Iterate to the next frame. The frame will not necessarily scope, for
3989 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273990 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293991 } while (search_frame != main_frame);
3992 }
3993}
3994
[email protected]24a7f3c2010-03-25 08:26:493995void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3996 WebView* view = webview();
3997 if (!view)
3998 return;
3999
4000 WebDocument doc = view->mainFrame()->document();
4001 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014002 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494003 return;
4004 }
4005
4006 bool clear_selection =
4007 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4008 if (clear_selection)
4009 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4010
4011 WebFrame* frame = view->mainFrame();
4012 while (frame) {
4013 frame->stopFinding(clear_selection);
4014 frame = frame->traverseNext(false);
4015 }
4016
4017 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4018 WebFrame* focused_frame = view->focusedFrame();
4019 if (focused_frame) {
4020 WebDocument doc = focused_frame->document();
4021 if (!doc.isNull()) {
4022 WebNode node = doc.focusedNode();
4023 if (!node.isNull())
4024 node.simulateClick();
4025 }
4026 }
4027 }
4028}
4029
4030void RenderView::OnFindReplyAck() {
4031 // Check if there is any queued up request waiting to be sent.
4032 if (queued_find_reply_message_.get()) {
4033 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424034 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494035 }
4036}
4037
[email protected]8934a3b2010-02-25 00:34:004038bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354039 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004040 return current_content_settings_.settings[settings_type] !=
4041 CONTENT_SETTING_BLOCK;
4042}
4043
[email protected]55126132010-08-19 14:53:284044void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4045 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004046 if (!content_blocked_[settings_type]) {
4047 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284048 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4049 resource_identifier));
[email protected]0de80162010-02-03 04:52:354050 }
[email protected]0de80162010-02-03 04:52:354051}
4052
[email protected]71b0d5d2010-02-15 05:43:074053void RenderView::ClearBlockedContentSettings() {
4054 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4055 content_blocked_[i] = false;
4056}
4057
[email protected]aad51d1c2010-08-05 08:38:094058WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame,
4059 const WebPluginParams& params,
4060 const FilePath& path,
4061 pepper::PluginModule* pepper_module) {
[email protected]b75b8292010-10-01 07:28:254062 return new pepper::WebPluginImpl(
4063 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094064}
[email protected]00152e92010-07-19 11:47:404065
[email protected]aad51d1c2010-08-05 08:38:094066WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame,
4067 const WebPluginParams& params,
4068 const FilePath& path,
4069 const std::string& mime_type) {
[email protected]20a793e2010-10-12 06:50:084070 return new webkit_glue::WebPluginImpl(
4071 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404072}
4073
[email protected]57b66d02010-09-30 11:24:514074WebPlugin* RenderView::CreateOutdatedPluginPlaceholder(
4075 WebFrame* frame,
4076 const WebPluginParams& params,
4077 PluginGroup* group) {
4078 int resource_id = IDR_OUTDATED_PLUGIN_HTML;
4079 const base::StringPiece template_html(
4080 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id));
4081
4082 DCHECK(!template_html.empty()) << "unable to load template. ID: "
4083 << resource_id;
4084
4085 DictionaryValue values;
[email protected]fc61e222010-10-11 15:42:144086 values.SetString("message",
[email protected]57b66d02010-09-30 11:24:514087 l10n_util::GetStringFUTF8(IDS_PLUGIN_OUTDATED, group->GetGroupName()));
4088 values.Set("pluginGroup", group->GetDataForUI());
4089
4090 // "t" is the id of the templates root node.
4091 std::string htmlData = jstemplate_builder::GetTemplatesHtml(
4092 template_html, &values, "t");
4093
4094 return WebViewPlugin::Create(NULL,
4095 webkit_preferences_,
4096 htmlData,
4097 GURL("chrome://outdatedplugin/"));
4098}
4099
[email protected]40bd6582009-12-04 23:49:514100void RenderView::OnZoom(PageZoom::Function function) {
4101 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4102 return;
4103
[email protected]258d31122010-05-09 10:59:414104 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524105
[email protected]b75b8292010-10-01 07:28:254106 double old_zoom_level = webview()->zoomLevel();
4107 double zoom_level;
4108 if (function == PageZoom::RESET) {
4109 zoom_level = 0;
4110 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4111 // Previous zoom level is a whole number, so just increment/decrement.
4112 zoom_level = old_zoom_level + function;
4113 } else {
4114 // Either the user hit the zoom factor limit and thus the zoom level is now
4115 // not a whole number, or a plugin changed it to a custom value. We want
4116 // to go to the next whole number so that the user can always get back to
4117 // 100% with the keyboard/menu.
4118 if ((old_zoom_level > 1 && function > 0) ||
4119 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454120 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254121 } else {
4122 // We're going towards 100%, so first go to the next whole number.
4123 zoom_level = static_cast<int>(old_zoom_level);
4124 }
4125 }
[email protected]40bd6582009-12-04 23:49:514126
[email protected]b75b8292010-10-01 07:28:254127 webview()->setZoomLevel(false, zoom_level);
4128 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514129}
4130
[email protected]9d797f32010-04-23 07:17:544131void RenderView::OnSetContentSettingsForLoadingURL(
4132 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014133 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544134 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014135}
4136
[email protected]9d797f32010-04-23 07:17:544137void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254138 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544139 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294140}
4141
[email protected]41fc0322009-09-04 22:23:404142void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274143 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294144}
4145
[email protected]a697f4c2009-09-14 22:30:184146void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274147 WebString no_encoding;
4148 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184149}
4150
[email protected]20ad2692009-11-20 18:27:204151bool RenderView::GetAllChildFrames(
4152 WebFrame* parent_frame,
4153 std::vector<WebFrame*>* frames_vector) const {
4154 if (!parent_frame)
4155 return false;
4156 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4157 child_frame = child_frame->nextSibling()) {
4158 frames_vector->push_back(child_frame);
4159 GetAllChildFrames(child_frame, frames_vector);
4160 }
4161 return true;
4162}
4163
[email protected]dd7daa82009-08-10 05:46:454164WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4165 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274166 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454167
4168 // xpath string can represent a frame deep down the tree (across multiple
4169 // frame DOMs).
4170 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4171 // should break into 2 xpaths
4172 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4173
[email protected]26aa0482009-09-30 16:55:274174 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454175
4176 std::wstring xpath_remaining = xpath;
4177 while (!xpath_remaining.empty()) {
4178 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4179 std::wstring xpath_child;
4180 if (delim_pos != std::wstring::npos) {
4181 xpath_child = xpath_remaining.substr(0, delim_pos);
4182 xpath_remaining.erase(0, delim_pos + 1);
4183 } else {
4184 xpath_remaining.swap(xpath_child);
4185 }
4186 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294187 }
4188
[email protected]dd7daa82009-08-10 05:46:454189 return frame;
initial.commit09911bf2008-07-26 23:55:294190}
4191
[email protected]15d9c0c2010-09-10 22:36:264192void RenderView::SetSuggestResult(const std::string& suggest) {
[email protected]5cbd61f2010-10-14 03:49:494193 // Explicitly allow empty strings to be sent to the browser.
4194 Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest));
[email protected]15d9c0c2010-09-10 22:36:264195}
4196
[email protected]882b7b22010-10-05 03:34:534197void RenderView::EvaluateScript(const string16& frame_xpath,
4198 const string16& script,
4199 int id,
4200 bool notify_result) {
4201 v8::Handle<v8::Value> result;
4202 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4203 if (web_frame)
4204 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4205 if (notify_result) {
4206 bool bool_result = !result.IsEmpty() && result->IsBoolean() ?
4207 result->BooleanValue() : false;
4208 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result));
4209 }
initial.commit09911bf2008-07-26 23:55:294210}
4211
[email protected]1810e132009-03-24 23:35:484212void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084213 const std::string& css,
4214 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484215 WebFrame* web_frame = GetChildFrame(frame_xpath);
4216 if (!web_frame)
4217 return;
4218
[email protected]ffaef0c2009-09-15 17:08:084219 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484220}
4221
[email protected]00c39612010-03-06 02:53:284222void RenderView::OnPepperPluginDestroy(
4223 WebPluginDelegatePepper* pepper_plugin) {
4224 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014225 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4226 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284227 NOTREACHED();
4228 return;
4229 }
[email protected]53900d52010-06-16 04:25:014230 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474231
4232 // The plugin could have been destroyed while it was waiting for a file
4233 // choose callback, so check all pending completion callbacks and NULL them.
4234 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4235 file_chooser_completions_.begin();
4236 i != file_chooser_completions_.end(); /* nothing */) {
4237 if ((*i)->completion == pepper_plugin) {
4238 // We NULL the first one instead of deleting it because the plugin might
4239 // be the one waiting for a file choose callback. If the callback later
4240 // comes, we don't want to send the result to the next callback in line.
4241 if (i == file_chooser_completions_.begin())
4242 (*i)->completion = NULL;
4243 else
4244 i = file_chooser_completions_.erase(i);
4245 } else {
4246 ++i;
4247 }
4248 }
[email protected]00c39612010-03-06 02:53:284249}
4250
[email protected]882b7b22010-10-05 03:34:534251void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4252 const string16& jscript,
4253 int id,
4254 bool notify_result) {
4255 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294256}
4257
[email protected]1810e132009-03-24 23:35:484258void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084259 const std::string& css,
4260 const std::string& id) {
4261 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414262
4263 // Notify RenderViewHost that css has been inserted into the frame.
4264 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484265}
4266
[email protected]7ea066a2009-04-06 20:21:594267void RenderView::OnAddMessageToConsole(
4268 const string16& frame_xpath,
4269 const string16& message,
4270 const WebConsoleMessage::Level& level) {
4271 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594272 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454273 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294274}
4275
[email protected]81e63782009-02-27 19:35:094276void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4277 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294278}
4279
4280void RenderView::OnSetDOMUIProperty(const std::string& name,
4281 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094282 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c091c2c2010-09-17 19:05:464283 GetDOMUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294284}
4285
4286void RenderView::OnReservePageIDRange(int size_of_range) {
4287 next_page_id_ += size_of_range + 1;
4288}
4289
[email protected]e80c73b2009-04-07 23:24:584290void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4291 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254292 bool ended,
4293 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034294 if (ended) {
[email protected]26aa0482009-09-30 16:55:274295 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204296 } else {
4297 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034298 }
initial.commit09911bf2008-07-26 23:55:294299}
4300
4301void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274302 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294303}
4304
initial.commit09911bf2008-07-26 23:55:294305void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:164306 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:084307#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:064308 password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(),
[email protected]03f57072010-07-14 17:36:084309 form_data);
[email protected]ad24ccb2010-07-15 21:38:204310#else
4311 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:084312#endif
initial.commit09911bf2008-07-26 23:55:294313}
4314
4315void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584316 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254317 const gfx::Point& screen_point,
4318 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274319 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584320 drop_data.ToDragData(),
4321 drop_data.identity,
4322 client_point,
[email protected]1d9f4132009-09-08 17:29:254323 screen_point,
4324 ops);
initial.commit09911bf2008-07-26 23:55:294325
[email protected]1d9f4132009-09-08 17:29:254326 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294327}
4328
[email protected]e80c73b2009-04-07 23:24:584329void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254330 const gfx::Point& screen_point,
4331 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274332 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254333 client_point,
4334 screen_point,
4335 ops);
initial.commit09911bf2008-07-26 23:55:294336
[email protected]1d9f4132009-09-08 17:29:254337 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294338}
4339
4340void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274341 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294342}
4343
[email protected]e80c73b2009-04-07 23:24:584344void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4345 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274346 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294347}
4348
4349void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594350 webkit_preferences_ = prefs;
4351 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294352}
4353
4354void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4355 alternate_error_page_url_ = url;
4356}
4357
[email protected]a0c7153e2009-12-09 14:36:334358void RenderView::OnCustomContextMenuAction(unsigned action) {
4359 webview()->performCustomContextMenuAction(action);
4360}
4361
[email protected]d4a00a72010-01-29 01:44:424362void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024363 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424364 const std::string& source_lang,
4365 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024366 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4367 translate_script);
[email protected]d4a00a72010-01-29 01:44:424368}
4369
[email protected]85d252e2010-04-06 22:21:024370void RenderView::OnRevertTranslation(int page_id) {
4371 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324372}
4373
initial.commit09911bf2008-07-26 23:55:294374void RenderView::OnInstallMissingPlugin() {
4375 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594376 if (first_default_plugin_)
4377 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294378}
4379
[email protected]97c5c592010-08-03 08:22:214380void RenderView::OnLoadBlockedPlugins() {
4381 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4382 Source<RenderView>(this),
4383 NotificationService::NoDetails());
4384}
4385
[email protected]cdaf8d02010-03-30 19:52:474386void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364387 // This could happen if we navigated to a different page before the user
4388 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474389 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364390 return;
4391
[email protected]cdaf8d02010-03-30 19:52:474392 WebVector<WebString> ws_file_names(paths.size());
4393 for (size_t i = 0; i < paths.size(); ++i)
4394 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464395
[email protected]cdaf8d02010-03-30 19:52:474396 if (file_chooser_completions_.front()->completion)
4397 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4398 file_chooser_completions_.pop_front();
4399
4400 // If there are more pending file chooser requests, schedule one now.
4401 if (!file_chooser_completions_.empty()) {
4402 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4403 file_chooser_completions_.front()->params));
4404 }
initial.commit09911bf2008-07-26 23:55:294405}
4406
4407void RenderView::OnEnableViewSourceMode() {
4408 if (!webview())
4409 return;
[email protected]26aa0482009-09-30 16:55:274410 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294411 if (!main_frame)
4412 return;
4413
[email protected]dd7daa82009-08-10 05:46:454414 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294415}
4416
[email protected]770dd8b2010-05-24 18:11:394417void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4418 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244419 if (send_preferred_size_changes_)
4420 return;
[email protected]9fb325e2010-05-06 18:23:244421 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394422
4423 // WebKit doesn't send a notification of the effective height of the page
4424 // changes, so poll for it.
4425 // TODO: Add a notification for this to WebKit, remove polling. After that's
4426 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4427 // http://crbug.com/44850
4428 if (flags & kPreferredSizeHeightThisIsSlow) {
4429 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4430 &RenderView::CheckPreferredSize);
4431 }
[email protected]0666aef2009-05-13 19:48:084432}
4433
[email protected]cda45c02010-02-25 19:28:104434void RenderView::OnDisableScrollbarsForSmallWindows(
4435 const gfx::Size& disable_scrollbar_size_limit) {
4436 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4437}
4438
[email protected]80d96fa2009-06-10 22:34:514439void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4440 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374441 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034442#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414443 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4444 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464445 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344446 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4447 renderer_prefs.thumb_inactive_color,
4448 renderer_prefs.thumb_active_color,
4449 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324450
[email protected]644d77e2010-01-27 01:03:104451 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324452 webview()->setScrollbarColors(
4453 renderer_prefs.thumb_inactive_color,
4454 renderer_prefs.thumb_active_color,
4455 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104456 webview()->setSelectionColors(
4457 renderer_prefs.active_selection_bg_color,
4458 renderer_prefs.active_selection_fg_color,
4459 renderer_prefs.inactive_selection_bg_color,
4460 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464461 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104462 }
[email protected]7a74e102009-09-03 00:16:564463#endif
[email protected]80d96fa2009-06-10 22:34:514464}
4465
[email protected]952cb702009-10-07 05:50:284466void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4467 const WebMediaPlayerAction& action) {
4468 if (webview())
4469 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564470}
4471
[email protected]7b291f92009-08-14 05:43:534472void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4473 view_type_ = type;
4474}
4475
4476void RenderView::OnUpdateBrowserWindowId(int window_id) {
4477 browser_window_id_ = window_id;
4478}
4479
[email protected]dea2d372010-09-25 06:41:144480void RenderView::OnEnableAccessibility() {
4481 if (WebAccessibilityCache::accessibilityEnabled())
4482 return;
[email protected]9f4db512010-05-10 20:21:414483
[email protected]dea2d372010-09-25 06:41:144484 WebAccessibilityCache::enableAccessibility();
4485
4486 if (webview()) {
4487 // It's possible that the webview has already loaded a webpage without
4488 // accessibility being enabled. Initialize the browser's cached
4489 // accessibility tree by sending it a 'load complete' notification.
4490 postAccessibilityNotification(
4491 webview()->accessibilityObject(),
4492 WebKit::WebAccessibilityNotificationLoadComplete);
4493 }
[email protected]266eb6f2008-09-30 23:56:504494}
4495
[email protected]aef92842010-05-21 16:54:364496void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4497 if (!accessibility_.get())
4498 return;
[email protected]02ea2f312010-09-27 17:03:364499
4500 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4501 WebAccessibilityObject root = webview()->accessibilityObject();
4502 if (!obj.isValid() || !root.isValid())
4503 return;
4504
4505 // By convention, calling SetFocus on the root of the tree should clear the
4506 // current focus. Otherwise set the focus to the new node.
4507 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4508 webview()->clearFocusedNode();
4509 else
4510 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364511}
4512
4513void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4514 if (!accessibility_.get())
4515 return;
[email protected]02ea2f312010-09-27 17:03:364516
4517 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4518 if (!obj.isValid())
4519 return;
4520
4521 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364522}
4523
[email protected]9892b472010-09-16 00:23:424524void RenderView::OnAccessibilityNotificationsAck() {
[email protected]520cb7d72010-08-31 11:54:314525 if (!accessibility_.get())
4526 return;
4527
[email protected]9892b472010-09-16 00:23:424528 if (!pending_accessibility_notifications_.empty()) {
4529 Send(new ViewHostMsg_AccessibilityNotifications(
[email protected]520cb7d72010-08-31 11:54:314530 routing_id_,
[email protected]9892b472010-09-16 00:23:424531 pending_accessibility_notifications_));
[email protected]520cb7d72010-08-31 11:54:314532 }
4533
[email protected]9892b472010-09-16 00:23:424534 pending_accessibility_notifications_.clear();
[email protected]520cb7d72010-08-31 11:54:314535}
4536
initial.commit09911bf2008-07-26 23:55:294537void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4538 const GURL& page_url) {
4539 // Prepare list to storage all savable resource links.
4540 std::vector<GURL> resources_list;
4541 std::vector<GURL> referrers_list;
4542 std::vector<GURL> frames_list;
4543 webkit_glue::SavableResourcesResult result(&resources_list,
4544 &referrers_list,
4545 &frames_list);
4546
[email protected]dbeb3952009-10-13 18:01:184547 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4548 webview(),
4549 page_url,
4550 &result,
4551 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294552 // If something is wrong when collecting all savable resource links,
4553 // send empty list to embedder(browser) to tell it failed.
4554 referrers_list.clear();
4555 resources_list.clear();
4556 frames_list.clear();
4557 }
4558
4559 // Send result of all savable resource links to embedder.
4560 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4561 resources_list,
4562 referrers_list,
4563 frames_list));
4564}
4565
4566void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324567 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314568 const std::vector<FilePath>& local_paths,
4569 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074570
4571 // Convert std::vector of GURLs to WebVector<WebURL>
4572 WebVector<WebURL> weburl_links(links);
4573
4574 // Convert std::vector of std::strings to WebVector<WebString>
4575 WebVector<WebString> webstring_paths(local_paths.size());
4576 for (size_t i = 0; i < local_paths.size(); i++)
4577 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4578
4579 WebPageSerializer::serialize(webview()->mainFrame(),
4580 true, this, weburl_links, webstring_paths,
4581 webkit_glue::FilePathToWebString(
4582 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294583}
4584
[email protected]d9ec5c0f2009-12-23 11:55:074585void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4586 const WebCString& data,
4587 WebPageSerializerClient::PageSerializationStatus status) {
4588 Send(new ViewHostMsg_SendSerializedHtmlData(
4589 routing_id_,
4590 frame_url,
4591 data.data(),
4592 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294593}
4594
[email protected]9b18a84f2010-06-10 15:54:044595void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274596 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474597 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294598}
4599
[email protected]eb6b87a2009-07-24 15:57:394600void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294601 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4602 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4603 // in the onunload handler from appearing. For now, we're bypassing that and
4604 // calling the FrameLoader's CloseURL method directly. This should be
4605 // revisited to avoid having two ways to close a page. Having a single way
4606 // to close that can run onunload is also useful for fixing
4607 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274608 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294609 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454610 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174611 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294612 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4613 // multiple times for the same frame, but it will simplify things.
[email protected]05c8e502010-08-15 15:13:524614
4615 // Ensure state contains scheme.
4616 NavigationState* navigation_state =
4617 NavigationState::FromDataSource(main_frame->dataSource());
4618 if (url.SchemeIs("http"))
4619 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
4620 else if (url.SchemeIs("https"))
4621 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
4622
4623 // Dump will only be provided when scheme is http or https.
4624 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294625 }
[email protected]26aa0482009-09-30 16:55:274626 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294627
[email protected]ab9eabac2010-03-16 16:54:104628 // Reset stats
4629 cross_origin_access_count_ = 0;
4630 same_origin_access_count_ = 0;
4631
[email protected]eb6b87a2009-07-24 15:57:394632 // Just echo back the params in the ACK.
4633 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294634}
4635
4636void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574637#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294638 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464639 if (webview())
4640 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574641#else // defined(OS_WIN)
4642 // TODO(port): we don't support theming on non-Windows platforms yet
4643 NOTIMPLEMENTED();
4644#endif
initial.commit09911bf2008-07-26 23:55:294645}
4646
[email protected]9b18a84f2010-06-10 15:54:044647void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4648 const std::string& origin,
4649 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154650 if (message.empty())
4651 return;
[email protected]c091c2c2010-09-17 19:05:464652 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
4653 target);
[email protected]3ac14a052008-08-15 21:22:154654}
4655
[email protected]0aa55312008-10-17 21:53:084656void RenderView::OnDisassociateFromPopupCount() {
4657 if (decrement_shared_popup_at_destruction_)
4658 shared_popup_counter_->data--;
4659 shared_popup_counter_ = new SharedRenderViewCounter(0);
4660 decrement_shared_popup_at_destruction_ = false;
4661}
4662
[email protected]15d79e12009-08-02 19:23:454663bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4664 const WebURLError& error,
4665 bool replace) {
4666 // We only show alternate error pages in the main frame. They are
4667 // intended to assist the user when navigating, so there is not much
4668 // value in showing them for failed subframes. Ideally, we would be
4669 // able to use the TYPED transition type for this, but that flag is
4670 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454671 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454672 return false;
4673
4674 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374675 // connection failure.
[email protected]15d79e12009-08-02 19:23:454676 int ec = error.reason;
4677 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4678 ec != net::ERR_CONNECTION_FAILED &&
4679 ec != net::ERR_CONNECTION_REFUSED &&
4680 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374681 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454682 return false;
4683
4684 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554685 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454686 if (!error_page_url.is_valid())
4687 return false;
4688
4689 // Load an empty page first so there is an immediate response to the error,
4690 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454691 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454692 GURL(kUnreachableWebDataURL),
4693 error.unreachableURL,
4694 replace);
4695
4696 // Now, create a fetcher for the error page and associate it with the data
4697 // source we just created via the LoadHTMLString call. That way if another
4698 // navigation occurs, the fetcher will get destroyed.
4699 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454700 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454701 navigation_state->set_alt_error_page_fetcher(
4702 new AltErrorPageResourceFetcher(
4703 error_page_url, frame, error,
4704 NewCallback(this, &RenderView::AltErrorPageFinished)));
4705 return true;
4706}
4707
initial.commit09911bf2008-07-26 23:55:294708std::string RenderView::GetAltHTMLForTemplate(
4709 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394710 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294711 ResourceBundle::GetSharedInstance().GetRawDataResource(
4712 template_resource_id));
4713
4714 if (template_html.empty()) {
4715 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4716 return "";
4717 }
[email protected]7cd22a52009-07-14 00:40:254718
initial.commit09911bf2008-07-26 23:55:294719 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254720 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294721 template_html, &error_strings, "t");
4722}
[email protected]0e79b9e2009-02-13 04:20:484723
[email protected]15d79e12009-08-02 19:23:454724void RenderView::AltErrorPageFinished(WebFrame* frame,
4725 const WebURLError& original_error,
4726 const std::string& html) {
4727 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554728
4729 // If we failed to download the alternate error page, fall back to the
4730 // original error page if present. Otherwise, LoadNavigationErrorPage
4731 // will simply display a default error page.
4732 const std::string* html_to_load = &html;
4733 if (html.empty()) {
4734 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454735 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554736 html_to_load = &navigation_state->postponed_data();
4737 }
[email protected]3f853a52010-09-13 19:15:084738 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
4739 true);
[email protected]15d79e12009-08-02 19:23:454740}
4741
[email protected]30f75e62009-02-25 22:01:004742void RenderView::OnMoveOrResizeStarted() {
4743 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474744 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004745}
4746
[email protected]30f75e62009-02-25 22:01:004747void RenderView::OnResize(const gfx::Size& new_size,
4748 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104749 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474750 webview()->hidePopups();
[email protected]98e92fe22010-09-24 22:15:134751
[email protected]cda45c02010-02-25 19:28:104752 if (send_preferred_size_changes_) {
[email protected]98e92fe22010-09-24 22:15:134753 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4754 // either width or height, allow scroll bars.
4755 bool allow_scrollbars = (
4756 disable_scrollbars_size_limit_.width() <= new_size.width() ||
4757 disable_scrollbars_size_limit_.height() <= new_size.height());
4758 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
[email protected]cda45c02010-02-25 19:28:104759 }
4760 }
4761
[email protected]30f75e62009-02-25 22:01:004762 RenderWidget::OnResize(new_size, resizer_rect);
4763}
[email protected]0aa477bd2009-03-23 22:21:434764
[email protected]00c39612010-03-06 02:53:284765void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014766 // Notify the pepper plugins that we started painting.
4767 pepper_delegate_.ViewInitiatedPaint();
4768
4769 // Notify any "old-style" pepper plugins that we started painting. This is
4770 // used for internal bookkeeping only, so we know that the set can not change
4771 // under us.
[email protected]00c39612010-03-06 02:53:284772 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014773 current_oldstyle_pepper_plugins_.begin();
4774 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284775 (*i)->RenderViewInitiatedPaint();
4776}
4777
4778void RenderView::DidFlushPaint() {
4779 // Notify any pepper plugins that we painted. This will call into the plugin,
4780 // and we it may ask to close itself as a result. This will, in turn, modify
4781 // our set, possibly invalidating the iterator. So we iterate on a copy that
4782 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014783 pepper_delegate_.ViewFlushedPaint();
4784
4785 // Notify any old-style pepper plugins that we painted. This will call into
4786 // the plugin, and we it may ask to close itself as a result. This will, in
4787 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4788 // a copy that won't change out from under us.
4789 // This should be deleted when we don't support old Pepper anymore.
4790 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284791 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4792 i != plugins.end(); ++i) {
4793 // The copy above makes sure our iterator is never invalid if some plugins
4794 // are destroyed. But some plugin may decide to close all of its views in
4795 // response to a paint in one of them, so we need to make sure each one is
4796 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014797 if (current_oldstyle_pepper_plugins_.find(*i) !=
4798 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284799 (*i)->RenderViewFlushedPaint();
4800 }
4801
4802 WebFrame* main_frame = webview()->mainFrame();
4803
4804 // If we have a provisional frame we are between the start and commit stages
4805 // of loading and we don't want to save stats.
4806 if (!main_frame->provisionalDataSource()) {
4807 WebDataSource* ds = main_frame->dataSource();
4808 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4809 DCHECK(navigation_state);
4810
[email protected]05c8e502010-08-15 15:13:524811 // TODO(jar): The following code should all be inside a method, probably in
4812 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284813 Time now = Time::Now();
4814 if (navigation_state->first_paint_time().is_null()) {
4815 navigation_state->set_first_paint_time(now);
4816 }
4817 if (navigation_state->first_paint_after_load_time().is_null() &&
4818 !navigation_state->finish_load_time().is_null()) {
4819 navigation_state->set_first_paint_after_load_time(now);
4820 }
4821 }
4822}
4823
[email protected]ca4847f2010-09-24 05:39:154824bool RenderView::GetBitmapForOptimizedPluginPaint(
4825 const gfx::Rect& paint_bounds,
4826 TransportDIB** dib,
4827 gfx::Rect* location,
4828 gfx::Rect* clip) {
4829 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4830 paint_bounds, dib, location, clip);
4831}
4832
[email protected]05d478752009-04-08 23:38:164833void RenderView::OnClearFocusedNode() {
4834 if (webview())
[email protected]26aa0482009-09-30 16:55:274835 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164836}
4837
[email protected]699ab0d2009-04-23 23:19:144838void RenderView::OnSetBackground(const SkBitmap& background) {
4839 if (webview())
[email protected]b4bb2502009-10-01 22:35:274840 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144841
4842 SetBackground(background);
4843}
4844
[email protected]8c66c5a2009-07-22 17:26:344845void RenderView::OnSetActive(bool active) {
4846 if (webview())
[email protected]b4bb2502009-10-01 22:35:274847 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264848
4849#if defined(OS_MACOSX)
4850 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4851 for (plugin_it = plugin_delegates_.begin();
4852 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4853 (*plugin_it)->SetWindowFocus(active);
4854 }
4855#endif
[email protected]8c66c5a2009-07-22 17:26:344856}
4857
[email protected]6ce7abc52010-02-02 18:40:144858#if defined(OS_MACOSX)
4859void RenderView::OnSetWindowVisibility(bool visible) {
4860 // Inform plugins that their container has changed visibility.
4861 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4862 for (plugin_it = plugin_delegates_.begin();
4863 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4864 (*plugin_it)->SetContainerVisibility(visible);
4865 }
4866}
[email protected]1e6e3c992010-02-08 15:52:134867
[email protected]4d51d5bf2010-07-26 18:48:264868void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4869 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134870 // Inform plugins that their window's frame has changed.
4871 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4872 for (plugin_it = plugin_delegates_.begin();
4873 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4874 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4875 }
4876}
[email protected]6ce7abc52010-02-02 18:40:144877#endif // OS_MACOSX
4878
[email protected]8b8e7c92010-08-19 18:05:564879void RenderView::SendExtensionRequest(
4880 const ViewHostMsg_DomMessage_Params& params) {
4881 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:274882}
4883
[email protected]c6619182009-05-12 14:59:324884void RenderView::OnExtensionResponse(int request_id,
4885 bool success,
4886 const std::string& response,
4887 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354888 ExtensionProcessBindings::HandleResponse(
4889 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274890}
[email protected]c20210e62009-04-03 21:39:264891
[email protected]7120f132009-07-20 21:05:374892void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494893 const ListValue& args,
[email protected]414785a2010-10-08 21:32:344894 bool cross_incognito,
[email protected]a807bbe2010-04-14 10:51:194895 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494896 RendererExtensionBindings::Invoke(
[email protected]414785a2010-10-08 21:32:344897 function_name, args, this, cross_incognito, event_url);
[email protected]7120f132009-07-20 21:05:374898}
4899
[email protected]e7e4f3c2009-04-21 15:24:084900// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264901//
[email protected]c20210e62009-04-03 21:39:264902// The time points we keep are
4903// request: time document was requested by user
4904// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254905// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294906// finish_document: main document loaded, before onload()
[email protected]05c8e502010-08-15 15:13:524907// finish_all_loads: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294908// first_paint: first paint performed
4909// first_paint_after_load: first paint performed after load is finished
4910// begin: request if it was user requested, start otherwise
4911//
[email protected]e7e4f3c2009-04-21 15:24:084912// It's possible for the request time not to be set, if a client
4913// redirect had been done (the user never requested the page)
4914// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294915// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264916void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504917 // Configuration for PLT related histograms.
4918 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4919 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4920 static const size_t kPLTCount(100);
4921 #define PLT_HISTOGRAM(name, sample) \
4922 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4923
[email protected]26aa0482009-09-30 16:55:274924 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564925 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454926 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564927
[email protected]05c8e502010-08-15 15:13:524928 URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type();
4929 if (scheme_type == 0)
4930 return;
4931 DCHECK(scheme_type == URLPattern::SCHEME_HTTP ||
4932 scheme_type == URLPattern::SCHEME_HTTPS);
4933
[email protected]f9f4841b2010-03-20 05:41:424934 // If we've already dumped, do nothing.
4935 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294936 return;
[email protected]cf9a7bc2010-06-11 18:54:504937
4938 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454939 Time start = navigation_state->start_load_time();
4940 if (start.is_null())
4941 return; // Probably very premature abandonment of page.
4942 Time commit = navigation_state->commit_load_time();
4943 if (commit.is_null())
4944 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504945
[email protected]b855ebe62010-05-12 23:01:454946 // We properly handle null values for the next 3 variables.
4947 Time request = navigation_state->request_time();
4948 Time first_paint = navigation_state->first_paint_time();
4949 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454950 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]05c8e502010-08-15 15:13:524951 Time finish_all_loads = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564952
[email protected]f9f4841b2010-03-20 05:41:424953 // Handle case where user hits "stop" or "back" before loading completely.
[email protected]05c8e502010-08-15 15:13:524954 bool abandoned_page = finish_doc.is_null();
[email protected]f9f4841b2010-03-20 05:41:424955 if (abandoned_page) {
[email protected]05c8e502010-08-15 15:13:524956 finish_doc = Time::Now();
4957 navigation_state->set_finish_document_load_time(finish_doc);
[email protected]f9f4841b2010-03-20 05:41:424958 }
[email protected]f9f4841b2010-03-20 05:41:424959
[email protected]05c8e502010-08-15 15:13:524960 // TODO(jar): We should really discriminate the definition of "abandon" more
4961 // finely. We should have:
4962 // abandon_before_document_loaded
4963 // abandon_before_onload_fired
4964
4965 if (finish_all_loads.is_null()) {
4966 finish_all_loads = Time::Now();
4967 navigation_state->set_finish_load_time(finish_all_loads);
4968 } else {
4969 DCHECK(!abandoned_page); // How can the doc have finished but not the page?
[email protected]cf9a7bc2010-06-11 18:54:504970 if (!abandoned_page)
4971 return; // Don't try to record a stat which is broken.
[email protected]cf9a7bc2010-06-11 18:54:504972 }
4973
4974 // Note: Client side redirects will have no request time.
4975 Time begin = request.is_null() ? start : request;
4976 TimeDelta begin_to_finish_doc = finish_doc - begin;
[email protected]05c8e502010-08-15 15:13:524977 TimeDelta begin_to_finish_all_loads = finish_all_loads - begin;
4978 TimeDelta start_to_finish_all_loads = finish_all_loads - start;
[email protected]ef1d8d322010-06-13 18:31:254979 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424980
[email protected]a7ccc4d2010-01-27 08:14:484981 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504982
[email protected]05c8e502010-08-15 15:13:524983 // The above code sanitized all values of times, in preparation for creating
4984 // actual histograms. The remainder of this code could be run at destructor
4985 // time for the navigation_state, since all data is intact.
4986
[email protected]cf9a7bc2010-06-11 18:54:504987 // Aggregate PLT data across all link types.
4988 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4989 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4990 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254991 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504992 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
[email protected]05c8e502010-08-15 15:13:524993 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc);
[email protected]cf9a7bc2010-06-11 18:54:504994 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
[email protected]05c8e502010-08-15 15:13:524995 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504996 if (!request.is_null()) {
4997 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
[email protected]05c8e502010-08-15 15:13:524998 PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request);
[email protected]cf9a7bc2010-06-11 18:54:504999 }
[email protected]05c8e502010-08-15 15:13:525000 PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit);
[email protected]cf9a7bc2010-06-11 18:54:505001 if (!first_paint.is_null()) {
5002 DCHECK(begin <= first_paint);
5003 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
5004 DCHECK(commit <= first_paint);
5005 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
5006 }
5007 if (!first_paint_after_load.is_null()) {
5008 DCHECK(begin <= first_paint_after_load);
5009 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
5010 first_paint_after_load - begin);
5011 DCHECK(commit <= first_paint_after_load);
5012 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
5013 first_paint_after_load - commit);
[email protected]05c8e502010-08-15 15:13:525014 DCHECK(finish_all_loads <= first_paint_after_load);
[email protected]cf9a7bc2010-06-11 18:54:505015 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
[email protected]05c8e502010-08-15 15:13:525016 first_paint_after_load - finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505017 }
5018 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525019 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505020
5021 // Load type related histograms.
5022 switch (load_type) {
5023 case NavigationState::UNDEFINED_LOAD:
5024 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525025 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505026 break;
5027 case NavigationState::RELOAD:
5028 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525029 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505030 break;
5031 case NavigationState::HISTORY_LOAD:
5032 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525033 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505034 break;
5035 case NavigationState::NORMAL_LOAD:
5036 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525037 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505038 break;
5039 case NavigationState::LINK_LOAD_NORMAL:
5040 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
5041 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525042 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal",
5043 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505044 break;
5045 case NavigationState::LINK_LOAD_RELOAD:
5046 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
5047 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525048 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload",
5049 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505050 break;
5051 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5052 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
5053 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525054 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk",
5055 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505056 break;
5057 case NavigationState::LINK_LOAD_CACHE_ONLY:
5058 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
5059 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:525060 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly",
5061 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505062 break;
5063 default:
5064 break;
5065 }
5066
5067 // Histograms to determine if DNS prefetching has an impact on PLT.
[email protected]835d7c82010-10-14 04:38:385068 static bool use_dns_histogram(base::FieldTrialList::Find("DnsImpact") &&
5069 !base::FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]cf9a7bc2010-06-11 18:54:505070 if (use_dns_histogram) {
5071 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385072 base::FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
[email protected]cf9a7bc2010-06-11 18:54:505073 abandoned_page ? 1 : 0, 2);
5074 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385075 base::FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
[email protected]cf9a7bc2010-06-11 18:54:505076 load_type, NavigationState::kLoadTypeMax);
5077 switch (load_type) {
5078 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385079 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]05c8e502010-08-15 15:13:525080 "PLT.BeginToFinish_NormalLoad", "DnsImpact"),
5081 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505082 break;
5083 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385084 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505085 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:525086 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505087 break;
5088 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385089 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505090 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:525091 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505092 break;
5093 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385094 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505095 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:525096 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505097 break;
5098 default:
5099 break;
5100 }
5101 }
5102
[email protected]8a3125a712010-08-09 18:58:515103 // Histograms to determine if content prefetching has an impact on PLT.
5104 static const bool prefetching_fieldtrial =
[email protected]835d7c82010-10-14 04:38:385105 base::FieldTrialList::Find("Prefetch") &&
5106 !base::FieldTrialList::Find("Prefetch")->group_name().empty();
[email protected]13ae2df92010-08-19 20:05:105107 if (prefetching_fieldtrial) {
5108 if (navigation_state->was_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:515109 PLT_HISTOGRAM(
[email protected]835d7c82010-10-14 04:38:385110 base::FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher",
[email protected]8a3125a712010-08-09 18:58:515111 "Prefetch"),
5112 begin_to_finish_doc);
5113 PLT_HISTOGRAM(
[email protected]835d7c82010-10-14 04:38:385114 base::FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher",
5115 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525116 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515117 }
[email protected]13ae2df92010-08-19 20:05:105118 if (navigation_state->was_referred_by_prefetcher()) {
[email protected]835d7c82010-10-14 04:38:385119 PLT_HISTOGRAM(base::FieldTrial::MakeName(
5120 "PLT.BeginToFinishDoc_ContentPrefetcherReferrer",
5121 "Prefetch"),
[email protected]8a3125a712010-08-09 18:58:515122 begin_to_finish_doc);
[email protected]835d7c82010-10-14 04:38:385123 PLT_HISTOGRAM(base::FieldTrial::MakeName(
5124 "PLT.BeginToFinish_ContentPrefetcherReferrer",
5125 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525126 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515127 }
[email protected]835d7c82010-10-14 04:38:385128 UMA_HISTOGRAM_ENUMERATION(
5129 base::FieldTrial::MakeName("PLT.Abandoned", "Prefetch"),
5130 abandoned_page ? 1 : 0, 2);
5131 PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinishDoc",
5132 "Prefetch"),
[email protected]8a3125a712010-08-09 18:58:515133 begin_to_finish_doc);
[email protected]835d7c82010-10-14 04:38:385134 PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525135 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515136 }
5137
[email protected]06d94042010-08-25 01:45:225138 // Histograms to determine if backup connection jobs have an impact on PLT.
5139 static const bool connect_backup_jobs_fieldtrial(
[email protected]835d7c82010-10-14 04:38:385140 base::FieldTrialList::Find("ConnnectBackupJobs") &&
5141 !base::FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty());
[email protected]06d94042010-08-25 01:45:225142 if (connect_backup_jobs_fieldtrial) {
5143 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385144 base::FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"),
[email protected]06d94042010-08-25 01:45:225145 abandoned_page ? 1 : 0, 2);
5146 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385147 base::FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"),
[email protected]06d94042010-08-25 01:45:225148 load_type, NavigationState::kLoadTypeMax);
5149 switch (load_type) {
5150 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385151 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]06d94042010-08-25 01:45:225152 "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"),
5153 begin_to_finish_all_loads);
5154 break;
5155 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385156 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]06d94042010-08-25 01:45:225157 "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"),
5158 begin_to_finish_all_loads);
5159 break;
5160 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385161 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]06d94042010-08-25 01:45:225162 "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"),
5163 begin_to_finish_all_loads);
5164 break;
5165 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385166 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]06d94042010-08-25 01:45:225167 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"),
5168 begin_to_finish_all_loads);
5169 break;
5170 default:
5171 break;
5172 }
5173 }
5174
[email protected]cf9a7bc2010-06-11 18:54:505175 // Histograms to determine if the number of connections has an
5176 // impact on PLT.
5177 // TODO(jar): Consider removing the per-link-type versions. We
5178 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
[email protected]97546492010-08-09 05:14:495179 static bool use_connection_impact_histogram(
[email protected]835d7c82010-10-14 04:38:385180 base::FieldTrialList::Find("ConnCountImpact") &&
5181 !base::FieldTrialList::Find("ConnCountImpact")->group_name().empty());
[email protected]97546492010-08-09 05:14:495182 if (use_connection_impact_histogram) {
[email protected]cf9a7bc2010-06-11 18:54:505183 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385184 base::FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
[email protected]cf9a7bc2010-06-11 18:54:505185 abandoned_page ? 1 : 0, 2);
5186 switch (load_type) {
5187 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385188 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505189 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525190 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505191 break;
5192 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385193 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505194 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525195 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505196 break;
5197 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385198 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505199 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525200 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505201 break;
5202 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385203 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505204 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525205 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505206 break;
5207 default:
5208 break;
5209 }
5210 }
5211
[email protected]78a258a2010-08-02 16:34:265212 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:005213 static bool use_idle_socket_timeout_histogram(
[email protected]835d7c82010-10-14 04:38:385214 base::FieldTrialList::Find("IdleSktToImpact") &&
5215 !base::FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
[email protected]241c5c2c2010-06-21 18:46:005216 if (use_idle_socket_timeout_histogram) {
5217 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385218 base::FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
[email protected]241c5c2c2010-06-21 18:46:005219 abandoned_page ? 1 : 0, 2);
5220 switch (load_type) {
5221 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385222 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]241c5c2c2010-06-21 18:46:005223 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525224 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005225 break;
5226 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385227 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]241c5c2c2010-06-21 18:46:005228 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525229 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005230 break;
5231 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385232 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]241c5c2c2010-06-21 18:46:005233 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525234 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005235 break;
5236 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385237 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]241c5c2c2010-06-21 18:46:005238 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525239 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005240 break;
5241 default:
5242 break;
5243 }
5244 }
5245
[email protected]78a258a2010-08-02 16:34:265246 // Histograms to determine effect of number of connections per proxy.
5247 static bool use_proxy_connection_impact_histogram(
[email protected]835d7c82010-10-14 04:38:385248 base::FieldTrialList::Find("ProxyConnectionImpact") &&
5249 !base::FieldTrialList::Find("ProxyConnectionImpact")->
5250 group_name().empty());
[email protected]78a258a2010-08-02 16:34:265251 if (use_proxy_connection_impact_histogram) {
5252 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385253 base::FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
[email protected]78a258a2010-08-02 16:34:265254 abandoned_page ? 1 : 0, 2);
5255 switch (load_type) {
5256 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385257 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]78a258a2010-08-02 16:34:265258 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525259 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265260 break;
5261 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385262 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]78a258a2010-08-02 16:34:265263 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525264 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265265 break;
5266 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385267 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]78a258a2010-08-02 16:34:265268 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525269 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265270 break;
5271 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385272 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]78a258a2010-08-02 16:34:265273 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525274 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265275 break;
5276 default:
5277 break;
5278 }
5279 }
5280
[email protected]cf9a7bc2010-06-11 18:54:505281 // Histograms to determine if SDCH has an impact.
5282 // TODO(jar): Consider removing per-link load types and the enumeration.
[email protected]835d7c82010-10-14 04:38:385283 static bool use_sdch_histogram(base::FieldTrialList::Find("GlobalSdch") &&
5284 !base::FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]cf9a7bc2010-06-11 18:54:505285 if (use_sdch_histogram) {
5286 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385287 base::FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
[email protected]cf9a7bc2010-06-11 18:54:505288 load_type, NavigationState::kLoadTypeMax);
5289 switch (load_type) {
5290 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385291 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505292 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525293 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505294 break;
5295 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385296 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505297 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525298 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505299 break;
5300 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385301 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505302 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525303 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505304 break;
5305 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385306 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505307 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525308 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505309 break;
5310 case NavigationState::LINK_LOAD_CACHE_ONLY:
[email protected]835d7c82010-10-14 04:38:385311 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505312 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525313 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505314 break;
5315 default:
5316 break;
5317 }
5318 }
5319
5320 // Histograms to determine if cache size has an impact on PLT.
[email protected]835d7c82010-10-14 04:38:385321 static bool use_cache_histogram1(base::FieldTrialList::Find("CacheSize") &&
5322 !base::FieldTrialList::Find("CacheSize")->group_name().empty());
5323 if (use_cache_histogram1 &&
5324 NavigationState::LINK_LOAD_NORMAL <= load_type &&
[email protected]cf9a7bc2010-06-11 18:54:505325 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
5326 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
5327 // StartToFinish or BeginToFinish would be better.
[email protected]835d7c82010-10-14 04:38:385328 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]cf9a7bc2010-06-11 18:54:505329 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
5330 }
5331
[email protected]1a20f102010-09-16 21:50:395332 // Histograms to determine if cache throttling has an impact on PLT.
[email protected]835d7c82010-10-14 04:38:385333 static bool use_cache_histogram2(base::FieldTrialList::Find("CacheThrottle") &&
5334 !base::FieldTrialList::Find("CacheThrottle")->group_name().empty());
[email protected]1a20f102010-09-16 21:50:395335 if (use_cache_histogram2) {
5336 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385337 base::FieldTrial::MakeName("PLT.Abandoned", "CacheThrottle"),
[email protected]1a20f102010-09-16 21:50:395338 abandoned_page ? 1 : 0, 2);
5339 switch (load_type) {
5340 case NavigationState::RELOAD:
[email protected]835d7c82010-10-14 04:38:385341 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395342 "PLT.BeginToFinish_Reload", "CacheThrottle"),
5343 begin_to_finish_all_loads);
5344 break;
5345 case NavigationState::HISTORY_LOAD:
[email protected]835d7c82010-10-14 04:38:385346 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395347 "PLT.BeginToFinish_HistoryLoad", "CacheThrottle"),
5348 begin_to_finish_all_loads);
5349 break;
5350 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385351 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395352 "PLT.BeginToFinish_NormalLoad", "CacheThrottle"),
5353 begin_to_finish_all_loads);
5354 break;
5355 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385356 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395357 "PLT.BeginToFinish_LinkLoadNormal", "CacheThrottle"),
5358 begin_to_finish_all_loads);
5359 break;
5360 case NavigationState::LINK_LOAD_RELOAD:
[email protected]835d7c82010-10-14 04:38:385361 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395362 "PLT.BeginToFinish_LinkLoadReload", "CacheThrottle"),
5363 begin_to_finish_all_loads);
5364 break;
5365 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
[email protected]835d7c82010-10-14 04:38:385366 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395367 "PLT.BeginToFinish_LinkLoadStaleOk", "CacheThrottle"),
5368 begin_to_finish_all_loads);
5369 break;
5370 case NavigationState::LINK_LOAD_CACHE_ONLY:
[email protected]835d7c82010-10-14 04:38:385371 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395372 "PLT.BeginToFinish_LinkLoadCacheOnly", "CacheThrottle"),
5373 begin_to_finish_all_loads);
5374 break;
5375 default:
5376 break;
5377 }
5378 if (NavigationState::RELOAD <= load_type &&
5379 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
[email protected]835d7c82010-10-14 04:38:385380 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]1a20f102010-09-16 21:50:395381 "PLT.BeginToFinish", "CacheThrottle"),
5382 begin_to_finish_all_loads);
5383 }
5384 }
5385
[email protected]8cfe6bb2010-08-27 02:35:005386 // For the SPDY field trials, we need to verify that the page loaded was
5387 // the type we requested:
5388 // if we asked for a SPDY request, we got a SPDY request
5389 // if we asked for a HTTP request, we got a HTTP request
5390 // Due to spdy version mismatches, it is possible that we ask for SPDY
5391 // but didn't get SPDY.
[email protected]835d7c82010-10-14 04:38:385392 static bool use_spdy_histogram(base::FieldTrialList::Find("SpdyImpact") &&
5393 !base::FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]8cfe6bb2010-08-27 02:35:005394 if (use_spdy_histogram) {
5395 // We take extra effort to only compute these once.
5396 static bool in_spdy_trial =
[email protected]835d7c82010-10-14 04:38:385397 base::FieldTrialList::Find("SpdyImpact")->group_name() ==
5398 "npn_with_spdy";
[email protected]8cfe6bb2010-08-27 02:35:005399 static bool in_http_trial =
[email protected]835d7c82010-10-14 04:38:385400 base::FieldTrialList::Find("SpdyImpact")->group_name() ==
5401 "npn_with_http";
[email protected]cf9a7bc2010-06-11 18:54:505402
[email protected]8cfe6bb2010-08-27 02:35:005403 bool spdy_trial_success = navigation_state->was_fetched_via_spdy() ?
5404 in_spdy_trial : in_http_trial;
5405 if (spdy_trial_success) {
5406 // Histograms to determine if SPDY has an impact for https traffic.
5407 // TODO(mbelshe): After we've seen the difference between BeginToFinish
5408 // and StartToFinish, consider removing one or the other.
5409 if (scheme_type == URLPattern::SCHEME_HTTPS &&
5410 navigation_state->was_npn_negotiated()) {
5411 UMA_HISTOGRAM_ENUMERATION(
[email protected]835d7c82010-10-14 04:38:385412 base::FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
[email protected]8cfe6bb2010-08-27 02:35:005413 abandoned_page ? 1 : 0, 2);
5414 switch (load_type) {
5415 case NavigationState::LINK_LOAD_NORMAL:
[email protected]835d7c82010-10-14 04:38:385416 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]8cfe6bb2010-08-27 02:35:005417 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5418 begin_to_finish_all_loads);
[email protected]835d7c82010-10-14 04:38:385419 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]8cfe6bb2010-08-27 02:35:005420 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5421 start_to_finish_all_loads);
[email protected]835d7c82010-10-14 04:38:385422 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]8cfe6bb2010-08-27 02:35:005423 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5424 start_to_commit);
5425 break;
5426 case NavigationState::NORMAL_LOAD:
[email protected]835d7c82010-10-14 04:38:385427 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]8cfe6bb2010-08-27 02:35:005428 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5429 begin_to_finish_all_loads);
[email protected]835d7c82010-10-14 04:38:385430 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]8cfe6bb2010-08-27 02:35:005431 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5432 start_to_finish_all_loads);
[email protected]835d7c82010-10-14 04:38:385433 PLT_HISTOGRAM(base::FieldTrial::MakeName(
[email protected]8cfe6bb2010-08-27 02:35:005434 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
5435 start_to_commit);
5436 break;
5437 default:
5438 break;
5439 }
[email protected]193b0b892010-06-26 03:57:575440 }
[email protected]8cfe6bb2010-08-27 02:35:005441
5442 // Histograms to compare the impact of alternate protocol over http
5443 // traffic: when spdy is used vs. when http is used.
5444 if (scheme_type == URLPattern::SCHEME_HTTP &&
5445 navigation_state->was_alternate_protocol_available()) {
5446 if (!navigation_state->was_npn_negotiated()) {
5447 // This means that even there is alternate protocols for npn_http or
[email protected]835d7c82010-10-14 04:38:385448 // npn_spdy, they are not taken (due to the base::FieldTrial).
[email protected]8cfe6bb2010-08-27 02:35:005449 switch (load_type) {
5450 case NavigationState::LINK_LOAD_NORMAL:
5451 PLT_HISTOGRAM(
5452 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
5453 start_to_finish_all_loads);
5454 PLT_HISTOGRAM(
5455 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
5456 start_to_commit);
5457 break;
5458 case NavigationState::NORMAL_LOAD:
5459 PLT_HISTOGRAM(
5460 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
5461 start_to_finish_all_loads);
5462 PLT_HISTOGRAM(
5463 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
5464 start_to_commit);
5465 break;
5466 default:
5467 break;
5468 }
5469 } else if (navigation_state->was_fetched_via_spdy()) {
5470 switch (load_type) {
5471 case NavigationState::LINK_LOAD_NORMAL:
5472 PLT_HISTOGRAM(
5473 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
5474 start_to_finish_all_loads);
5475 PLT_HISTOGRAM(
5476 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
5477 start_to_commit);
5478 break;
5479 case NavigationState::NORMAL_LOAD:
5480 PLT_HISTOGRAM(
5481 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
5482 start_to_finish_all_loads);
5483 PLT_HISTOGRAM(
5484 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
5485 start_to_commit);
5486 break;
5487 default:
5488 break;
5489 }
5490 }
[email protected]193b0b892010-06-26 03:57:575491 }
5492 }
5493 }
5494
[email protected]cf9a7bc2010-06-11 18:54:505495 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:505496 if (navigation_state->was_fetched_via_proxy()) {
[email protected]05c8e502010-08-15 15:13:525497 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5498 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505499 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
[email protected]05c8e502010-08-15 15:13:525500 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505501 } else {
[email protected]05c8e502010-08-15 15:13:525502 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5503 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505504 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
[email protected]05c8e502010-08-15 15:13:525505 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505506 }
5507 } else {
[email protected]05c8e502010-08-15 15:13:525508 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5509 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https",
5510 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505511 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
[email protected]05c8e502010-08-15 15:13:525512 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505513 } else {
[email protected]05c8e502010-08-15 15:13:525514 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5515 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http",
5516 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505517 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
[email protected]05c8e502010-08-15 15:13:525518 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505519 }
5520 }
[email protected]a7ccc4d2010-01-27 08:14:485521
[email protected]ab9eabac2010-03-16 16:54:105522 // Site isolation metrics.
5523 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
5524 cross_origin_access_count_);
5525 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
5526 same_origin_access_count_);
5527
[email protected]05c8e502010-08-15 15:13:525528 // TODO(jar): This is the ONLY call in this method that needed more than
5529 // navigation_state. This should be relocated, or changed, so that this
5530 // body can be made a method on NavigationStates, and run via its destructor.
[email protected]cf9a7bc2010-06-11 18:54:505531 // Log some PLT data to the error log.
5532 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:295533
5534 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:415535
5536 // Since there are currently no guarantees that renderer histograms will be
5537 // sent to the browser, we initiate a PostTask here to be sure that we send
5538 // the histograms we generated. Without this call, pages that don't have an
5539 // on-close-handler might generate data that is lost when the renderer is
5540 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:485541 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
5542 // should post when the onload is complete, so that it doesn't interfere with
5543 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:415544 if (RenderThread::current()) {
5545 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:135546 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:415547 }
[email protected]c20210e62009-04-03 21:39:265548}
[email protected]e846d0d2009-05-20 00:53:065549
[email protected]f8999642009-10-27 21:39:425550void RenderView::LogNavigationState(const NavigationState* state,
5551 const WebDataSource* ds) const {
5552 // Because this function gets called on every page load,
5553 // take extra care to optimize it away if logging is turned off.
5554 if (logging::LOG_INFO < logging::GetMinLogLevel())
5555 return;
5556
5557 DCHECK(state);
5558 DCHECK(ds);
5559 GURL url(ds->request().url());
5560 Time start = state->start_load_time();
5561 Time finish = state->finish_load_time();
5562 // TODO(mbelshe): should we log more stats?
5563 LOG(INFO) << "PLT: "
5564 << (finish - start).InMilliseconds()
5565 << "ms "
5566 << url.spec();
5567}
5568
[email protected]9892b472010-09-16 00:23:425569void RenderView::postAccessibilityNotification(
5570 const WebAccessibilityObject& obj,
5571 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145572 if (!accessibility_.get() && webview()) {
5573 // Load complete should be our first notification sent.
5574 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5575 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5576 return;
5577
5578 // Create and initialize our accessibility cache
5579 accessibility_.reset(WebAccessibilityCache::create());
5580 accessibility_->initialize(webview());
5581 }
5582
[email protected]a3fa4f92010-09-30 22:19:335583 if (!accessibility_->isCached(obj)) {
5584 // The browser doesn't know about objects that are not in the cache. Send a
5585 // children change for the first accestor that actually is in the cache.
5586 WebAccessibilityObject parent = obj;
5587 while (parent.isValid() && !accessibility_->isCached(parent))
5588 parent = parent.parentObject();
5589
5590 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5591 if (!parent.isValid())
5592 return;
5593 postAccessibilityNotification(
5594 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5595
5596 // The parent's children change takes care of the child's children change.
5597 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5598 return;
5599 }
5600
[email protected]dea2d372010-09-25 06:41:145601 // Add the accessibility object to our cache and ensure it's valid.
5602 if (accessibility_->addOrGetId(obj) < 0)
[email protected]a3018be2010-03-09 04:28:485603 return;
5604
[email protected]9892b472010-09-16 00:23:425605 ViewHostMsg_AccessibilityNotification_Params param;
5606 switch (notification) {
5607 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
5608 param.notification_type =
5609 ViewHostMsg_AccessibilityNotification_Params::
5610 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
5611 break;
5612 case WebKit::WebAccessibilityNotificationChildrenChanged:
5613 param.notification_type =
5614 ViewHostMsg_AccessibilityNotification_Params::
5615 NOTIFICATION_TYPE_CHILDREN_CHANGED;
5616 break;
[email protected]dea2d372010-09-25 06:41:145617 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
5618 param.notification_type =
5619 ViewHostMsg_AccessibilityNotification_Params::
5620 NOTIFICATION_TYPE_FOCUS_CHANGED;
5621 break;
5622 case WebKit::WebAccessibilityNotificationLoadComplete:
5623 param.notification_type =
5624 ViewHostMsg_AccessibilityNotification_Params::
5625 NOTIFICATION_TYPE_LOAD_COMPLETE;
5626 break;
[email protected]9892b472010-09-16 00:23:425627 case WebKit::WebAccessibilityNotificationValueChanged:
5628 param.notification_type =
5629 ViewHostMsg_AccessibilityNotification_Params::
5630 NOTIFICATION_TYPE_VALUE_CHANGED;
5631 break;
[email protected]bd554c642010-10-01 19:52:045632 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
5633 param.notification_type =
5634 ViewHostMsg_AccessibilityNotification_Params::
5635 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
5636 break;
[email protected]9892b472010-09-16 00:23:425637 default:
5638 return;
5639 }
5640 param.acc_obj = WebAccessibility(obj, accessibility_.get());
[email protected]a3018be2010-03-09 04:28:485641
[email protected]9892b472010-09-16 00:23:425642 if (pending_accessibility_notifications_.empty()) {
5643 Send(new ViewHostMsg_AccessibilityNotifications(
5644 routing_id_,
5645 pending_accessibility_notifications_));
[email protected]520cb7d72010-08-31 11:54:315646 }
5647
[email protected]9892b472010-09-16 00:23:425648 pending_accessibility_notifications_.push_back(param);
[email protected]520cb7d72010-08-31 11:54:315649}
5650
[email protected]0fda7272009-06-26 15:49:335651void RenderView::Print(WebFrame* frame, bool script_initiated) {
5652 DCHECK(frame);
5653 if (print_helper_.get() == NULL) {
5654 print_helper_.reset(new PrintWebViewHelper(this));
5655 }
5656 print_helper_->Print(frame, script_initiated);
5657}
[email protected]446705872009-09-10 07:22:485658
5659void RenderView::OnSetEditCommandsForNextKeyEvent(
5660 const EditCommands& edit_commands) {
5661 edit_commands_ = edit_commands;
5662}
5663
[email protected]61f5a7b2009-12-22 22:21:205664void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275665 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355666 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205667 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5668 false));
[email protected]912256b32009-09-18 09:47:355669 return;
5670 }
5671
[email protected]fa7b6b542009-11-03 05:02:305672 WebDataSource* ds = main_frame->dataSource();
5673 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5674 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205675 pending_code_execution_queue_.push(
5676 linked_ptr<ViewMsg_ExecuteCode_Params>(
5677 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305678 return;
5679 }
5680
[email protected]61f5a7b2009-12-22 22:21:205681 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305682}
5683
5684void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205685 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205686 std::vector<WebFrame*> frame_vector;
5687 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205688 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205689 GetAllChildFrames(frame, &frame_vector);
5690
5691 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5692 frame_it != frame_vector.end(); ++frame_it) {
5693 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205694 if (params.is_javascript) {
[email protected]be7e5cb2010-10-04 12:53:175695 ExtensionRendererInfo* extension =
5696 ExtensionRendererInfo::GetByID(params.extension_id);
5697
5698 const std::vector<URLPattern> host_permissions =
5699 extension->host_permissions();
5700 if (!Extension::CanExecuteScriptOnPage(
5701 frame->url(),
5702 extension->allowed_to_execute_script_everywhere(),
5703 &host_permissions,
5704 NULL,
5705 NULL)) {
[email protected]61f5a7b2009-12-22 22:21:205706 continue;
[email protected]be7e5cb2010-10-04 12:53:175707 }
[email protected]61f5a7b2009-12-22 22:21:205708
[email protected]20ad2692009-11-20 18:27:205709 std::vector<WebScriptSource> sources;
5710 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205711 WebScriptSource(WebString::fromUTF8(params.code)));
5712 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205713 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205714 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205715 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5716 } else {
[email protected]61f5a7b2009-12-22 22:21:205717 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205718 }
[email protected]912256b32009-09-18 09:47:355719 }
5720
[email protected]61f5a7b2009-12-22 22:21:205721 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355722}
5723
[email protected]60c42a8c72009-10-09 04:08:595724void RenderView::Close() {
5725 // We need to grab a pointer to the doomed WebView before we destroy it.
5726 WebView* doomed = webview();
5727 RenderWidget::Close();
5728 Singleton<ViewMap>::get()->erase(doomed);
5729}
5730
[email protected]446705872009-09-10 07:22:485731void RenderView::DidHandleKeyEvent() {
5732 edit_commands_.clear();
5733}
5734
[email protected]6a8ddba52010-09-05 04:38:065735void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
5736 page_click_tracker_->DidHandleMouseEvent(event);
5737}
5738
[email protected]941e4552010-02-01 21:23:435739#if defined(OS_MACOSX)
5740void RenderView::OnWasHidden() {
5741 RenderWidget::OnWasHidden();
5742
5743 // Inform plugins that their container is no longer visible.
5744 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5745 for (plugin_it = plugin_delegates_.begin();
5746 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5747 (*plugin_it)->SetContainerVisibility(false);
5748 }
5749}
5750
5751void RenderView::OnWasRestored(bool needs_repainting) {
5752 RenderWidget::OnWasRestored(needs_repainting);
5753
5754 // Inform plugins that their container is now visible.
5755 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5756 for (plugin_it = plugin_delegates_.begin();
5757 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5758 (*plugin_it)->SetContainerVisibility(true);
5759 }
5760}
[email protected]784ea1ab2010-09-18 00:02:345761#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135762
5763void RenderView::OnSetFocus(bool enable) {
5764 RenderWidget::OnSetFocus(enable);
5765
[email protected]7d3c02c2010-05-05 23:10:315766 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075767 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135768 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5769 for (plugin_it = plugin_delegates_.begin();
5770 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345771#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315772 // RenderWidget's call to setFocus can cause the underlying webview's
5773 // activation state to change just like a call to setIsActive.
5774 if (enable)
5775 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345776#endif
[email protected]7d3c02c2010-05-05 23:10:315777 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135778 }
[email protected]589621b2010-09-23 22:01:075779
5780 // Notify all Pepper plugins.
5781 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135782 }
5783}
[email protected]941e4552010-02-01 21:23:435784
[email protected]83dde542009-09-11 20:59:555785void RenderView::EnsureDocumentTag() {
5786 // TODO(darin): There's actually no reason for this to be here. We should
5787 // have the browser side manage the document tag.
5788#if defined(OS_MACOSX)
5789 if (!has_document_tag_) {
5790 // Make the call to get the tag.
5791 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5792 has_document_tag_ = true;
5793 }
5794#endif
5795}
[email protected]12636df2009-09-28 22:32:215796
[email protected]43f28f832010-02-03 02:28:485797#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035798gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235799 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485800 gfx::PluginWindowHandle window = NULL;
5801 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235802 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115803 if (window) {
5804 fake_plugin_window_handles_.insert(window);
5805 }
[email protected]43f28f832010-02-03 02:28:485806 return window;
5807}
5808
5809void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115810 if (window && fake_plugin_window_handles_.find(window) !=
5811 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485812 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115813 fake_plugin_window_handles_.erase(window);
5814 }
[email protected]43f28f832010-02-03 02:28:485815}
5816
[email protected]44ce0b12010-03-12 16:45:335817void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5818 int32 width,
5819 int32 height,
5820 uint64 io_surface_identifier) {
5821 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485822 routing_id(), window, width, height, io_surface_identifier));
5823}
5824
[email protected]44ce0b12010-03-12 16:45:335825void RenderView::AcceleratedSurfaceSetTransportDIB(
5826 gfx::PluginWindowHandle window,
5827 int32 width,
5828 int32 height,
5829 TransportDIB::Handle transport_dib) {
5830 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075831 routing_id(), window, width, height, transport_dib));
5832}
5833
[email protected]44ce0b12010-03-12 16:45:335834TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5835 size_t size) {
[email protected]1aef98132010-02-23 18:00:075836 TransportDIB::Handle dib_handle;
5837 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385838 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075839 return dib_handle;
5840 // Return an invalid handle if Send() fails.
5841 return TransportDIB::DefaultHandleValue();
5842}
5843
[email protected]44ce0b12010-03-12 16:45:335844void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075845 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5846}
5847
[email protected]44ce0b12010-03-12 16:45:335848void RenderView::AcceleratedSurfaceBuffersSwapped(
5849 gfx::PluginWindowHandle window) {
5850 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485851}
5852#endif
[email protected]58c321d2010-02-19 12:11:285853
[email protected]cdaf8d02010-03-30 19:52:475854bool RenderView::ScheduleFileChooser(
5855 const ViewHostMsg_RunFileChooser_Params& params,
5856 WebFileChooserCompletion* completion) {
5857 static const size_t kMaximumPendingFileChooseRequests = 4;
5858 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5859 // This sanity check prevents too many file choose requests from getting
5860 // queued which could DoS the user. Getting these is most likely a
5861 // programming error (there are many ways to DoS the user so it's not
5862 // considered a "real" security check), either in JS requesting many file
5863 // choosers to pop up, or in a plugin.
5864 //
5865 // TODO(brettw) we might possibly want to require a user gesture to open
5866 // a file picker, which will address this issue in a better way.
5867 return false;
5868 }
5869
5870 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5871 new PendingFileChooser(params, completion)));
5872 if (file_chooser_completions_.size() == 1) {
5873 // Actually show the browse dialog when this is the first request.
5874 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5875 }
5876 return true;
5877}
5878
[email protected]290838a2010-04-27 17:37:015879void RenderView::OnPageTranslated() {
5880 WebFrame* frame = webview()->mainFrame();
5881 if (!frame)
5882 return;
5883
5884 // The page is translated, so try to extract the form data again.
[email protected]6a8ddba52010-09-05 04:38:065885 autofill_helper_->FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015886}
5887
[email protected]8a5f7002010-03-31 13:47:355888WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285889 if (!geolocation_dispatcher_.get())
5890 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5891 return geolocation_dispatcher_.get();
5892}
[email protected]61c9f032010-03-31 23:04:195893
[email protected]638694c2010-08-04 22:24:115894WebKit::WebSpeechInputController* RenderView::speechInputController(
5895 WebKit::WebSpeechInputListener* listener) {
5896 if (!speech_input_dispatcher_.get())
5897 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5898 return speech_input_dispatcher_.get();
5899}
5900
[email protected]57ead352010-08-11 14:42:535901WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
5902 if (!device_orientation_dispatcher_.get())
5903 device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this));
5904 return device_orientation_dispatcher_.get();
5905}
5906
[email protected]b75b8292010-10-01 07:28:255907void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5908 // For now, don't remember plugin zoom values. We don't want to mix them with
5909 // normal web content (i.e. a fixed layout plugin would usually want them
5910 // different).
5911 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5912
[email protected]b75b8292010-10-01 07:28:255913 int minimum_percent = static_cast<int>(
5914 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5915 int maximum_percent = static_cast<int>(
5916 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255917
5918 Send(new ViewHostMsg_UpdateZoomLimits(
5919 routing_id_, minimum_percent, maximum_percent, remember));
5920}
5921
5922void RenderView::zoomLevelChanged() {
5923 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5924
[email protected]b75b8292010-10-01 07:28:255925 // Tell the browser which url got zoomed so it can update the menu and the
5926 // saved values if necessary
5927 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415928 routing_id_, webview()->zoomLevel(), remember,
5929 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255930}
5931
[email protected]8079b362010-05-07 18:37:455932bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195933 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455934 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195935 if (frame->parent() != NULL)
5936 return false;
5937
[email protected]f0a3d0b2010-08-06 22:51:535938 // Navigations initiated within Webkit are not sent out to the external host
5939 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275940 // 1. The url scheme is not http/https
5941 // 2. There is no opener and this is not the first url being opened by this
5942 // RenderView.
5943 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535944 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535945 // 4. Reloads/form submits/back forward navigations
5946 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5947 return false;
5948
[email protected]d0ed50d2010-06-22 01:01:325949 // Not interested in reloads.
5950 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015951 type != WebKit::WebNavigationTypeFormSubmitted &&
5952 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325953 // The opener relationship between the new window and the parent allows the
5954 // new window to script the parent and vice versa. This is not allowed if
5955 // the origins of the two domains are different. This can be treated as a
5956 // top level navigation and routed back to the host.
5957 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275958 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475959 // Force link click navigations to always be routed to the host as they
5960 // may update session state on the server.
5961 if (type == WebKit::WebNavigationTypeLinkClicked)
5962 return true;
[email protected]900eb2f12010-08-23 22:36:275963 // If this is the first page being loaded by this RenderView instance then
5964 // it should stay here.
5965 if (page_id_ == -1) {
5966 return false;
5967 } else {
[email protected]d0ed50d2010-06-22 01:01:325968 return true;
[email protected]900eb2f12010-08-23 22:36:275969 }
[email protected]d0ed50d2010-06-22 01:01:325970 }
[email protected]900eb2f12010-08-23 22:36:275971
5972 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5973 return true;
[email protected]d0ed50d2010-06-22 01:01:325974 }
[email protected]61c9f032010-03-31 23:04:195975 return false;
5976}
[email protected]2b06a992010-08-21 05:48:225977
[email protected]27a9ef32010-09-10 04:06:245978void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5979 IPC::PlatformFileForTransit file_for_transit,
5980 int message_id) {
5981 pepper_delegate_.OnAsyncFileOpened(
5982 error_code,
5983 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5984 message_id);
5985}