blob: b863fbb64f6b445160c5a3b6727ee0f2243be0de [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]e09ba552009-02-05 03:26:2937#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2638#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5940#include "chrome/common/url_constants.h"
[email protected]534c66c2010-04-28 22:53:1141#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2543#include "chrome/renderer/audio_message_filter.h"
[email protected]00152e92010-07-19 11:47:4044#include "chrome/renderer/blocked_plugin.h"
[email protected]e4ac5df2009-03-17 15:33:1145#include "chrome/renderer/devtools_agent.h"
46#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3547#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3248#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3549#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3750#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2851#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2952#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5653#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1154#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5655#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1256#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3057#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5058#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2559#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2860#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2661#include "chrome/renderer/render_view_visitor.h"
[email protected]035545f2010-04-09 13:10:2162#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3463#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]638694c2010-08-04 22:24:1164#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4665#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3566#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2967#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2968#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2969#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4270#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5671#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1572#include "gfx/color_utils.h"
73#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5774#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2675#include "gfx/point.h"
76#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2777#include "grit/generated_resources.h"
78#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3479#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2980#include "net/base/escape.h"
81#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0082#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1083#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3084#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:0685#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4986#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:2687#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0788#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4989#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3291#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4992#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3593#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5994#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4995#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4198#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5099#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49100#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32101#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07102#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49103#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40104#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17105#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49106#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49107#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
108#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
109#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
110#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
111#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
112#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40113#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49114#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34115#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49116#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
117#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
118#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
119#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
120#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
121#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26122#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11123#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04124#include "webkit/appcache/web_application_cache_host_impl.h"
initial.commit09911bf2008-07-26 23:55:29125#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59126#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24127#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24128#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34129#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26130#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17131#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51132#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09133#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26134#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38135#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17136#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29137#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30138#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23139#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30140#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40141#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09142#include "webkit/glue/site_isolation_metrics.h"
initial.commit09911bf2008-07-26 23:55:29143#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29144#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17145#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29146
[email protected]6c8afae52009-01-22 02:24:57147#if defined(OS_WIN)
148// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57149// * theming
[email protected]cd818412010-03-19 03:23:15150#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03151#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46152#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33153#elif defined(OS_MACOSX)
154#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57155#endif
156
[email protected]80f584d92010-01-21 03:59:04157using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26158using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33159using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45160using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59161using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24162using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17163using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56164using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10165using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09166using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15167using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08168using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21169using WebKit::WebApplicationCacheHost;
170using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41171using WebKit::WebColor;
172using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59173using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44174using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51175using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07176using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55177using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28178using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29179using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00180using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58181using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25182using WebKit::WebDragOperation;
183using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51184using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47185using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49186using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59187using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48188using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45189using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17190using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41191using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50192using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17193using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28194using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17195using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28196using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28197using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51198using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07199using WebKit::WebPageSerializer;
200using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17201using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40202using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49203using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09204using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52205using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59206using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51207using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52208using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40209using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35210using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29211using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59212using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42213using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02214using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34215using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28216using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51217using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52218using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28219using WebKit::WebURL;
220using WebKit::WebURLError;
221using WebKit::WebURLRequest;
222using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28223using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03224using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28225using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43226using WebKit::WebWorker;
227using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11228using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33229
initial.commit09911bf2008-07-26 23:55:29230//-----------------------------------------------------------------------------
231
[email protected]3354d3e2010-06-10 19:53:02232typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
233
initial.commit09911bf2008-07-26 23:55:29234// define to write the time necessary for thumbnail/DOM text retrieval,
235// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29236// #define TIME_TEXT_RETRIEVAL
237
238// maximum number of characters in the document to index, any text beyond this
239// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57240static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29241
242// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37243static const int kThumbnailWidth = 212;
244static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29245
246// Delay in milliseconds that we'll wait before capturing the page contents
247// and thumbnail.
248static const int kDelayForCaptureMs = 500;
249
250// Typically, we capture the page data once the page is loaded.
251// Sometimes, the page never finishes to load, preventing the page capture
252// To workaround this problem, we always perform a capture after the following
253// delay.
254static const int kDelayForForcedCaptureMs = 6000;
255
[email protected]882daa92009-11-05 16:31:31256// Time, in seconds, we delay before sending content state changes (such as form
257// state and scroll position) to the browser. We delay sending changes to avoid
258// spamming the browser.
259// To avoid having tab/session restore require sending a message to get the
260// current content state during tab closing we use a shorter timeout for the
261// foreground renderer. This means there is a small window of time from which
262// content state is modified and not sent to session restore, but this is
263// better than having to wake up all renderers during shutdown.
264static const int kDelaySecondsForContentStateSyncHidden = 5;
265static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29266
[email protected]0aa55312008-10-17 21:53:08267// The maximum number of popups that can be spawned from one page.
268static const int kMaximumNumberOfUnacknowledgedPopups = 25;
269
initial.commit09911bf2008-07-26 23:55:29270static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16271 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29272
[email protected]50b691c2008-10-31 19:08:35273static const char* const kBackForwardNavigationScheme = "history";
274
[email protected]726985e22009-06-18 21:09:28275static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
276 WebVector<WebURL> urls;
277 ds->redirectChain(urls);
278 result->reserve(urls.size());
279 for (size_t i = 0; i < urls.size(); ++i)
280 result->push_back(urls[i]);
281}
282
[email protected]61f5a7b2009-12-22 22:21:20283static bool UrlMatchesPermissions(
284 const GURL& url, const std::vector<URLPattern>& host_permissions) {
285 for (size_t i = 0; i < host_permissions.size(); ++i) {
286 if (host_permissions[i].MatchesUrl(url))
287 return true;
288 }
289
290 return false;
291}
292
[email protected]30507922010-01-15 16:48:23293static bool PaintViewIntoCanvas(WebView* view,
294 skia::PlatformCanvas& canvas) {
295 view->layout();
296 const WebSize& size = view->size();
297
298 if (!canvas.initialize(size.width, size.height, true))
299 return false;
300
301 view->paint(webkit_glue::ToWebCanvas(&canvas),
302 WebRect(0, 0, size.width, size.height));
303 // TODO: Add a way to snapshot the whole page, not just the currently
304 // visible part.
305
306 return true;
307}
308
309// Calculates how "boring" a thumbnail is. The boring score is the
310// 0,1 ranged percentage of pixels that are the most common
311// luma. Higher boring scores indicate that a higher percentage of a
312// bitmap are all the same brightness.
313static double CalculateBoringScore(SkBitmap* bitmap) {
314 int histogram[256] = {0};
315 color_utils::BuildLumaHistogram(bitmap, histogram);
316
317 int color_count = *std::max_element(histogram, histogram + 256);
318 int pixel_count = bitmap->width() * bitmap->height();
319 return static_cast<double>(color_count) / pixel_count;
320}
321
[email protected]12bc8472010-04-15 07:29:40322// True if |frame| contains content that is white-listed for content settings.
323static bool IsWhitelistedForContentSettings(WebFrame* frame) {
324 WebSecurityOrigin origin = frame->securityOrigin();
325 if (origin.isEmpty())
326 return false; // Uninitialized document?
327
328 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
329 return true; // Browser UI elements should still work.
330
331 // If the scheme is ftp: or file:, an empty file name indicates a directory
332 // listing, which requires JavaScript to function properly.
333 GURL frame_url = frame->url();
334 const char* kDirProtocols[] = { "ftp", "file" };
335 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
336 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
337 return frame_url.SchemeIs(kDirProtocols[i]) &&
338 frame_url.ExtractFileName().empty();
339 }
340 }
341
342 return false;
343}
344
[email protected]3a8eecb2010-04-22 23:56:30345// Returns true if the frame is navigating to an URL either into or out of an
346// extension app's extent.
347static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
348 if (!RenderThread::current())
349 return false;
350
351 // If the URL is still empty, this is a window.open navigation. Check the
352 // opener's URL.
353 GURL old_url(frame->url());
354 if (old_url.is_empty() && frame->opener())
355 old_url = frame->opener()->url();
356
357 std::string old_extension =
[email protected]4fdbc1492010-07-01 01:20:59358 RenderThread::current()->GetExtensionIdByURL(old_url);
359 if (!old_extension.empty()) {
360 if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) ==
361 old_extension) {
362 return false;
363 }
364 }
365
[email protected]3a8eecb2010-04-22 23:56:30366 std::string new_extension =
[email protected]4fdbc1492010-07-01 01:20:59367 RenderThread::current()->GetExtensionIdByURL(new_url);
368 return old_extension != new_extension;
[email protected]3a8eecb2010-04-22 23:56:30369}
370
[email protected]3354d3e2010-06-10 19:53:02371// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
372// if it failed.
373//
374// Note this only works on Windows at this time. It always returns 'unknown'
375// on other platforms.
[email protected]e5106202010-06-11 21:12:36376static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17377 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02378 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08379 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02380 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02381 Language cld_language =
[email protected]e5106202010-06-11 21:12:36382 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08383 &num_languages, NULL, &text_bytes);
384 // We don't trust the result if the CLD reports that the detection is not
385 // reliable, or if the actual text used to detect the language was less than
386 // 100 bytes (short texts can often lead to wrong results).
387 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02388 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
389 // We should not use LanguageCode_ISO_639_1 because it does not cover all
390 // the languages CLD can detect. As a result, it'll return the invalid
391 // language code for tradtional Chinese among others.
392 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
393 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
394 // for Simplified Chinese.
395 language = LanguageCodeWithDialects(cld_language);
396 }
397 return language;
398}
399
initial.commit09911bf2008-07-26 23:55:29400///////////////////////////////////////////////////////////////////////////////
401
[email protected]60c42a8c72009-10-09 04:08:59402int32 RenderView::next_page_id_ = 1;
403
[email protected]cdaf8d02010-03-30 19:52:47404struct RenderView::PendingFileChooser {
405 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
406 WebFileChooserCompletion* c)
407 : params(p),
408 completion(c) {
409 }
410 ViewHostMsg_RunFileChooser_Params params;
411 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
412};
413
[email protected]2fab253a2009-08-17 23:00:59414RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34415 const WebPreferences& webkit_preferences,
416 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12417 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02418 webkit_preferences_(webkit_preferences),
419 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09420 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02421 send_preferred_size_changes_(false),
422 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24423 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21424 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02425 opened_by_user_gesture_(true),
426 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24427 page_id_(-1),
428 last_page_id_sent_to_browser_(-1),
429 last_indexed_page_id_(-1),
[email protected]3354d3e2010-06-10 19:53:02430 last_top_level_navigation_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00431 history_list_offset_(-1),
432 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24433 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55434#if defined(OS_MACOSX)
435 has_document_tag_(false),
436#endif
[email protected]98324892009-09-09 21:16:05437 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10438 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17439 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02440 target_url_status_(TARGET_NONE),
441 spelling_panel_visible_(false),
442 view_type_(ViewType::INVALID),
443 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18444 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]3354d3e2010-06-10 19:53:02445 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
446 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]03f57072010-07-14 17:36:08447 ALLOW_THIS_IN_INITIALIZER_LIST(password_autocomplete_manager_(this)),
[email protected]679f128f2010-07-22 22:57:44448 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_helper_(this)),
[email protected]3354d3e2010-06-10 19:53:02449 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
450 ALLOW_THIS_IN_INITIALIZER_LIST(
451 notification_provider_(new NotificationProvider(this))),
452 session_storage_namespace_id_(session_storage_namespace_id),
453 decrement_shared_popup_at_destruction_(false) {
[email protected]71b0d5d2010-02-15 05:43:07454 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29455}
456
457RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08458 if (decrement_shared_popup_at_destruction_)
459 shared_popup_counter_->data--;
460
[email protected]b0950a72009-09-29 23:16:17461 // Dispose of un-disposed image fetchers.
462 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
463 i != image_fetchers_.end(); ++i) {
464 delete *i;
465 }
466
[email protected]a1128322009-10-06 18:38:46467 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47468 while (!file_chooser_completions_.empty()) {
469 if (file_chooser_completions_.front()->completion) {
470 file_chooser_completions_.front()->completion->didChooseFile(
471 WebVector<WebString>());
472 }
473 file_chooser_completions_.pop_front();
474 }
[email protected]a1128322009-10-06 18:38:46475
[email protected]83dde542009-09-11 20:59:55476#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05477 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55478 if (has_document_tag_)
479 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
480#endif
[email protected]98324892009-09-09 21:16:05481
[email protected]5fb88962009-04-16 19:03:25482 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59483
484#ifndef NDEBUG
485 // Make sure we are no longer referenced by the ViewMap.
486 ViewMap* views = Singleton<ViewMap>::get();
487 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
488 DCHECK_NE(this, it->second) << "Failed to call Close?";
489#endif
490}
491
492/*static*/
493void RenderView::ForEach(RenderViewVisitor* visitor) {
494 ViewMap* views = Singleton<ViewMap>::get();
495 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
496 if (!visitor->Visit(it->second))
497 return;
498 }
499}
500
501/*static*/
502RenderView* RenderView::FromWebView(WebView* webview) {
503 ViewMap* views = Singleton<ViewMap>::get();
504 ViewMap::iterator it = views->find(webview);
505 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29506}
507
508/*static*/
[email protected]0aa55312008-10-17 21:53:08509RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24510 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15511 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08512 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51513 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08514 const WebPreferences& webkit_prefs,
515 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34516 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26517 int64 session_storage_namespace_id,
518 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29519 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34520 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
521 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29522 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29523 opener_id,
[email protected]80d96fa2009-06-10 22:34:51524 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08525 counter,
[email protected]8ab04652010-06-12 02:47:26526 routing_id,
527 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29528 return view;
529}
530
531/*static*/
532void RenderView::SetNextPageID(int32 next_page_id) {
533 // This method should only be called during process startup, and the given
534 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05535 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29536 DCHECK(next_page_id >= next_page_id_);
537 next_page_id_ = next_page_id;
538}
539
[email protected]4d51d5bf2010-07-26 18:48:26540WebKit::WebView* RenderView::webview() const{
541 return static_cast<WebKit::WebView*>(webwidget());
542}
543
[email protected]afe3a1672009-11-17 19:04:12544void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56545 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
546}
547
[email protected]a3a8fb6d2009-10-22 20:12:51548void RenderView::PluginCrashed(const FilePath& plugin_path) {
549 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29550}
551
[email protected]aad51d1c2010-08-05 08:38:09552WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
553 const WebPluginParams& params) {
554 WebPluginInfo info;
555 bool found;
556 std::string mime_type;
557 Send(new ViewHostMsg_GetPluginInfo(
558 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
559 &info, &mime_type));
560 if (!found || !info.enabled)
561 return NULL;
562 scoped_refptr<pepper::PluginModule> pepper_module =
563 PepperPluginRegistry::GetInstance()->GetModule(info.path);
564 if (pepper_module)
565 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
566 else
567 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
568}
569
[email protected]d8fd6fa2010-02-01 15:54:26570#if defined(OS_MACOSX)
571void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
572 plugin_delegates_.insert(delegate);
573}
574
575void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
576 plugin_delegates_.erase(delegate);
577}
578#endif
579
[email protected]18bcc3c2009-01-27 21:39:15580void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29581 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51582 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08583 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26584 int32 routing_id,
585 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29586 DCHECK(!webview());
587
588 if (opener_id != MSG_ROUTING_NONE)
589 opener_id_ = opener_id;
590
[email protected]0aa55312008-10-17 21:53:08591 if (counter) {
592 shared_popup_counter_ = counter;
593 shared_popup_counter_->data++;
594 decrement_shared_popup_at_destruction_ = true;
595 } else {
596 shared_popup_counter_ = new SharedRenderViewCounter(0);
597 decrement_shared_popup_at_destruction_ = false;
598 }
599
[email protected]58bfc6b2009-06-24 09:45:02600 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04601
[email protected]9a6c6232010-06-25 11:46:49602 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59603 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59604 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27605 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23606 if (!frame_name.empty())
607 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29608
[email protected]d3ba77272009-09-03 00:06:09609 OnSetRendererPrefs(renderer_prefs);
610
initial.commit09911bf2008-07-26 23:55:29611 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24612 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29613 // Take a reference on behalf of the RenderThread. This will be balanced
614 // when we receive ViewMsg_Close.
615 AddRef();
616
617 // If this is a popup, we must wait for the CreatingNew_ACK message before
618 // completing initialization. Otherwise, we can finish it now.
619 if (opener_id == MSG_ROUTING_NONE) {
620 did_show_ = true;
621 CompleteInit(parent_hwnd);
622 }
623
624 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29625
[email protected]58bfc6b2009-06-24 09:45:02626 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09627 if (command_line.HasSwitch(switches::kDomAutomationController))
628 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29629
[email protected]5fb88962009-04-16 19:03:25630 audio_message_filter_ = new AudioMessageFilter(routing_id_);
631 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29632}
633
634void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27635 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27636 if (main_frame)
637 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26638
[email protected]b2abac72009-02-26 12:39:28639 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11640 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28641 return;
[email protected]b4b967e2009-04-22 11:33:05642 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
643 return;
[email protected]b6849bda2009-10-14 23:59:26644 if (notification_provider_->OnMessageReceived(message))
645 return;
[email protected]58c321d2010-02-19 12:11:28646 if (geolocation_dispatcher_.get() &&
647 geolocation_dispatcher_->OnMessageReceived(message)) {
648 return;
649 }
[email protected]638694c2010-08-04 22:24:11650 if (speech_input_dispatcher_.get() &&
651 speech_input_dispatcher_->OnMessageReceived(message)) {
652 return;
653 }
[email protected]b2abac72009-02-26 12:39:28654
initial.commit09911bf2008-07-26 23:55:29655 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04656 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
657 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29658 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01659 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29660 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
661 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56662 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29663 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
664 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
665 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
666 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27667#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35668 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27669#endif
initial.commit09911bf2008-07-26 23:55:29670 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
671 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05672 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
673 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
674 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04675 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29676 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
677 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
678 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15679 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29680 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49681 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
682 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17683 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54684 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
685 OnSetContentSettingsForLoadingURL)
686 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
687 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29688 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18689 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
690 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28691 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33692 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29693 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48694 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29695 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29696 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29697 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
698 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
699 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
700 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
701 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45702 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29703 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50704 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
705 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29706 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
707 OnDragSourceSystemDragEnded)
708 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29709 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
710 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
711 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
712 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:21713 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:29714 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
715 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29716 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
717 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04718 IPC_MESSAGE_HANDLER(
719 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
720 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29721 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04722 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29723 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
724 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45725 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04726 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08727 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
728 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24729 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
730 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48731 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
732 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40733 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
734 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00735 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27736 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37737 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
738 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16739 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14740 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25741 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
742 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10743 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
744 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51745 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53746 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
747 OnUpdateBrowserWindowId)
748 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
749 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56750 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34751 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14752#if defined(OS_MACOSX)
753 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13754 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14755#endif
[email protected]446705872009-09-10 07:22:48756 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33757 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35758 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
759 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33760 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
761 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42762 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02763 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09764 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36765 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
766 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
767 OnAccessibilityDoDefaultAction)
[email protected]634a6f92008-12-01 21:39:31768
initial.commit09911bf2008-07-26 23:55:29769 // Have the super handle all other messages.
770 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
771 IPC_END_MESSAGE_MAP()
772}
773
[email protected]9b18a84f2010-06-10 15:54:04774void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27775 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29776 if (!main_frame)
777 return;
778
779 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45780 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29781 if (url.is_empty())
782 return;
783
784 if (size_.IsEmpty())
785 return; // Don't create an empty thumbnail!
786
787 ThumbnailScore score;
788 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02789 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15790 &thumbnail, &score))
791 return;
792
initial.commit09911bf2008-07-26 23:55:29793 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46794 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29795}
796
[email protected]9b18a84f2010-06-10 15:54:04797void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23798 SkBitmap snapshot;
799 bool error = false;
800
801 WebFrame* main_frame = webview()->mainFrame();
802 if (!main_frame)
803 error = true;
804
805 if (!error && !CaptureSnapshot(webview(), &snapshot))
806 error = true;
807
808 DCHECK(error == snapshot.empty()) <<
809 "Snapshot should be empty on error, non-empty otherwise.";
810
811 // Send the snapshot to the browser process.
812 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
813}
814
[email protected]068637222009-01-29 16:58:07815void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29816 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58817 if (webview()) {
818 // If the user has selected text in the currently focused frame we print
819 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27820 if (webview()->focusedFrame()->hasSelection())
821 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58822 else
[email protected]26aa0482009-09-30 16:55:27823 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58824 }
initial.commit09911bf2008-07-26 23:55:29825}
826
[email protected]82270452009-06-19 15:58:01827void RenderView::OnPrintingDone(int document_cookie, bool success) {
828 // Ignoring document cookie here since only one print job can be outstanding
829 // per renderer and document_cookie is 0 when printing is successful.
830 DCHECK(print_helper_.get());
831 if (print_helper_.get() != NULL) {
832 print_helper_->DidFinishPrinting(success);
833 }
834}
835
initial.commit09911bf2008-07-26 23:55:29836void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
837 if (load_id != page_id_)
838 return; // this capture call is no longer relevant due to navigation
839 if (load_id == last_indexed_page_id_)
840 return; // we already indexed this page
841
842 if (!webview())
843 return;
844
[email protected]26aa0482009-09-30 16:55:27845 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29846 if (!main_frame)
847 return;
848
849 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45850 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29851 return;
852
853 // Don't index/capture pages that failed to load. This only checks the top
854 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45855 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28856 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29857 return;
858
859 if (!preliminary_capture)
860 last_indexed_page_id_ = load_id;
861
[email protected]a8a81292010-01-21 00:32:45862 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45863 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29864 if (url.is_empty())
865 return;
866
[email protected]a8a81292010-01-21 00:32:45867 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36868 string16 contents;
initial.commit09911bf2008-07-26 23:55:29869 CaptureText(main_frame, &contents);
870 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45871 base::TimeTicks begin_time = base::TimeTicks::Now();
872 std::string language = DetermineTextLanguage(contents);
873 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
874 base::TimeTicks::Now() - begin_time);
[email protected]1c57b7b2010-07-12 17:38:10875 WebKit::WebDocument document = main_frame->document();
[email protected]a8a81292010-01-21 00:32:45876 // Send the text to the browser for indexing (the browser might decide not
877 // to index, if the URL is HTTPS for instance) and language discovery.
878 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
[email protected]1c57b7b2010-07-12 17:38:10879 language, IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27880 }
881
[email protected]9b18a84f2010-06-10 15:54:04882 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29883}
884
[email protected]e5106202010-06-11 21:12:36885void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29886 contents->clear();
887 if (!frame)
888 return;
889
890#ifdef TIME_TEXT_RETRIEVAL
891 double begin = time_util::GetHighResolutionTimeNow();
892#endif
893
894 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36895 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29896
897#ifdef TIME_TEXT_RETRIEVAL
898 double end = time_util::GetHighResolutionTimeNow();
899 char buf[128];
900 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
901 contents.size(), (end - begin)*1000);
902 OutputDebugStringA(buf);
903#endif
904
905 // When the contents are clipped to the maximum, we don't want to have a
906 // partial word indexed at the end that might have been clipped. Therefore,
907 // terminate the string at the last space to ensure no words are clipped.
908 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36909 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29910 if (last_space_index == std::wstring::npos)
911 return; // don't index if we got a huge block of text with no spaces
912 contents->resize(last_space_index);
913 }
914}
915
[email protected]8649fb32009-06-26 17:51:02916bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29917 int w,
918 int h,
919 SkBitmap* thumbnail,
920 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23921 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15922
[email protected]8649fb32009-06-26 17:51:02923 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23924
925 // Paint |view| into |canvas|.
926 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02927 return false;
[email protected]8649fb32009-06-26 17:51:02928
929 skia::BitmapPlatformDevice& device =
930 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
931
932 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29933
[email protected]cab34d6a2009-09-24 01:14:52934 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29935 float dest_aspect = dest_rect.width() / dest_rect.height();
936
937 // Get the src rect so that we can preserve the aspect ratio while filling
938 // the destination.
939 SkIRect src_rect;
940 if (src_bmp.width() < dest_rect.width() ||
941 src_bmp.height() < dest_rect.height()) {
942 // Source image is smaller: we clip the part of source image within the
943 // dest rect, and then stretch it to fill the dest rect. We don't respect
944 // the aspect ratio in this case.
945 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
946 static_cast<S16CPU>(dest_rect.height()));
947 score->good_clipping = false;
948 } else {
949 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
950 if (src_aspect > dest_aspect) {
951 // Wider than tall, clip horizontally: we center the smaller thumbnail in
952 // the wider screen.
953 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
954 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
955 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
956 score->good_clipping = false;
957 } else {
958 src_rect.set(0, 0, src_bmp.width(),
959 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
960 score->good_clipping = true;
961 }
962 }
963
[email protected]26aa0482009-09-30 16:55:27964 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29965
966 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02967 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29968
969 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14970 *thumbnail = skia::ImageOperations::Resize(
971 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29972
973 score->boring_score = CalculateBoringScore(thumbnail);
974
[email protected]30507922010-01-15 16:48:23975 HISTOGRAM_TIMES("Renderer4.Thumbnail",
976 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15977 return true;
initial.commit09911bf2008-07-26 23:55:29978}
979
[email protected]30507922010-01-15 16:48:23980bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
981 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29982
[email protected]30507922010-01-15 16:48:23983 skia::PlatformCanvas canvas;
984 if (!PaintViewIntoCanvas(view, canvas))
985 return false;
986
987 skia::BitmapPlatformDevice& device =
988 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
989
990 const SkBitmap& bitmap = device.accessBitmap(false);
991 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
992 return false;
993
994 HISTOGRAM_TIMES("Renderer4.Snapshot",
995 base::TimeTicks::Now() - beginning_time);
996 return true;
initial.commit09911bf2008-07-26 23:55:29997}
998
999void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1000 if (!webview())
1001 return;
1002
[email protected]3cc72b12010-03-18 23:03:001003 history_list_offset_ = params.current_history_list_offset;
1004 history_list_length_ = params.current_history_list_length;
1005
[email protected]8c785c62009-07-13 14:20:151006 if (devtools_agent_.get())
1007 devtools_agent_->OnNavigate();
1008
[email protected]422197532010-01-25 17:38:231009 if (notification_provider_.get())
1010 notification_provider_->OnNavigate();
1011
[email protected]a9f607e2009-10-23 19:59:271012 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261013
initial.commit09911bf2008-07-26 23:55:291014 AboutHandler::MaybeHandle(params.url);
1015
[email protected]ecbf10d2010-02-18 13:03:291016 bool is_reload =
1017 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1018 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291019
[email protected]26aa0482009-09-30 16:55:271020 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451021 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291022 // We cannot reload if we do not have any history state. This happens, for
1023 // example, when recovering from a crash. Our workaround here is a bit of
1024 // a hack since it means that reload after a crashed tab does not cause an
1025 // end-to-end cache validation.
1026 is_reload = false;
1027 }
1028
[email protected]77f17a82009-05-21 04:42:541029 // A navigation resulting from loading a javascript URL should not be treated
1030 // as a browser initiated event. Instead, we want it to look as if the page
1031 // initiated any load resulting from JS execution.
1032 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301033 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001034 params.page_id,
1035 params.pending_history_list_offset,
1036 params.transition,
1037 params.request_time);
[email protected]5e369672009-11-03 23:48:301038 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1039 // We're doing a load of a page that was restored from the last session.
1040 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1041 // which can result in stale data for pages that are set to expire. We
1042 // explicitly override that by setting the policy here so that as
1043 // necessary we load from the network.
1044 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1045 }
1046 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541047 }
initial.commit09911bf2008-07-26 23:55:291048
[email protected]a7ccc4d2010-01-27 08:14:481049 NavigationState* navigation_state = pending_navigation_state_.get();
1050
[email protected]04d3c6e2009-05-22 17:00:131051 // If we are reloading, then WebKit will use the history state of the current
1052 // page, so we should just ignore any given history state. Otherwise, if we
1053 // have history state, then we need to navigate to it, which corresponds to a
1054 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551055 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481056 if (navigation_state)
1057 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291058 bool ignore_cache = (params.navigation_type ==
1059 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1060 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551061 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131062 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581063 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481064 if (navigation_state)
1065 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451066 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171067 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131068 } else {
1069 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281070 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291071
[email protected]e6f546c32009-07-01 17:12:551072 // A session history navigation should have been accompanied by state.
1073 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131074
[email protected]dd7daa82009-08-10 05:46:451075 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551076 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131077
[email protected]726985e22009-06-18 21:09:281078 if (params.referrer.is_valid()) {
1079 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1080 WebString::fromUTF8(params.referrer.spec()));
1081 }
[email protected]04d3c6e2009-05-22 17:00:131082
[email protected]a7ccc4d2010-01-27 08:14:481083 if (navigation_state)
1084 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451085 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501086 }
1087
[email protected]77f17a82009-05-21 04:42:541088 // In case LoadRequest failed before DidCreateDataSource was called.
1089 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291090}
1091
1092// Stop loading the current page
1093void RenderView::OnStop() {
1094 if (webview())
[email protected]b4bb2502009-10-01 22:35:271095 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291096}
1097
[email protected]ecbf10d2010-02-18 13:03:291098// Reload current focused frame.
1099// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561100void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291101 if (webview() && webview()->focusedFrame()) {
1102 // We always obey the cache (ignore_cache=false) here.
1103 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1104 // a cache-ignoring reload of the frame.
1105 webview()->focusedFrame()->reload(false);
1106 }
[email protected]1dda4022010-01-28 18:24:561107}
1108
initial.commit09911bf2008-07-26 23:55:291109void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271110 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291111}
1112
[email protected]68b1e922009-06-23 16:00:251113void RenderView::OnExecuteEditCommand(const std::string& name,
1114 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271115 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251116 return;
1117
[email protected]26aa0482009-09-30 16:55:271118 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451119 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251120}
1121
[email protected]b2abac72009-02-26 12:39:281122void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111123 DCHECK(!devtools_client_.get());
1124 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281125}
1126
initial.commit09911bf2008-07-26 23:55:291127void RenderView::OnUpdateTargetURLAck() {
1128 // Check if there is a targeturl waiting to be sent.
1129 if (target_url_status_ == TARGET_PENDING) {
1130 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1131 pending_target_url_));
1132 }
1133
1134 target_url_status_ = TARGET_NONE;
1135}
1136
1137void RenderView::OnUndo() {
1138 if (!webview())
1139 return;
1140
[email protected]26aa0482009-09-30 16:55:271141 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121142 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291143}
1144
1145void RenderView::OnRedo() {
1146 if (!webview())
1147 return;
1148
[email protected]26aa0482009-09-30 16:55:271149 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121150 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291151}
1152
1153void RenderView::OnCut() {
1154 if (!webview())
1155 return;
1156
[email protected]26aa0482009-09-30 16:55:271157 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121158 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291159}
1160
1161void RenderView::OnCopy() {
1162 if (!webview())
1163 return;
1164
[email protected]26aa0482009-09-30 16:55:271165 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121166 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291167}
1168
[email protected]c0cc3092009-09-12 08:27:271169#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351170void RenderView::OnCopyToFindPboard() {
1171 if (!webview())
1172 return;
1173
1174 // Since the find pasteboard supports only plain text, this can be simpler
1175 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271176 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351177 if (frame->hasSelection()) {
1178 string16 selection = frame->selectionAsText();
1179 RenderThread::current()->Send(
1180 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1181 }
1182
[email protected]afe3a1672009-11-17 19:04:121183 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351184}
[email protected]c0cc3092009-09-12 08:27:271185#endif
[email protected]a954bf72009-09-12 07:30:351186
initial.commit09911bf2008-07-26 23:55:291187void RenderView::OnPaste() {
1188 if (!webview())
1189 return;
1190
[email protected]26aa0482009-09-30 16:55:271191 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121192 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291193}
1194
[email protected]2a3a7762009-10-19 19:17:321195void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291196 if (!webview())
1197 return;
1198
[email protected]1ff7a032010-02-03 02:46:031199 WebFrame* frame = webview()->focusedFrame();
1200 if (!frame->hasSelection())
1201 frame->selectWordAroundCaret();
1202 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291203}
1204
[email protected]98324892009-09-09 21:16:051205void RenderView::OnAdvanceToNextMisspelling() {
1206 if (!webview())
1207 return;
[email protected]26aa0482009-09-30 16:55:271208 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051209 WebString::fromUTF8("AdvanceToNextMisspelling"));
1210}
1211
1212void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1213 if (!webview())
1214 return;
1215 // We need to tell the webView whether the spelling panel is visible or not so
1216 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261217 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271218 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051219 WebString::fromUTF8("ToggleSpellPanel"));
1220}
1221
[email protected]bbbd545c2008-12-15 20:18:041222void RenderView::OnToggleSpellCheck() {
1223 if (!webview())
1224 return;
1225
[email protected]26aa0482009-09-30 16:55:271226 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451227 frame->enableContinuousSpellChecking(
1228 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041229}
1230
initial.commit09911bf2008-07-26 23:55:291231void RenderView::OnDelete() {
1232 if (!webview())
1233 return;
1234
[email protected]26aa0482009-09-30 16:55:271235 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121236 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291237}
1238
1239void RenderView::OnSelectAll() {
1240 if (!webview())
1241 return;
1242
[email protected]26aa0482009-09-30 16:55:271243 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221244 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121245 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291246}
1247
1248void RenderView::OnSetInitialFocus(bool reverse) {
1249 if (!webview())
1250 return;
[email protected]26aa0482009-09-30 16:55:271251 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291252}
1253
1254///////////////////////////////////////////////////////////////////////////////
1255
[email protected]433819d2010-01-30 20:20:011256void RenderView::SetContentSettings(const ContentSettings& settings) {
1257 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011258}
1259
initial.commit09911bf2008-07-26 23:55:291260// Tell the embedding application that the URL of the active page has changed
1261void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451262 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291263 DCHECK(ds);
1264
[email protected]726985e22009-06-18 21:09:281265 const WebURLRequest& request = ds->request();
1266 const WebURLRequest& original_request = ds->originalRequest();
1267 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291268
[email protected]daa8c58e2009-06-15 17:21:101269 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1270 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291271
1272 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281273 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291274 params.is_post = false;
1275 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281276 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551277 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291278 // SSL state specified in the request takes precedence over the one in the
1279 // response.
1280 // So far this is only intended for error pages that are not expected to be
1281 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281282 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551283 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291284 } else {
[email protected]726985e22009-06-18 21:09:281285 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291286 }
1287
1288 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281289 if (ds->hasUnreachableURL()) {
1290 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291291 } else {
[email protected]726985e22009-06-18 21:09:281292 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291293 }
1294
[email protected]726985e22009-06-18 21:09:281295 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241296 params.should_update_history = !ds->hasUnreachableURL() &&
1297 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291298
[email protected]ce0e250d2009-10-23 21:00:351299 params.searchable_form_url = navigation_state->searchable_form_url();
1300 params.searchable_form_encoding =
1301 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291302
1303 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101304 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291305 if (password_form_data)
1306 params.password_form = *password_form_data;
1307
1308 params.gesture = navigation_gesture_;
1309 navigation_gesture_ = NavigationGestureUnknown;
1310
[email protected]dd7daa82009-08-10 05:46:451311 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291312 // Top-level navigation.
1313
[email protected]71b0d5d2010-02-15 05:43:071314 // Clear "block" flags for the new page. This needs to happen before any of
1315 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1316 // so that these functions can correctly detect that a piece of content
1317 // flipped from "not blocked" to "blocked".
1318 ClearBlockedContentSettings();
1319
[email protected]62d2a112010-04-07 00:53:021320 // Set content settings. Default them from the parent window if one exists.
1321 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011322 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541323 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011324 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011325 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011326
1327 // These content settings were merely recorded transiently for this load.
1328 // We can erase them now. If at some point we reload this page, the
1329 // browser will send us new, up-to-date content settings.
1330 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401331 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101332 // The opener's view is not guaranteed to be non-null (it could be
1333 // detached from its page but not yet destructed).
1334 if (WebView* opener_view = frame->opener()->view()) {
1335 RenderView* opener = FromWebView(opener_view);
1336 SetContentSettings(opener->current_content_settings_);
1337 }
[email protected]f85f0702010-01-30 09:31:011338 }
1339
[email protected]40bd6582009-12-04 23:49:511340 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011341 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541342 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011343 if (host_zoom != host_zoom_levels_.end()) {
1344 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511345 // This zoom level was merely recorded transiently for this load. We can
1346 // erase it now. If at some point we reload this page, the browser will
1347 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011348 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511349 }
1350
initial.commit09911bf2008-07-26 23:55:291351 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551352 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291353
[email protected]daa8c58e2009-06-15 17:21:101354 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291355 if (!PageTransition::IsMainFrame(params.transition)) {
1356 // If the main frame does a load, it should not be reported as a subframe
1357 // navigation. This can occur in the following case:
1358 // 1. You're on a site with frames.
1359 // 2. You do a subframe navigation. This is stored with transition type
1360 // MANUAL_SUBFRAME.
1361 // 3. You navigate to some non-frame site, say, google.com.
1362 // 4. You navigate back to the page from step 2. Since it was initially
1363 // MANUAL_SUBFRAME, it will be that same transition type here.
1364 // We don't want that, because any navigation that changes the toplevel
1365 // frame should be tracked as a toplevel navigation (this allows us to
1366 // update the URL bar, etc).
1367 params.transition = PageTransition::LINK;
1368 }
1369
initial.commit09911bf2008-07-26 23:55:291370 // If we have a valid consumed client redirect source,
1371 // the page contained a client redirect (meta refresh, document.loc...),
1372 // so we set the referrer and transition to match.
1373 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041374 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291375 params.referrer = completed_client_redirect_src_;
1376 params.transition = static_cast<PageTransition::Type>(
1377 params.transition | PageTransition::CLIENT_REDIRECT);
1378 } else {
1379 // Bug 654101: the referrer will be empty on https->http transitions. It
1380 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281381 params.referrer = GURL(
1382 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291383 }
1384
[email protected]726985e22009-06-18 21:09:281385 string16 method = request.httpMethod();
1386 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291387 params.is_post = true;
1388
[email protected]c2a797d2009-09-21 16:46:321389 // Save some histogram data so we can compute the average memory used per
1390 // page load of the glyphs.
1391 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1392 webkit_glue::GetGlyphPageCount());
1393
[email protected]15cf526b2010-02-12 06:33:491394 // This message needs to be sent before any of allowScripts(),
1395 // allowImages(), allowPlugins() is called for the new page, so that when
1396 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1397 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291398 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1399 } else {
1400 // Subframe navigation: the type depends on whether this navigation
1401 // generated a new session history entry. When they do generate a session
1402 // history entry, it means the user initiated the navigation and we should
1403 // mark it as such. This test checks if this is the first time UpdateURL
1404 // has been called since WillNavigateToURL was called to initiate the load.
1405 if (page_id_ > last_page_id_sent_to_browser_)
1406 params.transition = PageTransition::MANUAL_SUBFRAME;
1407 else
1408 params.transition = PageTransition::AUTO_SUBFRAME;
1409
initial.commit09911bf2008-07-26 23:55:291410 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1411 }
1412
1413 last_page_id_sent_to_browser_ =
1414 std::max(last_page_id_sent_to_browser_, page_id_);
1415
1416 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101417 // we don't want the transition type to persist. Just clear it.
1418 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501419
[email protected]c7287a92009-11-04 20:06:151420 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091421 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351422 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501423 }
initial.commit09911bf2008-07-26 23:55:291424}
1425
1426// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171427void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291428 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171429 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171430 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171431 routing_id_,
1432 page_id_,
1433 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1434 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171435 }
initial.commit09911bf2008-07-26 23:55:291436}
1437
1438void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401439 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291440 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271441 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291442 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301443 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291444 last_encoding_name_ = encoding_name;
1445
[email protected]e38f40152008-09-12 23:08:301446 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291447 }
1448}
1449
[email protected]f4d34b52008-11-24 23:05:011450// Sends the previous session history state to the browser so it will be saved
1451// before we navigate to a new page. This must be called *before* the page ID
1452// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291453void RenderView::UpdateSessionHistory(WebFrame* frame) {
1454 // If we have a valid page ID at this point, then it corresponds to the page
1455 // we are navigating away from. Otherwise, this is the first navigation, so
1456 // there is no past session history to record.
1457 if (page_id_ == -1)
1458 return;
1459
[email protected]ca948a22009-06-25 19:36:171460 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271461 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171462 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291463 return;
[email protected]ca948a22009-06-25 19:36:171464
1465 Send(new ViewHostMsg_UpdateState(
1466 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291467}
1468
[email protected]3d9689372009-09-10 04:29:171469void RenderView::OpenURL(
1470 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1471 Send(new ViewHostMsg_OpenURL(
1472 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1473}
1474
[email protected]79dbc662009-09-04 05:42:511475// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291476
initial.commit09911bf2008-07-26 23:55:291477void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281478 const WebURLRequest& failed_request,
1479 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291480 const std::string& html,
1481 bool replace) {
[email protected]726985e22009-06-18 21:09:281482 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291483
1484 std::string alt_html;
1485 if (html.empty()) {
1486 // Use a local error page.
1487 int resource_id;
1488 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281489 if (error.reason == net::ERR_CACHE_MISS &&
1490 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291491 GetFormRepostErrorValues(failed_url, &error_strings);
1492 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1493 } else {
1494 GetLocalizedErrorValues(error, &error_strings);
1495 resource_id = IDR_NET_ERROR_HTML;
1496 }
initial.commit09911bf2008-07-26 23:55:291497
1498 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1499 } else {
1500 alt_html = html;
1501 }
1502
[email protected]dd7daa82009-08-10 05:46:451503 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551504 GURL(kUnreachableWebDataURL),
1505 failed_url,
1506 replace);
initial.commit09911bf2008-07-26 23:55:291507}
1508
[email protected]7ccddb8c2009-08-04 17:36:551509void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291510 dom_automation_controller_.set_message_sender(this);
1511 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551512 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291513 L"domAutomationController");
1514}
1515
initial.commit09911bf2008-07-26 23:55:291516bool RenderView::RunJavaScriptMessage(int type,
1517 const std::wstring& message,
1518 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071519 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291520 std::wstring* result) {
1521 bool success = false;
1522 std::wstring result_temp;
1523 if (!result)
1524 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291525
[email protected]12636df2009-09-28 22:32:211526 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1527 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291528 return success;
1529}
1530
[email protected]c1f50aa2010-02-18 03:46:571531bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1532 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1533 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1534 // it is particularly important that we do not call willEnterModalLoop as
1535 // that would defer resource loads for the dialog itself.
1536 if (RenderThread::current()) // Will be NULL during unit tests.
1537 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1538
1539 message->EnableMessagePumping(); // Runs a nested message loop.
1540 return Send(message);
1541}
1542
initial.commit09911bf2008-07-26 23:55:291543void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1544 if (!osd_url.is_empty())
1545 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1546 autodetected));
1547}
1548
[email protected]95056b582010-02-18 01:29:241549void RenderView::OnAutoFillSuggestionsReturned(
1550 int query_id,
[email protected]8f6e6582010-04-09 02:03:071551 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391552 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411553 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391554 const std::vector<int>& unique_ids) {
[email protected]a53e06832010-07-28 22:46:411555 autofill_helper_.SuggestionsReceived(
1556 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031557}
1558
[email protected]45c6e532010-03-15 23:51:241559void RenderView::OnAutoFillFormDataFilled(int query_id,
1560 const webkit_glue::FormData& form) {
[email protected]679f128f2010-07-22 22:57:441561 autofill_helper_.FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481562}
1563
[email protected]e8345242010-05-06 03:00:401564void RenderView::OnAllowScriptToClose(bool script_can_close) {
1565 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311566}
1567
initial.commit09911bf2008-07-26 23:55:291568uint32 RenderView::GetCPBrowsingContext() {
1569 uint32 context = 0;
1570 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1571 return context;
1572}
1573
initial.commit09911bf2008-07-26 23:55:291574void RenderView::AddSearchProvider(const std::string& url) {
1575 AddGURLSearchProvider(GURL(url),
1576 false); // not autodetected
1577}
1578
[email protected]155f35e2010-07-17 00:30:181579ViewHostMsg_GetSearchProviderInstallState_Params
1580RenderView::GetSearchProviderInstallState(const std::string& url) {
1581 GURL inquiry_url = GURL(url);
1582 if (inquiry_url.is_empty())
1583 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
1584 ViewHostMsg_GetSearchProviderInstallState_Params install;
1585 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
1586 inquiry_url,
1587 &install));
1588 return install;
1589}
1590
[email protected]f103ab72009-09-02 17:10:591591void RenderView::OnMissingPluginStatus(
1592 WebPluginDelegateProxy* delegate,
1593 int status) {
[email protected]6c8afae52009-01-22 02:24:571594#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591595 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291596 // Show the InfoBar for the first available plugin.
1597 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591598 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291599 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1600 }
1601 } else {
1602 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1603 // to start the download/install.
1604 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1605 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1606 }
1607 }
[email protected]6c8afae52009-01-22 02:24:571608#else
[email protected]76c3b312010-05-20 21:38:291609 // TODO(port): Implement the infobar that accompanies the default plugin.
1610 // Linux: http://crbug.com/10952
1611 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571612 NOTIMPLEMENTED();
1613#endif
initial.commit09911bf2008-07-26 23:55:291614}
1615
[email protected]48c9cf2d2009-09-16 16:47:521616// WebKit::WebViewClient ------------------------------------------------------
1617
[email protected]8ab04652010-06-12 02:47:261618WebView* RenderView::createView(
1619 WebFrame* creator,
1620 const WebWindowFeatures& features,
1621 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521622 // Check to make sure we aren't overloading on popups.
1623 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1624 return NULL;
1625
1626 // This window can't be closed from a window.close() call until we receive a
1627 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401628 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521629
[email protected]8ab04652010-06-12 02:47:261630 ViewHostMsg_CreateWindow_Params params;
1631 params.opener_id = routing_id_;
1632 params.user_gesture = creator->isProcessingUserGesture();
1633 params.window_container_type = WindowFeaturesToContainerType(features);
1634 params.session_storage_namespace_id = session_storage_namespace_id_;
1635 params.frame_name = frame_name;
1636
[email protected]48c9cf2d2009-09-16 16:47:521637 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341638 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261639 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521640
[email protected]48c9cf2d2009-09-16 16:47:521641 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261642 new ViewHostMsg_CreateWindow(params,
1643 &routing_id,
1644 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211645 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521646 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521647
[email protected]48c9cf2d2009-09-16 16:47:521648 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421649 0,
[email protected]12636df2009-09-28 22:32:211650 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521651 renderer_preferences_,
1652 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211653 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341654 routing_id,
[email protected]8ab04652010-06-12 02:47:261655 cloned_session_storage_namespace_id,
1656 frame_name);
1657 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521658
[email protected]007a848b2009-10-26 15:55:461659 // Record whether the creator frame is trying to suppress the opener field.
1660 view->opener_suppressed_ = opener_suppressed;
1661
[email protected]48c9cf2d2009-09-16 16:47:521662 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091663 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521664 if (!creator_url.is_valid() || !creator_url.IsStandard())
1665 creator_url = GURL();
1666 view->creator_url_ = creator_url;
1667
1668 // Copy over the alternate error page URL so we can have alt error pages in
1669 // the new render view (we don't need the browser to send the URL back down).
1670 view->alternate_error_page_url_ = alternate_error_page_url_;
1671
1672 return view->webview();
1673}
1674
[email protected]3e2b375b2010-04-07 17:03:121675WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521676 RenderWidget* widget = RenderWidget::Create(routing_id_,
1677 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121678 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521679 return widget->webwidget();
1680}
1681
1682WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1683 RenderWidget* widget = RenderWidget::Create(routing_id_,
1684 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121685 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521686 widget->ConfigureAsExternalPopupMenu(info);
1687 return widget->webwidget();
1688}
1689
[email protected]68c50e52010-05-12 11:14:391690WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341691 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391692 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291693 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1694 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1695 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341696}
1697
[email protected]48c9cf2d2009-09-16 16:47:521698void RenderView::didAddMessageToConsole(
1699 const WebConsoleMessage& message, const WebString& source_name,
1700 unsigned source_line) {
1701 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1702 UTF16ToWideHack(message.text),
1703 static_cast<int32>(source_line),
1704 UTF16ToWideHack(source_name)));
1705}
1706
1707void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581708 DCHECK(frame);
1709 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521710}
1711
[email protected]3354d3e2010-06-10 19:53:021712WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1713 return notification_provider_.get();
1714}
1715
[email protected]48c9cf2d2009-09-16 16:47:521716void RenderView::didStartLoading() {
1717 if (is_loading_) {
1718 DLOG(WARNING) << "didStartLoading called while loading";
1719 return;
1720 }
1721
1722 is_loading_ = true;
1723 // Clear the pointer so that we can assign it only when there is an unknown
1724 // plugin on a page.
1725 first_default_plugin_.reset();
1726
1727 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1728}
1729
1730void RenderView::didStopLoading() {
1731 if (!is_loading_) {
1732 DLOG(WARNING) << "DidStopLoading called while not loading";
1733 return;
1734 }
1735
1736 is_loading_ = false;
1737
1738 // NOTE: For now we're doing the safest thing, and sending out notification
1739 // when done loading. This currently isn't an issue as the favicon is only
1740 // displayed when done loading. Ideally we would send notification when
1741 // finished parsing the head, but webkit doesn't support that yet.
1742 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271743 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521744 if (!favicon_url.is_empty())
1745 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1746
[email protected]26aa0482009-09-30 16:55:271747 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521748 true); // autodetected
1749
1750 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1751
[email protected]f9f4841b2010-03-20 05:41:421752 MessageLoop::current()->PostDelayedTask(
1753 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521754 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1755 false),
1756 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521757}
1758
[email protected]f55039a2010-02-17 14:12:061759bool RenderView::isSmartInsertDeleteEnabled() {
1760#if defined(OS_MACOSX)
1761 return true;
1762#else
1763 return false;
1764#endif
1765}
1766
[email protected]04fc9482009-09-18 22:13:031767bool RenderView::isSelectTrailingWhitespaceEnabled() {
1768#if defined(OS_WIN)
1769 return true;
1770#else
1771 return false;
1772#endif
1773}
1774
[email protected]04fc9482009-09-18 22:13:031775void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031776#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031777 if (!handling_input_event_)
1778 return;
1779 // TODO(estade): investigate incremental updates to the selection so that we
1780 // don't send the entire selection over IPC every time.
1781 if (!is_empty_selection) {
1782 // Sometimes we get repeated didChangeSelection calls from webkit when
1783 // the selection hasn't actually changed. We don't want to report these
1784 // because it will cause us to continually claim the X clipboard.
1785 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271786 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031787 if (this_selection == last_selection_)
1788 return;
1789
1790 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1791 this_selection));
1792 last_selection_ = this_selection;
1793 } else {
1794 last_selection_.clear();
1795 }
1796#endif
1797}
1798
1799void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121800 const std::string& name = UTF16ToUTF8(command_name);
1801 if (StartsWithASCII(name, "Move", true) ||
1802 StartsWithASCII(name, "Insert", true) ||
1803 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031804 return;
1805 UserMetricsRecordAction(name);
1806}
1807
[email protected]03f57072010-07-14 17:36:081808void RenderView::textFieldDidBeginEditing(
1809 const WebKit::WebInputElement& element) {
1810#if defined(WEBKIT_BUG_41283_IS_FIXED)
1811 password_autocomplete_manager_.TextFieldDidBeginEditing(element);
1812#endif
1813}
1814
1815void RenderView::textFieldDidEndEditing(
1816 const WebKit::WebInputElement& element) {
1817#if defined(WEBKIT_BUG_41283_IS_FIXED)
1818 password_autocomplete_manager_.TextFieldDidEndEditing(element);
1819#endif
1820}
1821
1822void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1823#if defined(WEBKIT_BUG_41283_IS_FIXED)
1824 password_autocomplete_manager_.TextDidChangeInTextField(element);
1825#endif
1826}
1827
1828void RenderView::textFieldDidReceiveKeyDown(
1829 const WebKit::WebInputElement& element,
1830 const WebKit::WebKeyboardEvent& event) {
1831#if defined(WEBKIT_BUG_41283_IS_FIXED)
1832 password_autocomplete_manager_.TextFieldHandlingKeyDown(element, event);
1833#endif
1834}
1835
[email protected]b2528b72009-09-24 06:57:101836bool RenderView::handleCurrentKeyboardEvent() {
1837 if (edit_commands_.empty())
1838 return false;
1839
[email protected]26aa0482009-09-30 16:55:271840 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101841 if (!frame)
1842 return false;
1843
1844 EditCommands::iterator it = edit_commands_.begin();
1845 EditCommands::iterator end = edit_commands_.end();
1846
[email protected]507b33ea2009-09-29 03:56:511847 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101848 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331849 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1850 // key (but it's the exception). Once one edit command is not executed, it
1851 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101852 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1853 WebString::fromUTF8(it->value)))
1854 break;
[email protected]507b33ea2009-09-29 03:56:511855 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101856 }
1857
[email protected]507b33ea2009-09-29 03:56:511858 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101859}
1860
[email protected]2a3a7762009-10-19 19:17:321861void RenderView::spellCheck(const WebString& text,
1862 int& misspelled_offset,
1863 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561864 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461865
[email protected]85c55dc2009-11-06 03:05:461866 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171867 RenderThread* thread = RenderThread::current();
1868 // Will be NULL during unit tests.
1869 if (thread) {
[email protected]c27324b2009-11-19 22:44:291870 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171871 word.c_str(), word.size(), document_tag_,
1872 &misspelled_offset, &misspelled_length, NULL);
1873 }
[email protected]1dbafaf72009-09-23 19:43:561874}
1875
1876WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321877 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561878 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261879 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561880 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171881 RenderThread* thread = RenderThread::current();
1882 // Will be NULL during unit tests.
1883 if (thread) {
1884 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291885 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171886 word, document_tag_);
1887 }
[email protected]1dbafaf72009-09-23 19:43:561888 }
[email protected]2a3a7762009-10-19 19:17:321889 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561890}
1891
[email protected]c49085c72009-10-02 16:28:561892void RenderView::showSpellingUI(bool show) {
1893 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1894}
1895
[email protected]8922e1f2009-10-03 05:01:261896bool RenderView::isShowingSpellingUI() {
1897 return spelling_panel_visible_;
1898}
1899
[email protected]1dbafaf72009-09-23 19:43:561900void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321901 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1902 word));
[email protected]1dbafaf72009-09-23 19:43:561903}
1904
[email protected]a1128322009-10-06 18:38:461905bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351906 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471907 WebFileChooserCompletion* chooser_completion) {
1908 ViewHostMsg_RunFileChooser_Params ipc_params;
1909 ipc_params.mode = params.multiSelect ?
1910 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1911 ViewHostMsg_RunFileChooser_Params::Open;
1912 ipc_params.title = params.title;
1913 ipc_params.default_file_name =
1914 webkit_glue::WebStringToFilePath(params.initialValue);
1915
1916 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461917}
1918
[email protected]48c9cf2d2009-09-16 16:47:521919void RenderView::runModalAlertDialog(
1920 WebFrame* frame, const WebString& message) {
1921 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1922 UTF16ToWideHack(message),
1923 std::wstring(),
1924 frame->url(),
1925 NULL);
1926}
1927
1928bool RenderView::runModalConfirmDialog(
1929 WebFrame* frame, const WebString& message) {
1930 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1931 UTF16ToWideHack(message),
1932 std::wstring(),
1933 frame->url(),
1934 NULL);
1935}
1936
1937bool RenderView::runModalPromptDialog(
1938 WebFrame* frame, const WebString& message, const WebString& default_value,
1939 WebString* actual_value) {
1940 std::wstring result;
1941 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1942 UTF16ToWideHack(message),
1943 UTF16ToWideHack(default_value),
1944 frame->url(),
1945 &result);
1946 if (ok)
1947 actual_value->assign(WideToUTF16Hack(result));
1948 return ok;
1949}
1950
1951bool RenderView::runModalBeforeUnloadDialog(
1952 WebFrame* frame, const WebString& message) {
1953 bool success = false;
1954 // This is an ignored return value, but is included so we can accept the same
1955 // response as RunJavaScriptMessage.
1956 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211957 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521958 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211959 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521960 return success;
1961}
1962
[email protected]79e37442009-10-09 18:17:441963void RenderView::showContextMenu(
1964 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291965 ContextMenuParams params = ContextMenuParams(data);
1966 if (!params.misspelled_word.empty() && RenderThread::current()) {
1967 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041968 bool spelled_right = RenderThread::current()->spellchecker()->
1969 SpellCheckWord(
1970 params.misspelled_word.c_str(), params.misspelled_word.size(),
1971 document_tag_,
1972 &misspelled_offset, &misspelled_length,
1973 &params.dictionary_suggestions);
1974 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291975 params.misspelled_word.clear();
1976 }
1977
1978 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441979}
1980
[email protected]52f139e2c2010-06-11 16:56:091981bool RenderView::supportsFullscreen() {
1982 return CommandLine::ForCurrentProcess()->HasSwitch(
1983 switches::kEnableVideoFullscreen);
1984}
1985
1986void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1987 NOTIMPLEMENTED();
1988}
1989
1990void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1991 NOTIMPLEMENTED();
1992}
1993
[email protected]48c9cf2d2009-09-16 16:47:521994void RenderView::setStatusText(const WebString& text) {
1995}
1996
[email protected]163f8242009-10-30 20:19:551997void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581998 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521999 if (latest_url == target_url_)
2000 return;
[email protected]163f8242009-10-30 20:19:552001
[email protected]48c9cf2d2009-09-16 16:47:522002 // Tell the browser to display a destination link.
2003 if (target_url_status_ == TARGET_INFLIGHT ||
2004 target_url_status_ == TARGET_PENDING) {
2005 // If we have a request in-flight, save the URL to be sent when we
2006 // receive an ACK to the in-flight request. We can happily overwrite
2007 // any existing pending sends.
2008 pending_target_url_ = latest_url;
2009 target_url_status_ = TARGET_PENDING;
2010 } else {
2011 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2012 target_url_ = latest_url;
2013 target_url_status_ = TARGET_INFLIGHT;
2014 }
2015}
2016
[email protected]1c57b7b2010-07-12 17:38:102017bool RenderView::IsPageTranslatable(WebKit::WebDocument* document) {
2018 std::vector<WebKit::WebElement> meta_elements;
2019 webkit_glue::GetMetaElementsWithName(document, ASCIIToUTF16("google"),
2020 &meta_elements);
2021 std::vector<WebKit::WebElement>::const_iterator iter;
2022 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) {
2023 WebString attribute = iter->getAttribute("value");
2024 if (attribute.isNull()) // We support both 'value' and 'content'.
2025 attribute = iter->getAttribute("content");
2026 if (attribute.isNull())
2027 continue;
2028 if (LowerCaseEqualsASCII(attribute, "notranslate"))
2029 return false;
2030 }
2031 return true;
2032}
2033
[email protected]882daa92009-11-05 16:31:312034void RenderView::StartNavStateSyncTimerIfNecessary() {
2035 int delay;
2036 if (send_content_state_immediately_)
2037 delay = 0;
2038 else if (is_hidden())
2039 delay = kDelaySecondsForContentStateSyncHidden;
2040 else
2041 delay = kDelaySecondsForContentStateSync;
2042
2043 if (nav_state_sync_timer_.IsRunning()) {
2044 // The timer is already running. If the delay of the timer maches the amount
2045 // we want to delay by, then return. Otherwise stop the timer so that it
2046 // gets started with the right delay.
2047 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2048 return;
2049 nav_state_sync_timer_.Stop();
2050 }
2051
2052 nav_state_sync_timer_.Start(
2053 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2054}
2055
[email protected]163f8242009-10-30 20:19:552056void RenderView::setMouseOverURL(const WebURL& url) {
2057 mouse_over_url_ = GURL(url);
2058 UpdateTargetURL(mouse_over_url_, focus_url_);
2059}
2060
2061void RenderView::setKeyboardFocusURL(const WebURL& url) {
2062 focus_url_ = GURL(url);
2063 UpdateTargetURL(focus_url_, mouse_over_url_);
2064}
2065
[email protected]48c9cf2d2009-09-16 16:47:522066void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2067 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2068 hint));
2069}
2070
[email protected]c27ae592010-03-18 15:24:412071void RenderView::startDragging(const WebDragData& data,
2072 WebDragOperationsMask mask,
2073 const WebImage& image,
2074 const WebPoint& imageOffset) {
2075#if WEBKIT_USING_SKIA
2076 SkBitmap bitmap(image.getSkBitmap());
2077#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332078 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412079#endif
2080
[email protected]48c9cf2d2009-09-16 16:47:522081 Send(new ViewHostMsg_StartDragging(routing_id_,
2082 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412083 mask,
2084 bitmap,
2085 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522086}
2087
[email protected]28b92df2009-09-25 17:35:452088bool RenderView::acceptsLoadDrops() {
2089 return renderer_preferences_.can_accept_load_drops;
2090}
2091
[email protected]48c9cf2d2009-09-16 16:47:522092void RenderView::focusNext() {
2093 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2094}
2095
2096void RenderView::focusPrevious() {
2097 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2098}
2099
[email protected]08e9e132010-06-01 16:58:492100void RenderView::focusedNodeChanged(const WebNode& node) {
2101 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2102}
2103
[email protected]48c9cf2d2009-09-16 16:47:522104void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522105 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2106}
2107
2108int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002109 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522110}
2111
2112int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002113 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522114}
2115
[email protected]c4e98902010-06-01 10:20:142116void RenderView::didUpdateInspectorSetting(const WebString& key,
2117 const WebString& value) {
2118 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2119 key.utf8(),
2120 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262121}
2122
[email protected]acca2a1f2009-10-16 03:53:392123void RenderView::queryAutofillSuggestions(const WebNode& node,
2124 const WebString& name,
2125 const WebString& value) {
[email protected]679f128f2010-07-22 22:57:442126 autofill_helper_.QueryAutocompleteSuggestions(node, name, value);
[email protected]acca2a1f2009-10-16 03:53:392127}
2128
2129void RenderView::removeAutofillSuggestions(const WebString& name,
2130 const WebString& value) {
[email protected]679f128f2010-07-22 22:57:442131 autofill_helper_.RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a1f2009-10-16 03:53:392132}
2133
[email protected]18ca9a6b2010-06-02 19:05:182134void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2135 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202136 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392137 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202138 unsigned index) {
[email protected]679f128f2010-07-22 22:57:442139 autofill_helper_.DidAcceptAutoFillSuggestion(node, value, label, unique_id,
2140 index);
[email protected]18ca9a6b2010-06-02 19:05:182141}
[email protected]c83641732010-02-20 01:04:482142
[email protected]18ca9a6b2010-06-02 19:05:182143void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2144 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392145 const WebKit::WebString& label,
2146 int unique_id) {
[email protected]679f128f2010-07-22 22:57:442147 autofill_helper_.DidSelectAutoFillSuggestion(node, value, label, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182148}
2149
2150void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]679f128f2010-07-22 22:57:442151 autofill_helper_.DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482152}
2153
[email protected]03f57072010-07-14 17:36:082154void RenderView::didAcceptAutocompleteSuggestion(
2155 const WebKit::WebInputElement& user_element) {
2156#if defined(WEBKIT_BUG_41283_IS_FIXED)
2157 bool result = password_autocomplete_manager_.FillPassword(user_element);
2158 // Since this user name was selected from a suggestion list, we should always
2159 // have password for it.
2160 DCHECK(result);
2161#endif
2162}
2163
[email protected]79dbc662009-09-04 05:42:512164// WebKit::WebWidgetClient ----------------------------------------------------
2165
initial.commit09911bf2008-07-26 23:55:292166// We are supposed to get a single call to Show for a newly created RenderView
2167// that was created via RenderView::CreateWebView. So, we wait until this
2168// point to dispatch the ShowView message.
2169//
2170// This method provides us with the information about how to display the newly
2171// created RenderView (i.e., as a constrained popup or as a new tab).
2172//
[email protected]4873c7d2009-07-16 06:36:282173void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292174 DCHECK(!did_show_) << "received extraneous Show call";
2175 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2176
2177 if (did_show_)
2178 return;
2179 did_show_ = true;
2180
[email protected]28295ec2009-10-16 05:34:332181 // Force new windows to a popup if they were not opened with a user gesture.
2182 if (!opened_by_user_gesture_) {
2183 // We exempt background tabs for compat with older versions of Chrome.
2184 // TODO(darin): This seems bogus. These should have a user gesture, so
2185 // we probably don't need this check.
2186 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2187 policy = WebKit::WebNavigationPolicyNewPopup;
2188 }
2189
initial.commit09911bf2008-07-26 23:55:292190 // NOTE: initial_pos_ may still have its default values at this point, but
2191 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2192 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282193 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2194 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292195 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242196 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292197}
2198
[email protected]4873c7d2009-07-16 06:36:282199void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132200 // Cancel pending translations so that the translate_helper_ does not attempt
2201 // to access the WebView.
2202 translate_helper_.CancelPendingTranslation();
2203
[email protected]e8345242010-05-06 03:00:402204 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282205 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312206}
2207
[email protected]4873c7d2009-07-16 06:36:282208void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292209 DCHECK(did_show_) << "should already have shown the view";
2210
[email protected]c1f50aa2010-02-18 03:46:572211 // We must keep WebKit's shared timer running in this case in order to allow
2212 // showModalDialog to function properly.
2213 //
2214 // TODO(darin): WebKit should really be smarter about suppressing events and
2215 // timers so that we do not need to manage the shared timer in such a heavy
2216 // handed manner.
2217 //
2218 if (RenderThread::current()) // Will be NULL during unit tests.
2219 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2220
[email protected]12636df2009-09-28 22:32:212221 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292222}
2223
[email protected]3d9689372009-09-10 04:29:172224// WebKit::WebFrameClient -----------------------------------------------------
2225
[email protected]00152e92010-07-19 11:47:402226WebPlugin* RenderView::createPlugin(WebFrame* frame,
2227 const WebPluginParams& params) {
[email protected]7a13e792010-08-03 08:18:242228 bool found = false;
2229 WebPluginInfo info;
2230 GURL url(params.url);
[email protected]0cdafff2010-07-26 09:54:372231 std::string actual_mime_type;
[email protected]7a13e792010-08-03 08:18:242232 Send(new ViewHostMsg_GetPluginInfo(url,
2233 frame->top()->url(),
[email protected]aad51d1c2010-08-05 08:38:092234 params.mimeType.utf8(),
[email protected]7a13e792010-08-03 08:18:242235 &found,
2236 &info,
[email protected]aad51d1c2010-08-05 08:38:092237 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242238
[email protected]250afb02010-08-06 15:50:572239 if (!found || !info.enabled)
[email protected]0cdafff2010-07-26 09:54:372240 return NULL;
[email protected]4e0616e2010-05-28 14:55:532241
[email protected]aad51d1c2010-08-05 08:38:092242 if (info.path.value() != kDefaultPluginLibraryName) {
2243 if (!AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS)) {
2244 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
2245 switches::kEnableClickToPlay));
2246 didNotAllowPlugins(frame);
[email protected]250afb02010-08-06 15:50:572247 return CreatePluginPlaceholder(frame, params);
[email protected]aad51d1c2010-08-05 08:38:092248 }
2249 scoped_refptr<pepper::PluginModule> pepper_module =
2250 PepperPluginRegistry::GetInstance()->GetModule(info.path);
2251 if (pepper_module)
2252 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
2253 if (CommandLine::ForCurrentProcess()->HasSwitch(
2254 switches::kBlockNonSandboxedPlugins)) {
[email protected]250afb02010-08-06 15:50:572255 Send(new ViewHostMsg_NonSandboxedPluginBlocked(routing_id_, info.name));
2256 return CreatePluginPlaceholder(frame, params);
[email protected]aad51d1c2010-08-05 08:38:092257 }
[email protected]0cdafff2010-07-26 09:54:372258 }
[email protected]aad51d1c2010-08-05 08:38:092259 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]3d9689372009-09-10 04:29:172260}
2261
2262WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562263 WebApplicationCacheHostImpl* appcache_host =
2264 WebApplicationCacheHostImpl::FromFrame(frame);
2265 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2266 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2267 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172268}
2269
[email protected]9c00f002009-11-05 22:37:422270WebSharedWorker* RenderView::createSharedWorker(
2271 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372272 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422273
[email protected]30447b62009-11-13 01:13:372274 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512275 bool exists = false;
[email protected]30447b62009-11-13 01:13:372276 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512277 ViewHostMsg_CreateWorker_Params params;
2278 params.url = url;
2279 params.is_shared = true;
2280 params.name = name;
2281 params.document_id = document_id;
2282 params.render_view_route_id = routing_id_;
2283 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232284 params.parent_appcache_host_id = 0;
2285 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372286 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512287 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372288 if (url_mismatch) {
2289 return NULL;
2290 } else {
2291 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492292 document_id,
[email protected]6de0bcf2010-02-17 22:00:512293 exists,
[email protected]30447b62009-11-13 01:13:372294 route_id,
2295 routing_id_);
2296 }
[email protected]9c00f002009-11-05 22:37:422297}
2298
[email protected]3d9689372009-09-10 04:29:172299WebMediaPlayer* RenderView::createMediaPlayer(
2300 WebFrame* frame, WebMediaPlayerClient* client) {
2301 scoped_refptr<media::FilterFactoryCollection> factory =
2302 new media::FilterFactoryCollection();
2303 // Add in any custom filter factories first.
2304 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2305 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2306 // Add the chrome specific audio renderer.
2307 factory->AddFactory(
2308 AudioRendererImpl::CreateFactory(audio_message_filter()));
2309 }
2310
[email protected]80f584d92010-01-21 03:59:042311 WebApplicationCacheHostImpl* appcache_host =
2312 WebApplicationCacheHostImpl::FromFrame(frame);
2313
[email protected]3d9689372009-09-10 04:29:172314 // TODO(hclam): obtain the following parameters from |client|.
2315 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2316 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152317 GURL(), // referrer
2318 "null", // frame origin
2319 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172320 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042321 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172322 routing_id());
2323
[email protected]0436b9a2009-10-23 00:23:052324 // A simple data source that keeps all data in memory.
2325 media::FilterFactory* simple_data_source_factory =
2326 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2327 bridge_factory);
2328 // A sophisticated data source that does memory caching.
2329 media::FilterFactory* buffered_data_source_factory =
2330 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2331 bridge_factory);
2332 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2333 factory->AddFactory(simple_data_source_factory);
2334 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172335 } else {
[email protected]0436b9a2009-10-23 00:23:052336 factory->AddFactory(buffered_data_source_factory);
2337 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172338 }
[email protected]8400e032010-02-26 18:50:112339
2340 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2341 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2342 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2343 } else {
[email protected]b57509eb2010-03-30 01:26:282344 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2345 factory_factory =
2346 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112347 }
2348
2349 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172350}
2351
[email protected]035545f2010-04-09 13:10:212352WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2353 WebFrame* frame, WebApplicationCacheHostClient* client) {
2354 return new RendererWebApplicationCacheHostImpl(
2355 FromWebView(frame->view()), client,
2356 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2357}
2358
[email protected]b921cfd22010-02-25 16:57:512359WebCookieJar* RenderView::cookieJar() {
2360 return &cookie_jar_;
2361}
2362
[email protected]3d9689372009-09-10 04:29:172363void RenderView::willClose(WebFrame* frame) {
2364 if (!frame->parent()) {
2365 const GURL& url = frame->url();
2366 if (url.SchemeIs("http") || url.SchemeIs("https"))
2367 DumpLoadHistograms();
2368 }
[email protected]fa7b6b542009-11-03 05:02:302369
2370 WebDataSource* ds = frame->dataSource();
2371 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2372 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162373
[email protected]679f128f2010-07-22 22:57:442374 autofill_helper_.FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172375}
2376
[email protected]684e4a42010-01-30 06:44:112377bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402378 if (enabled_per_settings &&
2379 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2380 return true;
2381
2382 if (IsWhitelistedForContentSettings(frame))
2383 return true;
2384
2385 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2386 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112387}
2388
[email protected]d5f9e4f2010-07-28 08:31:302389bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
2390 if (CommandLine::ForCurrentProcess()->HasSwitch(
2391 switches::kEnableClickToPlay)) {
2392 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
2393 }
2394 return (enabled_per_settings &&
2395 AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS));
2396}
2397
2398
[email protected]3d9689372009-09-10 04:29:172399void RenderView::loadURLExternally(
2400 WebFrame* frame, const WebURLRequest& request,
2401 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592402 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2403 if (policy == WebKit::WebNavigationPolicyDownload) {
2404 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2405 } else {
2406 OpenURL(request.url(), referrer, policy);
2407 }
[email protected]3d9689372009-09-10 04:29:172408}
2409
2410WebNavigationPolicy RenderView::decidePolicyForNavigation(
2411 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222412 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172413 // Webkit is asking whether to navigate to a new URL.
2414 // This is fine normally, except if we're showing UI from one security
2415 // context and they're trying to navigate to a different context.
2416 const GURL& url = request.url();
2417
2418 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302419 // navigations.
[email protected]8079b362010-05-07 18:37:452420 if (renderer_preferences_.browser_handles_top_level_requests &&
2421 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192422 last_top_level_navigation_page_id_ = page_id_;
2423 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2424 OpenURL(url, referrer, default_policy);
2425 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172426 }
2427
2428 // A content initiated navigation may have originated from a link-click,
2429 // script, drag-n-drop operation, etc.
2430 bool is_content_initiated =
2431 NavigationState::FromDataSource(frame->provisionalDataSource())->
2432 is_content_initiated();
2433
2434 // We only care about navigations that are within the current tab (as opposed
2435 // to, for example, opening a new window).
2436 // But we sometimes navigate to about:blank to clear a tab, and we want to
2437 // still allow that.
2438 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2439 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532440 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172441 !url.SchemeIs(chrome::kAboutScheme)) {
2442 // When we received such unsolicited navigations, we sometimes want to
2443 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302444 if (CrossesExtensionExtents(frame, url) ||
2445 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172446 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422447 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172448 OpenURL(url, GURL(), default_policy);
2449 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2450 }
[email protected]8079b362010-05-07 18:37:452451
2452 // We forward navigations from extensions to the browser if they are
2453 // top-level events, even if the browser hasn't expressed interest.
2454 //
2455 // Note that we've already forwarded cross-extension extents navigations
2456 // above.
2457 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]c240ace2010-06-16 18:31:532458 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]8079b362010-05-07 18:37:452459 OpenURL(url, GURL(), default_policy);
2460 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2461 }
[email protected]3d9689372009-09-10 04:29:172462 }
2463
2464 // Detect when a page is "forking" a new tab that can be safely rendered in
2465 // its own process. This is done by sites like Gmail that try to open links
2466 // in new windows without script connections back to the original page. We
2467 // treat such cases as browser navigations (in which we will create a new
2468 // renderer for a cross-site navigation), rather than WebKit navigations.
2469 //
2470 // We use the following heuristic to decide whether to fork a new page in its
2471 // own process:
2472 // The parent page must open a new tab to about:blank, set the new tab's
2473 // window.opener to null, and then redirect the tab to a cross-site URL using
2474 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462475 //
2476 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2477 // (see below).
[email protected]3d9689372009-09-10 04:29:172478 bool is_fork =
2479 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252480 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172481 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522482 historyBackListCount() < 1 &&
2483 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172484 // The parent page must have set the child's window.opener to null before
2485 // redirecting to the desired URL.
2486 frame->opener() == NULL &&
2487 // Must be a top-level frame.
2488 frame->parent() == NULL &&
2489 // Must not have issued the request from this page.
2490 is_content_initiated &&
2491 // Must be targeted at the current tab.
2492 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2493 // Must be a JavaScript navigation, which appears as "other".
2494 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462495
2496 // Recognize if this navigation is from a link with rel=noreferrer and
2497 // target=_blank attributes, in which case the opener will be suppressed. If
2498 // so, it is safe to load cross-site pages in a separate process, so we
2499 // should let the browser handle it.
2500 bool is_noreferrer_and_blank_target =
2501 // Frame should be top level and not yet navigated.
2502 frame->parent() == NULL &&
2503 frame->url().isEmpty() &&
2504 historyBackListCount() < 1 &&
2505 historyForwardListCount() < 1 &&
2506 // Links with rel=noreferrer will have no Referer field, and their
2507 // resulting frame will have its window.opener suppressed.
2508 // TODO(creis): should add a request.httpReferrer() method to help avoid
2509 // typos on the unusual spelling of Referer.
2510 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2511 opener_suppressed_ &&
2512 frame->opener() == NULL &&
2513 // Links with target=_blank will have no name.
2514 frame->name().isNull() &&
2515 // Another frame (with a non-empty creator) should have initiated the
2516 // request, targeted at this frame.
2517 !creator_url_.is_empty() &&
2518 is_content_initiated &&
2519 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2520 type == WebKit::WebNavigationTypeOther;
2521
2522 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172523 // Open the URL via the browser, not via WebKit.
2524 OpenURL(url, GURL(), default_policy);
2525 return WebKit::WebNavigationPolicyIgnore;
2526 }
2527
2528 return default_policy;
2529}
2530
[email protected]6069da8c2009-10-20 20:33:492531bool RenderView::canHandleRequest(
2532 WebFrame* frame, const WebURLRequest& request) {
2533 // We allow WebKit to think that everything can be handled even though
2534 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342535 return true;
2536}
2537
[email protected]6069da8c2009-10-20 20:33:492538WebURLError RenderView::cannotHandleRequestError(
2539 WebFrame* frame, const WebURLRequest& request) {
2540 NOTREACHED(); // Since we said we can handle all requests.
2541 return WebURLError();
2542}
2543
2544WebURLError RenderView::cancelledError(
2545 WebFrame* frame, const WebURLRequest& request) {
2546 WebURLError error;
2547 error.domain = WebString::fromUTF8(net::kErrorDomain);
2548 error.reason = net::ERR_ABORTED;
2549 error.unreachableURL = request.url();
2550 return error;
[email protected]7b7a7dc2009-10-19 02:23:342551}
2552
2553void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492554 WebFrame*, const WebURLError&) {
2555 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342556}
2557
[email protected]90eeddb2010-05-06 21:06:432558void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2559 const WebKit::WebFormElement& form) {
2560 // Some login forms have onSubmit handlers that put a hash of the password
2561 // into a hidden field and then clear the password. (Issue 28910.)
2562 // This method gets called before any of those handlers run, so save away
2563 // a copy of the password in case it gets lost.
2564 NavigationState* navigation_state =
2565 NavigationState::FromDataSource(frame->dataSource());
2566 navigation_state->set_password_form_data(
2567 PasswordFormDomManager::CreatePasswordForm(form));
2568}
2569
[email protected]979c28b2009-11-07 01:30:482570void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172571 NavigationState* navigation_state =
2572 NavigationState::FromDataSource(frame->provisionalDataSource());
2573
2574 if (navigation_state->transition_type() == PageTransition::LINK)
2575 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2576
2577 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352578 WebSearchableFormData web_searchable_form_data(form);
2579 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2580 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212581 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432582 PasswordForm* password_form_data =
2583 PasswordFormDomManager::CreatePasswordForm(form);
2584 navigation_state->set_password_form_data(password_form_data);
2585
2586 // If the password has been cleared, recover it from the form contents already
2587 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2588 // opposed to the provisionalDataSource's, which is what we're storing into
2589 // now.)
2590 if (password_form_data && password_form_data->password_value.empty()) {
2591 NavigationState* old_navigation_state =
2592 NavigationState::FromDataSource(frame->dataSource());
2593 if (old_navigation_state) {
2594 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2595 if (old_form_data && old_form_data->action == password_form_data->action)
2596 password_form_data->password_value = old_form_data->password_value;
2597 }
2598 }
[email protected]3d9689372009-09-10 04:29:172599
[email protected]b1438212010-04-03 00:30:592600 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042601 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092602 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592603 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172604}
2605
2606void RenderView::willPerformClientRedirect(
2607 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2608 double fire_time) {
2609 // Ignore
2610}
2611
2612void RenderView::didCancelClientRedirect(WebFrame* frame) {
2613 // Ignore
2614}
2615
2616void RenderView::didCompleteClientRedirect(
2617 WebFrame* frame, const WebURL& from) {
2618 if (!frame->parent())
2619 completed_client_redirect_src_ = from;
2620}
2621
2622void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2623 // The rest of RenderView assumes that a WebDataSource will always have a
2624 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482625 bool content_initiated = !pending_navigation_state_.get();
2626 NavigationState* state = content_initiated ?
2627 NavigationState::CreateContentInitiated() :
2628 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182629 if (content_initiated) {
2630 switch (ds->request().cachePolicy()) {
2631 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2632 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2633 break;
2634 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2635 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2636 break;
2637 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2638 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2639 break;
2640 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2641 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2642 break;
2643 }
2644 }
[email protected]fa7b6b542009-11-03 05:02:302645
2646 state->set_user_script_idle_scheduler(
2647 new UserScriptIdleScheduler(this, frame));
2648 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172649}
2650
2651void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2652 WebDataSource* ds = frame->provisionalDataSource();
2653 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2654
2655 navigation_state->set_start_load_time(Time::Now());
2656
2657 // Update the request time if WebKit has better knowledge of it.
2658 if (navigation_state->request_time().is_null()) {
2659 double event_time = ds->triggeringEventTime();
2660 if (event_time != 0.0)
2661 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2662 }
2663
2664 bool is_top_most = !frame->parent();
2665 if (is_top_most) {
2666 navigation_gesture_ = frame->isProcessingUserGesture() ?
2667 NavigationGestureUnknown : NavigationGestureAuto;
2668
2669 // Make sure redirect tracking state is clear for the new load.
2670 completed_client_redirect_src_ = GURL();
2671 } else if (frame->parent()->isLoading()) {
2672 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002673 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172674 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2675 }
2676
2677 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2678 routing_id_, is_top_most, ds->request().url()));
2679}
2680
2681void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2682 if (frame->parent())
2683 return;
2684 // Received a redirect on the main frame.
2685 WebDataSource* data_source = frame->provisionalDataSource();
2686 if (!data_source) {
2687 // Should only be invoked when we have a data source.
2688 NOTREACHED();
2689 return;
2690 }
2691 std::vector<GURL> redirects;
2692 GetRedirectChain(data_source, &redirects);
2693 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512694 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2695 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172696 }
2697}
2698
[email protected]40bd6582009-12-04 23:49:512699void RenderView::didFailProvisionalLoad(WebFrame* frame,
2700 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172701 // Notify the browser that we failed a provisional load with an error.
2702 //
2703 // Note: It is important this notification occur before DidStopLoading so the
2704 // SSL manager can react to the provisional load failure before being
2705 // notified the load stopped.
2706 //
2707 WebDataSource* ds = frame->provisionalDataSource();
2708 DCHECK(ds);
2709
2710 const WebURLRequest& failed_request = ds->request();
2711
2712 bool show_repost_interstitial =
2713 (error.reason == net::ERR_CACHE_MISS &&
2714 EqualsASCII(failed_request.httpMethod(), "POST"));
2715 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2716 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2717 show_repost_interstitial));
2718
2719 // Don't display an error page if this is simply a cancelled load. Aside
2720 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2721 if (error.reason == net::ERR_ABORTED)
2722 return;
2723
2724 // Make sure we never show errors in view source mode.
2725 frame->enableViewSourceMode(false);
2726
2727 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2728
2729 // If this is a failed back/forward/reload navigation, then we need to do a
2730 // 'replace' load. This is necessary to avoid messing up session history.
2731 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2732 // as session history is concerned.
2733 //
2734 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2735 // the page id.
2736 //
2737 bool replace =
2738 navigation_state->pending_page_id() != -1 ||
2739 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2740
2741 // If we failed on a browser initiated request, then make sure that our error
2742 // page load is regarded as the same browser initiated request.
2743 if (!navigation_state->is_content_initiated()) {
2744 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2745 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002746 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172747 navigation_state->transition_type(),
2748 navigation_state->request_time()));
2749 }
2750
2751 // Provide the user with a more helpful error page?
2752 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2753 return;
2754
2755 // Fallback to a local error page.
2756 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2757 replace);
2758}
2759
2760void RenderView::didReceiveDocumentData(
2761 WebFrame* frame, const char* data, size_t data_len,
2762 bool& prevent_default) {
2763 NavigationState* navigation_state =
2764 NavigationState::FromDataSource(frame->dataSource());
2765 if (!navigation_state->postpone_loading_data())
2766 return;
2767
2768 // We're going to call commitDocumentData ourselves...
2769 prevent_default = true;
2770
2771 // Continue buffering the response data for the original 404 page. If it
2772 // grows too large, then we'll just let it through.
2773 navigation_state->append_postponed_data(data, data_len);
2774 if (navigation_state->postponed_data().size() >= 512) {
2775 navigation_state->set_postpone_loading_data(false);
2776 frame->commitDocumentData(navigation_state->postponed_data().data(),
2777 navigation_state->postponed_data().size());
2778 navigation_state->clear_postponed_data();
2779 }
2780}
2781
[email protected]40bd6582009-12-04 23:49:512782void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2783 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172784 NavigationState* navigation_state =
2785 NavigationState::FromDataSource(frame->dataSource());
2786
2787 navigation_state->set_commit_load_time(Time::Now());
2788 if (is_new_navigation) {
2789 // When we perform a new navigation, we need to update the previous session
2790 // history entry with state for the page we are leaving.
2791 UpdateSessionHistory(frame);
2792
2793 // We bump our Page ID to correspond with the new session history entry.
2794 page_id_ = next_page_id_++;
2795
[email protected]d64b07b2010-04-20 22:14:062796 // Any pending translation is now obsolete.
2797 translate_helper_.CancelPendingTranslation();
2798
[email protected]3cc72b12010-03-18 23:03:002799 // Advance our offset in session history, applying the length limit. There
2800 // is now no forward history.
2801 history_list_offset_++;
2802 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2803 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2804 history_list_length_ = history_list_offset_ + 1;
2805
[email protected]f9f4841b2010-03-20 05:41:422806 MessageLoop::current()->PostDelayedTask(
2807 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172808 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2809 page_id_, true),
2810 kDelayForForcedCaptureMs);
2811 } else {
2812 // Inspect the navigation_state on this frame to see if the navigation
2813 // corresponds to a session history navigation... Note: |frame| may or
2814 // may not be the toplevel frame, but for the case of capturing session
2815 // history, the first committed frame suffices. We keep track of whether
2816 // we've seen this commit before so that only capture session history once
2817 // per navigation.
2818 //
2819 // Note that we need to check if the page ID changed. In the case of a
2820 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2821 // previous URL and the current page ID, which would be wrong.
2822 if (navigation_state->pending_page_id() != -1 &&
2823 navigation_state->pending_page_id() != page_id_ &&
2824 !navigation_state->request_committed()) {
2825 // This is a successful session history navigation!
2826 UpdateSessionHistory(frame);
2827 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002828
2829 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172830 }
2831 }
2832
2833 // Remember that we've already processed this request, so we don't update
2834 // the session history again. We do this regardless of whether this is
2835 // a session history navigation, because if we attempted a session history
2836 // navigation without valid HistoryItem state, WebCore will think it is a
2837 // new navigation.
2838 navigation_state->set_request_committed(true);
2839
2840 UpdateURL(frame);
2841
2842 // If this committed load was initiated by a client redirect, we're
2843 // at the last stop now, so clear it.
2844 completed_client_redirect_src_ = GURL();
2845
2846 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272847 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172848}
2849
2850void RenderView::didClearWindowObject(WebFrame* frame) {
2851 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2852 BindDOMAutomationController(frame);
2853 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2854 dom_ui_bindings_.set_message_sender(this);
2855 dom_ui_bindings_.set_routing_id(routing_id_);
2856 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2857 }
2858 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2859 external_host_bindings_.set_message_sender(this);
2860 external_host_bindings_.set_routing_id(routing_id_);
2861 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2862 }
2863}
2864
2865void RenderView::didCreateDocumentElement(WebFrame* frame) {
2866 if (RenderThread::current()) { // Will be NULL during unit tests.
2867 RenderThread::current()->user_script_slave()->InjectScripts(
2868 frame, UserScript::DOCUMENT_START);
2869 }
[email protected]078b34612009-09-19 19:31:512870 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2871 view_type_ == ViewType::EXTENSION_MOLE) {
2872 InjectToolstripCSS();
2873 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2874 }
[email protected]3d9689372009-09-10 04:29:172875
2876 // Notify the browser about non-blank documents loading in the top frame.
2877 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252878 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272879 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172880 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2881 }
2882}
2883
2884void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2885 UpdateTitle(frame, title);
2886
2887 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272888 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172889}
2890
[email protected]5019ef12010-04-27 17:26:582891void RenderView::didChangeIcons(WebFrame* frame) {
2892 if (!frame->parent()) {
2893 Send(new ViewHostMsg_UpdateFavIconURL(
2894 routing_id_,
2895 page_id_,
2896 frame->favIconURL()));
2897 }
2898}
2899
[email protected]3d9689372009-09-10 04:29:172900void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2901 WebDataSource* ds = frame->dataSource();
2902 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2903 DCHECK(navigation_state);
2904 navigation_state->set_finish_document_load_time(Time::Now());
2905
2906 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2907
[email protected]e9e07992010-02-17 21:04:362908 // The document has now been fully loaded. Scan for forms to be sent up to
2909 // the browser.
[email protected]679f128f2010-07-22 22:57:442910 autofill_helper_.FrameContentsAvailable(frame);
2911 password_autocomplete_manager_.SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172912
2913 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272914 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172915
2916 if (RenderThread::current()) { // Will be NULL during unit tests.
2917 RenderThread::current()->user_script_slave()->InjectScripts(
2918 frame, UserScript::DOCUMENT_END);
2919 }
[email protected]fa7b6b542009-11-03 05:02:302920
2921 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2922}
2923
2924void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2925 if (RenderThread::current()) { // Will be NULL during unit tests.
2926 RenderThread::current()->user_script_slave()->InjectScripts(
2927 frame, UserScript::DOCUMENT_IDLE);
2928 }
2929
2930 WebFrame* main_frame = webview()->mainFrame();
2931 if (frame == main_frame) {
2932 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202933 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302934 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202935 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302936 pending_code_execution_queue_.pop();
2937 }
2938 }
[email protected]3d9689372009-09-10 04:29:172939}
2940
2941void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:262942 if (webview()->mainFrame() == frame)
2943 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172944}
2945
2946void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2947 // Ignore
2948}
2949
2950void RenderView::didFinishLoad(WebFrame* frame) {
2951 WebDataSource* ds = frame->dataSource();
2952 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2953 DCHECK(navigation_state);
2954 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302955 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412956
2957 // Let the password manager know which password forms are actually visible.
[email protected]679f128f2010-07-22 22:57:442958 password_autocomplete_manager_.SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172959}
2960
[email protected]ccbe04e2010-03-17 17:58:432961void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172962 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062963
2964 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2965 // since a new one gets created by didCreateDataSource.
2966 NavigationState* state =
2967 NavigationState::FromDataSource(frame->dataSource());
2968 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2969
[email protected]3d9689372009-09-10 04:29:172970 // If this was a reference fragment navigation that we initiated, then we
2971 // could end up having a non-null pending navigation state. We just need to
2972 // update the ExtraData on the datasource so that others who read the
2973 // ExtraData will get the new NavigationState. Similarly, if we did not
2974 // initiate this navigation, then we need to take care to reset any pre-
2975 // existing navigation state to a content-initiated navigation state.
2976 // DidCreateDataSource conveniently takes care of this for us.
2977 didCreateDataSource(frame, frame->dataSource());
2978
[email protected]f6c2459d2010-02-24 22:34:062979 if (idle_scheduler_ran) {
2980 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2981 NavigationState* new_state =
2982 NavigationState::FromDataSource(frame->dataSource());
2983 new_state->user_script_idle_scheduler()->set_has_run(true);
2984 }
2985
[email protected]3d9689372009-09-10 04:29:172986 didCommitProvisionalLoad(frame, is_new_navigation);
2987
[email protected]26aa0482009-09-30 16:55:272988 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172989}
2990
[email protected]476b6f82009-09-10 21:00:592991void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312992 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592993}
2994
[email protected]3d9689372009-09-10 04:29:172995void RenderView::assignIdentifierToRequest(
2996 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2997 // Ignore
2998}
2999
3000void RenderView::willSendRequest(
3001 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3002 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303003 WebFrame* top_frame = frame->top();
3004 if (!top_frame)
3005 top_frame = frame;
3006 WebDataSource* data_source = top_frame->provisionalDataSource();
3007 if (!data_source)
3008 data_source = top_frame->dataSource();
3009 if (data_source) {
3010 NavigationState* state = NavigationState::FromDataSource(data_source);
3011 if (state && state->is_cache_policy_override_set())
3012 request.setCachePolicy(state->cache_policy_override());
3013 }
[email protected]3d9689372009-09-10 04:29:173014 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503015 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133016 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493017
[email protected]85cc78c2010-05-04 18:30:093018 // Temporary metrics, see site_isolation_metrics.h
3019 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173020}
3021
3022void RenderView::didReceiveResponse(
3023 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493024
[email protected]85cc78c2010-05-04 18:30:093025 // Temporary metrics, see site_isolation_metrics.h
3026 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3027 identifier,
3028 response);
[email protected]fa0a3432010-03-30 16:53:493029
[email protected]3d9689372009-09-10 04:29:173030 // Only do this for responses that correspond to a provisional data source
3031 // of the top-most frame. If we have a provisional data source, then we
3032 // can't have any sub-resources yet, so we know that this response must
3033 // correspond to a frame load.
3034 if (!frame->provisionalDataSource() || frame->parent())
3035 return;
3036
3037 // If we are in view source mode, then just let the user see the source of
3038 // the server's 404 error page.
3039 if (frame->isViewSourceModeEnabled())
3040 return;
3041
[email protected]65041fa2010-05-21 06:56:533042 NavigationState* navigation_state =
3043 NavigationState::FromDataSource(frame->provisionalDataSource());
3044 CHECK(navigation_state);
3045
[email protected]972ebdff2010-06-10 22:59:073046 // Record page load flags.
3047 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3048 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573049 navigation_state->set_was_alternate_protocol_available(
3050 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073051 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]65041fa2010-05-21 06:56:533052
[email protected]f48013be2010-01-14 22:07:453053 // Consider loading an alternate error page for 404 responses.
3054 if (response.httpStatusCode() != 404)
3055 return;
3056
[email protected]3d9689372009-09-10 04:29:173057 // Can we even load an alternate error page for this URL?
3058 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3059 return;
3060
[email protected]3d9689372009-09-10 04:29:173061 navigation_state->set_postpone_loading_data(true);
3062 navigation_state->clear_postponed_data();
3063}
3064
3065void RenderView::didFinishResourceLoad(
3066 WebFrame* frame, unsigned identifier) {
3067 NavigationState* navigation_state =
3068 NavigationState::FromDataSource(frame->dataSource());
3069 if (!navigation_state->postpone_loading_data())
3070 return;
3071
3072 // The server returned a 404 and the content was < 512 bytes (which we
3073 // suppressed). Go ahead and fetch the alternate page content.
3074
3075 const GURL& frame_url = frame->url();
3076
3077 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3078 DCHECK(error_page_url.is_valid());
3079
3080 WebURLError original_error;
3081 original_error.unreachableURL = frame_url;
3082
3083 navigation_state->set_alt_error_page_fetcher(
3084 new AltErrorPageResourceFetcher(
3085 error_page_url, frame, original_error,
3086 NewCallback(this, &RenderView::AltErrorPageFinished)));
3087}
3088
3089void RenderView::didFailResourceLoad(
3090 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3091 // Ignore
3092}
3093
3094void RenderView::didLoadResourceFromMemoryCache(
3095 WebFrame* frame, const WebURLRequest& request,
3096 const WebURLResponse& response) {
3097 // Let the browser know we loaded a resource from the memory cache. This
3098 // message is needed to display the correct SSL indicators.
3099 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3100 routing_id_,
3101 request.url(),
[email protected]91733b62009-09-18 06:21:093102 frame->securityOrigin().toString().utf8(),
3103 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173104 response.securityInfo()));
3105}
3106
[email protected]6069da8c2009-10-20 20:33:493107void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293108 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3109}
3110
3111void RenderView::didRunInsecureContent(
3112 WebFrame* frame, const WebSecurityOrigin& origin) {
3113 Send(new ViewHostMsg_DidRunInsecureContent(
3114 routing_id_,
3115 origin.toString().utf8()));
3116}
3117
[email protected]7ea093ba2009-11-03 05:54:593118bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403119 if (enabled_per_settings &&
3120 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3121 return true;
[email protected]7ea093ba2009-11-03 05:54:593122
[email protected]12bc8472010-04-15 07:29:403123 if (IsWhitelistedForContentSettings(frame))
3124 return true;
[email protected]7ea093ba2009-11-03 05:54:593125
3126 return false; // Other protocols fall through here.
3127}
3128
[email protected]0a1a45432010-03-31 08:09:453129bool RenderView::allowDatabase(
3130 WebFrame* frame, const WebString& name, const WebString& display_name,
3131 unsigned long estimated_size) {
3132 WebSecurityOrigin origin = frame->securityOrigin();
3133 if (origin.isEmpty())
3134 return false; // Uninitialized document?
3135
3136 bool result;
3137 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3138 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3139 return false;
[email protected]9fb83e82010-07-02 18:24:553140 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3141 GURL(origin.toString().utf8()),
3142 name,
3143 display_name,
3144 estimated_size,
3145 !result));
[email protected]0a1a45432010-03-31 08:09:453146 return result;
3147}
[email protected]8934a3b2010-02-25 00:34:003148void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
3149 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
3150}
3151
[email protected]c21f1d52010-03-04 03:19:433152void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
3153 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
3154}
3155
[email protected]3d9689372009-09-10 04:29:173156void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3157 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3158}
3159
[email protected]0c882b282009-10-07 17:01:283160void RenderView::didCreateScriptContext(WebFrame* frame) {
3161 EventBindings::HandleContextCreated(frame, false);
3162}
3163
3164void RenderView::didDestroyScriptContext(WebFrame* frame) {
3165 EventBindings::HandleContextDestroyed(frame);
3166}
3167
3168void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3169 EventBindings::HandleContextCreated(frame, true);
3170}
3171
[email protected]fc86daa2010-03-30 23:52:533172void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3173 WebFrame* target,
3174 bool cross_origin,
3175 const WebString& property_name,
3176 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103177 // TODO(johnnyg): track the individual properties and repeat event_ids.
3178 if (cross_origin)
3179 cross_origin_access_count_++;
3180 else
3181 same_origin_access_count_++;
3182}
3183
[email protected]3d9689372009-09-10 04:29:173184void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143185 CheckPreferredSize();
3186}
3187
3188void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173189 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253190 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173191 // message.
[email protected]705243f2010-05-05 19:58:073192 if (!send_preferred_size_changes_ || !webview())
3193 return;
[email protected]dfca5acf2010-03-22 03:28:433194
[email protected]705243f2010-05-05 19:58:073195 // WebCore likes to tell us things have changed even when they haven't, so
3196 // cache the width and height and only send the IPC message when we're sure
3197 // they're different.
3198 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3199 webview()->mainFrame()->documentElementScrollHeight());
3200 if (size == preferred_size_)
3201 return;
[email protected]c27324b2009-11-19 22:44:293202
[email protected]705243f2010-05-05 19:58:073203 preferred_size_ = size;
3204 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3205 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173206}
3207
[email protected]143dcd592009-11-06 21:33:493208void RenderView::didChangeScrollOffset(WebFrame* frame) {
3209 StartNavStateSyncTimerIfNecessary();
3210}
3211
[email protected]8922e1f2009-10-03 05:01:263212void RenderView::reportFindInPageMatchCount(int request_id, int count,
3213 bool final_update) {
3214 // If we have a message that has been queued up, then we should just replace
3215 // it. The ACK from the browser will make sure it gets sent when the browser
3216 // wants it.
3217 if (queued_find_reply_message_.get()) {
3218 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3219 routing_id_,
3220 request_id,
3221 count,
3222 gfx::Rect(),
3223 -1, // Don't update active match ordinal.
3224 final_update);
3225 queued_find_reply_message_.reset(msg);
3226 } else {
3227 // Send the search result over to the browser process.
3228 Send(new ViewHostMsg_Find_Reply(
3229 routing_id_,
3230 request_id,
3231 count,
3232 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073233 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263234 final_update));
3235 }
3236}
3237
3238void RenderView::reportFindInPageSelection(int request_id,
3239 int active_match_ordinal,
3240 const WebRect& selection_rect) {
3241 // Send the search result over to the browser process.
3242 Send(new ViewHostMsg_Find_Reply(routing_id_,
3243 request_id,
3244 -1,
3245 selection_rect,
3246 active_match_ordinal,
3247 false));
3248}
3249
[email protected]24a7f3c2010-03-25 08:26:493250void RenderView::ReportNoFindInPageResults(int request_id) {
3251 Send(new ViewHostMsg_Find_Reply(routing_id_,
3252 request_id,
3253 0,
3254 gfx::Rect(),
3255 0,
3256 true));
3257}
3258
[email protected]79dbc662009-09-04 05:42:513259// webkit_glue::WebPluginPageDelegate -----------------------------------------
3260
[email protected]f103ab72009-09-02 17:10:593261webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533262 const FilePath& file_path,
3263 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593264 if (!PluginChannelHost::IsListening())
3265 return NULL;
3266
[email protected]d2139662009-12-10 03:21:143267 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283268 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143269 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163270 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533271 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143272 if (CommandLine::ForCurrentProcess()->
3273 HasSwitch(switches::kInternalPepper)) {
3274 in_process_plugin = true;
3275 use_pepper_host = true;
3276 } else {
3277 // In process Pepper plugins must be explicitly enabled.
3278 return NULL;
3279 }
[email protected]4e0616e2010-05-28 14:55:533280 } else {
3281 FilePath internal_pdf_path;
3282 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3283 if (file_path == internal_pdf_path) {
3284 in_process_plugin = true;
3285 use_pepper_host = true;
3286 }
[email protected]26e8d5e2009-10-13 02:47:163287 }
[email protected]4e0616e2010-05-28 14:55:533288
[email protected]d2139662009-12-10 03:21:143289 // Check for Native Client modules.
[email protected]8f05f7f2010-07-30 23:12:433290 if (mime_type == "application/x-nacl-srpc") {
3291 // NaCl is only permitted when we're in an extension/application with the
3292 // appropriate permission, or when explicitly enabled on the command line.
3293
3294 // TODO(cbiffle): need browser test for this before M7 (bug 45881)
3295 GURL main_frame_url(webview()->mainFrame()->url());
3296 const std::string &extension_id =
3297 RenderThread::current()->GetExtensionIdByURL(main_frame_url);
3298 bool in_ext = extension_id != "";
3299 bool explicit_enable =
3300 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3301
3302 if (in_ext) {
3303 if (ExtensionProcessBindings::HasPermission(extension_id,
3304 Extension::kNativeClientPermission)) {
3305 in_process_plugin = true;
3306 use_pepper_host = true;
3307 } else {
3308 // Disable NaCl for apps lacking the permission, even with the flag.
3309 return NULL;
3310 }
3311 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463312 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143313 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463314 }
3315 }
[email protected]4e0616e2010-05-28 14:55:533316
[email protected]d032f492009-09-29 00:33:463317 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143318 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283319 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533320 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333321 if (!pepper_plugin)
3322 return NULL;
3323
[email protected]53900d52010-06-16 04:25:013324 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283325 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143326 } else {
[email protected]6876dff2010-01-15 19:38:093327#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143328 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533329 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093330#else
[email protected]596b2c42010-01-14 20:40:433331 NOTIMPLEMENTED();
3332 return NULL;
[email protected]7b6616f2010-01-14 18:07:553333#endif
[email protected]6876dff2010-01-15 19:38:093334 }
[email protected]f103ab72009-09-02 17:10:593335 }
3336
[email protected]4e0616e2010-05-28 14:55:533337 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593338}
3339
3340void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033341#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593342 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3343 routing_id(), window));
3344#endif
3345}
3346
3347void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033348#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593349 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3350 routing_id(), window));
3351#endif
3352 CleanupWindowInPluginMoves(window);
3353}
3354
3355void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3356 SchedulePluginMove(move);
3357}
3358
3359void RenderView::DidStartLoadingForPlugin() {
3360 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523361 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593362}
3363
3364void RenderView::DidStopLoadingForPlugin() {
3365 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523366 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593367}
3368
3369void RenderView::ShowModalHTMLDialogForPlugin(
3370 const GURL& url,
3371 const gfx::Size& size,
3372 const std::string& json_arguments,
3373 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213374 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593375 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213376 json_retval));
[email protected]f103ab72009-09-02 17:10:593377}
3378
[email protected]b921cfd22010-02-25 16:57:513379WebCookieJar* RenderView::GetCookieJar() {
3380 return &cookie_jar_;
3381}
3382
initial.commit09911bf2008-07-26 23:55:293383void RenderView::SyncNavigationState() {
3384 if (!webview())
3385 return;
3386
[email protected]26aa0482009-09-30 16:55:273387 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173388 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293389 return;
[email protected]ca948a22009-06-25 19:36:173390
3391 Send(new ViewHostMsg_UpdateState(
3392 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293393}
3394
[email protected]b0950a72009-09-29 23:16:173395bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3396 // Make sure webview was not shut down.
3397 if (!webview())
3398 return false;
3399 // Create an image resource fetcher and assign it with a call back object.
3400 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273401 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173402 NewCallback(this, &RenderView::DidDownloadImage)));
3403 return true;
3404}
3405
3406void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293407 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173408 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473409 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3410 fetcher->id(),
3411 fetcher->image_url(),
3412 image.isNull(),
3413 image));
[email protected]b0950a72009-09-29 23:16:173414 // Dispose of the image fetcher.
3415 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3416 image_fetchers_.erase(fetcher);
3417 // We're in the callback from the ImageResourceFetcher, best to delay
3418 // deletion.
3419 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293420}
3421
[email protected]bf5c2ff392009-07-08 16:24:333422void RenderView::OnDownloadFavIcon(int id,
3423 const GURL& image_url,
3424 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343425 bool data_image_failed = false;
3426 if (image_url.SchemeIs("data")) {
3427 SkBitmap data_image = ImageFromDataUrl(image_url);
3428 data_image_failed = data_image.empty();
3429 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333430 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3431 data_image));
[email protected]f11ca0732009-04-11 00:09:343432 }
3433 }
3434
[email protected]bf5c2ff392009-07-08 16:24:333435 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173436 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333437 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3438 SkBitmap()));
3439 }
initial.commit09911bf2008-07-26 23:55:293440}
3441
[email protected]f11ca0732009-04-11 00:09:343442SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3443 std::string mime_type, char_set, data;
3444 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3445 // Decode the favicon using WebKit's image decoder.
3446 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3447 const unsigned char* src_data =
3448 reinterpret_cast<const unsigned char*>(&data[0]);
3449
3450 return decoder.Decode(src_data, data.size());
3451 }
3452 return SkBitmap();
3453}
3454
initial.commit09911bf2008-07-26 23:55:293455void RenderView::OnGetApplicationInfo(int page_id) {
3456 webkit_glue::WebApplicationInfo app_info;
3457 if (page_id == page_id_)
3458 webkit_glue::GetApplicationInfo(webview(), &app_info);
3459
3460 // Prune out any data URLs in the set of icons. The browser process expects
3461 // any icon with a data URL to have originated from a favicon. We don't want
3462 // to decode arbitrary data URLs in the browser process. See
3463 // http://b/issue?id=1162972
3464 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593465 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293466 app_info.icons.erase(app_info.icons.begin() + i);
3467 --i;
3468 }
3469 }
3470
3471 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3472}
3473
[email protected]7ccddb8c2009-08-04 17:36:553474GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293475 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553476 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293477 // If the URL that failed was secure, then the embedding web page was not
3478 // expecting a network attacker to be able to manipulate its contents. As
3479 // we fetch alternate error pages over HTTP, we would be allowing a network
3480 // attacker to manipulate the contents of the response if we tried to use
3481 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153482 return GURL();
initial.commit09911bf2008-07-26 23:55:293483 }
3484
3485 // Grab the base URL from the browser process.
3486 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153487 return GURL();
initial.commit09911bf2008-07-26 23:55:293488
3489 // Strip query params from the failed URL.
3490 GURL::Replacements remove_params;
3491 remove_params.ClearUsername();
3492 remove_params.ClearPassword();
3493 remove_params.ClearQuery();
3494 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553495 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503496 std::string spec_to_send = url_to_send.spec();
3497 // Notify link doctor of the url truncation by sending of "?" at the end.
3498 if (failed_url.has_query())
3499 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293500
3501 // Construct the query params to send to link doctor.
3502 std::string params(alternate_error_page_url_.query());
3503 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503504 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293505 params.append("&sourceid=chrome");
3506 params.append("&error=");
3507 switch (error_type) {
3508 case DNS_ERROR:
3509 params.append("dnserror");
3510 break;
3511
3512 case HTTP_404:
3513 params.append("http404");
3514 break;
3515
[email protected]5df266ac2008-10-15 19:50:133516 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333517 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133518 break;
3519
initial.commit09911bf2008-07-26 23:55:293520 default:
3521 NOTREACHED() << "unknown ErrorPageType";
3522 }
3523
3524 // OK, build the final url to return.
3525 GURL::Replacements link_doctor_params;
3526 link_doctor_params.SetQueryStr(params);
3527 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3528 return url;
3529}
3530
[email protected]0fdbf8c2010-07-08 20:33:013531WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3532 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493533}
3534
[email protected]6069da8c2009-10-20 20:33:493535void RenderView::OnFind(int request_id, const string16& search_text,
3536 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273537 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493538
3539 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493540 if (options.findNext) {
3541 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013542 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493543 } else {
[email protected]afdbd142010-07-10 08:01:233544 if (GetWebPluginFromPluginDocument()->startFind(
3545 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493546 } else {
3547 ReportNoFindInPageResults(request_id);
3548 }
3549 }
3550 return;
3551 }
3552
[email protected]b4bb2502009-10-01 22:35:273553 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273554 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293555 WebFrame* search_frame = focused_frame; // start searching focused frame.
3556
3557 bool multi_frame = (frame_after_main != main_frame);
3558
3559 // If we have multiple frames, we don't want to wrap the search within the
3560 // frame, so we check here if we only have main_frame in the chain.
3561 bool wrap_within_frame = !multi_frame;
3562
[email protected]b3f2b912009-04-09 16:18:523563 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293564 bool result = false;
3565
[email protected]7830da3e2009-11-06 16:27:263566 // If something is selected when we start searching it means we cannot just
3567 // increment the current match ordinal; we need to re-generate it.
3568 WebRange current_selection = focused_frame->selectionRange();
3569
initial.commit09911bf2008-07-26 23:55:293570 do {
[email protected]dd7daa82009-08-10 05:46:453571 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593572 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293573
3574 if (!result) {
3575 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223576 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293577
3578 // Find the next frame, but skip the invisible ones.
3579 do {
3580 // What is the next frame to search? (we might be going backwards). Note
3581 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593582 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273583 search_frame->traverseNext(true) :
3584 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453585 } while (!search_frame->hasVisibleContent() &&
3586 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293587
[email protected]884db412008-11-24 23:46:503588 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223589 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293590
3591 // If we have multiple frames and we have wrapped back around to the
3592 // focused frame, we need to search it once more allowing wrap within
3593 // the frame, otherwise it will report 'no match' if the focused frame has
3594 // reported matches, but no frames after the focused_frame contain a
3595 // match for the search word(s).
3596 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453597 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593598 request_id, search_text, options, true, // Force wrapping.
3599 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293600 }
3601 }
3602
[email protected]26aa0482009-09-30 16:55:273603 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293604 } while (!result && search_frame != focused_frame);
3605
[email protected]7830da3e2009-11-06 16:27:263606 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293607 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453608 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293609 } else {
3610 // If nothing is found, set result to "0 of 0", otherwise, set it to
3611 // "-1 of 1" to indicate that we found at least one item, but we don't know
3612 // yet what is active.
3613 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3614 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293615
[email protected]4f3dc372009-02-24 00:10:293616 // If we find no matches then this will be our last status update.
3617 // Otherwise the scoping effort will send more results.
3618 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293619
[email protected]4f3dc372009-02-24 00:10:293620 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403621 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593622 request_id,
[email protected]4f3dc372009-02-24 00:10:293623 match_count,
3624 selection_rect,
3625 ordinal,
3626 final_status_update));
initial.commit09911bf2008-07-26 23:55:293627
initial.commit09911bf2008-07-26 23:55:293628 // Scoping effort begins, starting with the mainframe.
3629 search_frame = main_frame;
3630
[email protected]dd7daa82009-08-10 05:46:453631 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293632
3633 do {
3634 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453635 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293636
3637 // We don't start another scoping effort unless at least one match has
3638 // been found.
3639 if (result) {
3640 // Start new scoping request. If the scoping function determines that it
3641 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453642 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593643 search_text,
3644 options,
initial.commit09911bf2008-07-26 23:55:293645 true); // reset the tickmarks
3646 }
3647
3648 // Iterate to the next frame. The frame will not necessarily scope, for
3649 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273650 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293651 } while (search_frame != main_frame);
3652 }
3653}
3654
[email protected]24a7f3c2010-03-25 08:26:493655void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3656 WebView* view = webview();
3657 if (!view)
3658 return;
3659
3660 WebDocument doc = view->mainFrame()->document();
3661 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013662 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493663 return;
3664 }
3665
3666 bool clear_selection =
3667 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3668 if (clear_selection)
3669 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3670
3671 WebFrame* frame = view->mainFrame();
3672 while (frame) {
3673 frame->stopFinding(clear_selection);
3674 frame = frame->traverseNext(false);
3675 }
3676
3677 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3678 WebFrame* focused_frame = view->focusedFrame();
3679 if (focused_frame) {
3680 WebDocument doc = focused_frame->document();
3681 if (!doc.isNull()) {
3682 WebNode node = doc.focusedNode();
3683 if (!node.isNull())
3684 node.simulateClick();
3685 }
3686 }
3687 }
3688}
3689
3690void RenderView::OnFindReplyAck() {
3691 // Check if there is any queued up request waiting to be sent.
3692 if (queued_find_reply_message_.get()) {
3693 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423694 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493695 }
3696}
3697
[email protected]8934a3b2010-02-25 00:34:003698bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353699 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003700 return current_content_settings_.settings[settings_type] !=
3701 CONTENT_SETTING_BLOCK;
3702}
3703
3704void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3705 if (!content_blocked_[settings_type]) {
3706 content_blocked_[settings_type] = true;
3707 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353708 }
[email protected]0de80162010-02-03 04:52:353709}
3710
[email protected]71b0d5d2010-02-15 05:43:073711void RenderView::ClearBlockedContentSettings() {
3712 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3713 content_blocked_[i] = false;
3714}
3715
[email protected]aad51d1c2010-08-05 08:38:093716WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame,
3717 const WebPluginParams& params,
3718 const FilePath& path,
3719 pepper::PluginModule* pepper_module) {
3720 WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params,
3721 pepper_delegate_.AsWeakPtr());
3722 if (plugin && !frame->parent() && frame->document().isPluginDocument()) {
3723 // If this is a full-page plugin hosting the internal PDF plugin, we want
3724 // to notify the browser so that it can treat things like zooming
3725 // differently.
3726 // TODO(sanjeevr): Use a Pepper interface to determine this rather than
3727 // hardcode this for the PDF plugin path.
3728 FilePath pdf_path;
3729 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
3730 if (path == pdf_path)
3731 Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_));
[email protected]0cdafff2010-07-26 09:54:373732 }
[email protected]aad51d1c2010-08-05 08:38:093733 return plugin;
3734}
[email protected]00152e92010-07-19 11:47:403735
[email protected]aad51d1c2010-08-05 08:38:093736WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame,
3737 const WebPluginParams& params,
3738 const FilePath& path,
3739 const std::string& mime_type) {
3740 std::string actual_mime_type(mime_type);
[email protected]00152e92010-07-19 11:47:403741 if (actual_mime_type.empty())
3742 actual_mime_type = params.mimeType.utf8();
3743
[email protected]aad51d1c2010-08-05 08:38:093744 return new webkit_glue::WebPluginImpl(frame, params, path,
[email protected]7a13e792010-08-03 08:18:243745 actual_mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403746}
3747
3748WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame,
[email protected]250afb02010-08-06 15:50:573749 const WebPluginParams& params) {
[email protected]00152e92010-07-19 11:47:403750 // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed.
[email protected]250afb02010-08-06 15:50:573751 BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params);
[email protected]00152e92010-07-19 11:47:403752 WebViewPlugin* plugin = blocked_plugin->plugin();
[email protected]250afb02010-08-06 15:50:573753 webkit_preferences_.Apply(plugin->web_view());
[email protected]00152e92010-07-19 11:47:403754 return plugin;
3755}
3756
[email protected]40bd6582009-12-04 23:49:513757void RenderView::OnZoom(PageZoom::Function function) {
3758 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3759 return;
3760
[email protected]258d31122010-05-09 10:59:413761 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523762
[email protected]40bd6582009-12-04 23:49:513763 int zoom_level = webview()->zoomLevel();
3764 int new_zoom_level = webview()->setZoomLevel(false,
3765 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3766
[email protected]9d797f32010-04-23 07:17:543767 // Tell the browser which url got zoomed so it can update the saved values.
3768 Send(new ViewHostMsg_DidZoomURL(
3769 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513770}
3771
[email protected]9d797f32010-04-23 07:17:543772void RenderView::OnSetContentSettingsForLoadingURL(
3773 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013774 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543775 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013776}
3777
[email protected]9d797f32010-04-23 07:17:543778void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3779 int zoom_level) {
3780 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293781}
3782
[email protected]41fc0322009-09-04 22:23:403783void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273784 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293785}
3786
[email protected]a697f4c2009-09-14 22:30:183787void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273788 WebString no_encoding;
3789 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183790}
3791
[email protected]20ad2692009-11-20 18:27:203792bool RenderView::GetAllChildFrames(
3793 WebFrame* parent_frame,
3794 std::vector<WebFrame*>* frames_vector) const {
3795 if (!parent_frame)
3796 return false;
3797 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3798 child_frame = child_frame->nextSibling()) {
3799 frames_vector->push_back(child_frame);
3800 GetAllChildFrames(child_frame, frames_vector);
3801 }
3802 return true;
3803}
3804
[email protected]dd7daa82009-08-10 05:46:453805WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3806 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273807 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453808
3809 // xpath string can represent a frame deep down the tree (across multiple
3810 // frame DOMs).
3811 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3812 // should break into 2 xpaths
3813 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3814
[email protected]26aa0482009-09-30 16:55:273815 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453816
3817 std::wstring xpath_remaining = xpath;
3818 while (!xpath_remaining.empty()) {
3819 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3820 std::wstring xpath_child;
3821 if (delim_pos != std::wstring::npos) {
3822 xpath_child = xpath_remaining.substr(0, delim_pos);
3823 xpath_remaining.erase(0, delim_pos + 1);
3824 } else {
3825 xpath_remaining.swap(xpath_child);
3826 }
3827 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293828 }
3829
[email protected]dd7daa82009-08-10 05:46:453830 return frame;
initial.commit09911bf2008-07-26 23:55:293831}
3832
[email protected]f29acf52008-11-03 20:08:333833void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3834 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293835 WebFrame* web_frame = GetChildFrame(frame_xpath);
3836 if (!web_frame)
3837 return;
3838
[email protected]dd7daa82009-08-10 05:46:453839 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293840}
3841
[email protected]1810e132009-03-24 23:35:483842void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083843 const std::string& css,
3844 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483845 WebFrame* web_frame = GetChildFrame(frame_xpath);
3846 if (!web_frame)
3847 return;
3848
[email protected]ffaef0c2009-09-15 17:08:083849 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483850}
3851
[email protected]00c39612010-03-06 02:53:283852void RenderView::OnPepperPluginDestroy(
3853 WebPluginDelegatePepper* pepper_plugin) {
3854 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:013855 current_oldstyle_pepper_plugins_.find(pepper_plugin);
3856 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:283857 NOTREACHED();
3858 return;
3859 }
[email protected]53900d52010-06-16 04:25:013860 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473861
3862 // The plugin could have been destroyed while it was waiting for a file
3863 // choose callback, so check all pending completion callbacks and NULL them.
3864 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3865 file_chooser_completions_.begin();
3866 i != file_chooser_completions_.end(); /* nothing */) {
3867 if ((*i)->completion == pepper_plugin) {
3868 // We NULL the first one instead of deleting it because the plugin might
3869 // be the one waiting for a file choose callback. If the callback later
3870 // comes, we don't want to send the result to the next callback in line.
3871 if (i == file_chooser_completions_.begin())
3872 (*i)->completion = NULL;
3873 else
3874 i = file_chooser_completions_.erase(i);
3875 } else {
3876 ++i;
3877 }
3878 }
[email protected]00c39612010-03-06 02:53:283879}
3880
initial.commit09911bf2008-07-26 23:55:293881void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3882 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333883 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293884}
3885
[email protected]1810e132009-03-24 23:35:483886void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083887 const std::string& css,
3888 const std::string& id) {
3889 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413890
3891 // Notify RenderViewHost that css has been inserted into the frame.
3892 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483893}
3894
[email protected]7ea066a2009-04-06 20:21:593895void RenderView::OnAddMessageToConsole(
3896 const string16& frame_xpath,
3897 const string16& message,
3898 const WebConsoleMessage::Level& level) {
3899 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593900 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453901 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293902}
3903
[email protected]81e63782009-02-27 19:35:093904void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3905 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293906}
3907
3908void RenderView::OnSetDOMUIProperty(const std::string& name,
3909 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093910 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293911 dom_ui_bindings_.SetProperty(name, value);
3912}
3913
3914void RenderView::OnReservePageIDRange(int size_of_range) {
3915 next_page_id_ += size_of_range + 1;
3916}
3917
[email protected]e80c73b2009-04-07 23:24:583918void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3919 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253920 bool ended,
3921 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033922 if (ended) {
[email protected]26aa0482009-09-30 16:55:273923 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203924 } else {
3925 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033926 }
initial.commit09911bf2008-07-26 23:55:293927}
3928
3929void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273930 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293931}
3932
initial.commit09911bf2008-07-26 23:55:293933void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163934 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:083935#if defined(WEBKIT_BUG_41283_IS_FIXED)
3936 password_autocomplete_manager_.ReceivedPasswordFormFillData(webview(),
3937 form_data);
[email protected]ad24ccb2010-07-15 21:38:203938#else
3939 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:083940#endif
initial.commit09911bf2008-07-26 23:55:293941}
3942
3943void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583944 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253945 const gfx::Point& screen_point,
3946 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273947 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583948 drop_data.ToDragData(),
3949 drop_data.identity,
3950 client_point,
[email protected]1d9f4132009-09-08 17:29:253951 screen_point,
3952 ops);
initial.commit09911bf2008-07-26 23:55:293953
[email protected]1d9f4132009-09-08 17:29:253954 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293955}
3956
[email protected]e80c73b2009-04-07 23:24:583957void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253958 const gfx::Point& screen_point,
3959 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273960 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253961 client_point,
3962 screen_point,
3963 ops);
initial.commit09911bf2008-07-26 23:55:293964
[email protected]1d9f4132009-09-08 17:29:253965 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293966}
3967
3968void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273969 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293970}
3971
[email protected]e80c73b2009-04-07 23:24:583972void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3973 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273974 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293975}
3976
3977void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593978 webkit_preferences_ = prefs;
3979 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293980}
3981
3982void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3983 alternate_error_page_url_ = url;
3984}
3985
[email protected]a0c7153e2009-12-09 14:36:333986void RenderView::OnCustomContextMenuAction(unsigned action) {
3987 webview()->performCustomContextMenuAction(action);
3988}
3989
[email protected]d4a00a72010-01-29 01:44:423990void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023991 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423992 const std::string& source_lang,
3993 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023994 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3995 translate_script);
[email protected]d4a00a72010-01-29 01:44:423996}
3997
[email protected]85d252e2010-04-06 22:21:023998void RenderView::OnRevertTranslation(int page_id) {
3999 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324000}
4001
initial.commit09911bf2008-07-26 23:55:294002void RenderView::OnInstallMissingPlugin() {
4003 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594004 if (first_default_plugin_)
4005 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294006}
4007
[email protected]97c5c592010-08-03 08:22:214008void RenderView::OnLoadBlockedPlugins() {
4009 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4010 Source<RenderView>(this),
4011 NotificationService::NoDetails());
4012}
4013
[email protected]cdaf8d02010-03-30 19:52:474014void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364015 // This could happen if we navigated to a different page before the user
4016 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474017 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364018 return;
4019
[email protected]cdaf8d02010-03-30 19:52:474020 WebVector<WebString> ws_file_names(paths.size());
4021 for (size_t i = 0; i < paths.size(); ++i)
4022 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464023
[email protected]cdaf8d02010-03-30 19:52:474024 if (file_chooser_completions_.front()->completion)
4025 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4026 file_chooser_completions_.pop_front();
4027
4028 // If there are more pending file chooser requests, schedule one now.
4029 if (!file_chooser_completions_.empty()) {
4030 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4031 file_chooser_completions_.front()->params));
4032 }
initial.commit09911bf2008-07-26 23:55:294033}
4034
4035void RenderView::OnEnableViewSourceMode() {
4036 if (!webview())
4037 return;
[email protected]26aa0482009-09-30 16:55:274038 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294039 if (!main_frame)
4040 return;
4041
[email protected]dd7daa82009-08-10 05:46:454042 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294043}
4044
[email protected]770dd8b2010-05-24 18:11:394045void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4046 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244047 if (send_preferred_size_changes_)
4048 return;
[email protected]9fb325e2010-05-06 18:23:244049 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394050
4051 // WebKit doesn't send a notification of the effective height of the page
4052 // changes, so poll for it.
4053 // TODO: Add a notification for this to WebKit, remove polling. After that's
4054 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4055 // http://crbug.com/44850
4056 if (flags & kPreferredSizeHeightThisIsSlow) {
4057 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4058 &RenderView::CheckPreferredSize);
4059 }
[email protected]0666aef2009-05-13 19:48:084060}
4061
[email protected]cda45c02010-02-25 19:28:104062void RenderView::OnDisableScrollbarsForSmallWindows(
4063 const gfx::Size& disable_scrollbar_size_limit) {
4064 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4065}
4066
[email protected]80d96fa2009-06-10 22:34:514067void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4068 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374069 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034070#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414071 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4072 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464073 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324074
[email protected]644d77e2010-01-27 01:03:104075 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324076 webview()->setScrollbarColors(
4077 renderer_prefs.thumb_inactive_color,
4078 renderer_prefs.thumb_active_color,
4079 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104080 webview()->setSelectionColors(
4081 renderer_prefs.active_selection_bg_color,
4082 renderer_prefs.active_selection_fg_color,
4083 renderer_prefs.inactive_selection_bg_color,
4084 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:014085 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:104086 }
[email protected]7a74e102009-09-03 00:16:564087#endif
[email protected]80d96fa2009-06-10 22:34:514088}
4089
[email protected]952cb702009-10-07 05:50:284090void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4091 const WebMediaPlayerAction& action) {
4092 if (webview())
4093 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564094}
4095
[email protected]7b291f92009-08-14 05:43:534096void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:514097 // When this is first set, the bindings aren't fully loaded. We only need
4098 // to call through this API after the page has already been loaded. It's
4099 // also called in didCreateDocumentElement to bootstrap.
4100 if (view_type_ != ViewType::INVALID) {
4101 if (type == ViewType::EXTENSION_MOLE ||
4102 type == ViewType::EXTENSION_TOOLSTRIP) {
4103 ExtensionProcessBindings::SetViewType(webview(), type);
4104 }
4105 }
[email protected]7b291f92009-08-14 05:43:534106 view_type_ = type;
4107}
4108
4109void RenderView::OnUpdateBrowserWindowId(int window_id) {
4110 browser_window_id_ = window_id;
4111}
4112
[email protected]b3df5a42010-05-11 14:31:094113void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364114 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414115 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114116 accessibility_.reset(WebAccessibilityCache::create());
4117 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:414118
[email protected]b3df5a42010-05-11 14:31:094119 WebAccessibilityObject src_tree = webview()->accessibilityObject();
4120 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
4121 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504122}
4123
[email protected]aef92842010-05-21 16:54:364124void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4125 if (!accessibility_.get())
4126 return;
4127 if (accessibility_->isValidId(acc_obj_id)) {
4128 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4129 // By convention, calling SetFocus on the root of the tree (id = 1000)
4130 // should clear the current focus. Otherwise set the focus to the new
4131 // node.
4132 if (acc_obj_id == 1000)
4133 webview()->clearFocusedNode();
4134 else
4135 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4136 }
4137}
4138
4139void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4140 if (!accessibility_.get())
4141 return;
4142 if (accessibility_->isValidId(acc_obj_id)) {
4143 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4144 }
4145}
4146
initial.commit09911bf2008-07-26 23:55:294147void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4148 const GURL& page_url) {
4149 // Prepare list to storage all savable resource links.
4150 std::vector<GURL> resources_list;
4151 std::vector<GURL> referrers_list;
4152 std::vector<GURL> frames_list;
4153 webkit_glue::SavableResourcesResult result(&resources_list,
4154 &referrers_list,
4155 &frames_list);
4156
[email protected]dbeb3952009-10-13 18:01:184157 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4158 webview(),
4159 page_url,
4160 &result,
4161 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294162 // If something is wrong when collecting all savable resource links,
4163 // send empty list to embedder(browser) to tell it failed.
4164 referrers_list.clear();
4165 resources_list.clear();
4166 frames_list.clear();
4167 }
4168
4169 // Send result of all savable resource links to embedder.
4170 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4171 resources_list,
4172 referrers_list,
4173 frames_list));
4174}
4175
4176void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324177 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314178 const std::vector<FilePath>& local_paths,
4179 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074180
4181 // Convert std::vector of GURLs to WebVector<WebURL>
4182 WebVector<WebURL> weburl_links(links);
4183
4184 // Convert std::vector of std::strings to WebVector<WebString>
4185 WebVector<WebString> webstring_paths(local_paths.size());
4186 for (size_t i = 0; i < local_paths.size(); i++)
4187 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4188
4189 WebPageSerializer::serialize(webview()->mainFrame(),
4190 true, this, weburl_links, webstring_paths,
4191 webkit_glue::FilePathToWebString(
4192 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294193}
4194
[email protected]d9ec5c0f2009-12-23 11:55:074195void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4196 const WebCString& data,
4197 WebPageSerializerClient::PageSerializationStatus status) {
4198 Send(new ViewHostMsg_SendSerializedHtmlData(
4199 routing_id_,
4200 frame_url,
4201 data.data(),
4202 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294203}
4204
[email protected]9b18a84f2010-06-10 15:54:044205void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274206 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474207 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294208}
4209
[email protected]eb6b87a2009-07-24 15:57:394210void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294211 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4212 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4213 // in the onunload handler from appearing. For now, we're bypassing that and
4214 // calling the FrameLoader's CloseURL method directly. This should be
4215 // revisited to avoid having two ways to close a page. Having a single way
4216 // to close that can run onunload is also useful for fixing
4217 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274218 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294219 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454220 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174221 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294222 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4223 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454224 if (url.SchemeIs(chrome::kHttpScheme) ||
4225 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294226 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294227 }
[email protected]26aa0482009-09-30 16:55:274228 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294229
[email protected]ab9eabac2010-03-16 16:54:104230 // Reset stats
4231 cross_origin_access_count_ = 0;
4232 same_origin_access_count_ = 0;
4233
[email protected]eb6b87a2009-07-24 15:57:394234 // Just echo back the params in the ACK.
4235 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294236}
4237
4238void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574239#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294240 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014241 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574242#else // defined(OS_WIN)
4243 // TODO(port): we don't support theming on non-Windows platforms yet
4244 NOTIMPLEMENTED();
4245#endif
initial.commit09911bf2008-07-26 23:55:294246}
4247
[email protected]9b18a84f2010-06-10 15:54:044248void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4249 const std::string& origin,
4250 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154251 if (message.empty())
4252 return;
[email protected]28790922009-03-09 19:48:374253 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4254 target);
[email protected]3ac14a052008-08-15 21:22:154255}
4256
[email protected]0aa55312008-10-17 21:53:084257void RenderView::OnDisassociateFromPopupCount() {
4258 if (decrement_shared_popup_at_destruction_)
4259 shared_popup_counter_->data--;
4260 shared_popup_counter_ = new SharedRenderViewCounter(0);
4261 decrement_shared_popup_at_destruction_ = false;
4262}
4263
[email protected]15d79e12009-08-02 19:23:454264bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4265 const WebURLError& error,
4266 bool replace) {
4267 // We only show alternate error pages in the main frame. They are
4268 // intended to assist the user when navigating, so there is not much
4269 // value in showing them for failed subframes. Ideally, we would be
4270 // able to use the TYPED transition type for this, but that flag is
4271 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454272 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454273 return false;
4274
4275 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374276 // connection failure.
[email protected]15d79e12009-08-02 19:23:454277 int ec = error.reason;
4278 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4279 ec != net::ERR_CONNECTION_FAILED &&
4280 ec != net::ERR_CONNECTION_REFUSED &&
4281 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374282 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454283 return false;
4284
4285 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554286 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454287 if (!error_page_url.is_valid())
4288 return false;
4289
4290 // Load an empty page first so there is an immediate response to the error,
4291 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454292 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454293 GURL(kUnreachableWebDataURL),
4294 error.unreachableURL,
4295 replace);
4296
4297 // Now, create a fetcher for the error page and associate it with the data
4298 // source we just created via the LoadHTMLString call. That way if another
4299 // navigation occurs, the fetcher will get destroyed.
4300 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454301 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454302 navigation_state->set_alt_error_page_fetcher(
4303 new AltErrorPageResourceFetcher(
4304 error_page_url, frame, error,
4305 NewCallback(this, &RenderView::AltErrorPageFinished)));
4306 return true;
4307}
4308
initial.commit09911bf2008-07-26 23:55:294309std::string RenderView::GetAltHTMLForTemplate(
4310 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394311 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294312 ResourceBundle::GetSharedInstance().GetRawDataResource(
4313 template_resource_id));
4314
4315 if (template_html.empty()) {
4316 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4317 return "";
4318 }
[email protected]7cd22a52009-07-14 00:40:254319
initial.commit09911bf2008-07-26 23:55:294320 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254321 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294322 template_html, &error_strings, "t");
4323}
[email protected]0e79b9e2009-02-13 04:20:484324
[email protected]15d79e12009-08-02 19:23:454325void RenderView::AltErrorPageFinished(WebFrame* frame,
4326 const WebURLError& original_error,
4327 const std::string& html) {
4328 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554329
4330 // If we failed to download the alternate error page, fall back to the
4331 // original error page if present. Otherwise, LoadNavigationErrorPage
4332 // will simply display a default error page.
4333 const std::string* html_to_load = &html;
4334 if (html.empty()) {
4335 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454336 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554337 html_to_load = &navigation_state->postponed_data();
4338 }
4339 LoadNavigationErrorPage(
4340 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454341}
4342
[email protected]30f75e62009-02-25 22:01:004343void RenderView::OnMoveOrResizeStarted() {
4344 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474345 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004346}
4347
[email protected]30f75e62009-02-25 22:01:004348void RenderView::OnResize(const gfx::Size& new_size,
4349 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104350 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474351 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104352
4353 if (send_preferred_size_changes_) {
4354 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4355 // either width or height, allow scroll bars.
4356 bool allow_scrollbars = (
4357 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244358 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104359 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4360 }
4361 }
4362
[email protected]30f75e62009-02-25 22:01:004363 RenderWidget::OnResize(new_size, resizer_rect);
4364}
[email protected]0aa477bd2009-03-23 22:21:434365
[email protected]00c39612010-03-06 02:53:284366void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014367 // Notify the pepper plugins that we started painting.
4368 pepper_delegate_.ViewInitiatedPaint();
4369
4370 // Notify any "old-style" pepper plugins that we started painting. This is
4371 // used for internal bookkeeping only, so we know that the set can not change
4372 // under us.
[email protected]00c39612010-03-06 02:53:284373 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014374 current_oldstyle_pepper_plugins_.begin();
4375 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284376 (*i)->RenderViewInitiatedPaint();
4377}
4378
4379void RenderView::DidFlushPaint() {
4380 // Notify any pepper plugins that we painted. This will call into the plugin,
4381 // and we it may ask to close itself as a result. This will, in turn, modify
4382 // our set, possibly invalidating the iterator. So we iterate on a copy that
4383 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014384 pepper_delegate_.ViewFlushedPaint();
4385
4386 // Notify any old-style pepper plugins that we painted. This will call into
4387 // the plugin, and we it may ask to close itself as a result. This will, in
4388 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4389 // a copy that won't change out from under us.
4390 // This should be deleted when we don't support old Pepper anymore.
4391 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284392 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4393 i != plugins.end(); ++i) {
4394 // The copy above makes sure our iterator is never invalid if some plugins
4395 // are destroyed. But some plugin may decide to close all of its views in
4396 // response to a paint in one of them, so we need to make sure each one is
4397 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014398 if (current_oldstyle_pepper_plugins_.find(*i) !=
4399 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284400 (*i)->RenderViewFlushedPaint();
4401 }
4402
4403 WebFrame* main_frame = webview()->mainFrame();
4404
4405 // If we have a provisional frame we are between the start and commit stages
4406 // of loading and we don't want to save stats.
4407 if (!main_frame->provisionalDataSource()) {
4408 WebDataSource* ds = main_frame->dataSource();
4409 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4410 DCHECK(navigation_state);
4411
4412 Time now = Time::Now();
4413 if (navigation_state->first_paint_time().is_null()) {
4414 navigation_state->set_first_paint_time(now);
4415 }
4416 if (navigation_state->first_paint_after_load_time().is_null() &&
4417 !navigation_state->finish_load_time().is_null()) {
4418 navigation_state->set_first_paint_after_load_time(now);
4419 }
4420 }
4421}
4422
[email protected]05d478752009-04-08 23:38:164423void RenderView::OnClearFocusedNode() {
4424 if (webview())
[email protected]26aa0482009-09-30 16:55:274425 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164426}
4427
[email protected]699ab0d2009-04-23 23:19:144428void RenderView::OnSetBackground(const SkBitmap& background) {
4429 if (webview())
[email protected]b4bb2502009-10-01 22:35:274430 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144431
4432 SetBackground(background);
4433}
4434
[email protected]8c66c5a2009-07-22 17:26:344435void RenderView::OnSetActive(bool active) {
4436 if (webview())
[email protected]b4bb2502009-10-01 22:35:274437 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264438
4439#if defined(OS_MACOSX)
4440 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4441 for (plugin_it = plugin_delegates_.begin();
4442 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4443 (*plugin_it)->SetWindowFocus(active);
4444 }
4445#endif
[email protected]8c66c5a2009-07-22 17:26:344446}
4447
[email protected]6ce7abc52010-02-02 18:40:144448#if defined(OS_MACOSX)
4449void RenderView::OnSetWindowVisibility(bool visible) {
4450 // Inform plugins that their container has changed visibility.
4451 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4452 for (plugin_it = plugin_delegates_.begin();
4453 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4454 (*plugin_it)->SetContainerVisibility(visible);
4455 }
4456}
[email protected]1e6e3c992010-02-08 15:52:134457
[email protected]4d51d5bf2010-07-26 18:48:264458void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4459 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134460 // Inform plugins that their window's frame has changed.
4461 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4462 for (plugin_it = plugin_delegates_.begin();
4463 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4464 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4465 }
4466}
[email protected]6ce7abc52010-02-02 18:40:144467#endif // OS_MACOSX
4468
[email protected]309d7a282009-03-24 09:18:274469void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584470 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394471 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324472 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474473 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394474 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4475 name,
4476 args,
4477 source_url,
4478 request_id,
[email protected]2f25d7b92009-06-10 00:06:474479 has_callback));
[email protected]309d7a282009-03-24 09:18:274480}
4481
[email protected]c6619182009-05-12 14:59:324482void RenderView::OnExtensionResponse(int request_id,
4483 bool success,
4484 const std::string& response,
4485 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354486 ExtensionProcessBindings::HandleResponse(
4487 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274488}
[email protected]c20210e62009-04-03 21:39:264489
[email protected]078b34612009-09-19 19:31:514490void RenderView::InjectToolstripCSS() {
4491 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4492 return;
4493
4494 static const base::StringPiece toolstrip_css(
4495 ResourceBundle::GetSharedInstance().GetRawDataResource(
4496 IDR_EXTENSION_TOOLSTRIP_CSS));
4497 std::string css = toolstrip_css.as_string();
4498 InsertCSS(L"", css, "ToolstripDefaultCSS");
4499}
4500
[email protected]7120f132009-07-20 21:05:374501void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494502 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194503 bool requires_incognito_access,
4504 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494505 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194506 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374507}
4508
[email protected]e7e4f3c2009-04-21 15:24:084509// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264510//
[email protected]c20210e62009-04-03 21:39:264511// The time points we keep are
4512// request: time document was requested by user
4513// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254514// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294515// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264516// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294517// first_paint: first paint performed
4518// first_paint_after_load: first paint performed after load is finished
4519// begin: request if it was user requested, start otherwise
4520//
[email protected]e7e4f3c2009-04-21 15:24:084521// It's possible for the request time not to be set, if a client
4522// redirect had been done (the user never requested the page)
4523// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294524// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264525void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504526 // Configuration for PLT related histograms.
4527 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4528 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4529 static const size_t kPLTCount(100);
4530 #define PLT_HISTOGRAM(name, sample) \
4531 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4532
[email protected]26aa0482009-09-30 16:55:274533 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564534 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454535 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564536
[email protected]f9f4841b2010-03-20 05:41:424537 // If we've already dumped, do nothing.
4538 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294539 return;
[email protected]cf9a7bc2010-06-11 18:54:504540
4541 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454542 Time start = navigation_state->start_load_time();
4543 if (start.is_null())
4544 return; // Probably very premature abandonment of page.
4545 Time commit = navigation_state->commit_load_time();
4546 if (commit.is_null())
4547 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504548
[email protected]b855ebe62010-05-12 23:01:454549 // We properly handle null values for the next 3 variables.
4550 Time request = navigation_state->request_time();
4551 Time first_paint = navigation_state->first_paint_time();
4552 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454553 Time finish = navigation_state->finish_load_time();
4554 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564555
[email protected]f9f4841b2010-03-20 05:41:424556 // Handle case where user hits "stop" or "back" before loading completely.
4557 bool abandoned_page = finish.is_null();
4558 if (abandoned_page) {
4559 finish = Time::Now();
4560 navigation_state->set_finish_load_time(finish);
4561 }
[email protected]f9f4841b2010-03-20 05:41:424562
[email protected]cf9a7bc2010-06-11 18:54:504563 if (finish_doc.is_null()) {
4564 DCHECK(abandoned_page); // how can the doc have finished but not the page?
4565 if (!abandoned_page)
4566 return; // Don't try to record a stat which is broken.
4567 finish_doc = finish;
4568 navigation_state->set_finish_document_load_time(finish_doc);
4569 }
4570
4571 // Note: Client side redirects will have no request time.
4572 Time begin = request.is_null() ? start : request;
4573 TimeDelta begin_to_finish_doc = finish_doc - begin;
4574 TimeDelta begin_to_finish = finish - begin;
4575 TimeDelta start_to_finish = finish - start;
[email protected]ef1d8d322010-06-13 18:31:254576 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424577
[email protected]a7ccc4d2010-01-27 08:14:484578 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504579
4580 // Aggregate PLT data across all link types.
4581 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4582 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4583 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254584 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504585 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
4586 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish - finish_doc);
4587 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
4588 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish);
4589 if (!request.is_null()) {
4590 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
4591 PLT_HISTOGRAM("PLT.RequestToFinish", finish - request);
4592 }
4593 PLT_HISTOGRAM("PLT.CommitToFinish", finish - commit);
4594 if (!first_paint.is_null()) {
4595 DCHECK(begin <= first_paint);
4596 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4597 DCHECK(commit <= first_paint);
4598 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4599 }
4600 if (!first_paint_after_load.is_null()) {
4601 DCHECK(begin <= first_paint_after_load);
4602 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4603 first_paint_after_load - begin);
4604 DCHECK(commit <= first_paint_after_load);
4605 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4606 first_paint_after_load - commit);
4607 DCHECK(finish <= first_paint_after_load);
4608 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
4609 first_paint_after_load - finish);
4610 }
4611 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
4612 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish);
4613
4614 // Load type related histograms.
4615 switch (load_type) {
4616 case NavigationState::UNDEFINED_LOAD:
4617 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
4618 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish);
4619 break;
4620 case NavigationState::RELOAD:
4621 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
4622 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish);
4623 break;
4624 case NavigationState::HISTORY_LOAD:
4625 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
4626 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish);
4627 break;
4628 case NavigationState::NORMAL_LOAD:
4629 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
4630 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish);
4631 break;
4632 case NavigationState::LINK_LOAD_NORMAL:
4633 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4634 begin_to_finish_doc);
4635 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", begin_to_finish);
4636 break;
4637 case NavigationState::LINK_LOAD_RELOAD:
4638 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4639 begin_to_finish_doc);
4640 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", begin_to_finish);
4641 break;
4642 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4643 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4644 begin_to_finish_doc);
4645 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", begin_to_finish);
4646 break;
4647 case NavigationState::LINK_LOAD_CACHE_ONLY:
4648 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4649 begin_to_finish_doc);
4650 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", begin_to_finish);
4651 break;
4652 default:
4653 break;
4654 }
4655
4656 // Histograms to determine if DNS prefetching has an impact on PLT.
4657 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4658 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4659 if (use_dns_histogram) {
4660 UMA_HISTOGRAM_ENUMERATION(
4661 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4662 abandoned_page ? 1 : 0, 2);
4663 UMA_HISTOGRAM_ENUMERATION(
4664 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4665 load_type, NavigationState::kLoadTypeMax);
4666 switch (load_type) {
4667 case NavigationState::NORMAL_LOAD:
4668 PLT_HISTOGRAM(FieldTrial::MakeName(
4669 "PLT.BeginToFinish_NormalLoad", "DnsImpact"), begin_to_finish);
4670 break;
4671 case NavigationState::LINK_LOAD_NORMAL:
4672 PLT_HISTOGRAM(FieldTrial::MakeName(
4673 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4674 begin_to_finish);
4675 break;
4676 case NavigationState::LINK_LOAD_RELOAD:
4677 PLT_HISTOGRAM(FieldTrial::MakeName(
4678 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
4679 begin_to_finish);
4680 break;
4681 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4682 PLT_HISTOGRAM(FieldTrial::MakeName(
4683 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4684 begin_to_finish);
4685 break;
4686 default:
4687 break;
4688 }
4689 }
4690
4691 // Histograms to determine if the number of connections has an
4692 // impact on PLT.
4693 // TODO(jar): Consider removing the per-link-type versions. We
4694 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
[email protected]97546492010-08-09 05:14:494695 static bool use_connection_impact_histogram(
[email protected]cf9a7bc2010-06-11 18:54:504696 FieldTrialList::Find("ConnCountImpact") &&
4697 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
[email protected]97546492010-08-09 05:14:494698 if (use_connection_impact_histogram) {
[email protected]cf9a7bc2010-06-11 18:54:504699 UMA_HISTOGRAM_ENUMERATION(
4700 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
4701 abandoned_page ? 1 : 0, 2);
4702 switch (load_type) {
4703 case NavigationState::NORMAL_LOAD:
4704 PLT_HISTOGRAM(FieldTrial::MakeName(
4705 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
4706 begin_to_finish);
4707 break;
4708 case NavigationState::LINK_LOAD_NORMAL:
4709 PLT_HISTOGRAM(FieldTrial::MakeName(
4710 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
4711 begin_to_finish);
4712 break;
4713 case NavigationState::LINK_LOAD_RELOAD:
4714 PLT_HISTOGRAM(FieldTrial::MakeName(
4715 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
4716 begin_to_finish);
4717 break;
4718 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4719 PLT_HISTOGRAM(FieldTrial::MakeName(
4720 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
4721 begin_to_finish);
4722 break;
4723 default:
4724 break;
4725 }
4726 }
4727
[email protected]78a258a2010-08-02 16:34:264728 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:004729 static bool use_idle_socket_timeout_histogram(
4730 FieldTrialList::Find("IdleSktToImpact") &&
4731 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
4732 if (use_idle_socket_timeout_histogram) {
4733 UMA_HISTOGRAM_ENUMERATION(
4734 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
4735 abandoned_page ? 1 : 0, 2);
4736 switch (load_type) {
4737 case NavigationState::NORMAL_LOAD:
4738 PLT_HISTOGRAM(FieldTrial::MakeName(
4739 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
4740 begin_to_finish);
4741 break;
4742 case NavigationState::LINK_LOAD_NORMAL:
4743 PLT_HISTOGRAM(FieldTrial::MakeName(
4744 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
4745 begin_to_finish);
4746 break;
4747 case NavigationState::LINK_LOAD_RELOAD:
4748 PLT_HISTOGRAM(FieldTrial::MakeName(
4749 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
4750 begin_to_finish);
4751 break;
4752 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4753 PLT_HISTOGRAM(FieldTrial::MakeName(
4754 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
4755 begin_to_finish);
4756 break;
4757 default:
4758 break;
4759 }
4760 }
4761
[email protected]78a258a2010-08-02 16:34:264762 // Histograms to determine effect of number of connections per proxy.
4763 static bool use_proxy_connection_impact_histogram(
4764 FieldTrialList::Find("ProxyConnectionImpact") &&
4765 !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty());
4766 if (use_proxy_connection_impact_histogram) {
4767 UMA_HISTOGRAM_ENUMERATION(
4768 FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
4769 abandoned_page ? 1 : 0, 2);
4770 switch (load_type) {
4771 case NavigationState::NORMAL_LOAD:
4772 PLT_HISTOGRAM(FieldTrial::MakeName(
4773 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
4774 begin_to_finish);
4775 break;
4776 case NavigationState::LINK_LOAD_NORMAL:
4777 PLT_HISTOGRAM(FieldTrial::MakeName(
4778 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
4779 begin_to_finish);
4780 break;
4781 case NavigationState::LINK_LOAD_RELOAD:
4782 PLT_HISTOGRAM(FieldTrial::MakeName(
4783 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
4784 begin_to_finish);
4785 break;
4786 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4787 PLT_HISTOGRAM(FieldTrial::MakeName(
4788 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
4789 begin_to_finish);
4790 break;
4791 default:
4792 break;
4793 }
4794 }
4795
[email protected]cf9a7bc2010-06-11 18:54:504796 // Histograms to determine if SDCH has an impact.
4797 // TODO(jar): Consider removing per-link load types and the enumeration.
4798 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4799 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4800 if (use_sdch_histogram) {
4801 UMA_HISTOGRAM_ENUMERATION(
4802 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
4803 load_type, NavigationState::kLoadTypeMax);
4804 switch (load_type) {
4805 case NavigationState::NORMAL_LOAD:
4806 PLT_HISTOGRAM(FieldTrial::MakeName(
4807 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
4808 begin_to_finish);
4809 break;
4810 case NavigationState::LINK_LOAD_NORMAL:
4811 PLT_HISTOGRAM(FieldTrial::MakeName(
4812 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4813 begin_to_finish);
4814 break;
4815 case NavigationState::LINK_LOAD_RELOAD:
4816 PLT_HISTOGRAM(FieldTrial::MakeName(
4817 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4818 begin_to_finish);
4819 break;
4820 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4821 PLT_HISTOGRAM(FieldTrial::MakeName(
4822 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4823 begin_to_finish);
4824 break;
4825 case NavigationState::LINK_LOAD_CACHE_ONLY:
4826 PLT_HISTOGRAM(FieldTrial::MakeName(
4827 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4828 begin_to_finish);
4829 break;
4830 default:
4831 break;
4832 }
4833 }
4834
4835 // Histograms to determine if cache size has an impact on PLT.
4836 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4837 !FieldTrialList::Find("CacheSize")->group_name().empty());
4838 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4839 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
4840 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
4841 // StartToFinish or BeginToFinish would be better.
4842 PLT_HISTOGRAM(FieldTrial::MakeName(
4843 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
4844 }
4845
[email protected]115f5542010-07-28 06:48:214846
4847 GURL url = GURL(main_frame->url());
4848
4849 // Histograms to determine if SPDY has an impact for https traffic.
[email protected]cf9a7bc2010-06-11 18:54:504850 // TODO(mbelshe): After we've seen the difference between BeginToFinish
4851 // and StartToFinish, consider removing one or the other.
4852 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
4853 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]115f5542010-07-28 06:48:214854 if (use_spdy_histogram && url.SchemeIs("https") &&
4855 navigation_state->was_npn_negotiated()) {
[email protected]30b35882010-06-14 21:21:014856 UMA_HISTOGRAM_ENUMERATION(
4857 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
4858 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:504859 switch (load_type) {
4860 case NavigationState::LINK_LOAD_NORMAL:
4861 PLT_HISTOGRAM(FieldTrial::MakeName(
4862 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4863 begin_to_finish);
4864 PLT_HISTOGRAM(FieldTrial::MakeName(
4865 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4866 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254867 PLT_HISTOGRAM(FieldTrial::MakeName(
4868 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4869 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504870 break;
4871 case NavigationState::NORMAL_LOAD:
4872 PLT_HISTOGRAM(FieldTrial::MakeName(
4873 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4874 begin_to_finish);
4875 PLT_HISTOGRAM(FieldTrial::MakeName(
4876 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4877 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254878 PLT_HISTOGRAM(FieldTrial::MakeName(
4879 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
4880 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504881 break;
4882 default:
4883 break;
4884 }
4885 }
4886
[email protected]115f5542010-07-28 06:48:214887 // Histograms to compare the impact of alternate protocol over http traffic:
4888 // when spdy is used vs. when http is used.
4889 if (url.SchemeIs("http") &&
4890 navigation_state->was_alternate_protocol_available()) {
[email protected]193b0b892010-06-26 03:57:574891 if (!navigation_state->was_npn_negotiated()) {
4892 // This means that even there is alternate protocols for npn_http or
4893 // npn_spdy, they are not taken (due to the fieldtrial).
4894 switch (load_type) {
4895 case NavigationState::LINK_LOAD_NORMAL:
4896 PLT_HISTOGRAM(
4897 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
4898 start_to_finish);
4899 PLT_HISTOGRAM(
4900 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
4901 start_to_commit);
4902 break;
4903 case NavigationState::NORMAL_LOAD:
4904 PLT_HISTOGRAM(
4905 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
4906 start_to_finish);
4907 PLT_HISTOGRAM(
4908 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
4909 start_to_commit);
4910 break;
4911 default:
4912 break;
4913 }
4914 } else if (navigation_state->was_fetched_via_spdy()) {
4915 switch (load_type) {
4916 case NavigationState::LINK_LOAD_NORMAL:
4917 PLT_HISTOGRAM(
4918 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
4919 start_to_finish);
4920 PLT_HISTOGRAM(
4921 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
4922 start_to_commit);
4923 break;
4924 case NavigationState::NORMAL_LOAD:
4925 PLT_HISTOGRAM(
4926 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
4927 start_to_finish);
4928 PLT_HISTOGRAM(
4929 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
4930 start_to_commit);
4931 break;
4932 default:
4933 break;
4934 }
4935 }
4936 }
4937
[email protected]cf9a7bc2010-06-11 18:54:504938 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:504939 if (navigation_state->was_fetched_via_proxy()) {
4940 if (url.SchemeIs("https")) {
4941 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish);
4942 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
4943 abandoned_page ? 1 : 0, 2);
4944 } else {
4945 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish);
4946 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
4947 abandoned_page ? 1 : 0, 2);
4948 }
4949 } else {
4950 if (url.SchemeIs("https")) {
4951 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", start_to_finish);
4952 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
4953 abandoned_page ? 1 : 0, 2);
4954 } else {
4955 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", start_to_finish);
4956 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
4957 abandoned_page ? 1 : 0, 2);
4958 }
4959 }
[email protected]a7ccc4d2010-01-27 08:14:484960
[email protected]ab9eabac2010-03-16 16:54:104961 // Site isolation metrics.
4962 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4963 cross_origin_access_count_);
4964 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4965 same_origin_access_count_);
4966
[email protected]cf9a7bc2010-06-11 18:54:504967 // Log some PLT data to the error log.
4968 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294969
4970 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414971
4972 // Since there are currently no guarantees that renderer histograms will be
4973 // sent to the browser, we initiate a PostTask here to be sure that we send
4974 // the histograms we generated. Without this call, pages that don't have an
4975 // on-close-handler might generate data that is lost when the renderer is
4976 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484977 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4978 // should post when the onload is complete, so that it doesn't interfere with
4979 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414980 if (RenderThread::current()) {
4981 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134982 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414983 }
[email protected]c20210e62009-04-03 21:39:264984}
[email protected]e846d0d2009-05-20 00:53:064985
[email protected]f8999642009-10-27 21:39:424986void RenderView::LogNavigationState(const NavigationState* state,
4987 const WebDataSource* ds) const {
4988 // Because this function gets called on every page load,
4989 // take extra care to optimize it away if logging is turned off.
4990 if (logging::LOG_INFO < logging::GetMinLogLevel())
4991 return;
4992
4993 DCHECK(state);
4994 DCHECK(ds);
4995 GURL url(ds->request().url());
4996 Time start = state->start_load_time();
4997 Time finish = state->finish_load_time();
4998 // TODO(mbelshe): should we log more stats?
4999 LOG(INFO) << "PLT: "
5000 << (finish - start).InMilliseconds()
5001 << "ms "
5002 << url.spec();
5003}
5004
[email protected]cc0445f2009-10-13 16:09:085005void RenderView::focusAccessibilityObject(
5006 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:065007#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:155008 // TODO(dglazkov): Current logic implies that focus change can only be made
5009 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5010 // where accessibility is initialized. We should determine whether that's
5011 // right.
5012 if (!accessibility_.get())
5013 return;
[email protected]e846d0d2009-05-20 00:53:065014
5015 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:155016 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:065017
5018 // If id is valid, alert the browser side that an accessibility focus change
5019 // occurred.
5020 if (acc_obj_id >= 0)
5021 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
5022
5023#else // defined(OS_WIN)
5024 // TODO(port): accessibility not yet implemented
5025 NOTIMPLEMENTED();
5026#endif
5027}
[email protected]daa8c58e2009-06-15 17:21:105028
[email protected]a3018be2010-03-09 04:28:485029void RenderView::didChangeAccessibilityObjectState(
5030 const WebKit::WebAccessibilityObject& acc_obj) {
5031#if defined(OS_WIN)
5032 // TODO(dglazkov): Current logic implies that a state change can only be made
5033 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
5034 // where accessibility is initialized. We should determine whether that's
5035 // right.
5036 if (!accessibility_.get())
5037 return;
5038
5039 // Retrieve the accessibility object id of the AccessibilityObject.
5040 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
5041
5042 // If id is valid, alert the browser side that an accessibility object state
5043 // change occurred.
5044 if (acc_obj_id >= 0)
5045 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
5046 acc_obj_id));
5047
5048#else // defined(OS_WIN)
5049 // TODO(port): accessibility not yet implemented
5050 NOTIMPLEMENTED();
5051#endif
5052}
5053
[email protected]0fda7272009-06-26 15:49:335054void RenderView::Print(WebFrame* frame, bool script_initiated) {
5055 DCHECK(frame);
5056 if (print_helper_.get() == NULL) {
5057 print_helper_.reset(new PrintWebViewHelper(this));
5058 }
5059 print_helper_->Print(frame, script_initiated);
5060}
[email protected]446705872009-09-10 07:22:485061
5062void RenderView::OnSetEditCommandsForNextKeyEvent(
5063 const EditCommands& edit_commands) {
5064 edit_commands_ = edit_commands;
5065}
5066
[email protected]61f5a7b2009-12-22 22:21:205067void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275068 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355069 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205070 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5071 false));
[email protected]912256b32009-09-18 09:47:355072 return;
5073 }
5074
[email protected]fa7b6b542009-11-03 05:02:305075 WebDataSource* ds = main_frame->dataSource();
5076 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5077 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205078 pending_code_execution_queue_.push(
5079 linked_ptr<ViewMsg_ExecuteCode_Params>(
5080 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305081 return;
5082 }
5083
[email protected]61f5a7b2009-12-22 22:21:205084 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305085}
5086
5087void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205088 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485089 // Don't execute scripts in gallery pages.
5090 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085091 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5092 && !CommandLine::ForCurrentProcess()->HasSwitch(
5093 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485094 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5095 return;
5096 }
5097
[email protected]20ad2692009-11-20 18:27:205098 std::vector<WebFrame*> frame_vector;
5099 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205100 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205101 GetAllChildFrames(frame, &frame_vector);
5102
5103 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5104 frame_it != frame_vector.end(); ++frame_it) {
5105 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205106 if (params.is_javascript) {
5107 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5108 continue;
5109
[email protected]20ad2692009-11-20 18:27:205110 std::vector<WebScriptSource> sources;
5111 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205112 WebScriptSource(WebString::fromUTF8(params.code)));
5113 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205114 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205115 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205116 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5117 } else {
[email protected]61f5a7b2009-12-22 22:21:205118 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205119 }
[email protected]912256b32009-09-18 09:47:355120 }
5121
[email protected]61f5a7b2009-12-22 22:21:205122 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355123}
5124
[email protected]60c42a8c72009-10-09 04:08:595125void RenderView::Close() {
5126 // We need to grab a pointer to the doomed WebView before we destroy it.
5127 WebView* doomed = webview();
5128 RenderWidget::Close();
5129 Singleton<ViewMap>::get()->erase(doomed);
5130}
5131
[email protected]446705872009-09-10 07:22:485132void RenderView::DidHandleKeyEvent() {
5133 edit_commands_.clear();
5134}
5135
[email protected]941e4552010-02-01 21:23:435136#if defined(OS_MACOSX)
5137void RenderView::OnWasHidden() {
5138 RenderWidget::OnWasHidden();
5139
5140 // Inform plugins that their container is no longer visible.
5141 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5142 for (plugin_it = plugin_delegates_.begin();
5143 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5144 (*plugin_it)->SetContainerVisibility(false);
5145 }
5146}
5147
5148void RenderView::OnWasRestored(bool needs_repainting) {
5149 RenderWidget::OnWasRestored(needs_repainting);
5150
5151 // Inform plugins that their container is now visible.
5152 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5153 for (plugin_it = plugin_delegates_.begin();
5154 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5155 (*plugin_it)->SetContainerVisibility(true);
5156 }
5157}
[email protected]1e6e3c992010-02-08 15:52:135158
5159void RenderView::OnSetFocus(bool enable) {
5160 RenderWidget::OnSetFocus(enable);
5161
[email protected]7d3c02c2010-05-05 23:10:315162 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135163 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5164 for (plugin_it = plugin_delegates_.begin();
5165 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315166 // RenderWidget's call to setFocus can cause the underlying webview's
5167 // activation state to change just like a call to setIsActive.
5168 if (enable)
5169 (*plugin_it)->SetWindowFocus(true);
5170 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135171 }
5172 }
5173}
[email protected]941e4552010-02-01 21:23:435174#endif // OS_MACOSX
5175
[email protected]83dde542009-09-11 20:59:555176void RenderView::EnsureDocumentTag() {
5177 // TODO(darin): There's actually no reason for this to be here. We should
5178 // have the browser side manage the document tag.
5179#if defined(OS_MACOSX)
5180 if (!has_document_tag_) {
5181 // Make the call to get the tag.
5182 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5183 has_document_tag_ = true;
5184 }
5185#endif
5186}
[email protected]12636df2009-09-28 22:32:215187
[email protected]43f28f832010-02-03 02:28:485188#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035189gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235190 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485191 gfx::PluginWindowHandle window = NULL;
5192 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235193 routing_id(), opaque, root, &window));
[email protected]43f28f832010-02-03 02:28:485194 return window;
5195}
5196
5197void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5198 if (window)
5199 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5200}
5201
[email protected]44ce0b12010-03-12 16:45:335202void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5203 int32 width,
5204 int32 height,
5205 uint64 io_surface_identifier) {
5206 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485207 routing_id(), window, width, height, io_surface_identifier));
5208}
5209
[email protected]44ce0b12010-03-12 16:45:335210void RenderView::AcceleratedSurfaceSetTransportDIB(
5211 gfx::PluginWindowHandle window,
5212 int32 width,
5213 int32 height,
5214 TransportDIB::Handle transport_dib) {
5215 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075216 routing_id(), window, width, height, transport_dib));
5217}
5218
[email protected]44ce0b12010-03-12 16:45:335219TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5220 size_t size) {
[email protected]1aef98132010-02-23 18:00:075221 TransportDIB::Handle dib_handle;
5222 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385223 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075224 return dib_handle;
5225 // Return an invalid handle if Send() fails.
5226 return TransportDIB::DefaultHandleValue();
5227}
5228
[email protected]44ce0b12010-03-12 16:45:335229void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075230 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5231}
5232
[email protected]44ce0b12010-03-12 16:45:335233void RenderView::AcceleratedSurfaceBuffersSwapped(
5234 gfx::PluginWindowHandle window) {
5235 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485236}
5237#endif
[email protected]58c321d2010-02-19 12:11:285238
[email protected]cdaf8d02010-03-30 19:52:475239bool RenderView::ScheduleFileChooser(
5240 const ViewHostMsg_RunFileChooser_Params& params,
5241 WebFileChooserCompletion* completion) {
5242 static const size_t kMaximumPendingFileChooseRequests = 4;
5243 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5244 // This sanity check prevents too many file choose requests from getting
5245 // queued which could DoS the user. Getting these is most likely a
5246 // programming error (there are many ways to DoS the user so it's not
5247 // considered a "real" security check), either in JS requesting many file
5248 // choosers to pop up, or in a plugin.
5249 //
5250 // TODO(brettw) we might possibly want to require a user gesture to open
5251 // a file picker, which will address this issue in a better way.
5252 return false;
5253 }
5254
5255 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5256 new PendingFileChooser(params, completion)));
5257 if (file_chooser_completions_.size() == 1) {
5258 // Actually show the browse dialog when this is the first request.
5259 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5260 }
5261 return true;
5262}
5263
[email protected]290838a2010-04-27 17:37:015264void RenderView::OnPageTranslated() {
5265 WebFrame* frame = webview()->mainFrame();
5266 if (!frame)
5267 return;
5268
5269 // The page is translated, so try to extract the form data again.
[email protected]679f128f2010-07-22 22:57:445270 autofill_helper_.FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015271}
5272
[email protected]8a5f7002010-03-31 13:47:355273WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285274 if (!geolocation_dispatcher_.get())
5275 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5276 return geolocation_dispatcher_.get();
5277}
[email protected]61c9f032010-03-31 23:04:195278
[email protected]638694c2010-08-04 22:24:115279WebKit::WebSpeechInputController* RenderView::speechInputController(
5280 WebKit::WebSpeechInputListener* listener) {
5281 if (!speech_input_dispatcher_.get())
5282 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5283 return speech_input_dispatcher_.get();
5284}
5285
[email protected]8079b362010-05-07 18:37:455286bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195287 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455288 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195289 if (frame->parent() != NULL)
5290 return false;
5291
[email protected]f0a3d0b2010-08-06 22:51:535292 // Navigations initiated within Webkit are not sent out to the external host
5293 // in the following cases.
5294 // 1. The url scheme or the frame url scheme is not http/https
5295 // 2. The origin of the url and the frame is the same in which case the
5296 // opener relationship is maintained.
5297 // 3. Anchor navigation within the same page.
5298 // 4. Reloads/form submits/back forward navigations
5299 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5300 return false;
5301
5302 GURL frame_url(frame->url());
5303 if (!frame_url.SchemeIs("http") && !frame_url.SchemeIs("https"))
5304 return false;
5305
[email protected]61c9f032010-03-31 23:04:195306 // Skip if navigation is on the same page (using '#').
[email protected]f0a3d0b2010-08-06 22:51:535307 GURL frame_origin = frame_url.GetOrigin();
[email protected]61c9f032010-03-31 23:04:195308 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5309 // The link click could stay on the same page, in cases where it sends some
5310 // parameters to the same URL.
5311 if (type == WebKit::WebNavigationTypeLinkClicked)
5312 return true;
5313
5314 if (last_top_level_navigation_page_id_ != page_id_ &&
5315 // Not interested in reloads.
5316 type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015317 type != WebKit::WebNavigationTypeFormSubmitted &&
5318 type != WebKit::WebNavigationTypeBackForward) {
[email protected]61c9f032010-03-31 23:04:195319 return true;
5320 }
5321 }
[email protected]d0ed50d2010-06-22 01:01:325322 // Not interested in reloads.
5323 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015324 type != WebKit::WebNavigationTypeFormSubmitted &&
5325 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325326 // The opener relationship between the new window and the parent allows the
5327 // new window to script the parent and vice versa. This is not allowed if
5328 // the origins of the two domains are different. This can be treated as a
5329 // top level navigation and routed back to the host.
5330 WebKit::WebFrame* opener = frame->opener();
5331 if (opener) {
5332 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5333 return true;
5334 }
5335 }
[email protected]61c9f032010-03-31 23:04:195336 return false;
5337}