blob: 98fa3781a59ca077ca4e350e32b57473c257b396 [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]2f979172010-09-16 21:54:0348#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4049#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5350#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1151#include "chrome/renderer/devtools_agent.h"
52#include "chrome/renderer/devtools_client.h"
[email protected]2f979172010-09-16 21:54:0353#include "chrome/renderer/dom_ui_bindings.h"
[email protected]912256b32009-09-18 09:47:3554#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0455#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]5351dbc2010-08-27 15:22:1156#include "chrome/renderer/extensions/extension_renderer_info.h"
[email protected]f816c012009-06-26 21:48:3257#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3558#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3759#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0360#include "chrome/renderer/external_host_bindings.h"
[email protected]58c321d2010-02-19 12:11:2861#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2962#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5663#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4164#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]8400e032010-02-26 18:50:1165#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5666#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1267#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0668#include "chrome/renderer/page_click_tracker.h"
69#include "chrome/renderer/password_autocomplete_manager.h"
[email protected]8beff0762009-09-29 02:18:3070#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5071#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2572#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2873#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2674#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1875#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3976#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2177#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3478#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]638694c2010-08-04 22:24:1179#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4680#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3581#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2982#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2983#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2984#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4285#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5686#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1587#include "gfx/color_utils.h"
88#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5789#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2690#include "gfx/point.h"
91#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2792#include "grit/generated_resources.h"
93#include "grit/renderer_resources.h"
[email protected]ee68378a2010-08-10 01:05:4194#include "media/base/media_switches.h"
[email protected]f11ca0732009-04-11 00:09:3495#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2996#include "net/base/escape.h"
97#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0098#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1099#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:30100#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:06101#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:49102#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:26103#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:07104#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:49105#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
106#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:32107#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49108#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:35109#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]7a4de7a62010-08-17 18:38:24110#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]2b06a992010-08-21 05:48:22111#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
112#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
[email protected]b1438212010-04-03 00:30:59113#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49114#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
115#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
116#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41117#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50118#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49119#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32120#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07121#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49122#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40123#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17124#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49125#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49126#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
127#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
128#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
129#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
130#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
131#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40132#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49133#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34134#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49135#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
136#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
137#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
138#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
139#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
140#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26141#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11142#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04143#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]7a4de7a62010-08-17 18:38:24144#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29145#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59146#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24147#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24148#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34149#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26150#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17151#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51152#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09153#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26154#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38155#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17156#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29157#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30158#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23159#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30160#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40161#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09162#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24163#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29164#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29165#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17166#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29167
[email protected]6c8afae52009-01-22 02:24:57168#if defined(OS_WIN)
169// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57170// * theming
[email protected]cd818412010-03-19 03:23:15171#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03172#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46173#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33174#elif defined(OS_MACOSX)
175#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57176#endif
177
[email protected]80f584d92010-01-21 03:59:04178using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26179using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33180using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45181using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59182using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24183using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17184using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56185using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10186using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09187using webkit_glue::SiteIsolationMetrics;
[email protected]416ac2e2010-09-01 17:15:16188using webkit_glue::WebAccessibility;
[email protected]c7287a92009-11-04 20:06:15189using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42190using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08191using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21192using WebKit::WebApplicationCacheHost;
193using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41194using WebKit::WebColor;
195using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59196using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44197using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51198using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07199using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55200using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28201using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29202using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00203using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58204using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25205using WebKit::WebDragOperation;
206using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51207using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47208using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22209using WebKit::WebFileSystem;
210using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49211using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59212using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48213using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45214using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17215using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41216using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50217using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17218using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28219using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17220using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28221using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28222using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51223using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07224using WebKit::WebPageSerializer;
225using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17226using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40227using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49228using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09229using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52230using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59231using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51232using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52233using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40234using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35235using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29236using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59237using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42238using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02239using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34240using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28241using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51242using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52243using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28244using WebKit::WebURL;
245using WebKit::WebURLError;
246using WebKit::WebURLRequest;
247using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28248using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03249using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28250using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43251using WebKit::WebWorker;
252using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11253using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33254
initial.commit09911bf2008-07-26 23:55:29255//-----------------------------------------------------------------------------
256
[email protected]3354d3e2010-06-10 19:53:02257typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
258
initial.commit09911bf2008-07-26 23:55:29259// define to write the time necessary for thumbnail/DOM text retrieval,
260// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29261// #define TIME_TEXT_RETRIEVAL
262
263// maximum number of characters in the document to index, any text beyond this
264// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57265static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29266
267// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37268static const int kThumbnailWidth = 212;
269static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29270
271// Delay in milliseconds that we'll wait before capturing the page contents
272// and thumbnail.
273static const int kDelayForCaptureMs = 500;
274
275// Typically, we capture the page data once the page is loaded.
276// Sometimes, the page never finishes to load, preventing the page capture
277// To workaround this problem, we always perform a capture after the following
278// delay.
279static const int kDelayForForcedCaptureMs = 6000;
280
[email protected]882daa92009-11-05 16:31:31281// Time, in seconds, we delay before sending content state changes (such as form
282// state and scroll position) to the browser. We delay sending changes to avoid
283// spamming the browser.
284// To avoid having tab/session restore require sending a message to get the
285// current content state during tab closing we use a shorter timeout for the
286// foreground renderer. This means there is a small window of time from which
287// content state is modified and not sent to session restore, but this is
288// better than having to wake up all renderers during shutdown.
289static const int kDelaySecondsForContentStateSyncHidden = 5;
290static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29291
[email protected]0aa55312008-10-17 21:53:08292// The maximum number of popups that can be spawned from one page.
293static const int kMaximumNumberOfUnacknowledgedPopups = 25;
294
initial.commit09911bf2008-07-26 23:55:29295static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16296 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29297
[email protected]50b691c2008-10-31 19:08:35298static const char* const kBackForwardNavigationScheme = "history";
299
[email protected]726985e22009-06-18 21:09:28300static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
301 WebVector<WebURL> urls;
302 ds->redirectChain(urls);
303 result->reserve(urls.size());
304 for (size_t i = 0; i < urls.size(); ++i)
305 result->push_back(urls[i]);
306}
307
[email protected]61f5a7b2009-12-22 22:21:20308static bool UrlMatchesPermissions(
309 const GURL& url, const std::vector<URLPattern>& host_permissions) {
310 for (size_t i = 0; i < host_permissions.size(); ++i) {
311 if (host_permissions[i].MatchesUrl(url))
312 return true;
313 }
314
315 return false;
316}
317
[email protected]30507922010-01-15 16:48:23318static bool PaintViewIntoCanvas(WebView* view,
319 skia::PlatformCanvas& canvas) {
320 view->layout();
321 const WebSize& size = view->size();
322
323 if (!canvas.initialize(size.width, size.height, true))
324 return false;
325
326 view->paint(webkit_glue::ToWebCanvas(&canvas),
327 WebRect(0, 0, size.width, size.height));
328 // TODO: Add a way to snapshot the whole page, not just the currently
329 // visible part.
330
331 return true;
332}
333
334// Calculates how "boring" a thumbnail is. The boring score is the
335// 0,1 ranged percentage of pixels that are the most common
336// luma. Higher boring scores indicate that a higher percentage of a
337// bitmap are all the same brightness.
338static double CalculateBoringScore(SkBitmap* bitmap) {
339 int histogram[256] = {0};
340 color_utils::BuildLumaHistogram(bitmap, histogram);
341
342 int color_count = *std::max_element(histogram, histogram + 256);
343 int pixel_count = bitmap->width() * bitmap->height();
344 return static_cast<double>(color_count) / pixel_count;
345}
346
[email protected]12bc8472010-04-15 07:29:40347// True if |frame| contains content that is white-listed for content settings.
348static bool IsWhitelistedForContentSettings(WebFrame* frame) {
349 WebSecurityOrigin origin = frame->securityOrigin();
350 if (origin.isEmpty())
351 return false; // Uninitialized document?
352
353 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
354 return true; // Browser UI elements should still work.
355
356 // If the scheme is ftp: or file:, an empty file name indicates a directory
357 // listing, which requires JavaScript to function properly.
358 GURL frame_url = frame->url();
359 const char* kDirProtocols[] = { "ftp", "file" };
360 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
361 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
362 return frame_url.SchemeIs(kDirProtocols[i]) &&
363 frame_url.ExtractFileName().empty();
364 }
365 }
366
367 return false;
368}
369
[email protected]3a8eecb2010-04-22 23:56:30370// Returns true if the frame is navigating to an URL either into or out of an
371// extension app's extent.
372static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
373 if (!RenderThread::current())
374 return false;
375
376 // If the URL is still empty, this is a window.open navigation. Check the
377 // opener's URL.
378 GURL old_url(frame->url());
379 if (old_url.is_empty() && frame->opener())
380 old_url = frame->opener()->url();
381
[email protected]5351dbc2010-08-27 15:22:11382 return !ExtensionRendererInfo::InSameExtent(old_url, new_url);
[email protected]3a8eecb2010-04-22 23:56:30383}
384
[email protected]3354d3e2010-06-10 19:53:02385// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
386// if it failed.
[email protected]e5106202010-06-11 21:12:36387static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17388 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02389 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08390 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02391 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02392 Language cld_language =
[email protected]e5106202010-06-11 21:12:36393 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08394 &num_languages, NULL, &text_bytes);
395 // We don't trust the result if the CLD reports that the detection is not
396 // reliable, or if the actual text used to detect the language was less than
397 // 100 bytes (short texts can often lead to wrong results).
398 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02399 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
400 // We should not use LanguageCode_ISO_639_1 because it does not cover all
401 // the languages CLD can detect. As a result, it'll return the invalid
402 // language code for tradtional Chinese among others.
403 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
404 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
405 // for Simplified Chinese.
406 language = LanguageCodeWithDialects(cld_language);
407 }
408 return language;
409}
410
[email protected]2b06a992010-08-21 05:48:22411// Holds pending openFileSystem callbacks.
412struct RenderView::PendingOpenFileSystem {
413 explicit PendingOpenFileSystem(WebFileSystemCallbacks* c) : callbacks(c) {
414 }
415 ~PendingOpenFileSystem() {
416 if (callbacks)
417 callbacks->didFail(WebKit::WebFileErrorAbort);
418 }
419 WebFileSystemCallbacks* callbacks;
420};
421
initial.commit09911bf2008-07-26 23:55:29422///////////////////////////////////////////////////////////////////////////////
423
[email protected]60c42a8c72009-10-09 04:08:59424int32 RenderView::next_page_id_ = 1;
425
[email protected]cdaf8d02010-03-30 19:52:47426struct RenderView::PendingFileChooser {
427 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
428 WebFileChooserCompletion* c)
429 : params(p),
430 completion(c) {
431 }
432 ViewHostMsg_RunFileChooser_Params params;
433 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
434};
435
[email protected]2fab253a2009-08-17 23:00:59436RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34437 const WebPreferences& webkit_preferences,
438 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12439 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02440 webkit_preferences_(webkit_preferences),
441 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09442 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02443 send_preferred_size_changes_(false),
444 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24445 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21446 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02447 opened_by_user_gesture_(true),
448 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24449 page_id_(-1),
450 last_page_id_sent_to_browser_(-1),
451 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00452 history_list_offset_(-1),
453 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24454 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55455#if defined(OS_MACOSX)
456 has_document_tag_(false),
457#endif
[email protected]98324892009-09-09 21:16:05458 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10459 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17460 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02461 target_url_status_(TARGET_NONE),
462 spelling_panel_visible_(false),
463 view_type_(ViewType::INVALID),
464 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18465 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30466 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
467 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02468 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
469 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
470 ALLOW_THIS_IN_INITIALIZER_LIST(
471 notification_provider_(new NotificationProvider(this))),
472 session_storage_namespace_id_(session_storage_namespace_id),
473 decrement_shared_popup_at_destruction_(false) {
[email protected]6a8ddba52010-09-05 04:38:06474 password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this));
475 autofill_helper_.reset(new AutoFillHelper(this));
476 page_click_tracker_.reset(new PageClickTracker(this));
477 // Note that the order of insertion of the listeners is important.
478 // The password_autocomplete_manager_ takes the first shot at processing the
479 // notification and can stop the propagation.
480 page_click_tracker_->AddListener(password_autocomplete_manager_.get());
481 page_click_tracker_->AddListener(autofill_helper_.get());
[email protected]71b0d5d2010-02-15 05:43:07482 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29483}
484
485RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08486 if (decrement_shared_popup_at_destruction_)
487 shared_popup_counter_->data--;
488
[email protected]b0950a72009-09-29 23:16:17489 // Dispose of un-disposed image fetchers.
490 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
491 i != image_fetchers_.end(); ++i) {
492 delete *i;
493 }
494
[email protected]a1128322009-10-06 18:38:46495 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47496 while (!file_chooser_completions_.empty()) {
497 if (file_chooser_completions_.front()->completion) {
498 file_chooser_completions_.front()->completion->didChooseFile(
499 WebVector<WebString>());
500 }
501 file_chooser_completions_.pop_front();
502 }
[email protected]a1128322009-10-06 18:38:46503
[email protected]83dde542009-09-11 20:59:55504#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05505 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55506 if (has_document_tag_)
507 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
508#endif
[email protected]98324892009-09-09 21:16:05509
[email protected]5fb88962009-04-16 19:03:25510 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59511
512#ifndef NDEBUG
513 // Make sure we are no longer referenced by the ViewMap.
514 ViewMap* views = Singleton<ViewMap>::get();
515 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
516 DCHECK_NE(this, it->second) << "Failed to call Close?";
517#endif
518}
519
520/*static*/
521void RenderView::ForEach(RenderViewVisitor* visitor) {
522 ViewMap* views = Singleton<ViewMap>::get();
523 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
524 if (!visitor->Visit(it->second))
525 return;
526 }
527}
528
529/*static*/
530RenderView* RenderView::FromWebView(WebView* webview) {
531 ViewMap* views = Singleton<ViewMap>::get();
532 ViewMap::iterator it = views->find(webview);
533 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29534}
535
536/*static*/
[email protected]0aa55312008-10-17 21:53:08537RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24538 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15539 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08540 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51541 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08542 const WebPreferences& webkit_prefs,
543 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34544 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26545 int64 session_storage_namespace_id,
546 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29547 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34548 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
549 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29550 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29551 opener_id,
[email protected]80d96fa2009-06-10 22:34:51552 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08553 counter,
[email protected]8ab04652010-06-12 02:47:26554 routing_id,
555 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29556 return view;
557}
558
559/*static*/
560void RenderView::SetNextPageID(int32 next_page_id) {
561 // This method should only be called during process startup, and the given
562 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05563 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29564 DCHECK(next_page_id >= next_page_id_);
565 next_page_id_ = next_page_id;
566}
567
[email protected]8a3125a712010-08-09 18:58:51568WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26569 return static_cast<WebKit::WebView*>(webwidget());
570}
571
[email protected]afe3a1672009-11-17 19:04:12572void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56573 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
574}
575
[email protected]a3a8fb6d2009-10-22 20:12:51576void RenderView::PluginCrashed(const FilePath& plugin_path) {
577 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29578}
579
[email protected]aad51d1c2010-08-05 08:38:09580WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
581 const WebPluginParams& params) {
582 WebPluginInfo info;
583 bool found;
[email protected]55126132010-08-19 14:53:28584 ContentSetting setting;
[email protected]aad51d1c2010-08-05 08:38:09585 std::string mime_type;
586 Send(new ViewHostMsg_GetPluginInfo(
587 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
[email protected]55126132010-08-19 14:53:28588 &info, &setting, &mime_type));
[email protected]aad51d1c2010-08-05 08:38:09589 if (!found || !info.enabled)
590 return NULL;
591 scoped_refptr<pepper::PluginModule> pepper_module =
592 PepperPluginRegistry::GetInstance()->GetModule(info.path);
593 if (pepper_module)
594 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
595 else
596 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
597}
598
[email protected]d8fd6fa2010-02-01 15:54:26599void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
600 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30601 // If the renderer is visible, set initial visibility and focus state.
602 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34603#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30604 delegate->SetContainerVisibility(true);
605 if (webview() && webview()->isActive())
606 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34607#endif
[email protected]49232292010-09-03 19:07:30608 }
[email protected]784ea1ab2010-09-18 00:02:34609 // Plugins start assuming the content has focus (so that they work in
610 // environments where RenderView isn't hosting them), so we always have to
611 // set the initial state. See webplugin_delegate_impl.h for details.
612 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26613}
614
615void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
616 plugin_delegates_.erase(delegate);
617}
[email protected]d8fd6fa2010-02-01 15:54:26618
[email protected]18bcc3c2009-01-27 21:39:15619void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29620 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51621 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08622 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26623 int32 routing_id,
624 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29625 DCHECK(!webview());
626
627 if (opener_id != MSG_ROUTING_NONE)
628 opener_id_ = opener_id;
629
[email protected]0aa55312008-10-17 21:53:08630 if (counter) {
631 shared_popup_counter_ = counter;
632 shared_popup_counter_->data++;
633 decrement_shared_popup_at_destruction_ = true;
634 } else {
635 shared_popup_counter_ = new SharedRenderViewCounter(0);
636 decrement_shared_popup_at_destruction_ = false;
637 }
638
[email protected]58bfc6b2009-06-24 09:45:02639 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04640
[email protected]9a6c6232010-06-25 11:46:49641 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59642 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59643 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27644 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23645 if (!frame_name.empty())
646 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29647
[email protected]d3ba77272009-09-03 00:06:09648 OnSetRendererPrefs(renderer_prefs);
649
initial.commit09911bf2008-07-26 23:55:29650 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24651 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29652 // Take a reference on behalf of the RenderThread. This will be balanced
653 // when we receive ViewMsg_Close.
654 AddRef();
655
656 // If this is a popup, we must wait for the CreatingNew_ACK message before
657 // completing initialization. Otherwise, we can finish it now.
658 if (opener_id == MSG_ROUTING_NONE) {
659 did_show_ = true;
660 CompleteInit(parent_hwnd);
661 }
662
663 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29664
[email protected]58bfc6b2009-06-24 09:45:02665 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09666 if (command_line.HasSwitch(switches::kDomAutomationController))
667 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29668
[email protected]5fb88962009-04-16 19:03:25669 audio_message_filter_ = new AudioMessageFilter(routing_id_);
670 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29671}
672
673void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27674 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27675 if (main_frame)
676 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26677
[email protected]b2abac72009-02-26 12:39:28678 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11679 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28680 return;
[email protected]b4b967e2009-04-22 11:33:05681 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
682 return;
[email protected]b6849bda2009-10-14 23:59:26683 if (notification_provider_->OnMessageReceived(message))
684 return;
[email protected]58c321d2010-02-19 12:11:28685 if (geolocation_dispatcher_.get() &&
686 geolocation_dispatcher_->OnMessageReceived(message)) {
687 return;
688 }
[email protected]638694c2010-08-04 22:24:11689 if (speech_input_dispatcher_.get() &&
690 speech_input_dispatcher_->OnMessageReceived(message)) {
691 return;
692 }
[email protected]57ead352010-08-11 14:42:53693 if (device_orientation_dispatcher_.get() &&
694 device_orientation_dispatcher_->OnMessageReceived(message)) {
695 return;
696 }
[email protected]b2abac72009-02-26 12:39:28697
initial.commit09911bf2008-07-26 23:55:29698 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04699 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
700 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29701 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01702 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29703 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
704 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56705 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29706 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
707 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
708 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
709 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27710#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35711 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27712#endif
initial.commit09911bf2008-07-26 23:55:29713 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
714 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05715 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
716 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
717 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04718 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29719 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
720 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
721 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15722 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29723 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49724 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
725 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17726 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54727 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
728 OnSetContentSettingsForLoadingURL)
729 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
730 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29731 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18732 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
733 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28734 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33735 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29736 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48737 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29738 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29739 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29740 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
741 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
742 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
743 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
744 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45745 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29746 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50747 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
748 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29749 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
750 OnDragSourceSystemDragEnded)
751 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29752 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
753 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
754 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
755 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:21756 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:29757 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
758 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29759 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
760 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04761 IPC_MESSAGE_HANDLER(
762 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
763 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29764 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04765 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29766 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
767 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45768 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04769 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08770 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
771 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24772 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
773 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48774 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
775 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40776 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
777 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00778 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27779 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37780 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
781 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16782 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14783 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25784 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
785 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10786 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
787 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51788 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53789 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
790 OnUpdateBrowserWindowId)
791 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
792 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56793 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34794 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14795#if defined(OS_MACOSX)
796 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13797 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14798#endif
[email protected]446705872009-09-10 07:22:48799 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33800 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35801 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
802 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33803 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
804 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42805 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02806 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09807 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36808 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
809 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
810 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42811 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
812 OnAccessibilityNotificationsAck)
[email protected]2b06a992010-08-21 05:48:22813 IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete,
814 OnOpenFileSystemRequestComplete)
[email protected]27a9ef32010-09-10 04:06:24815 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]634a6f92008-12-01 21:39:31816
initial.commit09911bf2008-07-26 23:55:29817 // Have the super handle all other messages.
818 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
819 IPC_END_MESSAGE_MAP()
820}
821
[email protected]9b18a84f2010-06-10 15:54:04822void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27823 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29824 if (!main_frame)
825 return;
826
827 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45828 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29829 if (url.is_empty())
830 return;
831
832 if (size_.IsEmpty())
833 return; // Don't create an empty thumbnail!
834
835 ThumbnailScore score;
836 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02837 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15838 &thumbnail, &score))
839 return;
840
initial.commit09911bf2008-07-26 23:55:29841 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46842 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29843}
844
[email protected]9b18a84f2010-06-10 15:54:04845void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23846 SkBitmap snapshot;
847 bool error = false;
848
849 WebFrame* main_frame = webview()->mainFrame();
850 if (!main_frame)
851 error = true;
852
853 if (!error && !CaptureSnapshot(webview(), &snapshot))
854 error = true;
855
856 DCHECK(error == snapshot.empty()) <<
857 "Snapshot should be empty on error, non-empty otherwise.";
858
859 // Send the snapshot to the browser process.
860 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
861}
862
[email protected]068637222009-01-29 16:58:07863void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29864 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58865 if (webview()) {
866 // If the user has selected text in the currently focused frame we print
867 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27868 if (webview()->focusedFrame()->hasSelection())
869 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58870 else
[email protected]26aa0482009-09-30 16:55:27871 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58872 }
initial.commit09911bf2008-07-26 23:55:29873}
874
[email protected]82270452009-06-19 15:58:01875void RenderView::OnPrintingDone(int document_cookie, bool success) {
876 // Ignoring document cookie here since only one print job can be outstanding
877 // per renderer and document_cookie is 0 when printing is successful.
878 DCHECK(print_helper_.get());
879 if (print_helper_.get() != NULL) {
880 print_helper_->DidFinishPrinting(success);
881 }
882}
883
initial.commit09911bf2008-07-26 23:55:29884void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
885 if (load_id != page_id_)
886 return; // this capture call is no longer relevant due to navigation
887 if (load_id == last_indexed_page_id_)
888 return; // we already indexed this page
889
890 if (!webview())
891 return;
892
[email protected]26aa0482009-09-30 16:55:27893 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29894 if (!main_frame)
895 return;
896
897 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45898 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29899 return;
900
901 // Don't index/capture pages that failed to load. This only checks the top
902 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45903 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28904 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29905 return;
906
907 if (!preliminary_capture)
908 last_indexed_page_id_ = load_id;
909
[email protected]a8a81292010-01-21 00:32:45910 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45911 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29912 if (url.is_empty())
913 return;
914
[email protected]a8a81292010-01-21 00:32:45915 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36916 string16 contents;
initial.commit09911bf2008-07-26 23:55:29917 CaptureText(main_frame, &contents);
918 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:10919 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:37920 // If the page explicitly specifies a language, use it, otherwise we'll
921 // determine it based on the text content using the CLD.
922 std::string language =
923 TranslateHelper::GetPageLanguageFromMetaTag(&document);
924 if (language.empty()) {
925 base::TimeTicks begin_time = base::TimeTicks::Now();
926 language = DetermineTextLanguage(contents);
927 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
928 base::TimeTicks::Now() - begin_time);
929 }
[email protected]a8a81292010-01-21 00:32:45930 // Send the text to the browser for indexing (the browser might decide not
931 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:37932 Send(new ViewHostMsg_PageContents(
933 routing_id_, url, load_id, contents, language,
934 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27935 }
936
[email protected]9b18a84f2010-06-10 15:54:04937 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]e5106202010-06-11 21:12:36940void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29941 contents->clear();
942 if (!frame)
943 return;
944
945#ifdef TIME_TEXT_RETRIEVAL
946 double begin = time_util::GetHighResolutionTimeNow();
947#endif
948
949 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36950 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29951
952#ifdef TIME_TEXT_RETRIEVAL
953 double end = time_util::GetHighResolutionTimeNow();
954 char buf[128];
955 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
956 contents.size(), (end - begin)*1000);
957 OutputDebugStringA(buf);
958#endif
959
960 // When the contents are clipped to the maximum, we don't want to have a
961 // partial word indexed at the end that might have been clipped. Therefore,
962 // terminate the string at the last space to ensure no words are clipped.
963 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36964 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29965 if (last_space_index == std::wstring::npos)
966 return; // don't index if we got a huge block of text with no spaces
967 contents->resize(last_space_index);
968 }
969}
970
[email protected]8649fb32009-06-26 17:51:02971bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29972 int w,
973 int h,
974 SkBitmap* thumbnail,
975 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23976 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15977
[email protected]8649fb32009-06-26 17:51:02978 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23979
980 // Paint |view| into |canvas|.
981 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02982 return false;
[email protected]8649fb32009-06-26 17:51:02983
984 skia::BitmapPlatformDevice& device =
985 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
986
987 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29988
[email protected]cab34d6a2009-09-24 01:14:52989 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29990 float dest_aspect = dest_rect.width() / dest_rect.height();
991
992 // Get the src rect so that we can preserve the aspect ratio while filling
993 // the destination.
994 SkIRect src_rect;
995 if (src_bmp.width() < dest_rect.width() ||
996 src_bmp.height() < dest_rect.height()) {
997 // Source image is smaller: we clip the part of source image within the
998 // dest rect, and then stretch it to fill the dest rect. We don't respect
999 // the aspect ratio in this case.
1000 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1001 static_cast<S16CPU>(dest_rect.height()));
1002 score->good_clipping = false;
1003 } else {
1004 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1005 if (src_aspect > dest_aspect) {
1006 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1007 // the wider screen.
1008 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1009 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1010 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1011 score->good_clipping = false;
1012 } else {
1013 src_rect.set(0, 0, src_bmp.width(),
1014 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1015 score->good_clipping = true;
1016 }
1017 }
1018
[email protected]26aa0482009-09-30 16:55:271019 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291020
1021 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021022 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291023
1024 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:141025 *thumbnail = skia::ImageOperations::Resize(
1026 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291027
1028 score->boring_score = CalculateBoringScore(thumbnail);
1029
[email protected]30507922010-01-15 16:48:231030 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1031 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:151032 return true;
initial.commit09911bf2008-07-26 23:55:291033}
1034
[email protected]30507922010-01-15 16:48:231035bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1036 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291037
[email protected]30507922010-01-15 16:48:231038 skia::PlatformCanvas canvas;
1039 if (!PaintViewIntoCanvas(view, canvas))
1040 return false;
1041
1042 skia::BitmapPlatformDevice& device =
1043 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1044
1045 const SkBitmap& bitmap = device.accessBitmap(false);
1046 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1047 return false;
1048
1049 HISTOGRAM_TIMES("Renderer4.Snapshot",
1050 base::TimeTicks::Now() - beginning_time);
1051 return true;
initial.commit09911bf2008-07-26 23:55:291052}
1053
1054void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1055 if (!webview())
1056 return;
1057
[email protected]3cc72b12010-03-18 23:03:001058 history_list_offset_ = params.current_history_list_offset;
1059 history_list_length_ = params.current_history_list_length;
1060
[email protected]8c785c62009-07-13 14:20:151061 if (devtools_agent_.get())
1062 devtools_agent_->OnNavigate();
1063
[email protected]422197532010-01-25 17:38:231064 if (notification_provider_.get())
1065 notification_provider_->OnNavigate();
1066
[email protected]a9f607e2009-10-23 19:59:271067 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261068
initial.commit09911bf2008-07-26 23:55:291069 AboutHandler::MaybeHandle(params.url);
1070
[email protected]ecbf10d2010-02-18 13:03:291071 bool is_reload =
1072 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1073 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291074
[email protected]26aa0482009-09-30 16:55:271075 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451076 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291077 // We cannot reload if we do not have any history state. This happens, for
1078 // example, when recovering from a crash. Our workaround here is a bit of
1079 // a hack since it means that reload after a crashed tab does not cause an
1080 // end-to-end cache validation.
1081 is_reload = false;
1082 }
1083
[email protected]77f17a82009-05-21 04:42:541084 // A navigation resulting from loading a javascript URL should not be treated
1085 // as a browser initiated event. Instead, we want it to look as if the page
1086 // initiated any load resulting from JS execution.
1087 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301088 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001089 params.page_id,
1090 params.pending_history_list_offset,
1091 params.transition,
1092 params.request_time);
[email protected]5e369672009-11-03 23:48:301093 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1094 // We're doing a load of a page that was restored from the last session.
1095 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1096 // which can result in stale data for pages that are set to expire. We
1097 // explicitly override that by setting the policy here so that as
1098 // necessary we load from the network.
1099 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1100 }
1101 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541102 }
initial.commit09911bf2008-07-26 23:55:291103
[email protected]a7ccc4d2010-01-27 08:14:481104 NavigationState* navigation_state = pending_navigation_state_.get();
1105
[email protected]04d3c6e2009-05-22 17:00:131106 // If we are reloading, then WebKit will use the history state of the current
1107 // page, so we should just ignore any given history state. Otherwise, if we
1108 // have history state, then we need to navigate to it, which corresponds to a
1109 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551110 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481111 if (navigation_state)
1112 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291113 bool ignore_cache = (params.navigation_type ==
1114 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1115 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551116 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131117 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581118 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481119 if (navigation_state)
1120 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451121 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171122 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131123 } else {
1124 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281125 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291126
[email protected]e6f546c32009-07-01 17:12:551127 // A session history navigation should have been accompanied by state.
1128 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131129
[email protected]dd7daa82009-08-10 05:46:451130 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551131 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131132
[email protected]726985e22009-06-18 21:09:281133 if (params.referrer.is_valid()) {
1134 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1135 WebString::fromUTF8(params.referrer.spec()));
1136 }
[email protected]04d3c6e2009-05-22 17:00:131137
[email protected]a7ccc4d2010-01-27 08:14:481138 if (navigation_state)
1139 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451140 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501141 }
1142
[email protected]77f17a82009-05-21 04:42:541143 // In case LoadRequest failed before DidCreateDataSource was called.
1144 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291145}
1146
1147// Stop loading the current page
1148void RenderView::OnStop() {
1149 if (webview())
[email protected]b4bb2502009-10-01 22:35:271150 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291151}
1152
[email protected]ecbf10d2010-02-18 13:03:291153// Reload current focused frame.
1154// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561155void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291156 if (webview() && webview()->focusedFrame()) {
1157 // We always obey the cache (ignore_cache=false) here.
1158 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1159 // a cache-ignoring reload of the frame.
1160 webview()->focusedFrame()->reload(false);
1161 }
[email protected]1dda4022010-01-28 18:24:561162}
1163
initial.commit09911bf2008-07-26 23:55:291164void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271165 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291166}
1167
[email protected]68b1e922009-06-23 16:00:251168void RenderView::OnExecuteEditCommand(const std::string& name,
1169 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271170 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251171 return;
1172
[email protected]26aa0482009-09-30 16:55:271173 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451174 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251175}
1176
[email protected]b2abac72009-02-26 12:39:281177void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111178 DCHECK(!devtools_client_.get());
1179 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281180}
1181
initial.commit09911bf2008-07-26 23:55:291182void RenderView::OnUpdateTargetURLAck() {
1183 // Check if there is a targeturl waiting to be sent.
1184 if (target_url_status_ == TARGET_PENDING) {
1185 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1186 pending_target_url_));
1187 }
1188
1189 target_url_status_ = TARGET_NONE;
1190}
1191
1192void RenderView::OnUndo() {
1193 if (!webview())
1194 return;
1195
[email protected]26aa0482009-09-30 16:55:271196 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121197 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291198}
1199
1200void RenderView::OnRedo() {
1201 if (!webview())
1202 return;
1203
[email protected]26aa0482009-09-30 16:55:271204 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121205 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291206}
1207
1208void RenderView::OnCut() {
1209 if (!webview())
1210 return;
1211
[email protected]26aa0482009-09-30 16:55:271212 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121213 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291214}
1215
1216void RenderView::OnCopy() {
1217 if (!webview())
1218 return;
1219
[email protected]26aa0482009-09-30 16:55:271220 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121221 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291222}
1223
[email protected]c0cc3092009-09-12 08:27:271224#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351225void RenderView::OnCopyToFindPboard() {
1226 if (!webview())
1227 return;
1228
1229 // Since the find pasteboard supports only plain text, this can be simpler
1230 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271231 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351232 if (frame->hasSelection()) {
1233 string16 selection = frame->selectionAsText();
1234 RenderThread::current()->Send(
1235 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1236 }
1237
[email protected]afe3a1672009-11-17 19:04:121238 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351239}
[email protected]c0cc3092009-09-12 08:27:271240#endif
[email protected]a954bf72009-09-12 07:30:351241
initial.commit09911bf2008-07-26 23:55:291242void RenderView::OnPaste() {
1243 if (!webview())
1244 return;
1245
[email protected]26aa0482009-09-30 16:55:271246 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121247 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291248}
1249
[email protected]2a3a7762009-10-19 19:17:321250void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291251 if (!webview())
1252 return;
1253
[email protected]1ff7a032010-02-03 02:46:031254 WebFrame* frame = webview()->focusedFrame();
1255 if (!frame->hasSelection())
1256 frame->selectWordAroundCaret();
1257 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291258}
1259
[email protected]98324892009-09-09 21:16:051260void RenderView::OnAdvanceToNextMisspelling() {
1261 if (!webview())
1262 return;
[email protected]26aa0482009-09-30 16:55:271263 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051264 WebString::fromUTF8("AdvanceToNextMisspelling"));
1265}
1266
1267void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1268 if (!webview())
1269 return;
1270 // We need to tell the webView whether the spelling panel is visible or not so
1271 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261272 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271273 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051274 WebString::fromUTF8("ToggleSpellPanel"));
1275}
1276
[email protected]bbbd545c2008-12-15 20:18:041277void RenderView::OnToggleSpellCheck() {
1278 if (!webview())
1279 return;
1280
[email protected]26aa0482009-09-30 16:55:271281 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451282 frame->enableContinuousSpellChecking(
1283 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041284}
1285
initial.commit09911bf2008-07-26 23:55:291286void RenderView::OnDelete() {
1287 if (!webview())
1288 return;
1289
[email protected]26aa0482009-09-30 16:55:271290 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121291 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291292}
1293
1294void RenderView::OnSelectAll() {
1295 if (!webview())
1296 return;
1297
[email protected]26aa0482009-09-30 16:55:271298 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221299 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121300 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291301}
1302
1303void RenderView::OnSetInitialFocus(bool reverse) {
1304 if (!webview())
1305 return;
[email protected]26aa0482009-09-30 16:55:271306 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291307}
1308
1309///////////////////////////////////////////////////////////////////////////////
1310
[email protected]433819d2010-01-30 20:20:011311void RenderView::SetContentSettings(const ContentSettings& settings) {
1312 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011313}
1314
initial.commit09911bf2008-07-26 23:55:291315// Tell the embedding application that the URL of the active page has changed
1316void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451317 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291318 DCHECK(ds);
1319
[email protected]726985e22009-06-18 21:09:281320 const WebURLRequest& request = ds->request();
1321 const WebURLRequest& original_request = ds->originalRequest();
1322 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291323
[email protected]daa8c58e2009-06-15 17:21:101324 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1325 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291326
1327 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281328 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291329 params.is_post = false;
1330 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281331 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091332 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551333 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291334 // SSL state specified in the request takes precedence over the one in the
1335 // response.
1336 // So far this is only intended for error pages that are not expected to be
1337 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281338 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551339 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291340 } else {
[email protected]726985e22009-06-18 21:09:281341 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291342 }
1343
1344 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281345 if (ds->hasUnreachableURL()) {
1346 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291347 } else {
[email protected]726985e22009-06-18 21:09:281348 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291349 }
1350
[email protected]726985e22009-06-18 21:09:281351 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241352 params.should_update_history = !ds->hasUnreachableURL() &&
1353 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291354
[email protected]ce0e250d2009-10-23 21:00:351355 params.searchable_form_url = navigation_state->searchable_form_url();
1356 params.searchable_form_encoding =
1357 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291358
1359 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101360 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291361 if (password_form_data)
1362 params.password_form = *password_form_data;
1363
1364 params.gesture = navigation_gesture_;
1365 navigation_gesture_ = NavigationGestureUnknown;
1366
[email protected]dd7daa82009-08-10 05:46:451367 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291368 // Top-level navigation.
1369
[email protected]71b0d5d2010-02-15 05:43:071370 // Clear "block" flags for the new page. This needs to happen before any of
1371 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1372 // so that these functions can correctly detect that a piece of content
1373 // flipped from "not blocked" to "blocked".
1374 ClearBlockedContentSettings();
1375
[email protected]62d2a112010-04-07 00:53:021376 // Set content settings. Default them from the parent window if one exists.
1377 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011378 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541379 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011380 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011381 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011382
1383 // These content settings were merely recorded transiently for this load.
1384 // We can erase them now. If at some point we reload this page, the
1385 // browser will send us new, up-to-date content settings.
1386 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401387 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101388 // The opener's view is not guaranteed to be non-null (it could be
1389 // detached from its page but not yet destructed).
1390 if (WebView* opener_view = frame->opener()->view()) {
1391 RenderView* opener = FromWebView(opener_view);
1392 SetContentSettings(opener->current_content_settings_);
1393 }
[email protected]f85f0702010-01-30 09:31:011394 }
1395
[email protected]40bd6582009-12-04 23:49:511396 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011397 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541398 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011399 if (host_zoom != host_zoom_levels_.end()) {
1400 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511401 // This zoom level was merely recorded transiently for this load. We can
1402 // erase it now. If at some point we reload this page, the browser will
1403 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011404 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511405 }
1406
initial.commit09911bf2008-07-26 23:55:291407 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551408 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291409
[email protected]daa8c58e2009-06-15 17:21:101410 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291411 if (!PageTransition::IsMainFrame(params.transition)) {
1412 // If the main frame does a load, it should not be reported as a subframe
1413 // navigation. This can occur in the following case:
1414 // 1. You're on a site with frames.
1415 // 2. You do a subframe navigation. This is stored with transition type
1416 // MANUAL_SUBFRAME.
1417 // 3. You navigate to some non-frame site, say, google.com.
1418 // 4. You navigate back to the page from step 2. Since it was initially
1419 // MANUAL_SUBFRAME, it will be that same transition type here.
1420 // We don't want that, because any navigation that changes the toplevel
1421 // frame should be tracked as a toplevel navigation (this allows us to
1422 // update the URL bar, etc).
1423 params.transition = PageTransition::LINK;
1424 }
1425
initial.commit09911bf2008-07-26 23:55:291426 // If we have a valid consumed client redirect source,
1427 // the page contained a client redirect (meta refresh, document.loc...),
1428 // so we set the referrer and transition to match.
1429 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041430 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291431 params.referrer = completed_client_redirect_src_;
1432 params.transition = static_cast<PageTransition::Type>(
1433 params.transition | PageTransition::CLIENT_REDIRECT);
1434 } else {
1435 // Bug 654101: the referrer will be empty on https->http transitions. It
1436 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281437 params.referrer = GURL(
1438 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291439 }
1440
[email protected]726985e22009-06-18 21:09:281441 string16 method = request.httpMethod();
1442 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291443 params.is_post = true;
1444
[email protected]c2a797d2009-09-21 16:46:321445 // Save some histogram data so we can compute the average memory used per
1446 // page load of the glyphs.
1447 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1448 webkit_glue::GetGlyphPageCount());
1449
[email protected]15cf526b2010-02-12 06:33:491450 // This message needs to be sent before any of allowScripts(),
1451 // allowImages(), allowPlugins() is called for the new page, so that when
1452 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1453 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291454 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1455 } else {
1456 // Subframe navigation: the type depends on whether this navigation
1457 // generated a new session history entry. When they do generate a session
1458 // history entry, it means the user initiated the navigation and we should
1459 // mark it as such. This test checks if this is the first time UpdateURL
1460 // has been called since WillNavigateToURL was called to initiate the load.
1461 if (page_id_ > last_page_id_sent_to_browser_)
1462 params.transition = PageTransition::MANUAL_SUBFRAME;
1463 else
1464 params.transition = PageTransition::AUTO_SUBFRAME;
1465
initial.commit09911bf2008-07-26 23:55:291466 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1467 }
1468
1469 last_page_id_sent_to_browser_ =
1470 std::max(last_page_id_sent_to_browser_, page_id_);
1471
1472 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101473 // we don't want the transition type to persist. Just clear it.
1474 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501475
[email protected]af15bed2010-08-25 21:12:091476 // Check if the navigation was within the same page, in which case we don't
1477 // want to clear the accessibility cache.
1478 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]b3df5a42010-05-11 14:31:091479 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351480 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501481 }
[email protected]9892b472010-09-16 00:23:421482 pending_accessibility_notifications_.clear();
initial.commit09911bf2008-07-26 23:55:291483}
1484
1485// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171486void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291487 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171488 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171489 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171490 routing_id_,
1491 page_id_,
1492 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1493 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171494 }
initial.commit09911bf2008-07-26 23:55:291495}
1496
1497void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401498 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291499 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271500 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291501 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301502 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291503 last_encoding_name_ = encoding_name;
1504
[email protected]e38f40152008-09-12 23:08:301505 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291506 }
1507}
1508
[email protected]f4d34b52008-11-24 23:05:011509// Sends the previous session history state to the browser so it will be saved
1510// before we navigate to a new page. This must be called *before* the page ID
1511// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291512void RenderView::UpdateSessionHistory(WebFrame* frame) {
1513 // If we have a valid page ID at this point, then it corresponds to the page
1514 // we are navigating away from. Otherwise, this is the first navigation, so
1515 // there is no past session history to record.
1516 if (page_id_ == -1)
1517 return;
1518
[email protected]ca948a22009-06-25 19:36:171519 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271520 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171521 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291522 return;
[email protected]ca948a22009-06-25 19:36:171523
1524 Send(new ViewHostMsg_UpdateState(
1525 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291526}
1527
[email protected]3d9689372009-09-10 04:29:171528void RenderView::OpenURL(
1529 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1530 Send(new ViewHostMsg_OpenURL(
1531 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1532}
1533
[email protected]79dbc662009-09-04 05:42:511534// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291535
initial.commit09911bf2008-07-26 23:55:291536void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281537 const WebURLRequest& failed_request,
1538 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291539 const std::string& html,
1540 bool replace) {
[email protected]726985e22009-06-18 21:09:281541 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291542 std::string alt_html;
[email protected]07b493512010-08-27 15:39:291543 ExtensionRendererInfo* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291544 if (html.empty()) {
1545 // Use a local error page.
1546 int resource_id;
1547 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111548
1549 if (failed_url.is_valid())
1550 extension = ExtensionRendererInfo::GetByURL(failed_url);
1551 if (extension) {
[email protected]3f853a52010-09-13 19:15:081552 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1553 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111554
1555 // TODO(erikkay): Should we use a different template for different
1556 // error messages?
1557 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291558 } else {
[email protected]3f853a52010-09-13 19:15:081559 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1560 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111561 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081562 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111563 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1564 } else {
[email protected]3f853a52010-09-13 19:15:081565 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111566 resource_id = IDR_NET_ERROR_HTML;
1567 }
initial.commit09911bf2008-07-26 23:55:291568 }
initial.commit09911bf2008-07-26 23:55:291569
1570 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1571 } else {
1572 alt_html = html;
1573 }
1574
[email protected]dd7daa82009-08-10 05:46:451575 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551576 GURL(kUnreachableWebDataURL),
1577 failed_url,
1578 replace);
initial.commit09911bf2008-07-26 23:55:291579}
1580
[email protected]7ccddb8c2009-08-04 17:36:551581void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031582 if (!dom_automation_controller_.get()) {
1583 dom_automation_controller_.reset(new DomAutomationController());
1584 }
1585 dom_automation_controller_->set_message_sender(this);
1586 dom_automation_controller_->set_routing_id(routing_id_);
1587 dom_automation_controller_->BindToJavascript(frame,
1588 L"domAutomationController");
initial.commit09911bf2008-07-26 23:55:291589}
1590
initial.commit09911bf2008-07-26 23:55:291591bool RenderView::RunJavaScriptMessage(int type,
1592 const std::wstring& message,
1593 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071594 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291595 std::wstring* result) {
1596 bool success = false;
1597 std::wstring result_temp;
1598 if (!result)
1599 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291600
[email protected]12636df2009-09-28 22:32:211601 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1602 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291603 return success;
1604}
1605
[email protected]c1f50aa2010-02-18 03:46:571606bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1607 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1608 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1609 // it is particularly important that we do not call willEnterModalLoop as
1610 // that would defer resource loads for the dialog itself.
1611 if (RenderThread::current()) // Will be NULL during unit tests.
1612 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1613
1614 message->EnableMessagePumping(); // Runs a nested message loop.
1615 return Send(message);
1616}
1617
initial.commit09911bf2008-07-26 23:55:291618void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1619 if (!osd_url.is_empty())
1620 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1621 autodetected));
1622}
1623
[email protected]95056b582010-02-18 01:29:241624void RenderView::OnAutoFillSuggestionsReturned(
1625 int query_id,
[email protected]8f6e6582010-04-09 02:03:071626 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391627 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411628 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391629 const std::vector<int>& unique_ids) {
[email protected]6a8ddba52010-09-05 04:38:061630 autofill_helper_->SuggestionsReceived(
[email protected]a53e06832010-07-28 22:46:411631 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031632}
1633
[email protected]45c6e532010-03-15 23:51:241634void RenderView::OnAutoFillFormDataFilled(int query_id,
1635 const webkit_glue::FormData& form) {
[email protected]6a8ddba52010-09-05 04:38:061636 autofill_helper_->FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481637}
1638
[email protected]e8345242010-05-06 03:00:401639void RenderView::OnAllowScriptToClose(bool script_can_close) {
1640 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311641}
1642
initial.commit09911bf2008-07-26 23:55:291643uint32 RenderView::GetCPBrowsingContext() {
1644 uint32 context = 0;
1645 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1646 return context;
1647}
1648
initial.commit09911bf2008-07-26 23:55:291649void RenderView::AddSearchProvider(const std::string& url) {
1650 AddGURLSearchProvider(GURL(url),
1651 false); // not autodetected
1652}
1653
[email protected]155f35e2010-07-17 00:30:181654ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251655RenderView::GetSearchProviderInstallState(WebFrame* frame,
1656 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181657 GURL inquiry_url = GURL(url);
1658 if (inquiry_url.is_empty())
1659 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251660
[email protected]155f35e2010-07-17 00:30:181661 ViewHostMsg_GetSearchProviderInstallState_Params install;
1662 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:251663 frame->url(),
[email protected]155f35e2010-07-17 00:30:181664 inquiry_url,
1665 &install));
1666 return install;
1667}
1668
[email protected]f103ab72009-09-02 17:10:591669void RenderView::OnMissingPluginStatus(
1670 WebPluginDelegateProxy* delegate,
1671 int status) {
[email protected]6c8afae52009-01-22 02:24:571672#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591673 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291674 // Show the InfoBar for the first available plugin.
1675 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591676 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291677 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1678 }
1679 } else {
1680 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1681 // to start the download/install.
1682 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1683 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1684 }
1685 }
[email protected]6c8afae52009-01-22 02:24:571686#else
[email protected]76c3b312010-05-20 21:38:291687 // TODO(port): Implement the infobar that accompanies the default plugin.
1688 // Linux: http://crbug.com/10952
1689 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571690 NOTIMPLEMENTED();
1691#endif
initial.commit09911bf2008-07-26 23:55:291692}
1693
[email protected]48c9cf2d2009-09-16 16:47:521694// WebKit::WebViewClient ------------------------------------------------------
1695
[email protected]8ab04652010-06-12 02:47:261696WebView* RenderView::createView(
1697 WebFrame* creator,
1698 const WebWindowFeatures& features,
1699 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521700 // Check to make sure we aren't overloading on popups.
1701 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1702 return NULL;
1703
1704 // This window can't be closed from a window.close() call until we receive a
1705 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401706 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521707
[email protected]8ab04652010-06-12 02:47:261708 ViewHostMsg_CreateWindow_Params params;
1709 params.opener_id = routing_id_;
1710 params.user_gesture = creator->isProcessingUserGesture();
1711 params.window_container_type = WindowFeaturesToContainerType(features);
1712 params.session_storage_namespace_id = session_storage_namespace_id_;
1713 params.frame_name = frame_name;
1714
[email protected]48c9cf2d2009-09-16 16:47:521715 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341716 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261717 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521718
[email protected]48c9cf2d2009-09-16 16:47:521719 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261720 new ViewHostMsg_CreateWindow(params,
1721 &routing_id,
1722 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211723 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521724 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521725
[email protected]48c9cf2d2009-09-16 16:47:521726 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421727 0,
[email protected]12636df2009-09-28 22:32:211728 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521729 renderer_preferences_,
1730 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211731 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341732 routing_id,
[email protected]8ab04652010-06-12 02:47:261733 cloned_session_storage_namespace_id,
1734 frame_name);
1735 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521736
[email protected]007a848b2009-10-26 15:55:461737 // Record whether the creator frame is trying to suppress the opener field.
1738 view->opener_suppressed_ = opener_suppressed;
1739
[email protected]48c9cf2d2009-09-16 16:47:521740 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091741 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521742 if (!creator_url.is_valid() || !creator_url.IsStandard())
1743 creator_url = GURL();
1744 view->creator_url_ = creator_url;
1745
1746 // Copy over the alternate error page URL so we can have alt error pages in
1747 // the new render view (we don't need the browser to send the URL back down).
1748 view->alternate_error_page_url_ = alternate_error_page_url_;
1749
1750 return view->webview();
1751}
1752
[email protected]3e2b375b2010-04-07 17:03:121753WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521754 RenderWidget* widget = RenderWidget::Create(routing_id_,
1755 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121756 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521757 return widget->webwidget();
1758}
1759
1760WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1761 RenderWidget* widget = RenderWidget::Create(routing_id_,
1762 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121763 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521764 widget->ConfigureAsExternalPopupMenu(info);
1765 return widget->webwidget();
1766}
1767
[email protected]484955942010-08-19 16:13:181768WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
1769 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
1770 render_thread_,
1771 popup_type);
1772 return widget->webwidget();
1773}
1774
[email protected]79c7bed2010-09-14 22:28:391775pepper::FullscreenContainer* RenderView::CreatePepperFullscreenContainer(
1776 pepper::PluginInstance* plugin) {
1777 RenderWidgetFullscreenPepper* widget =
1778 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
1779 widget->show(WebKit::WebNavigationPolicyIgnore);
1780 return widget->container();
1781}
1782
[email protected]68c50e52010-05-12 11:14:391783WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341784 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391785 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291786 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1787 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1788 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341789}
1790
[email protected]48c9cf2d2009-09-16 16:47:521791void RenderView::didAddMessageToConsole(
1792 const WebConsoleMessage& message, const WebString& source_name,
1793 unsigned source_line) {
1794 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1795 UTF16ToWideHack(message.text),
1796 static_cast<int32>(source_line),
1797 UTF16ToWideHack(source_name)));
1798}
1799
1800void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581801 DCHECK(frame);
1802 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521803}
1804
[email protected]3354d3e2010-06-10 19:53:021805WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1806 return notification_provider_.get();
1807}
1808
[email protected]48c9cf2d2009-09-16 16:47:521809void RenderView::didStartLoading() {
1810 if (is_loading_) {
1811 DLOG(WARNING) << "didStartLoading called while loading";
1812 return;
1813 }
1814
1815 is_loading_ = true;
1816 // Clear the pointer so that we can assign it only when there is an unknown
1817 // plugin on a page.
1818 first_default_plugin_.reset();
1819
1820 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1821}
1822
1823void RenderView::didStopLoading() {
1824 if (!is_loading_) {
1825 DLOG(WARNING) << "DidStopLoading called while not loading";
1826 return;
1827 }
1828
1829 is_loading_ = false;
1830
1831 // NOTE: For now we're doing the safest thing, and sending out notification
1832 // when done loading. This currently isn't an issue as the favicon is only
1833 // displayed when done loading. Ideally we would send notification when
1834 // finished parsing the head, but webkit doesn't support that yet.
1835 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271836 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521837 if (!favicon_url.is_empty())
1838 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1839
[email protected]26aa0482009-09-30 16:55:271840 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521841 true); // autodetected
1842
1843 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1844
[email protected]f9f4841b2010-03-20 05:41:421845 MessageLoop::current()->PostDelayedTask(
1846 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:301847 page_info_method_factory_.NewRunnableMethod(
1848 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:371849 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521850}
1851
[email protected]f55039a2010-02-17 14:12:061852bool RenderView::isSmartInsertDeleteEnabled() {
1853#if defined(OS_MACOSX)
1854 return true;
1855#else
1856 return false;
1857#endif
1858}
1859
[email protected]04fc9482009-09-18 22:13:031860bool RenderView::isSelectTrailingWhitespaceEnabled() {
1861#if defined(OS_WIN)
1862 return true;
1863#else
1864 return false;
1865#endif
1866}
1867
[email protected]04fc9482009-09-18 22:13:031868void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]eef99c22010-08-17 05:55:161869#if defined(USE_X11) || defined(OS_MACOSX)
[email protected]04fc9482009-09-18 22:13:031870 if (!handling_input_event_)
1871 return;
1872 // TODO(estade): investigate incremental updates to the selection so that we
1873 // don't send the entire selection over IPC every time.
1874 if (!is_empty_selection) {
1875 // Sometimes we get repeated didChangeSelection calls from webkit when
1876 // the selection hasn't actually changed. We don't want to report these
1877 // because it will cause us to continually claim the X clipboard.
1878 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271879 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031880 if (this_selection == last_selection_)
1881 return;
1882
1883 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1884 this_selection));
1885 last_selection_ = this_selection;
1886 } else {
1887 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:161888 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1889 last_selection_));
[email protected]04fc9482009-09-18 22:13:031890 }
1891#endif
1892}
1893
1894void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121895 const std::string& name = UTF16ToUTF8(command_name);
1896 if (StartsWithASCII(name, "Move", true) ||
1897 StartsWithASCII(name, "Insert", true) ||
1898 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031899 return;
1900 UserMetricsRecordAction(name);
1901}
1902
[email protected]03f57072010-07-14 17:36:081903void RenderView::textFieldDidEndEditing(
1904 const WebKit::WebInputElement& element) {
1905#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061906 password_autocomplete_manager_->TextFieldDidEndEditing(element);
[email protected]03f57072010-07-14 17:36:081907#endif
1908}
1909
1910void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1911#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]e47aec52010-08-12 00:50:301912 // We post a task for doing the AutoFill as the caret position is not set
1913 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
1914 // it is needed to trigger autofill.
1915 autofill_method_factory_.RevokeAll();
1916 MessageLoop::current()->PostTask(
1917 FROM_HERE,
1918 autofill_method_factory_.NewRunnableMethod(
1919 &RenderView::TextFieldDidChangeImpl, element));
[email protected]03f57072010-07-14 17:36:081920#endif
1921}
1922
[email protected]e47aec52010-08-12 00:50:301923void RenderView::TextFieldDidChangeImpl(
1924 const WebKit::WebInputElement& element) {
[email protected]6a8ddba52010-09-05 04:38:061925 if (password_autocomplete_manager_->TextDidChangeInTextField(element))
[email protected]e47aec52010-08-12 00:50:301926 return;
[email protected]6a8ddba52010-09-05 04:38:061927 autofill_helper_->TextDidChangeInTextField(element);
[email protected]e47aec52010-08-12 00:50:301928}
1929
[email protected]03f57072010-07-14 17:36:081930void RenderView::textFieldDidReceiveKeyDown(
1931 const WebKit::WebInputElement& element,
1932 const WebKit::WebKeyboardEvent& event) {
1933#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061934 password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event);
[email protected]03f57072010-07-14 17:36:081935#endif
1936}
1937
[email protected]b2528b72009-09-24 06:57:101938bool RenderView::handleCurrentKeyboardEvent() {
1939 if (edit_commands_.empty())
1940 return false;
1941
[email protected]26aa0482009-09-30 16:55:271942 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101943 if (!frame)
1944 return false;
1945
1946 EditCommands::iterator it = edit_commands_.begin();
1947 EditCommands::iterator end = edit_commands_.end();
1948
[email protected]507b33ea2009-09-29 03:56:511949 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101950 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331951 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1952 // key (but it's the exception). Once one edit command is not executed, it
1953 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101954 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1955 WebString::fromUTF8(it->value)))
1956 break;
[email protected]507b33ea2009-09-29 03:56:511957 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101958 }
1959
[email protected]507b33ea2009-09-29 03:56:511960 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101961}
1962
[email protected]e47aec52010-08-12 00:50:301963void RenderView::inputElementClicked(const WebKit::WebInputElement& element,
1964 bool already_focused) {
1965#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:061966 if (password_autocomplete_manager_->InputElementClicked(element,
1967 already_focused)) {
[email protected]e47aec52010-08-12 00:50:301968 return;
1969 }
[email protected]6a8ddba52010-09-05 04:38:061970 autofill_helper_->InputElementClicked(element, already_focused);
[email protected]e47aec52010-08-12 00:50:301971#endif
1972}
1973
[email protected]2a3a7762009-10-19 19:17:321974void RenderView::spellCheck(const WebString& text,
1975 int& misspelled_offset,
1976 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561977 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461978
[email protected]85c55dc2009-11-06 03:05:461979 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171980 RenderThread* thread = RenderThread::current();
1981 // Will be NULL during unit tests.
1982 if (thread) {
[email protected]c27324b2009-11-19 22:44:291983 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171984 word.c_str(), word.size(), document_tag_,
1985 &misspelled_offset, &misspelled_length, NULL);
1986 }
[email protected]1dbafaf72009-09-23 19:43:561987}
1988
1989WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321990 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561991 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261992 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561993 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171994 RenderThread* thread = RenderThread::current();
1995 // Will be NULL during unit tests.
1996 if (thread) {
1997 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291998 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171999 word, document_tag_);
2000 }
[email protected]1dbafaf72009-09-23 19:43:562001 }
[email protected]2a3a7762009-10-19 19:17:322002 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562003}
2004
[email protected]c49085c72009-10-02 16:28:562005void RenderView::showSpellingUI(bool show) {
2006 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2007}
2008
[email protected]8922e1f2009-10-03 05:01:262009bool RenderView::isShowingSpellingUI() {
2010 return spelling_panel_visible_;
2011}
2012
[email protected]1dbafaf72009-09-23 19:43:562013void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322014 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2015 word));
[email protected]1dbafaf72009-09-23 19:43:562016}
2017
[email protected]a1128322009-10-06 18:38:462018bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352019 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472020 WebFileChooserCompletion* chooser_completion) {
2021 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262022 if (params.directory)
2023 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2024 else if (params.multiSelect)
2025 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2026 else
2027 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472028 ipc_params.title = params.title;
2029 ipc_params.default_file_name =
2030 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592031 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472032
2033 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462034}
2035
[email protected]48c9cf2d2009-09-16 16:47:522036void RenderView::runModalAlertDialog(
2037 WebFrame* frame, const WebString& message) {
2038 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
2039 UTF16ToWideHack(message),
2040 std::wstring(),
2041 frame->url(),
2042 NULL);
2043}
2044
2045bool RenderView::runModalConfirmDialog(
2046 WebFrame* frame, const WebString& message) {
2047 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
2048 UTF16ToWideHack(message),
2049 std::wstring(),
2050 frame->url(),
2051 NULL);
2052}
2053
2054bool RenderView::runModalPromptDialog(
2055 WebFrame* frame, const WebString& message, const WebString& default_value,
2056 WebString* actual_value) {
2057 std::wstring result;
2058 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
2059 UTF16ToWideHack(message),
2060 UTF16ToWideHack(default_value),
2061 frame->url(),
2062 &result);
2063 if (ok)
2064 actual_value->assign(WideToUTF16Hack(result));
2065 return ok;
2066}
2067
2068bool RenderView::runModalBeforeUnloadDialog(
2069 WebFrame* frame, const WebString& message) {
2070 bool success = false;
2071 // This is an ignored return value, but is included so we can accept the same
2072 // response as RunJavaScriptMessage.
2073 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212074 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522075 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212076 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522077 return success;
2078}
2079
[email protected]79e37442009-10-09 18:17:442080void RenderView::showContextMenu(
2081 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292082 ContextMenuParams params = ContextMenuParams(data);
2083 if (!params.misspelled_word.empty() && RenderThread::current()) {
2084 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042085 bool spelled_right = RenderThread::current()->spellchecker()->
2086 SpellCheckWord(
2087 params.misspelled_word.c_str(), params.misspelled_word.size(),
2088 document_tag_,
2089 &misspelled_offset, &misspelled_length,
2090 &params.dictionary_suggestions);
2091 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292092 params.misspelled_word.clear();
2093 }
[email protected]216932c2010-08-26 21:44:272094 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2095 // it. We replace it with an empty GURL so the appropriate items are disabled
2096 // in the context menu.
2097 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2098 // data encoded images. We should have a way to save them.
2099 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2100 params.src_url = GURL();
[email protected]c27324b2009-11-19 22:44:292101 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442102}
2103
[email protected]52f139e2c2010-06-11 16:56:092104bool RenderView::supportsFullscreen() {
2105 return CommandLine::ForCurrentProcess()->HasSwitch(
2106 switches::kEnableVideoFullscreen);
2107}
2108
2109void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2110 NOTIMPLEMENTED();
2111}
2112
2113void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2114 NOTIMPLEMENTED();
2115}
2116
[email protected]48c9cf2d2009-09-16 16:47:522117void RenderView::setStatusText(const WebString& text) {
2118}
2119
[email protected]163f8242009-10-30 20:19:552120void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582121 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522122 if (latest_url == target_url_)
2123 return;
[email protected]163f8242009-10-30 20:19:552124
[email protected]48c9cf2d2009-09-16 16:47:522125 // Tell the browser to display a destination link.
2126 if (target_url_status_ == TARGET_INFLIGHT ||
2127 target_url_status_ == TARGET_PENDING) {
2128 // If we have a request in-flight, save the URL to be sent when we
2129 // receive an ACK to the in-flight request. We can happily overwrite
2130 // any existing pending sends.
2131 pending_target_url_ = latest_url;
2132 target_url_status_ = TARGET_PENDING;
2133 } else {
2134 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2135 target_url_ = latest_url;
2136 target_url_status_ = TARGET_INFLIGHT;
2137 }
2138}
2139
[email protected]882daa92009-11-05 16:31:312140void RenderView::StartNavStateSyncTimerIfNecessary() {
2141 int delay;
2142 if (send_content_state_immediately_)
2143 delay = 0;
2144 else if (is_hidden())
2145 delay = kDelaySecondsForContentStateSyncHidden;
2146 else
2147 delay = kDelaySecondsForContentStateSync;
2148
2149 if (nav_state_sync_timer_.IsRunning()) {
2150 // The timer is already running. If the delay of the timer maches the amount
2151 // we want to delay by, then return. Otherwise stop the timer so that it
2152 // gets started with the right delay.
2153 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2154 return;
2155 nav_state_sync_timer_.Stop();
2156 }
2157
2158 nav_state_sync_timer_.Start(
2159 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2160}
2161
[email protected]163f8242009-10-30 20:19:552162void RenderView::setMouseOverURL(const WebURL& url) {
2163 mouse_over_url_ = GURL(url);
2164 UpdateTargetURL(mouse_over_url_, focus_url_);
2165}
2166
2167void RenderView::setKeyboardFocusURL(const WebURL& url) {
2168 focus_url_ = GURL(url);
2169 UpdateTargetURL(focus_url_, mouse_over_url_);
2170}
2171
[email protected]48c9cf2d2009-09-16 16:47:522172void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2173 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2174 hint));
2175}
2176
[email protected]c27ae592010-03-18 15:24:412177void RenderView::startDragging(const WebDragData& data,
2178 WebDragOperationsMask mask,
2179 const WebImage& image,
2180 const WebPoint& imageOffset) {
2181#if WEBKIT_USING_SKIA
2182 SkBitmap bitmap(image.getSkBitmap());
2183#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332184 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412185#endif
2186
[email protected]48c9cf2d2009-09-16 16:47:522187 Send(new ViewHostMsg_StartDragging(routing_id_,
2188 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412189 mask,
2190 bitmap,
2191 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522192}
2193
[email protected]28b92df2009-09-25 17:35:452194bool RenderView::acceptsLoadDrops() {
2195 return renderer_preferences_.can_accept_load_drops;
2196}
2197
[email protected]48c9cf2d2009-09-16 16:47:522198void RenderView::focusNext() {
2199 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2200}
2201
2202void RenderView::focusPrevious() {
2203 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2204}
2205
[email protected]08e9e132010-06-01 16:58:492206void RenderView::focusedNodeChanged(const WebNode& node) {
2207 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2208}
2209
[email protected]48c9cf2d2009-09-16 16:47:522210void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522211 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2212}
2213
2214int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002215 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522216}
2217
2218int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002219 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522220}
2221
[email protected]c4e98902010-06-01 10:20:142222void RenderView::didUpdateInspectorSetting(const WebString& key,
2223 const WebString& value) {
2224 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2225 key.utf8(),
2226 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262227}
2228
[email protected]acca2a1f2009-10-16 03:53:392229void RenderView::queryAutofillSuggestions(const WebNode& node,
2230 const WebString& name,
2231 const WebString& value) {
[email protected]a5e84bd2010-09-14 22:23:362232 autofill_helper_->QueryAutoFillSuggestions(node);
[email protected]acca2a1f2009-10-16 03:53:392233}
2234
2235void RenderView::removeAutofillSuggestions(const WebString& name,
2236 const WebString& value) {
[email protected]6a8ddba52010-09-05 04:38:062237 autofill_helper_->RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a1f2009-10-16 03:53:392238}
2239
[email protected]18ca9a6b2010-06-02 19:05:182240void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2241 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202242 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392243 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202244 unsigned index) {
[email protected]a5e84bd2010-09-14 22:23:362245 autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index);
[email protected]18ca9a6b2010-06-02 19:05:182246}
[email protected]c83641732010-02-20 01:04:482247
[email protected]18ca9a6b2010-06-02 19:05:182248void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2249 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392250 const WebKit::WebString& label,
2251 int unique_id) {
[email protected]a5e84bd2010-09-14 22:23:362252 autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182253}
2254
2255void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]6a8ddba52010-09-05 04:38:062256 autofill_helper_->DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482257}
2258
[email protected]03f57072010-07-14 17:36:082259void RenderView::didAcceptAutocompleteSuggestion(
2260 const WebKit::WebInputElement& user_element) {
2261#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:062262 bool result = password_autocomplete_manager_->FillPassword(user_element);
[email protected]03f57072010-07-14 17:36:082263 // Since this user name was selected from a suggestion list, we should always
2264 // have password for it.
2265 DCHECK(result);
2266#endif
2267}
2268
[email protected]79dbc662009-09-04 05:42:512269// WebKit::WebWidgetClient ----------------------------------------------------
2270
[email protected]ea42e7782010-08-23 23:58:122271void RenderView::didFocus() {
2272 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2273 // we won't have to test for user gesture anymore and we can
2274 // move that code back to render_widget.cc
2275 if (webview() && webview()->mainFrame() &&
2276 webview()->mainFrame()->isProcessingUserGesture()) {
2277 Send(new ViewHostMsg_Focus(routing_id_));
2278 }
2279}
2280
2281void RenderView::didBlur() {
2282 // TODO(jcivelli): see TODO above in didFocus().
2283 if (webview() && webview()->mainFrame() &&
2284 webview()->mainFrame()->isProcessingUserGesture()) {
2285 Send(new ViewHostMsg_Blur(routing_id_));
2286 }
2287}
2288
initial.commit09911bf2008-07-26 23:55:292289// We are supposed to get a single call to Show for a newly created RenderView
2290// that was created via RenderView::CreateWebView. So, we wait until this
2291// point to dispatch the ShowView message.
2292//
2293// This method provides us with the information about how to display the newly
2294// created RenderView (i.e., as a constrained popup or as a new tab).
2295//
[email protected]4873c7d2009-07-16 06:36:282296void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292297 DCHECK(!did_show_) << "received extraneous Show call";
2298 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2299
2300 if (did_show_)
2301 return;
2302 did_show_ = true;
2303
[email protected]4026ce1e2010-09-14 19:35:042304 // Extensions and apps always allowed to create unrequested popups. The second
2305 // check is necessary to include content scripts.
2306 if (ExtensionRendererInfo::GetByURL(creator_url_) ||
2307 bindings_utils::GetInfoForCurrentContext()) {
2308 opened_by_user_gesture_ = true;
2309 }
2310
[email protected]28295ec2009-10-16 05:34:332311 // Force new windows to a popup if they were not opened with a user gesture.
2312 if (!opened_by_user_gesture_) {
2313 // We exempt background tabs for compat with older versions of Chrome.
2314 // TODO(darin): This seems bogus. These should have a user gesture, so
2315 // we probably don't need this check.
2316 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2317 policy = WebKit::WebNavigationPolicyNewPopup;
2318 }
2319
initial.commit09911bf2008-07-26 23:55:292320 // NOTE: initial_pos_ may still have its default values at this point, but
2321 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2322 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282323 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2324 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292325 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242326 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292327}
2328
[email protected]4873c7d2009-07-16 06:36:282329void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132330 // Cancel pending translations so that the translate_helper_ does not attempt
2331 // to access the WebView.
2332 translate_helper_.CancelPendingTranslation();
2333
[email protected]e8345242010-05-06 03:00:402334 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282335 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312336}
2337
[email protected]4873c7d2009-07-16 06:36:282338void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292339 DCHECK(did_show_) << "should already have shown the view";
2340
[email protected]c1f50aa2010-02-18 03:46:572341 // We must keep WebKit's shared timer running in this case in order to allow
2342 // showModalDialog to function properly.
2343 //
2344 // TODO(darin): WebKit should really be smarter about suppressing events and
2345 // timers so that we do not need to manage the shared timer in such a heavy
2346 // handed manner.
2347 //
2348 if (RenderThread::current()) // Will be NULL during unit tests.
2349 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2350
[email protected]12636df2009-09-28 22:32:212351 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292352}
2353
[email protected]3d9689372009-09-10 04:29:172354// WebKit::WebFrameClient -----------------------------------------------------
2355
[email protected]00152e92010-07-19 11:47:402356WebPlugin* RenderView::createPlugin(WebFrame* frame,
2357 const WebPluginParams& params) {
[email protected]7a13e792010-08-03 08:18:242358 bool found = false;
[email protected]55126132010-08-19 14:53:282359 ContentSetting setting = CONTENT_SETTING_DEFAULT;
2360 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]7a13e792010-08-03 08:18:242361 WebPluginInfo info;
2362 GURL url(params.url);
[email protected]0cdafff2010-07-26 09:54:372363 std::string actual_mime_type;
[email protected]7a13e792010-08-03 08:18:242364 Send(new ViewHostMsg_GetPluginInfo(url,
2365 frame->top()->url(),
[email protected]aad51d1c2010-08-05 08:38:092366 params.mimeType.utf8(),
[email protected]7a13e792010-08-03 08:18:242367 &found,
2368 &info,
[email protected]55126132010-08-19 14:53:282369 &setting,
[email protected]aad51d1c2010-08-05 08:38:092370 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242371
[email protected]851b1eb2010-08-09 13:32:292372 if (!found)
[email protected]0cdafff2010-07-26 09:54:372373 return NULL;
[email protected]4e0616e2010-05-28 14:55:532374
[email protected]74b8d3e42010-09-21 15:00:342375 scoped_ptr<PluginGroup> group(PluginGroup::CopyOrCreatePluginGroup(info));
[email protected]851b1eb2010-08-09 13:32:292376 group->AddPlugin(info, 0);
2377
2378 if (!info.enabled) {
[email protected]55126132010-08-19 14:53:282379 if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) &&
[email protected]851b1eb2010-08-09 13:32:292380 group->IsVulnerable()) {
2381 Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_,
2382 group->GetGroupName(),
2383 GURL(group->GetUpdateURL())));
2384 return CreatePluginPlaceholder(frame, params, group.get());
2385 }
2386 return NULL;
2387 }
2388
[email protected]aad51d1c2010-08-05 08:38:092389 if (info.path.value() != kDefaultPluginLibraryName) {
[email protected]55126132010-08-19 14:53:282390 std::string resource;
[email protected]74b8d3e42010-09-21 15:00:342391 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2392 resource = group->identifier();
[email protected]55126132010-08-19 14:53:282393 if (setting == CONTENT_SETTING_BLOCK) {
[email protected]a16a4212010-09-01 08:07:462394 DCHECK(!cmd->HasSwitch(switches::kDisableClickToPlay));
[email protected]55126132010-08-19 14:53:282395 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]851b1eb2010-08-09 13:32:292396 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092397 }
2398 scoped_refptr<pepper::PluginModule> pepper_module =
2399 PepperPluginRegistry::GetInstance()->GetModule(info.path);
2400 if (pepper_module)
2401 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]5e45686b2010-08-30 17:05:342402 if (setting != CONTENT_SETTING_ALLOW) {
2403 // If the host is not whitelisted for this plugin, block it.
[email protected]851b1eb2010-08-09 13:32:292404 Send(new ViewHostMsg_NonSandboxedPluginBlocked(routing_id_,
[email protected]55126132010-08-19 14:53:282405 resource,
[email protected]851b1eb2010-08-09 13:32:292406 group->GetGroupName()));
2407 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092408 }
[email protected]0cdafff2010-07-26 09:54:372409 }
[email protected]aad51d1c2010-08-05 08:38:092410 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]3d9689372009-09-10 04:29:172411}
2412
2413WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562414 WebApplicationCacheHostImpl* appcache_host =
2415 WebApplicationCacheHostImpl::FromFrame(frame);
2416 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2417 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2418 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172419}
2420
[email protected]9c00f002009-11-05 22:37:422421WebSharedWorker* RenderView::createSharedWorker(
2422 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372423 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422424
[email protected]30447b62009-11-13 01:13:372425 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512426 bool exists = false;
[email protected]30447b62009-11-13 01:13:372427 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512428 ViewHostMsg_CreateWorker_Params params;
2429 params.url = url;
2430 params.is_shared = true;
2431 params.name = name;
2432 params.document_id = document_id;
2433 params.render_view_route_id = routing_id_;
2434 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232435 params.parent_appcache_host_id = 0;
2436 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372437 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512438 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372439 if (url_mismatch) {
2440 return NULL;
2441 } else {
2442 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492443 document_id,
[email protected]6de0bcf2010-02-17 22:00:512444 exists,
[email protected]30447b62009-11-13 01:13:372445 route_id,
2446 routing_id_);
2447 }
[email protected]9c00f002009-11-05 22:37:422448}
2449
[email protected]3d9689372009-09-10 04:29:172450WebMediaPlayer* RenderView::createMediaPlayer(
2451 WebFrame* frame, WebMediaPlayerClient* client) {
2452 scoped_refptr<media::FilterFactoryCollection> factory =
2453 new media::FilterFactoryCollection();
2454 // Add in any custom filter factories first.
2455 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2456 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2457 // Add the chrome specific audio renderer.
2458 factory->AddFactory(
2459 AudioRendererImpl::CreateFactory(audio_message_filter()));
2460 }
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;
[email protected]a58db8b2010-08-24 01:51:232590 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192591 OpenURL(url, referrer, default_policy);
2592 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172593 }
2594
2595 // A content initiated navigation may have originated from a link-click,
2596 // script, drag-n-drop operation, etc.
2597 bool is_content_initiated =
2598 NavigationState::FromDataSource(frame->provisionalDataSource())->
2599 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582600 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172601
2602 // We only care about navigations that are within the current tab (as opposed
2603 // to, for example, opening a new window).
2604 // But we sometimes navigate to about:blank to clear a tab, and we want to
2605 // still allow that.
2606 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2607 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532608 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172609 !url.SchemeIs(chrome::kAboutScheme)) {
2610 // When we received such unsolicited navigations, we sometimes want to
2611 // punt them up to the browser to handle.
[email protected]5351dbc2010-08-27 15:22:112612 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172613 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422614 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]5351dbc2010-08-27 15:22:112615 // We don't send referrer from these special pages.
[email protected]3d9689372009-09-10 04:29:172616 OpenURL(url, GURL(), default_policy);
2617 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2618 }
[email protected]8079b362010-05-07 18:37:452619
[email protected]5351dbc2010-08-27 15:22:112620 // We forward non-local navigations from extensions to the browser if they
2621 // are top-level events, even if the browser hasn't expressed interest.
[email protected]a6b960ad972010-09-01 19:53:582622 // TODO(erikkay) crbug.com/54118 - combine this clause and the next into
2623 // some shared logic.
[email protected]8079b362010-05-07 18:37:452624 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]a6b960ad972010-09-01 19:53:582625 old_url.SchemeIs(chrome::kExtensionScheme) &&
[email protected]c240ace2010-06-16 18:31:532626 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]5351dbc2010-08-27 15:22:112627 // We don't send referrer from extensions.
[email protected]8079b362010-05-07 18:37:452628 OpenURL(url, GURL(), default_policy);
2629 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2630 }
[email protected]5351dbc2010-08-27 15:22:112631
2632 // If the navigation would cross an app extent boundary, we also need
2633 // to defer to the browser to ensure process isolation.
2634 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2635 // which means that things like the back button won't trigger it. Is that
2636 // OK?
2637 if (CrossesExtensionExtents(frame, url)) {
2638 // Include the referrer in this case since we're going from a hosted web
2639 // page. (the packaged case is handled previously by the extension
2640 // navigation test)
2641 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2642 OpenURL(url, referrer, default_policy);
2643 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2644 }
[email protected]3d9689372009-09-10 04:29:172645 }
2646
2647 // Detect when a page is "forking" a new tab that can be safely rendered in
2648 // its own process. This is done by sites like Gmail that try to open links
2649 // in new windows without script connections back to the original page. We
2650 // treat such cases as browser navigations (in which we will create a new
2651 // renderer for a cross-site navigation), rather than WebKit navigations.
2652 //
2653 // We use the following heuristic to decide whether to fork a new page in its
2654 // own process:
2655 // The parent page must open a new tab to about:blank, set the new tab's
2656 // window.opener to null, and then redirect the tab to a cross-site URL using
2657 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462658 //
2659 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2660 // (see below).
[email protected]3d9689372009-09-10 04:29:172661 bool is_fork =
2662 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582663 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172664 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522665 historyBackListCount() < 1 &&
2666 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172667 // The parent page must have set the child's window.opener to null before
2668 // redirecting to the desired URL.
2669 frame->opener() == NULL &&
2670 // Must be a top-level frame.
2671 frame->parent() == NULL &&
2672 // Must not have issued the request from this page.
2673 is_content_initiated &&
2674 // Must be targeted at the current tab.
2675 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2676 // Must be a JavaScript navigation, which appears as "other".
2677 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462678
2679 // Recognize if this navigation is from a link with rel=noreferrer and
2680 // target=_blank attributes, in which case the opener will be suppressed. If
2681 // so, it is safe to load cross-site pages in a separate process, so we
2682 // should let the browser handle it.
2683 bool is_noreferrer_and_blank_target =
2684 // Frame should be top level and not yet navigated.
2685 frame->parent() == NULL &&
2686 frame->url().isEmpty() &&
2687 historyBackListCount() < 1 &&
2688 historyForwardListCount() < 1 &&
2689 // Links with rel=noreferrer will have no Referer field, and their
2690 // resulting frame will have its window.opener suppressed.
2691 // TODO(creis): should add a request.httpReferrer() method to help avoid
2692 // typos on the unusual spelling of Referer.
2693 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2694 opener_suppressed_ &&
2695 frame->opener() == NULL &&
2696 // Links with target=_blank will have no name.
2697 frame->name().isNull() &&
2698 // Another frame (with a non-empty creator) should have initiated the
2699 // request, targeted at this frame.
2700 !creator_url_.is_empty() &&
2701 is_content_initiated &&
2702 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2703 type == WebKit::WebNavigationTypeOther;
2704
2705 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172706 // Open the URL via the browser, not via WebKit.
2707 OpenURL(url, GURL(), default_policy);
2708 return WebKit::WebNavigationPolicyIgnore;
2709 }
2710
2711 return default_policy;
2712}
2713
[email protected]6069da8c2009-10-20 20:33:492714bool RenderView::canHandleRequest(
2715 WebFrame* frame, const WebURLRequest& request) {
2716 // We allow WebKit to think that everything can be handled even though
2717 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342718 return true;
2719}
2720
[email protected]6069da8c2009-10-20 20:33:492721WebURLError RenderView::cannotHandleRequestError(
2722 WebFrame* frame, const WebURLRequest& request) {
2723 NOTREACHED(); // Since we said we can handle all requests.
2724 return WebURLError();
2725}
2726
2727WebURLError RenderView::cancelledError(
2728 WebFrame* frame, const WebURLRequest& request) {
2729 WebURLError error;
2730 error.domain = WebString::fromUTF8(net::kErrorDomain);
2731 error.reason = net::ERR_ABORTED;
2732 error.unreachableURL = request.url();
2733 return error;
[email protected]7b7a7dc2009-10-19 02:23:342734}
2735
2736void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492737 WebFrame*, const WebURLError&) {
2738 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342739}
2740
[email protected]90eeddb2010-05-06 21:06:432741void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2742 const WebKit::WebFormElement& form) {
2743 // Some login forms have onSubmit handlers that put a hash of the password
2744 // into a hidden field and then clear the password. (Issue 28910.)
2745 // This method gets called before any of those handlers run, so save away
2746 // a copy of the password in case it gets lost.
2747 NavigationState* navigation_state =
2748 NavigationState::FromDataSource(frame->dataSource());
2749 navigation_state->set_password_form_data(
2750 PasswordFormDomManager::CreatePasswordForm(form));
2751}
2752
[email protected]979c28b2009-11-07 01:30:482753void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172754 NavigationState* navigation_state =
2755 NavigationState::FromDataSource(frame->provisionalDataSource());
2756
2757 if (navigation_state->transition_type() == PageTransition::LINK)
2758 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2759
2760 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352761 WebSearchableFormData web_searchable_form_data(form);
2762 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2763 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212764 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432765 PasswordForm* password_form_data =
2766 PasswordFormDomManager::CreatePasswordForm(form);
2767 navigation_state->set_password_form_data(password_form_data);
2768
2769 // If the password has been cleared, recover it from the form contents already
2770 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2771 // opposed to the provisionalDataSource's, which is what we're storing into
2772 // now.)
2773 if (password_form_data && password_form_data->password_value.empty()) {
2774 NavigationState* old_navigation_state =
2775 NavigationState::FromDataSource(frame->dataSource());
2776 if (old_navigation_state) {
2777 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2778 if (old_form_data && old_form_data->action == password_form_data->action)
2779 password_form_data->password_value = old_form_data->password_value;
2780 }
2781 }
[email protected]3d9689372009-09-10 04:29:172782
[email protected]b1438212010-04-03 00:30:592783 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042784 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092785 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592786 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172787}
2788
2789void RenderView::willPerformClientRedirect(
2790 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2791 double fire_time) {
2792 // Ignore
2793}
2794
2795void RenderView::didCancelClientRedirect(WebFrame* frame) {
2796 // Ignore
2797}
2798
2799void RenderView::didCompleteClientRedirect(
2800 WebFrame* frame, const WebURL& from) {
2801 if (!frame->parent())
2802 completed_client_redirect_src_ = from;
2803}
2804
2805void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2806 // The rest of RenderView assumes that a WebDataSource will always have a
2807 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482808 bool content_initiated = !pending_navigation_state_.get();
2809 NavigationState* state = content_initiated ?
2810 NavigationState::CreateContentInitiated() :
2811 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512812
[email protected]8a3125a712010-08-09 18:58:512813 // NavigationState::referred_by_prefetcher_ is true if we are
2814 // navigating from a page that used prefetching using a link on that
2815 // page. We are early enough in the request process here that we
2816 // can still see the NavigationState of the previous page and set
2817 // this value appropriately.
2818 // TODO(gavinp): catch the important case of navigation in a new
2819 // renderer process.
2820 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302821 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522822 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512823 const GURL referrer(
2824 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2825 if (!referrer.is_empty() &&
2826 NavigationState::FromDataSource(
2827 old_frame->dataSource())->was_prefetcher()) {
2828 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2829 WebDataSource* old_frame_ds = old_frame->dataSource();
2830 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2831 state->set_was_referred_by_prefetcher(true);
2832 break;
2833 }
2834 }
2835 }
2836 }
2837 }
2838
[email protected]4c1b6f0b2010-02-07 16:38:182839 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522840 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512841 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182842 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2843 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2844 break;
2845 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2846 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2847 break;
2848 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2849 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2850 break;
2851 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2852 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2853 break;
2854 }
2855 }
[email protected]fa7b6b542009-11-03 05:02:302856
2857 state->set_user_script_idle_scheduler(
2858 new UserScriptIdleScheduler(this, frame));
2859 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172860}
2861
2862void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2863 WebDataSource* ds = frame->provisionalDataSource();
2864 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2865
[email protected]3d9689372009-09-10 04:29:172866 // Update the request time if WebKit has better knowledge of it.
2867 if (navigation_state->request_time().is_null()) {
2868 double event_time = ds->triggeringEventTime();
2869 if (event_time != 0.0)
2870 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2871 }
2872
[email protected]05c8e502010-08-15 15:13:522873 // Start time is only set after request time.
2874 navigation_state->set_start_load_time(Time::Now());
2875
[email protected]3d9689372009-09-10 04:29:172876 bool is_top_most = !frame->parent();
2877 if (is_top_most) {
2878 navigation_gesture_ = frame->isProcessingUserGesture() ?
2879 NavigationGestureUnknown : NavigationGestureAuto;
2880
2881 // Make sure redirect tracking state is clear for the new load.
2882 completed_client_redirect_src_ = GURL();
2883 } else if (frame->parent()->isLoading()) {
2884 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002885 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172886 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2887 }
2888
2889 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2890 routing_id_, is_top_most, ds->request().url()));
2891}
2892
2893void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2894 if (frame->parent())
2895 return;
2896 // Received a redirect on the main frame.
2897 WebDataSource* data_source = frame->provisionalDataSource();
2898 if (!data_source) {
2899 // Should only be invoked when we have a data source.
2900 NOTREACHED();
2901 return;
2902 }
2903 std::vector<GURL> redirects;
2904 GetRedirectChain(data_source, &redirects);
2905 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512906 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2907 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172908 }
2909}
2910
[email protected]40bd6582009-12-04 23:49:512911void RenderView::didFailProvisionalLoad(WebFrame* frame,
2912 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172913 // Notify the browser that we failed a provisional load with an error.
2914 //
2915 // Note: It is important this notification occur before DidStopLoading so the
2916 // SSL manager can react to the provisional load failure before being
2917 // notified the load stopped.
2918 //
2919 WebDataSource* ds = frame->provisionalDataSource();
2920 DCHECK(ds);
2921
2922 const WebURLRequest& failed_request = ds->request();
2923
2924 bool show_repost_interstitial =
2925 (error.reason == net::ERR_CACHE_MISS &&
2926 EqualsASCII(failed_request.httpMethod(), "POST"));
2927 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2928 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2929 show_repost_interstitial));
2930
2931 // Don't display an error page if this is simply a cancelled load. Aside
2932 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2933 if (error.reason == net::ERR_ABORTED)
2934 return;
2935
2936 // Make sure we never show errors in view source mode.
2937 frame->enableViewSourceMode(false);
2938
2939 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2940
2941 // If this is a failed back/forward/reload navigation, then we need to do a
2942 // 'replace' load. This is necessary to avoid messing up session history.
2943 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2944 // as session history is concerned.
2945 //
2946 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2947 // the page id.
2948 //
2949 bool replace =
2950 navigation_state->pending_page_id() != -1 ||
2951 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2952
2953 // If we failed on a browser initiated request, then make sure that our error
2954 // page load is regarded as the same browser initiated request.
2955 if (!navigation_state->is_content_initiated()) {
2956 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2957 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002958 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172959 navigation_state->transition_type(),
2960 navigation_state->request_time()));
2961 }
2962
2963 // Provide the user with a more helpful error page?
2964 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2965 return;
2966
2967 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082968 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172969}
2970
2971void RenderView::didReceiveDocumentData(
2972 WebFrame* frame, const char* data, size_t data_len,
2973 bool& prevent_default) {
2974 NavigationState* navigation_state =
2975 NavigationState::FromDataSource(frame->dataSource());
2976 if (!navigation_state->postpone_loading_data())
2977 return;
2978
2979 // We're going to call commitDocumentData ourselves...
2980 prevent_default = true;
2981
[email protected]3f853a52010-09-13 19:15:082982 // Continue buffering the response data for the original error page. If it
2983 // grows too large, then we'll just let it through. For any error other than
2984 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:172985 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:082986 if (navigation_state->postponed_data().size() >= 512 ||
2987 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:172988 navigation_state->set_postpone_loading_data(false);
2989 frame->commitDocumentData(navigation_state->postponed_data().data(),
2990 navigation_state->postponed_data().size());
2991 navigation_state->clear_postponed_data();
2992 }
2993}
2994
[email protected]40bd6582009-12-04 23:49:512995void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2996 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172997 NavigationState* navigation_state =
2998 NavigationState::FromDataSource(frame->dataSource());
2999
3000 navigation_state->set_commit_load_time(Time::Now());
3001 if (is_new_navigation) {
3002 // When we perform a new navigation, we need to update the previous session
3003 // history entry with state for the page we are leaving.
3004 UpdateSessionHistory(frame);
3005
3006 // We bump our Page ID to correspond with the new session history entry.
3007 page_id_ = next_page_id_++;
3008
[email protected]d64b07b2010-04-20 22:14:063009 // Any pending translation is now obsolete.
3010 translate_helper_.CancelPendingTranslation();
3011
[email protected]3cc72b12010-03-18 23:03:003012 // Advance our offset in session history, applying the length limit. There
3013 // is now no forward history.
3014 history_list_offset_++;
3015 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3016 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3017 history_list_length_ = history_list_offset_ + 1;
3018
[email protected]f9f4841b2010-03-20 05:41:423019 MessageLoop::current()->PostDelayedTask(
3020 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303021 page_info_method_factory_.NewRunnableMethod(
3022 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173023 kDelayForForcedCaptureMs);
3024 } else {
3025 // Inspect the navigation_state on this frame to see if the navigation
3026 // corresponds to a session history navigation... Note: |frame| may or
3027 // may not be the toplevel frame, but for the case of capturing session
3028 // history, the first committed frame suffices. We keep track of whether
3029 // we've seen this commit before so that only capture session history once
3030 // per navigation.
3031 //
3032 // Note that we need to check if the page ID changed. In the case of a
3033 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3034 // previous URL and the current page ID, which would be wrong.
3035 if (navigation_state->pending_page_id() != -1 &&
3036 navigation_state->pending_page_id() != page_id_ &&
3037 !navigation_state->request_committed()) {
3038 // This is a successful session history navigation!
3039 UpdateSessionHistory(frame);
3040 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003041
3042 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173043 }
3044 }
3045
3046 // Remember that we've already processed this request, so we don't update
3047 // the session history again. We do this regardless of whether this is
3048 // a session history navigation, because if we attempted a session history
3049 // navigation without valid HistoryItem state, WebCore will think it is a
3050 // new navigation.
3051 navigation_state->set_request_committed(true);
3052
3053 UpdateURL(frame);
3054
3055 // If this committed load was initiated by a client redirect, we're
3056 // at the last stop now, so clear it.
3057 completed_client_redirect_src_ = GURL();
3058
3059 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273060 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173061}
3062
3063void RenderView::didClearWindowObject(WebFrame* frame) {
3064 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3065 BindDOMAutomationController(frame);
3066 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463067 GetDOMUIBindings()->set_message_sender(this);
3068 GetDOMUIBindings()->set_routing_id(routing_id_);
3069 GetDOMUIBindings()->BindToJavascript(frame, L"chrome");
[email protected]3d9689372009-09-10 04:29:173070 }
3071 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463072 GetExternalHostBindings()->set_message_sender(this);
3073 GetExternalHostBindings()->set_routing_id(routing_id_);
3074 GetExternalHostBindings()->BindToJavascript(frame, L"externalHost");
[email protected]3d9689372009-09-10 04:29:173075 }
3076}
3077
3078void RenderView::didCreateDocumentElement(WebFrame* frame) {
3079 if (RenderThread::current()) { // Will be NULL during unit tests.
3080 RenderThread::current()->user_script_slave()->InjectScripts(
3081 frame, UserScript::DOCUMENT_START);
3082 }
3083
3084 // Notify the browser about non-blank documents loading in the top frame.
3085 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253086 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273087 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173088 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3089 }
3090}
3091
3092void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3093 UpdateTitle(frame, title);
3094
3095 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273096 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173097}
3098
[email protected]5019ef12010-04-27 17:26:583099void RenderView::didChangeIcons(WebFrame* frame) {
3100 if (!frame->parent()) {
3101 Send(new ViewHostMsg_UpdateFavIconURL(
3102 routing_id_,
3103 page_id_,
3104 frame->favIconURL()));
3105 }
3106}
3107
[email protected]3d9689372009-09-10 04:29:173108void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3109 WebDataSource* ds = frame->dataSource();
3110 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3111 DCHECK(navigation_state);
3112 navigation_state->set_finish_document_load_time(Time::Now());
3113
3114 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
3115
[email protected]6a8ddba52010-09-05 04:38:063116 page_click_tracker_->StartTrackingFrame(frame);
[email protected]e9e07992010-02-17 21:04:363117 // The document has now been fully loaded. Scan for forms to be sent up to
3118 // the browser.
[email protected]6a8ddba52010-09-05 04:38:063119 autofill_helper_->FrameContentsAvailable(frame);
3120 password_autocomplete_manager_->SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:173121
3122 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273123 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173124
3125 if (RenderThread::current()) { // Will be NULL during unit tests.
3126 RenderThread::current()->user_script_slave()->InjectScripts(
3127 frame, UserScript::DOCUMENT_END);
3128 }
[email protected]fa7b6b542009-11-03 05:02:303129
3130 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3131}
3132
3133void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3134 if (RenderThread::current()) { // Will be NULL during unit tests.
3135 RenderThread::current()->user_script_slave()->InjectScripts(
3136 frame, UserScript::DOCUMENT_IDLE);
3137 }
3138
3139 WebFrame* main_frame = webview()->mainFrame();
3140 if (frame == main_frame) {
3141 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203142 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303143 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203144 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303145 pending_code_execution_queue_.pop();
3146 }
3147 }
[email protected]3d9689372009-09-10 04:29:173148}
3149
3150void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083151 if (webview()->mainFrame() == frame) {
3152 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3153 page_id_));
3154 }
[email protected]3d9689372009-09-10 04:29:173155}
3156
3157void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3158 // Ignore
3159}
3160
3161void RenderView::didFinishLoad(WebFrame* frame) {
3162 WebDataSource* ds = frame->dataSource();
3163 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3164 DCHECK(navigation_state);
3165 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303166 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413167
3168 // Let the password manager know which password forms are actually visible.
[email protected]6a8ddba52010-09-05 04:38:063169 password_autocomplete_manager_->SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:173170}
3171
[email protected]ccbe04e2010-03-17 17:58:433172void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173173 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063174 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3175 // since a new one gets created by didCreateDataSource.
[email protected]af15bed2010-08-25 21:12:093176 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
[email protected]f6c2459d2010-02-24 22:34:063177 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3178
[email protected]3d9689372009-09-10 04:29:173179 // If this was a reference fragment navigation that we initiated, then we
3180 // could end up having a non-null pending navigation state. We just need to
3181 // update the ExtraData on the datasource so that others who read the
3182 // ExtraData will get the new NavigationState. Similarly, if we did not
3183 // initiate this navigation, then we need to take care to reset any pre-
3184 // existing navigation state to a content-initiated navigation state.
3185 // DidCreateDataSource conveniently takes care of this for us.
3186 didCreateDataSource(frame, frame->dataSource());
3187
[email protected]af15bed2010-08-25 21:12:093188 NavigationState* new_state =
3189 NavigationState::FromDataSource(frame->dataSource());
3190 new_state->set_was_within_same_page(true);
3191
[email protected]f6c2459d2010-02-24 22:34:063192 if (idle_scheduler_ran) {
3193 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
[email protected]f6c2459d2010-02-24 22:34:063194 new_state->user_script_idle_scheduler()->set_has_run(true);
3195 }
3196
[email protected]3d9689372009-09-10 04:29:173197 didCommitProvisionalLoad(frame, is_new_navigation);
3198
[email protected]26aa0482009-09-30 16:55:273199 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173200}
3201
[email protected]476b6f82009-09-10 21:00:593202void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313203 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593204}
3205
[email protected]3d9689372009-09-10 04:29:173206void RenderView::assignIdentifierToRequest(
3207 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3208 // Ignore
3209}
3210
3211void RenderView::willSendRequest(
3212 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3213 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303214 WebFrame* top_frame = frame->top();
3215 if (!top_frame)
3216 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513217 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3218 WebDataSource* top_data_source = top_frame->dataSource();
3219 WebDataSource* data_source =
3220 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303221 if (data_source) {
3222 NavigationState* state = NavigationState::FromDataSource(data_source);
3223 if (state && state->is_cache_policy_override_set())
3224 request.setCachePolicy(state->cache_policy_override());
3225 }
[email protected]8a3125a712010-08-09 18:58:513226
3227 if (top_data_source) {
3228 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3229 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3230 state->set_was_prefetcher(true);
3231 }
3232
[email protected]3d9689372009-09-10 04:29:173233 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503234 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133235 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493236
[email protected]85cc78c2010-05-04 18:30:093237 // Temporary metrics, see site_isolation_metrics.h
3238 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173239}
3240
3241void RenderView::didReceiveResponse(
3242 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493243
[email protected]85cc78c2010-05-04 18:30:093244 // Temporary metrics, see site_isolation_metrics.h
3245 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3246 identifier,
3247 response);
[email protected]fa0a3432010-03-30 16:53:493248
[email protected]3d9689372009-09-10 04:29:173249 // Only do this for responses that correspond to a provisional data source
3250 // of the top-most frame. If we have a provisional data source, then we
3251 // can't have any sub-resources yet, so we know that this response must
3252 // correspond to a frame load.
3253 if (!frame->provisionalDataSource() || frame->parent())
3254 return;
3255
3256 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083257 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173258 if (frame->isViewSourceModeEnabled())
3259 return;
3260
[email protected]65041fa2010-05-21 06:56:533261 NavigationState* navigation_state =
3262 NavigationState::FromDataSource(frame->provisionalDataSource());
3263 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083264 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533265
[email protected]972ebdff2010-06-10 22:59:073266 // Record page load flags.
3267 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3268 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573269 navigation_state->set_was_alternate_protocol_available(
3270 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073271 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083272 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533273
[email protected]f48013be2010-01-14 22:07:453274 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083275 if (http_status_code == 404) {
3276 // Can we even load an alternate error page for this URL?
3277 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3278 return;
3279 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3280 http_status_code)) {
3281 // If no corresponding error strings for a particular status code, just
3282 // render any received data, regardless of whether or not the status code
3283 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453284 return;
[email protected]3f853a52010-09-13 19:15:083285 }
[email protected]3d9689372009-09-10 04:29:173286
[email protected]3d9689372009-09-10 04:29:173287 navigation_state->set_postpone_loading_data(true);
3288 navigation_state->clear_postponed_data();
3289}
3290
3291void RenderView::didFinishResourceLoad(
3292 WebFrame* frame, unsigned identifier) {
3293 NavigationState* navigation_state =
3294 NavigationState::FromDataSource(frame->dataSource());
3295 if (!navigation_state->postpone_loading_data())
3296 return;
3297
[email protected]3f853a52010-09-13 19:15:083298 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173299 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083300 int http_status_code = navigation_state->http_status_code();
3301 if (http_status_code == 404) {
3302 // On 404s, try a remote search page as a fallback.
3303 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173304
[email protected]3f853a52010-09-13 19:15:083305 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3306 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173307
[email protected]3f853a52010-09-13 19:15:083308 WebURLError original_error;
3309 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173310
[email protected]3f853a52010-09-13 19:15:083311 navigation_state->set_alt_error_page_fetcher(
3312 new AltErrorPageResourceFetcher(
3313 error_page_url, frame, original_error,
3314 NewCallback(this, &RenderView::AltErrorPageFinished)));
3315 } else {
3316 // On other errors, use an internal error page.
3317 WebURLError error;
3318 error.unreachableURL = frame->url();
3319 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3320 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173321
[email protected]3f853a52010-09-13 19:15:083322 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3323 std::string(), true);
3324 }
[email protected]3d9689372009-09-10 04:29:173325}
3326
3327void RenderView::didFailResourceLoad(
3328 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3329 // Ignore
3330}
3331
3332void RenderView::didLoadResourceFromMemoryCache(
3333 WebFrame* frame, const WebURLRequest& request,
3334 const WebURLResponse& response) {
3335 // Let the browser know we loaded a resource from the memory cache. This
3336 // message is needed to display the correct SSL indicators.
3337 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3338 routing_id_,
3339 request.url(),
[email protected]91733b62009-09-18 06:21:093340 frame->securityOrigin().toString().utf8(),
3341 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173342 response.securityInfo()));
3343}
3344
[email protected]6069da8c2009-10-20 20:33:493345void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293346 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3347}
3348
3349void RenderView::didRunInsecureContent(
3350 WebFrame* frame, const WebSecurityOrigin& origin) {
3351 Send(new ViewHostMsg_DidRunInsecureContent(
3352 routing_id_,
3353 origin.toString().utf8()));
3354}
3355
[email protected]7ea093ba2009-11-03 05:54:593356bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403357 if (enabled_per_settings &&
3358 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3359 return true;
[email protected]7ea093ba2009-11-03 05:54:593360
[email protected]12bc8472010-04-15 07:29:403361 if (IsWhitelistedForContentSettings(frame))
3362 return true;
[email protected]7ea093ba2009-11-03 05:54:593363
3364 return false; // Other protocols fall through here.
3365}
3366
[email protected]0a1a45432010-03-31 08:09:453367bool RenderView::allowDatabase(
3368 WebFrame* frame, const WebString& name, const WebString& display_name,
3369 unsigned long estimated_size) {
3370 WebSecurityOrigin origin = frame->securityOrigin();
3371 if (origin.isEmpty())
3372 return false; // Uninitialized document?
3373
3374 bool result;
3375 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3376 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3377 return false;
[email protected]9fb83e82010-07-02 18:24:553378 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3379 GURL(origin.toString().utf8()),
3380 name,
3381 display_name,
3382 estimated_size,
3383 !result));
[email protected]0a1a45432010-03-31 08:09:453384 return result;
3385}
[email protected]8934a3b2010-02-25 00:34:003386void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283387 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003388}
3389
[email protected]c21f1d52010-03-04 03:19:433390void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283391 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433392}
3393
[email protected]3d9689372009-09-10 04:29:173394void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3395 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3396}
3397
[email protected]0c882b282009-10-07 17:01:283398void RenderView::didCreateScriptContext(WebFrame* frame) {
3399 EventBindings::HandleContextCreated(frame, false);
3400}
3401
3402void RenderView::didDestroyScriptContext(WebFrame* frame) {
3403 EventBindings::HandleContextDestroyed(frame);
3404}
3405
3406void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3407 EventBindings::HandleContextCreated(frame, true);
3408}
3409
[email protected]af7eb3fb2010-09-23 21:31:063410bool RenderView::allowScriptExtension(WebFrame* frame,
3411 const WebString& extension_name,
3412 int extension_group) {
3413 // NULL in unit tests.
3414 if (!RenderThread::current())
3415 return true;
3416
3417 // Note: we prefer the provisional URL here instead of the document URL
3418 // because we might be currently loading an URL into a blank page.
3419 // See http://code.google.com/p/chromium/issues/detail?id=10924
3420 WebDataSource* ds = frame->provisionalDataSource();
3421 if (!ds)
3422 ds = frame->dataSource();
3423 return RenderThread::current()->AllowScriptExtension(
3424 extension_name.utf8(), ds->request().url(), extension_group);
3425}
3426
[email protected]fc86daa2010-03-30 23:52:533427void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3428 WebFrame* target,
3429 bool cross_origin,
3430 const WebString& property_name,
3431 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103432 // TODO(johnnyg): track the individual properties and repeat event_ids.
3433 if (cross_origin)
3434 cross_origin_access_count_++;
3435 else
3436 same_origin_access_count_++;
3437}
3438
[email protected]3d9689372009-09-10 04:29:173439void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143440 CheckPreferredSize();
3441}
3442
3443void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173444 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253445 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173446 // message.
[email protected]705243f2010-05-05 19:58:073447 if (!send_preferred_size_changes_ || !webview())
3448 return;
[email protected]dfca5acf2010-03-22 03:28:433449
[email protected]705243f2010-05-05 19:58:073450 // WebCore likes to tell us things have changed even when they haven't, so
3451 // cache the width and height and only send the IPC message when we're sure
3452 // they're different.
3453 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3454 webview()->mainFrame()->documentElementScrollHeight());
3455 if (size == preferred_size_)
3456 return;
[email protected]c27324b2009-11-19 22:44:293457
[email protected]705243f2010-05-05 19:58:073458 preferred_size_ = size;
3459 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3460 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173461}
3462
[email protected]143dcd592009-11-06 21:33:493463void RenderView::didChangeScrollOffset(WebFrame* frame) {
3464 StartNavStateSyncTimerIfNecessary();
3465}
3466
[email protected]8922e1f2009-10-03 05:01:263467void RenderView::reportFindInPageMatchCount(int request_id, int count,
3468 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113469 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3470 if (!count)
3471 active_match_ordinal = 0;
3472
3473 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3474 routing_id_,
3475 request_id,
3476 count,
3477 gfx::Rect(),
3478 active_match_ordinal,
3479 final_update);
3480
[email protected]8922e1f2009-10-03 05:01:263481 // If we have a message that has been queued up, then we should just replace
3482 // it. The ACK from the browser will make sure it gets sent when the browser
3483 // wants it.
3484 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263485 queued_find_reply_message_.reset(msg);
3486 } else {
3487 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113488 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263489 }
3490}
3491
3492void RenderView::reportFindInPageSelection(int request_id,
3493 int active_match_ordinal,
3494 const WebRect& selection_rect) {
3495 // Send the search result over to the browser process.
3496 Send(new ViewHostMsg_Find_Reply(routing_id_,
3497 request_id,
3498 -1,
3499 selection_rect,
3500 active_match_ordinal,
3501 false));
3502}
3503
[email protected]2b06a992010-08-21 05:48:223504void RenderView::openFileSystem(
3505 WebFrame* frame,
3506 WebFileSystem::Type type,
3507 long long size,
3508 WebFileSystemCallbacks* callbacks) {
3509 scoped_ptr<PendingOpenFileSystem> request(
3510 new PendingOpenFileSystem(callbacks));
3511
3512 WebSecurityOrigin origin = frame->securityOrigin();
3513 if (origin.isEmpty())
3514 return; // Uninitialized document?
3515
3516 ViewHostMsg_OpenFileSystemRequest_Params params;
3517 params.routing_id = routing_id_;
3518 params.request_id = pending_file_system_requests_.Add(request.release());
3519 params.origin_url = GURL(origin.toString());
3520 params.type = type;
3521 params.requested_size = size;
3522
3523 Send(new ViewHostMsg_OpenFileSystemRequest(params));
3524}
3525
[email protected]79dbc662009-09-04 05:42:513526// webkit_glue::WebPluginPageDelegate -----------------------------------------
3527
[email protected]f103ab72009-09-02 17:10:593528webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533529 const FilePath& file_path,
3530 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593531 if (!PluginChannelHost::IsListening())
3532 return NULL;
3533
[email protected]d2139662009-12-10 03:21:143534 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283535 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143536 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163537 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533538 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143539 if (CommandLine::ForCurrentProcess()->
3540 HasSwitch(switches::kInternalPepper)) {
3541 in_process_plugin = true;
3542 use_pepper_host = true;
3543 } else {
3544 // In process Pepper plugins must be explicitly enabled.
3545 return NULL;
3546 }
[email protected]4e0616e2010-05-28 14:55:533547 } else {
3548 FilePath internal_pdf_path;
3549 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3550 if (file_path == internal_pdf_path) {
3551 in_process_plugin = true;
3552 use_pepper_host = true;
3553 }
[email protected]26e8d5e2009-10-13 02:47:163554 }
[email protected]4e0616e2010-05-28 14:55:533555
[email protected]d2139662009-12-10 03:21:143556 // Check for Native Client modules.
[email protected]5cad70a82010-09-03 22:14:113557 if (mime_type == "application/x-nacl-srpc" &&
3558 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
[email protected]8f05f7f2010-07-30 23:12:433559 // NaCl is only permitted when we're in an extension/application with the
3560 // appropriate permission, or when explicitly enabled on the command line.
3561
[email protected]8f05f7f2010-07-30 23:12:433562 GURL main_frame_url(webview()->mainFrame()->url());
[email protected]5351dbc2010-08-27 15:22:113563 ExtensionRendererInfo* extension =
3564 ExtensionRendererInfo::GetByURL(main_frame_url);
3565 bool in_ext = extension != NULL;
[email protected]8f05f7f2010-07-30 23:12:433566 bool explicit_enable =
3567 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3568
3569 if (in_ext) {
[email protected]5cad70a82010-09-03 22:14:113570 // TODO(cbiffle): NaCl is back to experimental for M7.
[email protected]5351dbc2010-08-27 15:22:113571 if (ExtensionProcessBindings::HasPermission(extension->id(),
[email protected]5cad70a82010-09-03 22:14:113572 Extension::kExperimentalPermission)) {
[email protected]8f05f7f2010-07-30 23:12:433573 in_process_plugin = true;
3574 use_pepper_host = true;
3575 } else {
3576 // Disable NaCl for apps lacking the permission, even with the flag.
3577 return NULL;
3578 }
3579 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463580 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143581 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463582 }
3583 }
[email protected]4e0616e2010-05-28 14:55:533584
[email protected]d032f492009-09-29 00:33:463585 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143586 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283587 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533588 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333589 if (!pepper_plugin)
3590 return NULL;
3591
[email protected]53900d52010-06-16 04:25:013592 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283593 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143594 } else {
[email protected]6876dff2010-01-15 19:38:093595#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143596 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533597 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093598#else
[email protected]596b2c42010-01-14 20:40:433599 NOTIMPLEMENTED();
3600 return NULL;
[email protected]7b6616f2010-01-14 18:07:553601#endif
[email protected]6876dff2010-01-15 19:38:093602 }
[email protected]f103ab72009-09-02 17:10:593603 }
3604
[email protected]4e0616e2010-05-28 14:55:533605 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593606}
3607
3608void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033609#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593610 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3611 routing_id(), window));
3612#endif
3613}
3614
3615void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033616#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593617 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3618 routing_id(), window));
3619#endif
3620 CleanupWindowInPluginMoves(window);
3621}
3622
3623void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3624 SchedulePluginMove(move);
3625}
3626
3627void RenderView::DidStartLoadingForPlugin() {
3628 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523629 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593630}
3631
3632void RenderView::DidStopLoadingForPlugin() {
3633 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523634 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593635}
3636
3637void RenderView::ShowModalHTMLDialogForPlugin(
3638 const GURL& url,
3639 const gfx::Size& size,
3640 const std::string& json_arguments,
3641 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213642 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593643 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213644 json_retval));
[email protected]f103ab72009-09-02 17:10:593645}
3646
[email protected]b921cfd22010-02-25 16:57:513647WebCookieJar* RenderView::GetCookieJar() {
3648 return &cookie_jar_;
3649}
3650
initial.commit09911bf2008-07-26 23:55:293651void RenderView::SyncNavigationState() {
3652 if (!webview())
3653 return;
3654
[email protected]26aa0482009-09-30 16:55:273655 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173656 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293657 return;
[email protected]ca948a22009-06-25 19:36:173658
3659 Send(new ViewHostMsg_UpdateState(
3660 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293661}
3662
[email protected]b0950a72009-09-29 23:16:173663bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3664 // Make sure webview was not shut down.
3665 if (!webview())
3666 return false;
3667 // Create an image resource fetcher and assign it with a call back object.
3668 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273669 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173670 NewCallback(this, &RenderView::DidDownloadImage)));
3671 return true;
3672}
3673
3674void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293675 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173676 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473677 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3678 fetcher->id(),
3679 fetcher->image_url(),
3680 image.isNull(),
3681 image));
[email protected]b0950a72009-09-29 23:16:173682 // Dispose of the image fetcher.
3683 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3684 image_fetchers_.erase(fetcher);
3685 // We're in the callback from the ImageResourceFetcher, best to delay
3686 // deletion.
3687 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293688}
3689
[email protected]bf5c2ff392009-07-08 16:24:333690void RenderView::OnDownloadFavIcon(int id,
3691 const GURL& image_url,
3692 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343693 bool data_image_failed = false;
3694 if (image_url.SchemeIs("data")) {
3695 SkBitmap data_image = ImageFromDataUrl(image_url);
3696 data_image_failed = data_image.empty();
3697 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333698 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3699 data_image));
[email protected]f11ca0732009-04-11 00:09:343700 }
3701 }
3702
[email protected]bf5c2ff392009-07-08 16:24:333703 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173704 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333705 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3706 SkBitmap()));
3707 }
initial.commit09911bf2008-07-26 23:55:293708}
3709
[email protected]f11ca0732009-04-11 00:09:343710SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3711 std::string mime_type, char_set, data;
3712 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3713 // Decode the favicon using WebKit's image decoder.
3714 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3715 const unsigned char* src_data =
3716 reinterpret_cast<const unsigned char*>(&data[0]);
3717
3718 return decoder.Decode(src_data, data.size());
3719 }
3720 return SkBitmap();
3721}
3722
initial.commit09911bf2008-07-26 23:55:293723void RenderView::OnGetApplicationInfo(int page_id) {
3724 webkit_glue::WebApplicationInfo app_info;
3725 if (page_id == page_id_)
3726 webkit_glue::GetApplicationInfo(webview(), &app_info);
3727
3728 // Prune out any data URLs in the set of icons. The browser process expects
3729 // any icon with a data URL to have originated from a favicon. We don't want
3730 // to decode arbitrary data URLs in the browser process. See
3731 // http://b/issue?id=1162972
3732 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593733 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293734 app_info.icons.erase(app_info.icons.begin() + i);
3735 --i;
3736 }
3737 }
3738
3739 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3740}
3741
[email protected]7ccddb8c2009-08-04 17:36:553742GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293743 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553744 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293745 // If the URL that failed was secure, then the embedding web page was not
3746 // expecting a network attacker to be able to manipulate its contents. As
3747 // we fetch alternate error pages over HTTP, we would be allowing a network
3748 // attacker to manipulate the contents of the response if we tried to use
3749 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153750 return GURL();
initial.commit09911bf2008-07-26 23:55:293751 }
3752
3753 // Grab the base URL from the browser process.
3754 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153755 return GURL();
initial.commit09911bf2008-07-26 23:55:293756
3757 // Strip query params from the failed URL.
3758 GURL::Replacements remove_params;
3759 remove_params.ClearUsername();
3760 remove_params.ClearPassword();
3761 remove_params.ClearQuery();
3762 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553763 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503764 std::string spec_to_send = url_to_send.spec();
3765 // Notify link doctor of the url truncation by sending of "?" at the end.
3766 if (failed_url.has_query())
3767 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293768
3769 // Construct the query params to send to link doctor.
3770 std::string params(alternate_error_page_url_.query());
3771 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503772 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293773 params.append("&sourceid=chrome");
3774 params.append("&error=");
3775 switch (error_type) {
3776 case DNS_ERROR:
3777 params.append("dnserror");
3778 break;
3779
3780 case HTTP_404:
3781 params.append("http404");
3782 break;
3783
[email protected]5df266ac2008-10-15 19:50:133784 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333785 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133786 break;
3787
initial.commit09911bf2008-07-26 23:55:293788 default:
3789 NOTREACHED() << "unknown ErrorPageType";
3790 }
3791
3792 // OK, build the final url to return.
3793 GURL::Replacements link_doctor_params;
3794 link_doctor_params.SetQueryStr(params);
3795 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3796 return url;
3797}
3798
[email protected]c091c2c2010-09-17 19:05:463799DOMUIBindings* RenderView::GetDOMUIBindings() {
3800 if (!dom_ui_bindings_.get()) {
3801 dom_ui_bindings_.reset(new DOMUIBindings());
3802 }
3803 return dom_ui_bindings_.get();
3804}
3805
3806ExternalHostBindings* RenderView::GetExternalHostBindings() {
3807 if (!external_host_bindings_.get()) {
3808 external_host_bindings_.reset(new ExternalHostBindings());
3809 }
3810 return external_host_bindings_.get();
3811}
3812
[email protected]0fdbf8c2010-07-08 20:33:013813WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3814 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493815}
3816
[email protected]6069da8c2009-10-20 20:33:493817void RenderView::OnFind(int request_id, const string16& search_text,
3818 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273819 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493820
3821 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493822 if (options.findNext) {
3823 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013824 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493825 } else {
[email protected]afdbd142010-07-10 08:01:233826 if (GetWebPluginFromPluginDocument()->startFind(
3827 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493828 } else {
[email protected]e7c58a32010-08-13 19:47:113829 // Send "no results".
3830 Send(new ViewHostMsg_Find_Reply(routing_id_,
3831 request_id,
3832 0,
3833 gfx::Rect(),
3834 0,
3835 true));
[email protected]24a7f3c2010-03-25 08:26:493836 }
3837 }
3838 return;
3839 }
3840
[email protected]b4bb2502009-10-01 22:35:273841 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273842 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293843 WebFrame* search_frame = focused_frame; // start searching focused frame.
3844
3845 bool multi_frame = (frame_after_main != main_frame);
3846
3847 // If we have multiple frames, we don't want to wrap the search within the
3848 // frame, so we check here if we only have main_frame in the chain.
3849 bool wrap_within_frame = !multi_frame;
3850
[email protected]b3f2b912009-04-09 16:18:523851 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293852 bool result = false;
3853
[email protected]7830da3e2009-11-06 16:27:263854 // If something is selected when we start searching it means we cannot just
3855 // increment the current match ordinal; we need to re-generate it.
3856 WebRange current_selection = focused_frame->selectionRange();
3857
initial.commit09911bf2008-07-26 23:55:293858 do {
[email protected]dd7daa82009-08-10 05:46:453859 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593860 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293861
3862 if (!result) {
3863 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223864 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293865
3866 // Find the next frame, but skip the invisible ones.
3867 do {
3868 // What is the next frame to search? (we might be going backwards). Note
3869 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593870 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273871 search_frame->traverseNext(true) :
3872 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453873 } while (!search_frame->hasVisibleContent() &&
3874 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293875
[email protected]884db412008-11-24 23:46:503876 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223877 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293878
3879 // If we have multiple frames and we have wrapped back around to the
3880 // focused frame, we need to search it once more allowing wrap within
3881 // the frame, otherwise it will report 'no match' if the focused frame has
3882 // reported matches, but no frames after the focused_frame contain a
3883 // match for the search word(s).
3884 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453885 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593886 request_id, search_text, options, true, // Force wrapping.
3887 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293888 }
3889 }
3890
[email protected]26aa0482009-09-30 16:55:273891 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293892 } while (!result && search_frame != focused_frame);
3893
[email protected]7830da3e2009-11-06 16:27:263894 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293895 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453896 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293897 } else {
3898 // If nothing is found, set result to "0 of 0", otherwise, set it to
3899 // "-1 of 1" to indicate that we found at least one item, but we don't know
3900 // yet what is active.
3901 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3902 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293903
[email protected]4f3dc372009-02-24 00:10:293904 // If we find no matches then this will be our last status update.
3905 // Otherwise the scoping effort will send more results.
3906 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293907
[email protected]4f3dc372009-02-24 00:10:293908 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403909 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593910 request_id,
[email protected]4f3dc372009-02-24 00:10:293911 match_count,
3912 selection_rect,
3913 ordinal,
3914 final_status_update));
initial.commit09911bf2008-07-26 23:55:293915
initial.commit09911bf2008-07-26 23:55:293916 // Scoping effort begins, starting with the mainframe.
3917 search_frame = main_frame;
3918
[email protected]dd7daa82009-08-10 05:46:453919 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293920
3921 do {
3922 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453923 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293924
3925 // We don't start another scoping effort unless at least one match has
3926 // been found.
3927 if (result) {
3928 // Start new scoping request. If the scoping function determines that it
3929 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453930 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593931 search_text,
3932 options,
initial.commit09911bf2008-07-26 23:55:293933 true); // reset the tickmarks
3934 }
3935
3936 // Iterate to the next frame. The frame will not necessarily scope, for
3937 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273938 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293939 } while (search_frame != main_frame);
3940 }
3941}
3942
[email protected]24a7f3c2010-03-25 08:26:493943void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3944 WebView* view = webview();
3945 if (!view)
3946 return;
3947
3948 WebDocument doc = view->mainFrame()->document();
3949 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013950 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493951 return;
3952 }
3953
3954 bool clear_selection =
3955 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3956 if (clear_selection)
3957 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3958
3959 WebFrame* frame = view->mainFrame();
3960 while (frame) {
3961 frame->stopFinding(clear_selection);
3962 frame = frame->traverseNext(false);
3963 }
3964
3965 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3966 WebFrame* focused_frame = view->focusedFrame();
3967 if (focused_frame) {
3968 WebDocument doc = focused_frame->document();
3969 if (!doc.isNull()) {
3970 WebNode node = doc.focusedNode();
3971 if (!node.isNull())
3972 node.simulateClick();
3973 }
3974 }
3975 }
3976}
3977
3978void RenderView::OnFindReplyAck() {
3979 // Check if there is any queued up request waiting to be sent.
3980 if (queued_find_reply_message_.get()) {
3981 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423982 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493983 }
3984}
3985
[email protected]8934a3b2010-02-25 00:34:003986bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353987 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003988 return current_content_settings_.settings[settings_type] !=
3989 CONTENT_SETTING_BLOCK;
3990}
3991
[email protected]55126132010-08-19 14:53:283992void RenderView::DidBlockContentType(ContentSettingsType settings_type,
3993 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:003994 if (!content_blocked_[settings_type]) {
3995 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:283996 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
3997 resource_identifier));
[email protected]0de80162010-02-03 04:52:353998 }
[email protected]0de80162010-02-03 04:52:353999}
4000
[email protected]71b0d5d2010-02-15 05:43:074001void RenderView::ClearBlockedContentSettings() {
4002 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4003 content_blocked_[i] = false;
4004}
4005
[email protected]aad51d1c2010-08-05 08:38:094006WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame,
4007 const WebPluginParams& params,
4008 const FilePath& path,
4009 pepper::PluginModule* pepper_module) {
4010 WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params,
4011 pepper_delegate_.AsWeakPtr());
4012 if (plugin && !frame->parent() && frame->document().isPluginDocument()) {
4013 // If this is a full-page plugin hosting the internal PDF plugin, we want
4014 // to notify the browser so that it can treat things like zooming
4015 // differently.
4016 // TODO(sanjeevr): Use a Pepper interface to determine this rather than
4017 // hardcode this for the PDF plugin path.
4018 FilePath pdf_path;
4019 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
4020 if (path == pdf_path)
4021 Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_));
[email protected]0cdafff2010-07-26 09:54:374022 }
[email protected]aad51d1c2010-08-05 08:38:094023 return plugin;
4024}
[email protected]00152e92010-07-19 11:47:404025
[email protected]aad51d1c2010-08-05 08:38:094026WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame,
4027 const WebPluginParams& params,
4028 const FilePath& path,
4029 const std::string& mime_type) {
4030 std::string actual_mime_type(mime_type);
[email protected]00152e92010-07-19 11:47:404031 if (actual_mime_type.empty())
4032 actual_mime_type = params.mimeType.utf8();
4033
[email protected]aad51d1c2010-08-05 08:38:094034 return new webkit_glue::WebPluginImpl(frame, params, path,
[email protected]7a13e792010-08-03 08:18:244035 actual_mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404036}
4037
4038WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame,
[email protected]851b1eb2010-08-09 13:32:294039 const WebPluginParams& params,
4040 PluginGroup* group) {
[email protected]00152e92010-07-19 11:47:404041 // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed.
[email protected]851b1eb2010-08-09 13:32:294042 BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params, group);
[email protected]00152e92010-07-19 11:47:404043 WebViewPlugin* plugin = blocked_plugin->plugin();
[email protected]851b1eb2010-08-09 13:32:294044 WebView* web_view = plugin->web_view();
4045 webkit_preferences_.Apply(web_view);
[email protected]00152e92010-07-19 11:47:404046 return plugin;
4047}
4048
[email protected]40bd6582009-12-04 23:49:514049void RenderView::OnZoom(PageZoom::Function function) {
4050 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4051 return;
4052
[email protected]258d31122010-05-09 10:59:414053 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524054
[email protected]40bd6582009-12-04 23:49:514055 int zoom_level = webview()->zoomLevel();
4056 int new_zoom_level = webview()->setZoomLevel(false,
4057 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
4058
[email protected]9d797f32010-04-23 07:17:544059 // Tell the browser which url got zoomed so it can update the saved values.
4060 Send(new ViewHostMsg_DidZoomURL(
4061 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:514062}
4063
[email protected]9d797f32010-04-23 07:17:544064void RenderView::OnSetContentSettingsForLoadingURL(
4065 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014066 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544067 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014068}
4069
[email protected]9d797f32010-04-23 07:17:544070void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
4071 int zoom_level) {
4072 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294073}
4074
[email protected]41fc0322009-09-04 22:23:404075void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274076 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294077}
4078
[email protected]a697f4c2009-09-14 22:30:184079void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274080 WebString no_encoding;
4081 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184082}
4083
[email protected]20ad2692009-11-20 18:27:204084bool RenderView::GetAllChildFrames(
4085 WebFrame* parent_frame,
4086 std::vector<WebFrame*>* frames_vector) const {
4087 if (!parent_frame)
4088 return false;
4089 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4090 child_frame = child_frame->nextSibling()) {
4091 frames_vector->push_back(child_frame);
4092 GetAllChildFrames(child_frame, frames_vector);
4093 }
4094 return true;
4095}
4096
[email protected]dd7daa82009-08-10 05:46:454097WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4098 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274099 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454100
4101 // xpath string can represent a frame deep down the tree (across multiple
4102 // frame DOMs).
4103 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4104 // should break into 2 xpaths
4105 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4106
[email protected]26aa0482009-09-30 16:55:274107 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454108
4109 std::wstring xpath_remaining = xpath;
4110 while (!xpath_remaining.empty()) {
4111 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4112 std::wstring xpath_child;
4113 if (delim_pos != std::wstring::npos) {
4114 xpath_child = xpath_remaining.substr(0, delim_pos);
4115 xpath_remaining.erase(0, delim_pos + 1);
4116 } else {
4117 xpath_remaining.swap(xpath_child);
4118 }
4119 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294120 }
4121
[email protected]dd7daa82009-08-10 05:46:454122 return frame;
initial.commit09911bf2008-07-26 23:55:294123}
4124
[email protected]15d9c0c2010-09-10 22:36:264125void RenderView::SetSuggestResult(const std::string& suggest) {
4126 if (!suggest.empty())
4127 Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest));
4128}
4129
[email protected]f29acf52008-11-03 20:08:334130void RenderView::EvaluateScript(const std::wstring& frame_xpath,
4131 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:294132 WebFrame* web_frame = GetChildFrame(frame_xpath);
4133 if (!web_frame)
4134 return;
4135
[email protected]dd7daa82009-08-10 05:46:454136 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:294137}
4138
[email protected]1810e132009-03-24 23:35:484139void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084140 const std::string& css,
4141 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484142 WebFrame* web_frame = GetChildFrame(frame_xpath);
4143 if (!web_frame)
4144 return;
4145
[email protected]ffaef0c2009-09-15 17:08:084146 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484147}
4148
[email protected]00c39612010-03-06 02:53:284149void RenderView::OnPepperPluginDestroy(
4150 WebPluginDelegatePepper* pepper_plugin) {
4151 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014152 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4153 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284154 NOTREACHED();
4155 return;
4156 }
[email protected]53900d52010-06-16 04:25:014157 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474158
4159 // The plugin could have been destroyed while it was waiting for a file
4160 // choose callback, so check all pending completion callbacks and NULL them.
4161 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4162 file_chooser_completions_.begin();
4163 i != file_chooser_completions_.end(); /* nothing */) {
4164 if ((*i)->completion == pepper_plugin) {
4165 // We NULL the first one instead of deleting it because the plugin might
4166 // be the one waiting for a file choose callback. If the callback later
4167 // comes, we don't want to send the result to the next callback in line.
4168 if (i == file_chooser_completions_.begin())
4169 (*i)->completion = NULL;
4170 else
4171 i = file_chooser_completions_.erase(i);
4172 } else {
4173 ++i;
4174 }
4175 }
[email protected]00c39612010-03-06 02:53:284176}
4177
initial.commit09911bf2008-07-26 23:55:294178void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
4179 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:334180 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:294181}
4182
[email protected]1810e132009-03-24 23:35:484183void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084184 const std::string& css,
4185 const std::string& id) {
4186 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414187
4188 // Notify RenderViewHost that css has been inserted into the frame.
4189 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484190}
4191
[email protected]7ea066a2009-04-06 20:21:594192void RenderView::OnAddMessageToConsole(
4193 const string16& frame_xpath,
4194 const string16& message,
4195 const WebConsoleMessage::Level& level) {
4196 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594197 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454198 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294199}
4200
[email protected]81e63782009-02-27 19:35:094201void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4202 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294203}
4204
4205void RenderView::OnSetDOMUIProperty(const std::string& name,
4206 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094207 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c091c2c2010-09-17 19:05:464208 GetDOMUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294209}
4210
4211void RenderView::OnReservePageIDRange(int size_of_range) {
4212 next_page_id_ += size_of_range + 1;
4213}
4214
[email protected]e80c73b2009-04-07 23:24:584215void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4216 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254217 bool ended,
4218 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034219 if (ended) {
[email protected]26aa0482009-09-30 16:55:274220 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204221 } else {
4222 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034223 }
initial.commit09911bf2008-07-26 23:55:294224}
4225
4226void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274227 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294228}
4229
initial.commit09911bf2008-07-26 23:55:294230void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:164231 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:084232#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]6a8ddba52010-09-05 04:38:064233 password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(),
[email protected]03f57072010-07-14 17:36:084234 form_data);
[email protected]ad24ccb2010-07-15 21:38:204235#else
4236 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:084237#endif
initial.commit09911bf2008-07-26 23:55:294238}
4239
4240void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584241 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254242 const gfx::Point& screen_point,
4243 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274244 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584245 drop_data.ToDragData(),
4246 drop_data.identity,
4247 client_point,
[email protected]1d9f4132009-09-08 17:29:254248 screen_point,
4249 ops);
initial.commit09911bf2008-07-26 23:55:294250
[email protected]1d9f4132009-09-08 17:29:254251 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294252}
4253
[email protected]e80c73b2009-04-07 23:24:584254void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254255 const gfx::Point& screen_point,
4256 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274257 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254258 client_point,
4259 screen_point,
4260 ops);
initial.commit09911bf2008-07-26 23:55:294261
[email protected]1d9f4132009-09-08 17:29:254262 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294263}
4264
4265void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274266 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294267}
4268
[email protected]e80c73b2009-04-07 23:24:584269void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4270 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274271 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294272}
4273
4274void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594275 webkit_preferences_ = prefs;
4276 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294277}
4278
4279void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4280 alternate_error_page_url_ = url;
4281}
4282
[email protected]a0c7153e2009-12-09 14:36:334283void RenderView::OnCustomContextMenuAction(unsigned action) {
4284 webview()->performCustomContextMenuAction(action);
4285}
4286
[email protected]d4a00a72010-01-29 01:44:424287void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024288 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424289 const std::string& source_lang,
4290 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024291 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4292 translate_script);
[email protected]d4a00a72010-01-29 01:44:424293}
4294
[email protected]85d252e2010-04-06 22:21:024295void RenderView::OnRevertTranslation(int page_id) {
4296 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324297}
4298
initial.commit09911bf2008-07-26 23:55:294299void RenderView::OnInstallMissingPlugin() {
4300 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594301 if (first_default_plugin_)
4302 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294303}
4304
[email protected]97c5c592010-08-03 08:22:214305void RenderView::OnLoadBlockedPlugins() {
4306 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4307 Source<RenderView>(this),
4308 NotificationService::NoDetails());
4309}
4310
[email protected]cdaf8d02010-03-30 19:52:474311void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364312 // This could happen if we navigated to a different page before the user
4313 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474314 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364315 return;
4316
[email protected]cdaf8d02010-03-30 19:52:474317 WebVector<WebString> ws_file_names(paths.size());
4318 for (size_t i = 0; i < paths.size(); ++i)
4319 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464320
[email protected]cdaf8d02010-03-30 19:52:474321 if (file_chooser_completions_.front()->completion)
4322 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4323 file_chooser_completions_.pop_front();
4324
4325 // If there are more pending file chooser requests, schedule one now.
4326 if (!file_chooser_completions_.empty()) {
4327 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4328 file_chooser_completions_.front()->params));
4329 }
initial.commit09911bf2008-07-26 23:55:294330}
4331
4332void RenderView::OnEnableViewSourceMode() {
4333 if (!webview())
4334 return;
[email protected]26aa0482009-09-30 16:55:274335 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294336 if (!main_frame)
4337 return;
4338
[email protected]dd7daa82009-08-10 05:46:454339 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294340}
4341
[email protected]770dd8b2010-05-24 18:11:394342void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4343 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244344 if (send_preferred_size_changes_)
4345 return;
[email protected]9fb325e2010-05-06 18:23:244346 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394347
4348 // WebKit doesn't send a notification of the effective height of the page
4349 // changes, so poll for it.
4350 // TODO: Add a notification for this to WebKit, remove polling. After that's
4351 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4352 // http://crbug.com/44850
4353 if (flags & kPreferredSizeHeightThisIsSlow) {
4354 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4355 &RenderView::CheckPreferredSize);
4356 }
[email protected]0666aef2009-05-13 19:48:084357}
4358
[email protected]cda45c02010-02-25 19:28:104359void RenderView::OnDisableScrollbarsForSmallWindows(
4360 const gfx::Size& disable_scrollbar_size_limit) {
4361 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4362}
4363
[email protected]80d96fa2009-06-10 22:34:514364void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4365 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374366 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034367#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414368 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4369 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464370 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324371
[email protected]644d77e2010-01-27 01:03:104372 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324373 webview()->setScrollbarColors(
4374 renderer_prefs.thumb_inactive_color,
4375 renderer_prefs.thumb_active_color,
4376 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104377 webview()->setSelectionColors(
4378 renderer_prefs.active_selection_bg_color,
4379 renderer_prefs.active_selection_fg_color,
4380 renderer_prefs.inactive_selection_bg_color,
4381 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464382 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104383 }
[email protected]7a74e102009-09-03 00:16:564384#endif
[email protected]80d96fa2009-06-10 22:34:514385}
4386
[email protected]952cb702009-10-07 05:50:284387void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4388 const WebMediaPlayerAction& action) {
4389 if (webview())
4390 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564391}
4392
[email protected]7b291f92009-08-14 05:43:534393void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4394 view_type_ = type;
4395}
4396
4397void RenderView::OnUpdateBrowserWindowId(int window_id) {
4398 browser_window_id_ = window_id;
4399}
4400
[email protected]b3df5a42010-05-11 14:31:094401void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364402 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414403 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114404 accessibility_.reset(WebAccessibilityCache::create());
4405 accessibility_->initialize(webview());
[email protected]9892b472010-09-16 00:23:424406 pending_accessibility_notifications_.clear();
[email protected]9f4db512010-05-10 20:21:414407
[email protected]b3df5a42010-05-11 14:31:094408 WebAccessibilityObject src_tree = webview()->accessibilityObject();
[email protected]416ac2e2010-09-01 17:15:164409 WebAccessibility dst_tree(src_tree, accessibility_.get());
[email protected]b3df5a42010-05-11 14:31:094410 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504411}
4412
[email protected]aef92842010-05-21 16:54:364413void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4414 if (!accessibility_.get())
4415 return;
4416 if (accessibility_->isValidId(acc_obj_id)) {
4417 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4418 // By convention, calling SetFocus on the root of the tree (id = 1000)
4419 // should clear the current focus. Otherwise set the focus to the new
4420 // node.
4421 if (acc_obj_id == 1000)
4422 webview()->clearFocusedNode();
4423 else
4424 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4425 }
4426}
4427
4428void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4429 if (!accessibility_.get())
4430 return;
4431 if (accessibility_->isValidId(acc_obj_id)) {
4432 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4433 }
4434}
4435
[email protected]9892b472010-09-16 00:23:424436void RenderView::OnAccessibilityNotificationsAck() {
[email protected]520cb7d72010-08-31 11:54:314437 if (!accessibility_.get())
4438 return;
4439
[email protected]9892b472010-09-16 00:23:424440 if (!pending_accessibility_notifications_.empty()) {
4441 Send(new ViewHostMsg_AccessibilityNotifications(
[email protected]520cb7d72010-08-31 11:54:314442 routing_id_,
[email protected]9892b472010-09-16 00:23:424443 pending_accessibility_notifications_));
[email protected]520cb7d72010-08-31 11:54:314444 }
4445
[email protected]9892b472010-09-16 00:23:424446 pending_accessibility_notifications_.clear();
[email protected]520cb7d72010-08-31 11:54:314447}
4448
initial.commit09911bf2008-07-26 23:55:294449void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4450 const GURL& page_url) {
4451 // Prepare list to storage all savable resource links.
4452 std::vector<GURL> resources_list;
4453 std::vector<GURL> referrers_list;
4454 std::vector<GURL> frames_list;
4455 webkit_glue::SavableResourcesResult result(&resources_list,
4456 &referrers_list,
4457 &frames_list);
4458
[email protected]dbeb3952009-10-13 18:01:184459 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4460 webview(),
4461 page_url,
4462 &result,
4463 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294464 // If something is wrong when collecting all savable resource links,
4465 // send empty list to embedder(browser) to tell it failed.
4466 referrers_list.clear();
4467 resources_list.clear();
4468 frames_list.clear();
4469 }
4470
4471 // Send result of all savable resource links to embedder.
4472 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4473 resources_list,
4474 referrers_list,
4475 frames_list));
4476}
4477
4478void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324479 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314480 const std::vector<FilePath>& local_paths,
4481 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074482
4483 // Convert std::vector of GURLs to WebVector<WebURL>
4484 WebVector<WebURL> weburl_links(links);
4485
4486 // Convert std::vector of std::strings to WebVector<WebString>
4487 WebVector<WebString> webstring_paths(local_paths.size());
4488 for (size_t i = 0; i < local_paths.size(); i++)
4489 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4490
4491 WebPageSerializer::serialize(webview()->mainFrame(),
4492 true, this, weburl_links, webstring_paths,
4493 webkit_glue::FilePathToWebString(
4494 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294495}
4496
[email protected]d9ec5c0f2009-12-23 11:55:074497void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4498 const WebCString& data,
4499 WebPageSerializerClient::PageSerializationStatus status) {
4500 Send(new ViewHostMsg_SendSerializedHtmlData(
4501 routing_id_,
4502 frame_url,
4503 data.data(),
4504 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294505}
4506
[email protected]9b18a84f2010-06-10 15:54:044507void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274508 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474509 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294510}
4511
[email protected]eb6b87a2009-07-24 15:57:394512void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294513 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4514 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4515 // in the onunload handler from appearing. For now, we're bypassing that and
4516 // calling the FrameLoader's CloseURL method directly. This should be
4517 // revisited to avoid having two ways to close a page. Having a single way
4518 // to close that can run onunload is also useful for fixing
4519 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274520 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294521 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454522 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174523 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294524 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4525 // multiple times for the same frame, but it will simplify things.
[email protected]05c8e502010-08-15 15:13:524526
4527 // Ensure state contains scheme.
4528 NavigationState* navigation_state =
4529 NavigationState::FromDataSource(main_frame->dataSource());
4530 if (url.SchemeIs("http"))
4531 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP);
4532 else if (url.SchemeIs("https"))
4533 navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS);
4534
4535 // Dump will only be provided when scheme is http or https.
4536 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294537 }
[email protected]26aa0482009-09-30 16:55:274538 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294539
[email protected]ab9eabac2010-03-16 16:54:104540 // Reset stats
4541 cross_origin_access_count_ = 0;
4542 same_origin_access_count_ = 0;
4543
[email protected]eb6b87a2009-07-24 15:57:394544 // Just echo back the params in the ACK.
4545 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294546}
4547
4548void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574549#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294550 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464551 if (webview())
4552 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574553#else // defined(OS_WIN)
4554 // TODO(port): we don't support theming on non-Windows platforms yet
4555 NOTIMPLEMENTED();
4556#endif
initial.commit09911bf2008-07-26 23:55:294557}
4558
[email protected]9b18a84f2010-06-10 15:54:044559void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4560 const std::string& origin,
4561 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154562 if (message.empty())
4563 return;
[email protected]c091c2c2010-09-17 19:05:464564 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
4565 target);
[email protected]3ac14a052008-08-15 21:22:154566}
4567
[email protected]0aa55312008-10-17 21:53:084568void RenderView::OnDisassociateFromPopupCount() {
4569 if (decrement_shared_popup_at_destruction_)
4570 shared_popup_counter_->data--;
4571 shared_popup_counter_ = new SharedRenderViewCounter(0);
4572 decrement_shared_popup_at_destruction_ = false;
4573}
4574
[email protected]15d79e12009-08-02 19:23:454575bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4576 const WebURLError& error,
4577 bool replace) {
4578 // We only show alternate error pages in the main frame. They are
4579 // intended to assist the user when navigating, so there is not much
4580 // value in showing them for failed subframes. Ideally, we would be
4581 // able to use the TYPED transition type for this, but that flag is
4582 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454583 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454584 return false;
4585
4586 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374587 // connection failure.
[email protected]15d79e12009-08-02 19:23:454588 int ec = error.reason;
4589 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4590 ec != net::ERR_CONNECTION_FAILED &&
4591 ec != net::ERR_CONNECTION_REFUSED &&
4592 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374593 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454594 return false;
4595
4596 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554597 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454598 if (!error_page_url.is_valid())
4599 return false;
4600
4601 // Load an empty page first so there is an immediate response to the error,
4602 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454603 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454604 GURL(kUnreachableWebDataURL),
4605 error.unreachableURL,
4606 replace);
4607
4608 // Now, create a fetcher for the error page and associate it with the data
4609 // source we just created via the LoadHTMLString call. That way if another
4610 // navigation occurs, the fetcher will get destroyed.
4611 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454612 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454613 navigation_state->set_alt_error_page_fetcher(
4614 new AltErrorPageResourceFetcher(
4615 error_page_url, frame, error,
4616 NewCallback(this, &RenderView::AltErrorPageFinished)));
4617 return true;
4618}
4619
initial.commit09911bf2008-07-26 23:55:294620std::string RenderView::GetAltHTMLForTemplate(
4621 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394622 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294623 ResourceBundle::GetSharedInstance().GetRawDataResource(
4624 template_resource_id));
4625
4626 if (template_html.empty()) {
4627 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4628 return "";
4629 }
[email protected]7cd22a52009-07-14 00:40:254630
initial.commit09911bf2008-07-26 23:55:294631 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254632 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294633 template_html, &error_strings, "t");
4634}
[email protected]0e79b9e2009-02-13 04:20:484635
[email protected]15d79e12009-08-02 19:23:454636void RenderView::AltErrorPageFinished(WebFrame* frame,
4637 const WebURLError& original_error,
4638 const std::string& html) {
4639 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554640
4641 // If we failed to download the alternate error page, fall back to the
4642 // original error page if present. Otherwise, LoadNavigationErrorPage
4643 // will simply display a default error page.
4644 const std::string* html_to_load = &html;
4645 if (html.empty()) {
4646 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454647 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554648 html_to_load = &navigation_state->postponed_data();
4649 }
[email protected]3f853a52010-09-13 19:15:084650 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
4651 true);
[email protected]15d79e12009-08-02 19:23:454652}
4653
[email protected]30f75e62009-02-25 22:01:004654void RenderView::OnMoveOrResizeStarted() {
4655 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474656 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004657}
4658
[email protected]30f75e62009-02-25 22:01:004659void RenderView::OnResize(const gfx::Size& new_size,
4660 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104661 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474662 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104663 if (send_preferred_size_changes_) {
[email protected]0695ef42010-09-23 22:42:174664 webview()->mainFrame()->setCanHaveScrollbars(
4665 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104666 }
4667 }
4668
[email protected]30f75e62009-02-25 22:01:004669 RenderWidget::OnResize(new_size, resizer_rect);
4670}
[email protected]0aa477bd2009-03-23 22:21:434671
[email protected]00c39612010-03-06 02:53:284672void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014673 // Notify the pepper plugins that we started painting.
4674 pepper_delegate_.ViewInitiatedPaint();
4675
4676 // Notify any "old-style" pepper plugins that we started painting. This is
4677 // used for internal bookkeeping only, so we know that the set can not change
4678 // under us.
[email protected]00c39612010-03-06 02:53:284679 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014680 current_oldstyle_pepper_plugins_.begin();
4681 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284682 (*i)->RenderViewInitiatedPaint();
4683}
4684
4685void RenderView::DidFlushPaint() {
4686 // Notify any pepper plugins that we painted. This will call into the plugin,
4687 // and we it may ask to close itself as a result. This will, in turn, modify
4688 // our set, possibly invalidating the iterator. So we iterate on a copy that
4689 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014690 pepper_delegate_.ViewFlushedPaint();
4691
4692 // Notify any old-style pepper plugins that we painted. This will call into
4693 // the plugin, and we it may ask to close itself as a result. This will, in
4694 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4695 // a copy that won't change out from under us.
4696 // This should be deleted when we don't support old Pepper anymore.
4697 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284698 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4699 i != plugins.end(); ++i) {
4700 // The copy above makes sure our iterator is never invalid if some plugins
4701 // are destroyed. But some plugin may decide to close all of its views in
4702 // response to a paint in one of them, so we need to make sure each one is
4703 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014704 if (current_oldstyle_pepper_plugins_.find(*i) !=
4705 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284706 (*i)->RenderViewFlushedPaint();
4707 }
4708
4709 WebFrame* main_frame = webview()->mainFrame();
4710
4711 // If we have a provisional frame we are between the start and commit stages
4712 // of loading and we don't want to save stats.
4713 if (!main_frame->provisionalDataSource()) {
4714 WebDataSource* ds = main_frame->dataSource();
4715 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4716 DCHECK(navigation_state);
4717
[email protected]05c8e502010-08-15 15:13:524718 // TODO(jar): The following code should all be inside a method, probably in
4719 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284720 Time now = Time::Now();
4721 if (navigation_state->first_paint_time().is_null()) {
4722 navigation_state->set_first_paint_time(now);
4723 }
4724 if (navigation_state->first_paint_after_load_time().is_null() &&
4725 !navigation_state->finish_load_time().is_null()) {
4726 navigation_state->set_first_paint_after_load_time(now);
4727 }
4728 }
4729}
4730
[email protected]ca4847f2010-09-24 05:39:154731bool RenderView::GetBitmapForOptimizedPluginPaint(
4732 const gfx::Rect& paint_bounds,
4733 TransportDIB** dib,
4734 gfx::Rect* location,
4735 gfx::Rect* clip) {
4736 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4737 paint_bounds, dib, location, clip);
4738}
4739
[email protected]05d478752009-04-08 23:38:164740void RenderView::OnClearFocusedNode() {
4741 if (webview())
[email protected]26aa0482009-09-30 16:55:274742 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164743}
4744
[email protected]699ab0d2009-04-23 23:19:144745void RenderView::OnSetBackground(const SkBitmap& background) {
4746 if (webview())
[email protected]b4bb2502009-10-01 22:35:274747 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144748
4749 SetBackground(background);
4750}
4751
[email protected]8c66c5a2009-07-22 17:26:344752void RenderView::OnSetActive(bool active) {
4753 if (webview())
[email protected]b4bb2502009-10-01 22:35:274754 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264755
4756#if defined(OS_MACOSX)
4757 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4758 for (plugin_it = plugin_delegates_.begin();
4759 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4760 (*plugin_it)->SetWindowFocus(active);
4761 }
4762#endif
[email protected]8c66c5a2009-07-22 17:26:344763}
4764
[email protected]6ce7abc52010-02-02 18:40:144765#if defined(OS_MACOSX)
4766void RenderView::OnSetWindowVisibility(bool visible) {
4767 // Inform plugins that their container has changed visibility.
4768 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4769 for (plugin_it = plugin_delegates_.begin();
4770 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4771 (*plugin_it)->SetContainerVisibility(visible);
4772 }
4773}
[email protected]1e6e3c992010-02-08 15:52:134774
[email protected]4d51d5bf2010-07-26 18:48:264775void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4776 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134777 // Inform plugins that their window's frame has changed.
4778 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4779 for (plugin_it = plugin_delegates_.begin();
4780 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4781 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4782 }
4783}
[email protected]6ce7abc52010-02-02 18:40:144784#endif // OS_MACOSX
4785
[email protected]8b8e7c92010-08-19 18:05:564786void RenderView::SendExtensionRequest(
4787 const ViewHostMsg_DomMessage_Params& params) {
4788 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:274789}
4790
[email protected]c6619182009-05-12 14:59:324791void RenderView::OnExtensionResponse(int request_id,
4792 bool success,
4793 const std::string& response,
4794 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354795 ExtensionProcessBindings::HandleResponse(
4796 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274797}
[email protected]c20210e62009-04-03 21:39:264798
[email protected]7120f132009-07-20 21:05:374799void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494800 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194801 bool requires_incognito_access,
4802 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494803 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194804 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374805}
4806
[email protected]e7e4f3c2009-04-21 15:24:084807// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264808//
[email protected]c20210e62009-04-03 21:39:264809// The time points we keep are
4810// request: time document was requested by user
4811// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254812// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294813// finish_document: main document loaded, before onload()
[email protected]05c8e502010-08-15 15:13:524814// finish_all_loads: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294815// first_paint: first paint performed
4816// first_paint_after_load: first paint performed after load is finished
4817// begin: request if it was user requested, start otherwise
4818//
[email protected]e7e4f3c2009-04-21 15:24:084819// It's possible for the request time not to be set, if a client
4820// redirect had been done (the user never requested the page)
4821// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294822// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264823void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504824 // Configuration for PLT related histograms.
4825 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4826 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4827 static const size_t kPLTCount(100);
4828 #define PLT_HISTOGRAM(name, sample) \
4829 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4830
[email protected]26aa0482009-09-30 16:55:274831 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564832 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454833 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564834
[email protected]05c8e502010-08-15 15:13:524835 URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type();
4836 if (scheme_type == 0)
4837 return;
4838 DCHECK(scheme_type == URLPattern::SCHEME_HTTP ||
4839 scheme_type == URLPattern::SCHEME_HTTPS);
4840
[email protected]f9f4841b2010-03-20 05:41:424841 // If we've already dumped, do nothing.
4842 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294843 return;
[email protected]cf9a7bc2010-06-11 18:54:504844
4845 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454846 Time start = navigation_state->start_load_time();
4847 if (start.is_null())
4848 return; // Probably very premature abandonment of page.
4849 Time commit = navigation_state->commit_load_time();
4850 if (commit.is_null())
4851 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504852
[email protected]b855ebe62010-05-12 23:01:454853 // We properly handle null values for the next 3 variables.
4854 Time request = navigation_state->request_time();
4855 Time first_paint = navigation_state->first_paint_time();
4856 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454857 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]05c8e502010-08-15 15:13:524858 Time finish_all_loads = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564859
[email protected]f9f4841b2010-03-20 05:41:424860 // Handle case where user hits "stop" or "back" before loading completely.
[email protected]05c8e502010-08-15 15:13:524861 bool abandoned_page = finish_doc.is_null();
[email protected]f9f4841b2010-03-20 05:41:424862 if (abandoned_page) {
[email protected]05c8e502010-08-15 15:13:524863 finish_doc = Time::Now();
4864 navigation_state->set_finish_document_load_time(finish_doc);
[email protected]f9f4841b2010-03-20 05:41:424865 }
[email protected]f9f4841b2010-03-20 05:41:424866
[email protected]05c8e502010-08-15 15:13:524867 // TODO(jar): We should really discriminate the definition of "abandon" more
4868 // finely. We should have:
4869 // abandon_before_document_loaded
4870 // abandon_before_onload_fired
4871
4872 if (finish_all_loads.is_null()) {
4873 finish_all_loads = Time::Now();
4874 navigation_state->set_finish_load_time(finish_all_loads);
4875 } else {
4876 DCHECK(!abandoned_page); // How can the doc have finished but not the page?
[email protected]cf9a7bc2010-06-11 18:54:504877 if (!abandoned_page)
4878 return; // Don't try to record a stat which is broken.
[email protected]cf9a7bc2010-06-11 18:54:504879 }
4880
4881 // Note: Client side redirects will have no request time.
4882 Time begin = request.is_null() ? start : request;
4883 TimeDelta begin_to_finish_doc = finish_doc - begin;
[email protected]05c8e502010-08-15 15:13:524884 TimeDelta begin_to_finish_all_loads = finish_all_loads - begin;
4885 TimeDelta start_to_finish_all_loads = finish_all_loads - start;
[email protected]ef1d8d322010-06-13 18:31:254886 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424887
[email protected]a7ccc4d2010-01-27 08:14:484888 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504889
[email protected]05c8e502010-08-15 15:13:524890 // The above code sanitized all values of times, in preparation for creating
4891 // actual histograms. The remainder of this code could be run at destructor
4892 // time for the navigation_state, since all data is intact.
4893
[email protected]cf9a7bc2010-06-11 18:54:504894 // Aggregate PLT data across all link types.
4895 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4896 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4897 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254898 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504899 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
[email protected]05c8e502010-08-15 15:13:524900 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc);
[email protected]cf9a7bc2010-06-11 18:54:504901 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
[email protected]05c8e502010-08-15 15:13:524902 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504903 if (!request.is_null()) {
4904 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
[email protected]05c8e502010-08-15 15:13:524905 PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request);
[email protected]cf9a7bc2010-06-11 18:54:504906 }
[email protected]05c8e502010-08-15 15:13:524907 PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit);
[email protected]cf9a7bc2010-06-11 18:54:504908 if (!first_paint.is_null()) {
4909 DCHECK(begin <= first_paint);
4910 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4911 DCHECK(commit <= first_paint);
4912 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4913 }
4914 if (!first_paint_after_load.is_null()) {
4915 DCHECK(begin <= first_paint_after_load);
4916 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4917 first_paint_after_load - begin);
4918 DCHECK(commit <= first_paint_after_load);
4919 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4920 first_paint_after_load - commit);
[email protected]05c8e502010-08-15 15:13:524921 DCHECK(finish_all_loads <= first_paint_after_load);
[email protected]cf9a7bc2010-06-11 18:54:504922 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
[email protected]05c8e502010-08-15 15:13:524923 first_paint_after_load - finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504924 }
4925 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524926 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504927
4928 // Load type related histograms.
4929 switch (load_type) {
4930 case NavigationState::UNDEFINED_LOAD:
4931 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524932 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504933 break;
4934 case NavigationState::RELOAD:
4935 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524936 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504937 break;
4938 case NavigationState::HISTORY_LOAD:
4939 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524940 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504941 break;
4942 case NavigationState::NORMAL_LOAD:
4943 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524944 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504945 break;
4946 case NavigationState::LINK_LOAD_NORMAL:
4947 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4948 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524949 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal",
4950 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504951 break;
4952 case NavigationState::LINK_LOAD_RELOAD:
4953 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4954 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524955 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload",
4956 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504957 break;
4958 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4959 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4960 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524961 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk",
4962 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504963 break;
4964 case NavigationState::LINK_LOAD_CACHE_ONLY:
4965 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4966 begin_to_finish_doc);
[email protected]05c8e502010-08-15 15:13:524967 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly",
4968 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504969 break;
4970 default:
4971 break;
4972 }
4973
4974 // Histograms to determine if DNS prefetching has an impact on PLT.
4975 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4976 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4977 if (use_dns_histogram) {
4978 UMA_HISTOGRAM_ENUMERATION(
4979 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4980 abandoned_page ? 1 : 0, 2);
4981 UMA_HISTOGRAM_ENUMERATION(
4982 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4983 load_type, NavigationState::kLoadTypeMax);
4984 switch (load_type) {
4985 case NavigationState::NORMAL_LOAD:
4986 PLT_HISTOGRAM(FieldTrial::MakeName(
[email protected]05c8e502010-08-15 15:13:524987 "PLT.BeginToFinish_NormalLoad", "DnsImpact"),
4988 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504989 break;
4990 case NavigationState::LINK_LOAD_NORMAL:
4991 PLT_HISTOGRAM(FieldTrial::MakeName(
4992 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524993 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504994 break;
4995 case NavigationState::LINK_LOAD_RELOAD:
4996 PLT_HISTOGRAM(FieldTrial::MakeName(
4997 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:524998 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:504999 break;
5000 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5001 PLT_HISTOGRAM(FieldTrial::MakeName(
5002 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
[email protected]05c8e502010-08-15 15:13:525003 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505004 break;
5005 default:
5006 break;
5007 }
5008 }
5009
[email protected]8a3125a712010-08-09 18:58:515010 // Histograms to determine if content prefetching has an impact on PLT.
5011 static const bool prefetching_fieldtrial =
5012 FieldTrialList::Find("Prefetch") &&
5013 !FieldTrialList::Find("Prefetch")->group_name().empty();
[email protected]13ae2df92010-08-19 20:05:105014 if (prefetching_fieldtrial) {
5015 if (navigation_state->was_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:515016 PLT_HISTOGRAM(
5017 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher",
5018 "Prefetch"),
5019 begin_to_finish_doc);
5020 PLT_HISTOGRAM(
5021 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher",
5022 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525023 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515024 }
[email protected]13ae2df92010-08-19 20:05:105025 if (navigation_state->was_referred_by_prefetcher()) {
[email protected]8a3125a712010-08-09 18:58:515026 PLT_HISTOGRAM(
5027 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcherReferrer",
5028 "Prefetch"),
5029 begin_to_finish_doc);
5030 PLT_HISTOGRAM(
5031 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcherReferrer",
5032 "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525033 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515034 }
[email protected]8a3125a712010-08-09 18:58:515035 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName("PLT.Abandoned", "Prefetch"),
5036 abandoned_page ? 1 : 0, 2);
5037 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinishDoc", "Prefetch"),
5038 begin_to_finish_doc);
5039 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"),
[email protected]05c8e502010-08-15 15:13:525040 begin_to_finish_all_loads);
[email protected]8a3125a712010-08-09 18:58:515041 }
5042
[email protected]06d94042010-08-25 01:45:225043 // Histograms to determine if backup connection jobs have an impact on PLT.
5044 static const bool connect_backup_jobs_fieldtrial(
5045 FieldTrialList::Find("ConnnectBackupJobs") &&
5046 !FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty());
5047 if (connect_backup_jobs_fieldtrial) {
5048 UMA_HISTOGRAM_ENUMERATION(
5049 FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"),
5050 abandoned_page ? 1 : 0, 2);
5051 UMA_HISTOGRAM_ENUMERATION(
5052 FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"),
5053 load_type, NavigationState::kLoadTypeMax);
5054 switch (load_type) {
5055 case NavigationState::NORMAL_LOAD:
5056 PLT_HISTOGRAM(FieldTrial::MakeName(
5057 "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"),
5058 begin_to_finish_all_loads);
5059 break;
5060 case NavigationState::LINK_LOAD_NORMAL:
5061 PLT_HISTOGRAM(FieldTrial::MakeName(
5062 "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"),
5063 begin_to_finish_all_loads);
5064 break;
5065 case NavigationState::LINK_LOAD_RELOAD:
5066 PLT_HISTOGRAM(FieldTrial::MakeName(
5067 "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"),
5068 begin_to_finish_all_loads);
5069 break;
5070 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5071 PLT_HISTOGRAM(FieldTrial::MakeName(
5072 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"),
5073 begin_to_finish_all_loads);
5074 break;
5075 default:
5076 break;
5077 }
5078 }
5079
[email protected]cf9a7bc2010-06-11 18:54:505080 // Histograms to determine if the number of connections has an
5081 // impact on PLT.
5082 // TODO(jar): Consider removing the per-link-type versions. We
5083 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
[email protected]97546492010-08-09 05:14:495084 static bool use_connection_impact_histogram(
[email protected]cf9a7bc2010-06-11 18:54:505085 FieldTrialList::Find("ConnCountImpact") &&
5086 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
[email protected]97546492010-08-09 05:14:495087 if (use_connection_impact_histogram) {
[email protected]cf9a7bc2010-06-11 18:54:505088 UMA_HISTOGRAM_ENUMERATION(
5089 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
5090 abandoned_page ? 1 : 0, 2);
5091 switch (load_type) {
5092 case NavigationState::NORMAL_LOAD:
5093 PLT_HISTOGRAM(FieldTrial::MakeName(
5094 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525095 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505096 break;
5097 case NavigationState::LINK_LOAD_NORMAL:
5098 PLT_HISTOGRAM(FieldTrial::MakeName(
5099 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525100 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505101 break;
5102 case NavigationState::LINK_LOAD_RELOAD:
5103 PLT_HISTOGRAM(FieldTrial::MakeName(
5104 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525105 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505106 break;
5107 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5108 PLT_HISTOGRAM(FieldTrial::MakeName(
5109 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
[email protected]05c8e502010-08-15 15:13:525110 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505111 break;
5112 default:
5113 break;
5114 }
5115 }
5116
[email protected]78a258a2010-08-02 16:34:265117 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:005118 static bool use_idle_socket_timeout_histogram(
5119 FieldTrialList::Find("IdleSktToImpact") &&
5120 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
5121 if (use_idle_socket_timeout_histogram) {
5122 UMA_HISTOGRAM_ENUMERATION(
5123 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
5124 abandoned_page ? 1 : 0, 2);
5125 switch (load_type) {
5126 case NavigationState::NORMAL_LOAD:
5127 PLT_HISTOGRAM(FieldTrial::MakeName(
5128 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525129 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005130 break;
5131 case NavigationState::LINK_LOAD_NORMAL:
5132 PLT_HISTOGRAM(FieldTrial::MakeName(
5133 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525134 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005135 break;
5136 case NavigationState::LINK_LOAD_RELOAD:
5137 PLT_HISTOGRAM(FieldTrial::MakeName(
5138 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525139 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005140 break;
5141 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5142 PLT_HISTOGRAM(FieldTrial::MakeName(
5143 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
[email protected]05c8e502010-08-15 15:13:525144 begin_to_finish_all_loads);
[email protected]241c5c2c2010-06-21 18:46:005145 break;
5146 default:
5147 break;
5148 }
5149 }
5150
[email protected]78a258a2010-08-02 16:34:265151 // Histograms to determine effect of number of connections per proxy.
5152 static bool use_proxy_connection_impact_histogram(
5153 FieldTrialList::Find("ProxyConnectionImpact") &&
5154 !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty());
5155 if (use_proxy_connection_impact_histogram) {
5156 UMA_HISTOGRAM_ENUMERATION(
5157 FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
5158 abandoned_page ? 1 : 0, 2);
5159 switch (load_type) {
5160 case NavigationState::NORMAL_LOAD:
5161 PLT_HISTOGRAM(FieldTrial::MakeName(
5162 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525163 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265164 break;
5165 case NavigationState::LINK_LOAD_NORMAL:
5166 PLT_HISTOGRAM(FieldTrial::MakeName(
5167 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525168 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265169 break;
5170 case NavigationState::LINK_LOAD_RELOAD:
5171 PLT_HISTOGRAM(FieldTrial::MakeName(
5172 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525173 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265174 break;
5175 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5176 PLT_HISTOGRAM(FieldTrial::MakeName(
5177 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
[email protected]05c8e502010-08-15 15:13:525178 begin_to_finish_all_loads);
[email protected]78a258a2010-08-02 16:34:265179 break;
5180 default:
5181 break;
5182 }
5183 }
5184
[email protected]cf9a7bc2010-06-11 18:54:505185 // Histograms to determine if SDCH has an impact.
5186 // TODO(jar): Consider removing per-link load types and the enumeration.
5187 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
5188 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
5189 if (use_sdch_histogram) {
5190 UMA_HISTOGRAM_ENUMERATION(
5191 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
5192 load_type, NavigationState::kLoadTypeMax);
5193 switch (load_type) {
5194 case NavigationState::NORMAL_LOAD:
5195 PLT_HISTOGRAM(FieldTrial::MakeName(
5196 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525197 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505198 break;
5199 case NavigationState::LINK_LOAD_NORMAL:
5200 PLT_HISTOGRAM(FieldTrial::MakeName(
5201 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525202 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505203 break;
5204 case NavigationState::LINK_LOAD_RELOAD:
5205 PLT_HISTOGRAM(FieldTrial::MakeName(
5206 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525207 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505208 break;
5209 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5210 PLT_HISTOGRAM(FieldTrial::MakeName(
5211 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525212 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505213 break;
5214 case NavigationState::LINK_LOAD_CACHE_ONLY:
5215 PLT_HISTOGRAM(FieldTrial::MakeName(
5216 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
[email protected]05c8e502010-08-15 15:13:525217 begin_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505218 break;
5219 default:
5220 break;
5221 }
5222 }
5223
5224 // Histograms to determine if cache size has an impact on PLT.
5225 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
5226 !FieldTrialList::Find("CacheSize")->group_name().empty());
5227 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
5228 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
5229 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
5230 // StartToFinish or BeginToFinish would be better.
5231 PLT_HISTOGRAM(FieldTrial::MakeName(
5232 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
5233 }
5234
[email protected]1a20f102010-09-16 21:50:395235 // Histograms to determine if cache throttling has an impact on PLT.
5236 static bool use_cache_histogram2(FieldTrialList::Find("CacheThrottle") &&
5237 !FieldTrialList::Find("CacheThrottle")->group_name().empty());
5238 if (use_cache_histogram2) {
5239 UMA_HISTOGRAM_ENUMERATION(
5240 FieldTrial::MakeName("PLT.Abandoned", "CacheThrottle"),
5241 abandoned_page ? 1 : 0, 2);
5242 switch (load_type) {
5243 case NavigationState::RELOAD:
5244 PLT_HISTOGRAM(FieldTrial::MakeName(
5245 "PLT.BeginToFinish_Reload", "CacheThrottle"),
5246 begin_to_finish_all_loads);
5247 break;
5248 case NavigationState::HISTORY_LOAD:
5249 PLT_HISTOGRAM(FieldTrial::MakeName(
5250 "PLT.BeginToFinish_HistoryLoad", "CacheThrottle"),
5251 begin_to_finish_all_loads);
5252 break;
5253 case NavigationState::NORMAL_LOAD:
5254 PLT_HISTOGRAM(FieldTrial::MakeName(
5255 "PLT.BeginToFinish_NormalLoad", "CacheThrottle"),
5256 begin_to_finish_all_loads);
5257 break;
5258 case NavigationState::LINK_LOAD_NORMAL:
5259 PLT_HISTOGRAM(FieldTrial::MakeName(
5260 "PLT.BeginToFinish_LinkLoadNormal", "CacheThrottle"),
5261 begin_to_finish_all_loads);
5262 break;
5263 case NavigationState::LINK_LOAD_RELOAD:
5264 PLT_HISTOGRAM(FieldTrial::MakeName(
5265 "PLT.BeginToFinish_LinkLoadReload", "CacheThrottle"),
5266 begin_to_finish_all_loads);
5267 break;
5268 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
5269 PLT_HISTOGRAM(FieldTrial::MakeName(
5270 "PLT.BeginToFinish_LinkLoadStaleOk", "CacheThrottle"),
5271 begin_to_finish_all_loads);
5272 break;
5273 case NavigationState::LINK_LOAD_CACHE_ONLY:
5274 PLT_HISTOGRAM(FieldTrial::MakeName(
5275 "PLT.BeginToFinish_LinkLoadCacheOnly", "CacheThrottle"),
5276 begin_to_finish_all_loads);
5277 break;
5278 default:
5279 break;
5280 }
5281 if (NavigationState::RELOAD <= load_type &&
5282 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
5283 PLT_HISTOGRAM(FieldTrial::MakeName(
5284 "PLT.BeginToFinish", "CacheThrottle"),
5285 begin_to_finish_all_loads);
5286 }
5287 }
5288
[email protected]8cfe6bb2010-08-27 02:35:005289 // For the SPDY field trials, we need to verify that the page loaded was
5290 // the type we requested:
5291 // if we asked for a SPDY request, we got a SPDY request
5292 // if we asked for a HTTP request, we got a HTTP request
5293 // Due to spdy version mismatches, it is possible that we ask for SPDY
5294 // but didn't get SPDY.
[email protected]cf9a7bc2010-06-11 18:54:505295 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
5296 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]8cfe6bb2010-08-27 02:35:005297 if (use_spdy_histogram) {
5298 // We take extra effort to only compute these once.
5299 static bool in_spdy_trial =
5300 FieldTrialList::Find("SpdyImpact")->group_name() == "npn_with_spdy";
5301 static bool in_http_trial =
5302 FieldTrialList::Find("SpdyImpact")->group_name() == "npn_with_http";
[email protected]cf9a7bc2010-06-11 18:54:505303
[email protected]8cfe6bb2010-08-27 02:35:005304 bool spdy_trial_success = navigation_state->was_fetched_via_spdy() ?
5305 in_spdy_trial : in_http_trial;
5306 if (spdy_trial_success) {
5307 // Histograms to determine if SPDY has an impact for https traffic.
5308 // TODO(mbelshe): After we've seen the difference between BeginToFinish
5309 // and StartToFinish, consider removing one or the other.
5310 if (scheme_type == URLPattern::SCHEME_HTTPS &&
5311 navigation_state->was_npn_negotiated()) {
5312 UMA_HISTOGRAM_ENUMERATION(
5313 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
5314 abandoned_page ? 1 : 0, 2);
5315 switch (load_type) {
5316 case NavigationState::LINK_LOAD_NORMAL:
5317 PLT_HISTOGRAM(FieldTrial::MakeName(
5318 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5319 begin_to_finish_all_loads);
5320 PLT_HISTOGRAM(FieldTrial::MakeName(
5321 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5322 start_to_finish_all_loads);
5323 PLT_HISTOGRAM(FieldTrial::MakeName(
5324 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5325 start_to_commit);
5326 break;
5327 case NavigationState::NORMAL_LOAD:
5328 PLT_HISTOGRAM(FieldTrial::MakeName(
5329 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5330 begin_to_finish_all_loads);
5331 PLT_HISTOGRAM(FieldTrial::MakeName(
5332 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5333 start_to_finish_all_loads);
5334 PLT_HISTOGRAM(FieldTrial::MakeName(
5335 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
5336 start_to_commit);
5337 break;
5338 default:
5339 break;
5340 }
[email protected]193b0b892010-06-26 03:57:575341 }
[email protected]8cfe6bb2010-08-27 02:35:005342
5343 // Histograms to compare the impact of alternate protocol over http
5344 // traffic: when spdy is used vs. when http is used.
5345 if (scheme_type == URLPattern::SCHEME_HTTP &&
5346 navigation_state->was_alternate_protocol_available()) {
5347 if (!navigation_state->was_npn_negotiated()) {
5348 // This means that even there is alternate protocols for npn_http or
5349 // npn_spdy, they are not taken (due to the fieldtrial).
5350 switch (load_type) {
5351 case NavigationState::LINK_LOAD_NORMAL:
5352 PLT_HISTOGRAM(
5353 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
5354 start_to_finish_all_loads);
5355 PLT_HISTOGRAM(
5356 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
5357 start_to_commit);
5358 break;
5359 case NavigationState::NORMAL_LOAD:
5360 PLT_HISTOGRAM(
5361 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
5362 start_to_finish_all_loads);
5363 PLT_HISTOGRAM(
5364 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
5365 start_to_commit);
5366 break;
5367 default:
5368 break;
5369 }
5370 } else if (navigation_state->was_fetched_via_spdy()) {
5371 switch (load_type) {
5372 case NavigationState::LINK_LOAD_NORMAL:
5373 PLT_HISTOGRAM(
5374 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
5375 start_to_finish_all_loads);
5376 PLT_HISTOGRAM(
5377 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
5378 start_to_commit);
5379 break;
5380 case NavigationState::NORMAL_LOAD:
5381 PLT_HISTOGRAM(
5382 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
5383 start_to_finish_all_loads);
5384 PLT_HISTOGRAM(
5385 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
5386 start_to_commit);
5387 break;
5388 default:
5389 break;
5390 }
5391 }
[email protected]193b0b892010-06-26 03:57:575392 }
5393 }
5394 }
5395
[email protected]cf9a7bc2010-06-11 18:54:505396 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:505397 if (navigation_state->was_fetched_via_proxy()) {
[email protected]05c8e502010-08-15 15:13:525398 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5399 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505400 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
[email protected]05c8e502010-08-15 15:13:525401 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505402 } else {
[email protected]05c8e502010-08-15 15:13:525403 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5404 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505405 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
[email protected]05c8e502010-08-15 15:13:525406 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505407 }
5408 } else {
[email protected]05c8e502010-08-15 15:13:525409 if (scheme_type == URLPattern::SCHEME_HTTPS) {
5410 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https",
5411 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505412 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
[email protected]05c8e502010-08-15 15:13:525413 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505414 } else {
[email protected]05c8e502010-08-15 15:13:525415 DCHECK(scheme_type == URLPattern::SCHEME_HTTP);
5416 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http",
5417 start_to_finish_all_loads);
[email protected]cf9a7bc2010-06-11 18:54:505418 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
[email protected]05c8e502010-08-15 15:13:525419 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505420 }
5421 }
[email protected]a7ccc4d2010-01-27 08:14:485422
[email protected]ab9eabac2010-03-16 16:54:105423 // Site isolation metrics.
5424 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
5425 cross_origin_access_count_);
5426 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
5427 same_origin_access_count_);
5428
[email protected]05c8e502010-08-15 15:13:525429 // TODO(jar): This is the ONLY call in this method that needed more than
5430 // navigation_state. This should be relocated, or changed, so that this
5431 // body can be made a method on NavigationStates, and run via its destructor.
[email protected]cf9a7bc2010-06-11 18:54:505432 // Log some PLT data to the error log.
5433 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:295434
5435 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:415436
5437 // Since there are currently no guarantees that renderer histograms will be
5438 // sent to the browser, we initiate a PostTask here to be sure that we send
5439 // the histograms we generated. Without this call, pages that don't have an
5440 // on-close-handler might generate data that is lost when the renderer is
5441 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:485442 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
5443 // should post when the onload is complete, so that it doesn't interfere with
5444 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:415445 if (RenderThread::current()) {
5446 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:135447 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:415448 }
[email protected]c20210e62009-04-03 21:39:265449}
[email protected]e846d0d2009-05-20 00:53:065450
[email protected]f8999642009-10-27 21:39:425451void RenderView::LogNavigationState(const NavigationState* state,
5452 const WebDataSource* ds) const {
5453 // Because this function gets called on every page load,
5454 // take extra care to optimize it away if logging is turned off.
5455 if (logging::LOG_INFO < logging::GetMinLogLevel())
5456 return;
5457
5458 DCHECK(state);
5459 DCHECK(ds);
5460 GURL url(ds->request().url());
5461 Time start = state->start_load_time();
5462 Time finish = state->finish_load_time();
5463 // TODO(mbelshe): should we log more stats?
5464 LOG(INFO) << "PLT: "
5465 << (finish - start).InMilliseconds()
5466 << "ms "
5467 << url.spec();
5468}
5469
[email protected]cc0445f2009-10-13 16:09:085470void RenderView::focusAccessibilityObject(
5471 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:065472#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:155473 // TODO(dglazkov): Current logic implies that focus change can only be made
5474 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5475 // where accessibility is initialized. We should determine whether that's
5476 // right.
5477 if (!accessibility_.get())
5478 return;
[email protected]e846d0d2009-05-20 00:53:065479
5480 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:155481 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:065482
5483 // If id is valid, alert the browser side that an accessibility focus change
5484 // occurred.
5485 if (acc_obj_id >= 0)
5486 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
5487
5488#else // defined(OS_WIN)
5489 // TODO(port): accessibility not yet implemented
5490 NOTIMPLEMENTED();
5491#endif
5492}
[email protected]daa8c58e2009-06-15 17:21:105493
[email protected]9892b472010-09-16 00:23:425494void RenderView::postAccessibilityNotification(
5495 const WebAccessibilityObject& obj,
5496 WebAccessibilityNotification notification) {
5497 if (!accessibility_.get() || (accessibility_->addOrGetId(obj) < 0))
[email protected]a3018be2010-03-09 04:28:485498 return;
5499
[email protected]9892b472010-09-16 00:23:425500 ViewHostMsg_AccessibilityNotification_Params param;
5501 switch (notification) {
5502 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
5503 param.notification_type =
5504 ViewHostMsg_AccessibilityNotification_Params::
5505 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
5506 break;
5507 case WebKit::WebAccessibilityNotificationChildrenChanged:
5508 param.notification_type =
5509 ViewHostMsg_AccessibilityNotification_Params::
5510 NOTIFICATION_TYPE_CHILDREN_CHANGED;
5511 break;
5512 case WebKit::WebAccessibilityNotificationValueChanged:
5513 param.notification_type =
5514 ViewHostMsg_AccessibilityNotification_Params::
5515 NOTIFICATION_TYPE_VALUE_CHANGED;
5516 break;
5517 default:
5518 return;
5519 }
5520 param.acc_obj = WebAccessibility(obj, accessibility_.get());
[email protected]a3018be2010-03-09 04:28:485521
[email protected]9892b472010-09-16 00:23:425522 if (pending_accessibility_notifications_.empty()) {
5523 Send(new ViewHostMsg_AccessibilityNotifications(
5524 routing_id_,
5525 pending_accessibility_notifications_));
[email protected]520cb7d72010-08-31 11:54:315526 }
5527
[email protected]9892b472010-09-16 00:23:425528 pending_accessibility_notifications_.push_back(param);
[email protected]520cb7d72010-08-31 11:54:315529}
5530
[email protected]0fda7272009-06-26 15:49:335531void RenderView::Print(WebFrame* frame, bool script_initiated) {
5532 DCHECK(frame);
5533 if (print_helper_.get() == NULL) {
5534 print_helper_.reset(new PrintWebViewHelper(this));
5535 }
5536 print_helper_->Print(frame, script_initiated);
5537}
[email protected]446705872009-09-10 07:22:485538
5539void RenderView::OnSetEditCommandsForNextKeyEvent(
5540 const EditCommands& edit_commands) {
5541 edit_commands_ = edit_commands;
5542}
5543
[email protected]61f5a7b2009-12-22 22:21:205544void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275545 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355546 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205547 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5548 false));
[email protected]912256b32009-09-18 09:47:355549 return;
5550 }
5551
[email protected]fa7b6b542009-11-03 05:02:305552 WebDataSource* ds = main_frame->dataSource();
5553 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5554 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205555 pending_code_execution_queue_.push(
5556 linked_ptr<ViewMsg_ExecuteCode_Params>(
5557 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305558 return;
5559 }
5560
[email protected]61f5a7b2009-12-22 22:21:205561 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305562}
5563
5564void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205565 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485566 // Don't execute scripts in gallery pages.
5567 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085568 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5569 && !CommandLine::ForCurrentProcess()->HasSwitch(
5570 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485571 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5572 return;
5573 }
5574
[email protected]20ad2692009-11-20 18:27:205575 std::vector<WebFrame*> frame_vector;
5576 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205577 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205578 GetAllChildFrames(frame, &frame_vector);
5579
5580 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5581 frame_it != frame_vector.end(); ++frame_it) {
5582 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205583 if (params.is_javascript) {
5584 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5585 continue;
5586
[email protected]20ad2692009-11-20 18:27:205587 std::vector<WebScriptSource> sources;
5588 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205589 WebScriptSource(WebString::fromUTF8(params.code)));
5590 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205591 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205592 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205593 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5594 } else {
[email protected]61f5a7b2009-12-22 22:21:205595 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205596 }
[email protected]912256b32009-09-18 09:47:355597 }
5598
[email protected]61f5a7b2009-12-22 22:21:205599 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355600}
5601
[email protected]60c42a8c72009-10-09 04:08:595602void RenderView::Close() {
5603 // We need to grab a pointer to the doomed WebView before we destroy it.
5604 WebView* doomed = webview();
5605 RenderWidget::Close();
5606 Singleton<ViewMap>::get()->erase(doomed);
5607}
5608
[email protected]446705872009-09-10 07:22:485609void RenderView::DidHandleKeyEvent() {
5610 edit_commands_.clear();
5611}
5612
[email protected]6a8ddba52010-09-05 04:38:065613void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
5614 page_click_tracker_->DidHandleMouseEvent(event);
5615}
5616
[email protected]941e4552010-02-01 21:23:435617#if defined(OS_MACOSX)
5618void RenderView::OnWasHidden() {
5619 RenderWidget::OnWasHidden();
5620
5621 // Inform plugins that their container is no longer visible.
5622 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5623 for (plugin_it = plugin_delegates_.begin();
5624 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5625 (*plugin_it)->SetContainerVisibility(false);
5626 }
5627}
5628
5629void RenderView::OnWasRestored(bool needs_repainting) {
5630 RenderWidget::OnWasRestored(needs_repainting);
5631
5632 // Inform plugins that their container is now visible.
5633 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5634 for (plugin_it = plugin_delegates_.begin();
5635 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5636 (*plugin_it)->SetContainerVisibility(true);
5637 }
5638}
[email protected]784ea1ab2010-09-18 00:02:345639#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135640
5641void RenderView::OnSetFocus(bool enable) {
5642 RenderWidget::OnSetFocus(enable);
5643
[email protected]7d3c02c2010-05-05 23:10:315644 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075645 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135646 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5647 for (plugin_it = plugin_delegates_.begin();
5648 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345649#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315650 // RenderWidget's call to setFocus can cause the underlying webview's
5651 // activation state to change just like a call to setIsActive.
5652 if (enable)
5653 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345654#endif
[email protected]7d3c02c2010-05-05 23:10:315655 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135656 }
[email protected]589621b2010-09-23 22:01:075657
5658 // Notify all Pepper plugins.
5659 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135660 }
5661}
[email protected]941e4552010-02-01 21:23:435662
[email protected]83dde542009-09-11 20:59:555663void RenderView::EnsureDocumentTag() {
5664 // TODO(darin): There's actually no reason for this to be here. We should
5665 // have the browser side manage the document tag.
5666#if defined(OS_MACOSX)
5667 if (!has_document_tag_) {
5668 // Make the call to get the tag.
5669 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5670 has_document_tag_ = true;
5671 }
5672#endif
5673}
[email protected]12636df2009-09-28 22:32:215674
[email protected]43f28f832010-02-03 02:28:485675#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035676gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235677 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485678 gfx::PluginWindowHandle window = NULL;
5679 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235680 routing_id(), opaque, root, &window));
[email protected]43f28f832010-02-03 02:28:485681 return window;
5682}
5683
5684void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5685 if (window)
5686 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5687}
5688
[email protected]44ce0b12010-03-12 16:45:335689void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5690 int32 width,
5691 int32 height,
5692 uint64 io_surface_identifier) {
5693 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485694 routing_id(), window, width, height, io_surface_identifier));
5695}
5696
[email protected]44ce0b12010-03-12 16:45:335697void RenderView::AcceleratedSurfaceSetTransportDIB(
5698 gfx::PluginWindowHandle window,
5699 int32 width,
5700 int32 height,
5701 TransportDIB::Handle transport_dib) {
5702 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075703 routing_id(), window, width, height, transport_dib));
5704}
5705
[email protected]44ce0b12010-03-12 16:45:335706TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5707 size_t size) {
[email protected]1aef98132010-02-23 18:00:075708 TransportDIB::Handle dib_handle;
5709 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385710 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075711 return dib_handle;
5712 // Return an invalid handle if Send() fails.
5713 return TransportDIB::DefaultHandleValue();
5714}
5715
[email protected]44ce0b12010-03-12 16:45:335716void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075717 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5718}
5719
[email protected]44ce0b12010-03-12 16:45:335720void RenderView::AcceleratedSurfaceBuffersSwapped(
5721 gfx::PluginWindowHandle window) {
5722 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485723}
5724#endif
[email protected]58c321d2010-02-19 12:11:285725
[email protected]cdaf8d02010-03-30 19:52:475726bool RenderView::ScheduleFileChooser(
5727 const ViewHostMsg_RunFileChooser_Params& params,
5728 WebFileChooserCompletion* completion) {
5729 static const size_t kMaximumPendingFileChooseRequests = 4;
5730 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5731 // This sanity check prevents too many file choose requests from getting
5732 // queued which could DoS the user. Getting these is most likely a
5733 // programming error (there are many ways to DoS the user so it's not
5734 // considered a "real" security check), either in JS requesting many file
5735 // choosers to pop up, or in a plugin.
5736 //
5737 // TODO(brettw) we might possibly want to require a user gesture to open
5738 // a file picker, which will address this issue in a better way.
5739 return false;
5740 }
5741
5742 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5743 new PendingFileChooser(params, completion)));
5744 if (file_chooser_completions_.size() == 1) {
5745 // Actually show the browse dialog when this is the first request.
5746 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5747 }
5748 return true;
5749}
5750
[email protected]290838a2010-04-27 17:37:015751void RenderView::OnPageTranslated() {
5752 WebFrame* frame = webview()->mainFrame();
5753 if (!frame)
5754 return;
5755
5756 // The page is translated, so try to extract the form data again.
[email protected]6a8ddba52010-09-05 04:38:065757 autofill_helper_->FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015758}
5759
[email protected]8a5f7002010-03-31 13:47:355760WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285761 if (!geolocation_dispatcher_.get())
5762 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5763 return geolocation_dispatcher_.get();
5764}
[email protected]61c9f032010-03-31 23:04:195765
[email protected]638694c2010-08-04 22:24:115766WebKit::WebSpeechInputController* RenderView::speechInputController(
5767 WebKit::WebSpeechInputListener* listener) {
5768 if (!speech_input_dispatcher_.get())
5769 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5770 return speech_input_dispatcher_.get();
5771}
5772
[email protected]57ead352010-08-11 14:42:535773WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
5774 if (!device_orientation_dispatcher_.get())
5775 device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this));
5776 return device_orientation_dispatcher_.get();
5777}
5778
[email protected]8079b362010-05-07 18:37:455779bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195780 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455781 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195782 if (frame->parent() != NULL)
5783 return false;
5784
[email protected]f0a3d0b2010-08-06 22:51:535785 // Navigations initiated within Webkit are not sent out to the external host
5786 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275787 // 1. The url scheme is not http/https
5788 // 2. There is no opener and this is not the first url being opened by this
5789 // RenderView.
5790 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535791 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535792 // 4. Reloads/form submits/back forward navigations
5793 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5794 return false;
5795
[email protected]d0ed50d2010-06-22 01:01:325796 // Not interested in reloads.
5797 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015798 type != WebKit::WebNavigationTypeFormSubmitted &&
5799 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325800 // The opener relationship between the new window and the parent allows the
5801 // new window to script the parent and vice versa. This is not allowed if
5802 // the origins of the two domains are different. This can be treated as a
5803 // top level navigation and routed back to the host.
5804 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275805 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475806 // Force link click navigations to always be routed to the host as they
5807 // may update session state on the server.
5808 if (type == WebKit::WebNavigationTypeLinkClicked)
5809 return true;
[email protected]900eb2f12010-08-23 22:36:275810 // If this is the first page being loaded by this RenderView instance then
5811 // it should stay here.
5812 if (page_id_ == -1) {
5813 return false;
5814 } else {
[email protected]d0ed50d2010-06-22 01:01:325815 return true;
[email protected]900eb2f12010-08-23 22:36:275816 }
[email protected]d0ed50d2010-06-22 01:01:325817 }
[email protected]900eb2f12010-08-23 22:36:275818
5819 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5820 return true;
[email protected]d0ed50d2010-06-22 01:01:325821 }
[email protected]61c9f032010-03-31 23:04:195822 return false;
5823}
[email protected]2b06a992010-08-21 05:48:225824
5825void RenderView::OnOpenFileSystemRequestComplete(
5826 int request_id, bool accepted, const string16& name,
5827 const string16& root_path) {
5828 PendingOpenFileSystem* request = pending_file_system_requests_.Lookup(
5829 request_id);
5830 DCHECK(request);
5831 if (accepted)
5832 request->callbacks->didOpenFileSystem(name, root_path);
5833 else
5834 request->callbacks->didFail(WebKit::WebFileErrorSecurity);
5835 request->callbacks = NULL;
5836 pending_file_system_requests_.Remove(request_id);
5837}
[email protected]27a9ef32010-09-10 04:06:245838
5839void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5840 IPC::PlatformFileForTransit file_for_transit,
5841 int message_id) {
5842 pepper_delegate_.OnAsyncFileOpened(
5843 error_code,
5844 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5845 message_id);
5846}