blob: 919ee4ced09a89f17312de2ecca958e0c5d99945 [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]be1ce6a72010-08-03 14:35:2224#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5725#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2126#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2830#include "chrome/common/chrome_paths.h"
31#include "chrome/common/chrome_switches.h"
[email protected]a0cf04a2010-06-23 03:29:5532#include "chrome/common/extensions/extension.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2134#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1735#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5336#include "chrome/common/pepper_plugin_registry.h"
[email protected]851b1eb2010-08-09 13:32:2937#include "chrome/common/plugin_group.h"
[email protected]e09ba552009-02-05 03:26:2938#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2639#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5941#include "chrome/common/url_constants.h"
[email protected]534c66c2010-04-28 22:53:1142#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2943#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2544#include "chrome/renderer/audio_message_filter.h"
[email protected]00152e92010-07-19 11:47:4045#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5346#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1147#include "chrome/renderer/devtools_agent.h"
48#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3549#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3250#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3551#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3752#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2853#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2954#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5655#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4156#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]8400e032010-02-26 18:50:1157#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5658#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1259#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3060#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5061#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2562#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2863#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2664#include "chrome/renderer/render_view_visitor.h"
[email protected]035545f2010-04-09 13:10:2165#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3466#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]638694c2010-08-04 22:24:1167#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4668#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3569#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2970#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2971#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2972#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4273#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5674#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1575#include "gfx/color_utils.h"
76#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5777#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2678#include "gfx/point.h"
79#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2780#include "grit/generated_resources.h"
81#include "grit/renderer_resources.h"
[email protected]ee68378a2010-08-10 01:05:4182#include "media/base/media_switches.h"
[email protected]f11ca0732009-04-11 00:09:3483#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2984#include "net/base/escape.h"
85#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0086#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1087#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3088#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:0689#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4990#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:2691#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0792#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4993#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3295#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4996#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3597#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]1c99edc2010-08-11 17:36:3298#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]b1438212010-04-03 00:30:5999#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49100#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41103#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50104#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49105#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32106#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07107#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49108#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40109#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17110#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49111#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49112#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
113#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
114#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
115#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
116#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
117#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40118#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49119#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34120#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49121#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
122#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
123#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
124#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
125#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
126#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26127#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11128#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04129#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]996e88a52010-08-12 17:48:54130#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29131#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59132#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24133#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24134#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34135#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26136#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17137#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51138#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09139#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26140#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38141#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17142#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29143#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30144#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23145#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30146#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40147#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09148#include "webkit/glue/site_isolation_metrics.h"
[email protected]1c99edc2010-08-11 17:36:32149#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29150#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29151#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17152#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29153
[email protected]6c8afae52009-01-22 02:24:57154#if defined(OS_WIN)
155// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57156// * theming
[email protected]cd818412010-03-19 03:23:15157#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03158#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46159#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33160#elif defined(OS_MACOSX)
161#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57162#endif
163
[email protected]80f584d92010-01-21 03:59:04164using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26165using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33166using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45167using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59168using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24169using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17170using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56171using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10172using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09173using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15174using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08175using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21176using WebKit::WebApplicationCacheHost;
177using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41178using WebKit::WebColor;
179using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59180using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44181using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51182using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07183using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55184using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28185using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29186using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00187using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58188using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25189using WebKit::WebDragOperation;
190using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51191using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47192using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49193using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59194using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48195using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45196using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17197using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41198using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50199using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17200using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28201using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17202using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28203using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28204using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51205using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07206using WebKit::WebPageSerializer;
207using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17208using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40209using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49210using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09211using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52212using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59213using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51214using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52215using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40216using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35217using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29218using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59219using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42220using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02221using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34222using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28223using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51224using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52225using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28226using WebKit::WebURL;
227using WebKit::WebURLError;
228using WebKit::WebURLRequest;
229using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28230using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03231using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28232using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43233using WebKit::WebWorker;
234using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11235using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33236
initial.commit09911bf2008-07-26 23:55:29237//-----------------------------------------------------------------------------
238
[email protected]3354d3e2010-06-10 19:53:02239typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
240
initial.commit09911bf2008-07-26 23:55:29241// define to write the time necessary for thumbnail/DOM text retrieval,
242// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29243// #define TIME_TEXT_RETRIEVAL
244
245// maximum number of characters in the document to index, any text beyond this
246// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57247static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29248
249// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37250static const int kThumbnailWidth = 212;
251static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29252
253// Delay in milliseconds that we'll wait before capturing the page contents
254// and thumbnail.
255static const int kDelayForCaptureMs = 500;
256
257// Typically, we capture the page data once the page is loaded.
258// Sometimes, the page never finishes to load, preventing the page capture
259// To workaround this problem, we always perform a capture after the following
260// delay.
261static const int kDelayForForcedCaptureMs = 6000;
262
[email protected]882daa92009-11-05 16:31:31263// Time, in seconds, we delay before sending content state changes (such as form
264// state and scroll position) to the browser. We delay sending changes to avoid
265// spamming the browser.
266// To avoid having tab/session restore require sending a message to get the
267// current content state during tab closing we use a shorter timeout for the
268// foreground renderer. This means there is a small window of time from which
269// content state is modified and not sent to session restore, but this is
270// better than having to wake up all renderers during shutdown.
271static const int kDelaySecondsForContentStateSyncHidden = 5;
272static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29273
[email protected]0aa55312008-10-17 21:53:08274// The maximum number of popups that can be spawned from one page.
275static const int kMaximumNumberOfUnacknowledgedPopups = 25;
276
initial.commit09911bf2008-07-26 23:55:29277static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16278 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29279
[email protected]50b691c2008-10-31 19:08:35280static const char* const kBackForwardNavigationScheme = "history";
281
[email protected]726985e22009-06-18 21:09:28282static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
283 WebVector<WebURL> urls;
284 ds->redirectChain(urls);
285 result->reserve(urls.size());
286 for (size_t i = 0; i < urls.size(); ++i)
287 result->push_back(urls[i]);
288}
289
[email protected]61f5a7b2009-12-22 22:21:20290static bool UrlMatchesPermissions(
291 const GURL& url, const std::vector<URLPattern>& host_permissions) {
292 for (size_t i = 0; i < host_permissions.size(); ++i) {
293 if (host_permissions[i].MatchesUrl(url))
294 return true;
295 }
296
297 return false;
298}
299
[email protected]30507922010-01-15 16:48:23300static bool PaintViewIntoCanvas(WebView* view,
301 skia::PlatformCanvas& canvas) {
302 view->layout();
303 const WebSize& size = view->size();
304
305 if (!canvas.initialize(size.width, size.height, true))
306 return false;
307
308 view->paint(webkit_glue::ToWebCanvas(&canvas),
309 WebRect(0, 0, size.width, size.height));
310 // TODO: Add a way to snapshot the whole page, not just the currently
311 // visible part.
312
313 return true;
314}
315
316// Calculates how "boring" a thumbnail is. The boring score is the
317// 0,1 ranged percentage of pixels that are the most common
318// luma. Higher boring scores indicate that a higher percentage of a
319// bitmap are all the same brightness.
320static double CalculateBoringScore(SkBitmap* bitmap) {
321 int histogram[256] = {0};
322 color_utils::BuildLumaHistogram(bitmap, histogram);
323
324 int color_count = *std::max_element(histogram, histogram + 256);
325 int pixel_count = bitmap->width() * bitmap->height();
326 return static_cast<double>(color_count) / pixel_count;
327}
328
[email protected]12bc8472010-04-15 07:29:40329// True if |frame| contains content that is white-listed for content settings.
330static bool IsWhitelistedForContentSettings(WebFrame* frame) {
331 WebSecurityOrigin origin = frame->securityOrigin();
332 if (origin.isEmpty())
333 return false; // Uninitialized document?
334
335 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
336 return true; // Browser UI elements should still work.
337
338 // If the scheme is ftp: or file:, an empty file name indicates a directory
339 // listing, which requires JavaScript to function properly.
340 GURL frame_url = frame->url();
341 const char* kDirProtocols[] = { "ftp", "file" };
342 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
343 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
344 return frame_url.SchemeIs(kDirProtocols[i]) &&
345 frame_url.ExtractFileName().empty();
346 }
347 }
348
349 return false;
350}
351
[email protected]3a8eecb2010-04-22 23:56:30352// Returns true if the frame is navigating to an URL either into or out of an
353// extension app's extent.
354static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
355 if (!RenderThread::current())
356 return false;
357
358 // If the URL is still empty, this is a window.open navigation. Check the
359 // opener's URL.
360 GURL old_url(frame->url());
361 if (old_url.is_empty() && frame->opener())
362 old_url = frame->opener()->url();
363
364 std::string old_extension =
[email protected]4fdbc1492010-07-01 01:20:59365 RenderThread::current()->GetExtensionIdByURL(old_url);
366 if (!old_extension.empty()) {
367 if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) ==
368 old_extension) {
369 return false;
370 }
371 }
372
[email protected]3a8eecb2010-04-22 23:56:30373 std::string new_extension =
[email protected]4fdbc1492010-07-01 01:20:59374 RenderThread::current()->GetExtensionIdByURL(new_url);
375 return old_extension != new_extension;
[email protected]3a8eecb2010-04-22 23:56:30376}
377
[email protected]3354d3e2010-06-10 19:53:02378// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
379// if it failed.
380//
381// Note this only works on Windows at this time. It always returns 'unknown'
382// on other platforms.
[email protected]e5106202010-06-11 21:12:36383static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17384 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02385 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08386 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02387 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02388 Language cld_language =
[email protected]e5106202010-06-11 21:12:36389 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08390 &num_languages, NULL, &text_bytes);
391 // We don't trust the result if the CLD reports that the detection is not
392 // reliable, or if the actual text used to detect the language was less than
393 // 100 bytes (short texts can often lead to wrong results).
394 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02395 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
396 // We should not use LanguageCode_ISO_639_1 because it does not cover all
397 // the languages CLD can detect. As a result, it'll return the invalid
398 // language code for tradtional Chinese among others.
399 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
400 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
401 // for Simplified Chinese.
402 language = LanguageCodeWithDialects(cld_language);
403 }
404 return language;
405}
406
initial.commit09911bf2008-07-26 23:55:29407///////////////////////////////////////////////////////////////////////////////
408
[email protected]60c42a8c72009-10-09 04:08:59409int32 RenderView::next_page_id_ = 1;
410
[email protected]cdaf8d02010-03-30 19:52:47411struct RenderView::PendingFileChooser {
412 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
413 WebFileChooserCompletion* c)
414 : params(p),
415 completion(c) {
416 }
417 ViewHostMsg_RunFileChooser_Params params;
418 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
419};
420
[email protected]2fab253a2009-08-17 23:00:59421RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34422 const WebPreferences& webkit_preferences,
423 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12424 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02425 webkit_preferences_(webkit_preferences),
426 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09427 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02428 send_preferred_size_changes_(false),
429 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24430 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21431 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02432 opened_by_user_gesture_(true),
433 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24434 page_id_(-1),
435 last_page_id_sent_to_browser_(-1),
436 last_indexed_page_id_(-1),
[email protected]3354d3e2010-06-10 19:53:02437 last_top_level_navigation_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00438 history_list_offset_(-1),
439 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24440 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55441#if defined(OS_MACOSX)
442 has_document_tag_(false),
443#endif
[email protected]98324892009-09-09 21:16:05444 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10445 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17446 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02447 target_url_status_(TARGET_NONE),
448 spelling_panel_visible_(false),
449 view_type_(ViewType::INVALID),
450 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18451 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30452 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
453 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02454 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]03f57072010-07-14 17:36:08455 ALLOW_THIS_IN_INITIALIZER_LIST(password_autocomplete_manager_(this)),
[email protected]679f128f2010-07-22 22:57:44456 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_helper_(this)),
[email protected]3354d3e2010-06-10 19:53:02457 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
458 ALLOW_THIS_IN_INITIALIZER_LIST(
459 notification_provider_(new NotificationProvider(this))),
460 session_storage_namespace_id_(session_storage_namespace_id),
461 decrement_shared_popup_at_destruction_(false) {
[email protected]71b0d5d2010-02-15 05:43:07462 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29463}
464
465RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08466 if (decrement_shared_popup_at_destruction_)
467 shared_popup_counter_->data--;
468
[email protected]b0950a72009-09-29 23:16:17469 // Dispose of un-disposed image fetchers.
470 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
471 i != image_fetchers_.end(); ++i) {
472 delete *i;
473 }
474
[email protected]a1128322009-10-06 18:38:46475 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47476 while (!file_chooser_completions_.empty()) {
477 if (file_chooser_completions_.front()->completion) {
478 file_chooser_completions_.front()->completion->didChooseFile(
479 WebVector<WebString>());
480 }
481 file_chooser_completions_.pop_front();
482 }
[email protected]a1128322009-10-06 18:38:46483
[email protected]83dde542009-09-11 20:59:55484#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05485 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55486 if (has_document_tag_)
487 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
488#endif
[email protected]98324892009-09-09 21:16:05489
[email protected]5fb88962009-04-16 19:03:25490 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59491
492#ifndef NDEBUG
493 // Make sure we are no longer referenced by the ViewMap.
494 ViewMap* views = Singleton<ViewMap>::get();
495 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
496 DCHECK_NE(this, it->second) << "Failed to call Close?";
497#endif
498}
499
500/*static*/
501void RenderView::ForEach(RenderViewVisitor* visitor) {
502 ViewMap* views = Singleton<ViewMap>::get();
503 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
504 if (!visitor->Visit(it->second))
505 return;
506 }
507}
508
509/*static*/
510RenderView* RenderView::FromWebView(WebView* webview) {
511 ViewMap* views = Singleton<ViewMap>::get();
512 ViewMap::iterator it = views->find(webview);
513 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29514}
515
516/*static*/
[email protected]0aa55312008-10-17 21:53:08517RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24518 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15519 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08520 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51521 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08522 const WebPreferences& webkit_prefs,
523 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34524 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26525 int64 session_storage_namespace_id,
526 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29527 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34528 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
529 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29530 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29531 opener_id,
[email protected]80d96fa2009-06-10 22:34:51532 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08533 counter,
[email protected]8ab04652010-06-12 02:47:26534 routing_id,
535 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29536 return view;
537}
538
539/*static*/
540void RenderView::SetNextPageID(int32 next_page_id) {
541 // This method should only be called during process startup, and the given
542 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05543 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29544 DCHECK(next_page_id >= next_page_id_);
545 next_page_id_ = next_page_id;
546}
547
[email protected]8a3125a712010-08-09 18:58:51548WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26549 return static_cast<WebKit::WebView*>(webwidget());
550}
551
[email protected]afe3a1672009-11-17 19:04:12552void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56553 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
554}
555
[email protected]a3a8fb6d2009-10-22 20:12:51556void RenderView::PluginCrashed(const FilePath& plugin_path) {
557 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29558}
559
[email protected]aad51d1c2010-08-05 08:38:09560WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
561 const WebPluginParams& params) {
562 WebPluginInfo info;
563 bool found;
564 std::string mime_type;
565 Send(new ViewHostMsg_GetPluginInfo(
566 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
[email protected]6b3db4352010-08-12 16:14:22567 &info, &mime_type));
[email protected]aad51d1c2010-08-05 08:38:09568 if (!found || !info.enabled)
569 return NULL;
570 scoped_refptr<pepper::PluginModule> pepper_module =
571 PepperPluginRegistry::GetInstance()->GetModule(info.path);
572 if (pepper_module)
573 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
574 else
575 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
576}
577
[email protected]d8fd6fa2010-02-01 15:54:26578#if defined(OS_MACOSX)
579void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
580 plugin_delegates_.insert(delegate);
581}
582
583void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
584 plugin_delegates_.erase(delegate);
585}
586#endif
587
[email protected]18bcc3c2009-01-27 21:39:15588void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29589 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51590 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08591 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26592 int32 routing_id,
593 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29594 DCHECK(!webview());
595
596 if (opener_id != MSG_ROUTING_NONE)
597 opener_id_ = opener_id;
598
[email protected]0aa55312008-10-17 21:53:08599 if (counter) {
600 shared_popup_counter_ = counter;
601 shared_popup_counter_->data++;
602 decrement_shared_popup_at_destruction_ = true;
603 } else {
604 shared_popup_counter_ = new SharedRenderViewCounter(0);
605 decrement_shared_popup_at_destruction_ = false;
606 }
607
[email protected]58bfc6b2009-06-24 09:45:02608 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04609
[email protected]9a6c6232010-06-25 11:46:49610 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59611 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59612 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27613 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23614 if (!frame_name.empty())
615 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29616
[email protected]d3ba77272009-09-03 00:06:09617 OnSetRendererPrefs(renderer_prefs);
618
initial.commit09911bf2008-07-26 23:55:29619 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24620 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29621 // Take a reference on behalf of the RenderThread. This will be balanced
622 // when we receive ViewMsg_Close.
623 AddRef();
624
625 // If this is a popup, we must wait for the CreatingNew_ACK message before
626 // completing initialization. Otherwise, we can finish it now.
627 if (opener_id == MSG_ROUTING_NONE) {
628 did_show_ = true;
629 CompleteInit(parent_hwnd);
630 }
631
632 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29633
[email protected]58bfc6b2009-06-24 09:45:02634 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09635 if (command_line.HasSwitch(switches::kDomAutomationController))
636 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29637
[email protected]5fb88962009-04-16 19:03:25638 audio_message_filter_ = new AudioMessageFilter(routing_id_);
639 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29640}
641
642void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27643 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27644 if (main_frame)
645 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26646
[email protected]b2abac72009-02-26 12:39:28647 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11648 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28649 return;
[email protected]b4b967e2009-04-22 11:33:05650 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
651 return;
[email protected]b6849bda2009-10-14 23:59:26652 if (notification_provider_->OnMessageReceived(message))
653 return;
[email protected]58c321d2010-02-19 12:11:28654 if (geolocation_dispatcher_.get() &&
655 geolocation_dispatcher_->OnMessageReceived(message)) {
656 return;
657 }
[email protected]638694c2010-08-04 22:24:11658 if (speech_input_dispatcher_.get() &&
659 speech_input_dispatcher_->OnMessageReceived(message)) {
660 return;
661 }
[email protected]57ead352010-08-11 14:42:53662 if (device_orientation_dispatcher_.get() &&
663 device_orientation_dispatcher_->OnMessageReceived(message)) {
664 return;
665 }
[email protected]b2abac72009-02-26 12:39:28666
initial.commit09911bf2008-07-26 23:55:29667 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04668 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
669 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29670 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01671 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29672 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
673 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56674 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29675 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
676 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
677 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
678 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27679#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35680 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27681#endif
initial.commit09911bf2008-07-26 23:55:29682 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
683 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05684 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
685 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
686 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04687 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29688 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
689 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
690 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15691 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29692 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49693 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
694 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17695 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54696 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
697 OnSetContentSettingsForLoadingURL)
698 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
699 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29700 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18701 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
702 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28703 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33704 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29705 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48706 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29707 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29708 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29709 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
710 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
711 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
712 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
713 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45714 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29715 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50716 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
717 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29718 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
719 OnDragSourceSystemDragEnded)
720 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29721 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
722 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
723 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
724 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:21725 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:29726 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
727 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29728 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
729 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04730 IPC_MESSAGE_HANDLER(
731 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
732 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29733 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04734 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29735 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
736 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45737 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04738 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08739 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
740 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24741 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
742 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48743 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
744 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40745 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
746 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00747 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27748 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37749 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
750 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16751 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14752 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25753 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
754 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10755 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
756 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51757 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53758 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
759 OnUpdateBrowserWindowId)
760 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
761 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56762 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34763 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14764#if defined(OS_MACOSX)
765 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13766 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14767#endif
[email protected]446705872009-09-10 07:22:48768 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33769 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35770 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
771 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33772 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
773 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42774 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02775 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09776 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36777 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
778 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
779 OnAccessibilityDoDefaultAction)
[email protected]634a6f92008-12-01 21:39:31780
initial.commit09911bf2008-07-26 23:55:29781 // Have the super handle all other messages.
782 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
783 IPC_END_MESSAGE_MAP()
784}
785
[email protected]9b18a84f2010-06-10 15:54:04786void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27787 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29788 if (!main_frame)
789 return;
790
791 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45792 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29793 if (url.is_empty())
794 return;
795
796 if (size_.IsEmpty())
797 return; // Don't create an empty thumbnail!
798
799 ThumbnailScore score;
800 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02801 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15802 &thumbnail, &score))
803 return;
804
initial.commit09911bf2008-07-26 23:55:29805 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46806 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29807}
808
[email protected]9b18a84f2010-06-10 15:54:04809void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23810 SkBitmap snapshot;
811 bool error = false;
812
813 WebFrame* main_frame = webview()->mainFrame();
814 if (!main_frame)
815 error = true;
816
817 if (!error && !CaptureSnapshot(webview(), &snapshot))
818 error = true;
819
820 DCHECK(error == snapshot.empty()) <<
821 "Snapshot should be empty on error, non-empty otherwise.";
822
823 // Send the snapshot to the browser process.
824 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
825}
826
[email protected]068637222009-01-29 16:58:07827void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29828 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58829 if (webview()) {
830 // If the user has selected text in the currently focused frame we print
831 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27832 if (webview()->focusedFrame()->hasSelection())
833 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58834 else
[email protected]26aa0482009-09-30 16:55:27835 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58836 }
initial.commit09911bf2008-07-26 23:55:29837}
838
[email protected]82270452009-06-19 15:58:01839void RenderView::OnPrintingDone(int document_cookie, bool success) {
840 // Ignoring document cookie here since only one print job can be outstanding
841 // per renderer and document_cookie is 0 when printing is successful.
842 DCHECK(print_helper_.get());
843 if (print_helper_.get() != NULL) {
844 print_helper_->DidFinishPrinting(success);
845 }
846}
847
initial.commit09911bf2008-07-26 23:55:29848void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
849 if (load_id != page_id_)
850 return; // this capture call is no longer relevant due to navigation
851 if (load_id == last_indexed_page_id_)
852 return; // we already indexed this page
853
854 if (!webview())
855 return;
856
[email protected]26aa0482009-09-30 16:55:27857 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29858 if (!main_frame)
859 return;
860
861 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45862 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29863 return;
864
865 // Don't index/capture pages that failed to load. This only checks the top
866 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45867 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28868 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29869 return;
870
871 if (!preliminary_capture)
872 last_indexed_page_id_ = load_id;
873
[email protected]a8a81292010-01-21 00:32:45874 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45875 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29876 if (url.is_empty())
877 return;
878
[email protected]a8a81292010-01-21 00:32:45879 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36880 string16 contents;
initial.commit09911bf2008-07-26 23:55:29881 CaptureText(main_frame, &contents);
882 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45883 base::TimeTicks begin_time = base::TimeTicks::Now();
884 std::string language = DetermineTextLanguage(contents);
885 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
886 base::TimeTicks::Now() - begin_time);
[email protected]1c57b7b2010-07-12 17:38:10887 WebKit::WebDocument document = main_frame->document();
[email protected]a8a81292010-01-21 00:32:45888 // Send the text to the browser for indexing (the browser might decide not
889 // to index, if the URL is HTTPS for instance) and language discovery.
890 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
[email protected]1c57b7b2010-07-12 17:38:10891 language, IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27892 }
893
[email protected]9b18a84f2010-06-10 15:54:04894 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29895}
896
[email protected]e5106202010-06-11 21:12:36897void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29898 contents->clear();
899 if (!frame)
900 return;
901
902#ifdef TIME_TEXT_RETRIEVAL
903 double begin = time_util::GetHighResolutionTimeNow();
904#endif
905
906 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36907 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29908
909#ifdef TIME_TEXT_RETRIEVAL
910 double end = time_util::GetHighResolutionTimeNow();
911 char buf[128];
912 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
913 contents.size(), (end - begin)*1000);
914 OutputDebugStringA(buf);
915#endif
916
917 // When the contents are clipped to the maximum, we don't want to have a
918 // partial word indexed at the end that might have been clipped. Therefore,
919 // terminate the string at the last space to ensure no words are clipped.
920 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36921 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29922 if (last_space_index == std::wstring::npos)
923 return; // don't index if we got a huge block of text with no spaces
924 contents->resize(last_space_index);
925 }
926}
927
[email protected]8649fb32009-06-26 17:51:02928bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29929 int w,
930 int h,
931 SkBitmap* thumbnail,
932 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23933 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15934
[email protected]8649fb32009-06-26 17:51:02935 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23936
937 // Paint |view| into |canvas|.
938 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02939 return false;
[email protected]8649fb32009-06-26 17:51:02940
941 skia::BitmapPlatformDevice& device =
942 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
943
944 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29945
[email protected]cab34d6a2009-09-24 01:14:52946 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29947 float dest_aspect = dest_rect.width() / dest_rect.height();
948
949 // Get the src rect so that we can preserve the aspect ratio while filling
950 // the destination.
951 SkIRect src_rect;
952 if (src_bmp.width() < dest_rect.width() ||
953 src_bmp.height() < dest_rect.height()) {
954 // Source image is smaller: we clip the part of source image within the
955 // dest rect, and then stretch it to fill the dest rect. We don't respect
956 // the aspect ratio in this case.
957 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
958 static_cast<S16CPU>(dest_rect.height()));
959 score->good_clipping = false;
960 } else {
961 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
962 if (src_aspect > dest_aspect) {
963 // Wider than tall, clip horizontally: we center the smaller thumbnail in
964 // the wider screen.
965 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
966 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
967 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
968 score->good_clipping = false;
969 } else {
970 src_rect.set(0, 0, src_bmp.width(),
971 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
972 score->good_clipping = true;
973 }
974 }
975
[email protected]26aa0482009-09-30 16:55:27976 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29977
978 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02979 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29980
981 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14982 *thumbnail = skia::ImageOperations::Resize(
983 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29984
985 score->boring_score = CalculateBoringScore(thumbnail);
986
[email protected]30507922010-01-15 16:48:23987 HISTOGRAM_TIMES("Renderer4.Thumbnail",
988 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15989 return true;
initial.commit09911bf2008-07-26 23:55:29990}
991
[email protected]30507922010-01-15 16:48:23992bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
993 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29994
[email protected]30507922010-01-15 16:48:23995 skia::PlatformCanvas canvas;
996 if (!PaintViewIntoCanvas(view, canvas))
997 return false;
998
999 skia::BitmapPlatformDevice& device =
1000 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1001
1002 const SkBitmap& bitmap = device.accessBitmap(false);
1003 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1004 return false;
1005
1006 HISTOGRAM_TIMES("Renderer4.Snapshot",
1007 base::TimeTicks::Now() - beginning_time);
1008 return true;
initial.commit09911bf2008-07-26 23:55:291009}
1010
1011void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1012 if (!webview())
1013 return;
1014
[email protected]3cc72b12010-03-18 23:03:001015 history_list_offset_ = params.current_history_list_offset;
1016 history_list_length_ = params.current_history_list_length;
1017
[email protected]8c785c62009-07-13 14:20:151018 if (devtools_agent_.get())
1019 devtools_agent_->OnNavigate();
1020
[email protected]422197532010-01-25 17:38:231021 if (notification_provider_.get())
1022 notification_provider_->OnNavigate();
1023
[email protected]a9f607e2009-10-23 19:59:271024 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261025
initial.commit09911bf2008-07-26 23:55:291026 AboutHandler::MaybeHandle(params.url);
1027
[email protected]ecbf10d2010-02-18 13:03:291028 bool is_reload =
1029 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1030 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291031
[email protected]26aa0482009-09-30 16:55:271032 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451033 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291034 // We cannot reload if we do not have any history state. This happens, for
1035 // example, when recovering from a crash. Our workaround here is a bit of
1036 // a hack since it means that reload after a crashed tab does not cause an
1037 // end-to-end cache validation.
1038 is_reload = false;
1039 }
1040
[email protected]77f17a82009-05-21 04:42:541041 // A navigation resulting from loading a javascript URL should not be treated
1042 // as a browser initiated event. Instead, we want it to look as if the page
1043 // initiated any load resulting from JS execution.
1044 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301045 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001046 params.page_id,
1047 params.pending_history_list_offset,
1048 params.transition,
1049 params.request_time);
[email protected]5e369672009-11-03 23:48:301050 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1051 // We're doing a load of a page that was restored from the last session.
1052 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1053 // which can result in stale data for pages that are set to expire. We
1054 // explicitly override that by setting the policy here so that as
1055 // necessary we load from the network.
1056 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1057 }
1058 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541059 }
initial.commit09911bf2008-07-26 23:55:291060
[email protected]a7ccc4d2010-01-27 08:14:481061 NavigationState* navigation_state = pending_navigation_state_.get();
1062
[email protected]04d3c6e2009-05-22 17:00:131063 // If we are reloading, then WebKit will use the history state of the current
1064 // page, so we should just ignore any given history state. Otherwise, if we
1065 // have history state, then we need to navigate to it, which corresponds to a
1066 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551067 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481068 if (navigation_state)
1069 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291070 bool ignore_cache = (params.navigation_type ==
1071 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1072 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551073 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131074 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581075 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481076 if (navigation_state)
1077 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451078 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171079 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131080 } else {
1081 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281082 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291083
[email protected]e6f546c32009-07-01 17:12:551084 // A session history navigation should have been accompanied by state.
1085 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131086
[email protected]dd7daa82009-08-10 05:46:451087 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551088 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131089
[email protected]726985e22009-06-18 21:09:281090 if (params.referrer.is_valid()) {
1091 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1092 WebString::fromUTF8(params.referrer.spec()));
1093 }
[email protected]04d3c6e2009-05-22 17:00:131094
[email protected]a7ccc4d2010-01-27 08:14:481095 if (navigation_state)
1096 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451097 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501098 }
1099
[email protected]77f17a82009-05-21 04:42:541100 // In case LoadRequest failed before DidCreateDataSource was called.
1101 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291102}
1103
1104// Stop loading the current page
1105void RenderView::OnStop() {
1106 if (webview())
[email protected]b4bb2502009-10-01 22:35:271107 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291108}
1109
[email protected]ecbf10d2010-02-18 13:03:291110// Reload current focused frame.
1111// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561112void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291113 if (webview() && webview()->focusedFrame()) {
1114 // We always obey the cache (ignore_cache=false) here.
1115 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1116 // a cache-ignoring reload of the frame.
1117 webview()->focusedFrame()->reload(false);
1118 }
[email protected]1dda4022010-01-28 18:24:561119}
1120
initial.commit09911bf2008-07-26 23:55:291121void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271122 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291123}
1124
[email protected]68b1e922009-06-23 16:00:251125void RenderView::OnExecuteEditCommand(const std::string& name,
1126 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271127 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251128 return;
1129
[email protected]26aa0482009-09-30 16:55:271130 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451131 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251132}
1133
[email protected]b2abac72009-02-26 12:39:281134void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111135 DCHECK(!devtools_client_.get());
1136 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281137}
1138
initial.commit09911bf2008-07-26 23:55:291139void RenderView::OnUpdateTargetURLAck() {
1140 // Check if there is a targeturl waiting to be sent.
1141 if (target_url_status_ == TARGET_PENDING) {
1142 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1143 pending_target_url_));
1144 }
1145
1146 target_url_status_ = TARGET_NONE;
1147}
1148
1149void RenderView::OnUndo() {
1150 if (!webview())
1151 return;
1152
[email protected]26aa0482009-09-30 16:55:271153 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121154 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291155}
1156
1157void RenderView::OnRedo() {
1158 if (!webview())
1159 return;
1160
[email protected]26aa0482009-09-30 16:55:271161 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121162 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291163}
1164
1165void RenderView::OnCut() {
1166 if (!webview())
1167 return;
1168
[email protected]26aa0482009-09-30 16:55:271169 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121170 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291171}
1172
1173void RenderView::OnCopy() {
1174 if (!webview())
1175 return;
1176
[email protected]26aa0482009-09-30 16:55:271177 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121178 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291179}
1180
[email protected]c0cc3092009-09-12 08:27:271181#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351182void RenderView::OnCopyToFindPboard() {
1183 if (!webview())
1184 return;
1185
1186 // Since the find pasteboard supports only plain text, this can be simpler
1187 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271188 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351189 if (frame->hasSelection()) {
1190 string16 selection = frame->selectionAsText();
1191 RenderThread::current()->Send(
1192 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1193 }
1194
[email protected]afe3a1672009-11-17 19:04:121195 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351196}
[email protected]c0cc3092009-09-12 08:27:271197#endif
[email protected]a954bf72009-09-12 07:30:351198
initial.commit09911bf2008-07-26 23:55:291199void RenderView::OnPaste() {
1200 if (!webview())
1201 return;
1202
[email protected]26aa0482009-09-30 16:55:271203 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121204 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291205}
1206
[email protected]2a3a7762009-10-19 19:17:321207void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291208 if (!webview())
1209 return;
1210
[email protected]1ff7a032010-02-03 02:46:031211 WebFrame* frame = webview()->focusedFrame();
1212 if (!frame->hasSelection())
1213 frame->selectWordAroundCaret();
1214 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291215}
1216
[email protected]98324892009-09-09 21:16:051217void RenderView::OnAdvanceToNextMisspelling() {
1218 if (!webview())
1219 return;
[email protected]26aa0482009-09-30 16:55:271220 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051221 WebString::fromUTF8("AdvanceToNextMisspelling"));
1222}
1223
1224void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1225 if (!webview())
1226 return;
1227 // We need to tell the webView whether the spelling panel is visible or not so
1228 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261229 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271230 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051231 WebString::fromUTF8("ToggleSpellPanel"));
1232}
1233
[email protected]bbbd545c2008-12-15 20:18:041234void RenderView::OnToggleSpellCheck() {
1235 if (!webview())
1236 return;
1237
[email protected]26aa0482009-09-30 16:55:271238 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451239 frame->enableContinuousSpellChecking(
1240 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041241}
1242
initial.commit09911bf2008-07-26 23:55:291243void RenderView::OnDelete() {
1244 if (!webview())
1245 return;
1246
[email protected]26aa0482009-09-30 16:55:271247 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121248 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291249}
1250
1251void RenderView::OnSelectAll() {
1252 if (!webview())
1253 return;
1254
[email protected]26aa0482009-09-30 16:55:271255 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221256 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121257 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291258}
1259
1260void RenderView::OnSetInitialFocus(bool reverse) {
1261 if (!webview())
1262 return;
[email protected]26aa0482009-09-30 16:55:271263 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291264}
1265
1266///////////////////////////////////////////////////////////////////////////////
1267
[email protected]433819d2010-01-30 20:20:011268void RenderView::SetContentSettings(const ContentSettings& settings) {
1269 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011270}
1271
initial.commit09911bf2008-07-26 23:55:291272// Tell the embedding application that the URL of the active page has changed
1273void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451274 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291275 DCHECK(ds);
1276
[email protected]726985e22009-06-18 21:09:281277 const WebURLRequest& request = ds->request();
1278 const WebURLRequest& original_request = ds->originalRequest();
1279 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291280
[email protected]daa8c58e2009-06-15 17:21:101281 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1282 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291283
1284 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281285 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291286 params.is_post = false;
1287 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281288 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551289 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291290 // SSL state specified in the request takes precedence over the one in the
1291 // response.
1292 // So far this is only intended for error pages that are not expected to be
1293 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281294 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551295 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291296 } else {
[email protected]726985e22009-06-18 21:09:281297 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291298 }
1299
1300 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281301 if (ds->hasUnreachableURL()) {
1302 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291303 } else {
[email protected]726985e22009-06-18 21:09:281304 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291305 }
1306
[email protected]726985e22009-06-18 21:09:281307 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241308 params.should_update_history = !ds->hasUnreachableURL() &&
1309 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291310
[email protected]ce0e250d2009-10-23 21:00:351311 params.searchable_form_url = navigation_state->searchable_form_url();
1312 params.searchable_form_encoding =
1313 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291314
1315 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101316 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291317 if (password_form_data)
1318 params.password_form = *password_form_data;
1319
1320 params.gesture = navigation_gesture_;
1321 navigation_gesture_ = NavigationGestureUnknown;
1322
[email protected]dd7daa82009-08-10 05:46:451323 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291324 // Top-level navigation.
1325
[email protected]71b0d5d2010-02-15 05:43:071326 // Clear "block" flags for the new page. This needs to happen before any of
1327 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1328 // so that these functions can correctly detect that a piece of content
1329 // flipped from "not blocked" to "blocked".
1330 ClearBlockedContentSettings();
1331
[email protected]62d2a112010-04-07 00:53:021332 // Set content settings. Default them from the parent window if one exists.
1333 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011334 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541335 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011336 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011337 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011338
1339 // These content settings were merely recorded transiently for this load.
1340 // We can erase them now. If at some point we reload this page, the
1341 // browser will send us new, up-to-date content settings.
1342 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401343 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101344 // The opener's view is not guaranteed to be non-null (it could be
1345 // detached from its page but not yet destructed).
1346 if (WebView* opener_view = frame->opener()->view()) {
1347 RenderView* opener = FromWebView(opener_view);
1348 SetContentSettings(opener->current_content_settings_);
1349 }
[email protected]f85f0702010-01-30 09:31:011350 }
1351
[email protected]40bd6582009-12-04 23:49:511352 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011353 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541354 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011355 if (host_zoom != host_zoom_levels_.end()) {
1356 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511357 // This zoom level was merely recorded transiently for this load. We can
1358 // erase it now. If at some point we reload this page, the browser will
1359 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011360 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511361 }
1362
initial.commit09911bf2008-07-26 23:55:291363 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551364 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291365
[email protected]daa8c58e2009-06-15 17:21:101366 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291367 if (!PageTransition::IsMainFrame(params.transition)) {
1368 // If the main frame does a load, it should not be reported as a subframe
1369 // navigation. This can occur in the following case:
1370 // 1. You're on a site with frames.
1371 // 2. You do a subframe navigation. This is stored with transition type
1372 // MANUAL_SUBFRAME.
1373 // 3. You navigate to some non-frame site, say, google.com.
1374 // 4. You navigate back to the page from step 2. Since it was initially
1375 // MANUAL_SUBFRAME, it will be that same transition type here.
1376 // We don't want that, because any navigation that changes the toplevel
1377 // frame should be tracked as a toplevel navigation (this allows us to
1378 // update the URL bar, etc).
1379 params.transition = PageTransition::LINK;
1380 }
1381
initial.commit09911bf2008-07-26 23:55:291382 // If we have a valid consumed client redirect source,
1383 // the page contained a client redirect (meta refresh, document.loc...),
1384 // so we set the referrer and transition to match.
1385 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041386 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291387 params.referrer = completed_client_redirect_src_;
1388 params.transition = static_cast<PageTransition::Type>(
1389 params.transition | PageTransition::CLIENT_REDIRECT);
1390 } else {
1391 // Bug 654101: the referrer will be empty on https->http transitions. It
1392 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281393 params.referrer = GURL(
1394 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291395 }
1396
[email protected]726985e22009-06-18 21:09:281397 string16 method = request.httpMethod();
1398 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291399 params.is_post = true;
1400
[email protected]c2a797d2009-09-21 16:46:321401 // Save some histogram data so we can compute the average memory used per
1402 // page load of the glyphs.
1403 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1404 webkit_glue::GetGlyphPageCount());
1405
[email protected]15cf526b2010-02-12 06:33:491406 // This message needs to be sent before any of allowScripts(),
1407 // allowImages(), allowPlugins() is called for the new page, so that when
1408 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1409 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291410 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1411 } else {
1412 // Subframe navigation: the type depends on whether this navigation
1413 // generated a new session history entry. When they do generate a session
1414 // history entry, it means the user initiated the navigation and we should
1415 // mark it as such. This test checks if this is the first time UpdateURL
1416 // has been called since WillNavigateToURL was called to initiate the load.
1417 if (page_id_ > last_page_id_sent_to_browser_)
1418 params.transition = PageTransition::MANUAL_SUBFRAME;
1419 else
1420 params.transition = PageTransition::AUTO_SUBFRAME;
1421
initial.commit09911bf2008-07-26 23:55:291422 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1423 }
1424
1425 last_page_id_sent_to_browser_ =
1426 std::max(last_page_id_sent_to_browser_, page_id_);
1427
1428 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101429 // we don't want the transition type to persist. Just clear it.
1430 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501431
[email protected]c7287a92009-11-04 20:06:151432 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091433 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351434 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501435 }
initial.commit09911bf2008-07-26 23:55:291436}
1437
1438// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171439void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291440 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171441 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171442 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171443 routing_id_,
1444 page_id_,
1445 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1446 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171447 }
initial.commit09911bf2008-07-26 23:55:291448}
1449
1450void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401451 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291452 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271453 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291454 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301455 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291456 last_encoding_name_ = encoding_name;
1457
[email protected]e38f40152008-09-12 23:08:301458 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291459 }
1460}
1461
[email protected]f4d34b52008-11-24 23:05:011462// Sends the previous session history state to the browser so it will be saved
1463// before we navigate to a new page. This must be called *before* the page ID
1464// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291465void RenderView::UpdateSessionHistory(WebFrame* frame) {
1466 // If we have a valid page ID at this point, then it corresponds to the page
1467 // we are navigating away from. Otherwise, this is the first navigation, so
1468 // there is no past session history to record.
1469 if (page_id_ == -1)
1470 return;
1471
[email protected]ca948a22009-06-25 19:36:171472 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271473 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171474 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291475 return;
[email protected]ca948a22009-06-25 19:36:171476
1477 Send(new ViewHostMsg_UpdateState(
1478 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291479}
1480
[email protected]3d9689372009-09-10 04:29:171481void RenderView::OpenURL(
1482 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1483 Send(new ViewHostMsg_OpenURL(
1484 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1485}
1486
[email protected]79dbc662009-09-04 05:42:511487// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291488
initial.commit09911bf2008-07-26 23:55:291489void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281490 const WebURLRequest& failed_request,
1491 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291492 const std::string& html,
1493 bool replace) {
[email protected]726985e22009-06-18 21:09:281494 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291495
1496 std::string alt_html;
1497 if (html.empty()) {
1498 // Use a local error page.
1499 int resource_id;
1500 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281501 if (error.reason == net::ERR_CACHE_MISS &&
1502 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291503 GetFormRepostErrorValues(failed_url, &error_strings);
1504 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1505 } else {
1506 GetLocalizedErrorValues(error, &error_strings);
1507 resource_id = IDR_NET_ERROR_HTML;
1508 }
initial.commit09911bf2008-07-26 23:55:291509
1510 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1511 } else {
1512 alt_html = html;
1513 }
1514
[email protected]dd7daa82009-08-10 05:46:451515 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551516 GURL(kUnreachableWebDataURL),
1517 failed_url,
1518 replace);
initial.commit09911bf2008-07-26 23:55:291519}
1520
[email protected]7ccddb8c2009-08-04 17:36:551521void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291522 dom_automation_controller_.set_message_sender(this);
1523 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551524 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291525 L"domAutomationController");
1526}
1527
initial.commit09911bf2008-07-26 23:55:291528bool RenderView::RunJavaScriptMessage(int type,
1529 const std::wstring& message,
1530 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071531 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291532 std::wstring* result) {
1533 bool success = false;
1534 std::wstring result_temp;
1535 if (!result)
1536 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291537
[email protected]12636df2009-09-28 22:32:211538 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1539 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291540 return success;
1541}
1542
[email protected]c1f50aa2010-02-18 03:46:571543bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1544 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1545 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1546 // it is particularly important that we do not call willEnterModalLoop as
1547 // that would defer resource loads for the dialog itself.
1548 if (RenderThread::current()) // Will be NULL during unit tests.
1549 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1550
1551 message->EnableMessagePumping(); // Runs a nested message loop.
1552 return Send(message);
1553}
1554
initial.commit09911bf2008-07-26 23:55:291555void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1556 if (!osd_url.is_empty())
1557 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1558 autodetected));
1559}
1560
[email protected]95056b582010-02-18 01:29:241561void RenderView::OnAutoFillSuggestionsReturned(
1562 int query_id,
[email protected]8f6e6582010-04-09 02:03:071563 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391564 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411565 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391566 const std::vector<int>& unique_ids) {
[email protected]a53e06832010-07-28 22:46:411567 autofill_helper_.SuggestionsReceived(
1568 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031569}
1570
[email protected]45c6e532010-03-15 23:51:241571void RenderView::OnAutoFillFormDataFilled(int query_id,
1572 const webkit_glue::FormData& form) {
[email protected]679f128f2010-07-22 22:57:441573 autofill_helper_.FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481574}
1575
[email protected]e8345242010-05-06 03:00:401576void RenderView::OnAllowScriptToClose(bool script_can_close) {
1577 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311578}
1579
initial.commit09911bf2008-07-26 23:55:291580uint32 RenderView::GetCPBrowsingContext() {
1581 uint32 context = 0;
1582 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1583 return context;
1584}
1585
initial.commit09911bf2008-07-26 23:55:291586void RenderView::AddSearchProvider(const std::string& url) {
1587 AddGURLSearchProvider(GURL(url),
1588 false); // not autodetected
1589}
1590
[email protected]155f35e2010-07-17 00:30:181591ViewHostMsg_GetSearchProviderInstallState_Params
1592RenderView::GetSearchProviderInstallState(const std::string& url) {
1593 GURL inquiry_url = GURL(url);
1594 if (inquiry_url.is_empty())
1595 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
1596 ViewHostMsg_GetSearchProviderInstallState_Params install;
1597 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
1598 inquiry_url,
1599 &install));
1600 return install;
1601}
1602
[email protected]f103ab72009-09-02 17:10:591603void RenderView::OnMissingPluginStatus(
1604 WebPluginDelegateProxy* delegate,
1605 int status) {
[email protected]6c8afae52009-01-22 02:24:571606#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591607 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291608 // Show the InfoBar for the first available plugin.
1609 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591610 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291611 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1612 }
1613 } else {
1614 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1615 // to start the download/install.
1616 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1617 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1618 }
1619 }
[email protected]6c8afae52009-01-22 02:24:571620#else
[email protected]76c3b312010-05-20 21:38:291621 // TODO(port): Implement the infobar that accompanies the default plugin.
1622 // Linux: http://crbug.com/10952
1623 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571624 NOTIMPLEMENTED();
1625#endif
initial.commit09911bf2008-07-26 23:55:291626}
1627
[email protected]48c9cf2d2009-09-16 16:47:521628// WebKit::WebViewClient ------------------------------------------------------
1629
[email protected]8ab04652010-06-12 02:47:261630WebView* RenderView::createView(
1631 WebFrame* creator,
1632 const WebWindowFeatures& features,
1633 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521634 // Check to make sure we aren't overloading on popups.
1635 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1636 return NULL;
1637
1638 // This window can't be closed from a window.close() call until we receive a
1639 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401640 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521641
[email protected]8ab04652010-06-12 02:47:261642 ViewHostMsg_CreateWindow_Params params;
1643 params.opener_id = routing_id_;
1644 params.user_gesture = creator->isProcessingUserGesture();
1645 params.window_container_type = WindowFeaturesToContainerType(features);
1646 params.session_storage_namespace_id = session_storage_namespace_id_;
1647 params.frame_name = frame_name;
1648
[email protected]48c9cf2d2009-09-16 16:47:521649 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341650 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261651 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521652
[email protected]48c9cf2d2009-09-16 16:47:521653 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261654 new ViewHostMsg_CreateWindow(params,
1655 &routing_id,
1656 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211657 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521658 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521659
[email protected]48c9cf2d2009-09-16 16:47:521660 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421661 0,
[email protected]12636df2009-09-28 22:32:211662 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521663 renderer_preferences_,
1664 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211665 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341666 routing_id,
[email protected]8ab04652010-06-12 02:47:261667 cloned_session_storage_namespace_id,
1668 frame_name);
1669 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521670
[email protected]007a848b2009-10-26 15:55:461671 // Record whether the creator frame is trying to suppress the opener field.
1672 view->opener_suppressed_ = opener_suppressed;
1673
[email protected]48c9cf2d2009-09-16 16:47:521674 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091675 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521676 if (!creator_url.is_valid() || !creator_url.IsStandard())
1677 creator_url = GURL();
1678 view->creator_url_ = creator_url;
1679
1680 // Copy over the alternate error page URL so we can have alt error pages in
1681 // the new render view (we don't need the browser to send the URL back down).
1682 view->alternate_error_page_url_ = alternate_error_page_url_;
1683
1684 return view->webview();
1685}
1686
[email protected]3e2b375b2010-04-07 17:03:121687WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521688 RenderWidget* widget = RenderWidget::Create(routing_id_,
1689 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121690 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521691 return widget->webwidget();
1692}
1693
1694WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1695 RenderWidget* widget = RenderWidget::Create(routing_id_,
1696 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121697 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521698 widget->ConfigureAsExternalPopupMenu(info);
1699 return widget->webwidget();
1700}
1701
[email protected]68c50e52010-05-12 11:14:391702WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341703 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391704 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291705 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1706 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1707 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341708}
1709
[email protected]48c9cf2d2009-09-16 16:47:521710void RenderView::didAddMessageToConsole(
1711 const WebConsoleMessage& message, const WebString& source_name,
1712 unsigned source_line) {
1713 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1714 UTF16ToWideHack(message.text),
1715 static_cast<int32>(source_line),
1716 UTF16ToWideHack(source_name)));
1717}
1718
1719void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581720 DCHECK(frame);
1721 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521722}
1723
[email protected]3354d3e2010-06-10 19:53:021724WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1725 return notification_provider_.get();
1726}
1727
[email protected]48c9cf2d2009-09-16 16:47:521728void RenderView::didStartLoading() {
1729 if (is_loading_) {
1730 DLOG(WARNING) << "didStartLoading called while loading";
1731 return;
1732 }
1733
1734 is_loading_ = true;
1735 // Clear the pointer so that we can assign it only when there is an unknown
1736 // plugin on a page.
1737 first_default_plugin_.reset();
1738
1739 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1740}
1741
1742void RenderView::didStopLoading() {
1743 if (!is_loading_) {
1744 DLOG(WARNING) << "DidStopLoading called while not loading";
1745 return;
1746 }
1747
1748 is_loading_ = false;
1749
1750 // NOTE: For now we're doing the safest thing, and sending out notification
1751 // when done loading. This currently isn't an issue as the favicon is only
1752 // displayed when done loading. Ideally we would send notification when
1753 // finished parsing the head, but webkit doesn't support that yet.
1754 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271755 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521756 if (!favicon_url.is_empty())
1757 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1758
[email protected]26aa0482009-09-30 16:55:271759 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521760 true); // autodetected
1761
1762 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1763
[email protected]f9f4841b2010-03-20 05:41:421764 MessageLoop::current()->PostDelayedTask(
1765 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:301766 page_info_method_factory_.NewRunnableMethod(
1767 &RenderView::CapturePageInfo, page_id_, false),
[email protected]48c9cf2d2009-09-16 16:47:521768 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521769}
1770
[email protected]f55039a2010-02-17 14:12:061771bool RenderView::isSmartInsertDeleteEnabled() {
1772#if defined(OS_MACOSX)
1773 return true;
1774#else
1775 return false;
1776#endif
1777}
1778
[email protected]04fc9482009-09-18 22:13:031779bool RenderView::isSelectTrailingWhitespaceEnabled() {
1780#if defined(OS_WIN)
1781 return true;
1782#else
1783 return false;
1784#endif
1785}
1786
[email protected]04fc9482009-09-18 22:13:031787void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031788#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031789 if (!handling_input_event_)
1790 return;
1791 // TODO(estade): investigate incremental updates to the selection so that we
1792 // don't send the entire selection over IPC every time.
1793 if (!is_empty_selection) {
1794 // Sometimes we get repeated didChangeSelection calls from webkit when
1795 // the selection hasn't actually changed. We don't want to report these
1796 // because it will cause us to continually claim the X clipboard.
1797 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271798 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031799 if (this_selection == last_selection_)
1800 return;
1801
1802 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1803 this_selection));
1804 last_selection_ = this_selection;
1805 } else {
1806 last_selection_.clear();
1807 }
1808#endif
1809}
1810
1811void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121812 const std::string& name = UTF16ToUTF8(command_name);
1813 if (StartsWithASCII(name, "Move", true) ||
1814 StartsWithASCII(name, "Insert", true) ||
1815 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031816 return;
1817 UserMetricsRecordAction(name);
1818}
1819
[email protected]03f57072010-07-14 17:36:081820void RenderView::textFieldDidEndEditing(
1821 const WebKit::WebInputElement& element) {
1822#if defined(WEBKIT_BUG_41283_IS_FIXED)
1823 password_autocomplete_manager_.TextFieldDidEndEditing(element);
1824#endif
1825}
1826
1827void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1828#if defined(WEBKIT_BUG_41283_IS_FIXED)
[email protected]e47aec52010-08-12 00:50:301829 // We post a task for doing the AutoFill as the caret position is not set
1830 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
1831 // it is needed to trigger autofill.
1832 autofill_method_factory_.RevokeAll();
1833 MessageLoop::current()->PostTask(
1834 FROM_HERE,
1835 autofill_method_factory_.NewRunnableMethod(
1836 &RenderView::TextFieldDidChangeImpl, element));
[email protected]03f57072010-07-14 17:36:081837#endif
1838}
1839
[email protected]e47aec52010-08-12 00:50:301840void RenderView::TextFieldDidChangeImpl(
1841 const WebKit::WebInputElement& element) {
1842 if (password_autocomplete_manager_.TextDidChangeInTextField(element))
1843 return;
1844 autofill_helper_.TextDidChangeInTextField(element);
1845}
1846
[email protected]03f57072010-07-14 17:36:081847void RenderView::textFieldDidReceiveKeyDown(
1848 const WebKit::WebInputElement& element,
1849 const WebKit::WebKeyboardEvent& event) {
1850#if defined(WEBKIT_BUG_41283_IS_FIXED)
1851 password_autocomplete_manager_.TextFieldHandlingKeyDown(element, event);
1852#endif
1853}
1854
[email protected]b2528b72009-09-24 06:57:101855bool RenderView::handleCurrentKeyboardEvent() {
1856 if (edit_commands_.empty())
1857 return false;
1858
[email protected]26aa0482009-09-30 16:55:271859 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101860 if (!frame)
1861 return false;
1862
1863 EditCommands::iterator it = edit_commands_.begin();
1864 EditCommands::iterator end = edit_commands_.end();
1865
[email protected]507b33ea2009-09-29 03:56:511866 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101867 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331868 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1869 // key (but it's the exception). Once one edit command is not executed, it
1870 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101871 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1872 WebString::fromUTF8(it->value)))
1873 break;
[email protected]507b33ea2009-09-29 03:56:511874 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101875 }
1876
[email protected]507b33ea2009-09-29 03:56:511877 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101878}
1879
[email protected]e47aec52010-08-12 00:50:301880void RenderView::inputElementClicked(const WebKit::WebInputElement& element,
1881 bool already_focused) {
1882#if defined(WEBKIT_BUG_41283_IS_FIXED)
1883 if (password_autocomplete_manager_.InputElementClicked(element,
1884 already_focused)) {
1885 return;
1886 }
1887 autofill_helper_.InputElementClicked(element, already_focused);
1888#endif
1889}
1890
[email protected]2a3a7762009-10-19 19:17:321891void RenderView::spellCheck(const WebString& text,
1892 int& misspelled_offset,
1893 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561894 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461895
[email protected]85c55dc2009-11-06 03:05:461896 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171897 RenderThread* thread = RenderThread::current();
1898 // Will be NULL during unit tests.
1899 if (thread) {
[email protected]c27324b2009-11-19 22:44:291900 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171901 word.c_str(), word.size(), document_tag_,
1902 &misspelled_offset, &misspelled_length, NULL);
1903 }
[email protected]1dbafaf72009-09-23 19:43:561904}
1905
1906WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321907 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561908 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261909 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561910 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171911 RenderThread* thread = RenderThread::current();
1912 // Will be NULL during unit tests.
1913 if (thread) {
1914 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291915 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171916 word, document_tag_);
1917 }
[email protected]1dbafaf72009-09-23 19:43:561918 }
[email protected]2a3a7762009-10-19 19:17:321919 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561920}
1921
[email protected]c49085c72009-10-02 16:28:561922void RenderView::showSpellingUI(bool show) {
1923 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1924}
1925
[email protected]8922e1f2009-10-03 05:01:261926bool RenderView::isShowingSpellingUI() {
1927 return spelling_panel_visible_;
1928}
1929
[email protected]1dbafaf72009-09-23 19:43:561930void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321931 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1932 word));
[email protected]1dbafaf72009-09-23 19:43:561933}
1934
[email protected]a1128322009-10-06 18:38:461935bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351936 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471937 WebFileChooserCompletion* chooser_completion) {
1938 ViewHostMsg_RunFileChooser_Params ipc_params;
1939 ipc_params.mode = params.multiSelect ?
1940 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1941 ViewHostMsg_RunFileChooser_Params::Open;
1942 ipc_params.title = params.title;
1943 ipc_params.default_file_name =
1944 webkit_glue::WebStringToFilePath(params.initialValue);
1945
1946 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461947}
1948
[email protected]48c9cf2d2009-09-16 16:47:521949void RenderView::runModalAlertDialog(
1950 WebFrame* frame, const WebString& message) {
1951 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1952 UTF16ToWideHack(message),
1953 std::wstring(),
1954 frame->url(),
1955 NULL);
1956}
1957
1958bool RenderView::runModalConfirmDialog(
1959 WebFrame* frame, const WebString& message) {
1960 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1961 UTF16ToWideHack(message),
1962 std::wstring(),
1963 frame->url(),
1964 NULL);
1965}
1966
1967bool RenderView::runModalPromptDialog(
1968 WebFrame* frame, const WebString& message, const WebString& default_value,
1969 WebString* actual_value) {
1970 std::wstring result;
1971 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1972 UTF16ToWideHack(message),
1973 UTF16ToWideHack(default_value),
1974 frame->url(),
1975 &result);
1976 if (ok)
1977 actual_value->assign(WideToUTF16Hack(result));
1978 return ok;
1979}
1980
1981bool RenderView::runModalBeforeUnloadDialog(
1982 WebFrame* frame, const WebString& message) {
1983 bool success = false;
1984 // This is an ignored return value, but is included so we can accept the same
1985 // response as RunJavaScriptMessage.
1986 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211987 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521988 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211989 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521990 return success;
1991}
1992
[email protected]79e37442009-10-09 18:17:441993void RenderView::showContextMenu(
1994 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291995 ContextMenuParams params = ContextMenuParams(data);
1996 if (!params.misspelled_word.empty() && RenderThread::current()) {
1997 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041998 bool spelled_right = RenderThread::current()->spellchecker()->
1999 SpellCheckWord(
2000 params.misspelled_word.c_str(), params.misspelled_word.size(),
2001 document_tag_,
2002 &misspelled_offset, &misspelled_length,
2003 &params.dictionary_suggestions);
2004 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292005 params.misspelled_word.clear();
2006 }
2007
2008 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442009}
2010
[email protected]52f139e2c2010-06-11 16:56:092011bool RenderView::supportsFullscreen() {
2012 return CommandLine::ForCurrentProcess()->HasSwitch(
2013 switches::kEnableVideoFullscreen);
2014}
2015
2016void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2017 NOTIMPLEMENTED();
2018}
2019
2020void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2021 NOTIMPLEMENTED();
2022}
2023
[email protected]48c9cf2d2009-09-16 16:47:522024void RenderView::setStatusText(const WebString& text) {
2025}
2026
[email protected]163f8242009-10-30 20:19:552027void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582028 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522029 if (latest_url == target_url_)
2030 return;
[email protected]163f8242009-10-30 20:19:552031
[email protected]48c9cf2d2009-09-16 16:47:522032 // Tell the browser to display a destination link.
2033 if (target_url_status_ == TARGET_INFLIGHT ||
2034 target_url_status_ == TARGET_PENDING) {
2035 // If we have a request in-flight, save the URL to be sent when we
2036 // receive an ACK to the in-flight request. We can happily overwrite
2037 // any existing pending sends.
2038 pending_target_url_ = latest_url;
2039 target_url_status_ = TARGET_PENDING;
2040 } else {
2041 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2042 target_url_ = latest_url;
2043 target_url_status_ = TARGET_INFLIGHT;
2044 }
2045}
2046
[email protected]1c57b7b2010-07-12 17:38:102047bool RenderView::IsPageTranslatable(WebKit::WebDocument* document) {
2048 std::vector<WebKit::WebElement> meta_elements;
2049 webkit_glue::GetMetaElementsWithName(document, ASCIIToUTF16("google"),
2050 &meta_elements);
2051 std::vector<WebKit::WebElement>::const_iterator iter;
2052 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) {
2053 WebString attribute = iter->getAttribute("value");
2054 if (attribute.isNull()) // We support both 'value' and 'content'.
2055 attribute = iter->getAttribute("content");
2056 if (attribute.isNull())
2057 continue;
2058 if (LowerCaseEqualsASCII(attribute, "notranslate"))
2059 return false;
2060 }
2061 return true;
2062}
2063
[email protected]882daa92009-11-05 16:31:312064void RenderView::StartNavStateSyncTimerIfNecessary() {
2065 int delay;
2066 if (send_content_state_immediately_)
2067 delay = 0;
2068 else if (is_hidden())
2069 delay = kDelaySecondsForContentStateSyncHidden;
2070 else
2071 delay = kDelaySecondsForContentStateSync;
2072
2073 if (nav_state_sync_timer_.IsRunning()) {
2074 // The timer is already running. If the delay of the timer maches the amount
2075 // we want to delay by, then return. Otherwise stop the timer so that it
2076 // gets started with the right delay.
2077 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2078 return;
2079 nav_state_sync_timer_.Stop();
2080 }
2081
2082 nav_state_sync_timer_.Start(
2083 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2084}
2085
[email protected]163f8242009-10-30 20:19:552086void RenderView::setMouseOverURL(const WebURL& url) {
2087 mouse_over_url_ = GURL(url);
2088 UpdateTargetURL(mouse_over_url_, focus_url_);
2089}
2090
2091void RenderView::setKeyboardFocusURL(const WebURL& url) {
2092 focus_url_ = GURL(url);
2093 UpdateTargetURL(focus_url_, mouse_over_url_);
2094}
2095
[email protected]48c9cf2d2009-09-16 16:47:522096void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2097 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2098 hint));
2099}
2100
[email protected]c27ae592010-03-18 15:24:412101void RenderView::startDragging(const WebDragData& data,
2102 WebDragOperationsMask mask,
2103 const WebImage& image,
2104 const WebPoint& imageOffset) {
2105#if WEBKIT_USING_SKIA
2106 SkBitmap bitmap(image.getSkBitmap());
2107#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332108 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412109#endif
2110
[email protected]48c9cf2d2009-09-16 16:47:522111 Send(new ViewHostMsg_StartDragging(routing_id_,
2112 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412113 mask,
2114 bitmap,
2115 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522116}
2117
[email protected]28b92df2009-09-25 17:35:452118bool RenderView::acceptsLoadDrops() {
2119 return renderer_preferences_.can_accept_load_drops;
2120}
2121
[email protected]48c9cf2d2009-09-16 16:47:522122void RenderView::focusNext() {
2123 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2124}
2125
2126void RenderView::focusPrevious() {
2127 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2128}
2129
[email protected]08e9e132010-06-01 16:58:492130void RenderView::focusedNodeChanged(const WebNode& node) {
2131 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2132}
2133
[email protected]48c9cf2d2009-09-16 16:47:522134void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522135 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2136}
2137
2138int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002139 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522140}
2141
2142int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002143 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522144}
2145
[email protected]c4e98902010-06-01 10:20:142146void RenderView::didUpdateInspectorSetting(const WebString& key,
2147 const WebString& value) {
2148 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2149 key.utf8(),
2150 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262151}
2152
[email protected]acca2a1f2009-10-16 03:53:392153void RenderView::queryAutofillSuggestions(const WebNode& node,
2154 const WebString& name,
2155 const WebString& value) {
[email protected]e47aec52010-08-12 00:50:302156 autofill_helper_.QueryAutoFillSuggestions(node, name, value);
[email protected]acca2a1f2009-10-16 03:53:392157}
2158
2159void RenderView::removeAutofillSuggestions(const WebString& name,
2160 const WebString& value) {
[email protected]679f128f2010-07-22 22:57:442161 autofill_helper_.RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a1f2009-10-16 03:53:392162}
2163
[email protected]18ca9a6b2010-06-02 19:05:182164void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2165 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202166 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392167 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202168 unsigned index) {
[email protected]679f128f2010-07-22 22:57:442169 autofill_helper_.DidAcceptAutoFillSuggestion(node, value, label, unique_id,
2170 index);
[email protected]18ca9a6b2010-06-02 19:05:182171}
[email protected]c83641732010-02-20 01:04:482172
[email protected]18ca9a6b2010-06-02 19:05:182173void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2174 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392175 const WebKit::WebString& label,
2176 int unique_id) {
[email protected]679f128f2010-07-22 22:57:442177 autofill_helper_.DidSelectAutoFillSuggestion(node, value, label, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182178}
2179
2180void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]679f128f2010-07-22 22:57:442181 autofill_helper_.DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482182}
2183
[email protected]03f57072010-07-14 17:36:082184void RenderView::didAcceptAutocompleteSuggestion(
2185 const WebKit::WebInputElement& user_element) {
2186#if defined(WEBKIT_BUG_41283_IS_FIXED)
2187 bool result = password_autocomplete_manager_.FillPassword(user_element);
2188 // Since this user name was selected from a suggestion list, we should always
2189 // have password for it.
2190 DCHECK(result);
2191#endif
2192}
2193
[email protected]79dbc662009-09-04 05:42:512194// WebKit::WebWidgetClient ----------------------------------------------------
2195
initial.commit09911bf2008-07-26 23:55:292196// We are supposed to get a single call to Show for a newly created RenderView
2197// that was created via RenderView::CreateWebView. So, we wait until this
2198// point to dispatch the ShowView message.
2199//
2200// This method provides us with the information about how to display the newly
2201// created RenderView (i.e., as a constrained popup or as a new tab).
2202//
[email protected]4873c7d2009-07-16 06:36:282203void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292204 DCHECK(!did_show_) << "received extraneous Show call";
2205 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2206
2207 if (did_show_)
2208 return;
2209 did_show_ = true;
2210
[email protected]28295ec2009-10-16 05:34:332211 // Force new windows to a popup if they were not opened with a user gesture.
2212 if (!opened_by_user_gesture_) {
2213 // We exempt background tabs for compat with older versions of Chrome.
2214 // TODO(darin): This seems bogus. These should have a user gesture, so
2215 // we probably don't need this check.
2216 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2217 policy = WebKit::WebNavigationPolicyNewPopup;
2218 }
2219
initial.commit09911bf2008-07-26 23:55:292220 // NOTE: initial_pos_ may still have its default values at this point, but
2221 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2222 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282223 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2224 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292225 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242226 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292227}
2228
[email protected]4873c7d2009-07-16 06:36:282229void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132230 // Cancel pending translations so that the translate_helper_ does not attempt
2231 // to access the WebView.
2232 translate_helper_.CancelPendingTranslation();
2233
[email protected]e8345242010-05-06 03:00:402234 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282235 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312236}
2237
[email protected]4873c7d2009-07-16 06:36:282238void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292239 DCHECK(did_show_) << "should already have shown the view";
2240
[email protected]c1f50aa2010-02-18 03:46:572241 // We must keep WebKit's shared timer running in this case in order to allow
2242 // showModalDialog to function properly.
2243 //
2244 // TODO(darin): WebKit should really be smarter about suppressing events and
2245 // timers so that we do not need to manage the shared timer in such a heavy
2246 // handed manner.
2247 //
2248 if (RenderThread::current()) // Will be NULL during unit tests.
2249 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2250
[email protected]12636df2009-09-28 22:32:212251 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292252}
2253
[email protected]3d9689372009-09-10 04:29:172254// WebKit::WebFrameClient -----------------------------------------------------
2255
[email protected]00152e92010-07-19 11:47:402256WebPlugin* RenderView::createPlugin(WebFrame* frame,
2257 const WebPluginParams& params) {
[email protected]7a13e792010-08-03 08:18:242258 bool found = false;
2259 WebPluginInfo info;
2260 GURL url(params.url);
[email protected]0cdafff2010-07-26 09:54:372261 std::string actual_mime_type;
[email protected]7a13e792010-08-03 08:18:242262 Send(new ViewHostMsg_GetPluginInfo(url,
2263 frame->top()->url(),
[email protected]aad51d1c2010-08-05 08:38:092264 params.mimeType.utf8(),
[email protected]7a13e792010-08-03 08:18:242265 &found,
2266 &info,
[email protected]aad51d1c2010-08-05 08:38:092267 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242268
[email protected]851b1eb2010-08-09 13:32:292269 if (!found)
[email protected]0cdafff2010-07-26 09:54:372270 return NULL;
[email protected]4e0616e2010-05-28 14:55:532271
[email protected]851b1eb2010-08-09 13:32:292272 scoped_ptr<PluginGroup> group(PluginGroup::FindHardcodedPluginGroup(info));
2273 group->AddPlugin(info, 0);
2274
2275 if (!info.enabled) {
[email protected]6b3db4352010-08-12 16:14:222276 if (CommandLine::ForCurrentProcess()->HasSwitch(
2277 switches::kDisableOutdatedPlugins) &&
[email protected]851b1eb2010-08-09 13:32:292278 group->IsVulnerable()) {
2279 Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_,
2280 group->GetGroupName(),
2281 GURL(group->GetUpdateURL())));
2282 return CreatePluginPlaceholder(frame, params, group.get());
2283 }
2284 return NULL;
2285 }
2286
[email protected]aad51d1c2010-08-05 08:38:092287 if (info.path.value() != kDefaultPluginLibraryName) {
[email protected]6b3db4352010-08-12 16:14:222288 if (!AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS)) {
2289 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
2290 switches::kEnableClickToPlay));
2291 didNotAllowPlugins(frame);
[email protected]851b1eb2010-08-09 13:32:292292 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092293 }
2294 scoped_refptr<pepper::PluginModule> pepper_module =
2295 PepperPluginRegistry::GetInstance()->GetModule(info.path);
2296 if (pepper_module)
2297 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
2298 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]6b3db4352010-08-12 16:14:222299 switches::kBlockNonSandboxedPlugins)) {
[email protected]851b1eb2010-08-09 13:32:292300 Send(new ViewHostMsg_NonSandboxedPluginBlocked(routing_id_,
2301 group->GetGroupName()));
2302 return CreatePluginPlaceholder(frame, params, NULL);
[email protected]aad51d1c2010-08-05 08:38:092303 }
[email protected]0cdafff2010-07-26 09:54:372304 }
[email protected]aad51d1c2010-08-05 08:38:092305 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]3d9689372009-09-10 04:29:172306}
2307
2308WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562309 WebApplicationCacheHostImpl* appcache_host =
2310 WebApplicationCacheHostImpl::FromFrame(frame);
2311 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2312 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2313 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172314}
2315
[email protected]9c00f002009-11-05 22:37:422316WebSharedWorker* RenderView::createSharedWorker(
2317 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372318 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422319
[email protected]30447b62009-11-13 01:13:372320 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512321 bool exists = false;
[email protected]30447b62009-11-13 01:13:372322 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512323 ViewHostMsg_CreateWorker_Params params;
2324 params.url = url;
2325 params.is_shared = true;
2326 params.name = name;
2327 params.document_id = document_id;
2328 params.render_view_route_id = routing_id_;
2329 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232330 params.parent_appcache_host_id = 0;
2331 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372332 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512333 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372334 if (url_mismatch) {
2335 return NULL;
2336 } else {
2337 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492338 document_id,
[email protected]6de0bcf2010-02-17 22:00:512339 exists,
[email protected]30447b62009-11-13 01:13:372340 route_id,
2341 routing_id_);
2342 }
[email protected]9c00f002009-11-05 22:37:422343}
2344
[email protected]3d9689372009-09-10 04:29:172345WebMediaPlayer* RenderView::createMediaPlayer(
2346 WebFrame* frame, WebMediaPlayerClient* client) {
2347 scoped_refptr<media::FilterFactoryCollection> factory =
2348 new media::FilterFactoryCollection();
2349 // Add in any custom filter factories first.
2350 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2351 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2352 // Add the chrome specific audio renderer.
2353 factory->AddFactory(
2354 AudioRendererImpl::CreateFactory(audio_message_filter()));
2355 }
2356
[email protected]ee68378a2010-08-10 01:05:412357 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
2358 cmd_line->HasSwitch(switches::kEnableAcceleratedCompositing)) {
2359 // Add the hardware video decoder factory.
2360 factory->AddFactory(
2361 media::IpcVideoDecoder::CreateFactory(MessageLoop::current()));
2362 }
2363
[email protected]80f584d92010-01-21 03:59:042364 WebApplicationCacheHostImpl* appcache_host =
2365 WebApplicationCacheHostImpl::FromFrame(frame);
2366
[email protected]3d9689372009-09-10 04:29:172367 // TODO(hclam): obtain the following parameters from |client|.
2368 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2369 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152370 GURL(), // referrer
2371 "null", // frame origin
2372 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172373 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042374 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172375 routing_id());
2376
[email protected]0436b9a2009-10-23 00:23:052377 // A simple data source that keeps all data in memory.
2378 media::FilterFactory* simple_data_source_factory =
2379 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2380 bridge_factory);
2381 // A sophisticated data source that does memory caching.
2382 media::FilterFactory* buffered_data_source_factory =
2383 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2384 bridge_factory);
2385 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2386 factory->AddFactory(simple_data_source_factory);
2387 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172388 } else {
[email protected]0436b9a2009-10-23 00:23:052389 factory->AddFactory(buffered_data_source_factory);
2390 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172391 }
[email protected]8400e032010-02-26 18:50:112392
2393 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2394 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2395 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2396 } else {
[email protected]b57509eb2010-03-30 01:26:282397 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2398 factory_factory =
2399 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112400 }
2401
2402 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172403}
2404
[email protected]035545f2010-04-09 13:10:212405WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2406 WebFrame* frame, WebApplicationCacheHostClient* client) {
2407 return new RendererWebApplicationCacheHostImpl(
2408 FromWebView(frame->view()), client,
2409 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2410}
2411
[email protected]b921cfd22010-02-25 16:57:512412WebCookieJar* RenderView::cookieJar() {
2413 return &cookie_jar_;
2414}
2415
[email protected]5041f982010-08-11 21:40:452416void RenderView::frameDetached(WebFrame* frame) {
2417 autofill_helper_.FrameDetached(frame);
2418}
2419
[email protected]3d9689372009-09-10 04:29:172420void RenderView::willClose(WebFrame* frame) {
2421 if (!frame->parent()) {
2422 const GURL& url = frame->url();
2423 if (url.SchemeIs("http") || url.SchemeIs("https"))
2424 DumpLoadHistograms();
2425 }
[email protected]fa7b6b542009-11-03 05:02:302426
2427 WebDataSource* ds = frame->dataSource();
2428 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2429 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162430
[email protected]5041f982010-08-11 21:40:452431 // TODO(jhawkins): Remove once frameDetached is called by WebKit.
[email protected]679f128f2010-07-22 22:57:442432 autofill_helper_.FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172433}
2434
[email protected]684e4a42010-01-30 06:44:112435bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402436 if (enabled_per_settings &&
2437 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2438 return true;
2439
2440 if (IsWhitelistedForContentSettings(frame))
2441 return true;
2442
[email protected]6b3db4352010-08-12 16:14:222443 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
[email protected]12bc8472010-04-15 07:29:402444 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112445}
2446
[email protected]d5f9e4f2010-07-28 08:31:302447bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
2448 if (CommandLine::ForCurrentProcess()->HasSwitch(
2449 switches::kEnableClickToPlay)) {
2450 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
2451 }
2452 return (enabled_per_settings &&
2453 AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS));
2454}
2455
2456
[email protected]3d9689372009-09-10 04:29:172457void RenderView::loadURLExternally(
2458 WebFrame* frame, const WebURLRequest& request,
2459 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592460 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2461 if (policy == WebKit::WebNavigationPolicyDownload) {
2462 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2463 } else {
2464 OpenURL(request.url(), referrer, policy);
2465 }
[email protected]3d9689372009-09-10 04:29:172466}
2467
2468WebNavigationPolicy RenderView::decidePolicyForNavigation(
2469 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222470 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172471 // Webkit is asking whether to navigate to a new URL.
2472 // This is fine normally, except if we're showing UI from one security
2473 // context and they're trying to navigate to a different context.
2474 const GURL& url = request.url();
2475
2476 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302477 // navigations.
[email protected]8079b362010-05-07 18:37:452478 if (renderer_preferences_.browser_handles_top_level_requests &&
2479 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192480 last_top_level_navigation_page_id_ = page_id_;
2481 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2482 OpenURL(url, referrer, default_policy);
2483 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172484 }
2485
2486 // A content initiated navigation may have originated from a link-click,
2487 // script, drag-n-drop operation, etc.
2488 bool is_content_initiated =
2489 NavigationState::FromDataSource(frame->provisionalDataSource())->
2490 is_content_initiated();
2491
2492 // We only care about navigations that are within the current tab (as opposed
2493 // to, for example, opening a new window).
2494 // But we sometimes navigate to about:blank to clear a tab, and we want to
2495 // still allow that.
2496 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2497 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532498 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172499 !url.SchemeIs(chrome::kAboutScheme)) {
2500 // When we received such unsolicited navigations, we sometimes want to
2501 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302502 if (CrossesExtensionExtents(frame, url) ||
2503 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172504 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422505 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172506 OpenURL(url, GURL(), default_policy);
2507 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2508 }
[email protected]8079b362010-05-07 18:37:452509
2510 // We forward navigations from extensions to the browser if they are
2511 // top-level events, even if the browser hasn't expressed interest.
2512 //
2513 // Note that we've already forwarded cross-extension extents navigations
2514 // above.
2515 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]c240ace2010-06-16 18:31:532516 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]8079b362010-05-07 18:37:452517 OpenURL(url, GURL(), default_policy);
2518 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2519 }
[email protected]3d9689372009-09-10 04:29:172520 }
2521
2522 // Detect when a page is "forking" a new tab that can be safely rendered in
2523 // its own process. This is done by sites like Gmail that try to open links
2524 // in new windows without script connections back to the original page. We
2525 // treat such cases as browser navigations (in which we will create a new
2526 // renderer for a cross-site navigation), rather than WebKit navigations.
2527 //
2528 // We use the following heuristic to decide whether to fork a new page in its
2529 // own process:
2530 // The parent page must open a new tab to about:blank, set the new tab's
2531 // window.opener to null, and then redirect the tab to a cross-site URL using
2532 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462533 //
2534 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2535 // (see below).
[email protected]3d9689372009-09-10 04:29:172536 bool is_fork =
2537 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252538 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172539 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522540 historyBackListCount() < 1 &&
2541 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172542 // The parent page must have set the child's window.opener to null before
2543 // redirecting to the desired URL.
2544 frame->opener() == NULL &&
2545 // Must be a top-level frame.
2546 frame->parent() == NULL &&
2547 // Must not have issued the request from this page.
2548 is_content_initiated &&
2549 // Must be targeted at the current tab.
2550 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2551 // Must be a JavaScript navigation, which appears as "other".
2552 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462553
2554 // Recognize if this navigation is from a link with rel=noreferrer and
2555 // target=_blank attributes, in which case the opener will be suppressed. If
2556 // so, it is safe to load cross-site pages in a separate process, so we
2557 // should let the browser handle it.
2558 bool is_noreferrer_and_blank_target =
2559 // Frame should be top level and not yet navigated.
2560 frame->parent() == NULL &&
2561 frame->url().isEmpty() &&
2562 historyBackListCount() < 1 &&
2563 historyForwardListCount() < 1 &&
2564 // Links with rel=noreferrer will have no Referer field, and their
2565 // resulting frame will have its window.opener suppressed.
2566 // TODO(creis): should add a request.httpReferrer() method to help avoid
2567 // typos on the unusual spelling of Referer.
2568 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2569 opener_suppressed_ &&
2570 frame->opener() == NULL &&
2571 // Links with target=_blank will have no name.
2572 frame->name().isNull() &&
2573 // Another frame (with a non-empty creator) should have initiated the
2574 // request, targeted at this frame.
2575 !creator_url_.is_empty() &&
2576 is_content_initiated &&
2577 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2578 type == WebKit::WebNavigationTypeOther;
2579
2580 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172581 // Open the URL via the browser, not via WebKit.
2582 OpenURL(url, GURL(), default_policy);
2583 return WebKit::WebNavigationPolicyIgnore;
2584 }
2585
2586 return default_policy;
2587}
2588
[email protected]6069da8c2009-10-20 20:33:492589bool RenderView::canHandleRequest(
2590 WebFrame* frame, const WebURLRequest& request) {
2591 // We allow WebKit to think that everything can be handled even though
2592 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342593 return true;
2594}
2595
[email protected]6069da8c2009-10-20 20:33:492596WebURLError RenderView::cannotHandleRequestError(
2597 WebFrame* frame, const WebURLRequest& request) {
2598 NOTREACHED(); // Since we said we can handle all requests.
2599 return WebURLError();
2600}
2601
2602WebURLError RenderView::cancelledError(
2603 WebFrame* frame, const WebURLRequest& request) {
2604 WebURLError error;
2605 error.domain = WebString::fromUTF8(net::kErrorDomain);
2606 error.reason = net::ERR_ABORTED;
2607 error.unreachableURL = request.url();
2608 return error;
[email protected]7b7a7dc2009-10-19 02:23:342609}
2610
2611void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492612 WebFrame*, const WebURLError&) {
2613 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342614}
2615
[email protected]90eeddb2010-05-06 21:06:432616void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2617 const WebKit::WebFormElement& form) {
2618 // Some login forms have onSubmit handlers that put a hash of the password
2619 // into a hidden field and then clear the password. (Issue 28910.)
2620 // This method gets called before any of those handlers run, so save away
2621 // a copy of the password in case it gets lost.
2622 NavigationState* navigation_state =
2623 NavigationState::FromDataSource(frame->dataSource());
2624 navigation_state->set_password_form_data(
2625 PasswordFormDomManager::CreatePasswordForm(form));
2626}
2627
[email protected]979c28b2009-11-07 01:30:482628void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172629 NavigationState* navigation_state =
2630 NavigationState::FromDataSource(frame->provisionalDataSource());
2631
2632 if (navigation_state->transition_type() == PageTransition::LINK)
2633 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2634
2635 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352636 WebSearchableFormData web_searchable_form_data(form);
2637 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2638 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212639 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432640 PasswordForm* password_form_data =
2641 PasswordFormDomManager::CreatePasswordForm(form);
2642 navigation_state->set_password_form_data(password_form_data);
2643
2644 // If the password has been cleared, recover it from the form contents already
2645 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2646 // opposed to the provisionalDataSource's, which is what we're storing into
2647 // now.)
2648 if (password_form_data && password_form_data->password_value.empty()) {
2649 NavigationState* old_navigation_state =
2650 NavigationState::FromDataSource(frame->dataSource());
2651 if (old_navigation_state) {
2652 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2653 if (old_form_data && old_form_data->action == password_form_data->action)
2654 password_form_data->password_value = old_form_data->password_value;
2655 }
2656 }
[email protected]3d9689372009-09-10 04:29:172657
[email protected]b1438212010-04-03 00:30:592658 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042659 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092660 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592661 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172662}
2663
2664void RenderView::willPerformClientRedirect(
2665 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2666 double fire_time) {
2667 // Ignore
2668}
2669
2670void RenderView::didCancelClientRedirect(WebFrame* frame) {
2671 // Ignore
2672}
2673
2674void RenderView::didCompleteClientRedirect(
2675 WebFrame* frame, const WebURL& from) {
2676 if (!frame->parent())
2677 completed_client_redirect_src_ = from;
2678}
2679
2680void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2681 // The rest of RenderView assumes that a WebDataSource will always have a
2682 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482683 bool content_initiated = !pending_navigation_state_.get();
2684 NavigationState* state = content_initiated ?
2685 NavigationState::CreateContentInitiated() :
2686 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512687
2688 const WebURLRequest& original_request = ds->originalRequest();
2689 const WebURLRequest& request = ds->request();
2690
2691 // NavigationState::referred_by_prefetcher_ is true if we are
2692 // navigating from a page that used prefetching using a link on that
2693 // page. We are early enough in the request process here that we
2694 // can still see the NavigationState of the previous page and set
2695 // this value appropriately.
2696 // TODO(gavinp): catch the important case of navigation in a new
2697 // renderer process.
2698 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302699 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]8a3125a712010-08-09 18:58:512700 const GURL referrer(
2701 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2702 if (!referrer.is_empty() &&
2703 NavigationState::FromDataSource(
2704 old_frame->dataSource())->was_prefetcher()) {
2705 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2706 WebDataSource* old_frame_ds = old_frame->dataSource();
2707 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2708 state->set_was_referred_by_prefetcher(true);
2709 break;
2710 }
2711 }
2712 }
2713 }
2714 }
2715
[email protected]4c1b6f0b2010-02-07 16:38:182716 if (content_initiated) {
[email protected]8a3125a712010-08-09 18:58:512717 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182718 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2719 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2720 break;
2721 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2722 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2723 break;
2724 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2725 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2726 break;
2727 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2728 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2729 break;
2730 }
2731 }
[email protected]fa7b6b542009-11-03 05:02:302732
2733 state->set_user_script_idle_scheduler(
2734 new UserScriptIdleScheduler(this, frame));
2735 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172736}
2737
2738void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2739 WebDataSource* ds = frame->provisionalDataSource();
2740 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2741
2742 navigation_state->set_start_load_time(Time::Now());
2743
2744 // Update the request time if WebKit has better knowledge of it.
2745 if (navigation_state->request_time().is_null()) {
2746 double event_time = ds->triggeringEventTime();
2747 if (event_time != 0.0)
2748 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2749 }
2750
2751 bool is_top_most = !frame->parent();
2752 if (is_top_most) {
2753 navigation_gesture_ = frame->isProcessingUserGesture() ?
2754 NavigationGestureUnknown : NavigationGestureAuto;
2755
2756 // Make sure redirect tracking state is clear for the new load.
2757 completed_client_redirect_src_ = GURL();
2758 } else if (frame->parent()->isLoading()) {
2759 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002760 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172761 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2762 }
2763
2764 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2765 routing_id_, is_top_most, ds->request().url()));
2766}
2767
2768void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2769 if (frame->parent())
2770 return;
2771 // Received a redirect on the main frame.
2772 WebDataSource* data_source = frame->provisionalDataSource();
2773 if (!data_source) {
2774 // Should only be invoked when we have a data source.
2775 NOTREACHED();
2776 return;
2777 }
2778 std::vector<GURL> redirects;
2779 GetRedirectChain(data_source, &redirects);
2780 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512781 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2782 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172783 }
2784}
2785
[email protected]40bd6582009-12-04 23:49:512786void RenderView::didFailProvisionalLoad(WebFrame* frame,
2787 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172788 // Notify the browser that we failed a provisional load with an error.
2789 //
2790 // Note: It is important this notification occur before DidStopLoading so the
2791 // SSL manager can react to the provisional load failure before being
2792 // notified the load stopped.
2793 //
2794 WebDataSource* ds = frame->provisionalDataSource();
2795 DCHECK(ds);
2796
2797 const WebURLRequest& failed_request = ds->request();
2798
2799 bool show_repost_interstitial =
2800 (error.reason == net::ERR_CACHE_MISS &&
2801 EqualsASCII(failed_request.httpMethod(), "POST"));
2802 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2803 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2804 show_repost_interstitial));
2805
2806 // Don't display an error page if this is simply a cancelled load. Aside
2807 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2808 if (error.reason == net::ERR_ABORTED)
2809 return;
2810
2811 // Make sure we never show errors in view source mode.
2812 frame->enableViewSourceMode(false);
2813
2814 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2815
2816 // If this is a failed back/forward/reload navigation, then we need to do a
2817 // 'replace' load. This is necessary to avoid messing up session history.
2818 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2819 // as session history is concerned.
2820 //
2821 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2822 // the page id.
2823 //
2824 bool replace =
2825 navigation_state->pending_page_id() != -1 ||
2826 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2827
2828 // If we failed on a browser initiated request, then make sure that our error
2829 // page load is regarded as the same browser initiated request.
2830 if (!navigation_state->is_content_initiated()) {
2831 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2832 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002833 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172834 navigation_state->transition_type(),
2835 navigation_state->request_time()));
2836 }
2837
2838 // Provide the user with a more helpful error page?
2839 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2840 return;
2841
2842 // Fallback to a local error page.
2843 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2844 replace);
2845}
2846
2847void RenderView::didReceiveDocumentData(
2848 WebFrame* frame, const char* data, size_t data_len,
2849 bool& prevent_default) {
2850 NavigationState* navigation_state =
2851 NavigationState::FromDataSource(frame->dataSource());
2852 if (!navigation_state->postpone_loading_data())
2853 return;
2854
2855 // We're going to call commitDocumentData ourselves...
2856 prevent_default = true;
2857
2858 // Continue buffering the response data for the original 404 page. If it
2859 // grows too large, then we'll just let it through.
2860 navigation_state->append_postponed_data(data, data_len);
2861 if (navigation_state->postponed_data().size() >= 512) {
2862 navigation_state->set_postpone_loading_data(false);
2863 frame->commitDocumentData(navigation_state->postponed_data().data(),
2864 navigation_state->postponed_data().size());
2865 navigation_state->clear_postponed_data();
2866 }
2867}
2868
[email protected]40bd6582009-12-04 23:49:512869void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2870 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172871 NavigationState* navigation_state =
2872 NavigationState::FromDataSource(frame->dataSource());
2873
2874 navigation_state->set_commit_load_time(Time::Now());
2875 if (is_new_navigation) {
2876 // When we perform a new navigation, we need to update the previous session
2877 // history entry with state for the page we are leaving.
2878 UpdateSessionHistory(frame);
2879
2880 // We bump our Page ID to correspond with the new session history entry.
2881 page_id_ = next_page_id_++;
2882
[email protected]d64b07b2010-04-20 22:14:062883 // Any pending translation is now obsolete.
2884 translate_helper_.CancelPendingTranslation();
2885
[email protected]3cc72b12010-03-18 23:03:002886 // Advance our offset in session history, applying the length limit. There
2887 // is now no forward history.
2888 history_list_offset_++;
2889 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2890 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2891 history_list_length_ = history_list_offset_ + 1;
2892
[email protected]f9f4841b2010-03-20 05:41:422893 MessageLoop::current()->PostDelayedTask(
2894 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302895 page_info_method_factory_.NewRunnableMethod(
2896 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:172897 kDelayForForcedCaptureMs);
2898 } else {
2899 // Inspect the navigation_state on this frame to see if the navigation
2900 // corresponds to a session history navigation... Note: |frame| may or
2901 // may not be the toplevel frame, but for the case of capturing session
2902 // history, the first committed frame suffices. We keep track of whether
2903 // we've seen this commit before so that only capture session history once
2904 // per navigation.
2905 //
2906 // Note that we need to check if the page ID changed. In the case of a
2907 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2908 // previous URL and the current page ID, which would be wrong.
2909 if (navigation_state->pending_page_id() != -1 &&
2910 navigation_state->pending_page_id() != page_id_ &&
2911 !navigation_state->request_committed()) {
2912 // This is a successful session history navigation!
2913 UpdateSessionHistory(frame);
2914 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002915
2916 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172917 }
2918 }
2919
2920 // Remember that we've already processed this request, so we don't update
2921 // the session history again. We do this regardless of whether this is
2922 // a session history navigation, because if we attempted a session history
2923 // navigation without valid HistoryItem state, WebCore will think it is a
2924 // new navigation.
2925 navigation_state->set_request_committed(true);
2926
2927 UpdateURL(frame);
2928
2929 // If this committed load was initiated by a client redirect, we're
2930 // at the last stop now, so clear it.
2931 completed_client_redirect_src_ = GURL();
2932
2933 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272934 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172935}
2936
2937void RenderView::didClearWindowObject(WebFrame* frame) {
2938 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2939 BindDOMAutomationController(frame);
2940 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2941 dom_ui_bindings_.set_message_sender(this);
2942 dom_ui_bindings_.set_routing_id(routing_id_);
2943 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2944 }
2945 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2946 external_host_bindings_.set_message_sender(this);
2947 external_host_bindings_.set_routing_id(routing_id_);
2948 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2949 }
2950}
2951
2952void RenderView::didCreateDocumentElement(WebFrame* frame) {
2953 if (RenderThread::current()) { // Will be NULL during unit tests.
2954 RenderThread::current()->user_script_slave()->InjectScripts(
2955 frame, UserScript::DOCUMENT_START);
2956 }
[email protected]078b34612009-09-19 19:31:512957 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2958 view_type_ == ViewType::EXTENSION_MOLE) {
2959 InjectToolstripCSS();
2960 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2961 }
[email protected]3d9689372009-09-10 04:29:172962
2963 // Notify the browser about non-blank documents loading in the top frame.
2964 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252965 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272966 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172967 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2968 }
2969}
2970
2971void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2972 UpdateTitle(frame, title);
2973
2974 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272975 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172976}
2977
[email protected]5019ef12010-04-27 17:26:582978void RenderView::didChangeIcons(WebFrame* frame) {
2979 if (!frame->parent()) {
2980 Send(new ViewHostMsg_UpdateFavIconURL(
2981 routing_id_,
2982 page_id_,
2983 frame->favIconURL()));
2984 }
2985}
2986
[email protected]3d9689372009-09-10 04:29:172987void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2988 WebDataSource* ds = frame->dataSource();
2989 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2990 DCHECK(navigation_state);
2991 navigation_state->set_finish_document_load_time(Time::Now());
2992
2993 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2994
[email protected]e9e07992010-02-17 21:04:362995 // The document has now been fully loaded. Scan for forms to be sent up to
2996 // the browser.
[email protected]679f128f2010-07-22 22:57:442997 autofill_helper_.FrameContentsAvailable(frame);
2998 password_autocomplete_manager_.SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172999
3000 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273001 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173002
3003 if (RenderThread::current()) { // Will be NULL during unit tests.
3004 RenderThread::current()->user_script_slave()->InjectScripts(
3005 frame, UserScript::DOCUMENT_END);
3006 }
[email protected]fa7b6b542009-11-03 05:02:303007
3008 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3009}
3010
3011void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3012 if (RenderThread::current()) { // Will be NULL during unit tests.
3013 RenderThread::current()->user_script_slave()->InjectScripts(
3014 frame, UserScript::DOCUMENT_IDLE);
3015 }
3016
3017 WebFrame* main_frame = webview()->mainFrame();
3018 if (frame == main_frame) {
3019 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203020 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303021 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203022 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303023 pending_code_execution_queue_.pop();
3024 }
3025 }
[email protected]3d9689372009-09-10 04:29:173026}
3027
3028void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:263029 if (webview()->mainFrame() == frame)
3030 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173031}
3032
3033void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3034 // Ignore
3035}
3036
3037void RenderView::didFinishLoad(WebFrame* frame) {
3038 WebDataSource* ds = frame->dataSource();
3039 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3040 DCHECK(navigation_state);
3041 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303042 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413043
3044 // Let the password manager know which password forms are actually visible.
[email protected]679f128f2010-07-22 22:57:443045 password_autocomplete_manager_.SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:173046}
3047
[email protected]ccbe04e2010-03-17 17:58:433048void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173049 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063050
3051 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3052 // since a new one gets created by didCreateDataSource.
3053 NavigationState* state =
3054 NavigationState::FromDataSource(frame->dataSource());
3055 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3056
[email protected]3d9689372009-09-10 04:29:173057 // If this was a reference fragment navigation that we initiated, then we
3058 // could end up having a non-null pending navigation state. We just need to
3059 // update the ExtraData on the datasource so that others who read the
3060 // ExtraData will get the new NavigationState. Similarly, if we did not
3061 // initiate this navigation, then we need to take care to reset any pre-
3062 // existing navigation state to a content-initiated navigation state.
3063 // DidCreateDataSource conveniently takes care of this for us.
3064 didCreateDataSource(frame, frame->dataSource());
3065
[email protected]f6c2459d2010-02-24 22:34:063066 if (idle_scheduler_ran) {
3067 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
3068 NavigationState* new_state =
3069 NavigationState::FromDataSource(frame->dataSource());
3070 new_state->user_script_idle_scheduler()->set_has_run(true);
3071 }
3072
[email protected]3d9689372009-09-10 04:29:173073 didCommitProvisionalLoad(frame, is_new_navigation);
3074
[email protected]26aa0482009-09-30 16:55:273075 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173076}
3077
[email protected]476b6f82009-09-10 21:00:593078void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313079 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593080}
3081
[email protected]3d9689372009-09-10 04:29:173082void RenderView::assignIdentifierToRequest(
3083 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3084 // Ignore
3085}
3086
3087void RenderView::willSendRequest(
3088 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3089 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303090 WebFrame* top_frame = frame->top();
3091 if (!top_frame)
3092 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513093 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3094 WebDataSource* top_data_source = top_frame->dataSource();
3095 WebDataSource* data_source =
3096 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303097 if (data_source) {
3098 NavigationState* state = NavigationState::FromDataSource(data_source);
3099 if (state && state->is_cache_policy_override_set())
3100 request.setCachePolicy(state->cache_policy_override());
3101 }
[email protected]8a3125a712010-08-09 18:58:513102
3103 if (top_data_source) {
3104 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3105 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3106 state->set_was_prefetcher(true);
3107 }
3108
[email protected]3d9689372009-09-10 04:29:173109 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503110 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133111 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493112
[email protected]85cc78c2010-05-04 18:30:093113 // Temporary metrics, see site_isolation_metrics.h
3114 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173115}
3116
3117void RenderView::didReceiveResponse(
3118 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493119
[email protected]85cc78c2010-05-04 18:30:093120 // Temporary metrics, see site_isolation_metrics.h
3121 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3122 identifier,
3123 response);
[email protected]fa0a3432010-03-30 16:53:493124
[email protected]3d9689372009-09-10 04:29:173125 // Only do this for responses that correspond to a provisional data source
3126 // of the top-most frame. If we have a provisional data source, then we
3127 // can't have any sub-resources yet, so we know that this response must
3128 // correspond to a frame load.
3129 if (!frame->provisionalDataSource() || frame->parent())
3130 return;
3131
3132 // If we are in view source mode, then just let the user see the source of
3133 // the server's 404 error page.
3134 if (frame->isViewSourceModeEnabled())
3135 return;
3136
[email protected]65041fa2010-05-21 06:56:533137 NavigationState* navigation_state =
3138 NavigationState::FromDataSource(frame->provisionalDataSource());
3139 CHECK(navigation_state);
3140
[email protected]972ebdff2010-06-10 22:59:073141 // Record page load flags.
3142 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3143 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573144 navigation_state->set_was_alternate_protocol_available(
3145 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073146 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]65041fa2010-05-21 06:56:533147
[email protected]f48013be2010-01-14 22:07:453148 // Consider loading an alternate error page for 404 responses.
3149 if (response.httpStatusCode() != 404)
3150 return;
3151
[email protected]3d9689372009-09-10 04:29:173152 // Can we even load an alternate error page for this URL?
3153 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3154 return;
3155
[email protected]3d9689372009-09-10 04:29:173156 navigation_state->set_postpone_loading_data(true);
3157 navigation_state->clear_postponed_data();
3158}
3159
3160void RenderView::didFinishResourceLoad(
3161 WebFrame* frame, unsigned identifier) {
3162 NavigationState* navigation_state =
3163 NavigationState::FromDataSource(frame->dataSource());
3164 if (!navigation_state->postpone_loading_data())
3165 return;
3166
3167 // The server returned a 404 and the content was < 512 bytes (which we
3168 // suppressed). Go ahead and fetch the alternate page content.
3169
3170 const GURL& frame_url = frame->url();
3171
3172 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3173 DCHECK(error_page_url.is_valid());
3174
3175 WebURLError original_error;
3176 original_error.unreachableURL = frame_url;
3177
3178 navigation_state->set_alt_error_page_fetcher(
3179 new AltErrorPageResourceFetcher(
3180 error_page_url, frame, original_error,
3181 NewCallback(this, &RenderView::AltErrorPageFinished)));
3182}
3183
3184void RenderView::didFailResourceLoad(
3185 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3186 // Ignore
3187}
3188
3189void RenderView::didLoadResourceFromMemoryCache(
3190 WebFrame* frame, const WebURLRequest& request,
3191 const WebURLResponse& response) {
3192 // Let the browser know we loaded a resource from the memory cache. This
3193 // message is needed to display the correct SSL indicators.
3194 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3195 routing_id_,
3196 request.url(),
[email protected]91733b62009-09-18 06:21:093197 frame->securityOrigin().toString().utf8(),
3198 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173199 response.securityInfo()));
3200}
3201
[email protected]6069da8c2009-10-20 20:33:493202void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293203 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3204}
3205
3206void RenderView::didRunInsecureContent(
3207 WebFrame* frame, const WebSecurityOrigin& origin) {
3208 Send(new ViewHostMsg_DidRunInsecureContent(
3209 routing_id_,
3210 origin.toString().utf8()));
3211}
3212
[email protected]7ea093ba2009-11-03 05:54:593213bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403214 if (enabled_per_settings &&
3215 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3216 return true;
[email protected]7ea093ba2009-11-03 05:54:593217
[email protected]12bc8472010-04-15 07:29:403218 if (IsWhitelistedForContentSettings(frame))
3219 return true;
[email protected]7ea093ba2009-11-03 05:54:593220
3221 return false; // Other protocols fall through here.
3222}
3223
[email protected]0a1a45432010-03-31 08:09:453224bool RenderView::allowDatabase(
3225 WebFrame* frame, const WebString& name, const WebString& display_name,
3226 unsigned long estimated_size) {
3227 WebSecurityOrigin origin = frame->securityOrigin();
3228 if (origin.isEmpty())
3229 return false; // Uninitialized document?
3230
3231 bool result;
3232 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3233 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3234 return false;
[email protected]9fb83e82010-07-02 18:24:553235 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3236 GURL(origin.toString().utf8()),
3237 name,
3238 display_name,
3239 estimated_size,
3240 !result));
[email protected]0a1a45432010-03-31 08:09:453241 return result;
3242}
[email protected]8934a3b2010-02-25 00:34:003243void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]6b3db4352010-08-12 16:14:223244 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]8934a3b2010-02-25 00:34:003245}
3246
[email protected]c21f1d52010-03-04 03:19:433247void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]6b3db4352010-08-12 16:14:223248 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]c21f1d52010-03-04 03:19:433249}
3250
[email protected]3d9689372009-09-10 04:29:173251void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3252 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3253}
3254
[email protected]0c882b282009-10-07 17:01:283255void RenderView::didCreateScriptContext(WebFrame* frame) {
3256 EventBindings::HandleContextCreated(frame, false);
3257}
3258
3259void RenderView::didDestroyScriptContext(WebFrame* frame) {
3260 EventBindings::HandleContextDestroyed(frame);
3261}
3262
3263void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3264 EventBindings::HandleContextCreated(frame, true);
3265}
3266
[email protected]fc86daa2010-03-30 23:52:533267void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3268 WebFrame* target,
3269 bool cross_origin,
3270 const WebString& property_name,
3271 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103272 // TODO(johnnyg): track the individual properties and repeat event_ids.
3273 if (cross_origin)
3274 cross_origin_access_count_++;
3275 else
3276 same_origin_access_count_++;
3277}
3278
[email protected]3d9689372009-09-10 04:29:173279void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143280 CheckPreferredSize();
3281}
3282
3283void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173284 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253285 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173286 // message.
[email protected]705243f2010-05-05 19:58:073287 if (!send_preferred_size_changes_ || !webview())
3288 return;
[email protected]dfca5acf2010-03-22 03:28:433289
[email protected]705243f2010-05-05 19:58:073290 // WebCore likes to tell us things have changed even when they haven't, so
3291 // cache the width and height and only send the IPC message when we're sure
3292 // they're different.
3293 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3294 webview()->mainFrame()->documentElementScrollHeight());
3295 if (size == preferred_size_)
3296 return;
[email protected]c27324b2009-11-19 22:44:293297
[email protected]705243f2010-05-05 19:58:073298 preferred_size_ = size;
3299 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3300 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173301}
3302
[email protected]143dcd592009-11-06 21:33:493303void RenderView::didChangeScrollOffset(WebFrame* frame) {
3304 StartNavStateSyncTimerIfNecessary();
3305}
3306
[email protected]8922e1f2009-10-03 05:01:263307void RenderView::reportFindInPageMatchCount(int request_id, int count,
3308 bool final_update) {
3309 // If we have a message that has been queued up, then we should just replace
3310 // it. The ACK from the browser will make sure it gets sent when the browser
3311 // wants it.
3312 if (queued_find_reply_message_.get()) {
3313 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3314 routing_id_,
3315 request_id,
3316 count,
3317 gfx::Rect(),
3318 -1, // Don't update active match ordinal.
3319 final_update);
3320 queued_find_reply_message_.reset(msg);
3321 } else {
3322 // Send the search result over to the browser process.
3323 Send(new ViewHostMsg_Find_Reply(
3324 routing_id_,
3325 request_id,
3326 count,
3327 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073328 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263329 final_update));
3330 }
3331}
3332
3333void RenderView::reportFindInPageSelection(int request_id,
3334 int active_match_ordinal,
3335 const WebRect& selection_rect) {
3336 // Send the search result over to the browser process.
3337 Send(new ViewHostMsg_Find_Reply(routing_id_,
3338 request_id,
3339 -1,
3340 selection_rect,
3341 active_match_ordinal,
3342 false));
3343}
3344
[email protected]24a7f3c2010-03-25 08:26:493345void RenderView::ReportNoFindInPageResults(int request_id) {
3346 Send(new ViewHostMsg_Find_Reply(routing_id_,
3347 request_id,
3348 0,
3349 gfx::Rect(),
3350 0,
3351 true));
3352}
3353
[email protected]79dbc662009-09-04 05:42:513354// webkit_glue::WebPluginPageDelegate -----------------------------------------
3355
[email protected]f103ab72009-09-02 17:10:593356webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533357 const FilePath& file_path,
3358 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593359 if (!PluginChannelHost::IsListening())
3360 return NULL;
3361
[email protected]d2139662009-12-10 03:21:143362 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283363 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143364 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163365 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533366 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143367 if (CommandLine::ForCurrentProcess()->
3368 HasSwitch(switches::kInternalPepper)) {
3369 in_process_plugin = true;
3370 use_pepper_host = true;
3371 } else {
3372 // In process Pepper plugins must be explicitly enabled.
3373 return NULL;
3374 }
[email protected]4e0616e2010-05-28 14:55:533375 } else {
3376 FilePath internal_pdf_path;
3377 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3378 if (file_path == internal_pdf_path) {
3379 in_process_plugin = true;
3380 use_pepper_host = true;
3381 }
[email protected]26e8d5e2009-10-13 02:47:163382 }
[email protected]4e0616e2010-05-28 14:55:533383
[email protected]d2139662009-12-10 03:21:143384 // Check for Native Client modules.
[email protected]8f05f7f2010-07-30 23:12:433385 if (mime_type == "application/x-nacl-srpc") {
3386 // NaCl is only permitted when we're in an extension/application with the
3387 // appropriate permission, or when explicitly enabled on the command line.
3388
3389 // TODO(cbiffle): need browser test for this before M7 (bug 45881)
3390 GURL main_frame_url(webview()->mainFrame()->url());
3391 const std::string &extension_id =
3392 RenderThread::current()->GetExtensionIdByURL(main_frame_url);
3393 bool in_ext = extension_id != "";
3394 bool explicit_enable =
3395 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3396
3397 if (in_ext) {
3398 if (ExtensionProcessBindings::HasPermission(extension_id,
3399 Extension::kNativeClientPermission)) {
3400 in_process_plugin = true;
3401 use_pepper_host = true;
3402 } else {
3403 // Disable NaCl for apps lacking the permission, even with the flag.
3404 return NULL;
3405 }
3406 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463407 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143408 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463409 }
3410 }
[email protected]4e0616e2010-05-28 14:55:533411
[email protected]d032f492009-09-29 00:33:463412 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143413 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283414 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533415 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333416 if (!pepper_plugin)
3417 return NULL;
3418
[email protected]53900d52010-06-16 04:25:013419 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283420 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143421 } else {
[email protected]6876dff2010-01-15 19:38:093422#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143423 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533424 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093425#else
[email protected]596b2c42010-01-14 20:40:433426 NOTIMPLEMENTED();
3427 return NULL;
[email protected]7b6616f2010-01-14 18:07:553428#endif
[email protected]6876dff2010-01-15 19:38:093429 }
[email protected]f103ab72009-09-02 17:10:593430 }
3431
[email protected]4e0616e2010-05-28 14:55:533432 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593433}
3434
3435void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033436#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593437 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3438 routing_id(), window));
3439#endif
3440}
3441
3442void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033443#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593444 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3445 routing_id(), window));
3446#endif
3447 CleanupWindowInPluginMoves(window);
3448}
3449
3450void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3451 SchedulePluginMove(move);
3452}
3453
3454void RenderView::DidStartLoadingForPlugin() {
3455 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523456 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593457}
3458
3459void RenderView::DidStopLoadingForPlugin() {
3460 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523461 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593462}
3463
3464void RenderView::ShowModalHTMLDialogForPlugin(
3465 const GURL& url,
3466 const gfx::Size& size,
3467 const std::string& json_arguments,
3468 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213469 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593470 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213471 json_retval));
[email protected]f103ab72009-09-02 17:10:593472}
3473
[email protected]b921cfd22010-02-25 16:57:513474WebCookieJar* RenderView::GetCookieJar() {
3475 return &cookie_jar_;
3476}
3477
initial.commit09911bf2008-07-26 23:55:293478void RenderView::SyncNavigationState() {
3479 if (!webview())
3480 return;
3481
[email protected]26aa0482009-09-30 16:55:273482 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173483 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293484 return;
[email protected]ca948a22009-06-25 19:36:173485
3486 Send(new ViewHostMsg_UpdateState(
3487 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293488}
3489
[email protected]b0950a72009-09-29 23:16:173490bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3491 // Make sure webview was not shut down.
3492 if (!webview())
3493 return false;
3494 // Create an image resource fetcher and assign it with a call back object.
3495 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273496 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173497 NewCallback(this, &RenderView::DidDownloadImage)));
3498 return true;
3499}
3500
3501void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293502 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173503 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473504 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3505 fetcher->id(),
3506 fetcher->image_url(),
3507 image.isNull(),
3508 image));
[email protected]b0950a72009-09-29 23:16:173509 // Dispose of the image fetcher.
3510 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3511 image_fetchers_.erase(fetcher);
3512 // We're in the callback from the ImageResourceFetcher, best to delay
3513 // deletion.
3514 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293515}
3516
[email protected]bf5c2ff392009-07-08 16:24:333517void RenderView::OnDownloadFavIcon(int id,
3518 const GURL& image_url,
3519 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343520 bool data_image_failed = false;
3521 if (image_url.SchemeIs("data")) {
3522 SkBitmap data_image = ImageFromDataUrl(image_url);
3523 data_image_failed = data_image.empty();
3524 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333525 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3526 data_image));
[email protected]f11ca0732009-04-11 00:09:343527 }
3528 }
3529
[email protected]bf5c2ff392009-07-08 16:24:333530 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173531 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333532 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3533 SkBitmap()));
3534 }
initial.commit09911bf2008-07-26 23:55:293535}
3536
[email protected]f11ca0732009-04-11 00:09:343537SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3538 std::string mime_type, char_set, data;
3539 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3540 // Decode the favicon using WebKit's image decoder.
3541 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3542 const unsigned char* src_data =
3543 reinterpret_cast<const unsigned char*>(&data[0]);
3544
3545 return decoder.Decode(src_data, data.size());
3546 }
3547 return SkBitmap();
3548}
3549
initial.commit09911bf2008-07-26 23:55:293550void RenderView::OnGetApplicationInfo(int page_id) {
3551 webkit_glue::WebApplicationInfo app_info;
3552 if (page_id == page_id_)
3553 webkit_glue::GetApplicationInfo(webview(), &app_info);
3554
3555 // Prune out any data URLs in the set of icons. The browser process expects
3556 // any icon with a data URL to have originated from a favicon. We don't want
3557 // to decode arbitrary data URLs in the browser process. See
3558 // http://b/issue?id=1162972
3559 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593560 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293561 app_info.icons.erase(app_info.icons.begin() + i);
3562 --i;
3563 }
3564 }
3565
3566 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3567}
3568
[email protected]7ccddb8c2009-08-04 17:36:553569GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293570 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553571 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293572 // If the URL that failed was secure, then the embedding web page was not
3573 // expecting a network attacker to be able to manipulate its contents. As
3574 // we fetch alternate error pages over HTTP, we would be allowing a network
3575 // attacker to manipulate the contents of the response if we tried to use
3576 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153577 return GURL();
initial.commit09911bf2008-07-26 23:55:293578 }
3579
3580 // Grab the base URL from the browser process.
3581 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153582 return GURL();
initial.commit09911bf2008-07-26 23:55:293583
3584 // Strip query params from the failed URL.
3585 GURL::Replacements remove_params;
3586 remove_params.ClearUsername();
3587 remove_params.ClearPassword();
3588 remove_params.ClearQuery();
3589 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553590 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503591 std::string spec_to_send = url_to_send.spec();
3592 // Notify link doctor of the url truncation by sending of "?" at the end.
3593 if (failed_url.has_query())
3594 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293595
3596 // Construct the query params to send to link doctor.
3597 std::string params(alternate_error_page_url_.query());
3598 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503599 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293600 params.append("&sourceid=chrome");
3601 params.append("&error=");
3602 switch (error_type) {
3603 case DNS_ERROR:
3604 params.append("dnserror");
3605 break;
3606
3607 case HTTP_404:
3608 params.append("http404");
3609 break;
3610
[email protected]5df266ac2008-10-15 19:50:133611 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333612 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133613 break;
3614
initial.commit09911bf2008-07-26 23:55:293615 default:
3616 NOTREACHED() << "unknown ErrorPageType";
3617 }
3618
3619 // OK, build the final url to return.
3620 GURL::Replacements link_doctor_params;
3621 link_doctor_params.SetQueryStr(params);
3622 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3623 return url;
3624}
3625
[email protected]0fdbf8c2010-07-08 20:33:013626WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3627 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493628}
3629
[email protected]6069da8c2009-10-20 20:33:493630void RenderView::OnFind(int request_id, const string16& search_text,
3631 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273632 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493633
3634 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493635 if (options.findNext) {
3636 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013637 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493638 } else {
[email protected]afdbd142010-07-10 08:01:233639 if (GetWebPluginFromPluginDocument()->startFind(
3640 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493641 } else {
3642 ReportNoFindInPageResults(request_id);
3643 }
3644 }
3645 return;
3646 }
3647
[email protected]b4bb2502009-10-01 22:35:273648 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273649 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293650 WebFrame* search_frame = focused_frame; // start searching focused frame.
3651
3652 bool multi_frame = (frame_after_main != main_frame);
3653
3654 // If we have multiple frames, we don't want to wrap the search within the
3655 // frame, so we check here if we only have main_frame in the chain.
3656 bool wrap_within_frame = !multi_frame;
3657
[email protected]b3f2b912009-04-09 16:18:523658 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293659 bool result = false;
3660
[email protected]7830da3e2009-11-06 16:27:263661 // If something is selected when we start searching it means we cannot just
3662 // increment the current match ordinal; we need to re-generate it.
3663 WebRange current_selection = focused_frame->selectionRange();
3664
initial.commit09911bf2008-07-26 23:55:293665 do {
[email protected]dd7daa82009-08-10 05:46:453666 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593667 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293668
3669 if (!result) {
3670 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223671 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293672
3673 // Find the next frame, but skip the invisible ones.
3674 do {
3675 // What is the next frame to search? (we might be going backwards). Note
3676 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593677 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273678 search_frame->traverseNext(true) :
3679 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453680 } while (!search_frame->hasVisibleContent() &&
3681 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293682
[email protected]884db412008-11-24 23:46:503683 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223684 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293685
3686 // If we have multiple frames and we have wrapped back around to the
3687 // focused frame, we need to search it once more allowing wrap within
3688 // the frame, otherwise it will report 'no match' if the focused frame has
3689 // reported matches, but no frames after the focused_frame contain a
3690 // match for the search word(s).
3691 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453692 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593693 request_id, search_text, options, true, // Force wrapping.
3694 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293695 }
3696 }
3697
[email protected]26aa0482009-09-30 16:55:273698 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293699 } while (!result && search_frame != focused_frame);
3700
[email protected]7830da3e2009-11-06 16:27:263701 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293702 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453703 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293704 } else {
3705 // If nothing is found, set result to "0 of 0", otherwise, set it to
3706 // "-1 of 1" to indicate that we found at least one item, but we don't know
3707 // yet what is active.
3708 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3709 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293710
[email protected]4f3dc372009-02-24 00:10:293711 // If we find no matches then this will be our last status update.
3712 // Otherwise the scoping effort will send more results.
3713 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293714
[email protected]4f3dc372009-02-24 00:10:293715 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403716 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593717 request_id,
[email protected]4f3dc372009-02-24 00:10:293718 match_count,
3719 selection_rect,
3720 ordinal,
3721 final_status_update));
initial.commit09911bf2008-07-26 23:55:293722
initial.commit09911bf2008-07-26 23:55:293723 // Scoping effort begins, starting with the mainframe.
3724 search_frame = main_frame;
3725
[email protected]dd7daa82009-08-10 05:46:453726 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293727
3728 do {
3729 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453730 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293731
3732 // We don't start another scoping effort unless at least one match has
3733 // been found.
3734 if (result) {
3735 // Start new scoping request. If the scoping function determines that it
3736 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453737 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593738 search_text,
3739 options,
initial.commit09911bf2008-07-26 23:55:293740 true); // reset the tickmarks
3741 }
3742
3743 // Iterate to the next frame. The frame will not necessarily scope, for
3744 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273745 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293746 } while (search_frame != main_frame);
3747 }
3748}
3749
[email protected]24a7f3c2010-03-25 08:26:493750void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3751 WebView* view = webview();
3752 if (!view)
3753 return;
3754
3755 WebDocument doc = view->mainFrame()->document();
3756 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013757 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493758 return;
3759 }
3760
3761 bool clear_selection =
3762 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3763 if (clear_selection)
3764 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3765
3766 WebFrame* frame = view->mainFrame();
3767 while (frame) {
3768 frame->stopFinding(clear_selection);
3769 frame = frame->traverseNext(false);
3770 }
3771
3772 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3773 WebFrame* focused_frame = view->focusedFrame();
3774 if (focused_frame) {
3775 WebDocument doc = focused_frame->document();
3776 if (!doc.isNull()) {
3777 WebNode node = doc.focusedNode();
3778 if (!node.isNull())
3779 node.simulateClick();
3780 }
3781 }
3782 }
3783}
3784
3785void RenderView::OnFindReplyAck() {
3786 // Check if there is any queued up request waiting to be sent.
3787 if (queued_find_reply_message_.get()) {
3788 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423789 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493790 }
3791}
3792
[email protected]8934a3b2010-02-25 00:34:003793bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353794 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003795 return current_content_settings_.settings[settings_type] !=
3796 CONTENT_SETTING_BLOCK;
3797}
3798
[email protected]6b3db4352010-08-12 16:14:223799void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
[email protected]8934a3b2010-02-25 00:34:003800 if (!content_blocked_[settings_type]) {
3801 content_blocked_[settings_type] = true;
[email protected]6b3db4352010-08-12 16:14:223802 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353803 }
[email protected]0de80162010-02-03 04:52:353804}
3805
[email protected]71b0d5d2010-02-15 05:43:073806void RenderView::ClearBlockedContentSettings() {
3807 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3808 content_blocked_[i] = false;
3809}
3810
[email protected]aad51d1c2010-08-05 08:38:093811WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame,
3812 const WebPluginParams& params,
3813 const FilePath& path,
3814 pepper::PluginModule* pepper_module) {
3815 WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params,
3816 pepper_delegate_.AsWeakPtr());
3817 if (plugin && !frame->parent() && frame->document().isPluginDocument()) {
3818 // If this is a full-page plugin hosting the internal PDF plugin, we want
3819 // to notify the browser so that it can treat things like zooming
3820 // differently.
3821 // TODO(sanjeevr): Use a Pepper interface to determine this rather than
3822 // hardcode this for the PDF plugin path.
3823 FilePath pdf_path;
3824 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
3825 if (path == pdf_path)
3826 Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_));
[email protected]0cdafff2010-07-26 09:54:373827 }
[email protected]aad51d1c2010-08-05 08:38:093828 return plugin;
3829}
[email protected]00152e92010-07-19 11:47:403830
[email protected]aad51d1c2010-08-05 08:38:093831WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame,
3832 const WebPluginParams& params,
3833 const FilePath& path,
3834 const std::string& mime_type) {
3835 std::string actual_mime_type(mime_type);
[email protected]00152e92010-07-19 11:47:403836 if (actual_mime_type.empty())
3837 actual_mime_type = params.mimeType.utf8();
3838
[email protected]aad51d1c2010-08-05 08:38:093839 return new webkit_glue::WebPluginImpl(frame, params, path,
[email protected]7a13e792010-08-03 08:18:243840 actual_mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403841}
3842
3843WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame,
[email protected]851b1eb2010-08-09 13:32:293844 const WebPluginParams& params,
3845 PluginGroup* group) {
[email protected]00152e92010-07-19 11:47:403846 // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed.
[email protected]851b1eb2010-08-09 13:32:293847 BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params, group);
[email protected]00152e92010-07-19 11:47:403848 WebViewPlugin* plugin = blocked_plugin->plugin();
[email protected]851b1eb2010-08-09 13:32:293849 WebView* web_view = plugin->web_view();
3850 webkit_preferences_.Apply(web_view);
[email protected]00152e92010-07-19 11:47:403851 return plugin;
3852}
3853
[email protected]40bd6582009-12-04 23:49:513854void RenderView::OnZoom(PageZoom::Function function) {
3855 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3856 return;
3857
[email protected]258d31122010-05-09 10:59:413858 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523859
[email protected]40bd6582009-12-04 23:49:513860 int zoom_level = webview()->zoomLevel();
3861 int new_zoom_level = webview()->setZoomLevel(false,
3862 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3863
[email protected]9d797f32010-04-23 07:17:543864 // Tell the browser which url got zoomed so it can update the saved values.
3865 Send(new ViewHostMsg_DidZoomURL(
3866 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513867}
3868
[email protected]9d797f32010-04-23 07:17:543869void RenderView::OnSetContentSettingsForLoadingURL(
3870 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013871 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543872 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013873}
3874
[email protected]9d797f32010-04-23 07:17:543875void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3876 int zoom_level) {
3877 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293878}
3879
[email protected]41fc0322009-09-04 22:23:403880void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273881 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293882}
3883
[email protected]a697f4c2009-09-14 22:30:183884void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273885 WebString no_encoding;
3886 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183887}
3888
[email protected]20ad2692009-11-20 18:27:203889bool RenderView::GetAllChildFrames(
3890 WebFrame* parent_frame,
3891 std::vector<WebFrame*>* frames_vector) const {
3892 if (!parent_frame)
3893 return false;
3894 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3895 child_frame = child_frame->nextSibling()) {
3896 frames_vector->push_back(child_frame);
3897 GetAllChildFrames(child_frame, frames_vector);
3898 }
3899 return true;
3900}
3901
[email protected]dd7daa82009-08-10 05:46:453902WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3903 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273904 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453905
3906 // xpath string can represent a frame deep down the tree (across multiple
3907 // frame DOMs).
3908 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3909 // should break into 2 xpaths
3910 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3911
[email protected]26aa0482009-09-30 16:55:273912 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453913
3914 std::wstring xpath_remaining = xpath;
3915 while (!xpath_remaining.empty()) {
3916 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3917 std::wstring xpath_child;
3918 if (delim_pos != std::wstring::npos) {
3919 xpath_child = xpath_remaining.substr(0, delim_pos);
3920 xpath_remaining.erase(0, delim_pos + 1);
3921 } else {
3922 xpath_remaining.swap(xpath_child);
3923 }
3924 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293925 }
3926
[email protected]dd7daa82009-08-10 05:46:453927 return frame;
initial.commit09911bf2008-07-26 23:55:293928}
3929
[email protected]f29acf52008-11-03 20:08:333930void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3931 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293932 WebFrame* web_frame = GetChildFrame(frame_xpath);
3933 if (!web_frame)
3934 return;
3935
[email protected]dd7daa82009-08-10 05:46:453936 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293937}
3938
[email protected]1810e132009-03-24 23:35:483939void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083940 const std::string& css,
3941 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483942 WebFrame* web_frame = GetChildFrame(frame_xpath);
3943 if (!web_frame)
3944 return;
3945
[email protected]ffaef0c2009-09-15 17:08:083946 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483947}
3948
[email protected]00c39612010-03-06 02:53:283949void RenderView::OnPepperPluginDestroy(
3950 WebPluginDelegatePepper* pepper_plugin) {
3951 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:013952 current_oldstyle_pepper_plugins_.find(pepper_plugin);
3953 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:283954 NOTREACHED();
3955 return;
3956 }
[email protected]53900d52010-06-16 04:25:013957 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473958
3959 // The plugin could have been destroyed while it was waiting for a file
3960 // choose callback, so check all pending completion callbacks and NULL them.
3961 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3962 file_chooser_completions_.begin();
3963 i != file_chooser_completions_.end(); /* nothing */) {
3964 if ((*i)->completion == pepper_plugin) {
3965 // We NULL the first one instead of deleting it because the plugin might
3966 // be the one waiting for a file choose callback. If the callback later
3967 // comes, we don't want to send the result to the next callback in line.
3968 if (i == file_chooser_completions_.begin())
3969 (*i)->completion = NULL;
3970 else
3971 i = file_chooser_completions_.erase(i);
3972 } else {
3973 ++i;
3974 }
3975 }
[email protected]00c39612010-03-06 02:53:283976}
3977
initial.commit09911bf2008-07-26 23:55:293978void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3979 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333980 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293981}
3982
[email protected]1810e132009-03-24 23:35:483983void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083984 const std::string& css,
3985 const std::string& id) {
3986 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413987
3988 // Notify RenderViewHost that css has been inserted into the frame.
3989 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483990}
3991
[email protected]7ea066a2009-04-06 20:21:593992void RenderView::OnAddMessageToConsole(
3993 const string16& frame_xpath,
3994 const string16& message,
3995 const WebConsoleMessage::Level& level) {
3996 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593997 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453998 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293999}
4000
[email protected]81e63782009-02-27 19:35:094001void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4002 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294003}
4004
4005void RenderView::OnSetDOMUIProperty(const std::string& name,
4006 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094007 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:294008 dom_ui_bindings_.SetProperty(name, value);
4009}
4010
4011void RenderView::OnReservePageIDRange(int size_of_range) {
4012 next_page_id_ += size_of_range + 1;
4013}
4014
[email protected]e80c73b2009-04-07 23:24:584015void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4016 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254017 bool ended,
4018 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034019 if (ended) {
[email protected]26aa0482009-09-30 16:55:274020 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204021 } else {
4022 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034023 }
initial.commit09911bf2008-07-26 23:55:294024}
4025
4026void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274027 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294028}
4029
initial.commit09911bf2008-07-26 23:55:294030void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:164031 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:084032#if defined(WEBKIT_BUG_41283_IS_FIXED)
4033 password_autocomplete_manager_.ReceivedPasswordFormFillData(webview(),
4034 form_data);
[email protected]ad24ccb2010-07-15 21:38:204035#else
4036 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:084037#endif
initial.commit09911bf2008-07-26 23:55:294038}
4039
4040void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584041 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254042 const gfx::Point& screen_point,
4043 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274044 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584045 drop_data.ToDragData(),
4046 drop_data.identity,
4047 client_point,
[email protected]1d9f4132009-09-08 17:29:254048 screen_point,
4049 ops);
initial.commit09911bf2008-07-26 23:55:294050
[email protected]1d9f4132009-09-08 17:29:254051 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294052}
4053
[email protected]e80c73b2009-04-07 23:24:584054void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254055 const gfx::Point& screen_point,
4056 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274057 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254058 client_point,
4059 screen_point,
4060 ops);
initial.commit09911bf2008-07-26 23:55:294061
[email protected]1d9f4132009-09-08 17:29:254062 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294063}
4064
4065void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274066 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294067}
4068
[email protected]e80c73b2009-04-07 23:24:584069void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4070 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274071 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294072}
4073
4074void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594075 webkit_preferences_ = prefs;
4076 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294077}
4078
4079void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4080 alternate_error_page_url_ = url;
4081}
4082
[email protected]a0c7153e2009-12-09 14:36:334083void RenderView::OnCustomContextMenuAction(unsigned action) {
4084 webview()->performCustomContextMenuAction(action);
4085}
4086
[email protected]d4a00a72010-01-29 01:44:424087void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024088 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424089 const std::string& source_lang,
4090 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024091 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4092 translate_script);
[email protected]d4a00a72010-01-29 01:44:424093}
4094
[email protected]85d252e2010-04-06 22:21:024095void RenderView::OnRevertTranslation(int page_id) {
4096 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324097}
4098
initial.commit09911bf2008-07-26 23:55:294099void RenderView::OnInstallMissingPlugin() {
4100 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594101 if (first_default_plugin_)
4102 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294103}
4104
[email protected]97c5c592010-08-03 08:22:214105void RenderView::OnLoadBlockedPlugins() {
4106 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4107 Source<RenderView>(this),
4108 NotificationService::NoDetails());
4109}
4110
[email protected]cdaf8d02010-03-30 19:52:474111void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364112 // This could happen if we navigated to a different page before the user
4113 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474114 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364115 return;
4116
[email protected]cdaf8d02010-03-30 19:52:474117 WebVector<WebString> ws_file_names(paths.size());
4118 for (size_t i = 0; i < paths.size(); ++i)
4119 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464120
[email protected]cdaf8d02010-03-30 19:52:474121 if (file_chooser_completions_.front()->completion)
4122 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4123 file_chooser_completions_.pop_front();
4124
4125 // If there are more pending file chooser requests, schedule one now.
4126 if (!file_chooser_completions_.empty()) {
4127 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4128 file_chooser_completions_.front()->params));
4129 }
initial.commit09911bf2008-07-26 23:55:294130}
4131
4132void RenderView::OnEnableViewSourceMode() {
4133 if (!webview())
4134 return;
[email protected]26aa0482009-09-30 16:55:274135 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294136 if (!main_frame)
4137 return;
4138
[email protected]dd7daa82009-08-10 05:46:454139 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294140}
4141
[email protected]770dd8b2010-05-24 18:11:394142void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4143 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244144 if (send_preferred_size_changes_)
4145 return;
[email protected]9fb325e2010-05-06 18:23:244146 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394147
4148 // WebKit doesn't send a notification of the effective height of the page
4149 // changes, so poll for it.
4150 // TODO: Add a notification for this to WebKit, remove polling. After that's
4151 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4152 // http://crbug.com/44850
4153 if (flags & kPreferredSizeHeightThisIsSlow) {
4154 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4155 &RenderView::CheckPreferredSize);
4156 }
[email protected]0666aef2009-05-13 19:48:084157}
4158
[email protected]cda45c02010-02-25 19:28:104159void RenderView::OnDisableScrollbarsForSmallWindows(
4160 const gfx::Size& disable_scrollbar_size_limit) {
4161 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4162}
4163
[email protected]80d96fa2009-06-10 22:34:514164void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4165 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374166 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034167#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414168 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4169 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464170 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324171
[email protected]644d77e2010-01-27 01:03:104172 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324173 webview()->setScrollbarColors(
4174 renderer_prefs.thumb_inactive_color,
4175 renderer_prefs.thumb_active_color,
4176 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104177 webview()->setSelectionColors(
4178 renderer_prefs.active_selection_bg_color,
4179 renderer_prefs.active_selection_fg_color,
4180 renderer_prefs.inactive_selection_bg_color,
4181 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:014182 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:104183 }
[email protected]7a74e102009-09-03 00:16:564184#endif
[email protected]80d96fa2009-06-10 22:34:514185}
4186
[email protected]952cb702009-10-07 05:50:284187void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4188 const WebMediaPlayerAction& action) {
4189 if (webview())
4190 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564191}
4192
[email protected]7b291f92009-08-14 05:43:534193void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:514194 // When this is first set, the bindings aren't fully loaded. We only need
4195 // to call through this API after the page has already been loaded. It's
4196 // also called in didCreateDocumentElement to bootstrap.
4197 if (view_type_ != ViewType::INVALID) {
4198 if (type == ViewType::EXTENSION_MOLE ||
4199 type == ViewType::EXTENSION_TOOLSTRIP) {
4200 ExtensionProcessBindings::SetViewType(webview(), type);
4201 }
4202 }
[email protected]7b291f92009-08-14 05:43:534203 view_type_ = type;
4204}
4205
4206void RenderView::OnUpdateBrowserWindowId(int window_id) {
4207 browser_window_id_ = window_id;
4208}
4209
[email protected]b3df5a42010-05-11 14:31:094210void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364211 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414212 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114213 accessibility_.reset(WebAccessibilityCache::create());
4214 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:414215
[email protected]b3df5a42010-05-11 14:31:094216 WebAccessibilityObject src_tree = webview()->accessibilityObject();
4217 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
4218 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504219}
4220
[email protected]aef92842010-05-21 16:54:364221void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4222 if (!accessibility_.get())
4223 return;
4224 if (accessibility_->isValidId(acc_obj_id)) {
4225 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4226 // By convention, calling SetFocus on the root of the tree (id = 1000)
4227 // should clear the current focus. Otherwise set the focus to the new
4228 // node.
4229 if (acc_obj_id == 1000)
4230 webview()->clearFocusedNode();
4231 else
4232 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4233 }
4234}
4235
4236void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4237 if (!accessibility_.get())
4238 return;
4239 if (accessibility_->isValidId(acc_obj_id)) {
4240 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4241 }
4242}
4243
initial.commit09911bf2008-07-26 23:55:294244void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4245 const GURL& page_url) {
4246 // Prepare list to storage all savable resource links.
4247 std::vector<GURL> resources_list;
4248 std::vector<GURL> referrers_list;
4249 std::vector<GURL> frames_list;
4250 webkit_glue::SavableResourcesResult result(&resources_list,
4251 &referrers_list,
4252 &frames_list);
4253
[email protected]dbeb3952009-10-13 18:01:184254 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4255 webview(),
4256 page_url,
4257 &result,
4258 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294259 // If something is wrong when collecting all savable resource links,
4260 // send empty list to embedder(browser) to tell it failed.
4261 referrers_list.clear();
4262 resources_list.clear();
4263 frames_list.clear();
4264 }
4265
4266 // Send result of all savable resource links to embedder.
4267 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4268 resources_list,
4269 referrers_list,
4270 frames_list));
4271}
4272
4273void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324274 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314275 const std::vector<FilePath>& local_paths,
4276 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074277
4278 // Convert std::vector of GURLs to WebVector<WebURL>
4279 WebVector<WebURL> weburl_links(links);
4280
4281 // Convert std::vector of std::strings to WebVector<WebString>
4282 WebVector<WebString> webstring_paths(local_paths.size());
4283 for (size_t i = 0; i < local_paths.size(); i++)
4284 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4285
4286 WebPageSerializer::serialize(webview()->mainFrame(),
4287 true, this, weburl_links, webstring_paths,
4288 webkit_glue::FilePathToWebString(
4289 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294290}
4291
[email protected]d9ec5c0f2009-12-23 11:55:074292void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4293 const WebCString& data,
4294 WebPageSerializerClient::PageSerializationStatus status) {
4295 Send(new ViewHostMsg_SendSerializedHtmlData(
4296 routing_id_,
4297 frame_url,
4298 data.data(),
4299 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294300}
4301
[email protected]9b18a84f2010-06-10 15:54:044302void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274303 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474304 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294305}
4306
[email protected]eb6b87a2009-07-24 15:57:394307void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294308 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4309 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4310 // in the onunload handler from appearing. For now, we're bypassing that and
4311 // calling the FrameLoader's CloseURL method directly. This should be
4312 // revisited to avoid having two ways to close a page. Having a single way
4313 // to close that can run onunload is also useful for fixing
4314 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274315 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294316 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454317 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174318 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294319 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4320 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454321 if (url.SchemeIs(chrome::kHttpScheme) ||
4322 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294323 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294324 }
[email protected]26aa0482009-09-30 16:55:274325 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294326
[email protected]ab9eabac2010-03-16 16:54:104327 // Reset stats
4328 cross_origin_access_count_ = 0;
4329 same_origin_access_count_ = 0;
4330
[email protected]eb6b87a2009-07-24 15:57:394331 // Just echo back the params in the ACK.
4332 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294333}
4334
4335void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574336#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294337 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014338 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574339#else // defined(OS_WIN)
4340 // TODO(port): we don't support theming on non-Windows platforms yet
4341 NOTIMPLEMENTED();
4342#endif
initial.commit09911bf2008-07-26 23:55:294343}
4344
[email protected]9b18a84f2010-06-10 15:54:044345void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4346 const std::string& origin,
4347 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154348 if (message.empty())
4349 return;
[email protected]28790922009-03-09 19:48:374350 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4351 target);
[email protected]3ac14a052008-08-15 21:22:154352}
4353
[email protected]0aa55312008-10-17 21:53:084354void RenderView::OnDisassociateFromPopupCount() {
4355 if (decrement_shared_popup_at_destruction_)
4356 shared_popup_counter_->data--;
4357 shared_popup_counter_ = new SharedRenderViewCounter(0);
4358 decrement_shared_popup_at_destruction_ = false;
4359}
4360
[email protected]15d79e12009-08-02 19:23:454361bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4362 const WebURLError& error,
4363 bool replace) {
4364 // We only show alternate error pages in the main frame. They are
4365 // intended to assist the user when navigating, so there is not much
4366 // value in showing them for failed subframes. Ideally, we would be
4367 // able to use the TYPED transition type for this, but that flag is
4368 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454369 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454370 return false;
4371
4372 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374373 // connection failure.
[email protected]15d79e12009-08-02 19:23:454374 int ec = error.reason;
4375 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4376 ec != net::ERR_CONNECTION_FAILED &&
4377 ec != net::ERR_CONNECTION_REFUSED &&
4378 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374379 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454380 return false;
4381
4382 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554383 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454384 if (!error_page_url.is_valid())
4385 return false;
4386
4387 // Load an empty page first so there is an immediate response to the error,
4388 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454389 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454390 GURL(kUnreachableWebDataURL),
4391 error.unreachableURL,
4392 replace);
4393
4394 // Now, create a fetcher for the error page and associate it with the data
4395 // source we just created via the LoadHTMLString call. That way if another
4396 // navigation occurs, the fetcher will get destroyed.
4397 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454398 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454399 navigation_state->set_alt_error_page_fetcher(
4400 new AltErrorPageResourceFetcher(
4401 error_page_url, frame, error,
4402 NewCallback(this, &RenderView::AltErrorPageFinished)));
4403 return true;
4404}
4405
initial.commit09911bf2008-07-26 23:55:294406std::string RenderView::GetAltHTMLForTemplate(
4407 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394408 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294409 ResourceBundle::GetSharedInstance().GetRawDataResource(
4410 template_resource_id));
4411
4412 if (template_html.empty()) {
4413 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4414 return "";
4415 }
[email protected]7cd22a52009-07-14 00:40:254416
initial.commit09911bf2008-07-26 23:55:294417 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254418 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294419 template_html, &error_strings, "t");
4420}
[email protected]0e79b9e2009-02-13 04:20:484421
[email protected]15d79e12009-08-02 19:23:454422void RenderView::AltErrorPageFinished(WebFrame* frame,
4423 const WebURLError& original_error,
4424 const std::string& html) {
4425 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554426
4427 // If we failed to download the alternate error page, fall back to the
4428 // original error page if present. Otherwise, LoadNavigationErrorPage
4429 // will simply display a default error page.
4430 const std::string* html_to_load = &html;
4431 if (html.empty()) {
4432 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454433 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554434 html_to_load = &navigation_state->postponed_data();
4435 }
4436 LoadNavigationErrorPage(
4437 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454438}
4439
[email protected]30f75e62009-02-25 22:01:004440void RenderView::OnMoveOrResizeStarted() {
4441 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474442 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004443}
4444
[email protected]30f75e62009-02-25 22:01:004445void RenderView::OnResize(const gfx::Size& new_size,
4446 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104447 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474448 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104449
4450 if (send_preferred_size_changes_) {
4451 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4452 // either width or height, allow scroll bars.
4453 bool allow_scrollbars = (
4454 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244455 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104456 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4457 }
4458 }
4459
[email protected]30f75e62009-02-25 22:01:004460 RenderWidget::OnResize(new_size, resizer_rect);
4461}
[email protected]0aa477bd2009-03-23 22:21:434462
[email protected]00c39612010-03-06 02:53:284463void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014464 // Notify the pepper plugins that we started painting.
4465 pepper_delegate_.ViewInitiatedPaint();
4466
4467 // Notify any "old-style" pepper plugins that we started painting. This is
4468 // used for internal bookkeeping only, so we know that the set can not change
4469 // under us.
[email protected]00c39612010-03-06 02:53:284470 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014471 current_oldstyle_pepper_plugins_.begin();
4472 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284473 (*i)->RenderViewInitiatedPaint();
4474}
4475
4476void RenderView::DidFlushPaint() {
4477 // Notify any pepper plugins that we painted. This will call into the plugin,
4478 // and we it may ask to close itself as a result. This will, in turn, modify
4479 // our set, possibly invalidating the iterator. So we iterate on a copy that
4480 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014481 pepper_delegate_.ViewFlushedPaint();
4482
4483 // Notify any old-style pepper plugins that we painted. This will call into
4484 // the plugin, and we it may ask to close itself as a result. This will, in
4485 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4486 // a copy that won't change out from under us.
4487 // This should be deleted when we don't support old Pepper anymore.
4488 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284489 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4490 i != plugins.end(); ++i) {
4491 // The copy above makes sure our iterator is never invalid if some plugins
4492 // are destroyed. But some plugin may decide to close all of its views in
4493 // response to a paint in one of them, so we need to make sure each one is
4494 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014495 if (current_oldstyle_pepper_plugins_.find(*i) !=
4496 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284497 (*i)->RenderViewFlushedPaint();
4498 }
4499
4500 WebFrame* main_frame = webview()->mainFrame();
4501
4502 // If we have a provisional frame we are between the start and commit stages
4503 // of loading and we don't want to save stats.
4504 if (!main_frame->provisionalDataSource()) {
4505 WebDataSource* ds = main_frame->dataSource();
4506 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4507 DCHECK(navigation_state);
4508
4509 Time now = Time::Now();
4510 if (navigation_state->first_paint_time().is_null()) {
4511 navigation_state->set_first_paint_time(now);
4512 }
4513 if (navigation_state->first_paint_after_load_time().is_null() &&
4514 !navigation_state->finish_load_time().is_null()) {
4515 navigation_state->set_first_paint_after_load_time(now);
4516 }
4517 }
4518}
4519
[email protected]05d478752009-04-08 23:38:164520void RenderView::OnClearFocusedNode() {
4521 if (webview())
[email protected]26aa0482009-09-30 16:55:274522 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164523}
4524
[email protected]699ab0d2009-04-23 23:19:144525void RenderView::OnSetBackground(const SkBitmap& background) {
4526 if (webview())
[email protected]b4bb2502009-10-01 22:35:274527 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144528
4529 SetBackground(background);
4530}
4531
[email protected]8c66c5a2009-07-22 17:26:344532void RenderView::OnSetActive(bool active) {
4533 if (webview())
[email protected]b4bb2502009-10-01 22:35:274534 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264535
4536#if defined(OS_MACOSX)
4537 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4538 for (plugin_it = plugin_delegates_.begin();
4539 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4540 (*plugin_it)->SetWindowFocus(active);
4541 }
4542#endif
[email protected]8c66c5a2009-07-22 17:26:344543}
4544
[email protected]6ce7abc52010-02-02 18:40:144545#if defined(OS_MACOSX)
4546void RenderView::OnSetWindowVisibility(bool visible) {
4547 // Inform plugins that their container has changed visibility.
4548 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4549 for (plugin_it = plugin_delegates_.begin();
4550 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4551 (*plugin_it)->SetContainerVisibility(visible);
4552 }
4553}
[email protected]1e6e3c992010-02-08 15:52:134554
[email protected]4d51d5bf2010-07-26 18:48:264555void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4556 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134557 // Inform plugins that their window's frame has changed.
4558 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4559 for (plugin_it = plugin_delegates_.begin();
4560 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4561 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4562 }
4563}
[email protected]6ce7abc52010-02-02 18:40:144564#endif // OS_MACOSX
4565
[email protected]309d7a282009-03-24 09:18:274566void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584567 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394568 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324569 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474570 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394571 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4572 name,
4573 args,
4574 source_url,
4575 request_id,
[email protected]2f25d7b92009-06-10 00:06:474576 has_callback));
[email protected]309d7a282009-03-24 09:18:274577}
4578
[email protected]c6619182009-05-12 14:59:324579void RenderView::OnExtensionResponse(int request_id,
4580 bool success,
4581 const std::string& response,
4582 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354583 ExtensionProcessBindings::HandleResponse(
4584 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274585}
[email protected]c20210e62009-04-03 21:39:264586
[email protected]078b34612009-09-19 19:31:514587void RenderView::InjectToolstripCSS() {
4588 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4589 return;
4590
4591 static const base::StringPiece toolstrip_css(
4592 ResourceBundle::GetSharedInstance().GetRawDataResource(
4593 IDR_EXTENSION_TOOLSTRIP_CSS));
4594 std::string css = toolstrip_css.as_string();
4595 InsertCSS(L"", css, "ToolstripDefaultCSS");
4596}
4597
[email protected]7120f132009-07-20 21:05:374598void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494599 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194600 bool requires_incognito_access,
4601 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494602 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194603 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374604}
4605
[email protected]e7e4f3c2009-04-21 15:24:084606// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264607//
[email protected]c20210e62009-04-03 21:39:264608// The time points we keep are
4609// request: time document was requested by user
4610// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254611// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294612// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264613// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294614// first_paint: first paint performed
4615// first_paint_after_load: first paint performed after load is finished
4616// begin: request if it was user requested, start otherwise
4617//
[email protected]e7e4f3c2009-04-21 15:24:084618// It's possible for the request time not to be set, if a client
4619// redirect had been done (the user never requested the page)
4620// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294621// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264622void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504623 // Configuration for PLT related histograms.
4624 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4625 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4626 static const size_t kPLTCount(100);
4627 #define PLT_HISTOGRAM(name, sample) \
4628 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4629
[email protected]26aa0482009-09-30 16:55:274630 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564631 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454632 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564633
[email protected]f9f4841b2010-03-20 05:41:424634 // If we've already dumped, do nothing.
4635 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294636 return;
[email protected]cf9a7bc2010-06-11 18:54:504637
4638 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454639 Time start = navigation_state->start_load_time();
4640 if (start.is_null())
4641 return; // Probably very premature abandonment of page.
4642 Time commit = navigation_state->commit_load_time();
4643 if (commit.is_null())
4644 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504645
[email protected]b855ebe62010-05-12 23:01:454646 // We properly handle null values for the next 3 variables.
4647 Time request = navigation_state->request_time();
4648 Time first_paint = navigation_state->first_paint_time();
4649 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454650 Time finish = navigation_state->finish_load_time();
4651 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564652
[email protected]f9f4841b2010-03-20 05:41:424653 // Handle case where user hits "stop" or "back" before loading completely.
4654 bool abandoned_page = finish.is_null();
4655 if (abandoned_page) {
4656 finish = Time::Now();
4657 navigation_state->set_finish_load_time(finish);
4658 }
[email protected]f9f4841b2010-03-20 05:41:424659
[email protected]cf9a7bc2010-06-11 18:54:504660 if (finish_doc.is_null()) {
4661 DCHECK(abandoned_page); // how can the doc have finished but not the page?
4662 if (!abandoned_page)
4663 return; // Don't try to record a stat which is broken.
4664 finish_doc = finish;
4665 navigation_state->set_finish_document_load_time(finish_doc);
4666 }
4667
4668 // Note: Client side redirects will have no request time.
4669 Time begin = request.is_null() ? start : request;
4670 TimeDelta begin_to_finish_doc = finish_doc - begin;
4671 TimeDelta begin_to_finish = finish - begin;
4672 TimeDelta start_to_finish = finish - start;
[email protected]ef1d8d322010-06-13 18:31:254673 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424674
[email protected]a7ccc4d2010-01-27 08:14:484675 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504676
4677 // Aggregate PLT data across all link types.
4678 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4679 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4680 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254681 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504682 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
4683 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish - finish_doc);
4684 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
4685 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish);
4686 if (!request.is_null()) {
4687 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
4688 PLT_HISTOGRAM("PLT.RequestToFinish", finish - request);
4689 }
4690 PLT_HISTOGRAM("PLT.CommitToFinish", finish - commit);
4691 if (!first_paint.is_null()) {
4692 DCHECK(begin <= first_paint);
4693 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4694 DCHECK(commit <= first_paint);
4695 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4696 }
4697 if (!first_paint_after_load.is_null()) {
4698 DCHECK(begin <= first_paint_after_load);
4699 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4700 first_paint_after_load - begin);
4701 DCHECK(commit <= first_paint_after_load);
4702 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4703 first_paint_after_load - commit);
4704 DCHECK(finish <= first_paint_after_load);
4705 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
4706 first_paint_after_load - finish);
4707 }
4708 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
4709 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish);
4710
4711 // Load type related histograms.
4712 switch (load_type) {
4713 case NavigationState::UNDEFINED_LOAD:
4714 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
4715 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish);
4716 break;
4717 case NavigationState::RELOAD:
4718 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
4719 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish);
4720 break;
4721 case NavigationState::HISTORY_LOAD:
4722 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
4723 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish);
4724 break;
4725 case NavigationState::NORMAL_LOAD:
4726 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
4727 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish);
4728 break;
4729 case NavigationState::LINK_LOAD_NORMAL:
4730 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4731 begin_to_finish_doc);
4732 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", begin_to_finish);
4733 break;
4734 case NavigationState::LINK_LOAD_RELOAD:
4735 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4736 begin_to_finish_doc);
4737 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", begin_to_finish);
4738 break;
4739 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4740 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4741 begin_to_finish_doc);
4742 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", begin_to_finish);
4743 break;
4744 case NavigationState::LINK_LOAD_CACHE_ONLY:
4745 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4746 begin_to_finish_doc);
4747 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", begin_to_finish);
4748 break;
4749 default:
4750 break;
4751 }
4752
4753 // Histograms to determine if DNS prefetching has an impact on PLT.
4754 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4755 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4756 if (use_dns_histogram) {
4757 UMA_HISTOGRAM_ENUMERATION(
4758 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4759 abandoned_page ? 1 : 0, 2);
4760 UMA_HISTOGRAM_ENUMERATION(
4761 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4762 load_type, NavigationState::kLoadTypeMax);
4763 switch (load_type) {
4764 case NavigationState::NORMAL_LOAD:
4765 PLT_HISTOGRAM(FieldTrial::MakeName(
4766 "PLT.BeginToFinish_NormalLoad", "DnsImpact"), begin_to_finish);
4767 break;
4768 case NavigationState::LINK_LOAD_NORMAL:
4769 PLT_HISTOGRAM(FieldTrial::MakeName(
4770 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4771 begin_to_finish);
4772 break;
4773 case NavigationState::LINK_LOAD_RELOAD:
4774 PLT_HISTOGRAM(FieldTrial::MakeName(
4775 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
4776 begin_to_finish);
4777 break;
4778 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4779 PLT_HISTOGRAM(FieldTrial::MakeName(
4780 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4781 begin_to_finish);
4782 break;
4783 default:
4784 break;
4785 }
4786 }
4787
[email protected]8a3125a712010-08-09 18:58:514788 // Histograms to determine if content prefetching has an impact on PLT.
4789 static const bool prefetching_fieldtrial =
4790 FieldTrialList::Find("Prefetch") &&
4791 !FieldTrialList::Find("Prefetch")->group_name().empty();
4792 static const bool prefetching_explicitly_disabled =
4793 CommandLine::ForCurrentProcess()->HasSwitch(
4794 switches::kDisableContentPrefetch);
4795 if (navigation_state->was_prefetcher()) {
4796 if (!prefetching_explicitly_disabled) {
4797 PLT_HISTOGRAM("PLT.BeginToFinishDoc_ContentPrefetcher",
4798 begin_to_finish_doc);
4799 PLT_HISTOGRAM("PLT.BeginToFinish_ContentPrefetcher",
4800 begin_to_finish);
4801 }
4802 if (prefetching_fieldtrial) {
4803 PLT_HISTOGRAM(
4804 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher",
4805 "Prefetch"),
4806 begin_to_finish_doc);
4807 PLT_HISTOGRAM(
4808 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher",
4809 "Prefetch"),
4810 begin_to_finish);
4811 }
4812 }
4813 if (navigation_state->was_referred_by_prefetcher()) {
4814 if (!prefetching_explicitly_disabled) {
4815 PLT_HISTOGRAM("PLT.BeginToFinishDoc_ContentPrefetcherReferrer",
4816 begin_to_finish_doc);
4817 PLT_HISTOGRAM("PLT.BeginToFinish_ContentPrefetcherReferrer",
4818 begin_to_finish);
4819 }
4820 if (prefetching_fieldtrial) {
4821 PLT_HISTOGRAM(
4822 FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcherReferrer",
4823 "Prefetch"),
4824 begin_to_finish_doc);
4825 PLT_HISTOGRAM(
4826 FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcherReferrer",
4827 "Prefetch"),
4828 begin_to_finish);
4829 }
4830 }
4831 if (prefetching_fieldtrial) {
4832 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName("PLT.Abandoned", "Prefetch"),
4833 abandoned_page ? 1 : 0, 2);
4834 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinishDoc", "Prefetch"),
4835 begin_to_finish_doc);
4836 PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"),
4837 begin_to_finish);
4838 }
4839
[email protected]cf9a7bc2010-06-11 18:54:504840 // Histograms to determine if the number of connections has an
4841 // impact on PLT.
4842 // TODO(jar): Consider removing the per-link-type versions. We
4843 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
[email protected]97546492010-08-09 05:14:494844 static bool use_connection_impact_histogram(
[email protected]cf9a7bc2010-06-11 18:54:504845 FieldTrialList::Find("ConnCountImpact") &&
4846 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
[email protected]97546492010-08-09 05:14:494847 if (use_connection_impact_histogram) {
[email protected]cf9a7bc2010-06-11 18:54:504848 UMA_HISTOGRAM_ENUMERATION(
4849 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
4850 abandoned_page ? 1 : 0, 2);
4851 switch (load_type) {
4852 case NavigationState::NORMAL_LOAD:
4853 PLT_HISTOGRAM(FieldTrial::MakeName(
4854 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
4855 begin_to_finish);
4856 break;
4857 case NavigationState::LINK_LOAD_NORMAL:
4858 PLT_HISTOGRAM(FieldTrial::MakeName(
4859 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
4860 begin_to_finish);
4861 break;
4862 case NavigationState::LINK_LOAD_RELOAD:
4863 PLT_HISTOGRAM(FieldTrial::MakeName(
4864 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
4865 begin_to_finish);
4866 break;
4867 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4868 PLT_HISTOGRAM(FieldTrial::MakeName(
4869 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
4870 begin_to_finish);
4871 break;
4872 default:
4873 break;
4874 }
4875 }
4876
[email protected]78a258a2010-08-02 16:34:264877 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:004878 static bool use_idle_socket_timeout_histogram(
4879 FieldTrialList::Find("IdleSktToImpact") &&
4880 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
4881 if (use_idle_socket_timeout_histogram) {
4882 UMA_HISTOGRAM_ENUMERATION(
4883 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
4884 abandoned_page ? 1 : 0, 2);
4885 switch (load_type) {
4886 case NavigationState::NORMAL_LOAD:
4887 PLT_HISTOGRAM(FieldTrial::MakeName(
4888 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
4889 begin_to_finish);
4890 break;
4891 case NavigationState::LINK_LOAD_NORMAL:
4892 PLT_HISTOGRAM(FieldTrial::MakeName(
4893 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
4894 begin_to_finish);
4895 break;
4896 case NavigationState::LINK_LOAD_RELOAD:
4897 PLT_HISTOGRAM(FieldTrial::MakeName(
4898 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
4899 begin_to_finish);
4900 break;
4901 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4902 PLT_HISTOGRAM(FieldTrial::MakeName(
4903 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
4904 begin_to_finish);
4905 break;
4906 default:
4907 break;
4908 }
4909 }
4910
[email protected]78a258a2010-08-02 16:34:264911 // Histograms to determine effect of number of connections per proxy.
4912 static bool use_proxy_connection_impact_histogram(
4913 FieldTrialList::Find("ProxyConnectionImpact") &&
4914 !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty());
4915 if (use_proxy_connection_impact_histogram) {
4916 UMA_HISTOGRAM_ENUMERATION(
4917 FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
4918 abandoned_page ? 1 : 0, 2);
4919 switch (load_type) {
4920 case NavigationState::NORMAL_LOAD:
4921 PLT_HISTOGRAM(FieldTrial::MakeName(
4922 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
4923 begin_to_finish);
4924 break;
4925 case NavigationState::LINK_LOAD_NORMAL:
4926 PLT_HISTOGRAM(FieldTrial::MakeName(
4927 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
4928 begin_to_finish);
4929 break;
4930 case NavigationState::LINK_LOAD_RELOAD:
4931 PLT_HISTOGRAM(FieldTrial::MakeName(
4932 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
4933 begin_to_finish);
4934 break;
4935 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4936 PLT_HISTOGRAM(FieldTrial::MakeName(
4937 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
4938 begin_to_finish);
4939 break;
4940 default:
4941 break;
4942 }
4943 }
4944
[email protected]cf9a7bc2010-06-11 18:54:504945 // Histograms to determine if SDCH has an impact.
4946 // TODO(jar): Consider removing per-link load types and the enumeration.
4947 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4948 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4949 if (use_sdch_histogram) {
4950 UMA_HISTOGRAM_ENUMERATION(
4951 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
4952 load_type, NavigationState::kLoadTypeMax);
4953 switch (load_type) {
4954 case NavigationState::NORMAL_LOAD:
4955 PLT_HISTOGRAM(FieldTrial::MakeName(
4956 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
4957 begin_to_finish);
4958 break;
4959 case NavigationState::LINK_LOAD_NORMAL:
4960 PLT_HISTOGRAM(FieldTrial::MakeName(
4961 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4962 begin_to_finish);
4963 break;
4964 case NavigationState::LINK_LOAD_RELOAD:
4965 PLT_HISTOGRAM(FieldTrial::MakeName(
4966 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4967 begin_to_finish);
4968 break;
4969 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4970 PLT_HISTOGRAM(FieldTrial::MakeName(
4971 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4972 begin_to_finish);
4973 break;
4974 case NavigationState::LINK_LOAD_CACHE_ONLY:
4975 PLT_HISTOGRAM(FieldTrial::MakeName(
4976 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4977 begin_to_finish);
4978 break;
4979 default:
4980 break;
4981 }
4982 }
4983
4984 // Histograms to determine if cache size has an impact on PLT.
4985 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4986 !FieldTrialList::Find("CacheSize")->group_name().empty());
4987 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4988 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
4989 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
4990 // StartToFinish or BeginToFinish would be better.
4991 PLT_HISTOGRAM(FieldTrial::MakeName(
4992 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
4993 }
4994
[email protected]115f5542010-07-28 06:48:214995
4996 GURL url = GURL(main_frame->url());
4997
4998 // Histograms to determine if SPDY has an impact for https traffic.
[email protected]cf9a7bc2010-06-11 18:54:504999 // TODO(mbelshe): After we've seen the difference between BeginToFinish
5000 // and StartToFinish, consider removing one or the other.
5001 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
5002 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]115f5542010-07-28 06:48:215003 if (use_spdy_histogram && url.SchemeIs("https") &&
5004 navigation_state->was_npn_negotiated()) {
[email protected]30b35882010-06-14 21:21:015005 UMA_HISTOGRAM_ENUMERATION(
5006 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
5007 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:505008 switch (load_type) {
5009 case NavigationState::LINK_LOAD_NORMAL:
5010 PLT_HISTOGRAM(FieldTrial::MakeName(
5011 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5012 begin_to_finish);
5013 PLT_HISTOGRAM(FieldTrial::MakeName(
5014 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5015 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:255016 PLT_HISTOGRAM(FieldTrial::MakeName(
5017 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
5018 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:505019 break;
5020 case NavigationState::NORMAL_LOAD:
5021 PLT_HISTOGRAM(FieldTrial::MakeName(
5022 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5023 begin_to_finish);
5024 PLT_HISTOGRAM(FieldTrial::MakeName(
5025 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
5026 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:255027 PLT_HISTOGRAM(FieldTrial::MakeName(
5028 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
5029 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:505030 break;
5031 default:
5032 break;
5033 }
5034 }
5035
[email protected]115f5542010-07-28 06:48:215036 // Histograms to compare the impact of alternate protocol over http traffic:
5037 // when spdy is used vs. when http is used.
5038 if (url.SchemeIs("http") &&
5039 navigation_state->was_alternate_protocol_available()) {
[email protected]193b0b892010-06-26 03:57:575040 if (!navigation_state->was_npn_negotiated()) {
5041 // This means that even there is alternate protocols for npn_http or
5042 // npn_spdy, they are not taken (due to the fieldtrial).
5043 switch (load_type) {
5044 case NavigationState::LINK_LOAD_NORMAL:
5045 PLT_HISTOGRAM(
5046 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
5047 start_to_finish);
5048 PLT_HISTOGRAM(
5049 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
5050 start_to_commit);
5051 break;
5052 case NavigationState::NORMAL_LOAD:
5053 PLT_HISTOGRAM(
5054 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
5055 start_to_finish);
5056 PLT_HISTOGRAM(
5057 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
5058 start_to_commit);
5059 break;
5060 default:
5061 break;
5062 }
5063 } else if (navigation_state->was_fetched_via_spdy()) {
5064 switch (load_type) {
5065 case NavigationState::LINK_LOAD_NORMAL:
5066 PLT_HISTOGRAM(
5067 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
5068 start_to_finish);
5069 PLT_HISTOGRAM(
5070 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
5071 start_to_commit);
5072 break;
5073 case NavigationState::NORMAL_LOAD:
5074 PLT_HISTOGRAM(
5075 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
5076 start_to_finish);
5077 PLT_HISTOGRAM(
5078 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
5079 start_to_commit);
5080 break;
5081 default:
5082 break;
5083 }
5084 }
5085 }
5086
[email protected]cf9a7bc2010-06-11 18:54:505087 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:505088 if (navigation_state->was_fetched_via_proxy()) {
5089 if (url.SchemeIs("https")) {
5090 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish);
5091 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
5092 abandoned_page ? 1 : 0, 2);
5093 } else {
5094 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish);
5095 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
5096 abandoned_page ? 1 : 0, 2);
5097 }
5098 } else {
5099 if (url.SchemeIs("https")) {
5100 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", start_to_finish);
5101 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
5102 abandoned_page ? 1 : 0, 2);
5103 } else {
5104 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", start_to_finish);
5105 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
5106 abandoned_page ? 1 : 0, 2);
5107 }
5108 }
[email protected]a7ccc4d2010-01-27 08:14:485109
[email protected]ab9eabac2010-03-16 16:54:105110 // Site isolation metrics.
5111 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
5112 cross_origin_access_count_);
5113 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
5114 same_origin_access_count_);
5115
[email protected]cf9a7bc2010-06-11 18:54:505116 // Log some PLT data to the error log.
5117 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:295118
5119 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:415120
5121 // Since there are currently no guarantees that renderer histograms will be
5122 // sent to the browser, we initiate a PostTask here to be sure that we send
5123 // the histograms we generated. Without this call, pages that don't have an
5124 // on-close-handler might generate data that is lost when the renderer is
5125 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:485126 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
5127 // should post when the onload is complete, so that it doesn't interfere with
5128 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:415129 if (RenderThread::current()) {
5130 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:135131 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:415132 }
[email protected]c20210e62009-04-03 21:39:265133}
[email protected]e846d0d2009-05-20 00:53:065134
[email protected]f8999642009-10-27 21:39:425135void RenderView::LogNavigationState(const NavigationState* state,
5136 const WebDataSource* ds) const {
5137 // Because this function gets called on every page load,
5138 // take extra care to optimize it away if logging is turned off.
5139 if (logging::LOG_INFO < logging::GetMinLogLevel())
5140 return;
5141
5142 DCHECK(state);
5143 DCHECK(ds);
5144 GURL url(ds->request().url());
5145 Time start = state->start_load_time();
5146 Time finish = state->finish_load_time();
5147 // TODO(mbelshe): should we log more stats?
5148 LOG(INFO) << "PLT: "
5149 << (finish - start).InMilliseconds()
5150 << "ms "
5151 << url.spec();
5152}
5153
[email protected]cc0445f2009-10-13 16:09:085154void RenderView::focusAccessibilityObject(
5155 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:065156#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:155157 // TODO(dglazkov): Current logic implies that focus change can only be made
5158 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5159 // where accessibility is initialized. We should determine whether that's
5160 // right.
5161 if (!accessibility_.get())
5162 return;
[email protected]e846d0d2009-05-20 00:53:065163
5164 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:155165 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:065166
5167 // If id is valid, alert the browser side that an accessibility focus change
5168 // occurred.
5169 if (acc_obj_id >= 0)
5170 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
5171
5172#else // defined(OS_WIN)
5173 // TODO(port): accessibility not yet implemented
5174 NOTIMPLEMENTED();
5175#endif
5176}
[email protected]daa8c58e2009-06-15 17:21:105177
[email protected]a3018be2010-03-09 04:28:485178void RenderView::didChangeAccessibilityObjectState(
5179 const WebKit::WebAccessibilityObject& acc_obj) {
5180#if defined(OS_WIN)
5181 // TODO(dglazkov): Current logic implies that a state change can only be made
5182 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5183 // where accessibility is initialized. We should determine whether that's
5184 // right.
5185 if (!accessibility_.get())
5186 return;
5187
5188 // Retrieve the accessibility object id of the AccessibilityObject.
5189 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
5190
5191 // If id is valid, alert the browser side that an accessibility object state
5192 // change occurred.
5193 if (acc_obj_id >= 0)
5194 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
5195 acc_obj_id));
5196
5197#else // defined(OS_WIN)
5198 // TODO(port): accessibility not yet implemented
5199 NOTIMPLEMENTED();
5200#endif
5201}
5202
[email protected]0fda7272009-06-26 15:49:335203void RenderView::Print(WebFrame* frame, bool script_initiated) {
5204 DCHECK(frame);
5205 if (print_helper_.get() == NULL) {
5206 print_helper_.reset(new PrintWebViewHelper(this));
5207 }
5208 print_helper_->Print(frame, script_initiated);
5209}
[email protected]446705872009-09-10 07:22:485210
5211void RenderView::OnSetEditCommandsForNextKeyEvent(
5212 const EditCommands& edit_commands) {
5213 edit_commands_ = edit_commands;
5214}
5215
[email protected]61f5a7b2009-12-22 22:21:205216void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275217 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355218 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205219 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5220 false));
[email protected]912256b32009-09-18 09:47:355221 return;
5222 }
5223
[email protected]fa7b6b542009-11-03 05:02:305224 WebDataSource* ds = main_frame->dataSource();
5225 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5226 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205227 pending_code_execution_queue_.push(
5228 linked_ptr<ViewMsg_ExecuteCode_Params>(
5229 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305230 return;
5231 }
5232
[email protected]61f5a7b2009-12-22 22:21:205233 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305234}
5235
5236void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205237 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485238 // Don't execute scripts in gallery pages.
5239 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085240 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5241 && !CommandLine::ForCurrentProcess()->HasSwitch(
5242 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485243 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5244 return;
5245 }
5246
[email protected]20ad2692009-11-20 18:27:205247 std::vector<WebFrame*> frame_vector;
5248 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205249 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205250 GetAllChildFrames(frame, &frame_vector);
5251
5252 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5253 frame_it != frame_vector.end(); ++frame_it) {
5254 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205255 if (params.is_javascript) {
5256 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5257 continue;
5258
[email protected]20ad2692009-11-20 18:27:205259 std::vector<WebScriptSource> sources;
5260 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205261 WebScriptSource(WebString::fromUTF8(params.code)));
5262 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205263 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205264 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205265 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5266 } else {
[email protected]61f5a7b2009-12-22 22:21:205267 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205268 }
[email protected]912256b32009-09-18 09:47:355269 }
5270
[email protected]61f5a7b2009-12-22 22:21:205271 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355272}
5273
[email protected]60c42a8c72009-10-09 04:08:595274void RenderView::Close() {
5275 // We need to grab a pointer to the doomed WebView before we destroy it.
5276 WebView* doomed = webview();
5277 RenderWidget::Close();
5278 Singleton<ViewMap>::get()->erase(doomed);
5279}
5280
[email protected]446705872009-09-10 07:22:485281void RenderView::DidHandleKeyEvent() {
5282 edit_commands_.clear();
5283}
5284
[email protected]941e4552010-02-01 21:23:435285#if defined(OS_MACOSX)
5286void RenderView::OnWasHidden() {
5287 RenderWidget::OnWasHidden();
5288
5289 // Inform plugins that their container is no longer visible.
5290 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5291 for (plugin_it = plugin_delegates_.begin();
5292 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5293 (*plugin_it)->SetContainerVisibility(false);
5294 }
5295}
5296
5297void RenderView::OnWasRestored(bool needs_repainting) {
5298 RenderWidget::OnWasRestored(needs_repainting);
5299
5300 // Inform plugins that their container is now visible.
5301 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5302 for (plugin_it = plugin_delegates_.begin();
5303 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5304 (*plugin_it)->SetContainerVisibility(true);
5305 }
5306}
[email protected]1e6e3c992010-02-08 15:52:135307
5308void RenderView::OnSetFocus(bool enable) {
5309 RenderWidget::OnSetFocus(enable);
5310
[email protected]7d3c02c2010-05-05 23:10:315311 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135312 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5313 for (plugin_it = plugin_delegates_.begin();
5314 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315315 // RenderWidget's call to setFocus can cause the underlying webview's
5316 // activation state to change just like a call to setIsActive.
5317 if (enable)
5318 (*plugin_it)->SetWindowFocus(true);
5319 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135320 }
5321 }
5322}
[email protected]941e4552010-02-01 21:23:435323#endif // OS_MACOSX
5324
[email protected]83dde542009-09-11 20:59:555325void RenderView::EnsureDocumentTag() {
5326 // TODO(darin): There's actually no reason for this to be here. We should
5327 // have the browser side manage the document tag.
5328#if defined(OS_MACOSX)
5329 if (!has_document_tag_) {
5330 // Make the call to get the tag.
5331 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5332 has_document_tag_ = true;
5333 }
5334#endif
5335}
[email protected]12636df2009-09-28 22:32:215336
[email protected]43f28f832010-02-03 02:28:485337#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035338gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235339 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485340 gfx::PluginWindowHandle window = NULL;
5341 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235342 routing_id(), opaque, root, &window));
[email protected]43f28f832010-02-03 02:28:485343 return window;
5344}
5345
5346void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5347 if (window)
5348 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5349}
5350
[email protected]44ce0b12010-03-12 16:45:335351void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5352 int32 width,
5353 int32 height,
5354 uint64 io_surface_identifier) {
5355 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485356 routing_id(), window, width, height, io_surface_identifier));
5357}
5358
[email protected]44ce0b12010-03-12 16:45:335359void RenderView::AcceleratedSurfaceSetTransportDIB(
5360 gfx::PluginWindowHandle window,
5361 int32 width,
5362 int32 height,
5363 TransportDIB::Handle transport_dib) {
5364 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075365 routing_id(), window, width, height, transport_dib));
5366}
5367
[email protected]44ce0b12010-03-12 16:45:335368TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5369 size_t size) {
[email protected]1aef98132010-02-23 18:00:075370 TransportDIB::Handle dib_handle;
5371 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385372 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075373 return dib_handle;
5374 // Return an invalid handle if Send() fails.
5375 return TransportDIB::DefaultHandleValue();
5376}
5377
[email protected]44ce0b12010-03-12 16:45:335378void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075379 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5380}
5381
[email protected]44ce0b12010-03-12 16:45:335382void RenderView::AcceleratedSurfaceBuffersSwapped(
5383 gfx::PluginWindowHandle window) {
5384 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485385}
5386#endif
[email protected]58c321d2010-02-19 12:11:285387
[email protected]cdaf8d02010-03-30 19:52:475388bool RenderView::ScheduleFileChooser(
5389 const ViewHostMsg_RunFileChooser_Params& params,
5390 WebFileChooserCompletion* completion) {
5391 static const size_t kMaximumPendingFileChooseRequests = 4;
5392 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5393 // This sanity check prevents too many file choose requests from getting
5394 // queued which could DoS the user. Getting these is most likely a
5395 // programming error (there are many ways to DoS the user so it's not
5396 // considered a "real" security check), either in JS requesting many file
5397 // choosers to pop up, or in a plugin.
5398 //
5399 // TODO(brettw) we might possibly want to require a user gesture to open
5400 // a file picker, which will address this issue in a better way.
5401 return false;
5402 }
5403
5404 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5405 new PendingFileChooser(params, completion)));
5406 if (file_chooser_completions_.size() == 1) {
5407 // Actually show the browse dialog when this is the first request.
5408 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5409 }
5410 return true;
5411}
5412
[email protected]290838a2010-04-27 17:37:015413void RenderView::OnPageTranslated() {
5414 WebFrame* frame = webview()->mainFrame();
5415 if (!frame)
5416 return;
5417
5418 // The page is translated, so try to extract the form data again.
[email protected]679f128f2010-07-22 22:57:445419 autofill_helper_.FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015420}
5421
[email protected]8a5f7002010-03-31 13:47:355422WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285423 if (!geolocation_dispatcher_.get())
5424 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5425 return geolocation_dispatcher_.get();
5426}
[email protected]61c9f032010-03-31 23:04:195427
[email protected]638694c2010-08-04 22:24:115428WebKit::WebSpeechInputController* RenderView::speechInputController(
5429 WebKit::WebSpeechInputListener* listener) {
5430 if (!speech_input_dispatcher_.get())
5431 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5432 return speech_input_dispatcher_.get();
5433}
5434
[email protected]57ead352010-08-11 14:42:535435WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
5436 if (!device_orientation_dispatcher_.get())
5437 device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this));
5438 return device_orientation_dispatcher_.get();
5439}
5440
[email protected]8079b362010-05-07 18:37:455441bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195442 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455443 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195444 if (frame->parent() != NULL)
5445 return false;
5446
[email protected]f0a3d0b2010-08-06 22:51:535447 // Navigations initiated within Webkit are not sent out to the external host
5448 // in the following cases.
5449 // 1. The url scheme or the frame url scheme is not http/https
5450 // 2. The origin of the url and the frame is the same in which case the
5451 // opener relationship is maintained.
5452 // 3. Anchor navigation within the same page.
5453 // 4. Reloads/form submits/back forward navigations
5454 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5455 return false;
5456
5457 GURL frame_url(frame->url());
5458 if (!frame_url.SchemeIs("http") && !frame_url.SchemeIs("https"))
5459 return false;
5460
[email protected]61c9f032010-03-31 23:04:195461 // Skip if navigation is on the same page (using '#').
[email protected]f0a3d0b2010-08-06 22:51:535462 GURL frame_origin = frame_url.GetOrigin();
[email protected]61c9f032010-03-31 23:04:195463 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5464 // The link click could stay on the same page, in cases where it sends some
5465 // parameters to the same URL.
5466 if (type == WebKit::WebNavigationTypeLinkClicked)
5467 return true;
5468
5469 if (last_top_level_navigation_page_id_ != page_id_ &&
5470 // Not interested in reloads.
5471 type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015472 type != WebKit::WebNavigationTypeFormSubmitted &&
5473 type != WebKit::WebNavigationTypeBackForward) {
[email protected]61c9f032010-03-31 23:04:195474 return true;
5475 }
5476 }
[email protected]d0ed50d2010-06-22 01:01:325477 // Not interested in reloads.
5478 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015479 type != WebKit::WebNavigationTypeFormSubmitted &&
5480 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325481 // The opener relationship between the new window and the parent allows the
5482 // new window to script the parent and vice versa. This is not allowed if
5483 // the origins of the two domains are different. This can be treated as a
5484 // top level navigation and routed back to the host.
5485 WebKit::WebFrame* opener = frame->opener();
5486 if (opener) {
5487 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5488 return true;
5489 }
5490 }
[email protected]61c9f032010-03-31 23:04:195491 return false;
5492}