blob: c2db5d5e0954974efe59bb993ad6780a37fef79d [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]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2125#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2829#include "chrome/common/chrome_paths.h"
30#include "chrome/common/chrome_switches.h"
[email protected]a0cf04a2010-06-23 03:29:5531#include "chrome/common/extensions/extension.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1733#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5334#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2935#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2636#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5938#include "chrome/common/url_constants.h"
[email protected]534c66c2010-04-28 22:53:1139#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2541#include "chrome/renderer/audio_message_filter.h"
[email protected]00152e92010-07-19 11:47:4042#include "chrome/renderer/blocked_plugin.h"
[email protected]e4ac5df2009-03-17 15:33:1143#include "chrome/renderer/devtools_agent.h"
44#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3545#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3246#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3547#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3748#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2849#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5651#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1152#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5653#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1254#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3055#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5056#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2557#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2858#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2659#include "chrome/renderer/render_view_visitor.h"
[email protected]035545f2010-04-09 13:10:2160#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3461#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4662#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3563#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2965#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2966#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4267#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5668#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1569#include "gfx/color_utils.h"
70#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5771#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2672#include "gfx/point.h"
73#include "gfx/rect.h"
[email protected]34ac8f32009-02-22 23:03:2774#include "grit/generated_resources.h"
75#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3476#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2977#include "net/base/escape.h"
78#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0079#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1080#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3081#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]b5558cf22010-07-12 17:30:0682#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4983#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:2684#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0785#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4986#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
87#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3288#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4989#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3590#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5991#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4992#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4195#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5096#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4997#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3298#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0799#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49100#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40101#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]b4f68dea2010-05-13 06:03:17102#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:49103#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49104#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
105#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
106#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
107#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
108#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
109#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40110#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49111#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34112#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49113#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
114#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
115#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
116#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
117#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
118#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26119#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11120#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04121#include "webkit/appcache/web_application_cache_host_impl.h"
initial.commit09911bf2008-07-26 23:55:29122#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59123#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24124#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24125#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34126#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26127#include "webkit/glue/image_resource_fetcher.h"
[email protected]8e296bbd2009-07-22 21:37:17128#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51129#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09130#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26131#include "webkit/glue/password_form_dom_manager.h"
[email protected]0d64bb72010-07-07 05:36:38132#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17133#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29134#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30135#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23136#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30137#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]00152e92010-07-19 11:47:40138#include "webkit/glue/plugins/webview_plugin.h"
[email protected]85cc78c2010-05-04 18:30:09139#include "webkit/glue/site_isolation_metrics.h"
initial.commit09911bf2008-07-26 23:55:29140#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29141#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17142#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29143
[email protected]6c8afae52009-01-22 02:24:57144#if defined(OS_WIN)
145// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57146// * theming
[email protected]cd818412010-03-19 03:23:15147#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03148#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46149#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33150#elif defined(OS_MACOSX)
151#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57152#endif
153
[email protected]80f584d92010-01-21 03:59:04154using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26155using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33156using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45157using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59158using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24159using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17160using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56161using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10162using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09163using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15164using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08165using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21166using WebKit::WebApplicationCacheHost;
167using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41168using WebKit::WebColor;
169using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59170using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44171using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51172using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07173using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55174using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28175using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29176using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00177using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58178using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25179using WebKit::WebDragOperation;
180using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51181using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47182using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49183using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59184using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48185using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45186using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17187using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41188using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50189using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17190using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28191using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17192using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28193using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28194using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51195using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07196using WebKit::WebPageSerializer;
197using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17198using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40199using WebKit::WebPluginContainer;
[email protected]3d9689372009-09-10 04:29:17200using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49201using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52202using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59203using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51204using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52205using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40206using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35207using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29208using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59209using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42210using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02211using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34212using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28213using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51214using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52215using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28216using WebKit::WebURL;
217using WebKit::WebURLError;
218using WebKit::WebURLRequest;
219using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28220using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03221using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28222using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43223using WebKit::WebWorker;
224using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11225using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33226
initial.commit09911bf2008-07-26 23:55:29227//-----------------------------------------------------------------------------
228
[email protected]3354d3e2010-06-10 19:53:02229typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
230
initial.commit09911bf2008-07-26 23:55:29231// define to write the time necessary for thumbnail/DOM text retrieval,
232// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29233// #define TIME_TEXT_RETRIEVAL
234
235// maximum number of characters in the document to index, any text beyond this
236// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57237static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29238
239// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37240static const int kThumbnailWidth = 212;
241static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29242
243// Delay in milliseconds that we'll wait before capturing the page contents
244// and thumbnail.
245static const int kDelayForCaptureMs = 500;
246
247// Typically, we capture the page data once the page is loaded.
248// Sometimes, the page never finishes to load, preventing the page capture
249// To workaround this problem, we always perform a capture after the following
250// delay.
251static const int kDelayForForcedCaptureMs = 6000;
252
[email protected]882daa92009-11-05 16:31:31253// Time, in seconds, we delay before sending content state changes (such as form
254// state and scroll position) to the browser. We delay sending changes to avoid
255// spamming the browser.
256// To avoid having tab/session restore require sending a message to get the
257// current content state during tab closing we use a shorter timeout for the
258// foreground renderer. This means there is a small window of time from which
259// content state is modified and not sent to session restore, but this is
260// better than having to wake up all renderers during shutdown.
261static const int kDelaySecondsForContentStateSyncHidden = 5;
262static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29263
[email protected]0aa55312008-10-17 21:53:08264// The maximum number of popups that can be spawned from one page.
265static const int kMaximumNumberOfUnacknowledgedPopups = 25;
266
initial.commit09911bf2008-07-26 23:55:29267static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16268 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29269
[email protected]50b691c2008-10-31 19:08:35270static const char* const kBackForwardNavigationScheme = "history";
271
[email protected]726985e22009-06-18 21:09:28272static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
273 WebVector<WebURL> urls;
274 ds->redirectChain(urls);
275 result->reserve(urls.size());
276 for (size_t i = 0; i < urls.size(); ++i)
277 result->push_back(urls[i]);
278}
279
[email protected]61f5a7b2009-12-22 22:21:20280static bool UrlMatchesPermissions(
281 const GURL& url, const std::vector<URLPattern>& host_permissions) {
282 for (size_t i = 0; i < host_permissions.size(); ++i) {
283 if (host_permissions[i].MatchesUrl(url))
284 return true;
285 }
286
287 return false;
288}
289
[email protected]30507922010-01-15 16:48:23290static bool PaintViewIntoCanvas(WebView* view,
291 skia::PlatformCanvas& canvas) {
292 view->layout();
293 const WebSize& size = view->size();
294
295 if (!canvas.initialize(size.width, size.height, true))
296 return false;
297
298 view->paint(webkit_glue::ToWebCanvas(&canvas),
299 WebRect(0, 0, size.width, size.height));
300 // TODO: Add a way to snapshot the whole page, not just the currently
301 // visible part.
302
303 return true;
304}
305
306// Calculates how "boring" a thumbnail is. The boring score is the
307// 0,1 ranged percentage of pixels that are the most common
308// luma. Higher boring scores indicate that a higher percentage of a
309// bitmap are all the same brightness.
310static double CalculateBoringScore(SkBitmap* bitmap) {
311 int histogram[256] = {0};
312 color_utils::BuildLumaHistogram(bitmap, histogram);
313
314 int color_count = *std::max_element(histogram, histogram + 256);
315 int pixel_count = bitmap->width() * bitmap->height();
316 return static_cast<double>(color_count) / pixel_count;
317}
318
[email protected]12bc8472010-04-15 07:29:40319// True if |frame| contains content that is white-listed for content settings.
320static bool IsWhitelistedForContentSettings(WebFrame* frame) {
321 WebSecurityOrigin origin = frame->securityOrigin();
322 if (origin.isEmpty())
323 return false; // Uninitialized document?
324
325 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
326 return true; // Browser UI elements should still work.
327
328 // If the scheme is ftp: or file:, an empty file name indicates a directory
329 // listing, which requires JavaScript to function properly.
330 GURL frame_url = frame->url();
331 const char* kDirProtocols[] = { "ftp", "file" };
332 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
333 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
334 return frame_url.SchemeIs(kDirProtocols[i]) &&
335 frame_url.ExtractFileName().empty();
336 }
337 }
338
339 return false;
340}
341
[email protected]3a8eecb2010-04-22 23:56:30342// Returns true if the frame is navigating to an URL either into or out of an
343// extension app's extent.
344static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
345 if (!RenderThread::current())
346 return false;
347
348 // If the URL is still empty, this is a window.open navigation. Check the
349 // opener's URL.
350 GURL old_url(frame->url());
351 if (old_url.is_empty() && frame->opener())
352 old_url = frame->opener()->url();
353
354 std::string old_extension =
[email protected]4fdbc1492010-07-01 01:20:59355 RenderThread::current()->GetExtensionIdByURL(old_url);
356 if (!old_extension.empty()) {
357 if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) ==
358 old_extension) {
359 return false;
360 }
361 }
362
[email protected]3a8eecb2010-04-22 23:56:30363 std::string new_extension =
[email protected]4fdbc1492010-07-01 01:20:59364 RenderThread::current()->GetExtensionIdByURL(new_url);
365 return old_extension != new_extension;
[email protected]3a8eecb2010-04-22 23:56:30366}
367
[email protected]3354d3e2010-06-10 19:53:02368// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
369// if it failed.
370//
371// Note this only works on Windows at this time. It always returns 'unknown'
372// on other platforms.
[email protected]e5106202010-06-11 21:12:36373static std::string DetermineTextLanguage(const string16& text) {
[email protected]3354d3e2010-06-10 19:53:02374 // Text with less than 100 bytes will probably not provide good results.
375 // Report it as unknown language.
376 if (text.length() < 100)
[email protected]655f97c32010-07-22 21:24:17377 return chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02378
[email protected]655f97c32010-07-22 21:24:17379 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02380 int num_languages = 0;
381 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02382 Language cld_language =
[email protected]e5106202010-06-11 21:12:36383 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]3354d3e2010-06-10 19:53:02384 &num_languages, NULL);
385 if (is_reliable && cld_language != NUM_LANGUAGES &&
386 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
387 // We should not use LanguageCode_ISO_639_1 because it does not cover all
388 // the languages CLD can detect. As a result, it'll return the invalid
389 // language code for tradtional Chinese among others.
390 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
391 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
392 // for Simplified Chinese.
393 language = LanguageCodeWithDialects(cld_language);
394 }
395 return language;
396}
397
initial.commit09911bf2008-07-26 23:55:29398///////////////////////////////////////////////////////////////////////////////
399
[email protected]60c42a8c72009-10-09 04:08:59400int32 RenderView::next_page_id_ = 1;
401
[email protected]cdaf8d02010-03-30 19:52:47402struct RenderView::PendingFileChooser {
403 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
404 WebFileChooserCompletion* c)
405 : params(p),
406 completion(c) {
407 }
408 ViewHostMsg_RunFileChooser_Params params;
409 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
410};
411
[email protected]2fab253a2009-08-17 23:00:59412RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34413 const WebPreferences& webkit_preferences,
414 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12415 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02416 webkit_preferences_(webkit_preferences),
417 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09418 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02419 send_preferred_size_changes_(false),
420 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24421 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21422 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02423 opened_by_user_gesture_(true),
424 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24425 page_id_(-1),
426 last_page_id_sent_to_browser_(-1),
427 last_indexed_page_id_(-1),
[email protected]3354d3e2010-06-10 19:53:02428 last_top_level_navigation_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00429 history_list_offset_(-1),
430 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24431 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55432#if defined(OS_MACOSX)
433 has_document_tag_(false),
434#endif
[email protected]98324892009-09-09 21:16:05435 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10436 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17437 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02438 target_url_status_(TARGET_NONE),
439 spelling_panel_visible_(false),
440 view_type_(ViewType::INVALID),
441 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18442 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]3354d3e2010-06-10 19:53:02443 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
444 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]03f57072010-07-14 17:36:08445 ALLOW_THIS_IN_INITIALIZER_LIST(password_autocomplete_manager_(this)),
[email protected]679f128f2010-07-22 22:57:44446 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_helper_(this)),
[email protected]3354d3e2010-06-10 19:53:02447 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
448 ALLOW_THIS_IN_INITIALIZER_LIST(
449 notification_provider_(new NotificationProvider(this))),
450 session_storage_namespace_id_(session_storage_namespace_id),
451 decrement_shared_popup_at_destruction_(false) {
[email protected]71b0d5d2010-02-15 05:43:07452 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29453}
454
455RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08456 if (decrement_shared_popup_at_destruction_)
457 shared_popup_counter_->data--;
458
[email protected]b0950a72009-09-29 23:16:17459 // Dispose of un-disposed image fetchers.
460 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
461 i != image_fetchers_.end(); ++i) {
462 delete *i;
463 }
464
[email protected]a1128322009-10-06 18:38:46465 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47466 while (!file_chooser_completions_.empty()) {
467 if (file_chooser_completions_.front()->completion) {
468 file_chooser_completions_.front()->completion->didChooseFile(
469 WebVector<WebString>());
470 }
471 file_chooser_completions_.pop_front();
472 }
[email protected]a1128322009-10-06 18:38:46473
[email protected]83dde542009-09-11 20:59:55474#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05475 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55476 if (has_document_tag_)
477 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
478#endif
[email protected]98324892009-09-09 21:16:05479
[email protected]5fb88962009-04-16 19:03:25480 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59481
482#ifndef NDEBUG
483 // Make sure we are no longer referenced by the ViewMap.
484 ViewMap* views = Singleton<ViewMap>::get();
485 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
486 DCHECK_NE(this, it->second) << "Failed to call Close?";
487#endif
488}
489
490/*static*/
491void RenderView::ForEach(RenderViewVisitor* visitor) {
492 ViewMap* views = Singleton<ViewMap>::get();
493 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
494 if (!visitor->Visit(it->second))
495 return;
496 }
497}
498
499/*static*/
500RenderView* RenderView::FromWebView(WebView* webview) {
501 ViewMap* views = Singleton<ViewMap>::get();
502 ViewMap::iterator it = views->find(webview);
503 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29504}
505
506/*static*/
[email protected]0aa55312008-10-17 21:53:08507RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24508 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15509 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08510 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51511 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08512 const WebPreferences& webkit_prefs,
513 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34514 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26515 int64 session_storage_namespace_id,
516 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29517 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34518 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
519 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29520 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29521 opener_id,
[email protected]80d96fa2009-06-10 22:34:51522 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08523 counter,
[email protected]8ab04652010-06-12 02:47:26524 routing_id,
525 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29526 return view;
527}
528
529/*static*/
530void RenderView::SetNextPageID(int32 next_page_id) {
531 // This method should only be called during process startup, and the given
532 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05533 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29534 DCHECK(next_page_id >= next_page_id_);
535 next_page_id_ = next_page_id;
536}
537
[email protected]4d51d5bf2010-07-26 18:48:26538WebKit::WebView* RenderView::webview() const{
539 return static_cast<WebKit::WebView*>(webwidget());
540}
541
[email protected]afe3a1672009-11-17 19:04:12542void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56543 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
544}
545
[email protected]a3a8fb6d2009-10-22 20:12:51546void RenderView::PluginCrashed(const FilePath& plugin_path) {
547 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29548}
549
[email protected]d8fd6fa2010-02-01 15:54:26550#if defined(OS_MACOSX)
551void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
552 plugin_delegates_.insert(delegate);
553}
554
555void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
556 plugin_delegates_.erase(delegate);
557}
558#endif
559
[email protected]18bcc3c2009-01-27 21:39:15560void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29561 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51562 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08563 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26564 int32 routing_id,
565 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29566 DCHECK(!webview());
567
568 if (opener_id != MSG_ROUTING_NONE)
569 opener_id_ = opener_id;
570
[email protected]0aa55312008-10-17 21:53:08571 if (counter) {
572 shared_popup_counter_ = counter;
573 shared_popup_counter_->data++;
574 decrement_shared_popup_at_destruction_ = true;
575 } else {
576 shared_popup_counter_ = new SharedRenderViewCounter(0);
577 decrement_shared_popup_at_destruction_ = false;
578 }
579
[email protected]58bfc6b2009-06-24 09:45:02580 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04581
[email protected]9a6c6232010-06-25 11:46:49582 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59583 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59584 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27585 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23586 if (!frame_name.empty())
587 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29588
[email protected]d3ba77272009-09-03 00:06:09589 OnSetRendererPrefs(renderer_prefs);
590
initial.commit09911bf2008-07-26 23:55:29591 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24592 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29593 // Take a reference on behalf of the RenderThread. This will be balanced
594 // when we receive ViewMsg_Close.
595 AddRef();
596
597 // If this is a popup, we must wait for the CreatingNew_ACK message before
598 // completing initialization. Otherwise, we can finish it now.
599 if (opener_id == MSG_ROUTING_NONE) {
600 did_show_ = true;
601 CompleteInit(parent_hwnd);
602 }
603
604 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29605
[email protected]58bfc6b2009-06-24 09:45:02606 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09607 if (command_line.HasSwitch(switches::kDomAutomationController))
608 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29609
[email protected]5fb88962009-04-16 19:03:25610 audio_message_filter_ = new AudioMessageFilter(routing_id_);
611 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29612}
613
614void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27615 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27616 if (main_frame)
617 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26618
[email protected]b2abac72009-02-26 12:39:28619 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11620 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28621 return;
[email protected]b4b967e2009-04-22 11:33:05622 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
623 return;
[email protected]b6849bda2009-10-14 23:59:26624 if (notification_provider_->OnMessageReceived(message))
625 return;
[email protected]58c321d2010-02-19 12:11:28626 if (geolocation_dispatcher_.get() &&
627 geolocation_dispatcher_->OnMessageReceived(message)) {
628 return;
629 }
[email protected]b2abac72009-02-26 12:39:28630
initial.commit09911bf2008-07-26 23:55:29631 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04632 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
633 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29634 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01635 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29636 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
637 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56638 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29639 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
640 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
641 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
642 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27643#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35644 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27645#endif
initial.commit09911bf2008-07-26 23:55:29646 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
647 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05648 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
649 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
650 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04651 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29652 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
653 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
654 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15655 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29656 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49657 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
658 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17659 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54660 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
661 OnSetContentSettingsForLoadingURL)
662 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
663 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29664 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18665 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
666 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28667 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33668 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29669 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48670 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29671 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29672 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29673 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
674 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
675 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
676 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
677 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45678 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29679 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50680 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
681 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29682 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
683 OnDragSourceSystemDragEnded)
684 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29685 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
686 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
687 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
688 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
689 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
690 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29691 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
692 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04693 IPC_MESSAGE_HANDLER(
694 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
695 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29696 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04697 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29698 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
699 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45700 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04701 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08702 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
703 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24704 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
705 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48706 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
707 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40708 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
709 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00710 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27711 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37712 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
713 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16714 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14715 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25716 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
717 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10718 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
719 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51720 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53721 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
722 OnUpdateBrowserWindowId)
723 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
724 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56725 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34726 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14727#if defined(OS_MACOSX)
728 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13729 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14730#endif
[email protected]446705872009-09-10 07:22:48731 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33732 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35733 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
734 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33735 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
736 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42737 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02738 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09739 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36740 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
741 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
742 OnAccessibilityDoDefaultAction)
[email protected]634a6f92008-12-01 21:39:31743
initial.commit09911bf2008-07-26 23:55:29744 // Have the super handle all other messages.
745 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
746 IPC_END_MESSAGE_MAP()
747}
748
[email protected]9b18a84f2010-06-10 15:54:04749void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27750 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29751 if (!main_frame)
752 return;
753
754 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45755 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29756 if (url.is_empty())
757 return;
758
759 if (size_.IsEmpty())
760 return; // Don't create an empty thumbnail!
761
762 ThumbnailScore score;
763 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02764 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15765 &thumbnail, &score))
766 return;
767
initial.commit09911bf2008-07-26 23:55:29768 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46769 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29770}
771
[email protected]9b18a84f2010-06-10 15:54:04772void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23773 SkBitmap snapshot;
774 bool error = false;
775
776 WebFrame* main_frame = webview()->mainFrame();
777 if (!main_frame)
778 error = true;
779
780 if (!error && !CaptureSnapshot(webview(), &snapshot))
781 error = true;
782
783 DCHECK(error == snapshot.empty()) <<
784 "Snapshot should be empty on error, non-empty otherwise.";
785
786 // Send the snapshot to the browser process.
787 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
788}
789
[email protected]068637222009-01-29 16:58:07790void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29791 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58792 if (webview()) {
793 // If the user has selected text in the currently focused frame we print
794 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27795 if (webview()->focusedFrame()->hasSelection())
796 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58797 else
[email protected]26aa0482009-09-30 16:55:27798 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58799 }
initial.commit09911bf2008-07-26 23:55:29800}
801
[email protected]82270452009-06-19 15:58:01802void RenderView::OnPrintingDone(int document_cookie, bool success) {
803 // Ignoring document cookie here since only one print job can be outstanding
804 // per renderer and document_cookie is 0 when printing is successful.
805 DCHECK(print_helper_.get());
806 if (print_helper_.get() != NULL) {
807 print_helper_->DidFinishPrinting(success);
808 }
809}
810
initial.commit09911bf2008-07-26 23:55:29811void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
812 if (load_id != page_id_)
813 return; // this capture call is no longer relevant due to navigation
814 if (load_id == last_indexed_page_id_)
815 return; // we already indexed this page
816
817 if (!webview())
818 return;
819
[email protected]26aa0482009-09-30 16:55:27820 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29821 if (!main_frame)
822 return;
823
824 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45825 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29826 return;
827
828 // Don't index/capture pages that failed to load. This only checks the top
829 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45830 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28831 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29832 return;
833
834 if (!preliminary_capture)
835 last_indexed_page_id_ = load_id;
836
[email protected]a8a81292010-01-21 00:32:45837 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45838 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29839 if (url.is_empty())
840 return;
841
[email protected]a8a81292010-01-21 00:32:45842 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36843 string16 contents;
initial.commit09911bf2008-07-26 23:55:29844 CaptureText(main_frame, &contents);
845 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45846 base::TimeTicks begin_time = base::TimeTicks::Now();
847 std::string language = DetermineTextLanguage(contents);
848 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
849 base::TimeTicks::Now() - begin_time);
[email protected]1c57b7b2010-07-12 17:38:10850 WebKit::WebDocument document = main_frame->document();
[email protected]a8a81292010-01-21 00:32:45851 // Send the text to the browser for indexing (the browser might decide not
852 // to index, if the URL is HTTPS for instance) and language discovery.
853 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
[email protected]1c57b7b2010-07-12 17:38:10854 language, IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27855 }
856
[email protected]9b18a84f2010-06-10 15:54:04857 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29858}
859
[email protected]e5106202010-06-11 21:12:36860void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29861 contents->clear();
862 if (!frame)
863 return;
864
865#ifdef TIME_TEXT_RETRIEVAL
866 double begin = time_util::GetHighResolutionTimeNow();
867#endif
868
869 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36870 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29871
872#ifdef TIME_TEXT_RETRIEVAL
873 double end = time_util::GetHighResolutionTimeNow();
874 char buf[128];
875 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
876 contents.size(), (end - begin)*1000);
877 OutputDebugStringA(buf);
878#endif
879
880 // When the contents are clipped to the maximum, we don't want to have a
881 // partial word indexed at the end that might have been clipped. Therefore,
882 // terminate the string at the last space to ensure no words are clipped.
883 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36884 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29885 if (last_space_index == std::wstring::npos)
886 return; // don't index if we got a huge block of text with no spaces
887 contents->resize(last_space_index);
888 }
889}
890
[email protected]8649fb32009-06-26 17:51:02891bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29892 int w,
893 int h,
894 SkBitmap* thumbnail,
895 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23896 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15897
[email protected]8649fb32009-06-26 17:51:02898 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23899
900 // Paint |view| into |canvas|.
901 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02902 return false;
[email protected]8649fb32009-06-26 17:51:02903
904 skia::BitmapPlatformDevice& device =
905 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
906
907 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29908
[email protected]cab34d6a2009-09-24 01:14:52909 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29910 float dest_aspect = dest_rect.width() / dest_rect.height();
911
912 // Get the src rect so that we can preserve the aspect ratio while filling
913 // the destination.
914 SkIRect src_rect;
915 if (src_bmp.width() < dest_rect.width() ||
916 src_bmp.height() < dest_rect.height()) {
917 // Source image is smaller: we clip the part of source image within the
918 // dest rect, and then stretch it to fill the dest rect. We don't respect
919 // the aspect ratio in this case.
920 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
921 static_cast<S16CPU>(dest_rect.height()));
922 score->good_clipping = false;
923 } else {
924 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
925 if (src_aspect > dest_aspect) {
926 // Wider than tall, clip horizontally: we center the smaller thumbnail in
927 // the wider screen.
928 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
929 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
930 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
931 score->good_clipping = false;
932 } else {
933 src_rect.set(0, 0, src_bmp.width(),
934 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
935 score->good_clipping = true;
936 }
937 }
938
[email protected]26aa0482009-09-30 16:55:27939 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29940
941 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02942 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29943
944 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14945 *thumbnail = skia::ImageOperations::Resize(
946 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29947
948 score->boring_score = CalculateBoringScore(thumbnail);
949
[email protected]30507922010-01-15 16:48:23950 HISTOGRAM_TIMES("Renderer4.Thumbnail",
951 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15952 return true;
initial.commit09911bf2008-07-26 23:55:29953}
954
[email protected]30507922010-01-15 16:48:23955bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
956 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29957
[email protected]30507922010-01-15 16:48:23958 skia::PlatformCanvas canvas;
959 if (!PaintViewIntoCanvas(view, canvas))
960 return false;
961
962 skia::BitmapPlatformDevice& device =
963 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
964
965 const SkBitmap& bitmap = device.accessBitmap(false);
966 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
967 return false;
968
969 HISTOGRAM_TIMES("Renderer4.Snapshot",
970 base::TimeTicks::Now() - beginning_time);
971 return true;
initial.commit09911bf2008-07-26 23:55:29972}
973
974void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
975 if (!webview())
976 return;
977
[email protected]3cc72b12010-03-18 23:03:00978 history_list_offset_ = params.current_history_list_offset;
979 history_list_length_ = params.current_history_list_length;
980
[email protected]8c785c62009-07-13 14:20:15981 if (devtools_agent_.get())
982 devtools_agent_->OnNavigate();
983
[email protected]422197532010-01-25 17:38:23984 if (notification_provider_.get())
985 notification_provider_->OnNavigate();
986
[email protected]a9f607e2009-10-23 19:59:27987 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26988
initial.commit09911bf2008-07-26 23:55:29989 AboutHandler::MaybeHandle(params.url);
990
[email protected]ecbf10d2010-02-18 13:03:29991 bool is_reload =
992 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
993 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29994
[email protected]26aa0482009-09-30 16:55:27995 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45996 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29997 // We cannot reload if we do not have any history state. This happens, for
998 // example, when recovering from a crash. Our workaround here is a bit of
999 // a hack since it means that reload after a crashed tab does not cause an
1000 // end-to-end cache validation.
1001 is_reload = false;
1002 }
1003
[email protected]77f17a82009-05-21 04:42:541004 // A navigation resulting from loading a javascript URL should not be treated
1005 // as a browser initiated event. Instead, we want it to look as if the page
1006 // initiated any load resulting from JS execution.
1007 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301008 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001009 params.page_id,
1010 params.pending_history_list_offset,
1011 params.transition,
1012 params.request_time);
[email protected]5e369672009-11-03 23:48:301013 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1014 // We're doing a load of a page that was restored from the last session.
1015 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1016 // which can result in stale data for pages that are set to expire. We
1017 // explicitly override that by setting the policy here so that as
1018 // necessary we load from the network.
1019 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1020 }
1021 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541022 }
initial.commit09911bf2008-07-26 23:55:291023
[email protected]a7ccc4d2010-01-27 08:14:481024 NavigationState* navigation_state = pending_navigation_state_.get();
1025
[email protected]04d3c6e2009-05-22 17:00:131026 // If we are reloading, then WebKit will use the history state of the current
1027 // page, so we should just ignore any given history state. Otherwise, if we
1028 // have history state, then we need to navigate to it, which corresponds to a
1029 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551030 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481031 if (navigation_state)
1032 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291033 bool ignore_cache = (params.navigation_type ==
1034 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1035 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551036 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131037 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581038 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481039 if (navigation_state)
1040 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451041 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171042 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131043 } else {
1044 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281045 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291046
[email protected]e6f546c32009-07-01 17:12:551047 // A session history navigation should have been accompanied by state.
1048 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131049
[email protected]dd7daa82009-08-10 05:46:451050 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551051 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131052
[email protected]726985e22009-06-18 21:09:281053 if (params.referrer.is_valid()) {
1054 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1055 WebString::fromUTF8(params.referrer.spec()));
1056 }
[email protected]04d3c6e2009-05-22 17:00:131057
[email protected]a7ccc4d2010-01-27 08:14:481058 if (navigation_state)
1059 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451060 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501061 }
1062
[email protected]77f17a82009-05-21 04:42:541063 // In case LoadRequest failed before DidCreateDataSource was called.
1064 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291065}
1066
1067// Stop loading the current page
1068void RenderView::OnStop() {
1069 if (webview())
[email protected]b4bb2502009-10-01 22:35:271070 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291071}
1072
[email protected]ecbf10d2010-02-18 13:03:291073// Reload current focused frame.
1074// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561075void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291076 if (webview() && webview()->focusedFrame()) {
1077 // We always obey the cache (ignore_cache=false) here.
1078 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1079 // a cache-ignoring reload of the frame.
1080 webview()->focusedFrame()->reload(false);
1081 }
[email protected]1dda4022010-01-28 18:24:561082}
1083
initial.commit09911bf2008-07-26 23:55:291084void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271085 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291086}
1087
[email protected]68b1e922009-06-23 16:00:251088void RenderView::OnExecuteEditCommand(const std::string& name,
1089 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271090 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251091 return;
1092
[email protected]26aa0482009-09-30 16:55:271093 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451094 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251095}
1096
[email protected]b2abac72009-02-26 12:39:281097void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111098 DCHECK(!devtools_client_.get());
1099 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281100}
1101
initial.commit09911bf2008-07-26 23:55:291102void RenderView::OnUpdateTargetURLAck() {
1103 // Check if there is a targeturl waiting to be sent.
1104 if (target_url_status_ == TARGET_PENDING) {
1105 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1106 pending_target_url_));
1107 }
1108
1109 target_url_status_ = TARGET_NONE;
1110}
1111
1112void RenderView::OnUndo() {
1113 if (!webview())
1114 return;
1115
[email protected]26aa0482009-09-30 16:55:271116 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121117 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291118}
1119
1120void RenderView::OnRedo() {
1121 if (!webview())
1122 return;
1123
[email protected]26aa0482009-09-30 16:55:271124 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121125 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291126}
1127
1128void RenderView::OnCut() {
1129 if (!webview())
1130 return;
1131
[email protected]26aa0482009-09-30 16:55:271132 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121133 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291134}
1135
1136void RenderView::OnCopy() {
1137 if (!webview())
1138 return;
1139
[email protected]26aa0482009-09-30 16:55:271140 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121141 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291142}
1143
[email protected]c0cc3092009-09-12 08:27:271144#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351145void RenderView::OnCopyToFindPboard() {
1146 if (!webview())
1147 return;
1148
1149 // Since the find pasteboard supports only plain text, this can be simpler
1150 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271151 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351152 if (frame->hasSelection()) {
1153 string16 selection = frame->selectionAsText();
1154 RenderThread::current()->Send(
1155 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1156 }
1157
[email protected]afe3a1672009-11-17 19:04:121158 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351159}
[email protected]c0cc3092009-09-12 08:27:271160#endif
[email protected]a954bf72009-09-12 07:30:351161
initial.commit09911bf2008-07-26 23:55:291162void RenderView::OnPaste() {
1163 if (!webview())
1164 return;
1165
[email protected]26aa0482009-09-30 16:55:271166 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121167 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291168}
1169
[email protected]2a3a7762009-10-19 19:17:321170void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291171 if (!webview())
1172 return;
1173
[email protected]1ff7a032010-02-03 02:46:031174 WebFrame* frame = webview()->focusedFrame();
1175 if (!frame->hasSelection())
1176 frame->selectWordAroundCaret();
1177 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291178}
1179
[email protected]98324892009-09-09 21:16:051180void RenderView::OnAdvanceToNextMisspelling() {
1181 if (!webview())
1182 return;
[email protected]26aa0482009-09-30 16:55:271183 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051184 WebString::fromUTF8("AdvanceToNextMisspelling"));
1185}
1186
1187void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1188 if (!webview())
1189 return;
1190 // We need to tell the webView whether the spelling panel is visible or not so
1191 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261192 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271193 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051194 WebString::fromUTF8("ToggleSpellPanel"));
1195}
1196
[email protected]bbbd545c2008-12-15 20:18:041197void RenderView::OnToggleSpellCheck() {
1198 if (!webview())
1199 return;
1200
[email protected]26aa0482009-09-30 16:55:271201 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451202 frame->enableContinuousSpellChecking(
1203 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041204}
1205
initial.commit09911bf2008-07-26 23:55:291206void RenderView::OnDelete() {
1207 if (!webview())
1208 return;
1209
[email protected]26aa0482009-09-30 16:55:271210 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121211 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291212}
1213
1214void RenderView::OnSelectAll() {
1215 if (!webview())
1216 return;
1217
[email protected]26aa0482009-09-30 16:55:271218 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221219 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121220 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291221}
1222
1223void RenderView::OnSetInitialFocus(bool reverse) {
1224 if (!webview())
1225 return;
[email protected]26aa0482009-09-30 16:55:271226 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291227}
1228
1229///////////////////////////////////////////////////////////////////////////////
1230
[email protected]433819d2010-01-30 20:20:011231void RenderView::SetContentSettings(const ContentSettings& settings) {
1232 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011233}
1234
initial.commit09911bf2008-07-26 23:55:291235// Tell the embedding application that the URL of the active page has changed
1236void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451237 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291238 DCHECK(ds);
1239
[email protected]726985e22009-06-18 21:09:281240 const WebURLRequest& request = ds->request();
1241 const WebURLRequest& original_request = ds->originalRequest();
1242 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291243
[email protected]daa8c58e2009-06-15 17:21:101244 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1245 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291246
1247 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281248 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291249 params.is_post = false;
1250 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281251 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551252 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291253 // SSL state specified in the request takes precedence over the one in the
1254 // response.
1255 // So far this is only intended for error pages that are not expected to be
1256 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281257 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551258 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291259 } else {
[email protected]726985e22009-06-18 21:09:281260 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291261 }
1262
1263 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281264 if (ds->hasUnreachableURL()) {
1265 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291266 } else {
[email protected]726985e22009-06-18 21:09:281267 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291268 }
1269
[email protected]726985e22009-06-18 21:09:281270 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241271 params.should_update_history = !ds->hasUnreachableURL() &&
1272 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291273
[email protected]ce0e250d2009-10-23 21:00:351274 params.searchable_form_url = navigation_state->searchable_form_url();
1275 params.searchable_form_encoding =
1276 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291277
1278 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101279 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291280 if (password_form_data)
1281 params.password_form = *password_form_data;
1282
1283 params.gesture = navigation_gesture_;
1284 navigation_gesture_ = NavigationGestureUnknown;
1285
[email protected]dd7daa82009-08-10 05:46:451286 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291287 // Top-level navigation.
1288
[email protected]71b0d5d2010-02-15 05:43:071289 // Clear "block" flags for the new page. This needs to happen before any of
1290 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1291 // so that these functions can correctly detect that a piece of content
1292 // flipped from "not blocked" to "blocked".
1293 ClearBlockedContentSettings();
1294
[email protected]62d2a112010-04-07 00:53:021295 // Set content settings. Default them from the parent window if one exists.
1296 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011297 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541298 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011299 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011300 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011301
1302 // These content settings were merely recorded transiently for this load.
1303 // We can erase them now. If at some point we reload this page, the
1304 // browser will send us new, up-to-date content settings.
1305 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401306 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101307 // The opener's view is not guaranteed to be non-null (it could be
1308 // detached from its page but not yet destructed).
1309 if (WebView* opener_view = frame->opener()->view()) {
1310 RenderView* opener = FromWebView(opener_view);
1311 SetContentSettings(opener->current_content_settings_);
1312 }
[email protected]f85f0702010-01-30 09:31:011313 }
1314
[email protected]40bd6582009-12-04 23:49:511315 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011316 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541317 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011318 if (host_zoom != host_zoom_levels_.end()) {
1319 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511320 // This zoom level was merely recorded transiently for this load. We can
1321 // erase it now. If at some point we reload this page, the browser will
1322 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011323 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511324 }
1325
initial.commit09911bf2008-07-26 23:55:291326 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551327 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291328
[email protected]daa8c58e2009-06-15 17:21:101329 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291330 if (!PageTransition::IsMainFrame(params.transition)) {
1331 // If the main frame does a load, it should not be reported as a subframe
1332 // navigation. This can occur in the following case:
1333 // 1. You're on a site with frames.
1334 // 2. You do a subframe navigation. This is stored with transition type
1335 // MANUAL_SUBFRAME.
1336 // 3. You navigate to some non-frame site, say, google.com.
1337 // 4. You navigate back to the page from step 2. Since it was initially
1338 // MANUAL_SUBFRAME, it will be that same transition type here.
1339 // We don't want that, because any navigation that changes the toplevel
1340 // frame should be tracked as a toplevel navigation (this allows us to
1341 // update the URL bar, etc).
1342 params.transition = PageTransition::LINK;
1343 }
1344
initial.commit09911bf2008-07-26 23:55:291345 // If we have a valid consumed client redirect source,
1346 // the page contained a client redirect (meta refresh, document.loc...),
1347 // so we set the referrer and transition to match.
1348 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041349 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291350 params.referrer = completed_client_redirect_src_;
1351 params.transition = static_cast<PageTransition::Type>(
1352 params.transition | PageTransition::CLIENT_REDIRECT);
1353 } else {
1354 // Bug 654101: the referrer will be empty on https->http transitions. It
1355 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281356 params.referrer = GURL(
1357 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291358 }
1359
[email protected]726985e22009-06-18 21:09:281360 string16 method = request.httpMethod();
1361 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291362 params.is_post = true;
1363
[email protected]c2a797d2009-09-21 16:46:321364 // Save some histogram data so we can compute the average memory used per
1365 // page load of the glyphs.
1366 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1367 webkit_glue::GetGlyphPageCount());
1368
[email protected]15cf526b2010-02-12 06:33:491369 // This message needs to be sent before any of allowScripts(),
1370 // allowImages(), allowPlugins() is called for the new page, so that when
1371 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1372 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291373 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1374 } else {
1375 // Subframe navigation: the type depends on whether this navigation
1376 // generated a new session history entry. When they do generate a session
1377 // history entry, it means the user initiated the navigation and we should
1378 // mark it as such. This test checks if this is the first time UpdateURL
1379 // has been called since WillNavigateToURL was called to initiate the load.
1380 if (page_id_ > last_page_id_sent_to_browser_)
1381 params.transition = PageTransition::MANUAL_SUBFRAME;
1382 else
1383 params.transition = PageTransition::AUTO_SUBFRAME;
1384
initial.commit09911bf2008-07-26 23:55:291385 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1386 }
1387
1388 last_page_id_sent_to_browser_ =
1389 std::max(last_page_id_sent_to_browser_, page_id_);
1390
1391 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101392 // we don't want the transition type to persist. Just clear it.
1393 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501394
[email protected]c7287a92009-11-04 20:06:151395 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091396 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351397 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501398 }
initial.commit09911bf2008-07-26 23:55:291399}
1400
1401// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171402void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291403 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171404 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171405 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171406 routing_id_,
1407 page_id_,
1408 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1409 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171410 }
initial.commit09911bf2008-07-26 23:55:291411}
1412
1413void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401414 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291415 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271416 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291417 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301418 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291419 last_encoding_name_ = encoding_name;
1420
[email protected]e38f40152008-09-12 23:08:301421 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291422 }
1423}
1424
[email protected]f4d34b52008-11-24 23:05:011425// Sends the previous session history state to the browser so it will be saved
1426// before we navigate to a new page. This must be called *before* the page ID
1427// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291428void RenderView::UpdateSessionHistory(WebFrame* frame) {
1429 // If we have a valid page ID at this point, then it corresponds to the page
1430 // we are navigating away from. Otherwise, this is the first navigation, so
1431 // there is no past session history to record.
1432 if (page_id_ == -1)
1433 return;
1434
[email protected]ca948a22009-06-25 19:36:171435 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271436 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171437 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291438 return;
[email protected]ca948a22009-06-25 19:36:171439
1440 Send(new ViewHostMsg_UpdateState(
1441 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291442}
1443
[email protected]3d9689372009-09-10 04:29:171444void RenderView::OpenURL(
1445 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1446 Send(new ViewHostMsg_OpenURL(
1447 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1448}
1449
[email protected]79dbc662009-09-04 05:42:511450// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291451
initial.commit09911bf2008-07-26 23:55:291452void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281453 const WebURLRequest& failed_request,
1454 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291455 const std::string& html,
1456 bool replace) {
[email protected]726985e22009-06-18 21:09:281457 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291458
1459 std::string alt_html;
1460 if (html.empty()) {
1461 // Use a local error page.
1462 int resource_id;
1463 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281464 if (error.reason == net::ERR_CACHE_MISS &&
1465 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291466 GetFormRepostErrorValues(failed_url, &error_strings);
1467 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1468 } else {
1469 GetLocalizedErrorValues(error, &error_strings);
1470 resource_id = IDR_NET_ERROR_HTML;
1471 }
initial.commit09911bf2008-07-26 23:55:291472
1473 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1474 } else {
1475 alt_html = html;
1476 }
1477
[email protected]dd7daa82009-08-10 05:46:451478 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551479 GURL(kUnreachableWebDataURL),
1480 failed_url,
1481 replace);
initial.commit09911bf2008-07-26 23:55:291482}
1483
[email protected]7ccddb8c2009-08-04 17:36:551484void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291485 dom_automation_controller_.set_message_sender(this);
1486 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551487 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291488 L"domAutomationController");
1489}
1490
initial.commit09911bf2008-07-26 23:55:291491bool RenderView::RunJavaScriptMessage(int type,
1492 const std::wstring& message,
1493 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071494 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291495 std::wstring* result) {
1496 bool success = false;
1497 std::wstring result_temp;
1498 if (!result)
1499 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291500
[email protected]12636df2009-09-28 22:32:211501 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1502 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291503 return success;
1504}
1505
[email protected]c1f50aa2010-02-18 03:46:571506bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1507 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1508 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1509 // it is particularly important that we do not call willEnterModalLoop as
1510 // that would defer resource loads for the dialog itself.
1511 if (RenderThread::current()) // Will be NULL during unit tests.
1512 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1513
1514 message->EnableMessagePumping(); // Runs a nested message loop.
1515 return Send(message);
1516}
1517
initial.commit09911bf2008-07-26 23:55:291518void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1519 if (!osd_url.is_empty())
1520 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1521 autodetected));
1522}
1523
[email protected]95056b582010-02-18 01:29:241524void RenderView::OnAutoFillSuggestionsReturned(
1525 int query_id,
[email protected]8f6e6582010-04-09 02:03:071526 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391527 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411528 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391529 const std::vector<int>& unique_ids) {
[email protected]a53e06832010-07-28 22:46:411530 autofill_helper_.SuggestionsReceived(
1531 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031532}
1533
[email protected]45c6e532010-03-15 23:51:241534void RenderView::OnAutoFillFormDataFilled(int query_id,
1535 const webkit_glue::FormData& form) {
[email protected]679f128f2010-07-22 22:57:441536 autofill_helper_.FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481537}
1538
[email protected]e8345242010-05-06 03:00:401539void RenderView::OnAllowScriptToClose(bool script_can_close) {
1540 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311541}
1542
initial.commit09911bf2008-07-26 23:55:291543uint32 RenderView::GetCPBrowsingContext() {
1544 uint32 context = 0;
1545 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1546 return context;
1547}
1548
initial.commit09911bf2008-07-26 23:55:291549void RenderView::AddSearchProvider(const std::string& url) {
1550 AddGURLSearchProvider(GURL(url),
1551 false); // not autodetected
1552}
1553
[email protected]155f35e2010-07-17 00:30:181554ViewHostMsg_GetSearchProviderInstallState_Params
1555RenderView::GetSearchProviderInstallState(const std::string& url) {
1556 GURL inquiry_url = GURL(url);
1557 if (inquiry_url.is_empty())
1558 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
1559 ViewHostMsg_GetSearchProviderInstallState_Params install;
1560 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
1561 inquiry_url,
1562 &install));
1563 return install;
1564}
1565
[email protected]f103ab72009-09-02 17:10:591566void RenderView::OnMissingPluginStatus(
1567 WebPluginDelegateProxy* delegate,
1568 int status) {
[email protected]6c8afae52009-01-22 02:24:571569#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591570 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291571 // Show the InfoBar for the first available plugin.
1572 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591573 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291574 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1575 }
1576 } else {
1577 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1578 // to start the download/install.
1579 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1580 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1581 }
1582 }
[email protected]6c8afae52009-01-22 02:24:571583#else
[email protected]76c3b312010-05-20 21:38:291584 // TODO(port): Implement the infobar that accompanies the default plugin.
1585 // Linux: http://crbug.com/10952
1586 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571587 NOTIMPLEMENTED();
1588#endif
initial.commit09911bf2008-07-26 23:55:291589}
1590
[email protected]48c9cf2d2009-09-16 16:47:521591// WebKit::WebViewClient ------------------------------------------------------
1592
[email protected]8ab04652010-06-12 02:47:261593WebView* RenderView::createView(
1594 WebFrame* creator,
1595 const WebWindowFeatures& features,
1596 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521597 // Check to make sure we aren't overloading on popups.
1598 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1599 return NULL;
1600
1601 // This window can't be closed from a window.close() call until we receive a
1602 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401603 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521604
[email protected]8ab04652010-06-12 02:47:261605 ViewHostMsg_CreateWindow_Params params;
1606 params.opener_id = routing_id_;
1607 params.user_gesture = creator->isProcessingUserGesture();
1608 params.window_container_type = WindowFeaturesToContainerType(features);
1609 params.session_storage_namespace_id = session_storage_namespace_id_;
1610 params.frame_name = frame_name;
1611
[email protected]48c9cf2d2009-09-16 16:47:521612 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341613 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261614 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521615
[email protected]48c9cf2d2009-09-16 16:47:521616 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261617 new ViewHostMsg_CreateWindow(params,
1618 &routing_id,
1619 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211620 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521621 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521622
[email protected]48c9cf2d2009-09-16 16:47:521623 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421624 0,
[email protected]12636df2009-09-28 22:32:211625 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521626 renderer_preferences_,
1627 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211628 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341629 routing_id,
[email protected]8ab04652010-06-12 02:47:261630 cloned_session_storage_namespace_id,
1631 frame_name);
1632 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521633
[email protected]007a848b2009-10-26 15:55:461634 // Record whether the creator frame is trying to suppress the opener field.
1635 view->opener_suppressed_ = opener_suppressed;
1636
[email protected]48c9cf2d2009-09-16 16:47:521637 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091638 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521639 if (!creator_url.is_valid() || !creator_url.IsStandard())
1640 creator_url = GURL();
1641 view->creator_url_ = creator_url;
1642
1643 // Copy over the alternate error page URL so we can have alt error pages in
1644 // the new render view (we don't need the browser to send the URL back down).
1645 view->alternate_error_page_url_ = alternate_error_page_url_;
1646
1647 return view->webview();
1648}
1649
[email protected]3e2b375b2010-04-07 17:03:121650WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521651 RenderWidget* widget = RenderWidget::Create(routing_id_,
1652 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121653 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521654 return widget->webwidget();
1655}
1656
1657WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1658 RenderWidget* widget = RenderWidget::Create(routing_id_,
1659 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121660 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521661 widget->ConfigureAsExternalPopupMenu(info);
1662 return widget->webwidget();
1663}
1664
[email protected]68c50e52010-05-12 11:14:391665WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341666 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391667 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291668 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1669 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1670 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341671}
1672
[email protected]48c9cf2d2009-09-16 16:47:521673void RenderView::didAddMessageToConsole(
1674 const WebConsoleMessage& message, const WebString& source_name,
1675 unsigned source_line) {
1676 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1677 UTF16ToWideHack(message.text),
1678 static_cast<int32>(source_line),
1679 UTF16ToWideHack(source_name)));
1680}
1681
1682void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581683 DCHECK(frame);
1684 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521685}
1686
[email protected]3354d3e2010-06-10 19:53:021687WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1688 return notification_provider_.get();
1689}
1690
[email protected]48c9cf2d2009-09-16 16:47:521691void RenderView::didStartLoading() {
1692 if (is_loading_) {
1693 DLOG(WARNING) << "didStartLoading called while loading";
1694 return;
1695 }
1696
1697 is_loading_ = true;
1698 // Clear the pointer so that we can assign it only when there is an unknown
1699 // plugin on a page.
1700 first_default_plugin_.reset();
1701
1702 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1703}
1704
1705void RenderView::didStopLoading() {
1706 if (!is_loading_) {
1707 DLOG(WARNING) << "DidStopLoading called while not loading";
1708 return;
1709 }
1710
1711 is_loading_ = false;
1712
1713 // NOTE: For now we're doing the safest thing, and sending out notification
1714 // when done loading. This currently isn't an issue as the favicon is only
1715 // displayed when done loading. Ideally we would send notification when
1716 // finished parsing the head, but webkit doesn't support that yet.
1717 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271718 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521719 if (!favicon_url.is_empty())
1720 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1721
[email protected]26aa0482009-09-30 16:55:271722 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521723 true); // autodetected
1724
1725 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1726
[email protected]f9f4841b2010-03-20 05:41:421727 MessageLoop::current()->PostDelayedTask(
1728 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521729 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1730 false),
1731 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521732}
1733
[email protected]f55039a2010-02-17 14:12:061734bool RenderView::isSmartInsertDeleteEnabled() {
1735#if defined(OS_MACOSX)
1736 return true;
1737#else
1738 return false;
1739#endif
1740}
1741
[email protected]04fc9482009-09-18 22:13:031742bool RenderView::isSelectTrailingWhitespaceEnabled() {
1743#if defined(OS_WIN)
1744 return true;
1745#else
1746 return false;
1747#endif
1748}
1749
[email protected]04fc9482009-09-18 22:13:031750void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031751#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031752 if (!handling_input_event_)
1753 return;
1754 // TODO(estade): investigate incremental updates to the selection so that we
1755 // don't send the entire selection over IPC every time.
1756 if (!is_empty_selection) {
1757 // Sometimes we get repeated didChangeSelection calls from webkit when
1758 // the selection hasn't actually changed. We don't want to report these
1759 // because it will cause us to continually claim the X clipboard.
1760 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271761 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031762 if (this_selection == last_selection_)
1763 return;
1764
1765 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1766 this_selection));
1767 last_selection_ = this_selection;
1768 } else {
1769 last_selection_.clear();
1770 }
1771#endif
1772}
1773
1774void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121775 const std::string& name = UTF16ToUTF8(command_name);
1776 if (StartsWithASCII(name, "Move", true) ||
1777 StartsWithASCII(name, "Insert", true) ||
1778 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031779 return;
1780 UserMetricsRecordAction(name);
1781}
1782
[email protected]03f57072010-07-14 17:36:081783void RenderView::textFieldDidBeginEditing(
1784 const WebKit::WebInputElement& element) {
1785#if defined(WEBKIT_BUG_41283_IS_FIXED)
1786 password_autocomplete_manager_.TextFieldDidBeginEditing(element);
1787#endif
1788}
1789
1790void RenderView::textFieldDidEndEditing(
1791 const WebKit::WebInputElement& element) {
1792#if defined(WEBKIT_BUG_41283_IS_FIXED)
1793 password_autocomplete_manager_.TextFieldDidEndEditing(element);
1794#endif
1795}
1796
1797void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1798#if defined(WEBKIT_BUG_41283_IS_FIXED)
1799 password_autocomplete_manager_.TextDidChangeInTextField(element);
1800#endif
1801}
1802
1803void RenderView::textFieldDidReceiveKeyDown(
1804 const WebKit::WebInputElement& element,
1805 const WebKit::WebKeyboardEvent& event) {
1806#if defined(WEBKIT_BUG_41283_IS_FIXED)
1807 password_autocomplete_manager_.TextFieldHandlingKeyDown(element, event);
1808#endif
1809}
1810
[email protected]b2528b72009-09-24 06:57:101811bool RenderView::handleCurrentKeyboardEvent() {
1812 if (edit_commands_.empty())
1813 return false;
1814
[email protected]26aa0482009-09-30 16:55:271815 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101816 if (!frame)
1817 return false;
1818
1819 EditCommands::iterator it = edit_commands_.begin();
1820 EditCommands::iterator end = edit_commands_.end();
1821
[email protected]507b33ea2009-09-29 03:56:511822 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101823 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331824 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1825 // key (but it's the exception). Once one edit command is not executed, it
1826 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101827 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1828 WebString::fromUTF8(it->value)))
1829 break;
[email protected]507b33ea2009-09-29 03:56:511830 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101831 }
1832
[email protected]507b33ea2009-09-29 03:56:511833 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101834}
1835
[email protected]2a3a7762009-10-19 19:17:321836void RenderView::spellCheck(const WebString& text,
1837 int& misspelled_offset,
1838 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561839 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461840
[email protected]85c55dc2009-11-06 03:05:461841 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171842 RenderThread* thread = RenderThread::current();
1843 // Will be NULL during unit tests.
1844 if (thread) {
[email protected]c27324b2009-11-19 22:44:291845 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171846 word.c_str(), word.size(), document_tag_,
1847 &misspelled_offset, &misspelled_length, NULL);
1848 }
[email protected]1dbafaf72009-09-23 19:43:561849}
1850
1851WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321852 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561853 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261854 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561855 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171856 RenderThread* thread = RenderThread::current();
1857 // Will be NULL during unit tests.
1858 if (thread) {
1859 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291860 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171861 word, document_tag_);
1862 }
[email protected]1dbafaf72009-09-23 19:43:561863 }
[email protected]2a3a7762009-10-19 19:17:321864 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561865}
1866
[email protected]c49085c72009-10-02 16:28:561867void RenderView::showSpellingUI(bool show) {
1868 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1869}
1870
[email protected]8922e1f2009-10-03 05:01:261871bool RenderView::isShowingSpellingUI() {
1872 return spelling_panel_visible_;
1873}
1874
[email protected]1dbafaf72009-09-23 19:43:561875void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321876 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1877 word));
[email protected]1dbafaf72009-09-23 19:43:561878}
1879
[email protected]a1128322009-10-06 18:38:461880bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351881 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471882 WebFileChooserCompletion* chooser_completion) {
1883 ViewHostMsg_RunFileChooser_Params ipc_params;
1884 ipc_params.mode = params.multiSelect ?
1885 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1886 ViewHostMsg_RunFileChooser_Params::Open;
1887 ipc_params.title = params.title;
1888 ipc_params.default_file_name =
1889 webkit_glue::WebStringToFilePath(params.initialValue);
1890
1891 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461892}
1893
[email protected]48c9cf2d2009-09-16 16:47:521894void RenderView::runModalAlertDialog(
1895 WebFrame* frame, const WebString& message) {
1896 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1897 UTF16ToWideHack(message),
1898 std::wstring(),
1899 frame->url(),
1900 NULL);
1901}
1902
1903bool RenderView::runModalConfirmDialog(
1904 WebFrame* frame, const WebString& message) {
1905 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1906 UTF16ToWideHack(message),
1907 std::wstring(),
1908 frame->url(),
1909 NULL);
1910}
1911
1912bool RenderView::runModalPromptDialog(
1913 WebFrame* frame, const WebString& message, const WebString& default_value,
1914 WebString* actual_value) {
1915 std::wstring result;
1916 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1917 UTF16ToWideHack(message),
1918 UTF16ToWideHack(default_value),
1919 frame->url(),
1920 &result);
1921 if (ok)
1922 actual_value->assign(WideToUTF16Hack(result));
1923 return ok;
1924}
1925
1926bool RenderView::runModalBeforeUnloadDialog(
1927 WebFrame* frame, const WebString& message) {
1928 bool success = false;
1929 // This is an ignored return value, but is included so we can accept the same
1930 // response as RunJavaScriptMessage.
1931 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211932 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521933 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211934 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521935 return success;
1936}
1937
[email protected]79e37442009-10-09 18:17:441938void RenderView::showContextMenu(
1939 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291940 ContextMenuParams params = ContextMenuParams(data);
1941 if (!params.misspelled_word.empty() && RenderThread::current()) {
1942 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041943 bool spelled_right = RenderThread::current()->spellchecker()->
1944 SpellCheckWord(
1945 params.misspelled_word.c_str(), params.misspelled_word.size(),
1946 document_tag_,
1947 &misspelled_offset, &misspelled_length,
1948 &params.dictionary_suggestions);
1949 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291950 params.misspelled_word.clear();
1951 }
1952
1953 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441954}
1955
[email protected]52f139e2c2010-06-11 16:56:091956bool RenderView::supportsFullscreen() {
1957 return CommandLine::ForCurrentProcess()->HasSwitch(
1958 switches::kEnableVideoFullscreen);
1959}
1960
1961void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1962 NOTIMPLEMENTED();
1963}
1964
1965void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1966 NOTIMPLEMENTED();
1967}
1968
[email protected]48c9cf2d2009-09-16 16:47:521969void RenderView::setStatusText(const WebString& text) {
1970}
1971
[email protected]163f8242009-10-30 20:19:551972void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581973 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521974 if (latest_url == target_url_)
1975 return;
[email protected]163f8242009-10-30 20:19:551976
[email protected]48c9cf2d2009-09-16 16:47:521977 // Tell the browser to display a destination link.
1978 if (target_url_status_ == TARGET_INFLIGHT ||
1979 target_url_status_ == TARGET_PENDING) {
1980 // If we have a request in-flight, save the URL to be sent when we
1981 // receive an ACK to the in-flight request. We can happily overwrite
1982 // any existing pending sends.
1983 pending_target_url_ = latest_url;
1984 target_url_status_ = TARGET_PENDING;
1985 } else {
1986 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1987 target_url_ = latest_url;
1988 target_url_status_ = TARGET_INFLIGHT;
1989 }
1990}
1991
[email protected]1c57b7b2010-07-12 17:38:101992bool RenderView::IsPageTranslatable(WebKit::WebDocument* document) {
1993 std::vector<WebKit::WebElement> meta_elements;
1994 webkit_glue::GetMetaElementsWithName(document, ASCIIToUTF16("google"),
1995 &meta_elements);
1996 std::vector<WebKit::WebElement>::const_iterator iter;
1997 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) {
1998 WebString attribute = iter->getAttribute("value");
1999 if (attribute.isNull()) // We support both 'value' and 'content'.
2000 attribute = iter->getAttribute("content");
2001 if (attribute.isNull())
2002 continue;
2003 if (LowerCaseEqualsASCII(attribute, "notranslate"))
2004 return false;
2005 }
2006 return true;
2007}
2008
[email protected]882daa92009-11-05 16:31:312009void RenderView::StartNavStateSyncTimerIfNecessary() {
2010 int delay;
2011 if (send_content_state_immediately_)
2012 delay = 0;
2013 else if (is_hidden())
2014 delay = kDelaySecondsForContentStateSyncHidden;
2015 else
2016 delay = kDelaySecondsForContentStateSync;
2017
2018 if (nav_state_sync_timer_.IsRunning()) {
2019 // The timer is already running. If the delay of the timer maches the amount
2020 // we want to delay by, then return. Otherwise stop the timer so that it
2021 // gets started with the right delay.
2022 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2023 return;
2024 nav_state_sync_timer_.Stop();
2025 }
2026
2027 nav_state_sync_timer_.Start(
2028 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2029}
2030
[email protected]163f8242009-10-30 20:19:552031void RenderView::setMouseOverURL(const WebURL& url) {
2032 mouse_over_url_ = GURL(url);
2033 UpdateTargetURL(mouse_over_url_, focus_url_);
2034}
2035
2036void RenderView::setKeyboardFocusURL(const WebURL& url) {
2037 focus_url_ = GURL(url);
2038 UpdateTargetURL(focus_url_, mouse_over_url_);
2039}
2040
[email protected]48c9cf2d2009-09-16 16:47:522041void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2042 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2043 hint));
2044}
2045
[email protected]c27ae592010-03-18 15:24:412046void RenderView::startDragging(const WebDragData& data,
2047 WebDragOperationsMask mask,
2048 const WebImage& image,
2049 const WebPoint& imageOffset) {
2050#if WEBKIT_USING_SKIA
2051 SkBitmap bitmap(image.getSkBitmap());
2052#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332053 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412054#endif
2055
[email protected]48c9cf2d2009-09-16 16:47:522056 Send(new ViewHostMsg_StartDragging(routing_id_,
2057 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412058 mask,
2059 bitmap,
2060 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522061}
2062
[email protected]28b92df2009-09-25 17:35:452063bool RenderView::acceptsLoadDrops() {
2064 return renderer_preferences_.can_accept_load_drops;
2065}
2066
[email protected]48c9cf2d2009-09-16 16:47:522067void RenderView::focusNext() {
2068 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2069}
2070
2071void RenderView::focusPrevious() {
2072 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2073}
2074
[email protected]08e9e132010-06-01 16:58:492075void RenderView::focusedNodeChanged(const WebNode& node) {
2076 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2077}
2078
[email protected]48c9cf2d2009-09-16 16:47:522079void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522080 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2081}
2082
2083int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002084 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522085}
2086
2087int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002088 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522089}
2090
[email protected]c4e98902010-06-01 10:20:142091void RenderView::didUpdateInspectorSetting(const WebString& key,
2092 const WebString& value) {
2093 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2094 key.utf8(),
2095 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262096}
2097
[email protected]acca2a1f2009-10-16 03:53:392098void RenderView::queryAutofillSuggestions(const WebNode& node,
2099 const WebString& name,
2100 const WebString& value) {
[email protected]679f128f2010-07-22 22:57:442101 autofill_helper_.QueryAutocompleteSuggestions(node, name, value);
[email protected]acca2a1f2009-10-16 03:53:392102}
2103
2104void RenderView::removeAutofillSuggestions(const WebString& name,
2105 const WebString& value) {
[email protected]679f128f2010-07-22 22:57:442106 autofill_helper_.RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a1f2009-10-16 03:53:392107}
2108
[email protected]18ca9a6b2010-06-02 19:05:182109void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2110 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202111 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392112 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202113 unsigned index) {
[email protected]679f128f2010-07-22 22:57:442114 autofill_helper_.DidAcceptAutoFillSuggestion(node, value, label, unique_id,
2115 index);
[email protected]18ca9a6b2010-06-02 19:05:182116}
[email protected]c83641732010-02-20 01:04:482117
[email protected]18ca9a6b2010-06-02 19:05:182118void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2119 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392120 const WebKit::WebString& label,
2121 int unique_id) {
[email protected]679f128f2010-07-22 22:57:442122 autofill_helper_.DidSelectAutoFillSuggestion(node, value, label, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182123}
2124
2125void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]679f128f2010-07-22 22:57:442126 autofill_helper_.DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482127}
2128
[email protected]03f57072010-07-14 17:36:082129void RenderView::didAcceptAutocompleteSuggestion(
2130 const WebKit::WebInputElement& user_element) {
2131#if defined(WEBKIT_BUG_41283_IS_FIXED)
2132 bool result = password_autocomplete_manager_.FillPassword(user_element);
2133 // Since this user name was selected from a suggestion list, we should always
2134 // have password for it.
2135 DCHECK(result);
2136#endif
2137}
2138
[email protected]79dbc662009-09-04 05:42:512139// WebKit::WebWidgetClient ----------------------------------------------------
2140
initial.commit09911bf2008-07-26 23:55:292141// We are supposed to get a single call to Show for a newly created RenderView
2142// that was created via RenderView::CreateWebView. So, we wait until this
2143// point to dispatch the ShowView message.
2144//
2145// This method provides us with the information about how to display the newly
2146// created RenderView (i.e., as a constrained popup or as a new tab).
2147//
[email protected]4873c7d2009-07-16 06:36:282148void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292149 DCHECK(!did_show_) << "received extraneous Show call";
2150 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2151
2152 if (did_show_)
2153 return;
2154 did_show_ = true;
2155
[email protected]28295ec2009-10-16 05:34:332156 // Force new windows to a popup if they were not opened with a user gesture.
2157 if (!opened_by_user_gesture_) {
2158 // We exempt background tabs for compat with older versions of Chrome.
2159 // TODO(darin): This seems bogus. These should have a user gesture, so
2160 // we probably don't need this check.
2161 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2162 policy = WebKit::WebNavigationPolicyNewPopup;
2163 }
2164
initial.commit09911bf2008-07-26 23:55:292165 // NOTE: initial_pos_ may still have its default values at this point, but
2166 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2167 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282168 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2169 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292170 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242171 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292172}
2173
[email protected]4873c7d2009-07-16 06:36:282174void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132175 // Cancel pending translations so that the translate_helper_ does not attempt
2176 // to access the WebView.
2177 translate_helper_.CancelPendingTranslation();
2178
[email protected]e8345242010-05-06 03:00:402179 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282180 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312181}
2182
[email protected]4873c7d2009-07-16 06:36:282183void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292184 DCHECK(did_show_) << "should already have shown the view";
2185
[email protected]c1f50aa2010-02-18 03:46:572186 // We must keep WebKit's shared timer running in this case in order to allow
2187 // showModalDialog to function properly.
2188 //
2189 // TODO(darin): WebKit should really be smarter about suppressing events and
2190 // timers so that we do not need to manage the shared timer in such a heavy
2191 // handed manner.
2192 //
2193 if (RenderThread::current()) // Will be NULL during unit tests.
2194 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2195
[email protected]12636df2009-09-28 22:32:212196 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292197}
2198
[email protected]3d9689372009-09-10 04:29:172199// WebKit::WebFrameClient -----------------------------------------------------
2200
[email protected]00152e92010-07-19 11:47:402201WebPlugin* RenderView::createPlugin(WebFrame* frame,
2202 const WebPluginParams& params) {
[email protected]0cdafff2010-07-26 09:54:372203 FilePath path;
2204 std::string actual_mime_type;
2205 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2206 params.url, frame->top()->url(), params.mimeType.utf8(), &path,
2207 &actual_mime_type));
2208 if (path.value().empty())
2209 return NULL;
[email protected]4e0616e2010-05-28 14:55:532210
[email protected]d5f9e4f2010-07-28 08:31:302211 if (CommandLine::ForCurrentProcess()->HasSwitch(
2212 switches::kEnableClickToPlay)) {
2213 if (!AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS) &&
2214 path.value() != kDefaultPluginLibraryName) {
2215 didNotAllowPlugins(frame);
2216 return CreatePluginPlaceholder(frame, params);
2217 }
[email protected]0cdafff2010-07-26 09:54:372218 }
2219 return CreatePluginInternal(frame, params, actual_mime_type, path);
[email protected]3d9689372009-09-10 04:29:172220}
2221
2222WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562223 WebApplicationCacheHostImpl* appcache_host =
2224 WebApplicationCacheHostImpl::FromFrame(frame);
2225 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2226 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2227 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172228}
2229
[email protected]9c00f002009-11-05 22:37:422230WebSharedWorker* RenderView::createSharedWorker(
2231 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372232 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422233
[email protected]30447b62009-11-13 01:13:372234 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512235 bool exists = false;
[email protected]30447b62009-11-13 01:13:372236 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512237 ViewHostMsg_CreateWorker_Params params;
2238 params.url = url;
2239 params.is_shared = true;
2240 params.name = name;
2241 params.document_id = document_id;
2242 params.render_view_route_id = routing_id_;
2243 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232244 params.parent_appcache_host_id = 0;
2245 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372246 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512247 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372248 if (url_mismatch) {
2249 return NULL;
2250 } else {
2251 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492252 document_id,
[email protected]6de0bcf2010-02-17 22:00:512253 exists,
[email protected]30447b62009-11-13 01:13:372254 route_id,
2255 routing_id_);
2256 }
[email protected]9c00f002009-11-05 22:37:422257}
2258
[email protected]3d9689372009-09-10 04:29:172259WebMediaPlayer* RenderView::createMediaPlayer(
2260 WebFrame* frame, WebMediaPlayerClient* client) {
2261 scoped_refptr<media::FilterFactoryCollection> factory =
2262 new media::FilterFactoryCollection();
2263 // Add in any custom filter factories first.
2264 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2265 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2266 // Add the chrome specific audio renderer.
2267 factory->AddFactory(
2268 AudioRendererImpl::CreateFactory(audio_message_filter()));
2269 }
2270
[email protected]80f584d92010-01-21 03:59:042271 WebApplicationCacheHostImpl* appcache_host =
2272 WebApplicationCacheHostImpl::FromFrame(frame);
2273
[email protected]3d9689372009-09-10 04:29:172274 // TODO(hclam): obtain the following parameters from |client|.
2275 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2276 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152277 GURL(), // referrer
2278 "null", // frame origin
2279 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172280 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042281 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172282 routing_id());
2283
[email protected]0436b9a2009-10-23 00:23:052284 // A simple data source that keeps all data in memory.
2285 media::FilterFactory* simple_data_source_factory =
2286 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2287 bridge_factory);
2288 // A sophisticated data source that does memory caching.
2289 media::FilterFactory* buffered_data_source_factory =
2290 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2291 bridge_factory);
2292 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2293 factory->AddFactory(simple_data_source_factory);
2294 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172295 } else {
[email protected]0436b9a2009-10-23 00:23:052296 factory->AddFactory(buffered_data_source_factory);
2297 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172298 }
[email protected]8400e032010-02-26 18:50:112299
2300 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2301 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2302 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2303 } else {
[email protected]b57509eb2010-03-30 01:26:282304 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2305 factory_factory =
2306 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112307 }
2308
2309 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172310}
2311
[email protected]035545f2010-04-09 13:10:212312WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2313 WebFrame* frame, WebApplicationCacheHostClient* client) {
2314 return new RendererWebApplicationCacheHostImpl(
2315 FromWebView(frame->view()), client,
2316 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2317}
2318
[email protected]b921cfd22010-02-25 16:57:512319WebCookieJar* RenderView::cookieJar() {
2320 return &cookie_jar_;
2321}
2322
[email protected]3d9689372009-09-10 04:29:172323void RenderView::willClose(WebFrame* frame) {
2324 if (!frame->parent()) {
2325 const GURL& url = frame->url();
2326 if (url.SchemeIs("http") || url.SchemeIs("https"))
2327 DumpLoadHistograms();
2328 }
[email protected]fa7b6b542009-11-03 05:02:302329
2330 WebDataSource* ds = frame->dataSource();
2331 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2332 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162333
[email protected]679f128f2010-07-22 22:57:442334 autofill_helper_.FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172335}
2336
[email protected]684e4a42010-01-30 06:44:112337bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402338 if (enabled_per_settings &&
2339 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2340 return true;
2341
2342 if (IsWhitelistedForContentSettings(frame))
2343 return true;
2344
2345 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2346 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112347}
2348
[email protected]d5f9e4f2010-07-28 08:31:302349bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
2350 if (CommandLine::ForCurrentProcess()->HasSwitch(
2351 switches::kEnableClickToPlay)) {
2352 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
2353 }
2354 return (enabled_per_settings &&
2355 AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS));
2356}
2357
2358
[email protected]3d9689372009-09-10 04:29:172359void RenderView::loadURLExternally(
2360 WebFrame* frame, const WebURLRequest& request,
2361 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592362 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2363 if (policy == WebKit::WebNavigationPolicyDownload) {
2364 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2365 } else {
2366 OpenURL(request.url(), referrer, policy);
2367 }
[email protected]3d9689372009-09-10 04:29:172368}
2369
2370WebNavigationPolicy RenderView::decidePolicyForNavigation(
2371 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222372 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172373 // Webkit is asking whether to navigate to a new URL.
2374 // This is fine normally, except if we're showing UI from one security
2375 // context and they're trying to navigate to a different context.
2376 const GURL& url = request.url();
2377
2378 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302379 // navigations.
[email protected]8079b362010-05-07 18:37:452380 if (renderer_preferences_.browser_handles_top_level_requests &&
2381 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192382 last_top_level_navigation_page_id_ = page_id_;
2383 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2384 OpenURL(url, referrer, default_policy);
2385 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172386 }
2387
2388 // A content initiated navigation may have originated from a link-click,
2389 // script, drag-n-drop operation, etc.
2390 bool is_content_initiated =
2391 NavigationState::FromDataSource(frame->provisionalDataSource())->
2392 is_content_initiated();
2393
2394 // We only care about navigations that are within the current tab (as opposed
2395 // to, for example, opening a new window).
2396 // But we sometimes navigate to about:blank to clear a tab, and we want to
2397 // still allow that.
2398 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2399 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532400 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172401 !url.SchemeIs(chrome::kAboutScheme)) {
2402 // When we received such unsolicited navigations, we sometimes want to
2403 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302404 if (CrossesExtensionExtents(frame, url) ||
2405 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172406 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422407 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172408 OpenURL(url, GURL(), default_policy);
2409 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2410 }
[email protected]8079b362010-05-07 18:37:452411
2412 // We forward navigations from extensions to the browser if they are
2413 // top-level events, even if the browser hasn't expressed interest.
2414 //
2415 // Note that we've already forwarded cross-extension extents navigations
2416 // above.
2417 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]c240ace2010-06-16 18:31:532418 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]8079b362010-05-07 18:37:452419 OpenURL(url, GURL(), default_policy);
2420 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2421 }
[email protected]3d9689372009-09-10 04:29:172422 }
2423
2424 // Detect when a page is "forking" a new tab that can be safely rendered in
2425 // its own process. This is done by sites like Gmail that try to open links
2426 // in new windows without script connections back to the original page. We
2427 // treat such cases as browser navigations (in which we will create a new
2428 // renderer for a cross-site navigation), rather than WebKit navigations.
2429 //
2430 // We use the following heuristic to decide whether to fork a new page in its
2431 // own process:
2432 // The parent page must open a new tab to about:blank, set the new tab's
2433 // window.opener to null, and then redirect the tab to a cross-site URL using
2434 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462435 //
2436 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2437 // (see below).
[email protected]3d9689372009-09-10 04:29:172438 bool is_fork =
2439 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252440 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172441 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522442 historyBackListCount() < 1 &&
2443 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172444 // The parent page must have set the child's window.opener to null before
2445 // redirecting to the desired URL.
2446 frame->opener() == NULL &&
2447 // Must be a top-level frame.
2448 frame->parent() == NULL &&
2449 // Must not have issued the request from this page.
2450 is_content_initiated &&
2451 // Must be targeted at the current tab.
2452 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2453 // Must be a JavaScript navigation, which appears as "other".
2454 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462455
2456 // Recognize if this navigation is from a link with rel=noreferrer and
2457 // target=_blank attributes, in which case the opener will be suppressed. If
2458 // so, it is safe to load cross-site pages in a separate process, so we
2459 // should let the browser handle it.
2460 bool is_noreferrer_and_blank_target =
2461 // Frame should be top level and not yet navigated.
2462 frame->parent() == NULL &&
2463 frame->url().isEmpty() &&
2464 historyBackListCount() < 1 &&
2465 historyForwardListCount() < 1 &&
2466 // Links with rel=noreferrer will have no Referer field, and their
2467 // resulting frame will have its window.opener suppressed.
2468 // TODO(creis): should add a request.httpReferrer() method to help avoid
2469 // typos on the unusual spelling of Referer.
2470 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2471 opener_suppressed_ &&
2472 frame->opener() == NULL &&
2473 // Links with target=_blank will have no name.
2474 frame->name().isNull() &&
2475 // Another frame (with a non-empty creator) should have initiated the
2476 // request, targeted at this frame.
2477 !creator_url_.is_empty() &&
2478 is_content_initiated &&
2479 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2480 type == WebKit::WebNavigationTypeOther;
2481
2482 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172483 // Open the URL via the browser, not via WebKit.
2484 OpenURL(url, GURL(), default_policy);
2485 return WebKit::WebNavigationPolicyIgnore;
2486 }
2487
2488 return default_policy;
2489}
2490
[email protected]6069da8c2009-10-20 20:33:492491bool RenderView::canHandleRequest(
2492 WebFrame* frame, const WebURLRequest& request) {
2493 // We allow WebKit to think that everything can be handled even though
2494 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342495 return true;
2496}
2497
[email protected]6069da8c2009-10-20 20:33:492498WebURLError RenderView::cannotHandleRequestError(
2499 WebFrame* frame, const WebURLRequest& request) {
2500 NOTREACHED(); // Since we said we can handle all requests.
2501 return WebURLError();
2502}
2503
2504WebURLError RenderView::cancelledError(
2505 WebFrame* frame, const WebURLRequest& request) {
2506 WebURLError error;
2507 error.domain = WebString::fromUTF8(net::kErrorDomain);
2508 error.reason = net::ERR_ABORTED;
2509 error.unreachableURL = request.url();
2510 return error;
[email protected]7b7a7dc2009-10-19 02:23:342511}
2512
2513void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492514 WebFrame*, const WebURLError&) {
2515 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342516}
2517
[email protected]90eeddb2010-05-06 21:06:432518void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2519 const WebKit::WebFormElement& form) {
2520 // Some login forms have onSubmit handlers that put a hash of the password
2521 // into a hidden field and then clear the password. (Issue 28910.)
2522 // This method gets called before any of those handlers run, so save away
2523 // a copy of the password in case it gets lost.
2524 NavigationState* navigation_state =
2525 NavigationState::FromDataSource(frame->dataSource());
2526 navigation_state->set_password_form_data(
2527 PasswordFormDomManager::CreatePasswordForm(form));
2528}
2529
[email protected]979c28b2009-11-07 01:30:482530void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172531 NavigationState* navigation_state =
2532 NavigationState::FromDataSource(frame->provisionalDataSource());
2533
2534 if (navigation_state->transition_type() == PageTransition::LINK)
2535 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2536
2537 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352538 WebSearchableFormData web_searchable_form_data(form);
2539 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2540 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212541 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432542 PasswordForm* password_form_data =
2543 PasswordFormDomManager::CreatePasswordForm(form);
2544 navigation_state->set_password_form_data(password_form_data);
2545
2546 // If the password has been cleared, recover it from the form contents already
2547 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2548 // opposed to the provisionalDataSource's, which is what we're storing into
2549 // now.)
2550 if (password_form_data && password_form_data->password_value.empty()) {
2551 NavigationState* old_navigation_state =
2552 NavigationState::FromDataSource(frame->dataSource());
2553 if (old_navigation_state) {
2554 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2555 if (old_form_data && old_form_data->action == password_form_data->action)
2556 password_form_data->password_value = old_form_data->password_value;
2557 }
2558 }
[email protected]3d9689372009-09-10 04:29:172559
[email protected]b1438212010-04-03 00:30:592560 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042561 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092562 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592563 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172564}
2565
2566void RenderView::willPerformClientRedirect(
2567 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2568 double fire_time) {
2569 // Ignore
2570}
2571
2572void RenderView::didCancelClientRedirect(WebFrame* frame) {
2573 // Ignore
2574}
2575
2576void RenderView::didCompleteClientRedirect(
2577 WebFrame* frame, const WebURL& from) {
2578 if (!frame->parent())
2579 completed_client_redirect_src_ = from;
2580}
2581
2582void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2583 // The rest of RenderView assumes that a WebDataSource will always have a
2584 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482585 bool content_initiated = !pending_navigation_state_.get();
2586 NavigationState* state = content_initiated ?
2587 NavigationState::CreateContentInitiated() :
2588 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182589 if (content_initiated) {
2590 switch (ds->request().cachePolicy()) {
2591 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2592 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2593 break;
2594 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2595 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2596 break;
2597 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2598 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2599 break;
2600 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2601 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2602 break;
2603 }
2604 }
[email protected]fa7b6b542009-11-03 05:02:302605
2606 state->set_user_script_idle_scheduler(
2607 new UserScriptIdleScheduler(this, frame));
2608 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172609}
2610
2611void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2612 WebDataSource* ds = frame->provisionalDataSource();
2613 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2614
2615 navigation_state->set_start_load_time(Time::Now());
2616
2617 // Update the request time if WebKit has better knowledge of it.
2618 if (navigation_state->request_time().is_null()) {
2619 double event_time = ds->triggeringEventTime();
2620 if (event_time != 0.0)
2621 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2622 }
2623
2624 bool is_top_most = !frame->parent();
2625 if (is_top_most) {
2626 navigation_gesture_ = frame->isProcessingUserGesture() ?
2627 NavigationGestureUnknown : NavigationGestureAuto;
2628
2629 // Make sure redirect tracking state is clear for the new load.
2630 completed_client_redirect_src_ = GURL();
2631 } else if (frame->parent()->isLoading()) {
2632 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002633 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172634 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2635 }
2636
2637 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2638 routing_id_, is_top_most, ds->request().url()));
2639}
2640
2641void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2642 if (frame->parent())
2643 return;
2644 // Received a redirect on the main frame.
2645 WebDataSource* data_source = frame->provisionalDataSource();
2646 if (!data_source) {
2647 // Should only be invoked when we have a data source.
2648 NOTREACHED();
2649 return;
2650 }
2651 std::vector<GURL> redirects;
2652 GetRedirectChain(data_source, &redirects);
2653 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512654 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2655 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172656 }
2657}
2658
[email protected]40bd6582009-12-04 23:49:512659void RenderView::didFailProvisionalLoad(WebFrame* frame,
2660 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172661 // Notify the browser that we failed a provisional load with an error.
2662 //
2663 // Note: It is important this notification occur before DidStopLoading so the
2664 // SSL manager can react to the provisional load failure before being
2665 // notified the load stopped.
2666 //
2667 WebDataSource* ds = frame->provisionalDataSource();
2668 DCHECK(ds);
2669
2670 const WebURLRequest& failed_request = ds->request();
2671
2672 bool show_repost_interstitial =
2673 (error.reason == net::ERR_CACHE_MISS &&
2674 EqualsASCII(failed_request.httpMethod(), "POST"));
2675 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2676 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2677 show_repost_interstitial));
2678
2679 // Don't display an error page if this is simply a cancelled load. Aside
2680 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2681 if (error.reason == net::ERR_ABORTED)
2682 return;
2683
2684 // Make sure we never show errors in view source mode.
2685 frame->enableViewSourceMode(false);
2686
2687 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2688
2689 // If this is a failed back/forward/reload navigation, then we need to do a
2690 // 'replace' load. This is necessary to avoid messing up session history.
2691 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2692 // as session history is concerned.
2693 //
2694 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2695 // the page id.
2696 //
2697 bool replace =
2698 navigation_state->pending_page_id() != -1 ||
2699 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2700
2701 // If we failed on a browser initiated request, then make sure that our error
2702 // page load is regarded as the same browser initiated request.
2703 if (!navigation_state->is_content_initiated()) {
2704 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2705 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002706 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172707 navigation_state->transition_type(),
2708 navigation_state->request_time()));
2709 }
2710
2711 // Provide the user with a more helpful error page?
2712 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2713 return;
2714
2715 // Fallback to a local error page.
2716 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2717 replace);
2718}
2719
2720void RenderView::didReceiveDocumentData(
2721 WebFrame* frame, const char* data, size_t data_len,
2722 bool& prevent_default) {
2723 NavigationState* navigation_state =
2724 NavigationState::FromDataSource(frame->dataSource());
2725 if (!navigation_state->postpone_loading_data())
2726 return;
2727
2728 // We're going to call commitDocumentData ourselves...
2729 prevent_default = true;
2730
2731 // Continue buffering the response data for the original 404 page. If it
2732 // grows too large, then we'll just let it through.
2733 navigation_state->append_postponed_data(data, data_len);
2734 if (navigation_state->postponed_data().size() >= 512) {
2735 navigation_state->set_postpone_loading_data(false);
2736 frame->commitDocumentData(navigation_state->postponed_data().data(),
2737 navigation_state->postponed_data().size());
2738 navigation_state->clear_postponed_data();
2739 }
2740}
2741
[email protected]40bd6582009-12-04 23:49:512742void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2743 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172744 NavigationState* navigation_state =
2745 NavigationState::FromDataSource(frame->dataSource());
2746
2747 navigation_state->set_commit_load_time(Time::Now());
2748 if (is_new_navigation) {
2749 // When we perform a new navigation, we need to update the previous session
2750 // history entry with state for the page we are leaving.
2751 UpdateSessionHistory(frame);
2752
2753 // We bump our Page ID to correspond with the new session history entry.
2754 page_id_ = next_page_id_++;
2755
[email protected]d64b07b2010-04-20 22:14:062756 // Any pending translation is now obsolete.
2757 translate_helper_.CancelPendingTranslation();
2758
[email protected]3cc72b12010-03-18 23:03:002759 // Advance our offset in session history, applying the length limit. There
2760 // is now no forward history.
2761 history_list_offset_++;
2762 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2763 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2764 history_list_length_ = history_list_offset_ + 1;
2765
[email protected]f9f4841b2010-03-20 05:41:422766 MessageLoop::current()->PostDelayedTask(
2767 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172768 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2769 page_id_, true),
2770 kDelayForForcedCaptureMs);
2771 } else {
2772 // Inspect the navigation_state on this frame to see if the navigation
2773 // corresponds to a session history navigation... Note: |frame| may or
2774 // may not be the toplevel frame, but for the case of capturing session
2775 // history, the first committed frame suffices. We keep track of whether
2776 // we've seen this commit before so that only capture session history once
2777 // per navigation.
2778 //
2779 // Note that we need to check if the page ID changed. In the case of a
2780 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2781 // previous URL and the current page ID, which would be wrong.
2782 if (navigation_state->pending_page_id() != -1 &&
2783 navigation_state->pending_page_id() != page_id_ &&
2784 !navigation_state->request_committed()) {
2785 // This is a successful session history navigation!
2786 UpdateSessionHistory(frame);
2787 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002788
2789 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172790 }
2791 }
2792
2793 // Remember that we've already processed this request, so we don't update
2794 // the session history again. We do this regardless of whether this is
2795 // a session history navigation, because if we attempted a session history
2796 // navigation without valid HistoryItem state, WebCore will think it is a
2797 // new navigation.
2798 navigation_state->set_request_committed(true);
2799
2800 UpdateURL(frame);
2801
2802 // If this committed load was initiated by a client redirect, we're
2803 // at the last stop now, so clear it.
2804 completed_client_redirect_src_ = GURL();
2805
2806 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272807 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172808}
2809
2810void RenderView::didClearWindowObject(WebFrame* frame) {
2811 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2812 BindDOMAutomationController(frame);
2813 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2814 dom_ui_bindings_.set_message_sender(this);
2815 dom_ui_bindings_.set_routing_id(routing_id_);
2816 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2817 }
2818 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2819 external_host_bindings_.set_message_sender(this);
2820 external_host_bindings_.set_routing_id(routing_id_);
2821 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2822 }
2823}
2824
2825void RenderView::didCreateDocumentElement(WebFrame* frame) {
2826 if (RenderThread::current()) { // Will be NULL during unit tests.
2827 RenderThread::current()->user_script_slave()->InjectScripts(
2828 frame, UserScript::DOCUMENT_START);
2829 }
[email protected]078b34612009-09-19 19:31:512830 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2831 view_type_ == ViewType::EXTENSION_MOLE) {
2832 InjectToolstripCSS();
2833 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2834 }
[email protected]3d9689372009-09-10 04:29:172835
2836 // Notify the browser about non-blank documents loading in the top frame.
2837 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252838 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272839 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172840 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2841 }
2842}
2843
2844void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2845 UpdateTitle(frame, title);
2846
2847 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272848 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172849}
2850
[email protected]5019ef12010-04-27 17:26:582851void RenderView::didChangeIcons(WebFrame* frame) {
2852 if (!frame->parent()) {
2853 Send(new ViewHostMsg_UpdateFavIconURL(
2854 routing_id_,
2855 page_id_,
2856 frame->favIconURL()));
2857 }
2858}
2859
[email protected]3d9689372009-09-10 04:29:172860void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2861 WebDataSource* ds = frame->dataSource();
2862 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2863 DCHECK(navigation_state);
2864 navigation_state->set_finish_document_load_time(Time::Now());
2865
2866 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2867
[email protected]e9e07992010-02-17 21:04:362868 // The document has now been fully loaded. Scan for forms to be sent up to
2869 // the browser.
[email protected]679f128f2010-07-22 22:57:442870 autofill_helper_.FrameContentsAvailable(frame);
2871 password_autocomplete_manager_.SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172872
2873 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272874 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172875
2876 if (RenderThread::current()) { // Will be NULL during unit tests.
2877 RenderThread::current()->user_script_slave()->InjectScripts(
2878 frame, UserScript::DOCUMENT_END);
2879 }
[email protected]fa7b6b542009-11-03 05:02:302880
2881 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2882}
2883
2884void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2885 if (RenderThread::current()) { // Will be NULL during unit tests.
2886 RenderThread::current()->user_script_slave()->InjectScripts(
2887 frame, UserScript::DOCUMENT_IDLE);
2888 }
2889
2890 WebFrame* main_frame = webview()->mainFrame();
2891 if (frame == main_frame) {
2892 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202893 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302894 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202895 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302896 pending_code_execution_queue_.pop();
2897 }
2898 }
[email protected]3d9689372009-09-10 04:29:172899}
2900
2901void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:262902 if (webview()->mainFrame() == frame)
2903 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172904}
2905
2906void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2907 // Ignore
2908}
2909
2910void RenderView::didFinishLoad(WebFrame* frame) {
2911 WebDataSource* ds = frame->dataSource();
2912 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2913 DCHECK(navigation_state);
2914 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302915 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412916
2917 // Let the password manager know which password forms are actually visible.
[email protected]679f128f2010-07-22 22:57:442918 password_autocomplete_manager_.SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172919}
2920
[email protected]ccbe04e2010-03-17 17:58:432921void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172922 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062923
2924 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2925 // since a new one gets created by didCreateDataSource.
2926 NavigationState* state =
2927 NavigationState::FromDataSource(frame->dataSource());
2928 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2929
[email protected]3d9689372009-09-10 04:29:172930 // If this was a reference fragment navigation that we initiated, then we
2931 // could end up having a non-null pending navigation state. We just need to
2932 // update the ExtraData on the datasource so that others who read the
2933 // ExtraData will get the new NavigationState. Similarly, if we did not
2934 // initiate this navigation, then we need to take care to reset any pre-
2935 // existing navigation state to a content-initiated navigation state.
2936 // DidCreateDataSource conveniently takes care of this for us.
2937 didCreateDataSource(frame, frame->dataSource());
2938
[email protected]f6c2459d2010-02-24 22:34:062939 if (idle_scheduler_ran) {
2940 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2941 NavigationState* new_state =
2942 NavigationState::FromDataSource(frame->dataSource());
2943 new_state->user_script_idle_scheduler()->set_has_run(true);
2944 }
2945
[email protected]3d9689372009-09-10 04:29:172946 didCommitProvisionalLoad(frame, is_new_navigation);
2947
[email protected]26aa0482009-09-30 16:55:272948 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172949}
2950
[email protected]476b6f82009-09-10 21:00:592951void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312952 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592953}
2954
[email protected]3d9689372009-09-10 04:29:172955void RenderView::assignIdentifierToRequest(
2956 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2957 // Ignore
2958}
2959
2960void RenderView::willSendRequest(
2961 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2962 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302963 WebFrame* top_frame = frame->top();
2964 if (!top_frame)
2965 top_frame = frame;
2966 WebDataSource* data_source = top_frame->provisionalDataSource();
2967 if (!data_source)
2968 data_source = top_frame->dataSource();
2969 if (data_source) {
2970 NavigationState* state = NavigationState::FromDataSource(data_source);
2971 if (state && state->is_cache_policy_override_set())
2972 request.setCachePolicy(state->cache_policy_override());
2973 }
[email protected]3d9689372009-09-10 04:29:172974 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502975 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132976 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492977
[email protected]85cc78c2010-05-04 18:30:092978 // Temporary metrics, see site_isolation_metrics.h
2979 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172980}
2981
2982void RenderView::didReceiveResponse(
2983 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492984
[email protected]85cc78c2010-05-04 18:30:092985 // Temporary metrics, see site_isolation_metrics.h
2986 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2987 identifier,
2988 response);
[email protected]fa0a3432010-03-30 16:53:492989
[email protected]3d9689372009-09-10 04:29:172990 // Only do this for responses that correspond to a provisional data source
2991 // of the top-most frame. If we have a provisional data source, then we
2992 // can't have any sub-resources yet, so we know that this response must
2993 // correspond to a frame load.
2994 if (!frame->provisionalDataSource() || frame->parent())
2995 return;
2996
2997 // If we are in view source mode, then just let the user see the source of
2998 // the server's 404 error page.
2999 if (frame->isViewSourceModeEnabled())
3000 return;
3001
[email protected]65041fa2010-05-21 06:56:533002 NavigationState* navigation_state =
3003 NavigationState::FromDataSource(frame->provisionalDataSource());
3004 CHECK(navigation_state);
3005
[email protected]972ebdff2010-06-10 22:59:073006 // Record page load flags.
3007 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3008 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573009 navigation_state->set_was_alternate_protocol_available(
3010 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073011 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]65041fa2010-05-21 06:56:533012
[email protected]f48013be2010-01-14 22:07:453013 // Consider loading an alternate error page for 404 responses.
3014 if (response.httpStatusCode() != 404)
3015 return;
3016
[email protected]3d9689372009-09-10 04:29:173017 // Can we even load an alternate error page for this URL?
3018 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3019 return;
3020
[email protected]3d9689372009-09-10 04:29:173021 navigation_state->set_postpone_loading_data(true);
3022 navigation_state->clear_postponed_data();
3023}
3024
3025void RenderView::didFinishResourceLoad(
3026 WebFrame* frame, unsigned identifier) {
3027 NavigationState* navigation_state =
3028 NavigationState::FromDataSource(frame->dataSource());
3029 if (!navigation_state->postpone_loading_data())
3030 return;
3031
3032 // The server returned a 404 and the content was < 512 bytes (which we
3033 // suppressed). Go ahead and fetch the alternate page content.
3034
3035 const GURL& frame_url = frame->url();
3036
3037 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3038 DCHECK(error_page_url.is_valid());
3039
3040 WebURLError original_error;
3041 original_error.unreachableURL = frame_url;
3042
3043 navigation_state->set_alt_error_page_fetcher(
3044 new AltErrorPageResourceFetcher(
3045 error_page_url, frame, original_error,
3046 NewCallback(this, &RenderView::AltErrorPageFinished)));
3047}
3048
3049void RenderView::didFailResourceLoad(
3050 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3051 // Ignore
3052}
3053
3054void RenderView::didLoadResourceFromMemoryCache(
3055 WebFrame* frame, const WebURLRequest& request,
3056 const WebURLResponse& response) {
3057 // Let the browser know we loaded a resource from the memory cache. This
3058 // message is needed to display the correct SSL indicators.
3059 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3060 routing_id_,
3061 request.url(),
[email protected]91733b62009-09-18 06:21:093062 frame->securityOrigin().toString().utf8(),
3063 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173064 response.securityInfo()));
3065}
3066
[email protected]6069da8c2009-10-20 20:33:493067void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293068 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3069}
3070
3071void RenderView::didRunInsecureContent(
3072 WebFrame* frame, const WebSecurityOrigin& origin) {
3073 Send(new ViewHostMsg_DidRunInsecureContent(
3074 routing_id_,
3075 origin.toString().utf8()));
3076}
3077
[email protected]7ea093ba2009-11-03 05:54:593078bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403079 if (enabled_per_settings &&
3080 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3081 return true;
[email protected]7ea093ba2009-11-03 05:54:593082
[email protected]12bc8472010-04-15 07:29:403083 if (IsWhitelistedForContentSettings(frame))
3084 return true;
[email protected]7ea093ba2009-11-03 05:54:593085
3086 return false; // Other protocols fall through here.
3087}
3088
[email protected]0a1a45432010-03-31 08:09:453089bool RenderView::allowDatabase(
3090 WebFrame* frame, const WebString& name, const WebString& display_name,
3091 unsigned long estimated_size) {
3092 WebSecurityOrigin origin = frame->securityOrigin();
3093 if (origin.isEmpty())
3094 return false; // Uninitialized document?
3095
3096 bool result;
3097 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3098 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3099 return false;
[email protected]9fb83e82010-07-02 18:24:553100 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3101 GURL(origin.toString().utf8()),
3102 name,
3103 display_name,
3104 estimated_size,
3105 !result));
[email protected]0a1a45432010-03-31 08:09:453106 return result;
3107}
[email protected]8934a3b2010-02-25 00:34:003108void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
3109 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
3110}
3111
[email protected]c21f1d52010-03-04 03:19:433112void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
3113 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
3114}
3115
[email protected]3d9689372009-09-10 04:29:173116void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3117 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3118}
3119
[email protected]0c882b282009-10-07 17:01:283120void RenderView::didCreateScriptContext(WebFrame* frame) {
3121 EventBindings::HandleContextCreated(frame, false);
3122}
3123
3124void RenderView::didDestroyScriptContext(WebFrame* frame) {
3125 EventBindings::HandleContextDestroyed(frame);
3126}
3127
3128void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3129 EventBindings::HandleContextCreated(frame, true);
3130}
3131
[email protected]fc86daa2010-03-30 23:52:533132void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3133 WebFrame* target,
3134 bool cross_origin,
3135 const WebString& property_name,
3136 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103137 // TODO(johnnyg): track the individual properties and repeat event_ids.
3138 if (cross_origin)
3139 cross_origin_access_count_++;
3140 else
3141 same_origin_access_count_++;
3142}
3143
[email protected]3d9689372009-09-10 04:29:173144void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143145 CheckPreferredSize();
3146}
3147
3148void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173149 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253150 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173151 // message.
[email protected]705243f2010-05-05 19:58:073152 if (!send_preferred_size_changes_ || !webview())
3153 return;
[email protected]dfca5acf2010-03-22 03:28:433154
[email protected]705243f2010-05-05 19:58:073155 // WebCore likes to tell us things have changed even when they haven't, so
3156 // cache the width and height and only send the IPC message when we're sure
3157 // they're different.
3158 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3159 webview()->mainFrame()->documentElementScrollHeight());
3160 if (size == preferred_size_)
3161 return;
[email protected]c27324b2009-11-19 22:44:293162
[email protected]705243f2010-05-05 19:58:073163 preferred_size_ = size;
3164 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3165 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173166}
3167
[email protected]143dcd592009-11-06 21:33:493168void RenderView::didChangeScrollOffset(WebFrame* frame) {
3169 StartNavStateSyncTimerIfNecessary();
3170}
3171
[email protected]8922e1f2009-10-03 05:01:263172void RenderView::reportFindInPageMatchCount(int request_id, int count,
3173 bool final_update) {
3174 // If we have a message that has been queued up, then we should just replace
3175 // it. The ACK from the browser will make sure it gets sent when the browser
3176 // wants it.
3177 if (queued_find_reply_message_.get()) {
3178 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3179 routing_id_,
3180 request_id,
3181 count,
3182 gfx::Rect(),
3183 -1, // Don't update active match ordinal.
3184 final_update);
3185 queued_find_reply_message_.reset(msg);
3186 } else {
3187 // Send the search result over to the browser process.
3188 Send(new ViewHostMsg_Find_Reply(
3189 routing_id_,
3190 request_id,
3191 count,
3192 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073193 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263194 final_update));
3195 }
3196}
3197
3198void RenderView::reportFindInPageSelection(int request_id,
3199 int active_match_ordinal,
3200 const WebRect& selection_rect) {
3201 // Send the search result over to the browser process.
3202 Send(new ViewHostMsg_Find_Reply(routing_id_,
3203 request_id,
3204 -1,
3205 selection_rect,
3206 active_match_ordinal,
3207 false));
3208}
3209
[email protected]24a7f3c2010-03-25 08:26:493210void RenderView::ReportNoFindInPageResults(int request_id) {
3211 Send(new ViewHostMsg_Find_Reply(routing_id_,
3212 request_id,
3213 0,
3214 gfx::Rect(),
3215 0,
3216 true));
3217}
3218
[email protected]79dbc662009-09-04 05:42:513219// webkit_glue::WebPluginPageDelegate -----------------------------------------
3220
[email protected]f103ab72009-09-02 17:10:593221webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533222 const FilePath& file_path,
3223 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593224 if (!PluginChannelHost::IsListening())
3225 return NULL;
3226
[email protected]d2139662009-12-10 03:21:143227 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283228 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143229 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163230 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533231 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143232 if (CommandLine::ForCurrentProcess()->
3233 HasSwitch(switches::kInternalPepper)) {
3234 in_process_plugin = true;
3235 use_pepper_host = true;
3236 } else {
3237 // In process Pepper plugins must be explicitly enabled.
3238 return NULL;
3239 }
[email protected]4e0616e2010-05-28 14:55:533240 } else {
3241 FilePath internal_pdf_path;
3242 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3243 if (file_path == internal_pdf_path) {
3244 in_process_plugin = true;
3245 use_pepper_host = true;
3246 }
[email protected]26e8d5e2009-10-13 02:47:163247 }
[email protected]4e0616e2010-05-28 14:55:533248
[email protected]d2139662009-12-10 03:21:143249 // Check for Native Client modules.
[email protected]8f05f7f2010-07-30 23:12:433250 if (mime_type == "application/x-nacl-srpc") {
3251 // NaCl is only permitted when we're in an extension/application with the
3252 // appropriate permission, or when explicitly enabled on the command line.
3253
3254 // TODO(cbiffle): need browser test for this before M7 (bug 45881)
3255 GURL main_frame_url(webview()->mainFrame()->url());
3256 const std::string &extension_id =
3257 RenderThread::current()->GetExtensionIdByURL(main_frame_url);
3258 bool in_ext = extension_id != "";
3259 bool explicit_enable =
3260 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3261
3262 if (in_ext) {
3263 if (ExtensionProcessBindings::HasPermission(extension_id,
3264 Extension::kNativeClientPermission)) {
3265 in_process_plugin = true;
3266 use_pepper_host = true;
3267 } else {
3268 // Disable NaCl for apps lacking the permission, even with the flag.
3269 return NULL;
3270 }
3271 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463272 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143273 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463274 }
3275 }
[email protected]4e0616e2010-05-28 14:55:533276
[email protected]d032f492009-09-29 00:33:463277 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143278 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283279 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533280 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333281 if (!pepper_plugin)
3282 return NULL;
3283
[email protected]53900d52010-06-16 04:25:013284 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283285 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143286 } else {
[email protected]6876dff2010-01-15 19:38:093287#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143288 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533289 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093290#else
[email protected]596b2c42010-01-14 20:40:433291 NOTIMPLEMENTED();
3292 return NULL;
[email protected]7b6616f2010-01-14 18:07:553293#endif
[email protected]6876dff2010-01-15 19:38:093294 }
[email protected]f103ab72009-09-02 17:10:593295 }
3296
[email protected]4e0616e2010-05-28 14:55:533297 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593298}
3299
3300void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033301#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593302 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3303 routing_id(), window));
3304#endif
3305}
3306
3307void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033308#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593309 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3310 routing_id(), window));
3311#endif
3312 CleanupWindowInPluginMoves(window);
3313}
3314
3315void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3316 SchedulePluginMove(move);
3317}
3318
3319void RenderView::DidStartLoadingForPlugin() {
3320 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523321 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593322}
3323
3324void RenderView::DidStopLoadingForPlugin() {
3325 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523326 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593327}
3328
3329void RenderView::ShowModalHTMLDialogForPlugin(
3330 const GURL& url,
3331 const gfx::Size& size,
3332 const std::string& json_arguments,
3333 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213334 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593335 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213336 json_retval));
[email protected]f103ab72009-09-02 17:10:593337}
3338
[email protected]b921cfd22010-02-25 16:57:513339WebCookieJar* RenderView::GetCookieJar() {
3340 return &cookie_jar_;
3341}
3342
initial.commit09911bf2008-07-26 23:55:293343void RenderView::SyncNavigationState() {
3344 if (!webview())
3345 return;
3346
[email protected]26aa0482009-09-30 16:55:273347 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173348 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293349 return;
[email protected]ca948a22009-06-25 19:36:173350
3351 Send(new ViewHostMsg_UpdateState(
3352 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293353}
3354
[email protected]b0950a72009-09-29 23:16:173355bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3356 // Make sure webview was not shut down.
3357 if (!webview())
3358 return false;
3359 // Create an image resource fetcher and assign it with a call back object.
3360 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273361 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173362 NewCallback(this, &RenderView::DidDownloadImage)));
3363 return true;
3364}
3365
3366void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293367 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173368 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473369 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3370 fetcher->id(),
3371 fetcher->image_url(),
3372 image.isNull(),
3373 image));
[email protected]b0950a72009-09-29 23:16:173374 // Dispose of the image fetcher.
3375 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3376 image_fetchers_.erase(fetcher);
3377 // We're in the callback from the ImageResourceFetcher, best to delay
3378 // deletion.
3379 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293380}
3381
[email protected]bf5c2ff392009-07-08 16:24:333382void RenderView::OnDownloadFavIcon(int id,
3383 const GURL& image_url,
3384 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343385 bool data_image_failed = false;
3386 if (image_url.SchemeIs("data")) {
3387 SkBitmap data_image = ImageFromDataUrl(image_url);
3388 data_image_failed = data_image.empty();
3389 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333390 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3391 data_image));
[email protected]f11ca0732009-04-11 00:09:343392 }
3393 }
3394
[email protected]bf5c2ff392009-07-08 16:24:333395 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173396 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333397 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3398 SkBitmap()));
3399 }
initial.commit09911bf2008-07-26 23:55:293400}
3401
[email protected]f11ca0732009-04-11 00:09:343402SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3403 std::string mime_type, char_set, data;
3404 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3405 // Decode the favicon using WebKit's image decoder.
3406 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3407 const unsigned char* src_data =
3408 reinterpret_cast<const unsigned char*>(&data[0]);
3409
3410 return decoder.Decode(src_data, data.size());
3411 }
3412 return SkBitmap();
3413}
3414
initial.commit09911bf2008-07-26 23:55:293415void RenderView::OnGetApplicationInfo(int page_id) {
3416 webkit_glue::WebApplicationInfo app_info;
3417 if (page_id == page_id_)
3418 webkit_glue::GetApplicationInfo(webview(), &app_info);
3419
3420 // Prune out any data URLs in the set of icons. The browser process expects
3421 // any icon with a data URL to have originated from a favicon. We don't want
3422 // to decode arbitrary data URLs in the browser process. See
3423 // http://b/issue?id=1162972
3424 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593425 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293426 app_info.icons.erase(app_info.icons.begin() + i);
3427 --i;
3428 }
3429 }
3430
3431 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3432}
3433
[email protected]7ccddb8c2009-08-04 17:36:553434GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293435 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553436 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293437 // If the URL that failed was secure, then the embedding web page was not
3438 // expecting a network attacker to be able to manipulate its contents. As
3439 // we fetch alternate error pages over HTTP, we would be allowing a network
3440 // attacker to manipulate the contents of the response if we tried to use
3441 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153442 return GURL();
initial.commit09911bf2008-07-26 23:55:293443 }
3444
3445 // Grab the base URL from the browser process.
3446 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153447 return GURL();
initial.commit09911bf2008-07-26 23:55:293448
3449 // Strip query params from the failed URL.
3450 GURL::Replacements remove_params;
3451 remove_params.ClearUsername();
3452 remove_params.ClearPassword();
3453 remove_params.ClearQuery();
3454 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553455 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503456 std::string spec_to_send = url_to_send.spec();
3457 // Notify link doctor of the url truncation by sending of "?" at the end.
3458 if (failed_url.has_query())
3459 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293460
3461 // Construct the query params to send to link doctor.
3462 std::string params(alternate_error_page_url_.query());
3463 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503464 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293465 params.append("&sourceid=chrome");
3466 params.append("&error=");
3467 switch (error_type) {
3468 case DNS_ERROR:
3469 params.append("dnserror");
3470 break;
3471
3472 case HTTP_404:
3473 params.append("http404");
3474 break;
3475
[email protected]5df266ac2008-10-15 19:50:133476 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333477 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133478 break;
3479
initial.commit09911bf2008-07-26 23:55:293480 default:
3481 NOTREACHED() << "unknown ErrorPageType";
3482 }
3483
3484 // OK, build the final url to return.
3485 GURL::Replacements link_doctor_params;
3486 link_doctor_params.SetQueryStr(params);
3487 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3488 return url;
3489}
3490
[email protected]0fdbf8c2010-07-08 20:33:013491WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3492 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493493}
3494
[email protected]6069da8c2009-10-20 20:33:493495void RenderView::OnFind(int request_id, const string16& search_text,
3496 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273497 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493498
3499 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493500 if (options.findNext) {
3501 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013502 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493503 } else {
[email protected]afdbd142010-07-10 08:01:233504 if (GetWebPluginFromPluginDocument()->startFind(
3505 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493506 } else {
3507 ReportNoFindInPageResults(request_id);
3508 }
3509 }
3510 return;
3511 }
3512
[email protected]b4bb2502009-10-01 22:35:273513 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273514 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293515 WebFrame* search_frame = focused_frame; // start searching focused frame.
3516
3517 bool multi_frame = (frame_after_main != main_frame);
3518
3519 // If we have multiple frames, we don't want to wrap the search within the
3520 // frame, so we check here if we only have main_frame in the chain.
3521 bool wrap_within_frame = !multi_frame;
3522
[email protected]b3f2b912009-04-09 16:18:523523 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293524 bool result = false;
3525
[email protected]7830da3e2009-11-06 16:27:263526 // If something is selected when we start searching it means we cannot just
3527 // increment the current match ordinal; we need to re-generate it.
3528 WebRange current_selection = focused_frame->selectionRange();
3529
initial.commit09911bf2008-07-26 23:55:293530 do {
[email protected]dd7daa82009-08-10 05:46:453531 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593532 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293533
3534 if (!result) {
3535 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223536 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293537
3538 // Find the next frame, but skip the invisible ones.
3539 do {
3540 // What is the next frame to search? (we might be going backwards). Note
3541 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593542 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273543 search_frame->traverseNext(true) :
3544 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453545 } while (!search_frame->hasVisibleContent() &&
3546 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293547
[email protected]884db412008-11-24 23:46:503548 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223549 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293550
3551 // If we have multiple frames and we have wrapped back around to the
3552 // focused frame, we need to search it once more allowing wrap within
3553 // the frame, otherwise it will report 'no match' if the focused frame has
3554 // reported matches, but no frames after the focused_frame contain a
3555 // match for the search word(s).
3556 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453557 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593558 request_id, search_text, options, true, // Force wrapping.
3559 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293560 }
3561 }
3562
[email protected]26aa0482009-09-30 16:55:273563 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293564 } while (!result && search_frame != focused_frame);
3565
[email protected]7830da3e2009-11-06 16:27:263566 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293567 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453568 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293569 } else {
3570 // If nothing is found, set result to "0 of 0", otherwise, set it to
3571 // "-1 of 1" to indicate that we found at least one item, but we don't know
3572 // yet what is active.
3573 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3574 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293575
[email protected]4f3dc372009-02-24 00:10:293576 // If we find no matches then this will be our last status update.
3577 // Otherwise the scoping effort will send more results.
3578 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293579
[email protected]4f3dc372009-02-24 00:10:293580 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403581 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593582 request_id,
[email protected]4f3dc372009-02-24 00:10:293583 match_count,
3584 selection_rect,
3585 ordinal,
3586 final_status_update));
initial.commit09911bf2008-07-26 23:55:293587
initial.commit09911bf2008-07-26 23:55:293588 // Scoping effort begins, starting with the mainframe.
3589 search_frame = main_frame;
3590
[email protected]dd7daa82009-08-10 05:46:453591 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293592
3593 do {
3594 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453595 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293596
3597 // We don't start another scoping effort unless at least one match has
3598 // been found.
3599 if (result) {
3600 // Start new scoping request. If the scoping function determines that it
3601 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453602 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593603 search_text,
3604 options,
initial.commit09911bf2008-07-26 23:55:293605 true); // reset the tickmarks
3606 }
3607
3608 // Iterate to the next frame. The frame will not necessarily scope, for
3609 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273610 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293611 } while (search_frame != main_frame);
3612 }
3613}
3614
[email protected]24a7f3c2010-03-25 08:26:493615void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3616 WebView* view = webview();
3617 if (!view)
3618 return;
3619
3620 WebDocument doc = view->mainFrame()->document();
3621 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013622 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493623 return;
3624 }
3625
3626 bool clear_selection =
3627 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3628 if (clear_selection)
3629 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3630
3631 WebFrame* frame = view->mainFrame();
3632 while (frame) {
3633 frame->stopFinding(clear_selection);
3634 frame = frame->traverseNext(false);
3635 }
3636
3637 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3638 WebFrame* focused_frame = view->focusedFrame();
3639 if (focused_frame) {
3640 WebDocument doc = focused_frame->document();
3641 if (!doc.isNull()) {
3642 WebNode node = doc.focusedNode();
3643 if (!node.isNull())
3644 node.simulateClick();
3645 }
3646 }
3647 }
3648}
3649
3650void RenderView::OnFindReplyAck() {
3651 // Check if there is any queued up request waiting to be sent.
3652 if (queued_find_reply_message_.get()) {
3653 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423654 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493655 }
3656}
3657
[email protected]8934a3b2010-02-25 00:34:003658bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353659 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003660 return current_content_settings_.settings[settings_type] !=
3661 CONTENT_SETTING_BLOCK;
3662}
3663
3664void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3665 if (!content_blocked_[settings_type]) {
3666 content_blocked_[settings_type] = true;
3667 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353668 }
[email protected]0de80162010-02-03 04:52:353669}
3670
[email protected]71b0d5d2010-02-15 05:43:073671void RenderView::ClearBlockedContentSettings() {
3672 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3673 content_blocked_[i] = false;
3674}
3675
[email protected]00152e92010-07-19 11:47:403676WebPlugin* RenderView::CreatePluginInternal(WebFrame* frame,
[email protected]0cdafff2010-07-26 09:54:373677 const WebPluginParams& params,
3678 const std::string& mime_type,
3679 const FilePath& plugin_path) {
3680 FilePath path(plugin_path);
3681 std::string actual_mime_type(mime_type);
3682 if (path.value().empty()) {
3683 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3684 params.url, frame->top()->url(), params.mimeType.utf8(), &path,
3685 &actual_mime_type));
3686 }
[email protected]00152e92010-07-19 11:47:403687 if (path.value().empty())
3688 return NULL;
3689
3690 if (actual_mime_type.empty())
3691 actual_mime_type = params.mimeType.utf8();
3692
3693 scoped_refptr<pepper::PluginModule> pepper_module =
3694 PepperPluginRegistry::GetInstance()->GetModule(path);
3695 if (pepper_module) {
[email protected]ebf40a72010-07-22 01:46:383696 WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params,
3697 pepper_delegate_.AsWeakPtr());
3698 if (plugin && !frame->parent() && frame->document().isPluginDocument()) {
3699 // If this is a full-page plugin hosting the internal PDF plugin, we want
3700 // to notify the browser so that it can treat things like zooming
3701 // differently.
3702 // TODO(sanjeevr): Use a Pepper interface to determine this rather than
3703 // hardcode this for the PDF plugin path.
3704 FilePath pdf_path;
3705 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
3706 if (path == pdf_path)
3707 Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_));
3708 }
3709 return plugin;
[email protected]00152e92010-07-19 11:47:403710 }
3711
3712 return new webkit_glue::WebPluginImpl(frame, params, path, actual_mime_type,
3713 AsWeakPtr());
3714}
3715
3716WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame,
3717 const WebPluginParams& params) {
3718 // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed.
3719 BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params);
3720 WebViewPlugin* plugin = blocked_plugin->plugin();
3721 webkit_preferences_.Apply(plugin->web_view());
3722 return plugin;
3723}
3724
[email protected]40bd6582009-12-04 23:49:513725void RenderView::OnZoom(PageZoom::Function function) {
3726 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3727 return;
3728
[email protected]258d31122010-05-09 10:59:413729 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523730
[email protected]40bd6582009-12-04 23:49:513731 int zoom_level = webview()->zoomLevel();
3732 int new_zoom_level = webview()->setZoomLevel(false,
3733 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3734
[email protected]9d797f32010-04-23 07:17:543735 // Tell the browser which url got zoomed so it can update the saved values.
3736 Send(new ViewHostMsg_DidZoomURL(
3737 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513738}
3739
[email protected]9d797f32010-04-23 07:17:543740void RenderView::OnSetContentSettingsForLoadingURL(
3741 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013742 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543743 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013744}
3745
[email protected]9d797f32010-04-23 07:17:543746void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3747 int zoom_level) {
3748 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293749}
3750
[email protected]41fc0322009-09-04 22:23:403751void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273752 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293753}
3754
[email protected]a697f4c2009-09-14 22:30:183755void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273756 WebString no_encoding;
3757 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183758}
3759
[email protected]20ad2692009-11-20 18:27:203760bool RenderView::GetAllChildFrames(
3761 WebFrame* parent_frame,
3762 std::vector<WebFrame*>* frames_vector) const {
3763 if (!parent_frame)
3764 return false;
3765 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3766 child_frame = child_frame->nextSibling()) {
3767 frames_vector->push_back(child_frame);
3768 GetAllChildFrames(child_frame, frames_vector);
3769 }
3770 return true;
3771}
3772
[email protected]dd7daa82009-08-10 05:46:453773WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3774 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273775 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453776
3777 // xpath string can represent a frame deep down the tree (across multiple
3778 // frame DOMs).
3779 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3780 // should break into 2 xpaths
3781 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3782
[email protected]26aa0482009-09-30 16:55:273783 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453784
3785 std::wstring xpath_remaining = xpath;
3786 while (!xpath_remaining.empty()) {
3787 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3788 std::wstring xpath_child;
3789 if (delim_pos != std::wstring::npos) {
3790 xpath_child = xpath_remaining.substr(0, delim_pos);
3791 xpath_remaining.erase(0, delim_pos + 1);
3792 } else {
3793 xpath_remaining.swap(xpath_child);
3794 }
3795 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293796 }
3797
[email protected]dd7daa82009-08-10 05:46:453798 return frame;
initial.commit09911bf2008-07-26 23:55:293799}
3800
[email protected]f29acf52008-11-03 20:08:333801void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3802 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293803 WebFrame* web_frame = GetChildFrame(frame_xpath);
3804 if (!web_frame)
3805 return;
3806
[email protected]dd7daa82009-08-10 05:46:453807 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293808}
3809
[email protected]1810e132009-03-24 23:35:483810void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083811 const std::string& css,
3812 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483813 WebFrame* web_frame = GetChildFrame(frame_xpath);
3814 if (!web_frame)
3815 return;
3816
[email protected]ffaef0c2009-09-15 17:08:083817 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483818}
3819
[email protected]00c39612010-03-06 02:53:283820void RenderView::OnPepperPluginDestroy(
3821 WebPluginDelegatePepper* pepper_plugin) {
3822 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:013823 current_oldstyle_pepper_plugins_.find(pepper_plugin);
3824 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:283825 NOTREACHED();
3826 return;
3827 }
[email protected]53900d52010-06-16 04:25:013828 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473829
3830 // The plugin could have been destroyed while it was waiting for a file
3831 // choose callback, so check all pending completion callbacks and NULL them.
3832 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3833 file_chooser_completions_.begin();
3834 i != file_chooser_completions_.end(); /* nothing */) {
3835 if ((*i)->completion == pepper_plugin) {
3836 // We NULL the first one instead of deleting it because the plugin might
3837 // be the one waiting for a file choose callback. If the callback later
3838 // comes, we don't want to send the result to the next callback in line.
3839 if (i == file_chooser_completions_.begin())
3840 (*i)->completion = NULL;
3841 else
3842 i = file_chooser_completions_.erase(i);
3843 } else {
3844 ++i;
3845 }
3846 }
[email protected]00c39612010-03-06 02:53:283847}
3848
initial.commit09911bf2008-07-26 23:55:293849void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3850 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333851 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293852}
3853
[email protected]1810e132009-03-24 23:35:483854void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083855 const std::string& css,
3856 const std::string& id) {
3857 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413858
3859 // Notify RenderViewHost that css has been inserted into the frame.
3860 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483861}
3862
[email protected]7ea066a2009-04-06 20:21:593863void RenderView::OnAddMessageToConsole(
3864 const string16& frame_xpath,
3865 const string16& message,
3866 const WebConsoleMessage::Level& level) {
3867 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593868 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453869 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293870}
3871
[email protected]81e63782009-02-27 19:35:093872void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3873 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293874}
3875
3876void RenderView::OnSetDOMUIProperty(const std::string& name,
3877 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093878 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293879 dom_ui_bindings_.SetProperty(name, value);
3880}
3881
3882void RenderView::OnReservePageIDRange(int size_of_range) {
3883 next_page_id_ += size_of_range + 1;
3884}
3885
[email protected]e80c73b2009-04-07 23:24:583886void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3887 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253888 bool ended,
3889 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033890 if (ended) {
[email protected]26aa0482009-09-30 16:55:273891 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203892 } else {
3893 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033894 }
initial.commit09911bf2008-07-26 23:55:293895}
3896
3897void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273898 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293899}
3900
initial.commit09911bf2008-07-26 23:55:293901void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163902 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]03f57072010-07-14 17:36:083903#if defined(WEBKIT_BUG_41283_IS_FIXED)
3904 password_autocomplete_manager_.ReceivedPasswordFormFillData(webview(),
3905 form_data);
[email protected]ad24ccb2010-07-15 21:38:203906#else
3907 webkit_glue::FillPasswordForm(this->webview(), form_data);
[email protected]03f57072010-07-14 17:36:083908#endif
initial.commit09911bf2008-07-26 23:55:293909}
3910
3911void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583912 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253913 const gfx::Point& screen_point,
3914 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273915 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583916 drop_data.ToDragData(),
3917 drop_data.identity,
3918 client_point,
[email protected]1d9f4132009-09-08 17:29:253919 screen_point,
3920 ops);
initial.commit09911bf2008-07-26 23:55:293921
[email protected]1d9f4132009-09-08 17:29:253922 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293923}
3924
[email protected]e80c73b2009-04-07 23:24:583925void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253926 const gfx::Point& screen_point,
3927 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273928 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253929 client_point,
3930 screen_point,
3931 ops);
initial.commit09911bf2008-07-26 23:55:293932
[email protected]1d9f4132009-09-08 17:29:253933 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293934}
3935
3936void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273937 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293938}
3939
[email protected]e80c73b2009-04-07 23:24:583940void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3941 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273942 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293943}
3944
3945void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593946 webkit_preferences_ = prefs;
3947 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293948}
3949
3950void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3951 alternate_error_page_url_ = url;
3952}
3953
[email protected]a0c7153e2009-12-09 14:36:333954void RenderView::OnCustomContextMenuAction(unsigned action) {
3955 webview()->performCustomContextMenuAction(action);
3956}
3957
[email protected]d4a00a72010-01-29 01:44:423958void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023959 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423960 const std::string& source_lang,
3961 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023962 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3963 translate_script);
[email protected]d4a00a72010-01-29 01:44:423964}
3965
[email protected]85d252e2010-04-06 22:21:023966void RenderView::OnRevertTranslation(int page_id) {
3967 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323968}
3969
initial.commit09911bf2008-07-26 23:55:293970void RenderView::OnInstallMissingPlugin() {
3971 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593972 if (first_default_plugin_)
3973 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293974}
3975
[email protected]cdaf8d02010-03-30 19:52:473976void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363977 // This could happen if we navigated to a different page before the user
3978 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473979 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363980 return;
3981
[email protected]cdaf8d02010-03-30 19:52:473982 WebVector<WebString> ws_file_names(paths.size());
3983 for (size_t i = 0; i < paths.size(); ++i)
3984 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463985
[email protected]cdaf8d02010-03-30 19:52:473986 if (file_chooser_completions_.front()->completion)
3987 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3988 file_chooser_completions_.pop_front();
3989
3990 // If there are more pending file chooser requests, schedule one now.
3991 if (!file_chooser_completions_.empty()) {
3992 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3993 file_chooser_completions_.front()->params));
3994 }
initial.commit09911bf2008-07-26 23:55:293995}
3996
3997void RenderView::OnEnableViewSourceMode() {
3998 if (!webview())
3999 return;
[email protected]26aa0482009-09-30 16:55:274000 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294001 if (!main_frame)
4002 return;
4003
[email protected]dd7daa82009-08-10 05:46:454004 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294005}
4006
[email protected]770dd8b2010-05-24 18:11:394007void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4008 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244009 if (send_preferred_size_changes_)
4010 return;
[email protected]9fb325e2010-05-06 18:23:244011 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394012
4013 // WebKit doesn't send a notification of the effective height of the page
4014 // changes, so poll for it.
4015 // TODO: Add a notification for this to WebKit, remove polling. After that's
4016 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4017 // http://crbug.com/44850
4018 if (flags & kPreferredSizeHeightThisIsSlow) {
4019 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4020 &RenderView::CheckPreferredSize);
4021 }
[email protected]0666aef2009-05-13 19:48:084022}
4023
[email protected]cda45c02010-02-25 19:28:104024void RenderView::OnDisableScrollbarsForSmallWindows(
4025 const gfx::Size& disable_scrollbar_size_limit) {
4026 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4027}
4028
[email protected]80d96fa2009-06-10 22:34:514029void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4030 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374031 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034032#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414033 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4034 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464035 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324036
[email protected]644d77e2010-01-27 01:03:104037 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324038 webview()->setScrollbarColors(
4039 renderer_prefs.thumb_inactive_color,
4040 renderer_prefs.thumb_active_color,
4041 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104042 webview()->setSelectionColors(
4043 renderer_prefs.active_selection_bg_color,
4044 renderer_prefs.active_selection_fg_color,
4045 renderer_prefs.inactive_selection_bg_color,
4046 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:014047 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:104048 }
[email protected]7a74e102009-09-03 00:16:564049#endif
[email protected]80d96fa2009-06-10 22:34:514050}
4051
[email protected]952cb702009-10-07 05:50:284052void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4053 const WebMediaPlayerAction& action) {
4054 if (webview())
4055 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564056}
4057
[email protected]7b291f92009-08-14 05:43:534058void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:514059 // When this is first set, the bindings aren't fully loaded. We only need
4060 // to call through this API after the page has already been loaded. It's
4061 // also called in didCreateDocumentElement to bootstrap.
4062 if (view_type_ != ViewType::INVALID) {
4063 if (type == ViewType::EXTENSION_MOLE ||
4064 type == ViewType::EXTENSION_TOOLSTRIP) {
4065 ExtensionProcessBindings::SetViewType(webview(), type);
4066 }
4067 }
[email protected]7b291f92009-08-14 05:43:534068 view_type_ = type;
4069}
4070
4071void RenderView::OnUpdateBrowserWindowId(int window_id) {
4072 browser_window_id_ = window_id;
4073}
4074
[email protected]b3df5a42010-05-11 14:31:094075void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364076 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414077 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114078 accessibility_.reset(WebAccessibilityCache::create());
4079 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:414080
[email protected]b3df5a42010-05-11 14:31:094081 WebAccessibilityObject src_tree = webview()->accessibilityObject();
4082 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
4083 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504084}
4085
[email protected]aef92842010-05-21 16:54:364086void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4087 if (!accessibility_.get())
4088 return;
4089 if (accessibility_->isValidId(acc_obj_id)) {
4090 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4091 // By convention, calling SetFocus on the root of the tree (id = 1000)
4092 // should clear the current focus. Otherwise set the focus to the new
4093 // node.
4094 if (acc_obj_id == 1000)
4095 webview()->clearFocusedNode();
4096 else
4097 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4098 }
4099}
4100
4101void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4102 if (!accessibility_.get())
4103 return;
4104 if (accessibility_->isValidId(acc_obj_id)) {
4105 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4106 }
4107}
4108
initial.commit09911bf2008-07-26 23:55:294109void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4110 const GURL& page_url) {
4111 // Prepare list to storage all savable resource links.
4112 std::vector<GURL> resources_list;
4113 std::vector<GURL> referrers_list;
4114 std::vector<GURL> frames_list;
4115 webkit_glue::SavableResourcesResult result(&resources_list,
4116 &referrers_list,
4117 &frames_list);
4118
[email protected]dbeb3952009-10-13 18:01:184119 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4120 webview(),
4121 page_url,
4122 &result,
4123 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294124 // If something is wrong when collecting all savable resource links,
4125 // send empty list to embedder(browser) to tell it failed.
4126 referrers_list.clear();
4127 resources_list.clear();
4128 frames_list.clear();
4129 }
4130
4131 // Send result of all savable resource links to embedder.
4132 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4133 resources_list,
4134 referrers_list,
4135 frames_list));
4136}
4137
4138void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324139 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314140 const std::vector<FilePath>& local_paths,
4141 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074142
4143 // Convert std::vector of GURLs to WebVector<WebURL>
4144 WebVector<WebURL> weburl_links(links);
4145
4146 // Convert std::vector of std::strings to WebVector<WebString>
4147 WebVector<WebString> webstring_paths(local_paths.size());
4148 for (size_t i = 0; i < local_paths.size(); i++)
4149 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4150
4151 WebPageSerializer::serialize(webview()->mainFrame(),
4152 true, this, weburl_links, webstring_paths,
4153 webkit_glue::FilePathToWebString(
4154 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294155}
4156
[email protected]d9ec5c0f2009-12-23 11:55:074157void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4158 const WebCString& data,
4159 WebPageSerializerClient::PageSerializationStatus status) {
4160 Send(new ViewHostMsg_SendSerializedHtmlData(
4161 routing_id_,
4162 frame_url,
4163 data.data(),
4164 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294165}
4166
[email protected]9b18a84f2010-06-10 15:54:044167void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274168 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474169 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294170}
4171
[email protected]eb6b87a2009-07-24 15:57:394172void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294173 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4174 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4175 // in the onunload handler from appearing. For now, we're bypassing that and
4176 // calling the FrameLoader's CloseURL method directly. This should be
4177 // revisited to avoid having two ways to close a page. Having a single way
4178 // to close that can run onunload is also useful for fixing
4179 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274180 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294181 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454182 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174183 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294184 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4185 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454186 if (url.SchemeIs(chrome::kHttpScheme) ||
4187 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294188 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294189 }
[email protected]26aa0482009-09-30 16:55:274190 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294191
[email protected]ab9eabac2010-03-16 16:54:104192 // Reset stats
4193 cross_origin_access_count_ = 0;
4194 same_origin_access_count_ = 0;
4195
[email protected]eb6b87a2009-07-24 15:57:394196 // Just echo back the params in the ACK.
4197 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294198}
4199
4200void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574201#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294202 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014203 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574204#else // defined(OS_WIN)
4205 // TODO(port): we don't support theming on non-Windows platforms yet
4206 NOTIMPLEMENTED();
4207#endif
initial.commit09911bf2008-07-26 23:55:294208}
4209
[email protected]9b18a84f2010-06-10 15:54:044210void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4211 const std::string& origin,
4212 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154213 if (message.empty())
4214 return;
[email protected]28790922009-03-09 19:48:374215 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4216 target);
[email protected]3ac14a052008-08-15 21:22:154217}
4218
[email protected]0aa55312008-10-17 21:53:084219void RenderView::OnDisassociateFromPopupCount() {
4220 if (decrement_shared_popup_at_destruction_)
4221 shared_popup_counter_->data--;
4222 shared_popup_counter_ = new SharedRenderViewCounter(0);
4223 decrement_shared_popup_at_destruction_ = false;
4224}
4225
[email protected]15d79e12009-08-02 19:23:454226bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4227 const WebURLError& error,
4228 bool replace) {
4229 // We only show alternate error pages in the main frame. They are
4230 // intended to assist the user when navigating, so there is not much
4231 // value in showing them for failed subframes. Ideally, we would be
4232 // able to use the TYPED transition type for this, but that flag is
4233 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454234 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454235 return false;
4236
4237 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374238 // connection failure.
[email protected]15d79e12009-08-02 19:23:454239 int ec = error.reason;
4240 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4241 ec != net::ERR_CONNECTION_FAILED &&
4242 ec != net::ERR_CONNECTION_REFUSED &&
4243 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374244 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454245 return false;
4246
4247 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554248 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454249 if (!error_page_url.is_valid())
4250 return false;
4251
4252 // Load an empty page first so there is an immediate response to the error,
4253 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454254 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454255 GURL(kUnreachableWebDataURL),
4256 error.unreachableURL,
4257 replace);
4258
4259 // Now, create a fetcher for the error page and associate it with the data
4260 // source we just created via the LoadHTMLString call. That way if another
4261 // navigation occurs, the fetcher will get destroyed.
4262 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454263 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454264 navigation_state->set_alt_error_page_fetcher(
4265 new AltErrorPageResourceFetcher(
4266 error_page_url, frame, error,
4267 NewCallback(this, &RenderView::AltErrorPageFinished)));
4268 return true;
4269}
4270
initial.commit09911bf2008-07-26 23:55:294271std::string RenderView::GetAltHTMLForTemplate(
4272 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394273 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294274 ResourceBundle::GetSharedInstance().GetRawDataResource(
4275 template_resource_id));
4276
4277 if (template_html.empty()) {
4278 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4279 return "";
4280 }
[email protected]7cd22a52009-07-14 00:40:254281
initial.commit09911bf2008-07-26 23:55:294282 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254283 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294284 template_html, &error_strings, "t");
4285}
[email protected]0e79b9e2009-02-13 04:20:484286
[email protected]15d79e12009-08-02 19:23:454287void RenderView::AltErrorPageFinished(WebFrame* frame,
4288 const WebURLError& original_error,
4289 const std::string& html) {
4290 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554291
4292 // If we failed to download the alternate error page, fall back to the
4293 // original error page if present. Otherwise, LoadNavigationErrorPage
4294 // will simply display a default error page.
4295 const std::string* html_to_load = &html;
4296 if (html.empty()) {
4297 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454298 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554299 html_to_load = &navigation_state->postponed_data();
4300 }
4301 LoadNavigationErrorPage(
4302 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454303}
4304
[email protected]30f75e62009-02-25 22:01:004305void RenderView::OnMoveOrResizeStarted() {
4306 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474307 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004308}
4309
[email protected]30f75e62009-02-25 22:01:004310void RenderView::OnResize(const gfx::Size& new_size,
4311 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104312 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474313 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104314
4315 if (send_preferred_size_changes_) {
4316 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4317 // either width or height, allow scroll bars.
4318 bool allow_scrollbars = (
4319 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244320 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104321 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4322 }
4323 }
4324
[email protected]30f75e62009-02-25 22:01:004325 RenderWidget::OnResize(new_size, resizer_rect);
4326}
[email protected]0aa477bd2009-03-23 22:21:434327
[email protected]00c39612010-03-06 02:53:284328void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014329 // Notify the pepper plugins that we started painting.
4330 pepper_delegate_.ViewInitiatedPaint();
4331
4332 // Notify any "old-style" pepper plugins that we started painting. This is
4333 // used for internal bookkeeping only, so we know that the set can not change
4334 // under us.
[email protected]00c39612010-03-06 02:53:284335 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014336 current_oldstyle_pepper_plugins_.begin();
4337 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284338 (*i)->RenderViewInitiatedPaint();
4339}
4340
4341void RenderView::DidFlushPaint() {
4342 // Notify any pepper plugins that we painted. This will call into the plugin,
4343 // and we it may ask to close itself as a result. This will, in turn, modify
4344 // our set, possibly invalidating the iterator. So we iterate on a copy that
4345 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014346 pepper_delegate_.ViewFlushedPaint();
4347
4348 // Notify any old-style pepper plugins that we painted. This will call into
4349 // the plugin, and we it may ask to close itself as a result. This will, in
4350 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4351 // a copy that won't change out from under us.
4352 // This should be deleted when we don't support old Pepper anymore.
4353 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284354 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4355 i != plugins.end(); ++i) {
4356 // The copy above makes sure our iterator is never invalid if some plugins
4357 // are destroyed. But some plugin may decide to close all of its views in
4358 // response to a paint in one of them, so we need to make sure each one is
4359 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014360 if (current_oldstyle_pepper_plugins_.find(*i) !=
4361 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284362 (*i)->RenderViewFlushedPaint();
4363 }
4364
4365 WebFrame* main_frame = webview()->mainFrame();
4366
4367 // If we have a provisional frame we are between the start and commit stages
4368 // of loading and we don't want to save stats.
4369 if (!main_frame->provisionalDataSource()) {
4370 WebDataSource* ds = main_frame->dataSource();
4371 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4372 DCHECK(navigation_state);
4373
4374 Time now = Time::Now();
4375 if (navigation_state->first_paint_time().is_null()) {
4376 navigation_state->set_first_paint_time(now);
4377 }
4378 if (navigation_state->first_paint_after_load_time().is_null() &&
4379 !navigation_state->finish_load_time().is_null()) {
4380 navigation_state->set_first_paint_after_load_time(now);
4381 }
4382 }
4383}
4384
[email protected]05d478752009-04-08 23:38:164385void RenderView::OnClearFocusedNode() {
4386 if (webview())
[email protected]26aa0482009-09-30 16:55:274387 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164388}
4389
[email protected]699ab0d2009-04-23 23:19:144390void RenderView::OnSetBackground(const SkBitmap& background) {
4391 if (webview())
[email protected]b4bb2502009-10-01 22:35:274392 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144393
4394 SetBackground(background);
4395}
4396
[email protected]8c66c5a2009-07-22 17:26:344397void RenderView::OnSetActive(bool active) {
4398 if (webview())
[email protected]b4bb2502009-10-01 22:35:274399 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264400
4401#if defined(OS_MACOSX)
4402 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4403 for (plugin_it = plugin_delegates_.begin();
4404 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4405 (*plugin_it)->SetWindowFocus(active);
4406 }
4407#endif
[email protected]8c66c5a2009-07-22 17:26:344408}
4409
[email protected]6ce7abc52010-02-02 18:40:144410#if defined(OS_MACOSX)
4411void RenderView::OnSetWindowVisibility(bool visible) {
4412 // Inform plugins that their container has changed visibility.
4413 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4414 for (plugin_it = plugin_delegates_.begin();
4415 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4416 (*plugin_it)->SetContainerVisibility(visible);
4417 }
4418}
[email protected]1e6e3c992010-02-08 15:52:134419
[email protected]4d51d5bf2010-07-26 18:48:264420void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4421 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134422 // Inform plugins that their window's frame has changed.
4423 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4424 for (plugin_it = plugin_delegates_.begin();
4425 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4426 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4427 }
4428}
[email protected]6ce7abc52010-02-02 18:40:144429#endif // OS_MACOSX
4430
[email protected]309d7a282009-03-24 09:18:274431void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584432 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394433 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324434 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474435 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394436 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4437 name,
4438 args,
4439 source_url,
4440 request_id,
[email protected]2f25d7b92009-06-10 00:06:474441 has_callback));
[email protected]309d7a282009-03-24 09:18:274442}
4443
[email protected]c6619182009-05-12 14:59:324444void RenderView::OnExtensionResponse(int request_id,
4445 bool success,
4446 const std::string& response,
4447 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354448 ExtensionProcessBindings::HandleResponse(
4449 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274450}
[email protected]c20210e62009-04-03 21:39:264451
[email protected]078b34612009-09-19 19:31:514452void RenderView::InjectToolstripCSS() {
4453 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4454 return;
4455
4456 static const base::StringPiece toolstrip_css(
4457 ResourceBundle::GetSharedInstance().GetRawDataResource(
4458 IDR_EXTENSION_TOOLSTRIP_CSS));
4459 std::string css = toolstrip_css.as_string();
4460 InsertCSS(L"", css, "ToolstripDefaultCSS");
4461}
4462
[email protected]7120f132009-07-20 21:05:374463void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494464 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194465 bool requires_incognito_access,
4466 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494467 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194468 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374469}
4470
[email protected]e7e4f3c2009-04-21 15:24:084471// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264472//
[email protected]c20210e62009-04-03 21:39:264473// The time points we keep are
4474// request: time document was requested by user
4475// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254476// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294477// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264478// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294479// first_paint: first paint performed
4480// first_paint_after_load: first paint performed after load is finished
4481// begin: request if it was user requested, start otherwise
4482//
[email protected]e7e4f3c2009-04-21 15:24:084483// It's possible for the request time not to be set, if a client
4484// redirect had been done (the user never requested the page)
4485// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294486// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264487void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504488 // Configuration for PLT related histograms.
4489 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4490 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4491 static const size_t kPLTCount(100);
4492 #define PLT_HISTOGRAM(name, sample) \
4493 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4494
[email protected]26aa0482009-09-30 16:55:274495 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564496 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454497 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564498
[email protected]f9f4841b2010-03-20 05:41:424499 // If we've already dumped, do nothing.
4500 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294501 return;
[email protected]cf9a7bc2010-06-11 18:54:504502
4503 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454504 Time start = navigation_state->start_load_time();
4505 if (start.is_null())
4506 return; // Probably very premature abandonment of page.
4507 Time commit = navigation_state->commit_load_time();
4508 if (commit.is_null())
4509 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504510
[email protected]b855ebe62010-05-12 23:01:454511 // We properly handle null values for the next 3 variables.
4512 Time request = navigation_state->request_time();
4513 Time first_paint = navigation_state->first_paint_time();
4514 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454515 Time finish = navigation_state->finish_load_time();
4516 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564517
[email protected]f9f4841b2010-03-20 05:41:424518 // Handle case where user hits "stop" or "back" before loading completely.
4519 bool abandoned_page = finish.is_null();
4520 if (abandoned_page) {
4521 finish = Time::Now();
4522 navigation_state->set_finish_load_time(finish);
4523 }
[email protected]f9f4841b2010-03-20 05:41:424524
[email protected]cf9a7bc2010-06-11 18:54:504525 if (finish_doc.is_null()) {
4526 DCHECK(abandoned_page); // how can the doc have finished but not the page?
4527 if (!abandoned_page)
4528 return; // Don't try to record a stat which is broken.
4529 finish_doc = finish;
4530 navigation_state->set_finish_document_load_time(finish_doc);
4531 }
4532
4533 // Note: Client side redirects will have no request time.
4534 Time begin = request.is_null() ? start : request;
4535 TimeDelta begin_to_finish_doc = finish_doc - begin;
4536 TimeDelta begin_to_finish = finish - begin;
4537 TimeDelta start_to_finish = finish - start;
[email protected]ef1d8d322010-06-13 18:31:254538 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424539
[email protected]a7ccc4d2010-01-27 08:14:484540 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504541
4542 // Aggregate PLT data across all link types.
4543 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4544 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4545 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254546 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504547 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
4548 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish - finish_doc);
4549 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
4550 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish);
4551 if (!request.is_null()) {
4552 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
4553 PLT_HISTOGRAM("PLT.RequestToFinish", finish - request);
4554 }
4555 PLT_HISTOGRAM("PLT.CommitToFinish", finish - commit);
4556 if (!first_paint.is_null()) {
4557 DCHECK(begin <= first_paint);
4558 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4559 DCHECK(commit <= first_paint);
4560 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4561 }
4562 if (!first_paint_after_load.is_null()) {
4563 DCHECK(begin <= first_paint_after_load);
4564 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4565 first_paint_after_load - begin);
4566 DCHECK(commit <= first_paint_after_load);
4567 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4568 first_paint_after_load - commit);
4569 DCHECK(finish <= first_paint_after_load);
4570 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
4571 first_paint_after_load - finish);
4572 }
4573 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
4574 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish);
4575
4576 // Load type related histograms.
4577 switch (load_type) {
4578 case NavigationState::UNDEFINED_LOAD:
4579 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
4580 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish);
4581 break;
4582 case NavigationState::RELOAD:
4583 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
4584 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish);
4585 break;
4586 case NavigationState::HISTORY_LOAD:
4587 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
4588 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish);
4589 break;
4590 case NavigationState::NORMAL_LOAD:
4591 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
4592 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish);
4593 break;
4594 case NavigationState::LINK_LOAD_NORMAL:
4595 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4596 begin_to_finish_doc);
4597 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", begin_to_finish);
4598 break;
4599 case NavigationState::LINK_LOAD_RELOAD:
4600 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4601 begin_to_finish_doc);
4602 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", begin_to_finish);
4603 break;
4604 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4605 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4606 begin_to_finish_doc);
4607 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", begin_to_finish);
4608 break;
4609 case NavigationState::LINK_LOAD_CACHE_ONLY:
4610 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4611 begin_to_finish_doc);
4612 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", begin_to_finish);
4613 break;
4614 default:
4615 break;
4616 }
4617
4618 // Histograms to determine if DNS prefetching has an impact on PLT.
4619 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4620 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4621 if (use_dns_histogram) {
4622 UMA_HISTOGRAM_ENUMERATION(
4623 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4624 abandoned_page ? 1 : 0, 2);
4625 UMA_HISTOGRAM_ENUMERATION(
4626 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4627 load_type, NavigationState::kLoadTypeMax);
4628 switch (load_type) {
4629 case NavigationState::NORMAL_LOAD:
4630 PLT_HISTOGRAM(FieldTrial::MakeName(
4631 "PLT.BeginToFinish_NormalLoad", "DnsImpact"), begin_to_finish);
4632 break;
4633 case NavigationState::LINK_LOAD_NORMAL:
4634 PLT_HISTOGRAM(FieldTrial::MakeName(
4635 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4636 begin_to_finish);
4637 break;
4638 case NavigationState::LINK_LOAD_RELOAD:
4639 PLT_HISTOGRAM(FieldTrial::MakeName(
4640 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
4641 begin_to_finish);
4642 break;
4643 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4644 PLT_HISTOGRAM(FieldTrial::MakeName(
4645 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4646 begin_to_finish);
4647 break;
4648 default:
4649 break;
4650 }
4651 }
4652
4653 // Histograms to determine if the number of connections has an
4654 // impact on PLT.
4655 // TODO(jar): Consider removing the per-link-type versions. We
4656 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
4657 static bool use_conn_impact_histogram(
4658 FieldTrialList::Find("ConnCountImpact") &&
4659 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
4660 if (use_conn_impact_histogram) {
4661 UMA_HISTOGRAM_ENUMERATION(
4662 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
4663 abandoned_page ? 1 : 0, 2);
4664 switch (load_type) {
4665 case NavigationState::NORMAL_LOAD:
4666 PLT_HISTOGRAM(FieldTrial::MakeName(
4667 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
4668 begin_to_finish);
4669 break;
4670 case NavigationState::LINK_LOAD_NORMAL:
4671 PLT_HISTOGRAM(FieldTrial::MakeName(
4672 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
4673 begin_to_finish);
4674 break;
4675 case NavigationState::LINK_LOAD_RELOAD:
4676 PLT_HISTOGRAM(FieldTrial::MakeName(
4677 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
4678 begin_to_finish);
4679 break;
4680 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4681 PLT_HISTOGRAM(FieldTrial::MakeName(
4682 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
4683 begin_to_finish);
4684 break;
4685 default:
4686 break;
4687 }
4688 }
4689
[email protected]78a258a2010-08-02 16:34:264690 // Histograms to determine effect of idle socket timeout.
[email protected]241c5c2c2010-06-21 18:46:004691 static bool use_idle_socket_timeout_histogram(
4692 FieldTrialList::Find("IdleSktToImpact") &&
4693 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
4694 if (use_idle_socket_timeout_histogram) {
4695 UMA_HISTOGRAM_ENUMERATION(
4696 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
4697 abandoned_page ? 1 : 0, 2);
4698 switch (load_type) {
4699 case NavigationState::NORMAL_LOAD:
4700 PLT_HISTOGRAM(FieldTrial::MakeName(
4701 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
4702 begin_to_finish);
4703 break;
4704 case NavigationState::LINK_LOAD_NORMAL:
4705 PLT_HISTOGRAM(FieldTrial::MakeName(
4706 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
4707 begin_to_finish);
4708 break;
4709 case NavigationState::LINK_LOAD_RELOAD:
4710 PLT_HISTOGRAM(FieldTrial::MakeName(
4711 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
4712 begin_to_finish);
4713 break;
4714 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4715 PLT_HISTOGRAM(FieldTrial::MakeName(
4716 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
4717 begin_to_finish);
4718 break;
4719 default:
4720 break;
4721 }
4722 }
4723
[email protected]78a258a2010-08-02 16:34:264724 // Histograms to determine effect of number of connections per proxy.
4725 static bool use_proxy_connection_impact_histogram(
4726 FieldTrialList::Find("ProxyConnectionImpact") &&
4727 !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty());
4728 if (use_proxy_connection_impact_histogram) {
4729 UMA_HISTOGRAM_ENUMERATION(
4730 FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"),
4731 abandoned_page ? 1 : 0, 2);
4732 switch (load_type) {
4733 case NavigationState::NORMAL_LOAD:
4734 PLT_HISTOGRAM(FieldTrial::MakeName(
4735 "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"),
4736 begin_to_finish);
4737 break;
4738 case NavigationState::LINK_LOAD_NORMAL:
4739 PLT_HISTOGRAM(FieldTrial::MakeName(
4740 "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"),
4741 begin_to_finish);
4742 break;
4743 case NavigationState::LINK_LOAD_RELOAD:
4744 PLT_HISTOGRAM(FieldTrial::MakeName(
4745 "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"),
4746 begin_to_finish);
4747 break;
4748 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4749 PLT_HISTOGRAM(FieldTrial::MakeName(
4750 "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"),
4751 begin_to_finish);
4752 break;
4753 default:
4754 break;
4755 }
4756 }
4757
[email protected]cf9a7bc2010-06-11 18:54:504758 // Histograms to determine if SDCH has an impact.
4759 // TODO(jar): Consider removing per-link load types and the enumeration.
4760 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4761 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4762 if (use_sdch_histogram) {
4763 UMA_HISTOGRAM_ENUMERATION(
4764 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
4765 load_type, NavigationState::kLoadTypeMax);
4766 switch (load_type) {
4767 case NavigationState::NORMAL_LOAD:
4768 PLT_HISTOGRAM(FieldTrial::MakeName(
4769 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
4770 begin_to_finish);
4771 break;
4772 case NavigationState::LINK_LOAD_NORMAL:
4773 PLT_HISTOGRAM(FieldTrial::MakeName(
4774 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4775 begin_to_finish);
4776 break;
4777 case NavigationState::LINK_LOAD_RELOAD:
4778 PLT_HISTOGRAM(FieldTrial::MakeName(
4779 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4780 begin_to_finish);
4781 break;
4782 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4783 PLT_HISTOGRAM(FieldTrial::MakeName(
4784 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4785 begin_to_finish);
4786 break;
4787 case NavigationState::LINK_LOAD_CACHE_ONLY:
4788 PLT_HISTOGRAM(FieldTrial::MakeName(
4789 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4790 begin_to_finish);
4791 break;
4792 default:
4793 break;
4794 }
4795 }
4796
4797 // Histograms to determine if cache size has an impact on PLT.
4798 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4799 !FieldTrialList::Find("CacheSize")->group_name().empty());
4800 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4801 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
4802 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
4803 // StartToFinish or BeginToFinish would be better.
4804 PLT_HISTOGRAM(FieldTrial::MakeName(
4805 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
4806 }
4807
[email protected]115f5542010-07-28 06:48:214808
4809 GURL url = GURL(main_frame->url());
4810
4811 // Histograms to determine if SPDY has an impact for https traffic.
[email protected]cf9a7bc2010-06-11 18:54:504812 // TODO(mbelshe): After we've seen the difference between BeginToFinish
4813 // and StartToFinish, consider removing one or the other.
4814 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
4815 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]115f5542010-07-28 06:48:214816 if (use_spdy_histogram && url.SchemeIs("https") &&
4817 navigation_state->was_npn_negotiated()) {
[email protected]30b35882010-06-14 21:21:014818 UMA_HISTOGRAM_ENUMERATION(
4819 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
4820 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:504821 switch (load_type) {
4822 case NavigationState::LINK_LOAD_NORMAL:
4823 PLT_HISTOGRAM(FieldTrial::MakeName(
4824 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4825 begin_to_finish);
4826 PLT_HISTOGRAM(FieldTrial::MakeName(
4827 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4828 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254829 PLT_HISTOGRAM(FieldTrial::MakeName(
4830 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4831 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504832 break;
4833 case NavigationState::NORMAL_LOAD:
4834 PLT_HISTOGRAM(FieldTrial::MakeName(
4835 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4836 begin_to_finish);
4837 PLT_HISTOGRAM(FieldTrial::MakeName(
4838 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4839 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254840 PLT_HISTOGRAM(FieldTrial::MakeName(
4841 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
4842 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504843 break;
4844 default:
4845 break;
4846 }
4847 }
4848
[email protected]115f5542010-07-28 06:48:214849 // Histograms to compare the impact of alternate protocol over http traffic:
4850 // when spdy is used vs. when http is used.
4851 if (url.SchemeIs("http") &&
4852 navigation_state->was_alternate_protocol_available()) {
[email protected]193b0b892010-06-26 03:57:574853 if (!navigation_state->was_npn_negotiated()) {
4854 // This means that even there is alternate protocols for npn_http or
4855 // npn_spdy, they are not taken (due to the fieldtrial).
4856 switch (load_type) {
4857 case NavigationState::LINK_LOAD_NORMAL:
4858 PLT_HISTOGRAM(
4859 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
4860 start_to_finish);
4861 PLT_HISTOGRAM(
4862 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
4863 start_to_commit);
4864 break;
4865 case NavigationState::NORMAL_LOAD:
4866 PLT_HISTOGRAM(
4867 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
4868 start_to_finish);
4869 PLT_HISTOGRAM(
4870 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
4871 start_to_commit);
4872 break;
4873 default:
4874 break;
4875 }
4876 } else if (navigation_state->was_fetched_via_spdy()) {
4877 switch (load_type) {
4878 case NavigationState::LINK_LOAD_NORMAL:
4879 PLT_HISTOGRAM(
4880 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
4881 start_to_finish);
4882 PLT_HISTOGRAM(
4883 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
4884 start_to_commit);
4885 break;
4886 case NavigationState::NORMAL_LOAD:
4887 PLT_HISTOGRAM(
4888 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
4889 start_to_finish);
4890 PLT_HISTOGRAM(
4891 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
4892 start_to_commit);
4893 break;
4894 default:
4895 break;
4896 }
4897 }
4898 }
4899
[email protected]cf9a7bc2010-06-11 18:54:504900 // Record page load time and abandonment rates for proxy cases.
[email protected]cf9a7bc2010-06-11 18:54:504901 if (navigation_state->was_fetched_via_proxy()) {
4902 if (url.SchemeIs("https")) {
4903 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish);
4904 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
4905 abandoned_page ? 1 : 0, 2);
4906 } else {
4907 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish);
4908 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
4909 abandoned_page ? 1 : 0, 2);
4910 }
4911 } else {
4912 if (url.SchemeIs("https")) {
4913 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", start_to_finish);
4914 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
4915 abandoned_page ? 1 : 0, 2);
4916 } else {
4917 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", start_to_finish);
4918 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
4919 abandoned_page ? 1 : 0, 2);
4920 }
4921 }
[email protected]a7ccc4d2010-01-27 08:14:484922
[email protected]ab9eabac2010-03-16 16:54:104923 // Site isolation metrics.
4924 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4925 cross_origin_access_count_);
4926 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4927 same_origin_access_count_);
4928
[email protected]cf9a7bc2010-06-11 18:54:504929 // Log some PLT data to the error log.
4930 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294931
4932 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414933
4934 // Since there are currently no guarantees that renderer histograms will be
4935 // sent to the browser, we initiate a PostTask here to be sure that we send
4936 // the histograms we generated. Without this call, pages that don't have an
4937 // on-close-handler might generate data that is lost when the renderer is
4938 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484939 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4940 // should post when the onload is complete, so that it doesn't interfere with
4941 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414942 if (RenderThread::current()) {
4943 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134944 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414945 }
[email protected]c20210e62009-04-03 21:39:264946}
[email protected]e846d0d2009-05-20 00:53:064947
[email protected]f8999642009-10-27 21:39:424948void RenderView::LogNavigationState(const NavigationState* state,
4949 const WebDataSource* ds) const {
4950 // Because this function gets called on every page load,
4951 // take extra care to optimize it away if logging is turned off.
4952 if (logging::LOG_INFO < logging::GetMinLogLevel())
4953 return;
4954
4955 DCHECK(state);
4956 DCHECK(ds);
4957 GURL url(ds->request().url());
4958 Time start = state->start_load_time();
4959 Time finish = state->finish_load_time();
4960 // TODO(mbelshe): should we log more stats?
4961 LOG(INFO) << "PLT: "
4962 << (finish - start).InMilliseconds()
4963 << "ms "
4964 << url.spec();
4965}
4966
[email protected]cc0445f2009-10-13 16:09:084967void RenderView::focusAccessibilityObject(
4968 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064969#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154970 // TODO(dglazkov): Current logic implies that focus change can only be made
4971 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4972 // where accessibility is initialized. We should determine whether that's
4973 // right.
4974 if (!accessibility_.get())
4975 return;
[email protected]e846d0d2009-05-20 00:53:064976
4977 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154978 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064979
4980 // If id is valid, alert the browser side that an accessibility focus change
4981 // occurred.
4982 if (acc_obj_id >= 0)
4983 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4984
4985#else // defined(OS_WIN)
4986 // TODO(port): accessibility not yet implemented
4987 NOTIMPLEMENTED();
4988#endif
4989}
[email protected]daa8c58e2009-06-15 17:21:104990
[email protected]a3018be2010-03-09 04:28:484991void RenderView::didChangeAccessibilityObjectState(
4992 const WebKit::WebAccessibilityObject& acc_obj) {
4993#if defined(OS_WIN)
4994 // TODO(dglazkov): Current logic implies that a state change can only be made
4995 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4996 // where accessibility is initialized. We should determine whether that's
4997 // right.
4998 if (!accessibility_.get())
4999 return;
5000
5001 // Retrieve the accessibility object id of the AccessibilityObject.
5002 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
5003
5004 // If id is valid, alert the browser side that an accessibility object state
5005 // change occurred.
5006 if (acc_obj_id >= 0)
5007 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
5008 acc_obj_id));
5009
5010#else // defined(OS_WIN)
5011 // TODO(port): accessibility not yet implemented
5012 NOTIMPLEMENTED();
5013#endif
5014}
5015
[email protected]0fda7272009-06-26 15:49:335016void RenderView::Print(WebFrame* frame, bool script_initiated) {
5017 DCHECK(frame);
5018 if (print_helper_.get() == NULL) {
5019 print_helper_.reset(new PrintWebViewHelper(this));
5020 }
5021 print_helper_->Print(frame, script_initiated);
5022}
[email protected]446705872009-09-10 07:22:485023
5024void RenderView::OnSetEditCommandsForNextKeyEvent(
5025 const EditCommands& edit_commands) {
5026 edit_commands_ = edit_commands;
5027}
5028
[email protected]61f5a7b2009-12-22 22:21:205029void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275030 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355031 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205032 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5033 false));
[email protected]912256b32009-09-18 09:47:355034 return;
5035 }
5036
[email protected]fa7b6b542009-11-03 05:02:305037 WebDataSource* ds = main_frame->dataSource();
5038 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5039 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205040 pending_code_execution_queue_.push(
5041 linked_ptr<ViewMsg_ExecuteCode_Params>(
5042 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305043 return;
5044 }
5045
[email protected]61f5a7b2009-12-22 22:21:205046 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305047}
5048
5049void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205050 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485051 // Don't execute scripts in gallery pages.
5052 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085053 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5054 && !CommandLine::ForCurrentProcess()->HasSwitch(
5055 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485056 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5057 return;
5058 }
5059
[email protected]20ad2692009-11-20 18:27:205060 std::vector<WebFrame*> frame_vector;
5061 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205062 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205063 GetAllChildFrames(frame, &frame_vector);
5064
5065 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5066 frame_it != frame_vector.end(); ++frame_it) {
5067 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205068 if (params.is_javascript) {
5069 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5070 continue;
5071
[email protected]20ad2692009-11-20 18:27:205072 std::vector<WebScriptSource> sources;
5073 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205074 WebScriptSource(WebString::fromUTF8(params.code)));
5075 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205076 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205077 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205078 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5079 } else {
[email protected]61f5a7b2009-12-22 22:21:205080 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205081 }
[email protected]912256b32009-09-18 09:47:355082 }
5083
[email protected]61f5a7b2009-12-22 22:21:205084 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355085}
5086
[email protected]60c42a8c72009-10-09 04:08:595087void RenderView::Close() {
5088 // We need to grab a pointer to the doomed WebView before we destroy it.
5089 WebView* doomed = webview();
5090 RenderWidget::Close();
5091 Singleton<ViewMap>::get()->erase(doomed);
5092}
5093
[email protected]446705872009-09-10 07:22:485094void RenderView::DidHandleKeyEvent() {
5095 edit_commands_.clear();
5096}
5097
[email protected]941e4552010-02-01 21:23:435098#if defined(OS_MACOSX)
5099void RenderView::OnWasHidden() {
5100 RenderWidget::OnWasHidden();
5101
5102 // Inform plugins that their container is no longer visible.
5103 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5104 for (plugin_it = plugin_delegates_.begin();
5105 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5106 (*plugin_it)->SetContainerVisibility(false);
5107 }
5108}
5109
5110void RenderView::OnWasRestored(bool needs_repainting) {
5111 RenderWidget::OnWasRestored(needs_repainting);
5112
5113 // Inform plugins that their container is now visible.
5114 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5115 for (plugin_it = plugin_delegates_.begin();
5116 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5117 (*plugin_it)->SetContainerVisibility(true);
5118 }
5119}
[email protected]1e6e3c992010-02-08 15:52:135120
5121void RenderView::OnSetFocus(bool enable) {
5122 RenderWidget::OnSetFocus(enable);
5123
[email protected]7d3c02c2010-05-05 23:10:315124 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135125 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5126 for (plugin_it = plugin_delegates_.begin();
5127 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315128 // RenderWidget's call to setFocus can cause the underlying webview's
5129 // activation state to change just like a call to setIsActive.
5130 if (enable)
5131 (*plugin_it)->SetWindowFocus(true);
5132 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135133 }
5134 }
5135}
[email protected]941e4552010-02-01 21:23:435136#endif // OS_MACOSX
5137
[email protected]83dde542009-09-11 20:59:555138void RenderView::EnsureDocumentTag() {
5139 // TODO(darin): There's actually no reason for this to be here. We should
5140 // have the browser side manage the document tag.
5141#if defined(OS_MACOSX)
5142 if (!has_document_tag_) {
5143 // Make the call to get the tag.
5144 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5145 has_document_tag_ = true;
5146 }
5147#endif
5148}
[email protected]12636df2009-09-28 22:32:215149
[email protected]43f28f832010-02-03 02:28:485150#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035151gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
5152 bool opaque) {
[email protected]43f28f832010-02-03 02:28:485153 gfx::PluginWindowHandle window = NULL;
5154 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]ea04a4e12010-04-15 00:58:035155 routing_id(), opaque, &window));
[email protected]43f28f832010-02-03 02:28:485156 return window;
5157}
5158
5159void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5160 if (window)
5161 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5162}
5163
[email protected]44ce0b12010-03-12 16:45:335164void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5165 int32 width,
5166 int32 height,
5167 uint64 io_surface_identifier) {
5168 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485169 routing_id(), window, width, height, io_surface_identifier));
5170}
5171
[email protected]44ce0b12010-03-12 16:45:335172void RenderView::AcceleratedSurfaceSetTransportDIB(
5173 gfx::PluginWindowHandle window,
5174 int32 width,
5175 int32 height,
5176 TransportDIB::Handle transport_dib) {
5177 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075178 routing_id(), window, width, height, transport_dib));
5179}
5180
[email protected]44ce0b12010-03-12 16:45:335181TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5182 size_t size) {
[email protected]1aef98132010-02-23 18:00:075183 TransportDIB::Handle dib_handle;
5184 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385185 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075186 return dib_handle;
5187 // Return an invalid handle if Send() fails.
5188 return TransportDIB::DefaultHandleValue();
5189}
5190
[email protected]44ce0b12010-03-12 16:45:335191void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075192 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5193}
5194
[email protected]44ce0b12010-03-12 16:45:335195void RenderView::AcceleratedSurfaceBuffersSwapped(
5196 gfx::PluginWindowHandle window) {
5197 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485198}
5199#endif
[email protected]58c321d2010-02-19 12:11:285200
[email protected]cdaf8d02010-03-30 19:52:475201bool RenderView::ScheduleFileChooser(
5202 const ViewHostMsg_RunFileChooser_Params& params,
5203 WebFileChooserCompletion* completion) {
5204 static const size_t kMaximumPendingFileChooseRequests = 4;
5205 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5206 // This sanity check prevents too many file choose requests from getting
5207 // queued which could DoS the user. Getting these is most likely a
5208 // programming error (there are many ways to DoS the user so it's not
5209 // considered a "real" security check), either in JS requesting many file
5210 // choosers to pop up, or in a plugin.
5211 //
5212 // TODO(brettw) we might possibly want to require a user gesture to open
5213 // a file picker, which will address this issue in a better way.
5214 return false;
5215 }
5216
5217 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5218 new PendingFileChooser(params, completion)));
5219 if (file_chooser_completions_.size() == 1) {
5220 // Actually show the browse dialog when this is the first request.
5221 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5222 }
5223 return true;
5224}
5225
[email protected]290838a2010-04-27 17:37:015226void RenderView::OnPageTranslated() {
5227 WebFrame* frame = webview()->mainFrame();
5228 if (!frame)
5229 return;
5230
5231 // The page is translated, so try to extract the form data again.
[email protected]679f128f2010-07-22 22:57:445232 autofill_helper_.FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015233}
5234
[email protected]8a5f7002010-03-31 13:47:355235WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285236 if (!geolocation_dispatcher_.get())
5237 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5238 return geolocation_dispatcher_.get();
5239}
[email protected]61c9f032010-03-31 23:04:195240
[email protected]8079b362010-05-07 18:37:455241bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195242 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455243 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195244 if (frame->parent() != NULL)
5245 return false;
5246
5247 // Skip if navigation is on the same page (using '#').
5248 GURL frame_origin = GURL(frame->url()).GetOrigin();
5249 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5250 // The link click could stay on the same page, in cases where it sends some
5251 // parameters to the same URL.
5252 if (type == WebKit::WebNavigationTypeLinkClicked)
5253 return true;
5254
5255 if (last_top_level_navigation_page_id_ != page_id_ &&
5256 // Not interested in reloads.
5257 type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015258 type != WebKit::WebNavigationTypeFormSubmitted &&
5259 type != WebKit::WebNavigationTypeBackForward) {
[email protected]61c9f032010-03-31 23:04:195260 return true;
5261 }
5262 }
[email protected]d0ed50d2010-06-22 01:01:325263 // Not interested in reloads.
5264 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015265 type != WebKit::WebNavigationTypeFormSubmitted &&
5266 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325267 // The opener relationship between the new window and the parent allows the
5268 // new window to script the parent and vice versa. This is not allowed if
5269 // the origins of the two domains are different. This can be treated as a
5270 // top level navigation and routed back to the host.
5271 WebKit::WebFrame* opener = frame->opener();
5272 if (opener) {
5273 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5274 return true;
5275 }
5276 }
[email protected]61c9f032010-03-31 23:04:195277 return false;
5278}