blob: ac7d9b52337532f2bf020686427e1fb9149dffde [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]a92b8642009-05-05 23:38:5611#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3112#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1113#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5914#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5016#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0517#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2318#include "base/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5321#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2324#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5725#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2126#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2830#include "chrome/common/chrome_paths.h"
31#include "chrome/common/chrome_switches.h"
[email protected]d146b832009-12-23 02:45:4832#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1734#include "chrome/common/page_zoom.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]e4ac5df2009-03-17 15:33:1142#include "chrome/renderer/devtools_agent.h"
43#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3544#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3245#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3546#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3747#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2848#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5650#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1151#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5652#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1253#include "chrome/renderer/notification_provider.h"
[email protected]53af1d62010-05-14 03:40:2654#include "chrome/renderer/pepper_plugin_registry.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]035545f2010-04-09 13:10:2159#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3460#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4661#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3562#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2964#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2965#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4266#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5667#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1568#include "gfx/color_utils.h"
69#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5770#include "gfx/native_widget_types.h"
[email protected]34ac8f32009-02-22 23:03:2771#include "grit/generated_resources.h"
72#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3473#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2974#include "net/base/escape.h"
75#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0076#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1077#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3078#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]d9ec5c0f2009-12-23 11:55:0780#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4981#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3283#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4984#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3585#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5986#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4987#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
88#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4190#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5091#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4992#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3293#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0794#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4995#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]b4f68dea2010-05-13 06:03:1796#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:4997#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4998#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34105#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49106#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
107#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
108#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
109#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
110#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
111#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]534c66c2010-04-28 22:53:11112#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04113#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29114#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29115#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59116#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24117#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24118#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34119#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17120#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51121#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09122#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29123#include "webkit/glue/password_form.h"
[email protected]b4f68dea2010-05-13 06:03:17124#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29125#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30126#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23127#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30128#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]85cc78c2010-05-04 18:30:09129#include "webkit/glue/site_isolation_metrics.h"
initial.commit09911bf2008-07-26 23:55:29130#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29131#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17132#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29133
[email protected]6c8afae52009-01-22 02:24:57134#if defined(OS_WIN)
135// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57136// * theming
[email protected]cd818412010-03-19 03:23:15137#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03138#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46139#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33140#elif defined(OS_MACOSX)
141#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57142#endif
143
[email protected]80f584d92010-01-21 03:59:04144using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26145using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33146using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45147using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59148using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24149using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17150using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56151using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10152using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09153using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15154using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08155using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21156using WebKit::WebApplicationCacheHost;
157using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41158using WebKit::WebColor;
159using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59160using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44161using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51162using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07163using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55164using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28165using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29166using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00167using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58168using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25169using WebKit::WebDragOperation;
170using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51171using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47172using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49173using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59174using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48175using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45176using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17177using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41178using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50179using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17180using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28181using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17182using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28183using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28184using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51185using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07186using WebKit::WebPageSerializer;
187using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17188using WebKit::WebPlugin;
189using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49190using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52191using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59192using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51193using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52194using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40195using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35196using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29197using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59198using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42199using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02200using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34201using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28202using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51203using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52204using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28205using WebKit::WebURL;
206using WebKit::WebURLError;
207using WebKit::WebURLRequest;
208using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28209using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03210using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28211using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43212using WebKit::WebWorker;
213using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11214using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33215
initial.commit09911bf2008-07-26 23:55:29216//-----------------------------------------------------------------------------
217
218// define to write the time necessary for thumbnail/DOM text retrieval,
219// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29220// #define TIME_TEXT_RETRIEVAL
221
222// maximum number of characters in the document to index, any text beyond this
223// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57224static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29225
226// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37227static const int kThumbnailWidth = 212;
228static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29229
230// Delay in milliseconds that we'll wait before capturing the page contents
231// and thumbnail.
232static const int kDelayForCaptureMs = 500;
233
234// Typically, we capture the page data once the page is loaded.
235// Sometimes, the page never finishes to load, preventing the page capture
236// To workaround this problem, we always perform a capture after the following
237// delay.
238static const int kDelayForForcedCaptureMs = 6000;
239
[email protected]882daa92009-11-05 16:31:31240// Time, in seconds, we delay before sending content state changes (such as form
241// state and scroll position) to the browser. We delay sending changes to avoid
242// spamming the browser.
243// To avoid having tab/session restore require sending a message to get the
244// current content state during tab closing we use a shorter timeout for the
245// foreground renderer. This means there is a small window of time from which
246// content state is modified and not sent to session restore, but this is
247// better than having to wake up all renderers during shutdown.
248static const int kDelaySecondsForContentStateSyncHidden = 5;
249static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29250
[email protected]0aa55312008-10-17 21:53:08251// The maximum number of popups that can be spawned from one page.
252static const int kMaximumNumberOfUnacknowledgedPopups = 25;
253
initial.commit09911bf2008-07-26 23:55:29254static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16255 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29256
[email protected]50b691c2008-10-31 19:08:35257static const char* const kBackForwardNavigationScheme = "history";
258
[email protected]d64b07b2010-04-20 22:14:06259// static
260const char* const RenderView::kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13261
[email protected]726985e22009-06-18 21:09:28262static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
263 WebVector<WebURL> urls;
264 ds->redirectChain(urls);
265 result->reserve(urls.size());
266 for (size_t i = 0; i < urls.size(); ++i)
267 result->push_back(urls[i]);
268}
269
[email protected]61f5a7b2009-12-22 22:21:20270static bool UrlMatchesPermissions(
271 const GURL& url, const std::vector<URLPattern>& host_permissions) {
272 for (size_t i = 0; i < host_permissions.size(); ++i) {
273 if (host_permissions[i].MatchesUrl(url))
274 return true;
275 }
276
277 return false;
278}
279
[email protected]30507922010-01-15 16:48:23280static bool PaintViewIntoCanvas(WebView* view,
281 skia::PlatformCanvas& canvas) {
282 view->layout();
283 const WebSize& size = view->size();
284
285 if (!canvas.initialize(size.width, size.height, true))
286 return false;
287
288 view->paint(webkit_glue::ToWebCanvas(&canvas),
289 WebRect(0, 0, size.width, size.height));
290 // TODO: Add a way to snapshot the whole page, not just the currently
291 // visible part.
292
293 return true;
294}
295
296// Calculates how "boring" a thumbnail is. The boring score is the
297// 0,1 ranged percentage of pixels that are the most common
298// luma. Higher boring scores indicate that a higher percentage of a
299// bitmap are all the same brightness.
300static double CalculateBoringScore(SkBitmap* bitmap) {
301 int histogram[256] = {0};
302 color_utils::BuildLumaHistogram(bitmap, histogram);
303
304 int color_count = *std::max_element(histogram, histogram + 256);
305 int pixel_count = bitmap->width() * bitmap->height();
306 return static_cast<double>(color_count) / pixel_count;
307}
308
[email protected]12bc8472010-04-15 07:29:40309// True if |frame| contains content that is white-listed for content settings.
310static bool IsWhitelistedForContentSettings(WebFrame* frame) {
311 WebSecurityOrigin origin = frame->securityOrigin();
312 if (origin.isEmpty())
313 return false; // Uninitialized document?
314
315 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
316 return true; // Browser UI elements should still work.
317
318 // If the scheme is ftp: or file:, an empty file name indicates a directory
319 // listing, which requires JavaScript to function properly.
320 GURL frame_url = frame->url();
321 const char* kDirProtocols[] = { "ftp", "file" };
322 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
323 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
324 return frame_url.SchemeIs(kDirProtocols[i]) &&
325 frame_url.ExtractFileName().empty();
326 }
327 }
328
329 return false;
330}
331
[email protected]3a8eecb2010-04-22 23:56:30332// Returns true if the frame is navigating to an URL either into or out of an
333// extension app's extent.
334static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
335 if (!RenderThread::current())
336 return false;
337
338 // If the URL is still empty, this is a window.open navigation. Check the
339 // opener's URL.
340 GURL old_url(frame->url());
341 if (old_url.is_empty() && frame->opener())
342 old_url = frame->opener()->url();
343
344 std::string old_extension =
345 RenderThread::current()->GetExtensionIdForURL(old_url);
346 std::string new_extension =
347 RenderThread::current()->GetExtensionIdForURL(new_url);
348 return (old_extension != new_extension);
349}
350
initial.commit09911bf2008-07-26 23:55:29351///////////////////////////////////////////////////////////////////////////////
352
[email protected]60c42a8c72009-10-09 04:08:59353int32 RenderView::next_page_id_ = 1;
354
[email protected]cdaf8d02010-03-30 19:52:47355struct RenderView::PendingFileChooser {
356 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
357 WebFileChooserCompletion* c)
358 : params(p),
359 completion(c) {
360 }
361 ViewHostMsg_RunFileChooser_Params params;
362 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
363};
364
[email protected]2fab253a2009-08-17 23:00:59365RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34366 const WebPreferences& webkit_preferences,
367 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12368 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]81e63782009-02-27 19:35:09369 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21370 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24371 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21372 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24373 page_id_(-1),
374 last_page_id_sent_to_browser_(-1),
375 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24376 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46377 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50378 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11379 devtools_agent_(NULL),
380 devtools_client_(NULL),
[email protected]3cc72b12010-03-18 23:03:00381 history_list_offset_(-1),
382 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24383 has_unload_listener_(false),
384 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39385 autofill_query_id_(0),
[email protected]e8345242010-05-06 03:00:40386 script_can_close_(true),
[email protected]8922e1f2009-10-03 05:01:26387 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31388 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25389 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26390 ALLOW_THIS_IN_INITIALIZER_LIST(
391 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53392 view_type_(ViewType::INVALID),
393 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55394 last_top_level_navigation_page_id_(-1),
395#if defined(OS_MACOSX)
396 has_document_tag_(false),
397#endif
[email protected]98324892009-09-09 21:16:05398 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32399 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34400 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ab9eabac2010-03-16 16:54:10401 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]85d252e2010-04-06 22:21:02402 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]ab9eabac2010-03-16 16:54:10403 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17404 same_origin_access_count_(0),
405 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]71b0d5d2010-02-15 05:43:07406 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29407}
408
409RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08410 if (decrement_shared_popup_at_destruction_)
411 shared_popup_counter_->data--;
412
[email protected]b0950a72009-09-29 23:16:17413 // Dispose of un-disposed image fetchers.
414 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
415 i != image_fetchers_.end(); ++i) {
416 delete *i;
417 }
418
[email protected]a1128322009-10-06 18:38:46419 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47420 while (!file_chooser_completions_.empty()) {
421 if (file_chooser_completions_.front()->completion) {
422 file_chooser_completions_.front()->completion->didChooseFile(
423 WebVector<WebString>());
424 }
425 file_chooser_completions_.pop_front();
426 }
[email protected]a1128322009-10-06 18:38:46427
[email protected]83dde542009-09-11 20:59:55428#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05429 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55430 if (has_document_tag_)
431 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
432#endif
[email protected]98324892009-09-09 21:16:05433
[email protected]5fb88962009-04-16 19:03:25434 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59435
436#ifndef NDEBUG
437 // Make sure we are no longer referenced by the ViewMap.
438 ViewMap* views = Singleton<ViewMap>::get();
439 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
440 DCHECK_NE(this, it->second) << "Failed to call Close?";
441#endif
442}
443
444/*static*/
445void RenderView::ForEach(RenderViewVisitor* visitor) {
446 ViewMap* views = Singleton<ViewMap>::get();
447 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
448 if (!visitor->Visit(it->second))
449 return;
450 }
451}
452
453/*static*/
454RenderView* RenderView::FromWebView(WebView* webview) {
455 ViewMap* views = Singleton<ViewMap>::get();
456 ViewMap::iterator it = views->find(webview);
457 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29458}
459
460/*static*/
[email protected]0aa55312008-10-17 21:53:08461RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24462 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15463 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08464 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51465 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08466 const WebPreferences& webkit_prefs,
467 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34468 int32 routing_id,
469 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29470 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34471 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
472 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29473 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29474 opener_id,
[email protected]80d96fa2009-06-10 22:34:51475 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08476 counter,
initial.commit09911bf2008-07-26 23:55:29477 routing_id); // adds reference
478 return view;
479}
480
481/*static*/
482void RenderView::SetNextPageID(int32 next_page_id) {
483 // This method should only be called during process startup, and the given
484 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05485 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29486 DCHECK(next_page_id >= next_page_id_);
487 next_page_id_ = next_page_id;
488}
489
[email protected]afe3a1672009-11-17 19:04:12490void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56491 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
492}
493
[email protected]a3a8fb6d2009-10-22 20:12:51494void RenderView::PluginCrashed(const FilePath& plugin_path) {
495 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29496}
497
[email protected]d8fd6fa2010-02-01 15:54:26498#if defined(OS_MACOSX)
499void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
500 plugin_delegates_.insert(delegate);
501}
502
503void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
504 plugin_delegates_.erase(delegate);
505}
506#endif
507
[email protected]18bcc3c2009-01-27 21:39:15508void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29509 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51510 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08511 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29512 int32 routing_id) {
513 DCHECK(!webview());
514
515 if (opener_id != MSG_ROUTING_NONE)
516 opener_id_ = opener_id;
517
[email protected]0aa55312008-10-17 21:53:08518 if (counter) {
519 shared_popup_counter_ = counter;
520 shared_popup_counter_->data++;
521 decrement_shared_popup_at_destruction_ = true;
522 } else {
523 shared_popup_counter_ = new SharedRenderViewCounter(0);
524 decrement_shared_popup_at_destruction_ = false;
525 }
526
[email protected]58bfc6b2009-06-24 09:45:02527 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04528
[email protected]50ae00ef2009-10-19 05:11:03529 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59530 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59531 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27532 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29533 webview()->setDevToolsAgent(
534 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29535
[email protected]d3ba77272009-09-03 00:06:09536 OnSetRendererPrefs(renderer_prefs);
537
initial.commit09911bf2008-07-26 23:55:29538 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24539 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29540 // Take a reference on behalf of the RenderThread. This will be balanced
541 // when we receive ViewMsg_Close.
542 AddRef();
543
544 // If this is a popup, we must wait for the CreatingNew_ACK message before
545 // completing initialization. Otherwise, we can finish it now.
546 if (opener_id == MSG_ROUTING_NONE) {
547 did_show_ = true;
548 CompleteInit(parent_hwnd);
549 }
550
551 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29552
[email protected]58bfc6b2009-06-24 09:45:02553 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09554 if (command_line.HasSwitch(switches::kDomAutomationController))
555 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29556
[email protected]5fb88962009-04-16 19:03:25557 audio_message_filter_ = new AudioMessageFilter(routing_id_);
558 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29559}
560
561void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27562 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27563 if (main_frame)
564 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26565
[email protected]b2abac72009-02-26 12:39:28566 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11567 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28568 return;
[email protected]b4b967e2009-04-22 11:33:05569 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
570 return;
[email protected]b6849bda2009-10-14 23:59:26571 if (notification_provider_->OnMessageReceived(message))
572 return;
[email protected]58c321d2010-02-19 12:11:28573 if (geolocation_dispatcher_.get() &&
574 geolocation_dispatcher_->OnMessageReceived(message)) {
575 return;
576 }
[email protected]b2abac72009-02-26 12:39:28577
initial.commit09911bf2008-07-26 23:55:29578 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29579 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23580 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29581 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01582 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29583 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
584 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56585 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29586 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
587 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
588 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
589 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27590#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35591 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27592#endif
initial.commit09911bf2008-07-26 23:55:29593 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
594 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05595 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
596 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
597 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04598 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29599 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
600 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
601 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15602 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29603 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49604 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
605 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17606 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54607 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
608 OnSetContentSettingsForLoadingURL)
609 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
610 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29611 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18612 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
613 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28614 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33615 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29616 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48617 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29618 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29619 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29620 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
621 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
622 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
623 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
624 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45625 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29626 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50627 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
628 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29629 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
630 OnDragSourceSystemDragEnded)
631 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29632 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
633 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
634 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
635 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
636 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
637 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29638 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
639 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04640 IPC_MESSAGE_HANDLER(
641 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
642 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29643 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
644 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
645 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
646 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45647 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
648 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08649 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
650 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24651 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
652 OnAutoFillSuggestionsReturned)
[email protected]cf28ec52010-04-09 22:56:34653 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillForms, OnAutoFillForms)
[email protected]95056b582010-02-18 01:29:24654 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
655 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48656 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
657 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40658 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
659 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00660 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27661 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37662 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
663 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16664 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14665 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25666 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
667 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10668 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
669 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51670 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53671 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
672 OnUpdateBrowserWindowId)
673 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
674 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56675 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34676 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14677#if defined(OS_MACOSX)
678 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13679 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14680#endif
[email protected]446705872009-09-10 07:22:48681 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33682 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35683 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
684 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33685 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
686 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42687 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02688 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09689 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36690 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
691 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
692 OnAccessibilityDoDefaultAction)
[email protected]634a6f92008-12-01 21:39:31693
initial.commit09911bf2008-07-26 23:55:29694 // Have the super handle all other messages.
695 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
696 IPC_END_MESSAGE_MAP()
697}
698
initial.commit09911bf2008-07-26 23:55:29699void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27700 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29701 if (!main_frame)
702 return;
703
704 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45705 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29706 if (url.is_empty())
707 return;
708
709 if (size_.IsEmpty())
710 return; // Don't create an empty thumbnail!
711
712 ThumbnailScore score;
713 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02714 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15715 &thumbnail, &score))
716 return;
717
initial.commit09911bf2008-07-26 23:55:29718 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46719 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29720}
721
[email protected]30507922010-01-15 16:48:23722void RenderView::SendSnapshot() {
723 SkBitmap snapshot;
724 bool error = false;
725
726 WebFrame* main_frame = webview()->mainFrame();
727 if (!main_frame)
728 error = true;
729
730 if (!error && !CaptureSnapshot(webview(), &snapshot))
731 error = true;
732
733 DCHECK(error == snapshot.empty()) <<
734 "Snapshot should be empty on error, non-empty otherwise.";
735
736 // Send the snapshot to the browser process.
737 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
738}
739
[email protected]068637222009-01-29 16:58:07740void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29741 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58742 if (webview()) {
743 // If the user has selected text in the currently focused frame we print
744 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27745 if (webview()->focusedFrame()->hasSelection())
746 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58747 else
[email protected]26aa0482009-09-30 16:55:27748 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58749 }
initial.commit09911bf2008-07-26 23:55:29750}
751
[email protected]82270452009-06-19 15:58:01752void RenderView::OnPrintingDone(int document_cookie, bool success) {
753 // Ignoring document cookie here since only one print job can be outstanding
754 // per renderer and document_cookie is 0 when printing is successful.
755 DCHECK(print_helper_.get());
756 if (print_helper_.get() != NULL) {
757 print_helper_->DidFinishPrinting(success);
758 }
759}
760
initial.commit09911bf2008-07-26 23:55:29761void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
762 if (load_id != page_id_)
763 return; // this capture call is no longer relevant due to navigation
764 if (load_id == last_indexed_page_id_)
765 return; // we already indexed this page
766
767 if (!webview())
768 return;
769
[email protected]26aa0482009-09-30 16:55:27770 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29771 if (!main_frame)
772 return;
773
774 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45775 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29776 return;
777
778 // Don't index/capture pages that failed to load. This only checks the top
779 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45780 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28781 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29782 return;
783
784 if (!preliminary_capture)
785 last_indexed_page_id_ = load_id;
786
[email protected]a8a81292010-01-21 00:32:45787 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45788 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29789 if (url.is_empty())
790 return;
791
[email protected]a8a81292010-01-21 00:32:45792 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29793 std::wstring contents;
794 CaptureText(main_frame, &contents);
795 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45796 base::TimeTicks begin_time = base::TimeTicks::Now();
797 std::string language = DetermineTextLanguage(contents);
798 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
799 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52800
[email protected]a8a81292010-01-21 00:32:45801 // Send the text to the browser for indexing (the browser might decide not
802 // to index, if the URL is HTTPS for instance) and language discovery.
803 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
804 language));
[email protected]5c4266922009-07-10 16:41:27805 }
806
initial.commit09911bf2008-07-26 23:55:29807 // thumbnail
808 SendThumbnail();
809}
810
811void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
812 contents->clear();
813 if (!frame)
814 return;
815
816#ifdef TIME_TEXT_RETRIEVAL
817 double begin = time_util::GetHighResolutionTimeNow();
818#endif
819
820 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45821 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29822
823#ifdef TIME_TEXT_RETRIEVAL
824 double end = time_util::GetHighResolutionTimeNow();
825 char buf[128];
826 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
827 contents.size(), (end - begin)*1000);
828 OutputDebugStringA(buf);
829#endif
830
831 // When the contents are clipped to the maximum, we don't want to have a
832 // partial word indexed at the end that might have been clipped. Therefore,
833 // terminate the string at the last space to ensure no words are clipped.
834 if (contents->size() == kMaxIndexChars) {
835 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
836 if (last_space_index == std::wstring::npos)
837 return; // don't index if we got a huge block of text with no spaces
838 contents->resize(last_space_index);
839 }
840}
841
[email protected]8649fb32009-06-26 17:51:02842bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29843 int w,
844 int h,
845 SkBitmap* thumbnail,
846 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23847 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15848
[email protected]8649fb32009-06-26 17:51:02849 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23850
851 // Paint |view| into |canvas|.
852 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02853 return false;
[email protected]8649fb32009-06-26 17:51:02854
855 skia::BitmapPlatformDevice& device =
856 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
857
858 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29859
[email protected]cab34d6a2009-09-24 01:14:52860 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29861 float dest_aspect = dest_rect.width() / dest_rect.height();
862
863 // Get the src rect so that we can preserve the aspect ratio while filling
864 // the destination.
865 SkIRect src_rect;
866 if (src_bmp.width() < dest_rect.width() ||
867 src_bmp.height() < dest_rect.height()) {
868 // Source image is smaller: we clip the part of source image within the
869 // dest rect, and then stretch it to fill the dest rect. We don't respect
870 // the aspect ratio in this case.
871 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
872 static_cast<S16CPU>(dest_rect.height()));
873 score->good_clipping = false;
874 } else {
875 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
876 if (src_aspect > dest_aspect) {
877 // Wider than tall, clip horizontally: we center the smaller thumbnail in
878 // the wider screen.
879 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
880 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
881 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
882 score->good_clipping = false;
883 } else {
884 src_rect.set(0, 0, src_bmp.width(),
885 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
886 score->good_clipping = true;
887 }
888 }
889
[email protected]26aa0482009-09-30 16:55:27890 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29891
892 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02893 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29894
895 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14896 *thumbnail = skia::ImageOperations::Resize(
897 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29898
899 score->boring_score = CalculateBoringScore(thumbnail);
900
[email protected]30507922010-01-15 16:48:23901 HISTOGRAM_TIMES("Renderer4.Thumbnail",
902 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15903 return true;
initial.commit09911bf2008-07-26 23:55:29904}
905
[email protected]30507922010-01-15 16:48:23906bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
907 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29908
[email protected]30507922010-01-15 16:48:23909 skia::PlatformCanvas canvas;
910 if (!PaintViewIntoCanvas(view, canvas))
911 return false;
912
913 skia::BitmapPlatformDevice& device =
914 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
915
916 const SkBitmap& bitmap = device.accessBitmap(false);
917 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
918 return false;
919
920 HISTOGRAM_TIMES("Renderer4.Snapshot",
921 base::TimeTicks::Now() - beginning_time);
922 return true;
initial.commit09911bf2008-07-26 23:55:29923}
924
925void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
926 if (!webview())
927 return;
928
[email protected]3cc72b12010-03-18 23:03:00929 history_list_offset_ = params.current_history_list_offset;
930 history_list_length_ = params.current_history_list_length;
931
[email protected]8c785c62009-07-13 14:20:15932 if (devtools_agent_.get())
933 devtools_agent_->OnNavigate();
934
[email protected]422197532010-01-25 17:38:23935 if (notification_provider_.get())
936 notification_provider_->OnNavigate();
937
[email protected]a9f607e2009-10-23 19:59:27938 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26939
initial.commit09911bf2008-07-26 23:55:29940 AboutHandler::MaybeHandle(params.url);
941
[email protected]ecbf10d2010-02-18 13:03:29942 bool is_reload =
943 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
944 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29945
[email protected]26aa0482009-09-30 16:55:27946 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45947 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29948 // We cannot reload if we do not have any history state. This happens, for
949 // example, when recovering from a crash. Our workaround here is a bit of
950 // a hack since it means that reload after a crashed tab does not cause an
951 // end-to-end cache validation.
952 is_reload = false;
953 }
954
[email protected]77f17a82009-05-21 04:42:54955 // A navigation resulting from loading a javascript URL should not be treated
956 // as a browser initiated event. Instead, we want it to look as if the page
957 // initiated any load resulting from JS execution.
958 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30959 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00960 params.page_id,
961 params.pending_history_list_offset,
962 params.transition,
963 params.request_time);
[email protected]5e369672009-11-03 23:48:30964 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
965 // We're doing a load of a page that was restored from the last session.
966 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
967 // which can result in stale data for pages that are set to expire. We
968 // explicitly override that by setting the policy here so that as
969 // necessary we load from the network.
970 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
971 }
972 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54973 }
initial.commit09911bf2008-07-26 23:55:29974
[email protected]a7ccc4d2010-01-27 08:14:48975 NavigationState* navigation_state = pending_navigation_state_.get();
976
[email protected]04d3c6e2009-05-22 17:00:13977 // If we are reloading, then WebKit will use the history state of the current
978 // page, so we should just ignore any given history state. Otherwise, if we
979 // have history state, then we need to navigate to it, which corresponds to a
980 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55981 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48982 if (navigation_state)
983 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29984 bool ignore_cache = (params.navigation_type ==
985 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
986 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55987 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13988 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58989 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48990 if (navigation_state)
991 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45992 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17993 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13994 } else {
995 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28996 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29997
[email protected]e6f546c32009-07-01 17:12:55998 // A session history navigation should have been accompanied by state.
999 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131000
[email protected]dd7daa82009-08-10 05:46:451001 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551002 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131003
[email protected]726985e22009-06-18 21:09:281004 if (params.referrer.is_valid()) {
1005 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1006 WebString::fromUTF8(params.referrer.spec()));
1007 }
[email protected]04d3c6e2009-05-22 17:00:131008
[email protected]a7ccc4d2010-01-27 08:14:481009 if (navigation_state)
1010 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451011 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501012 }
1013
[email protected]77f17a82009-05-21 04:42:541014 // In case LoadRequest failed before DidCreateDataSource was called.
1015 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291016}
1017
1018// Stop loading the current page
1019void RenderView::OnStop() {
1020 if (webview())
[email protected]b4bb2502009-10-01 22:35:271021 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291022}
1023
[email protected]ecbf10d2010-02-18 13:03:291024// Reload current focused frame.
1025// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561026void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291027 if (webview() && webview()->focusedFrame()) {
1028 // We always obey the cache (ignore_cache=false) here.
1029 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1030 // a cache-ignoring reload of the frame.
1031 webview()->focusedFrame()->reload(false);
1032 }
[email protected]1dda4022010-01-28 18:24:561033}
1034
initial.commit09911bf2008-07-26 23:55:291035void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271036 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291037}
1038
[email protected]68b1e922009-06-23 16:00:251039void RenderView::OnExecuteEditCommand(const std::string& name,
1040 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271041 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251042 return;
1043
[email protected]26aa0482009-09-30 16:55:271044 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451045 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251046}
1047
[email protected]b2abac72009-02-26 12:39:281048void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111049 DCHECK(!devtools_client_.get());
1050 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281051}
1052
initial.commit09911bf2008-07-26 23:55:291053void RenderView::OnUpdateTargetURLAck() {
1054 // Check if there is a targeturl waiting to be sent.
1055 if (target_url_status_ == TARGET_PENDING) {
1056 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1057 pending_target_url_));
1058 }
1059
1060 target_url_status_ = TARGET_NONE;
1061}
1062
1063void RenderView::OnUndo() {
1064 if (!webview())
1065 return;
1066
[email protected]26aa0482009-09-30 16:55:271067 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121068 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291069}
1070
1071void RenderView::OnRedo() {
1072 if (!webview())
1073 return;
1074
[email protected]26aa0482009-09-30 16:55:271075 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121076 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291077}
1078
1079void RenderView::OnCut() {
1080 if (!webview())
1081 return;
1082
[email protected]26aa0482009-09-30 16:55:271083 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121084 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291085}
1086
1087void RenderView::OnCopy() {
1088 if (!webview())
1089 return;
1090
[email protected]26aa0482009-09-30 16:55:271091 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121092 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291093}
1094
[email protected]c0cc3092009-09-12 08:27:271095#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351096void RenderView::OnCopyToFindPboard() {
1097 if (!webview())
1098 return;
1099
1100 // Since the find pasteboard supports only plain text, this can be simpler
1101 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271102 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351103 if (frame->hasSelection()) {
1104 string16 selection = frame->selectionAsText();
1105 RenderThread::current()->Send(
1106 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1107 }
1108
[email protected]afe3a1672009-11-17 19:04:121109 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351110}
[email protected]c0cc3092009-09-12 08:27:271111#endif
[email protected]a954bf72009-09-12 07:30:351112
initial.commit09911bf2008-07-26 23:55:291113void RenderView::OnPaste() {
1114 if (!webview())
1115 return;
1116
[email protected]26aa0482009-09-30 16:55:271117 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121118 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291119}
1120
[email protected]2a3a7762009-10-19 19:17:321121void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291122 if (!webview())
1123 return;
1124
[email protected]1ff7a032010-02-03 02:46:031125 WebFrame* frame = webview()->focusedFrame();
1126 if (!frame->hasSelection())
1127 frame->selectWordAroundCaret();
1128 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291129}
1130
[email protected]98324892009-09-09 21:16:051131void RenderView::OnAdvanceToNextMisspelling() {
1132 if (!webview())
1133 return;
[email protected]26aa0482009-09-30 16:55:271134 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051135 WebString::fromUTF8("AdvanceToNextMisspelling"));
1136}
1137
1138void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1139 if (!webview())
1140 return;
1141 // We need to tell the webView whether the spelling panel is visible or not so
1142 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261143 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271144 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051145 WebString::fromUTF8("ToggleSpellPanel"));
1146}
1147
[email protected]bbbd545c2008-12-15 20:18:041148void RenderView::OnToggleSpellCheck() {
1149 if (!webview())
1150 return;
1151
[email protected]26aa0482009-09-30 16:55:271152 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451153 frame->enableContinuousSpellChecking(
1154 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041155}
1156
initial.commit09911bf2008-07-26 23:55:291157void RenderView::OnDelete() {
1158 if (!webview())
1159 return;
1160
[email protected]26aa0482009-09-30 16:55:271161 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121162 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291163}
1164
1165void RenderView::OnSelectAll() {
1166 if (!webview())
1167 return;
1168
[email protected]26aa0482009-09-30 16:55:271169 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221170 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121171 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291172}
1173
1174void RenderView::OnSetInitialFocus(bool reverse) {
1175 if (!webview())
1176 return;
[email protected]26aa0482009-09-30 16:55:271177 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291178}
1179
1180///////////////////////////////////////////////////////////////////////////////
1181
[email protected]433819d2010-01-30 20:20:011182void RenderView::SetContentSettings(const ContentSettings& settings) {
1183 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011184}
1185
initial.commit09911bf2008-07-26 23:55:291186// Tell the embedding application that the URL of the active page has changed
1187void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451188 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291189 DCHECK(ds);
1190
[email protected]726985e22009-06-18 21:09:281191 const WebURLRequest& request = ds->request();
1192 const WebURLRequest& original_request = ds->originalRequest();
1193 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291194
[email protected]daa8c58e2009-06-15 17:21:101195 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1196 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291197
1198 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281199 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291200 params.is_post = false;
1201 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281202 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551203 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291204 // SSL state specified in the request takes precedence over the one in the
1205 // response.
1206 // So far this is only intended for error pages that are not expected to be
1207 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281208 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551209 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291210 } else {
[email protected]726985e22009-06-18 21:09:281211 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291212 }
1213
1214 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281215 if (ds->hasUnreachableURL()) {
1216 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291217 } else {
[email protected]726985e22009-06-18 21:09:281218 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291219 }
1220
[email protected]726985e22009-06-18 21:09:281221 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241222 params.should_update_history = !ds->hasUnreachableURL() &&
1223 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291224
[email protected]ce0e250d2009-10-23 21:00:351225 params.searchable_form_url = navigation_state->searchable_form_url();
1226 params.searchable_form_encoding =
1227 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291228
1229 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101230 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291231 if (password_form_data)
1232 params.password_form = *password_form_data;
1233
1234 params.gesture = navigation_gesture_;
1235 navigation_gesture_ = NavigationGestureUnknown;
1236
[email protected]dd7daa82009-08-10 05:46:451237 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291238 // Top-level navigation.
1239
[email protected]71b0d5d2010-02-15 05:43:071240 // Clear "block" flags for the new page. This needs to happen before any of
1241 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1242 // so that these functions can correctly detect that a piece of content
1243 // flipped from "not blocked" to "blocked".
1244 ClearBlockedContentSettings();
1245
[email protected]62d2a112010-04-07 00:53:021246 // Set content settings. Default them from the parent window if one exists.
1247 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011248 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541249 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011250 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011251 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011252
1253 // These content settings were merely recorded transiently for this load.
1254 // We can erase them now. If at some point we reload this page, the
1255 // browser will send us new, up-to-date content settings.
1256 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401257 } else if (frame->opener()) {
1258 WebView* opener_view = frame->opener()->view();
1259 RenderView* opener = FromWebView(opener_view);
1260 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011261 }
1262
[email protected]40bd6582009-12-04 23:49:511263 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011264 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541265 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011266 if (host_zoom != host_zoom_levels_.end()) {
1267 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511268 // This zoom level was merely recorded transiently for this load. We can
1269 // erase it now. If at some point we reload this page, the browser will
1270 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011271 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511272 }
1273
initial.commit09911bf2008-07-26 23:55:291274 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551275 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291276
[email protected]daa8c58e2009-06-15 17:21:101277 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291278 if (!PageTransition::IsMainFrame(params.transition)) {
1279 // If the main frame does a load, it should not be reported as a subframe
1280 // navigation. This can occur in the following case:
1281 // 1. You're on a site with frames.
1282 // 2. You do a subframe navigation. This is stored with transition type
1283 // MANUAL_SUBFRAME.
1284 // 3. You navigate to some non-frame site, say, google.com.
1285 // 4. You navigate back to the page from step 2. Since it was initially
1286 // MANUAL_SUBFRAME, it will be that same transition type here.
1287 // We don't want that, because any navigation that changes the toplevel
1288 // frame should be tracked as a toplevel navigation (this allows us to
1289 // update the URL bar, etc).
1290 params.transition = PageTransition::LINK;
1291 }
1292
initial.commit09911bf2008-07-26 23:55:291293 // If we have a valid consumed client redirect source,
1294 // the page contained a client redirect (meta refresh, document.loc...),
1295 // so we set the referrer and transition to match.
1296 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041297 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291298 params.referrer = completed_client_redirect_src_;
1299 params.transition = static_cast<PageTransition::Type>(
1300 params.transition | PageTransition::CLIENT_REDIRECT);
1301 } else {
1302 // Bug 654101: the referrer will be empty on https->http transitions. It
1303 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281304 params.referrer = GURL(
1305 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291306 }
1307
[email protected]726985e22009-06-18 21:09:281308 string16 method = request.httpMethod();
1309 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291310 params.is_post = true;
1311
[email protected]c2a797d2009-09-21 16:46:321312 // Save some histogram data so we can compute the average memory used per
1313 // page load of the glyphs.
1314 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1315 webkit_glue::GetGlyphPageCount());
1316
[email protected]15cf526b2010-02-12 06:33:491317 // This message needs to be sent before any of allowScripts(),
1318 // allowImages(), allowPlugins() is called for the new page, so that when
1319 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1320 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291321 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1322 } else {
1323 // Subframe navigation: the type depends on whether this navigation
1324 // generated a new session history entry. When they do generate a session
1325 // history entry, it means the user initiated the navigation and we should
1326 // mark it as such. This test checks if this is the first time UpdateURL
1327 // has been called since WillNavigateToURL was called to initiate the load.
1328 if (page_id_ > last_page_id_sent_to_browser_)
1329 params.transition = PageTransition::MANUAL_SUBFRAME;
1330 else
1331 params.transition = PageTransition::AUTO_SUBFRAME;
1332
initial.commit09911bf2008-07-26 23:55:291333 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1334 }
1335
1336 last_page_id_sent_to_browser_ =
1337 std::max(last_page_id_sent_to_browser_, page_id_);
1338
1339 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101340 // we don't want the transition type to persist. Just clear it.
1341 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501342
[email protected]c7287a92009-11-04 20:06:151343 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091344 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351345 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501346 }
initial.commit09911bf2008-07-26 23:55:291347}
1348
1349// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171350void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291351 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171352 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171353 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171354 routing_id_,
1355 page_id_,
1356 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1357 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171358 }
initial.commit09911bf2008-07-26 23:55:291359}
1360
1361void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401362 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291363 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271364 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291365 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301366 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291367 last_encoding_name_ = encoding_name;
1368
[email protected]e38f40152008-09-12 23:08:301369 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291370 }
1371}
1372
[email protected]f4d34b52008-11-24 23:05:011373// Sends the previous session history state to the browser so it will be saved
1374// before we navigate to a new page. This must be called *before* the page ID
1375// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291376void RenderView::UpdateSessionHistory(WebFrame* frame) {
1377 // If we have a valid page ID at this point, then it corresponds to the page
1378 // we are navigating away from. Otherwise, this is the first navigation, so
1379 // there is no past session history to record.
1380 if (page_id_ == -1)
1381 return;
1382
[email protected]ca948a22009-06-25 19:36:171383 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271384 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171385 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291386 return;
[email protected]ca948a22009-06-25 19:36:171387
1388 Send(new ViewHostMsg_UpdateState(
1389 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291390}
1391
[email protected]3d9689372009-09-10 04:29:171392void RenderView::OpenURL(
1393 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1394 Send(new ViewHostMsg_OpenURL(
1395 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1396}
1397
[email protected]79dbc662009-09-04 05:42:511398// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291399
initial.commit09911bf2008-07-26 23:55:291400void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281401 const WebURLRequest& failed_request,
1402 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291403 const std::string& html,
1404 bool replace) {
[email protected]726985e22009-06-18 21:09:281405 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291406
1407 std::string alt_html;
1408 if (html.empty()) {
1409 // Use a local error page.
1410 int resource_id;
1411 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281412 if (error.reason == net::ERR_CACHE_MISS &&
1413 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291414 GetFormRepostErrorValues(failed_url, &error_strings);
1415 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1416 } else {
1417 GetLocalizedErrorValues(error, &error_strings);
1418 resource_id = IDR_NET_ERROR_HTML;
1419 }
initial.commit09911bf2008-07-26 23:55:291420
1421 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1422 } else {
1423 alt_html = html;
1424 }
1425
[email protected]dd7daa82009-08-10 05:46:451426 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551427 GURL(kUnreachableWebDataURL),
1428 failed_url,
1429 replace);
initial.commit09911bf2008-07-26 23:55:291430}
1431
[email protected]7ccddb8c2009-08-04 17:36:551432void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291433 dom_automation_controller_.set_message_sender(this);
1434 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551435 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291436 L"domAutomationController");
1437}
1438
initial.commit09911bf2008-07-26 23:55:291439bool RenderView::RunJavaScriptMessage(int type,
1440 const std::wstring& message,
1441 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071442 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291443 std::wstring* result) {
1444 bool success = false;
1445 std::wstring result_temp;
1446 if (!result)
1447 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291448
[email protected]12636df2009-09-28 22:32:211449 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1450 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291451 return success;
1452}
1453
[email protected]c1f50aa2010-02-18 03:46:571454bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1455 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1456 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1457 // it is particularly important that we do not call willEnterModalLoop as
1458 // that would defer resource loads for the dialog itself.
1459 if (RenderThread::current()) // Will be NULL during unit tests.
1460 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1461
1462 message->EnableMessagePumping(); // Runs a nested message loop.
1463 return Send(message);
1464}
1465
initial.commit09911bf2008-07-26 23:55:291466void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1467 if (!osd_url.is_empty())
1468 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1469 autodetected));
1470}
1471
[email protected]95056b582010-02-18 01:29:241472void RenderView::OnAutoFillSuggestionsReturned(
1473 int query_id,
[email protected]8f6e6582010-04-09 02:03:071474 const std::vector<string16>& values,
[email protected]95056b582010-02-18 01:29:241475 const std::vector<string16>& labels,
1476 int default_suggestion_index) {
1477 if (webview() && query_id == autofill_query_id_) {
1478 webview()->applyAutoFillSuggestions(
[email protected]8f6e6582010-04-09 02:03:071479 autofill_query_node_, values, labels, default_suggestion_index);
[email protected]95056b582010-02-18 01:29:241480 }
1481 autofill_query_node_.reset();
1482}
1483
[email protected]cf28ec52010-04-09 22:56:341484void RenderView::OnAutoFillForms(
1485 const std::vector<webkit_glue::FormData>& forms) {
1486 form_manager_.FillForms(forms);
1487}
1488
[email protected]95056b582010-02-18 01:29:241489void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391490 int query_id,
1491 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031492 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181493 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081494 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391495 autofill_query_node_, suggestions, default_suggestion_index);
1496 }
1497 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031498}
1499
[email protected]45c6e532010-03-15 23:51:241500void RenderView::OnAutoFillFormDataFilled(int query_id,
1501 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481502 if (query_id != autofill_query_id_)
1503 return;
1504
1505 form_manager_.FillForm(form);
1506}
1507
[email protected]e8345242010-05-06 03:00:401508void RenderView::OnAllowScriptToClose(bool script_can_close) {
1509 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311510}
1511
initial.commit09911bf2008-07-26 23:55:291512uint32 RenderView::GetCPBrowsingContext() {
1513 uint32 context = 0;
1514 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1515 return context;
1516}
1517
initial.commit09911bf2008-07-26 23:55:291518void RenderView::AddSearchProvider(const std::string& url) {
1519 AddGURLSearchProvider(GURL(url),
1520 false); // not autodetected
1521}
1522
[email protected]f103ab72009-09-02 17:10:591523void RenderView::OnMissingPluginStatus(
1524 WebPluginDelegateProxy* delegate,
1525 int status) {
[email protected]6c8afae52009-01-22 02:24:571526#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591527 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291528 // Show the InfoBar for the first available plugin.
1529 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591530 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291531 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1532 }
1533 } else {
1534 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1535 // to start the download/install.
1536 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1537 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1538 }
1539 }
[email protected]6c8afae52009-01-22 02:24:571540#else
[email protected]76c3b312010-05-20 21:38:291541 // TODO(port): Implement the infobar that accompanies the default plugin.
1542 // Linux: http://crbug.com/10952
1543 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571544 NOTIMPLEMENTED();
1545#endif
initial.commit09911bf2008-07-26 23:55:291546}
1547
[email protected]48c9cf2d2009-09-16 16:47:521548// WebKit::WebViewClient ------------------------------------------------------
1549
[email protected]534c66c2010-04-28 22:53:111550WebView* RenderView::createView(
1551 WebFrame* creator,
1552 const WebWindowFeatures& features) {
[email protected]48c9cf2d2009-09-16 16:47:521553 // Check to make sure we aren't overloading on popups.
1554 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1555 return NULL;
1556
1557 // This window can't be closed from a window.close() call until we receive a
1558 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401559 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521560
1561 int32 routing_id = MSG_ROUTING_NONE;
1562 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461563 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341564 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521565
[email protected]48c9cf2d2009-09-16 16:47:521566 render_thread_->Send(
[email protected]534c66c2010-04-28 22:53:111567 new ViewHostMsg_CreateWindow(
1568 routing_id_,
1569 user_gesture,
1570 WindowFeaturesToContainerType(features),
1571 session_storage_namespace_id_,
1572 &routing_id,
1573 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211574 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521575 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521576
[email protected]48c9cf2d2009-09-16 16:47:521577 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421578 0,
[email protected]12636df2009-09-28 22:32:211579 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521580 renderer_preferences_,
1581 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211582 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341583 routing_id,
1584 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521585 view->opened_by_user_gesture_ = user_gesture;
1586
[email protected]007a848b2009-10-26 15:55:461587 // Record whether the creator frame is trying to suppress the opener field.
1588 view->opener_suppressed_ = opener_suppressed;
1589
[email protected]48c9cf2d2009-09-16 16:47:521590 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091591 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521592 if (!creator_url.is_valid() || !creator_url.IsStandard())
1593 creator_url = GURL();
1594 view->creator_url_ = creator_url;
1595
1596 // Copy over the alternate error page URL so we can have alt error pages in
1597 // the new render view (we don't need the browser to send the URL back down).
1598 view->alternate_error_page_url_ = alternate_error_page_url_;
1599
1600 return view->webview();
1601}
1602
[email protected]3e2b375b2010-04-07 17:03:121603WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521604 RenderWidget* widget = RenderWidget::Create(routing_id_,
1605 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121606 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521607 return widget->webwidget();
1608}
1609
1610WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1611 RenderWidget* widget = RenderWidget::Create(routing_id_,
1612 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121613 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521614 widget->ConfigureAsExternalPopupMenu(info);
1615 return widget->webwidget();
1616}
1617
[email protected]68c50e52010-05-12 11:14:391618WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341619 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391620 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291621 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1622 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1623 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341624}
1625
[email protected]48c9cf2d2009-09-16 16:47:521626void RenderView::didAddMessageToConsole(
1627 const WebConsoleMessage& message, const WebString& source_name,
1628 unsigned source_line) {
1629 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1630 UTF16ToWideHack(message.text),
1631 static_cast<int32>(source_line),
1632 UTF16ToWideHack(source_name)));
1633}
1634
1635void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581636 DCHECK(frame);
1637 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521638}
1639
1640void RenderView::didStartLoading() {
1641 if (is_loading_) {
1642 DLOG(WARNING) << "didStartLoading called while loading";
1643 return;
1644 }
1645
1646 is_loading_ = true;
1647 // Clear the pointer so that we can assign it only when there is an unknown
1648 // plugin on a page.
1649 first_default_plugin_.reset();
1650
1651 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1652}
1653
1654void RenderView::didStopLoading() {
1655 if (!is_loading_) {
1656 DLOG(WARNING) << "DidStopLoading called while not loading";
1657 return;
1658 }
1659
1660 is_loading_ = false;
1661
1662 // NOTE: For now we're doing the safest thing, and sending out notification
1663 // when done loading. This currently isn't an issue as the favicon is only
1664 // displayed when done loading. Ideally we would send notification when
1665 // finished parsing the head, but webkit doesn't support that yet.
1666 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271667 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521668 if (!favicon_url.is_empty())
1669 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1670
[email protected]26aa0482009-09-30 16:55:271671 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521672 true); // autodetected
1673
1674 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1675
[email protected]f9f4841b2010-03-20 05:41:421676 MessageLoop::current()->PostDelayedTask(
1677 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521678 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1679 false),
1680 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521681}
1682
[email protected]f55039a2010-02-17 14:12:061683bool RenderView::isSmartInsertDeleteEnabled() {
1684#if defined(OS_MACOSX)
1685 return true;
1686#else
1687 return false;
1688#endif
1689}
1690
[email protected]04fc9482009-09-18 22:13:031691bool RenderView::isSelectTrailingWhitespaceEnabled() {
1692#if defined(OS_WIN)
1693 return true;
1694#else
1695 return false;
1696#endif
1697}
1698
1699void RenderView::setInputMethodEnabled(bool enabled) {
1700 // Save the updated IME status and mark the input focus has been updated.
1701 // The IME status is to be sent to a browser process next time when
1702 // the input caret is rendered.
1703 if (!ime_control_busy_) {
1704 ime_control_updated_ = true;
1705 ime_control_new_state_ = enabled;
1706 }
1707}
1708
1709void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031710#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031711 if (!handling_input_event_)
1712 return;
1713 // TODO(estade): investigate incremental updates to the selection so that we
1714 // don't send the entire selection over IPC every time.
1715 if (!is_empty_selection) {
1716 // Sometimes we get repeated didChangeSelection calls from webkit when
1717 // the selection hasn't actually changed. We don't want to report these
1718 // because it will cause us to continually claim the X clipboard.
1719 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271720 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031721 if (this_selection == last_selection_)
1722 return;
1723
1724 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1725 this_selection));
1726 last_selection_ = this_selection;
1727 } else {
1728 last_selection_.clear();
1729 }
1730#endif
1731}
1732
1733void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121734 const std::string& name = UTF16ToUTF8(command_name);
1735 if (StartsWithASCII(name, "Move", true) ||
1736 StartsWithASCII(name, "Insert", true) ||
1737 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031738 return;
1739 UserMetricsRecordAction(name);
1740}
1741
[email protected]b2528b72009-09-24 06:57:101742bool RenderView::handleCurrentKeyboardEvent() {
1743 if (edit_commands_.empty())
1744 return false;
1745
[email protected]26aa0482009-09-30 16:55:271746 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101747 if (!frame)
1748 return false;
1749
1750 EditCommands::iterator it = edit_commands_.begin();
1751 EditCommands::iterator end = edit_commands_.end();
1752
[email protected]507b33ea2009-09-29 03:56:511753 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101754 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331755 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1756 // key (but it's the exception). Once one edit command is not executed, it
1757 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101758 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1759 WebString::fromUTF8(it->value)))
1760 break;
[email protected]507b33ea2009-09-29 03:56:511761 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101762 }
1763
[email protected]507b33ea2009-09-29 03:56:511764 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101765}
1766
[email protected]2a3a7762009-10-19 19:17:321767void RenderView::spellCheck(const WebString& text,
1768 int& misspelled_offset,
1769 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561770 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461771
[email protected]85c55dc2009-11-06 03:05:461772 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171773 RenderThread* thread = RenderThread::current();
1774 // Will be NULL during unit tests.
1775 if (thread) {
[email protected]c27324b2009-11-19 22:44:291776 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171777 word.c_str(), word.size(), document_tag_,
1778 &misspelled_offset, &misspelled_length, NULL);
1779 }
[email protected]1dbafaf72009-09-23 19:43:561780}
1781
1782WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321783 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561784 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261785 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561786 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171787 RenderThread* thread = RenderThread::current();
1788 // Will be NULL during unit tests.
1789 if (thread) {
1790 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291791 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171792 word, document_tag_);
1793 }
[email protected]1dbafaf72009-09-23 19:43:561794 }
[email protected]2a3a7762009-10-19 19:17:321795 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561796}
1797
[email protected]c49085c72009-10-02 16:28:561798void RenderView::showSpellingUI(bool show) {
1799 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1800}
1801
[email protected]8922e1f2009-10-03 05:01:261802bool RenderView::isShowingSpellingUI() {
1803 return spelling_panel_visible_;
1804}
1805
[email protected]1dbafaf72009-09-23 19:43:561806void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321807 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1808 word));
[email protected]1dbafaf72009-09-23 19:43:561809}
1810
[email protected]a1128322009-10-06 18:38:461811bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351812 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471813 WebFileChooserCompletion* chooser_completion) {
1814 ViewHostMsg_RunFileChooser_Params ipc_params;
1815 ipc_params.mode = params.multiSelect ?
1816 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1817 ViewHostMsg_RunFileChooser_Params::Open;
1818 ipc_params.title = params.title;
1819 ipc_params.default_file_name =
1820 webkit_glue::WebStringToFilePath(params.initialValue);
1821
1822 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461823}
1824
[email protected]48c9cf2d2009-09-16 16:47:521825void RenderView::runModalAlertDialog(
1826 WebFrame* frame, const WebString& message) {
1827 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1828 UTF16ToWideHack(message),
1829 std::wstring(),
1830 frame->url(),
1831 NULL);
1832}
1833
1834bool RenderView::runModalConfirmDialog(
1835 WebFrame* frame, const WebString& message) {
1836 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1837 UTF16ToWideHack(message),
1838 std::wstring(),
1839 frame->url(),
1840 NULL);
1841}
1842
1843bool RenderView::runModalPromptDialog(
1844 WebFrame* frame, const WebString& message, const WebString& default_value,
1845 WebString* actual_value) {
1846 std::wstring result;
1847 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1848 UTF16ToWideHack(message),
1849 UTF16ToWideHack(default_value),
1850 frame->url(),
1851 &result);
1852 if (ok)
1853 actual_value->assign(WideToUTF16Hack(result));
1854 return ok;
1855}
1856
1857bool RenderView::runModalBeforeUnloadDialog(
1858 WebFrame* frame, const WebString& message) {
1859 bool success = false;
1860 // This is an ignored return value, but is included so we can accept the same
1861 // response as RunJavaScriptMessage.
1862 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211863 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521864 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211865 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521866 return success;
1867}
1868
[email protected]79e37442009-10-09 18:17:441869void RenderView::showContextMenu(
1870 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291871 ContextMenuParams params = ContextMenuParams(data);
1872 if (!params.misspelled_word.empty() && RenderThread::current()) {
1873 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041874 bool spelled_right = RenderThread::current()->spellchecker()->
1875 SpellCheckWord(
1876 params.misspelled_word.c_str(), params.misspelled_word.size(),
1877 document_tag_,
1878 &misspelled_offset, &misspelled_length,
1879 &params.dictionary_suggestions);
1880 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291881 params.misspelled_word.clear();
1882 }
1883
1884 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441885}
1886
[email protected]48c9cf2d2009-09-16 16:47:521887void RenderView::setStatusText(const WebString& text) {
1888}
1889
[email protected]163f8242009-10-30 20:19:551890void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581891 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521892 if (latest_url == target_url_)
1893 return;
[email protected]163f8242009-10-30 20:19:551894
[email protected]48c9cf2d2009-09-16 16:47:521895 // Tell the browser to display a destination link.
1896 if (target_url_status_ == TARGET_INFLIGHT ||
1897 target_url_status_ == TARGET_PENDING) {
1898 // If we have a request in-flight, save the URL to be sent when we
1899 // receive an ACK to the in-flight request. We can happily overwrite
1900 // any existing pending sends.
1901 pending_target_url_ = latest_url;
1902 target_url_status_ = TARGET_PENDING;
1903 } else {
1904 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1905 target_url_ = latest_url;
1906 target_url_status_ = TARGET_INFLIGHT;
1907 }
1908}
1909
[email protected]882daa92009-11-05 16:31:311910void RenderView::StartNavStateSyncTimerIfNecessary() {
1911 int delay;
1912 if (send_content_state_immediately_)
1913 delay = 0;
1914 else if (is_hidden())
1915 delay = kDelaySecondsForContentStateSyncHidden;
1916 else
1917 delay = kDelaySecondsForContentStateSync;
1918
1919 if (nav_state_sync_timer_.IsRunning()) {
1920 // The timer is already running. If the delay of the timer maches the amount
1921 // we want to delay by, then return. Otherwise stop the timer so that it
1922 // gets started with the right delay.
1923 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1924 return;
1925 nav_state_sync_timer_.Stop();
1926 }
1927
1928 nav_state_sync_timer_.Start(
1929 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1930}
1931
[email protected]163f8242009-10-30 20:19:551932void RenderView::setMouseOverURL(const WebURL& url) {
1933 mouse_over_url_ = GURL(url);
1934 UpdateTargetURL(mouse_over_url_, focus_url_);
1935}
1936
1937void RenderView::setKeyboardFocusURL(const WebURL& url) {
1938 focus_url_ = GURL(url);
1939 UpdateTargetURL(focus_url_, mouse_over_url_);
1940}
1941
[email protected]48c9cf2d2009-09-16 16:47:521942void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1943 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1944 hint));
1945}
1946
[email protected]c27ae592010-03-18 15:24:411947void RenderView::startDragging(const WebDragData& data,
1948 WebDragOperationsMask mask,
1949 const WebImage& image,
1950 const WebPoint& imageOffset) {
1951#if WEBKIT_USING_SKIA
1952 SkBitmap bitmap(image.getSkBitmap());
1953#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331954 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411955#endif
1956
[email protected]48c9cf2d2009-09-16 16:47:521957 Send(new ViewHostMsg_StartDragging(routing_id_,
1958 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411959 mask,
1960 bitmap,
1961 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521962}
1963
[email protected]28b92df2009-09-25 17:35:451964bool RenderView::acceptsLoadDrops() {
1965 return renderer_preferences_.can_accept_load_drops;
1966}
1967
[email protected]48c9cf2d2009-09-16 16:47:521968void RenderView::focusNext() {
1969 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1970}
1971
1972void RenderView::focusPrevious() {
1973 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1974}
1975
1976void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521977 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1978}
1979
1980int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001981 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521982}
1983
1984int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001985 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521986}
1987
[email protected]8922e1f2009-10-03 05:01:261988void RenderView::didUpdateInspectorSettings() {
1989 Send(new ViewHostMsg_UpdateInspectorSettings(
1990 routing_id_, webview()->inspectorSettings().utf8()));
1991}
1992
[email protected]acca2a1f2009-10-16 03:53:391993void RenderView::queryAutofillSuggestions(const WebNode& node,
1994 const WebString& name,
1995 const WebString& value) {
1996 static int query_counter = 0;
1997 autofill_query_id_ = query_counter++;
1998 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:361999
2000 const WebFormControlElement& element =
[email protected]f40b49e2010-05-05 22:38:452001 node.toConst<WebFormControlElement>();
[email protected]e250e492010-04-06 21:35:362002
[email protected]dede9342010-04-12 16:51:112003 webkit_glue::FormField field;
2004 FormManager::WebFormControlElementToFormField(element, true, &field);
[email protected]e250e492010-04-06 21:35:362005
[email protected]72eb2da2010-04-14 00:31:082006 // WebFormControlElementToFormField does not scrape the DOM for the field
2007 // label, so find the label here.
2008 // TODO(jhawkins): Add form and field identities so we can use the cached form
2009 // data in FormManager.
2010 field.set_label(FormManager::LabelForElement(element));
2011
[email protected]dede9342010-04-12 16:51:112012 Send(new ViewHostMsg_QueryFormFieldAutofill(
2013 routing_id_, autofill_query_id_, field));
[email protected]acca2a1f2009-10-16 03:53:392014}
2015
2016void RenderView::removeAutofillSuggestions(const WebString& name,
2017 const WebString& value) {
2018 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
2019}
2020
[email protected]c83641732010-02-20 01:04:482021void RenderView::didAcceptAutoFillSuggestion(
2022 const WebKit::WebNode& node,
[email protected]8f6e6582010-04-09 02:03:072023 const WebKit::WebString& value,
[email protected]c83641732010-02-20 01:04:482024 const WebKit::WebString& label) {
2025 static int query_counter = 0;
2026 autofill_query_id_ = query_counter++;
2027
[email protected]45c6e532010-03-15 23:51:242028 webkit_glue::FormData form;
[email protected]f40b49e2010-05-05 22:38:452029 const WebInputElement element = node.toConst<WebInputElement>();
[email protected]b1438212010-04-03 00:30:592030 if (!form_manager_.FindFormWithFormControlElement(
[email protected]da592272010-04-14 20:08:492031 element, FormManager::REQUIRE_NONE, &form))
[email protected]c83641732010-02-20 01:04:482032 return;
2033
2034 Send(new ViewHostMsg_FillAutoFillFormData(
[email protected]8f6e6582010-04-09 02:03:072035 routing_id_, autofill_query_id_, form, value, label));
[email protected]c83641732010-02-20 01:04:482036}
2037
[email protected]79dbc662009-09-04 05:42:512038// WebKit::WebWidgetClient ----------------------------------------------------
2039
initial.commit09911bf2008-07-26 23:55:292040// We are supposed to get a single call to Show for a newly created RenderView
2041// that was created via RenderView::CreateWebView. So, we wait until this
2042// point to dispatch the ShowView message.
2043//
2044// This method provides us with the information about how to display the newly
2045// created RenderView (i.e., as a constrained popup or as a new tab).
2046//
[email protected]4873c7d2009-07-16 06:36:282047void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292048 DCHECK(!did_show_) << "received extraneous Show call";
2049 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2050
2051 if (did_show_)
2052 return;
2053 did_show_ = true;
2054
[email protected]28295ec2009-10-16 05:34:332055 // Force new windows to a popup if they were not opened with a user gesture.
2056 if (!opened_by_user_gesture_) {
2057 // We exempt background tabs for compat with older versions of Chrome.
2058 // TODO(darin): This seems bogus. These should have a user gesture, so
2059 // we probably don't need this check.
2060 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2061 policy = WebKit::WebNavigationPolicyNewPopup;
2062 }
2063
initial.commit09911bf2008-07-26 23:55:292064 // NOTE: initial_pos_ may still have its default values at this point, but
2065 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2066 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282067 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2068 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292069 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242070 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292071}
2072
[email protected]4873c7d2009-07-16 06:36:282073void RenderView::closeWidgetSoon() {
[email protected]e8345242010-05-06 03:00:402074 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282075 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312076}
2077
[email protected]4873c7d2009-07-16 06:36:282078void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292079 DCHECK(did_show_) << "should already have shown the view";
2080
[email protected]c1f50aa2010-02-18 03:46:572081 // We must keep WebKit's shared timer running in this case in order to allow
2082 // showModalDialog to function properly.
2083 //
2084 // TODO(darin): WebKit should really be smarter about suppressing events and
2085 // timers so that we do not need to manage the shared timer in such a heavy
2086 // handed manner.
2087 //
2088 if (RenderThread::current()) // Will be NULL during unit tests.
2089 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2090
[email protected]12636df2009-09-28 22:32:212091 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292092}
2093
[email protected]3d9689372009-09-10 04:29:172094// WebKit::WebFrameClient -----------------------------------------------------
2095
2096WebPlugin* RenderView::createPlugin(
2097 WebFrame* frame, const WebPluginParams& params) {
[email protected]53af1d62010-05-14 03:40:262098 scoped_refptr<pepper::PluginModule> pepper_module =
2099 PepperPluginRegistry::GetInstance()->GetModule(params.mimeType.utf8());
2100 if (pepper_module) {
2101 return new pepper::WebPluginImpl(pepper_module, frame, params,
[email protected]b4f68dea2010-05-13 06:03:172102 pepper_delegate_.AsWeakPtr());
2103 }
[email protected]3d9689372009-09-10 04:29:172104 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2105}
2106
2107WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562108 WebApplicationCacheHostImpl* appcache_host =
2109 WebApplicationCacheHostImpl::FromFrame(frame);
2110 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2111 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2112 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172113}
2114
[email protected]9c00f002009-11-05 22:37:422115WebSharedWorker* RenderView::createSharedWorker(
2116 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372117 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422118
[email protected]30447b62009-11-13 01:13:372119 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512120 bool exists = false;
[email protected]30447b62009-11-13 01:13:372121 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512122 ViewHostMsg_CreateWorker_Params params;
2123 params.url = url;
2124 params.is_shared = true;
2125 params.name = name;
2126 params.document_id = document_id;
2127 params.render_view_route_id = routing_id_;
2128 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232129 params.parent_appcache_host_id = 0;
2130 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372131 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512132 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372133 if (url_mismatch) {
2134 return NULL;
2135 } else {
2136 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492137 document_id,
[email protected]6de0bcf2010-02-17 22:00:512138 exists,
[email protected]30447b62009-11-13 01:13:372139 route_id,
2140 routing_id_);
2141 }
[email protected]9c00f002009-11-05 22:37:422142}
2143
[email protected]3d9689372009-09-10 04:29:172144WebMediaPlayer* RenderView::createMediaPlayer(
2145 WebFrame* frame, WebMediaPlayerClient* client) {
2146 scoped_refptr<media::FilterFactoryCollection> factory =
2147 new media::FilterFactoryCollection();
2148 // Add in any custom filter factories first.
2149 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2150 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2151 // Add the chrome specific audio renderer.
2152 factory->AddFactory(
2153 AudioRendererImpl::CreateFactory(audio_message_filter()));
2154 }
2155
[email protected]80f584d92010-01-21 03:59:042156 WebApplicationCacheHostImpl* appcache_host =
2157 WebApplicationCacheHostImpl::FromFrame(frame);
2158
[email protected]3d9689372009-09-10 04:29:172159 // TODO(hclam): obtain the following parameters from |client|.
2160 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2161 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152162 GURL(), // referrer
2163 "null", // frame origin
2164 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172165 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042166 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172167 routing_id());
2168
[email protected]0436b9a2009-10-23 00:23:052169 // A simple data source that keeps all data in memory.
2170 media::FilterFactory* simple_data_source_factory =
2171 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2172 bridge_factory);
2173 // A sophisticated data source that does memory caching.
2174 media::FilterFactory* buffered_data_source_factory =
2175 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2176 bridge_factory);
2177 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2178 factory->AddFactory(simple_data_source_factory);
2179 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172180 } else {
[email protected]0436b9a2009-10-23 00:23:052181 factory->AddFactory(buffered_data_source_factory);
2182 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172183 }
[email protected]8400e032010-02-26 18:50:112184
2185 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2186 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2187 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2188 } else {
[email protected]b57509eb2010-03-30 01:26:282189 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2190 factory_factory =
2191 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112192 }
2193
2194 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172195}
2196
[email protected]035545f2010-04-09 13:10:212197WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2198 WebFrame* frame, WebApplicationCacheHostClient* client) {
2199 return new RendererWebApplicationCacheHostImpl(
2200 FromWebView(frame->view()), client,
2201 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2202}
2203
[email protected]b921cfd22010-02-25 16:57:512204WebCookieJar* RenderView::cookieJar() {
2205 return &cookie_jar_;
2206}
2207
[email protected]3d9689372009-09-10 04:29:172208void RenderView::willClose(WebFrame* frame) {
2209 if (!frame->parent()) {
2210 const GURL& url = frame->url();
2211 if (url.SchemeIs("http") || url.SchemeIs("https"))
2212 DumpLoadHistograms();
2213 }
[email protected]fa7b6b542009-11-03 05:02:302214
2215 WebDataSource* ds = frame->dataSource();
2216 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2217 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162218
2219 form_manager_.ResetFrame(frame);
[email protected]3d9689372009-09-10 04:29:172220}
2221
[email protected]684e4a42010-01-30 06:44:112222bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002223 if (!enabled_per_settings)
2224 return false;
[email protected]c21f1d52010-03-04 03:19:432225 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112226}
2227
2228bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402229 if (enabled_per_settings &&
2230 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2231 return true;
2232
2233 if (IsWhitelistedForContentSettings(frame))
2234 return true;
2235
2236 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2237 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112238}
2239
[email protected]3d9689372009-09-10 04:29:172240void RenderView::loadURLExternally(
2241 WebFrame* frame, const WebURLRequest& request,
2242 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592243 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2244 if (policy == WebKit::WebNavigationPolicyDownload) {
2245 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2246 } else {
2247 OpenURL(request.url(), referrer, policy);
2248 }
[email protected]3d9689372009-09-10 04:29:172249}
2250
2251WebNavigationPolicy RenderView::decidePolicyForNavigation(
2252 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222253 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172254 // Webkit is asking whether to navigate to a new URL.
2255 // This is fine normally, except if we're showing UI from one security
2256 // context and they're trying to navigate to a different context.
2257 const GURL& url = request.url();
2258
2259 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302260 // navigations.
[email protected]8079b362010-05-07 18:37:452261 if (renderer_preferences_.browser_handles_top_level_requests &&
2262 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192263 last_top_level_navigation_page_id_ = page_id_;
2264 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2265 OpenURL(url, referrer, default_policy);
2266 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172267 }
2268
2269 // A content initiated navigation may have originated from a link-click,
2270 // script, drag-n-drop operation, etc.
2271 bool is_content_initiated =
2272 NavigationState::FromDataSource(frame->provisionalDataSource())->
2273 is_content_initiated();
2274
2275 // We only care about navigations that are within the current tab (as opposed
2276 // to, for example, opening a new window).
2277 // But we sometimes navigate to about:blank to clear a tab, and we want to
2278 // still allow that.
2279 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2280 is_content_initiated && frame->parent() == NULL &&
2281 !url.SchemeIs(chrome::kAboutScheme)) {
2282 // When we received such unsolicited navigations, we sometimes want to
2283 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302284 if (CrossesExtensionExtents(frame, url) ||
2285 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172286 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422287 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172288 OpenURL(url, GURL(), default_policy);
2289 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2290 }
[email protected]8079b362010-05-07 18:37:452291
2292 // We forward navigations from extensions to the browser if they are
2293 // top-level events, even if the browser hasn't expressed interest.
2294 //
2295 // Note that we've already forwarded cross-extension extents navigations
2296 // above.
2297 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
2298 IsNonLocalTopLevelNavigation(url, frame, type)) {
2299 OpenURL(url, GURL(), default_policy);
2300 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2301 }
[email protected]3d9689372009-09-10 04:29:172302 }
2303
2304 // Detect when a page is "forking" a new tab that can be safely rendered in
2305 // its own process. This is done by sites like Gmail that try to open links
2306 // in new windows without script connections back to the original page. We
2307 // treat such cases as browser navigations (in which we will create a new
2308 // renderer for a cross-site navigation), rather than WebKit navigations.
2309 //
2310 // We use the following heuristic to decide whether to fork a new page in its
2311 // own process:
2312 // The parent page must open a new tab to about:blank, set the new tab's
2313 // window.opener to null, and then redirect the tab to a cross-site URL using
2314 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462315 //
2316 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2317 // (see below).
[email protected]3d9689372009-09-10 04:29:172318 bool is_fork =
2319 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252320 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172321 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522322 historyBackListCount() < 1 &&
2323 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172324 // The parent page must have set the child's window.opener to null before
2325 // redirecting to the desired URL.
2326 frame->opener() == NULL &&
2327 // Must be a top-level frame.
2328 frame->parent() == NULL &&
2329 // Must not have issued the request from this page.
2330 is_content_initiated &&
2331 // Must be targeted at the current tab.
2332 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2333 // Must be a JavaScript navigation, which appears as "other".
2334 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462335
2336 // Recognize if this navigation is from a link with rel=noreferrer and
2337 // target=_blank attributes, in which case the opener will be suppressed. If
2338 // so, it is safe to load cross-site pages in a separate process, so we
2339 // should let the browser handle it.
2340 bool is_noreferrer_and_blank_target =
2341 // Frame should be top level and not yet navigated.
2342 frame->parent() == NULL &&
2343 frame->url().isEmpty() &&
2344 historyBackListCount() < 1 &&
2345 historyForwardListCount() < 1 &&
2346 // Links with rel=noreferrer will have no Referer field, and their
2347 // resulting frame will have its window.opener suppressed.
2348 // TODO(creis): should add a request.httpReferrer() method to help avoid
2349 // typos on the unusual spelling of Referer.
2350 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2351 opener_suppressed_ &&
2352 frame->opener() == NULL &&
2353 // Links with target=_blank will have no name.
2354 frame->name().isNull() &&
2355 // Another frame (with a non-empty creator) should have initiated the
2356 // request, targeted at this frame.
2357 !creator_url_.is_empty() &&
2358 is_content_initiated &&
2359 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2360 type == WebKit::WebNavigationTypeOther;
2361
2362 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172363 // Open the URL via the browser, not via WebKit.
2364 OpenURL(url, GURL(), default_policy);
2365 return WebKit::WebNavigationPolicyIgnore;
2366 }
2367
2368 return default_policy;
2369}
2370
[email protected]6069da8c2009-10-20 20:33:492371bool RenderView::canHandleRequest(
2372 WebFrame* frame, const WebURLRequest& request) {
2373 // We allow WebKit to think that everything can be handled even though
2374 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342375 return true;
2376}
2377
[email protected]6069da8c2009-10-20 20:33:492378WebURLError RenderView::cannotHandleRequestError(
2379 WebFrame* frame, const WebURLRequest& request) {
2380 NOTREACHED(); // Since we said we can handle all requests.
2381 return WebURLError();
2382}
2383
2384WebURLError RenderView::cancelledError(
2385 WebFrame* frame, const WebURLRequest& request) {
2386 WebURLError error;
2387 error.domain = WebString::fromUTF8(net::kErrorDomain);
2388 error.reason = net::ERR_ABORTED;
2389 error.unreachableURL = request.url();
2390 return error;
[email protected]7b7a7dc2009-10-19 02:23:342391}
2392
2393void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492394 WebFrame*, const WebURLError&) {
2395 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342396}
2397
[email protected]90eeddb2010-05-06 21:06:432398void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2399 const WebKit::WebFormElement& form) {
2400 // Some login forms have onSubmit handlers that put a hash of the password
2401 // into a hidden field and then clear the password. (Issue 28910.)
2402 // This method gets called before any of those handlers run, so save away
2403 // a copy of the password in case it gets lost.
2404 NavigationState* navigation_state =
2405 NavigationState::FromDataSource(frame->dataSource());
2406 navigation_state->set_password_form_data(
2407 PasswordFormDomManager::CreatePasswordForm(form));
2408}
2409
[email protected]979c28b2009-11-07 01:30:482410void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172411 NavigationState* navigation_state =
2412 NavigationState::FromDataSource(frame->provisionalDataSource());
2413
2414 if (navigation_state->transition_type() == PageTransition::LINK)
2415 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2416
2417 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352418 WebSearchableFormData web_searchable_form_data(form);
2419 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2420 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212421 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432422 PasswordForm* password_form_data =
2423 PasswordFormDomManager::CreatePasswordForm(form);
2424 navigation_state->set_password_form_data(password_form_data);
2425
2426 // If the password has been cleared, recover it from the form contents already
2427 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2428 // opposed to the provisionalDataSource's, which is what we're storing into
2429 // now.)
2430 if (password_form_data && password_form_data->password_value.empty()) {
2431 NavigationState* old_navigation_state =
2432 NavigationState::FromDataSource(frame->dataSource());
2433 if (old_navigation_state) {
2434 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2435 if (old_form_data && old_form_data->action == password_form_data->action)
2436 password_form_data->password_value = old_form_data->password_value;
2437 }
2438 }
[email protected]3d9689372009-09-10 04:29:172439
[email protected]b1438212010-04-03 00:30:592440 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042441 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092442 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592443 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172444}
2445
2446void RenderView::willPerformClientRedirect(
2447 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2448 double fire_time) {
2449 // Ignore
2450}
2451
2452void RenderView::didCancelClientRedirect(WebFrame* frame) {
2453 // Ignore
2454}
2455
2456void RenderView::didCompleteClientRedirect(
2457 WebFrame* frame, const WebURL& from) {
2458 if (!frame->parent())
2459 completed_client_redirect_src_ = from;
2460}
2461
2462void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2463 // The rest of RenderView assumes that a WebDataSource will always have a
2464 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482465 bool content_initiated = !pending_navigation_state_.get();
2466 NavigationState* state = content_initiated ?
2467 NavigationState::CreateContentInitiated() :
2468 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182469 if (content_initiated) {
2470 switch (ds->request().cachePolicy()) {
2471 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2472 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2473 break;
2474 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2475 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2476 break;
2477 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2478 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2479 break;
2480 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2481 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2482 break;
2483 }
2484 }
[email protected]fa7b6b542009-11-03 05:02:302485
2486 state->set_user_script_idle_scheduler(
2487 new UserScriptIdleScheduler(this, frame));
2488 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172489}
2490
2491void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2492 WebDataSource* ds = frame->provisionalDataSource();
2493 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2494
2495 navigation_state->set_start_load_time(Time::Now());
2496
2497 // Update the request time if WebKit has better knowledge of it.
2498 if (navigation_state->request_time().is_null()) {
2499 double event_time = ds->triggeringEventTime();
2500 if (event_time != 0.0)
2501 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2502 }
2503
2504 bool is_top_most = !frame->parent();
2505 if (is_top_most) {
2506 navigation_gesture_ = frame->isProcessingUserGesture() ?
2507 NavigationGestureUnknown : NavigationGestureAuto;
2508
2509 // Make sure redirect tracking state is clear for the new load.
2510 completed_client_redirect_src_ = GURL();
2511 } else if (frame->parent()->isLoading()) {
2512 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002513 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172514 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2515 }
2516
2517 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2518 routing_id_, is_top_most, ds->request().url()));
2519}
2520
2521void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2522 if (frame->parent())
2523 return;
2524 // Received a redirect on the main frame.
2525 WebDataSource* data_source = frame->provisionalDataSource();
2526 if (!data_source) {
2527 // Should only be invoked when we have a data source.
2528 NOTREACHED();
2529 return;
2530 }
2531 std::vector<GURL> redirects;
2532 GetRedirectChain(data_source, &redirects);
2533 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512534 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2535 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172536 }
2537}
2538
[email protected]40bd6582009-12-04 23:49:512539void RenderView::didFailProvisionalLoad(WebFrame* frame,
2540 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172541 // Notify the browser that we failed a provisional load with an error.
2542 //
2543 // Note: It is important this notification occur before DidStopLoading so the
2544 // SSL manager can react to the provisional load failure before being
2545 // notified the load stopped.
2546 //
2547 WebDataSource* ds = frame->provisionalDataSource();
2548 DCHECK(ds);
2549
2550 const WebURLRequest& failed_request = ds->request();
2551
2552 bool show_repost_interstitial =
2553 (error.reason == net::ERR_CACHE_MISS &&
2554 EqualsASCII(failed_request.httpMethod(), "POST"));
2555 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2556 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2557 show_repost_interstitial));
2558
2559 // Don't display an error page if this is simply a cancelled load. Aside
2560 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2561 if (error.reason == net::ERR_ABORTED)
2562 return;
2563
2564 // Make sure we never show errors in view source mode.
2565 frame->enableViewSourceMode(false);
2566
2567 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2568
2569 // If this is a failed back/forward/reload navigation, then we need to do a
2570 // 'replace' load. This is necessary to avoid messing up session history.
2571 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2572 // as session history is concerned.
2573 //
2574 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2575 // the page id.
2576 //
2577 bool replace =
2578 navigation_state->pending_page_id() != -1 ||
2579 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2580
2581 // If we failed on a browser initiated request, then make sure that our error
2582 // page load is regarded as the same browser initiated request.
2583 if (!navigation_state->is_content_initiated()) {
2584 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2585 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002586 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172587 navigation_state->transition_type(),
2588 navigation_state->request_time()));
2589 }
2590
2591 // Provide the user with a more helpful error page?
2592 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2593 return;
2594
2595 // Fallback to a local error page.
2596 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2597 replace);
2598}
2599
2600void RenderView::didReceiveDocumentData(
2601 WebFrame* frame, const char* data, size_t data_len,
2602 bool& prevent_default) {
2603 NavigationState* navigation_state =
2604 NavigationState::FromDataSource(frame->dataSource());
2605 if (!navigation_state->postpone_loading_data())
2606 return;
2607
2608 // We're going to call commitDocumentData ourselves...
2609 prevent_default = true;
2610
2611 // Continue buffering the response data for the original 404 page. If it
2612 // grows too large, then we'll just let it through.
2613 navigation_state->append_postponed_data(data, data_len);
2614 if (navigation_state->postponed_data().size() >= 512) {
2615 navigation_state->set_postpone_loading_data(false);
2616 frame->commitDocumentData(navigation_state->postponed_data().data(),
2617 navigation_state->postponed_data().size());
2618 navigation_state->clear_postponed_data();
2619 }
2620}
2621
[email protected]40bd6582009-12-04 23:49:512622void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2623 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172624 NavigationState* navigation_state =
2625 NavigationState::FromDataSource(frame->dataSource());
2626
2627 navigation_state->set_commit_load_time(Time::Now());
2628 if (is_new_navigation) {
2629 // When we perform a new navigation, we need to update the previous session
2630 // history entry with state for the page we are leaving.
2631 UpdateSessionHistory(frame);
2632
2633 // We bump our Page ID to correspond with the new session history entry.
2634 page_id_ = next_page_id_++;
2635
[email protected]d64b07b2010-04-20 22:14:062636 // Any pending translation is now obsolete.
2637 translate_helper_.CancelPendingTranslation();
2638
[email protected]3cc72b12010-03-18 23:03:002639 // Advance our offset in session history, applying the length limit. There
2640 // is now no forward history.
2641 history_list_offset_++;
2642 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2643 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2644 history_list_length_ = history_list_offset_ + 1;
2645
[email protected]f9f4841b2010-03-20 05:41:422646 MessageLoop::current()->PostDelayedTask(
2647 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172648 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2649 page_id_, true),
2650 kDelayForForcedCaptureMs);
2651 } else {
2652 // Inspect the navigation_state on this frame to see if the navigation
2653 // corresponds to a session history navigation... Note: |frame| may or
2654 // may not be the toplevel frame, but for the case of capturing session
2655 // history, the first committed frame suffices. We keep track of whether
2656 // we've seen this commit before so that only capture session history once
2657 // per navigation.
2658 //
2659 // Note that we need to check if the page ID changed. In the case of a
2660 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2661 // previous URL and the current page ID, which would be wrong.
2662 if (navigation_state->pending_page_id() != -1 &&
2663 navigation_state->pending_page_id() != page_id_ &&
2664 !navigation_state->request_committed()) {
2665 // This is a successful session history navigation!
2666 UpdateSessionHistory(frame);
2667 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002668
2669 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172670 }
2671 }
2672
2673 // Remember that we've already processed this request, so we don't update
2674 // the session history again. We do this regardless of whether this is
2675 // a session history navigation, because if we attempted a session history
2676 // navigation without valid HistoryItem state, WebCore will think it is a
2677 // new navigation.
2678 navigation_state->set_request_committed(true);
2679
2680 UpdateURL(frame);
2681
2682 // If this committed load was initiated by a client redirect, we're
2683 // at the last stop now, so clear it.
2684 completed_client_redirect_src_ = GURL();
2685
2686 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272687 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172688}
2689
2690void RenderView::didClearWindowObject(WebFrame* frame) {
2691 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2692 BindDOMAutomationController(frame);
2693 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2694 dom_ui_bindings_.set_message_sender(this);
2695 dom_ui_bindings_.set_routing_id(routing_id_);
2696 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2697 }
2698 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2699 external_host_bindings_.set_message_sender(this);
2700 external_host_bindings_.set_routing_id(routing_id_);
2701 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2702 }
2703}
2704
2705void RenderView::didCreateDocumentElement(WebFrame* frame) {
2706 if (RenderThread::current()) { // Will be NULL during unit tests.
2707 RenderThread::current()->user_script_slave()->InjectScripts(
2708 frame, UserScript::DOCUMENT_START);
2709 }
[email protected]078b34612009-09-19 19:31:512710 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2711 view_type_ == ViewType::EXTENSION_MOLE) {
2712 InjectToolstripCSS();
2713 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2714 }
[email protected]3d9689372009-09-10 04:29:172715
2716 // Notify the browser about non-blank documents loading in the top frame.
2717 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252718 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272719 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172720 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2721 }
2722}
2723
2724void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2725 UpdateTitle(frame, title);
2726
2727 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272728 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172729}
2730
[email protected]5019ef12010-04-27 17:26:582731void RenderView::didChangeIcons(WebFrame* frame) {
2732 if (!frame->parent()) {
2733 Send(new ViewHostMsg_UpdateFavIconURL(
2734 routing_id_,
2735 page_id_,
2736 frame->favIconURL()));
2737 }
2738}
2739
[email protected]3d9689372009-09-10 04:29:172740void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2741 WebDataSource* ds = frame->dataSource();
2742 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2743 DCHECK(navigation_state);
2744 navigation_state->set_finish_document_load_time(Time::Now());
2745
2746 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2747
[email protected]e9e07992010-02-17 21:04:362748 // The document has now been fully loaded. Scan for forms to be sent up to
2749 // the browser.
2750 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482751 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362752 SendForms(frame);
[email protected]4d44a1c2010-04-28 19:20:412753 SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172754
2755 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272756 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172757
2758 if (RenderThread::current()) { // Will be NULL during unit tests.
2759 RenderThread::current()->user_script_slave()->InjectScripts(
2760 frame, UserScript::DOCUMENT_END);
2761 }
[email protected]fa7b6b542009-11-03 05:02:302762
2763 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2764}
2765
2766void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2767 if (RenderThread::current()) { // Will be NULL during unit tests.
2768 RenderThread::current()->user_script_slave()->InjectScripts(
2769 frame, UserScript::DOCUMENT_IDLE);
2770 }
2771
2772 WebFrame* main_frame = webview()->mainFrame();
2773 if (frame == main_frame) {
2774 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202775 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302776 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202777 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302778 pending_code_execution_queue_.pop();
2779 }
2780 }
[email protected]3d9689372009-09-10 04:29:172781}
2782
2783void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:262784 if (webview()->mainFrame() == frame)
2785 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172786}
2787
2788void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2789 // Ignore
2790}
2791
2792void RenderView::didFinishLoad(WebFrame* frame) {
2793 WebDataSource* ds = frame->dataSource();
2794 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2795 DCHECK(navigation_state);
2796 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302797 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412798
2799 // Let the password manager know which password forms are actually visible.
2800 SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172801}
2802
[email protected]ccbe04e2010-03-17 17:58:432803void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172804 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062805
2806 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2807 // since a new one gets created by didCreateDataSource.
2808 NavigationState* state =
2809 NavigationState::FromDataSource(frame->dataSource());
2810 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2811
[email protected]3d9689372009-09-10 04:29:172812 // If this was a reference fragment navigation that we initiated, then we
2813 // could end up having a non-null pending navigation state. We just need to
2814 // update the ExtraData on the datasource so that others who read the
2815 // ExtraData will get the new NavigationState. Similarly, if we did not
2816 // initiate this navigation, then we need to take care to reset any pre-
2817 // existing navigation state to a content-initiated navigation state.
2818 // DidCreateDataSource conveniently takes care of this for us.
2819 didCreateDataSource(frame, frame->dataSource());
2820
[email protected]f6c2459d2010-02-24 22:34:062821 if (idle_scheduler_ran) {
2822 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2823 NavigationState* new_state =
2824 NavigationState::FromDataSource(frame->dataSource());
2825 new_state->user_script_idle_scheduler()->set_has_run(true);
2826 }
2827
[email protected]3d9689372009-09-10 04:29:172828 didCommitProvisionalLoad(frame, is_new_navigation);
2829
[email protected]26aa0482009-09-30 16:55:272830 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172831}
2832
[email protected]476b6f82009-09-10 21:00:592833void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312834 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592835}
2836
[email protected]3d9689372009-09-10 04:29:172837void RenderView::assignIdentifierToRequest(
2838 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2839 // Ignore
2840}
2841
2842void RenderView::willSendRequest(
2843 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2844 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302845 WebFrame* top_frame = frame->top();
2846 if (!top_frame)
2847 top_frame = frame;
2848 WebDataSource* data_source = top_frame->provisionalDataSource();
2849 if (!data_source)
2850 data_source = top_frame->dataSource();
2851 if (data_source) {
2852 NavigationState* state = NavigationState::FromDataSource(data_source);
2853 if (state && state->is_cache_policy_override_set())
2854 request.setCachePolicy(state->cache_policy_override());
2855 }
[email protected]3d9689372009-09-10 04:29:172856 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502857 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132858 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492859
[email protected]85cc78c2010-05-04 18:30:092860 // Temporary metrics, see site_isolation_metrics.h
2861 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172862}
2863
2864void RenderView::didReceiveResponse(
2865 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492866
[email protected]85cc78c2010-05-04 18:30:092867 // Temporary metrics, see site_isolation_metrics.h
2868 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2869 identifier,
2870 response);
[email protected]fa0a3432010-03-30 16:53:492871
[email protected]3d9689372009-09-10 04:29:172872 // Only do this for responses that correspond to a provisional data source
2873 // of the top-most frame. If we have a provisional data source, then we
2874 // can't have any sub-resources yet, so we know that this response must
2875 // correspond to a frame load.
2876 if (!frame->provisionalDataSource() || frame->parent())
2877 return;
2878
2879 // If we are in view source mode, then just let the user see the source of
2880 // the server's 404 error page.
2881 if (frame->isViewSourceModeEnabled())
2882 return;
2883
[email protected]65041fa2010-05-21 06:56:532884 NavigationState* navigation_state =
2885 NavigationState::FromDataSource(frame->provisionalDataSource());
2886 CHECK(navigation_state);
2887
[email protected]f48013be2010-01-14 22:07:452888 // Record that this was a page loaded over SPDY.
2889 if (response.wasFetchedViaSPDY()) {
[email protected]f48013be2010-01-14 22:07:452890 navigation_state->set_was_fetched_via_spdy(true);
2891 }
2892
[email protected]65041fa2010-05-21 06:56:532893 // Record that npn protocol was negotiated when fetching this page.
2894 if (response.wasNpnNegotiated()) {
2895 navigation_state->set_was_npn_negotiated(true);
2896 }
2897
[email protected]f48013be2010-01-14 22:07:452898 // Consider loading an alternate error page for 404 responses.
2899 if (response.httpStatusCode() != 404)
2900 return;
2901
[email protected]3d9689372009-09-10 04:29:172902 // Can we even load an alternate error page for this URL?
2903 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2904 return;
2905
[email protected]3d9689372009-09-10 04:29:172906 navigation_state->set_postpone_loading_data(true);
2907 navigation_state->clear_postponed_data();
2908}
2909
2910void RenderView::didFinishResourceLoad(
2911 WebFrame* frame, unsigned identifier) {
2912 NavigationState* navigation_state =
2913 NavigationState::FromDataSource(frame->dataSource());
2914 if (!navigation_state->postpone_loading_data())
2915 return;
2916
2917 // The server returned a 404 and the content was < 512 bytes (which we
2918 // suppressed). Go ahead and fetch the alternate page content.
2919
2920 const GURL& frame_url = frame->url();
2921
2922 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2923 DCHECK(error_page_url.is_valid());
2924
2925 WebURLError original_error;
2926 original_error.unreachableURL = frame_url;
2927
2928 navigation_state->set_alt_error_page_fetcher(
2929 new AltErrorPageResourceFetcher(
2930 error_page_url, frame, original_error,
2931 NewCallback(this, &RenderView::AltErrorPageFinished)));
2932}
2933
2934void RenderView::didFailResourceLoad(
2935 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2936 // Ignore
2937}
2938
2939void RenderView::didLoadResourceFromMemoryCache(
2940 WebFrame* frame, const WebURLRequest& request,
2941 const WebURLResponse& response) {
2942 // Let the browser know we loaded a resource from the memory cache. This
2943 // message is needed to display the correct SSL indicators.
2944 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2945 routing_id_,
2946 request.url(),
[email protected]91733b62009-09-18 06:21:092947 frame->securityOrigin().toString().utf8(),
2948 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172949 response.securityInfo()));
2950}
2951
[email protected]6069da8c2009-10-20 20:33:492952void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292953 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2954}
2955
2956void RenderView::didRunInsecureContent(
2957 WebFrame* frame, const WebSecurityOrigin& origin) {
2958 Send(new ViewHostMsg_DidRunInsecureContent(
2959 routing_id_,
2960 origin.toString().utf8()));
2961}
2962
[email protected]7ea093ba2009-11-03 05:54:592963bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402964 if (enabled_per_settings &&
2965 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
2966 return true;
[email protected]7ea093ba2009-11-03 05:54:592967
[email protected]12bc8472010-04-15 07:29:402968 if (IsWhitelistedForContentSettings(frame))
2969 return true;
[email protected]7ea093ba2009-11-03 05:54:592970
2971 return false; // Other protocols fall through here.
2972}
2973
[email protected]0a1a45432010-03-31 08:09:452974bool RenderView::allowDatabase(
2975 WebFrame* frame, const WebString& name, const WebString& display_name,
2976 unsigned long estimated_size) {
2977 WebSecurityOrigin origin = frame->securityOrigin();
2978 if (origin.isEmpty())
2979 return false; // Uninitialized document?
2980
2981 bool result;
2982 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
2983 origin.toString().utf8(), name, display_name, estimated_size, &result)))
2984 return false;
2985 if (!result)
2986 DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES);
2987 return result;
2988}
[email protected]8934a3b2010-02-25 00:34:002989void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2990 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2991}
2992
[email protected]c21f1d52010-03-04 03:19:432993void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2994 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2995}
2996
[email protected]3d9689372009-09-10 04:29:172997void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2998 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2999}
3000
[email protected]0c882b282009-10-07 17:01:283001void RenderView::didCreateScriptContext(WebFrame* frame) {
3002 EventBindings::HandleContextCreated(frame, false);
3003}
3004
3005void RenderView::didDestroyScriptContext(WebFrame* frame) {
3006 EventBindings::HandleContextDestroyed(frame);
3007}
3008
3009void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3010 EventBindings::HandleContextCreated(frame, true);
3011}
3012
[email protected]fc86daa2010-03-30 23:52:533013void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3014 WebFrame* target,
3015 bool cross_origin,
3016 const WebString& property_name,
3017 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103018 // TODO(johnnyg): track the individual properties and repeat event_ids.
3019 if (cross_origin)
3020 cross_origin_access_count_++;
3021 else
3022 same_origin_access_count_++;
3023}
3024
[email protected]3d9689372009-09-10 04:29:173025void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143026 CheckPreferredSize();
3027}
3028
3029void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173030 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253031 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173032 // message.
[email protected]705243f2010-05-05 19:58:073033 if (!send_preferred_size_changes_ || !webview())
3034 return;
[email protected]dfca5acf2010-03-22 03:28:433035
[email protected]705243f2010-05-05 19:58:073036 // WebCore likes to tell us things have changed even when they haven't, so
3037 // cache the width and height and only send the IPC message when we're sure
3038 // they're different.
3039 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3040 webview()->mainFrame()->documentElementScrollHeight());
3041 if (size == preferred_size_)
3042 return;
[email protected]c27324b2009-11-19 22:44:293043
[email protected]705243f2010-05-05 19:58:073044 preferred_size_ = size;
3045 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3046 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173047}
3048
[email protected]143dcd592009-11-06 21:33:493049void RenderView::didChangeScrollOffset(WebFrame* frame) {
3050 StartNavStateSyncTimerIfNecessary();
3051}
3052
[email protected]8922e1f2009-10-03 05:01:263053void RenderView::reportFindInPageMatchCount(int request_id, int count,
3054 bool final_update) {
3055 // If we have a message that has been queued up, then we should just replace
3056 // it. The ACK from the browser will make sure it gets sent when the browser
3057 // wants it.
3058 if (queued_find_reply_message_.get()) {
3059 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3060 routing_id_,
3061 request_id,
3062 count,
3063 gfx::Rect(),
3064 -1, // Don't update active match ordinal.
3065 final_update);
3066 queued_find_reply_message_.reset(msg);
3067 } else {
3068 // Send the search result over to the browser process.
3069 Send(new ViewHostMsg_Find_Reply(
3070 routing_id_,
3071 request_id,
3072 count,
3073 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073074 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263075 final_update));
3076 }
3077}
3078
3079void RenderView::reportFindInPageSelection(int request_id,
3080 int active_match_ordinal,
3081 const WebRect& selection_rect) {
3082 // Send the search result over to the browser process.
3083 Send(new ViewHostMsg_Find_Reply(routing_id_,
3084 request_id,
3085 -1,
3086 selection_rect,
3087 active_match_ordinal,
3088 false));
3089}
3090
[email protected]24a7f3c2010-03-25 08:26:493091void RenderView::ReportNoFindInPageResults(int request_id) {
3092 Send(new ViewHostMsg_Find_Reply(routing_id_,
3093 request_id,
3094 0,
3095 gfx::Rect(),
3096 0,
3097 true));
3098}
3099
[email protected]79dbc662009-09-04 05:42:513100// webkit_glue::WebPluginPageDelegate -----------------------------------------
3101
[email protected]f103ab72009-09-02 17:10:593102webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
3103 const GURL& url,
3104 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:593105 std::string* actual_mime_type) {
3106 if (!PluginChannelHost::IsListening())
3107 return NULL;
3108
3109 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:273110 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:593111 if (main_frame)
3112 policy_url = main_frame->url();
3113
3114 FilePath path;
[email protected]610c0892009-09-08 19:46:183115 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3116 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:593117 if (path.value().empty())
3118 return NULL;
3119
[email protected]7bf795d92010-05-22 00:14:283120 FilePath internal_pdf_path;
3121 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3122
[email protected]f103ab72009-09-02 17:10:593123 const std::string* mime_type_to_use;
3124 if (!actual_mime_type->empty())
3125 mime_type_to_use = actual_mime_type;
3126 else
3127 mime_type_to_use = &mime_type;
3128
[email protected]d2139662009-12-10 03:21:143129 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283130 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143131 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163132 const char kPepperPrefix[] = "pepper-";
3133 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143134 if (CommandLine::ForCurrentProcess()->
3135 HasSwitch(switches::kInternalPepper)) {
3136 in_process_plugin = true;
3137 use_pepper_host = true;
3138 } else {
3139 // In process Pepper plugins must be explicitly enabled.
3140 return NULL;
3141 }
[email protected]7bf795d92010-05-22 00:14:283142 } else if (path == internal_pdf_path) {
[email protected]d7ce4272010-03-27 01:06:013143 in_process_plugin = true;
3144 use_pepper_host = true;
[email protected]26e8d5e2009-10-13 02:47:163145 }
[email protected]d2139662009-12-10 03:21:143146 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463147 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3148 if (mime_type == "application/x-nacl-srpc") {
3149 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143150 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463151 }
3152 }
3153 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143154 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283155 WebPluginDelegatePepper* pepper_plugin =
3156 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3157 AsWeakPtr());
3158 current_pepper_plugins_.insert(pepper_plugin);
3159 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143160 } else {
[email protected]6876dff2010-01-15 19:38:093161#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143162 return WebPluginDelegateImpl::Create(
3163 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093164#else
[email protected]596b2c42010-01-14 20:40:433165 NOTIMPLEMENTED();
3166 return NULL;
[email protected]7b6616f2010-01-14 18:07:553167#endif
[email protected]6876dff2010-01-15 19:38:093168 }
[email protected]f103ab72009-09-02 17:10:593169 }
3170
[email protected]610c0892009-09-08 19:46:183171 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593172}
3173
3174void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033175#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593176 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3177 routing_id(), window));
3178#endif
3179}
3180
3181void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033182#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593183 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3184 routing_id(), window));
3185#endif
3186 CleanupWindowInPluginMoves(window);
3187}
3188
3189void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3190 SchedulePluginMove(move);
3191}
3192
3193void RenderView::DidStartLoadingForPlugin() {
3194 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523195 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593196}
3197
3198void RenderView::DidStopLoadingForPlugin() {
3199 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523200 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593201}
3202
3203void RenderView::ShowModalHTMLDialogForPlugin(
3204 const GURL& url,
3205 const gfx::Size& size,
3206 const std::string& json_arguments,
3207 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213208 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593209 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213210 json_retval));
[email protected]f103ab72009-09-02 17:10:593211}
3212
[email protected]b921cfd22010-02-25 16:57:513213WebCookieJar* RenderView::GetCookieJar() {
3214 return &cookie_jar_;
3215}
3216
initial.commit09911bf2008-07-26 23:55:293217void RenderView::SyncNavigationState() {
3218 if (!webview())
3219 return;
3220
[email protected]26aa0482009-09-30 16:55:273221 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173222 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293223 return;
[email protected]ca948a22009-06-25 19:36:173224
3225 Send(new ViewHostMsg_UpdateState(
3226 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293227}
3228
[email protected]b0950a72009-09-29 23:16:173229bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3230 // Make sure webview was not shut down.
3231 if (!webview())
3232 return false;
3233 // Create an image resource fetcher and assign it with a call back object.
3234 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273235 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173236 NewCallback(this, &RenderView::DidDownloadImage)));
3237 return true;
3238}
3239
3240void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293241 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173242 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473243 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3244 fetcher->id(),
3245 fetcher->image_url(),
3246 image.isNull(),
3247 image));
[email protected]b0950a72009-09-29 23:16:173248 // Dispose of the image fetcher.
3249 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3250 image_fetchers_.erase(fetcher);
3251 // We're in the callback from the ImageResourceFetcher, best to delay
3252 // deletion.
3253 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293254}
3255
[email protected]bf5c2ff392009-07-08 16:24:333256void RenderView::OnDownloadFavIcon(int id,
3257 const GURL& image_url,
3258 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343259 bool data_image_failed = false;
3260 if (image_url.SchemeIs("data")) {
3261 SkBitmap data_image = ImageFromDataUrl(image_url);
3262 data_image_failed = data_image.empty();
3263 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333264 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3265 data_image));
[email protected]f11ca0732009-04-11 00:09:343266 }
3267 }
3268
[email protected]bf5c2ff392009-07-08 16:24:333269 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173270 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333271 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3272 SkBitmap()));
3273 }
initial.commit09911bf2008-07-26 23:55:293274}
3275
[email protected]f11ca0732009-04-11 00:09:343276SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3277 std::string mime_type, char_set, data;
3278 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3279 // Decode the favicon using WebKit's image decoder.
3280 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3281 const unsigned char* src_data =
3282 reinterpret_cast<const unsigned char*>(&data[0]);
3283
3284 return decoder.Decode(src_data, data.size());
3285 }
3286 return SkBitmap();
3287}
3288
initial.commit09911bf2008-07-26 23:55:293289void RenderView::OnGetApplicationInfo(int page_id) {
3290 webkit_glue::WebApplicationInfo app_info;
3291 if (page_id == page_id_)
3292 webkit_glue::GetApplicationInfo(webview(), &app_info);
3293
3294 // Prune out any data URLs in the set of icons. The browser process expects
3295 // any icon with a data URL to have originated from a favicon. We don't want
3296 // to decode arbitrary data URLs in the browser process. See
3297 // http://b/issue?id=1162972
3298 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593299 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293300 app_info.icons.erase(app_info.icons.begin() + i);
3301 --i;
3302 }
3303 }
3304
3305 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3306}
3307
[email protected]7ccddb8c2009-08-04 17:36:553308GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293309 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553310 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293311 // If the URL that failed was secure, then the embedding web page was not
3312 // expecting a network attacker to be able to manipulate its contents. As
3313 // we fetch alternate error pages over HTTP, we would be allowing a network
3314 // attacker to manipulate the contents of the response if we tried to use
3315 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153316 return GURL();
initial.commit09911bf2008-07-26 23:55:293317 }
3318
3319 // Grab the base URL from the browser process.
3320 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153321 return GURL();
initial.commit09911bf2008-07-26 23:55:293322
3323 // Strip query params from the failed URL.
3324 GURL::Replacements remove_params;
3325 remove_params.ClearUsername();
3326 remove_params.ClearPassword();
3327 remove_params.ClearQuery();
3328 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553329 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503330 std::string spec_to_send = url_to_send.spec();
3331 // Notify link doctor of the url truncation by sending of "?" at the end.
3332 if (failed_url.has_query())
3333 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293334
3335 // Construct the query params to send to link doctor.
3336 std::string params(alternate_error_page_url_.query());
3337 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503338 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293339 params.append("&sourceid=chrome");
3340 params.append("&error=");
3341 switch (error_type) {
3342 case DNS_ERROR:
3343 params.append("dnserror");
3344 break;
3345
3346 case HTTP_404:
3347 params.append("http404");
3348 break;
3349
[email protected]5df266ac2008-10-15 19:50:133350 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333351 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133352 break;
3353
initial.commit09911bf2008-07-26 23:55:293354 default:
3355 NOTREACHED() << "unknown ErrorPageType";
3356 }
3357
3358 // OK, build the final url to return.
3359 GURL::Replacements link_doctor_params;
3360 link_doctor_params.SetQueryStr(params);
3361 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3362 return url;
3363}
3364
[email protected]24a7f3c2010-03-25 08:26:493365webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
[email protected]f40b49e2010-05-05 22:38:453366 WebPlugin* plugin =
3367 webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493368 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3369}
3370
[email protected]6069da8c2009-10-20 20:33:493371void RenderView::OnFind(int request_id, const string16& search_text,
3372 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273373 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493374
3375 if (main_frame->document().isPluginDocument()) {
3376 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3377 if (options.findNext) {
3378 // Just navigate back/forward.
3379 delegate->SelectFindResult(options.forward);
3380 } else {
3381 if (delegate->SupportsFind()) {
3382 delegate->StartFind(UTF16ToUTF8(search_text),
3383 options.matchCase,
3384 request_id);
3385 } else {
3386 ReportNoFindInPageResults(request_id);
3387 }
3388 }
3389 return;
3390 }
3391
[email protected]b4bb2502009-10-01 22:35:273392 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273393 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293394 WebFrame* search_frame = focused_frame; // start searching focused frame.
3395
3396 bool multi_frame = (frame_after_main != main_frame);
3397
3398 // If we have multiple frames, we don't want to wrap the search within the
3399 // frame, so we check here if we only have main_frame in the chain.
3400 bool wrap_within_frame = !multi_frame;
3401
[email protected]b3f2b912009-04-09 16:18:523402 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293403 bool result = false;
3404
[email protected]7830da3e2009-11-06 16:27:263405 // If something is selected when we start searching it means we cannot just
3406 // increment the current match ordinal; we need to re-generate it.
3407 WebRange current_selection = focused_frame->selectionRange();
3408
initial.commit09911bf2008-07-26 23:55:293409 do {
[email protected]dd7daa82009-08-10 05:46:453410 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593411 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293412
3413 if (!result) {
3414 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223415 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293416
3417 // Find the next frame, but skip the invisible ones.
3418 do {
3419 // What is the next frame to search? (we might be going backwards). Note
3420 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593421 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273422 search_frame->traverseNext(true) :
3423 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453424 } while (!search_frame->hasVisibleContent() &&
3425 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293426
[email protected]884db412008-11-24 23:46:503427 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223428 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293429
3430 // If we have multiple frames and we have wrapped back around to the
3431 // focused frame, we need to search it once more allowing wrap within
3432 // the frame, otherwise it will report 'no match' if the focused frame has
3433 // reported matches, but no frames after the focused_frame contain a
3434 // match for the search word(s).
3435 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453436 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593437 request_id, search_text, options, true, // Force wrapping.
3438 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293439 }
3440 }
3441
[email protected]26aa0482009-09-30 16:55:273442 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293443 } while (!result && search_frame != focused_frame);
3444
[email protected]7830da3e2009-11-06 16:27:263445 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293446 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453447 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293448 } else {
3449 // If nothing is found, set result to "0 of 0", otherwise, set it to
3450 // "-1 of 1" to indicate that we found at least one item, but we don't know
3451 // yet what is active.
3452 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3453 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293454
[email protected]4f3dc372009-02-24 00:10:293455 // If we find no matches then this will be our last status update.
3456 // Otherwise the scoping effort will send more results.
3457 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293458
[email protected]4f3dc372009-02-24 00:10:293459 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403460 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593461 request_id,
[email protected]4f3dc372009-02-24 00:10:293462 match_count,
3463 selection_rect,
3464 ordinal,
3465 final_status_update));
initial.commit09911bf2008-07-26 23:55:293466
initial.commit09911bf2008-07-26 23:55:293467 // Scoping effort begins, starting with the mainframe.
3468 search_frame = main_frame;
3469
[email protected]dd7daa82009-08-10 05:46:453470 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293471
3472 do {
3473 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453474 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293475
3476 // We don't start another scoping effort unless at least one match has
3477 // been found.
3478 if (result) {
3479 // Start new scoping request. If the scoping function determines that it
3480 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453481 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593482 search_text,
3483 options,
initial.commit09911bf2008-07-26 23:55:293484 true); // reset the tickmarks
3485 }
3486
3487 // Iterate to the next frame. The frame will not necessarily scope, for
3488 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273489 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293490 } while (search_frame != main_frame);
3491 }
3492}
3493
[email protected]24a7f3c2010-03-25 08:26:493494void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3495 WebView* view = webview();
3496 if (!view)
3497 return;
3498
3499 WebDocument doc = view->mainFrame()->document();
3500 if (doc.isPluginDocument()) {
3501 GetDelegateForPluginDocument()->StopFind();
3502 return;
3503 }
3504
3505 bool clear_selection =
3506 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3507 if (clear_selection)
3508 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3509
3510 WebFrame* frame = view->mainFrame();
3511 while (frame) {
3512 frame->stopFinding(clear_selection);
3513 frame = frame->traverseNext(false);
3514 }
3515
3516 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3517 WebFrame* focused_frame = view->focusedFrame();
3518 if (focused_frame) {
3519 WebDocument doc = focused_frame->document();
3520 if (!doc.isNull()) {
3521 WebNode node = doc.focusedNode();
3522 if (!node.isNull())
3523 node.simulateClick();
3524 }
3525 }
3526 }
3527}
3528
3529void RenderView::OnFindReplyAck() {
3530 // Check if there is any queued up request waiting to be sent.
3531 if (queued_find_reply_message_.get()) {
3532 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423533 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493534 }
3535}
3536
[email protected]8c4cdd42010-01-12 21:31:133537// static
3538std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403539 // Text with less than 100 bytes will probably not provide good results.
3540 // Report it as unknown language.
3541 if (text.length() < 100)
3542 return kUnknownLanguageCode;
3543
[email protected]8c4cdd42010-01-12 21:31:133544 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133545 int num_languages = 0;
3546 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423547 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133548 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423549 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133550 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403551 if (is_reliable && cld_language != NUM_LANGUAGES &&
3552 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483553 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3554 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263555 // language code for tradtional Chinese among others.
3556 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3557 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3558 // for Simplified Chinese.
3559 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133560 }
[email protected]8c4cdd42010-01-12 21:31:133561 return language;
[email protected]7893a982010-01-07 23:25:523562}
3563
[email protected]8934a3b2010-02-25 00:34:003564bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353565 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003566 return current_content_settings_.settings[settings_type] !=
3567 CONTENT_SETTING_BLOCK;
3568}
3569
3570void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3571 if (!content_blocked_[settings_type]) {
3572 content_blocked_[settings_type] = true;
3573 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353574 }
[email protected]0de80162010-02-03 04:52:353575}
3576
[email protected]71b0d5d2010-02-15 05:43:073577void RenderView::ClearBlockedContentSettings() {
3578 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3579 content_blocked_[i] = false;
3580}
3581
initial.commit09911bf2008-07-26 23:55:293582void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3583 Send(new ViewHostMsg_DnsPrefetch(host_names));
3584}
3585
[email protected]40bd6582009-12-04 23:49:513586void RenderView::OnZoom(PageZoom::Function function) {
3587 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3588 return;
3589
[email protected]258d31122010-05-09 10:59:413590 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523591 // Should we be saving zoom levels for plugins? It's not clear, so for now
3592 // don't.
3593 if (webview()->mainFrame()->document().isPluginDocument()) {
3594 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3595 int zoom;
3596 if (function == PageZoom::RESET) {
3597 zoom = 0;
3598 } else if (function == PageZoom::ZOOM_OUT) {
3599 zoom = -1;
3600 } else if (function == PageZoom::ZOOM_IN) {
3601 zoom = 1;
3602 } else {
3603 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113604 return;
[email protected]b03794d2010-03-26 19:57:523605 }
3606 delegate->Zoom(zoom);
3607 return;
3608 }
3609
[email protected]40bd6582009-12-04 23:49:513610 int zoom_level = webview()->zoomLevel();
3611 int new_zoom_level = webview()->setZoomLevel(false,
3612 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3613
[email protected]9d797f32010-04-23 07:17:543614 // Tell the browser which url got zoomed so it can update the saved values.
3615 Send(new ViewHostMsg_DidZoomURL(
3616 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513617}
3618
[email protected]9d797f32010-04-23 07:17:543619void RenderView::OnSetContentSettingsForLoadingURL(
3620 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013621 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543622 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013623}
3624
[email protected]9d797f32010-04-23 07:17:543625void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3626 int zoom_level) {
3627 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293628}
3629
[email protected]41fc0322009-09-04 22:23:403630void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273631 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293632}
3633
[email protected]a697f4c2009-09-14 22:30:183634void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273635 WebString no_encoding;
3636 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183637}
3638
[email protected]20ad2692009-11-20 18:27:203639bool RenderView::GetAllChildFrames(
3640 WebFrame* parent_frame,
3641 std::vector<WebFrame*>* frames_vector) const {
3642 if (!parent_frame)
3643 return false;
3644 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3645 child_frame = child_frame->nextSibling()) {
3646 frames_vector->push_back(child_frame);
3647 GetAllChildFrames(child_frame, frames_vector);
3648 }
3649 return true;
3650}
3651
[email protected]dd7daa82009-08-10 05:46:453652WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3653 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273654 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453655
3656 // xpath string can represent a frame deep down the tree (across multiple
3657 // frame DOMs).
3658 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3659 // should break into 2 xpaths
3660 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3661
[email protected]26aa0482009-09-30 16:55:273662 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453663
3664 std::wstring xpath_remaining = xpath;
3665 while (!xpath_remaining.empty()) {
3666 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3667 std::wstring xpath_child;
3668 if (delim_pos != std::wstring::npos) {
3669 xpath_child = xpath_remaining.substr(0, delim_pos);
3670 xpath_remaining.erase(0, delim_pos + 1);
3671 } else {
3672 xpath_remaining.swap(xpath_child);
3673 }
3674 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293675 }
3676
[email protected]dd7daa82009-08-10 05:46:453677 return frame;
initial.commit09911bf2008-07-26 23:55:293678}
3679
[email protected]f29acf52008-11-03 20:08:333680void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3681 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293682 WebFrame* web_frame = GetChildFrame(frame_xpath);
3683 if (!web_frame)
3684 return;
3685
[email protected]dd7daa82009-08-10 05:46:453686 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293687}
3688
[email protected]1810e132009-03-24 23:35:483689void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083690 const std::string& css,
3691 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483692 WebFrame* web_frame = GetChildFrame(frame_xpath);
3693 if (!web_frame)
3694 return;
3695
[email protected]ffaef0c2009-09-15 17:08:083696 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483697}
3698
[email protected]00c39612010-03-06 02:53:283699void RenderView::OnPepperPluginDestroy(
3700 WebPluginDelegatePepper* pepper_plugin) {
3701 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3702 current_pepper_plugins_.find(pepper_plugin);
3703 if (found_pepper == current_pepper_plugins_.end()) {
3704 NOTREACHED();
3705 return;
3706 }
3707 current_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473708
3709 // The plugin could have been destroyed while it was waiting for a file
3710 // choose callback, so check all pending completion callbacks and NULL them.
3711 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3712 file_chooser_completions_.begin();
3713 i != file_chooser_completions_.end(); /* nothing */) {
3714 if ((*i)->completion == pepper_plugin) {
3715 // We NULL the first one instead of deleting it because the plugin might
3716 // be the one waiting for a file choose callback. If the callback later
3717 // comes, we don't want to send the result to the next callback in line.
3718 if (i == file_chooser_completions_.begin())
3719 (*i)->completion = NULL;
3720 else
3721 i = file_chooser_completions_.erase(i);
3722 } else {
3723 ++i;
3724 }
3725 }
[email protected]00c39612010-03-06 02:53:283726}
3727
initial.commit09911bf2008-07-26 23:55:293728void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3729 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333730 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293731}
3732
[email protected]1810e132009-03-24 23:35:483733void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083734 const std::string& css,
3735 const std::string& id) {
3736 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413737
3738 // Notify RenderViewHost that css has been inserted into the frame.
3739 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483740}
3741
[email protected]7ea066a2009-04-06 20:21:593742void RenderView::OnAddMessageToConsole(
3743 const string16& frame_xpath,
3744 const string16& message,
3745 const WebConsoleMessage::Level& level) {
3746 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593747 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453748 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293749}
3750
[email protected]81e63782009-02-27 19:35:093751void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3752 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293753}
3754
3755void RenderView::OnSetDOMUIProperty(const std::string& name,
3756 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093757 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293758 dom_ui_bindings_.SetProperty(name, value);
3759}
3760
3761void RenderView::OnReservePageIDRange(int size_of_range) {
3762 next_page_id_ += size_of_range + 1;
3763}
3764
[email protected]e80c73b2009-04-07 23:24:583765void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3766 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253767 bool ended,
3768 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033769 if (ended) {
[email protected]26aa0482009-09-30 16:55:273770 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033771 }
initial.commit09911bf2008-07-26 23:55:293772}
3773
3774void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273775 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293776}
3777
initial.commit09911bf2008-07-26 23:55:293778void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103779 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293780 webkit_glue::FillPasswordForm(this->webview(), form_data);
3781}
3782
3783void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583784 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253785 const gfx::Point& screen_point,
3786 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273787 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583788 drop_data.ToDragData(),
3789 drop_data.identity,
3790 client_point,
[email protected]1d9f4132009-09-08 17:29:253791 screen_point,
3792 ops);
initial.commit09911bf2008-07-26 23:55:293793
[email protected]1d9f4132009-09-08 17:29:253794 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293795}
3796
[email protected]e80c73b2009-04-07 23:24:583797void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253798 const gfx::Point& screen_point,
3799 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273800 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253801 client_point,
3802 screen_point,
3803 ops);
initial.commit09911bf2008-07-26 23:55:293804
[email protected]1d9f4132009-09-08 17:29:253805 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293806}
3807
3808void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273809 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293810}
3811
[email protected]e80c73b2009-04-07 23:24:583812void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3813 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273814 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293815}
3816
3817void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593818 webkit_preferences_ = prefs;
3819 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293820}
3821
3822void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3823 alternate_error_page_url_ = url;
3824}
3825
[email protected]a0c7153e2009-12-09 14:36:333826void RenderView::OnCustomContextMenuAction(unsigned action) {
3827 webview()->performCustomContextMenuAction(action);
3828}
3829
[email protected]d4a00a72010-01-29 01:44:423830void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023831 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423832 const std::string& source_lang,
3833 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023834 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3835 translate_script);
[email protected]d4a00a72010-01-29 01:44:423836}
3837
[email protected]85d252e2010-04-06 22:21:023838void RenderView::OnRevertTranslation(int page_id) {
3839 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323840}
3841
initial.commit09911bf2008-07-26 23:55:293842void RenderView::OnInstallMissingPlugin() {
3843 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593844 if (first_default_plugin_)
3845 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293846}
3847
[email protected]cdaf8d02010-03-30 19:52:473848void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363849 // This could happen if we navigated to a different page before the user
3850 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473851 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363852 return;
3853
[email protected]cdaf8d02010-03-30 19:52:473854 WebVector<WebString> ws_file_names(paths.size());
3855 for (size_t i = 0; i < paths.size(); ++i)
3856 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463857
[email protected]cdaf8d02010-03-30 19:52:473858 if (file_chooser_completions_.front()->completion)
3859 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3860 file_chooser_completions_.pop_front();
3861
3862 // If there are more pending file chooser requests, schedule one now.
3863 if (!file_chooser_completions_.empty()) {
3864 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3865 file_chooser_completions_.front()->params));
3866 }
initial.commit09911bf2008-07-26 23:55:293867}
3868
3869void RenderView::OnEnableViewSourceMode() {
3870 if (!webview())
3871 return;
[email protected]26aa0482009-09-30 16:55:273872 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293873 if (!main_frame)
3874 return;
3875
[email protected]dd7daa82009-08-10 05:46:453876 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293877}
3878
[email protected]770dd8b2010-05-24 18:11:393879void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3880 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243881 if (send_preferred_size_changes_)
3882 return;
[email protected]9fb325e2010-05-06 18:23:243883 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393884
3885 // WebKit doesn't send a notification of the effective height of the page
3886 // changes, so poll for it.
3887 // TODO: Add a notification for this to WebKit, remove polling. After that's
3888 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
3889 // http://crbug.com/44850
3890 if (flags & kPreferredSizeHeightThisIsSlow) {
3891 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3892 &RenderView::CheckPreferredSize);
3893 }
[email protected]0666aef2009-05-13 19:48:083894}
3895
[email protected]cda45c02010-02-25 19:28:103896void RenderView::OnDisableScrollbarsForSmallWindows(
3897 const gfx::Size& disable_scrollbar_size_limit) {
3898 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3899}
3900
[email protected]80d96fa2009-06-10 22:34:513901void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3902 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373903 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033904#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413905 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3906 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463907 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323908
[email protected]644d77e2010-01-27 01:03:103909 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323910 webview()->setScrollbarColors(
3911 renderer_prefs.thumb_inactive_color,
3912 renderer_prefs.thumb_active_color,
3913 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103914 webview()->setSelectionColors(
3915 renderer_prefs.active_selection_bg_color,
3916 renderer_prefs.active_selection_fg_color,
3917 renderer_prefs.inactive_selection_bg_color,
3918 renderer_prefs.inactive_selection_fg_color);
3919 }
[email protected]7a74e102009-09-03 00:16:563920#endif
[email protected]80d96fa2009-06-10 22:34:513921}
3922
[email protected]952cb702009-10-07 05:50:283923void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3924 const WebMediaPlayerAction& action) {
3925 if (webview())
3926 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563927}
3928
[email protected]7b291f92009-08-14 05:43:533929void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513930 // When this is first set, the bindings aren't fully loaded. We only need
3931 // to call through this API after the page has already been loaded. It's
3932 // also called in didCreateDocumentElement to bootstrap.
3933 if (view_type_ != ViewType::INVALID) {
3934 if (type == ViewType::EXTENSION_MOLE ||
3935 type == ViewType::EXTENSION_TOOLSTRIP) {
3936 ExtensionProcessBindings::SetViewType(webview(), type);
3937 }
3938 }
[email protected]7b291f92009-08-14 05:43:533939 view_type_ = type;
3940}
3941
3942void RenderView::OnUpdateBrowserWindowId(int window_id) {
3943 browser_window_id_ = window_id;
3944}
3945
[email protected]b3df5a42010-05-11 14:31:093946void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:363947 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:413948 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:113949 accessibility_.reset(WebAccessibilityCache::create());
3950 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:413951
[email protected]b3df5a42010-05-11 14:31:093952 WebAccessibilityObject src_tree = webview()->accessibilityObject();
3953 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
3954 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:503955}
3956
[email protected]aef92842010-05-21 16:54:363957void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3958 if (!accessibility_.get())
3959 return;
3960 if (accessibility_->isValidId(acc_obj_id)) {
3961 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
3962 // By convention, calling SetFocus on the root of the tree (id = 1000)
3963 // should clear the current focus. Otherwise set the focus to the new
3964 // node.
3965 if (acc_obj_id == 1000)
3966 webview()->clearFocusedNode();
3967 else
3968 accessibility_->getObjectById(acc_obj_id).setFocused(true);
3969 }
3970}
3971
3972void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3973 if (!accessibility_.get())
3974 return;
3975 if (accessibility_->isValidId(acc_obj_id)) {
3976 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
3977 }
3978}
3979
initial.commit09911bf2008-07-26 23:55:293980void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3981 const GURL& page_url) {
3982 // Prepare list to storage all savable resource links.
3983 std::vector<GURL> resources_list;
3984 std::vector<GURL> referrers_list;
3985 std::vector<GURL> frames_list;
3986 webkit_glue::SavableResourcesResult result(&resources_list,
3987 &referrers_list,
3988 &frames_list);
3989
[email protected]dbeb3952009-10-13 18:01:183990 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3991 webview(),
3992 page_url,
3993 &result,
3994 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293995 // If something is wrong when collecting all savable resource links,
3996 // send empty list to embedder(browser) to tell it failed.
3997 referrers_list.clear();
3998 resources_list.clear();
3999 frames_list.clear();
4000 }
4001
4002 // Send result of all savable resource links to embedder.
4003 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4004 resources_list,
4005 referrers_list,
4006 frames_list));
4007}
4008
4009void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324010 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314011 const std::vector<FilePath>& local_paths,
4012 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074013
4014 // Convert std::vector of GURLs to WebVector<WebURL>
4015 WebVector<WebURL> weburl_links(links);
4016
4017 // Convert std::vector of std::strings to WebVector<WebString>
4018 WebVector<WebString> webstring_paths(local_paths.size());
4019 for (size_t i = 0; i < local_paths.size(); i++)
4020 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4021
4022 WebPageSerializer::serialize(webview()->mainFrame(),
4023 true, this, weburl_links, webstring_paths,
4024 webkit_glue::FilePathToWebString(
4025 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294026}
4027
[email protected]d9ec5c0f2009-12-23 11:55:074028void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4029 const WebCString& data,
4030 WebPageSerializerClient::PageSerializationStatus status) {
4031 Send(new ViewHostMsg_SendSerializedHtmlData(
4032 routing_id_,
4033 frame_url,
4034 data.data(),
4035 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294036}
4037
[email protected]04b4a6c2008-08-02 00:44:474038void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:274039 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474040 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294041}
4042
[email protected]eb6b87a2009-07-24 15:57:394043void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294044 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4045 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4046 // in the onunload handler from appearing. For now, we're bypassing that and
4047 // calling the FrameLoader's CloseURL method directly. This should be
4048 // revisited to avoid having two ways to close a page. Having a single way
4049 // to close that can run onunload is also useful for fixing
4050 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274051 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294052 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454053 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174054 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294055 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4056 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454057 if (url.SchemeIs(chrome::kHttpScheme) ||
4058 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294059 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294060 }
[email protected]26aa0482009-09-30 16:55:274061 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294062
[email protected]ab9eabac2010-03-16 16:54:104063 // Reset stats
4064 cross_origin_access_count_ = 0;
4065 same_origin_access_count_ = 0;
4066
[email protected]eb6b87a2009-07-24 15:57:394067 // Just echo back the params in the ACK.
4068 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294069}
4070
4071void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574072#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294073 gfx::NativeTheme::instance()->CloseHandles();
4074 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:284075 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:574076#else // defined(OS_WIN)
4077 // TODO(port): we don't support theming on non-Windows platforms yet
4078 NOTIMPLEMENTED();
4079#endif
initial.commit09911bf2008-07-26 23:55:294080}
4081
[email protected]28790922009-03-09 19:48:374082void RenderView::OnMessageFromExternalHost(const std::string& message,
4083 const std::string& origin,
4084 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154085 if (message.empty())
4086 return;
4087
[email protected]28790922009-03-09 19:48:374088 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4089 target);
[email protected]3ac14a052008-08-15 21:22:154090}
4091
[email protected]0aa55312008-10-17 21:53:084092void RenderView::OnDisassociateFromPopupCount() {
4093 if (decrement_shared_popup_at_destruction_)
4094 shared_popup_counter_->data--;
4095 shared_popup_counter_ = new SharedRenderViewCounter(0);
4096 decrement_shared_popup_at_destruction_ = false;
4097}
4098
[email protected]15d79e12009-08-02 19:23:454099bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4100 const WebURLError& error,
4101 bool replace) {
4102 // We only show alternate error pages in the main frame. They are
4103 // intended to assist the user when navigating, so there is not much
4104 // value in showing them for failed subframes. Ideally, we would be
4105 // able to use the TYPED transition type for this, but that flag is
4106 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454107 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454108 return false;
4109
4110 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374111 // connection failure.
[email protected]15d79e12009-08-02 19:23:454112 int ec = error.reason;
4113 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4114 ec != net::ERR_CONNECTION_FAILED &&
4115 ec != net::ERR_CONNECTION_REFUSED &&
4116 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374117 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454118 return false;
4119
4120 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554121 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454122 if (!error_page_url.is_valid())
4123 return false;
4124
4125 // Load an empty page first so there is an immediate response to the error,
4126 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454127 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454128 GURL(kUnreachableWebDataURL),
4129 error.unreachableURL,
4130 replace);
4131
4132 // Now, create a fetcher for the error page and associate it with the data
4133 // source we just created via the LoadHTMLString call. That way if another
4134 // navigation occurs, the fetcher will get destroyed.
4135 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454136 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454137 navigation_state->set_alt_error_page_fetcher(
4138 new AltErrorPageResourceFetcher(
4139 error_page_url, frame, error,
4140 NewCallback(this, &RenderView::AltErrorPageFinished)));
4141 return true;
4142}
4143
initial.commit09911bf2008-07-26 23:55:294144std::string RenderView::GetAltHTMLForTemplate(
4145 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394146 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294147 ResourceBundle::GetSharedInstance().GetRawDataResource(
4148 template_resource_id));
4149
4150 if (template_html.empty()) {
4151 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4152 return "";
4153 }
[email protected]7cd22a52009-07-14 00:40:254154
initial.commit09911bf2008-07-26 23:55:294155 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254156 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294157 template_html, &error_strings, "t");
4158}
[email protected]0e79b9e2009-02-13 04:20:484159
[email protected]15d79e12009-08-02 19:23:454160void RenderView::AltErrorPageFinished(WebFrame* frame,
4161 const WebURLError& original_error,
4162 const std::string& html) {
4163 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554164
4165 // If we failed to download the alternate error page, fall back to the
4166 // original error page if present. Otherwise, LoadNavigationErrorPage
4167 // will simply display a default error page.
4168 const std::string* html_to_load = &html;
4169 if (html.empty()) {
4170 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454171 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554172 html_to_load = &navigation_state->postponed_data();
4173 }
4174 LoadNavigationErrorPage(
4175 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454176}
4177
[email protected]30f75e62009-02-25 22:01:004178void RenderView::OnMoveOrResizeStarted() {
4179 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474180 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004181}
4182
[email protected]30f75e62009-02-25 22:01:004183void RenderView::OnResize(const gfx::Size& new_size,
4184 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104185 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474186 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104187
4188 if (send_preferred_size_changes_) {
4189 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4190 // either width or height, allow scroll bars.
4191 bool allow_scrollbars = (
4192 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244193 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104194 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4195 }
4196 }
4197
[email protected]30f75e62009-02-25 22:01:004198 RenderWidget::OnResize(new_size, resizer_rect);
4199}
[email protected]0aa477bd2009-03-23 22:21:434200
[email protected]00c39612010-03-06 02:53:284201void RenderView::DidInitiatePaint() {
4202 // Notify any pepper plugins that we started painting. The plugin "should"
4203 // never notified that we started painting, this is used for internal
4204 // bookkeeping only, so we know that the set can not change under us.
4205 for (std::set<WebPluginDelegatePepper*>::iterator i =
4206 current_pepper_plugins_.begin();
4207 i != current_pepper_plugins_.end(); ++i)
4208 (*i)->RenderViewInitiatedPaint();
4209}
4210
4211void RenderView::DidFlushPaint() {
4212 // Notify any pepper plugins that we painted. This will call into the plugin,
4213 // and we it may ask to close itself as a result. This will, in turn, modify
4214 // our set, possibly invalidating the iterator. So we iterate on a copy that
4215 // won't change out from under us.
4216 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4217 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4218 i != plugins.end(); ++i) {
4219 // The copy above makes sure our iterator is never invalid if some plugins
4220 // are destroyed. But some plugin may decide to close all of its views in
4221 // response to a paint in one of them, so we need to make sure each one is
4222 // still "current" before using it.
4223 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4224 (*i)->RenderViewFlushedPaint();
4225 }
4226
4227 WebFrame* main_frame = webview()->mainFrame();
4228
4229 // If we have a provisional frame we are between the start and commit stages
4230 // of loading and we don't want to save stats.
4231 if (!main_frame->provisionalDataSource()) {
4232 WebDataSource* ds = main_frame->dataSource();
4233 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4234 DCHECK(navigation_state);
4235
4236 Time now = Time::Now();
4237 if (navigation_state->first_paint_time().is_null()) {
4238 navigation_state->set_first_paint_time(now);
4239 }
4240 if (navigation_state->first_paint_after_load_time().is_null() &&
4241 !navigation_state->finish_load_time().is_null()) {
4242 navigation_state->set_first_paint_after_load_time(now);
4243 }
4244 }
4245}
4246
4247
[email protected]05d478752009-04-08 23:38:164248void RenderView::OnClearFocusedNode() {
4249 if (webview())
[email protected]26aa0482009-09-30 16:55:274250 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164251}
4252
[email protected]699ab0d2009-04-23 23:19:144253void RenderView::OnSetBackground(const SkBitmap& background) {
4254 if (webview())
[email protected]b4bb2502009-10-01 22:35:274255 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144256
4257 SetBackground(background);
4258}
4259
[email protected]8c66c5a2009-07-22 17:26:344260void RenderView::OnSetActive(bool active) {
4261 if (webview())
[email protected]b4bb2502009-10-01 22:35:274262 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264263
4264#if defined(OS_MACOSX)
4265 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4266 for (plugin_it = plugin_delegates_.begin();
4267 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4268 (*plugin_it)->SetWindowFocus(active);
4269 }
4270#endif
[email protected]8c66c5a2009-07-22 17:26:344271}
4272
[email protected]6ce7abc52010-02-02 18:40:144273#if defined(OS_MACOSX)
4274void RenderView::OnSetWindowVisibility(bool visible) {
4275 // Inform plugins that their container has changed visibility.
4276 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4277 for (plugin_it = plugin_delegates_.begin();
4278 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4279 (*plugin_it)->SetContainerVisibility(visible);
4280 }
4281}
[email protected]1e6e3c992010-02-08 15:52:134282
4283void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4284 gfx::Rect view_frame) {
4285 // Inform plugins that their window's frame has changed.
4286 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4287 for (plugin_it = plugin_delegates_.begin();
4288 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4289 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4290 }
4291}
[email protected]6ce7abc52010-02-02 18:40:144292#endif // OS_MACOSX
4293
[email protected]309d7a282009-03-24 09:18:274294void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584295 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394296 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324297 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474298 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394299 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4300 name,
4301 args,
4302 source_url,
4303 request_id,
[email protected]2f25d7b92009-06-10 00:06:474304 has_callback));
[email protected]309d7a282009-03-24 09:18:274305}
4306
[email protected]c6619182009-05-12 14:59:324307void RenderView::OnExtensionResponse(int request_id,
4308 bool success,
4309 const std::string& response,
4310 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354311 ExtensionProcessBindings::HandleResponse(
4312 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274313}
[email protected]c20210e62009-04-03 21:39:264314
[email protected]078b34612009-09-19 19:31:514315void RenderView::InjectToolstripCSS() {
4316 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4317 return;
4318
4319 static const base::StringPiece toolstrip_css(
4320 ResourceBundle::GetSharedInstance().GetRawDataResource(
4321 IDR_EXTENSION_TOOLSTRIP_CSS));
4322 std::string css = toolstrip_css.as_string();
4323 InsertCSS(L"", css, "ToolstripDefaultCSS");
4324}
4325
[email protected]7120f132009-07-20 21:05:374326void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494327 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194328 bool requires_incognito_access,
4329 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494330 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194331 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374332}
4333
[email protected]e7e4f3c2009-04-21 15:24:084334// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264335//
[email protected]7a9b51f2009-06-29 21:28:294336// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264337// The time points we keep are
4338// request: time document was requested by user
4339// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254340// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294341// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264342// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294343// first_paint: first paint performed
4344// first_paint_after_load: first paint performed after load is finished
4345// begin: request if it was user requested, start otherwise
4346//
[email protected]c20210e62009-04-03 21:39:264347// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254348// request->start,
[email protected]7a9b51f2009-06-29 21:28:294349// start->commit,
4350// commit->finish_document,
4351// finish_document->finish,
4352// begin->commit,
4353// begin->finishDoc,
4354// begin->finish,
4355// begin->first_paint,
4356// begin->first_paint_after_load
4357// commit->finishDoc,
4358// commit->first_paint,
4359// commit->first_paint_after_load,
4360// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264361//
[email protected]e7e4f3c2009-04-21 15:24:084362// It's possible for the request time not to be set, if a client
4363// redirect had been done (the user never requested the page)
4364// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294365// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264366void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274367 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564368 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454369 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564370
[email protected]f9f4841b2010-03-20 05:41:424371 // If we've already dumped, do nothing.
4372 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294373 return;
[email protected]b855ebe62010-05-12 23:01:454374 Time start = navigation_state->start_load_time();
4375 if (start.is_null())
4376 return; // Probably very premature abandonment of page.
4377 Time commit = navigation_state->commit_load_time();
4378 if (commit.is_null())
4379 return; // Probably very premature abandonment of page.
4380 // We properly handle null values for the next 3 variables.
4381 Time request = navigation_state->request_time();
4382 Time first_paint = navigation_state->first_paint_time();
4383 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
4384
4385 Time finish = navigation_state->finish_load_time();
4386 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564387
[email protected]f9f4841b2010-03-20 05:41:424388 // Handle case where user hits "stop" or "back" before loading completely.
4389 bool abandoned_page = finish.is_null();
4390 if (abandoned_page) {
4391 finish = Time::Now();
4392 navigation_state->set_finish_load_time(finish);
4393 }
[email protected]b855ebe62010-05-12 23:01:454394 if (finish_doc.is_null()) {
4395 finish_doc = Time::Now();
4396 navigation_state->set_finish_document_load_time(finish_doc);
4397 }
[email protected]f9f4841b2010-03-20 05:41:424398 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4399
[email protected]f8999642009-10-27 21:39:424400 LogNavigationState(navigation_state, main_frame->dataSource());
4401
[email protected]a7ccc4d2010-01-27 08:14:484402 NavigationState::LoadType load_type = navigation_state->load_type();
4403 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184404 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484405
[email protected]ab9eabac2010-03-16 16:54:104406 // Site isolation metrics.
4407 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4408 cross_origin_access_count_);
4409 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4410 same_origin_access_count_);
4411
[email protected]c20210e62009-04-03 21:39:264412
[email protected]7a9b51f2009-06-29 21:28:294413 Time begin;
4414 // Client side redirects will have no request time.
4415 if (request.is_null()) {
4416 begin = start;
4417 } else {
4418 begin = request;
4419 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084420 }
[email protected]7a9b51f2009-06-29 21:28:294421 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4422 UMA_HISTOGRAM_MEDIUM_TIMES(
4423 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4424 UMA_HISTOGRAM_MEDIUM_TIMES(
4425 "Renderer4.FinishDocToFinish", finish - finish_doc);
4426
4427 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484428
4429 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4430 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4431 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484432 TimeDelta begin_to_finish_doc = finish_doc - begin;
4433 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184434
4435 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4436 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4437 static const size_t kBeginToFinishBucketCount(100);
4438 TimeDelta begin_to_finish = finish_doc - begin;
4439 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4440 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4441
[email protected]a7ccc4d2010-01-27 08:14:484442 switch (load_type) {
4443 case NavigationState::UNDEFINED_LOAD:
4444 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4445 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4446 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184447 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4448 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4449 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484450 break;
4451 case NavigationState::RELOAD:
4452 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4453 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4454 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184455 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4456 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4457 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484458 break;
4459 case NavigationState::HISTORY_LOAD:
4460 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4461 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4462 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184463 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4464 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4465 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484466 break;
4467 case NavigationState::NORMAL_LOAD:
4468 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4469 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4470 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184471 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4472 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4473 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484474 break;
[email protected]4c1b6f0b2010-02-07 16:38:184475 case NavigationState::LINK_LOAD_NORMAL:
4476 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484477 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4478 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184479 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4480 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4481 kBeginToFinishBucketCount);
4482 break;
4483 case NavigationState::LINK_LOAD_RELOAD:
4484 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4485 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4486 kBeginToFinishDocBucketCount);
4487 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4488 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4489 kBeginToFinishBucketCount);
4490 break;
4491 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4492 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4493 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4494 kBeginToFinishDocBucketCount);
4495 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4496 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4497 kBeginToFinishBucketCount);
4498 break;
4499 case NavigationState::LINK_LOAD_CACHE_ONLY:
4500 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4501 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4502 kBeginToFinishDocBucketCount);
4503 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4504 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4505 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484506 break;
4507 default:
4508 break;
4509 }
4510
4511 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4512 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4513 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424514 UMA_HISTOGRAM_ENUMERATION(
4515 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4516 abandoned_page ? 1 : 0, 2);
4517 UMA_HISTOGRAM_ENUMERATION(
4518 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484519 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484520 switch (load_type) {
4521 case NavigationState::NORMAL_LOAD:
4522 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184523 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4524 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4525 kBeginToFinishBucketCount);
4526 break;
4527 case NavigationState::LINK_LOAD_NORMAL:
4528 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184529 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4530 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4531 kBeginToFinishBucketCount);
4532 break;
4533 case NavigationState::LINK_LOAD_RELOAD:
4534 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184535 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4536 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4537 kBeginToFinishBucketCount);
4538 break;
4539 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4540 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184541 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4542 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4543 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484544 break;
4545 default:
4546 break;
4547 }
4548 }
4549
4550 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4551 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4552 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484553 UMA_HISTOGRAM_ENUMERATION(
4554 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4555 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484556 switch (load_type) {
4557 case NavigationState::NORMAL_LOAD:
4558 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484559 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4560 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4561 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484562 break;
[email protected]4c1b6f0b2010-02-07 16:38:184563 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484564 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484565 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4566 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4567 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184568 break;
4569 case NavigationState::LINK_LOAD_RELOAD:
4570 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484571 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4572 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4573 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184574 break;
4575 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4576 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484577 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4578 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4579 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184580 break;
4581 case NavigationState::LINK_LOAD_CACHE_ONLY:
4582 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484583 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4584 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4585 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484586 break;
4587 default:
4588 break;
4589 }
4590 }
4591
4592 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4593 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184594 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4595 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484596 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4597 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4598 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4599 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544600
[email protected]65041fa2010-05-21 06:56:534601 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
4602 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
4603 if (use_spdy_histogram) {
4604 switch (load_type) {
4605 case NavigationState::LINK_LOAD_NORMAL:
4606 if (navigation_state->was_npn_negotiated()) {
4607 DCHECK(FieldTrialList::Find("SpdyImpact")->group_name() ==
4608 "_npn_with_http" ||
4609 FieldTrialList::Find("SpdyImpact")->group_name() ==
4610 "_npn_with_spdy");
4611 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4612 "Renderer4.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4613 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4614 kBeginToFinishBucketCount);
4615 }
4616 break;
4617 default:
4618 break;
4619 }
4620 }
4621
[email protected]0a32257a2009-07-09 18:10:414622 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4623 finish - start, kBeginToFinishMin,
4624 kBeginToFinishMax, kBeginToFinishBucketCount);
4625 if (!request.is_null())
4626 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4627 finish - request, kBeginToFinishMin,
4628 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544629
[email protected]7a9b51f2009-06-29 21:28:294630 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4631
4632 if (!first_paint.is_null()) {
[email protected]b855ebe62010-05-12 23:01:454633 DCHECK(begin <= first_paint);
[email protected]7a9b51f2009-06-29 21:28:294634 UMA_HISTOGRAM_MEDIUM_TIMES(
4635 "Renderer4.BeginToFirstPaint", first_paint - begin);
[email protected]b855ebe62010-05-12 23:01:454636 DCHECK(commit <= first_paint);
[email protected]7a9b51f2009-06-29 21:28:294637 UMA_HISTOGRAM_MEDIUM_TIMES(
4638 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264639 }
[email protected]7a9b51f2009-06-29 21:28:294640
4641 if (!first_paint_after_load.is_null()) {
[email protected]b855ebe62010-05-12 23:01:454642 DCHECK(begin <= first_paint_after_load);
[email protected]7a9b51f2009-06-29 21:28:294643 UMA_HISTOGRAM_MEDIUM_TIMES(
4644 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
[email protected]b855ebe62010-05-12 23:01:454645 DCHECK(commit <= first_paint_after_load);
[email protected]7a9b51f2009-06-29 21:28:294646 UMA_HISTOGRAM_MEDIUM_TIMES(
4647 "Renderer4.CommitToFirstPaintAfterLoad",
4648 first_paint_after_load - commit);
[email protected]b855ebe62010-05-12 23:01:454649 DCHECK(finish <= first_paint_after_load);
[email protected]7a9b51f2009-06-29 21:28:294650 UMA_HISTOGRAM_MEDIUM_TIMES(
4651 "Renderer4.FinishToFirstPaintAfterLoad",
4652 first_paint_after_load - finish);
4653 }
4654
4655 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414656
4657 // Since there are currently no guarantees that renderer histograms will be
4658 // sent to the browser, we initiate a PostTask here to be sure that we send
4659 // the histograms we generated. Without this call, pages that don't have an
4660 // on-close-handler might generate data that is lost when the renderer is
4661 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484662 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4663 // should post when the onload is complete, so that it doesn't interfere with
4664 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414665 if (RenderThread::current()) {
4666 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134667 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414668 }
[email protected]c20210e62009-04-03 21:39:264669}
[email protected]e846d0d2009-05-20 00:53:064670
[email protected]f8999642009-10-27 21:39:424671void RenderView::LogNavigationState(const NavigationState* state,
4672 const WebDataSource* ds) const {
4673 // Because this function gets called on every page load,
4674 // take extra care to optimize it away if logging is turned off.
4675 if (logging::LOG_INFO < logging::GetMinLogLevel())
4676 return;
4677
4678 DCHECK(state);
4679 DCHECK(ds);
4680 GURL url(ds->request().url());
4681 Time start = state->start_load_time();
4682 Time finish = state->finish_load_time();
4683 // TODO(mbelshe): should we log more stats?
4684 LOG(INFO) << "PLT: "
4685 << (finish - start).InMilliseconds()
4686 << "ms "
4687 << url.spec();
4688}
4689
[email protected]cc0445f2009-10-13 16:09:084690void RenderView::focusAccessibilityObject(
4691 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064692#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154693 // TODO(dglazkov): Current logic implies that focus change can only be made
4694 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4695 // where accessibility is initialized. We should determine whether that's
4696 // right.
4697 if (!accessibility_.get())
4698 return;
[email protected]e846d0d2009-05-20 00:53:064699
4700 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154701 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064702
4703 // If id is valid, alert the browser side that an accessibility focus change
4704 // occurred.
4705 if (acc_obj_id >= 0)
4706 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4707
4708#else // defined(OS_WIN)
4709 // TODO(port): accessibility not yet implemented
4710 NOTIMPLEMENTED();
4711#endif
4712}
[email protected]daa8c58e2009-06-15 17:21:104713
[email protected]e9e07992010-02-17 21:04:364714void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044715 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4716 // control elements in the cache.
4717 WebVector<WebFormElement> web_forms;
4718 frame->forms(web_forms);
4719
[email protected]b1438212010-04-03 00:30:594720 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044721 for (size_t i = 0; i < web_forms.size(); ++i) {
4722 const WebFormElement& web_form = web_forms[i];
4723
4724 FormData form;
[email protected]b715f7f2010-04-05 22:01:044725 if (FormManager::WebFormElementToFormData(
[email protected]573c1c272010-05-25 19:28:064726 web_form, FormManager::REQUIRE_NONE, false, &form))
[email protected]b715f7f2010-04-05 22:01:044727 forms.push_back(form);
4728 }
[email protected]e6efd022010-03-31 09:34:504729
4730 if (!forms.empty())
4731 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364732}
4733
[email protected]a3018be2010-03-09 04:28:484734void RenderView::didChangeAccessibilityObjectState(
4735 const WebKit::WebAccessibilityObject& acc_obj) {
4736#if defined(OS_WIN)
4737 // TODO(dglazkov): Current logic implies that a state change can only be made
4738 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4739 // where accessibility is initialized. We should determine whether that's
4740 // right.
4741 if (!accessibility_.get())
4742 return;
4743
4744 // Retrieve the accessibility object id of the AccessibilityObject.
4745 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4746
4747 // If id is valid, alert the browser side that an accessibility object state
4748 // change occurred.
4749 if (acc_obj_id >= 0)
4750 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4751 acc_obj_id));
4752
4753#else // defined(OS_WIN)
4754 // TODO(port): accessibility not yet implemented
4755 NOTIMPLEMENTED();
4756#endif
4757}
4758
[email protected]4d44a1c2010-04-28 19:20:414759void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) {
[email protected]55ced002010-05-21 04:49:594760 // Make sure that this security origin is allowed to use password manager.
4761 WebSecurityOrigin security_origin = frame->securityOrigin();
4762 if (!security_origin.canAccessPasswordManager())
4763 return;
4764
[email protected]979c28b2009-11-07 01:30:484765 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454766 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104767
4768 std::vector<PasswordForm> password_forms;
4769 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484770 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104771
4772 // Respect autocomplete=off.
[email protected]4d44a1c2010-04-28 19:20:414773 if (!form.autoComplete())
4774 continue;
4775 if (only_visible && !form.hasNonEmptyBoundingBox())
4776 continue;
4777 scoped_ptr<PasswordForm> password_form(
4778 PasswordFormDomManager::CreatePasswordForm(form));
4779 if (password_form.get())
4780 password_forms.push_back(*password_form);
[email protected]daa8c58e2009-06-15 17:21:104781 }
4782
[email protected]4d44a1c2010-04-28 19:20:414783 if (password_forms.empty())
4784 return;
4785 if (only_visible)
4786 Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms));
4787 else
4788 Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms));
[email protected]daa8c58e2009-06-15 17:21:104789}
[email protected]0fda7272009-06-26 15:49:334790
4791void RenderView::Print(WebFrame* frame, bool script_initiated) {
4792 DCHECK(frame);
4793 if (print_helper_.get() == NULL) {
4794 print_helper_.reset(new PrintWebViewHelper(this));
4795 }
4796 print_helper_->Print(frame, script_initiated);
4797}
[email protected]446705872009-09-10 07:22:484798
4799void RenderView::OnSetEditCommandsForNextKeyEvent(
4800 const EditCommands& edit_commands) {
4801 edit_commands_ = edit_commands;
4802}
4803
[email protected]61f5a7b2009-12-22 22:21:204804void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274805 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354806 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204807 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4808 false));
[email protected]912256b32009-09-18 09:47:354809 return;
4810 }
4811
[email protected]fa7b6b542009-11-03 05:02:304812 WebDataSource* ds = main_frame->dataSource();
4813 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4814 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204815 pending_code_execution_queue_.push(
4816 linked_ptr<ViewMsg_ExecuteCode_Params>(
4817 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304818 return;
4819 }
4820
[email protected]61f5a7b2009-12-22 22:21:204821 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304822}
4823
4824void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204825 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484826 // Don't execute scripts in gallery pages.
4827 GURL frame_url = GURL(frame->url());
4828 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4829 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4830 return;
4831 }
4832
[email protected]20ad2692009-11-20 18:27:204833 std::vector<WebFrame*> frame_vector;
4834 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204835 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204836 GetAllChildFrames(frame, &frame_vector);
4837
4838 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4839 frame_it != frame_vector.end(); ++frame_it) {
4840 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204841 if (params.is_javascript) {
4842 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4843 continue;
4844
[email protected]20ad2692009-11-20 18:27:204845 std::vector<WebScriptSource> sources;
4846 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204847 WebScriptSource(WebString::fromUTF8(params.code)));
4848 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204849 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204850 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204851 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4852 } else {
[email protected]61f5a7b2009-12-22 22:21:204853 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204854 }
[email protected]912256b32009-09-18 09:47:354855 }
4856
[email protected]61f5a7b2009-12-22 22:21:204857 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354858}
4859
[email protected]60c42a8c72009-10-09 04:08:594860void RenderView::Close() {
4861 // We need to grab a pointer to the doomed WebView before we destroy it.
4862 WebView* doomed = webview();
4863 RenderWidget::Close();
4864 Singleton<ViewMap>::get()->erase(doomed);
4865}
4866
[email protected]446705872009-09-10 07:22:484867void RenderView::DidHandleKeyEvent() {
4868 edit_commands_.clear();
4869}
4870
[email protected]941e4552010-02-01 21:23:434871#if defined(OS_MACOSX)
4872void RenderView::OnWasHidden() {
4873 RenderWidget::OnWasHidden();
4874
4875 // Inform plugins that their container is no longer visible.
4876 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4877 for (plugin_it = plugin_delegates_.begin();
4878 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4879 (*plugin_it)->SetContainerVisibility(false);
4880 }
4881}
4882
4883void RenderView::OnWasRestored(bool needs_repainting) {
4884 RenderWidget::OnWasRestored(needs_repainting);
4885
4886 // Inform plugins that their container is now visible.
4887 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4888 for (plugin_it = plugin_delegates_.begin();
4889 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4890 (*plugin_it)->SetContainerVisibility(true);
4891 }
4892}
[email protected]1e6e3c992010-02-08 15:52:134893
4894void RenderView::OnSetFocus(bool enable) {
4895 RenderWidget::OnSetFocus(enable);
4896
[email protected]7d3c02c2010-05-05 23:10:314897 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:134898 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4899 for (plugin_it = plugin_delegates_.begin();
4900 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:314901 // RenderWidget's call to setFocus can cause the underlying webview's
4902 // activation state to change just like a call to setIsActive.
4903 if (enable)
4904 (*plugin_it)->SetWindowFocus(true);
4905 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134906 }
4907 }
4908}
[email protected]941e4552010-02-01 21:23:434909#endif // OS_MACOSX
4910
[email protected]83dde542009-09-11 20:59:554911void RenderView::EnsureDocumentTag() {
4912 // TODO(darin): There's actually no reason for this to be here. We should
4913 // have the browser side manage the document tag.
4914#if defined(OS_MACOSX)
4915 if (!has_document_tag_) {
4916 // Make the call to get the tag.
4917 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4918 has_document_tag_ = true;
4919 }
4920#endif
4921}
[email protected]12636df2009-09-28 22:32:214922
[email protected]43f28f832010-02-03 02:28:484923#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:034924gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
4925 bool opaque) {
[email protected]43f28f832010-02-03 02:28:484926 gfx::PluginWindowHandle window = NULL;
4927 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]ea04a4e12010-04-15 00:58:034928 routing_id(), opaque, &window));
[email protected]43f28f832010-02-03 02:28:484929 return window;
4930}
4931
4932void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4933 if (window)
4934 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4935}
4936
[email protected]44ce0b12010-03-12 16:45:334937void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4938 int32 width,
4939 int32 height,
4940 uint64 io_surface_identifier) {
4941 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484942 routing_id(), window, width, height, io_surface_identifier));
4943}
4944
[email protected]44ce0b12010-03-12 16:45:334945void RenderView::AcceleratedSurfaceSetTransportDIB(
4946 gfx::PluginWindowHandle window,
4947 int32 width,
4948 int32 height,
4949 TransportDIB::Handle transport_dib) {
4950 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074951 routing_id(), window, width, height, transport_dib));
4952}
4953
[email protected]44ce0b12010-03-12 16:45:334954TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4955 size_t size) {
[email protected]1aef98132010-02-23 18:00:074956 TransportDIB::Handle dib_handle;
4957 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384958 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074959 return dib_handle;
4960 // Return an invalid handle if Send() fails.
4961 return TransportDIB::DefaultHandleValue();
4962}
4963
[email protected]44ce0b12010-03-12 16:45:334964void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074965 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4966}
4967
[email protected]44ce0b12010-03-12 16:45:334968void RenderView::AcceleratedSurfaceBuffersSwapped(
4969 gfx::PluginWindowHandle window) {
4970 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484971}
4972#endif
[email protected]58c321d2010-02-19 12:11:284973
[email protected]cdaf8d02010-03-30 19:52:474974bool RenderView::ScheduleFileChooser(
4975 const ViewHostMsg_RunFileChooser_Params& params,
4976 WebFileChooserCompletion* completion) {
4977 static const size_t kMaximumPendingFileChooseRequests = 4;
4978 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4979 // This sanity check prevents too many file choose requests from getting
4980 // queued which could DoS the user. Getting these is most likely a
4981 // programming error (there are many ways to DoS the user so it's not
4982 // considered a "real" security check), either in JS requesting many file
4983 // choosers to pop up, or in a plugin.
4984 //
4985 // TODO(brettw) we might possibly want to require a user gesture to open
4986 // a file picker, which will address this issue in a better way.
4987 return false;
4988 }
4989
4990 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4991 new PendingFileChooser(params, completion)));
4992 if (file_chooser_completions_.size() == 1) {
4993 // Actually show the browse dialog when this is the first request.
4994 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4995 }
4996 return true;
4997}
4998
[email protected]290838a2010-04-27 17:37:014999void RenderView::OnPageTranslated() {
5000 WebFrame* frame = webview()->mainFrame();
5001 if (!frame)
5002 return;
5003
5004 // The page is translated, so try to extract the form data again.
5005 form_manager_.ExtractForms(frame);
5006 SendForms(frame);
5007}
5008
[email protected]8a5f7002010-03-31 13:47:355009WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285010 if (!geolocation_dispatcher_.get())
5011 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5012 return geolocation_dispatcher_.get();
5013}
[email protected]61c9f032010-03-31 23:04:195014
[email protected]8079b362010-05-07 18:37:455015bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195016 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455017 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195018 if (frame->parent() != NULL)
5019 return false;
5020
5021 // Skip if navigation is on the same page (using '#').
5022 GURL frame_origin = GURL(frame->url()).GetOrigin();
5023 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5024 // The link click could stay on the same page, in cases where it sends some
5025 // parameters to the same URL.
5026 if (type == WebKit::WebNavigationTypeLinkClicked)
5027 return true;
5028
5029 if (last_top_level_navigation_page_id_ != page_id_ &&
5030 // Not interested in reloads.
5031 type != WebKit::WebNavigationTypeReload &&
5032 type != WebKit::WebNavigationTypeFormSubmitted) {
5033 return true;
5034 }
5035 }
5036 return false;
5037}