blob: 21608d3efae10a3d2654d69b81290c4a86b98961 [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>
8#include <string>
9#include <vector>
10
[email protected]37126212009-05-06 02:23:3111#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1112#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5913#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0516#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2317#include "base/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2818#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5119#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5320#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
22#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2323#include "base/time.h"
[email protected]55126132010-08-19 14:53:2824#include "base/sys_string_conversions.h"
[email protected]be1ce6a72010-08-03 14:35:2225#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5726#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2127#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0928#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5529#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1730#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2831#include "chrome/common/chrome_paths.h"
32#include "chrome/common/chrome_switches.h"
[email protected]a0cf04a2010-06-23 03:29:5533#include "chrome/common/extensions/extension.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2135#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1736#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5337#include "chrome/common/pepper_plugin_registry.h"
[email protected]851b1eb2010-08-09 13:32:2938#include "chrome/common/plugin_group.h"
[email protected]e09ba552009-02-05 03:26:2939#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0240#include "chrome/common/render_messages_params.h"
[email protected]9b6f40e2009-06-11 15:54:2641#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5943#include "chrome/common/url_constants.h"
[email protected]534c66c2010-04-28 22:53:1144#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2546#include "chrome/renderer/audio_message_filter.h"
[email protected]00152e92010-07-19 11:47:4047#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5348#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1149#include "chrome/renderer/devtools_agent.h"
50#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3551#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3252#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3553#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3754#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2855#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2956#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5657#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4158#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]8400e032010-02-26 18:50:1159#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5660#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1261#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3062#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5063#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2564#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2865#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2666#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1867#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]035545f2010-04-09 13:10:2168#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3469#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]638694c2010-08-04 22:24:1170#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4671#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3572#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2973#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2974#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2975#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4276#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5677#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1578#include "gfx/color_utils.h"
79#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5780#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2681#include "gfx/point.h"
82#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2783#include "grit/generated_resources.h"
84#include "grit/renderer_resources.h"
[email protected]ee68378a2010-08-10 01:05:4185#include "media/base/media_switches.h"
[email protected]f11ca0732009-04-11 00:09:3486#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2987#include "net/base/escape.h"
88#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0089#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1090#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3091#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:0692#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4993#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:2694#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0795#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4996#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3298#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4999#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:35100#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]7a4de7a62010-08-17 18:38:24101#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]2b06a992010-08-21 05:48:22102#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
[email protected]b1438212010-04-03 00:30:59104#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49105#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
106#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
107#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41108#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50109#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49110#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32111#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07112#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49113#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40114#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17115#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49116#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49117#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
118#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
119#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
120#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
121#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
122#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40123#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49124#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34125#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49126#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
127#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
128#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
129#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
130#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
131#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26132#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11133#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04134#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]7a4de7a62010-08-17 18:38:24135#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29136#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59137#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24138#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24139#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34140#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26141#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17142#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51143#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09144#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26145#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38146#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17147#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29148#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30149#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23150#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30151#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40152#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09153#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24154#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29155#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29156#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17157#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29158
[email protected]6c8afae52009-01-22 02:24:57159#if defined(OS_WIN)
160// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57161// * theming
[email protected]cd818412010-03-19 03:23:15162#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03163#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46164#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33165#elif defined(OS_MACOSX)
166#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57167#endif
168
[email protected]80f584d92010-01-21 03:59:04169using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26170using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33171using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45172using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59173using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24174using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17175using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56176using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10177using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09178using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15179using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08180using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21181using WebKit::WebApplicationCacheHost;
182using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41183using WebKit::WebColor;
184using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59185using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44186using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51187using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07188using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55189using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28190using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29191using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00192using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58193using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25194using WebKit::WebDragOperation;
195using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51196using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47197using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22198using WebKit::WebFileSystem;
199using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49200using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59201using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48202using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45203using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17204using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41205using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50206using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17207using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28208using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17209using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28210using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28211using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51212using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07213using WebKit::WebPageSerializer;
214using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17215using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40216using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49217using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09218using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52219using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59220using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51221using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52222using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40223using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35224using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29225using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59226using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42227using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02228using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34229using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28230using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51231using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52232using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28233using WebKit::WebURL;
234using WebKit::WebURLError;
235using WebKit::WebURLRequest;
236using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28237using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03238using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28239using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43240using WebKit::WebWorker;
241using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11242using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33243
initial.commit09911bf2008-07-26 23:55:29244//-----------------------------------------------------------------------------
245
[email protected]3354d3e2010-06-10 19:53:02246typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
247
initial.commit09911bf2008-07-26 23:55:29248// define to write the time necessary for thumbnail/DOM text retrieval,
249// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29250// #define TIME_TEXT_RETRIEVAL
251
252// maximum number of characters in the document to index, any text beyond this
253// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57254static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29255
256// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37257static const int kThumbnailWidth = 212;
258static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29259
260// Delay in milliseconds that we'll wait before capturing the page contents
261// and thumbnail.
262static const int kDelayForCaptureMs = 500;
263
264// Typically, we capture the page data once the page is loaded.
265// Sometimes, the page never finishes to load, preventing the page capture
266// To workaround this problem, we always perform a capture after the following
267// delay.
268static const int kDelayForForcedCaptureMs = 6000;
269
[email protected]882daa92009-11-05 16:31:31270// Time, in seconds, we delay before sending content state changes (such as form
271// state and scroll position) to the browser. We delay sending changes to avoid
272// spamming the browser.
273// To avoid having tab/session restore require sending a message to get the
274// current content state during tab closing we use a shorter timeout for the
275// foreground renderer. This means there is a small window of time from which
276// content state is modified and not sent to session restore, but this is
277// better than having to wake up all renderers during shutdown.
278static const int kDelaySecondsForContentStateSyncHidden = 5;
279static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29280
[email protected]0aa55312008-10-17 21:53:08281// The maximum number of popups that can be spawned from one page.
282static const int kMaximumNumberOfUnacknowledgedPopups = 25;
283
initial.commit09911bf2008-07-26 23:55:29284static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16285 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29286
[email protected]50b691c2008-10-31 19:08:35287static const char* const kBackForwardNavigationScheme = "history";
288
[email protected]726985e22009-06-18 21:09:28289static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
290 WebVector<WebURL> urls;
291 ds->redirectChain(urls);
292 result->reserve(urls.size());
293 for (size_t i = 0; i < urls.size(); ++i)
294 result->push_back(urls[i]);
295}
296
[email protected]61f5a7b2009-12-22 22:21:20297static bool UrlMatchesPermissions(
298 const GURL& url, const std::vector<URLPattern>& host_permissions) {
299 for (size_t i = 0; i < host_permissions.size(); ++i) {
300 if (host_permissions[i].MatchesUrl(url))
301 return true;
302 }
303
304 return false;
305}
306
[email protected]30507922010-01-15 16:48:23307static bool PaintViewIntoCanvas(WebView* view,
308 skia::PlatformCanvas& canvas) {
309 view->layout();
310 const WebSize& size = view->size();
311
312 if (!canvas.initialize(size.width, size.height, true))
313 return false;
314
315 view->paint(webkit_glue::ToWebCanvas(&canvas),
316 WebRect(0, 0, size.width, size.height));
317 // TODO: Add a way to snapshot the whole page, not just the currently
318 // visible part.
319
320 return true;
321}
322
323// Calculates how "boring" a thumbnail is. The boring score is the
324// 0,1 ranged percentage of pixels that are the most common
325// luma. Higher boring scores indicate that a higher percentage of a
326// bitmap are all the same brightness.
327static double CalculateBoringScore(SkBitmap* bitmap) {
328 int histogram[256] = {0};
329 color_utils::BuildLumaHistogram(bitmap, histogram);
330
331 int color_count = *std::max_element(histogram, histogram + 256);
332 int pixel_count = bitmap->width() * bitmap->height();
333 return static_cast<double>(color_count) / pixel_count;
334}
335
[email protected]12bc8472010-04-15 07:29:40336// True if |frame| contains content that is white-listed for content settings.
337static bool IsWhitelistedForContentSettings(WebFrame* frame) {
338 WebSecurityOrigin origin = frame->securityOrigin();
339 if (origin.isEmpty())
340 return false; // Uninitialized document?
341
342 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
343 return true; // Browser UI elements should still work.
344
345 // If the scheme is ftp: or file:, an empty file name indicates a directory
346 // listing, which requires JavaScript to function properly.
347 GURL frame_url = frame->url();
348 const char* kDirProtocols[] = { "ftp", "file" };
349 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
350 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
351 return frame_url.SchemeIs(kDirProtocols[i]) &&
352 frame_url.ExtractFileName().empty();
353 }
354 }
355
356 return false;
357}
358
[email protected]3a8eecb2010-04-22 23:56:30359// Returns true if the frame is navigating to an URL either into or out of an
360// extension app's extent.
361static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
362 if (!RenderThread::current())
363 return false;
364
365 // If the URL is still empty, this is a window.open navigation. Check the
366 // opener's URL.
367 GURL old_url(frame->url());
368 if (old_url.is_empty() && frame->opener())
369 old_url = frame->opener()->url();
370
371 std::string old_extension =
[email protected]4fdbc1492010-07-01 01:20:59372 RenderThread::current()->GetExtensionIdByURL(old_url);
373 if (!old_extension.empty()) {
374 if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) ==
375 old_extension) {
376 return false;
377 }
378 }
379
[email protected]3a8eecb2010-04-22 23:56:30380 std::string new_extension =
[email protected]4fdbc1492010-07-01 01:20:59381 RenderThread::current()->GetExtensionIdByURL(new_url);
382 return old_extension != new_extension;
[email protected]3a8eecb2010-04-22 23:56:30383}
384
[email protected]3354d3e2010-06-10 19:53:02385// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
386// if it failed.
387//
388// Note this only works on Windows at this time. It always returns 'unknown'
389// on other platforms.
[email protected]e5106202010-06-11 21:12:36390static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17391 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02392 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08393 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02394 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02395 Language cld_language =
[email protected]e5106202010-06-11 21:12:36396 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08397 &num_languages, NULL, &text_bytes);
398 // We don't trust the result if the CLD reports that the detection is not
399 // reliable, or if the actual text used to detect the language was less than
400 // 100 bytes (short texts can often lead to wrong results).
401 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02402 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
403 // We should not use LanguageCode_ISO_639_1 because it does not cover all
404 // the languages CLD can detect. As a result, it'll return the invalid
405 // language code for tradtional Chinese among others.
406 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
407 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
408 // for Simplified Chinese.
409 language = LanguageCodeWithDialects(cld_language);
410 }
411 return language;
412}
413
[email protected]2b06a992010-08-21 05:48:22414// Holds pending openFileSystem callbacks.
415struct RenderView::PendingOpenFileSystem {
416 explicit PendingOpenFileSystem(WebFileSystemCallbacks* c) : callbacks(c) {
417 }
418 ~PendingOpenFileSystem() {
419 if (callbacks)
420 callbacks->didFail(WebKit::WebFileErrorAbort);
421 }
422 WebFileSystemCallbacks* callbacks;
423};
424
initial.commit09911bf2008-07-26 23:55:29425///////////////////////////////////////////////////////////////////////////////
426
[email protected]60c42a8c72009-10-09 04:08:59427int32 RenderView::next_page_id_ = 1;
428
[email protected]cdaf8d02010-03-30 19:52:47429struct RenderView::PendingFileChooser {
430 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
431 WebFileChooserCompletion* c)
432 : params(p),
433 completion(c) {
434 }
435 ViewHostMsg_RunFileChooser_Params params;
436 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
437};
438
[email protected]2fab253a2009-08-17 23:00:59439RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34440 const WebPreferences& webkit_preferences,
441 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12442 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02443 webkit_preferences_(webkit_preferences),
444 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09445 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02446 send_preferred_size_changes_(false),
447 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24448 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21449 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02450 opened_by_user_gesture_(true),
451 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24452 page_id_(-1),
453 last_page_id_sent_to_browser_(-1),
454 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00455 history_list_offset_(-1),
456 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24457 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55458#if defined(OS_MACOSX)
459 has_document_tag_(false),
460#endif
[email protected]98324892009-09-09 21:16:05461 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10462 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17463 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02464 target_url_status_(TARGET_NONE),
465 spelling_panel_visible_(false),
466 view_type_(ViewType::INVALID),
467 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18468 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30469 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
470 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02471 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]03f57072010-07-14 17:36:08472 ALLOW_THIS_IN_INITIALIZER_LIST(password_autocomplete_manager_(this)),
[email protected]679f128f2010-07-22 22:57:44473 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_helper_(this)),
[email protected]3354d3e2010-06-10 19:53:02474 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
475 ALLOW_THIS_IN_INITIALIZER_LIST(
476 notification_provider_(new NotificationProvider(this))),
477 session_storage_namespace_id_(session_storage_namespace_id),
478 decrement_shared_popup_at_destruction_(false) {
[email protected]71b0d5d2010-02-15 05:43:07479 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29480}
481
482RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08483 if (decrement_shared_popup_at_destruction_)
484 shared_popup_counter_->data--;
485
[email protected]b0950a72009-09-29 23:16:17486 // Dispose of un-disposed image fetchers.
487 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
488 i != image_fetchers_.end(); ++i) {
489 delete *i;
490 }
491
[email protected]a1128322009-10-06 18:38:46492 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47493 while (!file_chooser_completions_.empty()) {
494 if (file_chooser_completions_.front()->completion) {
495 file_chooser_completions_.front()->completion->didChooseFile(
496 WebVector<WebString>());
497 }
498 file_chooser_completions_.pop_front();
499 }
[email protected]a1128322009-10-06 18:38:46500
[email protected]83dde542009-09-11 20:59:55501#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05502 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55503 if (has_document_tag_)
504 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
505#endif
[email protected]98324892009-09-09 21:16:05506
[email protected]5fb88962009-04-16 19:03:25507 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59508
509#ifndef NDEBUG
510 // Make sure we are no longer referenced by the ViewMap.
511 ViewMap* views = Singleton<ViewMap>::get();
512 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
513 DCHECK_NE(this, it->second) << "Failed to call Close?";
514#endif
515}
516
517/*static*/
518void RenderView::ForEach(RenderViewVisitor* visitor) {
519 ViewMap* views = Singleton<ViewMap>::get();
520 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
521 if (!visitor->Visit(it->second))
522 return;
523 }
524}
525
526/*static*/
527RenderView* RenderView::FromWebView(WebView* webview) {
528 ViewMap* views = Singleton<ViewMap>::get();
529 ViewMap::iterator it = views->find(webview);
530 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29531}
532
533/*static*/
[email protected]0aa55312008-10-17 21:53:08534RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24535 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15536 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08537 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51538 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08539 const WebPreferences& webkit_prefs,
540 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34541 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26542 int64 session_storage_namespace_id,
543 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29544 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34545 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
546 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29547 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29548 opener_id,
[email protected]80d96fa2009-06-10 22:34:51549 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08550 counter,
[email protected]8ab04652010-06-12 02:47:26551 routing_id,
552 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29553 return view;
554}
555
556/*static*/
557void RenderView::SetNextPageID(int32 next_page_id) {
558 // This method should only be called during process startup, and the given
559 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05560 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29561 DCHECK(next_page_id >= next_page_id_);
562 next_page_id_ = next_page_id;
563}
564
[email protected]8a3125a712010-08-09 18:58:51565WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26566 return static_cast<WebKit::WebView*>(webwidget());
567}
568
[email protected]afe3a1672009-11-17 19:04:12569void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56570 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
571}
572
[email protected]a3a8fb6d2009-10-22 20:12:51573void RenderView::PluginCrashed(const FilePath& plugin_path) {
574 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29575}
576
[email protected]aad51d1c2010-08-05 08:38:09577WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
578 const WebPluginParams& params) {
579 WebPluginInfo info;
580 bool found;
[email protected]55126132010-08-19 14:53:28581 ContentSetting setting;
[email protected]aad51d1c2010-08-05 08:38:09582 std::string mime_type;
583 Send(new ViewHostMsg_GetPluginInfo(
584 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
[email protected]55126132010-08-19 14:53:28585 &info, &setting, &mime_type));
[email protected]aad51d1c2010-08-05 08:38:09586 if (!found || !info.enabled)
587 return NULL;
588 scoped_refptr<pepper::PluginModule> pepper_module =
589 PepperPluginRegistry::GetInstance()->GetModule(info.path);
590 if (pepper_module)
591 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
592 else
593 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
594}
595
[email protected]d8fd6fa2010-02-01 15:54:26596#if defined(OS_MACOSX)
597void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
598 plugin_delegates_.insert(delegate);
599}
600
601void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
602 plugin_delegates_.erase(delegate);
603}
604#endif
605
[email protected]18bcc3c2009-01-27 21:39:15606void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29607 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51608 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08609 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26610 int32 routing_id,
611 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29612 DCHECK(!webview());
613
614 if (opener_id != MSG_ROUTING_NONE)
615 opener_id_ = opener_id;
616
[email protected]0aa55312008-10-17 21:53:08617 if (counter) {
618 shared_popup_counter_ = counter;
619 shared_popup_counter_->data++;
620 decrement_shared_popup_at_destruction_ = true;
621 } else {
622 shared_popup_counter_ = new SharedRenderViewCounter(0);
623 decrement_shared_popup_at_destruction_ = false;
624 }
625
[email protected]58bfc6b2009-06-24 09:45:02626 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04627
[email protected]9a6c6232010-06-25 11:46:49628 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59629 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59630 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27631 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23632 if (!frame_name.empty())
633 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29634
[email protected]d3ba77272009-09-03 00:06:09635 OnSetRendererPrefs(renderer_prefs);
636
initial.commit09911bf2008-07-26 23:55:29637 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24638 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29639 // Take a reference on behalf of the RenderThread. This will be balanced
640 // when we receive ViewMsg_Close.
641 AddRef();
642
643 // If this is a popup, we must wait for the CreatingNew_ACK message before
644 // completing initialization. Otherwise, we can finish it now.
645 if (opener_id == MSG_ROUTING_NONE) {
646 did_show_ = true;
647 CompleteInit(parent_hwnd);
648 }
649
650 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29651
[email protected]58bfc6b2009-06-24 09:45:02652 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09653 if (command_line.HasSwitch(switches::kDomAutomationController))
654 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29655
[email protected]5fb88962009-04-16 19:03:25656 audio_message_filter_ = new AudioMessageFilter(routing_id_);
657 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29658}
659
660void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27661 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27662 if (main_frame)
663 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26664
[email protected]b2abac72009-02-26 12:39:28665 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11666 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28667 return;
[email protected]b4b967e2009-04-22 11:33:05668 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
669 return;
[email protected]b6849bda2009-10-14 23:59:26670 if (notification_provider_->OnMessageReceived(message))
671 return;
[email protected]58c321d2010-02-19 12:11:28672 if (geolocation_dispatcher_.get() &&
673 geolocation_dispatcher_->OnMessageReceived(message)) {
674 return;
675 }
[email protected]638694c2010-08-04 22:24:11676 if (speech_input_dispatcher_.get() &&
677 speech_input_dispatcher_->OnMessageReceived(message)) {
678 return;
679 }
[email protected]57ead352010-08-11 14:42:53680 if (device_orientation_dispatcher_.get() &&
681 device_orientation_dispatcher_->OnMessageReceived(message)) {
682 return;
683 }
[email protected]b2abac72009-02-26 12:39:28684
initial.commit09911bf2008-07-26 23:55:29685 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04686 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
687 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29688 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01689 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29690 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
691 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56692 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29693 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
694 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
695 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
696 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27697#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35698 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27699#endif
initial.commit09911bf2008-07-26 23:55:29700 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
701 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05702 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
703 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
704 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04705 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29706 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
707 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
708 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15709 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29710 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49711 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
712 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17713 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54714 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
715 OnSetContentSettingsForLoadingURL)
716 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
717 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29718 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18719 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
720 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28721 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33722 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29723 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48724 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29725 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29726 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29727 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
728 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
729 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
730 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
731 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45732 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29733 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50734 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
735 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29736 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
737 OnDragSourceSystemDragEnded)
738 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29739 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
740 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
741 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
742 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:21743 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:29744 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
745 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29746 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
747 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04748 IPC_MESSAGE_HANDLER(
749 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
750 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29751 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04752 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29753 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
754 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45755 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04756 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08757 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
758 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24759 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
760 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48761 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
762 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40763 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
764 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00765 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27766 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37767 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
768 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16769 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14770 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25771 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
772 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10773 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
774 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51775 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53776 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
777 OnUpdateBrowserWindowId)
778 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
779 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56780 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34781 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14782#if defined(OS_MACOSX)
783 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13784 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14785#endif
[email protected]446705872009-09-10 07:22:48786 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33787 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35788 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
789 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33790 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
791 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42792 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02793 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09794 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36795 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
796 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
797 OnAccessibilityDoDefaultAction)
[email protected]2b06a992010-08-21 05:48:22798 IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete,
799 OnOpenFileSystemRequestComplete)
[email protected]634a6f92008-12-01 21:39:31800
initial.commit09911bf2008-07-26 23:55:29801 // Have the super handle all other messages.
802 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
803 IPC_END_MESSAGE_MAP()
804}
805
[email protected]9b18a84f2010-06-10 15:54:04806void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27807 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29808 if (!main_frame)
809 return;
810
811 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45812 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29813 if (url.is_empty())
814 return;
815
816 if (size_.IsEmpty())
817 return; // Don't create an empty thumbnail!
818
819 ThumbnailScore score;
820 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02821 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15822 &thumbnail, &score))
823 return;
824
initial.commit09911bf2008-07-26 23:55:29825 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46826 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29827}
828
[email protected]9b18a84f2010-06-10 15:54:04829void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23830 SkBitmap snapshot;
831 bool error = false;
832
833 WebFrame* main_frame = webview()->mainFrame();
834 if (!main_frame)
835 error = true;
836
837 if (!error && !CaptureSnapshot(webview(), &snapshot))
838 error = true;
839
840 DCHECK(error == snapshot.empty()) <<
841 "Snapshot should be empty on error, non-empty otherwise.";
842
843 // Send the snapshot to the browser process.
844 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
845}
846
[email protected]068637222009-01-29 16:58:07847void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29848 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58849 if (webview()) {
850 // If the user has selected text in the currently focused frame we print
851 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27852 if (webview()->focusedFrame()->hasSelection())
853 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58854 else
[email protected]26aa0482009-09-30 16:55:27855 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58856 }
initial.commit09911bf2008-07-26 23:55:29857}
858
[email protected]82270452009-06-19 15:58:01859void RenderView::OnPrintingDone(int document_cookie, bool success) {
860 // Ignoring document cookie here since only one print job can be outstanding
861 // per renderer and document_cookie is 0 when printing is successful.
862 DCHECK(print_helper_.get());
863 if (print_helper_.get() != NULL) {
864 print_helper_->DidFinishPrinting(success);
865 }
866}
867
initial.commit09911bf2008-07-26 23:55:29868void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
869 if (load_id != page_id_)
870 return; // this capture call is no longer relevant due to navigation
871 if (load_id == last_indexed_page_id_)
872 return; // we already indexed this page
873
874 if (!webview())
875 return;
876
[email protected]26aa0482009-09-30 16:55:27877 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29878 if (!main_frame)
879 return;
880
881 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45882 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29883 return;
884
885 // Don't index/capture pages that failed to load. This only checks the top
886 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45887 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28888 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29889 return;
890
891 if (!preliminary_capture)
892 last_indexed_page_id_ = load_id;
893
[email protected]a8a81292010-01-21 00:32:45894 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45895 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29896 if (url.is_empty())
897 return;
898
[email protected]a8a81292010-01-21 00:32:45899 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36900 string16 contents;
initial.commit09911bf2008-07-26 23:55:29901 CaptureText(main_frame, &contents);
902 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45903 base::TimeTicks begin_time = base::TimeTicks::Now();
904 std::string language = DetermineTextLanguage(contents);
905 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
906 base::TimeTicks::Now() - begin_time);
[email protected]1c57b7b2010-07-12 17:38:10907 WebKit::WebDocument document = main_frame->document();
[email protected]a8a81292010-01-21 00:32:45908 // Send the text to the browser for indexing (the browser might decide not
909 // to index, if the URL is HTTPS for instance) and language discovery.
910 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
[email protected]1c57b7b2010-07-12 17:38:10911 language, IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27912 }
913
[email protected]9b18a84f2010-06-10 15:54:04914 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29915}
916
[email protected]e5106202010-06-11 21:12:36917void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29918 contents->clear();
919 if (!frame)
920 return;
921
922#ifdef TIME_TEXT_RETRIEVAL
923 double begin = time_util::GetHighResolutionTimeNow();
924#endif
925
926 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36927 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29928
929#ifdef TIME_TEXT_RETRIEVAL
930 double end = time_util::GetHighResolutionTimeNow();
931 char buf[128];
932 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
933 contents.size(), (end - begin)*1000);
934 OutputDebugStringA(buf);
935#endif
936
937 // When the contents are clipped to the maximum, we don't want to have a
938 // partial word indexed at the end that might have been clipped. Therefore,
939 // terminate the string at the last space to ensure no words are clipped.
940 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36941 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29942 if (last_space_index == std::wstring::npos)
943 return; // don't index if we got a huge block of text with no spaces
944 contents->resize(last_space_index);
945 }
946}
947
[email protected]8649fb32009-06-26 17:51:02948bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29949 int w,
950 int h,
951 SkBitmap* thumbnail,
952 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23953 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15954
[email protected]8649fb32009-06-26 17:51:02955 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23956
957 // Paint |view| into |canvas|.
958 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02959 return false;
[email protected]8649fb32009-06-26 17:51:02960
961 skia::BitmapPlatformDevice& device =
962 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
963
964 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29965
[email protected]cab34d6a2009-09-24 01:14:52966 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29967 float dest_aspect = dest_rect.width() / dest_rect.height();
968
969 // Get the src rect so that we can preserve the aspect ratio while filling
970 // the destination.
971 SkIRect src_rect;
972 if (src_bmp.width() < dest_rect.width() ||
973 src_bmp.height() < dest_rect.height()) {
974 // Source image is smaller: we clip the part of source image within the
975 // dest rect, and then stretch it to fill the dest rect. We don't respect
976 // the aspect ratio in this case.
977 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
978 static_cast<S16CPU>(dest_rect.height()));
979 score->good_clipping = false;
980 } else {
981 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
982 if (src_aspect > dest_aspect) {
983 // Wider than tall, clip horizontally: we center the smaller thumbnail in
984 // the wider screen.
985 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
986 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
987 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
988 score->good_clipping = false;
989 } else {
990 src_rect.set(0, 0, src_bmp.width(),
991 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
992 score->good_clipping = true;
993 }
994 }
995
[email protected]26aa0482009-09-30 16:55:27996 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29997
998 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02999 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291000
1001 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:141002 *thumbnail = skia::ImageOperations::Resize(
1003 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291004
1005 score->boring_score = CalculateBoringScore(thumbnail);
1006
[email protected]30507922010-01-15 16:48:231007 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1008 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:151009 return true;
initial.commit09911bf2008-07-26 23:55:291010}
1011
[email protected]30507922010-01-15 16:48:231012bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1013 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291014
[email protected]30507922010-01-15 16:48:231015 skia::PlatformCanvas canvas;
1016 if (!PaintViewIntoCanvas(view, canvas))
1017 return false;
1018
1019 skia::BitmapPlatformDevice& device =
1020 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1021
1022 const SkBitmap& bitmap = device.accessBitmap(false);
1023 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1024 return false;
1025
1026 HISTOGRAM_TIMES("Renderer4.Snapshot",
1027 base::TimeTicks::Now() - beginning_time);
1028 return true;
initial.commit09911bf2008-07-26 23:55:291029}
1030
1031void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1032 if (!webview())
1033 return;
1034
[email protected]3cc72b12010-03-18 23:03:001035 history_list_offset_ = params.current_history_list_offset;
1036 history_list_length_ = params.current_history_list_length;
1037
[email protected]8c785c62009-07-13 14:20:151038 if (devtools_agent_.get())
1039 devtools_agent_->OnNavigate();
1040
[email protected]422197532010-01-25 17:38:231041 if (notification_provider_.get())
1042 notification_provider_->OnNavigate();
1043
[email protected]a9f607e2009-10-23 19:59:271044 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261045
initial.commit09911bf2008-07-26 23:55:291046 AboutHandler::MaybeHandle(params.url);
1047
[email protected]ecbf10d2010-02-18 13:03:291048 bool is_reload =
1049 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1050 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291051
[email protected]26aa0482009-09-30 16:55:271052 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451053 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291054 // We cannot reload if we do not have any history state. This happens, for
1055 // example, when recovering from a crash. Our workaround here is a bit of
1056 // a hack since it means that reload after a crashed tab does not cause an
1057 // end-to-end cache validation.
1058 is_reload = false;
1059 }
1060
[email protected]77f17a82009-05-21 04:42:541061 // A navigation resulting from loading a javascript URL should not be treated
1062 // as a browser initiated event. Instead, we want it to look as if the page
1063 // initiated any load resulting from JS execution.
1064 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301065 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001066 params.page_id,
1067 params.pending_history_list_offset,
1068 params.transition,
1069 params.request_time);
[email protected]5e369672009-11-03 23:48:301070 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1071 // We're doing a load of a page that was restored from the last session.
1072 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1073 // which can result in stale data for pages that are set to expire. We
1074 // explicitly override that by setting the policy here so that as
1075 // necessary we load from the network.
1076 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1077 }
1078 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541079 }
initial.commit09911bf2008-07-26 23:55:291080
[email protected]a7ccc4d2010-01-27 08:14:481081 NavigationState* navigation_state = pending_navigation_state_.get();
1082
[email protected]04d3c6e2009-05-22 17:00:131083 // If we are reloading, then WebKit will use the history state of the current
1084 // page, so we should just ignore any given history state. Otherwise, if we
1085 // have history state, then we need to navigate to it, which corresponds to a
1086 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551087 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481088 if (navigation_state)
1089 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291090 bool ignore_cache = (params.navigation_type ==
1091 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1092 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551093 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131094 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581095 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481096 if (navigation_state)
1097 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451098 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171099 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131100 } else {
1101 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281102 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291103
[email protected]e6f546c32009-07-01 17:12:551104 // A session history navigation should have been accompanied by state.
1105 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131106
[email protected]dd7daa82009-08-10 05:46:451107 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551108 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131109
[email protected]726985e22009-06-18 21:09:281110 if (params.referrer.is_valid()) {
1111 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1112 WebString::fromUTF8(params.referrer.spec()));
1113 }
[email protected]04d3c6e2009-05-22 17:00:131114
[email protected]a7ccc4d2010-01-27 08:14:481115 if (navigation_state)
1116 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451117 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501118 }
1119
[email protected]77f17a82009-05-21 04:42:541120 // In case LoadRequest failed before DidCreateDataSource was called.
1121 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291122}
1123
1124// Stop loading the current page
1125void RenderView::OnStop() {
1126 if (webview())
[email protected]b4bb2502009-10-01 22:35:271127 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291128}
1129
[email protected]ecbf10d2010-02-18 13:03:291130// Reload current focused frame.
1131// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561132void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291133 if (webview() && webview()->focusedFrame()) {
1134 // We always obey the cache (ignore_cache=false) here.
1135 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1136 // a cache-ignoring reload of the frame.
1137 webview()->focusedFrame()->reload(false);
1138 }
[email protected]1dda4022010-01-28 18:24:561139}
1140
initial.commit09911bf2008-07-26 23:55:291141void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271142 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291143}
1144
[email protected]68b1e922009-06-23 16:00:251145void RenderView::OnExecuteEditCommand(const std::string& name,
1146 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271147 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251148 return;
1149
[email protected]26aa0482009-09-30 16:55:271150 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451151 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251152}
1153
[email protected]b2abac72009-02-26 12:39:281154void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111155 DCHECK(!devtools_client_.get());
1156 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281157}
1158
initial.commit09911bf2008-07-26 23:55:291159void RenderView::OnUpdateTargetURLAck() {
1160 // Check if there is a targeturl waiting to be sent.
1161 if (target_url_status_ == TARGET_PENDING) {
1162 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1163 pending_target_url_));
1164 }
1165
1166 target_url_status_ = TARGET_NONE;
1167}
1168
1169void RenderView::OnUndo() {
1170 if (!webview())
1171 return;
1172
[email protected]26aa0482009-09-30 16:55:271173 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121174 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291175}
1176
1177void RenderView::OnRedo() {
1178 if (!webview())
1179 return;
1180
[email protected]26aa0482009-09-30 16:55:271181 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121182 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291183}
1184
1185void RenderView::OnCut() {
1186 if (!webview())
1187 return;
1188
[email protected]26aa0482009-09-30 16:55:271189 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121190 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291191}
1192
1193void RenderView::OnCopy() {
1194 if (!webview())
1195 return;
1196
[email protected]26aa0482009-09-30 16:55:271197 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121198 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291199}
1200
[email protected]c0cc3092009-09-12 08:27:271201#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351202void RenderView::OnCopyToFindPboard() {
1203 if (!webview())
1204 return;
1205
1206 // Since the find pasteboard supports only plain text, this can be simpler
1207 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271208 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351209 if (frame->hasSelection()) {
1210 string16 selection = frame->selectionAsText();
1211 RenderThread::current()->Send(
1212 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1213 }
1214
[email protected]afe3a1672009-11-17 19:04:121215 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351216}
[email protected]c0cc3092009-09-12 08:27:271217#endif
[email protected]a954bf72009-09-12 07:30:351218
initial.commit09911bf2008-07-26 23:55:291219void RenderView::OnPaste() {
1220 if (!webview())
1221 return;
1222
[email protected]26aa0482009-09-30 16:55:271223 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121224 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291225}
1226
[email protected]2a3a7762009-10-19 19:17:321227void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291228 if (!webview())
1229 return;
1230
[email protected]1ff7a032010-02-03 02:46:031231 WebFrame* frame = webview()->focusedFrame();
1232 if (!frame->hasSelection())
1233 frame->selectWordAroundCaret();
1234 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291235}
1236
[email protected]98324892009-09-09 21:16:051237void RenderView::OnAdvanceToNextMisspelling() {
1238 if (!webview())
1239 return;
[email protected]26aa0482009-09-30 16:55:271240 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051241 WebString::fromUTF8("AdvanceToNextMisspelling"));
1242}
1243
1244void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1245 if (!webview())
1246 return;
1247 // We need to tell the webView whether the spelling panel is visible or not so
1248 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261249 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271250 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051251 WebString::fromUTF8("ToggleSpellPanel"));
1252}
1253
[email protected]bbbd545c2008-12-15 20:18:041254void RenderView::OnToggleSpellCheck() {
1255 if (!webview())
1256 return;
1257
[email protected]26aa0482009-09-30 16:55:271258 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451259 frame->enableContinuousSpellChecking(
1260 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041261}
1262
initial.commit09911bf2008-07-26 23:55:291263void RenderView::OnDelete() {
1264 if (!webview())
1265 return;
1266
[email protected]26aa0482009-09-30 16:55:271267 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121268 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291269}
1270
1271void RenderView::OnSelectAll() {
1272 if (!webview())
1273 return;
1274
[email protected]26aa0482009-09-30 16:55:271275 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221276 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121277 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291278}
1279
1280void RenderView::OnSetInitialFocus(bool reverse) {
1281 if (!webview())
1282 return;
[email protected]26aa0482009-09-30 16:55:271283 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291284}
1285
1286///////////////////////////////////////////////////////////////////////////////
1287
[email protected]433819d2010-01-30 20:20:011288void RenderView::SetContentSettings(const ContentSettings& settings) {
1289 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011290}
1291
initial.commit09911bf2008-07-26 23:55:291292// Tell the embedding application that the URL of the active page has changed
1293void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451294 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291295 DCHECK(ds);
1296
[email protected]726985e22009-06-18 21:09:281297 const WebURLRequest& request = ds->request();
1298 const WebURLRequest& original_request = ds->originalRequest();
1299 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291300
[email protected]daa8c58e2009-06-15 17:21:101301 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1302 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291303
1304 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281305 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291306 params.is_post = false;
1307 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281308 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091309 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551310 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291311 // SSL state specified in the request takes precedence over the one in the
1312 // response.
1313 // So far this is only intended for error pages that are not expected to be
1314 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281315 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551316 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291317 } else {
[email protected]726985e22009-06-18 21:09:281318 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291319 }
1320
1321 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281322 if (ds->hasUnreachableURL()) {
1323 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291324 } else {
[email protected]726985e22009-06-18 21:09:281325 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291326 }
1327
[email protected]726985e22009-06-18 21:09:281328 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241329 params.should_update_history = !ds->hasUnreachableURL() &&
1330 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291331
[email protected]ce0e250d2009-10-23 21:00:351332 params.searchable_form_url = navigation_state->searchable_form_url();
1333 params.searchable_form_encoding =
1334 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291335
1336 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101337 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291338 if (password_form_data)
1339 params.password_form = *password_form_data;
1340
1341 params.gesture = navigation_gesture_;
1342 navigation_gesture_ = NavigationGestureUnknown;
1343
[email protected]dd7daa82009-08-10 05:46:451344 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291345 // Top-level navigation.
1346
[email protected]71b0d5d2010-02-15 05:43:071347 // Clear "block" flags for the new page. This needs to happen before any of
1348 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1349 // so that these functions can correctly detect that a piece of content
1350 // flipped from "not blocked" to "blocked".
1351 ClearBlockedContentSettings();
1352
[email protected]62d2a112010-04-07 00:53:021353 // Set content settings. Default them from the parent window if one exists.
1354 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011355 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541356 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011357 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011358 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011359
1360 // These content settings were merely recorded transiently for this load.
1361 // We can erase them now. If at some point we reload this page, the
1362 // browser will send us new, up-to-date content settings.
1363 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401364 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101365 // The opener's view is not guaranteed to be non-null (it could be
1366 // detached from its page but not yet destructed).
1367 if (WebView* opener_view = frame->opener()->view()) {
1368 RenderView* opener = FromWebView(opener_view);
1369 SetContentSettings(opener->current_content_settings_);
1370 }
[email protected]f85f0702010-01-30 09:31:011371 }
1372
[email protected]40bd6582009-12-04 23:49:511373 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011374 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541375 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011376 if (host_zoom != host_zoom_levels_.end()) {
1377 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511378 // This zoom level was merely recorded transiently for this load. We can
1379 // erase it now. If at some point we reload this page, the browser will
1380 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011381 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511382 }
1383
initial.commit09911bf2008-07-26 23:55:291384 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551385 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291386
[email protected]daa8c58e2009-06-15 17:21:101387 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291388 if (!PageTransition::IsMainFrame(params.transition)) {
1389 // If the main frame does a load, it should not be reported as a subframe
1390 // navigation. This can occur in the following case:
1391 // 1. You're on a site with frames.
1392 // 2. You do a subframe navigation. This is stored with transition type
1393 // MANUAL_SUBFRAME.
1394 // 3. You navigate to some non-frame site, say, google.com.
1395 // 4. You navigate back to the page from step 2. Since it was initially
1396 // MANUAL_SUBFRAME, it will be that same transition type here.
1397 // We don't want that, because any navigation that changes the toplevel
1398 // frame should be tracked as a toplevel navigation (this allows us to
1399 // update the URL bar, etc).
1400 params.transition = PageTransition::LINK;
1401 }
1402
initial.commit09911bf2008-07-26 23:55:291403 // If we have a valid consumed client redirect source,
1404 // the page contained a client redirect (meta refresh, document.loc...),
1405 // so we set the referrer and transition to match.
1406 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041407 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291408 params.referrer = completed_client_redirect_src_;
1409 params.transition = static_cast<PageTransition::Type>(
1410 params.transition | PageTransition::CLIENT_REDIRECT);
1411 } else {
1412 // Bug 654101: the referrer will be empty on https->http transitions. It
1413 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281414 params.referrer = GURL(
1415 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291416 }
1417
[email protected]726985e22009-06-18 21:09:281418 string16 method = request.httpMethod();
1419 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291420 params.is_post = true;
1421
[email protected]c2a797d2009-09-21 16:46:321422 // Save some histogram data so we can compute the average memory used per
1423 // page load of the glyphs.
1424 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1425 webkit_glue::GetGlyphPageCount());
1426
[email protected]15cf526b2010-02-12 06:33:491427 // This message needs to be sent before any of allowScripts(),
1428 // allowImages(), allowPlugins() is called for the new page, so that when
1429 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1430 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291431 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1432 } else {
1433 // Subframe navigation: the type depends on whether this navigation
1434 // generated a new session history entry. When they do generate a session
1435 // history entry, it means the user initiated the navigation and we should
1436 // mark it as such. This test checks if this is the first time UpdateURL
1437 // has been called since WillNavigateToURL was called to initiate the load.
1438 if (page_id_ > last_page_id_sent_to_browser_)
1439 params.transition = PageTransition::MANUAL_SUBFRAME;
1440 else
1441 params.transition = PageTransition::AUTO_SUBFRAME;
1442
initial.commit09911bf2008-07-26 23:55:291443 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1444 }
1445
1446 last_page_id_sent_to_browser_ =
1447 std::max(last_page_id_sent_to_browser_, page_id_);
1448
1449 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101450 // we don't want the transition type to persist. Just clear it.
1451 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501452
[email protected]af15bed2010-08-25 21:12:091453 // Check if the navigation was within the same page, in which case we don't
1454 // want to clear the accessibility cache.
1455 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]b3df5a42010-05-11 14:31:091456 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351457 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501458 }
initial.commit09911bf2008-07-26 23:55:291459}
1460
1461// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171462void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291463 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171464 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171465 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171466 routing_id_,
1467 page_id_,
1468 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1469 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171470 }
initial.commit09911bf2008-07-26 23:55:291471}
1472
1473void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401474 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291475 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271476 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291477 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301478 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291479 last_encoding_name_ = encoding_name;
1480
[email protected]e38f40152008-09-12 23:08:301481 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291482 }
1483}
1484
[email protected]f4d34b52008-11-24 23:05:011485// Sends the previous session history state to the browser so it will be saved
1486// before we navigate to a new page. This must be called *before* the page ID
1487// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291488void RenderView::UpdateSessionHistory(WebFrame* frame) {
1489 // If we have a valid page ID at this point, then it corresponds to the page
1490 // we are navigating away from. Otherwise, this is the first navigation, so
1491 // there is no past session history to record.
1492 if (page_id_ == -1)
1493 return;
1494
[email protected]ca948a22009-06-25 19:36:171495 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271496 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171497 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291498 return;
[email protected]ca948a22009-06-25 19:36:171499
1500 Send(new ViewHostMsg_UpdateState(
1501 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291502}
1503
[email protected]3d9689372009-09-10 04:29:171504void RenderView::OpenURL(
1505 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1506 Send(new ViewHostMsg_OpenURL(
1507 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1508}
1509
[email protected]79dbc662009-09-04 05:42:511510// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291511
initial.commit09911bf2008-07-26 23:55:291512void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281513 const WebURLRequest& failed_request,
1514 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291515 const std::string& html,
1516 bool replace) {
[email protected]726985e22009-06-18 21:09:281517 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291518
1519 std::string alt_html;
1520 if (html.empty()) {
1521 // Use a local error page.
1522 int resource_id;
1523 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281524 if (error.reason == net::ERR_CACHE_MISS &&
1525 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291526 GetFormRepostErrorValues(failed_url, &error_strings);
1527 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1528 } else {
1529 GetLocalizedErrorValues(error, &error_strings);
1530 resource_id = IDR_NET_ERROR_HTML;
1531 }
initial.commit09911bf2008-07-26 23:55:291532
1533 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1534 } else {
1535 alt_html = html;
1536 }
1537
[email protected]dd7daa82009-08-10 05:46:451538 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551539 GURL(kUnreachableWebDataURL),
1540 failed_url,
1541 replace);
initial.commit09911bf2008-07-26 23:55:291542}
1543
[email protected]7ccddb8c2009-08-04 17:36:551544void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291545 dom_automation_controller_.set_message_sender(this);
1546 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551547 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291548 L"domAutomationController");
1549}
1550
initial.commit09911bf2008-07-26 23:55:291551bool RenderView::RunJavaScriptMessage(int type,
1552 const std::wstring& message,
1553 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071554 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291555 std::wstring* result) {
1556 bool success = false;
1557 std::wstring result_temp;
1558 if (!result)
1559 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291560
[email protected]12636df2009-09-28 22:32:211561 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1562 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291563 return success;
1564}
1565
[email protected]c1f50aa2010-02-18 03:46:571566bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1567 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1568 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1569 // it is particularly important that we do not call willEnterModalLoop as
1570 // that would defer resource loads for the dialog itself.
1571 if (RenderThread::current()) // Will be NULL during unit tests.
1572 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1573
1574 message->EnableMessagePumping(); // Runs a nested message loop.
1575 return Send(message);
1576}
1577
initial.commit09911bf2008-07-26 23:55:291578void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1579 if (!osd_url.is_empty())
1580 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1581 autodetected));
1582}
1583
[email protected]95056b582010-02-18 01:29:241584void RenderView::OnAutoFillSuggestionsReturned(
1585 int query_id,
[email protected]8f6e6582010-04-09 02:03:071586 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391587 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411588 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391589 const std::vector<int>& unique_ids) {
[email protected]a53e06832010-07-28 22:46:411590 autofill_helper_.SuggestionsReceived(
1591 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031592}
1593
[email protected]45c6e532010-03-15 23:51:241594void RenderView::OnAutoFillFormDataFilled(int query_id,
1595 const webkit_glue::FormData& form) {
[email protected]679f128f2010-07-22 22:57:441596 autofill_helper_.FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481597}
1598
[email protected]e8345242010-05-06 03:00:401599void RenderView::OnAllowScriptToClose(bool script_can_close) {
1600 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311601}
1602
initial.commit09911bf2008-07-26 23:55:291603uint32 RenderView::GetCPBrowsingContext() {
1604 uint32 context = 0;
1605 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1606 return context;
1607}
1608
initial.commit09911bf2008-07-26 23:55:291609void RenderView::AddSearchProvider(const std::string& url) {
1610 AddGURLSearchProvider(GURL(url),
1611 false); // not autodetected
1612}
1613
[email protected]155f35e2010-07-17 00:30:181614ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251615RenderView::GetSearchProviderInstallState(WebFrame* frame,
1616 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181617 GURL inquiry_url = GURL(url);
1618 if (inquiry_url.is_empty())
1619 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251620
[email protected]155f35e2010-07-17 00:30:181621 ViewHostMsg_GetSearchProviderInstallState_Params install;
1622 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:251623 frame->url(),
[email protected]155f35e2010-07-17 00:30:181624 inquiry_url,
1625 &install));
1626 return install;
1627}
1628
[email protected]f103ab72009-09-02 17:10:591629void RenderView::OnMissingPluginStatus(
1630 WebPluginDelegateProxy* delegate,
1631 int status) {
[email protected]6c8afae52009-01-22 02:24:571632#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591633 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291634 // Show the InfoBar for the first available plugin.
1635 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591636 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291637 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1638 }
1639 } else {
1640 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1641 // to start the download/install.
1642 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1643 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1644 }
1645 }
[email protected]6c8afae52009-01-22 02:24:571646#else
[email protected]76c3b312010-05-20 21:38:291647 // TODO(port): Implement the infobar that accompanies the default plugin.
1648 // Linux: http://crbug.com/10952
1649 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571650 NOTIMPLEMENTED();
1651#endif
initial.commit09911bf2008-07-26 23:55:291652}
1653
[email protected]48c9cf2d2009-09-16 16:47:521654// WebKit::WebViewClient ------------------------------------------------------
1655
[email protected]8ab04652010-06-12 02:47:261656WebView* RenderView::createView(
1657 WebFrame* creator,
1658 const WebWindowFeatures& features,
1659 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521660 // Check to make sure we aren't overloading on popups.
1661 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1662 return NULL;
1663
1664 // This window can't be closed from a window.close() call until we receive a
1665 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401666 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521667
[email protected]8ab04652010-06-12 02:47:261668 ViewHostMsg_CreateWindow_Params params;
1669 params.opener_id = routing_id_;
1670 params.user_gesture = creator->isProcessingUserGesture();
1671 params.window_container_type = WindowFeaturesToContainerType(features);
1672 params.session_storage_namespace_id = session_storage_namespace_id_;
1673 params.frame_name = frame_name;
1674
[email protected]48c9cf2d2009-09-16 16:47:521675 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341676 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261677 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521678
[email protected]48c9cf2d2009-09-16 16:47:521679 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261680 new ViewHostMsg_CreateWindow(params,
1681 &routing_id,
1682 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211683 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521684 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521685
[email protected]48c9cf2d2009-09-16 16:47:521686 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421687 0,
[email protected]12636df2009-09-28 22:32:211688 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521689 renderer_preferences_,
1690 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211691 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341692 routing_id,
[email protected]8ab04652010-06-12 02:47:261693 cloned_session_storage_namespace_id,
1694 frame_name);
1695 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521696
[email protected]007a848b2009-10-26 15:55:461697 // Record whether the creator frame is trying to suppress the opener field.
1698 view->opener_suppressed_ = opener_suppressed;
1699
[email protected]48c9cf2d2009-09-16 16:47:521700 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091701 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521702 if (!creator_url.is_valid() || !creator_url.IsStandard())
1703 creator_url = GURL();
1704 view->creator_url_ = creator_url;
1705
1706 // Copy over the alternate error page URL so we can have alt error pages in
1707 // the new render view (we don't need the browser to send the URL back down).
1708 view->alternate_error_page_url_ = alternate_error_page_url_;
1709
1710 return view->webview();
1711}
1712
[email protected]3e2b375b2010-04-07 17:03:121713WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521714 RenderWidget* widget = RenderWidget::Create(routing_id_,
1715 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121716 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521717 return widget->webwidget();
1718}
1719
1720WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1721 RenderWidget* widget = RenderWidget::Create(routing_id_,
1722 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121723 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521724 widget->ConfigureAsExternalPopupMenu(info);
1725 return widget->webwidget();
1726}
1727
[email protected]484955942010-08-19 16:13:181728WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
1729 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
1730 render_thread_,
1731 popup_type);
1732 return widget->webwidget();
1733}
1734
[email protected]68c50e52010-05-12 11:14:391735WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341736 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391737 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291738 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1739 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1740 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341741}
1742
[email protected]48c9cf2d2009-09-16 16:47:521743void RenderView::didAddMessageToConsole(
1744 const WebConsoleMessage& message, const WebString& source_name,
1745 unsigned source_line) {
1746 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1747 UTF16ToWideHack(message.text),
1748 static_cast<int32>(source_line),
1749 UTF16ToWideHack(source_name)));
1750}
1751
1752void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581753 DCHECK(frame);
1754 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521755}
1756
[email protected]3354d3e2010-06-10 19:53:021757WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1758 return notification_provider_.get();
1759}
1760
[email protected]48c9cf2d2009-09-16 16:47:521761void RenderView::didStartLoading() {
1762 if (is_loading_) {
1763 DLOG(WARNING) << "didStartLoading called while loading";
1764 return;
1765 }
1766
1767 is_loading_ = true;
1768 // Clear the pointer so that we can assign it only when there is an unknown
1769 // plugin on a page.
1770 first_default_plugin_.reset();
1771
1772 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1773}
1774
1775void RenderView::didStopLoading() {
1776 if (!is_loading_) {
1777 DLOG(WARNING) << "DidStopLoading called while not loading";
1778 return;
1779 }
1780
1781 is_loading_ = false;
1782
1783 // NOTE: For now we're doing the safest thing, and sending out notification
1784 // when done loading. This currently isn't an issue as the favicon is only
1785 // displayed when done loading. Ideally we would send notification when
1786 // finished parsing the head, but webkit doesn't support that yet.
1787 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271788 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521789 if (!favicon_url.is_empty())
1790 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1791
[email protected]26aa0482009-09-30 16:55:271792 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521793 true); // autodetected
1794
1795 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1796
[email protected]f9f4841b2010-03-20 05:41:421797 MessageLoop::current()->PostDelayedTask(
1798 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:301799 page_info_method_factory_.NewRunnableMethod(
1800 &RenderView::CapturePageInfo, page_id_, false),
[email protected]48c9cf2d2009-09-16 16:47:521801 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521802}
1803
[email protected]f55039a2010-02-17 14:12:061804bool RenderView::isSmartInsertDeleteEnabled() {
1805#if defined(OS_MACOSX)
1806 return true;
1807#else
1808 return false;
1809#endif
1810}
1811
[email protected]04fc9482009-09-18 22:13:031812bool RenderView::isSelectTrailingWhitespaceEnabled() {
1813#if defined(OS_WIN)
1814 return true;
1815#else
1816 return false;
1817#endif
1818}
1819
[email protected]04fc9482009-09-18 22:13:031820void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]eef99c22010-08-17 05:55:161821#if defined(USE_X11) || defined(OS_MACOSX)
[email protected]04fc9482009-09-18 22:13:031822 if (!handling_input_event_)
1823 return;
1824 // TODO(estade): investigate incremental updates to the selection so that we
1825 // don't send the entire selection over IPC every time.
1826 if (!is_empty_selection) {
1827 // Sometimes we get repeated didChangeSelection calls from webkit when
1828 // the selection hasn't actually changed. We don't want to report these
1829 // because it will cause us to continually claim the X clipboard.
1830 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271831 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031832 if (this_selection == last_selection_)
1833 return;
1834
1835 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1836 this_selection));
1837 last_selection_ = this_selection;
1838 } else {
1839 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:161840 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1841 last_selection_));
[email protected]04fc9482009-09-18 22:13:031842 }
1843#endif
1844}
1845
1846void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121847 const std::string& name = UTF16ToUTF8(command_name);
1848 if (StartsWithASCII(name, "Move", true) ||
1849 StartsWithASCII(name, "Insert", true) ||
1850 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031851 return;
1852 UserMetricsRecordAction(name);
1853}
1854
[email protected]03f57072010-07-14 17:36:081855void RenderView::textFieldDidEndEditing(
1856 const WebKit::WebInputElement& element) {
1857#if defined(WEBKIT_BUG_41283_IS_FIXED)
1858 password_autocomplete_manager_.TextFieldDidEndEditing(element);
1859#endif
1860}
1861
1862void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1863#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]e47aec52010-08-12 00:50:301864 // We post a task for doing the AutoFill as the caret position is not set
1865 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
1866 // it is needed to trigger autofill.
1867 autofill_method_factory_.RevokeAll();
1868 MessageLoop::current()->PostTask(
1869 FROM_HERE,
1870 autofill_method_factory_.NewRunnableMethod(
1871 &RenderView::TextFieldDidChangeImpl, element));
[email protected]03f57072010-07-14 17:36:081872#endif
1873}
1874
[email protected]e47aec52010-08-12 00:50:301875void RenderView::TextFieldDidChangeImpl(
1876 const WebKit::WebInputElement& element) {
1877 if (password_autocomplete_manager_.TextDidChangeInTextField(element))
1878 return;
1879 autofill_helper_.TextDidChangeInTextField(element);
1880}
1881
[email protected]03f57072010-07-14 17:36:081882void RenderView::textFieldDidReceiveKeyDown(
1883 const WebKit::WebInputElement& element,
1884 const WebKit::WebKeyboardEvent& event) {
1885#if defined(WEBKIT_BUG_41283_IS_FIXED)
1886 password_autocomplete_manager_.TextFieldHandlingKeyDown(element, event);
1887#endif
1888}
1889
[email protected]b2528b72009-09-24 06:57:101890bool RenderView::handleCurrentKeyboardEvent() {
1891 if (edit_commands_.empty())
1892 return false;
1893
[email protected]26aa0482009-09-30 16:55:271894 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101895 if (!frame)
1896 return false;
1897
1898 EditCommands::iterator it = edit_commands_.begin();
1899 EditCommands::iterator end = edit_commands_.end();
1900
[email protected]507b33ea2009-09-29 03:56:511901 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101902 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331903 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1904 // key (but it's the exception). Once one edit command is not executed, it
1905 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101906 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1907 WebString::fromUTF8(it->value)))
1908 break;
[email protected]507b33ea2009-09-29 03:56:511909 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101910 }
1911
[email protected]507b33ea2009-09-29 03:56:511912 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101913}
1914
[email protected]e47aec52010-08-12 00:50:301915void RenderView::inputElementClicked(const WebKit::WebInputElement& element,
1916 bool already_focused) {
1917#if defined(WEBKIT_BUG_41283_IS_FIXED)
1918 if (password_autocomplete_manager_.InputElementClicked(element,
1919 already_focused)) {
1920 return;
1921 }
1922 autofill_helper_.InputElementClicked(element, already_focused);
1923#endif
1924}
1925
[email protected]2a3a7762009-10-19 19:17:321926void RenderView::spellCheck(const WebString& text,
1927 int& misspelled_offset,
1928 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561929 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461930
[email protected]85c55dc2009-11-06 03:05:461931 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171932 RenderThread* thread = RenderThread::current();
1933 // Will be NULL during unit tests.
1934 if (thread) {
[email protected]c27324b2009-11-19 22:44:291935 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171936 word.c_str(), word.size(), document_tag_,
1937 &misspelled_offset, &misspelled_length, NULL);
1938 }
[email protected]1dbafaf72009-09-23 19:43:561939}
1940
1941WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321942 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561943 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261944 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561945 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171946 RenderThread* thread = RenderThread::current();
1947 // Will be NULL during unit tests.
1948 if (thread) {
1949 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291950 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171951 word, document_tag_);
1952 }
[email protected]1dbafaf72009-09-23 19:43:561953 }
[email protected]2a3a7762009-10-19 19:17:321954 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561955}
1956
[email protected]c49085c72009-10-02 16:28:561957void RenderView::showSpellingUI(bool show) {
1958 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1959}
1960
[email protected]8922e1f2009-10-03 05:01:261961bool RenderView::isShowingSpellingUI() {
1962 return spelling_panel_visible_;
1963}
1964
[email protected]1dbafaf72009-09-23 19:43:561965void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321966 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1967 word));
[email protected]1dbafaf72009-09-23 19:43:561968}
1969
[email protected]a1128322009-10-06 18:38:461970bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351971 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471972 WebFileChooserCompletion* chooser_completion) {
1973 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261974 if (params.directory)
1975 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
1976 else if (params.multiSelect)
1977 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
1978 else
1979 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:471980 ipc_params.title = params.title;
1981 ipc_params.default_file_name =
1982 webkit_glue::WebStringToFilePath(params.initialValue);
1983
1984 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461985}
1986
[email protected]48c9cf2d2009-09-16 16:47:521987void RenderView::runModalAlertDialog(
1988 WebFrame* frame, const WebString& message) {
1989 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1990 UTF16ToWideHack(message),
1991 std::wstring(),
1992 frame->url(),
1993 NULL);
1994}
1995
1996bool RenderView::runModalConfirmDialog(
1997 WebFrame* frame, const WebString& message) {
1998 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1999 UTF16ToWideHack(message),
2000 std::wstring(),
2001 frame->url(),
2002 NULL);
2003}
2004
2005bool RenderView::runModalPromptDialog(
2006 WebFrame* frame, const WebString& message, const WebString& default_value,
2007 WebString* actual_value) {
2008 std::wstring result;
2009 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
2010 UTF16ToWideHack(message),
2011 UTF16ToWideHack(default_value),
2012 frame->url(),
2013 &result);
2014 if (ok)
2015 actual_value->assign(WideToUTF16Hack(result));
2016 return ok;
2017}
2018
2019bool RenderView::runModalBeforeUnloadDialog(
2020 WebFrame* frame, const WebString& message) {
2021 bool success = false;
2022 // This is an ignored return value, but is included so we can accept the same
2023 // response as RunJavaScriptMessage.
2024 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212025 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522026 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212027 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522028 return success;
2029}
2030
[email protected]79e37442009-10-09 18:17:442031void RenderView::showContextMenu(
2032 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292033 ContextMenuParams params = ContextMenuParams(data);
2034 if (!params.misspelled_word.empty() && RenderThread::current()) {
2035 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042036 bool spelled_right = RenderThread::current()->spellchecker()->
2037 SpellCheckWord(
2038 params.misspelled_word.c_str(), params.misspelled_word.size(),
2039 document_tag_,
2040 &misspelled_offset, &misspelled_length,
2041 &params.dictionary_suggestions);
2042 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292043 params.misspelled_word.clear();
2044 }
2045
2046 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442047}
2048
[email protected]52f139e2c2010-06-11 16:56:092049bool RenderView::supportsFullscreen() {
2050 return CommandLine::ForCurrentProcess()->HasSwitch(
2051 switches::kEnableVideoFullscreen);
2052}
2053
2054void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2055 NOTIMPLEMENTED();
2056}
2057
2058void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2059 NOTIMPLEMENTED();
2060}
2061
[email protected]48c9cf2d2009-09-16 16:47:522062void RenderView::setStatusText(const WebString& text) {
2063}
2064
[email protected]163f8242009-10-30 20:19:552065void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582066 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522067 if (latest_url == target_url_)
2068 return;
[email protected]163f8242009-10-30 20:19:552069
[email protected]48c9cf2d2009-09-16 16:47:522070 // Tell the browser to display a destination link.
2071 if (target_url_status_ == TARGET_INFLIGHT ||
2072 target_url_status_ == TARGET_PENDING) {
2073 // If we have a request in-flight, save the URL to be sent when we
2074 // receive an ACK to the in-flight request. We can happily overwrite
2075 // any existing pending sends.
2076 pending_target_url_ = latest_url;
2077 target_url_status_ = TARGET_PENDING;
2078 } else {
2079 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2080 target_url_ = latest_url;
2081 target_url_status_ = TARGET_INFLIGHT;
2082 }
2083}
2084
[email protected]1c57b7b2010-07-12 17:38:102085bool RenderView::IsPageTranslatable(WebKit::WebDocument* document) {
2086 std::vector<WebKit::WebElement> meta_elements;
2087 webkit_glue::GetMetaElementsWithName(document, ASCIIToUTF16("google"),
2088 &meta_elements);
2089 std::vector<WebKit::WebElement>::const_iterator iter;
2090 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) {
2091 WebString attribute = iter->getAttribute("value");
2092 if (attribute.isNull()) // We support both 'value' and 'content'.
2093 attribute = iter->getAttribute("content");
2094 if (attribute.isNull())
2095 continue;
2096 if (LowerCaseEqualsASCII(attribute, "notranslate"))
2097 return false;
2098 }
2099 return true;
2100}
2101
[email protected]882daa92009-11-05 16:31:312102void RenderView::StartNavStateSyncTimerIfNecessary() {
2103 int delay;
2104 if (send_content_state_immediately_)
2105 delay = 0;
2106 else if (is_hidden())
2107 delay = kDelaySecondsForContentStateSyncHidden;
2108 else
2109 delay = kDelaySecondsForContentStateSync;
2110
2111 if (nav_state_sync_timer_.IsRunning()) {
2112 // The timer is already running. If the delay of the timer maches the amount
2113 // we want to delay by, then return. Otherwise stop the timer so that it
2114 // gets started with the right delay.
2115 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2116 return;
2117 nav_state_sync_timer_.Stop();
2118 }
2119
2120 nav_state_sync_timer_.Start(
2121 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2122}
2123
[email protected]163f8242009-10-30 20:19:552124void RenderView::setMouseOverURL(const WebURL& url) {
2125 mouse_over_url_ = GURL(url);
2126 UpdateTargetURL(mouse_over_url_, focus_url_);
2127}
2128
2129void RenderView::setKeyboardFocusURL(const WebURL& url) {
2130 focus_url_ = GURL(url);
2131 UpdateTargetURL(focus_url_, mouse_over_url_);
2132}
2133
[email protected]48c9cf2d2009-09-16 16:47:522134void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2135 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2136 hint));
2137}
2138
[email protected]c27ae592010-03-18 15:24:412139void RenderView::startDragging(const WebDragData& data,
2140 WebDragOperationsMask mask,
2141 const WebImage& image,
2142 const WebPoint& imageOffset) {
2143#if WEBKIT_USING_SKIA
2144 SkBitmap bitmap(image.getSkBitmap());
2145#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332146 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412147#endif
2148
[email protected]48c9cf2d2009-09-16 16:47:522149 Send(new ViewHostMsg_StartDragging(routing_id_,
2150 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412151 mask,
2152 bitmap,
2153 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522154}
2155
[email protected]28b92df2009-09-25 17:35:452156bool RenderView::acceptsLoadDrops() {
2157 return renderer_preferences_.can_accept_load_drops;
2158}
2159
[email protected]48c9cf2d2009-09-16 16:47:522160void RenderView::focusNext() {
2161 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2162}
2163
2164void RenderView::focusPrevious() {
2165 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2166}
2167
[email protected]08e9e132010-06-01 16:58:492168void RenderView::focusedNodeChanged(const WebNode& node) {
2169 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2170}
2171
[email protected]48c9cf2d2009-09-16 16:47:522172void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522173 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2174}
2175
2176int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002177 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522178}
2179
2180int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002181 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522182}
2183
[email protected]c4e98902010-06-01 10:20:142184void RenderView::didUpdateInspectorSetting(const WebString& key,
2185 const WebString& value) {
2186 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2187 key.utf8(),
2188 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262189}
2190
[email protected]acca2a12009-10-16 03:53:392191void RenderView::queryAutofillSuggestions(const WebNode& node,
2192 const WebString& name,
2193 const WebString& value) {
[email protected]e47aec52010-08-12 00:50:302194 autofill_helper_.QueryAutoFillSuggestions(node, name, value);
[email protected]acca2a12009-10-16 03:53:392195}
2196
2197void RenderView::removeAutofillSuggestions(const WebString& name,
2198 const WebString& value) {
[email protected]679f128f2010-07-22 22:57:442199 autofill_helper_.RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a12009-10-16 03:53:392200}
2201
[email protected]18ca9a6b2010-06-02 19:05:182202void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2203 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202204 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392205 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202206 unsigned index) {
[email protected]679f128f2010-07-22 22:57:442207 autofill_helper_.DidAcceptAutoFillSuggestion(node, value, label, unique_id,
2208 index);
[email protected]18ca9a6b2010-06-02 19:05:182209}
[email protected]c83641732010-02-20 01:04:482210
[email protected]18ca9a6b2010-06-02 19:05:182211void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2212 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392213 const WebKit::WebString& label,
2214 int unique_id) {
[email protected]679f128f2010-07-22 22:57:442215 autofill_helper_.DidSelectAutoFillSuggestion(node, value, label, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182216}
2217
2218void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]679f128f2010-07-22 22:57:442219 autofill_helper_.DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482220}
2221
[email protected]03f57072010-07-14 17:36:082222void RenderView::didAcceptAutocompleteSuggestion(
2223 const WebKit::WebInputElement& user_element) {
2224#if defined(WEBKIT_BUG_41283_IS_FIXED)
2225 bool result = password_autocomplete_manager_.FillPassword(user_element);
2226 // Since this user name was selected from a suggestion list, we should always
2227 // have password for it.
2228 DCHECK(result);
2229#endif
2230}
2231
[email protected]79dbc662009-09-04 05:42:512232// WebKit::WebWidgetClient ----------------------------------------------------
2233
[email protected]ea42e7782010-08-23 23:58:122234void RenderView::didFocus() {
2235 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2236 // we won't have to test for user gesture anymore and we can
2237 // move that code back to render_widget.cc
2238 if (webview() && webview()->mainFrame() &&
2239 webview()->mainFrame()->isProcessingUserGesture()) {
2240 Send(new ViewHostMsg_Focus(routing_id_));
2241 }
2242}
2243
2244void RenderView::didBlur() {
2245 // TODO(jcivelli): see TODO above in didFocus().
2246 if (webview() && webview()->mainFrame() &&
2247 webview()->mainFrame()->isProcessingUserGesture()) {
2248 Send(new ViewHostMsg_Blur(routing_id_));
2249 }
2250}
2251
initial.commit09911bf2008-07-26 23:55:292252// We are supposed to get a single call to Show for a newly created RenderView
2253// that was created via RenderView::CreateWebView. So, we wait until this
2254// point to dispatch the ShowView message.
2255//
2256// This method provides us with the information about how to display the newly
2257// created RenderView (i.e., as a constrained popup or as a new tab).
2258//
[email protected]4873c7d2009-07-16 06:36:282259void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292260 DCHECK(!did_show_) << "received extraneous Show call";
2261 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2262
2263 if (did_show_)
2264 return;
2265 did_show_ = true;
2266
[email protected]28295ec2009-10-16 05:34:332267 // Force new windows to a popup if they were not opened with a user gesture.
2268 if (!opened_by_user_gesture_) {
2269 // We exempt background tabs for compat with older versions of Chrome.
2270 // TODO(darin): This seems bogus. These should have a user gesture, so
2271 // we probably don't need this check.
2272 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2273 policy = WebKit::WebNavigationPolicyNewPopup;
2274 }
2275
initial.commit09911bf2008-07-26 23:55:292276 // NOTE: initial_pos_ may still have its default values at this point, but
2277 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2278 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282279 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2280 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292281 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242282 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292283}
2284
[email protected]4873c7d2009-07-16 06:36:282285void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132286 // Cancel pending translations so that the translate_helper_ does not attempt
2287 // to access the WebView.
2288 translate_helper_.CancelPendingTranslation();
2289
[email protected]e8345242010-05-06 03:00:402290 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282291 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312292}
2293
[email protected]4873c7d2009-07-16 06:36:282294void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292295 DCHECK(did_show_) << "should already have shown the view";
2296
[email protected]c1f50aa2010-02-18 03:46:572297 // We must keep WebKit's shared timer running in this case in order to allow
2298 // showModalDialog to function properly.
2299 //
2300 // TODO(darin): WebKit should really be smarter about suppressing events and
2301 // timers so that we do not need to manage the shared timer in such a heavy
2302 // handed manner.
2303 //
2304 if (RenderThread::current()) // Will be NULL during unit tests.
2305 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2306
[email protected]12636df2009-09-28 22:32:212307 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292308}
2309
[email protected]3d9689372009-09-10 04:29:172310// WebKit::WebFrameClient -----------------------------------------------------
2311
[email protected]00152e92010-07-19 11:47:402312WebPlugin* RenderView::createPlugin(WebFrame* frame,
2313 const WebPluginParams& params) {
[email protected]7a13e792010-08-03 08:18:242314 bool found = false;
[email protected]55126132010-08-19 14:53:282315 ContentSetting setting = CONTENT_SETTING_DEFAULT;
2316 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]7a13e792010-08-03 08:18:242317 WebPluginInfo info;
2318 GURL url(params.url);
[email protected]0cdafff2010-07-26 09:54:372319 std::string actual_mime_type;
[email protected]7a13e792010-08-03 08:18:242320 Send(new ViewHostMsg_GetPluginInfo(url,
2321 frame->top()->url(),
[email protected]aad51d1c2010-08-05 08:38:092322 params.mimeType.utf8(),
[email protected]7a13e792010-08-03 08:18:242323 &found,
2324 &info,
[email protected]55126132010-08-19 14:53:282325 &setting,
[email protected]aad51d1c2010-08-05 08:38:092326 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242327
[email protected]851b1eb2010-08-09 13:32:292328 if (!found)
[email protected]0cdafff2010-07-26 09:54:372329 return NULL;
[email protected]4e0616e2010-05-28 14:55:532330
[email protected]851b1eb2010-08-09 13:32:292331 scoped_ptr<PluginGroup> group(PluginGroup::FindHardcodedPluginGroup(info));
2332 group->AddPlugin(info, 0);
2333
2334 if (!info.enabled) {
[email protected]55126132010-08-19 14:53:282335 if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) &&
[email protected]851b1eb2010-08-09 13:32:292336 group->IsVulnerable()) {
2337 Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_,
2338 group->GetGroupName(),
2339 GURL(group->GetUpdateURL())));
2340 return CreatePluginPlaceholder(frame, params, group.get());
2341 }
2342 return NULL;
2343 }
2344
[email protected]aad51d1c2010-08-05 08:38:092345 if (info.path.value() != kDefaultPluginLibraryName) {
[email protected]55126132010-08-19 14:53:282346 std::string resource;
2347 if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) {
2348#if defined(OS_POSIX)
2349 resource = info.path.value();
2350#elif defined(OS_WIN)
2351 resource = base::SysWideToUTF8(info.path.value());
2352#endif
2353 }
2354 if (setting == CONTENT_SETTING_BLOCK) {
2355 DCHECK(cmd->HasSwitch(switches::kEnableClickToPlay));
2356 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]851b1eb2010-08-09 13:32:292357 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092358 }
2359 scoped_refptr<pepper::PluginModule> pepper_module =
2360 PepperPluginRegistry::GetInstance()->GetModule(info.path);
2361 if (pepper_module)
2362 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
2363 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]55126132010-08-19 14:53:282364 switches::kBlockNonSandboxedPlugins) &&
2365 setting != CONTENT_SETTING_ALLOW) {
[email protected]851b1eb2010-08-09 13:32:292366 Send(new ViewHostMsg_NonSandboxedPluginBlocked(routing_id_,
[email protected]55126132010-08-19 14:53:282367 resource,
[email protected]851b1eb2010-08-09 13:32:292368 group->GetGroupName()));
2369 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092370 }
[email protected]0cdafff2010-07-26 09:54:372371 }
[email protected]aad51d1c2010-08-05 08:38:092372 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]3d9689372009-09-10 04:29:172373}
2374
2375WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562376 WebApplicationCacheHostImpl* appcache_host =
2377 WebApplicationCacheHostImpl::FromFrame(frame);
2378 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2379 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2380 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172381}
2382
[email protected]9c00f002009-11-05 22:37:422383WebSharedWorker* RenderView::createSharedWorker(
2384 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372385 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422386
[email protected]30447b62009-11-13 01:13:372387 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512388 bool exists = false;
[email protected]30447b62009-11-13 01:13:372389 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512390 ViewHostMsg_CreateWorker_Params params;
2391 params.url = url;
2392 params.is_shared = true;
2393 params.name = name;
2394 params.document_id = document_id;
2395 params.render_view_route_id = routing_id_;
2396 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232397 params.parent_appcache_host_id = 0;
2398 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372399 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512400 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372401 if (url_mismatch) {
2402 return NULL;
2403 } else {
2404 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492405 document_id,
[email protected]6de0bcf2010-02-17 22:00:512406 exists,
[email protected]30447b62009-11-13 01:13:372407 route_id,
2408 routing_id_);
2409 }
[email protected]9c00f002009-11-05 22:37:422410}
2411
[email protected]3d9689372009-09-10 04:29:172412WebMediaPlayer* RenderView::createMediaPlayer(
2413 WebFrame* frame, WebMediaPlayerClient* client) {
2414 scoped_refptr<media::FilterFactoryCollection> factory =
2415 new media::FilterFactoryCollection();
2416 // Add in any custom filter factories first.
2417 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2418 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2419 // Add the chrome specific audio renderer.
2420 factory->AddFactory(
2421 AudioRendererImpl::CreateFactory(audio_message_filter()));
2422 }
2423
[email protected]ee68378a2010-08-10 01:05:412424 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
2425 cmd_line->HasSwitch(switches::kEnableAcceleratedCompositing)) {
2426 // Add the hardware video decoder factory.
2427 factory->AddFactory(
2428 media::IpcVideoDecoder::CreateFactory(MessageLoop::current()));
2429 }
2430
[email protected]80f584d92010-01-21 03:59:042431 WebApplicationCacheHostImpl* appcache_host =
2432 WebApplicationCacheHostImpl::FromFrame(frame);
2433
[email protected]3d9689372009-09-10 04:29:172434 // TODO(hclam): obtain the following parameters from |client|.
2435 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2436 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152437 GURL(), // referrer
2438 "null", // frame origin
2439 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172440 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042441 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172442 routing_id());
2443
[email protected]0436b9a2009-10-23 00:23:052444 // A simple data source that keeps all data in memory.
2445 media::FilterFactory* simple_data_source_factory =
2446 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2447 bridge_factory);
2448 // A sophisticated data source that does memory caching.
2449 media::FilterFactory* buffered_data_source_factory =
2450 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2451 bridge_factory);
2452 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2453 factory->AddFactory(simple_data_source_factory);
2454 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172455 } else {
[email protected]0436b9a2009-10-23 00:23:052456 factory->AddFactory(buffered_data_source_factory);
2457 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172458 }
[email protected]8400e032010-02-26 18:50:112459
2460 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2461 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2462 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2463 } else {
[email protected]b57509eb2010-03-30 01:26:282464 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2465 factory_factory =
2466 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112467 }
2468
2469 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172470}
2471
[email protected]035545f2010-04-09 13:10:212472WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2473 WebFrame* frame, WebApplicationCacheHostClient* client) {
2474 return new RendererWebApplicationCacheHostImpl(
2475 FromWebView(frame->view()), client,
2476 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2477}
2478
[email protected]b921cfd22010-02-25 16:57:512479WebCookieJar* RenderView::cookieJar() {
2480 return &cookie_jar_;
2481}
2482
[email protected]5041f982010-08-11 21:40:452483void RenderView::frameDetached(WebFrame* frame) {
2484 autofill_helper_.FrameDetached(frame);
2485}
2486
[email protected]3d9689372009-09-10 04:29:172487void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302488 WebDataSource* ds = frame->dataSource();
2489 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522490
2491 if (!frame->parent()) {
2492 const GURL& url = frame->url();
2493 // Ensure state contains scheme.
2494 if (url.SchemeIs("http"))
2495 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
2496 else if (url.SchemeIs("https"))
2497 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
2498
2499 // Dump will only be provided when scheme is http or https.
2500 DumpLoadHistograms();
2501 }
2502
[email protected]fa7b6b542009-11-03 05:02:302503 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162504
[email protected]5041f982010-08-11 21:40:452505 // TODO(jhawkins): Remove once frameDetached is called by WebKit.
[email protected]679f128f2010-07-22 22:57:442506 autofill_helper_.FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172507}
2508
[email protected]684e4a42010-01-30 06:44:112509bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402510 if (enabled_per_settings &&
2511 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2512 return true;
2513
2514 if (IsWhitelistedForContentSettings(frame))
2515 return true;
2516
[email protected]55126132010-08-19 14:53:282517 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402518 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112519}
2520
[email protected]d5f9e4f2010-07-28 08:31:302521bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
2522 if (CommandLine::ForCurrentProcess()->HasSwitch(
2523 switches::kEnableClickToPlay)) {
2524 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
2525 }
2526 return (enabled_per_settings &&
2527 AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS));
2528}
2529
2530
[email protected]3d9689372009-09-10 04:29:172531void RenderView::loadURLExternally(
2532 WebFrame* frame, const WebURLRequest& request,
2533 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592534 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2535 if (policy == WebKit::WebNavigationPolicyDownload) {
2536 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2537 } else {
2538 OpenURL(request.url(), referrer, policy);
2539 }
[email protected]3d9689372009-09-10 04:29:172540}
2541
2542WebNavigationPolicy RenderView::decidePolicyForNavigation(
2543 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222544 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172545 // Webkit is asking whether to navigate to a new URL.
2546 // This is fine normally, except if we're showing UI from one security
2547 // context and they're trying to navigate to a different context.
2548 const GURL& url = request.url();
2549
2550 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302551 // navigations.
[email protected]8079b362010-05-07 18:37:452552 if (renderer_preferences_.browser_handles_top_level_requests &&
2553 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192554 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232555 // Reset these counters as the RenderView could be reused for the next
2556 // navigation.
2557 page_id_ = -1;
2558 next_page_id_ = 1;
2559 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192560 OpenURL(url, referrer, default_policy);
2561 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172562 }
2563
2564 // A content initiated navigation may have originated from a link-click,
2565 // script, drag-n-drop operation, etc.
2566 bool is_content_initiated =
2567 NavigationState::FromDataSource(frame->provisionalDataSource())->
2568 is_content_initiated();
2569
2570 // We only care about navigations that are within the current tab (as opposed
2571 // to, for example, opening a new window).
2572 // But we sometimes navigate to about:blank to clear a tab, and we want to
2573 // still allow that.
2574 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2575 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532576 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172577 !url.SchemeIs(chrome::kAboutScheme)) {
2578 // When we received such unsolicited navigations, we sometimes want to
2579 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302580 if (CrossesExtensionExtents(frame, url) ||
2581 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172582 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422583 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172584 OpenURL(url, GURL(), default_policy);
2585 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2586 }
[email protected]8079b362010-05-07 18:37:452587
2588 // We forward navigations from extensions to the browser if they are
2589 // top-level events, even if the browser hasn't expressed interest.
2590 //
2591 // Note that we've already forwarded cross-extension extents navigations
2592 // above.
2593 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]c240ace2010-06-16 18:31:532594 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]8079b362010-05-07 18:37:452595 OpenURL(url, GURL(), default_policy);
2596 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2597 }
[email protected]3d9689372009-09-10 04:29:172598 }
2599
2600 // Detect when a page is "forking" a new tab that can be safely rendered in
2601 // its own process. This is done by sites like Gmail that try to open links
2602 // in new windows without script connections back to the original page. We
2603 // treat such cases as browser navigations (in which we will create a new
2604 // renderer for a cross-site navigation), rather than WebKit navigations.
2605 //
2606 // We use the following heuristic to decide whether to fork a new page in its
2607 // own process:
2608 // The parent page must open a new tab to about:blank, set the new tab's
2609 // window.opener to null, and then redirect the tab to a cross-site URL using
2610 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462611 //
2612 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2613 // (see below).
[email protected]3d9689372009-09-10 04:29:172614 bool is_fork =
2615 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252616 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172617 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522618 historyBackListCount() < 1 &&
2619 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172620 // The parent page must have set the child's window.opener to null before
2621 // redirecting to the desired URL.
2622 frame->opener() == NULL &&
2623 // Must be a top-level frame.
2624 frame->parent() == NULL &&
2625 // Must not have issued the request from this page.
2626 is_content_initiated &&
2627 // Must be targeted at the current tab.
2628 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2629 // Must be a JavaScript navigation, which appears as "other".
2630 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462631
2632 // Recognize if this navigation is from a link with rel=noreferrer and
2633 // target=_blank attributes, in which case the opener will be suppressed. If
2634 // so, it is safe to load cross-site pages in a separate process, so we
2635 // should let the browser handle it.
2636 bool is_noreferrer_and_blank_target =
2637 // Frame should be top level and not yet navigated.
2638 frame->parent() == NULL &&
2639 frame->url().isEmpty() &&
2640 historyBackListCount() < 1 &&
2641 historyForwardListCount() < 1 &&
2642 // Links with rel=noreferrer will have no Referer field, and their
2643 // resulting frame will have its window.opener suppressed.
2644 // TODO(creis): should add a request.httpReferrer() method to help avoid
2645 // typos on the unusual spelling of Referer.
2646 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2647 opener_suppressed_ &&
2648 frame->opener() == NULL &&
2649 // Links with target=_blank will have no name.
2650 frame->name().isNull() &&
2651 // Another frame (with a non-empty creator) should have initiated the
2652 // request, targeted at this frame.
2653 !creator_url_.is_empty() &&
2654 is_content_initiated &&
2655 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2656 type == WebKit::WebNavigationTypeOther;
2657
2658 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172659 // Open the URL via the browser, not via WebKit.
2660 OpenURL(url, GURL(), default_policy);
2661 return WebKit::WebNavigationPolicyIgnore;
2662 }
2663
2664 return default_policy;
2665}
2666
[email protected]6069da8c2009-10-20 20:33:492667bool RenderView::canHandleRequest(
2668 WebFrame* frame, const WebURLRequest& request) {
2669 // We allow WebKit to think that everything can be handled even though
2670 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342671 return true;
2672}
2673
[email protected]6069da8c2009-10-20 20:33:492674WebURLError RenderView::cannotHandleRequestError(
2675 WebFrame* frame, const WebURLRequest& request) {
2676 NOTREACHED(); // Since we said we can handle all requests.
2677 return WebURLError();
2678}
2679
2680WebURLError RenderView::cancelledError(
2681 WebFrame* frame, const WebURLRequest& request) {
2682 WebURLError error;
2683 error.domain = WebString::fromUTF8(net::kErrorDomain);
2684 error.reason = net::ERR_ABORTED;
2685 error.unreachableURL = request.url();
2686 return error;
[email protected]7b7a7dc2009-10-19 02:23:342687}
2688
2689void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492690 WebFrame*, const WebURLError&) {
2691 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342692}
2693
[email protected]90eeddb2010-05-06 21:06:432694void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2695 const WebKit::WebFormElement& form) {
2696 // Some login forms have onSubmit handlers that put a hash of the password
2697 // into a hidden field and then clear the password. (Issue 28910.)
2698 // This method gets called before any of those handlers run, so save away
2699 // a copy of the password in case it gets lost.
2700 NavigationState* navigation_state =
2701 NavigationState::FromDataSource(frame->dataSource());
2702 navigation_state->set_password_form_data(
2703 PasswordFormDomManager::CreatePasswordForm(form));
2704}
2705
[email protected]979c28b2009-11-07 01:30:482706void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172707 NavigationState* navigation_state =
2708 NavigationState::FromDataSource(frame->provisionalDataSource());
2709
2710 if (navigation_state->transition_type() == PageTransition::LINK)
2711 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2712
2713 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352714 WebSearchableFormData web_searchable_form_data(form);
2715 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2716 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212717 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432718 PasswordForm* password_form_data =
2719 PasswordFormDomManager::CreatePasswordForm(form);
2720 navigation_state->set_password_form_data(password_form_data);
2721
2722 // If the password has been cleared, recover it from the form contents already
2723 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2724 // opposed to the provisionalDataSource's, which is what we're storing into
2725 // now.)
2726 if (password_form_data && password_form_data->password_value.empty()) {
2727 NavigationState* old_navigation_state =
2728 NavigationState::FromDataSource(frame->dataSource());
2729 if (old_navigation_state) {
2730 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2731 if (old_form_data && old_form_data->action == password_form_data->action)
2732 password_form_data->password_value = old_form_data->password_value;
2733 }
2734 }
[email protected]3d9689372009-09-10 04:29:172735
[email protected]b1438212010-04-03 00:30:592736 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042737 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092738 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592739 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172740}
2741
2742void RenderView::willPerformClientRedirect(
2743 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2744 double fire_time) {
2745 // Ignore
2746}
2747
2748void RenderView::didCancelClientRedirect(WebFrame* frame) {
2749 // Ignore
2750}
2751
2752void RenderView::didCompleteClientRedirect(
2753 WebFrame* frame, const WebURL& from) {
2754 if (!frame->parent())
2755 completed_client_redirect_src_ = from;
2756}
2757
2758void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2759 // The rest of RenderView assumes that a WebDataSource will always have a
2760 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482761 bool content_initiated = !pending_navigation_state_.get();
2762 NavigationState* state = content_initiated ?
2763 NavigationState::CreateContentInitiated() :
2764 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512765
[email protected]8a3125a712010-08-09 18:58:512766 // NavigationState::referred_by_prefetcher_ is true if we are
2767 // navigating from a page that used prefetching using a link on that
2768 // page. We are early enough in the request process here that we
2769 // can still see the NavigationState of the previous page and set
2770 // this value appropriately.
2771 // TODO(gavinp): catch the important case of navigation in a new
2772 // renderer process.
2773 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302774 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522775 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512776 const GURL referrer(
2777 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2778 if (!referrer.is_empty() &&
2779 NavigationState::FromDataSource(
2780 old_frame->dataSource())->was_prefetcher()) {
2781 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2782 WebDataSource* old_frame_ds = old_frame->dataSource();
2783 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2784 state->set_was_referred_by_prefetcher(true);
2785 break;
2786 }
2787 }
2788 }
2789 }
2790 }
2791
[email protected]4c1b6f0b2010-02-07 16:38:182792 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522793 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512794 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182795 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2796 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2797 break;
2798 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2799 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2800 break;
2801 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2802 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2803 break;
2804 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2805 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2806 break;
2807 }
2808 }
[email protected]fa7b6b542009-11-03 05:02:302809
2810 state->set_user_script_idle_scheduler(
2811 new UserScriptIdleScheduler(this, frame));
2812 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172813}
2814
2815void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2816 WebDataSource* ds = frame->provisionalDataSource();
2817 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2818
[email protected]3d9689372009-09-10 04:29:172819 // Update the request time if WebKit has better knowledge of it.
2820 if (navigation_state->request_time().is_null()) {
2821 double event_time = ds->triggeringEventTime();
2822 if (event_time != 0.0)
2823 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2824 }
2825
[email protected]05c8e502010-08-15 15:13:522826 // Start time is only set after request time.
2827 navigation_state->set_start_load_time(Time::Now());
2828
[email protected]3d9689372009-09-10 04:29:172829 bool is_top_most = !frame->parent();
2830 if (is_top_most) {
2831 navigation_gesture_ = frame->isProcessingUserGesture() ?
2832 NavigationGestureUnknown : NavigationGestureAuto;
2833
2834 // Make sure redirect tracking state is clear for the new load.
2835 completed_client_redirect_src_ = GURL();
2836 } else if (frame->parent()->isLoading()) {
2837 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002838 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172839 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2840 }
2841
2842 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2843 routing_id_, is_top_most, ds->request().url()));
2844}
2845
2846void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2847 if (frame->parent())
2848 return;
2849 // Received a redirect on the main frame.
2850 WebDataSource* data_source = frame->provisionalDataSource();
2851 if (!data_source) {
2852 // Should only be invoked when we have a data source.
2853 NOTREACHED();
2854 return;
2855 }
2856 std::vector<GURL> redirects;
2857 GetRedirectChain(data_source, &redirects);
2858 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512859 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2860 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172861 }
2862}
2863
[email protected]40bd6582009-12-04 23:49:512864void RenderView::didFailProvisionalLoad(WebFrame* frame,
2865 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172866 // Notify the browser that we failed a provisional load with an error.
2867 //
2868 // Note: It is important this notification occur before DidStopLoading so the
2869 // SSL manager can react to the provisional load failure before being
2870 // notified the load stopped.
2871 //
2872 WebDataSource* ds = frame->provisionalDataSource();
2873 DCHECK(ds);
2874
2875 const WebURLRequest& failed_request = ds->request();
2876
2877 bool show_repost_interstitial =
2878 (error.reason == net::ERR_CACHE_MISS &&
2879 EqualsASCII(failed_request.httpMethod(), "POST"));
2880 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2881 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2882 show_repost_interstitial));
2883
2884 // Don't display an error page if this is simply a cancelled load. Aside
2885 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2886 if (error.reason == net::ERR_ABORTED)
2887 return;
2888
2889 // Make sure we never show errors in view source mode.
2890 frame->enableViewSourceMode(false);
2891
2892 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2893
2894 // If this is a failed back/forward/reload navigation, then we need to do a
2895 // 'replace' load. This is necessary to avoid messing up session history.
2896 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2897 // as session history is concerned.
2898 //
2899 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2900 // the page id.
2901 //
2902 bool replace =
2903 navigation_state->pending_page_id() != -1 ||
2904 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2905
2906 // If we failed on a browser initiated request, then make sure that our error
2907 // page load is regarded as the same browser initiated request.
2908 if (!navigation_state->is_content_initiated()) {
2909 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2910 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002911 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172912 navigation_state->transition_type(),
2913 navigation_state->request_time()));
2914 }
2915
2916 // Provide the user with a more helpful error page?
2917 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2918 return;
2919
2920 // Fallback to a local error page.
2921 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2922 replace);
2923}
2924
2925void RenderView::didReceiveDocumentData(
2926 WebFrame* frame, const char* data, size_t data_len,
2927 bool& prevent_default) {
2928 NavigationState* navigation_state =
2929 NavigationState::FromDataSource(frame->dataSource());
2930 if (!navigation_state->postpone_loading_data())
2931 return;
2932
2933 // We're going to call commitDocumentData ourselves...
2934 prevent_default = true;
2935
2936 // Continue buffering the response data for the original 404 page. If it
2937 // grows too large, then we'll just let it through.
2938 navigation_state->append_postponed_data(data, data_len);
2939 if (navigation_state->postponed_data().size() >= 512) {
2940 navigation_state->set_postpone_loading_data(false);
2941 frame->commitDocumentData(navigation_state->postponed_data().data(),
2942 navigation_state->postponed_data().size());
2943 navigation_state->clear_postponed_data();
2944 }
2945}
2946
[email protected]40bd6582009-12-04 23:49:512947void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2948 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172949 NavigationState* navigation_state =
2950 NavigationState::FromDataSource(frame->dataSource());
2951
2952 navigation_state->set_commit_load_time(Time::Now());
2953 if (is_new_navigation) {
2954 // When we perform a new navigation, we need to update the previous session
2955 // history entry with state for the page we are leaving.
2956 UpdateSessionHistory(frame);
2957
2958 // We bump our Page ID to correspond with the new session history entry.
2959 page_id_ = next_page_id_++;
2960
[email protected]d64b07b2010-04-20 22:14:062961 // Any pending translation is now obsolete.
2962 translate_helper_.CancelPendingTranslation();
2963
[email protected]3cc72b12010-03-18 23:03:002964 // Advance our offset in session history, applying the length limit. There
2965 // is now no forward history.
2966 history_list_offset_++;
2967 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2968 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2969 history_list_length_ = history_list_offset_ + 1;
2970
[email protected]f9f4841b2010-03-20 05:41:422971 MessageLoop::current()->PostDelayedTask(
2972 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302973 page_info_method_factory_.NewRunnableMethod(
2974 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:172975 kDelayForForcedCaptureMs);
2976 } else {
2977 // Inspect the navigation_state on this frame to see if the navigation
2978 // corresponds to a session history navigation... Note: |frame| may or
2979 // may not be the toplevel frame, but for the case of capturing session
2980 // history, the first committed frame suffices. We keep track of whether
2981 // we've seen this commit before so that only capture session history once
2982 // per navigation.
2983 //
2984 // Note that we need to check if the page ID changed. In the case of a
2985 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2986 // previous URL and the current page ID, which would be wrong.
2987 if (navigation_state->pending_page_id() != -1 &&
2988 navigation_state->pending_page_id() != page_id_ &&
2989 !navigation_state->request_committed()) {
2990 // This is a successful session history navigation!
2991 UpdateSessionHistory(frame);
2992 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002993
2994 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172995 }
2996 }
2997
2998 // Remember that we've already processed this request, so we don't update
2999 // the session history again. We do this regardless of whether this is
3000 // a session history navigation, because if we attempted a session history
3001 // navigation without valid HistoryItem state, WebCore will think it is a
3002 // new navigation.
3003 navigation_state->set_request_committed(true);
3004
3005 UpdateURL(frame);
3006
3007 // If this committed load was initiated by a client redirect, we're
3008 // at the last stop now, so clear it.
3009 completed_client_redirect_src_ = GURL();
3010
3011 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273012 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173013}
3014
3015void RenderView::didClearWindowObject(WebFrame* frame) {
3016 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3017 BindDOMAutomationController(frame);
3018 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
3019 dom_ui_bindings_.set_message_sender(this);
3020 dom_ui_bindings_.set_routing_id(routing_id_);
3021 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
3022 }
3023 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
3024 external_host_bindings_.set_message_sender(this);
3025 external_host_bindings_.set_routing_id(routing_id_);
3026 external_host_bindings_.BindToJavascript(frame, L"externalHost");
3027 }
3028}
3029
3030void RenderView::didCreateDocumentElement(WebFrame* frame) {
3031 if (RenderThread::current()) { // Will be NULL during unit tests.
3032 RenderThread::current()->user_script_slave()->InjectScripts(
3033 frame, UserScript::DOCUMENT_START);
3034 }
3035
3036 // Notify the browser about non-blank documents loading in the top frame.
3037 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253038 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273039 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173040 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3041 }
3042}
3043
3044void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3045 UpdateTitle(frame, title);
3046
3047 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273048 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173049}
3050
[email protected]5019ef12010-04-27 17:26:583051void RenderView::didChangeIcons(WebFrame* frame) {
3052 if (!frame->parent()) {
3053 Send(new ViewHostMsg_UpdateFavIconURL(
3054 routing_id_,
3055 page_id_,
3056 frame->favIconURL()));
3057 }
3058}
3059
[email protected]3d9689372009-09-10 04:29:173060void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3061 WebDataSource* ds = frame->dataSource();
3062 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3063 DCHECK(navigation_state);
3064 navigation_state->set_finish_document_load_time(Time::Now());
3065
3066 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
3067
[email protected]e9e07992010-02-17 21:04:363068 // The document has now been fully loaded. Scan for forms to be sent up to
3069 // the browser.
[email protected]679f128f2010-07-22 22:57:443070 autofill_helper_.FrameContentsAvailable(frame);
3071 password_autocomplete_manager_.SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:173072
3073 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273074 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173075
3076 if (RenderThread::current()) { // Will be NULL during unit tests.
3077 RenderThread::current()->user_script_slave()->InjectScripts(
3078 frame, UserScript::DOCUMENT_END);
3079 }
[email protected]fa7b6b542009-11-03 05:02:303080
3081 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3082}
3083
3084void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3085 if (RenderThread::current()) { // Will be NULL during unit tests.
3086 RenderThread::current()->user_script_slave()->InjectScripts(
3087 frame, UserScript::DOCUMENT_IDLE);
3088 }
3089
3090 WebFrame* main_frame = webview()->mainFrame();
3091 if (frame == main_frame) {
3092 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203093 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303094 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203095 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303096 pending_code_execution_queue_.pop();
3097 }
3098 }
[email protected]3d9689372009-09-10 04:29:173099}
3100
3101void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:263102 if (webview()->mainFrame() == frame)
3103 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173104}
3105
3106void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3107 // Ignore
3108}
3109
3110void RenderView::didFinishLoad(WebFrame* frame) {
3111 WebDataSource* ds = frame->dataSource();
3112 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3113 DCHECK(navigation_state);
3114 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303115 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413116
3117 // Let the password manager know which password forms are actually visible.
[email protected]679f128f2010-07-22 22:57:443118 password_autocomplete_manager_.SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:173119}
3120
[email protected]ccbe04e2010-03-17 17:58:433121void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173122 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063123 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3124 // since a new one gets created by didCreateDataSource.
[email protected]af15bed2010-08-25 21:12:093125 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
[email protected]f6c2459d2010-02-24 22:34:063126 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3127
[email protected]3d9689372009-09-10 04:29:173128 // If this was a reference fragment navigation that we initiated, then we
3129 // could end up having a non-null pending navigation state. We just need to
3130 // update the ExtraData on the datasource so that others who read the
3131 // ExtraData will get the new NavigationState. Similarly, if we did not
3132 // initiate this navigation, then we need to take care to reset any pre-
3133 // existing navigation state to a content-initiated navigation state.
3134 // DidCreateDataSource conveniently takes care of this for us.
3135 didCreateDataSource(frame, frame->dataSource());
3136
[email protected]af15bed2010-08-25 21:12:093137 NavigationState* new_state =
3138 NavigationState::FromDataSource(frame->dataSource());
3139 new_state->set_was_within_same_page(true);
3140
[email protected]f6c2459d2010-02-24 22:34:063141 if (idle_scheduler_ran) {
3142 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
[email protected]f6c2459d2010-02-24 22:34:063143 new_state->user_script_idle_scheduler()->set_has_run(true);
3144 }
3145
[email protected]3d9689372009-09-10 04:29:173146 didCommitProvisionalLoad(frame, is_new_navigation);
3147
[email protected]26aa0482009-09-30 16:55:273148 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173149}
3150
[email protected]476b6f82009-09-10 21:00:593151void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313152 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593153}
3154
[email protected]3d9689372009-09-10 04:29:173155void RenderView::assignIdentifierToRequest(
3156 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3157 // Ignore
3158}
3159
3160void RenderView::willSendRequest(
3161 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3162 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303163 WebFrame* top_frame = frame->top();
3164 if (!top_frame)
3165 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513166 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3167 WebDataSource* top_data_source = top_frame->dataSource();
3168 WebDataSource* data_source =
3169 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303170 if (data_source) {
3171 NavigationState* state = NavigationState::FromDataSource(data_source);
3172 if (state && state->is_cache_policy_override_set())
3173 request.setCachePolicy(state->cache_policy_override());
3174 }
[email protected]8a3125a712010-08-09 18:58:513175
3176 if (top_data_source) {
3177 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3178 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3179 state->set_was_prefetcher(true);
3180 }
3181
[email protected]3d9689372009-09-10 04:29:173182 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503183 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133184 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493185
[email protected]85cc78c2010-05-04 18:30:093186 // Temporary metrics, see site_isolation_metrics.h
3187 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173188}
3189
3190void RenderView::didReceiveResponse(
3191 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493192
[email protected]85cc78c2010-05-04 18:30:093193 // Temporary metrics, see site_isolation_metrics.h
3194 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3195 identifier,
3196 response);
[email protected]fa0a3432010-03-30 16:53:493197
[email protected]3d9689372009-09-10 04:29:173198 // Only do this for responses that correspond to a provisional data source
3199 // of the top-most frame. If we have a provisional data source, then we
3200 // can't have any sub-resources yet, so we know that this response must
3201 // correspond to a frame load.
3202 if (!frame->provisionalDataSource() || frame->parent())
3203 return;
3204
3205 // If we are in view source mode, then just let the user see the source of
3206 // the server's 404 error page.
3207 if (frame->isViewSourceModeEnabled())
3208 return;
3209
[email protected]65041fa2010-05-21 06:56:533210 NavigationState* navigation_state =
3211 NavigationState::FromDataSource(frame->provisionalDataSource());
3212 CHECK(navigation_state);
3213
[email protected]972ebdff2010-06-10 22:59:073214 // Record page load flags.
3215 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3216 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573217 navigation_state->set_was_alternate_protocol_available(
3218 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073219 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]65041fa2010-05-21 06:56:533220
[email protected]f48013be2010-01-14 22:07:453221 // Consider loading an alternate error page for 404 responses.
3222 if (response.httpStatusCode() != 404)
3223 return;
3224
[email protected]3d9689372009-09-10 04:29:173225 // Can we even load an alternate error page for this URL?
3226 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3227 return;
3228
[email protected]3d9689372009-09-10 04:29:173229 navigation_state->set_postpone_loading_data(true);
3230 navigation_state->clear_postponed_data();
3231}
3232
3233void RenderView::didFinishResourceLoad(
3234 WebFrame* frame, unsigned identifier) {
3235 NavigationState* navigation_state =
3236 NavigationState::FromDataSource(frame->dataSource());
3237 if (!navigation_state->postpone_loading_data())
3238 return;
3239
3240 // The server returned a 404 and the content was < 512 bytes (which we
3241 // suppressed). Go ahead and fetch the alternate page content.
3242
3243 const GURL& frame_url = frame->url();
3244
3245 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3246 DCHECK(error_page_url.is_valid());
3247
3248 WebURLError original_error;
3249 original_error.unreachableURL = frame_url;
3250
3251 navigation_state->set_alt_error_page_fetcher(
3252 new AltErrorPageResourceFetcher(
3253 error_page_url, frame, original_error,
3254 NewCallback(this, &RenderView::AltErrorPageFinished)));
3255}
3256
3257void RenderView::didFailResourceLoad(
3258 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3259 // Ignore
3260}
3261
3262void RenderView::didLoadResourceFromMemoryCache(
3263 WebFrame* frame, const WebURLRequest& request,
3264 const WebURLResponse& response) {
3265 // Let the browser know we loaded a resource from the memory cache. This
3266 // message is needed to display the correct SSL indicators.
3267 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3268 routing_id_,
3269 request.url(),
[email protected]91733b62009-09-18 06:21:093270 frame->securityOrigin().toString().utf8(),
3271 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173272 response.securityInfo()));
3273}
3274
[email protected]6069da8c2009-10-20 20:33:493275void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293276 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3277}
3278
3279void RenderView::didRunInsecureContent(
3280 WebFrame* frame, const WebSecurityOrigin& origin) {
3281 Send(new ViewHostMsg_DidRunInsecureContent(
3282 routing_id_,
3283 origin.toString().utf8()));
3284}
3285
[email protected]7ea093ba2009-11-03 05:54:593286bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403287 if (enabled_per_settings &&
3288 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3289 return true;
[email protected]7ea093ba2009-11-03 05:54:593290
[email protected]12bc8472010-04-15 07:29:403291 if (IsWhitelistedForContentSettings(frame))
3292 return true;
[email protected]7ea093ba2009-11-03 05:54:593293
3294 return false; // Other protocols fall through here.
3295}
3296
[email protected]0a1a45432010-03-31 08:09:453297bool RenderView::allowDatabase(
3298 WebFrame* frame, const WebString& name, const WebString& display_name,
3299 unsigned long estimated_size) {
3300 WebSecurityOrigin origin = frame->securityOrigin();
3301 if (origin.isEmpty())
3302 return false; // Uninitialized document?
3303
3304 bool result;
3305 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3306 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3307 return false;
[email protected]9fb83e82010-07-02 18:24:553308 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3309 GURL(origin.toString().utf8()),
3310 name,
3311 display_name,
3312 estimated_size,
3313 !result));
[email protected]0a1a45432010-03-31 08:09:453314 return result;
3315}
[email protected]8934a3b2010-02-25 00:34:003316void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283317 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003318}
3319
[email protected]c21f1d52010-03-04 03:19:433320void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283321 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433322}
3323
[email protected]3d9689372009-09-10 04:29:173324void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3325 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3326}
3327
[email protected]0c882b282009-10-07 17:01:283328void RenderView::didCreateScriptContext(WebFrame* frame) {
3329 EventBindings::HandleContextCreated(frame, false);
3330}
3331
3332void RenderView::didDestroyScriptContext(WebFrame* frame) {
3333 EventBindings::HandleContextDestroyed(frame);
3334}
3335
3336void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3337 EventBindings::HandleContextCreated(frame, true);
3338}
3339
[email protected]fc86daa2010-03-30 23:52:533340void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3341 WebFrame* target,
3342 bool cross_origin,
3343 const WebString& property_name,
3344 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103345 // TODO(johnnyg): track the individual properties and repeat event_ids.
3346 if (cross_origin)
3347 cross_origin_access_count_++;
3348 else
3349 same_origin_access_count_++;
3350}
3351
[email protected]3d9689372009-09-10 04:29:173352void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143353 CheckPreferredSize();
3354}
3355
3356void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173357 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253358 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173359 // message.
[email protected]705243f2010-05-05 19:58:073360 if (!send_preferred_size_changes_ || !webview())
3361 return;
[email protected]dfca5acf2010-03-22 03:28:433362
[email protected]705243f2010-05-05 19:58:073363 // WebCore likes to tell us things have changed even when they haven't, so
3364 // cache the width and height and only send the IPC message when we're sure
3365 // they're different.
3366 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3367 webview()->mainFrame()->documentElementScrollHeight());
3368 if (size == preferred_size_)
3369 return;
[email protected]c27324b2009-11-19 22:44:293370
[email protected]705243f2010-05-05 19:58:073371 preferred_size_ = size;
3372 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3373 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173374}
3375
[email protected]143dcd592009-11-06 21:33:493376void RenderView::didChangeScrollOffset(WebFrame* frame) {
3377 StartNavStateSyncTimerIfNecessary();
3378}
3379
[email protected]8922e1f2009-10-03 05:01:263380void RenderView::reportFindInPageMatchCount(int request_id, int count,
3381 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113382 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3383 if (!count)
3384 active_match_ordinal = 0;
3385
3386 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3387 routing_id_,
3388 request_id,
3389 count,
3390 gfx::Rect(),
3391 active_match_ordinal,
3392 final_update);
3393
[email protected]8922e1f2009-10-03 05:01:263394 // If we have a message that has been queued up, then we should just replace
3395 // it. The ACK from the browser will make sure it gets sent when the browser
3396 // wants it.
3397 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263398 queued_find_reply_message_.reset(msg);
3399 } else {
3400 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113401 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263402 }
3403}
3404
3405void RenderView::reportFindInPageSelection(int request_id,
3406 int active_match_ordinal,
3407 const WebRect& selection_rect) {
3408 // Send the search result over to the browser process.
3409 Send(new ViewHostMsg_Find_Reply(routing_id_,
3410 request_id,
3411 -1,
3412 selection_rect,
3413 active_match_ordinal,
3414 false));
3415}
3416
[email protected]2b06a992010-08-21 05:48:223417void RenderView::openFileSystem(
3418 WebFrame* frame,
3419 WebFileSystem::Type type,
3420 long long size,
3421 WebFileSystemCallbacks* callbacks) {
3422 scoped_ptr<PendingOpenFileSystem> request(
3423 new PendingOpenFileSystem(callbacks));
3424
3425 WebSecurityOrigin origin = frame->securityOrigin();
3426 if (origin.isEmpty())
3427 return; // Uninitialized document?
3428
3429 ViewHostMsg_OpenFileSystemRequest_Params params;
3430 params.routing_id = routing_id_;
3431 params.request_id = pending_file_system_requests_.Add(request.release());
3432 params.origin_url = GURL(origin.toString());
3433 params.type = type;
3434 params.requested_size = size;
3435
3436 Send(new ViewHostMsg_OpenFileSystemRequest(params));
3437}
3438
[email protected]79dbc662009-09-04 05:42:513439// webkit_glue::WebPluginPageDelegate -----------------------------------------
3440
[email protected]f103ab72009-09-02 17:10:593441webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533442 const FilePath& file_path,
3443 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593444 if (!PluginChannelHost::IsListening())
3445 return NULL;
3446
[email protected]d2139662009-12-10 03:21:143447 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283448 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143449 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163450 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533451 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143452 if (CommandLine::ForCurrentProcess()->
3453 HasSwitch(switches::kInternalPepper)) {
3454 in_process_plugin = true;
3455 use_pepper_host = true;
3456 } else {
3457 // In process Pepper plugins must be explicitly enabled.
3458 return NULL;
3459 }
[email protected]4e0616e2010-05-28 14:55:533460 } else {
3461 FilePath internal_pdf_path;
3462 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3463 if (file_path == internal_pdf_path) {
3464 in_process_plugin = true;
3465 use_pepper_host = true;
3466 }
[email protected]26e8d5e2009-10-13 02:47:163467 }
[email protected]4e0616e2010-05-28 14:55:533468
[email protected]d2139662009-12-10 03:21:143469 // Check for Native Client modules.
[email protected]8f05f7f2010-07-30 23:12:433470 if (mime_type == "application/x-nacl-srpc") {
3471 // NaCl is only permitted when we're in an extension/application with the
3472 // appropriate permission, or when explicitly enabled on the command line.
3473
3474 // TODO(cbiffle): need browser test for this before M7 (bug 45881)
3475 GURL main_frame_url(webview()->mainFrame()->url());
3476 const std::string &extension_id =
3477 RenderThread::current()->GetExtensionIdByURL(main_frame_url);
3478 bool in_ext = extension_id != "";
3479 bool explicit_enable =
3480 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3481
3482 if (in_ext) {
3483 if (ExtensionProcessBindings::HasPermission(extension_id,
3484 Extension::kNativeClientPermission)) {
3485 in_process_plugin = true;
3486 use_pepper_host = true;
3487 } else {
3488 // Disable NaCl for apps lacking the permission, even with the flag.
3489 return NULL;
3490 }
3491 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463492 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143493 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463494 }
3495 }
[email protected]4e0616e2010-05-28 14:55:533496
[email protected]d032f492009-09-29 00:33:463497 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143498 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283499 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533500 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333501 if (!pepper_plugin)
3502 return NULL;
3503
[email protected]53900d52010-06-16 04:25:013504 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283505 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143506 } else {
[email protected]6876dff2010-01-15 19:38:093507#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143508 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533509 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093510#else
[email protected]596b2c42010-01-14 20:40:433511 NOTIMPLEMENTED();
3512 return NULL;
[email protected]7b6616f2010-01-14 18:07:553513#endif
[email protected]6876dff2010-01-15 19:38:093514 }
[email protected]f103ab72009-09-02 17:10:593515 }
3516
[email protected]4e0616e2010-05-28 14:55:533517 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593518}
3519
3520void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033521#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593522 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3523 routing_id(), window));
3524#endif
3525}
3526
3527void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033528#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593529 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3530 routing_id(), window));
3531#endif
3532 CleanupWindowInPluginMoves(window);
3533}
3534
3535void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3536 SchedulePluginMove(move);
3537}
3538
3539void RenderView::DidStartLoadingForPlugin() {
3540 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523541 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593542}
3543
3544void RenderView::DidStopLoadingForPlugin() {
3545 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523546 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593547}
3548
3549void RenderView::ShowModalHTMLDialogForPlugin(
3550 const GURL& url,
3551 const gfx::Size& size,
3552 const std::string& json_arguments,
3553 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213554 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593555 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213556 json_retval));
[email protected]f103ab72009-09-02 17:10:593557}
3558
[email protected]b921cfd22010-02-25 16:57:513559WebCookieJar* RenderView::GetCookieJar() {
3560 return &cookie_jar_;
3561}
3562
initial.commit09911bf2008-07-26 23:55:293563void RenderView::SyncNavigationState() {
3564 if (!webview())
3565 return;
3566
[email protected]26aa0482009-09-30 16:55:273567 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173568 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293569 return;
[email protected]ca948a22009-06-25 19:36:173570
3571 Send(new ViewHostMsg_UpdateState(
3572 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293573}
3574
[email protected]b0950a72009-09-29 23:16:173575bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3576 // Make sure webview was not shut down.
3577 if (!webview())
3578 return false;
3579 // Create an image resource fetcher and assign it with a call back object.
3580 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273581 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173582 NewCallback(this, &RenderView::DidDownloadImage)));
3583 return true;
3584}
3585
3586void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293587 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173588 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473589 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3590 fetcher->id(),
3591 fetcher->image_url(),
3592 image.isNull(),
3593 image));
[email protected]b0950a72009-09-29 23:16:173594 // Dispose of the image fetcher.
3595 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3596 image_fetchers_.erase(fetcher);
3597 // We're in the callback from the ImageResourceFetcher, best to delay
3598 // deletion.
3599 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293600}
3601
[email protected]bf5c2ff392009-07-08 16:24:333602void RenderView::OnDownloadFavIcon(int id,
3603 const GURL& image_url,
3604 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343605 bool data_image_failed = false;
3606 if (image_url.SchemeIs("data")) {
3607 SkBitmap data_image = ImageFromDataUrl(image_url);
3608 data_image_failed = data_image.empty();
3609 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333610 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3611 data_image));
[email protected]f11ca0732009-04-11 00:09:343612 }
3613 }
3614
[email protected]bf5c2ff392009-07-08 16:24:333615 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173616 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333617 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3618 SkBitmap()));
3619 }
initial.commit09911bf2008-07-26 23:55:293620}
3621
[email protected]f11ca0732009-04-11 00:09:343622SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3623 std::string mime_type, char_set, data;
3624 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3625 // Decode the favicon using WebKit's image decoder.
3626 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3627 const unsigned char* src_data =
3628 reinterpret_cast<const unsigned char*>(&data[0]);
3629
3630 return decoder.Decode(src_data, data.size());
3631 }
3632 return SkBitmap();
3633}
3634
initial.commit09911bf2008-07-26 23:55:293635void RenderView::OnGetApplicationInfo(int page_id) {
3636 webkit_glue::WebApplicationInfo app_info;
3637 if (page_id == page_id_)
3638 webkit_glue::GetApplicationInfo(webview(), &app_info);
3639
3640 // Prune out any data URLs in the set of icons. The browser process expects
3641 // any icon with a data URL to have originated from a favicon. We don't want
3642 // to decode arbitrary data URLs in the browser process. See
3643 // http://b/issue?id=1162972
3644 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593645 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293646 app_info.icons.erase(app_info.icons.begin() + i);
3647 --i;
3648 }
3649 }
3650
3651 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3652}
3653
[email protected]7ccddb8c2009-08-04 17:36:553654GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293655 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553656 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293657 // If the URL that failed was secure, then the embedding web page was not
3658 // expecting a network attacker to be able to manipulate its contents. As
3659 // we fetch alternate error pages over HTTP, we would be allowing a network
3660 // attacker to manipulate the contents of the response if we tried to use
3661 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153662 return GURL();
initial.commit09911bf2008-07-26 23:55:293663 }
3664
3665 // Grab the base URL from the browser process.
3666 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153667 return GURL();
initial.commit09911bf2008-07-26 23:55:293668
3669 // Strip query params from the failed URL.
3670 GURL::Replacements remove_params;
3671 remove_params.ClearUsername();
3672 remove_params.ClearPassword();
3673 remove_params.ClearQuery();
3674 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553675 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503676 std::string spec_to_send = url_to_send.spec();
3677 // Notify link doctor of the url truncation by sending of "?" at the end.
3678 if (failed_url.has_query())
3679 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293680
3681 // Construct the query params to send to link doctor.
3682 std::string params(alternate_error_page_url_.query());
3683 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503684 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293685 params.append("&sourceid=chrome");
3686 params.append("&error=");
3687 switch (error_type) {
3688 case DNS_ERROR:
3689 params.append("dnserror");
3690 break;
3691
3692 case HTTP_404:
3693 params.append("http404");
3694 break;
3695
[email protected]5df266ac2008-10-15 19:50:133696 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333697 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133698 break;
3699
initial.commit09911bf2008-07-26 23:55:293700 default:
3701 NOTREACHED() << "unknown ErrorPageType";
3702 }
3703
3704 // OK, build the final url to return.
3705 GURL::Replacements link_doctor_params;
3706 link_doctor_params.SetQueryStr(params);
3707 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3708 return url;
3709}
3710
[email protected]0fdbf8c2010-07-08 20:33:013711WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3712 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493713}
3714
[email protected]6069da8c2009-10-20 20:33:493715void RenderView::OnFind(int request_id, const string16& search_text,
3716 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273717 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493718
3719 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493720 if (options.findNext) {
3721 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013722 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493723 } else {
[email protected]afdbd142010-07-10 08:01:233724 if (GetWebPluginFromPluginDocument()->startFind(
3725 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493726 } else {
[email protected]e7c58a32010-08-13 19:47:113727 // Send "no results".
3728 Send(new ViewHostMsg_Find_Reply(routing_id_,
3729 request_id,
3730 0,
3731 gfx::Rect(),
3732 0,
3733 true));
[email protected]24a7f3c2010-03-25 08:26:493734 }
3735 }
3736 return;
3737 }
3738
[email protected]b4bb2502009-10-01 22:35:273739 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273740 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293741 WebFrame* search_frame = focused_frame; // start searching focused frame.
3742
3743 bool multi_frame = (frame_after_main != main_frame);
3744
3745 // If we have multiple frames, we don't want to wrap the search within the
3746 // frame, so we check here if we only have main_frame in the chain.
3747 bool wrap_within_frame = !multi_frame;
3748
[email protected]b3f2b912009-04-09 16:18:523749 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293750 bool result = false;
3751
[email protected]7830da3e2009-11-06 16:27:263752 // If something is selected when we start searching it means we cannot just
3753 // increment the current match ordinal; we need to re-generate it.
3754 WebRange current_selection = focused_frame->selectionRange();
3755
initial.commit09911bf2008-07-26 23:55:293756 do {
[email protected]dd7daa82009-08-10 05:46:453757 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593758 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293759
3760 if (!result) {
3761 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223762 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293763
3764 // Find the next frame, but skip the invisible ones.
3765 do {
3766 // What is the next frame to search? (we might be going backwards). Note
3767 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593768 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273769 search_frame->traverseNext(true) :
3770 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453771 } while (!search_frame->hasVisibleContent() &&
3772 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293773
[email protected]884db412008-11-24 23:46:503774 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223775 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293776
3777 // If we have multiple frames and we have wrapped back around to the
3778 // focused frame, we need to search it once more allowing wrap within
3779 // the frame, otherwise it will report 'no match' if the focused frame has
3780 // reported matches, but no frames after the focused_frame contain a
3781 // match for the search word(s).
3782 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453783 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593784 request_id, search_text, options, true, // Force wrapping.
3785 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293786 }
3787 }
3788
[email protected]26aa0482009-09-30 16:55:273789 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293790 } while (!result && search_frame != focused_frame);
3791
[email protected]7830da3e2009-11-06 16:27:263792 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293793 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453794 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293795 } else {
3796 // If nothing is found, set result to "0 of 0", otherwise, set it to
3797 // "-1 of 1" to indicate that we found at least one item, but we don't know
3798 // yet what is active.
3799 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3800 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293801
[email protected]4f3dc372009-02-24 00:10:293802 // If we find no matches then this will be our last status update.
3803 // Otherwise the scoping effort will send more results.
3804 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293805
[email protected]4f3dc372009-02-24 00:10:293806 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403807 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593808 request_id,
[email protected]4f3dc372009-02-24 00:10:293809 match_count,
3810 selection_rect,
3811 ordinal,
3812 final_status_update));
initial.commit09911bf2008-07-26 23:55:293813
initial.commit09911bf2008-07-26 23:55:293814 // Scoping effort begins, starting with the mainframe.
3815 search_frame = main_frame;
3816
[email protected]dd7daa82009-08-10 05:46:453817 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293818
3819 do {
3820 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453821 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293822
3823 // We don't start another scoping effort unless at least one match has
3824 // been found.
3825 if (result) {
3826 // Start new scoping request. If the scoping function determines that it
3827 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453828 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593829 search_text,
3830 options,
initial.commit09911bf2008-07-26 23:55:293831 true); // reset the tickmarks
3832 }
3833
3834 // Iterate to the next frame. The frame will not necessarily scope, for
3835 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273836 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293837 } while (search_frame != main_frame);
3838 }
3839}
3840
[email protected]24a7f3c2010-03-25 08:26:493841void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3842 WebView* view = webview();
3843 if (!view)
3844 return;
3845
3846 WebDocument doc = view->mainFrame()->document();
3847 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013848 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493849 return;
3850 }
3851
3852 bool clear_selection =
3853 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3854 if (clear_selection)
3855 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3856
3857 WebFrame* frame = view->mainFrame();
3858 while (frame) {
3859 frame->stopFinding(clear_selection);
3860 frame = frame->traverseNext(false);
3861 }
3862
3863 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3864 WebFrame* focused_frame = view->focusedFrame();
3865 if (focused_frame) {
3866 WebDocument doc = focused_frame->document();
3867 if (!doc.isNull()) {
3868 WebNode node = doc.focusedNode();
3869 if (!node.isNull())
3870 node.simulateClick();
3871 }
3872 }
3873 }
3874}
3875
3876void RenderView::OnFindReplyAck() {
3877 // Check if there is any queued up request waiting to be sent.
3878 if (queued_find_reply_message_.get()) {
3879 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423880 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493881 }
3882}
3883
[email protected]8934a3b2010-02-25 00:34:003884bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353885 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003886 return current_content_settings_.settings[settings_type] !=
3887 CONTENT_SETTING_BLOCK;
3888}
3889
[email protected]55126132010-08-19 14:53:283890void RenderView::DidBlockContentType(ContentSettingsType settings_type,
3891 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:003892 if (!content_blocked_[settings_type]) {
3893 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:283894 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
3895 resource_identifier));
[email protected]0de80162010-02-03 04:52:353896 }
[email protected]0de80162010-02-03 04:52:353897}
3898
[email protected]71b0d5d2010-02-15 05:43:073899void RenderView::ClearBlockedContentSettings() {
3900 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3901 content_blocked_[i] = false;
3902}
3903
[email protected]aad51d1c2010-08-05 08:38:093904WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame,
3905 const WebPluginParams& params,
3906 const FilePath& path,
3907 pepper::PluginModule* pepper_module) {
3908 WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params,
3909 pepper_delegate_.AsWeakPtr());
3910 if (plugin && !frame->parent() && frame->document().isPluginDocument()) {
3911 // If this is a full-page plugin hosting the internal PDF plugin, we want
3912 // to notify the browser so that it can treat things like zooming
3913 // differently.
3914 // TODO(sanjeevr): Use a Pepper interface to determine this rather than
3915 // hardcode this for the PDF plugin path.
3916 FilePath pdf_path;
3917 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
3918 if (path == pdf_path)
3919 Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_));
[email protected]0cdafff2010-07-26 09:54:373920 }
[email protected]aad51d1c2010-08-05 08:38:093921 return plugin;
3922}
[email protected]00152e92010-07-19 11:47:403923
[email protected]aad51d1c2010-08-05 08:38:093924WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame,
3925 const WebPluginParams& params,
3926 const FilePath& path,
3927 const std::string& mime_type) {
3928 std::string actual_mime_type(mime_type);
[email protected]00152e92010-07-19 11:47:403929 if (actual_mime_type.empty())
3930 actual_mime_type = params.mimeType.utf8();
3931
[email protected]aad51d1c2010-08-05 08:38:093932 return new webkit_glue::WebPluginImpl(frame, params, path,
[email protected]7a13e792010-08-03 08:18:243933 actual_mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403934}
3935
3936WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame,
[email protected]851b1eb2010-08-09 13:32:293937 const WebPluginParams& params,
3938 PluginGroup* group) {
[email protected]00152e92010-07-19 11:47:403939 // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed.
[email protected]851b1eb2010-08-09 13:32:293940 BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params, group);
[email protected]00152e92010-07-19 11:47:403941 WebViewPlugin* plugin = blocked_plugin->plugin();
[email protected]851b1eb2010-08-09 13:32:293942 WebView* web_view = plugin->web_view();
3943 webkit_preferences_.Apply(web_view);
[email protected]00152e92010-07-19 11:47:403944 return plugin;
3945}
3946
[email protected]40bd6582009-12-04 23:49:513947void RenderView::OnZoom(PageZoom::Function function) {
3948 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3949 return;
3950
[email protected]258d31122010-05-09 10:59:413951 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523952
[email protected]40bd6582009-12-04 23:49:513953 int zoom_level = webview()->zoomLevel();
3954 int new_zoom_level = webview()->setZoomLevel(false,
3955 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3956
[email protected]9d797f32010-04-23 07:17:543957 // Tell the browser which url got zoomed so it can update the saved values.
3958 Send(new ViewHostMsg_DidZoomURL(
3959 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513960}
3961
[email protected]9d797f32010-04-23 07:17:543962void RenderView::OnSetContentSettingsForLoadingURL(
3963 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013964 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543965 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013966}
3967
[email protected]9d797f32010-04-23 07:17:543968void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3969 int zoom_level) {
3970 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293971}
3972
[email protected]41fc0322009-09-04 22:23:403973void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273974 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293975}
3976
[email protected]a697f4c2009-09-14 22:30:183977void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273978 WebString no_encoding;
3979 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183980}
3981
[email protected]20ad2692009-11-20 18:27:203982bool RenderView::GetAllChildFrames(
3983 WebFrame* parent_frame,
3984 std::vector<WebFrame*>* frames_vector) const {
3985 if (!parent_frame)
3986 return false;
3987 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3988 child_frame = child_frame->nextSibling()) {
3989 frames_vector->push_back(child_frame);
3990 GetAllChildFrames(child_frame, frames_vector);
3991 }
3992 return true;
3993}
3994
[email protected]dd7daa82009-08-10 05:46:453995WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3996 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273997 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453998
3999 // xpath string can represent a frame deep down the tree (across multiple
4000 // frame DOMs).
4001 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4002 // should break into 2 xpaths
4003 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4004
[email protected]26aa0482009-09-30 16:55:274005 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454006
4007 std::wstring xpath_remaining = xpath;
4008 while (!xpath_remaining.empty()) {
4009 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4010 std::wstring xpath_child;
4011 if (delim_pos != std::wstring::npos) {
4012 xpath_child = xpath_remaining.substr(0, delim_pos);
4013 xpath_remaining.erase(0, delim_pos + 1);
4014 } else {
4015 xpath_remaining.swap(xpath_child);
4016 }
4017 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294018 }
4019
[email protected]dd7daa82009-08-10 05:46:454020 return frame;
initial.commit09911bf2008-07-26 23:55:294021}
4022
[email protected]f29acf52008-11-03 20:08:334023void RenderView::EvaluateScript(const std::wstring& frame_xpath,
4024 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:294025 WebFrame* web_frame = GetChildFrame(frame_xpath);
4026 if (!web_frame)
4027 return;
4028
[email protected]dd7daa82009-08-10 05:46:454029 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:294030}
4031
[email protected]1810e132009-03-24 23:35:484032void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084033 const std::string& css,
4034 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484035 WebFrame* web_frame = GetChildFrame(frame_xpath);
4036 if (!web_frame)
4037 return;
4038
[email protected]ffaef0c2009-09-15 17:08:084039 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484040}
4041
[email protected]00c39612010-03-06 02:53:284042void RenderView::OnPepperPluginDestroy(
4043 WebPluginDelegatePepper* pepper_plugin) {
4044 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014045 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4046 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284047 NOTREACHED();
4048 return;
4049 }
[email protected]53900d52010-06-16 04:25:014050 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474051
4052 // The plugin could have been destroyed while it was waiting for a file
4053 // choose callback, so check all pending completion callbacks and NULL them.
4054 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4055 file_chooser_completions_.begin();
4056 i != file_chooser_completions_.end(); /* nothing */) {
4057 if ((*i)->completion == pepper_plugin) {
4058 // We NULL the first one instead of deleting it because the plugin might
4059 // be the one waiting for a file choose callback. If the callback later
4060 // comes, we don't want to send the result to the next callback in line.
4061 if (i == file_chooser_completions_.begin())
4062 (*i)->completion = NULL;
4063 else
4064 i = file_chooser_completions_.erase(i);
4065 } else {
4066 ++i;
4067 }
4068 }
[email protected]00c39612010-03-06 02:53:284069}
4070
initial.commit09911bf2008-07-26 23:55:294071void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
4072 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:334073 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:294074}
4075
[email protected]1810e132009-03-24 23:35:484076void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084077 const std::string& css,
4078 const std::string& id) {
4079 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414080
4081 // Notify RenderViewHost that css has been inserted into the frame.
4082 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484083}
4084
[email protected]7ea066a2009-04-06 20:21:594085void RenderView::OnAddMessageToConsole(
4086 const string16& frame_xpath,
4087 const string16& message,
4088 const WebConsoleMessage::Level& level) {
4089 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594090 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454091 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294092}
4093
[email protected]81e63782009-02-27 19:35:094094void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4095 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294096}
4097
4098void RenderView::OnSetDOMUIProperty(const std::string& name,
4099 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094100 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:294101 dom_ui_bindings_.SetProperty(name, value);
4102}
4103
4104void RenderView::OnReservePageIDRange(int size_of_range) {
4105 next_page_id_ += size_of_range + 1;
4106}
4107
[email protected]e80c73b2009-04-07 23:24:584108void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4109 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254110 bool ended,
4111 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034112 if (ended) {
[email protected]26aa0482009-09-30 16:55:274113 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204114 } else {
4115 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034116 }
initial.commit09911bf2008-07-26 23:55:294117}
4118
4119void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274120 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294121}
4122
initial.commit09911bf2008-07-26 23:55:294123void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:164124 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:084125#if defined(WEBKIT_BUG_41283_IS_FIXED)
4126 password_autocomplete_manager_.ReceivedPasswordFormFillData(webview(),
4127 form_data);
[email protected]ad24ccb2010-07-15 21:38:204128#else
4129 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:084130#endif
initial.commit09911bf2008-07-26 23:55:294131}
4132
4133void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584134 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254135 const gfx::Point& screen_point,
4136 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274137 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584138 drop_data.ToDragData(),
4139 drop_data.identity,
4140 client_point,
[email protected]1d9f4132009-09-08 17:29:254141 screen_point,
4142 ops);
initial.commit09911bf2008-07-26 23:55:294143
[email protected]1d9f4132009-09-08 17:29:254144 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294145}
4146
[email protected]e80c73b2009-04-07 23:24:584147void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254148 const gfx::Point& screen_point,
4149 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274150 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254151 client_point,
4152 screen_point,
4153 ops);
initial.commit09911bf2008-07-26 23:55:294154
[email protected]1d9f4132009-09-08 17:29:254155 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294156}
4157
4158void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274159 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294160}
4161
[email protected]e80c73b2009-04-07 23:24:584162void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4163 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274164 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294165}
4166
4167void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594168 webkit_preferences_ = prefs;
4169 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294170}
4171
4172void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4173 alternate_error_page_url_ = url;
4174}
4175
[email protected]a0c7153e2009-12-09 14:36:334176void RenderView::OnCustomContextMenuAction(unsigned action) {
4177 webview()->performCustomContextMenuAction(action);
4178}
4179
[email protected]d4a00a72010-01-29 01:44:424180void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024181 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424182 const std::string& source_lang,
4183 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024184 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4185 translate_script);
[email protected]d4a00a72010-01-29 01:44:424186}
4187
[email protected]85d252e2010-04-06 22:21:024188void RenderView::OnRevertTranslation(int page_id) {
4189 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324190}
4191
initial.commit09911bf2008-07-26 23:55:294192void RenderView::OnInstallMissingPlugin() {
4193 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594194 if (first_default_plugin_)
4195 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294196}
4197
[email protected]97c5c592010-08-03 08:22:214198void RenderView::OnLoadBlockedPlugins() {
4199 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4200 Source<RenderView>(this),
4201 NotificationService::NoDetails());
4202}
4203
[email protected]cdaf8d02010-03-30 19:52:474204void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364205 // This could happen if we navigated to a different page before the user
4206 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474207 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364208 return;
4209
[email protected]cdaf8d02010-03-30 19:52:474210 WebVector<WebString> ws_file_names(paths.size());
4211 for (size_t i = 0; i < paths.size(); ++i)
4212 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464213
[email protected]cdaf8d02010-03-30 19:52:474214 if (file_chooser_completions_.front()->completion)
4215 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4216 file_chooser_completions_.pop_front();
4217
4218 // If there are more pending file chooser requests, schedule one now.
4219 if (!file_chooser_completions_.empty()) {
4220 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4221 file_chooser_completions_.front()->params));
4222 }
initial.commit09911bf2008-07-26 23:55:294223}
4224
4225void RenderView::OnEnableViewSourceMode() {
4226 if (!webview())
4227 return;
[email protected]26aa0482009-09-30 16:55:274228 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294229 if (!main_frame)
4230 return;
4231
[email protected]dd7daa82009-08-10 05:46:454232 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294233}
4234
[email protected]770dd8b2010-05-24 18:11:394235void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4236 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244237 if (send_preferred_size_changes_)
4238 return;
[email protected]9fb325e2010-05-06 18:23:244239 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394240
4241 // WebKit doesn't send a notification of the effective height of the page
4242 // changes, so poll for it.
4243 // TODO: Add a notification for this to WebKit, remove polling. After that's
4244 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4245 // http://crbug.com/44850
4246 if (flags & kPreferredSizeHeightThisIsSlow) {
4247 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4248 &RenderView::CheckPreferredSize);
4249 }
[email protected]0666aef2009-05-13 19:48:084250}
4251
[email protected]cda45c02010-02-25 19:28:104252void RenderView::OnDisableScrollbarsForSmallWindows(
4253 const gfx::Size& disable_scrollbar_size_limit) {
4254 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4255}
4256
[email protected]80d96fa2009-06-10 22:34:514257void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4258 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374259 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034260#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414261 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4262 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464263 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324264
[email protected]644d77e2010-01-27 01:03:104265 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324266 webview()->setScrollbarColors(
4267 renderer_prefs.thumb_inactive_color,
4268 renderer_prefs.thumb_active_color,
4269 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104270 webview()->setSelectionColors(
4271 renderer_prefs.active_selection_bg_color,
4272 renderer_prefs.active_selection_fg_color,
4273 renderer_prefs.inactive_selection_bg_color,
4274 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:014275 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:104276 }
[email protected]7a74e102009-09-03 00:16:564277#endif
[email protected]80d96fa2009-06-10 22:34:514278}
4279
[email protected]952cb702009-10-07 05:50:284280void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4281 const WebMediaPlayerAction& action) {
4282 if (webview())
4283 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564284}
4285
[email protected]7b291f92009-08-14 05:43:534286void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4287 view_type_ = type;
4288}
4289
4290void RenderView::OnUpdateBrowserWindowId(int window_id) {
4291 browser_window_id_ = window_id;
4292}
4293
[email protected]b3df5a42010-05-11 14:31:094294void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364295 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414296 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114297 accessibility_.reset(WebAccessibilityCache::create());
4298 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:414299
[email protected]b3df5a42010-05-11 14:31:094300 WebAccessibilityObject src_tree = webview()->accessibilityObject();
4301 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
4302 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504303}
4304
[email protected]aef92842010-05-21 16:54:364305void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4306 if (!accessibility_.get())
4307 return;
4308 if (accessibility_->isValidId(acc_obj_id)) {
4309 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4310 // By convention, calling SetFocus on the root of the tree (id = 1000)
4311 // should clear the current focus. Otherwise set the focus to the new
4312 // node.
4313 if (acc_obj_id == 1000)
4314 webview()->clearFocusedNode();
4315 else
4316 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4317 }
4318}
4319
4320void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4321 if (!accessibility_.get())
4322 return;
4323 if (accessibility_->isValidId(acc_obj_id)) {
4324 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4325 }
4326}
4327
initial.commit09911bf2008-07-26 23:55:294328void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4329 const GURL& page_url) {
4330 // Prepare list to storage all savable resource links.
4331 std::vector<GURL> resources_list;
4332 std::vector<GURL> referrers_list;
4333 std::vector<GURL> frames_list;
4334 webkit_glue::SavableResourcesResult result(&resources_list,
4335 &referrers_list,
4336 &frames_list);
4337
[email protected]dbeb3952009-10-13 18:01:184338 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4339 webview(),
4340 page_url,
4341 &result,
4342 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294343 // If something is wrong when collecting all savable resource links,
4344 // send empty list to embedder(browser) to tell it failed.
4345 referrers_list.clear();
4346 resources_list.clear();
4347 frames_list.clear();
4348 }
4349
4350 // Send result of all savable resource links to embedder.
4351 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4352 resources_list,
4353 referrers_list,
4354 frames_list));
4355}
4356
4357void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324358 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314359 const std::vector<FilePath>& local_paths,
4360 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074361
4362 // Convert std::vector of GURLs to WebVector<WebURL>
4363 WebVector<WebURL> weburl_links(links);
4364
4365 // Convert std::vector of std::strings to WebVector<WebString>
4366 WebVector<WebString> webstring_paths(local_paths.size());
4367 for (size_t i = 0; i < local_paths.size(); i++)
4368 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4369
4370 WebPageSerializer::serialize(webview()->mainFrame(),
4371 true, this, weburl_links, webstring_paths,
4372 webkit_glue::FilePathToWebString(
4373 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294374}
4375
[email protected]d9ec5c0f2009-12-23 11:55:074376void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4377 const WebCString& data,
4378 WebPageSerializerClient::PageSerializationStatus status) {
4379 Send(new ViewHostMsg_SendSerializedHtmlData(
4380 routing_id_,
4381 frame_url,
4382 data.data(),
4383 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294384}
4385
[email protected]9b18a84f2010-06-10 15:54:044386void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274387 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474388 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294389}
4390
[email protected]eb6b87a2009-07-24 15:57:394391void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294392 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4393 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4394 // in the onunload handler from appearing. For now, we're bypassing that and
4395 // calling the FrameLoader's CloseURL method directly. This should be
4396 // revisited to avoid having two ways to close a page. Having a single way
4397 // to close that can run onunload is also useful for fixing
4398 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274399 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294400 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454401 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174402 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294403 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4404 // multiple times for the same frame, but it will simplify things.
[email protected]05c8e502010-08-15 15:13:524405
4406 // Ensure state contains scheme.
4407 NavigationState* navigation_state =
4408 NavigationState::FromDataSource(main_frame->dataSource());
4409 if (url.SchemeIs("http"))
4410 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
4411 else if (url.SchemeIs("https"))
4412 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
4413
4414 // Dump will only be provided when scheme is http or https.
4415 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294416 }
[email protected]26aa0482009-09-30 16:55:274417 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294418
[email protected]ab9eabac2010-03-16 16:54:104419 // Reset stats
4420 cross_origin_access_count_ = 0;
4421 same_origin_access_count_ = 0;
4422
[email protected]eb6b87a2009-07-24 15:57:394423 // Just echo back the params in the ACK.
4424 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294425}
4426
4427void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574428#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294429 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014430 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574431#else // defined(OS_WIN)
4432 // TODO(port): we don't support theming on non-Windows platforms yet
4433 NOTIMPLEMENTED();
4434#endif
initial.commit09911bf2008-07-26 23:55:294435}
4436
[email protected]9b18a84f2010-06-10 15:54:044437void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4438 const std::string& origin,
4439 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154440 if (message.empty())
4441 return;
[email protected]28790922009-03-09 19:48:374442 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4443 target);
[email protected]3ac14a052008-08-15 21:22:154444}
4445
[email protected]0aa55312008-10-17 21:53:084446void RenderView::OnDisassociateFromPopupCount() {
4447 if (decrement_shared_popup_at_destruction_)
4448 shared_popup_counter_->data--;
4449 shared_popup_counter_ = new SharedRenderViewCounter(0);
4450 decrement_shared_popup_at_destruction_ = false;
4451}
4452
[email protected]15d79e12009-08-02 19:23:454453bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4454 const WebURLError& error,
4455 bool replace) {
4456 // We only show alternate error pages in the main frame. They are
4457 // intended to assist the user when navigating, so there is not much
4458 // value in showing them for failed subframes. Ideally, we would be
4459 // able to use the TYPED transition type for this, but that flag is
4460 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454461 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454462 return false;
4463
4464 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374465 // connection failure.
[email protected]15d79e12009-08-02 19:23:454466 int ec = error.reason;
4467 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4468 ec != net::ERR_CONNECTION_FAILED &&
4469 ec != net::ERR_CONNECTION_REFUSED &&
4470 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374471 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454472 return false;
4473
4474 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554475 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454476 if (!error_page_url.is_valid())
4477 return false;
4478
4479 // Load an empty page first so there is an immediate response to the error,
4480 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454481 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454482 GURL(kUnreachableWebDataURL),
4483 error.unreachableURL,
4484 replace);
4485
4486 // Now, create a fetcher for the error page and associate it with the data
4487 // source we just created via the LoadHTMLString call. That way if another
4488 // navigation occurs, the fetcher will get destroyed.
4489 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454490 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454491 navigation_state->set_alt_error_page_fetcher(
4492 new AltErrorPageResourceFetcher(
4493 error_page_url, frame, error,
4494 NewCallback(this, &RenderView::AltErrorPageFinished)));
4495 return true;
4496}
4497
initial.commit09911bf2008-07-26 23:55:294498std::string RenderView::GetAltHTMLForTemplate(
4499 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394500 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294501 ResourceBundle::GetSharedInstance().GetRawDataResource(
4502 template_resource_id));
4503
4504 if (template_html.empty()) {
4505 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4506 return "";
4507 }
[email protected]7cd22a52009-07-14 00:40:254508
initial.commit09911bf2008-07-26 23:55:294509 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254510 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294511 template_html, &error_strings, "t");
4512}
[email protected]0e79b9e2009-02-13 04:20:484513
[email protected]15d79e12009-08-02 19:23:454514void RenderView::AltErrorPageFinished(WebFrame* frame,
4515 const WebURLError& original_error,
4516 const std::string& html) {
4517 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554518
4519 // If we failed to download the alternate error page, fall back to the
4520 // original error page if present. Otherwise, LoadNavigationErrorPage
4521 // will simply display a default error page.
4522 const std::string* html_to_load = &html;
4523 if (html.empty()) {
4524 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454525 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554526 html_to_load = &navigation_state->postponed_data();
4527 }
4528 LoadNavigationErrorPage(
4529 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454530}
4531
[email protected]30f75e62009-02-25 22:01:004532void RenderView::OnMoveOrResizeStarted() {
4533 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474534 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004535}
4536
[email protected]30f75e62009-02-25 22:01:004537void RenderView::OnResize(const gfx::Size& new_size,
4538 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104539 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474540 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104541
4542 if (send_preferred_size_changes_) {
4543 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4544 // either width or height, allow scroll bars.
4545 bool allow_scrollbars = (
4546 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244547 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104548 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4549 }
4550 }
4551
[email protected]30f75e62009-02-25 22:01:004552 RenderWidget::OnResize(new_size, resizer_rect);
4553}
[email protected]0aa477bd2009-03-23 22:21:434554
[email protected]00c39612010-03-06 02:53:284555void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014556 // Notify the pepper plugins that we started painting.
4557 pepper_delegate_.ViewInitiatedPaint();
4558
4559 // Notify any "old-style" pepper plugins that we started painting. This is
4560 // used for internal bookkeeping only, so we know that the set can not change
4561 // under us.
[email protected]00c39612010-03-06 02:53:284562 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014563 current_oldstyle_pepper_plugins_.begin();
4564 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284565 (*i)->RenderViewInitiatedPaint();
4566}
4567
4568void RenderView::DidFlushPaint() {
4569 // Notify any pepper plugins that we painted. This will call into the plugin,
4570 // and we it may ask to close itself as a result. This will, in turn, modify
4571 // our set, possibly invalidating the iterator. So we iterate on a copy that
4572 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014573 pepper_delegate_.ViewFlushedPaint();
4574
4575 // Notify any old-style pepper plugins that we painted. This will call into
4576 // the plugin, and we it may ask to close itself as a result. This will, in
4577 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4578 // a copy that won't change out from under us.
4579 // This should be deleted when we don't support old Pepper anymore.
4580 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284581 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4582 i != plugins.end(); ++i) {
4583 // The copy above makes sure our iterator is never invalid if some plugins
4584 // are destroyed. But some plugin may decide to close all of its views in
4585 // response to a paint in one of them, so we need to make sure each one is
4586 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014587 if (current_oldstyle_pepper_plugins_.find(*i) !=
4588 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284589 (*i)->RenderViewFlushedPaint();
4590 }
4591
4592 WebFrame* main_frame = webview()->mainFrame();
4593
4594 // If we have a provisional frame we are between the start and commit stages
4595 // of loading and we don't want to save stats.
4596 if (!main_frame->provisionalDataSource()) {
4597 WebDataSource* ds = main_frame->dataSource();
4598 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4599 DCHECK(navigation_state);
4600
[email protected]05c8e502010-08-15 15:13:524601 // TODO(jar): The following code should all be inside a method, probably in
4602 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284603 Time now = Time::Now();
4604 if (navigation_state->first_paint_time().is_null()) {
4605 navigation_state->set_first_paint_time(now);
4606 }
4607 if (navigation_state->first_paint_after_load_time().is_null() &&
4608 !navigation_state->finish_load_time().is_null()) {
4609 navigation_state->set_first_paint_after_load_time(now);
4610 }
4611 }
4612}
4613
[email protected]05d478752009-04-08 23:38:164614void RenderView::OnClearFocusedNode() {
4615 if (webview())
[email protected]26aa0482009-09-30 16:55:274616 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164617}
4618
[email protected]699ab0d2009-04-23 23:19:144619void RenderView::OnSetBackground(const SkBitmap& background) {
4620 if (webview())
[email protected]b4bb2502009-10-01 22:35:274621 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144622
4623 SetBackground(background);
4624}
4625
[email protected]8c66c5a2009-07-22 17:26:344626void RenderView::OnSetActive(bool active) {
4627 if (webview())
[email protected]b4bb2502009-10-01 22:35:274628 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264629
4630#if defined(OS_MACOSX)
4631 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4632 for (plugin_it = plugin_delegates_.begin();
4633 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4634 (*plugin_it)->SetWindowFocus(active);
4635 }
4636#endif
[email protected]8c66c5a2009-07-22 17:26:344637}
4638
[email protected]6ce7abc52010-02-02 18:40:144639#if defined(OS_MACOSX)
4640void RenderView::OnSetWindowVisibility(bool visible) {
4641 // Inform plugins that their container has changed visibility.
4642 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4643 for (plugin_it = plugin_delegates_.begin();
4644 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4645 (*plugin_it)->SetContainerVisibility(visible);
4646 }
4647}
[email protected]1e6e3c992010-02-08 15:52:134648
[email protected]4d51d5bf2010-07-26 18:48:264649void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4650 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134651 // Inform plugins that their window's frame has changed.
4652 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4653 for (plugin_it = plugin_delegates_.begin();
4654 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4655 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4656 }
4657}
[email protected]6ce7abc52010-02-02 18:40:144658#endif // OS_MACOSX
4659
[email protected]8b8e7c92010-08-19 18:05:564660void RenderView::SendExtensionRequest(
4661 const ViewHostMsg_DomMessage_Params& params) {
4662 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:274663}
4664
[email protected]c6619182009-05-12 14:59:324665void RenderView::OnExtensionResponse(int request_id,
4666 bool success,
4667 const std::string& response,
4668 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354669 ExtensionProcessBindings::HandleResponse(
4670 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274671}
[email protected]c20210e62009-04-03 21:39:264672
[email protected]7120f132009-07-20 21:05:374673void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494674 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194675 bool requires_incognito_access,
4676 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494677 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194678 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374679}
4680
[email protected]e7e4f3c2009-04-21 15:24:084681// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264682//
[email protected]c20210e62009-04-03 21:39:264683// The time points we keep are
4684// request: time document was requested by user
4685// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254686// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294687// finish_document: main document loaded, before onload()
[email protected]05c8e502010-08-15 15:13:524688// finish_all_loads: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294689// first_paint: first paint performed
4690// first_paint_after_load: first paint performed after load is finished
4691// begin: request if it was user requested, start otherwise
4692//
[email protected]e7e4f3c2009-04-21 15:24:084693// It's possible for the request time not to be set, if a client
4694// redirect had been done (the user never requested the page)
4695// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294696// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264697void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504698 // Configuration for PLT related histograms.
4699 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4700 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4701 static const size_t kPLTCount(100);
4702 #define PLT_HISTOGRAM(name, sample) \
4703 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4704
[email protected]26aa0482009-09-30 16:55:274705 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564706 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454707 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564708
[email protected]05c8e502010-08-15 15:13:524709 URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type();
4710 if (scheme_type == 0)
4711 return;
4712 DCHECK(scheme_type == URLPattern::SCHEME_HTTP ||
4713 scheme_type == URLPattern::SCHEME_HTTPS);
4714
[email protected]f9f4841b2010-03-20 05:41:424715 // If we've already dumped, do nothing.
4716 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294717 return;
[email protected]cf9a7bc2010-06-11 18:54:504718
4719 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454720 Time start = navigation_state->start_load_time();
4721 if (start.is_null())
4722 return; // Probably very premature abandonment of page.
4723 Time commit = navigation_state->commit_load_time();
4724 if (commit.is_null())
4725 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504726
[email protected]b855ebe62010-05-12 23:01:454727 // We properly handle null values for the next 3 variables.
4728 Time request = navigation_state->request_time();
4729 Time first_paint = navigation_state->first_paint_time();
4730 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454731 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]05c8e502010-08-15 15:13:524732 Time finish_all_loads = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564733
[email protected]f9f4841b2010-03-20 05:41:424734 // Handle case where user hits "stop" or "back" before loading completely.
[email protected]05c8e502010-08-15 15:13:524735 bool abandoned_page = finish_doc.is_null();
[email protected]f9f4841b2010-03-20 05:41:424736 if (abandoned_page) {
[email protected]05c8e502010-08-15 15:13:524737 finish_doc = Time::Now();
4738 navigation_state->set_finish_document_load_time(finish_doc);
[email protected]f9f4841b2010-03-20 05:41:424739 }
[email protected]f9f4841b2010-03-20 05:41:424740
[email protected]05c8e502010-08-15 15:13:524741 // TODO(jar): We should really discriminate the definition of "abandon" more
4742 // finely. We should have:
4743 // abandon_before_document_loaded
4744 // abandon_before_onload_fired
4745
4746 if (finish_all_loads.is_null()) {
4747 finish_all_loads = Time::Now();
4748 navigation_state->set_finish_load_time(finish_all_loads);
4749 } else {
4750 DCHECK(!abandoned_page); // How can the doc have finished but not the page?
[email protected]cf9a7bc2010-06-11 18:54:504751 if (!abandoned_page)
4752 return; // Don't try to record a stat which is broken.
[email protected]cf9a7bc2010-06-11 18:54:504753 }
4754
4755 // Note: Client side redirects will have no request time.
4756 Time begin = request.is_null() ? start : request;
4757 TimeDelta begin_to_finish_doc = finish_doc - begin;
[email protected]05c8e502010-08-15 15:13:524758 TimeDelta begin_to_finish_all_loads = finish_all_loads - begin;
4759 TimeDelta start_to_finish_all_loads = finish_all_loads - start;
[email protected]ef1d8d322010-06-13 18:31:254760 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424761
[email protected]a7ccc4d2010-01-27 08:14:484762 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504763
[email protected]05c8e502010-08-15 15:13:524764 // The above code sanitized all values of times, in preparation for creating
4765 // actual histograms. The remainder of this code could be run at destructor
4766 // time for the navigation_state, since all data is intact.
4767
[email protected]cf9a7bc2010-06-11 18:54:504768 // Aggregate PLT data across all link types.
4769 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4770 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4771 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254772 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504773 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
[email protected]05c8e502010-08-15 15:13:524774 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc);
[email protected]cf9a7bc2010-06-11 18:54:504775 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
[email protected]05c8e502010-08-15 15:13:524776 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504777 if (!request.is_null()) {
4778 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
[email protected]05c8e502010-08-15 15:13:524779 PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request);
[email protected]cf9a7bc2010-06-11 18:54:504780 }
[email protected]05c8e502010-08-15 15:13:524781 PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit);
[email protected]cf9a7bc2010-06-11 18:54:504782 if (!first_paint.is_null()) {
4783 DCHECK(begin <= first_paint);
4784 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4785 DCHECK(commit <= first_paint);
4786 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4787 }
4788 if (!first_paint_after_load.is_null()) {
4789 DCHECK(begin <= first_paint_after_load);
4790 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4791 first_paint_after_load - begin);
4792 DCHECK(commit <= first_paint_after_load);
4793 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4794 first_paint_after_load - commit);
[email protected]05c8e502010-08-15 15:13:524795 DCHECK(finish_all_loads <= first_paint_after_load);
[email protected]cf9a7bc2010-06-11 18:54:504796 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
[email protected]05c8e502010-08-15 15:13:524797 first_paint_after_load - finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504798 }
4799 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524800 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504801
4802 // Load type related histograms.
4803 switch (load_type) {
4804 case NavigationState::UNDEFINED_LOAD:
4805 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524806 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504807 break;
4808 case NavigationState::RELOAD:
4809 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524810 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504811 break;
4812 case NavigationState::HISTORY_LOAD:
4813 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524814 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504815 break;
4816 case NavigationState::NORMAL_LOAD:
4817 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524818 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504819 break;
4820 case NavigationState::LINK_LOAD_NORMAL:
4821 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4822 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524823 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal",
4824 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504825 break;
4826 case NavigationState::LINK_LOAD_RELOAD:
4827 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4828 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524829 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload",
4830 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504831 break;
4832 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4833 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4834 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524835 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk",
4836 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504837 break;
4838 case NavigationState::LINK_LOAD_CACHE_ONLY:
4839 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4840 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524841 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly",
4842 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504843 break;
4844 default:
4845 break;
4846 }
4847
4848 // Histograms to determine if DNS prefetching has an impact on PLT.
4849 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4850 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4851 if (use_dns_histogram) {
4852 UMA_HISTOGRAM_ENUMERATION(
4853 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4854 abandoned_page ? 1 : 0, 2);
4855 UMA_HISTOGRAM_ENUMERATION(
4856 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4857 load_type, NavigationState::kLoadTypeMax);
4858 switch (load_type) {
4859 case NavigationState::NORMAL_LOAD:
4860 PLT_HISTOGRAM(FieldTrial::MakeName(
[email protected]05c8e502010-08-15 15:13:524861 "PLT.BeginToFinish_NormalLoad", "DnsImpact"),
4862 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504863 break;
4864 case NavigationState::LINK_LOAD_NORMAL:
4865 PLT_HISTOGRAM(FieldTrial::MakeName(
4866 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524867 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504868 break;
4869 case NavigationState::LINK_LOAD_RELOAD:
4870 PLT_HISTOGRAM(FieldTrial::MakeName(
4871 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524872 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504873 break;
4874 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4875 PLT_HISTOGRAM(FieldTrial::MakeName(
4876 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524877 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504878 break;
4879 default:
4880 break;
4881 }
4882 }
4883
[email protected]8a3125a712010-08-09 18:58:514884 // Histograms to determine if content prefetching has an impact on PLT.
4885 static const bool prefetching_fieldtrial =
4886 FieldTrialList::Find("Prefetch") &&
4887 !FieldTrialList::Find("Prefetch")->group_name().empty();
[email protected]13ae2df92010-08-19 20:05:104888 if (prefetching_fieldtrial) {
4889 if (navigation_state->was_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:514890 PLT_HISTOGRAM(
4891 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher",
4892 "Prefetch"),
4893 begin_to_finish_doc);
4894 PLT_HISTOGRAM(
4895 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher",
4896 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:524897 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:514898 }
[email protected]13ae2df92010-08-19 20:05:104899 if (navigation_state->was_referred_by_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:514900 PLT_HISTOGRAM(
4901 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcherReferrer",
4902 "Prefetch"),
4903 begin_to_finish_doc);
4904 PLT_HISTOGRAM(
4905 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcherReferrer",
4906 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:524907 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:514908 }
[email protected]8a3125a712010-08-09 18:58:514909 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName("PLT.Abandoned", "Prefetch"),
4910 abandoned_page ? 1 : 0, 2);
4911 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinishDoc", "Prefetch"),
4912 begin_to_finish_doc);
4913 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"),
[email protected]05c8e502010-08-15 15:13:524914 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:514915 }
4916
[email protected]06d94042010-08-25 01:45:224917 // Histograms to determine if backup connection jobs have an impact on PLT.
4918 static const bool connect_backup_jobs_fieldtrial(
4919 FieldTrialList::Find("ConnnectBackupJobs") &&
4920 !FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty());
4921 if (connect_backup_jobs_fieldtrial) {
4922 UMA_HISTOGRAM_ENUMERATION(
4923 FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"),
4924 abandoned_page ? 1 : 0, 2);
4925 UMA_HISTOGRAM_ENUMERATION(
4926 FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"),
4927 load_type, NavigationState::kLoadTypeMax);
4928 switch (load_type) {
4929 case NavigationState::NORMAL_LOAD:
4930 PLT_HISTOGRAM(FieldTrial::MakeName(
4931 "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"),
4932 begin_to_finish_all_loads);
4933 break;
4934 case NavigationState::LINK_LOAD_NORMAL:
4935 PLT_HISTOGRAM(FieldTrial::MakeName(
4936 "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"),
4937 begin_to_finish_all_loads);
4938 break;
4939 case NavigationState::LINK_LOAD_RELOAD:
4940 PLT_HISTOGRAM(FieldTrial::MakeName(
4941 "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"),
4942 begin_to_finish_all_loads);
4943 break;
4944 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4945 PLT_HISTOGRAM(FieldTrial::MakeName(
4946 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"),
4947 begin_to_finish_all_loads);
4948 break;
4949 default:
4950 break;
4951 }
4952 }
4953
[email protected]cf9a7bc2010-06-11 18:54:504954 // Histograms to determine if the number of connections has an
4955 // impact on PLT.
4956 // TODO(jar): Consider removing the per-link-type versions. We
4957 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
[email protected]97546492010-08-09 05:14:494958 static bool use_connection_impact_histogram(
[email protected]cf9a7bc2010-06-11 18:54:504959 FieldTrialList::Find("ConnCountImpact") &&
4960 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
[email protected]97546492010-08-09 05:14:494961 if (use_connection_impact_histogram) {
[email protected]cf9a7bc2010-06-11 18:54:504962 UMA_HISTOGRAM_ENUMERATION(
4963 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
4964 abandoned_page ? 1 : 0, 2);
4965 switch (load_type) {
4966 case NavigationState::NORMAL_LOAD:
4967 PLT_HISTOGRAM(FieldTrial::MakeName(
4968 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:524969 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504970 break;
4971 case NavigationState::LINK_LOAD_NORMAL:
4972 PLT_HISTOGRAM(FieldTrial::MakeName(
4973 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:524974 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504975 break;
4976 case NavigationState::LINK_LOAD_RELOAD:
4977 PLT_HISTOGRAM(FieldTrial::MakeName(
4978 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:524979 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504980 break;
4981 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4982 PLT_HISTOGRAM(FieldTrial::MakeName(
4983 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:524984 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504985 break;
4986 default:
4987 break;
4988 }
4989 }
4990
[email protected]78a258a2010-08-02 16:34:264991 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:004992 static bool use_idle_socket_timeout_histogram(
4993 FieldTrialList::Find("IdleSktToImpact") &&
4994 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
4995 if (use_idle_socket_timeout_histogram) {
4996 UMA_HISTOGRAM_ENUMERATION(
4997 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
4998 abandoned_page ? 1 : 0, 2);
4999 switch (load_type) {
5000 case NavigationState::NORMAL_LOAD:
5001 PLT_HISTOGRAM(FieldTrial::MakeName(
5002 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525003 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005004 break;
5005 case NavigationState::LINK_LOAD_NORMAL:
5006 PLT_HISTOGRAM(FieldTrial::MakeName(
5007 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525008 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005009 break;
5010 case NavigationState::LINK_LOAD_RELOAD:
5011 PLT_HISTOGRAM(FieldTrial::MakeName(
5012 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525013 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005014 break;
5015 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5016 PLT_HISTOGRAM(FieldTrial::MakeName(
5017 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525018 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005019 break;
5020 default:
5021 break;
5022 }
5023 }
5024
[email protected]78a258a2010-08-02 16:34:265025 // Histograms to determine effect of number of connections per proxy.
5026 static bool use_proxy_connection_impact_histogram(
5027 FieldTrialList::Find("ProxyConnectionImpact") &&
5028 !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty());
5029 if (use_proxy_connection_impact_histogram) {
5030 UMA_HISTOGRAM_ENUMERATION(
5031 FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
5032 abandoned_page ? 1 : 0, 2);
5033 switch (load_type) {
5034 case NavigationState::NORMAL_LOAD:
5035 PLT_HISTOGRAM(FieldTrial::MakeName(
5036 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525037 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265038 break;
5039 case NavigationState::LINK_LOAD_NORMAL:
5040 PLT_HISTOGRAM(FieldTrial::MakeName(
5041 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525042 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265043 break;
5044 case NavigationState::LINK_LOAD_RELOAD:
5045 PLT_HISTOGRAM(FieldTrial::MakeName(
5046 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525047 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265048 break;
5049 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5050 PLT_HISTOGRAM(FieldTrial::MakeName(
5051 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525052 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265053 break;
5054 default:
5055 break;
5056 }
5057 }
5058
[email protected]cf9a7bc2010-06-11 18:54:505059 // Histograms to determine if SDCH has an impact.
5060 // TODO(jar): Consider removing per-link load types and the enumeration.
5061 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
5062 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
5063 if (use_sdch_histogram) {
5064 UMA_HISTOGRAM_ENUMERATION(
5065 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
5066 load_type, NavigationState::kLoadTypeMax);
5067 switch (load_type) {
5068 case NavigationState::NORMAL_LOAD:
5069 PLT_HISTOGRAM(FieldTrial::MakeName(
5070 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525071 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505072 break;
5073 case NavigationState::LINK_LOAD_NORMAL:
5074 PLT_HISTOGRAM(FieldTrial::MakeName(
5075 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525076 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505077 break;
5078 case NavigationState::LINK_LOAD_RELOAD:
5079 PLT_HISTOGRAM(FieldTrial::MakeName(
5080 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525081 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505082 break;
5083 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5084 PLT_HISTOGRAM(FieldTrial::MakeName(
5085 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
[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_CACHE_ONLY:
5089 PLT_HISTOGRAM(FieldTrial::MakeName(
5090 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525091 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505092 break;
5093 default:
5094 break;
5095 }
5096 }
5097
5098 // Histograms to determine if cache size has an impact on PLT.
5099 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
5100 !FieldTrialList::Find("CacheSize")->group_name().empty());
5101 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
5102 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
5103 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
5104 // StartToFinish or BeginToFinish would be better.
5105 PLT_HISTOGRAM(FieldTrial::MakeName(
5106 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
5107 }
5108
[email protected]115f5542010-07-28 06:48:215109
[email protected]115f5542010-07-28 06:48:215110 // Histograms to determine if SPDY has an impact for https traffic.
[email protected]cf9a7bc2010-06-11 18:54:505111 // TODO(mbelshe): After we've seen the difference between BeginToFinish
5112 // and StartToFinish, consider removing one or the other.
5113 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
5114 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]05c8e502010-08-15 15:13:525115 if (use_spdy_histogram &&
5116 scheme_type == URLPattern::SCHEME_HTTPS &&
[email protected]115f5542010-07-28 06:48:215117 navigation_state->was_npn_negotiated()) {
[email protected]30b35882010-06-14 21:21:015118 UMA_HISTOGRAM_ENUMERATION(
5119 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
5120 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505121 switch (load_type) {
5122 case NavigationState::LINK_LOAD_NORMAL:
5123 PLT_HISTOGRAM(FieldTrial::MakeName(
5124 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
[email protected]05c8e502010-08-15 15:13:525125 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505126 PLT_HISTOGRAM(FieldTrial::MakeName(
5127 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
[email protected]05c8e502010-08-15 15:13:525128 start_to_finish_all_loads);
[email protected]ef1d8d322010-06-13 18:31:255129 PLT_HISTOGRAM(FieldTrial::MakeName(
5130 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5131 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:505132 break;
5133 case NavigationState::NORMAL_LOAD:
5134 PLT_HISTOGRAM(FieldTrial::MakeName(
5135 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
[email protected]05c8e502010-08-15 15:13:525136 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505137 PLT_HISTOGRAM(FieldTrial::MakeName(
5138 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
[email protected]05c8e502010-08-15 15:13:525139 start_to_finish_all_loads);
[email protected]ef1d8d322010-06-13 18:31:255140 PLT_HISTOGRAM(FieldTrial::MakeName(
5141 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
5142 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:505143 break;
5144 default:
5145 break;
5146 }
5147 }
5148
[email protected]115f5542010-07-28 06:48:215149 // Histograms to compare the impact of alternate protocol over http traffic:
5150 // when spdy is used vs. when http is used.
[email protected]05c8e502010-08-15 15:13:525151 if (scheme_type == URLPattern::SCHEME_HTTP &&
[email protected]115f5542010-07-28 06:48:215152 navigation_state->was_alternate_protocol_available()) {
[email protected]193b0b892010-06-26 03:57:575153 if (!navigation_state->was_npn_negotiated()) {
5154 // This means that even there is alternate protocols for npn_http or
5155 // npn_spdy, they are not taken (due to the fieldtrial).
5156 switch (load_type) {
5157 case NavigationState::LINK_LOAD_NORMAL:
5158 PLT_HISTOGRAM(
5159 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
[email protected]05c8e502010-08-15 15:13:525160 start_to_finish_all_loads);
[email protected]193b0b892010-06-26 03:57:575161 PLT_HISTOGRAM(
5162 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
5163 start_to_commit);
5164 break;
5165 case NavigationState::NORMAL_LOAD:
5166 PLT_HISTOGRAM(
5167 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
[email protected]05c8e502010-08-15 15:13:525168 start_to_finish_all_loads);
[email protected]193b0b892010-06-26 03:57:575169 PLT_HISTOGRAM(
5170 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
5171 start_to_commit);
5172 break;
5173 default:
5174 break;
5175 }
5176 } else if (navigation_state->was_fetched_via_spdy()) {
5177 switch (load_type) {
5178 case NavigationState::LINK_LOAD_NORMAL:
5179 PLT_HISTOGRAM(
5180 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
[email protected]05c8e502010-08-15 15:13:525181 start_to_finish_all_loads);
[email protected]193b0b892010-06-26 03:57:575182 PLT_HISTOGRAM(
5183 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
5184 start_to_commit);
5185 break;
5186 case NavigationState::NORMAL_LOAD:
5187 PLT_HISTOGRAM(
5188 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
[email protected]05c8e502010-08-15 15:13:525189 start_to_finish_all_loads);
[email protected]193b0b892010-06-26 03:57:575190 PLT_HISTOGRAM(
5191 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
5192 start_to_commit);
5193 break;
5194 default:
5195 break;
5196 }
5197 }
5198 }
5199
[email protected]cf9a7bc2010-06-11 18:54:505200 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:505201 if (navigation_state->was_fetched_via_proxy()) {
[email protected]05c8e502010-08-15 15:13:525202 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5203 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505204 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
[email protected]05c8e502010-08-15 15:13:525205 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505206 } else {
[email protected]05c8e502010-08-15 15:13:525207 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5208 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505209 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
[email protected]05c8e502010-08-15 15:13:525210 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505211 }
5212 } else {
[email protected]05c8e502010-08-15 15:13:525213 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5214 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https",
5215 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505216 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
[email protected]05c8e502010-08-15 15:13:525217 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505218 } else {
[email protected]05c8e502010-08-15 15:13:525219 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5220 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http",
5221 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505222 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
[email protected]05c8e502010-08-15 15:13:525223 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505224 }
5225 }
[email protected]a7ccc4d2010-01-27 08:14:485226
[email protected]ab9eabac2010-03-16 16:54:105227 // Site isolation metrics.
5228 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
5229 cross_origin_access_count_);
5230 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
5231 same_origin_access_count_);
5232
[email protected]05c8e502010-08-15 15:13:525233 // TODO(jar): This is the ONLY call in this method that needed more than
5234 // navigation_state. This should be relocated, or changed, so that this
5235 // body can be made a method on NavigationStates, and run via its destructor.
[email protected]cf9a7bc2010-06-11 18:54:505236 // Log some PLT data to the error log.
5237 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:295238
5239 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:415240
5241 // Since there are currently no guarantees that renderer histograms will be
5242 // sent to the browser, we initiate a PostTask here to be sure that we send
5243 // the histograms we generated. Without this call, pages that don't have an
5244 // on-close-handler might generate data that is lost when the renderer is
5245 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:485246 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
5247 // should post when the onload is complete, so that it doesn't interfere with
5248 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:415249 if (RenderThread::current()) {
5250 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:135251 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:415252 }
[email protected]c20210e62009-04-03 21:39:265253}
[email protected]e846d0d2009-05-20 00:53:065254
[email protected]f8999642009-10-27 21:39:425255void RenderView::LogNavigationState(const NavigationState* state,
5256 const WebDataSource* ds) const {
5257 // Because this function gets called on every page load,
5258 // take extra care to optimize it away if logging is turned off.
5259 if (logging::LOG_INFO < logging::GetMinLogLevel())
5260 return;
5261
5262 DCHECK(state);
5263 DCHECK(ds);
5264 GURL url(ds->request().url());
5265 Time start = state->start_load_time();
5266 Time finish = state->finish_load_time();
5267 // TODO(mbelshe): should we log more stats?
5268 LOG(INFO) << "PLT: "
5269 << (finish - start).InMilliseconds()
5270 << "ms "
5271 << url.spec();
5272}
5273
[email protected]cc0445f2009-10-13 16:09:085274void RenderView::focusAccessibilityObject(
5275 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:065276#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:155277 // TODO(dglazkov): Current logic implies that focus change can only be made
5278 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5279 // where accessibility is initialized. We should determine whether that's
5280 // right.
5281 if (!accessibility_.get())
5282 return;
[email protected]e846d0d2009-05-20 00:53:065283
5284 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:155285 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:065286
5287 // If id is valid, alert the browser side that an accessibility focus change
5288 // occurred.
5289 if (acc_obj_id >= 0)
5290 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
5291
5292#else // defined(OS_WIN)
5293 // TODO(port): accessibility not yet implemented
5294 NOTIMPLEMENTED();
5295#endif
5296}
[email protected]daa8c58e2009-06-15 17:21:105297
[email protected]a3018be2010-03-09 04:28:485298void RenderView::didChangeAccessibilityObjectState(
5299 const WebKit::WebAccessibilityObject& acc_obj) {
5300#if defined(OS_WIN)
5301 // TODO(dglazkov): Current logic implies that a state change can only be made
5302 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5303 // where accessibility is initialized. We should determine whether that's
5304 // right.
5305 if (!accessibility_.get())
5306 return;
5307
5308 // Retrieve the accessibility object id of the AccessibilityObject.
5309 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
5310
5311 // If id is valid, alert the browser side that an accessibility object state
5312 // change occurred.
5313 if (acc_obj_id >= 0)
5314 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
5315 acc_obj_id));
5316
5317#else // defined(OS_WIN)
5318 // TODO(port): accessibility not yet implemented
5319 NOTIMPLEMENTED();
5320#endif
5321}
5322
[email protected]0fda7272009-06-26 15:49:335323void RenderView::Print(WebFrame* frame, bool script_initiated) {
5324 DCHECK(frame);
5325 if (print_helper_.get() == NULL) {
5326 print_helper_.reset(new PrintWebViewHelper(this));
5327 }
5328 print_helper_->Print(frame, script_initiated);
5329}
[email protected]446705872009-09-10 07:22:485330
5331void RenderView::OnSetEditCommandsForNextKeyEvent(
5332 const EditCommands& edit_commands) {
5333 edit_commands_ = edit_commands;
5334}
5335
[email protected]61f5a7b2009-12-22 22:21:205336void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275337 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355338 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205339 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5340 false));
[email protected]912256b32009-09-18 09:47:355341 return;
5342 }
5343
[email protected]fa7b6b542009-11-03 05:02:305344 WebDataSource* ds = main_frame->dataSource();
5345 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5346 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205347 pending_code_execution_queue_.push(
5348 linked_ptr<ViewMsg_ExecuteCode_Params>(
5349 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305350 return;
5351 }
5352
[email protected]61f5a7b2009-12-22 22:21:205353 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305354}
5355
5356void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205357 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485358 // Don't execute scripts in gallery pages.
5359 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085360 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5361 && !CommandLine::ForCurrentProcess()->HasSwitch(
5362 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485363 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5364 return;
5365 }
5366
[email protected]20ad2692009-11-20 18:27:205367 std::vector<WebFrame*> frame_vector;
5368 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205369 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205370 GetAllChildFrames(frame, &frame_vector);
5371
5372 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5373 frame_it != frame_vector.end(); ++frame_it) {
5374 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205375 if (params.is_javascript) {
5376 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5377 continue;
5378
[email protected]20ad2692009-11-20 18:27:205379 std::vector<WebScriptSource> sources;
5380 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205381 WebScriptSource(WebString::fromUTF8(params.code)));
5382 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205383 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205384 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205385 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5386 } else {
[email protected]61f5a7b2009-12-22 22:21:205387 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205388 }
[email protected]912256b32009-09-18 09:47:355389 }
5390
[email protected]61f5a7b2009-12-22 22:21:205391 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355392}
5393
[email protected]60c42a8c72009-10-09 04:08:595394void RenderView::Close() {
5395 // We need to grab a pointer to the doomed WebView before we destroy it.
5396 WebView* doomed = webview();
5397 RenderWidget::Close();
5398 Singleton<ViewMap>::get()->erase(doomed);
5399}
5400
[email protected]446705872009-09-10 07:22:485401void RenderView::DidHandleKeyEvent() {
5402 edit_commands_.clear();
5403}
5404
[email protected]941e4552010-02-01 21:23:435405#if defined(OS_MACOSX)
5406void RenderView::OnWasHidden() {
5407 RenderWidget::OnWasHidden();
5408
5409 // Inform plugins that their container is no longer visible.
5410 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5411 for (plugin_it = plugin_delegates_.begin();
5412 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5413 (*plugin_it)->SetContainerVisibility(false);
5414 }
5415}
5416
5417void RenderView::OnWasRestored(bool needs_repainting) {
5418 RenderWidget::OnWasRestored(needs_repainting);
5419
5420 // Inform plugins that their container is now visible.
5421 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5422 for (plugin_it = plugin_delegates_.begin();
5423 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5424 (*plugin_it)->SetContainerVisibility(true);
5425 }
5426}
[email protected]1e6e3c992010-02-08 15:52:135427
5428void RenderView::OnSetFocus(bool enable) {
5429 RenderWidget::OnSetFocus(enable);
5430
[email protected]7d3c02c2010-05-05 23:10:315431 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135432 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5433 for (plugin_it = plugin_delegates_.begin();
5434 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315435 // RenderWidget's call to setFocus can cause the underlying webview's
5436 // activation state to change just like a call to setIsActive.
5437 if (enable)
5438 (*plugin_it)->SetWindowFocus(true);
5439 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135440 }
5441 }
5442}
[email protected]941e4552010-02-01 21:23:435443#endif // OS_MACOSX
5444
[email protected]83dde542009-09-11 20:59:555445void RenderView::EnsureDocumentTag() {
5446 // TODO(darin): There's actually no reason for this to be here. We should
5447 // have the browser side manage the document tag.
5448#if defined(OS_MACOSX)
5449 if (!has_document_tag_) {
5450 // Make the call to get the tag.
5451 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5452 has_document_tag_ = true;
5453 }
5454#endif
5455}
[email protected]12636df2009-09-28 22:32:215456
[email protected]43f28f832010-02-03 02:28:485457#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035458gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235459 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485460 gfx::PluginWindowHandle window = NULL;
5461 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235462 routing_id(), opaque, root, &window));
[email protected]43f28f832010-02-03 02:28:485463 return window;
5464}
5465
5466void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5467 if (window)
5468 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5469}
5470
[email protected]44ce0b12010-03-12 16:45:335471void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5472 int32 width,
5473 int32 height,
5474 uint64 io_surface_identifier) {
5475 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485476 routing_id(), window, width, height, io_surface_identifier));
5477}
5478
[email protected]44ce0b12010-03-12 16:45:335479void RenderView::AcceleratedSurfaceSetTransportDIB(
5480 gfx::PluginWindowHandle window,
5481 int32 width,
5482 int32 height,
5483 TransportDIB::Handle transport_dib) {
5484 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075485 routing_id(), window, width, height, transport_dib));
5486}
5487
[email protected]44ce0b12010-03-12 16:45:335488TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5489 size_t size) {
[email protected]1aef98132010-02-23 18:00:075490 TransportDIB::Handle dib_handle;
5491 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385492 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075493 return dib_handle;
5494 // Return an invalid handle if Send() fails.
5495 return TransportDIB::DefaultHandleValue();
5496}
5497
[email protected]44ce0b12010-03-12 16:45:335498void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075499 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5500}
5501
[email protected]44ce0b12010-03-12 16:45:335502void RenderView::AcceleratedSurfaceBuffersSwapped(
5503 gfx::PluginWindowHandle window) {
5504 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485505}
5506#endif
[email protected]58c321d2010-02-19 12:11:285507
[email protected]cdaf8d02010-03-30 19:52:475508bool RenderView::ScheduleFileChooser(
5509 const ViewHostMsg_RunFileChooser_Params& params,
5510 WebFileChooserCompletion* completion) {
5511 static const size_t kMaximumPendingFileChooseRequests = 4;
5512 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5513 // This sanity check prevents too many file choose requests from getting
5514 // queued which could DoS the user. Getting these is most likely a
5515 // programming error (there are many ways to DoS the user so it's not
5516 // considered a "real" security check), either in JS requesting many file
5517 // choosers to pop up, or in a plugin.
5518 //
5519 // TODO(brettw) we might possibly want to require a user gesture to open
5520 // a file picker, which will address this issue in a better way.
5521 return false;
5522 }
5523
5524 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5525 new PendingFileChooser(params, completion)));
5526 if (file_chooser_completions_.size() == 1) {
5527 // Actually show the browse dialog when this is the first request.
5528 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5529 }
5530 return true;
5531}
5532
[email protected]290838a2010-04-27 17:37:015533void RenderView::OnPageTranslated() {
5534 WebFrame* frame = webview()->mainFrame();
5535 if (!frame)
5536 return;
5537
5538 // The page is translated, so try to extract the form data again.
[email protected]679f128f2010-07-22 22:57:445539 autofill_helper_.FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015540}
5541
[email protected]8a5f7002010-03-31 13:47:355542WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285543 if (!geolocation_dispatcher_.get())
5544 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5545 return geolocation_dispatcher_.get();
5546}
[email protected]61c9f032010-03-31 23:04:195547
[email protected]638694c2010-08-04 22:24:115548WebKit::WebSpeechInputController* RenderView::speechInputController(
5549 WebKit::WebSpeechInputListener* listener) {
5550 if (!speech_input_dispatcher_.get())
5551 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5552 return speech_input_dispatcher_.get();
5553}
5554
[email protected]57ead352010-08-11 14:42:535555WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
5556 if (!device_orientation_dispatcher_.get())
5557 device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this));
5558 return device_orientation_dispatcher_.get();
5559}
5560
[email protected]8079b362010-05-07 18:37:455561bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195562 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455563 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195564 if (frame->parent() != NULL)
5565 return false;
5566
[email protected]f0a3d0b2010-08-06 22:51:535567 // Navigations initiated within Webkit are not sent out to the external host
5568 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275569 // 1. The url scheme is not http/https
5570 // 2. There is no opener and this is not the first url being opened by this
5571 // RenderView.
5572 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535573 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535574 // 4. Reloads/form submits/back forward navigations
5575 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5576 return false;
5577
[email protected]d0ed50d2010-06-22 01:01:325578 // Not interested in reloads.
5579 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015580 type != WebKit::WebNavigationTypeFormSubmitted &&
5581 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325582 // The opener relationship between the new window and the parent allows the
5583 // new window to script the parent and vice versa. This is not allowed if
5584 // the origins of the two domains are different. This can be treated as a
5585 // top level navigation and routed back to the host.
5586 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275587 if (!opener) {
5588 // If this is the first page being loaded by this RenderView instance then
5589 // it should stay here.
5590 if (page_id_ == -1) {
5591 return false;
5592 } else {
[email protected]d0ed50d2010-06-22 01:01:325593 return true;
[email protected]900eb2f12010-08-23 22:36:275594 }
[email protected]d0ed50d2010-06-22 01:01:325595 }
[email protected]900eb2f12010-08-23 22:36:275596
5597 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5598 return true;
[email protected]d0ed50d2010-06-22 01:01:325599 }
[email protected]61c9f032010-03-31 23:04:195600 return false;
5601}
[email protected]2b06a992010-08-21 05:48:225602
5603void RenderView::OnOpenFileSystemRequestComplete(
5604 int request_id, bool accepted, const string16& name,
5605 const string16& root_path) {
5606 PendingOpenFileSystem* request = pending_file_system_requests_.Lookup(
5607 request_id);
5608 DCHECK(request);
5609 if (accepted)
5610 request->callbacks->didOpenFileSystem(name, root_path);
5611 else
5612 request->callbacks->didFail(WebKit::WebFileErrorSecurity);
5613 request->callbacks = NULL;
5614 pending_file_system_requests_.Remove(request_id);
5615}