blob: f8f3c39e6a1b144b7a5a40fe17937159aa4beaab [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]4e0616e2010-05-28 14:55:5335#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2637#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5939#include "chrome/common/url_constants.h"
[email protected]534c66c2010-04-28 22:53:1140#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2542#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1143#include "chrome/renderer/devtools_agent.h"
44#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3545#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3246#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3547#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3748#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2849#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5651#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1152#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5653#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1254#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3055#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5056#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2557#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2858#include "chrome/renderer/render_thread.h"
[email protected]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]acca2a12009-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]6f496b22010-05-27 22:59:201091 if (webview()->mainFrame()->document().isPluginDocument()) {
1092 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
1093 delegate->Copy();
1094 return;
1095 }
1096
[email protected]26aa0482009-09-30 16:55:271097 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121098 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291099}
1100
[email protected]c0cc3092009-09-12 08:27:271101#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351102void RenderView::OnCopyToFindPboard() {
1103 if (!webview())
1104 return;
1105
1106 // Since the find pasteboard supports only plain text, this can be simpler
1107 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271108 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351109 if (frame->hasSelection()) {
1110 string16 selection = frame->selectionAsText();
1111 RenderThread::current()->Send(
1112 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1113 }
1114
[email protected]afe3a1672009-11-17 19:04:121115 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351116}
[email protected]c0cc3092009-09-12 08:27:271117#endif
[email protected]a954bf72009-09-12 07:30:351118
initial.commit09911bf2008-07-26 23:55:291119void RenderView::OnPaste() {
1120 if (!webview())
1121 return;
1122
[email protected]26aa0482009-09-30 16:55:271123 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121124 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291125}
1126
[email protected]2a3a7762009-10-19 19:17:321127void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291128 if (!webview())
1129 return;
1130
[email protected]1ff7a032010-02-03 02:46:031131 WebFrame* frame = webview()->focusedFrame();
1132 if (!frame->hasSelection())
1133 frame->selectWordAroundCaret();
1134 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291135}
1136
[email protected]98324892009-09-09 21:16:051137void RenderView::OnAdvanceToNextMisspelling() {
1138 if (!webview())
1139 return;
[email protected]26aa0482009-09-30 16:55:271140 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051141 WebString::fromUTF8("AdvanceToNextMisspelling"));
1142}
1143
1144void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1145 if (!webview())
1146 return;
1147 // We need to tell the webView whether the spelling panel is visible or not so
1148 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261149 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271150 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051151 WebString::fromUTF8("ToggleSpellPanel"));
1152}
1153
[email protected]bbbd545c2008-12-15 20:18:041154void RenderView::OnToggleSpellCheck() {
1155 if (!webview())
1156 return;
1157
[email protected]26aa0482009-09-30 16:55:271158 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451159 frame->enableContinuousSpellChecking(
1160 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041161}
1162
initial.commit09911bf2008-07-26 23:55:291163void RenderView::OnDelete() {
1164 if (!webview())
1165 return;
1166
[email protected]26aa0482009-09-30 16:55:271167 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121168 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291169}
1170
1171void RenderView::OnSelectAll() {
1172 if (!webview())
1173 return;
1174
[email protected]26aa0482009-09-30 16:55:271175 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221176 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121177 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291178}
1179
1180void RenderView::OnSetInitialFocus(bool reverse) {
1181 if (!webview())
1182 return;
[email protected]26aa0482009-09-30 16:55:271183 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291184}
1185
1186///////////////////////////////////////////////////////////////////////////////
1187
[email protected]433819d2010-01-30 20:20:011188void RenderView::SetContentSettings(const ContentSettings& settings) {
1189 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011190}
1191
initial.commit09911bf2008-07-26 23:55:291192// Tell the embedding application that the URL of the active page has changed
1193void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451194 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291195 DCHECK(ds);
1196
[email protected]726985e22009-06-18 21:09:281197 const WebURLRequest& request = ds->request();
1198 const WebURLRequest& original_request = ds->originalRequest();
1199 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291200
[email protected]daa8c58e2009-06-15 17:21:101201 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1202 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291203
1204 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281205 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291206 params.is_post = false;
1207 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281208 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551209 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291210 // SSL state specified in the request takes precedence over the one in the
1211 // response.
1212 // So far this is only intended for error pages that are not expected to be
1213 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281214 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551215 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291216 } else {
[email protected]726985e22009-06-18 21:09:281217 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291218 }
1219
1220 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281221 if (ds->hasUnreachableURL()) {
1222 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291223 } else {
[email protected]726985e22009-06-18 21:09:281224 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291225 }
1226
[email protected]726985e22009-06-18 21:09:281227 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241228 params.should_update_history = !ds->hasUnreachableURL() &&
1229 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291230
[email protected]ce0e250d2009-10-23 21:00:351231 params.searchable_form_url = navigation_state->searchable_form_url();
1232 params.searchable_form_encoding =
1233 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291234
1235 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101236 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291237 if (password_form_data)
1238 params.password_form = *password_form_data;
1239
1240 params.gesture = navigation_gesture_;
1241 navigation_gesture_ = NavigationGestureUnknown;
1242
[email protected]dd7daa82009-08-10 05:46:451243 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291244 // Top-level navigation.
1245
[email protected]71b0d5d2010-02-15 05:43:071246 // Clear "block" flags for the new page. This needs to happen before any of
1247 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1248 // so that these functions can correctly detect that a piece of content
1249 // flipped from "not blocked" to "blocked".
1250 ClearBlockedContentSettings();
1251
[email protected]62d2a112010-04-07 00:53:021252 // Set content settings. Default them from the parent window if one exists.
1253 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011254 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541255 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011256 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011257 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011258
1259 // These content settings were merely recorded transiently for this load.
1260 // We can erase them now. If at some point we reload this page, the
1261 // browser will send us new, up-to-date content settings.
1262 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401263 } else if (frame->opener()) {
1264 WebView* opener_view = frame->opener()->view();
1265 RenderView* opener = FromWebView(opener_view);
1266 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011267 }
1268
[email protected]40bd6582009-12-04 23:49:511269 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011270 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541271 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011272 if (host_zoom != host_zoom_levels_.end()) {
1273 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511274 // This zoom level was merely recorded transiently for this load. We can
1275 // erase it now. If at some point we reload this page, the browser will
1276 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011277 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511278 }
1279
initial.commit09911bf2008-07-26 23:55:291280 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551281 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291282
[email protected]daa8c58e2009-06-15 17:21:101283 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291284 if (!PageTransition::IsMainFrame(params.transition)) {
1285 // If the main frame does a load, it should not be reported as a subframe
1286 // navigation. This can occur in the following case:
1287 // 1. You're on a site with frames.
1288 // 2. You do a subframe navigation. This is stored with transition type
1289 // MANUAL_SUBFRAME.
1290 // 3. You navigate to some non-frame site, say, google.com.
1291 // 4. You navigate back to the page from step 2. Since it was initially
1292 // MANUAL_SUBFRAME, it will be that same transition type here.
1293 // We don't want that, because any navigation that changes the toplevel
1294 // frame should be tracked as a toplevel navigation (this allows us to
1295 // update the URL bar, etc).
1296 params.transition = PageTransition::LINK;
1297 }
1298
initial.commit09911bf2008-07-26 23:55:291299 // If we have a valid consumed client redirect source,
1300 // the page contained a client redirect (meta refresh, document.loc...),
1301 // so we set the referrer and transition to match.
1302 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041303 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291304 params.referrer = completed_client_redirect_src_;
1305 params.transition = static_cast<PageTransition::Type>(
1306 params.transition | PageTransition::CLIENT_REDIRECT);
1307 } else {
1308 // Bug 654101: the referrer will be empty on https->http transitions. It
1309 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281310 params.referrer = GURL(
1311 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291312 }
1313
[email protected]726985e22009-06-18 21:09:281314 string16 method = request.httpMethod();
1315 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291316 params.is_post = true;
1317
[email protected]c2a797d2009-09-21 16:46:321318 // Save some histogram data so we can compute the average memory used per
1319 // page load of the glyphs.
1320 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1321 webkit_glue::GetGlyphPageCount());
1322
[email protected]15cf526b2010-02-12 06:33:491323 // This message needs to be sent before any of allowScripts(),
1324 // allowImages(), allowPlugins() is called for the new page, so that when
1325 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1326 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291327 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1328 } else {
1329 // Subframe navigation: the type depends on whether this navigation
1330 // generated a new session history entry. When they do generate a session
1331 // history entry, it means the user initiated the navigation and we should
1332 // mark it as such. This test checks if this is the first time UpdateURL
1333 // has been called since WillNavigateToURL was called to initiate the load.
1334 if (page_id_ > last_page_id_sent_to_browser_)
1335 params.transition = PageTransition::MANUAL_SUBFRAME;
1336 else
1337 params.transition = PageTransition::AUTO_SUBFRAME;
1338
initial.commit09911bf2008-07-26 23:55:291339 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1340 }
1341
1342 last_page_id_sent_to_browser_ =
1343 std::max(last_page_id_sent_to_browser_, page_id_);
1344
1345 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101346 // we don't want the transition type to persist. Just clear it.
1347 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501348
[email protected]c7287a92009-11-04 20:06:151349 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091350 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351351 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501352 }
initial.commit09911bf2008-07-26 23:55:291353}
1354
1355// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171356void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291357 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171358 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171359 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171360 routing_id_,
1361 page_id_,
1362 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1363 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171364 }
initial.commit09911bf2008-07-26 23:55:291365}
1366
1367void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401368 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291369 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271370 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291371 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301372 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291373 last_encoding_name_ = encoding_name;
1374
[email protected]e38f40152008-09-12 23:08:301375 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291376 }
1377}
1378
[email protected]f4d34b52008-11-24 23:05:011379// Sends the previous session history state to the browser so it will be saved
1380// before we navigate to a new page. This must be called *before* the page ID
1381// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291382void RenderView::UpdateSessionHistory(WebFrame* frame) {
1383 // If we have a valid page ID at this point, then it corresponds to the page
1384 // we are navigating away from. Otherwise, this is the first navigation, so
1385 // there is no past session history to record.
1386 if (page_id_ == -1)
1387 return;
1388
[email protected]ca948a22009-06-25 19:36:171389 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271390 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171391 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291392 return;
[email protected]ca948a22009-06-25 19:36:171393
1394 Send(new ViewHostMsg_UpdateState(
1395 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291396}
1397
[email protected]3d9689372009-09-10 04:29:171398void RenderView::OpenURL(
1399 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1400 Send(new ViewHostMsg_OpenURL(
1401 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1402}
1403
[email protected]79dbc662009-09-04 05:42:511404// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291405
initial.commit09911bf2008-07-26 23:55:291406void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281407 const WebURLRequest& failed_request,
1408 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291409 const std::string& html,
1410 bool replace) {
[email protected]726985e22009-06-18 21:09:281411 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291412
1413 std::string alt_html;
1414 if (html.empty()) {
1415 // Use a local error page.
1416 int resource_id;
1417 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281418 if (error.reason == net::ERR_CACHE_MISS &&
1419 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291420 GetFormRepostErrorValues(failed_url, &error_strings);
1421 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1422 } else {
1423 GetLocalizedErrorValues(error, &error_strings);
1424 resource_id = IDR_NET_ERROR_HTML;
1425 }
initial.commit09911bf2008-07-26 23:55:291426
1427 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1428 } else {
1429 alt_html = html;
1430 }
1431
[email protected]dd7daa82009-08-10 05:46:451432 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551433 GURL(kUnreachableWebDataURL),
1434 failed_url,
1435 replace);
initial.commit09911bf2008-07-26 23:55:291436}
1437
[email protected]7ccddb8c2009-08-04 17:36:551438void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291439 dom_automation_controller_.set_message_sender(this);
1440 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551441 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291442 L"domAutomationController");
1443}
1444
initial.commit09911bf2008-07-26 23:55:291445bool RenderView::RunJavaScriptMessage(int type,
1446 const std::wstring& message,
1447 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071448 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291449 std::wstring* result) {
1450 bool success = false;
1451 std::wstring result_temp;
1452 if (!result)
1453 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291454
[email protected]12636df2009-09-28 22:32:211455 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1456 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291457 return success;
1458}
1459
[email protected]c1f50aa2010-02-18 03:46:571460bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1461 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1462 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1463 // it is particularly important that we do not call willEnterModalLoop as
1464 // that would defer resource loads for the dialog itself.
1465 if (RenderThread::current()) // Will be NULL during unit tests.
1466 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1467
1468 message->EnableMessagePumping(); // Runs a nested message loop.
1469 return Send(message);
1470}
1471
initial.commit09911bf2008-07-26 23:55:291472void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1473 if (!osd_url.is_empty())
1474 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1475 autodetected));
1476}
1477
[email protected]95056b582010-02-18 01:29:241478void RenderView::OnAutoFillSuggestionsReturned(
1479 int query_id,
[email protected]8f6e6582010-04-09 02:03:071480 const std::vector<string16>& values,
[email protected]95056b582010-02-18 01:29:241481 const std::vector<string16>& labels,
1482 int default_suggestion_index) {
1483 if (webview() && query_id == autofill_query_id_) {
1484 webview()->applyAutoFillSuggestions(
[email protected]8f6e6582010-04-09 02:03:071485 autofill_query_node_, values, labels, default_suggestion_index);
[email protected]95056b582010-02-18 01:29:241486 }
1487 autofill_query_node_.reset();
1488}
1489
[email protected]cf28ec52010-04-09 22:56:341490void RenderView::OnAutoFillForms(
1491 const std::vector<webkit_glue::FormData>& forms) {
1492 form_manager_.FillForms(forms);
1493}
1494
[email protected]95056b582010-02-18 01:29:241495void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a12009-10-16 03:53:391496 int query_id,
1497 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031498 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181499 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081500 webview()->applyAutocompleteSuggestions(
[email protected]acca2a12009-10-16 03:53:391501 autofill_query_node_, suggestions, default_suggestion_index);
1502 }
1503 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031504}
1505
[email protected]45c6e532010-03-15 23:51:241506void RenderView::OnAutoFillFormDataFilled(int query_id,
1507 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481508 if (query_id != autofill_query_id_)
1509 return;
1510
1511 form_manager_.FillForm(form);
1512}
1513
[email protected]e8345242010-05-06 03:00:401514void RenderView::OnAllowScriptToClose(bool script_can_close) {
1515 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311516}
1517
initial.commit09911bf2008-07-26 23:55:291518uint32 RenderView::GetCPBrowsingContext() {
1519 uint32 context = 0;
1520 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1521 return context;
1522}
1523
initial.commit09911bf2008-07-26 23:55:291524void RenderView::AddSearchProvider(const std::string& url) {
1525 AddGURLSearchProvider(GURL(url),
1526 false); // not autodetected
1527}
1528
[email protected]f103ab72009-09-02 17:10:591529void RenderView::OnMissingPluginStatus(
1530 WebPluginDelegateProxy* delegate,
1531 int status) {
[email protected]6c8afae52009-01-22 02:24:571532#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591533 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291534 // Show the InfoBar for the first available plugin.
1535 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591536 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291537 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1538 }
1539 } else {
1540 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1541 // to start the download/install.
1542 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1543 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1544 }
1545 }
[email protected]6c8afae52009-01-22 02:24:571546#else
[email protected]76c3b312010-05-20 21:38:291547 // TODO(port): Implement the infobar that accompanies the default plugin.
1548 // Linux: http://crbug.com/10952
1549 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571550 NOTIMPLEMENTED();
1551#endif
initial.commit09911bf2008-07-26 23:55:291552}
1553
[email protected]48c9cf2d2009-09-16 16:47:521554// WebKit::WebViewClient ------------------------------------------------------
1555
[email protected]534c66c2010-04-28 22:53:111556WebView* RenderView::createView(
1557 WebFrame* creator,
1558 const WebWindowFeatures& features) {
[email protected]48c9cf2d2009-09-16 16:47:521559 // Check to make sure we aren't overloading on popups.
1560 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1561 return NULL;
1562
1563 // This window can't be closed from a window.close() call until we receive a
1564 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401565 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521566
1567 int32 routing_id = MSG_ROUTING_NONE;
1568 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461569 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341570 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521571
[email protected]48c9cf2d2009-09-16 16:47:521572 render_thread_->Send(
[email protected]534c66c2010-04-28 22:53:111573 new ViewHostMsg_CreateWindow(
1574 routing_id_,
1575 user_gesture,
1576 WindowFeaturesToContainerType(features),
1577 session_storage_namespace_id_,
1578 &routing_id,
1579 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211580 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521581 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521582
[email protected]48c9cf2d2009-09-16 16:47:521583 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421584 0,
[email protected]12636df2009-09-28 22:32:211585 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521586 renderer_preferences_,
1587 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211588 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341589 routing_id,
1590 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521591 view->opened_by_user_gesture_ = user_gesture;
1592
[email protected]007a848b2009-10-26 15:55:461593 // Record whether the creator frame is trying to suppress the opener field.
1594 view->opener_suppressed_ = opener_suppressed;
1595
[email protected]48c9cf2d2009-09-16 16:47:521596 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091597 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521598 if (!creator_url.is_valid() || !creator_url.IsStandard())
1599 creator_url = GURL();
1600 view->creator_url_ = creator_url;
1601
1602 // Copy over the alternate error page URL so we can have alt error pages in
1603 // the new render view (we don't need the browser to send the URL back down).
1604 view->alternate_error_page_url_ = alternate_error_page_url_;
1605
1606 return view->webview();
1607}
1608
[email protected]3e2b375b2010-04-07 17:03:121609WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521610 RenderWidget* widget = RenderWidget::Create(routing_id_,
1611 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121612 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521613 return widget->webwidget();
1614}
1615
1616WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1617 RenderWidget* widget = RenderWidget::Create(routing_id_,
1618 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121619 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521620 widget->ConfigureAsExternalPopupMenu(info);
1621 return widget->webwidget();
1622}
1623
[email protected]68c50e52010-05-12 11:14:391624WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341625 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391626 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291627 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1628 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1629 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341630}
1631
[email protected]48c9cf2d2009-09-16 16:47:521632void RenderView::didAddMessageToConsole(
1633 const WebConsoleMessage& message, const WebString& source_name,
1634 unsigned source_line) {
1635 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1636 UTF16ToWideHack(message.text),
1637 static_cast<int32>(source_line),
1638 UTF16ToWideHack(source_name)));
1639}
1640
1641void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581642 DCHECK(frame);
1643 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521644}
1645
1646void RenderView::didStartLoading() {
1647 if (is_loading_) {
1648 DLOG(WARNING) << "didStartLoading called while loading";
1649 return;
1650 }
1651
1652 is_loading_ = true;
1653 // Clear the pointer so that we can assign it only when there is an unknown
1654 // plugin on a page.
1655 first_default_plugin_.reset();
1656
1657 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1658}
1659
1660void RenderView::didStopLoading() {
1661 if (!is_loading_) {
1662 DLOG(WARNING) << "DidStopLoading called while not loading";
1663 return;
1664 }
1665
1666 is_loading_ = false;
1667
1668 // NOTE: For now we're doing the safest thing, and sending out notification
1669 // when done loading. This currently isn't an issue as the favicon is only
1670 // displayed when done loading. Ideally we would send notification when
1671 // finished parsing the head, but webkit doesn't support that yet.
1672 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271673 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521674 if (!favicon_url.is_empty())
1675 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1676
[email protected]26aa0482009-09-30 16:55:271677 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521678 true); // autodetected
1679
1680 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1681
[email protected]f9f4841b2010-03-20 05:41:421682 MessageLoop::current()->PostDelayedTask(
1683 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521684 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1685 false),
1686 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521687}
1688
[email protected]f55039a2010-02-17 14:12:061689bool RenderView::isSmartInsertDeleteEnabled() {
1690#if defined(OS_MACOSX)
1691 return true;
1692#else
1693 return false;
1694#endif
1695}
1696
[email protected]04fc9482009-09-18 22:13:031697bool RenderView::isSelectTrailingWhitespaceEnabled() {
1698#if defined(OS_WIN)
1699 return true;
1700#else
1701 return false;
1702#endif
1703}
1704
1705void RenderView::setInputMethodEnabled(bool enabled) {
1706 // Save the updated IME status and mark the input focus has been updated.
1707 // The IME status is to be sent to a browser process next time when
1708 // the input caret is rendered.
1709 if (!ime_control_busy_) {
1710 ime_control_updated_ = true;
1711 ime_control_new_state_ = enabled;
1712 }
1713}
1714
1715void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031716#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031717 if (!handling_input_event_)
1718 return;
1719 // TODO(estade): investigate incremental updates to the selection so that we
1720 // don't send the entire selection over IPC every time.
1721 if (!is_empty_selection) {
1722 // Sometimes we get repeated didChangeSelection calls from webkit when
1723 // the selection hasn't actually changed. We don't want to report these
1724 // because it will cause us to continually claim the X clipboard.
1725 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271726 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031727 if (this_selection == last_selection_)
1728 return;
1729
1730 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1731 this_selection));
1732 last_selection_ = this_selection;
1733 } else {
1734 last_selection_.clear();
1735 }
1736#endif
1737}
1738
1739void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121740 const std::string& name = UTF16ToUTF8(command_name);
1741 if (StartsWithASCII(name, "Move", true) ||
1742 StartsWithASCII(name, "Insert", true) ||
1743 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031744 return;
1745 UserMetricsRecordAction(name);
1746}
1747
[email protected]b2528b72009-09-24 06:57:101748bool RenderView::handleCurrentKeyboardEvent() {
1749 if (edit_commands_.empty())
1750 return false;
1751
[email protected]26aa0482009-09-30 16:55:271752 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101753 if (!frame)
1754 return false;
1755
1756 EditCommands::iterator it = edit_commands_.begin();
1757 EditCommands::iterator end = edit_commands_.end();
1758
[email protected]507b33ea2009-09-29 03:56:511759 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101760 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331761 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1762 // key (but it's the exception). Once one edit command is not executed, it
1763 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101764 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1765 WebString::fromUTF8(it->value)))
1766 break;
[email protected]507b33ea2009-09-29 03:56:511767 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101768 }
1769
[email protected]507b33ea2009-09-29 03:56:511770 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101771}
1772
[email protected]2a3a7762009-10-19 19:17:321773void RenderView::spellCheck(const WebString& text,
1774 int& misspelled_offset,
1775 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561776 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461777
[email protected]85c55dc2009-11-06 03:05:461778 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171779 RenderThread* thread = RenderThread::current();
1780 // Will be NULL during unit tests.
1781 if (thread) {
[email protected]c27324b2009-11-19 22:44:291782 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171783 word.c_str(), word.size(), document_tag_,
1784 &misspelled_offset, &misspelled_length, NULL);
1785 }
[email protected]1dbafaf72009-09-23 19:43:561786}
1787
1788WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321789 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561790 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261791 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561792 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171793 RenderThread* thread = RenderThread::current();
1794 // Will be NULL during unit tests.
1795 if (thread) {
1796 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291797 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171798 word, document_tag_);
1799 }
[email protected]1dbafaf72009-09-23 19:43:561800 }
[email protected]2a3a7762009-10-19 19:17:321801 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561802}
1803
[email protected]c49085c72009-10-02 16:28:561804void RenderView::showSpellingUI(bool show) {
1805 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1806}
1807
[email protected]8922e1f2009-10-03 05:01:261808bool RenderView::isShowingSpellingUI() {
1809 return spelling_panel_visible_;
1810}
1811
[email protected]1dbafaf72009-09-23 19:43:561812void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321813 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1814 word));
[email protected]1dbafaf72009-09-23 19:43:561815}
1816
[email protected]a1128322009-10-06 18:38:461817bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351818 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471819 WebFileChooserCompletion* chooser_completion) {
1820 ViewHostMsg_RunFileChooser_Params ipc_params;
1821 ipc_params.mode = params.multiSelect ?
1822 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1823 ViewHostMsg_RunFileChooser_Params::Open;
1824 ipc_params.title = params.title;
1825 ipc_params.default_file_name =
1826 webkit_glue::WebStringToFilePath(params.initialValue);
1827
1828 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461829}
1830
[email protected]48c9cf2d2009-09-16 16:47:521831void RenderView::runModalAlertDialog(
1832 WebFrame* frame, const WebString& message) {
1833 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1834 UTF16ToWideHack(message),
1835 std::wstring(),
1836 frame->url(),
1837 NULL);
1838}
1839
1840bool RenderView::runModalConfirmDialog(
1841 WebFrame* frame, const WebString& message) {
1842 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1843 UTF16ToWideHack(message),
1844 std::wstring(),
1845 frame->url(),
1846 NULL);
1847}
1848
1849bool RenderView::runModalPromptDialog(
1850 WebFrame* frame, const WebString& message, const WebString& default_value,
1851 WebString* actual_value) {
1852 std::wstring result;
1853 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1854 UTF16ToWideHack(message),
1855 UTF16ToWideHack(default_value),
1856 frame->url(),
1857 &result);
1858 if (ok)
1859 actual_value->assign(WideToUTF16Hack(result));
1860 return ok;
1861}
1862
1863bool RenderView::runModalBeforeUnloadDialog(
1864 WebFrame* frame, const WebString& message) {
1865 bool success = false;
1866 // This is an ignored return value, but is included so we can accept the same
1867 // response as RunJavaScriptMessage.
1868 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211869 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521870 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211871 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521872 return success;
1873}
1874
[email protected]79e37442009-10-09 18:17:441875void RenderView::showContextMenu(
1876 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291877 ContextMenuParams params = ContextMenuParams(data);
1878 if (!params.misspelled_word.empty() && RenderThread::current()) {
1879 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041880 bool spelled_right = RenderThread::current()->spellchecker()->
1881 SpellCheckWord(
1882 params.misspelled_word.c_str(), params.misspelled_word.size(),
1883 document_tag_,
1884 &misspelled_offset, &misspelled_length,
1885 &params.dictionary_suggestions);
1886 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291887 params.misspelled_word.clear();
1888 }
1889
1890 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441891}
1892
[email protected]48c9cf2d2009-09-16 16:47:521893void RenderView::setStatusText(const WebString& text) {
1894}
1895
[email protected]163f8242009-10-30 20:19:551896void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581897 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521898 if (latest_url == target_url_)
1899 return;
[email protected]163f8242009-10-30 20:19:551900
[email protected]48c9cf2d2009-09-16 16:47:521901 // Tell the browser to display a destination link.
1902 if (target_url_status_ == TARGET_INFLIGHT ||
1903 target_url_status_ == TARGET_PENDING) {
1904 // If we have a request in-flight, save the URL to be sent when we
1905 // receive an ACK to the in-flight request. We can happily overwrite
1906 // any existing pending sends.
1907 pending_target_url_ = latest_url;
1908 target_url_status_ = TARGET_PENDING;
1909 } else {
1910 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1911 target_url_ = latest_url;
1912 target_url_status_ = TARGET_INFLIGHT;
1913 }
1914}
1915
[email protected]882daa92009-11-05 16:31:311916void RenderView::StartNavStateSyncTimerIfNecessary() {
1917 int delay;
1918 if (send_content_state_immediately_)
1919 delay = 0;
1920 else if (is_hidden())
1921 delay = kDelaySecondsForContentStateSyncHidden;
1922 else
1923 delay = kDelaySecondsForContentStateSync;
1924
1925 if (nav_state_sync_timer_.IsRunning()) {
1926 // The timer is already running. If the delay of the timer maches the amount
1927 // we want to delay by, then return. Otherwise stop the timer so that it
1928 // gets started with the right delay.
1929 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1930 return;
1931 nav_state_sync_timer_.Stop();
1932 }
1933
1934 nav_state_sync_timer_.Start(
1935 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1936}
1937
[email protected]163f8242009-10-30 20:19:551938void RenderView::setMouseOverURL(const WebURL& url) {
1939 mouse_over_url_ = GURL(url);
1940 UpdateTargetURL(mouse_over_url_, focus_url_);
1941}
1942
1943void RenderView::setKeyboardFocusURL(const WebURL& url) {
1944 focus_url_ = GURL(url);
1945 UpdateTargetURL(focus_url_, mouse_over_url_);
1946}
1947
[email protected]48c9cf2d2009-09-16 16:47:521948void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1949 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1950 hint));
1951}
1952
[email protected]c27ae592010-03-18 15:24:411953void RenderView::startDragging(const WebDragData& data,
1954 WebDragOperationsMask mask,
1955 const WebImage& image,
1956 const WebPoint& imageOffset) {
1957#if WEBKIT_USING_SKIA
1958 SkBitmap bitmap(image.getSkBitmap());
1959#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331960 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411961#endif
1962
[email protected]48c9cf2d2009-09-16 16:47:521963 Send(new ViewHostMsg_StartDragging(routing_id_,
1964 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411965 mask,
1966 bitmap,
1967 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521968}
1969
[email protected]28b92df2009-09-25 17:35:451970bool RenderView::acceptsLoadDrops() {
1971 return renderer_preferences_.can_accept_load_drops;
1972}
1973
[email protected]48c9cf2d2009-09-16 16:47:521974void RenderView::focusNext() {
1975 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1976}
1977
1978void RenderView::focusPrevious() {
1979 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1980}
1981
1982void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521983 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1984}
1985
1986int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001987 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521988}
1989
1990int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001991 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521992}
1993
[email protected]c4e98902010-06-01 10:20:141994void RenderView::didUpdateInspectorSetting(const WebString& key,
1995 const WebString& value) {
1996 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1997 key.utf8(),
1998 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261999}
2000
[email protected]acca2a12009-10-16 03:53:392001void RenderView::queryAutofillSuggestions(const WebNode& node,
2002 const WebString& name,
2003 const WebString& value) {
2004 static int query_counter = 0;
2005 autofill_query_id_ = query_counter++;
2006 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:362007
2008 const WebFormControlElement& element =
[email protected]f40b49e2010-05-05 22:38:452009 node.toConst<WebFormControlElement>();
[email protected]e250e492010-04-06 21:35:362010
[email protected]dede9342010-04-12 16:51:112011 webkit_glue::FormField field;
2012 FormManager::WebFormControlElementToFormField(element, true, &field);
[email protected]e250e492010-04-06 21:35:362013
[email protected]72eb2da2010-04-14 00:31:082014 // WebFormControlElementToFormField does not scrape the DOM for the field
2015 // label, so find the label here.
2016 // TODO(jhawkins): Add form and field identities so we can use the cached form
2017 // data in FormManager.
2018 field.set_label(FormManager::LabelForElement(element));
2019
[email protected]dede9342010-04-12 16:51:112020 Send(new ViewHostMsg_QueryFormFieldAutofill(
2021 routing_id_, autofill_query_id_, field));
[email protected]acca2a12009-10-16 03:53:392022}
2023
2024void RenderView::removeAutofillSuggestions(const WebString& name,
2025 const WebString& value) {
2026 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
2027}
2028
[email protected]c83641732010-02-20 01:04:482029void RenderView::didAcceptAutoFillSuggestion(
2030 const WebKit::WebNode& node,
[email protected]8f6e6582010-04-09 02:03:072031 const WebKit::WebString& value,
[email protected]c83641732010-02-20 01:04:482032 const WebKit::WebString& label) {
2033 static int query_counter = 0;
2034 autofill_query_id_ = query_counter++;
2035
[email protected]45c6e532010-03-15 23:51:242036 webkit_glue::FormData form;
[email protected]f40b49e2010-05-05 22:38:452037 const WebInputElement element = node.toConst<WebInputElement>();
[email protected]b1438212010-04-03 00:30:592038 if (!form_manager_.FindFormWithFormControlElement(
[email protected]da592272010-04-14 20:08:492039 element, FormManager::REQUIRE_NONE, &form))
[email protected]c83641732010-02-20 01:04:482040 return;
2041
2042 Send(new ViewHostMsg_FillAutoFillFormData(
[email protected]8f6e6582010-04-09 02:03:072043 routing_id_, autofill_query_id_, form, value, label));
[email protected]c83641732010-02-20 01:04:482044}
2045
[email protected]79dbc662009-09-04 05:42:512046// WebKit::WebWidgetClient ----------------------------------------------------
2047
initial.commit09911bf2008-07-26 23:55:292048// We are supposed to get a single call to Show for a newly created RenderView
2049// that was created via RenderView::CreateWebView. So, we wait until this
2050// point to dispatch the ShowView message.
2051//
2052// This method provides us with the information about how to display the newly
2053// created RenderView (i.e., as a constrained popup or as a new tab).
2054//
[email protected]4873c7d2009-07-16 06:36:282055void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292056 DCHECK(!did_show_) << "received extraneous Show call";
2057 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2058
2059 if (did_show_)
2060 return;
2061 did_show_ = true;
2062
[email protected]28295ec2009-10-16 05:34:332063 // Force new windows to a popup if they were not opened with a user gesture.
2064 if (!opened_by_user_gesture_) {
2065 // We exempt background tabs for compat with older versions of Chrome.
2066 // TODO(darin): This seems bogus. These should have a user gesture, so
2067 // we probably don't need this check.
2068 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2069 policy = WebKit::WebNavigationPolicyNewPopup;
2070 }
2071
initial.commit09911bf2008-07-26 23:55:292072 // NOTE: initial_pos_ may still have its default values at this point, but
2073 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2074 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282075 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2076 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292077 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242078 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292079}
2080
[email protected]4873c7d2009-07-16 06:36:282081void RenderView::closeWidgetSoon() {
[email protected]e8345242010-05-06 03:00:402082 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282083 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312084}
2085
[email protected]4873c7d2009-07-16 06:36:282086void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292087 DCHECK(did_show_) << "should already have shown the view";
2088
[email protected]c1f50aa2010-02-18 03:46:572089 // We must keep WebKit's shared timer running in this case in order to allow
2090 // showModalDialog to function properly.
2091 //
2092 // TODO(darin): WebKit should really be smarter about suppressing events and
2093 // timers so that we do not need to manage the shared timer in such a heavy
2094 // handed manner.
2095 //
2096 if (RenderThread::current()) // Will be NULL during unit tests.
2097 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2098
[email protected]12636df2009-09-28 22:32:212099 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292100}
2101
[email protected]3d9689372009-09-10 04:29:172102// WebKit::WebFrameClient -----------------------------------------------------
2103
2104WebPlugin* RenderView::createPlugin(
2105 WebFrame* frame, const WebPluginParams& params) {
[email protected]4e0616e2010-05-28 14:55:532106 FilePath path;
2107 std::string actual_mime_type;
2108 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2109 params.url, frame->top()->url(), params.mimeType.utf8(), &path,
2110 &actual_mime_type));
2111 if (path.value().empty())
2112 return NULL;
2113
2114 if (actual_mime_type.empty())
2115 actual_mime_type = params.mimeType.utf8();
2116
[email protected]53af1d62010-05-14 03:40:262117 scoped_refptr<pepper::PluginModule> pepper_module =
[email protected]4e0616e2010-05-28 14:55:532118 PepperPluginRegistry::GetInstance()->GetModule(path);
[email protected]53af1d62010-05-14 03:40:262119 if (pepper_module) {
[email protected]4e0616e2010-05-28 14:55:532120 return new pepper::WebPluginImpl(pepper_module, params,
[email protected]b4f68dea2010-05-13 06:03:172121 pepper_delegate_.AsWeakPtr());
2122 }
[email protected]4e0616e2010-05-28 14:55:532123
2124 return new webkit_glue::WebPluginImpl(frame, params, path, actual_mime_type,
2125 AsWeakPtr());
[email protected]3d9689372009-09-10 04:29:172126}
2127
2128WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562129 WebApplicationCacheHostImpl* appcache_host =
2130 WebApplicationCacheHostImpl::FromFrame(frame);
2131 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2132 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2133 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172134}
2135
[email protected]9c00f002009-11-05 22:37:422136WebSharedWorker* RenderView::createSharedWorker(
2137 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372138 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422139
[email protected]30447b62009-11-13 01:13:372140 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512141 bool exists = false;
[email protected]30447b62009-11-13 01:13:372142 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512143 ViewHostMsg_CreateWorker_Params params;
2144 params.url = url;
2145 params.is_shared = true;
2146 params.name = name;
2147 params.document_id = document_id;
2148 params.render_view_route_id = routing_id_;
2149 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232150 params.parent_appcache_host_id = 0;
2151 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372152 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512153 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372154 if (url_mismatch) {
2155 return NULL;
2156 } else {
2157 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492158 document_id,
[email protected]6de0bcf2010-02-17 22:00:512159 exists,
[email protected]30447b62009-11-13 01:13:372160 route_id,
2161 routing_id_);
2162 }
[email protected]9c00f002009-11-05 22:37:422163}
2164
[email protected]3d9689372009-09-10 04:29:172165WebMediaPlayer* RenderView::createMediaPlayer(
2166 WebFrame* frame, WebMediaPlayerClient* client) {
2167 scoped_refptr<media::FilterFactoryCollection> factory =
2168 new media::FilterFactoryCollection();
2169 // Add in any custom filter factories first.
2170 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2171 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2172 // Add the chrome specific audio renderer.
2173 factory->AddFactory(
2174 AudioRendererImpl::CreateFactory(audio_message_filter()));
2175 }
2176
[email protected]80f584d92010-01-21 03:59:042177 WebApplicationCacheHostImpl* appcache_host =
2178 WebApplicationCacheHostImpl::FromFrame(frame);
2179
[email protected]3d9689372009-09-10 04:29:172180 // TODO(hclam): obtain the following parameters from |client|.
2181 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2182 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152183 GURL(), // referrer
2184 "null", // frame origin
2185 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172186 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042187 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172188 routing_id());
2189
[email protected]0436b9a2009-10-23 00:23:052190 // A simple data source that keeps all data in memory.
2191 media::FilterFactory* simple_data_source_factory =
2192 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2193 bridge_factory);
2194 // A sophisticated data source that does memory caching.
2195 media::FilterFactory* buffered_data_source_factory =
2196 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2197 bridge_factory);
2198 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2199 factory->AddFactory(simple_data_source_factory);
2200 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172201 } else {
[email protected]0436b9a2009-10-23 00:23:052202 factory->AddFactory(buffered_data_source_factory);
2203 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172204 }
[email protected]8400e032010-02-26 18:50:112205
2206 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2207 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2208 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2209 } else {
[email protected]b57509eb2010-03-30 01:26:282210 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2211 factory_factory =
2212 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112213 }
2214
2215 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172216}
2217
[email protected]035545f2010-04-09 13:10:212218WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2219 WebFrame* frame, WebApplicationCacheHostClient* client) {
2220 return new RendererWebApplicationCacheHostImpl(
2221 FromWebView(frame->view()), client,
2222 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2223}
2224
[email protected]b921cfd22010-02-25 16:57:512225WebCookieJar* RenderView::cookieJar() {
2226 return &cookie_jar_;
2227}
2228
[email protected]3d9689372009-09-10 04:29:172229void RenderView::willClose(WebFrame* frame) {
2230 if (!frame->parent()) {
2231 const GURL& url = frame->url();
2232 if (url.SchemeIs("http") || url.SchemeIs("https"))
2233 DumpLoadHistograms();
2234 }
[email protected]fa7b6b542009-11-03 05:02:302235
2236 WebDataSource* ds = frame->dataSource();
2237 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2238 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162239
2240 form_manager_.ResetFrame(frame);
[email protected]3d9689372009-09-10 04:29:172241}
2242
[email protected]684e4a42010-01-30 06:44:112243bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002244 if (!enabled_per_settings)
2245 return false;
[email protected]c21f1d52010-03-04 03:19:432246 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112247}
2248
2249bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402250 if (enabled_per_settings &&
2251 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2252 return true;
2253
2254 if (IsWhitelistedForContentSettings(frame))
2255 return true;
2256
2257 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2258 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112259}
2260
[email protected]3d9689372009-09-10 04:29:172261void RenderView::loadURLExternally(
2262 WebFrame* frame, const WebURLRequest& request,
2263 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592264 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2265 if (policy == WebKit::WebNavigationPolicyDownload) {
2266 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2267 } else {
2268 OpenURL(request.url(), referrer, policy);
2269 }
[email protected]3d9689372009-09-10 04:29:172270}
2271
2272WebNavigationPolicy RenderView::decidePolicyForNavigation(
2273 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222274 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172275 // Webkit is asking whether to navigate to a new URL.
2276 // This is fine normally, except if we're showing UI from one security
2277 // context and they're trying to navigate to a different context.
2278 const GURL& url = request.url();
2279
2280 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302281 // navigations.
[email protected]8079b362010-05-07 18:37:452282 if (renderer_preferences_.browser_handles_top_level_requests &&
2283 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192284 last_top_level_navigation_page_id_ = page_id_;
2285 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2286 OpenURL(url, referrer, default_policy);
2287 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172288 }
2289
2290 // A content initiated navigation may have originated from a link-click,
2291 // script, drag-n-drop operation, etc.
2292 bool is_content_initiated =
2293 NavigationState::FromDataSource(frame->provisionalDataSource())->
2294 is_content_initiated();
2295
2296 // We only care about navigations that are within the current tab (as opposed
2297 // to, for example, opening a new window).
2298 // But we sometimes navigate to about:blank to clear a tab, and we want to
2299 // still allow that.
2300 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2301 is_content_initiated && frame->parent() == NULL &&
2302 !url.SchemeIs(chrome::kAboutScheme)) {
2303 // When we received such unsolicited navigations, we sometimes want to
2304 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302305 if (CrossesExtensionExtents(frame, url) ||
2306 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172307 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422308 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172309 OpenURL(url, GURL(), default_policy);
2310 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2311 }
[email protected]8079b362010-05-07 18:37:452312
2313 // We forward navigations from extensions to the browser if they are
2314 // top-level events, even if the browser hasn't expressed interest.
2315 //
2316 // Note that we've already forwarded cross-extension extents navigations
2317 // above.
2318 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
2319 IsNonLocalTopLevelNavigation(url, frame, type)) {
2320 OpenURL(url, GURL(), default_policy);
2321 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2322 }
[email protected]3d9689372009-09-10 04:29:172323 }
2324
2325 // Detect when a page is "forking" a new tab that can be safely rendered in
2326 // its own process. This is done by sites like Gmail that try to open links
2327 // in new windows without script connections back to the original page. We
2328 // treat such cases as browser navigations (in which we will create a new
2329 // renderer for a cross-site navigation), rather than WebKit navigations.
2330 //
2331 // We use the following heuristic to decide whether to fork a new page in its
2332 // own process:
2333 // The parent page must open a new tab to about:blank, set the new tab's
2334 // window.opener to null, and then redirect the tab to a cross-site URL using
2335 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462336 //
2337 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2338 // (see below).
[email protected]3d9689372009-09-10 04:29:172339 bool is_fork =
2340 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252341 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172342 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522343 historyBackListCount() < 1 &&
2344 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172345 // The parent page must have set the child's window.opener to null before
2346 // redirecting to the desired URL.
2347 frame->opener() == NULL &&
2348 // Must be a top-level frame.
2349 frame->parent() == NULL &&
2350 // Must not have issued the request from this page.
2351 is_content_initiated &&
2352 // Must be targeted at the current tab.
2353 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2354 // Must be a JavaScript navigation, which appears as "other".
2355 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462356
2357 // Recognize if this navigation is from a link with rel=noreferrer and
2358 // target=_blank attributes, in which case the opener will be suppressed. If
2359 // so, it is safe to load cross-site pages in a separate process, so we
2360 // should let the browser handle it.
2361 bool is_noreferrer_and_blank_target =
2362 // Frame should be top level and not yet navigated.
2363 frame->parent() == NULL &&
2364 frame->url().isEmpty() &&
2365 historyBackListCount() < 1 &&
2366 historyForwardListCount() < 1 &&
2367 // Links with rel=noreferrer will have no Referer field, and their
2368 // resulting frame will have its window.opener suppressed.
2369 // TODO(creis): should add a request.httpReferrer() method to help avoid
2370 // typos on the unusual spelling of Referer.
2371 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2372 opener_suppressed_ &&
2373 frame->opener() == NULL &&
2374 // Links with target=_blank will have no name.
2375 frame->name().isNull() &&
2376 // Another frame (with a non-empty creator) should have initiated the
2377 // request, targeted at this frame.
2378 !creator_url_.is_empty() &&
2379 is_content_initiated &&
2380 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2381 type == WebKit::WebNavigationTypeOther;
2382
2383 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172384 // Open the URL via the browser, not via WebKit.
2385 OpenURL(url, GURL(), default_policy);
2386 return WebKit::WebNavigationPolicyIgnore;
2387 }
2388
2389 return default_policy;
2390}
2391
[email protected]6069da8c2009-10-20 20:33:492392bool RenderView::canHandleRequest(
2393 WebFrame* frame, const WebURLRequest& request) {
2394 // We allow WebKit to think that everything can be handled even though
2395 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342396 return true;
2397}
2398
[email protected]6069da8c2009-10-20 20:33:492399WebURLError RenderView::cannotHandleRequestError(
2400 WebFrame* frame, const WebURLRequest& request) {
2401 NOTREACHED(); // Since we said we can handle all requests.
2402 return WebURLError();
2403}
2404
2405WebURLError RenderView::cancelledError(
2406 WebFrame* frame, const WebURLRequest& request) {
2407 WebURLError error;
2408 error.domain = WebString::fromUTF8(net::kErrorDomain);
2409 error.reason = net::ERR_ABORTED;
2410 error.unreachableURL = request.url();
2411 return error;
[email protected]7b7a7dc2009-10-19 02:23:342412}
2413
2414void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492415 WebFrame*, const WebURLError&) {
2416 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342417}
2418
[email protected]90eeddb2010-05-06 21:06:432419void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2420 const WebKit::WebFormElement& form) {
2421 // Some login forms have onSubmit handlers that put a hash of the password
2422 // into a hidden field and then clear the password. (Issue 28910.)
2423 // This method gets called before any of those handlers run, so save away
2424 // a copy of the password in case it gets lost.
2425 NavigationState* navigation_state =
2426 NavigationState::FromDataSource(frame->dataSource());
2427 navigation_state->set_password_form_data(
2428 PasswordFormDomManager::CreatePasswordForm(form));
2429}
2430
[email protected]979c28b2009-11-07 01:30:482431void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172432 NavigationState* navigation_state =
2433 NavigationState::FromDataSource(frame->provisionalDataSource());
2434
2435 if (navigation_state->transition_type() == PageTransition::LINK)
2436 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2437
2438 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352439 WebSearchableFormData web_searchable_form_data(form);
2440 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2441 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212442 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432443 PasswordForm* password_form_data =
2444 PasswordFormDomManager::CreatePasswordForm(form);
2445 navigation_state->set_password_form_data(password_form_data);
2446
2447 // If the password has been cleared, recover it from the form contents already
2448 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2449 // opposed to the provisionalDataSource's, which is what we're storing into
2450 // now.)
2451 if (password_form_data && password_form_data->password_value.empty()) {
2452 NavigationState* old_navigation_state =
2453 NavigationState::FromDataSource(frame->dataSource());
2454 if (old_navigation_state) {
2455 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2456 if (old_form_data && old_form_data->action == password_form_data->action)
2457 password_form_data->password_value = old_form_data->password_value;
2458 }
2459 }
[email protected]3d9689372009-09-10 04:29:172460
[email protected]b1438212010-04-03 00:30:592461 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042462 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092463 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592464 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172465}
2466
2467void RenderView::willPerformClientRedirect(
2468 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2469 double fire_time) {
2470 // Ignore
2471}
2472
2473void RenderView::didCancelClientRedirect(WebFrame* frame) {
2474 // Ignore
2475}
2476
2477void RenderView::didCompleteClientRedirect(
2478 WebFrame* frame, const WebURL& from) {
2479 if (!frame->parent())
2480 completed_client_redirect_src_ = from;
2481}
2482
2483void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2484 // The rest of RenderView assumes that a WebDataSource will always have a
2485 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482486 bool content_initiated = !pending_navigation_state_.get();
2487 NavigationState* state = content_initiated ?
2488 NavigationState::CreateContentInitiated() :
2489 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182490 if (content_initiated) {
2491 switch (ds->request().cachePolicy()) {
2492 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2493 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2494 break;
2495 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2496 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2497 break;
2498 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2499 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2500 break;
2501 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2502 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2503 break;
2504 }
2505 }
[email protected]fa7b6b542009-11-03 05:02:302506
2507 state->set_user_script_idle_scheduler(
2508 new UserScriptIdleScheduler(this, frame));
2509 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172510}
2511
2512void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2513 WebDataSource* ds = frame->provisionalDataSource();
2514 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2515
2516 navigation_state->set_start_load_time(Time::Now());
2517
2518 // Update the request time if WebKit has better knowledge of it.
2519 if (navigation_state->request_time().is_null()) {
2520 double event_time = ds->triggeringEventTime();
2521 if (event_time != 0.0)
2522 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2523 }
2524
2525 bool is_top_most = !frame->parent();
2526 if (is_top_most) {
2527 navigation_gesture_ = frame->isProcessingUserGesture() ?
2528 NavigationGestureUnknown : NavigationGestureAuto;
2529
2530 // Make sure redirect tracking state is clear for the new load.
2531 completed_client_redirect_src_ = GURL();
2532 } else if (frame->parent()->isLoading()) {
2533 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002534 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172535 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2536 }
2537
2538 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2539 routing_id_, is_top_most, ds->request().url()));
2540}
2541
2542void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2543 if (frame->parent())
2544 return;
2545 // Received a redirect on the main frame.
2546 WebDataSource* data_source = frame->provisionalDataSource();
2547 if (!data_source) {
2548 // Should only be invoked when we have a data source.
2549 NOTREACHED();
2550 return;
2551 }
2552 std::vector<GURL> redirects;
2553 GetRedirectChain(data_source, &redirects);
2554 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512555 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2556 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172557 }
2558}
2559
[email protected]40bd6582009-12-04 23:49:512560void RenderView::didFailProvisionalLoad(WebFrame* frame,
2561 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172562 // Notify the browser that we failed a provisional load with an error.
2563 //
2564 // Note: It is important this notification occur before DidStopLoading so the
2565 // SSL manager can react to the provisional load failure before being
2566 // notified the load stopped.
2567 //
2568 WebDataSource* ds = frame->provisionalDataSource();
2569 DCHECK(ds);
2570
2571 const WebURLRequest& failed_request = ds->request();
2572
2573 bool show_repost_interstitial =
2574 (error.reason == net::ERR_CACHE_MISS &&
2575 EqualsASCII(failed_request.httpMethod(), "POST"));
2576 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2577 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2578 show_repost_interstitial));
2579
2580 // Don't display an error page if this is simply a cancelled load. Aside
2581 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2582 if (error.reason == net::ERR_ABORTED)
2583 return;
2584
2585 // Make sure we never show errors in view source mode.
2586 frame->enableViewSourceMode(false);
2587
2588 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2589
2590 // If this is a failed back/forward/reload navigation, then we need to do a
2591 // 'replace' load. This is necessary to avoid messing up session history.
2592 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2593 // as session history is concerned.
2594 //
2595 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2596 // the page id.
2597 //
2598 bool replace =
2599 navigation_state->pending_page_id() != -1 ||
2600 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2601
2602 // If we failed on a browser initiated request, then make sure that our error
2603 // page load is regarded as the same browser initiated request.
2604 if (!navigation_state->is_content_initiated()) {
2605 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2606 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002607 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172608 navigation_state->transition_type(),
2609 navigation_state->request_time()));
2610 }
2611
2612 // Provide the user with a more helpful error page?
2613 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2614 return;
2615
2616 // Fallback to a local error page.
2617 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2618 replace);
2619}
2620
2621void RenderView::didReceiveDocumentData(
2622 WebFrame* frame, const char* data, size_t data_len,
2623 bool& prevent_default) {
2624 NavigationState* navigation_state =
2625 NavigationState::FromDataSource(frame->dataSource());
2626 if (!navigation_state->postpone_loading_data())
2627 return;
2628
2629 // We're going to call commitDocumentData ourselves...
2630 prevent_default = true;
2631
2632 // Continue buffering the response data for the original 404 page. If it
2633 // grows too large, then we'll just let it through.
2634 navigation_state->append_postponed_data(data, data_len);
2635 if (navigation_state->postponed_data().size() >= 512) {
2636 navigation_state->set_postpone_loading_data(false);
2637 frame->commitDocumentData(navigation_state->postponed_data().data(),
2638 navigation_state->postponed_data().size());
2639 navigation_state->clear_postponed_data();
2640 }
2641}
2642
[email protected]40bd6582009-12-04 23:49:512643void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2644 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172645 NavigationState* navigation_state =
2646 NavigationState::FromDataSource(frame->dataSource());
2647
2648 navigation_state->set_commit_load_time(Time::Now());
2649 if (is_new_navigation) {
2650 // When we perform a new navigation, we need to update the previous session
2651 // history entry with state for the page we are leaving.
2652 UpdateSessionHistory(frame);
2653
2654 // We bump our Page ID to correspond with the new session history entry.
2655 page_id_ = next_page_id_++;
2656
[email protected]d64b07b2010-04-20 22:14:062657 // Any pending translation is now obsolete.
2658 translate_helper_.CancelPendingTranslation();
2659
[email protected]3cc72b12010-03-18 23:03:002660 // Advance our offset in session history, applying the length limit. There
2661 // is now no forward history.
2662 history_list_offset_++;
2663 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2664 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2665 history_list_length_ = history_list_offset_ + 1;
2666
[email protected]f9f4841b2010-03-20 05:41:422667 MessageLoop::current()->PostDelayedTask(
2668 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172669 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2670 page_id_, true),
2671 kDelayForForcedCaptureMs);
2672 } else {
2673 // Inspect the navigation_state on this frame to see if the navigation
2674 // corresponds to a session history navigation... Note: |frame| may or
2675 // may not be the toplevel frame, but for the case of capturing session
2676 // history, the first committed frame suffices. We keep track of whether
2677 // we've seen this commit before so that only capture session history once
2678 // per navigation.
2679 //
2680 // Note that we need to check if the page ID changed. In the case of a
2681 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2682 // previous URL and the current page ID, which would be wrong.
2683 if (navigation_state->pending_page_id() != -1 &&
2684 navigation_state->pending_page_id() != page_id_ &&
2685 !navigation_state->request_committed()) {
2686 // This is a successful session history navigation!
2687 UpdateSessionHistory(frame);
2688 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002689
2690 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172691 }
2692 }
2693
2694 // Remember that we've already processed this request, so we don't update
2695 // the session history again. We do this regardless of whether this is
2696 // a session history navigation, because if we attempted a session history
2697 // navigation without valid HistoryItem state, WebCore will think it is a
2698 // new navigation.
2699 navigation_state->set_request_committed(true);
2700
2701 UpdateURL(frame);
2702
2703 // If this committed load was initiated by a client redirect, we're
2704 // at the last stop now, so clear it.
2705 completed_client_redirect_src_ = GURL();
2706
2707 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272708 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172709}
2710
2711void RenderView::didClearWindowObject(WebFrame* frame) {
2712 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2713 BindDOMAutomationController(frame);
2714 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2715 dom_ui_bindings_.set_message_sender(this);
2716 dom_ui_bindings_.set_routing_id(routing_id_);
2717 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2718 }
2719 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2720 external_host_bindings_.set_message_sender(this);
2721 external_host_bindings_.set_routing_id(routing_id_);
2722 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2723 }
2724}
2725
2726void RenderView::didCreateDocumentElement(WebFrame* frame) {
2727 if (RenderThread::current()) { // Will be NULL during unit tests.
2728 RenderThread::current()->user_script_slave()->InjectScripts(
2729 frame, UserScript::DOCUMENT_START);
2730 }
[email protected]078b34612009-09-19 19:31:512731 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2732 view_type_ == ViewType::EXTENSION_MOLE) {
2733 InjectToolstripCSS();
2734 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2735 }
[email protected]3d9689372009-09-10 04:29:172736
2737 // Notify the browser about non-blank documents loading in the top frame.
2738 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252739 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272740 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172741 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2742 }
2743}
2744
2745void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2746 UpdateTitle(frame, title);
2747
2748 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272749 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172750}
2751
[email protected]5019ef12010-04-27 17:26:582752void RenderView::didChangeIcons(WebFrame* frame) {
2753 if (!frame->parent()) {
2754 Send(new ViewHostMsg_UpdateFavIconURL(
2755 routing_id_,
2756 page_id_,
2757 frame->favIconURL()));
2758 }
2759}
2760
[email protected]3d9689372009-09-10 04:29:172761void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2762 WebDataSource* ds = frame->dataSource();
2763 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2764 DCHECK(navigation_state);
2765 navigation_state->set_finish_document_load_time(Time::Now());
2766
2767 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2768
[email protected]e9e07992010-02-17 21:04:362769 // The document has now been fully loaded. Scan for forms to be sent up to
2770 // the browser.
2771 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482772 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362773 SendForms(frame);
[email protected]4d44a1c2010-04-28 19:20:412774 SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172775
2776 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272777 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172778
2779 if (RenderThread::current()) { // Will be NULL during unit tests.
2780 RenderThread::current()->user_script_slave()->InjectScripts(
2781 frame, UserScript::DOCUMENT_END);
2782 }
[email protected]fa7b6b542009-11-03 05:02:302783
2784 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2785}
2786
2787void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2788 if (RenderThread::current()) { // Will be NULL during unit tests.
2789 RenderThread::current()->user_script_slave()->InjectScripts(
2790 frame, UserScript::DOCUMENT_IDLE);
2791 }
2792
2793 WebFrame* main_frame = webview()->mainFrame();
2794 if (frame == main_frame) {
2795 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202796 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302797 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202798 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302799 pending_code_execution_queue_.pop();
2800 }
2801 }
[email protected]3d9689372009-09-10 04:29:172802}
2803
2804void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:262805 if (webview()->mainFrame() == frame)
2806 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172807}
2808
2809void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2810 // Ignore
2811}
2812
2813void RenderView::didFinishLoad(WebFrame* frame) {
2814 WebDataSource* ds = frame->dataSource();
2815 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2816 DCHECK(navigation_state);
2817 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302818 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412819
2820 // Let the password manager know which password forms are actually visible.
2821 SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172822}
2823
[email protected]ccbe04e2010-03-17 17:58:432824void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172825 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062826
2827 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2828 // since a new one gets created by didCreateDataSource.
2829 NavigationState* state =
2830 NavigationState::FromDataSource(frame->dataSource());
2831 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2832
[email protected]3d9689372009-09-10 04:29:172833 // If this was a reference fragment navigation that we initiated, then we
2834 // could end up having a non-null pending navigation state. We just need to
2835 // update the ExtraData on the datasource so that others who read the
2836 // ExtraData will get the new NavigationState. Similarly, if we did not
2837 // initiate this navigation, then we need to take care to reset any pre-
2838 // existing navigation state to a content-initiated navigation state.
2839 // DidCreateDataSource conveniently takes care of this for us.
2840 didCreateDataSource(frame, frame->dataSource());
2841
[email protected]f6c2459d2010-02-24 22:34:062842 if (idle_scheduler_ran) {
2843 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2844 NavigationState* new_state =
2845 NavigationState::FromDataSource(frame->dataSource());
2846 new_state->user_script_idle_scheduler()->set_has_run(true);
2847 }
2848
[email protected]3d9689372009-09-10 04:29:172849 didCommitProvisionalLoad(frame, is_new_navigation);
2850
[email protected]26aa0482009-09-30 16:55:272851 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172852}
2853
[email protected]476b6f82009-09-10 21:00:592854void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312855 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592856}
2857
[email protected]3d9689372009-09-10 04:29:172858void RenderView::assignIdentifierToRequest(
2859 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2860 // Ignore
2861}
2862
2863void RenderView::willSendRequest(
2864 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2865 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302866 WebFrame* top_frame = frame->top();
2867 if (!top_frame)
2868 top_frame = frame;
2869 WebDataSource* data_source = top_frame->provisionalDataSource();
2870 if (!data_source)
2871 data_source = top_frame->dataSource();
2872 if (data_source) {
2873 NavigationState* state = NavigationState::FromDataSource(data_source);
2874 if (state && state->is_cache_policy_override_set())
2875 request.setCachePolicy(state->cache_policy_override());
2876 }
[email protected]3d9689372009-09-10 04:29:172877 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502878 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132879 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492880
[email protected]85cc78c2010-05-04 18:30:092881 // Temporary metrics, see site_isolation_metrics.h
2882 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172883}
2884
2885void RenderView::didReceiveResponse(
2886 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492887
[email protected]85cc78c2010-05-04 18:30:092888 // Temporary metrics, see site_isolation_metrics.h
2889 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2890 identifier,
2891 response);
[email protected]fa0a3432010-03-30 16:53:492892
[email protected]3d9689372009-09-10 04:29:172893 // Only do this for responses that correspond to a provisional data source
2894 // of the top-most frame. If we have a provisional data source, then we
2895 // can't have any sub-resources yet, so we know that this response must
2896 // correspond to a frame load.
2897 if (!frame->provisionalDataSource() || frame->parent())
2898 return;
2899
2900 // If we are in view source mode, then just let the user see the source of
2901 // the server's 404 error page.
2902 if (frame->isViewSourceModeEnabled())
2903 return;
2904
[email protected]65041fa2010-05-21 06:56:532905 NavigationState* navigation_state =
2906 NavigationState::FromDataSource(frame->provisionalDataSource());
2907 CHECK(navigation_state);
2908
[email protected]f48013be2010-01-14 22:07:452909 // Record that this was a page loaded over SPDY.
2910 if (response.wasFetchedViaSPDY()) {
[email protected]f48013be2010-01-14 22:07:452911 navigation_state->set_was_fetched_via_spdy(true);
2912 }
2913
[email protected]65041fa2010-05-21 06:56:532914 // Record that npn protocol was negotiated when fetching this page.
2915 if (response.wasNpnNegotiated()) {
2916 navigation_state->set_was_npn_negotiated(true);
2917 }
2918
[email protected]f48013be2010-01-14 22:07:452919 // Consider loading an alternate error page for 404 responses.
2920 if (response.httpStatusCode() != 404)
2921 return;
2922
[email protected]3d9689372009-09-10 04:29:172923 // Can we even load an alternate error page for this URL?
2924 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2925 return;
2926
[email protected]3d9689372009-09-10 04:29:172927 navigation_state->set_postpone_loading_data(true);
2928 navigation_state->clear_postponed_data();
2929}
2930
2931void RenderView::didFinishResourceLoad(
2932 WebFrame* frame, unsigned identifier) {
2933 NavigationState* navigation_state =
2934 NavigationState::FromDataSource(frame->dataSource());
2935 if (!navigation_state->postpone_loading_data())
2936 return;
2937
2938 // The server returned a 404 and the content was < 512 bytes (which we
2939 // suppressed). Go ahead and fetch the alternate page content.
2940
2941 const GURL& frame_url = frame->url();
2942
2943 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2944 DCHECK(error_page_url.is_valid());
2945
2946 WebURLError original_error;
2947 original_error.unreachableURL = frame_url;
2948
2949 navigation_state->set_alt_error_page_fetcher(
2950 new AltErrorPageResourceFetcher(
2951 error_page_url, frame, original_error,
2952 NewCallback(this, &RenderView::AltErrorPageFinished)));
2953}
2954
2955void RenderView::didFailResourceLoad(
2956 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2957 // Ignore
2958}
2959
2960void RenderView::didLoadResourceFromMemoryCache(
2961 WebFrame* frame, const WebURLRequest& request,
2962 const WebURLResponse& response) {
2963 // Let the browser know we loaded a resource from the memory cache. This
2964 // message is needed to display the correct SSL indicators.
2965 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2966 routing_id_,
2967 request.url(),
[email protected]91733b62009-09-18 06:21:092968 frame->securityOrigin().toString().utf8(),
2969 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172970 response.securityInfo()));
2971}
2972
[email protected]6069da8c2009-10-20 20:33:492973void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292974 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2975}
2976
2977void RenderView::didRunInsecureContent(
2978 WebFrame* frame, const WebSecurityOrigin& origin) {
2979 Send(new ViewHostMsg_DidRunInsecureContent(
2980 routing_id_,
2981 origin.toString().utf8()));
2982}
2983
[email protected]7ea093ba2009-11-03 05:54:592984bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402985 if (enabled_per_settings &&
2986 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
2987 return true;
[email protected]7ea093ba2009-11-03 05:54:592988
[email protected]12bc8472010-04-15 07:29:402989 if (IsWhitelistedForContentSettings(frame))
2990 return true;
[email protected]7ea093ba2009-11-03 05:54:592991
2992 return false; // Other protocols fall through here.
2993}
2994
[email protected]0a1a45432010-03-31 08:09:452995bool RenderView::allowDatabase(
2996 WebFrame* frame, const WebString& name, const WebString& display_name,
2997 unsigned long estimated_size) {
2998 WebSecurityOrigin origin = frame->securityOrigin();
2999 if (origin.isEmpty())
3000 return false; // Uninitialized document?
3001
3002 bool result;
3003 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3004 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3005 return false;
3006 if (!result)
3007 DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES);
3008 return result;
3009}
[email protected]8934a3b2010-02-25 00:34:003010void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
3011 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
3012}
3013
[email protected]c21f1d52010-03-04 03:19:433014void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
3015 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
3016}
3017
[email protected]3d9689372009-09-10 04:29:173018void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3019 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3020}
3021
[email protected]0c882b282009-10-07 17:01:283022void RenderView::didCreateScriptContext(WebFrame* frame) {
3023 EventBindings::HandleContextCreated(frame, false);
3024}
3025
3026void RenderView::didDestroyScriptContext(WebFrame* frame) {
3027 EventBindings::HandleContextDestroyed(frame);
3028}
3029
3030void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3031 EventBindings::HandleContextCreated(frame, true);
3032}
3033
[email protected]fc86daa2010-03-30 23:52:533034void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3035 WebFrame* target,
3036 bool cross_origin,
3037 const WebString& property_name,
3038 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103039 // TODO(johnnyg): track the individual properties and repeat event_ids.
3040 if (cross_origin)
3041 cross_origin_access_count_++;
3042 else
3043 same_origin_access_count_++;
3044}
3045
[email protected]3d9689372009-09-10 04:29:173046void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143047 CheckPreferredSize();
3048}
3049
3050void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173051 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253052 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173053 // message.
[email protected]705243f2010-05-05 19:58:073054 if (!send_preferred_size_changes_ || !webview())
3055 return;
[email protected]dfca5acf2010-03-22 03:28:433056
[email protected]705243f2010-05-05 19:58:073057 // WebCore likes to tell us things have changed even when they haven't, so
3058 // cache the width and height and only send the IPC message when we're sure
3059 // they're different.
3060 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3061 webview()->mainFrame()->documentElementScrollHeight());
3062 if (size == preferred_size_)
3063 return;
[email protected]c27324b2009-11-19 22:44:293064
[email protected]705243f2010-05-05 19:58:073065 preferred_size_ = size;
3066 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3067 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173068}
3069
[email protected]143dcd592009-11-06 21:33:493070void RenderView::didChangeScrollOffset(WebFrame* frame) {
3071 StartNavStateSyncTimerIfNecessary();
3072}
3073
[email protected]8922e1f2009-10-03 05:01:263074void RenderView::reportFindInPageMatchCount(int request_id, int count,
3075 bool final_update) {
3076 // If we have a message that has been queued up, then we should just replace
3077 // it. The ACK from the browser will make sure it gets sent when the browser
3078 // wants it.
3079 if (queued_find_reply_message_.get()) {
3080 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3081 routing_id_,
3082 request_id,
3083 count,
3084 gfx::Rect(),
3085 -1, // Don't update active match ordinal.
3086 final_update);
3087 queued_find_reply_message_.reset(msg);
3088 } else {
3089 // Send the search result over to the browser process.
3090 Send(new ViewHostMsg_Find_Reply(
3091 routing_id_,
3092 request_id,
3093 count,
3094 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073095 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263096 final_update));
3097 }
3098}
3099
3100void RenderView::reportFindInPageSelection(int request_id,
3101 int active_match_ordinal,
3102 const WebRect& selection_rect) {
3103 // Send the search result over to the browser process.
3104 Send(new ViewHostMsg_Find_Reply(routing_id_,
3105 request_id,
3106 -1,
3107 selection_rect,
3108 active_match_ordinal,
3109 false));
3110}
3111
[email protected]24a7f3c2010-03-25 08:26:493112void RenderView::ReportNoFindInPageResults(int request_id) {
3113 Send(new ViewHostMsg_Find_Reply(routing_id_,
3114 request_id,
3115 0,
3116 gfx::Rect(),
3117 0,
3118 true));
3119}
3120
[email protected]79dbc662009-09-04 05:42:513121// webkit_glue::WebPluginPageDelegate -----------------------------------------
3122
[email protected]f103ab72009-09-02 17:10:593123webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533124 const FilePath& file_path,
3125 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593126 if (!PluginChannelHost::IsListening())
3127 return NULL;
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-";
[email protected]4e0616e2010-05-28 14:55:533133 if (StartsWithASCII(mime_type, 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]4e0616e2010-05-28 14:55:533142 } else {
3143 FilePath internal_pdf_path;
3144 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3145 if (file_path == internal_pdf_path) {
3146 in_process_plugin = true;
3147 use_pepper_host = true;
3148 }
[email protected]26e8d5e2009-10-13 02:47:163149 }
[email protected]4e0616e2010-05-28 14:55:533150
[email protected]d2139662009-12-10 03:21:143151 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463152 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3153 if (mime_type == "application/x-nacl-srpc") {
3154 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143155 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463156 }
3157 }
[email protected]4e0616e2010-05-28 14:55:533158
[email protected]d032f492009-09-29 00:33:463159 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143160 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283161 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533162 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]00c39612010-03-06 02:53:283163 current_pepper_plugins_.insert(pepper_plugin);
3164 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143165 } else {
[email protected]6876dff2010-01-15 19:38:093166#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143167 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533168 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093169#else
[email protected]596b2c42010-01-14 20:40:433170 NOTIMPLEMENTED();
3171 return NULL;
[email protected]7b6616f2010-01-14 18:07:553172#endif
[email protected]6876dff2010-01-15 19:38:093173 }
[email protected]f103ab72009-09-02 17:10:593174 }
3175
[email protected]4e0616e2010-05-28 14:55:533176 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593177}
3178
3179void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033180#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593181 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3182 routing_id(), window));
3183#endif
3184}
3185
3186void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033187#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593188 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3189 routing_id(), window));
3190#endif
3191 CleanupWindowInPluginMoves(window);
3192}
3193
3194void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3195 SchedulePluginMove(move);
3196}
3197
3198void RenderView::DidStartLoadingForPlugin() {
3199 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523200 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593201}
3202
3203void RenderView::DidStopLoadingForPlugin() {
3204 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523205 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593206}
3207
3208void RenderView::ShowModalHTMLDialogForPlugin(
3209 const GURL& url,
3210 const gfx::Size& size,
3211 const std::string& json_arguments,
3212 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213213 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593214 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213215 json_retval));
[email protected]f103ab72009-09-02 17:10:593216}
3217
[email protected]b921cfd22010-02-25 16:57:513218WebCookieJar* RenderView::GetCookieJar() {
3219 return &cookie_jar_;
3220}
3221
initial.commit09911bf2008-07-26 23:55:293222void RenderView::SyncNavigationState() {
3223 if (!webview())
3224 return;
3225
[email protected]26aa0482009-09-30 16:55:273226 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173227 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293228 return;
[email protected]ca948a22009-06-25 19:36:173229
3230 Send(new ViewHostMsg_UpdateState(
3231 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293232}
3233
[email protected]b0950a72009-09-29 23:16:173234bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3235 // Make sure webview was not shut down.
3236 if (!webview())
3237 return false;
3238 // Create an image resource fetcher and assign it with a call back object.
3239 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273240 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173241 NewCallback(this, &RenderView::DidDownloadImage)));
3242 return true;
3243}
3244
3245void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293246 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173247 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473248 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3249 fetcher->id(),
3250 fetcher->image_url(),
3251 image.isNull(),
3252 image));
[email protected]b0950a72009-09-29 23:16:173253 // Dispose of the image fetcher.
3254 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3255 image_fetchers_.erase(fetcher);
3256 // We're in the callback from the ImageResourceFetcher, best to delay
3257 // deletion.
3258 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293259}
3260
[email protected]bf5c2ff392009-07-08 16:24:333261void RenderView::OnDownloadFavIcon(int id,
3262 const GURL& image_url,
3263 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343264 bool data_image_failed = false;
3265 if (image_url.SchemeIs("data")) {
3266 SkBitmap data_image = ImageFromDataUrl(image_url);
3267 data_image_failed = data_image.empty();
3268 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333269 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3270 data_image));
[email protected]f11ca0732009-04-11 00:09:343271 }
3272 }
3273
[email protected]bf5c2ff392009-07-08 16:24:333274 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173275 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333276 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3277 SkBitmap()));
3278 }
initial.commit09911bf2008-07-26 23:55:293279}
3280
[email protected]f11ca0732009-04-11 00:09:343281SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3282 std::string mime_type, char_set, data;
3283 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3284 // Decode the favicon using WebKit's image decoder.
3285 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3286 const unsigned char* src_data =
3287 reinterpret_cast<const unsigned char*>(&data[0]);
3288
3289 return decoder.Decode(src_data, data.size());
3290 }
3291 return SkBitmap();
3292}
3293
initial.commit09911bf2008-07-26 23:55:293294void RenderView::OnGetApplicationInfo(int page_id) {
3295 webkit_glue::WebApplicationInfo app_info;
3296 if (page_id == page_id_)
3297 webkit_glue::GetApplicationInfo(webview(), &app_info);
3298
3299 // Prune out any data URLs in the set of icons. The browser process expects
3300 // any icon with a data URL to have originated from a favicon. We don't want
3301 // to decode arbitrary data URLs in the browser process. See
3302 // http://b/issue?id=1162972
3303 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593304 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293305 app_info.icons.erase(app_info.icons.begin() + i);
3306 --i;
3307 }
3308 }
3309
3310 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3311}
3312
[email protected]7ccddb8c2009-08-04 17:36:553313GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293314 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553315 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293316 // If the URL that failed was secure, then the embedding web page was not
3317 // expecting a network attacker to be able to manipulate its contents. As
3318 // we fetch alternate error pages over HTTP, we would be allowing a network
3319 // attacker to manipulate the contents of the response if we tried to use
3320 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153321 return GURL();
initial.commit09911bf2008-07-26 23:55:293322 }
3323
3324 // Grab the base URL from the browser process.
3325 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153326 return GURL();
initial.commit09911bf2008-07-26 23:55:293327
3328 // Strip query params from the failed URL.
3329 GURL::Replacements remove_params;
3330 remove_params.ClearUsername();
3331 remove_params.ClearPassword();
3332 remove_params.ClearQuery();
3333 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553334 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503335 std::string spec_to_send = url_to_send.spec();
3336 // Notify link doctor of the url truncation by sending of "?" at the end.
3337 if (failed_url.has_query())
3338 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293339
3340 // Construct the query params to send to link doctor.
3341 std::string params(alternate_error_page_url_.query());
3342 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503343 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293344 params.append("&sourceid=chrome");
3345 params.append("&error=");
3346 switch (error_type) {
3347 case DNS_ERROR:
3348 params.append("dnserror");
3349 break;
3350
3351 case HTTP_404:
3352 params.append("http404");
3353 break;
3354
[email protected]5df266ac2008-10-15 19:50:133355 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333356 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133357 break;
3358
initial.commit09911bf2008-07-26 23:55:293359 default:
3360 NOTREACHED() << "unknown ErrorPageType";
3361 }
3362
3363 // OK, build the final url to return.
3364 GURL::Replacements link_doctor_params;
3365 link_doctor_params.SetQueryStr(params);
3366 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3367 return url;
3368}
3369
[email protected]24a7f3c2010-03-25 08:26:493370webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
[email protected]f40b49e2010-05-05 22:38:453371 WebPlugin* plugin =
3372 webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493373 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3374}
3375
[email protected]6069da8c2009-10-20 20:33:493376void RenderView::OnFind(int request_id, const string16& search_text,
3377 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273378 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493379
3380 if (main_frame->document().isPluginDocument()) {
3381 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3382 if (options.findNext) {
3383 // Just navigate back/forward.
3384 delegate->SelectFindResult(options.forward);
3385 } else {
3386 if (delegate->SupportsFind()) {
3387 delegate->StartFind(UTF16ToUTF8(search_text),
3388 options.matchCase,
3389 request_id);
3390 } else {
3391 ReportNoFindInPageResults(request_id);
3392 }
3393 }
3394 return;
3395 }
3396
[email protected]b4bb2502009-10-01 22:35:273397 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273398 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293399 WebFrame* search_frame = focused_frame; // start searching focused frame.
3400
3401 bool multi_frame = (frame_after_main != main_frame);
3402
3403 // If we have multiple frames, we don't want to wrap the search within the
3404 // frame, so we check here if we only have main_frame in the chain.
3405 bool wrap_within_frame = !multi_frame;
3406
[email protected]b3f2b912009-04-09 16:18:523407 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293408 bool result = false;
3409
[email protected]7830da3e2009-11-06 16:27:263410 // If something is selected when we start searching it means we cannot just
3411 // increment the current match ordinal; we need to re-generate it.
3412 WebRange current_selection = focused_frame->selectionRange();
3413
initial.commit09911bf2008-07-26 23:55:293414 do {
[email protected]dd7daa82009-08-10 05:46:453415 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593416 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293417
3418 if (!result) {
3419 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223420 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293421
3422 // Find the next frame, but skip the invisible ones.
3423 do {
3424 // What is the next frame to search? (we might be going backwards). Note
3425 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593426 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273427 search_frame->traverseNext(true) :
3428 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453429 } while (!search_frame->hasVisibleContent() &&
3430 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293431
[email protected]884db412008-11-24 23:46:503432 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223433 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293434
3435 // If we have multiple frames and we have wrapped back around to the
3436 // focused frame, we need to search it once more allowing wrap within
3437 // the frame, otherwise it will report 'no match' if the focused frame has
3438 // reported matches, but no frames after the focused_frame contain a
3439 // match for the search word(s).
3440 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453441 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593442 request_id, search_text, options, true, // Force wrapping.
3443 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293444 }
3445 }
3446
[email protected]26aa0482009-09-30 16:55:273447 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293448 } while (!result && search_frame != focused_frame);
3449
[email protected]7830da3e2009-11-06 16:27:263450 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293451 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453452 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293453 } else {
3454 // If nothing is found, set result to "0 of 0", otherwise, set it to
3455 // "-1 of 1" to indicate that we found at least one item, but we don't know
3456 // yet what is active.
3457 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3458 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293459
[email protected]4f3dc372009-02-24 00:10:293460 // If we find no matches then this will be our last status update.
3461 // Otherwise the scoping effort will send more results.
3462 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293463
[email protected]4f3dc372009-02-24 00:10:293464 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403465 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593466 request_id,
[email protected]4f3dc372009-02-24 00:10:293467 match_count,
3468 selection_rect,
3469 ordinal,
3470 final_status_update));
initial.commit09911bf2008-07-26 23:55:293471
initial.commit09911bf2008-07-26 23:55:293472 // Scoping effort begins, starting with the mainframe.
3473 search_frame = main_frame;
3474
[email protected]dd7daa82009-08-10 05:46:453475 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293476
3477 do {
3478 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453479 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293480
3481 // We don't start another scoping effort unless at least one match has
3482 // been found.
3483 if (result) {
3484 // Start new scoping request. If the scoping function determines that it
3485 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453486 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593487 search_text,
3488 options,
initial.commit09911bf2008-07-26 23:55:293489 true); // reset the tickmarks
3490 }
3491
3492 // Iterate to the next frame. The frame will not necessarily scope, for
3493 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273494 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293495 } while (search_frame != main_frame);
3496 }
3497}
3498
[email protected]24a7f3c2010-03-25 08:26:493499void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3500 WebView* view = webview();
3501 if (!view)
3502 return;
3503
3504 WebDocument doc = view->mainFrame()->document();
3505 if (doc.isPluginDocument()) {
3506 GetDelegateForPluginDocument()->StopFind();
3507 return;
3508 }
3509
3510 bool clear_selection =
3511 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3512 if (clear_selection)
3513 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3514
3515 WebFrame* frame = view->mainFrame();
3516 while (frame) {
3517 frame->stopFinding(clear_selection);
3518 frame = frame->traverseNext(false);
3519 }
3520
3521 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3522 WebFrame* focused_frame = view->focusedFrame();
3523 if (focused_frame) {
3524 WebDocument doc = focused_frame->document();
3525 if (!doc.isNull()) {
3526 WebNode node = doc.focusedNode();
3527 if (!node.isNull())
3528 node.simulateClick();
3529 }
3530 }
3531 }
3532}
3533
3534void RenderView::OnFindReplyAck() {
3535 // Check if there is any queued up request waiting to be sent.
3536 if (queued_find_reply_message_.get()) {
3537 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423538 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493539 }
3540}
3541
[email protected]8c4cdd42010-01-12 21:31:133542// static
3543std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403544 // Text with less than 100 bytes will probably not provide good results.
3545 // Report it as unknown language.
3546 if (text.length() < 100)
3547 return kUnknownLanguageCode;
3548
[email protected]8c4cdd42010-01-12 21:31:133549 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133550 int num_languages = 0;
3551 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423552 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133553 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423554 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133555 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403556 if (is_reliable && cld_language != NUM_LANGUAGES &&
3557 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483558 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3559 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263560 // language code for tradtional Chinese among others.
3561 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3562 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3563 // for Simplified Chinese.
3564 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133565 }
[email protected]8c4cdd42010-01-12 21:31:133566 return language;
[email protected]7893a982010-01-07 23:25:523567}
3568
[email protected]8934a3b2010-02-25 00:34:003569bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353570 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003571 return current_content_settings_.settings[settings_type] !=
3572 CONTENT_SETTING_BLOCK;
3573}
3574
3575void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3576 if (!content_blocked_[settings_type]) {
3577 content_blocked_[settings_type] = true;
3578 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353579 }
[email protected]0de80162010-02-03 04:52:353580}
3581
[email protected]71b0d5d2010-02-15 05:43:073582void RenderView::ClearBlockedContentSettings() {
3583 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3584 content_blocked_[i] = false;
3585}
3586
initial.commit09911bf2008-07-26 23:55:293587void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3588 Send(new ViewHostMsg_DnsPrefetch(host_names));
3589}
3590
[email protected]40bd6582009-12-04 23:49:513591void RenderView::OnZoom(PageZoom::Function function) {
3592 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3593 return;
3594
[email protected]258d31122010-05-09 10:59:413595 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523596 // Should we be saving zoom levels for plugins? It's not clear, so for now
3597 // don't.
3598 if (webview()->mainFrame()->document().isPluginDocument()) {
3599 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3600 int zoom;
3601 if (function == PageZoom::RESET) {
3602 zoom = 0;
3603 } else if (function == PageZoom::ZOOM_OUT) {
3604 zoom = -1;
3605 } else if (function == PageZoom::ZOOM_IN) {
3606 zoom = 1;
3607 } else {
3608 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113609 return;
[email protected]b03794d2010-03-26 19:57:523610 }
3611 delegate->Zoom(zoom);
3612 return;
3613 }
3614
[email protected]40bd6582009-12-04 23:49:513615 int zoom_level = webview()->zoomLevel();
3616 int new_zoom_level = webview()->setZoomLevel(false,
3617 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3618
[email protected]9d797f32010-04-23 07:17:543619 // Tell the browser which url got zoomed so it can update the saved values.
3620 Send(new ViewHostMsg_DidZoomURL(
3621 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513622}
3623
[email protected]9d797f32010-04-23 07:17:543624void RenderView::OnSetContentSettingsForLoadingURL(
3625 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013626 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543627 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013628}
3629
[email protected]9d797f32010-04-23 07:17:543630void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3631 int zoom_level) {
3632 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293633}
3634
[email protected]41fc0322009-09-04 22:23:403635void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273636 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293637}
3638
[email protected]a697f4c2009-09-14 22:30:183639void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273640 WebString no_encoding;
3641 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183642}
3643
[email protected]20ad2692009-11-20 18:27:203644bool RenderView::GetAllChildFrames(
3645 WebFrame* parent_frame,
3646 std::vector<WebFrame*>* frames_vector) const {
3647 if (!parent_frame)
3648 return false;
3649 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3650 child_frame = child_frame->nextSibling()) {
3651 frames_vector->push_back(child_frame);
3652 GetAllChildFrames(child_frame, frames_vector);
3653 }
3654 return true;
3655}
3656
[email protected]dd7daa82009-08-10 05:46:453657WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3658 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273659 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453660
3661 // xpath string can represent a frame deep down the tree (across multiple
3662 // frame DOMs).
3663 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3664 // should break into 2 xpaths
3665 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3666
[email protected]26aa0482009-09-30 16:55:273667 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453668
3669 std::wstring xpath_remaining = xpath;
3670 while (!xpath_remaining.empty()) {
3671 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3672 std::wstring xpath_child;
3673 if (delim_pos != std::wstring::npos) {
3674 xpath_child = xpath_remaining.substr(0, delim_pos);
3675 xpath_remaining.erase(0, delim_pos + 1);
3676 } else {
3677 xpath_remaining.swap(xpath_child);
3678 }
3679 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293680 }
3681
[email protected]dd7daa82009-08-10 05:46:453682 return frame;
initial.commit09911bf2008-07-26 23:55:293683}
3684
[email protected]f29acf52008-11-03 20:08:333685void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3686 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293687 WebFrame* web_frame = GetChildFrame(frame_xpath);
3688 if (!web_frame)
3689 return;
3690
[email protected]dd7daa82009-08-10 05:46:453691 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293692}
3693
[email protected]1810e132009-03-24 23:35:483694void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083695 const std::string& css,
3696 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483697 WebFrame* web_frame = GetChildFrame(frame_xpath);
3698 if (!web_frame)
3699 return;
3700
[email protected]ffaef0c2009-09-15 17:08:083701 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483702}
3703
[email protected]00c39612010-03-06 02:53:283704void RenderView::OnPepperPluginDestroy(
3705 WebPluginDelegatePepper* pepper_plugin) {
3706 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3707 current_pepper_plugins_.find(pepper_plugin);
3708 if (found_pepper == current_pepper_plugins_.end()) {
3709 NOTREACHED();
3710 return;
3711 }
3712 current_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473713
3714 // The plugin could have been destroyed while it was waiting for a file
3715 // choose callback, so check all pending completion callbacks and NULL them.
3716 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3717 file_chooser_completions_.begin();
3718 i != file_chooser_completions_.end(); /* nothing */) {
3719 if ((*i)->completion == pepper_plugin) {
3720 // We NULL the first one instead of deleting it because the plugin might
3721 // be the one waiting for a file choose callback. If the callback later
3722 // comes, we don't want to send the result to the next callback in line.
3723 if (i == file_chooser_completions_.begin())
3724 (*i)->completion = NULL;
3725 else
3726 i = file_chooser_completions_.erase(i);
3727 } else {
3728 ++i;
3729 }
3730 }
[email protected]00c39612010-03-06 02:53:283731}
3732
initial.commit09911bf2008-07-26 23:55:293733void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3734 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333735 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293736}
3737
[email protected]1810e132009-03-24 23:35:483738void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083739 const std::string& css,
3740 const std::string& id) {
3741 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413742
3743 // Notify RenderViewHost that css has been inserted into the frame.
3744 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483745}
3746
[email protected]7ea066a2009-04-06 20:21:593747void RenderView::OnAddMessageToConsole(
3748 const string16& frame_xpath,
3749 const string16& message,
3750 const WebConsoleMessage::Level& level) {
3751 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593752 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453753 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293754}
3755
[email protected]81e63782009-02-27 19:35:093756void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3757 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293758}
3759
3760void RenderView::OnSetDOMUIProperty(const std::string& name,
3761 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093762 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293763 dom_ui_bindings_.SetProperty(name, value);
3764}
3765
3766void RenderView::OnReservePageIDRange(int size_of_range) {
3767 next_page_id_ += size_of_range + 1;
3768}
3769
[email protected]e80c73b2009-04-07 23:24:583770void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3771 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253772 bool ended,
3773 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033774 if (ended) {
[email protected]26aa0482009-09-30 16:55:273775 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033776 }
initial.commit09911bf2008-07-26 23:55:293777}
3778
3779void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273780 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293781}
3782
initial.commit09911bf2008-07-26 23:55:293783void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103784 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293785 webkit_glue::FillPasswordForm(this->webview(), form_data);
3786}
3787
3788void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583789 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253790 const gfx::Point& screen_point,
3791 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273792 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583793 drop_data.ToDragData(),
3794 drop_data.identity,
3795 client_point,
[email protected]1d9f4132009-09-08 17:29:253796 screen_point,
3797 ops);
initial.commit09911bf2008-07-26 23:55:293798
[email protected]1d9f4132009-09-08 17:29:253799 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293800}
3801
[email protected]e80c73b2009-04-07 23:24:583802void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253803 const gfx::Point& screen_point,
3804 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273805 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253806 client_point,
3807 screen_point,
3808 ops);
initial.commit09911bf2008-07-26 23:55:293809
[email protected]1d9f4132009-09-08 17:29:253810 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293811}
3812
3813void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273814 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293815}
3816
[email protected]e80c73b2009-04-07 23:24:583817void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3818 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273819 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293820}
3821
3822void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593823 webkit_preferences_ = prefs;
3824 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293825}
3826
3827void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3828 alternate_error_page_url_ = url;
3829}
3830
[email protected]a0c7153e2009-12-09 14:36:333831void RenderView::OnCustomContextMenuAction(unsigned action) {
3832 webview()->performCustomContextMenuAction(action);
3833}
3834
[email protected]d4a00a72010-01-29 01:44:423835void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023836 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423837 const std::string& source_lang,
3838 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023839 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3840 translate_script);
[email protected]d4a00a72010-01-29 01:44:423841}
3842
[email protected]85d252e2010-04-06 22:21:023843void RenderView::OnRevertTranslation(int page_id) {
3844 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323845}
3846
initial.commit09911bf2008-07-26 23:55:293847void RenderView::OnInstallMissingPlugin() {
3848 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593849 if (first_default_plugin_)
3850 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293851}
3852
[email protected]cdaf8d02010-03-30 19:52:473853void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363854 // This could happen if we navigated to a different page before the user
3855 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473856 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363857 return;
3858
[email protected]cdaf8d02010-03-30 19:52:473859 WebVector<WebString> ws_file_names(paths.size());
3860 for (size_t i = 0; i < paths.size(); ++i)
3861 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463862
[email protected]cdaf8d02010-03-30 19:52:473863 if (file_chooser_completions_.front()->completion)
3864 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3865 file_chooser_completions_.pop_front();
3866
3867 // If there are more pending file chooser requests, schedule one now.
3868 if (!file_chooser_completions_.empty()) {
3869 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3870 file_chooser_completions_.front()->params));
3871 }
initial.commit09911bf2008-07-26 23:55:293872}
3873
3874void RenderView::OnEnableViewSourceMode() {
3875 if (!webview())
3876 return;
[email protected]26aa0482009-09-30 16:55:273877 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293878 if (!main_frame)
3879 return;
3880
[email protected]dd7daa82009-08-10 05:46:453881 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293882}
3883
[email protected]770dd8b2010-05-24 18:11:393884void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3885 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243886 if (send_preferred_size_changes_)
3887 return;
[email protected]9fb325e2010-05-06 18:23:243888 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393889
3890 // WebKit doesn't send a notification of the effective height of the page
3891 // changes, so poll for it.
3892 // TODO: Add a notification for this to WebKit, remove polling. After that's
3893 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
3894 // http://crbug.com/44850
3895 if (flags & kPreferredSizeHeightThisIsSlow) {
3896 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3897 &RenderView::CheckPreferredSize);
3898 }
[email protected]0666aef2009-05-13 19:48:083899}
3900
[email protected]cda45c02010-02-25 19:28:103901void RenderView::OnDisableScrollbarsForSmallWindows(
3902 const gfx::Size& disable_scrollbar_size_limit) {
3903 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3904}
3905
[email protected]80d96fa2009-06-10 22:34:513906void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3907 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373908 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033909#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413910 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3911 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463912 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323913
[email protected]644d77e2010-01-27 01:03:103914 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323915 webview()->setScrollbarColors(
3916 renderer_prefs.thumb_inactive_color,
3917 renderer_prefs.thumb_active_color,
3918 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103919 webview()->setSelectionColors(
3920 renderer_prefs.active_selection_bg_color,
3921 renderer_prefs.active_selection_fg_color,
3922 renderer_prefs.inactive_selection_bg_color,
3923 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:013924 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:103925 }
[email protected]7a74e102009-09-03 00:16:563926#endif
[email protected]80d96fa2009-06-10 22:34:513927}
3928
[email protected]952cb702009-10-07 05:50:283929void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3930 const WebMediaPlayerAction& action) {
3931 if (webview())
3932 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563933}
3934
[email protected]7b291f92009-08-14 05:43:533935void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513936 // When this is first set, the bindings aren't fully loaded. We only need
3937 // to call through this API after the page has already been loaded. It's
3938 // also called in didCreateDocumentElement to bootstrap.
3939 if (view_type_ != ViewType::INVALID) {
3940 if (type == ViewType::EXTENSION_MOLE ||
3941 type == ViewType::EXTENSION_TOOLSTRIP) {
3942 ExtensionProcessBindings::SetViewType(webview(), type);
3943 }
3944 }
[email protected]7b291f92009-08-14 05:43:533945 view_type_ = type;
3946}
3947
3948void RenderView::OnUpdateBrowserWindowId(int window_id) {
3949 browser_window_id_ = window_id;
3950}
3951
[email protected]b3df5a42010-05-11 14:31:093952void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:363953 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:413954 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:113955 accessibility_.reset(WebAccessibilityCache::create());
3956 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:413957
[email protected]b3df5a42010-05-11 14:31:093958 WebAccessibilityObject src_tree = webview()->accessibilityObject();
3959 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
3960 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:503961}
3962
[email protected]aef92842010-05-21 16:54:363963void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3964 if (!accessibility_.get())
3965 return;
3966 if (accessibility_->isValidId(acc_obj_id)) {
3967 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
3968 // By convention, calling SetFocus on the root of the tree (id = 1000)
3969 // should clear the current focus. Otherwise set the focus to the new
3970 // node.
3971 if (acc_obj_id == 1000)
3972 webview()->clearFocusedNode();
3973 else
3974 accessibility_->getObjectById(acc_obj_id).setFocused(true);
3975 }
3976}
3977
3978void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3979 if (!accessibility_.get())
3980 return;
3981 if (accessibility_->isValidId(acc_obj_id)) {
3982 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
3983 }
3984}
3985
initial.commit09911bf2008-07-26 23:55:293986void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3987 const GURL& page_url) {
3988 // Prepare list to storage all savable resource links.
3989 std::vector<GURL> resources_list;
3990 std::vector<GURL> referrers_list;
3991 std::vector<GURL> frames_list;
3992 webkit_glue::SavableResourcesResult result(&resources_list,
3993 &referrers_list,
3994 &frames_list);
3995
[email protected]dbeb3952009-10-13 18:01:183996 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3997 webview(),
3998 page_url,
3999 &result,
4000 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294001 // If something is wrong when collecting all savable resource links,
4002 // send empty list to embedder(browser) to tell it failed.
4003 referrers_list.clear();
4004 resources_list.clear();
4005 frames_list.clear();
4006 }
4007
4008 // Send result of all savable resource links to embedder.
4009 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4010 resources_list,
4011 referrers_list,
4012 frames_list));
4013}
4014
4015void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324016 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314017 const std::vector<FilePath>& local_paths,
4018 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074019
4020 // Convert std::vector of GURLs to WebVector<WebURL>
4021 WebVector<WebURL> weburl_links(links);
4022
4023 // Convert std::vector of std::strings to WebVector<WebString>
4024 WebVector<WebString> webstring_paths(local_paths.size());
4025 for (size_t i = 0; i < local_paths.size(); i++)
4026 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4027
4028 WebPageSerializer::serialize(webview()->mainFrame(),
4029 true, this, weburl_links, webstring_paths,
4030 webkit_glue::FilePathToWebString(
4031 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294032}
4033
[email protected]d9ec5c0f2009-12-23 11:55:074034void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4035 const WebCString& data,
4036 WebPageSerializerClient::PageSerializationStatus status) {
4037 Send(new ViewHostMsg_SendSerializedHtmlData(
4038 routing_id_,
4039 frame_url,
4040 data.data(),
4041 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294042}
4043
[email protected]04b4a6c2008-08-02 00:44:474044void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:274045 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474046 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294047}
4048
[email protected]eb6b87a2009-07-24 15:57:394049void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294050 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4051 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4052 // in the onunload handler from appearing. For now, we're bypassing that and
4053 // calling the FrameLoader's CloseURL method directly. This should be
4054 // revisited to avoid having two ways to close a page. Having a single way
4055 // to close that can run onunload is also useful for fixing
4056 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274057 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294058 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454059 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174060 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294061 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4062 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454063 if (url.SchemeIs(chrome::kHttpScheme) ||
4064 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294065 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294066 }
[email protected]26aa0482009-09-30 16:55:274067 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294068
[email protected]ab9eabac2010-03-16 16:54:104069 // Reset stats
4070 cross_origin_access_count_ = 0;
4071 same_origin_access_count_ = 0;
4072
[email protected]eb6b87a2009-07-24 15:57:394073 // Just echo back the params in the ACK.
4074 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294075}
4076
4077void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574078#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294079 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014080 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574081#else // defined(OS_WIN)
4082 // TODO(port): we don't support theming on non-Windows platforms yet
4083 NOTIMPLEMENTED();
4084#endif
initial.commit09911bf2008-07-26 23:55:294085}
4086
[email protected]28790922009-03-09 19:48:374087void RenderView::OnMessageFromExternalHost(const std::string& message,
4088 const std::string& origin,
4089 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154090 if (message.empty())
4091 return;
4092
[email protected]28790922009-03-09 19:48:374093 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4094 target);
[email protected]3ac14a052008-08-15 21:22:154095}
4096
[email protected]0aa55312008-10-17 21:53:084097void RenderView::OnDisassociateFromPopupCount() {
4098 if (decrement_shared_popup_at_destruction_)
4099 shared_popup_counter_->data--;
4100 shared_popup_counter_ = new SharedRenderViewCounter(0);
4101 decrement_shared_popup_at_destruction_ = false;
4102}
4103
[email protected]15d79e12009-08-02 19:23:454104bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4105 const WebURLError& error,
4106 bool replace) {
4107 // We only show alternate error pages in the main frame. They are
4108 // intended to assist the user when navigating, so there is not much
4109 // value in showing them for failed subframes. Ideally, we would be
4110 // able to use the TYPED transition type for this, but that flag is
4111 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454112 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454113 return false;
4114
4115 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374116 // connection failure.
[email protected]15d79e12009-08-02 19:23:454117 int ec = error.reason;
4118 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4119 ec != net::ERR_CONNECTION_FAILED &&
4120 ec != net::ERR_CONNECTION_REFUSED &&
4121 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374122 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454123 return false;
4124
4125 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554126 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454127 if (!error_page_url.is_valid())
4128 return false;
4129
4130 // Load an empty page first so there is an immediate response to the error,
4131 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454132 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454133 GURL(kUnreachableWebDataURL),
4134 error.unreachableURL,
4135 replace);
4136
4137 // Now, create a fetcher for the error page and associate it with the data
4138 // source we just created via the LoadHTMLString call. That way if another
4139 // navigation occurs, the fetcher will get destroyed.
4140 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454141 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454142 navigation_state->set_alt_error_page_fetcher(
4143 new AltErrorPageResourceFetcher(
4144 error_page_url, frame, error,
4145 NewCallback(this, &RenderView::AltErrorPageFinished)));
4146 return true;
4147}
4148
initial.commit09911bf2008-07-26 23:55:294149std::string RenderView::GetAltHTMLForTemplate(
4150 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394151 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294152 ResourceBundle::GetSharedInstance().GetRawDataResource(
4153 template_resource_id));
4154
4155 if (template_html.empty()) {
4156 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4157 return "";
4158 }
[email protected]7cd22a52009-07-14 00:40:254159
initial.commit09911bf2008-07-26 23:55:294160 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254161 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294162 template_html, &error_strings, "t");
4163}
[email protected]0e79b9e2009-02-13 04:20:484164
[email protected]15d79e12009-08-02 19:23:454165void RenderView::AltErrorPageFinished(WebFrame* frame,
4166 const WebURLError& original_error,
4167 const std::string& html) {
4168 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554169
4170 // If we failed to download the alternate error page, fall back to the
4171 // original error page if present. Otherwise, LoadNavigationErrorPage
4172 // will simply display a default error page.
4173 const std::string* html_to_load = &html;
4174 if (html.empty()) {
4175 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454176 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554177 html_to_load = &navigation_state->postponed_data();
4178 }
4179 LoadNavigationErrorPage(
4180 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454181}
4182
[email protected]30f75e62009-02-25 22:01:004183void RenderView::OnMoveOrResizeStarted() {
4184 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474185 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004186}
4187
[email protected]30f75e62009-02-25 22:01:004188void RenderView::OnResize(const gfx::Size& new_size,
4189 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104190 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474191 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104192
4193 if (send_preferred_size_changes_) {
4194 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4195 // either width or height, allow scroll bars.
4196 bool allow_scrollbars = (
4197 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244198 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104199 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4200 }
4201 }
4202
[email protected]30f75e62009-02-25 22:01:004203 RenderWidget::OnResize(new_size, resizer_rect);
4204}
[email protected]0aa477bd2009-03-23 22:21:434205
[email protected]00c39612010-03-06 02:53:284206void RenderView::DidInitiatePaint() {
4207 // Notify any pepper plugins that we started painting. The plugin "should"
4208 // never notified that we started painting, this is used for internal
4209 // bookkeeping only, so we know that the set can not change under us.
4210 for (std::set<WebPluginDelegatePepper*>::iterator i =
4211 current_pepper_plugins_.begin();
4212 i != current_pepper_plugins_.end(); ++i)
4213 (*i)->RenderViewInitiatedPaint();
4214}
4215
4216void RenderView::DidFlushPaint() {
4217 // Notify any pepper plugins that we painted. This will call into the plugin,
4218 // and we it may ask to close itself as a result. This will, in turn, modify
4219 // our set, possibly invalidating the iterator. So we iterate on a copy that
4220 // won't change out from under us.
4221 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4222 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4223 i != plugins.end(); ++i) {
4224 // The copy above makes sure our iterator is never invalid if some plugins
4225 // are destroyed. But some plugin may decide to close all of its views in
4226 // response to a paint in one of them, so we need to make sure each one is
4227 // still "current" before using it.
4228 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4229 (*i)->RenderViewFlushedPaint();
4230 }
4231
4232 WebFrame* main_frame = webview()->mainFrame();
4233
4234 // If we have a provisional frame we are between the start and commit stages
4235 // of loading and we don't want to save stats.
4236 if (!main_frame->provisionalDataSource()) {
4237 WebDataSource* ds = main_frame->dataSource();
4238 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4239 DCHECK(navigation_state);
4240
4241 Time now = Time::Now();
4242 if (navigation_state->first_paint_time().is_null()) {
4243 navigation_state->set_first_paint_time(now);
4244 }
4245 if (navigation_state->first_paint_after_load_time().is_null() &&
4246 !navigation_state->finish_load_time().is_null()) {
4247 navigation_state->set_first_paint_after_load_time(now);
4248 }
4249 }
4250}
4251
4252
[email protected]05d478752009-04-08 23:38:164253void RenderView::OnClearFocusedNode() {
4254 if (webview())
[email protected]26aa0482009-09-30 16:55:274255 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164256}
4257
[email protected]699ab0d2009-04-23 23:19:144258void RenderView::OnSetBackground(const SkBitmap& background) {
4259 if (webview())
[email protected]b4bb2502009-10-01 22:35:274260 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144261
4262 SetBackground(background);
4263}
4264
[email protected]8c66c5a2009-07-22 17:26:344265void RenderView::OnSetActive(bool active) {
4266 if (webview())
[email protected]b4bb2502009-10-01 22:35:274267 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264268
4269#if defined(OS_MACOSX)
4270 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4271 for (plugin_it = plugin_delegates_.begin();
4272 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4273 (*plugin_it)->SetWindowFocus(active);
4274 }
4275#endif
[email protected]8c66c5a2009-07-22 17:26:344276}
4277
[email protected]6ce7abc52010-02-02 18:40:144278#if defined(OS_MACOSX)
4279void RenderView::OnSetWindowVisibility(bool visible) {
4280 // Inform plugins that their container has changed visibility.
4281 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4282 for (plugin_it = plugin_delegates_.begin();
4283 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4284 (*plugin_it)->SetContainerVisibility(visible);
4285 }
4286}
[email protected]1e6e3c992010-02-08 15:52:134287
4288void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4289 gfx::Rect view_frame) {
4290 // Inform plugins that their window's frame has changed.
4291 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4292 for (plugin_it = plugin_delegates_.begin();
4293 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4294 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4295 }
4296}
[email protected]6ce7abc52010-02-02 18:40:144297#endif // OS_MACOSX
4298
[email protected]309d7a282009-03-24 09:18:274299void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584300 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394301 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324302 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474303 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394304 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4305 name,
4306 args,
4307 source_url,
4308 request_id,
[email protected]2f25d7b92009-06-10 00:06:474309 has_callback));
[email protected]309d7a282009-03-24 09:18:274310}
4311
[email protected]c6619182009-05-12 14:59:324312void RenderView::OnExtensionResponse(int request_id,
4313 bool success,
4314 const std::string& response,
4315 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354316 ExtensionProcessBindings::HandleResponse(
4317 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274318}
[email protected]c20210e62009-04-03 21:39:264319
[email protected]078b34612009-09-19 19:31:514320void RenderView::InjectToolstripCSS() {
4321 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4322 return;
4323
4324 static const base::StringPiece toolstrip_css(
4325 ResourceBundle::GetSharedInstance().GetRawDataResource(
4326 IDR_EXTENSION_TOOLSTRIP_CSS));
4327 std::string css = toolstrip_css.as_string();
4328 InsertCSS(L"", css, "ToolstripDefaultCSS");
4329}
4330
[email protected]7120f132009-07-20 21:05:374331void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494332 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194333 bool requires_incognito_access,
4334 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494335 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194336 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374337}
4338
[email protected]e7e4f3c2009-04-21 15:24:084339// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264340//
[email protected]7a9b51f2009-06-29 21:28:294341// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264342// The time points we keep are
4343// request: time document was requested by user
4344// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254345// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294346// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264347// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294348// first_paint: first paint performed
4349// first_paint_after_load: first paint performed after load is finished
4350// begin: request if it was user requested, start otherwise
4351//
[email protected]c20210e62009-04-03 21:39:264352// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254353// request->start,
[email protected]7a9b51f2009-06-29 21:28:294354// start->commit,
4355// commit->finish_document,
4356// finish_document->finish,
4357// begin->commit,
4358// begin->finishDoc,
4359// begin->finish,
4360// begin->first_paint,
4361// begin->first_paint_after_load
4362// commit->finishDoc,
4363// commit->first_paint,
4364// commit->first_paint_after_load,
4365// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264366//
[email protected]e7e4f3c2009-04-21 15:24:084367// It's possible for the request time not to be set, if a client
4368// redirect had been done (the user never requested the page)
4369// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294370// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264371void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274372 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564373 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454374 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564375
[email protected]f9f4841b2010-03-20 05:41:424376 // If we've already dumped, do nothing.
4377 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294378 return;
[email protected]b855ebe62010-05-12 23:01:454379 Time start = navigation_state->start_load_time();
4380 if (start.is_null())
4381 return; // Probably very premature abandonment of page.
4382 Time commit = navigation_state->commit_load_time();
4383 if (commit.is_null())
4384 return; // Probably very premature abandonment of page.
4385 // We properly handle null values for the next 3 variables.
4386 Time request = navigation_state->request_time();
4387 Time first_paint = navigation_state->first_paint_time();
4388 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
4389
4390 Time finish = navigation_state->finish_load_time();
4391 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564392
[email protected]f9f4841b2010-03-20 05:41:424393 // Handle case where user hits "stop" or "back" before loading completely.
4394 bool abandoned_page = finish.is_null();
4395 if (abandoned_page) {
4396 finish = Time::Now();
4397 navigation_state->set_finish_load_time(finish);
4398 }
[email protected]b855ebe62010-05-12 23:01:454399 if (finish_doc.is_null()) {
4400 finish_doc = Time::Now();
4401 navigation_state->set_finish_document_load_time(finish_doc);
4402 }
[email protected]f9f4841b2010-03-20 05:41:424403 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4404
[email protected]f8999642009-10-27 21:39:424405 LogNavigationState(navigation_state, main_frame->dataSource());
4406
[email protected]a7ccc4d2010-01-27 08:14:484407 NavigationState::LoadType load_type = navigation_state->load_type();
4408 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184409 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484410
[email protected]ab9eabac2010-03-16 16:54:104411 // Site isolation metrics.
4412 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4413 cross_origin_access_count_);
4414 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4415 same_origin_access_count_);
4416
[email protected]c20210e62009-04-03 21:39:264417
[email protected]7a9b51f2009-06-29 21:28:294418 Time begin;
4419 // Client side redirects will have no request time.
4420 if (request.is_null()) {
4421 begin = start;
4422 } else {
4423 begin = request;
4424 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084425 }
[email protected]7a9b51f2009-06-29 21:28:294426 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4427 UMA_HISTOGRAM_MEDIUM_TIMES(
4428 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4429 UMA_HISTOGRAM_MEDIUM_TIMES(
4430 "Renderer4.FinishDocToFinish", finish - finish_doc);
4431
4432 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484433
4434 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4435 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4436 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484437 TimeDelta begin_to_finish_doc = finish_doc - begin;
4438 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184439
4440 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4441 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4442 static const size_t kBeginToFinishBucketCount(100);
4443 TimeDelta begin_to_finish = finish_doc - begin;
4444 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4445 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4446
[email protected]a7ccc4d2010-01-27 08:14:484447 switch (load_type) {
4448 case NavigationState::UNDEFINED_LOAD:
4449 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4450 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4451 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184452 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4453 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4454 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484455 break;
4456 case NavigationState::RELOAD:
4457 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4458 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4459 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184460 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4461 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4462 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484463 break;
4464 case NavigationState::HISTORY_LOAD:
4465 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4466 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4467 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184468 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4469 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4470 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484471 break;
4472 case NavigationState::NORMAL_LOAD:
4473 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4474 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4475 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184476 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4477 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4478 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484479 break;
[email protected]4c1b6f0b2010-02-07 16:38:184480 case NavigationState::LINK_LOAD_NORMAL:
4481 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484482 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4483 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184484 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4485 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4486 kBeginToFinishBucketCount);
4487 break;
4488 case NavigationState::LINK_LOAD_RELOAD:
4489 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4490 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4491 kBeginToFinishDocBucketCount);
4492 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4493 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4494 kBeginToFinishBucketCount);
4495 break;
4496 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4497 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4498 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4499 kBeginToFinishDocBucketCount);
4500 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4501 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4502 kBeginToFinishBucketCount);
4503 break;
4504 case NavigationState::LINK_LOAD_CACHE_ONLY:
4505 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4506 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4507 kBeginToFinishDocBucketCount);
4508 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4509 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4510 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484511 break;
4512 default:
4513 break;
4514 }
4515
4516 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4517 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4518 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424519 UMA_HISTOGRAM_ENUMERATION(
4520 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4521 abandoned_page ? 1 : 0, 2);
4522 UMA_HISTOGRAM_ENUMERATION(
4523 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484524 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484525 switch (load_type) {
4526 case NavigationState::NORMAL_LOAD:
4527 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184528 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4529 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4530 kBeginToFinishBucketCount);
4531 break;
4532 case NavigationState::LINK_LOAD_NORMAL:
4533 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184534 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4535 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4536 kBeginToFinishBucketCount);
4537 break;
4538 case NavigationState::LINK_LOAD_RELOAD:
4539 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184540 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4541 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4542 kBeginToFinishBucketCount);
4543 break;
4544 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4545 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184546 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4547 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4548 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484549 break;
4550 default:
4551 break;
4552 }
4553 }
4554
4555 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4556 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4557 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484558 UMA_HISTOGRAM_ENUMERATION(
4559 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4560 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484561 switch (load_type) {
4562 case NavigationState::NORMAL_LOAD:
4563 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484564 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4565 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4566 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484567 break;
[email protected]4c1b6f0b2010-02-07 16:38:184568 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484569 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484570 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4571 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4572 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184573 break;
4574 case NavigationState::LINK_LOAD_RELOAD:
4575 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484576 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4577 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4578 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184579 break;
4580 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4581 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484582 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4583 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4584 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184585 break;
4586 case NavigationState::LINK_LOAD_CACHE_ONLY:
4587 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484588 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4589 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4590 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484591 break;
4592 default:
4593 break;
4594 }
4595 }
4596
4597 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4598 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184599 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4600 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484601 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4602 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4603 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4604 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544605
[email protected]65041fa2010-05-21 06:56:534606 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
4607 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
4608 if (use_spdy_histogram) {
4609 switch (load_type) {
4610 case NavigationState::LINK_LOAD_NORMAL:
4611 if (navigation_state->was_npn_negotiated()) {
4612 DCHECK(FieldTrialList::Find("SpdyImpact")->group_name() ==
4613 "_npn_with_http" ||
4614 FieldTrialList::Find("SpdyImpact")->group_name() ==
4615 "_npn_with_spdy");
4616 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4617 "Renderer4.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4618 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4619 kBeginToFinishBucketCount);
4620 }
4621 break;
4622 default:
4623 break;
4624 }
4625 }
4626
[email protected]0a32257a2009-07-09 18:10:414627 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4628 finish - start, kBeginToFinishMin,
4629 kBeginToFinishMax, kBeginToFinishBucketCount);
4630 if (!request.is_null())
4631 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4632 finish - request, kBeginToFinishMin,
4633 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544634
[email protected]7a9b51f2009-06-29 21:28:294635 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4636
4637 if (!first_paint.is_null()) {
[email protected]b855ebe62010-05-12 23:01:454638 DCHECK(begin <= first_paint);
[email protected]7a9b51f2009-06-29 21:28:294639 UMA_HISTOGRAM_MEDIUM_TIMES(
4640 "Renderer4.BeginToFirstPaint", first_paint - begin);
[email protected]b855ebe62010-05-12 23:01:454641 DCHECK(commit <= first_paint);
[email protected]7a9b51f2009-06-29 21:28:294642 UMA_HISTOGRAM_MEDIUM_TIMES(
4643 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264644 }
[email protected]7a9b51f2009-06-29 21:28:294645
4646 if (!first_paint_after_load.is_null()) {
[email protected]b855ebe62010-05-12 23:01:454647 DCHECK(begin <= first_paint_after_load);
[email protected]7a9b51f2009-06-29 21:28:294648 UMA_HISTOGRAM_MEDIUM_TIMES(
4649 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
[email protected]b855ebe62010-05-12 23:01:454650 DCHECK(commit <= first_paint_after_load);
[email protected]7a9b51f2009-06-29 21:28:294651 UMA_HISTOGRAM_MEDIUM_TIMES(
4652 "Renderer4.CommitToFirstPaintAfterLoad",
4653 first_paint_after_load - commit);
[email protected]b855ebe62010-05-12 23:01:454654 DCHECK(finish <= first_paint_after_load);
[email protected]7a9b51f2009-06-29 21:28:294655 UMA_HISTOGRAM_MEDIUM_TIMES(
4656 "Renderer4.FinishToFirstPaintAfterLoad",
4657 first_paint_after_load - finish);
4658 }
4659
4660 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414661
4662 // Since there are currently no guarantees that renderer histograms will be
4663 // sent to the browser, we initiate a PostTask here to be sure that we send
4664 // the histograms we generated. Without this call, pages that don't have an
4665 // on-close-handler might generate data that is lost when the renderer is
4666 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484667 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4668 // should post when the onload is complete, so that it doesn't interfere with
4669 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414670 if (RenderThread::current()) {
4671 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134672 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414673 }
[email protected]c20210e62009-04-03 21:39:264674}
[email protected]e846d0d2009-05-20 00:53:064675
[email protected]f8999642009-10-27 21:39:424676void RenderView::LogNavigationState(const NavigationState* state,
4677 const WebDataSource* ds) const {
4678 // Because this function gets called on every page load,
4679 // take extra care to optimize it away if logging is turned off.
4680 if (logging::LOG_INFO < logging::GetMinLogLevel())
4681 return;
4682
4683 DCHECK(state);
4684 DCHECK(ds);
4685 GURL url(ds->request().url());
4686 Time start = state->start_load_time();
4687 Time finish = state->finish_load_time();
4688 // TODO(mbelshe): should we log more stats?
4689 LOG(INFO) << "PLT: "
4690 << (finish - start).InMilliseconds()
4691 << "ms "
4692 << url.spec();
4693}
4694
[email protected]cc0445f2009-10-13 16:09:084695void RenderView::focusAccessibilityObject(
4696 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064697#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154698 // TODO(dglazkov): Current logic implies that focus change can only be made
4699 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4700 // where accessibility is initialized. We should determine whether that's
4701 // right.
4702 if (!accessibility_.get())
4703 return;
[email protected]e846d0d2009-05-20 00:53:064704
4705 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154706 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064707
4708 // If id is valid, alert the browser side that an accessibility focus change
4709 // occurred.
4710 if (acc_obj_id >= 0)
4711 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4712
4713#else // defined(OS_WIN)
4714 // TODO(port): accessibility not yet implemented
4715 NOTIMPLEMENTED();
4716#endif
4717}
[email protected]daa8c58e2009-06-15 17:21:104718
[email protected]e9e07992010-02-17 21:04:364719void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044720 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4721 // control elements in the cache.
4722 WebVector<WebFormElement> web_forms;
4723 frame->forms(web_forms);
4724
[email protected]b1438212010-04-03 00:30:594725 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044726 for (size_t i = 0; i < web_forms.size(); ++i) {
4727 const WebFormElement& web_form = web_forms[i];
4728
4729 FormData form;
[email protected]b715f7f2010-04-05 22:01:044730 if (FormManager::WebFormElementToFormData(
[email protected]573c1c272010-05-25 19:28:064731 web_form, FormManager::REQUIRE_NONE, false, &form))
[email protected]b715f7f2010-04-05 22:01:044732 forms.push_back(form);
4733 }
[email protected]e6efd022010-03-31 09:34:504734
4735 if (!forms.empty())
4736 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364737}
4738
[email protected]a3018be2010-03-09 04:28:484739void RenderView::didChangeAccessibilityObjectState(
4740 const WebKit::WebAccessibilityObject& acc_obj) {
4741#if defined(OS_WIN)
4742 // TODO(dglazkov): Current logic implies that a state change can only be made
4743 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4744 // where accessibility is initialized. We should determine whether that's
4745 // right.
4746 if (!accessibility_.get())
4747 return;
4748
4749 // Retrieve the accessibility object id of the AccessibilityObject.
4750 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4751
4752 // If id is valid, alert the browser side that an accessibility object state
4753 // change occurred.
4754 if (acc_obj_id >= 0)
4755 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4756 acc_obj_id));
4757
4758#else // defined(OS_WIN)
4759 // TODO(port): accessibility not yet implemented
4760 NOTIMPLEMENTED();
4761#endif
4762}
4763
[email protected]4d44a1c2010-04-28 19:20:414764void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) {
[email protected]55ced002010-05-21 04:49:594765 // Make sure that this security origin is allowed to use password manager.
4766 WebSecurityOrigin security_origin = frame->securityOrigin();
4767 if (!security_origin.canAccessPasswordManager())
4768 return;
4769
[email protected]979c28b2009-11-07 01:30:484770 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454771 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104772
4773 std::vector<PasswordForm> password_forms;
4774 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484775 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104776
4777 // Respect autocomplete=off.
[email protected]4d44a1c2010-04-28 19:20:414778 if (!form.autoComplete())
4779 continue;
4780 if (only_visible && !form.hasNonEmptyBoundingBox())
4781 continue;
4782 scoped_ptr<PasswordForm> password_form(
4783 PasswordFormDomManager::CreatePasswordForm(form));
4784 if (password_form.get())
4785 password_forms.push_back(*password_form);
[email protected]daa8c58e2009-06-15 17:21:104786 }
4787
[email protected]4d44a1c2010-04-28 19:20:414788 if (password_forms.empty())
4789 return;
4790 if (only_visible)
4791 Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms));
4792 else
4793 Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms));
[email protected]daa8c58e2009-06-15 17:21:104794}
[email protected]0fda7272009-06-26 15:49:334795
4796void RenderView::Print(WebFrame* frame, bool script_initiated) {
4797 DCHECK(frame);
4798 if (print_helper_.get() == NULL) {
4799 print_helper_.reset(new PrintWebViewHelper(this));
4800 }
4801 print_helper_->Print(frame, script_initiated);
4802}
[email protected]446705872009-09-10 07:22:484803
4804void RenderView::OnSetEditCommandsForNextKeyEvent(
4805 const EditCommands& edit_commands) {
4806 edit_commands_ = edit_commands;
4807}
4808
[email protected]61f5a7b2009-12-22 22:21:204809void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274810 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354811 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204812 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4813 false));
[email protected]912256b32009-09-18 09:47:354814 return;
4815 }
4816
[email protected]fa7b6b542009-11-03 05:02:304817 WebDataSource* ds = main_frame->dataSource();
4818 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4819 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204820 pending_code_execution_queue_.push(
4821 linked_ptr<ViewMsg_ExecuteCode_Params>(
4822 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304823 return;
4824 }
4825
[email protected]61f5a7b2009-12-22 22:21:204826 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304827}
4828
4829void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204830 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484831 // Don't execute scripts in gallery pages.
4832 GURL frame_url = GURL(frame->url());
4833 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4834 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4835 return;
4836 }
4837
[email protected]20ad2692009-11-20 18:27:204838 std::vector<WebFrame*> frame_vector;
4839 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204840 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204841 GetAllChildFrames(frame, &frame_vector);
4842
4843 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4844 frame_it != frame_vector.end(); ++frame_it) {
4845 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204846 if (params.is_javascript) {
4847 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4848 continue;
4849
[email protected]20ad2692009-11-20 18:27:204850 std::vector<WebScriptSource> sources;
4851 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204852 WebScriptSource(WebString::fromUTF8(params.code)));
4853 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204854 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204855 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204856 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4857 } else {
[email protected]61f5a7b2009-12-22 22:21:204858 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204859 }
[email protected]912256b32009-09-18 09:47:354860 }
4861
[email protected]61f5a7b2009-12-22 22:21:204862 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354863}
4864
[email protected]60c42a8c72009-10-09 04:08:594865void RenderView::Close() {
4866 // We need to grab a pointer to the doomed WebView before we destroy it.
4867 WebView* doomed = webview();
4868 RenderWidget::Close();
4869 Singleton<ViewMap>::get()->erase(doomed);
4870}
4871
[email protected]446705872009-09-10 07:22:484872void RenderView::DidHandleKeyEvent() {
4873 edit_commands_.clear();
4874}
4875
[email protected]941e4552010-02-01 21:23:434876#if defined(OS_MACOSX)
4877void RenderView::OnWasHidden() {
4878 RenderWidget::OnWasHidden();
4879
4880 // Inform plugins that their container is no longer visible.
4881 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4882 for (plugin_it = plugin_delegates_.begin();
4883 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4884 (*plugin_it)->SetContainerVisibility(false);
4885 }
4886}
4887
4888void RenderView::OnWasRestored(bool needs_repainting) {
4889 RenderWidget::OnWasRestored(needs_repainting);
4890
4891 // Inform plugins that their container is now visible.
4892 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4893 for (plugin_it = plugin_delegates_.begin();
4894 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4895 (*plugin_it)->SetContainerVisibility(true);
4896 }
4897}
[email protected]1e6e3c992010-02-08 15:52:134898
4899void RenderView::OnSetFocus(bool enable) {
4900 RenderWidget::OnSetFocus(enable);
4901
[email protected]7d3c02c2010-05-05 23:10:314902 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:134903 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4904 for (plugin_it = plugin_delegates_.begin();
4905 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:314906 // RenderWidget's call to setFocus can cause the underlying webview's
4907 // activation state to change just like a call to setIsActive.
4908 if (enable)
4909 (*plugin_it)->SetWindowFocus(true);
4910 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134911 }
4912 }
4913}
[email protected]941e4552010-02-01 21:23:434914#endif // OS_MACOSX
4915
[email protected]83dde542009-09-11 20:59:554916void RenderView::EnsureDocumentTag() {
4917 // TODO(darin): There's actually no reason for this to be here. We should
4918 // have the browser side manage the document tag.
4919#if defined(OS_MACOSX)
4920 if (!has_document_tag_) {
4921 // Make the call to get the tag.
4922 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4923 has_document_tag_ = true;
4924 }
4925#endif
4926}
[email protected]12636df2009-09-28 22:32:214927
[email protected]43f28f832010-02-03 02:28:484928#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:034929gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
4930 bool opaque) {
[email protected]43f28f832010-02-03 02:28:484931 gfx::PluginWindowHandle window = NULL;
4932 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]ea04a4e12010-04-15 00:58:034933 routing_id(), opaque, &window));
[email protected]43f28f832010-02-03 02:28:484934 return window;
4935}
4936
4937void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4938 if (window)
4939 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4940}
4941
[email protected]44ce0b12010-03-12 16:45:334942void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4943 int32 width,
4944 int32 height,
4945 uint64 io_surface_identifier) {
4946 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484947 routing_id(), window, width, height, io_surface_identifier));
4948}
4949
[email protected]44ce0b12010-03-12 16:45:334950void RenderView::AcceleratedSurfaceSetTransportDIB(
4951 gfx::PluginWindowHandle window,
4952 int32 width,
4953 int32 height,
4954 TransportDIB::Handle transport_dib) {
4955 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074956 routing_id(), window, width, height, transport_dib));
4957}
4958
[email protected]44ce0b12010-03-12 16:45:334959TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4960 size_t size) {
[email protected]1aef98132010-02-23 18:00:074961 TransportDIB::Handle dib_handle;
4962 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384963 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074964 return dib_handle;
4965 // Return an invalid handle if Send() fails.
4966 return TransportDIB::DefaultHandleValue();
4967}
4968
[email protected]44ce0b12010-03-12 16:45:334969void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074970 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4971}
4972
[email protected]44ce0b12010-03-12 16:45:334973void RenderView::AcceleratedSurfaceBuffersSwapped(
4974 gfx::PluginWindowHandle window) {
4975 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484976}
4977#endif
[email protected]58c321d2010-02-19 12:11:284978
[email protected]cdaf8d02010-03-30 19:52:474979bool RenderView::ScheduleFileChooser(
4980 const ViewHostMsg_RunFileChooser_Params& params,
4981 WebFileChooserCompletion* completion) {
4982 static const size_t kMaximumPendingFileChooseRequests = 4;
4983 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4984 // This sanity check prevents too many file choose requests from getting
4985 // queued which could DoS the user. Getting these is most likely a
4986 // programming error (there are many ways to DoS the user so it's not
4987 // considered a "real" security check), either in JS requesting many file
4988 // choosers to pop up, or in a plugin.
4989 //
4990 // TODO(brettw) we might possibly want to require a user gesture to open
4991 // a file picker, which will address this issue in a better way.
4992 return false;
4993 }
4994
4995 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4996 new PendingFileChooser(params, completion)));
4997 if (file_chooser_completions_.size() == 1) {
4998 // Actually show the browse dialog when this is the first request.
4999 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5000 }
5001 return true;
5002}
5003
[email protected]290838a2010-04-27 17:37:015004void RenderView::OnPageTranslated() {
5005 WebFrame* frame = webview()->mainFrame();
5006 if (!frame)
5007 return;
5008
5009 // The page is translated, so try to extract the form data again.
5010 form_manager_.ExtractForms(frame);
5011 SendForms(frame);
5012}
5013
[email protected]8a5f7002010-03-31 13:47:355014WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285015 if (!geolocation_dispatcher_.get())
5016 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5017 return geolocation_dispatcher_.get();
5018}
[email protected]61c9f032010-03-31 23:04:195019
[email protected]8079b362010-05-07 18:37:455020bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195021 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455022 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195023 if (frame->parent() != NULL)
5024 return false;
5025
5026 // Skip if navigation is on the same page (using '#').
5027 GURL frame_origin = GURL(frame->url()).GetOrigin();
5028 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5029 // The link click could stay on the same page, in cases where it sends some
5030 // parameters to the same URL.
5031 if (type == WebKit::WebNavigationTypeLinkClicked)
5032 return true;
5033
5034 if (last_top_level_navigation_page_id_ != page_id_ &&
5035 // Not interested in reloads.
5036 type != WebKit::WebNavigationTypeReload &&
5037 type != WebKit::WebNavigationTypeFormSubmitted) {
5038 return true;
5039 }
5040 }
5041 return false;
5042}