blob: 39a65e86533baadd8351cb285981fb8c35d804be [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]6a8ddba52010-09-05 04:38:0647#include "chrome/renderer/autofill_helper.h"
[email protected]00152e92010-07-19 11:47:4048#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5349#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1150#include "chrome/renderer/devtools_agent.h"
51#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3552#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0453#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]5351dbc2010-08-27 15:22:1154#include "chrome/renderer/extensions/extension_renderer_info.h"
[email protected]f816c012009-06-26 21:48:3255#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3556#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3757#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2858#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5660#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4161#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]8400e032010-02-26 18:50:1162#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5663#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1264#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0665#include "chrome/renderer/page_click_tracker.h"
66#include "chrome/renderer/password_autocomplete_manager.h"
[email protected]8beff0762009-09-29 02:18:3067#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5068#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2569#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2870#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2671#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1872#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]035545f2010-04-09 13:10:2173#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3474#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]638694c2010-08-04 22:24:1175#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4676#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3577#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2978#include "chrome/renderer/visitedlink_slave.h"
[email protected]1cfb7420f2010-09-03 18:57:2479#include "chrome/renderer/webgles2context_impl.h"
[email protected]d439ba072009-10-17 22:32:2980#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2981#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4282#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5683#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1584#include "gfx/color_utils.h"
85#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5786#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2687#include "gfx/point.h"
88#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2789#include "grit/generated_resources.h"
90#include "grit/renderer_resources.h"
[email protected]ee68378a2010-08-10 01:05:4191#include "media/base/media_switches.h"
[email protected]f11ca0732009-04-11 00:09:3492#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2993#include "net/base/escape.h"
94#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0095#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1096#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3097#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:0698#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4999#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:26100#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:07101#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:49102#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:32104#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49105#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:35106#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]7a4de7a62010-08-17 18:38:24107#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]2b06a992010-08-21 05:48:22108#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
109#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
[email protected]b1438212010-04-03 00:30:59110#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49111#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
112#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
113#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41114#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50115#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49116#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32117#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07118#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49119#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40120#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17121#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49122#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49123#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
124#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
125#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
126#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
127#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
128#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40129#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49130#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34131#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49132#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
133#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
134#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
135#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
136#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
137#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26138#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11139#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04140#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]7a4de7a62010-08-17 18:38:24141#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29142#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59143#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24144#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24145#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34146#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26147#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17148#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51149#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09150#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26151#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38152#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17153#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29154#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30155#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23156#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30157#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40158#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09159#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24160#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29161#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29162#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17163#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29164
[email protected]6c8afae52009-01-22 02:24:57165#if defined(OS_WIN)
166// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57167// * theming
[email protected]cd818412010-03-19 03:23:15168#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03169#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46170#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33171#elif defined(OS_MACOSX)
172#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57173#endif
174
[email protected]80f584d92010-01-21 03:59:04175using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26176using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33177using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45178using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59179using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24180using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17181using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56182using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10183using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09184using webkit_glue::SiteIsolationMetrics;
[email protected]416ac2e2010-09-01 17:15:16185using webkit_glue::WebAccessibility;
[email protected]c7287a92009-11-04 20:06:15186using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08187using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21188using WebKit::WebApplicationCacheHost;
189using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41190using WebKit::WebColor;
191using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59192using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44193using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51194using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07195using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55196using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28197using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29198using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00199using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58200using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25201using WebKit::WebDragOperation;
202using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51203using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47204using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22205using WebKit::WebFileSystem;
206using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49207using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59208using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48209using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45210using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17211using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41212using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50213using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17214using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28215using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17216using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28217using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28218using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51219using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07220using WebKit::WebPageSerializer;
221using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17222using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40223using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49224using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09225using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52226using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59227using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51228using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52229using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40230using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35231using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29232using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59233using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42234using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02235using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34236using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28237using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51238using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52239using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28240using WebKit::WebURL;
241using WebKit::WebURLError;
242using WebKit::WebURLRequest;
243using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28244using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03245using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28246using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43247using WebKit::WebWorker;
248using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11249using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33250
initial.commit09911bf2008-07-26 23:55:29251//-----------------------------------------------------------------------------
252
[email protected]3354d3e2010-06-10 19:53:02253typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
254
initial.commit09911bf2008-07-26 23:55:29255// define to write the time necessary for thumbnail/DOM text retrieval,
256// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29257// #define TIME_TEXT_RETRIEVAL
258
259// maximum number of characters in the document to index, any text beyond this
260// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57261static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29262
263// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37264static const int kThumbnailWidth = 212;
265static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29266
267// Delay in milliseconds that we'll wait before capturing the page contents
268// and thumbnail.
269static const int kDelayForCaptureMs = 500;
270
271// Typically, we capture the page data once the page is loaded.
272// Sometimes, the page never finishes to load, preventing the page capture
273// To workaround this problem, we always perform a capture after the following
274// delay.
275static const int kDelayForForcedCaptureMs = 6000;
276
[email protected]882daa92009-11-05 16:31:31277// Time, in seconds, we delay before sending content state changes (such as form
278// state and scroll position) to the browser. We delay sending changes to avoid
279// spamming the browser.
280// To avoid having tab/session restore require sending a message to get the
281// current content state during tab closing we use a shorter timeout for the
282// foreground renderer. This means there is a small window of time from which
283// content state is modified and not sent to session restore, but this is
284// better than having to wake up all renderers during shutdown.
285static const int kDelaySecondsForContentStateSyncHidden = 5;
286static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29287
[email protected]0aa55312008-10-17 21:53:08288// The maximum number of popups that can be spawned from one page.
289static const int kMaximumNumberOfUnacknowledgedPopups = 25;
290
initial.commit09911bf2008-07-26 23:55:29291static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16292 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29293
[email protected]50b691c2008-10-31 19:08:35294static const char* const kBackForwardNavigationScheme = "history";
295
[email protected]726985e22009-06-18 21:09:28296static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
297 WebVector<WebURL> urls;
298 ds->redirectChain(urls);
299 result->reserve(urls.size());
300 for (size_t i = 0; i < urls.size(); ++i)
301 result->push_back(urls[i]);
302}
303
[email protected]61f5a7b2009-12-22 22:21:20304static bool UrlMatchesPermissions(
305 const GURL& url, const std::vector<URLPattern>& host_permissions) {
306 for (size_t i = 0; i < host_permissions.size(); ++i) {
307 if (host_permissions[i].MatchesUrl(url))
308 return true;
309 }
310
311 return false;
312}
313
[email protected]30507922010-01-15 16:48:23314static bool PaintViewIntoCanvas(WebView* view,
315 skia::PlatformCanvas& canvas) {
316 view->layout();
317 const WebSize& size = view->size();
318
319 if (!canvas.initialize(size.width, size.height, true))
320 return false;
321
322 view->paint(webkit_glue::ToWebCanvas(&canvas),
323 WebRect(0, 0, size.width, size.height));
324 // TODO: Add a way to snapshot the whole page, not just the currently
325 // visible part.
326
327 return true;
328}
329
330// Calculates how "boring" a thumbnail is. The boring score is the
331// 0,1 ranged percentage of pixels that are the most common
332// luma. Higher boring scores indicate that a higher percentage of a
333// bitmap are all the same brightness.
334static double CalculateBoringScore(SkBitmap* bitmap) {
335 int histogram[256] = {0};
336 color_utils::BuildLumaHistogram(bitmap, histogram);
337
338 int color_count = *std::max_element(histogram, histogram + 256);
339 int pixel_count = bitmap->width() * bitmap->height();
340 return static_cast<double>(color_count) / pixel_count;
341}
342
[email protected]12bc8472010-04-15 07:29:40343// True if |frame| contains content that is white-listed for content settings.
344static bool IsWhitelistedForContentSettings(WebFrame* frame) {
345 WebSecurityOrigin origin = frame->securityOrigin();
346 if (origin.isEmpty())
347 return false; // Uninitialized document?
348
349 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
350 return true; // Browser UI elements should still work.
351
352 // If the scheme is ftp: or file:, an empty file name indicates a directory
353 // listing, which requires JavaScript to function properly.
354 GURL frame_url = frame->url();
355 const char* kDirProtocols[] = { "ftp", "file" };
356 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
357 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
358 return frame_url.SchemeIs(kDirProtocols[i]) &&
359 frame_url.ExtractFileName().empty();
360 }
361 }
362
363 return false;
364}
365
[email protected]3a8eecb2010-04-22 23:56:30366// Returns true if the frame is navigating to an URL either into or out of an
367// extension app's extent.
368static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
369 if (!RenderThread::current())
370 return false;
371
372 // If the URL is still empty, this is a window.open navigation. Check the
373 // opener's URL.
374 GURL old_url(frame->url());
375 if (old_url.is_empty() && frame->opener())
376 old_url = frame->opener()->url();
377
[email protected]5351dbc2010-08-27 15:22:11378 return !ExtensionRendererInfo::InSameExtent(old_url, new_url);
[email protected]3a8eecb2010-04-22 23:56:30379}
380
[email protected]3354d3e2010-06-10 19:53:02381// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
382// if it failed.
[email protected]e5106202010-06-11 21:12:36383static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17384 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02385 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08386 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02387 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02388 Language cld_language =
[email protected]e5106202010-06-11 21:12:36389 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08390 &num_languages, NULL, &text_bytes);
391 // We don't trust the result if the CLD reports that the detection is not
392 // reliable, or if the actual text used to detect the language was less than
393 // 100 bytes (short texts can often lead to wrong results).
394 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02395 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
396 // We should not use LanguageCode_ISO_639_1 because it does not cover all
397 // the languages CLD can detect. As a result, it'll return the invalid
398 // language code for tradtional Chinese among others.
399 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
400 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
401 // for Simplified Chinese.
402 language = LanguageCodeWithDialects(cld_language);
403 }
404 return language;
405}
406
[email protected]2b06a992010-08-21 05:48:22407// Holds pending openFileSystem callbacks.
408struct RenderView::PendingOpenFileSystem {
409 explicit PendingOpenFileSystem(WebFileSystemCallbacks* c) : callbacks(c) {
410 }
411 ~PendingOpenFileSystem() {
412 if (callbacks)
413 callbacks->didFail(WebKit::WebFileErrorAbort);
414 }
415 WebFileSystemCallbacks* callbacks;
416};
417
initial.commit09911bf2008-07-26 23:55:29418///////////////////////////////////////////////////////////////////////////////
419
[email protected]60c42a8c72009-10-09 04:08:59420int32 RenderView::next_page_id_ = 1;
421
[email protected]cdaf8d02010-03-30 19:52:47422struct RenderView::PendingFileChooser {
423 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
424 WebFileChooserCompletion* c)
425 : params(p),
426 completion(c) {
427 }
428 ViewHostMsg_RunFileChooser_Params params;
429 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
430};
431
[email protected]2fab253a2009-08-17 23:00:59432RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34433 const WebPreferences& webkit_preferences,
434 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12435 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02436 webkit_preferences_(webkit_preferences),
437 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09438 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02439 send_preferred_size_changes_(false),
440 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24441 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21442 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02443 opened_by_user_gesture_(true),
444 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24445 page_id_(-1),
446 last_page_id_sent_to_browser_(-1),
447 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00448 history_list_offset_(-1),
449 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24450 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55451#if defined(OS_MACOSX)
452 has_document_tag_(false),
453#endif
[email protected]98324892009-09-09 21:16:05454 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10455 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17456 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02457 target_url_status_(TARGET_NONE),
458 spelling_panel_visible_(false),
459 view_type_(ViewType::INVALID),
460 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18461 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30462 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
463 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02464 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
465 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
466 ALLOW_THIS_IN_INITIALIZER_LIST(
467 notification_provider_(new NotificationProvider(this))),
468 session_storage_namespace_id_(session_storage_namespace_id),
469 decrement_shared_popup_at_destruction_(false) {
[email protected]6a8ddba52010-09-05 04:38:06470 password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this));
471 autofill_helper_.reset(new AutoFillHelper(this));
472 page_click_tracker_.reset(new PageClickTracker(this));
473 // Note that the order of insertion of the listeners is important.
474 // The password_autocomplete_manager_ takes the first shot at processing the
475 // notification and can stop the propagation.
476 page_click_tracker_->AddListener(password_autocomplete_manager_.get());
477 page_click_tracker_->AddListener(autofill_helper_.get());
[email protected]71b0d5d2010-02-15 05:43:07478 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29479}
480
481RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08482 if (decrement_shared_popup_at_destruction_)
483 shared_popup_counter_->data--;
484
[email protected]b0950a72009-09-29 23:16:17485 // Dispose of un-disposed image fetchers.
486 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
487 i != image_fetchers_.end(); ++i) {
488 delete *i;
489 }
490
[email protected]a1128322009-10-06 18:38:46491 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47492 while (!file_chooser_completions_.empty()) {
493 if (file_chooser_completions_.front()->completion) {
494 file_chooser_completions_.front()->completion->didChooseFile(
495 WebVector<WebString>());
496 }
497 file_chooser_completions_.pop_front();
498 }
[email protected]a1128322009-10-06 18:38:46499
[email protected]83dde542009-09-11 20:59:55500#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05501 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55502 if (has_document_tag_)
503 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
504#endif
[email protected]98324892009-09-09 21:16:05505
[email protected]5fb88962009-04-16 19:03:25506 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59507
508#ifndef NDEBUG
509 // Make sure we are no longer referenced by the ViewMap.
510 ViewMap* views = Singleton<ViewMap>::get();
511 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
512 DCHECK_NE(this, it->second) << "Failed to call Close?";
513#endif
514}
515
516/*static*/
517void RenderView::ForEach(RenderViewVisitor* visitor) {
518 ViewMap* views = Singleton<ViewMap>::get();
519 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
520 if (!visitor->Visit(it->second))
521 return;
522 }
523}
524
525/*static*/
526RenderView* RenderView::FromWebView(WebView* webview) {
527 ViewMap* views = Singleton<ViewMap>::get();
528 ViewMap::iterator it = views->find(webview);
529 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29530}
531
532/*static*/
[email protected]0aa55312008-10-17 21:53:08533RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24534 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15535 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08536 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51537 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08538 const WebPreferences& webkit_prefs,
539 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34540 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26541 int64 session_storage_namespace_id,
542 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29543 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34544 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
545 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29546 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29547 opener_id,
[email protected]80d96fa2009-06-10 22:34:51548 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08549 counter,
[email protected]8ab04652010-06-12 02:47:26550 routing_id,
551 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29552 return view;
553}
554
555/*static*/
556void RenderView::SetNextPageID(int32 next_page_id) {
557 // This method should only be called during process startup, and the given
558 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05559 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29560 DCHECK(next_page_id >= next_page_id_);
561 next_page_id_ = next_page_id;
562}
563
[email protected]8a3125a712010-08-09 18:58:51564WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26565 return static_cast<WebKit::WebView*>(webwidget());
566}
567
[email protected]afe3a1672009-11-17 19:04:12568void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56569 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
570}
571
[email protected]a3a8fb6d2009-10-22 20:12:51572void RenderView::PluginCrashed(const FilePath& plugin_path) {
573 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29574}
575
[email protected]aad51d1c2010-08-05 08:38:09576WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
577 const WebPluginParams& params) {
578 WebPluginInfo info;
579 bool found;
[email protected]55126132010-08-19 14:53:28580 ContentSetting setting;
[email protected]aad51d1c2010-08-05 08:38:09581 std::string mime_type;
582 Send(new ViewHostMsg_GetPluginInfo(
583 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
[email protected]55126132010-08-19 14:53:28584 &info, &setting, &mime_type));
[email protected]aad51d1c2010-08-05 08:38:09585 if (!found || !info.enabled)
586 return NULL;
587 scoped_refptr<pepper::PluginModule> pepper_module =
588 PepperPluginRegistry::GetInstance()->GetModule(info.path);
589 if (pepper_module)
590 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
591 else
592 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
593}
594
[email protected]d8fd6fa2010-02-01 15:54:26595#if defined(OS_MACOSX)
596void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
597 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30598 // If the renderer is visible, set initial visibility and focus state.
599 if (!is_hidden()) {
600 delegate->SetContainerVisibility(true);
601 if (webview() && webview()->isActive())
602 delegate->SetWindowFocus(true);
603 if (has_focus())
604 delegate->SetContentAreaFocus(true);
605 }
[email protected]d8fd6fa2010-02-01 15:54:26606}
607
608void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
609 plugin_delegates_.erase(delegate);
610}
611#endif
612
[email protected]18bcc3c2009-01-27 21:39:15613void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29614 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51615 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08616 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26617 int32 routing_id,
618 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29619 DCHECK(!webview());
620
621 if (opener_id != MSG_ROUTING_NONE)
622 opener_id_ = opener_id;
623
[email protected]0aa55312008-10-17 21:53:08624 if (counter) {
625 shared_popup_counter_ = counter;
626 shared_popup_counter_->data++;
627 decrement_shared_popup_at_destruction_ = true;
628 } else {
629 shared_popup_counter_ = new SharedRenderViewCounter(0);
630 decrement_shared_popup_at_destruction_ = false;
631 }
632
[email protected]58bfc6b2009-06-24 09:45:02633 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04634
[email protected]9a6c6232010-06-25 11:46:49635 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59636 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59637 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27638 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23639 if (!frame_name.empty())
640 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29641
[email protected]d3ba77272009-09-03 00:06:09642 OnSetRendererPrefs(renderer_prefs);
643
initial.commit09911bf2008-07-26 23:55:29644 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24645 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29646 // Take a reference on behalf of the RenderThread. This will be balanced
647 // when we receive ViewMsg_Close.
648 AddRef();
649
650 // If this is a popup, we must wait for the CreatingNew_ACK message before
651 // completing initialization. Otherwise, we can finish it now.
652 if (opener_id == MSG_ROUTING_NONE) {
653 did_show_ = true;
654 CompleteInit(parent_hwnd);
655 }
656
657 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29658
[email protected]58bfc6b2009-06-24 09:45:02659 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09660 if (command_line.HasSwitch(switches::kDomAutomationController))
661 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29662
[email protected]5fb88962009-04-16 19:03:25663 audio_message_filter_ = new AudioMessageFilter(routing_id_);
664 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29665}
666
667void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27668 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27669 if (main_frame)
670 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26671
[email protected]b2abac72009-02-26 12:39:28672 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11673 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28674 return;
[email protected]b4b967e2009-04-22 11:33:05675 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
676 return;
[email protected]b6849bda2009-10-14 23:59:26677 if (notification_provider_->OnMessageReceived(message))
678 return;
[email protected]58c321d2010-02-19 12:11:28679 if (geolocation_dispatcher_.get() &&
680 geolocation_dispatcher_->OnMessageReceived(message)) {
681 return;
682 }
[email protected]638694c2010-08-04 22:24:11683 if (speech_input_dispatcher_.get() &&
684 speech_input_dispatcher_->OnMessageReceived(message)) {
685 return;
686 }
[email protected]57ead352010-08-11 14:42:53687 if (device_orientation_dispatcher_.get() &&
688 device_orientation_dispatcher_->OnMessageReceived(message)) {
689 return;
690 }
[email protected]b2abac72009-02-26 12:39:28691
initial.commit09911bf2008-07-26 23:55:29692 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04693 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
694 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29695 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01696 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29697 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
698 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56699 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29700 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
701 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
702 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
703 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27704#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35705 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27706#endif
initial.commit09911bf2008-07-26 23:55:29707 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
708 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05709 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
710 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
711 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04712 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29713 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
714 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
715 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15716 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29717 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49718 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
719 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17720 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54721 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
722 OnSetContentSettingsForLoadingURL)
723 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
724 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29725 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18726 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
727 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28728 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33729 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29730 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48731 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29732 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29733 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29734 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
735 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
736 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
737 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
738 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45739 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29740 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50741 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
742 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29743 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
744 OnDragSourceSystemDragEnded)
745 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29746 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
747 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
748 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
749 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:21750 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:29751 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
752 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29753 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
754 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04755 IPC_MESSAGE_HANDLER(
756 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
757 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29758 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04759 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29760 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
761 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45762 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04763 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08764 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
765 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24766 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
767 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48768 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
769 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40770 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
771 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00772 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27773 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37774 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
775 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16776 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14777 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25778 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
779 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10780 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
781 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51782 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53783 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
784 OnUpdateBrowserWindowId)
785 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
786 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56787 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34788 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14789#if defined(OS_MACOSX)
790 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13791 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14792#endif
[email protected]446705872009-09-10 07:22:48793 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33794 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35795 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
796 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33797 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
798 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42799 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02800 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09801 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36802 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
803 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
804 OnAccessibilityDoDefaultAction)
[email protected]520cb7d72010-08-31 11:54:31805 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityObjectChildrenChange_ACK,
806 OnAccessibilityObjectChildrenChangeAck)
[email protected]2b06a992010-08-21 05:48:22807 IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete,
808 OnOpenFileSystemRequestComplete)
[email protected]27a9ef32010-09-10 04:06:24809 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]634a6f92008-12-01 21:39:31810
initial.commit09911bf2008-07-26 23:55:29811 // Have the super handle all other messages.
812 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
813 IPC_END_MESSAGE_MAP()
814}
815
[email protected]9b18a84f2010-06-10 15:54:04816void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27817 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29818 if (!main_frame)
819 return;
820
821 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45822 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29823 if (url.is_empty())
824 return;
825
826 if (size_.IsEmpty())
827 return; // Don't create an empty thumbnail!
828
829 ThumbnailScore score;
830 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02831 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15832 &thumbnail, &score))
833 return;
834
initial.commit09911bf2008-07-26 23:55:29835 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46836 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29837}
838
[email protected]9b18a84f2010-06-10 15:54:04839void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23840 SkBitmap snapshot;
841 bool error = false;
842
843 WebFrame* main_frame = webview()->mainFrame();
844 if (!main_frame)
845 error = true;
846
847 if (!error && !CaptureSnapshot(webview(), &snapshot))
848 error = true;
849
850 DCHECK(error == snapshot.empty()) <<
851 "Snapshot should be empty on error, non-empty otherwise.";
852
853 // Send the snapshot to the browser process.
854 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
855}
856
[email protected]068637222009-01-29 16:58:07857void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29858 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58859 if (webview()) {
860 // If the user has selected text in the currently focused frame we print
861 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27862 if (webview()->focusedFrame()->hasSelection())
863 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58864 else
[email protected]26aa0482009-09-30 16:55:27865 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58866 }
initial.commit09911bf2008-07-26 23:55:29867}
868
[email protected]82270452009-06-19 15:58:01869void RenderView::OnPrintingDone(int document_cookie, bool success) {
870 // Ignoring document cookie here since only one print job can be outstanding
871 // per renderer and document_cookie is 0 when printing is successful.
872 DCHECK(print_helper_.get());
873 if (print_helper_.get() != NULL) {
874 print_helper_->DidFinishPrinting(success);
875 }
876}
877
initial.commit09911bf2008-07-26 23:55:29878void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
879 if (load_id != page_id_)
880 return; // this capture call is no longer relevant due to navigation
881 if (load_id == last_indexed_page_id_)
882 return; // we already indexed this page
883
884 if (!webview())
885 return;
886
[email protected]26aa0482009-09-30 16:55:27887 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29888 if (!main_frame)
889 return;
890
891 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45892 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29893 return;
894
895 // Don't index/capture pages that failed to load. This only checks the top
896 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45897 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28898 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29899 return;
900
901 if (!preliminary_capture)
902 last_indexed_page_id_ = load_id;
903
[email protected]a8a81292010-01-21 00:32:45904 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45905 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29906 if (url.is_empty())
907 return;
908
[email protected]a8a81292010-01-21 00:32:45909 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36910 string16 contents;
initial.commit09911bf2008-07-26 23:55:29911 CaptureText(main_frame, &contents);
912 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:10913 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:37914 // If the page explicitly specifies a language, use it, otherwise we'll
915 // determine it based on the text content using the CLD.
916 std::string language =
917 TranslateHelper::GetPageLanguageFromMetaTag(&document);
918 if (language.empty()) {
919 base::TimeTicks begin_time = base::TimeTicks::Now();
920 language = DetermineTextLanguage(contents);
921 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
922 base::TimeTicks::Now() - begin_time);
923 }
[email protected]a8a81292010-01-21 00:32:45924 // Send the text to the browser for indexing (the browser might decide not
925 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:37926 Send(new ViewHostMsg_PageContents(
927 routing_id_, url, load_id, contents, language,
928 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27929 }
930
[email protected]9b18a84f2010-06-10 15:54:04931 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29932}
933
[email protected]e5106202010-06-11 21:12:36934void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29935 contents->clear();
936 if (!frame)
937 return;
938
939#ifdef TIME_TEXT_RETRIEVAL
940 double begin = time_util::GetHighResolutionTimeNow();
941#endif
942
943 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36944 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29945
946#ifdef TIME_TEXT_RETRIEVAL
947 double end = time_util::GetHighResolutionTimeNow();
948 char buf[128];
949 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
950 contents.size(), (end - begin)*1000);
951 OutputDebugStringA(buf);
952#endif
953
954 // When the contents are clipped to the maximum, we don't want to have a
955 // partial word indexed at the end that might have been clipped. Therefore,
956 // terminate the string at the last space to ensure no words are clipped.
957 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36958 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29959 if (last_space_index == std::wstring::npos)
960 return; // don't index if we got a huge block of text with no spaces
961 contents->resize(last_space_index);
962 }
963}
964
[email protected]8649fb32009-06-26 17:51:02965bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29966 int w,
967 int h,
968 SkBitmap* thumbnail,
969 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23970 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15971
[email protected]8649fb32009-06-26 17:51:02972 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23973
974 // Paint |view| into |canvas|.
975 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02976 return false;
[email protected]8649fb32009-06-26 17:51:02977
978 skia::BitmapPlatformDevice& device =
979 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
980
981 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29982
[email protected]cab34d6a2009-09-24 01:14:52983 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29984 float dest_aspect = dest_rect.width() / dest_rect.height();
985
986 // Get the src rect so that we can preserve the aspect ratio while filling
987 // the destination.
988 SkIRect src_rect;
989 if (src_bmp.width() < dest_rect.width() ||
990 src_bmp.height() < dest_rect.height()) {
991 // Source image is smaller: we clip the part of source image within the
992 // dest rect, and then stretch it to fill the dest rect. We don't respect
993 // the aspect ratio in this case.
994 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
995 static_cast<S16CPU>(dest_rect.height()));
996 score->good_clipping = false;
997 } else {
998 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
999 if (src_aspect > dest_aspect) {
1000 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1001 // the wider screen.
1002 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1003 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1004 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1005 score->good_clipping = false;
1006 } else {
1007 src_rect.set(0, 0, src_bmp.width(),
1008 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1009 score->good_clipping = true;
1010 }
1011 }
1012
[email protected]26aa0482009-09-30 16:55:271013 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291014
1015 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021016 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291017
1018 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:141019 *thumbnail = skia::ImageOperations::Resize(
1020 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291021
1022 score->boring_score = CalculateBoringScore(thumbnail);
1023
[email protected]30507922010-01-15 16:48:231024 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1025 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:151026 return true;
initial.commit09911bf2008-07-26 23:55:291027}
1028
[email protected]30507922010-01-15 16:48:231029bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1030 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291031
[email protected]30507922010-01-15 16:48:231032 skia::PlatformCanvas canvas;
1033 if (!PaintViewIntoCanvas(view, canvas))
1034 return false;
1035
1036 skia::BitmapPlatformDevice& device =
1037 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1038
1039 const SkBitmap& bitmap = device.accessBitmap(false);
1040 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1041 return false;
1042
1043 HISTOGRAM_TIMES("Renderer4.Snapshot",
1044 base::TimeTicks::Now() - beginning_time);
1045 return true;
initial.commit09911bf2008-07-26 23:55:291046}
1047
1048void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1049 if (!webview())
1050 return;
1051
[email protected]3cc72b12010-03-18 23:03:001052 history_list_offset_ = params.current_history_list_offset;
1053 history_list_length_ = params.current_history_list_length;
1054
[email protected]8c785c62009-07-13 14:20:151055 if (devtools_agent_.get())
1056 devtools_agent_->OnNavigate();
1057
[email protected]422197532010-01-25 17:38:231058 if (notification_provider_.get())
1059 notification_provider_->OnNavigate();
1060
[email protected]a9f607e2009-10-23 19:59:271061 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261062
initial.commit09911bf2008-07-26 23:55:291063 AboutHandler::MaybeHandle(params.url);
1064
[email protected]ecbf10d2010-02-18 13:03:291065 bool is_reload =
1066 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1067 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291068
[email protected]26aa0482009-09-30 16:55:271069 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451070 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291071 // We cannot reload if we do not have any history state. This happens, for
1072 // example, when recovering from a crash. Our workaround here is a bit of
1073 // a hack since it means that reload after a crashed tab does not cause an
1074 // end-to-end cache validation.
1075 is_reload = false;
1076 }
1077
[email protected]77f17a82009-05-21 04:42:541078 // A navigation resulting from loading a javascript URL should not be treated
1079 // as a browser initiated event. Instead, we want it to look as if the page
1080 // initiated any load resulting from JS execution.
1081 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301082 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001083 params.page_id,
1084 params.pending_history_list_offset,
1085 params.transition,
1086 params.request_time);
[email protected]5e369672009-11-03 23:48:301087 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1088 // We're doing a load of a page that was restored from the last session.
1089 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1090 // which can result in stale data for pages that are set to expire. We
1091 // explicitly override that by setting the policy here so that as
1092 // necessary we load from the network.
1093 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1094 }
1095 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541096 }
initial.commit09911bf2008-07-26 23:55:291097
[email protected]a7ccc4d2010-01-27 08:14:481098 NavigationState* navigation_state = pending_navigation_state_.get();
1099
[email protected]04d3c6e2009-05-22 17:00:131100 // If we are reloading, then WebKit will use the history state of the current
1101 // page, so we should just ignore any given history state. Otherwise, if we
1102 // have history state, then we need to navigate to it, which corresponds to a
1103 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551104 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481105 if (navigation_state)
1106 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291107 bool ignore_cache = (params.navigation_type ==
1108 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1109 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551110 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131111 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581112 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481113 if (navigation_state)
1114 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451115 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171116 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131117 } else {
1118 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281119 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291120
[email protected]e6f546c32009-07-01 17:12:551121 // A session history navigation should have been accompanied by state.
1122 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131123
[email protected]dd7daa82009-08-10 05:46:451124 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551125 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131126
[email protected]726985e22009-06-18 21:09:281127 if (params.referrer.is_valid()) {
1128 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1129 WebString::fromUTF8(params.referrer.spec()));
1130 }
[email protected]04d3c6e2009-05-22 17:00:131131
[email protected]a7ccc4d2010-01-27 08:14:481132 if (navigation_state)
1133 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451134 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501135 }
1136
[email protected]77f17a82009-05-21 04:42:541137 // In case LoadRequest failed before DidCreateDataSource was called.
1138 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291139}
1140
1141// Stop loading the current page
1142void RenderView::OnStop() {
1143 if (webview())
[email protected]b4bb2502009-10-01 22:35:271144 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291145}
1146
[email protected]ecbf10d2010-02-18 13:03:291147// Reload current focused frame.
1148// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561149void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291150 if (webview() && webview()->focusedFrame()) {
1151 // We always obey the cache (ignore_cache=false) here.
1152 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1153 // a cache-ignoring reload of the frame.
1154 webview()->focusedFrame()->reload(false);
1155 }
[email protected]1dda4022010-01-28 18:24:561156}
1157
initial.commit09911bf2008-07-26 23:55:291158void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271159 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291160}
1161
[email protected]68b1e922009-06-23 16:00:251162void RenderView::OnExecuteEditCommand(const std::string& name,
1163 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271164 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251165 return;
1166
[email protected]26aa0482009-09-30 16:55:271167 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451168 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251169}
1170
[email protected]b2abac72009-02-26 12:39:281171void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111172 DCHECK(!devtools_client_.get());
1173 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281174}
1175
initial.commit09911bf2008-07-26 23:55:291176void RenderView::OnUpdateTargetURLAck() {
1177 // Check if there is a targeturl waiting to be sent.
1178 if (target_url_status_ == TARGET_PENDING) {
1179 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1180 pending_target_url_));
1181 }
1182
1183 target_url_status_ = TARGET_NONE;
1184}
1185
1186void RenderView::OnUndo() {
1187 if (!webview())
1188 return;
1189
[email protected]26aa0482009-09-30 16:55:271190 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121191 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291192}
1193
1194void RenderView::OnRedo() {
1195 if (!webview())
1196 return;
1197
[email protected]26aa0482009-09-30 16:55:271198 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121199 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291200}
1201
1202void RenderView::OnCut() {
1203 if (!webview())
1204 return;
1205
[email protected]26aa0482009-09-30 16:55:271206 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121207 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291208}
1209
1210void RenderView::OnCopy() {
1211 if (!webview())
1212 return;
1213
[email protected]26aa0482009-09-30 16:55:271214 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121215 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291216}
1217
[email protected]c0cc3092009-09-12 08:27:271218#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351219void RenderView::OnCopyToFindPboard() {
1220 if (!webview())
1221 return;
1222
1223 // Since the find pasteboard supports only plain text, this can be simpler
1224 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271225 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351226 if (frame->hasSelection()) {
1227 string16 selection = frame->selectionAsText();
1228 RenderThread::current()->Send(
1229 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1230 }
1231
[email protected]afe3a1672009-11-17 19:04:121232 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351233}
[email protected]c0cc3092009-09-12 08:27:271234#endif
[email protected]a954bf72009-09-12 07:30:351235
initial.commit09911bf2008-07-26 23:55:291236void RenderView::OnPaste() {
1237 if (!webview())
1238 return;
1239
[email protected]26aa0482009-09-30 16:55:271240 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121241 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291242}
1243
[email protected]2a3a7762009-10-19 19:17:321244void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291245 if (!webview())
1246 return;
1247
[email protected]1ff7a032010-02-03 02:46:031248 WebFrame* frame = webview()->focusedFrame();
1249 if (!frame->hasSelection())
1250 frame->selectWordAroundCaret();
1251 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291252}
1253
[email protected]98324892009-09-09 21:16:051254void RenderView::OnAdvanceToNextMisspelling() {
1255 if (!webview())
1256 return;
[email protected]26aa0482009-09-30 16:55:271257 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051258 WebString::fromUTF8("AdvanceToNextMisspelling"));
1259}
1260
1261void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1262 if (!webview())
1263 return;
1264 // We need to tell the webView whether the spelling panel is visible or not so
1265 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261266 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271267 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051268 WebString::fromUTF8("ToggleSpellPanel"));
1269}
1270
[email protected]bbbd545c2008-12-15 20:18:041271void RenderView::OnToggleSpellCheck() {
1272 if (!webview())
1273 return;
1274
[email protected]26aa0482009-09-30 16:55:271275 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451276 frame->enableContinuousSpellChecking(
1277 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041278}
1279
initial.commit09911bf2008-07-26 23:55:291280void RenderView::OnDelete() {
1281 if (!webview())
1282 return;
1283
[email protected]26aa0482009-09-30 16:55:271284 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121285 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291286}
1287
1288void RenderView::OnSelectAll() {
1289 if (!webview())
1290 return;
1291
[email protected]26aa0482009-09-30 16:55:271292 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221293 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121294 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291295}
1296
1297void RenderView::OnSetInitialFocus(bool reverse) {
1298 if (!webview())
1299 return;
[email protected]26aa0482009-09-30 16:55:271300 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291301}
1302
1303///////////////////////////////////////////////////////////////////////////////
1304
[email protected]433819d2010-01-30 20:20:011305void RenderView::SetContentSettings(const ContentSettings& settings) {
1306 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011307}
1308
initial.commit09911bf2008-07-26 23:55:291309// Tell the embedding application that the URL of the active page has changed
1310void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451311 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291312 DCHECK(ds);
1313
[email protected]726985e22009-06-18 21:09:281314 const WebURLRequest& request = ds->request();
1315 const WebURLRequest& original_request = ds->originalRequest();
1316 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291317
[email protected]daa8c58e2009-06-15 17:21:101318 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1319 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291320
1321 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281322 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291323 params.is_post = false;
1324 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281325 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091326 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551327 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291328 // SSL state specified in the request takes precedence over the one in the
1329 // response.
1330 // So far this is only intended for error pages that are not expected to be
1331 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281332 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551333 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291334 } else {
[email protected]726985e22009-06-18 21:09:281335 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291336 }
1337
1338 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281339 if (ds->hasUnreachableURL()) {
1340 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291341 } else {
[email protected]726985e22009-06-18 21:09:281342 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291343 }
1344
[email protected]726985e22009-06-18 21:09:281345 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241346 params.should_update_history = !ds->hasUnreachableURL() &&
1347 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291348
[email protected]ce0e250d2009-10-23 21:00:351349 params.searchable_form_url = navigation_state->searchable_form_url();
1350 params.searchable_form_encoding =
1351 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291352
1353 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101354 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291355 if (password_form_data)
1356 params.password_form = *password_form_data;
1357
1358 params.gesture = navigation_gesture_;
1359 navigation_gesture_ = NavigationGestureUnknown;
1360
[email protected]dd7daa82009-08-10 05:46:451361 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291362 // Top-level navigation.
1363
[email protected]71b0d5d2010-02-15 05:43:071364 // Clear "block" flags for the new page. This needs to happen before any of
1365 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1366 // so that these functions can correctly detect that a piece of content
1367 // flipped from "not blocked" to "blocked".
1368 ClearBlockedContentSettings();
1369
[email protected]62d2a112010-04-07 00:53:021370 // Set content settings. Default them from the parent window if one exists.
1371 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011372 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541373 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011374 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011375 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011376
1377 // These content settings were merely recorded transiently for this load.
1378 // We can erase them now. If at some point we reload this page, the
1379 // browser will send us new, up-to-date content settings.
1380 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401381 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101382 // The opener's view is not guaranteed to be non-null (it could be
1383 // detached from its page but not yet destructed).
1384 if (WebView* opener_view = frame->opener()->view()) {
1385 RenderView* opener = FromWebView(opener_view);
1386 SetContentSettings(opener->current_content_settings_);
1387 }
[email protected]f85f0702010-01-30 09:31:011388 }
1389
[email protected]40bd6582009-12-04 23:49:511390 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011391 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541392 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011393 if (host_zoom != host_zoom_levels_.end()) {
1394 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511395 // This zoom level was merely recorded transiently for this load. We can
1396 // erase it now. If at some point we reload this page, the browser will
1397 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011398 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511399 }
1400
initial.commit09911bf2008-07-26 23:55:291401 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551402 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291403
[email protected]daa8c58e2009-06-15 17:21:101404 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291405 if (!PageTransition::IsMainFrame(params.transition)) {
1406 // If the main frame does a load, it should not be reported as a subframe
1407 // navigation. This can occur in the following case:
1408 // 1. You're on a site with frames.
1409 // 2. You do a subframe navigation. This is stored with transition type
1410 // MANUAL_SUBFRAME.
1411 // 3. You navigate to some non-frame site, say, google.com.
1412 // 4. You navigate back to the page from step 2. Since it was initially
1413 // MANUAL_SUBFRAME, it will be that same transition type here.
1414 // We don't want that, because any navigation that changes the toplevel
1415 // frame should be tracked as a toplevel navigation (this allows us to
1416 // update the URL bar, etc).
1417 params.transition = PageTransition::LINK;
1418 }
1419
initial.commit09911bf2008-07-26 23:55:291420 // If we have a valid consumed client redirect source,
1421 // the page contained a client redirect (meta refresh, document.loc...),
1422 // so we set the referrer and transition to match.
1423 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041424 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291425 params.referrer = completed_client_redirect_src_;
1426 params.transition = static_cast<PageTransition::Type>(
1427 params.transition | PageTransition::CLIENT_REDIRECT);
1428 } else {
1429 // Bug 654101: the referrer will be empty on https->http transitions. It
1430 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281431 params.referrer = GURL(
1432 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291433 }
1434
[email protected]726985e22009-06-18 21:09:281435 string16 method = request.httpMethod();
1436 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291437 params.is_post = true;
1438
[email protected]c2a797d2009-09-21 16:46:321439 // Save some histogram data so we can compute the average memory used per
1440 // page load of the glyphs.
1441 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1442 webkit_glue::GetGlyphPageCount());
1443
[email protected]15cf526b2010-02-12 06:33:491444 // This message needs to be sent before any of allowScripts(),
1445 // allowImages(), allowPlugins() is called for the new page, so that when
1446 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1447 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291448 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1449 } else {
1450 // Subframe navigation: the type depends on whether this navigation
1451 // generated a new session history entry. When they do generate a session
1452 // history entry, it means the user initiated the navigation and we should
1453 // mark it as such. This test checks if this is the first time UpdateURL
1454 // has been called since WillNavigateToURL was called to initiate the load.
1455 if (page_id_ > last_page_id_sent_to_browser_)
1456 params.transition = PageTransition::MANUAL_SUBFRAME;
1457 else
1458 params.transition = PageTransition::AUTO_SUBFRAME;
1459
initial.commit09911bf2008-07-26 23:55:291460 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1461 }
1462
1463 last_page_id_sent_to_browser_ =
1464 std::max(last_page_id_sent_to_browser_, page_id_);
1465
1466 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101467 // we don't want the transition type to persist. Just clear it.
1468 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501469
[email protected]af15bed2010-08-25 21:12:091470 // Check if the navigation was within the same page, in which case we don't
1471 // want to clear the accessibility cache.
1472 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]b3df5a42010-05-11 14:31:091473 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351474 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501475 }
[email protected]520cb7d72010-08-31 11:54:311476 accessibility_changes_.clear();
initial.commit09911bf2008-07-26 23:55:291477}
1478
1479// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171480void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291481 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171482 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171483 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171484 routing_id_,
1485 page_id_,
1486 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1487 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171488 }
initial.commit09911bf2008-07-26 23:55:291489}
1490
1491void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401492 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291493 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271494 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291495 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301496 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291497 last_encoding_name_ = encoding_name;
1498
[email protected]e38f40152008-09-12 23:08:301499 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291500 }
1501}
1502
[email protected]f4d34b52008-11-24 23:05:011503// Sends the previous session history state to the browser so it will be saved
1504// before we navigate to a new page. This must be called *before* the page ID
1505// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291506void RenderView::UpdateSessionHistory(WebFrame* frame) {
1507 // If we have a valid page ID at this point, then it corresponds to the page
1508 // we are navigating away from. Otherwise, this is the first navigation, so
1509 // there is no past session history to record.
1510 if (page_id_ == -1)
1511 return;
1512
[email protected]ca948a22009-06-25 19:36:171513 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271514 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171515 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291516 return;
[email protected]ca948a22009-06-25 19:36:171517
1518 Send(new ViewHostMsg_UpdateState(
1519 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291520}
1521
[email protected]3d9689372009-09-10 04:29:171522void RenderView::OpenURL(
1523 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1524 Send(new ViewHostMsg_OpenURL(
1525 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1526}
1527
[email protected]79dbc662009-09-04 05:42:511528// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291529
initial.commit09911bf2008-07-26 23:55:291530void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281531 const WebURLRequest& failed_request,
1532 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291533 const std::string& html,
1534 bool replace) {
[email protected]726985e22009-06-18 21:09:281535 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291536 std::string alt_html;
[email protected]07b493512010-08-27 15:39:291537 ExtensionRendererInfo* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291538 if (html.empty()) {
1539 // Use a local error page.
1540 int resource_id;
1541 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111542
1543 if (failed_url.is_valid())
1544 extension = ExtensionRendererInfo::GetByURL(failed_url);
1545 if (extension) {
[email protected]3f853a52010-09-13 19:15:081546 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1547 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111548
1549 // TODO(erikkay): Should we use a different template for different
1550 // error messages?
1551 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291552 } else {
[email protected]3f853a52010-09-13 19:15:081553 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1554 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111555 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081556 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111557 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1558 } else {
[email protected]3f853a52010-09-13 19:15:081559 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111560 resource_id = IDR_NET_ERROR_HTML;
1561 }
initial.commit09911bf2008-07-26 23:55:291562 }
initial.commit09911bf2008-07-26 23:55:291563
1564 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1565 } else {
1566 alt_html = html;
1567 }
1568
[email protected]dd7daa82009-08-10 05:46:451569 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551570 GURL(kUnreachableWebDataURL),
1571 failed_url,
1572 replace);
initial.commit09911bf2008-07-26 23:55:291573}
1574
[email protected]7ccddb8c2009-08-04 17:36:551575void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291576 dom_automation_controller_.set_message_sender(this);
1577 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551578 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291579 L"domAutomationController");
1580}
1581
initial.commit09911bf2008-07-26 23:55:291582bool RenderView::RunJavaScriptMessage(int type,
1583 const std::wstring& message,
1584 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071585 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291586 std::wstring* result) {
1587 bool success = false;
1588 std::wstring result_temp;
1589 if (!result)
1590 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291591
[email protected]12636df2009-09-28 22:32:211592 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1593 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291594 return success;
1595}
1596
[email protected]c1f50aa2010-02-18 03:46:571597bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1598 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1599 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1600 // it is particularly important that we do not call willEnterModalLoop as
1601 // that would defer resource loads for the dialog itself.
1602 if (RenderThread::current()) // Will be NULL during unit tests.
1603 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1604
1605 message->EnableMessagePumping(); // Runs a nested message loop.
1606 return Send(message);
1607}
1608
initial.commit09911bf2008-07-26 23:55:291609void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1610 if (!osd_url.is_empty())
1611 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1612 autodetected));
1613}
1614
[email protected]95056b582010-02-18 01:29:241615void RenderView::OnAutoFillSuggestionsReturned(
1616 int query_id,
[email protected]8f6e6582010-04-09 02:03:071617 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391618 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411619 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391620 const std::vector<int>& unique_ids) {
[email protected]6a8ddba52010-09-05 04:38:061621 autofill_helper_->SuggestionsReceived(
[email protected]a53e06832010-07-28 22:46:411622 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031623}
1624
[email protected]45c6e532010-03-15 23:51:241625void RenderView::OnAutoFillFormDataFilled(int query_id,
1626 const webkit_glue::FormData& form) {
[email protected]6a8ddba52010-09-05 04:38:061627 autofill_helper_->FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481628}
1629
[email protected]e8345242010-05-06 03:00:401630void RenderView::OnAllowScriptToClose(bool script_can_close) {
1631 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311632}
1633
initial.commit09911bf2008-07-26 23:55:291634uint32 RenderView::GetCPBrowsingContext() {
1635 uint32 context = 0;
1636 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1637 return context;
1638}
1639
initial.commit09911bf2008-07-26 23:55:291640void RenderView::AddSearchProvider(const std::string& url) {
1641 AddGURLSearchProvider(GURL(url),
1642 false); // not autodetected
1643}
1644
[email protected]155f35e2010-07-17 00:30:181645ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251646RenderView::GetSearchProviderInstallState(WebFrame* frame,
1647 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181648 GURL inquiry_url = GURL(url);
1649 if (inquiry_url.is_empty())
1650 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251651
[email protected]155f35e2010-07-17 00:30:181652 ViewHostMsg_GetSearchProviderInstallState_Params install;
1653 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:251654 frame->url(),
[email protected]155f35e2010-07-17 00:30:181655 inquiry_url,
1656 &install));
1657 return install;
1658}
1659
[email protected]f103ab72009-09-02 17:10:591660void RenderView::OnMissingPluginStatus(
1661 WebPluginDelegateProxy* delegate,
1662 int status) {
[email protected]6c8afae52009-01-22 02:24:571663#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591664 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291665 // Show the InfoBar for the first available plugin.
1666 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591667 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291668 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1669 }
1670 } else {
1671 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1672 // to start the download/install.
1673 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1674 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1675 }
1676 }
[email protected]6c8afae52009-01-22 02:24:571677#else
[email protected]76c3b312010-05-20 21:38:291678 // TODO(port): Implement the infobar that accompanies the default plugin.
1679 // Linux: http://crbug.com/10952
1680 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571681 NOTIMPLEMENTED();
1682#endif
initial.commit09911bf2008-07-26 23:55:291683}
1684
[email protected]48c9cf2d2009-09-16 16:47:521685// WebKit::WebViewClient ------------------------------------------------------
1686
[email protected]8ab04652010-06-12 02:47:261687WebView* RenderView::createView(
1688 WebFrame* creator,
1689 const WebWindowFeatures& features,
1690 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521691 // Check to make sure we aren't overloading on popups.
1692 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1693 return NULL;
1694
1695 // This window can't be closed from a window.close() call until we receive a
1696 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401697 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521698
[email protected]8ab04652010-06-12 02:47:261699 ViewHostMsg_CreateWindow_Params params;
1700 params.opener_id = routing_id_;
1701 params.user_gesture = creator->isProcessingUserGesture();
1702 params.window_container_type = WindowFeaturesToContainerType(features);
1703 params.session_storage_namespace_id = session_storage_namespace_id_;
1704 params.frame_name = frame_name;
1705
[email protected]48c9cf2d2009-09-16 16:47:521706 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341707 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261708 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521709
[email protected]48c9cf2d2009-09-16 16:47:521710 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261711 new ViewHostMsg_CreateWindow(params,
1712 &routing_id,
1713 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211714 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521715 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521716
[email protected]48c9cf2d2009-09-16 16:47:521717 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421718 0,
[email protected]12636df2009-09-28 22:32:211719 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521720 renderer_preferences_,
1721 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211722 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341723 routing_id,
[email protected]8ab04652010-06-12 02:47:261724 cloned_session_storage_namespace_id,
1725 frame_name);
1726 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521727
[email protected]007a848b2009-10-26 15:55:461728 // Record whether the creator frame is trying to suppress the opener field.
1729 view->opener_suppressed_ = opener_suppressed;
1730
[email protected]48c9cf2d2009-09-16 16:47:521731 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091732 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521733 if (!creator_url.is_valid() || !creator_url.IsStandard())
1734 creator_url = GURL();
1735 view->creator_url_ = creator_url;
1736
1737 // Copy over the alternate error page URL so we can have alt error pages in
1738 // the new render view (we don't need the browser to send the URL back down).
1739 view->alternate_error_page_url_ = alternate_error_page_url_;
1740
1741 return view->webview();
1742}
1743
[email protected]3e2b375b2010-04-07 17:03:121744WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521745 RenderWidget* widget = RenderWidget::Create(routing_id_,
1746 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121747 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521748 return widget->webwidget();
1749}
1750
1751WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1752 RenderWidget* widget = RenderWidget::Create(routing_id_,
1753 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121754 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521755 widget->ConfigureAsExternalPopupMenu(info);
1756 return widget->webwidget();
1757}
1758
[email protected]484955942010-08-19 16:13:181759WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
1760 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
1761 render_thread_,
1762 popup_type);
1763 return widget->webwidget();
1764}
1765
[email protected]68c50e52010-05-12 11:14:391766WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341767 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391768 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291769 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1770 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1771 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341772}
1773
[email protected]48c9cf2d2009-09-16 16:47:521774void RenderView::didAddMessageToConsole(
1775 const WebConsoleMessage& message, const WebString& source_name,
1776 unsigned source_line) {
1777 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1778 UTF16ToWideHack(message.text),
1779 static_cast<int32>(source_line),
1780 UTF16ToWideHack(source_name)));
1781}
1782
1783void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581784 DCHECK(frame);
1785 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521786}
1787
[email protected]3354d3e2010-06-10 19:53:021788WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1789 return notification_provider_.get();
1790}
1791
[email protected]48c9cf2d2009-09-16 16:47:521792void RenderView::didStartLoading() {
1793 if (is_loading_) {
1794 DLOG(WARNING) << "didStartLoading called while loading";
1795 return;
1796 }
1797
1798 is_loading_ = true;
1799 // Clear the pointer so that we can assign it only when there is an unknown
1800 // plugin on a page.
1801 first_default_plugin_.reset();
1802
1803 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1804}
1805
1806void RenderView::didStopLoading() {
1807 if (!is_loading_) {
1808 DLOG(WARNING) << "DidStopLoading called while not loading";
1809 return;
1810 }
1811
1812 is_loading_ = false;
1813
1814 // NOTE: For now we're doing the safest thing, and sending out notification
1815 // when done loading. This currently isn't an issue as the favicon is only
1816 // displayed when done loading. Ideally we would send notification when
1817 // finished parsing the head, but webkit doesn't support that yet.
1818 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271819 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521820 if (!favicon_url.is_empty())
1821 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1822
[email protected]26aa0482009-09-30 16:55:271823 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521824 true); // autodetected
1825
1826 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1827
[email protected]f9f4841b2010-03-20 05:41:421828 MessageLoop::current()->PostDelayedTask(
1829 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:301830 page_info_method_factory_.NewRunnableMethod(
1831 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:371832 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521833}
1834
[email protected]f55039a2010-02-17 14:12:061835bool RenderView::isSmartInsertDeleteEnabled() {
1836#if defined(OS_MACOSX)
1837 return true;
1838#else
1839 return false;
1840#endif
1841}
1842
[email protected]04fc9482009-09-18 22:13:031843bool RenderView::isSelectTrailingWhitespaceEnabled() {
1844#if defined(OS_WIN)
1845 return true;
1846#else
1847 return false;
1848#endif
1849}
1850
[email protected]04fc9482009-09-18 22:13:031851void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]eef99c22010-08-17 05:55:161852#if defined(USE_X11) || defined(OS_MACOSX)
[email protected]04fc9482009-09-18 22:13:031853 if (!handling_input_event_)
1854 return;
1855 // TODO(estade): investigate incremental updates to the selection so that we
1856 // don't send the entire selection over IPC every time.
1857 if (!is_empty_selection) {
1858 // Sometimes we get repeated didChangeSelection calls from webkit when
1859 // the selection hasn't actually changed. We don't want to report these
1860 // because it will cause us to continually claim the X clipboard.
1861 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271862 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031863 if (this_selection == last_selection_)
1864 return;
1865
1866 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1867 this_selection));
1868 last_selection_ = this_selection;
1869 } else {
1870 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:161871 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1872 last_selection_));
[email protected]04fc9482009-09-18 22:13:031873 }
1874#endif
1875}
1876
1877void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121878 const std::string& name = UTF16ToUTF8(command_name);
1879 if (StartsWithASCII(name, "Move", true) ||
1880 StartsWithASCII(name, "Insert", true) ||
1881 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031882 return;
1883 UserMetricsRecordAction(name);
1884}
1885
[email protected]03f57072010-07-14 17:36:081886void RenderView::textFieldDidEndEditing(
1887 const WebKit::WebInputElement& element) {
1888#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061889 password_autocomplete_manager_->TextFieldDidEndEditing(element);
[email protected]03f57072010-07-14 17:36:081890#endif
1891}
1892
1893void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1894#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]e47aec52010-08-12 00:50:301895 // We post a task for doing the AutoFill as the caret position is not set
1896 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
1897 // it is needed to trigger autofill.
1898 autofill_method_factory_.RevokeAll();
1899 MessageLoop::current()->PostTask(
1900 FROM_HERE,
1901 autofill_method_factory_.NewRunnableMethod(
1902 &RenderView::TextFieldDidChangeImpl, element));
[email protected]03f57072010-07-14 17:36:081903#endif
1904}
1905
[email protected]e47aec52010-08-12 00:50:301906void RenderView::TextFieldDidChangeImpl(
1907 const WebKit::WebInputElement& element) {
[email protected]6a8ddba52010-09-05 04:38:061908 if (password_autocomplete_manager_->TextDidChangeInTextField(element))
[email protected]e47aec52010-08-12 00:50:301909 return;
[email protected]6a8ddba52010-09-05 04:38:061910 autofill_helper_->TextDidChangeInTextField(element);
[email protected]e47aec52010-08-12 00:50:301911}
1912
[email protected]03f57072010-07-14 17:36:081913void RenderView::textFieldDidReceiveKeyDown(
1914 const WebKit::WebInputElement& element,
1915 const WebKit::WebKeyboardEvent& event) {
1916#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061917 password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event);
[email protected]03f57072010-07-14 17:36:081918#endif
1919}
1920
[email protected]b2528b72009-09-24 06:57:101921bool RenderView::handleCurrentKeyboardEvent() {
1922 if (edit_commands_.empty())
1923 return false;
1924
[email protected]26aa0482009-09-30 16:55:271925 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101926 if (!frame)
1927 return false;
1928
1929 EditCommands::iterator it = edit_commands_.begin();
1930 EditCommands::iterator end = edit_commands_.end();
1931
[email protected]507b33ea2009-09-29 03:56:511932 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101933 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331934 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1935 // key (but it's the exception). Once one edit command is not executed, it
1936 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101937 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1938 WebString::fromUTF8(it->value)))
1939 break;
[email protected]507b33ea2009-09-29 03:56:511940 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101941 }
1942
[email protected]507b33ea2009-09-29 03:56:511943 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101944}
1945
[email protected]e47aec52010-08-12 00:50:301946void RenderView::inputElementClicked(const WebKit::WebInputElement& element,
1947 bool already_focused) {
1948#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061949 if (password_autocomplete_manager_->InputElementClicked(element,
1950 already_focused)) {
[email protected]e47aec52010-08-12 00:50:301951 return;
1952 }
[email protected]6a8ddba52010-09-05 04:38:061953 autofill_helper_->InputElementClicked(element, already_focused);
[email protected]e47aec52010-08-12 00:50:301954#endif
1955}
1956
[email protected]2a3a7762009-10-19 19:17:321957void RenderView::spellCheck(const WebString& text,
1958 int& misspelled_offset,
1959 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561960 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461961
[email protected]85c55dc2009-11-06 03:05:461962 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171963 RenderThread* thread = RenderThread::current();
1964 // Will be NULL during unit tests.
1965 if (thread) {
[email protected]c27324b2009-11-19 22:44:291966 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171967 word.c_str(), word.size(), document_tag_,
1968 &misspelled_offset, &misspelled_length, NULL);
1969 }
[email protected]1dbafaf72009-09-23 19:43:561970}
1971
1972WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321973 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561974 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261975 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561976 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171977 RenderThread* thread = RenderThread::current();
1978 // Will be NULL during unit tests.
1979 if (thread) {
1980 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291981 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171982 word, document_tag_);
1983 }
[email protected]1dbafaf72009-09-23 19:43:561984 }
[email protected]2a3a7762009-10-19 19:17:321985 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561986}
1987
[email protected]c49085c72009-10-02 16:28:561988void RenderView::showSpellingUI(bool show) {
1989 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1990}
1991
[email protected]8922e1f2009-10-03 05:01:261992bool RenderView::isShowingSpellingUI() {
1993 return spelling_panel_visible_;
1994}
1995
[email protected]1dbafaf72009-09-23 19:43:561996void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321997 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1998 word));
[email protected]1dbafaf72009-09-23 19:43:561999}
2000
[email protected]a1128322009-10-06 18:38:462001bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352002 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472003 WebFileChooserCompletion* chooser_completion) {
2004 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262005 if (params.directory)
2006 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2007 else if (params.multiSelect)
2008 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2009 else
2010 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472011 ipc_params.title = params.title;
2012 ipc_params.default_file_name =
2013 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592014 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472015
2016 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462017}
2018
[email protected]48c9cf2d2009-09-16 16:47:522019void RenderView::runModalAlertDialog(
2020 WebFrame* frame, const WebString& message) {
2021 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
2022 UTF16ToWideHack(message),
2023 std::wstring(),
2024 frame->url(),
2025 NULL);
2026}
2027
2028bool RenderView::runModalConfirmDialog(
2029 WebFrame* frame, const WebString& message) {
2030 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
2031 UTF16ToWideHack(message),
2032 std::wstring(),
2033 frame->url(),
2034 NULL);
2035}
2036
2037bool RenderView::runModalPromptDialog(
2038 WebFrame* frame, const WebString& message, const WebString& default_value,
2039 WebString* actual_value) {
2040 std::wstring result;
2041 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
2042 UTF16ToWideHack(message),
2043 UTF16ToWideHack(default_value),
2044 frame->url(),
2045 &result);
2046 if (ok)
2047 actual_value->assign(WideToUTF16Hack(result));
2048 return ok;
2049}
2050
2051bool RenderView::runModalBeforeUnloadDialog(
2052 WebFrame* frame, const WebString& message) {
2053 bool success = false;
2054 // This is an ignored return value, but is included so we can accept the same
2055 // response as RunJavaScriptMessage.
2056 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212057 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522058 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212059 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522060 return success;
2061}
2062
[email protected]79e37442009-10-09 18:17:442063void RenderView::showContextMenu(
2064 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292065 ContextMenuParams params = ContextMenuParams(data);
2066 if (!params.misspelled_word.empty() && RenderThread::current()) {
2067 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042068 bool spelled_right = RenderThread::current()->spellchecker()->
2069 SpellCheckWord(
2070 params.misspelled_word.c_str(), params.misspelled_word.size(),
2071 document_tag_,
2072 &misspelled_offset, &misspelled_length,
2073 &params.dictionary_suggestions);
2074 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292075 params.misspelled_word.clear();
2076 }
[email protected]216932c2010-08-26 21:44:272077 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2078 // it. We replace it with an empty GURL so the appropriate items are disabled
2079 // in the context menu.
2080 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2081 // data encoded images. We should have a way to save them.
2082 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2083 params.src_url = GURL();
[email protected]c27324b2009-11-19 22:44:292084 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442085}
2086
[email protected]52f139e2c2010-06-11 16:56:092087bool RenderView::supportsFullscreen() {
2088 return CommandLine::ForCurrentProcess()->HasSwitch(
2089 switches::kEnableVideoFullscreen);
2090}
2091
2092void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2093 NOTIMPLEMENTED();
2094}
2095
2096void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2097 NOTIMPLEMENTED();
2098}
2099
[email protected]48c9cf2d2009-09-16 16:47:522100void RenderView::setStatusText(const WebString& text) {
2101}
2102
[email protected]163f8242009-10-30 20:19:552103void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582104 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522105 if (latest_url == target_url_)
2106 return;
[email protected]163f8242009-10-30 20:19:552107
[email protected]48c9cf2d2009-09-16 16:47:522108 // Tell the browser to display a destination link.
2109 if (target_url_status_ == TARGET_INFLIGHT ||
2110 target_url_status_ == TARGET_PENDING) {
2111 // If we have a request in-flight, save the URL to be sent when we
2112 // receive an ACK to the in-flight request. We can happily overwrite
2113 // any existing pending sends.
2114 pending_target_url_ = latest_url;
2115 target_url_status_ = TARGET_PENDING;
2116 } else {
2117 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2118 target_url_ = latest_url;
2119 target_url_status_ = TARGET_INFLIGHT;
2120 }
2121}
2122
[email protected]882daa92009-11-05 16:31:312123void RenderView::StartNavStateSyncTimerIfNecessary() {
2124 int delay;
2125 if (send_content_state_immediately_)
2126 delay = 0;
2127 else if (is_hidden())
2128 delay = kDelaySecondsForContentStateSyncHidden;
2129 else
2130 delay = kDelaySecondsForContentStateSync;
2131
2132 if (nav_state_sync_timer_.IsRunning()) {
2133 // The timer is already running. If the delay of the timer maches the amount
2134 // we want to delay by, then return. Otherwise stop the timer so that it
2135 // gets started with the right delay.
2136 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2137 return;
2138 nav_state_sync_timer_.Stop();
2139 }
2140
2141 nav_state_sync_timer_.Start(
2142 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2143}
2144
[email protected]163f8242009-10-30 20:19:552145void RenderView::setMouseOverURL(const WebURL& url) {
2146 mouse_over_url_ = GURL(url);
2147 UpdateTargetURL(mouse_over_url_, focus_url_);
2148}
2149
2150void RenderView::setKeyboardFocusURL(const WebURL& url) {
2151 focus_url_ = GURL(url);
2152 UpdateTargetURL(focus_url_, mouse_over_url_);
2153}
2154
[email protected]48c9cf2d2009-09-16 16:47:522155void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2156 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2157 hint));
2158}
2159
[email protected]c27ae592010-03-18 15:24:412160void RenderView::startDragging(const WebDragData& data,
2161 WebDragOperationsMask mask,
2162 const WebImage& image,
2163 const WebPoint& imageOffset) {
2164#if WEBKIT_USING_SKIA
2165 SkBitmap bitmap(image.getSkBitmap());
2166#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332167 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412168#endif
2169
[email protected]48c9cf2d2009-09-16 16:47:522170 Send(new ViewHostMsg_StartDragging(routing_id_,
2171 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412172 mask,
2173 bitmap,
2174 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522175}
2176
[email protected]28b92df2009-09-25 17:35:452177bool RenderView::acceptsLoadDrops() {
2178 return renderer_preferences_.can_accept_load_drops;
2179}
2180
[email protected]48c9cf2d2009-09-16 16:47:522181void RenderView::focusNext() {
2182 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2183}
2184
2185void RenderView::focusPrevious() {
2186 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2187}
2188
[email protected]08e9e132010-06-01 16:58:492189void RenderView::focusedNodeChanged(const WebNode& node) {
2190 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2191}
2192
[email protected]48c9cf2d2009-09-16 16:47:522193void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522194 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2195}
2196
2197int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002198 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522199}
2200
2201int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002202 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522203}
2204
[email protected]c4e98902010-06-01 10:20:142205void RenderView::didUpdateInspectorSetting(const WebString& key,
2206 const WebString& value) {
2207 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2208 key.utf8(),
2209 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262210}
2211
[email protected]acca2a1f2009-10-16 03:53:392212void RenderView::queryAutofillSuggestions(const WebNode& node,
2213 const WebString& name,
2214 const WebString& value) {
[email protected]a5e84bd2010-09-14 22:23:362215 autofill_helper_->QueryAutoFillSuggestions(node);
[email protected]acca2a1f2009-10-16 03:53:392216}
2217
2218void RenderView::removeAutofillSuggestions(const WebString& name,
2219 const WebString& value) {
[email protected]6a8ddba52010-09-05 04:38:062220 autofill_helper_->RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a1f2009-10-16 03:53:392221}
2222
[email protected]18ca9a6b2010-06-02 19:05:182223void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2224 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202225 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392226 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202227 unsigned index) {
[email protected]a5e84bd2010-09-14 22:23:362228 autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index);
[email protected]18ca9a6b2010-06-02 19:05:182229}
[email protected]c83641732010-02-20 01:04:482230
[email protected]18ca9a6b2010-06-02 19:05:182231void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2232 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392233 const WebKit::WebString& label,
2234 int unique_id) {
[email protected]a5e84bd2010-09-14 22:23:362235 autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182236}
2237
2238void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]6a8ddba52010-09-05 04:38:062239 autofill_helper_->DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482240}
2241
[email protected]03f57072010-07-14 17:36:082242void RenderView::didAcceptAutocompleteSuggestion(
2243 const WebKit::WebInputElement& user_element) {
2244#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:062245 bool result = password_autocomplete_manager_->FillPassword(user_element);
[email protected]03f57072010-07-14 17:36:082246 // Since this user name was selected from a suggestion list, we should always
2247 // have password for it.
2248 DCHECK(result);
2249#endif
2250}
2251
[email protected]79dbc662009-09-04 05:42:512252// WebKit::WebWidgetClient ----------------------------------------------------
2253
[email protected]ea42e7782010-08-23 23:58:122254void RenderView::didFocus() {
2255 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2256 // we won't have to test for user gesture anymore and we can
2257 // move that code back to render_widget.cc
2258 if (webview() && webview()->mainFrame() &&
2259 webview()->mainFrame()->isProcessingUserGesture()) {
2260 Send(new ViewHostMsg_Focus(routing_id_));
2261 }
2262}
2263
2264void RenderView::didBlur() {
2265 // TODO(jcivelli): see TODO above in didFocus().
2266 if (webview() && webview()->mainFrame() &&
2267 webview()->mainFrame()->isProcessingUserGesture()) {
2268 Send(new ViewHostMsg_Blur(routing_id_));
2269 }
2270}
2271
initial.commit09911bf2008-07-26 23:55:292272// We are supposed to get a single call to Show for a newly created RenderView
2273// that was created via RenderView::CreateWebView. So, we wait until this
2274// point to dispatch the ShowView message.
2275//
2276// This method provides us with the information about how to display the newly
2277// created RenderView (i.e., as a constrained popup or as a new tab).
2278//
[email protected]4873c7d2009-07-16 06:36:282279void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292280 DCHECK(!did_show_) << "received extraneous Show call";
2281 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2282
2283 if (did_show_)
2284 return;
2285 did_show_ = true;
2286
[email protected]4026ce1e2010-09-14 19:35:042287 // Extensions and apps always allowed to create unrequested popups. The second
2288 // check is necessary to include content scripts.
2289 if (ExtensionRendererInfo::GetByURL(creator_url_) ||
2290 bindings_utils::GetInfoForCurrentContext()) {
2291 opened_by_user_gesture_ = true;
2292 }
2293
[email protected]28295ec2009-10-16 05:34:332294 // Force new windows to a popup if they were not opened with a user gesture.
2295 if (!opened_by_user_gesture_) {
2296 // We exempt background tabs for compat with older versions of Chrome.
2297 // TODO(darin): This seems bogus. These should have a user gesture, so
2298 // we probably don't need this check.
2299 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2300 policy = WebKit::WebNavigationPolicyNewPopup;
2301 }
2302
initial.commit09911bf2008-07-26 23:55:292303 // NOTE: initial_pos_ may still have its default values at this point, but
2304 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2305 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282306 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2307 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292308 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242309 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292310}
2311
[email protected]4873c7d2009-07-16 06:36:282312void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132313 // Cancel pending translations so that the translate_helper_ does not attempt
2314 // to access the WebView.
2315 translate_helper_.CancelPendingTranslation();
2316
[email protected]e8345242010-05-06 03:00:402317 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282318 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312319}
2320
[email protected]4873c7d2009-07-16 06:36:282321void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292322 DCHECK(did_show_) << "should already have shown the view";
2323
[email protected]c1f50aa2010-02-18 03:46:572324 // We must keep WebKit's shared timer running in this case in order to allow
2325 // showModalDialog to function properly.
2326 //
2327 // TODO(darin): WebKit should really be smarter about suppressing events and
2328 // timers so that we do not need to manage the shared timer in such a heavy
2329 // handed manner.
2330 //
2331 if (RenderThread::current()) // Will be NULL during unit tests.
2332 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2333
[email protected]12636df2009-09-28 22:32:212334 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292335}
2336
[email protected]3d9689372009-09-10 04:29:172337// WebKit::WebFrameClient -----------------------------------------------------
2338
[email protected]00152e92010-07-19 11:47:402339WebPlugin* RenderView::createPlugin(WebFrame* frame,
2340 const WebPluginParams& params) {
[email protected]7a13e792010-08-03 08:18:242341 bool found = false;
[email protected]55126132010-08-19 14:53:282342 ContentSetting setting = CONTENT_SETTING_DEFAULT;
2343 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]7a13e792010-08-03 08:18:242344 WebPluginInfo info;
2345 GURL url(params.url);
[email protected]0cdafff2010-07-26 09:54:372346 std::string actual_mime_type;
[email protected]7a13e792010-08-03 08:18:242347 Send(new ViewHostMsg_GetPluginInfo(url,
2348 frame->top()->url(),
[email protected]aad51d1c2010-08-05 08:38:092349 params.mimeType.utf8(),
[email protected]7a13e792010-08-03 08:18:242350 &found,
2351 &info,
[email protected]55126132010-08-19 14:53:282352 &setting,
[email protected]aad51d1c2010-08-05 08:38:092353 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242354
[email protected]851b1eb2010-08-09 13:32:292355 if (!found)
[email protected]0cdafff2010-07-26 09:54:372356 return NULL;
[email protected]4e0616e2010-05-28 14:55:532357
[email protected]851b1eb2010-08-09 13:32:292358 scoped_ptr<PluginGroup> group(PluginGroup::FindHardcodedPluginGroup(info));
2359 group->AddPlugin(info, 0);
2360
2361 if (!info.enabled) {
[email protected]55126132010-08-19 14:53:282362 if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) &&
[email protected]851b1eb2010-08-09 13:32:292363 group->IsVulnerable()) {
2364 Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_,
2365 group->GetGroupName(),
2366 GURL(group->GetUpdateURL())));
2367 return CreatePluginPlaceholder(frame, params, group.get());
2368 }
2369 return NULL;
2370 }
2371
[email protected]aad51d1c2010-08-05 08:38:092372 if (info.path.value() != kDefaultPluginLibraryName) {
[email protected]55126132010-08-19 14:53:282373 std::string resource;
2374 if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) {
2375#if defined(OS_POSIX)
2376 resource = info.path.value();
2377#elif defined(OS_WIN)
2378 resource = base::SysWideToUTF8(info.path.value());
2379#endif
2380 }
2381 if (setting == CONTENT_SETTING_BLOCK) {
[email protected]a16a4212010-09-01 08:07:462382 DCHECK(!cmd->HasSwitch(switches::kDisableClickToPlay));
[email protected]55126132010-08-19 14:53:282383 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]851b1eb2010-08-09 13:32:292384 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092385 }
2386 scoped_refptr<pepper::PluginModule> pepper_module =
2387 PepperPluginRegistry::GetInstance()->GetModule(info.path);
2388 if (pepper_module)
2389 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]5e45686b2010-08-30 17:05:342390 if (setting != CONTENT_SETTING_ALLOW) {
2391 // If the host is not whitelisted for this plugin, block it.
[email protected]851b1eb2010-08-09 13:32:292392 Send(new ViewHostMsg_NonSandboxedPluginBlocked(routing_id_,
[email protected]55126132010-08-19 14:53:282393 resource,
[email protected]851b1eb2010-08-09 13:32:292394 group->GetGroupName()));
2395 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092396 }
[email protected]0cdafff2010-07-26 09:54:372397 }
[email protected]aad51d1c2010-08-05 08:38:092398 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]3d9689372009-09-10 04:29:172399}
2400
2401WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562402 WebApplicationCacheHostImpl* appcache_host =
2403 WebApplicationCacheHostImpl::FromFrame(frame);
2404 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2405 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2406 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172407}
2408
[email protected]9c00f002009-11-05 22:37:422409WebSharedWorker* RenderView::createSharedWorker(
2410 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372411 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422412
[email protected]30447b62009-11-13 01:13:372413 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512414 bool exists = false;
[email protected]30447b62009-11-13 01:13:372415 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512416 ViewHostMsg_CreateWorker_Params params;
2417 params.url = url;
2418 params.is_shared = true;
2419 params.name = name;
2420 params.document_id = document_id;
2421 params.render_view_route_id = routing_id_;
2422 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232423 params.parent_appcache_host_id = 0;
2424 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372425 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512426 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372427 if (url_mismatch) {
2428 return NULL;
2429 } else {
2430 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492431 document_id,
[email protected]6de0bcf2010-02-17 22:00:512432 exists,
[email protected]30447b62009-11-13 01:13:372433 route_id,
2434 routing_id_);
2435 }
[email protected]9c00f002009-11-05 22:37:422436}
2437
[email protected]3d9689372009-09-10 04:29:172438WebMediaPlayer* RenderView::createMediaPlayer(
2439 WebFrame* frame, WebMediaPlayerClient* client) {
2440 scoped_refptr<media::FilterFactoryCollection> factory =
2441 new media::FilterFactoryCollection();
2442 // Add in any custom filter factories first.
2443 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2444 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2445 // Add the chrome specific audio renderer.
2446 factory->AddFactory(
2447 AudioRendererImpl::CreateFactory(audio_message_filter()));
2448 }
2449
[email protected]68c665ed2010-09-07 23:09:132450 // TODO(hclam): Need to inject Gles2VideoDecodeContext here. Also I need
2451 // to create a factory for FFmpegVideoDecoder here so that it can use
2452 // the Gles2VideoDecodeContext.
[email protected]ee68378a2010-08-10 01:05:412453 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]01df0512010-09-08 05:53:042454 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]ee68378a2010-08-10 01:05:412455 // Add the hardware video decoder factory.
[email protected]1cfb7420f2010-09-03 18:57:242456 factory->AddFactory(IpcVideoDecoder::CreateFactory(
2457 MessageLoop::current(),
2458 reinterpret_cast<WebGLES2ContextImpl*>(
2459 webview()->gles2Context())->context()));
[email protected]ee68378a2010-08-10 01:05:412460 }
2461
[email protected]80f584d92010-01-21 03:59:042462 WebApplicationCacheHostImpl* appcache_host =
2463 WebApplicationCacheHostImpl::FromFrame(frame);
2464
[email protected]3d9689372009-09-10 04:29:172465 // TODO(hclam): obtain the following parameters from |client|.
2466 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2467 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152468 GURL(), // referrer
2469 "null", // frame origin
2470 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172471 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042472 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172473 routing_id());
2474
[email protected]0436b9a2009-10-23 00:23:052475 // A simple data source that keeps all data in memory.
2476 media::FilterFactory* simple_data_source_factory =
2477 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2478 bridge_factory);
2479 // A sophisticated data source that does memory caching.
2480 media::FilterFactory* buffered_data_source_factory =
2481 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2482 bridge_factory);
2483 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2484 factory->AddFactory(simple_data_source_factory);
2485 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172486 } else {
[email protected]0436b9a2009-10-23 00:23:052487 factory->AddFactory(buffered_data_source_factory);
2488 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172489 }
[email protected]8400e032010-02-26 18:50:112490
2491 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2492 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2493 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2494 } else {
[email protected]b57509eb2010-03-30 01:26:282495 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2496 factory_factory =
2497 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112498 }
2499
2500 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172501}
2502
[email protected]035545f2010-04-09 13:10:212503WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2504 WebFrame* frame, WebApplicationCacheHostClient* client) {
2505 return new RendererWebApplicationCacheHostImpl(
2506 FromWebView(frame->view()), client,
2507 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2508}
2509
[email protected]b921cfd22010-02-25 16:57:512510WebCookieJar* RenderView::cookieJar() {
2511 return &cookie_jar_;
2512}
2513
[email protected]5041f982010-08-11 21:40:452514void RenderView::frameDetached(WebFrame* frame) {
[email protected]6a8ddba52010-09-05 04:38:062515 autofill_helper_->FrameDetached(frame);
2516 page_click_tracker_->StopTrackingFrame(frame, true);
[email protected]5041f982010-08-11 21:40:452517}
2518
[email protected]3d9689372009-09-10 04:29:172519void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302520 WebDataSource* ds = frame->dataSource();
2521 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522522
2523 if (!frame->parent()) {
2524 const GURL& url = frame->url();
2525 // Ensure state contains scheme.
2526 if (url.SchemeIs("http"))
2527 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
2528 else if (url.SchemeIs("https"))
2529 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
2530
2531 // Dump will only be provided when scheme is http or https.
2532 DumpLoadHistograms();
2533 }
2534
[email protected]fa7b6b542009-11-03 05:02:302535 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162536
[email protected]5041f982010-08-11 21:40:452537 // TODO(jhawkins): Remove once frameDetached is called by WebKit.
[email protected]6a8ddba52010-09-05 04:38:062538 autofill_helper_->FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172539}
2540
[email protected]684e4a42010-01-30 06:44:112541bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402542 if (enabled_per_settings &&
2543 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2544 return true;
2545
2546 if (IsWhitelistedForContentSettings(frame))
2547 return true;
2548
[email protected]55126132010-08-19 14:53:282549 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402550 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112551}
2552
[email protected]d5f9e4f2010-07-28 08:31:302553bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]a16a4212010-09-01 08:07:462554 if (!CommandLine::ForCurrentProcess()->HasSwitch(
2555 switches::kDisableClickToPlay)) {
[email protected]d5f9e4f2010-07-28 08:31:302556 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
2557 }
[email protected]a16a4212010-09-01 08:07:462558 return enabled_per_settings &&
2559 AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]d5f9e4f2010-07-28 08:31:302560}
2561
2562
[email protected]3d9689372009-09-10 04:29:172563void RenderView::loadURLExternally(
2564 WebFrame* frame, const WebURLRequest& request,
2565 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592566 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2567 if (policy == WebKit::WebNavigationPolicyDownload) {
2568 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2569 } else {
2570 OpenURL(request.url(), referrer, policy);
2571 }
[email protected]3d9689372009-09-10 04:29:172572}
2573
2574WebNavigationPolicy RenderView::decidePolicyForNavigation(
2575 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222576 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172577 // Webkit is asking whether to navigate to a new URL.
2578 // This is fine normally, except if we're showing UI from one security
2579 // context and they're trying to navigate to a different context.
2580 const GURL& url = request.url();
2581
2582 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302583 // navigations.
[email protected]8079b362010-05-07 18:37:452584 if (renderer_preferences_.browser_handles_top_level_requests &&
2585 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192586 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232587 // Reset these counters as the RenderView could be reused for the next
2588 // navigation.
2589 page_id_ = -1;
2590 next_page_id_ = 1;
2591 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192592 OpenURL(url, referrer, default_policy);
2593 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172594 }
2595
2596 // A content initiated navigation may have originated from a link-click,
2597 // script, drag-n-drop operation, etc.
2598 bool is_content_initiated =
2599 NavigationState::FromDataSource(frame->provisionalDataSource())->
2600 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582601 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172602
2603 // We only care about navigations that are within the current tab (as opposed
2604 // to, for example, opening a new window).
2605 // But we sometimes navigate to about:blank to clear a tab, and we want to
2606 // still allow that.
2607 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2608 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532609 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172610 !url.SchemeIs(chrome::kAboutScheme)) {
2611 // When we received such unsolicited navigations, we sometimes want to
2612 // punt them up to the browser to handle.
[email protected]5351dbc2010-08-27 15:22:112613 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172614 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422615 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]5351dbc2010-08-27 15:22:112616 // We don't send referrer from these special pages.
[email protected]3d9689372009-09-10 04:29:172617 OpenURL(url, GURL(), default_policy);
2618 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2619 }
[email protected]8079b362010-05-07 18:37:452620
[email protected]5351dbc2010-08-27 15:22:112621 // We forward non-local navigations from extensions to the browser if they
2622 // are top-level events, even if the browser hasn't expressed interest.
[email protected]a6b960ad972010-09-01 19:53:582623 // TODO(erikkay) crbug.com/54118 - combine this clause and the next into
2624 // some shared logic.
[email protected]8079b362010-05-07 18:37:452625 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]a6b960ad972010-09-01 19:53:582626 old_url.SchemeIs(chrome::kExtensionScheme) &&
[email protected]c240ace2010-06-16 18:31:532627 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]5351dbc2010-08-27 15:22:112628 // We don't send referrer from extensions.
[email protected]8079b362010-05-07 18:37:452629 OpenURL(url, GURL(), default_policy);
2630 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2631 }
[email protected]5351dbc2010-08-27 15:22:112632
2633 // If the navigation would cross an app extent boundary, we also need
2634 // to defer to the browser to ensure process isolation.
2635 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2636 // which means that things like the back button won't trigger it. Is that
2637 // OK?
2638 if (CrossesExtensionExtents(frame, url)) {
2639 // Include the referrer in this case since we're going from a hosted web
2640 // page. (the packaged case is handled previously by the extension
2641 // navigation test)
2642 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2643 OpenURL(url, referrer, default_policy);
2644 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2645 }
[email protected]3d9689372009-09-10 04:29:172646 }
2647
2648 // Detect when a page is "forking" a new tab that can be safely rendered in
2649 // its own process. This is done by sites like Gmail that try to open links
2650 // in new windows without script connections back to the original page. We
2651 // treat such cases as browser navigations (in which we will create a new
2652 // renderer for a cross-site navigation), rather than WebKit navigations.
2653 //
2654 // We use the following heuristic to decide whether to fork a new page in its
2655 // own process:
2656 // The parent page must open a new tab to about:blank, set the new tab's
2657 // window.opener to null, and then redirect the tab to a cross-site URL using
2658 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462659 //
2660 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2661 // (see below).
[email protected]3d9689372009-09-10 04:29:172662 bool is_fork =
2663 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582664 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172665 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522666 historyBackListCount() < 1 &&
2667 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172668 // The parent page must have set the child's window.opener to null before
2669 // redirecting to the desired URL.
2670 frame->opener() == NULL &&
2671 // Must be a top-level frame.
2672 frame->parent() == NULL &&
2673 // Must not have issued the request from this page.
2674 is_content_initiated &&
2675 // Must be targeted at the current tab.
2676 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2677 // Must be a JavaScript navigation, which appears as "other".
2678 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462679
2680 // Recognize if this navigation is from a link with rel=noreferrer and
2681 // target=_blank attributes, in which case the opener will be suppressed. If
2682 // so, it is safe to load cross-site pages in a separate process, so we
2683 // should let the browser handle it.
2684 bool is_noreferrer_and_blank_target =
2685 // Frame should be top level and not yet navigated.
2686 frame->parent() == NULL &&
2687 frame->url().isEmpty() &&
2688 historyBackListCount() < 1 &&
2689 historyForwardListCount() < 1 &&
2690 // Links with rel=noreferrer will have no Referer field, and their
2691 // resulting frame will have its window.opener suppressed.
2692 // TODO(creis): should add a request.httpReferrer() method to help avoid
2693 // typos on the unusual spelling of Referer.
2694 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2695 opener_suppressed_ &&
2696 frame->opener() == NULL &&
2697 // Links with target=_blank will have no name.
2698 frame->name().isNull() &&
2699 // Another frame (with a non-empty creator) should have initiated the
2700 // request, targeted at this frame.
2701 !creator_url_.is_empty() &&
2702 is_content_initiated &&
2703 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2704 type == WebKit::WebNavigationTypeOther;
2705
2706 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172707 // Open the URL via the browser, not via WebKit.
2708 OpenURL(url, GURL(), default_policy);
2709 return WebKit::WebNavigationPolicyIgnore;
2710 }
2711
2712 return default_policy;
2713}
2714
[email protected]6069da8c2009-10-20 20:33:492715bool RenderView::canHandleRequest(
2716 WebFrame* frame, const WebURLRequest& request) {
2717 // We allow WebKit to think that everything can be handled even though
2718 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342719 return true;
2720}
2721
[email protected]6069da8c2009-10-20 20:33:492722WebURLError RenderView::cannotHandleRequestError(
2723 WebFrame* frame, const WebURLRequest& request) {
2724 NOTREACHED(); // Since we said we can handle all requests.
2725 return WebURLError();
2726}
2727
2728WebURLError RenderView::cancelledError(
2729 WebFrame* frame, const WebURLRequest& request) {
2730 WebURLError error;
2731 error.domain = WebString::fromUTF8(net::kErrorDomain);
2732 error.reason = net::ERR_ABORTED;
2733 error.unreachableURL = request.url();
2734 return error;
[email protected]7b7a7dc2009-10-19 02:23:342735}
2736
2737void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492738 WebFrame*, const WebURLError&) {
2739 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342740}
2741
[email protected]90eeddb2010-05-06 21:06:432742void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2743 const WebKit::WebFormElement& form) {
2744 // Some login forms have onSubmit handlers that put a hash of the password
2745 // into a hidden field and then clear the password. (Issue 28910.)
2746 // This method gets called before any of those handlers run, so save away
2747 // a copy of the password in case it gets lost.
2748 NavigationState* navigation_state =
2749 NavigationState::FromDataSource(frame->dataSource());
2750 navigation_state->set_password_form_data(
2751 PasswordFormDomManager::CreatePasswordForm(form));
2752}
2753
[email protected]979c28b2009-11-07 01:30:482754void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172755 NavigationState* navigation_state =
2756 NavigationState::FromDataSource(frame->provisionalDataSource());
2757
2758 if (navigation_state->transition_type() == PageTransition::LINK)
2759 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2760
2761 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352762 WebSearchableFormData web_searchable_form_data(form);
2763 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2764 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212765 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432766 PasswordForm* password_form_data =
2767 PasswordFormDomManager::CreatePasswordForm(form);
2768 navigation_state->set_password_form_data(password_form_data);
2769
2770 // If the password has been cleared, recover it from the form contents already
2771 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2772 // opposed to the provisionalDataSource's, which is what we're storing into
2773 // now.)
2774 if (password_form_data && password_form_data->password_value.empty()) {
2775 NavigationState* old_navigation_state =
2776 NavigationState::FromDataSource(frame->dataSource());
2777 if (old_navigation_state) {
2778 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2779 if (old_form_data && old_form_data->action == password_form_data->action)
2780 password_form_data->password_value = old_form_data->password_value;
2781 }
2782 }
[email protected]3d9689372009-09-10 04:29:172783
[email protected]b1438212010-04-03 00:30:592784 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042785 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092786 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592787 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172788}
2789
2790void RenderView::willPerformClientRedirect(
2791 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2792 double fire_time) {
2793 // Ignore
2794}
2795
2796void RenderView::didCancelClientRedirect(WebFrame* frame) {
2797 // Ignore
2798}
2799
2800void RenderView::didCompleteClientRedirect(
2801 WebFrame* frame, const WebURL& from) {
2802 if (!frame->parent())
2803 completed_client_redirect_src_ = from;
2804}
2805
2806void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2807 // The rest of RenderView assumes that a WebDataSource will always have a
2808 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482809 bool content_initiated = !pending_navigation_state_.get();
2810 NavigationState* state = content_initiated ?
2811 NavigationState::CreateContentInitiated() :
2812 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512813
[email protected]8a3125a712010-08-09 18:58:512814 // NavigationState::referred_by_prefetcher_ is true if we are
2815 // navigating from a page that used prefetching using a link on that
2816 // page. We are early enough in the request process here that we
2817 // can still see the NavigationState of the previous page and set
2818 // this value appropriately.
2819 // TODO(gavinp): catch the important case of navigation in a new
2820 // renderer process.
2821 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302822 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522823 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512824 const GURL referrer(
2825 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2826 if (!referrer.is_empty() &&
2827 NavigationState::FromDataSource(
2828 old_frame->dataSource())->was_prefetcher()) {
2829 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2830 WebDataSource* old_frame_ds = old_frame->dataSource();
2831 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2832 state->set_was_referred_by_prefetcher(true);
2833 break;
2834 }
2835 }
2836 }
2837 }
2838 }
2839
[email protected]4c1b6f0b2010-02-07 16:38:182840 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522841 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512842 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182843 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2844 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2845 break;
2846 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2847 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2848 break;
2849 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2850 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2851 break;
2852 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2853 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2854 break;
2855 }
2856 }
[email protected]fa7b6b542009-11-03 05:02:302857
2858 state->set_user_script_idle_scheduler(
2859 new UserScriptIdleScheduler(this, frame));
2860 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172861}
2862
2863void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2864 WebDataSource* ds = frame->provisionalDataSource();
2865 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2866
[email protected]3d9689372009-09-10 04:29:172867 // Update the request time if WebKit has better knowledge of it.
2868 if (navigation_state->request_time().is_null()) {
2869 double event_time = ds->triggeringEventTime();
2870 if (event_time != 0.0)
2871 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2872 }
2873
[email protected]05c8e502010-08-15 15:13:522874 // Start time is only set after request time.
2875 navigation_state->set_start_load_time(Time::Now());
2876
[email protected]3d9689372009-09-10 04:29:172877 bool is_top_most = !frame->parent();
2878 if (is_top_most) {
2879 navigation_gesture_ = frame->isProcessingUserGesture() ?
2880 NavigationGestureUnknown : NavigationGestureAuto;
2881
2882 // Make sure redirect tracking state is clear for the new load.
2883 completed_client_redirect_src_ = GURL();
2884 } else if (frame->parent()->isLoading()) {
2885 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002886 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172887 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2888 }
2889
2890 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2891 routing_id_, is_top_most, ds->request().url()));
2892}
2893
2894void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2895 if (frame->parent())
2896 return;
2897 // Received a redirect on the main frame.
2898 WebDataSource* data_source = frame->provisionalDataSource();
2899 if (!data_source) {
2900 // Should only be invoked when we have a data source.
2901 NOTREACHED();
2902 return;
2903 }
2904 std::vector<GURL> redirects;
2905 GetRedirectChain(data_source, &redirects);
2906 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512907 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2908 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172909 }
2910}
2911
[email protected]40bd6582009-12-04 23:49:512912void RenderView::didFailProvisionalLoad(WebFrame* frame,
2913 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172914 // Notify the browser that we failed a provisional load with an error.
2915 //
2916 // Note: It is important this notification occur before DidStopLoading so the
2917 // SSL manager can react to the provisional load failure before being
2918 // notified the load stopped.
2919 //
2920 WebDataSource* ds = frame->provisionalDataSource();
2921 DCHECK(ds);
2922
2923 const WebURLRequest& failed_request = ds->request();
2924
2925 bool show_repost_interstitial =
2926 (error.reason == net::ERR_CACHE_MISS &&
2927 EqualsASCII(failed_request.httpMethod(), "POST"));
2928 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2929 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2930 show_repost_interstitial));
2931
2932 // Don't display an error page if this is simply a cancelled load. Aside
2933 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2934 if (error.reason == net::ERR_ABORTED)
2935 return;
2936
2937 // Make sure we never show errors in view source mode.
2938 frame->enableViewSourceMode(false);
2939
2940 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2941
2942 // If this is a failed back/forward/reload navigation, then we need to do a
2943 // 'replace' load. This is necessary to avoid messing up session history.
2944 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2945 // as session history is concerned.
2946 //
2947 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2948 // the page id.
2949 //
2950 bool replace =
2951 navigation_state->pending_page_id() != -1 ||
2952 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2953
2954 // If we failed on a browser initiated request, then make sure that our error
2955 // page load is regarded as the same browser initiated request.
2956 if (!navigation_state->is_content_initiated()) {
2957 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2958 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002959 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172960 navigation_state->transition_type(),
2961 navigation_state->request_time()));
2962 }
2963
2964 // Provide the user with a more helpful error page?
2965 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2966 return;
2967
2968 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082969 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172970}
2971
2972void RenderView::didReceiveDocumentData(
2973 WebFrame* frame, const char* data, size_t data_len,
2974 bool& prevent_default) {
2975 NavigationState* navigation_state =
2976 NavigationState::FromDataSource(frame->dataSource());
2977 if (!navigation_state->postpone_loading_data())
2978 return;
2979
2980 // We're going to call commitDocumentData ourselves...
2981 prevent_default = true;
2982
[email protected]3f853a52010-09-13 19:15:082983 // Continue buffering the response data for the original error page. If it
2984 // grows too large, then we'll just let it through. For any error other than
2985 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:172986 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:082987 if (navigation_state->postponed_data().size() >= 512 ||
2988 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:172989 navigation_state->set_postpone_loading_data(false);
2990 frame->commitDocumentData(navigation_state->postponed_data().data(),
2991 navigation_state->postponed_data().size());
2992 navigation_state->clear_postponed_data();
2993 }
2994}
2995
[email protected]40bd6582009-12-04 23:49:512996void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2997 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172998 NavigationState* navigation_state =
2999 NavigationState::FromDataSource(frame->dataSource());
3000
3001 navigation_state->set_commit_load_time(Time::Now());
3002 if (is_new_navigation) {
3003 // When we perform a new navigation, we need to update the previous session
3004 // history entry with state for the page we are leaving.
3005 UpdateSessionHistory(frame);
3006
3007 // We bump our Page ID to correspond with the new session history entry.
3008 page_id_ = next_page_id_++;
3009
[email protected]d64b07b2010-04-20 22:14:063010 // Any pending translation is now obsolete.
3011 translate_helper_.CancelPendingTranslation();
3012
[email protected]3cc72b12010-03-18 23:03:003013 // Advance our offset in session history, applying the length limit. There
3014 // is now no forward history.
3015 history_list_offset_++;
3016 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3017 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3018 history_list_length_ = history_list_offset_ + 1;
3019
[email protected]f9f4841b2010-03-20 05:41:423020 MessageLoop::current()->PostDelayedTask(
3021 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303022 page_info_method_factory_.NewRunnableMethod(
3023 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173024 kDelayForForcedCaptureMs);
3025 } else {
3026 // Inspect the navigation_state on this frame to see if the navigation
3027 // corresponds to a session history navigation... Note: |frame| may or
3028 // may not be the toplevel frame, but for the case of capturing session
3029 // history, the first committed frame suffices. We keep track of whether
3030 // we've seen this commit before so that only capture session history once
3031 // per navigation.
3032 //
3033 // Note that we need to check if the page ID changed. In the case of a
3034 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3035 // previous URL and the current page ID, which would be wrong.
3036 if (navigation_state->pending_page_id() != -1 &&
3037 navigation_state->pending_page_id() != page_id_ &&
3038 !navigation_state->request_committed()) {
3039 // This is a successful session history navigation!
3040 UpdateSessionHistory(frame);
3041 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003042
3043 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173044 }
3045 }
3046
3047 // Remember that we've already processed this request, so we don't update
3048 // the session history again. We do this regardless of whether this is
3049 // a session history navigation, because if we attempted a session history
3050 // navigation without valid HistoryItem state, WebCore will think it is a
3051 // new navigation.
3052 navigation_state->set_request_committed(true);
3053
3054 UpdateURL(frame);
3055
3056 // If this committed load was initiated by a client redirect, we're
3057 // at the last stop now, so clear it.
3058 completed_client_redirect_src_ = GURL();
3059
3060 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273061 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173062}
3063
3064void RenderView::didClearWindowObject(WebFrame* frame) {
3065 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3066 BindDOMAutomationController(frame);
3067 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
3068 dom_ui_bindings_.set_message_sender(this);
3069 dom_ui_bindings_.set_routing_id(routing_id_);
3070 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
3071 }
3072 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
3073 external_host_bindings_.set_message_sender(this);
3074 external_host_bindings_.set_routing_id(routing_id_);
3075 external_host_bindings_.BindToJavascript(frame, L"externalHost");
3076 }
3077}
3078
3079void RenderView::didCreateDocumentElement(WebFrame* frame) {
3080 if (RenderThread::current()) { // Will be NULL during unit tests.
3081 RenderThread::current()->user_script_slave()->InjectScripts(
3082 frame, UserScript::DOCUMENT_START);
3083 }
3084
3085 // Notify the browser about non-blank documents loading in the top frame.
3086 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253087 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273088 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173089 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3090 }
3091}
3092
3093void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3094 UpdateTitle(frame, title);
3095
3096 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273097 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173098}
3099
[email protected]5019ef12010-04-27 17:26:583100void RenderView::didChangeIcons(WebFrame* frame) {
3101 if (!frame->parent()) {
3102 Send(new ViewHostMsg_UpdateFavIconURL(
3103 routing_id_,
3104 page_id_,
3105 frame->favIconURL()));
3106 }
3107}
3108
[email protected]3d9689372009-09-10 04:29:173109void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3110 WebDataSource* ds = frame->dataSource();
3111 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3112 DCHECK(navigation_state);
3113 navigation_state->set_finish_document_load_time(Time::Now());
3114
3115 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
3116
[email protected]6a8ddba52010-09-05 04:38:063117 page_click_tracker_->StartTrackingFrame(frame);
[email protected]e9e07992010-02-17 21:04:363118 // The document has now been fully loaded. Scan for forms to be sent up to
3119 // the browser.
[email protected]6a8ddba52010-09-05 04:38:063120 autofill_helper_->FrameContentsAvailable(frame);
3121 password_autocomplete_manager_->SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:173122
3123 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273124 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173125
3126 if (RenderThread::current()) { // Will be NULL during unit tests.
3127 RenderThread::current()->user_script_slave()->InjectScripts(
3128 frame, UserScript::DOCUMENT_END);
3129 }
[email protected]fa7b6b542009-11-03 05:02:303130
3131 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3132}
3133
3134void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3135 if (RenderThread::current()) { // Will be NULL during unit tests.
3136 RenderThread::current()->user_script_slave()->InjectScripts(
3137 frame, UserScript::DOCUMENT_IDLE);
3138 }
3139
3140 WebFrame* main_frame = webview()->mainFrame();
3141 if (frame == main_frame) {
3142 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203143 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303144 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203145 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303146 pending_code_execution_queue_.pop();
3147 }
3148 }
[email protected]3d9689372009-09-10 04:29:173149}
3150
3151void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083152 if (webview()->mainFrame() == frame) {
3153 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3154 page_id_));
3155 }
[email protected]3d9689372009-09-10 04:29:173156}
3157
3158void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3159 // Ignore
3160}
3161
3162void RenderView::didFinishLoad(WebFrame* frame) {
3163 WebDataSource* ds = frame->dataSource();
3164 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3165 DCHECK(navigation_state);
3166 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303167 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413168
3169 // Let the password manager know which password forms are actually visible.
[email protected]6a8ddba52010-09-05 04:38:063170 password_autocomplete_manager_->SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:173171}
3172
[email protected]ccbe04e2010-03-17 17:58:433173void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173174 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063175 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3176 // since a new one gets created by didCreateDataSource.
[email protected]af15bed2010-08-25 21:12:093177 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
[email protected]f6c2459d2010-02-24 22:34:063178 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3179
[email protected]3d9689372009-09-10 04:29:173180 // If this was a reference fragment navigation that we initiated, then we
3181 // could end up having a non-null pending navigation state. We just need to
3182 // update the ExtraData on the datasource so that others who read the
3183 // ExtraData will get the new NavigationState. Similarly, if we did not
3184 // initiate this navigation, then we need to take care to reset any pre-
3185 // existing navigation state to a content-initiated navigation state.
3186 // DidCreateDataSource conveniently takes care of this for us.
3187 didCreateDataSource(frame, frame->dataSource());
3188
[email protected]af15bed2010-08-25 21:12:093189 NavigationState* new_state =
3190 NavigationState::FromDataSource(frame->dataSource());
3191 new_state->set_was_within_same_page(true);
3192
[email protected]f6c2459d2010-02-24 22:34:063193 if (idle_scheduler_ran) {
3194 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
[email protected]f6c2459d2010-02-24 22:34:063195 new_state->user_script_idle_scheduler()->set_has_run(true);
3196 }
3197
[email protected]3d9689372009-09-10 04:29:173198 didCommitProvisionalLoad(frame, is_new_navigation);
3199
[email protected]26aa0482009-09-30 16:55:273200 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173201}
3202
[email protected]476b6f82009-09-10 21:00:593203void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313204 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593205}
3206
[email protected]3d9689372009-09-10 04:29:173207void RenderView::assignIdentifierToRequest(
3208 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3209 // Ignore
3210}
3211
3212void RenderView::willSendRequest(
3213 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3214 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303215 WebFrame* top_frame = frame->top();
3216 if (!top_frame)
3217 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513218 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3219 WebDataSource* top_data_source = top_frame->dataSource();
3220 WebDataSource* data_source =
3221 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303222 if (data_source) {
3223 NavigationState* state = NavigationState::FromDataSource(data_source);
3224 if (state && state->is_cache_policy_override_set())
3225 request.setCachePolicy(state->cache_policy_override());
3226 }
[email protected]8a3125a712010-08-09 18:58:513227
3228 if (top_data_source) {
3229 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3230 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3231 state->set_was_prefetcher(true);
3232 }
3233
[email protected]3d9689372009-09-10 04:29:173234 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503235 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133236 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493237
[email protected]85cc78c2010-05-04 18:30:093238 // Temporary metrics, see site_isolation_metrics.h
3239 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173240}
3241
3242void RenderView::didReceiveResponse(
3243 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493244
[email protected]85cc78c2010-05-04 18:30:093245 // Temporary metrics, see site_isolation_metrics.h
3246 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3247 identifier,
3248 response);
[email protected]fa0a3432010-03-30 16:53:493249
[email protected]3d9689372009-09-10 04:29:173250 // Only do this for responses that correspond to a provisional data source
3251 // of the top-most frame. If we have a provisional data source, then we
3252 // can't have any sub-resources yet, so we know that this response must
3253 // correspond to a frame load.
3254 if (!frame->provisionalDataSource() || frame->parent())
3255 return;
3256
3257 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083258 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173259 if (frame->isViewSourceModeEnabled())
3260 return;
3261
[email protected]65041fa2010-05-21 06:56:533262 NavigationState* navigation_state =
3263 NavigationState::FromDataSource(frame->provisionalDataSource());
3264 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083265 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533266
[email protected]972ebdff2010-06-10 22:59:073267 // Record page load flags.
3268 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3269 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573270 navigation_state->set_was_alternate_protocol_available(
3271 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073272 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083273 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533274
[email protected]f48013be2010-01-14 22:07:453275 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083276 if (http_status_code == 404) {
3277 // Can we even load an alternate error page for this URL?
3278 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3279 return;
3280 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3281 http_status_code)) {
3282 // If no corresponding error strings for a particular status code, just
3283 // render any received data, regardless of whether or not the status code
3284 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453285 return;
[email protected]3f853a52010-09-13 19:15:083286 }
[email protected]3d9689372009-09-10 04:29:173287
[email protected]3d9689372009-09-10 04:29:173288 navigation_state->set_postpone_loading_data(true);
3289 navigation_state->clear_postponed_data();
3290}
3291
3292void RenderView::didFinishResourceLoad(
3293 WebFrame* frame, unsigned identifier) {
3294 NavigationState* navigation_state =
3295 NavigationState::FromDataSource(frame->dataSource());
3296 if (!navigation_state->postpone_loading_data())
3297 return;
3298
[email protected]3f853a52010-09-13 19:15:083299 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173300 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083301 int http_status_code = navigation_state->http_status_code();
3302 if (http_status_code == 404) {
3303 // On 404s, try a remote search page as a fallback.
3304 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173305
[email protected]3f853a52010-09-13 19:15:083306 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3307 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173308
[email protected]3f853a52010-09-13 19:15:083309 WebURLError original_error;
3310 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173311
[email protected]3f853a52010-09-13 19:15:083312 navigation_state->set_alt_error_page_fetcher(
3313 new AltErrorPageResourceFetcher(
3314 error_page_url, frame, original_error,
3315 NewCallback(this, &RenderView::AltErrorPageFinished)));
3316 } else {
3317 // On other errors, use an internal error page.
3318 WebURLError error;
3319 error.unreachableURL = frame->url();
3320 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3321 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173322
[email protected]3f853a52010-09-13 19:15:083323 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3324 std::string(), true);
3325 }
[email protected]3d9689372009-09-10 04:29:173326}
3327
3328void RenderView::didFailResourceLoad(
3329 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3330 // Ignore
3331}
3332
3333void RenderView::didLoadResourceFromMemoryCache(
3334 WebFrame* frame, const WebURLRequest& request,
3335 const WebURLResponse& response) {
3336 // Let the browser know we loaded a resource from the memory cache. This
3337 // message is needed to display the correct SSL indicators.
3338 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3339 routing_id_,
3340 request.url(),
[email protected]91733b62009-09-18 06:21:093341 frame->securityOrigin().toString().utf8(),
3342 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173343 response.securityInfo()));
3344}
3345
[email protected]6069da8c2009-10-20 20:33:493346void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293347 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3348}
3349
3350void RenderView::didRunInsecureContent(
3351 WebFrame* frame, const WebSecurityOrigin& origin) {
3352 Send(new ViewHostMsg_DidRunInsecureContent(
3353 routing_id_,
3354 origin.toString().utf8()));
3355}
3356
[email protected]7ea093ba2009-11-03 05:54:593357bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403358 if (enabled_per_settings &&
3359 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3360 return true;
[email protected]7ea093ba2009-11-03 05:54:593361
[email protected]12bc8472010-04-15 07:29:403362 if (IsWhitelistedForContentSettings(frame))
3363 return true;
[email protected]7ea093ba2009-11-03 05:54:593364
3365 return false; // Other protocols fall through here.
3366}
3367
[email protected]0a1a45432010-03-31 08:09:453368bool RenderView::allowDatabase(
3369 WebFrame* frame, const WebString& name, const WebString& display_name,
3370 unsigned long estimated_size) {
3371 WebSecurityOrigin origin = frame->securityOrigin();
3372 if (origin.isEmpty())
3373 return false; // Uninitialized document?
3374
3375 bool result;
3376 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3377 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3378 return false;
[email protected]9fb83e82010-07-02 18:24:553379 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3380 GURL(origin.toString().utf8()),
3381 name,
3382 display_name,
3383 estimated_size,
3384 !result));
[email protected]0a1a45432010-03-31 08:09:453385 return result;
3386}
[email protected]8934a3b2010-02-25 00:34:003387void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283388 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003389}
3390
[email protected]c21f1d52010-03-04 03:19:433391void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283392 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433393}
3394
[email protected]3d9689372009-09-10 04:29:173395void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3396 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3397}
3398
[email protected]0c882b282009-10-07 17:01:283399void RenderView::didCreateScriptContext(WebFrame* frame) {
3400 EventBindings::HandleContextCreated(frame, false);
3401}
3402
3403void RenderView::didDestroyScriptContext(WebFrame* frame) {
3404 EventBindings::HandleContextDestroyed(frame);
3405}
3406
3407void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3408 EventBindings::HandleContextCreated(frame, true);
3409}
3410
[email protected]fc86daa2010-03-30 23:52:533411void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3412 WebFrame* target,
3413 bool cross_origin,
3414 const WebString& property_name,
3415 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103416 // TODO(johnnyg): track the individual properties and repeat event_ids.
3417 if (cross_origin)
3418 cross_origin_access_count_++;
3419 else
3420 same_origin_access_count_++;
3421}
3422
[email protected]3d9689372009-09-10 04:29:173423void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143424 CheckPreferredSize();
3425}
3426
3427void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173428 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253429 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173430 // message.
[email protected]705243f2010-05-05 19:58:073431 if (!send_preferred_size_changes_ || !webview())
3432 return;
[email protected]dfca5acf2010-03-22 03:28:433433
[email protected]705243f2010-05-05 19:58:073434 // WebCore likes to tell us things have changed even when they haven't, so
3435 // cache the width and height and only send the IPC message when we're sure
3436 // they're different.
3437 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3438 webview()->mainFrame()->documentElementScrollHeight());
3439 if (size == preferred_size_)
3440 return;
[email protected]c27324b2009-11-19 22:44:293441
[email protected]705243f2010-05-05 19:58:073442 preferred_size_ = size;
3443 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3444 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173445}
3446
[email protected]143dcd592009-11-06 21:33:493447void RenderView::didChangeScrollOffset(WebFrame* frame) {
3448 StartNavStateSyncTimerIfNecessary();
3449}
3450
[email protected]8922e1f2009-10-03 05:01:263451void RenderView::reportFindInPageMatchCount(int request_id, int count,
3452 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113453 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3454 if (!count)
3455 active_match_ordinal = 0;
3456
3457 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3458 routing_id_,
3459 request_id,
3460 count,
3461 gfx::Rect(),
3462 active_match_ordinal,
3463 final_update);
3464
[email protected]8922e1f2009-10-03 05:01:263465 // If we have a message that has been queued up, then we should just replace
3466 // it. The ACK from the browser will make sure it gets sent when the browser
3467 // wants it.
3468 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263469 queued_find_reply_message_.reset(msg);
3470 } else {
3471 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113472 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263473 }
3474}
3475
3476void RenderView::reportFindInPageSelection(int request_id,
3477 int active_match_ordinal,
3478 const WebRect& selection_rect) {
3479 // Send the search result over to the browser process.
3480 Send(new ViewHostMsg_Find_Reply(routing_id_,
3481 request_id,
3482 -1,
3483 selection_rect,
3484 active_match_ordinal,
3485 false));
3486}
3487
[email protected]2b06a992010-08-21 05:48:223488void RenderView::openFileSystem(
3489 WebFrame* frame,
3490 WebFileSystem::Type type,
3491 long long size,
3492 WebFileSystemCallbacks* callbacks) {
3493 scoped_ptr<PendingOpenFileSystem> request(
3494 new PendingOpenFileSystem(callbacks));
3495
3496 WebSecurityOrigin origin = frame->securityOrigin();
3497 if (origin.isEmpty())
3498 return; // Uninitialized document?
3499
3500 ViewHostMsg_OpenFileSystemRequest_Params params;
3501 params.routing_id = routing_id_;
3502 params.request_id = pending_file_system_requests_.Add(request.release());
3503 params.origin_url = GURL(origin.toString());
3504 params.type = type;
3505 params.requested_size = size;
3506
3507 Send(new ViewHostMsg_OpenFileSystemRequest(params));
3508}
3509
[email protected]79dbc662009-09-04 05:42:513510// webkit_glue::WebPluginPageDelegate -----------------------------------------
3511
[email protected]f103ab72009-09-02 17:10:593512webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533513 const FilePath& file_path,
3514 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593515 if (!PluginChannelHost::IsListening())
3516 return NULL;
3517
[email protected]d2139662009-12-10 03:21:143518 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283519 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143520 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163521 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533522 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143523 if (CommandLine::ForCurrentProcess()->
3524 HasSwitch(switches::kInternalPepper)) {
3525 in_process_plugin = true;
3526 use_pepper_host = true;
3527 } else {
3528 // In process Pepper plugins must be explicitly enabled.
3529 return NULL;
3530 }
[email protected]4e0616e2010-05-28 14:55:533531 } else {
3532 FilePath internal_pdf_path;
3533 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3534 if (file_path == internal_pdf_path) {
3535 in_process_plugin = true;
3536 use_pepper_host = true;
3537 }
[email protected]26e8d5e2009-10-13 02:47:163538 }
[email protected]4e0616e2010-05-28 14:55:533539
[email protected]d2139662009-12-10 03:21:143540 // Check for Native Client modules.
[email protected]5cad70a82010-09-03 22:14:113541 if (mime_type == "application/x-nacl-srpc" &&
3542 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
[email protected]8f05f7f2010-07-30 23:12:433543 // NaCl is only permitted when we're in an extension/application with the
3544 // appropriate permission, or when explicitly enabled on the command line.
3545
[email protected]8f05f7f2010-07-30 23:12:433546 GURL main_frame_url(webview()->mainFrame()->url());
[email protected]5351dbc2010-08-27 15:22:113547 ExtensionRendererInfo* extension =
3548 ExtensionRendererInfo::GetByURL(main_frame_url);
3549 bool in_ext = extension != NULL;
[email protected]8f05f7f2010-07-30 23:12:433550 bool explicit_enable =
3551 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3552
3553 if (in_ext) {
[email protected]5cad70a82010-09-03 22:14:113554 // TODO(cbiffle): NaCl is back to experimental for M7.
[email protected]5351dbc2010-08-27 15:22:113555 if (ExtensionProcessBindings::HasPermission(extension->id(),
[email protected]5cad70a82010-09-03 22:14:113556 Extension::kExperimentalPermission)) {
[email protected]8f05f7f2010-07-30 23:12:433557 in_process_plugin = true;
3558 use_pepper_host = true;
3559 } else {
3560 // Disable NaCl for apps lacking the permission, even with the flag.
3561 return NULL;
3562 }
3563 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463564 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143565 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463566 }
3567 }
[email protected]4e0616e2010-05-28 14:55:533568
[email protected]d032f492009-09-29 00:33:463569 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143570 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283571 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533572 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333573 if (!pepper_plugin)
3574 return NULL;
3575
[email protected]53900d52010-06-16 04:25:013576 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283577 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143578 } else {
[email protected]6876dff2010-01-15 19:38:093579#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143580 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533581 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093582#else
[email protected]596b2c42010-01-14 20:40:433583 NOTIMPLEMENTED();
3584 return NULL;
[email protected]7b6616f2010-01-14 18:07:553585#endif
[email protected]6876dff2010-01-15 19:38:093586 }
[email protected]f103ab72009-09-02 17:10:593587 }
3588
[email protected]4e0616e2010-05-28 14:55:533589 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593590}
3591
3592void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033593#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593594 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3595 routing_id(), window));
3596#endif
3597}
3598
3599void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033600#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593601 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3602 routing_id(), window));
3603#endif
3604 CleanupWindowInPluginMoves(window);
3605}
3606
3607void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3608 SchedulePluginMove(move);
3609}
3610
3611void RenderView::DidStartLoadingForPlugin() {
3612 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523613 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593614}
3615
3616void RenderView::DidStopLoadingForPlugin() {
3617 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523618 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593619}
3620
3621void RenderView::ShowModalHTMLDialogForPlugin(
3622 const GURL& url,
3623 const gfx::Size& size,
3624 const std::string& json_arguments,
3625 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213626 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593627 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213628 json_retval));
[email protected]f103ab72009-09-02 17:10:593629}
3630
[email protected]b921cfd22010-02-25 16:57:513631WebCookieJar* RenderView::GetCookieJar() {
3632 return &cookie_jar_;
3633}
3634
initial.commit09911bf2008-07-26 23:55:293635void RenderView::SyncNavigationState() {
3636 if (!webview())
3637 return;
3638
[email protected]26aa0482009-09-30 16:55:273639 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173640 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293641 return;
[email protected]ca948a22009-06-25 19:36:173642
3643 Send(new ViewHostMsg_UpdateState(
3644 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293645}
3646
[email protected]b0950a72009-09-29 23:16:173647bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3648 // Make sure webview was not shut down.
3649 if (!webview())
3650 return false;
3651 // Create an image resource fetcher and assign it with a call back object.
3652 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273653 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173654 NewCallback(this, &RenderView::DidDownloadImage)));
3655 return true;
3656}
3657
3658void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293659 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173660 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473661 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3662 fetcher->id(),
3663 fetcher->image_url(),
3664 image.isNull(),
3665 image));
[email protected]b0950a72009-09-29 23:16:173666 // Dispose of the image fetcher.
3667 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3668 image_fetchers_.erase(fetcher);
3669 // We're in the callback from the ImageResourceFetcher, best to delay
3670 // deletion.
3671 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293672}
3673
[email protected]bf5c2ff392009-07-08 16:24:333674void RenderView::OnDownloadFavIcon(int id,
3675 const GURL& image_url,
3676 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343677 bool data_image_failed = false;
3678 if (image_url.SchemeIs("data")) {
3679 SkBitmap data_image = ImageFromDataUrl(image_url);
3680 data_image_failed = data_image.empty();
3681 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333682 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3683 data_image));
[email protected]f11ca0732009-04-11 00:09:343684 }
3685 }
3686
[email protected]bf5c2ff392009-07-08 16:24:333687 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173688 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333689 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3690 SkBitmap()));
3691 }
initial.commit09911bf2008-07-26 23:55:293692}
3693
[email protected]f11ca0732009-04-11 00:09:343694SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3695 std::string mime_type, char_set, data;
3696 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3697 // Decode the favicon using WebKit's image decoder.
3698 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3699 const unsigned char* src_data =
3700 reinterpret_cast<const unsigned char*>(&data[0]);
3701
3702 return decoder.Decode(src_data, data.size());
3703 }
3704 return SkBitmap();
3705}
3706
initial.commit09911bf2008-07-26 23:55:293707void RenderView::OnGetApplicationInfo(int page_id) {
3708 webkit_glue::WebApplicationInfo app_info;
3709 if (page_id == page_id_)
3710 webkit_glue::GetApplicationInfo(webview(), &app_info);
3711
3712 // Prune out any data URLs in the set of icons. The browser process expects
3713 // any icon with a data URL to have originated from a favicon. We don't want
3714 // to decode arbitrary data URLs in the browser process. See
3715 // http://b/issue?id=1162972
3716 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593717 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293718 app_info.icons.erase(app_info.icons.begin() + i);
3719 --i;
3720 }
3721 }
3722
3723 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3724}
3725
[email protected]7ccddb8c2009-08-04 17:36:553726GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293727 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553728 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293729 // If the URL that failed was secure, then the embedding web page was not
3730 // expecting a network attacker to be able to manipulate its contents. As
3731 // we fetch alternate error pages over HTTP, we would be allowing a network
3732 // attacker to manipulate the contents of the response if we tried to use
3733 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153734 return GURL();
initial.commit09911bf2008-07-26 23:55:293735 }
3736
3737 // Grab the base URL from the browser process.
3738 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153739 return GURL();
initial.commit09911bf2008-07-26 23:55:293740
3741 // Strip query params from the failed URL.
3742 GURL::Replacements remove_params;
3743 remove_params.ClearUsername();
3744 remove_params.ClearPassword();
3745 remove_params.ClearQuery();
3746 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553747 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503748 std::string spec_to_send = url_to_send.spec();
3749 // Notify link doctor of the url truncation by sending of "?" at the end.
3750 if (failed_url.has_query())
3751 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293752
3753 // Construct the query params to send to link doctor.
3754 std::string params(alternate_error_page_url_.query());
3755 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503756 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293757 params.append("&sourceid=chrome");
3758 params.append("&error=");
3759 switch (error_type) {
3760 case DNS_ERROR:
3761 params.append("dnserror");
3762 break;
3763
3764 case HTTP_404:
3765 params.append("http404");
3766 break;
3767
[email protected]5df266ac2008-10-15 19:50:133768 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333769 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133770 break;
3771
initial.commit09911bf2008-07-26 23:55:293772 default:
3773 NOTREACHED() << "unknown ErrorPageType";
3774 }
3775
3776 // OK, build the final url to return.
3777 GURL::Replacements link_doctor_params;
3778 link_doctor_params.SetQueryStr(params);
3779 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3780 return url;
3781}
3782
[email protected]0fdbf8c2010-07-08 20:33:013783WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3784 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493785}
3786
[email protected]6069da8c2009-10-20 20:33:493787void RenderView::OnFind(int request_id, const string16& search_text,
3788 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273789 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493790
3791 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493792 if (options.findNext) {
3793 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013794 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493795 } else {
[email protected]afdbd142010-07-10 08:01:233796 if (GetWebPluginFromPluginDocument()->startFind(
3797 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493798 } else {
[email protected]e7c58a32010-08-13 19:47:113799 // Send "no results".
3800 Send(new ViewHostMsg_Find_Reply(routing_id_,
3801 request_id,
3802 0,
3803 gfx::Rect(),
3804 0,
3805 true));
[email protected]24a7f3c2010-03-25 08:26:493806 }
3807 }
3808 return;
3809 }
3810
[email protected]b4bb2502009-10-01 22:35:273811 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273812 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293813 WebFrame* search_frame = focused_frame; // start searching focused frame.
3814
3815 bool multi_frame = (frame_after_main != main_frame);
3816
3817 // If we have multiple frames, we don't want to wrap the search within the
3818 // frame, so we check here if we only have main_frame in the chain.
3819 bool wrap_within_frame = !multi_frame;
3820
[email protected]b3f2b912009-04-09 16:18:523821 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293822 bool result = false;
3823
[email protected]7830da3e2009-11-06 16:27:263824 // If something is selected when we start searching it means we cannot just
3825 // increment the current match ordinal; we need to re-generate it.
3826 WebRange current_selection = focused_frame->selectionRange();
3827
initial.commit09911bf2008-07-26 23:55:293828 do {
[email protected]dd7daa82009-08-10 05:46:453829 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593830 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293831
3832 if (!result) {
3833 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223834 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293835
3836 // Find the next frame, but skip the invisible ones.
3837 do {
3838 // What is the next frame to search? (we might be going backwards). Note
3839 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593840 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273841 search_frame->traverseNext(true) :
3842 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453843 } while (!search_frame->hasVisibleContent() &&
3844 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293845
[email protected]884db412008-11-24 23:46:503846 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223847 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293848
3849 // If we have multiple frames and we have wrapped back around to the
3850 // focused frame, we need to search it once more allowing wrap within
3851 // the frame, otherwise it will report 'no match' if the focused frame has
3852 // reported matches, but no frames after the focused_frame contain a
3853 // match for the search word(s).
3854 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453855 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593856 request_id, search_text, options, true, // Force wrapping.
3857 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293858 }
3859 }
3860
[email protected]26aa0482009-09-30 16:55:273861 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293862 } while (!result && search_frame != focused_frame);
3863
[email protected]7830da3e2009-11-06 16:27:263864 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293865 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453866 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293867 } else {
3868 // If nothing is found, set result to "0 of 0", otherwise, set it to
3869 // "-1 of 1" to indicate that we found at least one item, but we don't know
3870 // yet what is active.
3871 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3872 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293873
[email protected]4f3dc372009-02-24 00:10:293874 // If we find no matches then this will be our last status update.
3875 // Otherwise the scoping effort will send more results.
3876 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293877
[email protected]4f3dc372009-02-24 00:10:293878 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403879 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593880 request_id,
[email protected]4f3dc372009-02-24 00:10:293881 match_count,
3882 selection_rect,
3883 ordinal,
3884 final_status_update));
initial.commit09911bf2008-07-26 23:55:293885
initial.commit09911bf2008-07-26 23:55:293886 // Scoping effort begins, starting with the mainframe.
3887 search_frame = main_frame;
3888
[email protected]dd7daa82009-08-10 05:46:453889 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293890
3891 do {
3892 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453893 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293894
3895 // We don't start another scoping effort unless at least one match has
3896 // been found.
3897 if (result) {
3898 // Start new scoping request. If the scoping function determines that it
3899 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453900 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593901 search_text,
3902 options,
initial.commit09911bf2008-07-26 23:55:293903 true); // reset the tickmarks
3904 }
3905
3906 // Iterate to the next frame. The frame will not necessarily scope, for
3907 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273908 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293909 } while (search_frame != main_frame);
3910 }
3911}
3912
[email protected]24a7f3c2010-03-25 08:26:493913void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3914 WebView* view = webview();
3915 if (!view)
3916 return;
3917
3918 WebDocument doc = view->mainFrame()->document();
3919 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013920 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493921 return;
3922 }
3923
3924 bool clear_selection =
3925 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3926 if (clear_selection)
3927 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3928
3929 WebFrame* frame = view->mainFrame();
3930 while (frame) {
3931 frame->stopFinding(clear_selection);
3932 frame = frame->traverseNext(false);
3933 }
3934
3935 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3936 WebFrame* focused_frame = view->focusedFrame();
3937 if (focused_frame) {
3938 WebDocument doc = focused_frame->document();
3939 if (!doc.isNull()) {
3940 WebNode node = doc.focusedNode();
3941 if (!node.isNull())
3942 node.simulateClick();
3943 }
3944 }
3945 }
3946}
3947
3948void RenderView::OnFindReplyAck() {
3949 // Check if there is any queued up request waiting to be sent.
3950 if (queued_find_reply_message_.get()) {
3951 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423952 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493953 }
3954}
3955
[email protected]8934a3b2010-02-25 00:34:003956bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353957 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003958 return current_content_settings_.settings[settings_type] !=
3959 CONTENT_SETTING_BLOCK;
3960}
3961
[email protected]55126132010-08-19 14:53:283962void RenderView::DidBlockContentType(ContentSettingsType settings_type,
3963 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:003964 if (!content_blocked_[settings_type]) {
3965 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:283966 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
3967 resource_identifier));
[email protected]0de80162010-02-03 04:52:353968 }
[email protected]0de80162010-02-03 04:52:353969}
3970
[email protected]71b0d5d2010-02-15 05:43:073971void RenderView::ClearBlockedContentSettings() {
3972 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3973 content_blocked_[i] = false;
3974}
3975
[email protected]aad51d1c2010-08-05 08:38:093976WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame,
3977 const WebPluginParams& params,
3978 const FilePath& path,
3979 pepper::PluginModule* pepper_module) {
3980 WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params,
3981 pepper_delegate_.AsWeakPtr());
3982 if (plugin && !frame->parent() && frame->document().isPluginDocument()) {
3983 // If this is a full-page plugin hosting the internal PDF plugin, we want
3984 // to notify the browser so that it can treat things like zooming
3985 // differently.
3986 // TODO(sanjeevr): Use a Pepper interface to determine this rather than
3987 // hardcode this for the PDF plugin path.
3988 FilePath pdf_path;
3989 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
3990 if (path == pdf_path)
3991 Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_));
[email protected]0cdafff2010-07-26 09:54:373992 }
[email protected]aad51d1c2010-08-05 08:38:093993 return plugin;
3994}
[email protected]00152e92010-07-19 11:47:403995
[email protected]aad51d1c2010-08-05 08:38:093996WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame,
3997 const WebPluginParams& params,
3998 const FilePath& path,
3999 const std::string& mime_type) {
4000 std::string actual_mime_type(mime_type);
[email protected]00152e92010-07-19 11:47:404001 if (actual_mime_type.empty())
4002 actual_mime_type = params.mimeType.utf8();
4003
[email protected]aad51d1c2010-08-05 08:38:094004 return new webkit_glue::WebPluginImpl(frame, params, path,
[email protected]7a13e792010-08-03 08:18:244005 actual_mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404006}
4007
4008WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame,
[email protected]851b1eb2010-08-09 13:32:294009 const WebPluginParams& params,
4010 PluginGroup* group) {
[email protected]00152e92010-07-19 11:47:404011 // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed.
[email protected]851b1eb2010-08-09 13:32:294012 BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params, group);
[email protected]00152e92010-07-19 11:47:404013 WebViewPlugin* plugin = blocked_plugin->plugin();
[email protected]851b1eb2010-08-09 13:32:294014 WebView* web_view = plugin->web_view();
4015 webkit_preferences_.Apply(web_view);
[email protected]00152e92010-07-19 11:47:404016 return plugin;
4017}
4018
[email protected]40bd6582009-12-04 23:49:514019void RenderView::OnZoom(PageZoom::Function function) {
4020 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4021 return;
4022
[email protected]258d31122010-05-09 10:59:414023 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524024
[email protected]40bd6582009-12-04 23:49:514025 int zoom_level = webview()->zoomLevel();
4026 int new_zoom_level = webview()->setZoomLevel(false,
4027 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
4028
[email protected]9d797f32010-04-23 07:17:544029 // Tell the browser which url got zoomed so it can update the saved values.
4030 Send(new ViewHostMsg_DidZoomURL(
4031 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:514032}
4033
[email protected]9d797f32010-04-23 07:17:544034void RenderView::OnSetContentSettingsForLoadingURL(
4035 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014036 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544037 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014038}
4039
[email protected]9d797f32010-04-23 07:17:544040void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
4041 int zoom_level) {
4042 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294043}
4044
[email protected]41fc0322009-09-04 22:23:404045void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274046 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294047}
4048
[email protected]a697f4c2009-09-14 22:30:184049void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274050 WebString no_encoding;
4051 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184052}
4053
[email protected]20ad2692009-11-20 18:27:204054bool RenderView::GetAllChildFrames(
4055 WebFrame* parent_frame,
4056 std::vector<WebFrame*>* frames_vector) const {
4057 if (!parent_frame)
4058 return false;
4059 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4060 child_frame = child_frame->nextSibling()) {
4061 frames_vector->push_back(child_frame);
4062 GetAllChildFrames(child_frame, frames_vector);
4063 }
4064 return true;
4065}
4066
[email protected]dd7daa82009-08-10 05:46:454067WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4068 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274069 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454070
4071 // xpath string can represent a frame deep down the tree (across multiple
4072 // frame DOMs).
4073 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4074 // should break into 2 xpaths
4075 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4076
[email protected]26aa0482009-09-30 16:55:274077 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454078
4079 std::wstring xpath_remaining = xpath;
4080 while (!xpath_remaining.empty()) {
4081 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4082 std::wstring xpath_child;
4083 if (delim_pos != std::wstring::npos) {
4084 xpath_child = xpath_remaining.substr(0, delim_pos);
4085 xpath_remaining.erase(0, delim_pos + 1);
4086 } else {
4087 xpath_remaining.swap(xpath_child);
4088 }
4089 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294090 }
4091
[email protected]dd7daa82009-08-10 05:46:454092 return frame;
initial.commit09911bf2008-07-26 23:55:294093}
4094
[email protected]15d9c0c2010-09-10 22:36:264095void RenderView::SetSuggestResult(const std::string& suggest) {
4096 if (!suggest.empty())
4097 Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest));
4098}
4099
[email protected]f29acf52008-11-03 20:08:334100void RenderView::EvaluateScript(const std::wstring& frame_xpath,
4101 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:294102 WebFrame* web_frame = GetChildFrame(frame_xpath);
4103 if (!web_frame)
4104 return;
4105
[email protected]dd7daa82009-08-10 05:46:454106 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:294107}
4108
[email protected]1810e132009-03-24 23:35:484109void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084110 const std::string& css,
4111 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484112 WebFrame* web_frame = GetChildFrame(frame_xpath);
4113 if (!web_frame)
4114 return;
4115
[email protected]ffaef0c2009-09-15 17:08:084116 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484117}
4118
[email protected]00c39612010-03-06 02:53:284119void RenderView::OnPepperPluginDestroy(
4120 WebPluginDelegatePepper* pepper_plugin) {
4121 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014122 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4123 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284124 NOTREACHED();
4125 return;
4126 }
[email protected]53900d52010-06-16 04:25:014127 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474128
4129 // The plugin could have been destroyed while it was waiting for a file
4130 // choose callback, so check all pending completion callbacks and NULL them.
4131 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4132 file_chooser_completions_.begin();
4133 i != file_chooser_completions_.end(); /* nothing */) {
4134 if ((*i)->completion == pepper_plugin) {
4135 // We NULL the first one instead of deleting it because the plugin might
4136 // be the one waiting for a file choose callback. If the callback later
4137 // comes, we don't want to send the result to the next callback in line.
4138 if (i == file_chooser_completions_.begin())
4139 (*i)->completion = NULL;
4140 else
4141 i = file_chooser_completions_.erase(i);
4142 } else {
4143 ++i;
4144 }
4145 }
[email protected]00c39612010-03-06 02:53:284146}
4147
initial.commit09911bf2008-07-26 23:55:294148void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
4149 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:334150 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:294151}
4152
[email protected]1810e132009-03-24 23:35:484153void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084154 const std::string& css,
4155 const std::string& id) {
4156 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414157
4158 // Notify RenderViewHost that css has been inserted into the frame.
4159 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484160}
4161
[email protected]7ea066a2009-04-06 20:21:594162void RenderView::OnAddMessageToConsole(
4163 const string16& frame_xpath,
4164 const string16& message,
4165 const WebConsoleMessage::Level& level) {
4166 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594167 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454168 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294169}
4170
[email protected]81e63782009-02-27 19:35:094171void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4172 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294173}
4174
4175void RenderView::OnSetDOMUIProperty(const std::string& name,
4176 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094177 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:294178 dom_ui_bindings_.SetProperty(name, value);
4179}
4180
4181void RenderView::OnReservePageIDRange(int size_of_range) {
4182 next_page_id_ += size_of_range + 1;
4183}
4184
[email protected]e80c73b2009-04-07 23:24:584185void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4186 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254187 bool ended,
4188 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034189 if (ended) {
[email protected]26aa0482009-09-30 16:55:274190 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204191 } else {
4192 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034193 }
initial.commit09911bf2008-07-26 23:55:294194}
4195
4196void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274197 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294198}
4199
initial.commit09911bf2008-07-26 23:55:294200void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:164201 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:084202#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:064203 password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(),
[email protected]03f57072010-07-14 17:36:084204 form_data);
[email protected]ad24ccb2010-07-15 21:38:204205#else
4206 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:084207#endif
initial.commit09911bf2008-07-26 23:55:294208}
4209
4210void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584211 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254212 const gfx::Point& screen_point,
4213 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274214 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584215 drop_data.ToDragData(),
4216 drop_data.identity,
4217 client_point,
[email protected]1d9f4132009-09-08 17:29:254218 screen_point,
4219 ops);
initial.commit09911bf2008-07-26 23:55:294220
[email protected]1d9f4132009-09-08 17:29:254221 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294222}
4223
[email protected]e80c73b2009-04-07 23:24:584224void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254225 const gfx::Point& screen_point,
4226 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274227 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254228 client_point,
4229 screen_point,
4230 ops);
initial.commit09911bf2008-07-26 23:55:294231
[email protected]1d9f4132009-09-08 17:29:254232 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294233}
4234
4235void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274236 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294237}
4238
[email protected]e80c73b2009-04-07 23:24:584239void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4240 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274241 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294242}
4243
4244void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594245 webkit_preferences_ = prefs;
4246 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294247}
4248
4249void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4250 alternate_error_page_url_ = url;
4251}
4252
[email protected]a0c7153e2009-12-09 14:36:334253void RenderView::OnCustomContextMenuAction(unsigned action) {
4254 webview()->performCustomContextMenuAction(action);
4255}
4256
[email protected]d4a00a72010-01-29 01:44:424257void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024258 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424259 const std::string& source_lang,
4260 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024261 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4262 translate_script);
[email protected]d4a00a72010-01-29 01:44:424263}
4264
[email protected]85d252e2010-04-06 22:21:024265void RenderView::OnRevertTranslation(int page_id) {
4266 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324267}
4268
initial.commit09911bf2008-07-26 23:55:294269void RenderView::OnInstallMissingPlugin() {
4270 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594271 if (first_default_plugin_)
4272 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294273}
4274
[email protected]97c5c592010-08-03 08:22:214275void RenderView::OnLoadBlockedPlugins() {
4276 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4277 Source<RenderView>(this),
4278 NotificationService::NoDetails());
4279}
4280
[email protected]cdaf8d02010-03-30 19:52:474281void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364282 // This could happen if we navigated to a different page before the user
4283 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474284 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364285 return;
4286
[email protected]cdaf8d02010-03-30 19:52:474287 WebVector<WebString> ws_file_names(paths.size());
4288 for (size_t i = 0; i < paths.size(); ++i)
4289 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464290
[email protected]cdaf8d02010-03-30 19:52:474291 if (file_chooser_completions_.front()->completion)
4292 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4293 file_chooser_completions_.pop_front();
4294
4295 // If there are more pending file chooser requests, schedule one now.
4296 if (!file_chooser_completions_.empty()) {
4297 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4298 file_chooser_completions_.front()->params));
4299 }
initial.commit09911bf2008-07-26 23:55:294300}
4301
4302void RenderView::OnEnableViewSourceMode() {
4303 if (!webview())
4304 return;
[email protected]26aa0482009-09-30 16:55:274305 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294306 if (!main_frame)
4307 return;
4308
[email protected]dd7daa82009-08-10 05:46:454309 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294310}
4311
[email protected]770dd8b2010-05-24 18:11:394312void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4313 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244314 if (send_preferred_size_changes_)
4315 return;
[email protected]9fb325e2010-05-06 18:23:244316 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394317
4318 // WebKit doesn't send a notification of the effective height of the page
4319 // changes, so poll for it.
4320 // TODO: Add a notification for this to WebKit, remove polling. After that's
4321 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4322 // http://crbug.com/44850
4323 if (flags & kPreferredSizeHeightThisIsSlow) {
4324 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4325 &RenderView::CheckPreferredSize);
4326 }
[email protected]0666aef2009-05-13 19:48:084327}
4328
[email protected]cda45c02010-02-25 19:28:104329void RenderView::OnDisableScrollbarsForSmallWindows(
4330 const gfx::Size& disable_scrollbar_size_limit) {
4331 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4332}
4333
[email protected]80d96fa2009-06-10 22:34:514334void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4335 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374336 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034337#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414338 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4339 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464340 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324341
[email protected]644d77e2010-01-27 01:03:104342 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324343 webview()->setScrollbarColors(
4344 renderer_prefs.thumb_inactive_color,
4345 renderer_prefs.thumb_active_color,
4346 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104347 webview()->setSelectionColors(
4348 renderer_prefs.active_selection_bg_color,
4349 renderer_prefs.active_selection_fg_color,
4350 renderer_prefs.inactive_selection_bg_color,
4351 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464352 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104353 }
[email protected]7a74e102009-09-03 00:16:564354#endif
[email protected]80d96fa2009-06-10 22:34:514355}
4356
[email protected]952cb702009-10-07 05:50:284357void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4358 const WebMediaPlayerAction& action) {
4359 if (webview())
4360 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564361}
4362
[email protected]7b291f92009-08-14 05:43:534363void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4364 view_type_ = type;
4365}
4366
4367void RenderView::OnUpdateBrowserWindowId(int window_id) {
4368 browser_window_id_ = window_id;
4369}
4370
[email protected]b3df5a42010-05-11 14:31:094371void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364372 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414373 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114374 accessibility_.reset(WebAccessibilityCache::create());
4375 accessibility_->initialize(webview());
[email protected]520cb7d72010-08-31 11:54:314376 accessibility_changes_.clear();
[email protected]9f4db512010-05-10 20:21:414377
[email protected]b3df5a42010-05-11 14:31:094378 WebAccessibilityObject src_tree = webview()->accessibilityObject();
[email protected]416ac2e2010-09-01 17:15:164379 WebAccessibility dst_tree(src_tree, accessibility_.get());
[email protected]b3df5a42010-05-11 14:31:094380 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504381}
4382
[email protected]aef92842010-05-21 16:54:364383void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4384 if (!accessibility_.get())
4385 return;
4386 if (accessibility_->isValidId(acc_obj_id)) {
4387 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4388 // By convention, calling SetFocus on the root of the tree (id = 1000)
4389 // should clear the current focus. Otherwise set the focus to the new
4390 // node.
4391 if (acc_obj_id == 1000)
4392 webview()->clearFocusedNode();
4393 else
4394 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4395 }
4396}
4397
4398void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4399 if (!accessibility_.get())
4400 return;
4401 if (accessibility_->isValidId(acc_obj_id)) {
4402 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4403 }
4404}
4405
[email protected]520cb7d72010-08-31 11:54:314406void RenderView::OnAccessibilityObjectChildrenChangeAck() {
4407 if (!accessibility_.get())
4408 return;
4409
4410 if (!accessibility_changes_.empty()) {
4411 Send(new ViewHostMsg_AccessibilityObjectChildrenChange(
4412 routing_id_,
4413 accessibility_changes_));
4414 }
4415
4416 accessibility_changes_.clear();
4417}
4418
initial.commit09911bf2008-07-26 23:55:294419void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4420 const GURL& page_url) {
4421 // Prepare list to storage all savable resource links.
4422 std::vector<GURL> resources_list;
4423 std::vector<GURL> referrers_list;
4424 std::vector<GURL> frames_list;
4425 webkit_glue::SavableResourcesResult result(&resources_list,
4426 &referrers_list,
4427 &frames_list);
4428
[email protected]dbeb3952009-10-13 18:01:184429 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4430 webview(),
4431 page_url,
4432 &result,
4433 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294434 // If something is wrong when collecting all savable resource links,
4435 // send empty list to embedder(browser) to tell it failed.
4436 referrers_list.clear();
4437 resources_list.clear();
4438 frames_list.clear();
4439 }
4440
4441 // Send result of all savable resource links to embedder.
4442 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4443 resources_list,
4444 referrers_list,
4445 frames_list));
4446}
4447
4448void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324449 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314450 const std::vector<FilePath>& local_paths,
4451 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074452
4453 // Convert std::vector of GURLs to WebVector<WebURL>
4454 WebVector<WebURL> weburl_links(links);
4455
4456 // Convert std::vector of std::strings to WebVector<WebString>
4457 WebVector<WebString> webstring_paths(local_paths.size());
4458 for (size_t i = 0; i < local_paths.size(); i++)
4459 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4460
4461 WebPageSerializer::serialize(webview()->mainFrame(),
4462 true, this, weburl_links, webstring_paths,
4463 webkit_glue::FilePathToWebString(
4464 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294465}
4466
[email protected]d9ec5c0f2009-12-23 11:55:074467void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4468 const WebCString& data,
4469 WebPageSerializerClient::PageSerializationStatus status) {
4470 Send(new ViewHostMsg_SendSerializedHtmlData(
4471 routing_id_,
4472 frame_url,
4473 data.data(),
4474 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294475}
4476
[email protected]9b18a84f2010-06-10 15:54:044477void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274478 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474479 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294480}
4481
[email protected]eb6b87a2009-07-24 15:57:394482void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294483 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4484 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4485 // in the onunload handler from appearing. For now, we're bypassing that and
4486 // calling the FrameLoader's CloseURL method directly. This should be
4487 // revisited to avoid having two ways to close a page. Having a single way
4488 // to close that can run onunload is also useful for fixing
4489 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274490 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294491 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454492 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174493 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294494 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4495 // multiple times for the same frame, but it will simplify things.
[email protected]05c8e502010-08-15 15:13:524496
4497 // Ensure state contains scheme.
4498 NavigationState* navigation_state =
4499 NavigationState::FromDataSource(main_frame->dataSource());
4500 if (url.SchemeIs("http"))
4501 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
4502 else if (url.SchemeIs("https"))
4503 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
4504
4505 // Dump will only be provided when scheme is http or https.
4506 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294507 }
[email protected]26aa0482009-09-30 16:55:274508 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294509
[email protected]ab9eabac2010-03-16 16:54:104510 // Reset stats
4511 cross_origin_access_count_ = 0;
4512 same_origin_access_count_ = 0;
4513
[email protected]eb6b87a2009-07-24 15:57:394514 // Just echo back the params in the ACK.
4515 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294516}
4517
4518void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574519#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294520 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464521 if (webview())
4522 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574523#else // defined(OS_WIN)
4524 // TODO(port): we don't support theming on non-Windows platforms yet
4525 NOTIMPLEMENTED();
4526#endif
initial.commit09911bf2008-07-26 23:55:294527}
4528
[email protected]9b18a84f2010-06-10 15:54:044529void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4530 const std::string& origin,
4531 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154532 if (message.empty())
4533 return;
[email protected]28790922009-03-09 19:48:374534 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4535 target);
[email protected]3ac14a052008-08-15 21:22:154536}
4537
[email protected]0aa55312008-10-17 21:53:084538void RenderView::OnDisassociateFromPopupCount() {
4539 if (decrement_shared_popup_at_destruction_)
4540 shared_popup_counter_->data--;
4541 shared_popup_counter_ = new SharedRenderViewCounter(0);
4542 decrement_shared_popup_at_destruction_ = false;
4543}
4544
[email protected]15d79e12009-08-02 19:23:454545bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4546 const WebURLError& error,
4547 bool replace) {
4548 // We only show alternate error pages in the main frame. They are
4549 // intended to assist the user when navigating, so there is not much
4550 // value in showing them for failed subframes. Ideally, we would be
4551 // able to use the TYPED transition type for this, but that flag is
4552 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454553 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454554 return false;
4555
4556 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374557 // connection failure.
[email protected]15d79e12009-08-02 19:23:454558 int ec = error.reason;
4559 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4560 ec != net::ERR_CONNECTION_FAILED &&
4561 ec != net::ERR_CONNECTION_REFUSED &&
4562 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374563 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454564 return false;
4565
4566 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554567 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454568 if (!error_page_url.is_valid())
4569 return false;
4570
4571 // Load an empty page first so there is an immediate response to the error,
4572 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454573 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454574 GURL(kUnreachableWebDataURL),
4575 error.unreachableURL,
4576 replace);
4577
4578 // Now, create a fetcher for the error page and associate it with the data
4579 // source we just created via the LoadHTMLString call. That way if another
4580 // navigation occurs, the fetcher will get destroyed.
4581 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454582 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454583 navigation_state->set_alt_error_page_fetcher(
4584 new AltErrorPageResourceFetcher(
4585 error_page_url, frame, error,
4586 NewCallback(this, &RenderView::AltErrorPageFinished)));
4587 return true;
4588}
4589
initial.commit09911bf2008-07-26 23:55:294590std::string RenderView::GetAltHTMLForTemplate(
4591 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394592 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294593 ResourceBundle::GetSharedInstance().GetRawDataResource(
4594 template_resource_id));
4595
4596 if (template_html.empty()) {
4597 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4598 return "";
4599 }
[email protected]7cd22a52009-07-14 00:40:254600
initial.commit09911bf2008-07-26 23:55:294601 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254602 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294603 template_html, &error_strings, "t");
4604}
[email protected]0e79b9e2009-02-13 04:20:484605
[email protected]15d79e12009-08-02 19:23:454606void RenderView::AltErrorPageFinished(WebFrame* frame,
4607 const WebURLError& original_error,
4608 const std::string& html) {
4609 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554610
4611 // If we failed to download the alternate error page, fall back to the
4612 // original error page if present. Otherwise, LoadNavigationErrorPage
4613 // will simply display a default error page.
4614 const std::string* html_to_load = &html;
4615 if (html.empty()) {
4616 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454617 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554618 html_to_load = &navigation_state->postponed_data();
4619 }
[email protected]3f853a52010-09-13 19:15:084620 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
4621 true);
[email protected]15d79e12009-08-02 19:23:454622}
4623
[email protected]30f75e62009-02-25 22:01:004624void RenderView::OnMoveOrResizeStarted() {
4625 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474626 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004627}
4628
[email protected]30f75e62009-02-25 22:01:004629void RenderView::OnResize(const gfx::Size& new_size,
4630 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104631 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474632 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104633
4634 if (send_preferred_size_changes_) {
4635 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4636 // either width or height, allow scroll bars.
4637 bool allow_scrollbars = (
4638 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244639 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104640 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4641 }
4642 }
4643
[email protected]30f75e62009-02-25 22:01:004644 RenderWidget::OnResize(new_size, resizer_rect);
4645}
[email protected]0aa477bd2009-03-23 22:21:434646
[email protected]00c39612010-03-06 02:53:284647void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014648 // Notify the pepper plugins that we started painting.
4649 pepper_delegate_.ViewInitiatedPaint();
4650
4651 // Notify any "old-style" pepper plugins that we started painting. This is
4652 // used for internal bookkeeping only, so we know that the set can not change
4653 // under us.
[email protected]00c39612010-03-06 02:53:284654 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014655 current_oldstyle_pepper_plugins_.begin();
4656 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284657 (*i)->RenderViewInitiatedPaint();
4658}
4659
4660void RenderView::DidFlushPaint() {
4661 // Notify any pepper plugins that we painted. This will call into the plugin,
4662 // and we it may ask to close itself as a result. This will, in turn, modify
4663 // our set, possibly invalidating the iterator. So we iterate on a copy that
4664 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014665 pepper_delegate_.ViewFlushedPaint();
4666
4667 // Notify any old-style pepper plugins that we painted. This will call into
4668 // the plugin, and we it may ask to close itself as a result. This will, in
4669 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4670 // a copy that won't change out from under us.
4671 // This should be deleted when we don't support old Pepper anymore.
4672 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284673 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4674 i != plugins.end(); ++i) {
4675 // The copy above makes sure our iterator is never invalid if some plugins
4676 // are destroyed. But some plugin may decide to close all of its views in
4677 // response to a paint in one of them, so we need to make sure each one is
4678 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014679 if (current_oldstyle_pepper_plugins_.find(*i) !=
4680 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284681 (*i)->RenderViewFlushedPaint();
4682 }
4683
4684 WebFrame* main_frame = webview()->mainFrame();
4685
4686 // If we have a provisional frame we are between the start and commit stages
4687 // of loading and we don't want to save stats.
4688 if (!main_frame->provisionalDataSource()) {
4689 WebDataSource* ds = main_frame->dataSource();
4690 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4691 DCHECK(navigation_state);
4692
[email protected]05c8e502010-08-15 15:13:524693 // TODO(jar): The following code should all be inside a method, probably in
4694 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284695 Time now = Time::Now();
4696 if (navigation_state->first_paint_time().is_null()) {
4697 navigation_state->set_first_paint_time(now);
4698 }
4699 if (navigation_state->first_paint_after_load_time().is_null() &&
4700 !navigation_state->finish_load_time().is_null()) {
4701 navigation_state->set_first_paint_after_load_time(now);
4702 }
4703 }
4704}
4705
[email protected]05d478752009-04-08 23:38:164706void RenderView::OnClearFocusedNode() {
4707 if (webview())
[email protected]26aa0482009-09-30 16:55:274708 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164709}
4710
[email protected]699ab0d2009-04-23 23:19:144711void RenderView::OnSetBackground(const SkBitmap& background) {
4712 if (webview())
[email protected]b4bb2502009-10-01 22:35:274713 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144714
4715 SetBackground(background);
4716}
4717
[email protected]8c66c5a2009-07-22 17:26:344718void RenderView::OnSetActive(bool active) {
4719 if (webview())
[email protected]b4bb2502009-10-01 22:35:274720 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264721
4722#if defined(OS_MACOSX)
4723 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4724 for (plugin_it = plugin_delegates_.begin();
4725 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4726 (*plugin_it)->SetWindowFocus(active);
4727 }
4728#endif
[email protected]8c66c5a2009-07-22 17:26:344729}
4730
[email protected]6ce7abc52010-02-02 18:40:144731#if defined(OS_MACOSX)
4732void RenderView::OnSetWindowVisibility(bool visible) {
4733 // Inform plugins that their container has changed visibility.
4734 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4735 for (plugin_it = plugin_delegates_.begin();
4736 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4737 (*plugin_it)->SetContainerVisibility(visible);
4738 }
4739}
[email protected]1e6e3c992010-02-08 15:52:134740
[email protected]4d51d5bf2010-07-26 18:48:264741void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4742 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134743 // Inform plugins that their window's frame has changed.
4744 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4745 for (plugin_it = plugin_delegates_.begin();
4746 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4747 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4748 }
4749}
[email protected]6ce7abc52010-02-02 18:40:144750#endif // OS_MACOSX
4751
[email protected]8b8e7c92010-08-19 18:05:564752void RenderView::SendExtensionRequest(
4753 const ViewHostMsg_DomMessage_Params& params) {
4754 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:274755}
4756
[email protected]c6619182009-05-12 14:59:324757void RenderView::OnExtensionResponse(int request_id,
4758 bool success,
4759 const std::string& response,
4760 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354761 ExtensionProcessBindings::HandleResponse(
4762 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274763}
[email protected]c20210e62009-04-03 21:39:264764
[email protected]7120f132009-07-20 21:05:374765void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494766 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194767 bool requires_incognito_access,
4768 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494769 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194770 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374771}
4772
[email protected]e7e4f3c2009-04-21 15:24:084773// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264774//
[email protected]c20210e62009-04-03 21:39:264775// The time points we keep are
4776// request: time document was requested by user
4777// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254778// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294779// finish_document: main document loaded, before onload()
[email protected]05c8e502010-08-15 15:13:524780// finish_all_loads: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294781// first_paint: first paint performed
4782// first_paint_after_load: first paint performed after load is finished
4783// begin: request if it was user requested, start otherwise
4784//
[email protected]e7e4f3c2009-04-21 15:24:084785// It's possible for the request time not to be set, if a client
4786// redirect had been done (the user never requested the page)
4787// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294788// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264789void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504790 // Configuration for PLT related histograms.
4791 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4792 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4793 static const size_t kPLTCount(100);
4794 #define PLT_HISTOGRAM(name, sample) \
4795 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4796
[email protected]26aa0482009-09-30 16:55:274797 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564798 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454799 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564800
[email protected]05c8e502010-08-15 15:13:524801 URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type();
4802 if (scheme_type == 0)
4803 return;
4804 DCHECK(scheme_type == URLPattern::SCHEME_HTTP ||
4805 scheme_type == URLPattern::SCHEME_HTTPS);
4806
[email protected]f9f4841b2010-03-20 05:41:424807 // If we've already dumped, do nothing.
4808 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294809 return;
[email protected]cf9a7bc2010-06-11 18:54:504810
4811 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454812 Time start = navigation_state->start_load_time();
4813 if (start.is_null())
4814 return; // Probably very premature abandonment of page.
4815 Time commit = navigation_state->commit_load_time();
4816 if (commit.is_null())
4817 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504818
[email protected]b855ebe62010-05-12 23:01:454819 // We properly handle null values for the next 3 variables.
4820 Time request = navigation_state->request_time();
4821 Time first_paint = navigation_state->first_paint_time();
4822 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454823 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]05c8e502010-08-15 15:13:524824 Time finish_all_loads = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564825
[email protected]f9f4841b2010-03-20 05:41:424826 // Handle case where user hits "stop" or "back" before loading completely.
[email protected]05c8e502010-08-15 15:13:524827 bool abandoned_page = finish_doc.is_null();
[email protected]f9f4841b2010-03-20 05:41:424828 if (abandoned_page) {
[email protected]05c8e502010-08-15 15:13:524829 finish_doc = Time::Now();
4830 navigation_state->set_finish_document_load_time(finish_doc);
[email protected]f9f4841b2010-03-20 05:41:424831 }
[email protected]f9f4841b2010-03-20 05:41:424832
[email protected]05c8e502010-08-15 15:13:524833 // TODO(jar): We should really discriminate the definition of "abandon" more
4834 // finely. We should have:
4835 // abandon_before_document_loaded
4836 // abandon_before_onload_fired
4837
4838 if (finish_all_loads.is_null()) {
4839 finish_all_loads = Time::Now();
4840 navigation_state->set_finish_load_time(finish_all_loads);
4841 } else {
4842 DCHECK(!abandoned_page); // How can the doc have finished but not the page?
[email protected]cf9a7bc2010-06-11 18:54:504843 if (!abandoned_page)
4844 return; // Don't try to record a stat which is broken.
[email protected]cf9a7bc2010-06-11 18:54:504845 }
4846
4847 // Note: Client side redirects will have no request time.
4848 Time begin = request.is_null() ? start : request;
4849 TimeDelta begin_to_finish_doc = finish_doc - begin;
[email protected]05c8e502010-08-15 15:13:524850 TimeDelta begin_to_finish_all_loads = finish_all_loads - begin;
4851 TimeDelta start_to_finish_all_loads = finish_all_loads - start;
[email protected]ef1d8d322010-06-13 18:31:254852 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424853
[email protected]a7ccc4d2010-01-27 08:14:484854 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504855
[email protected]05c8e502010-08-15 15:13:524856 // The above code sanitized all values of times, in preparation for creating
4857 // actual histograms. The remainder of this code could be run at destructor
4858 // time for the navigation_state, since all data is intact.
4859
[email protected]cf9a7bc2010-06-11 18:54:504860 // Aggregate PLT data across all link types.
4861 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4862 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4863 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254864 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504865 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
[email protected]05c8e502010-08-15 15:13:524866 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc);
[email protected]cf9a7bc2010-06-11 18:54:504867 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
[email protected]05c8e502010-08-15 15:13:524868 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504869 if (!request.is_null()) {
4870 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
[email protected]05c8e502010-08-15 15:13:524871 PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request);
[email protected]cf9a7bc2010-06-11 18:54:504872 }
[email protected]05c8e502010-08-15 15:13:524873 PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit);
[email protected]cf9a7bc2010-06-11 18:54:504874 if (!first_paint.is_null()) {
4875 DCHECK(begin <= first_paint);
4876 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4877 DCHECK(commit <= first_paint);
4878 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4879 }
4880 if (!first_paint_after_load.is_null()) {
4881 DCHECK(begin <= first_paint_after_load);
4882 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4883 first_paint_after_load - begin);
4884 DCHECK(commit <= first_paint_after_load);
4885 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4886 first_paint_after_load - commit);
[email protected]05c8e502010-08-15 15:13:524887 DCHECK(finish_all_loads <= first_paint_after_load);
[email protected]cf9a7bc2010-06-11 18:54:504888 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
[email protected]05c8e502010-08-15 15:13:524889 first_paint_after_load - finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504890 }
4891 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524892 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504893
4894 // Load type related histograms.
4895 switch (load_type) {
4896 case NavigationState::UNDEFINED_LOAD:
4897 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524898 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504899 break;
4900 case NavigationState::RELOAD:
4901 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524902 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504903 break;
4904 case NavigationState::HISTORY_LOAD:
4905 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524906 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504907 break;
4908 case NavigationState::NORMAL_LOAD:
4909 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524910 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504911 break;
4912 case NavigationState::LINK_LOAD_NORMAL:
4913 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4914 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524915 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal",
4916 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504917 break;
4918 case NavigationState::LINK_LOAD_RELOAD:
4919 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4920 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524921 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload",
4922 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504923 break;
4924 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4925 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4926 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524927 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk",
4928 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504929 break;
4930 case NavigationState::LINK_LOAD_CACHE_ONLY:
4931 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4932 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524933 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly",
4934 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504935 break;
4936 default:
4937 break;
4938 }
4939
4940 // Histograms to determine if DNS prefetching has an impact on PLT.
4941 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4942 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4943 if (use_dns_histogram) {
4944 UMA_HISTOGRAM_ENUMERATION(
4945 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4946 abandoned_page ? 1 : 0, 2);
4947 UMA_HISTOGRAM_ENUMERATION(
4948 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4949 load_type, NavigationState::kLoadTypeMax);
4950 switch (load_type) {
4951 case NavigationState::NORMAL_LOAD:
4952 PLT_HISTOGRAM(FieldTrial::MakeName(
[email protected]05c8e502010-08-15 15:13:524953 "PLT.BeginToFinish_NormalLoad", "DnsImpact"),
4954 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504955 break;
4956 case NavigationState::LINK_LOAD_NORMAL:
4957 PLT_HISTOGRAM(FieldTrial::MakeName(
4958 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524959 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504960 break;
4961 case NavigationState::LINK_LOAD_RELOAD:
4962 PLT_HISTOGRAM(FieldTrial::MakeName(
4963 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524964 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504965 break;
4966 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4967 PLT_HISTOGRAM(FieldTrial::MakeName(
4968 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524969 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504970 break;
4971 default:
4972 break;
4973 }
4974 }
4975
[email protected]8a3125a712010-08-09 18:58:514976 // Histograms to determine if content prefetching has an impact on PLT.
4977 static const bool prefetching_fieldtrial =
4978 FieldTrialList::Find("Prefetch") &&
4979 !FieldTrialList::Find("Prefetch")->group_name().empty();
[email protected]13ae2df92010-08-19 20:05:104980 if (prefetching_fieldtrial) {
4981 if (navigation_state->was_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:514982 PLT_HISTOGRAM(
4983 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher",
4984 "Prefetch"),
4985 begin_to_finish_doc);
4986 PLT_HISTOGRAM(
4987 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher",
4988 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:524989 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:514990 }
[email protected]13ae2df92010-08-19 20:05:104991 if (navigation_state->was_referred_by_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:514992 PLT_HISTOGRAM(
4993 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcherReferrer",
4994 "Prefetch"),
4995 begin_to_finish_doc);
4996 PLT_HISTOGRAM(
4997 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcherReferrer",
4998 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:524999 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515000 }
[email protected]8a3125a712010-08-09 18:58:515001 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName("PLT.Abandoned", "Prefetch"),
5002 abandoned_page ? 1 : 0, 2);
5003 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinishDoc", "Prefetch"),
5004 begin_to_finish_doc);
5005 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525006 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515007 }
5008
[email protected]06d94042010-08-25 01:45:225009 // Histograms to determine if backup connection jobs have an impact on PLT.
5010 static const bool connect_backup_jobs_fieldtrial(
5011 FieldTrialList::Find("ConnnectBackupJobs") &&
5012 !FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty());
5013 if (connect_backup_jobs_fieldtrial) {
5014 UMA_HISTOGRAM_ENUMERATION(
5015 FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"),
5016 abandoned_page ? 1 : 0, 2);
5017 UMA_HISTOGRAM_ENUMERATION(
5018 FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"),
5019 load_type, NavigationState::kLoadTypeMax);
5020 switch (load_type) {
5021 case NavigationState::NORMAL_LOAD:
5022 PLT_HISTOGRAM(FieldTrial::MakeName(
5023 "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"),
5024 begin_to_finish_all_loads);
5025 break;
5026 case NavigationState::LINK_LOAD_NORMAL:
5027 PLT_HISTOGRAM(FieldTrial::MakeName(
5028 "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"),
5029 begin_to_finish_all_loads);
5030 break;
5031 case NavigationState::LINK_LOAD_RELOAD:
5032 PLT_HISTOGRAM(FieldTrial::MakeName(
5033 "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"),
5034 begin_to_finish_all_loads);
5035 break;
5036 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5037 PLT_HISTOGRAM(FieldTrial::MakeName(
5038 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"),
5039 begin_to_finish_all_loads);
5040 break;
5041 default:
5042 break;
5043 }
5044 }
5045
[email protected]cf9a7bc2010-06-11 18:54:505046 // Histograms to determine if the number of connections has an
5047 // impact on PLT.
5048 // TODO(jar): Consider removing the per-link-type versions. We
5049 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
[email protected]97546492010-08-09 05:14:495050 static bool use_connection_impact_histogram(
[email protected]cf9a7bc2010-06-11 18:54:505051 FieldTrialList::Find("ConnCountImpact") &&
5052 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
[email protected]97546492010-08-09 05:14:495053 if (use_connection_impact_histogram) {
[email protected]cf9a7bc2010-06-11 18:54:505054 UMA_HISTOGRAM_ENUMERATION(
5055 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
5056 abandoned_page ? 1 : 0, 2);
5057 switch (load_type) {
5058 case NavigationState::NORMAL_LOAD:
5059 PLT_HISTOGRAM(FieldTrial::MakeName(
5060 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525061 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505062 break;
5063 case NavigationState::LINK_LOAD_NORMAL:
5064 PLT_HISTOGRAM(FieldTrial::MakeName(
5065 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525066 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505067 break;
5068 case NavigationState::LINK_LOAD_RELOAD:
5069 PLT_HISTOGRAM(FieldTrial::MakeName(
5070 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
[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_CACHE_STALE_OK:
5074 PLT_HISTOGRAM(FieldTrial::MakeName(
5075 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525076 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505077 break;
5078 default:
5079 break;
5080 }
5081 }
5082
[email protected]78a258a2010-08-02 16:34:265083 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:005084 static bool use_idle_socket_timeout_histogram(
5085 FieldTrialList::Find("IdleSktToImpact") &&
5086 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
5087 if (use_idle_socket_timeout_histogram) {
5088 UMA_HISTOGRAM_ENUMERATION(
5089 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
5090 abandoned_page ? 1 : 0, 2);
5091 switch (load_type) {
5092 case NavigationState::NORMAL_LOAD:
5093 PLT_HISTOGRAM(FieldTrial::MakeName(
5094 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525095 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005096 break;
5097 case NavigationState::LINK_LOAD_NORMAL:
5098 PLT_HISTOGRAM(FieldTrial::MakeName(
5099 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525100 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005101 break;
5102 case NavigationState::LINK_LOAD_RELOAD:
5103 PLT_HISTOGRAM(FieldTrial::MakeName(
5104 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525105 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005106 break;
5107 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5108 PLT_HISTOGRAM(FieldTrial::MakeName(
5109 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525110 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005111 break;
5112 default:
5113 break;
5114 }
5115 }
5116
[email protected]78a258a2010-08-02 16:34:265117 // Histograms to determine effect of number of connections per proxy.
5118 static bool use_proxy_connection_impact_histogram(
5119 FieldTrialList::Find("ProxyConnectionImpact") &&
5120 !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty());
5121 if (use_proxy_connection_impact_histogram) {
5122 UMA_HISTOGRAM_ENUMERATION(
5123 FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
5124 abandoned_page ? 1 : 0, 2);
5125 switch (load_type) {
5126 case NavigationState::NORMAL_LOAD:
5127 PLT_HISTOGRAM(FieldTrial::MakeName(
5128 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525129 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265130 break;
5131 case NavigationState::LINK_LOAD_NORMAL:
5132 PLT_HISTOGRAM(FieldTrial::MakeName(
5133 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525134 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265135 break;
5136 case NavigationState::LINK_LOAD_RELOAD:
5137 PLT_HISTOGRAM(FieldTrial::MakeName(
5138 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525139 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265140 break;
5141 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5142 PLT_HISTOGRAM(FieldTrial::MakeName(
5143 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525144 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265145 break;
5146 default:
5147 break;
5148 }
5149 }
5150
[email protected]cf9a7bc2010-06-11 18:54:505151 // Histograms to determine if SDCH has an impact.
5152 // TODO(jar): Consider removing per-link load types and the enumeration.
5153 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
5154 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
5155 if (use_sdch_histogram) {
5156 UMA_HISTOGRAM_ENUMERATION(
5157 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
5158 load_type, NavigationState::kLoadTypeMax);
5159 switch (load_type) {
5160 case NavigationState::NORMAL_LOAD:
5161 PLT_HISTOGRAM(FieldTrial::MakeName(
5162 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525163 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505164 break;
5165 case NavigationState::LINK_LOAD_NORMAL:
5166 PLT_HISTOGRAM(FieldTrial::MakeName(
5167 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525168 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505169 break;
5170 case NavigationState::LINK_LOAD_RELOAD:
5171 PLT_HISTOGRAM(FieldTrial::MakeName(
5172 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525173 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505174 break;
5175 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5176 PLT_HISTOGRAM(FieldTrial::MakeName(
5177 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525178 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505179 break;
5180 case NavigationState::LINK_LOAD_CACHE_ONLY:
5181 PLT_HISTOGRAM(FieldTrial::MakeName(
5182 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525183 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505184 break;
5185 default:
5186 break;
5187 }
5188 }
5189
5190 // Histograms to determine if cache size has an impact on PLT.
5191 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
5192 !FieldTrialList::Find("CacheSize")->group_name().empty());
5193 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
5194 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
5195 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
5196 // StartToFinish or BeginToFinish would be better.
5197 PLT_HISTOGRAM(FieldTrial::MakeName(
5198 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
5199 }
5200
[email protected]8cfe6bb2010-08-27 02:35:005201 // For the SPDY field trials, we need to verify that the page loaded was
5202 // the type we requested:
5203 // if we asked for a SPDY request, we got a SPDY request
5204 // if we asked for a HTTP request, we got a HTTP request
5205 // Due to spdy version mismatches, it is possible that we ask for SPDY
5206 // but didn't get SPDY.
[email protected]cf9a7bc2010-06-11 18:54:505207 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
5208 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]8cfe6bb2010-08-27 02:35:005209 if (use_spdy_histogram) {
5210 // We take extra effort to only compute these once.
5211 static bool in_spdy_trial =
5212 FieldTrialList::Find("SpdyImpact")->group_name() == "npn_with_spdy";
5213 static bool in_http_trial =
5214 FieldTrialList::Find("SpdyImpact")->group_name() == "npn_with_http";
[email protected]cf9a7bc2010-06-11 18:54:505215
[email protected]8cfe6bb2010-08-27 02:35:005216 bool spdy_trial_success = navigation_state->was_fetched_via_spdy() ?
5217 in_spdy_trial : in_http_trial;
5218 if (spdy_trial_success) {
5219 // Histograms to determine if SPDY has an impact for https traffic.
5220 // TODO(mbelshe): After we've seen the difference between BeginToFinish
5221 // and StartToFinish, consider removing one or the other.
5222 if (scheme_type == URLPattern::SCHEME_HTTPS &&
5223 navigation_state->was_npn_negotiated()) {
5224 UMA_HISTOGRAM_ENUMERATION(
5225 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
5226 abandoned_page ? 1 : 0, 2);
5227 switch (load_type) {
5228 case NavigationState::LINK_LOAD_NORMAL:
5229 PLT_HISTOGRAM(FieldTrial::MakeName(
5230 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5231 begin_to_finish_all_loads);
5232 PLT_HISTOGRAM(FieldTrial::MakeName(
5233 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5234 start_to_finish_all_loads);
5235 PLT_HISTOGRAM(FieldTrial::MakeName(
5236 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5237 start_to_commit);
5238 break;
5239 case NavigationState::NORMAL_LOAD:
5240 PLT_HISTOGRAM(FieldTrial::MakeName(
5241 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5242 begin_to_finish_all_loads);
5243 PLT_HISTOGRAM(FieldTrial::MakeName(
5244 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5245 start_to_finish_all_loads);
5246 PLT_HISTOGRAM(FieldTrial::MakeName(
5247 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
5248 start_to_commit);
5249 break;
5250 default:
5251 break;
5252 }
[email protected]193b0b892010-06-26 03:57:575253 }
[email protected]8cfe6bb2010-08-27 02:35:005254
5255 // Histograms to compare the impact of alternate protocol over http
5256 // traffic: when spdy is used vs. when http is used.
5257 if (scheme_type == URLPattern::SCHEME_HTTP &&
5258 navigation_state->was_alternate_protocol_available()) {
5259 if (!navigation_state->was_npn_negotiated()) {
5260 // This means that even there is alternate protocols for npn_http or
5261 // npn_spdy, they are not taken (due to the fieldtrial).
5262 switch (load_type) {
5263 case NavigationState::LINK_LOAD_NORMAL:
5264 PLT_HISTOGRAM(
5265 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
5266 start_to_finish_all_loads);
5267 PLT_HISTOGRAM(
5268 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
5269 start_to_commit);
5270 break;
5271 case NavigationState::NORMAL_LOAD:
5272 PLT_HISTOGRAM(
5273 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
5274 start_to_finish_all_loads);
5275 PLT_HISTOGRAM(
5276 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
5277 start_to_commit);
5278 break;
5279 default:
5280 break;
5281 }
5282 } else if (navigation_state->was_fetched_via_spdy()) {
5283 switch (load_type) {
5284 case NavigationState::LINK_LOAD_NORMAL:
5285 PLT_HISTOGRAM(
5286 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
5287 start_to_finish_all_loads);
5288 PLT_HISTOGRAM(
5289 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
5290 start_to_commit);
5291 break;
5292 case NavigationState::NORMAL_LOAD:
5293 PLT_HISTOGRAM(
5294 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
5295 start_to_finish_all_loads);
5296 PLT_HISTOGRAM(
5297 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
5298 start_to_commit);
5299 break;
5300 default:
5301 break;
5302 }
5303 }
[email protected]193b0b892010-06-26 03:57:575304 }
5305 }
5306 }
5307
[email protected]cf9a7bc2010-06-11 18:54:505308 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:505309 if (navigation_state->was_fetched_via_proxy()) {
[email protected]05c8e502010-08-15 15:13:525310 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5311 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505312 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
[email protected]05c8e502010-08-15 15:13:525313 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505314 } else {
[email protected]05c8e502010-08-15 15:13:525315 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5316 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505317 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
[email protected]05c8e502010-08-15 15:13:525318 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505319 }
5320 } else {
[email protected]05c8e502010-08-15 15:13:525321 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5322 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https",
5323 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505324 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
[email protected]05c8e502010-08-15 15:13:525325 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505326 } else {
[email protected]05c8e502010-08-15 15:13:525327 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5328 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http",
5329 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505330 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
[email protected]05c8e502010-08-15 15:13:525331 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505332 }
5333 }
[email protected]a7ccc4d2010-01-27 08:14:485334
[email protected]ab9eabac2010-03-16 16:54:105335 // Site isolation metrics.
5336 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
5337 cross_origin_access_count_);
5338 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
5339 same_origin_access_count_);
5340
[email protected]05c8e502010-08-15 15:13:525341 // TODO(jar): This is the ONLY call in this method that needed more than
5342 // navigation_state. This should be relocated, or changed, so that this
5343 // body can be made a method on NavigationStates, and run via its destructor.
[email protected]cf9a7bc2010-06-11 18:54:505344 // Log some PLT data to the error log.
5345 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:295346
5347 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:415348
5349 // Since there are currently no guarantees that renderer histograms will be
5350 // sent to the browser, we initiate a PostTask here to be sure that we send
5351 // the histograms we generated. Without this call, pages that don't have an
5352 // on-close-handler might generate data that is lost when the renderer is
5353 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:485354 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
5355 // should post when the onload is complete, so that it doesn't interfere with
5356 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:415357 if (RenderThread::current()) {
5358 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:135359 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:415360 }
[email protected]c20210e62009-04-03 21:39:265361}
[email protected]e846d0d2009-05-20 00:53:065362
[email protected]f8999642009-10-27 21:39:425363void RenderView::LogNavigationState(const NavigationState* state,
5364 const WebDataSource* ds) const {
5365 // Because this function gets called on every page load,
5366 // take extra care to optimize it away if logging is turned off.
5367 if (logging::LOG_INFO < logging::GetMinLogLevel())
5368 return;
5369
5370 DCHECK(state);
5371 DCHECK(ds);
5372 GURL url(ds->request().url());
5373 Time start = state->start_load_time();
5374 Time finish = state->finish_load_time();
5375 // TODO(mbelshe): should we log more stats?
5376 LOG(INFO) << "PLT: "
5377 << (finish - start).InMilliseconds()
5378 << "ms "
5379 << url.spec();
5380}
5381
[email protected]cc0445f2009-10-13 16:09:085382void RenderView::focusAccessibilityObject(
5383 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:065384#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:155385 // TODO(dglazkov): Current logic implies that focus change can only be made
5386 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5387 // where accessibility is initialized. We should determine whether that's
5388 // right.
5389 if (!accessibility_.get())
5390 return;
[email protected]e846d0d2009-05-20 00:53:065391
5392 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:155393 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:065394
5395 // If id is valid, alert the browser side that an accessibility focus change
5396 // occurred.
5397 if (acc_obj_id >= 0)
5398 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
5399
5400#else // defined(OS_WIN)
5401 // TODO(port): accessibility not yet implemented
5402 NOTIMPLEMENTED();
5403#endif
5404}
[email protected]daa8c58e2009-06-15 17:21:105405
[email protected]a3018be2010-03-09 04:28:485406void RenderView::didChangeAccessibilityObjectState(
[email protected]416ac2e2010-09-01 17:15:165407 const WebAccessibilityObject& acc_obj) {
[email protected]a3018be2010-03-09 04:28:485408 if (!accessibility_.get())
5409 return;
5410
[email protected]416ac2e2010-09-01 17:15:165411 Send(new ViewHostMsg_AccessibilityObjectStateChange(
5412 routing_id_, WebAccessibility(acc_obj, accessibility_.get())));
[email protected]a3018be2010-03-09 04:28:485413}
5414
[email protected]520cb7d72010-08-31 11:54:315415void RenderView::didChangeAccessibilityObjectChildren(
[email protected]416ac2e2010-09-01 17:15:165416 const WebAccessibilityObject& acc_obj) {
[email protected]520cb7d72010-08-31 11:54:315417 if (!accessibility_.get())
5418 return;
5419
5420 if (accessibility_changes_.empty()) {
5421 Send(new ViewHostMsg_AccessibilityObjectChildrenChange(
[email protected]416ac2e2010-09-01 17:15:165422 routing_id_, std::vector<WebAccessibility>()));
[email protected]520cb7d72010-08-31 11:54:315423 }
5424
5425 accessibility_changes_.push_back(
[email protected]416ac2e2010-09-01 17:15:165426 WebAccessibility(acc_obj, accessibility_.get()));
[email protected]520cb7d72010-08-31 11:54:315427}
5428
[email protected]0fda7272009-06-26 15:49:335429void RenderView::Print(WebFrame* frame, bool script_initiated) {
5430 DCHECK(frame);
5431 if (print_helper_.get() == NULL) {
5432 print_helper_.reset(new PrintWebViewHelper(this));
5433 }
5434 print_helper_->Print(frame, script_initiated);
5435}
[email protected]446705872009-09-10 07:22:485436
5437void RenderView::OnSetEditCommandsForNextKeyEvent(
5438 const EditCommands& edit_commands) {
5439 edit_commands_ = edit_commands;
5440}
5441
[email protected]61f5a7b2009-12-22 22:21:205442void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275443 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355444 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205445 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5446 false));
[email protected]912256b32009-09-18 09:47:355447 return;
5448 }
5449
[email protected]fa7b6b542009-11-03 05:02:305450 WebDataSource* ds = main_frame->dataSource();
5451 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5452 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205453 pending_code_execution_queue_.push(
5454 linked_ptr<ViewMsg_ExecuteCode_Params>(
5455 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305456 return;
5457 }
5458
[email protected]61f5a7b2009-12-22 22:21:205459 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305460}
5461
5462void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205463 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485464 // Don't execute scripts in gallery pages.
5465 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085466 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5467 && !CommandLine::ForCurrentProcess()->HasSwitch(
5468 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485469 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5470 return;
5471 }
5472
[email protected]20ad2692009-11-20 18:27:205473 std::vector<WebFrame*> frame_vector;
5474 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205475 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205476 GetAllChildFrames(frame, &frame_vector);
5477
5478 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5479 frame_it != frame_vector.end(); ++frame_it) {
5480 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205481 if (params.is_javascript) {
5482 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5483 continue;
5484
[email protected]20ad2692009-11-20 18:27:205485 std::vector<WebScriptSource> sources;
5486 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205487 WebScriptSource(WebString::fromUTF8(params.code)));
5488 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205489 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205490 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205491 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5492 } else {
[email protected]61f5a7b2009-12-22 22:21:205493 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205494 }
[email protected]912256b32009-09-18 09:47:355495 }
5496
[email protected]61f5a7b2009-12-22 22:21:205497 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355498}
5499
[email protected]60c42a8c72009-10-09 04:08:595500void RenderView::Close() {
5501 // We need to grab a pointer to the doomed WebView before we destroy it.
5502 WebView* doomed = webview();
5503 RenderWidget::Close();
5504 Singleton<ViewMap>::get()->erase(doomed);
5505}
5506
[email protected]446705872009-09-10 07:22:485507void RenderView::DidHandleKeyEvent() {
5508 edit_commands_.clear();
5509}
5510
[email protected]6a8ddba52010-09-05 04:38:065511void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
5512 page_click_tracker_->DidHandleMouseEvent(event);
5513}
5514
[email protected]941e4552010-02-01 21:23:435515#if defined(OS_MACOSX)
5516void RenderView::OnWasHidden() {
5517 RenderWidget::OnWasHidden();
5518
5519 // Inform plugins that their container is no longer visible.
5520 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5521 for (plugin_it = plugin_delegates_.begin();
5522 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5523 (*plugin_it)->SetContainerVisibility(false);
5524 }
5525}
5526
5527void RenderView::OnWasRestored(bool needs_repainting) {
5528 RenderWidget::OnWasRestored(needs_repainting);
5529
5530 // Inform plugins that their container is now visible.
5531 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5532 for (plugin_it = plugin_delegates_.begin();
5533 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5534 (*plugin_it)->SetContainerVisibility(true);
5535 }
5536}
[email protected]1e6e3c992010-02-08 15:52:135537
5538void RenderView::OnSetFocus(bool enable) {
5539 RenderWidget::OnSetFocus(enable);
5540
[email protected]7d3c02c2010-05-05 23:10:315541 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135542 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5543 for (plugin_it = plugin_delegates_.begin();
5544 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315545 // RenderWidget's call to setFocus can cause the underlying webview's
5546 // activation state to change just like a call to setIsActive.
5547 if (enable)
5548 (*plugin_it)->SetWindowFocus(true);
5549 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135550 }
5551 }
5552}
[email protected]941e4552010-02-01 21:23:435553#endif // OS_MACOSX
5554
[email protected]83dde542009-09-11 20:59:555555void RenderView::EnsureDocumentTag() {
5556 // TODO(darin): There's actually no reason for this to be here. We should
5557 // have the browser side manage the document tag.
5558#if defined(OS_MACOSX)
5559 if (!has_document_tag_) {
5560 // Make the call to get the tag.
5561 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5562 has_document_tag_ = true;
5563 }
5564#endif
5565}
[email protected]12636df2009-09-28 22:32:215566
[email protected]43f28f832010-02-03 02:28:485567#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035568gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235569 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485570 gfx::PluginWindowHandle window = NULL;
5571 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235572 routing_id(), opaque, root, &window));
[email protected]43f28f832010-02-03 02:28:485573 return window;
5574}
5575
5576void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5577 if (window)
5578 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5579}
5580
[email protected]44ce0b12010-03-12 16:45:335581void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5582 int32 width,
5583 int32 height,
5584 uint64 io_surface_identifier) {
5585 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485586 routing_id(), window, width, height, io_surface_identifier));
5587}
5588
[email protected]44ce0b12010-03-12 16:45:335589void RenderView::AcceleratedSurfaceSetTransportDIB(
5590 gfx::PluginWindowHandle window,
5591 int32 width,
5592 int32 height,
5593 TransportDIB::Handle transport_dib) {
5594 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075595 routing_id(), window, width, height, transport_dib));
5596}
5597
[email protected]44ce0b12010-03-12 16:45:335598TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5599 size_t size) {
[email protected]1aef98132010-02-23 18:00:075600 TransportDIB::Handle dib_handle;
5601 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385602 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075603 return dib_handle;
5604 // Return an invalid handle if Send() fails.
5605 return TransportDIB::DefaultHandleValue();
5606}
5607
[email protected]44ce0b12010-03-12 16:45:335608void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075609 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5610}
5611
[email protected]44ce0b12010-03-12 16:45:335612void RenderView::AcceleratedSurfaceBuffersSwapped(
5613 gfx::PluginWindowHandle window) {
5614 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485615}
5616#endif
[email protected]58c321d2010-02-19 12:11:285617
[email protected]cdaf8d02010-03-30 19:52:475618bool RenderView::ScheduleFileChooser(
5619 const ViewHostMsg_RunFileChooser_Params& params,
5620 WebFileChooserCompletion* completion) {
5621 static const size_t kMaximumPendingFileChooseRequests = 4;
5622 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5623 // This sanity check prevents too many file choose requests from getting
5624 // queued which could DoS the user. Getting these is most likely a
5625 // programming error (there are many ways to DoS the user so it's not
5626 // considered a "real" security check), either in JS requesting many file
5627 // choosers to pop up, or in a plugin.
5628 //
5629 // TODO(brettw) we might possibly want to require a user gesture to open
5630 // a file picker, which will address this issue in a better way.
5631 return false;
5632 }
5633
5634 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5635 new PendingFileChooser(params, completion)));
5636 if (file_chooser_completions_.size() == 1) {
5637 // Actually show the browse dialog when this is the first request.
5638 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5639 }
5640 return true;
5641}
5642
[email protected]290838a2010-04-27 17:37:015643void RenderView::OnPageTranslated() {
5644 WebFrame* frame = webview()->mainFrame();
5645 if (!frame)
5646 return;
5647
5648 // The page is translated, so try to extract the form data again.
[email protected]6a8ddba52010-09-05 04:38:065649 autofill_helper_->FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015650}
5651
[email protected]8a5f7002010-03-31 13:47:355652WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285653 if (!geolocation_dispatcher_.get())
5654 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5655 return geolocation_dispatcher_.get();
5656}
[email protected]61c9f032010-03-31 23:04:195657
[email protected]638694c2010-08-04 22:24:115658WebKit::WebSpeechInputController* RenderView::speechInputController(
5659 WebKit::WebSpeechInputListener* listener) {
5660 if (!speech_input_dispatcher_.get())
5661 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5662 return speech_input_dispatcher_.get();
5663}
5664
[email protected]57ead352010-08-11 14:42:535665WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
5666 if (!device_orientation_dispatcher_.get())
5667 device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this));
5668 return device_orientation_dispatcher_.get();
5669}
5670
[email protected]8079b362010-05-07 18:37:455671bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195672 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455673 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195674 if (frame->parent() != NULL)
5675 return false;
5676
[email protected]f0a3d0b2010-08-06 22:51:535677 // Navigations initiated within Webkit are not sent out to the external host
5678 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275679 // 1. The url scheme is not http/https
5680 // 2. There is no opener and this is not the first url being opened by this
5681 // RenderView.
5682 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535683 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535684 // 4. Reloads/form submits/back forward navigations
5685 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5686 return false;
5687
[email protected]d0ed50d2010-06-22 01:01:325688 // Not interested in reloads.
5689 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015690 type != WebKit::WebNavigationTypeFormSubmitted &&
5691 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325692 // The opener relationship between the new window and the parent allows the
5693 // new window to script the parent and vice versa. This is not allowed if
5694 // the origins of the two domains are different. This can be treated as a
5695 // top level navigation and routed back to the host.
5696 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275697 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475698 // Force link click navigations to always be routed to the host as they
5699 // may update session state on the server.
5700 if (type == WebKit::WebNavigationTypeLinkClicked)
5701 return true;
[email protected]900eb2f12010-08-23 22:36:275702 // If this is the first page being loaded by this RenderView instance then
5703 // it should stay here.
5704 if (page_id_ == -1) {
5705 return false;
5706 } else {
[email protected]d0ed50d2010-06-22 01:01:325707 return true;
[email protected]900eb2f12010-08-23 22:36:275708 }
[email protected]d0ed50d2010-06-22 01:01:325709 }
[email protected]900eb2f12010-08-23 22:36:275710
5711 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5712 return true;
[email protected]d0ed50d2010-06-22 01:01:325713 }
[email protected]61c9f032010-03-31 23:04:195714 return false;
5715}
[email protected]2b06a992010-08-21 05:48:225716
5717void RenderView::OnOpenFileSystemRequestComplete(
5718 int request_id, bool accepted, const string16& name,
5719 const string16& root_path) {
5720 PendingOpenFileSystem* request = pending_file_system_requests_.Lookup(
5721 request_id);
5722 DCHECK(request);
5723 if (accepted)
5724 request->callbacks->didOpenFileSystem(name, root_path);
5725 else
5726 request->callbacks->didFail(WebKit::WebFileErrorSecurity);
5727 request->callbacks = NULL;
5728 pending_file_system_requests_.Remove(request_id);
5729}
[email protected]27a9ef32010-09-10 04:06:245730
5731void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5732 IPC::PlatformFileForTransit file_for_transit,
5733 int message_id) {
5734 pepper_delegate_.OnAsyncFileOpened(
5735 error_code,
5736 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5737 message_id);
5738}